File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed
Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -201,7 +201,7 @@ pub fn read_sysusers(rootfs: &Dir) -> Result<Vec<SysusersEntry>> {
201201}
202202
203203/// The result of analyzing /etc/{passwd,group} in a root vs systemd-sysusers.
204- #[ derive( Debug ) ]
204+ #[ derive( Debug , Default ) ]
205205pub struct SysusersAnalysis {
206206 /// Entries which are found in /etc/passwd but not present in systemd-sysusers.
207207 pub missing_users : BTreeSet < String > ,
@@ -230,8 +230,14 @@ pub fn analyze(rootfs: &Dir) -> Result<SysusersAnalysis> {
230230 id : Option < u32 > ,
231231 }
232232
233- let mut passwd = nameservice:: passwd:: load_etc_passwd ( rootfs)
233+ let Some ( passwd) = nameservice:: passwd:: load_etc_passwd ( rootfs)
234234 . map_err ( |e| Error :: PasswdLoadFailure ( e. to_string ( ) ) ) ?
235+ else {
236+ // If there's no /etc/passwd then we're done
237+ return Ok ( SysusersAnalysis :: default ( ) ) ;
238+ } ;
239+
240+ let mut passwd = passwd
235241 . into_iter ( )
236242 . map ( |mut e| {
237243 // Make the name be the map key, leaving the old value a stub
Original file line number Diff line number Diff line change 22// SPDX-License-Identifier: Apache-2.0 OR MIT
33
44use anyhow:: { anyhow, Context , Result } ;
5- use cap_std_ext:: cap_std:: fs:: Dir ;
5+ use cap_std_ext:: { cap_std:: fs:: Dir , dirext :: CapStdExtDirExt } ;
66use std:: io:: { BufRead , BufReader , Write } ;
77
88// Entry from passwd file.
@@ -78,9 +78,12 @@ pub(crate) fn parse_passwd_content(content: impl BufRead) -> Result<Vec<PasswdEn
7878 Ok ( passwds)
7979}
8080
81- pub ( crate ) fn load_etc_passwd ( rootfs : & Dir ) -> Result < Vec < PasswdEntry > > {
82- let r = rootfs. open ( "etc/passwd" ) . map ( BufReader :: new) ?;
83- parse_passwd_content ( r)
81+ pub ( crate ) fn load_etc_passwd ( rootfs : & Dir ) -> Result < Option < Vec < PasswdEntry > > > {
82+ if let Some ( r) = rootfs. open_optional ( "etc/passwd" ) ? {
83+ parse_passwd_content ( BufReader :: new ( r) ) . map ( Some )
84+ } else {
85+ Ok ( None )
86+ }
8487}
8588
8689#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments