From 71cba155925ba54bcef8c4b2944516eca9c83666 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 2 Jun 1994 19:41:33 +0000 Subject: [PATCH] added validate_only stuff --- parse.c | 5 ++++- sudo.c | 54 ++++++++++++++++++++++++++++++++---------------------- sudo.h | 1 + 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/parse.c b/parse.c index 127b54443..c80647983 100644 --- a/parse.c +++ b/parse.c @@ -488,7 +488,10 @@ int validate() */ switch (return_code) { case FOUND_USER: - return_code = cmnd_check(); + if (validate_only) + return_code = VALIDATE_OK; + else + return_code = cmnd_check(); delete_list(USER_LIST); delete_list(HOST_LIST); delete_list(CMND_LIST); diff --git a/sudo.c b/sudo.c index 6343583cd..f4c1fcf72 100644 --- a/sudo.c +++ b/sudo.c @@ -110,6 +110,7 @@ char host[MAXHOSTNAMELEN + 1]; char user[9]; char cwd[MAXPATHLEN + 1]; uid_t uid = -2; +int validate_only = 0; /******************************************************************** @@ -135,13 +136,16 @@ main(argc, argv) usage(); /* - * print version string and exit if we got -v + * print version string and exit if we got -V + * or set validate flag if we got -v. * when we add other options getopt(3) will be used */ if (*argv[1] == '-') - if (!strcmp(argv[1], "-v")) { + if (!strcmp(argv[1], "-V")) { (void) printf("CU Sudo version %s\n", version); exit(0); + } else if (!strcmp(argv[1], "-v")) { + validate_only = 1; } else { usage(); } @@ -168,6 +172,8 @@ main(argc, argv) case VALIDATE_OK: check_user(); log_error(ALL_SYSTEMS_GO); + if (validate_only) + exit(0); be_root(); EXEC(cmnd, &Argv[1]); perror(cmnd); /* exec failed! */ @@ -228,25 +234,6 @@ static void load_globals() exit(1); } - /* - * loading the cmnd global variable from argv[1] - */ - strncpy(path, Argv[1], MAXPATHLEN)[MAXPATHLEN] = 0; - /* become root for find_path() only */ - be_root(); - cmnd = find_path(path); /* get the absolute path */ - be_user(); - if (cmnd == NULL) { - (void) fprintf(stderr, "%s: %s: command not found\n", Argv[0], Argv[1]); - exit(1); - } - - if ((cmnd = strdup(cmnd)) == NULL) { - perror("malloc"); - (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]); - exit(1); - } - #ifdef NO_ROOT_SUDO if (uid == 0) { (void) fprintf(stderr, "You are already root, you don't need to use sudo.\n"); @@ -291,6 +278,29 @@ static void load_globals() *p = '\0'; #endif /* FQDN */ + /* + * loading the cmnd global variable from argv[1] + * unless they are just validating the time stamp + */ + if (validate_only) { + cmnd = "validate"; + } else { + strncpy(path, Argv[1], MAXPATHLEN)[MAXPATHLEN] = 0; + /* become root for find_path() only */ + be_root(); + cmnd = find_path(path); /* get the absolute path */ + be_user(); + if (cmnd == NULL) { + (void) fprintf(stderr, "%s: %s: command not found\n", Argv[0], Argv[1]); + exit(1); + } + } + + if ((cmnd = strdup(cmnd)) == NULL) { + perror("malloc"); + (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]); + exit(1); + } } @@ -304,7 +314,7 @@ static void load_globals() static void usage() { - (void) fprintf(stderr, "usage: %s [-v] [command]\n", *Argv); + (void) fprintf(stderr, "usage: %s [-V] [command]\n", *Argv); exit(1); } diff --git a/sudo.h b/sudo.h index a6a01c4c9..7dbd7e441 100644 --- a/sudo.h +++ b/sudo.h @@ -345,6 +345,7 @@ extern char cwd[]; extern char *cmnd; extern int Argc; extern char **Argv; +extern int validate_only; #endif extern int errno; extern char ** environ; -- 2.40.0