Nevermind, list! I figured out what I was doing wrong. My code previous
code was trying to add a new dn instead of modiying an existing one. A
code sample in this presentation set me straight:

http://ldap.perl.org/perl-ldap-oscon2001.pdf

And then I realized that $group_dn wasn't being defined properly. I was
leaving off the "cn=" at the start. My code has been reduced to this,
which works:


 $mesg = $ldap->modify($group_dn,
              add => { 'memberUid' => "$username" },
    );



Prentice 


On 04/05/2012 01:55 PM, Prentice Bisbal wrote:
> Dear Net::LDAPers,
>
> I'm using Net:LDAP to add/remove user accounts from LDAP. I've created a
> subroutine that adds the user to a group after their account is already
> created. I'm trying to add an additional MemberUID attribute to an
> existing posixGroup object. Here's my subroutine:
>
> sub ldap_add_group2
> {
>     my $ldap = $_[0];
>     my $ldap_base = $_[1];
>     my $username = $_[2];
>     my $group2 = $_[3];
>     my $debug = $_[4];  
>
>     my $entry;
>     my $mesg;
>     my $code;
>     my $error;
>     my $group_dn = "$group2,ou=Group,$ldap_base";
>    
>     if ($debug) {
>     print "Adding $username to secondary group $group2 ($group_dn)\n";
>     }
>     $entry = Net::LDAP::Entry->new($dn);
>     $entry->add('memberUid' => "$username");
>     $mesg = $entry->update($ldap);
>     $code = $mesg->code();
>     if ($code == 0) {
>     if ($debug) {
>         print "$Username added to LDAP group $group2\n";
>     }
>     } else {
>     $error = $mesg->error();
>     print "$error\n";
>     print "Error: Could not add $user to secondary group $group\n";
>     exit(1);
>     }
> }
>
>   
> This code is producing this error:
>
> addRequest.addRequest.objectName is undefined at
> /usr/local/perl-5.14.2/lib/site_perl/5.14.2/Net/LDAP/Message.pm line 194.
>  at /usr/local/perl-5.14.2/lib/site_perl/5.14.2/Net/LDAP/Entry.pm line 269.
> addRequest.addRequest.objectName is undefined at
> /usr/local/perl-5.14.2/lib/site_perl/5.14.2/Net/LDAP/Message.pm line 194.
>
> I know I'm probably doing something silly wrong. Can anyone point me in
> the right direction?
>
>

Reply via email to