mirror of
https://github.com/systemd/systemd.git
synced 2025-02-03 17:47:28 +03:00
Merge pull request #8316 from yuwata/fix-8315
sysusers: do not create duplicated groups when create users
This commit is contained in:
commit
47920c4a26
@ -1209,12 +1209,25 @@ static int process_item(Item *i) {
|
||||
|
||||
switch (i->type) {
|
||||
|
||||
case ADD_USER:
|
||||
r = add_group(i);
|
||||
if (r < 0)
|
||||
return r;
|
||||
case ADD_USER: {
|
||||
Item *j;
|
||||
|
||||
j = ordered_hashmap_get(groups, i->name);
|
||||
if (j && j->todo_group) {
|
||||
/* When the group with the same name is already in queue,
|
||||
* use the information about the group and do not create
|
||||
* duplicated group entry. */
|
||||
i->gid_set = j->gid_set;
|
||||
i->gid = j->gid;
|
||||
i->id_set_strict = true;
|
||||
} else {
|
||||
r = add_group(i);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
return add_user(i);
|
||||
}
|
||||
|
||||
case ADD_GROUP:
|
||||
return add_group(i);
|
||||
@ -1246,40 +1259,11 @@ static int add_implicit(void) {
|
||||
int r;
|
||||
|
||||
/* Implicitly create additional users and groups, if they were listed in "m" lines */
|
||||
|
||||
ORDERED_HASHMAP_FOREACH_KEY(l, g, members, iterator) {
|
||||
Item *i;
|
||||
char **m;
|
||||
|
||||
i = ordered_hashmap_get(groups, g);
|
||||
if (!i) {
|
||||
_cleanup_(item_freep) Item *j = NULL;
|
||||
|
||||
r = ordered_hashmap_ensure_allocated(&groups, &string_hash_ops);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
j = new0(Item, 1);
|
||||
if (!j)
|
||||
return log_oom();
|
||||
|
||||
j->type = ADD_GROUP;
|
||||
j->name = strdup(g);
|
||||
if (!j->name)
|
||||
return log_oom();
|
||||
|
||||
r = ordered_hashmap_put(groups, j->name, j);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
log_debug("Adding implicit group '%s' due to m line", j->name);
|
||||
j = NULL;
|
||||
}
|
||||
|
||||
STRV_FOREACH(m, l) {
|
||||
|
||||
i = ordered_hashmap_get(users, *m);
|
||||
if (!i) {
|
||||
STRV_FOREACH(m, l)
|
||||
if (!ordered_hashmap_get(users, *m)) {
|
||||
_cleanup_(item_freep) Item *j = NULL;
|
||||
|
||||
r = ordered_hashmap_ensure_allocated(&users, &string_hash_ops);
|
||||
@ -1302,6 +1286,30 @@ static int add_implicit(void) {
|
||||
log_debug("Adding implicit user '%s' due to m line", j->name);
|
||||
j = NULL;
|
||||
}
|
||||
|
||||
if (!(ordered_hashmap_get(users, g) ||
|
||||
ordered_hashmap_get(groups, g))) {
|
||||
_cleanup_(item_freep) Item *j = NULL;
|
||||
|
||||
r = ordered_hashmap_ensure_allocated(&groups, &string_hash_ops);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
j = new0(Item, 1);
|
||||
if (!j)
|
||||
return log_oom();
|
||||
|
||||
j->type = ADD_GROUP;
|
||||
j->name = strdup(g);
|
||||
if (!j->name)
|
||||
return log_oom();
|
||||
|
||||
r = ordered_hashmap_put(groups, j->name, j);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
log_debug("Adding implicit group '%s' due to m line", j->name);
|
||||
j = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
2
test/TEST-21-SYSUSERS/test-10.expected-group
Normal file
2
test/TEST-21-SYSUSERS/test-10.expected-group
Normal file
@ -0,0 +1,2 @@
|
||||
u1:x:300:u2
|
||||
u2:x:SYSTEM_UID_MAX:
|
2
test/TEST-21-SYSUSERS/test-10.expected-passwd
Normal file
2
test/TEST-21-SYSUSERS/test-10.expected-passwd
Normal file
@ -0,0 +1,2 @@
|
||||
u1:x:300:300::/:/sbin/nologin
|
||||
u2:x:SYSTEM_UID_MAX:SYSTEM_UID_MAX::/:/sbin/nologin
|
5
test/TEST-21-SYSUSERS/test-10.input
Normal file
5
test/TEST-21-SYSUSERS/test-10.input
Normal file
@ -0,0 +1,5 @@
|
||||
# check that 'm' lines do not conflicts 'u' line
|
||||
#
|
||||
#Type Name ID GECOS HOMEDIR
|
||||
u u1 300 - -
|
||||
m u2 u1
|
16
test/TEST-21-SYSUSERS/test-7.expected-group
Normal file
16
test/TEST-21-SYSUSERS/test-7.expected-group
Normal file
@ -0,0 +1,16 @@
|
||||
sys:x:3:
|
||||
mem:x:8:
|
||||
ftp:x:11:
|
||||
mail:x:12:
|
||||
log:x:19:
|
||||
smmsp:x:25:
|
||||
proc:x:26:
|
||||
games:x:50:
|
||||
lock:x:54:
|
||||
network:x:90:
|
||||
floppy:x:94:
|
||||
scanner:x:96:
|
||||
power:x:98:
|
||||
bin:x:1:
|
||||
daemon:x:2:
|
||||
http:x:33:
|
5
test/TEST-21-SYSUSERS/test-7.expected-passwd
Normal file
5
test/TEST-21-SYSUSERS/test-7.expected-passwd
Normal file
@ -0,0 +1,5 @@
|
||||
bin:x:1:1::/:/sbin/nologin
|
||||
daemon:x:2:2::/:/sbin/nologin
|
||||
mail:x:8:12::/var/spool/mail:/sbin/nologin
|
||||
ftp:x:14:11::/srv/ftp:/sbin/nologin
|
||||
http:x:33:33::/srv/http:/sbin/nologin
|
26
test/TEST-21-SYSUSERS/test-7.input
Normal file
26
test/TEST-21-SYSUSERS/test-7.input
Normal file
@ -0,0 +1,26 @@
|
||||
# Issue #8315
|
||||
#
|
||||
#Type Name ID GECOS HOMEDIR
|
||||
|
||||
# default arch groups
|
||||
# groups first, because we have user/group id mismatch on ftp and mail
|
||||
g sys 3 - -
|
||||
g mem 8 - -
|
||||
g ftp 11 - -
|
||||
g mail 12 - -
|
||||
g log 19 - -
|
||||
g smmsp 25 - -
|
||||
g proc 26 - -
|
||||
g games 50 - -
|
||||
g lock 54 - -
|
||||
g network 90 - -
|
||||
g floppy 94 - -
|
||||
g scanner 96 - -
|
||||
g power 98 - -
|
||||
|
||||
# default arch users
|
||||
u bin 1 - -
|
||||
u daemon 2 - -
|
||||
u mail 8 - /var/spool/mail
|
||||
u ftp 14 - /srv/ftp
|
||||
u http 33 - /srv/http
|
Loading…
x
Reference in New Issue
Block a user