Skip to content
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

Open
Tachi107 opened this issue Sep 15, 2024 · 5 comments
Open

Throws errors with minimal sysusers.d file #6

Tachi107 opened this issue Sep 15, 2024 · 5 comments
Assignees

Comments

@Tachi107
Copy link
Contributor

When reading a file like:

u test-user

opensysusers fails with:

groupadd: invalid group ID ''
useradd: invalid user ID ''

While systemd-sysusers parses the file just fine

@cromerc
Copy link
Owner

cromerc commented Sep 16, 2024

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.

@cromerc cromerc self-assigned this Sep 16, 2024
@Tachi107
Copy link
Contributor Author

Tachi107 commented Sep 16, 2024 via email

@cromerc
Copy link
Owner

cromerc commented Sep 16, 2024

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.

@Tachi107
Copy link
Contributor Author

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}"

@cromerc
Copy link
Owner

cromerc commented Sep 20, 2024

That looks like it would work just fine to set the default to dash if not present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants