summaryrefslogtreecommitdiff
path: root/src/sysusers
diff options
context:
space:
mode:
authorMichael Vogt <mvo@ubuntu.com>2018-01-23 19:53:08 +0100
committerMichael Vogt <mvo@ubuntu.com>2018-01-25 12:50:37 +0100
commit4cb41413c82e81fa4f9f211b95ac5cd5c13a543b (patch)
treebed473e5387471e38525f98f192dd13d23d75e8d /src/sysusers
parent5eb83fa6453d8a328376dabc826897f212451edd (diff)
downloadsystemd-4cb41413c82e81fa4f9f211b95ac5cd5c13a543b.tar.gz
systemd-4cb41413c82e81fa4f9f211b95ac5cd5c13a543b.tar.bz2
systemd-4cb41413c82e81fa4f9f211b95ac5cd5c13a543b.zip
sysusers: allow uid:gid in sysusers.conf files
This PR allows to write sysuser.conf lines like: ``` u games 5:60 - ``` This will create an a "games" user with uid 5 and games group with gid 60. This is arguable ugly, however it is required to represent certain configurations like the default passwd file on Debian and Ubuntu. When the ":" syntax is used and there is a group with the given gid already then no new group is created. This allows writing the following: ``` g unrelated 60 u games 5:60 - ``` which will create a "games" user with the uid 5 and the primary gid 60. No group games is created here (might be useful for [1]). [1] https://pagure.io/packaging-committee/issue/442
Diffstat (limited to 'src/sysusers')
-rw-r--r--src/sysusers/sysusers.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c
index d8009458ee..1845b80d49 100644
--- a/src/sysusers/sysusers.c
+++ b/src/sysusers/sysusers.c
@@ -64,6 +64,7 @@ typedef struct Item {
uid_t uid;
bool gid_set:1;
+ bool gid_existing_ok:1;
bool uid_set:1;
bool todo_user:1;
@@ -1100,6 +1101,8 @@ static int add_group(Item *i) {
return log_error_errno(r, "Failed to verify gid " GID_FMT ": %m", i->gid);
if (r == 0) {
log_debug("Suggested group ID " GID_FMT " for %s already used.", i->gid, i->name);
+ if (i->gid_existing_ok)
+ return 0;
i->gid_set = false;
}
}
@@ -1551,11 +1554,18 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
path_kill_slashes(i->uid_path);
} else {
- r = parse_uid(resolved_id, &i->uid);
- if (r < 0) {
- log_error("Failed to parse UID: %s", id);
- return -EBADMSG;
+ _cleanup_free_ char *uid = NULL, *gid = NULL;
+ if (split_pair(resolved_id, ":", &uid, &gid) == 0) {
+ r = parse_gid(gid, &i->gid);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse GID: '%s': %m", id);
+ i->gid_set = true;
+ i->gid_existing_ok = true;
+ free_and_replace(resolved_id, uid);
}
+ r = parse_uid(resolved_id, &i->uid);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse UID: '%s': %m", id);
i->uid_set = true;
}
@@ -1602,10 +1612,8 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
path_kill_slashes(i->gid_path);
} else {
r = parse_gid(resolved_id, &i->gid);
- if (r < 0) {
- log_error("Failed to parse GID: %s", id);
- return -EBADMSG;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse GID: '%s': %m", id);
i->gid_set = true;
}