From: SATOH Fumiyasu Date: Tue, 3 Nov 2009 09:51:40 +0000 (+0100) Subject: Portability: Use swap_uids() instead of setreuid() directly X-Git-Tag: cronie1.4.3~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c2a6e1969841312118d0eb09b396b823c195f6c;p=cronie Portability: Use swap_uids() instead of setreuid() directly Signed-off-by: Marcela Mašláňová --- diff --git a/src/crontab.c b/src/crontab.c index 1277fa2..d39b8f2 100644 --- a/src/crontab.c +++ b/src/crontab.c @@ -352,7 +352,6 @@ static void edit_cmd(void) { struct utimbuf utimebuf; WAIT_T waiter; PID_T pid, xpid; - int uid; log_it(RealUser, Pid, "BEGIN EDIT", User, 0); if (!glue_strings(n, sizeof n, SPOOL_DIR, User, '/')) { @@ -379,16 +378,21 @@ static void edit_cmd(void) { if (!glue_strings(Filename, sizeof Filename, tmp_path(), "crontab.XXXXXXXXXX", '/')) { fprintf(stderr, "path too long\n"); - goto fatal; + exit(ERROR_EXIT); + } + if (swap_uids() == -1) { + perror("swapping uids"); + exit(ERROR_EXIT); } - uid = MY_UID(pw); - setreuid(0, uid); if (-1 == (t = mkstemp(Filename))) { perror(Filename); goto fatal; } - setreuid(uid, 0); + if (swap_uids_back() == -1) { + perror("swapping uids back"); + goto fatal; + } if (!(NewCrontab = fdopen(t, "r+"))) { perror("fdopen"); goto fatal;