Make jade automatically has the password when used

this only affects using it from the terminal
axtloss/rework-partitioning
axtloss 2 years ago
parent 0f746eb241
commit 1fce78304f

@ -68,18 +68,16 @@ jade networking getcryst.al --ipv6
### configure users ### configure users
```sh ```sh
# make a new user called nonRootHaver, without sudo and easytohack as the password # make a new user called nonRootHaver, without sudo and easytohack as the password
# jade uses prehashed passwords for user creation, so you'll have to calculate the hash of the password jade users newUser nonRootHaver easytohack
jade users newUser nonRootHaver $(openssl passwd -6 easytohack)
# make a user called rootHaver, with sudo and omgsosuperhardtohack as the password # make a user called rootHaver, with sudo and omgsosuperhardtohack as the password
jade users newUser rootHaver $(openssl passwd -6 omgsuperhardtohack) --sudoer jade users newUser rootHaver omgsuperhardtohack --sudoer
``` ```
### set root password ### set root password
```sh ```sh
# set the root password to 'muchSecurity,veryHardToHack' # set the root password to 'muchSecurity,veryHardToHack'
# the same hashing thing goes for root passwords jade users rootPass muchSecurity,veryHardToHack
jade users rootPass $(openssl passwd -6 muchSecurity,veryHardToHack)
``` ```
### install a desktop environment ### install a desktop environment

@ -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(

@ -142,6 +142,7 @@ pub fn read_config(configpath: PathBuf) {
config.users[i].name.as_str(), config.users[i].name.as_str(),
config.users[i].hasroot, config.users[i].hasroot,
config.users[i].password.as_str(), config.users[i].password.as_str(),
false,
); );
println!("---------"); println!("---------");
} }

@ -49,7 +49,7 @@ fn main() {
} }
Command::Users { subcommand } => match subcommand { Command::Users { subcommand } => match subcommand {
UsersSubcommand::NewUser(args) => { UsersSubcommand::NewUser(args) => {
users::new_user(&args.username, args.hasroot, &args.password); users::new_user(&args.username, args.hasroot, &args.password, true);
} }
UsersSubcommand::RootPass { password } => { UsersSubcommand::RootPass { password } => {
users::root_pass(&password); users::root_pass(&password);

Loading…
Cancel
Save