mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-31 06:15:37 +00:00
Display a more helpful message if the user tries to run "sudo cd".
Since "cd" is a shell built-in command it cannot be run directly via sudo. The user either needs to spawn a shell via "sudo -s" or use the -D option to run a command in a specific directory.
This commit is contained in:
@@ -633,6 +633,15 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[],
|
||||
audit_failure(NewArgv, N_("%s: command not found"),
|
||||
user_cmnd);
|
||||
sudo_warnx(U_("%s: command not found"), user_cmnd);
|
||||
if (strncmp(user_cmnd, "cd", 2) == 0 && (user_cmnd[2] == '\0' ||
|
||||
isblank((unsigned char)user_cmnd[2]))) {
|
||||
sudo_warnx("%s",
|
||||
U_("\"cd\" is a shell built-in command, it cannot be run directly."));
|
||||
sudo_warnx("%s",
|
||||
U_("the -s option may be used to run a privileged shell."));
|
||||
sudo_warnx("%s",
|
||||
U_("the -D option may be used to run a command in a specific directory."));
|
||||
}
|
||||
}
|
||||
goto bad;
|
||||
}
|
||||
|
Reference in New Issue
Block a user