Commit 25e9cf6 1 parent f0e890a commit 25e9cf6 Copy full SHA for 25e9cf6
File tree 2 files changed +15
-6
lines changed
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>> {
201
201
}
202
202
203
203
/// The result of analyzing /etc/{passwd,group} in a root vs systemd-sysusers.
204
- #[ derive( Debug ) ]
204
+ #[ derive( Debug , Default ) ]
205
205
pub struct SysusersAnalysis {
206
206
/// Entries which are found in /etc/passwd but not present in systemd-sysusers.
207
207
pub missing_users : BTreeSet < String > ,
@@ -230,8 +230,14 @@ pub fn analyze(rootfs: &Dir) -> Result<SysusersAnalysis> {
230
230
id : Option < u32 > ,
231
231
}
232
232
233
- let mut passwd = nameservice:: passwd:: load_etc_passwd ( rootfs)
233
+ let Some ( passwd) = nameservice:: passwd:: load_etc_passwd ( rootfs)
234
234
. 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
235
241
. into_iter ( )
236
242
. map ( |mut e| {
237
243
// Make the name be the map key, leaving the old value a stub
Original file line number Diff line number Diff line change 2
2
// SPDX-License-Identifier: Apache-2.0 OR MIT
3
3
4
4
use anyhow:: { anyhow, Context , Result } ;
5
- use cap_std_ext:: cap_std:: fs:: Dir ;
5
+ use cap_std_ext:: { cap_std:: fs:: Dir , dirext :: CapStdExtDirExt } ;
6
6
use std:: io:: { BufRead , BufReader , Write } ;
7
7
8
8
// Entry from passwd file.
@@ -78,9 +78,12 @@ pub(crate) fn parse_passwd_content(content: impl BufRead) -> Result<Vec<PasswdEn
78
78
Ok ( passwds)
79
79
}
80
80
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
+ }
84
87
}
85
88
86
89
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments