#!/usr/bin/perl -w # #Author: Aaron Burgemeister (ab@novell.com) #Version: 0.1.20090227140000Z #License: GPL v3 http://www.gnu.org/licenses/gpl.html #Description: A little script to attempt an LDAP bind and return the result as #quickly as possible. use Net::LDAP; use Term::ReadKey; #Check for variables. if(scalar(@ARGV) < 2){usage();} else { $bindServer = shift(@ARGV); $bindDN = shift(@ARGV); } #Get the password one way or another. if(scalar(@ARGV) == 0) { print 'Please enter a password: '; ReadMode('noecho'); $bindPassword = ; print "\n"; ReadMode(0); } else { $bindPassword = shift(@ARGV); } chomp($bindPassword); #Bind to the server. my($ldap) = Net::LDAP->new($bindServer) or die "Can't bind to ldap: $!\n"; $mesg = $ldap->bind( dn => $bindDN, password => $bindPassword ); #Print the result. I need to find a way to change the return of the entire #script based on this result, but I'm not sure how consistent 'Success' #is, especially with l10n/i18n/g11n concerns. print $mesg->error . "\n"; $ldap->unbind; #Subroutine to print script usage to the screen. sub usage { print "\n" . 'Please provide a server, DN and password as arguments.'; print "\n" . 'Example: ./ldapbind.pl my.ldap.server.tld cn=admin,dc=user,dc=system passwordHere' . "\n\n"; exit 1; }