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

Thomas Lamprecht t.lamprecht at proxmox.com
Sat Mar 7 19:47:01 CET 2020


On 3/6/20 11:05 AM, Dominik Csapak wrote:
> 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) = @_;

call this $group_name_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)) {

what if $attr/$group_name_attr is undef? Seems that get_value may get you at least one
"Use of uninitialized value in lc" [0]

[0]: https://github.com/perl-ldap/perl-ldap/blob/master/lib/Net/LDAP/Entry.pm#L117

> +		$group->{name} = $name;
> +	    }
>  	    push @$groups, $group;
>  	}
>  
> 





More information about the pve-devel mailing list