error detection of LDAP server.

kawasa_r at itg.hitachi.co.jp kawasa_r at itg.hitachi.co.jp
Fri May 7 14:34:26 GMT 2004


When LDAP server or domain controller does not work correctly, winbind daemon 
takes a lot of time to detect it. 
We added a timeout threshold to resolve this.


Index: samba-302/source/lib/smbldap.c
===================================================================
RCS file: /cvs/samba-302/source/lib/smbldap.c,v
retrieving revision 1.2
retrieving revision 1.4
diff -u -r1.2 -r1.4
--- samba-302/source/lib/smbldap.c	4 Mar 2004 04:43:05 -0000	1.2
+++ samba-302/source/lib/smbldap.c	30 Mar 2004 12:19:07 -0000	1.4
@@ -525,6 +525,7 @@
 	int version;
 	BOOL ldap_v3 = False;
 	LDAP **ldap_struct = &ldap_state->ldap_struct;
+	int network_timeout = 60;
 
 #ifdef HAVE_LDAP_INITIALIZE
 	DEBUG(10, ("smbldap_open_connection: %s\n", ldap_state->uri));
@@ -602,6 +603,11 @@
 		}
 	}
 
+	/* SET NETWORK TIMEOUT */
+	if (ldap_set_option (*ldap_struct, LDAP_OPT_NETWORK_TIMEOUT, &network_timeout) != LDAP_OPT_SUCCESS ) {
+		DEBUG(0,("Failed to setup network timeout\n"));
+	}
+
 	if (lp_ldap_ssl() == LDAP_SSL_START_TLS) {
 #ifdef LDAP_OPT_X_TLS
 		if (ldap_v3) {
@@ -920,6 +926,7 @@
 	int 		rc = LDAP_SERVER_DOWN;
 	int 		attempts = 0;
 	char           *utf8_filter;
+	struct timeval timeout;
 
 	SMB_ASSERT(ldap_state);
 	
@@ -953,17 +960,24 @@
 		return LDAP_NO_MEMORY;
 	}
 
+	ZERO_STRUCT(timeout);
+	timeout.tv_sec = 60;
 	while ((rc == LDAP_SERVER_DOWN) && (attempts < SMBLDAP_NUM_RETRIES)) {
 		
 		if ((rc = smbldap_retry_open(ldap_state,&attempts)) != LDAP_SUCCESS)
 			continue;
 		
-		rc = ldap_search_s(ldap_state->ldap_struct, base, scope, 
-				   utf8_filter, attrs, attrsonly, res);
+		rc = ldap_search_st(ldap_state->ldap_struct, base, scope, 
+				   utf8_filter, attrs, attrsonly, &timeout, res);
 	}
 	
 	if (rc == LDAP_SERVER_DOWN) {
 		DEBUG(0,("%s: LDAP server is down!\n",FUNCTION_MACRO));
+		smbldap_close(ldap_state);	
+	} else if (rc == LDAP_TIMEOUT) {
+		DEBUG(0,("%s: LDAP TIMEOUT!\n",FUNCTION_MACRO));
+		ldap_server_down = True;
+		ldap_server_down_time = time(NULL);
 		smbldap_close(ldap_state);	
 	}
 
Index: samba-302/source/libads/ldap.c
===================================================================
RCS file: /cvs/samba-302/source/libads/ldap.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- samba-302/source/libads/ldap.c	16 Feb 2004 01:13:35 -0000	1.1
+++ samba-302/source/libads/ldap.c	17 Mar 2004 06:32:03 -0000	1.2
@@ -370,6 +370,7 @@
 	BerElement *cookie_be = NULL;
 	struct berval *cookie_bv= NULL;
 	TALLOC_CTX *ctx;
+	struct timeval timeout;
 
 	*res = NULL;
 
@@ -440,9 +441,11 @@
 	*/
 	ldap_set_option(ads->ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
 
+	ZERO_STRUCT(timeout);
+	timeout.tv_sec = 60;
 	rc = ldap_search_ext_s(ads->ld, utf8_path, scope, utf8_expr, 
 			       search_attrs, 0, controls,
-			       NULL, NULL, LDAP_NO_LIMIT, (LDAPMessage **)res);
+			       NULL, &timeout, LDAP_NO_LIMIT, (LDAPMessage **)res);
 
 	ber_free(cookie_be, 1);
 	ber_bvfree(cookie_bv);


More information about the samba-technical mailing list