summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-04-11 15:21:51 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2023-04-11 15:21:51 +0200
commitbd595c10e7fa3604a5120f9704d6571eae7640c2 (patch)
tree7bcf40fd487dce85ee3148e8c666b40f03bdc054
parent73c43e96e710d867b58db3aac8d87ea3e7a44fbb (diff)
downloadsystemd-bd595c10e7fa3604a5120f9704d6571eae7640c2.tar.gz
user-util: Add default_root_shell_at()
-rw-r--r--src/basic/user-util.c19
-rw-r--r--src/basic/user-util.h1
2 files changed, 16 insertions, 4 deletions
diff --git a/src/basic/user-util.c b/src/basic/user-util.c
index 551e98b427..cbf00a173a 100644
--- a/src/basic/user-util.c
+++ b/src/basic/user-util.c
@@ -156,21 +156,32 @@ bool is_nologin_shell(const char *shell) {
"/usr/bin/true");
}
-const char* default_root_shell(const char *root) {
+const char* default_root_shell_at(int rfd) {
/* We want to use the preferred shell, i.e. DEFAULT_USER_SHELL, which usually
* will be /bin/bash. Fall back to /bin/sh if DEFAULT_USER_SHELL is not found,
* or any access errors. */
- int r = chase(DEFAULT_USER_SHELL, root, CHASE_PREFIX_ROOT, NULL, NULL);
+ assert(rfd >= 0 || rfd == AT_FDCWD);
+
+ int r = chaseat(rfd, DEFAULT_USER_SHELL, CHASE_AT_RESOLVE_IN_ROOT, NULL, NULL);
if (r < 0 && r != -ENOENT)
- log_debug_errno(r, "Failed to look up shell '%s%s%s': %m",
- strempty(root), root ? "/" : "", DEFAULT_USER_SHELL);
+ log_debug_errno(r, "Failed to look up shell '%s': %m", DEFAULT_USER_SHELL);
if (r > 0)
return DEFAULT_USER_SHELL;
return "/bin/sh";
}
+const char *default_root_shell(const char *root) {
+ _cleanup_close_ int rfd = -EBADF;
+
+ rfd = open(empty_to_root(root), O_CLOEXEC | O_DIRECTORY | O_PATH);
+ if (rfd < 0)
+ return "/bin/sh";
+
+ return default_root_shell_at(rfd);
+}
+
static int synthesize_user_creds(
const char **username,
uid_t *uid, gid_t *gid,
diff --git a/src/basic/user-util.h b/src/basic/user-util.h
index f7ff35d0e0..5aca6307e0 100644
--- a/src/basic/user-util.h
+++ b/src/basic/user-util.h
@@ -131,6 +131,7 @@ int putsgent_sane(const struct sgrp *sg, FILE *stream);
#endif
bool is_nologin_shell(const char *shell);
+const char* default_root_shell_at(int rfd);
const char* default_root_shell(const char *root);
int is_this_me(const char *username);