Skip to content

Instantly share code, notes, and snippets.

@jatkins
Created January 18, 2013 18:50
Show Gist options
  • Save jatkins/4567213 to your computer and use it in GitHub Desktop.
Save jatkins/4567213 to your computer and use it in GitHub Desktop.
A quick and dirty perl script I wrote to search the LDAP system at the Wise office of NASA DEVELOP.
#!/usr/bin/perl
use Net::LDAP;
$ldap = Net::LDAP->new( 'mike.wisedevelop.org', port => 389 ) or die "$@";
$mesg = $ldap->start_tls( cafile => 'ssl/mike.cert.pem', capath => 'ssl/' );
$mesg = $ldap->bind ;
if ($ARGV[0] eq ""){
print "Ussage: search uid";
}
else {
$filter = "uid=$ARGV[0]*";
}
$mesg = $ldap->search( filter=>$filter, base=>"ou=People,dc=wisedevelop,dc=org", attrs=> ['cn', 'uid', 'uidNumber', 'gidNumber', 'shadowExpire', 'mail', 'l', 'mobile', 'loginShell', 'host']);
@entries = $mesg->entries;
if ( @entries == 0 ) {
print "There were no users found!\n";
}
else {
print "Found " . @entries . " users\n";
foreach $entry (@entries) {
print "dn: " . $entry->dn() . "\n";
@attrs = $entry->attributes();
foreach $attr (@attrs) {
printf("\t%s: %s\n", $attr, $entry->get_value($attr));
}
}
}
$mesg = $ldap->unbind;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment