]> granicus.if.org Git - sudo/commitdiff
added validate_only stuff
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 2 Jun 1994 19:41:33 +0000 (19:41 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 2 Jun 1994 19:41:33 +0000 (19:41 +0000)
parse.c
sudo.c
sudo.h

diff --git a/parse.c b/parse.c
index 127b54443c8b4bf82602bfe5a5fda59173b60ac4..c80647983343c2a0858ed6de0bdf055d232870b1 100644 (file)
--- 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 6343583cd61b33471f46096e815866b8a5bd56ac..f4c1fcf72990bcf72a9946c0649f18a83692b229 100644 (file)
--- 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 a6a01c4c9d81b16194c21e4636884c6723bec754..7dbd7e441802be376de9d8217b5c0b9d8b0da0bb 100644 (file)
--- 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;