]> 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:09:54 +0000 (17:09 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 9 Sep 2010 21:09:54 +0000 (17:09 -0400)
--HG--
branch : 1.7

visudo.c
visudo.pod

index e2ca61a11b419954c01cf29579db3f4a58b87080..c320602cb9f1567cb25ab6b4020fa6deb51ef17c 100644 (file)
--- a/visudo.c
+++ b/visudo.c
@@ -694,7 +694,10 @@ check_syntax(sudoers_path, quiet, 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);
@@ -724,9 +727,9 @@ check_syntax(sudoers_path, quiet, 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) {
index ccc5c00b223b961219e28ae56f1b966a9970420c..55e0c7c061981eae14d8dc9059b443f3ad9b394a 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