testsudoers: add -S option to specify /etc/shells path.

This commit is contained in:
Todd C. Miller
2023-09-10 16:44:24 -06:00
parent 034b2f3bdd
commit 0a85869286

View File

@@ -95,7 +95,7 @@ main(int argc, char *argv[])
struct sudo_nss_list snl = TAILQ_HEAD_INITIALIZER(snl); struct sudo_nss_list snl = TAILQ_HEAD_INITIALIZER(snl);
enum sudoers_formats input_format = format_sudoers; enum sudoers_formats input_format = format_sudoers;
struct sudo_nss testsudoers_nss; struct sudo_nss testsudoers_nss;
char *p, *grfile, *pwfile; char *p, *grfile, *pwfile, *shells;
const char *host = NULL; const char *host = NULL;
const char *errstr; const char *errstr;
int ch, dflag, exitcode = EXIT_FAILURE; int ch, dflag, exitcode = EXIT_FAILURE;
@@ -130,9 +130,9 @@ main(int argc, char *argv[])
goto done; goto done;
dflag = 0; dflag = 0;
grfile = pwfile = NULL; grfile = pwfile = shells = NULL;
test_ctx.mode = MODE_RUN; 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) { switch (ch) {
case 'D': case 'D':
test_ctx.runas.cwd = optarg; test_ctx.runas.cwd = optarg;
@@ -186,6 +186,9 @@ main(int argc, char *argv[])
case 'P': case 'P':
grfile = optarg; grfile = optarg;
break; break;
case 'S':
shells = optarg;
break;
case 'T': case 'T':
now = parse_gentime(optarg); now = parse_gentime(optarg);
if (now == -1) if (now == -1)
@@ -225,12 +228,14 @@ main(int argc, char *argv[])
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (grfile != NULL || pwfile != NULL) { if (grfile != NULL || pwfile != NULL || shells != NULL) {
/* Set group/passwd file and init the cache. */ /* Set group/passwd/shells file and init the cache. */
if (grfile) if (grfile)
testsudoers_setgrfile(grfile); testsudoers_setgrfile(grfile);
if (pwfile) if (pwfile)
testsudoers_setpwfile(pwfile); testsudoers_setpwfile(pwfile);
if (shells)
testsudoers_setshellfile(shells);
/* Use custom passwd/group backend. */ /* Use custom passwd/group backend. */
sudo_pwutil_set_backend(testsudoers_make_pwitem, sudo_pwutil_set_backend(testsudoers_make_pwitem,
@@ -772,6 +777,6 @@ testsudoers_error(const char *restrict buf)
sudo_noreturn static void sudo_noreturn static void
usage(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] <user> <command> [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] <user> <command> [args]\n", getprogname());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }