]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysusers: support `u username -:300` style syntax (#8325)
authorMichael Vogt <michael.vogt@gmail.com>
Fri, 2 Mar 2018 11:56:44 +0000 (12:56 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 2 Mar 2018 11:56:44 +0000 (12:56 +0100)
This PR implements the first part of RFE #8046. I.e. this allows to
write:
```
u username -:300
```
Where the uid is chosen automatically but the gid is fixed.

man/sysusers.d.xml
src/sysusers/sysusers.c
test/TEST-21-SYSUSERS/test-8.expected-group [new file with mode: 0644]
test/TEST-21-SYSUSERS/test-8.expected-passwd [new file with mode: 0644]
test/TEST-21-SYSUSERS/test-8.input [new file with mode: 0644]
test/TEST-21-SYSUSERS/test-9.expected-group [new file with mode: 0644]
test/TEST-21-SYSUSERS/test-9.expected-passwd [new file with mode: 0644]
test/TEST-21-SYSUSERS/test-9.input [new file with mode: 0644]

index 47f018f402053d4437a879a8bfaa3da6d0565e3f..1c87b1bdd167d888bc0f030e99f5b38c27346a48 100644 (file)
@@ -194,7 +194,8 @@ u     root     0              "Superuser"           /root          /bin/zsh</pro
       match the owners of pre-existing files (such as SUID or SGID
       binaries).
       The syntax <literal><replaceable>uid</replaceable>:<replaceable>gid</replaceable></literal> is also supported to
-      allow creating user and group pairs with different numeric UID and GID values. The group with the indicated GID must get created explicitly before or it must already exist.
+      allow creating user and group pairs with different numeric UID and GID values. The group with the indicated GID must get created explicitly before or it must already exist. Specifying <literal>-</literal> for the UID in this syntax
+      is also supported.
       </para>
 
       <para>For <varname>m</varname> lines, this field should contain
index 629bd883f1ae5ff73ee8e6c6dd48dcccb9747c31..cd273ef2c983f425ebe20af894579ad726b9f5c4 100644 (file)
@@ -1599,11 +1599,12 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
                                         i->id_set_strict = 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;
+                                if (!streq(resolved_id, "-")) {
+                                        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;
+                                }
                         }
                 }
 
diff --git a/test/TEST-21-SYSUSERS/test-8.expected-group b/test/TEST-21-SYSUSERS/test-8.expected-group
new file mode 100644 (file)
index 0000000..f09b2b6
--- /dev/null
@@ -0,0 +1 @@
+groupname:x:300:
diff --git a/test/TEST-21-SYSUSERS/test-8.expected-passwd b/test/TEST-21-SYSUSERS/test-8.expected-passwd
new file mode 100644 (file)
index 0000000..727b819
--- /dev/null
@@ -0,0 +1 @@
+username:x:SYSTEM_UID_MAX:300::/:/sbin/nologin
diff --git a/test/TEST-21-SYSUSERS/test-8.input b/test/TEST-21-SYSUSERS/test-8.input
new file mode 100644 (file)
index 0000000..b76dd3e
--- /dev/null
@@ -0,0 +1,2 @@
+g groupname 300
+u username -:300
diff --git a/test/TEST-21-SYSUSERS/test-9.expected-group b/test/TEST-21-SYSUSERS/test-9.expected-group
new file mode 100644 (file)
index 0000000..33335d4
--- /dev/null
@@ -0,0 +1 @@
+user1:x:300:
diff --git a/test/TEST-21-SYSUSERS/test-9.expected-passwd b/test/TEST-21-SYSUSERS/test-9.expected-passwd
new file mode 100644 (file)
index 0000000..a23260f
--- /dev/null
@@ -0,0 +1,2 @@
+user1:x:300:300::/:/sbin/nologin
+user2:x:SYSTEM_UID_MAX:300::/:/sbin/nologin
diff --git a/test/TEST-21-SYSUSERS/test-9.input b/test/TEST-21-SYSUSERS/test-9.input
new file mode 100644 (file)
index 0000000..4d53647
--- /dev/null
@@ -0,0 +1,2 @@
+u user1 300
+u user2 -:300