[pve-devel] [PATCH common 1/3] ldap: optionally save group name by attribute

Dominik Csapak d.csapak at proxmox.com
Fri Mar 6 11:05:34 CET 2020


Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PVE/LDAP.pm | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/PVE/LDAP.pm b/src/PVE/LDAP.pm
index cb88977..5bf52dd 100644
--- a/src/PVE/LDAP.pm
+++ b/src/PVE/LDAP.pm
@@ -176,7 +176,7 @@ sub query_users {
 }
 
 sub query_groups {
-    my ($ldap, $base_dn, $classes, $filter) = @_;
+    my ($ldap, $base_dn, $classes, $filter, $attr) = @_;
 
     my $tmp = "(|";
     for my $class (@$classes) {
@@ -193,12 +193,14 @@ sub query_groups {
 
     my $page = Net::LDAP::Control::Paged->new(size => 100);
 
+    my $attrs = [ 'member', 'uniqueMember' ];
+    push @$attrs, $attr if $attr;
     my @args = (
 	base     => $base_dn,
 	scope    => "subtree",
 	filter   => $filter,
 	control  => [ $page ],
-	attrs    => [ 'member', 'uniqueMember' ],
+	attrs    => $attrs,
     );
 
     my $cookie;
@@ -225,6 +227,9 @@ sub query_groups {
 		$members = [$entry->get_value('uniqueMember')];
 	    }
 	    $group->{members} = $members;
+	    if (my $name = $entry->get_value($attr)) {
+		$group->{name} = $name;
+	    }
 	    push @$groups, $group;
 	}
 
-- 
2.20.1





More information about the pve-devel mailing list