|
|
|
@ -2,7 +2,8 @@ use crate::internal::exec::*;
|
|
|
|
|
use crate::internal::*;
|
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
|
|
pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: bool) {
|
|
|
|
|
pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: bool, shell: &str) {
|
|
|
|
|
let mut shell: &str = shell;
|
|
|
|
|
if do_hash_pass {
|
|
|
|
|
let hashed_pass = &*hash_pass(password).stdout;
|
|
|
|
|
let _password = match std::str::from_utf8(hashed_pass) {
|
|
|
|
@ -10,13 +11,66 @@ pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: boo
|
|
|
|
|
Err(e) => panic!("Failed to hash password, invalid UTF-8 sequence {}", e),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
if shell == "fish" {
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec_chroot(
|
|
|
|
|
"bash",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("pacman -S fish --noconfirm"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"installed fish",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if shell == "zsh" {
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec_chroot(
|
|
|
|
|
"bash",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("pacman -S zsh --noconfirm"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"installed zsh",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else if shell == "tcsh" || shell == "csh" {
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec_chroot(
|
|
|
|
|
"bash",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("pacman -S tcsh --noconfirm"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"installed tcsh and csh",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec_chroot(
|
|
|
|
|
"bash",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("pacman -S fish --noconfirm"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
"no shell or unknown shell specified, installed fish",
|
|
|
|
|
);
|
|
|
|
|
shell = "fish";
|
|
|
|
|
}
|
|
|
|
|
let shell_path = match shell {
|
|
|
|
|
"bash" => "/bin/bash",
|
|
|
|
|
"csh" => "/bin/csh",
|
|
|
|
|
"fish" => "/bin/fish",
|
|
|
|
|
"tcsh" => "/bin/tcsh",
|
|
|
|
|
"zsh" => "/bin/zsh",
|
|
|
|
|
&_ => "/bin/fish",
|
|
|
|
|
};
|
|
|
|
|
exec_eval(
|
|
|
|
|
exec_chroot(
|
|
|
|
|
"useradd",
|
|
|
|
|
vec![
|
|
|
|
|
String::from("-m"),
|
|
|
|
|
String::from("-s"),
|
|
|
|
|
String::from("/bin/bash"),
|
|
|
|
|
String::from(shell_path),
|
|
|
|
|
String::from("-p"),
|
|
|
|
|
String::from(password).replace('\n', ""),
|
|
|
|
|
String::from(username),
|
|
|
|
@ -49,7 +103,7 @@ pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: boo
|
|
|
|
|
|
|
|
|
|
pub fn hash_pass(password: &str) -> std::process::Output {
|
|
|
|
|
let output = Command::new("openssl")
|
|
|
|
|
.args(["passwd", "-1", password])
|
|
|
|
|
.args(["passwd", "-6", password])
|
|
|
|
|
.output()
|
|
|
|
|
.expect("Failed to hash password");
|
|
|
|
|
output
|
|
|
|
@ -67,3 +121,4 @@ pub fn root_pass(root_pass: &str) {
|
|
|
|
|
"set root password",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|