1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

core: add EXEC_DIRECTORY_TYPE_SHALL_CHOWN() helper

Let's make ConfigurationDirectory= a bit less "special-casey", by hiding
the fact that it's the only per-service dir we do not do chown()ing for
inside of a new EXEC_DIRECTORY_TYPE_SHALL_CHOWN() helper.
This commit is contained in:
Lennart Poettering 2024-10-30 10:59:57 +01:00
parent ba21b29039
commit 2ef87de9d3
3 changed files with 12 additions and 5 deletions

View File

@ -2474,7 +2474,7 @@ static int setup_exec_directory(
} else {
_cleanup_free_ char *target = NULL;
if (type != EXEC_DIRECTORY_CONFIGURATION &&
if (EXEC_DIRECTORY_TYPE_SHALL_CHOWN(type) &&
readlink_and_make_absolute(p, &target) >= 0) {
_cleanup_free_ char *q = NULL, *q_resolved = NULL, *target_resolved = NULL;
@ -2526,7 +2526,7 @@ static int setup_exec_directory(
if (r != -EEXIST)
goto fail;
if (type == EXEC_DIRECTORY_CONFIGURATION) {
if (!EXEC_DIRECTORY_TYPE_SHALL_CHOWN(type)) {
struct stat st;
/* Don't change the owner/access mode of the configuration directory,
@ -3636,7 +3636,8 @@ static int compile_suggested_paths(const ExecContext *c, const ExecParameters *p
* directories. */
for (ExecDirectoryType t = 0; t < _EXEC_DIRECTORY_TYPE_MAX; t++) {
if (t == EXEC_DIRECTORY_CONFIGURATION)
if (!EXEC_DIRECTORY_TYPE_SHALL_CHOWN(t))
continue;
if (!p->prefix[t])

View File

@ -340,7 +340,7 @@ bool exec_directory_is_private(const ExecContext *context, ExecDirectoryType typ
if (!context->dynamic_user)
return false;
if (type == EXEC_DIRECTORY_CONFIGURATION)
if (!EXEC_DIRECTORY_TYPE_SHALL_CHOWN(type))
return false;
if (type == EXEC_DIRECTORY_RUNTIME && context->runtime_directory_preserve_mode == EXEC_PRESERVE_NO)
@ -1639,7 +1639,7 @@ int exec_context_get_clean_directories(
return r;
/* Also remove private directories unconditionally. */
if (t != EXEC_DIRECTORY_CONFIGURATION) {
if (EXEC_DIRECTORY_TYPE_SHALL_CHOWN(t)) {
j = path_join(prefix[t], "private", i->path);
if (!j)
return -ENOMEM;

View File

@ -152,6 +152,12 @@ typedef enum ExecDirectoryType {
_EXEC_DIRECTORY_TYPE_INVALID = -EINVAL,
} ExecDirectoryType;
static inline bool EXEC_DIRECTORY_TYPE_SHALL_CHOWN(ExecDirectoryType t) {
/* Returns true for the ExecDirectoryTypes that we shall chown()ing for the user to. We do this for
* all of them, except for configuration */
return t >= 0 && t < _EXEC_DIRECTORY_TYPE_MAX && t != EXEC_DIRECTORY_CONFIGURATION;
}
typedef struct ExecDirectoryItem {
char *path;
char **symlinks;