Skip to content

Commit 4088073

Browse files
committed
openrc-user: use /bin/sh if user's login shell is not in /etc/shells
Bug: #940
1 parent bf972af commit 4088073

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/openrc-user/openrc-user.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <sys/types.h>
88
#include <sys/wait.h>
99
#include <syslog.h>
10+
#include <string.h>
1011
#include <unistd.h>
1112
#include <signal.h>
1213
#include <spawn.h>
@@ -21,6 +22,28 @@
2122
#include "rc.h"
2223
#include "rc_exec.h"
2324

25+
static bool valid_shell(const char *shell) {
26+
FILE *fp = fopen(RC_SYSCONFDIR "/shells", "r");
27+
bool ret = false;
28+
char *line = NULL;
29+
size_t size;
30+
31+
if (!fp)
32+
return true;
33+
34+
while (xgetline(&line, &size, fp) != -1) {
35+
if (line[0] == '#')
36+
continue;
37+
if (strcmp(line, shell) == 0) {
38+
ret = true;
39+
break;
40+
}
41+
}
42+
43+
free(line);
44+
return ret;
45+
}
46+
2447
static bool spawn_openrc(const struct passwd *user, bool start) {
2548
char *argv0;
2649
const char *argv[] = {
@@ -32,7 +55,7 @@ static bool spawn_openrc(const struct passwd *user, bool start) {
3255

3356
/* shell might be a multicall binary, e.g busybox.
3457
* so setting argv[0] to "-" might not work */
35-
xasprintf(&argv0, "-%s", user->pw_shell);
58+
xasprintf(&argv0, "-%s", valid_shell(user->pw_shell) ? user->pw_shell : "/bin/sh");
3659
argv[0] = argv0;
3760
args = exec_init(argv);
3861
args.cmd = user->pw_shell;

0 commit comments

Comments
 (0)