Skip to content
Snippets Groups Projects
Commit 1359501d authored by SamwiseFilmore's avatar SamwiseFilmore
Browse files

Use shadowfile for user creation

parent 999db45b
No related branches found
No related tags found
1 merge request!7Use shadowfile for user creation
...@@ -163,6 +163,7 @@ pub fn install<P: AsRef<Path>, S: AsRef<str>>(config: Config, output: P, cookboo ...@@ -163,6 +163,7 @@ pub fn install<P: AsRef<Path>, S: AsRef<str>>(config: Config, output: P, cookboo
} }
let mut passwd = String::new(); let mut passwd = String::new();
let mut shadow = String::new();
let mut next_uid = 1000; let mut next_uid = 1000;
for (username, user) in config.users { for (username, user) in config.users {
let password = if let Some(password) = user.password { let password = if let Some(password) = user.password {
...@@ -195,11 +196,17 @@ pub fn install<P: AsRef<Path>, S: AsRef<str>>(config: Config, output: P, cookboo ...@@ -195,11 +196,17 @@ pub fn install<P: AsRef<Path>, S: AsRef<str>>(config: Config, output: P, cookboo
dir!(home.trim_matches('/')); dir!(home.trim_matches('/'));
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() {
if !passwd.is_empty() {
file!("etc/passwd", passwd.as_bytes(), false); file!("etc/passwd", passwd.as_bytes(), false);
} }
if !shadow.is_empty() {
file!("etc/shadow", shadow.as_bytes(), false);
}
Ok(()) Ok(())
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment