Minor changes
This commit is contained in:
parent
09556d9154
commit
2ad9fe6f3d
1 changed files with 34 additions and 35 deletions
69
src/main.rs
69
src/main.rs
|
@ -137,7 +137,7 @@ fn setup_user(username: String, password: String) {
|
|||
let username4 = &username;
|
||||
newser(username1.to_string());
|
||||
pwd(username2.to_string(), password);
|
||||
chroot(username3.to_string());
|
||||
chown_root(username3.to_string());
|
||||
quota(username4.to_string());
|
||||
|
||||
} else {
|
||||
|
@ -151,40 +151,6 @@ fn setup_user(username: String, password: String) {
|
|||
}
|
||||
}
|
||||
|
||||
// Set disk usage limit to the user by copying another user quota
|
||||
fn quota(username: String) {
|
||||
let output = Command::new("/usr/sbin/edquota")
|
||||
.arg("-p")
|
||||
.arg("testfract")
|
||||
.arg(&username)
|
||||
.output()
|
||||
.expect("failed to execute process");
|
||||
print_output(output);
|
||||
}
|
||||
|
||||
// Chown /srv/ht/username to root:root
|
||||
fn chroot(username: String) {
|
||||
|
||||
let mut path = "/srv/ht/".to_string();
|
||||
|
||||
path += &username;
|
||||
|
||||
let output = Command::new("/usr/bin/chown")
|
||||
.arg("root:root")
|
||||
.arg(&path)
|
||||
.output()
|
||||
.expect("Failed to chown /srv/ht/<username> to root:root");
|
||||
print_output(output);
|
||||
|
||||
let output = Command::new("/usr/bin/chmod")
|
||||
.arg("755")
|
||||
.arg(path)
|
||||
.output()
|
||||
.expect("Failed to chmod /srv/ht/<username> to 755");
|
||||
print_output(output);
|
||||
|
||||
}
|
||||
|
||||
// Creates a new user in the group 'ht', which is available only over SFTP
|
||||
fn newser(username: String) {
|
||||
let output = Command::new("/usr/sbin/useradd")
|
||||
|
@ -232,6 +198,39 @@ fn pwd(username: String, password: String) {
|
|||
}
|
||||
}
|
||||
|
||||
// Chown /srv/ht/username to root:root
|
||||
fn chown_root(username: String) {
|
||||
|
||||
let mut path = "/srv/ht/".to_string();
|
||||
|
||||
path += &username;
|
||||
|
||||
let output = Command::new("/usr/bin/chown")
|
||||
.arg("root:root")
|
||||
.arg(&path)
|
||||
.output()
|
||||
.expect("Failed to chown /srv/ht/<username> to root:root");
|
||||
print_output(output);
|
||||
|
||||
let output = Command::new("/usr/bin/chmod")
|
||||
.arg("755")
|
||||
.arg(path)
|
||||
.output()
|
||||
.expect("Failed to chmod /srv/ht/<username> to 755");
|
||||
print_output(output);
|
||||
}
|
||||
|
||||
// Set disk usage limit to the user by copying another user quota
|
||||
fn quota(username: String) {
|
||||
let output = Command::new("/usr/sbin/edquota")
|
||||
.arg("-p")
|
||||
.arg("vase")
|
||||
.arg(&username)
|
||||
.output()
|
||||
.expect("failed to execute process");
|
||||
print_output(output);
|
||||
}
|
||||
|
||||
fn is_string_lowercase(stri: String) -> bool {
|
||||
|
||||
let re = Regex::new("^[[:lower:]]+$").unwrap();
|
||||
|
|
Reference in a new issue