Merge pull request #8316 from yuwata/fix-8315

sysusers: do not create duplicated groups when create users
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-03-02 11:32:25 +01:00 committed by GitHub
commit 47920c4a26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 99 additions and 35 deletions

View file

@ -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;
}
}

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

View 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:

View 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

View 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