diff options
author | Michael Vogt <michael.vogt@gmail.com> | 2018-03-02 12:56:44 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-03-02 12:56:44 +0100 |
commit | 1825c909ffc596af1d68a7c50e16a498a31c3f5b (patch) | |
tree | 0bd8c61889a397844c6e89a3716b2bd60d6f8bc3 | |
parent | 283def70cfcbc3be2490d1151a2ec7f849a528be (diff) | |
download | systemd-1825c909ffc596af1d68a7c50e16a498a31c3f5b.tar.gz |
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.
-rw-r--r-- | man/sysusers.d.xml | 3 | ||||
-rw-r--r-- | src/sysusers/sysusers.c | 11 | ||||
-rw-r--r-- | test/TEST-21-SYSUSERS/test-8.expected-group | 1 | ||||
-rw-r--r-- | test/TEST-21-SYSUSERS/test-8.expected-passwd | 1 | ||||
-rw-r--r-- | test/TEST-21-SYSUSERS/test-8.input | 2 | ||||
-rw-r--r-- | test/TEST-21-SYSUSERS/test-9.expected-group | 1 | ||||
-rw-r--r-- | test/TEST-21-SYSUSERS/test-9.expected-passwd | 2 | ||||
-rw-r--r-- | test/TEST-21-SYSUSERS/test-9.input | 2 |
8 files changed, 17 insertions, 6 deletions
diff --git a/man/sysusers.d.xml b/man/sysusers.d.xml index 47f018f402..1c87b1bdd1 100644 --- a/man/sysusers.d.xml +++ b/man/sysusers.d.xml @@ -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 diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index 629bd883f1..cd273ef2c9 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 0000000000..f09b2b6426 --- /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 0000000000..727b8197ef --- /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 0000000000..b76dd3e20c --- /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 0000000000..33335d4eaa --- /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 0000000000..a23260f56e --- /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 0000000000..4d536472c2 --- /dev/null +++ b/test/TEST-21-SYSUSERS/test-9.input @@ -0,0 +1,2 @@ +u user1 300 +u user2 -:300 |