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

sysusers: do not implicitly create group by 'm' if 'u' with the same name exists

The commit e2c2060f7b makes 'm' lines
disturb 'u' lines.
This fixes the disturbance.
This commit is contained in:
Yu Watanabe 2018-03-02 07:38:28 +09:00
parent fb5dfbc2d8
commit d4f0412de4
4 changed files with 35 additions and 31 deletions

View File

@ -1259,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);
@ -1315,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;
}
}

View File

@ -0,0 +1,2 @@
u1:x:300:u2
u2:x:SYSTEM_UID_MAX:

View File

@ -0,0 +1,2 @@
u1:x:300:300::/:/sbin/nologin
u2:x:SYSTEM_UID_MAX:SYSTEM_UID_MAX::/:/sbin/nologin

View 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