Move check_user_shell() to pwutil.c as user_shell_valid()

This will make it possible to support a different backend which may
be used by testsudoers in the future.
This commit is contained in:
Todd C. Miller
2023-09-09 14:07:28 -06:00
parent 28a13501d8
commit d18ee8e0e7
8 changed files with 41 additions and 35 deletions

View File

@@ -449,3 +449,26 @@ again:
debug_return_ptr(&grlitem->cache);
}
/*
* Returns true if the specified shell is allowed by /etc/shells, else false.
*/
bool
valid_shell(const char *shell)
{
const char *entry;
debug_decl(valid_shell, SUDOERS_DEBUG_NSS);
sudo_debug_printf(SUDO_DEBUG_INFO,
"%s: checking /etc/shells for %s", __func__, shell);
setusershell();
while ((entry = getusershell()) != NULL) {
if (strcmp(entry, shell) == 0)
debug_return_bool(true);
}
endusershell();
debug_return_bool(false);
}