firstboot: Check if the given shell exists

This commit is contained in:
Daan De Meyer 2020-07-26 14:38:27 +01:00 committed by Lennart Poettering
parent 97efde65d8
commit 31363bd564
1 changed files with 23 additions and 6 deletions

View File

@ -604,6 +604,24 @@ static int prompt_root_password(void) {
return 0; return 0;
} }
static int find_shell(const char *path, const char *root) {
int r;
assert(path);
if (!valid_shell(path))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "%s is not a valid shell", path);
r = chase_symlinks(path, root, CHASE_PREFIX_ROOT, NULL, NULL);
if (r < 0) {
const char *p;
p = prefix_roota(root, path);
return log_error_errno(r, "Failed to resolve shell %s: %m", p);
}
return 0;
}
static int prompt_root_shell(void) { static int prompt_root_shell(void) {
int r; int r;
@ -625,10 +643,9 @@ static int prompt_root_shell(void) {
break; break;
} }
if (!valid_shell(s)) { r = find_shell(s, arg_root);
log_error("Specified shell invalid."); if (r < 0)
continue; continue;
}
arg_root_shell = TAKE_PTR(s); arg_root_shell = TAKE_PTR(s);
break; break;
@ -1167,9 +1184,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_ROOT_SHELL: case ARG_ROOT_SHELL:
if (!valid_shell(optarg)) r = find_shell(optarg, arg_root);
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), if (r < 0)
"%s is not a valid shell path", optarg); return r;
r = free_and_strdup(&arg_root_shell, optarg); r = free_and_strdup(&arg_root_shell, optarg);
if (r < 0) if (r < 0)