|
|
@ -1,7 +1,15 @@
|
|
|
|
use crate::internal::exec::*;
|
|
|
|
use crate::internal::exec::*;
|
|
|
|
use crate::internal::*;
|
|
|
|
use crate::internal::*;
|
|
|
|
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
|
|
|
|
pub fn new_user(username: &str, hasroot: bool, password: &str) {
|
|
|
|
pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: bool) {
|
|
|
|
|
|
|
|
if do_hash_pass {
|
|
|
|
|
|
|
|
let hashed_pass = &*hash_pass(password).stdout;
|
|
|
|
|
|
|
|
let password = match std::str::from_utf8(hashed_pass) {
|
|
|
|
|
|
|
|
Ok(v) => v,
|
|
|
|
|
|
|
|
Err(e) => panic!("Failed to hash password, invalid UTF-8 sequence {}", e),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
exec_eval(
|
|
|
|
exec_eval(
|
|
|
|
exec_chroot(
|
|
|
|
exec_chroot(
|
|
|
|
"useradd",
|
|
|
|
"useradd",
|
|
|
@ -10,7 +18,7 @@ pub fn new_user(username: &str, hasroot: bool, password: &str) {
|
|
|
|
String::from("-s"),
|
|
|
|
String::from("-s"),
|
|
|
|
String::from("/bin/bash"),
|
|
|
|
String::from("/bin/bash"),
|
|
|
|
String::from("-p"),
|
|
|
|
String::from("-p"),
|
|
|
|
String::from(password),
|
|
|
|
String::from(password).replace("\n", ""),
|
|
|
|
String::from(username),
|
|
|
|
String::from(username),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
@ -39,6 +47,19 @@ pub fn new_user(username: &str, hasroot: bool, password: &str) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn hash_pass(password: &str) -> std::process::Output {
|
|
|
|
|
|
|
|
let output = Command::new("openssl")
|
|
|
|
|
|
|
|
.args([
|
|
|
|
|
|
|
|
"passwd",
|
|
|
|
|
|
|
|
"-1",
|
|
|
|
|
|
|
|
password
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
.output()
|
|
|
|
|
|
|
|
.expect("Failed to hash password");
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn root_pass(root_pass: &str) {
|
|
|
|
pub fn root_pass(root_pass: &str) {
|
|
|
|
exec_eval(
|
|
|
|
exec_eval(
|
|
|
|
exec_chroot(
|
|
|
|
exec_chroot(
|
|
|
|