[Fedora-directory-commits] ldapserver/ldap/synctools/passwordsync/passsync syncserv.cpp, 1.7.2.6, 1.7.2.7
Nathan Kinder (nkinder)
fedora-directory-commits at redhat.com
Thu Mar 30 23:09:04 UTC 2006
Author: nkinder
Update of /cvs/dirsec/ldapserver/ldap/synctools/passwordsync/passsync
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv2067/passwordsync/passsync
Modified Files:
Tag: Directory71RtmBranch
syncserv.cpp
Log Message:
186657 - Implemented locking around passhook data file access
Index: syncserv.cpp
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/synctools/passwordsync/passsync/syncserv.cpp,v
retrieving revision 1.7.2.6
retrieving revision 1.7.2.7
diff -u -r1.7.2.6 -r1.7.2.7
--- syncserv.cpp 22 Mar 2006 18:53:37 -0000 1.7.2.6
+++ syncserv.cpp 30 Mar 2006 23:09:00 -0000 1.7.2.7
@@ -76,6 +76,7 @@
unsigned long size;
passhookEventHandle = CreateEvent(NULL, FALSE, FALSE, PASSHAND_EVENT_NAME);
+ passhookMutexHandle = CreateMutex(NULL, FALSE, PASSHOOK_MUTEX_NAME);
mainLdapConnection = NULL;
results = NULL;
currentResult = NULL;
@@ -211,10 +212,14 @@
timeStamp(&outLog);
outLog << "Backing off for " << BackoffTime(GetMinBackoff()) << "ms" << endl;
}
- WaitForSingleObject(passhookEventHandle, BackoffTime(GetMinBackoff()));
+ waitRes = WaitForSingleObject(passhookEventHandle, BackoffTime(GetMinBackoff()));
if(logLevel > 0) {
timeStamp(&outLog);
- outLog << "Backoff time expired. Attempting sync" << endl;
+ if (waitRes == WAIT_TIMEOUT) {
+ outLog << "Backoff time expired. Attempting sync" << endl;
+ } else {
+ outLog << "Received passhook event. Attempting sync" << endl;
+ }
}
}
@@ -226,24 +231,38 @@
if(passInfoList.size() > 0)
{
- if(saveSet(&passInfoList, dataFilename) == 0)
+ // Get mutex for passhook.dat
+ WaitForSingleObject(passhookMutexHandle, INFINITE);
+
+ // Need to loadSet here so we don't overwrite entries that passhook recently added
+ if(loadSet(&passInfoList, dataFilename) == 0)
{
- if(logLevel > 0)
+ if(saveSet(&passInfoList, dataFilename) == 0)
+ {
+ if(logLevel > 0)
+ {
+ timeStamp(&outLog);
+ outLog << passInfoList.size() << " entries saved to data file" << endl;
+ }
+ }
+ else
{
timeStamp(&outLog);
- outLog << passInfoList.size() << " entries saved to data file" << endl;
+ outLog << "Failed to save entries to data file" << endl;
}
- }
- else
- {
+ } else {
timeStamp(&outLog);
- outLog << "Failed to save entries to data file" << endl;
+ outLog << "Failed to load entries from file" << endl;
}
+
+ // Release mutex for passhook.dat
+ ReleaseMutex(passhookMutexHandle);
}
exit:
clearSet(&passInfoList);
CloseHandle(passhookEventHandle);
+ CloseHandle(passhookMutexHandle);
}
// ****************************************************************
@@ -258,6 +277,9 @@
char* dn = NULL;
int tempSize = passInfoList.size();
+ // Get mutex for passhook.dat
+ WaitForSingleObject(passhookMutexHandle, INFINITE);
+
if(loadSet(&passInfoList, dataFilename) == 0)
{
if((passInfoList.size() - tempSize) > 0)
@@ -289,6 +311,9 @@
outLog << "Failed to load entries from file" << endl;
}
+ // Release mutex for passhook.dat
+ ReleaseMutex(passhookMutexHandle);
+
if(passInfoList.size() > 0)
{
if(logLevel > 0)
More information about the Fedora-directory-commits
mailing list