Skip to content

Commit

Permalink
sysusers: Parse a leading - in user
Browse files Browse the repository at this point in the history
This is used in the wild by `vboxadd` from `virtualbox-guest-additions`.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Feb 22, 2025
1 parent 552da45 commit 2b32297
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion sysusers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ impl SysusersEntry {
.or_else(|| id.map(|id| (id, id)))
.map(|(uid, gid)| (Some(uid), Some(gid)))
.unwrap_or((None, None));
let uid = uid.map(|id| id.parse()).transpose().map_err(|_| err())?;
let uid = uid
.filter(|&v| v != "-")
.map(|id| id.parse())
.transpose()
.map_err(|_| err())?;
let pgid = pgid.map(|id| id.parse()).transpose().map_err(|_| err())?;
let (gecos, s) = Self::next_token_owned(s).ok_or_else(err.clone())?;
let (home, s) = Self::next_optional_token_owned(s).unwrap_or_default();
Expand Down Expand Up @@ -388,6 +392,7 @@ mod tests {
/// Non-default sysusers found in the wild
const OTHER_SYSUSERS_REF: &str = indoc! { r#"
u qemu 107:qemu "qemu user" - -
u vboxadd -:1 - /var/run/vboxadd -
"#};

fn parse_all(s: &str) -> impl Iterator<Item = SysusersEntry> + use<'_> {
Expand Down Expand Up @@ -458,6 +463,17 @@ mod tests {
shell: None
}
);
assert_eq!(
entries.next().unwrap(),
SysusersEntry::User {
name: "vboxadd".into(),
uid: None,
pgid: Some(1.into()),
gecos: "-".into(),
home: Some("/var/run/vboxadd".into()),
shell: None
}
);
assert_eq!(entries.count(), 0);

Ok(())
Expand Down

0 comments on commit 2b32297

Please sign in to comment.