]> granicus.if.org Git - sudo/commitdiff
More useful exit codes:
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 29 Mar 2011 21:53:02 +0000 (17:53 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 29 Mar 2011 21:53:02 +0000 (17:53 -0400)
 * 0 - parsed OK and command matched.
 * 1 - parse error
 * 2 - command not matched
 * 3 - command denied

--HG--
branch : 1.7

testsudoers.c

index 7e0ebbf56ae7c5cfba65cd53d3c71f86eb382143..ec17f3cbd5342c16bf6931dda0ca108c9f97423a 100644 (file)
@@ -222,10 +222,12 @@ main(argc, argv)
     /* Allocate space for data structures in the parser. */
     init_parser("sudoers", 0);
 
-    if (yyparse() != 0 || parse_error)
+    if (yyparse() != 0 || parse_error) {
+       parse_error = TRUE;
        (void) fputs("Does not parse", stdout);
-    else
+    } else {
        (void) fputs("Parses OK", stdout);
+    }
 
     if (!update_defaults(SETDEF_ALL))
        (void) fputs(" (problem with defaults entries)", stdout);
@@ -247,7 +249,7 @@ main(argc, argv)
        (void) putchar('\n');
        dump_sudoers();
        if (argc < 2)
-           exit(0);
+           exit(parse_error ? 1 : 0);
     }
 
     /* This loop must match the one in sudoers_lookup() */
@@ -280,7 +282,16 @@ main(argc, argv)
     printf("\nCommand %s\n", matched == ALLOW ? "allowed" :
        matched == DENY ? "denied" : "unmatched");
 
-    exit(0);
+    /*
+     * Exit codes:
+     * 0 - parsed OK and command matched.
+     * 1 - parse error
+     * 2 - command not matched
+     * 3 - command denied
+     */
+    if (parse_error)
+       exit(1);
+    exit(matched == ALLOW ? 0 : matched + 3);
 }
 
 void