]> git.proxmox.com Git - pve-access-control.git/commitdiff
api/users: catch existing user also on case insensitive realm
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 29 Sep 2020 05:09:51 +0000 (07:09 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 29 Sep 2020 06:51:36 +0000 (08:51 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/User.pm
PVE/AccessControl.pm

index f282a1c1793d4a6a30466ec9be81b9f5a2592a17..05de57f37d4155078b30cfd646bb7457732a5940 100644 (file)
@@ -234,8 +234,9 @@ __PACKAGE__->register_method ({
 
            my $usercfg = cfs_read_file("user.cfg");
 
-           die "user '$username' already exists\n"
-               if $usercfg->{users}->{$username};
+           # ensure "user exists" check works for case insensitive realms
+           $username = PVE::AccessControl::lookup_username($username, 1);
+           die "user '$username' already exists\n" if $usercfg->{users}->{$username};
 
            PVE::AccessControl::domain_set_password($realm, $ruid, $param->{password})
                if defined($param->{password});
index d3bc6ea78120390f02438565c0530985bbbf4c53..8b5be1e03c570eab4c381c75ccac3111ba19ffdd 100644 (file)
@@ -892,7 +892,7 @@ sub add_role_privs {
 }
 
 sub lookup_username {
-    my ($username) = @_;
+    my ($username, $noerr) = @_;
 
     $username =~ m!^(${PVE::Auth::Plugin::user_regex})\@(${PVE::Auth::Plugin::realm_regex})$!;
 
@@ -905,7 +905,7 @@ sub lookup_username {
        my @matches = grep { lc $username eq lc $_ } (keys %{$usercfg->{users}});
 
        die "ambiguous case insensitive match of username '$username', cannot safely grant access!\n"
-           if scalar @matches > 1;
+           if scalar @matches > 1 && !$noerr;
 
        return $matches[0]
     }