r15558: Do not wait endless for a CLDAP reply when the LDAP server is
authorGünther Deschner <gd@samba.org>
Fri, 12 May 2006 23:20:39 +0000 (23:20 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:16:59 +0000 (11:16 -0500)
unavailable; use "ldap timeout" handling.

Jerry, please check.

Guenther
(This used to be commit 821bbb4566c4b3f9798054ed3bf772db0c9ae3f2)

source3/libads/cldap.c

index 6a62f573c93941d4a08b9b6c1c73a02dd9afe700..775d43dc3f2188026d24fd57b44d367a5aee3ab7 100644 (file)
@@ -165,7 +165,17 @@ static int send_cldap_netlogon(int sock, const char *domain,
        return 0;
 }
 
-
+static SIG_ATOMIC_T gotalarm;
+                                                                                                                   
+/***************************************************************
+ Signal function to tell us we timed out.
+****************************************************************/
+                                                                                                                   
+static void gotalarm_sig(void)
+{
+       gotalarm = 1;
+}
+                                                                                                                   
 /*
   receive a cldap netlogon reply
 */
@@ -180,8 +190,18 @@ static int recv_cldap_netlogon(int sock, struct cldap_netlogon_reply *reply)
 
        blob = data_blob(NULL, 8192);
 
+       /* Setup timeout */
+       gotalarm = 0;
+       CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
+       alarm(lp_ldap_timeout());
+       /* End setup timeout. */
        ret = read(sock, blob.data, blob.length);
 
+       /* Teardown timeout. */
+       CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
+       alarm(0);
+
        if (ret <= 0) {
                d_fprintf(stderr, "no reply received to cldap netlogon\n");
                return -1;