]> git.proxmox.com Git - pve-access-control.git/commitdiff
Auth/LDAP: refactor out 'connect_and_bind'
authorDominik Csapak <d.csapak@proxmox.com>
Fri, 6 Mar 2020 10:05:41 +0000 (11:05 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 7 Mar 2020 18:50:22 +0000 (19:50 +0100)
we will use this not only for authentication but also for
getting users/groups from LDAP

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/Auth/LDAP.pm

index 0faa40a488d2933db31b744e79412ba4c009f144..5eef12c6869c3190a4a8db0477b9a6a587c0e479 100755 (executable)
@@ -80,8 +80,8 @@ sub options {
     };
 }
 
-sub authenticate_user {
-    my ($class, $config, $realm, $username, $password) = @_;
+sub connect_and_bind {
+    my ($class, $config, $realm) = @_;
 
     my $servers = [$config->{server1}];
     push @$servers, $config->{server2} if $config->{server2};
@@ -122,6 +122,20 @@ sub authenticate_user {
     }
 
     PVE::LDAP::ldap_bind($ldap, $bind_dn, $bind_pass);
+
+    if (!$config->{base_dn}) {
+       my $root = $ldap->root_dse(attrs => [ 'defaultNamingContext' ]);
+       $config->{base_dn} = $root->get_value('defaultNamingContext');
+    }
+
+    return $ldap;
+}
+
+sub authenticate_user {
+    my ($class, $config, $realm, $username, $password) = @_;
+
+    my $ldap = $class->connect_and_bind($config, $realm);
+
     my $user_dn = PVE::LDAP::get_user_dn($ldap, $username, $config->{user_attr}, $config->{base_dn});
     PVE::LDAP::auth_user_dn($ldap, $user_dn, $password);