unit: introduce %s specifier for the user shell
This commit is contained in:
@@ -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>
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+27
-2
@@ -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 }
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
+13
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user