summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--man/systemd.unit.xml5
-rw-r--r--src/core/execute.c2
-rw-r--r--src/core/unit.c29
-rw-r--r--src/login/loginctl.c8
-rw-r--r--src/login/logind.c2
-rw-r--r--src/nspawn/nspawn.c2
-rw-r--r--src/shared/util.c14
-rw-r--r--src/shared/util.h2
-rw-r--r--src/tmpfiles/tmpfiles.c2
9 files changed, 54 insertions, 12 deletions
diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
index 3236bfa741..4a2e9c3bf9 100644
--- a/man/systemd.unit.xml
+++ b/man/systemd.unit.xml
@@ -268,6 +268,11 @@
<entry>User home directory</entry>
<entry>This is the home directory of the configured user of the unit, or (if none is set) the user running the systemd instance.</entry>
</row>
+ <row>
+ <entry><literal>%s</literal></entry>
+ <entry>User shell</entry>
+ <entry>This is the shell of the configured user of the unit, or (if none is set) the user running the systemd instance.</entry>
+ </row>
</tbody>
</tgroup>
</table>
diff --git a/src/core/execute.c b/src/core/execute.c
index c0e8f9e013..daba1a3846 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -1182,7 +1182,7 @@ int exec_spawn(ExecCommand *command,
if (context->user) {
username = context->user;
- err = get_user_creds(&username, &uid, &gid, &home);
+ err = get_user_creds(&username, &uid, &gid, &home, NULL);
if (err < 0) {
r = EXIT_USER;
goto fail_child;
diff --git a/src/core/unit.c b/src/core/unit.c
index ed519b3bd5..673af13c3e 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2232,7 +2232,7 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) {
/* fish username from passwd */
username = s->exec_context.user;
- r = get_user_creds(&username, NULL, NULL, NULL);
+ r = get_user_creds(&username, NULL, NULL, NULL, NULL);
if (r < 0)
return NULL;
@@ -2256,13 +2256,37 @@ static char *specifier_user_home(char specifier, void *data, void *userdata) {
}
username = s->exec_context.user;
- r = get_user_creds(&username, NULL, NULL, &home);
+ r = get_user_creds(&username, NULL, NULL, &home, NULL);
if (r < 0)
return NULL;
return strdup(home);
}
+static char *specifier_user_shell(char specifier, void *data, void *userdata) {
+ Service *s = userdata;
+ int r;
+ const char *username, *shell;
+
+ /* return HOME if set, otherwise from passwd */
+ if (!s->exec_context.user) {
+ char *sh;
+
+ r = get_shell(&sh);
+ if (r < 0)
+ return strdup("/bin/sh");
+
+ return sh;
+ }
+
+ username = s->exec_context.user;
+ r = get_user_creds(&username, NULL, NULL, NULL, &shell);
+ if (r < 0)
+ return strdup("/bin/sh");
+
+ return strdup(shell);
+}
+
char *unit_name_printf(Unit *u, const char* format) {
/*
@@ -2316,6 +2340,7 @@ char *unit_full_printf(Unit *u, const char *format) {
{ 't', specifier_runtime, NULL },
{ 'u', specifier_user_name, NULL },
{ 'h', specifier_user_home, NULL },
+ { 's', specifier_user_shell, NULL },
{ 0, NULL, NULL }
};
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index a838a54086..7b751e778f 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -1089,7 +1089,7 @@ static int show(DBusConnection *bus, char **args, unsigned n) {
uid_t uid;
uint32_t u;
- ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL);
+ ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
if (ret < 0) {
log_error("User %s unknown.", args[i]);
goto finish;
@@ -1320,7 +1320,7 @@ static int enable_linger(DBusConnection *bus, char **args, unsigned n) {
goto finish;
}
- ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL);
+ ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
if (ret < 0) {
log_error("Failed to resolve user %s: %s", args[i], strerror(-ret));
goto finish;
@@ -1387,7 +1387,7 @@ static int terminate_user(DBusConnection *bus, char **args, unsigned n) {
goto finish;
}
- ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL);
+ ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
if (ret < 0) {
log_error("Failed to look up user %s: %s", args[i], strerror(-ret));
goto finish;
@@ -1455,7 +1455,7 @@ static int kill_user(DBusConnection *bus, char **args, unsigned n) {
goto finish;
}
- ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL);
+ ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
if (ret < 0) {
log_error("Failed to look up user %s: %s", args[i], strerror(-ret));
goto finish;
diff --git a/src/login/logind.c b/src/login/logind.c
index 1eb745adce..0775583147 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -279,7 +279,7 @@ int manager_add_user_by_name(Manager *m, const char *name, User **_user) {
assert(m);
assert(name);
- r = get_user_creds(&name, &uid, &gid, NULL);
+ r = get_user_creds(&name, &uid, &gid, NULL, NULL);
if (r < 0)
return r;
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index ffd8fd4ef5..2879db11eb 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -1059,7 +1059,7 @@ int main(int argc, char *argv[]) {
if (arg_user) {
- if (get_user_creds((const char**)&arg_user, &uid, &gid, &home) < 0) {
+ if (get_user_creds((const char**)&arg_user, &uid, &gid, &home, NULL) < 0) {
log_error("get_user_creds() failed: %m");
goto child_fail;
}
diff --git a/src/shared/util.c b/src/shared/util.c
index a0755efb14..43ec62eac6 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4905,7 +4905,12 @@ int socket_from_display(const char *display, char **path) {
return 0;
}
-int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home) {
+int get_user_creds(
+ const char **username,
+ uid_t *uid, gid_t *gid,
+ const char **home,
+ const char **shell) {
+
struct passwd *p;
uid_t u;
@@ -4926,6 +4931,10 @@ int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **h
if (home)
*home = "/root";
+
+ if (shell)
+ *shell = "/bin/sh";
+
return 0;
}
@@ -4957,6 +4966,9 @@ int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **h
if (home)
*home = p->pw_dir;
+ if (shell)
+ *shell = p->pw_shell;
+
return 0;
}
diff --git a/src/shared/util.h b/src/shared/util.h
index d3546ba1cd..3915904442 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -441,7 +441,7 @@ int fchmod_umask(int fd, mode_t mode);
bool display_is_local(const char *display);
int socket_from_display(const char *display, char **path);
-int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home);
+int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
int get_group_creds(const char **groupname, gid_t *gid);
int in_group(const char *name);
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 3b52b9889c..7a453dcc2a 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -1076,7 +1076,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
if (user && !streq(user, "-")) {
const char *u = user;
- r = get_user_creds(&u, &i->uid, NULL, NULL);
+ r = get_user_creds(&u, &i->uid, NULL, NULL, NULL);
if (r < 0) {
log_error("[%s:%u] Unknown user '%s'.", fname, line, user);
goto finish;