passwd: Only allow locking accounts as root
This is consistent with how Linux works and prevents accidentally locking yourself out.
This commit is contained in:
+25
-6
@@ -51,6 +51,31 @@ fn main() {
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
if args.is_present("LOCK") {
|
||||
if get_uid().unwrap_or_exit(1) != 0 {
|
||||
eprintln!("passwd: only root is allowed to lock accounts");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
let mut users =
|
||||
AllUsers::authenticator(Config::default().writeable(true)).unwrap_or_exit(1);
|
||||
|
||||
let Some(login) = args.value_of("LOGIN") else {
|
||||
eprintln!("passwd: no account specified to lock");
|
||||
exit(1);
|
||||
};
|
||||
|
||||
let user = users.get_mut_by_name(login).unwrap_or_else(|| {
|
||||
eprintln!("passwd: user does not exist: {}", login);
|
||||
exit(1);
|
||||
});
|
||||
|
||||
user.unset_passwd();
|
||||
users.save().unwrap_or_exit(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let uid = get_uid().unwrap_or_exit(1);
|
||||
let mut users = AllUsers::authenticator(Config::default().writeable(true)).unwrap_or_exit(1);
|
||||
|
||||
@@ -65,12 +90,6 @@ fn main() {
|
||||
}),
|
||||
};
|
||||
|
||||
if args.is_present("LOCK") {
|
||||
user.unset_passwd();
|
||||
users.save().unwrap_or_exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
if user.uid != uid && uid != 0 {
|
||||
eprintln!(
|
||||
"passwd: you do not have permission to set the password of '{}'",
|
||||
|
||||
Reference in New Issue
Block a user