- or download this
my $hostname = "ldap.example.com";
my $ldap = Net::LDAP->new($hostname)
or die "Unable to connect to LDAP server $hostname: $@\n";
- or download this
my $result = $ldap->bind();
- or download this
my $binddn = "uid=jblow, ou=People, dc=Example, dc=Com";
my $password = readpassword();
my $result = $ldap->bind(dn => $binddn, password => $password);
- 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";
}
- or download this
use Net::LDAP::Util qw(ldap_error_text);
my $result = $ldap->bind();
...
die "An error occurred binding to the LDAP server: "
.ldap_error_text($result->code)."\n";
}
- or download this
sub ldapassert {
my $mesg = shift;
...
return $mesg;
}
my $result = ldapassert($ldap->bind(), "binding to the server");
- or download this
my $searchresult = $ldap->search(base => "ou=People, dc=Example, dc=
+Com",
filter => "(objectClass=posixAccoun
+t)",
scope => "one",
attrs => ['cn', 'accountStatus'] );
- or download this
my $searchresult = do_search($ldap);
foreach my $entry ($searchresult->entries) {
print "Matched: ", $entry->dn, "\n";
}
- 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";
}
- or download this
sub changename {
my $entry = shift;
my $newname = shift;
$entry->replace(cn => $newname);
}
- 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");
}
- or download this
$_->replace(objectClass => [@{$_->get("objectClass")}, "extraClass"
+]