Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## I want to be able to return a single value, from an LDAP search.
- ## I can do this with a shell script, like this :
- ## SHELL
- ldapsearch -x -b ou=people,dc=caret,dc=cam,dc=ac,dc=uk -s one uid=* | grep uidNumber | tail -n 1 | awk '{print $2}'
- ## PERL
- ## ----------------------------
- ## Start the LDAP Bind process
- if (! defined ($LDAPSERVER))
- {
- $LDAPSERVER = "ldap.dmz.caret.local";
- }
- my $CAFILE = "/etc/ldap/cacerts/ldap-clients.pem";
- print "Enter your LDAP password, now. \n";
- my $BINDPASSWD = <>;
- if (defined ($VERBOSE))
- {
- print "SERVER - $LDAPSERVER\n";
- print "PASSWORD - $BINDPASSWD\n";
- }
- my $ldaps = Net::LDAP->new(
- "ldaps://$LDAPSERVER",
- port => '636',
- onerror => 'warn',
- verify => 'none',
- cafile => $CAFILE,
- ) or die "Can't connect to ldaps://$LDAPSERVER\n";
- $ldaps->bind( "uid=$BINDUSER,ou=people,dc=caret,dc=cam,dc=ac,dc=uk", password => "$BINDPASSWD" );
- sub lastuser {
- my($lastuid);
- my $lastuser = $ldaps->search(
- base => "ou=people,$LDAPBASE",
- filter => "(uid=*)",
- attrs => ['uidNumber'],
- scope => 'one'
- );
- if (defined ($VERBOSE)) {
- foreach my $entry ($lastuser->entries) { $entry->dump; }
- }
- foreach my $entry ($lastuser->entries) {
- $lastuid = $entry->get('uidNumber');
- }
- print "LASTUID = \n";
- my $uidtopass = print Dumper($lastuid);
- return $uidtopass;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement