-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throws errors with minimal sysusers.d file #6
Comments
https://www.freedesktop.org/software/systemd/man/latest/sysusers.d.html# According to the spec, that is an invalid sysuser.d file, for automatic ID it should not be left blank, it should be a dash "-". I guess the bigger question is whether I should stick to the spec... or should I mimic systemd's implementation? For clarification, when I originally wrote opensysusers, I followed faithfully the spec. Naturally this might mean that opensysusers isn't a 100% compatible drop in replacement. I am however not adverse to making it a drop in replacement since there is no other real alternative. |
The thing is, that from the spec it's not clear whether the file is invalid or not. In a lot of places, the manpage says "unset (or "-")".
For example, from the home directory field:
Only applies to lines of type u and should otherwise be left unset (or "-"). It is recommended to omit this
One might interpret this as saying that using dashes and omitting the field are equivalent.
Regardless of what systemd-sysusers does, I'd allow omitting dashes for two reasons:
1. It is a nice improvement over specifying three, (or wait, were they four?) dashes
2. Lots of trivial sysusers files already rely on this
3. It's not hard to implement. When the nth field is empty, you set all the fields from the nth to the last to their default value.
Il 16 settembre 2024 14:51:13 CEST, Chris Cromer ***@***.***> ha scritto:
…
https://www.freedesktop.org/software/systemd/man/latest/sysusers.d.html#
According to the spec, that is an invalid sysuser.d file, for automatic ID it should not be left blank, it should be a dash "-".
I guess the bigger question is whether I should stick to the spec... or should I mimic systemd's implementation?
|
Just based on point 2, I think it would be wise to go ahead and do it. Considering there are no real alternatives to the systemd implementation, having this program be a drop in replacement isn't a bad idea. |
What about this? (untested) diff --git a/sysusers b/sysusers
index 05f7a70..9a1f481 100755
--- a/sysusers
+++ b/sysusers
@@ -70,7 +70,7 @@ parse_string() {
#eval "set -- $1" # do not use eval, see CVE-2021-40084
set -- $1
- type="$1" name="$2" id="$3" gecos="$4" home="$5"
+ type="$1" name="${2:--}" id="${3:--}" gecos="${4:--}" home="${5:--}"
# and now set the GECOS field without eval
if [ "${type}" = u ]; then
@@ -93,7 +93,7 @@ parse_string() {
case "${type}" in
[gu])
case "${id}" in 65535|4294967295) warninvalid; return; esac
- [ "${home:--}" = '-' ] && home='/'
+ [ "${home}" = '-' ] && home='/'
add_group "${name}" "${id}"
if [ "${type}" = u ]; then
add_user "${name}" "${id}" "${gecos}" "${home}" |
That looks like it would work just fine to set the default to dash if not present. |
When reading a file like:
opensysusers fails with:
While systemd-sysusers parses the file just fine
The text was updated successfully, but these errors were encountered: