]> granicus.if.org Git - sudo/commitdiff
Make "visudo -c -f -" check the standard input.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 9 Sep 2010 21:10:23 +0000 (17:10 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 9 Sep 2010 21:10:23 +0000 (17:10 -0400)
doc/visudo.pod
plugins/sudoers/visudo.c

index d5d51f1a770244ebd15938dd650f43e2b62bcc48..073dda7eda8f78e33c36dfd45a9712b2017a3f8c 100644 (file)
@@ -82,6 +82,8 @@ Specify and alternate I<sudoers> file location.  With this option
 B<visudo> will edit (or check) the I<sudoers> file of your choice,
 instead of the default, F<@sysconfdir@/sudoers>.  The lock file used
 is the specified I<sudoers> file with ".tmp" appended to it.
+In B<check-only> mode only, the argument to B<-f> may be "-",
+indicating that I<sudoers> will be read from the standard input.
 
 =item -q
 
index de3921d8269735526e064ab3fd1c830eff60d7dc..f4f47fbfeed0a17221320bf9c1e7981da79cdbfe 100644 (file)
@@ -683,7 +683,10 @@ check_syntax(char *sudoers_path, int quiet, int strict)
     struct stat sb;
     int error;
 
-    if ((yyin = fopen(sudoers_path, "r")) == NULL) {
+    if (strcmp(sudoers_path, "-") == 0) {
+       yyin = stdin;
+       sudoers_path = "stdin";
+    } else if ((yyin = fopen(sudoers_path, "r")) == NULL) {
        if (!quiet)
            warning("unable to open %s", sudoers_path);
        exit(1);
@@ -713,9 +716,9 @@ check_syntax(char *sudoers_path, int quiet, int strict)
     }
     /* Check mode and owner in strict mode. */
 #ifdef HAVE_FSTAT
-    if (strict && fstat(fileno(yyin), &sb) == 0)
+    if (strict && yyin != stdin && fstat(fileno(yyin), &sb) == 0)
 #else
-    if (strict && stat(sudoers_path, &sb) == 0)
+    if (strict && yyin != stdin && stat(sudoers_path, &sb) == 0)
 #endif
     {
        if (sb.st_uid != SUDOERS_UID || sb.st_gid != SUDOERS_GID) {