This is metze's LDAP rebind sleep patch:
authorVolker Lendecke <vlendec@samba.org>
Thu, 25 Dec 2003 22:42:15 +0000 (22:42 +0000)
committerVolker Lendecke <vlendec@samba.org>
Thu, 25 Dec 2003 22:42:15 +0000 (22:42 +0000)
When smb.conf tells us to write to a read-only LDAP replica and we are
redirected by the LDAP server, the replication might take some seconds,
especially over slow links. This patch delays the next read after a rebind for
'ldap rebind sleep' milliseconds.

Metze, thanks for your patience.

Volker

source/include/smbldap.h
source/lib/smbldap.c
source/param/loadparm.c

index 17584c4fe4caa445389334d5c58b999a32488493..14ea2de012ce6d368c1ffb8ea71e4253974e0883 100644 (file)
@@ -138,6 +138,8 @@ struct smbldap_state {
 
        time_t last_use;
        smb_event_id_t event_id;
+
+       struct timeval last_rebind;
 };
 
 #endif         /* HAVE_LDAP */
index da409dce04eb776469abfc98aa3d5d9bac1ff3ad..d1117046c31bcf5a2ef6d5110806a6e4725f11a5 100644 (file)
@@ -661,6 +661,9 @@ static int rebindproc_with_state  (LDAP * ld, char **whop, char **credp,
                }
                *methodp = LDAP_AUTH_SIMPLE;
        }
+
+       gettimeofday(&(ldap_state->last_rebind),NULL);
+               
        return 0;
 }
 #endif /*defined(LDAP_API_FEATURE_X_OPENLDAP) && (LDAP_API_VERSION > 2000)*/
@@ -687,6 +690,8 @@ static int rebindproc_connect_with_state (LDAP *ldap_struct,
 
        rc = ldap_simple_bind_s(ldap_struct, ldap_state->bind_dn, ldap_state->bind_secret);
        
+       gettimeofday(&(ldap_state->last_rebind),NULL);
+
        return rc;
 }
 #endif /*defined(LDAP_API_FEATURE_X_OPENLDAP) && (LDAP_API_VERSION > 2000)*/
@@ -909,6 +914,29 @@ int smbldap_search(struct smbldap_state *ldap_state,
 
        SMB_ASSERT(ldap_state);
 
+       if (ldap_state->last_rebind.tv_sec > 0) {
+               struct timeval  tval;
+               int             tdiff = 0;
+               int             sleep_time = 0;
+
+               ZERO_STRUCT(tval);
+
+               gettimeofday(&tval,NULL);
+
+               tdiff = 1000000 *(tval.tv_sec - ldap_state->last_rebind.tv_sec) + 
+                       (tval.tv_usec - ldap_state->last_rebind.tv_usec);
+
+               sleep_time = ((1000*lp_ldap_rebind_sleep())-tdiff)/1000;
+
+               if (sleep_time > 0) {
+                       /* we wait for the LDAP replication */
+                       DEBUG(5,("smbldap_search: waiting %d milliseconds for LDAP replication.\n",sleep_time));
+                       msleep(sleep_time);
+                       DEBUG(5,("smbldap_search: go on!\n"));
+                       ZERO_STRUCT(ldap_state->last_rebind);
+               }
+       }
+
        if (push_utf8_allocate(&utf8_filter, filter) == (size_t)-1) {
                return LDAP_NO_MEMORY;
        }
index 124a905a79dbe8c898647587eae0cb570b260a6a..31348b559da2e32527726f4652f5f57980ff2da1 100644 (file)
@@ -233,6 +233,7 @@ typedef struct
        char *szLdapAdminDn;
        char *szAclCompat;
        int ldap_passwd_sync; 
+       int ldap_rebind_sleep;
        BOOL ldap_delete_dn;
        BOOL bMsAddPrinterWizard;
        BOOL bDNSproxy;
@@ -1077,6 +1078,7 @@ static struct parm_struct parm_table[] = {
        {"ldap ssl", P_ENUM, P_GLOBAL, &Globals.ldap_ssl, NULL, enum_ldap_ssl, FLAG_ADVANCED}, 
        {"ldap passwd sync", P_ENUM, P_GLOBAL, &Globals.ldap_passwd_sync, NULL, enum_ldap_passwd_sync, FLAG_ADVANCED}, 
        {"ldap delete dn", P_BOOL, P_GLOBAL, &Globals.ldap_delete_dn, NULL, NULL, FLAG_ADVANCED}, 
+       {"ldap rebind sleep", P_INTEGER, P_GLOBAL, &Globals.ldap_rebind_sleep, NULL, NULL, FLAG_ADVANCED},
 
        {N_("Miscellaneous Options"), P_SEP, P_SEPARATOR}, 
        {"add share command", P_STRING, P_GLOBAL, &Globals.szAddShareCommand, NULL, NULL, FLAG_ADVANCED}, 
@@ -1469,6 +1471,7 @@ static void init_globals(void)
        Globals.ldap_ssl = LDAP_SSL_ON;
        Globals.ldap_passwd_sync = LDAP_PASSWD_SYNC_OFF;
        Globals.ldap_delete_dn = False;
+       Globals.ldap_rebind_sleep = 1000; /* wait 1 sec for replication */
 
 /* these parameters are set to defaults that are more appropriate
    for the increasing samba install base:
@@ -1698,6 +1701,7 @@ FN_GLOBAL_STRING(lp_ldap_admin_dn, &Globals.szLdapAdminDn)
 FN_GLOBAL_INTEGER(lp_ldap_ssl, &Globals.ldap_ssl)
 FN_GLOBAL_INTEGER(lp_ldap_passwd_sync, &Globals.ldap_passwd_sync)
 FN_GLOBAL_BOOL(lp_ldap_delete_dn, &Globals.ldap_delete_dn)
+FN_GLOBAL_INTEGER(lp_ldap_rebind_sleep, &Globals.ldap_rebind_sleep)
 FN_GLOBAL_STRING(lp_add_share_cmd, &Globals.szAddShareCommand)
 FN_GLOBAL_STRING(lp_change_share_cmd, &Globals.szChangeShareCommand)
 FN_GLOBAL_STRING(lp_delete_share_cmd, &Globals.szDeleteShareCommand)