2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-31 22:35:10 +00:00

Add cwd_optional to command details and enable it in the sudoers plugin.

If cwd_optional is set to true, a failure to set the cwd will be a
warning, not an error, and the command will still run.
Debian bug #598519
This commit is contained in:
Todd C. Miller
2020-03-31 19:43:48 -06:00
parent 9dea4bb244
commit 93aa9f9e90
7 changed files with 55 additions and 6 deletions

View File

@@ -214,12 +214,15 @@ exec_setup(struct command_details *details, int errfd)
* specifies a different cwd. Must be done after uid change.
*/
if (details->cwd != NULL) {
if (details->chroot || user_details.cwd == NULL ||
if (details->chroot != NULL || user_details.cwd == NULL ||
strcmp(details->cwd, user_details.cwd) != 0) {
/* Note: cwd is relative to the new root, if any. */
if (chdir(details->cwd) != 0) {
if (chdir(details->cwd) == -1) {
sudo_warn(U_("unable to change directory to %s"), details->cwd);
goto done;
if (!details->cwd_optional)
goto done;
if (details->chroot != NULL)
sudo_warnx(U_("starting from %s"), "/");
}
}
}