]> granicus.if.org Git - sudo/commitdiff
Sudo should prompt for a password before telling the user that
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 7 Sep 1998 03:48:43 +0000 (03:48 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 7 Sep 1998 03:48:43 +0000 (03:48 +0000)
a command could not be found.

sudo.c

diff --git a/sudo.c b/sudo.c
index 442696afa5b02324431c5fe3876193bff75edf79..07fe56a967a21f38dba3b32fc92929bab6fb5ea1 100644 (file)
--- a/sudo.c
+++ b/sudo.c
@@ -126,7 +126,7 @@ static int  parse_args                      __P((void));
 static void usage                      __P((int));
 static void load_globals               __P((int));
 static int check_sudoers               __P((void));
-static void load_cmnd                  __P((int));
+static int load_cmnd                   __P((int));
 static void add_env                    __P((int));
 static void clean_env                  __P((char **, struct env_table *));
 extern int  user_is_exempt             __P((void));
@@ -189,7 +189,7 @@ int main(argc, argv)
     int argc;
     char **argv;
 {
-    int rtn;
+    int rtn, found_cmnd;
     int sudo_mode = MODE_RUN;
     extern char ** environ;
 
@@ -303,7 +303,7 @@ int main(argc, argv)
 #endif /* SECURE_PATH */
 
     if ((sudo_mode & MODE_RUN)) {
-       load_cmnd(sudo_mode);   /* load the cmnd global variable */
+       found_cmnd = load_cmnd(sudo_mode); /* load the cmnd global variable */
     } else if (sudo_mode == MODE_KILL) {
        remove_timestamp();     /* remove the timestamp ticket file */
        exit(0);
@@ -320,6 +320,14 @@ int main(argc, argv)
        case VALIDATE_OK_NOPASS:
            if (rtn != VALIDATE_OK_NOPASS) 
                check_user();
+
+           /* finally tell the user if the command did not exist */
+           if ((sudo_mode & MODE_RUN) && !found_cmnd) {
+               (void) fprintf(stderr, "%s: %s: command not found\n", Argv[0],
+                              cmnd);
+               exit(1);
+           }
+
            log_error(ALL_SYSTEMS_GO);
            if (sudo_mode == MODE_VALIDATE)
                exit(0);
@@ -749,9 +757,10 @@ static void add_env(contiguous)
  *  load_cmnd()
  *
  *  This function sets the cmnd global variable
+ *  Returns 1 on success, 0 on failure.
  */
 
-static void load_cmnd(sudo_mode)
+static int load_cmnd(sudo_mode)
     int sudo_mode;
 {
     if (strlen(NewArgv[0]) >= MAXPATHLEN) {
@@ -765,10 +774,10 @@ static void load_cmnd(sudo_mode)
      * Resolve the path
      */
     if ((cmnd = find_path(NewArgv[0])) == NULL) {
-       (void) fprintf(stderr, "%s: %s: command not found\n", Argv[0],
-                      NewArgv[0]);
-       exit(1);
-    }
+       cmnd = NewArgv[0];
+       return(0);
+    } else
+       return(1);
 }