浏览代码

170556 - Make passsync obey backoff for retries when DS is down

Nathan Kinder 20 年之前
父节点
当前提交
3f0041a0f4
共有 2 个文件被更改,包括 28 次插入29 次删除
  1. 27 28
      ldap/synctools/passwordsync/passsync/syncserv.cpp
  2. 1 1
      ldap/synctools/passwordsync/wix/PassSync.wxs

+ 27 - 28
ldap/synctools/passwordsync/passsync/syncserv.cpp

@@ -101,7 +101,7 @@ PassSyncService::PassSyncService(const TCHAR *serviceName) : CNTService(serviceN
 	}
 	else
 	{
-		maxBackoffTime = pow(2, 12) * SYNCSERV_BASE_BACKOFF_LEN;
+		maxBackoffTime = (1 << 12) * SYNCSERV_BASE_BACKOFF_LEN;
 	}
 
 	size = SYNCSERV_BUF_SIZE;
@@ -177,6 +177,18 @@ void PassSyncService::OnShutdown()
 void PassSyncService::Run()
 {
 	isRunning = true;
+
+	// Initialize NSS
+	if(ldapssl_client_init(certPath, &certdbh) != 0)
+	{
+		timeStamp(&outLog);
+		outLog << "Error initializing SSL: err=" << PR_GetError() << endl;
+		timeStamp(&outLog);
+		outLog << "Ensure that your SSL is setup correctly" << endl;
+
+		goto exit;
+	}
+
 	SyncPasswords();
 
 	while(isRunning)
@@ -229,6 +241,7 @@ void PassSyncService::Run()
 		}
 	}
 
+exit:
 	CloseHandle(passhookEventHandle);
 }
 
@@ -244,15 +257,6 @@ int PassSyncService::SyncPasswords()
 	char* dn;
 	int tempSize = passInfoList.size();
 
-	if(Connect(&mainLdapConnection, ldapAuthUsername, ldapAuthPassword) < 0)
-	{
-		// log connection failure.
-		timeStamp(&outLog);
-		outLog << "Can not connect to ldap server in SyncPasswords" << endl;
-
-		goto exit;
-	}
-
 	if(loadSet(&passInfoList, dataFilename) == 0)
 	{
 		if((passInfoList.size() - tempSize) > 0)
@@ -293,6 +297,15 @@ int PassSyncService::SyncPasswords()
 		}
 	}
 
+	if(Connect(&mainLdapConnection, ldapAuthUsername, ldapAuthPassword) < 0)
+	{
+		// log connection failure.
+		timeStamp(&outLog);
+		outLog << "Can not connect to ldap server in SyncPasswords" << endl;
+
+		goto exit;
+	}
+
 	currentPassInfo = passInfoList.begin();
 	while(currentPassInfo != passInfoList.end())
 	{
@@ -378,20 +391,6 @@ int PassSyncService::Connect(LDAP** connection, char* dn, char* auth)
 {
 	int result = 0;
 
-	if(ldapssl_client_init(certPath, &certdbh) != 0)
-	{
-		result = PR_GetError();
-
-		timeStamp(&outLog);
-		outLog << "ldapssl_client_init failed in Connect" << endl;
-		outLog << "\t" << result << ": " << ldap_err2string(result) << endl;
-
-		result = GetLastError();
-
-		result = -1;
-		goto exit;
-	}
-
 	*connection = ldapssl_init(ldapHostName, atoi(ldapHostPort), 1);
 
 	if(*connection == NULL)
@@ -604,7 +603,7 @@ unsigned long PassSyncService::BackoffTime(int backoff)
 
 	if(backoff > 0)
 	{
-		backoffTime = pow(2, backoff) * SYNCSERV_BASE_BACKOFF_LEN;
+		backoffTime = (1 << backoff) * SYNCSERV_BASE_BACKOFF_LEN;
 	}
 
 	return backoffTime;
@@ -624,12 +623,12 @@ void PassSyncService::UpdateBackoff()
 	currentPassInfo = passInfoList.begin();
 	while(currentPassInfo != passInfoList.end())
 	{
-		if((currentPassInfo->atTime + (BackoffTime(currentPassInfo->backoffCount) / 1000)) <= currentTime)
+		if(((unsigned long)currentPassInfo->atTime + (BackoffTime(currentPassInfo->backoffCount) / 1000)) <= (unsigned long)currentTime)
 		{
 			currentPassInfo->backoffCount++;
 		}
 
-		if((currentTime - currentPassInfo->atTime) > (maxBackoffTime / 1000))
+		if(((unsigned long)currentTime - (unsigned long)currentPassInfo->atTime) > (maxBackoffTime / 1000))
 		{
 			timeStamp(&outLog);
 			outLog << "Abandoning password change for " << currentPassInfo->username << ", backoff expired" << endl;
@@ -656,7 +655,7 @@ int PassSyncService::GetMinBackoff()
 
 	for(currentPassInfo = passInfoList.begin(); currentPassInfo != passInfoList.end(); currentPassInfo++)
 	{
-		if(currentPassInfo->backoffCount < minBackoff)
+		if((unsigned long)currentPassInfo->backoffCount < minBackoff)
 		{
 			minBackoff = currentPassInfo->backoffCount;
 		}

+ 1 - 1
ldap/synctools/passwordsync/wix/PassSync.wxs

@@ -137,7 +137,7 @@
 
 		  <ServiceInstall Id='PassSyncEXE' Name='PassSync' DisplayName='Password Synchronization' Type='ownProcess' 
 		   Interactive='yes' Start='auto' Vital='yes' ErrorControl='normal'/>
-		  <ServiceControl Id='PassSyncEXE' Name='PassSync' Start='install' Stop='both' Remove='uninstall' Wait='yes'/>
+		  <ServiceControl Id='PassSyncEXE' Name='PassSync' Start='install' Stop='both' Remove='uninstall' Wait='no'/>
 
 		  <Registry Id='InstPath' Root='HKLM' Key='Software\PasswordSync' Name='Install Path' Action='write' Type='string' Value='[INSTALLDIR]' />
 		  <Registry Id='HostName' Root='HKLM' Key='Software\PasswordSync' Name='Host Name' Action='write' Type='string' Value='[HOSTNAME]' />