[PATCH] ldap rebind sleep
Stefan Metzmacher
metze at metzemix.de
Wed Nov 12 12:21:31 GMT 2003
Stefan Metzmacher wrote:
> Andrew Bartlett wrote:
>
>> On Wed, 2003-11-12 at 11:39, Stefan Metzmacher wrote:
>>
>>
>>> Stefan Metzmacher wrote:
>>>
>>>
>>>
>>>> Stefan Metzmacher wrote:
>>>>
>>>>
>>>>
>>>>> Hi Guenther, Hi Andrew,
>>>>>
>>>>> here's the ldap rebind sleep patch
>>>>>
>>>>> gd: can you test it and report if it works ok,
>>>>> because I modified my old version a bit.
>>>>>
>>>>
>>>> Here's a new version
>>>> it now hold the timestamp of the last rebind and waits before the
>>>> next search
>>>> and compares the timestamp with the current time
>>>> and use the MIN() of the timediff and lp_ldap_rebind_sleep() as
>>>> argument of msleep()
>>>>
>>>
>>> so 3rd version...
>>> this works hopefully.
>>> the lp_ldap_rebind_sleep() is 1000 by default == 1 sec = 1000 msec
>>> == 1000000 usec
>>>
>>> gd: can you find out how long a standart replication takes, we then
>>> can use 2 * replication time for the sleep time
>>>
>>
>>
>> The main problem I see with this patch is that we need to use
>> sys_usleep() for portability, and it only allows usleep() to a value of
>> 1000000, which I think it 1 second.
>> Anyway, why not use the msleep we already use in the ldap code? It
>> isn't exactly like we need to be in any was precise about this :-)
>>
>>
> no problem
>
> then it's
>
> sleep_time = ((1000*lp_ldap_rebind_sleep())-tdiff)/1000;
> msleep(sleep_time);
>
> do we have a sys_msleep() also?
ok, here's the patch the default sleep time is 2000 msec now
--
metze
-------------------------------------------
Stefan (metze) Metzmacher <metze at metzemix.de>
-------------- next part --------------
Index: include/smbldap.h
===================================================================
RCS file: /cvsroot/samba/source/include/smbldap.h,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 smbldap.h
--- include/smbldap.h 18 Sep 2003 23:53:47 -0000 1.1.2.8
+++ include/smbldap.h 12 Nov 2003 12:13:09 -0000
@@ -137,6 +137,8 @@
time_t last_use;
smb_event_id_t event_id;
+
+ struct timeval last_rebind;
};
#endif /* HAVE_LDAP */
Index: lib/smbldap.c
===================================================================
RCS file: /cvsroot/samba/source/lib/smbldap.c,v
retrieving revision 1.1.2.18
diff -u -r1.1.2.18 smbldap.c
--- lib/smbldap.c 29 Oct 2003 21:27:59 -0000 1.1.2.18
+++ lib/smbldap.c 12 Nov 2003 12:13:11 -0000
@@ -660,6 +660,9 @@
}
*methodp = LDAP_AUTH_SIMPLE;
}
+
+ gettimeofday(&(ldap_state->last_rebind),NULL);
+
return 0;
}
#endif /*defined(LDAP_API_FEATURE_X_OPENLDAP) && (LDAP_API_VERSION > 2000)*/
@@ -685,7 +688,9 @@
username and password to? */
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)*/
@@ -908,6 +913,29 @@
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: param/loadparm.c
===================================================================
RCS file: /cvsroot/samba/source/param/loadparm.c,v
retrieving revision 1.397.2.106
diff -u -r1.397.2.106 loadparm.c
--- param/loadparm.c 6 Nov 2003 22:07:12 -0000 1.397.2.106
+++ param/loadparm.c 12 Nov 2003 12:13:21 -0000
@@ -232,7 +232,8 @@
char *szLdapFilter;
char *szLdapAdminDn;
char *szAclCompat;
- int ldap_passwd_sync;
+ int ldap_passwd_sync;
+ int ldap_rebind_sleep;
BOOL ldap_delete_dn;
BOOL bMsAddPrinterWizard;
BOOL bDNSproxy;
@@ -1074,6 +1075,7 @@
{"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},
@@ -1465,6 +1467,7 @@
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_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)
More information about the samba-technical
mailing list