shelldap
changeset 43 b8836c9018fb
parent 42 b8c6d4e8f828
child 44 4e77e8e5d467
--- a/shelldap	Tue Nov 27 11:32:41 2012 -0800
+++ b/shelldap	Tue Jan 08 11:27:59 2013 -0800
@@ -681,20 +681,30 @@
 		attrs	  => $opts->{'attrs'} || ['*']
 	);
 
+	# since search is used just about everywhere, this seems like
+	# a pretty good place to check for connection errors and try
+	# to re-establish a connection.
+	#
+	if ( $s->code() != 0 ) {
+		$self->debug( "Error ". $s->code() . ", retrying.\n" );
+		$self->{'ldap'} = undef;
+
+		$s = $self->ldap->search(
+			base	  => $opts->{'base'},
+			filter	  => $opts->{'filter'},
+			scope	  => $opts->{'scope'},
+			timelimit => $conf->{'timeout'},
+			typesonly => ! $opts->{'vals'},
+			attrs	  => $opts->{'attrs'} || ['*']
+		);
+	}
+
 	my $rv = {
 		code	  => $s->code(),
 		message   => $s->error(),
 		entries   => []
 	};
 
-	# since search is used just about everywhere, this seems like 
-	# a pretty good place to check for connection errors.
-	#
-	# check for a lost connection, kill cached object so we
-	# try to reconnect on the next search.
-	#
-	$self->{'ldap'} = undef if $s->code() == LDAP_SERVER_DOWN;
-
 	$rv->{'entries'} =
 	  $opts->{'scope'} eq 'base' ? [ $s->shift_entry() ] : [ $s->entries() ];