summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-11-12 16:37:14 +0100
committerLennart Poettering <lennart@poettering.net>2024-11-19 10:15:40 +0100
commitac8e381e262f16d77bef2bc77de1d864042dd5f4 (patch)
treed4f23b8c030e3e647388dce7b11487871395ddb7 /src/shared
parenttest: fix generate-sym-test using the wrong array (#35185) (diff)
downloadsystemd-ac8e381e262f16d77bef2bc77de1d864042dd5f4.tar.xz
systemd-ac8e381e262f16d77bef2bc77de1d864042dd5f4.zip
user-record: only synthesize default list of self-modifiable fields for *regular* users
For system users we should lock things down, hence generate an empty list. This is mostly a safety precaution, but also hides really confusing output of "userdbctl user" for an system user. Follow-up for: a192250eda1e5cc1f8fc799cf9b85d37e7fa0519
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/user-record.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/shared/user-record.c b/src/shared/user-record.c
index a63b907c74..4557718023 100644
--- a/src/shared/user-record.c
+++ b/src/shared/user-record.c
@@ -2165,8 +2165,15 @@ const char** user_record_self_modifiable_fields(UserRecord *h) {
assert(h);
+ /* Note: if the self_modifiable_fields field in UserRecord is NULL we'll apply a default, if we have
+ * one. If it is a non-NULL empty strv, we'll report it as explicit empty list. When the field is
+ * NULL and we have no default list we'll return NULL. */
+
/* Note that we intentionally distinguish between NULL and an empty array here */
- return (const char**) h->self_modifiable_fields ?: (const char**) default_fields;
+ if (h->self_modifiable_fields)
+ return (const char**) h->self_modifiable_fields;
+
+ return user_record_disposition(h) == USER_REGULAR ? (const char**) default_fields : NULL;
}
const char** user_record_self_modifiable_blobs(UserRecord *h) {
@@ -2180,7 +2187,10 @@ const char** user_record_self_modifiable_blobs(UserRecord *h) {
assert(h);
/* Note that we intentionally distinguish between NULL and an empty array here */
- return (const char**) h->self_modifiable_blobs ?: (const char**) default_blobs;
+ if (h->self_modifiable_blobs)
+ return (const char**) h->self_modifiable_blobs;
+
+ return user_record_disposition(h) == USER_REGULAR ? (const char**) default_blobs : NULL;
}
const char** user_record_self_modifiable_privileged(UserRecord *h) {
@@ -2201,7 +2211,10 @@ const char** user_record_self_modifiable_privileged(UserRecord *h) {
assert(h);
/* Note that we intentionally distinguish between NULL and an empty array here */
- return (const char**) h->self_modifiable_privileged ?: (const char**) default_fields;
+ if (h->self_modifiable_privileged)
+ return (const char**) h->self_modifiable_privileged;
+
+ return user_record_disposition(h) == USER_REGULAR ? (const char**) default_fields : NULL;
}
static int remove_self_modifiable_json_fields_common(UserRecord *current, sd_json_variant **target) {