Skip to content

feat: restore /etc/passwd shell paths on deactivation#377

Open
jfroche wants to merge 2 commits intomainfrom
fix/uninstall-users
Open

feat: restore /etc/passwd shell paths on deactivation#377
jfroche wants to merge 2 commits intomainfrom
fix/uninstall-users

Conversation

@jfroche
Copy link
Member

@jfroche jfroche commented Feb 27, 2026

During deactivation, scan /etc/passwd for shells under /run/system-manager/sw/ and restore them to FHS paths.

Shell restoration is best-effort: errors are logged but do not prevent deactivation from completing.

This fixes #371

During deactivation, scan /etc/passwd for shells under /run/system-manager/sw/ and restore them to FHS paths.

Shell restoration is best-effort: errors are logged but do not prevent deactivation from completing.

This fixes #371
Copy link
Member

@picnoir picnoir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, but LGTM.

Feel free to ignore them and merge that as it is. It's good enough from my perspective.

}

let fields: Vec<&str> = line.split(':').collect();
if fields.len() != 7 {
Copy link
Member

@picnoir picnoir Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://man7.org/linux/man-pages/man5/passwd.5.html (man 5 passwd)

^ shadow-utils is expecting 7 fields.

We're making assumptions about these fields later on, I think it'd be safer to loudly fail if the file we're modifying is not in the format we're expecting rather than silentlly ignoring the line.

}
base
}
_ => "/bin/sh",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, we can't necessarily assume /bin/sh exists from POSIX:

Applications should note that the standard PATH to the shell cannot be assumed to be either /bin/sh or /usr/bin/sh, and should be determined by interrogation of the PATH returned by getconf PATH, ensuring that the returned pathname is an absolute pathname and not a shell built-in.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html#tag_20_117_16

I looked at it, there's sadly no function able to resolve absolute paths from $PATH in the rust standard library. We'd have to parse the PATH and have a look in each directory manually. Or use the which crate. Or shell out to which.

Sounds like a lot of efforts for a nit. Let's ignore this for now.


If we were up to go that route, we could be a bit more fancy and try to find the shell set in the system-manager config on the host system.

I'd assume people using fish or zsh on system-manager are likely to have it installed on their host system as well.

That being said, we need to manually look in PATH to find the appropriate path for these shells.

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

Successfully merging this pull request may close these issues.

Document or Guide to uninstall or deactivate system-manager cleanly

2 participants