]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysusers: do not implicitly create group by 'm' if 'u' with the same name exists 8316/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 1 Mar 2018 22:38:28 +0000 (07:38 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 1 Mar 2018 22:38:28 +0000 (07:38 +0900)
The commit e2c2060f7b3b11fa3cca8899d80963b7a05cc4ab makes 'm' lines
disturb 'u' lines.
This fixes the disturbance.

src/sysusers/sysusers.c
test/TEST-21-SYSUSERS/test-10.expected-group [new file with mode: 0644]
test/TEST-21-SYSUSERS/test-10.expected-passwd [new file with mode: 0644]
test/TEST-21-SYSUSERS/test-10.input [new file with mode: 0644]

index 80a033054b8c7131fa30d11ca970fc48e69cb7a6..629bd883f1ae5ff73ee8e6c6dd48dcccb9747c31 100644 (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;
                 }
         }
 
diff --git a/test/TEST-21-SYSUSERS/test-10.expected-group b/test/TEST-21-SYSUSERS/test-10.expected-group
new file mode 100644 (file)
index 0000000..1c92158
--- /dev/null
@@ -0,0 +1,2 @@
+u1:x:300:u2
+u2:x:SYSTEM_UID_MAX:
diff --git a/test/TEST-21-SYSUSERS/test-10.expected-passwd b/test/TEST-21-SYSUSERS/test-10.expected-passwd
new file mode 100644 (file)
index 0000000..222334b
--- /dev/null
@@ -0,0 +1,2 @@
+u1:x:300:300::/:/sbin/nologin
+u2:x:SYSTEM_UID_MAX:SYSTEM_UID_MAX::/:/sbin/nologin
diff --git a/test/TEST-21-SYSUSERS/test-10.input b/test/TEST-21-SYSUSERS/test-10.input
new file mode 100644 (file)
index 0000000..8e18a00
--- /dev/null
@@ -0,0 +1,5 @@
+# check that 'm' lines do not conflicts 'u' line
+#
+#Type Name ID  GECOS HOMEDIR
+u     u1   300 -     -
+m     u2   u1