From 03cae0ca37b520247dbeadaab5e01e8f41034ed7 Mon Sep 17 00:00:00 2001 From: MggMuggins Date: Fri, 17 Aug 2018 17:26:11 -0500 Subject: [PATCH] Implement shadowfile --- src/lib.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index bda37cea54..1e512e22dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -151,6 +151,7 @@ pub fn install, S: AsRef>(config: Config, output_dir: P, coo } let mut passwd = String::new(); + let mut shadow = String::new(); let mut next_uid = 1000; for (username, user) in config.users { @@ -197,7 +198,8 @@ pub fn install, S: AsRef>(config: Config, output_dir: P, coo let password = hash_password(&password)?; - passwd.push_str(&format!("{};{};{};{};{};file:{};file:{}\n", username, password, uid, gid, name, home, shell)); + passwd.push_str(&format!("{};{};{};{};file:{};file:{}\n", username, uid, gid, name, home, shell)); + shadow.push_str(&format!("{};{}\n", username, password)); } if !passwd.is_empty() { @@ -212,6 +214,18 @@ pub fn install, S: AsRef>(config: Config, output_dir: P, coo gid: None }.create(&output_dir)?; } + + if !shadow.is_empty() { + FileConfig { + path: "/etc/shadow".to_string(), + data: shadow, + symlink: false, + directory: false, + mode: Some(0o0600), + uid: Some(0), + gid: Some(0) + }.create(&output_dir)?; + } Ok(()) }