Add struct sudoers_runas_context and move runas-specific bits into it.

This commit is contained in:
Todd C. Miller
2023-08-12 14:20:30 -06:00
parent d8b28dad97
commit a321e6cedf
26 changed files with 386 additions and 356 deletions

View File

@@ -57,7 +57,7 @@ check_user_shell(const struct passwd *pw)
}
/*
* Check whether user_ctx.runchroot matches def_runchroot.
* Check whether runas_ctx.chroot matches def_runchroot.
* Returns true if matched, false if not matched and -1 on error.
*/
int
@@ -65,20 +65,20 @@ check_user_runchroot(void)
{
debug_decl(check_user_runchroot, SUDOERS_DEBUG_AUTH);
if (user_ctx.runchroot == NULL)
if (runas_ctx.chroot == NULL)
debug_return_bool(true);
sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
"def_runchroot %s, user_ctx.runchroot %s",
"def_runchroot %s, runas_ctx.chroot %s",
def_runchroot ? def_runchroot : "none",
user_ctx.runchroot ? user_ctx.runchroot : "none");
runas_ctx.chroot ? runas_ctx.chroot : "none");
/* User may only specify a root dir if runchroot is "*" */
if (def_runchroot == NULL || strcmp(def_runchroot, "*") != 0)
debug_return_bool(false);
free(def_runchroot);
if ((def_runchroot = strdup(user_ctx.runchroot)) == NULL) {
if ((def_runchroot = strdup(runas_ctx.chroot)) == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_int(-1);
}
@@ -86,7 +86,7 @@ check_user_runchroot(void)
}
/*
* Check whether user_ctx.runcwd matches def_runcwd.
* Check whether runas_ctx.cwd matches def_runcwd.
* Returns true if matched, false if not matched and -1 on error.
*/
int
@@ -94,20 +94,20 @@ check_user_runcwd(void)
{
debug_decl(check_user_runcwd, SUDOERS_DEBUG_AUTH);
if (user_ctx.runcwd == NULL)
if (runas_ctx.cwd == NULL)
debug_return_bool(true);
sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
"def_runcwd %s, user_ctx.runcwd %s",
"def_runcwd %s, runas_ctx.cwd %s",
def_runcwd ? def_runcwd : "none",
user_ctx.runcwd ? user_ctx.runcwd : "none");
runas_ctx.cwd ? runas_ctx.cwd : "none");
/* User may only specify a cwd if runcwd is "*" */
if (def_runcwd == NULL || strcmp(def_runcwd, "*") != 0)
debug_return_bool(false);
free(def_runcwd);
if ((def_runcwd = strdup(user_ctx.runcwd)) == NULL) {
if ((def_runcwd = strdup(runas_ctx.cwd)) == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_int(-1);
}