]> granicus.if.org Git - cronie/commitdiff
Portability: Use swap_uids() instead of setreuid() directly
authorSATOH Fumiyasu <fumiyas@osstech.co.jp>
Tue, 3 Nov 2009 09:51:40 +0000 (10:51 +0100)
committerMarcela Mašláňová <mmaslano@redhat.com>
Tue, 3 Nov 2009 09:51:40 +0000 (10:51 +0100)
Signed-off-by: Marcela Mašláňová <mmaslano@redhat.com>
src/crontab.c

index 1277fa2c642ace55bdab0c5a39548aeac394afa1..d39b8f2cd4e024e8f95afcb6c83a91d6284e265c 100644 (file)
@@ -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;