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.
This commit is contained in:
Michael Vogt 2018-03-02 12:56:44 +01:00 committed by Zbigniew Jędrzejewski-Szmek
parent 283def70cf
commit 1825c909ff
8 changed files with 17 additions and 6 deletions

View 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

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

View File

@ -0,0 +1 @@
groupname:x:300:

View File

@ -0,0 +1 @@
username:x:SYSTEM_UID_MAX:300::/:/sbin/nologin

View File

@ -0,0 +1,2 @@
g groupname 300
u username -:300

View File

@ -0,0 +1 @@
user1:x:300:

View File

@ -0,0 +1,2 @@
user1:x:300:300::/:/sbin/nologin
user2:x:SYSTEM_UID_MAX:300::/:/sbin/nologin

View File

@ -0,0 +1,2 @@
u user1 300
u user2 -:300