From: Michael Vogt Date: Fri, 2 Mar 2018 11:56:44 +0000 (+0100) Subject: sysusers: support `u username -:300` style syntax (#8325) X-Git-Tag: v238~19 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1825c909ffc596af1d68a7c50e16a498a31c3f5b;p=thirdparty%2Fsystemd.git sysusers: support `u username -:300` style syntax (#8325) 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. --- diff --git a/man/sysusers.d.xml b/man/sysusers.d.xml index 47f018f4020..1c87b1bdd16 100644 --- a/man/sysusers.d.xml +++ b/man/sysusers.d.xml @@ -194,7 +194,8 @@ u root 0 "Superuser" /root /bin/zshuid:gid 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 - for the UID in this syntax + is also supported. For m lines, this field should contain diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index 629bd883f1a..cd273ef2c98 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -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 index 00000000000..f09b2b6426f --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-8.expected-group @@ -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 index 00000000000..727b8197efe --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-8.expected-passwd @@ -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 index 00000000000..b76dd3e20ce --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-8.input @@ -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 index 00000000000..33335d4eaa8 --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-9.expected-group @@ -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 index 00000000000..a23260f56e4 --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-9.expected-passwd @@ -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 index 00000000000..4d536472c28 --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-9.input @@ -0,0 +1,2 @@ +u user1 300 +u user2 -:300