]> granicus.if.org Git - sudo/commitdiff
Fix mode on sudoers as needed when the -f option is not specified.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 12 Jan 2012 18:20:10 +0000 (13:20 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 12 Jan 2012 18:20:10 +0000 (13:20 -0500)
--HG--
branch : 1.7

visudo.c

index dd32387db0306aa21ade7ba0064594296e66b59a..e3f9b8cfdeb5834509e1280827f20bccd708da90 100644 (file)
--- a/visudo.c
+++ b/visudo.c
@@ -235,12 +235,9 @@ main(argc, argv)
     /* Check edited files for a parse error and re-edit any that fail. */
     reparse_sudoers(editor, args, strict, quiet);
 
-    /* Install the sudoers temp files. */
+    /* Install the sudoers temp files as needed. */
     tq_foreach_fwd(&sudoerslist, sp) {
-       if (!sp->modified)
-           (void) unlink(sp->tpath);
-       else
-           (void) install_sudoers(sp, oldperms);
+       (void) install_sudoers(sp, oldperms);
     }
 
     exit(0);
@@ -533,6 +530,20 @@ install_sudoers(sp, oldperms)
 {
     struct stat sb;
 
+    if (!sp->modified) {
+       /*
+        * No changes but fix owner/mode if needed.
+        */
+       (void) unlink(sp->tpath);
+       if (!oldperms && fstat(sp->fd, &sb) != -1) {
+           if (sb.st_uid != SUDOERS_UID || sb.st_gid != SUDOERS_GID)
+               (void) chown(sp->path, SUDOERS_UID, SUDOERS_GID);
+           if ((sb.st_mode & 0777) != SUDOERS_MODE)
+               (void) chmod(sp->path, SUDOERS_MODE);
+       }
+       return TRUE;
+    }
+
     /*
      * Change mode and ownership of temp file so when
      * we move it to sp->path things are kosher.