|
|
| version 1.1.1.4, 2013/07/22 10:46:12 | version 1.1.1.5, 2013/10/14 07:56:35 |
|---|---|
| Line 70 | Line 70 |
| #if TIME_WITH_SYS_TIME | #if TIME_WITH_SYS_TIME |
| # include <time.h> | # include <time.h> |
| #endif | #endif |
| #ifdef HAVE_GETOPT_LONG | |
| # include <getopt.h> | |
| # else | |
| # include "compat/getopt.h" | |
| #endif /* HAVE_GETOPT_LONG */ | |
| #include "sudoers.h" | #include "sudoers.h" |
| #include "parse.h" | #include "parse.h" |
| Line 120 extern FILE *sudoersin; | Line 125 extern FILE *sudoersin; |
| extern char *sudoers, *errorfile; | extern char *sudoers, *errorfile; |
| extern int errorlineno; | extern int errorlineno; |
| extern bool parse_error; | extern bool parse_error; |
| /* For getopt(3) */ | |
| extern char *optarg; | |
| extern int optind; | |
| /* | /* |
| * Globals | * Globals |
| Line 132 struct passwd *list_pw; | Line 134 struct passwd *list_pw; |
| static struct sudoersfile_list sudoerslist; | static struct sudoersfile_list sudoerslist; |
| static struct rbtree *alias_freelist; | static struct rbtree *alias_freelist; |
| static bool checkonly; | static bool checkonly; |
| static const char short_opts[] = "cf:hqsV"; | |
| static struct option long_opts[] = { | |
| { "check", no_argument, NULL, 'c' }, | |
| { "file", required_argument, NULL, 'f' }, | |
| { "help", no_argument, NULL, 'h' }, | |
| { "quiet", no_argument, NULL, 'q' }, | |
| { "strict", no_argument, NULL, 's' }, | |
| { "version", no_argument, NULL, 'V' }, | |
| { NULL, no_argument, NULL, '\0' }, | |
| }; | |
| __dso_public int main(int argc, char *argv[]); | __dso_public int main(int argc, char *argv[]); |
| Line 173 main(int argc, char *argv[]) | Line 185 main(int argc, char *argv[]) |
| */ | */ |
| checkonly = oldperms = quiet = strict = false; | checkonly = oldperms = quiet = strict = false; |
| sudoers_path = _PATH_SUDOERS; | sudoers_path = _PATH_SUDOERS; |
| while ((ch = getopt(argc, argv, "Vcf:sq")) != -1) { | while ((ch = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { |
| switch (ch) { | switch (ch) { |
| case 'V': | case 'V': |
| (void) printf(_("%s version %s\n"), getprogname(), PACKAGE_VERSION); | (void) printf(_("%s version %s\n"), getprogname(), |
| (void) printf(_("%s grammar version %d\n"), getprogname(), SUDOERS_GRAMMAR_VERSION); | PACKAGE_VERSION); |
| (void) printf(_("%s grammar version %d\n"), getprogname(), | |
| SUDOERS_GRAMMAR_VERSION); | |
| goto done; | goto done; |
| case 'c': | case 'c': |
| checkonly = true; /* check mode */ | checkonly = true; /* check mode */ |
| Line 193 main(int argc, char *argv[]) | Line 207 main(int argc, char *argv[]) |
| strict = true; /* strict mode */ | strict = true; /* strict mode */ |
| break; | break; |
| case 'q': | case 'q': |
| quiet = false; /* quiet mode */ | quiet = true; /* quiet mode */ |
| break; | break; |
| default: | default: |
| usage(1); | usage(1); |
| Line 727 setup_signals(void) | Line 741 setup_signals(void) |
| /* | /* |
| * Setup signal handlers to cleanup nicely. | * Setup signal handlers to cleanup nicely. |
| */ | */ |
| zero_bytes(&sa, sizeof(sa)); | memset(&sa, 0, sizeof(sa)); |
| sigemptyset(&sa.sa_mask); | sigemptyset(&sa.sa_mask); |
| sa.sa_flags = SA_RESTART; | sa.sa_flags = SA_RESTART; |
| sa.sa_handler = quit; | sa.sa_handler = quit; |
| Line 838 check_syntax(char *sudoers_path, bool quiet, bool stri | Line 852 check_syntax(char *sudoers_path, bool quiet, bool stri |
| struct sudoersfile *sp; | struct sudoersfile *sp; |
| /* Parsed OK, check mode and owner. */ | /* Parsed OK, check mode and owner. */ |
| if (oldperms || check_owner(sudoers_path, quiet)) | if (oldperms || check_owner(sudoers_path, quiet)) { |
| (void) printf(_("%s: parsed OK\n"), sudoers_path); | if (!quiet) |
| else | (void) printf(_("%s: parsed OK\n"), sudoers_path); |
| } else { | |
| ok = false; | ok = false; |
| } | |
| tq_foreach_fwd(&sudoerslist, sp) { | tq_foreach_fwd(&sudoerslist, sp) { |
| if (oldperms || check_owner(sp->path, quiet)) | if (oldperms || check_owner(sp->path, quiet)) { |
| (void) printf(_("%s: parsed OK\n"), sp->path); | if (!quiet) |
| else | (void) printf(_("%s: parsed OK\n"), sp->path); |
| } else { | |
| ok = false; | ok = false; |
| } | |
| } | } |
| } | } |
| Line 1055 get_hostname(void) | Line 1073 get_hostname(void) |
| } else { | } else { |
| user_host = user_shost = "localhost"; | user_host = user_shost = "localhost"; |
| } | } |
| user_runhost = user_host; | |
| user_srunhost = user_shost; | |
| debug_return; | debug_return; |
| } | } |
| Line 1095 check_alias(char *name, int type, int strict, int quie | Line 1115 check_alias(char *name, int type, int strict, int quie |
| alias_put(a); | alias_put(a); |
| } else { | } else { |
| if (!quiet) { | if (!quiet) { |
| char *fmt; | |
| if (errno == ELOOP) { | if (errno == ELOOP) { |
| fmt = strict ? | warningx(strict ? |
| _("Error: cycle in %s_Alias `%s'") : | _("Error: cycle in %s_Alias `%s'") : |
| _("Warning: cycle in %s_Alias `%s'"); | _("Warning: cycle in %s_Alias `%s'"), |
| type == HOSTALIAS ? "Host" : type == CMNDALIAS ? "Cmnd" : | |
| type == USERALIAS ? "User" : type == RUNASALIAS ? "Runas" : | |
| "Unknown", name); | |
| } else { | } else { |
| fmt = strict ? | warningx(strict ? |
| _("Error: %s_Alias `%s' referenced but not defined") : | _("Error: %s_Alias `%s' referenced but not defined") : |
| _("Warning: %s_Alias `%s' referenced but not defined"); | _("Warning: %s_Alias `%s' referenced but not defined"), |
| type == HOSTALIAS ? "Host" : type == CMNDALIAS ? "Cmnd" : | |
| type == USERALIAS ? "User" : type == RUNASALIAS ? "Runas" : | |
| "Unknown", name); | |
| } | } |
| warningx(fmt, | |
| type == HOSTALIAS ? "Host" : type == CMNDALIAS ? "Cmnd" : | |
| type == USERALIAS ? "User" : type == RUNASALIAS ? "Runas" : | |
| "Unknown", name); | |
| } | } |
| errors++; | errors++; |
| } | } |
| Line 1294 help(void) | Line 1315 help(void) |
| (void) printf(_("%s - safely edit the sudoers file\n\n"), getprogname()); | (void) printf(_("%s - safely edit the sudoers file\n\n"), getprogname()); |
| usage(0); | usage(0); |
| (void) puts(_("\nOptions:\n" | (void) puts(_("\nOptions:\n" |
| " -c check-only mode\n" | " -c, --check check-only mode\n" |
| " -f sudoers specify sudoers file location\n" | " -f, --file=file specify sudoers file location\n" |
| " -h display help message and exit\n" | " -h, --help display help message and exit\n" |
| " -q less verbose (quiet) syntax error messages\n" | " -q, --quiet less verbose (quiet) syntax error messages\n" |
| " -s strict syntax checking\n" | " -s, --strict strict syntax checking\n" |
| " -V display version information and exit")); | " -V, --version display version information and exit")); |
| exit(0); | exit(0); |
| } | } |