From 752f8953f46905587ad868fe919c134c2fbd9dad Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 29 Mar 2011 17:53:02 -0400 Subject: [PATCH] More useful exit codes: * 0 - parsed OK and command matched. * 1 - parse error * 2 - command not matched * 3 - command denied --HG-- branch : 1.7 --- testsudoers.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/testsudoers.c b/testsudoers.c index 7e0ebbf56..ec17f3cbd 100644 --- a/testsudoers.c +++ b/testsudoers.c @@ -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 -- 2.40.0