mirror of
https://github.com/containers/bootc.git
synced 2026-02-05 15:45:53 +01:00
sysusers: Make loading /etc/passwd optional
On general principle; this fixes a test failure in the lint unit tests which don't create /etc/passwd. But also, someone might reasonably create an image this way. Signed-off-by: Colin Walters <walters@verbum.org>
This commit is contained in:
@@ -201,7 +201,7 @@ pub fn read_sysusers(rootfs: &Dir) -> Result<Vec<SysusersEntry>> {
|
||||
}
|
||||
|
||||
/// The result of analyzing /etc/{passwd,group} in a root vs systemd-sysusers.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct SysusersAnalysis {
|
||||
/// Entries which are found in /etc/passwd but not present in systemd-sysusers.
|
||||
pub missing_users: BTreeSet<String>,
|
||||
@@ -230,8 +230,14 @@ pub fn analyze(rootfs: &Dir) -> Result<SysusersAnalysis> {
|
||||
id: Option<u32>,
|
||||
}
|
||||
|
||||
let mut passwd = nameservice::passwd::load_etc_passwd(rootfs)
|
||||
let Some(passwd) = nameservice::passwd::load_etc_passwd(rootfs)
|
||||
.map_err(|e| Error::PasswdLoadFailure(e.to_string()))?
|
||||
else {
|
||||
// If there's no /etc/passwd then we're done
|
||||
return Ok(SysusersAnalysis::default());
|
||||
};
|
||||
|
||||
let mut passwd = passwd
|
||||
.into_iter()
|
||||
.map(|mut e| {
|
||||
// Make the name be the map key, leaving the old value a stub
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use cap_std_ext::cap_std::fs::Dir;
|
||||
use cap_std_ext::{cap_std::fs::Dir, dirext::CapStdExtDirExt};
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
|
||||
// Entry from passwd file.
|
||||
@@ -78,9 +78,12 @@ pub(crate) fn parse_passwd_content(content: impl BufRead) -> Result<Vec<PasswdEn
|
||||
Ok(passwds)
|
||||
}
|
||||
|
||||
pub(crate) fn load_etc_passwd(rootfs: &Dir) -> Result<Vec<PasswdEntry>> {
|
||||
let r = rootfs.open("etc/passwd").map(BufReader::new)?;
|
||||
parse_passwd_content(r)
|
||||
pub(crate) fn load_etc_passwd(rootfs: &Dir) -> Result<Option<Vec<PasswdEntry>>> {
|
||||
if let Some(r) = rootfs.open_optional("etc/passwd")? {
|
||||
parse_passwd_content(BufReader::new(r)).map(Some)
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user