mirror of
https://git.proxmox.com/git/pve-access-control
synced 2025-10-04 08:21:57 +00:00
set/remove 'x' for tfa keys in user.cfg in new api
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
9d06f6038e
commit
c55555ab74
@ -119,6 +119,22 @@ my sub root_permission_check : prototype($$$$) {
|
||||
return wantarray ? ($userid, $realm) : $userid;
|
||||
}
|
||||
|
||||
my sub set_user_tfa_enabled : prototype($$) {
|
||||
my ($userid, $enabled) = @_;
|
||||
|
||||
PVE::AccessControl::lock_user_config(sub {
|
||||
my $user_cfg = cfs_read_file('user.cfg');
|
||||
my $user = $user_cfg->{users}->{$userid};
|
||||
my $keys = $user->{keys};
|
||||
if ($keys && $keys !~ /^x(?:!.*)?$/) {
|
||||
die "user contains tfa keys directly in user.cfg,"
|
||||
." please remove them and add them via the TFA panel instead\n";
|
||||
}
|
||||
$user->{keys} = $enabled ? 'x' : undef;
|
||||
cfs_write_file("user.cfg", $user_cfg);
|
||||
}, "enabling TFA for the user failed");
|
||||
}
|
||||
|
||||
### OLD API
|
||||
|
||||
__PACKAGE__->register_method({
|
||||
@ -291,11 +307,15 @@ __PACKAGE__->register_method ({
|
||||
my $userid =
|
||||
root_permission_check($rpcenv, $authuser, $param->{userid}, $param->{password});
|
||||
|
||||
return PVE::AccessControl::lock_tfa_config(sub {
|
||||
my $has_entries_left = PVE::AccessControl::lock_tfa_config(sub {
|
||||
my $tfa_cfg = cfs_read_file('priv/tfa.cfg');
|
||||
$tfa_cfg->api_delete_tfa($userid, $param->{id});
|
||||
my $has_entries_left = $tfa_cfg->api_delete_tfa($userid, $param->{id});
|
||||
cfs_write_file('priv/tfa.cfg', $tfa_cfg);
|
||||
return $has_entries_left;
|
||||
});
|
||||
if (!$has_entries_left) {
|
||||
set_user_tfa_enabled($userid, 0);
|
||||
}
|
||||
}});
|
||||
|
||||
__PACKAGE__->register_method ({
|
||||
@ -404,6 +424,8 @@ __PACKAGE__->register_method ({
|
||||
$value = validate_yubico_otp($userid, $realm, $value);
|
||||
}
|
||||
|
||||
set_user_tfa_enabled($userid, 1);
|
||||
|
||||
return PVE::AccessControl::lock_tfa_config(sub {
|
||||
my $tfa_cfg = cfs_read_file('priv/tfa.cfg');
|
||||
PVE::AccessControl::configure_u2f_and_wa($tfa_cfg);
|
||||
|
Loading…
Reference in New Issue
Block a user