]> git.proxmox.com Git - pve-access-control.git/commitdiff
fix #2947 login name for the LDAP/AD realm can be case-insensitive
authorWolfgang Link <w.link@proxmox.com>
Tue, 8 Sep 2020 12:09:45 +0000 (14:09 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 29 Sep 2020 04:14:53 +0000 (06:14 +0200)
This is an optional for LDAP and AD realm.
The default behavior is case-sensitive.

Signed-off-by: Wolfgang Link <w.link@proxmox.com>
PVE/API2/AccessControl.pm
PVE/AccessControl.pm
PVE/Auth/AD.pm
PVE/Auth/LDAP.pm

index fd27786b1f0b8b83775a1019dbed5e8d410adbea..a77694b7561d64f080db9c4c26e22d6ffd7b0f1d 100644 (file)
@@ -292,6 +292,7 @@ __PACKAGE__->register_method ({
        my $username = $param->{username};
        $username .= "\@$param->{realm}" if $param->{realm};
 
        my $username = $param->{username};
        $username .= "\@$param->{realm}" if $param->{realm};
 
+       $username = PVE::AccessControl::lookup_username($username);
        my $rpcenv = PVE::RPCEnvironment::get();
 
        my $res;
        my $rpcenv = PVE::RPCEnvironment::get();
 
        my $res;
index 6a85c1a20b21722bf6cad45a231721919d807a19..d3bc6ea78120390f02438565c0530985bbbf4c53 100644 (file)
@@ -891,6 +891,28 @@ sub add_role_privs {
     }
 }
 
     }
 }
 
+sub lookup_username {
+    my ($username) = @_;
+
+    $username =~ m!^(${PVE::Auth::Plugin::user_regex})\@(${PVE::Auth::Plugin::realm_regex})$!;
+
+    my $realm = $2;
+    my $domain_cfg = cfs_read_file("domains.cfg");
+    my $casesensitive = $domain_cfg->{ids}->{$realm}->{'case-sensitive'} // 1;
+    my $usercfg = cfs_read_file('user.cfg');
+
+    if (!$casesensitive) {
+       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;
+
+       return $matches[0]
+    }
+
+    return $username;
+}
+
 sub normalize_path {
     my $path = shift;
 
 sub normalize_path {
     my $path = shift;
 
index 4d64c2064ea39a14628f7b162f585c40fa3a62e5..88b2098355bd3d1bf9cfb32be6ea257083b891d1 100755 (executable)
@@ -94,6 +94,7 @@ sub options {
        group_classes => { optional => 1 },
        'sync-defaults-options' => { optional => 1 },
        mode => { optional => 1 },
        group_classes => { optional => 1 },
        'sync-defaults-options' => { optional => 1 },
        mode => { optional => 1 },
+       'case-sensitive' => { optional => 1 },
     };
 }
 
     };
 }
 
index 09b220201a35ef49c18c852fe2f92560b1f71ea1..97d077886cd904863b65270580da8f46fb62f376 100755 (executable)
@@ -129,6 +129,12 @@ sub properties {
            optional => 1,
            default => 'ldap',
        },
            optional => 1,
            default => 'ldap',
        },
+        'case-sensitive' => {
+           description => "username is case-sensitive",
+           type => 'boolean',
+           optional => 1,
+           default => 1,
+       }
     };
 }
 
     };
 }
 
@@ -159,6 +165,7 @@ sub options {
        group_classes => { optional => 1 },
        'sync-defaults-options' => { optional => 1 },
        mode => { optional => 1 },
        group_classes => { optional => 1 },
        'sync-defaults-options' => { optional => 1 },
        mode => { optional => 1 },
+       'case-sensitive' => { optional => 1 },
     };
 }
 
     };
 }