From 0a8586928676319e9abf91b03ed6ac84d30f34e1 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 10 Sep 2023 16:44:24 -0600 Subject: [PATCH] testsudoers: add -S option to specify /etc/shells path. --- plugins/sudoers/testsudoers.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/sudoers/testsudoers.c b/plugins/sudoers/testsudoers.c index 4a8d4ee09..622bc2c78 100644 --- a/plugins/sudoers/testsudoers.c +++ b/plugins/sudoers/testsudoers.c @@ -95,7 +95,7 @@ main(int argc, char *argv[]) struct sudo_nss_list snl = TAILQ_HEAD_INITIALIZER(snl); enum sudoers_formats input_format = format_sudoers; struct sudo_nss testsudoers_nss; - char *p, *grfile, *pwfile; + char *p, *grfile, *pwfile, *shells; const char *host = NULL; const char *errstr; int ch, dflag, exitcode = EXIT_FAILURE; @@ -130,9 +130,9 @@ main(int argc, char *argv[]) goto done; dflag = 0; - grfile = pwfile = NULL; + grfile = pwfile = shells = NULL; test_ctx.mode = MODE_RUN; - while ((ch = getopt(argc, argv, "+D:dg:G:h:i:L:lP:p:R:T:tu:U:v")) != -1) { + while ((ch = getopt(argc, argv, "+D:dg:G:h:i:L:lP:p:R:S:T:tu:U:v")) != -1) { switch (ch) { case 'D': test_ctx.runas.cwd = optarg; @@ -186,6 +186,9 @@ main(int argc, char *argv[]) case 'P': grfile = optarg; break; + case 'S': + shells = optarg; + break; case 'T': now = parse_gentime(optarg); if (now == -1) @@ -225,12 +228,14 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (grfile != NULL || pwfile != NULL) { - /* Set group/passwd file and init the cache. */ + if (grfile != NULL || pwfile != NULL || shells != NULL) { + /* Set group/passwd/shells file and init the cache. */ if (grfile) testsudoers_setgrfile(grfile); if (pwfile) testsudoers_setpwfile(pwfile); + if (shells) + testsudoers_setshellfile(shells); /* Use custom passwd/group backend. */ sudo_pwutil_set_backend(testsudoers_make_pwitem, @@ -772,6 +777,6 @@ testsudoers_error(const char *restrict buf) sudo_noreturn static void usage(void) { - (void) fprintf(stderr, "usage: %s [-dltv] [-G sudoers_gid] [-g group] [-h host] [-i input_format] [-L list_user] [-P grfile] [-p pwfile] [-U sudoers_uid] [-u user] [args]\n", getprogname()); + (void) fprintf(stderr, "usage: %s [-dltv] [-G sudoers_gid] [-g group] [-h host] [-i input_format] [-L list_user] [-P grfile] [-p pwfile] [-S shells] [-U sudoers_uid] [-u user] [args]\n", getprogname()); exit(EXIT_FAILURE); }