Commit c531f726 authored by Jeremy Allison's avatar Jeremy Allison Committed by Gerald (Jerry) Carter
Browse files

r1325: Always use GetTimeOfDay() (wrapper). Ensure ldap replication

sleep time is not more than 5 seconds. Should fix issue
reported by Chris Garrigues <cwg@deepeddy.com>.
Jeremy.
(This used to be commit fbc06831d3a7e8645409158ee1ae1f9f192913a7)
parent 3382b0a2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -233,4 +233,6 @@
/* Number of microseconds to wait before a sharing violation. */
#define SHARING_VIOLATION_USEC_WAIT 950000

#define MAX_LDAP_REPLICATION_SLEEP_TIME 5000 /* In milliseconds. */

#endif
+11 −12
Original line number Diff line number Diff line
@@ -676,7 +676,7 @@ static int rebindproc_with_state (LDAP * ld, char **whop, char **credp,
		*methodp = LDAP_AUTH_SIMPLE;
	}

	gettimeofday(&(ldap_state->last_rebind),NULL);
	GetTimeOfDay(&ldap_state->last_rebind);
		
	return 0;
}
@@ -704,7 +704,7 @@ 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);
	GetTimeOfDay(&ldap_state->last_rebind);

	return rc;
}
@@ -755,8 +755,7 @@ static int smbldap_connect_system(struct smbldap_state *ldap_state, LDAP * ldap_
	char *ldap_secret;

	/* get the password */
	if (!fetch_ldap_pw(&ldap_dn, &ldap_secret))
	{
	if (!fetch_ldap_pw(&ldap_dn, &ldap_secret)) {
		DEBUG(0, ("ldap_connect_system: Failed to retrieve password from secrets.tdb\n"));
		return LDAP_INVALID_CREDENTIALS;
	}
@@ -854,7 +853,7 @@ static int smbldap_open(struct smbldap_state *ldap_state)


	ldap_state->last_ping = time(NULL);
	DEBUG(4,("The LDAP server is succesful connected\n"));
	DEBUG(4,("The LDAP server is succesfully connected\n"));

	return LDAP_SUCCESS;
}
@@ -933,25 +932,25 @@ int smbldap_search(struct smbldap_state *ldap_state,

	if (ldap_state->last_rebind.tv_sec > 0) {
		struct timeval	tval;
		int 		tdiff = 0;
		SMB_BIG_INT	tdiff = 0;
		int		sleep_time = 0;

		ZERO_STRUCT(tval);
		GetTimeOfDay(&tval);

		gettimeofday(&tval,NULL);

		tdiff = 1000000 *(tval.tv_sec - ldap_state->last_rebind.tv_sec) + 
			(tval.tv_usec - ldap_state->last_rebind.tv_usec);
		tdiff = usec_time_diff(&tval, &ldap_state->last_rebind.tv_sec);
		tdiff /= 1000; /* Convert to milliseconds. */

		sleep_time = ((1000*lp_ldap_replication_sleep())-tdiff)/1000;
		sleep_time = lp_ldap_replication_sleep()-(int)tdiff;
		sleep_time = MIN(sleep_time, MAX_LDAP_REPLICATION_SLEEP_TIME);

		if (sleep_time > 0) {
			/* we wait for the LDAP replication */
			DEBUG(5,("smbldap_search: waiting %d milliseconds for LDAP replication.\n",sleep_time));
			smb_msleep(sleep_time);
			DEBUG(5,("smbldap_search: go on!\n"));
			ZERO_STRUCT(ldap_state->last_rebind);
		}
		ZERO_STRUCT(ldap_state->last_rebind);
	}

	if (push_utf8_allocate(&utf8_filter, filter) == (size_t)-1) {
+1 −1
Original line number Diff line number Diff line
@@ -278,7 +278,7 @@ in notify_queue\n", msg->type, msg->field, msg->printer));
		return;
	}
	copy_notify2_msg(pnqueue->msg, msg);
	gettimeofday(&pnqueue->tv, NULL);
	GetTimeOfDay(&pnqueue->tv);
	pnqueue->buf = NULL;
	pnqueue->buflen = 0;

+2 −2
Original line number Diff line number Diff line
@@ -514,10 +514,10 @@ static BOOL sys_utmp_fill(struct utmp *u,
 *	But note that we do the more precise ut_tv as the final assignment.
 */
#if defined(HAVE_UT_UT_TIME)
	gettimeofday(&timeval, NULL);
	GetTimeOfDay(&timeval);
	u->ut_time = timeval.tv_sec;
#elif defined(HAVE_UT_UT_TV)
	gettimeofday(&timeval, NULL);
	GetTimeOfDay(&timeval);
	u->ut_tv = timeval;
#else
#error "with-utmp must have UT_TIME or UT_TV"
+2 −2
Original line number Diff line number Diff line
@@ -45,12 +45,12 @@ static struct timeval tp1,tp2;

void start_timer(void)
{
	gettimeofday(&tp1,NULL);
	GetTimeOfDay(&tp1
}

double end_timer(void)
{
	gettimeofday(&tp2,NULL);
	GetTimeOfDay(&tp2);
	return((tp2.tv_sec - tp1.tv_sec) + 
	       (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
}