Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Using Net::LDAP to access and update LDAP directories

by araqnid (Beadle)
on Sep 13, 2000 at 01:19 UTC ( #32196=perltutorial: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download

  1. or download this
      my $hostname = "";
      my $ldap = Net::LDAP->new($hostname)
       or die "Unable to connect to LDAP server $hostname: $@\n";
  2. or download this
      my $result = $ldap->bind();
  3. or download this
      my $binddn = "uid=jblow, ou=People, dc=Example, dc=Com";
      my $password = readpassword();
      my $result = $ldap->bind(dn => $binddn, password => $password);
  4. or download this
      my $result = $ldap->bind();
      if ($result->code) { # This makes Net::LDAP get the server response
        die "An error occurred binding to the LDAP server\n";
  5. or download this
      use Net::LDAP::Util qw(ldap_error_text);
      my $result = $ldap->bind();
        die "An error occurred binding to the LDAP server: "
  6. or download this
      sub ldapassert {
        my $mesg = shift;
        return $mesg;
      my $result = ldapassert($ldap->bind(), "binding to the server");
  7. or download this
      my $searchresult = $ldap->search(base => "ou=People, dc=Example, dc=
                                       filter => "(objectClass=posixAccoun
                               scope => "one",
                                       attrs => ['cn', 'accountStatus'] );
  8. or download this
       my $searchresult = do_search($ldap);
       foreach my $entry ($searchresult->entries) {
         print "Matched: ", $entry->dn, "\n";
  9. or download this
      my $sr = ldapassert($ldap->search(base => "ou=People, $ourdn",
                                        filter => "(objectClass=person)"
       my $uid = ${$entry->get('uid')}[0];
       print "$uid: $cn\n";
  10. or download this
      sub changename {
        my $entry = shift;
        my $newname = shift;
        $entry->replace(cn => $newname);
  11. or download this
      # Add "extraClass" to everyone's "objectClass" attribute.
      my $sr = ldapassert($ldap->search(base => $ourdn, filter => "(object
    +Class=person)"), "searching the LDAP server");
       $_->add(objectClass => "extraClass");
       ldapassert($_->update($ldap), "updating the LDAP server");
  12. or download this
       $_->replace(objectClass => [@{$_->get("objectClass")}, "extraClass"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perltutorial [id://32196]
[marto]: yeah, I think that as a group creatively they're done. I can understand how it'd be hard to stop the process, album/tour, album/tour, if that's pretty much all you've ever done :)
[marto]: Corion yes I saw them Pandemonium_Tour
[Corion]: marto: Yeah, and I doubt that they'll ever get back to something like Violator/Songs of Faith and Devotion - it would either alienate their "regular" crowd, or be "too much Violator" ;)
LanX needs to see Freddy Mercury'
[Corion]: marto: Yeah, I have that on DVD even, and I missed them last year because I was in London at the time ironically ;)
[marto]: put me in the mood to listen to this now :)
[Corion]: LanX: Well, grab a shovel :)
[Corion]: Kraftwerk also are still touring (well, only Ralf Hütter and Florian Schneider), but I'm too tight fisted to spend EUR 150+ for standing around two hours ;)
[Corion]: Oh. Queen have a new front man. Not really sure...
[marto]: Florian retired some years ago. I have been gifted a ticket to their show in Glasgow as my friends husband can no longer make it

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2017-03-24 11:47 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (301 votes). Check out past polls.