use symbolic LDAP error codes instead of numbers
authorPeter Marschall <peter@adpm.de>
Sat, 05 Mar 2011 17:33:41 +0100
changeset 16 a2e3faa3d2fc
parent 15 f6157d378459
child 17 669085d93aa3
use symbolic LDAP error codes instead of numbers
shelldap
--- a/shelldap	Tue Sep 06 15:59:05 2011 -0700
+++ b/shelldap	Sat Mar 05 17:33:41 2011 +0100
@@ -364,7 +364,7 @@
 use Term::ReadKey;
 use Term::Shell;
 use Digest::MD5;
-use Net::LDAP;
+use Net::LDAP qw(LDAP_SUCCESS LDAP_SERVER_DOWN);
 use Net::LDAP::LDIF;
 use Data::Dumper;
 use File::Temp;
@@ -661,7 +661,7 @@
 
 	my $r = $self->search({ base => $dn });
 
-	return $r->{'code'} == 0 ? 1 : 0;
+	return $r->{'code'} == LDAP_SUCCESS ? 1 : 0;
 }
 
 # perform an ldap search
@@ -698,7 +698,7 @@
 	# check for a lost connection, kill cached object so we
 	# try to reconnect on the next search.
 	#
-	$self->{'ldap'} = undef if $s->code() == 81;
+	$self->{'ldap'} = undef if $s->code() == LDAP_SERVER_DOWN;
 
 	$rv->{'entries'} =
 	  $opts->{'scope'} eq 'base' ? [ $s->shift_entry() ] : [ $s->entries() ];
@@ -1046,7 +1046,7 @@
 	my $s_rdn = $s_dn;
 	$self->rdn_to_dn( \$s_dn );
 	my $s = $self->search({ base => $s_dn, vals => 1 });
-	unless ( $s->{'code'} == 0 ) {
+	unless ( $s->{'code'} == LDAP_SUCCESS ) {
 		print "No such object\n";
 		return;
 	}
@@ -1632,7 +1632,7 @@
 		newpasswd => $pw
 	);
 
-	if ( $rv->code() == 0 ) {
+	if ( $rv->code() == LDAP_SUCCESS ) {
 		print "Password updated successfully.\n";
 	} else {
 		print "Password error: " . $rv->error() . "\n";