Author: rmeggins
Update of /cvs/dirsec/winsync/passwordsync/passsync In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv29691/passwordsync/passsync
Modified Files: ntservice.cpp passsync.mak service.cpp Added Files: dssynchmsg.res Log Message: Resolves: bug 482892 Description: Passsync service start and stop messages in Windows event viewer are not logged correctly Reviewed by: nkinder (Thanks!) Fix Description: Looks like someone had started to tie in the message catalog/resources, but didn't get far enough. 1) I used rc to compile the .rc file into a .res file - this new .res file is being added to CVS (cvs add -kb) 2) I added dssynchmsg.res to the link line 3) I made sure the passsync.exe main called the Install() method which installs the message catalog where the Event Viewer can find it. I had to make that code smarter, so it would not attempt to create/install something that was already there. Platforms tested: Windows 2003 Server Flag Day: no Doc impact: no
--- NEW FILE dssynchmsg.res ---
Notification-based monitoring of user changes has terminated.
Index: ntservice.cpp =================================================================== RCS file: /cvs/dirsec/winsync/passwordsync/passsync/ntservice.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ntservice.cpp 19 Apr 2005 22:07:44 -0000 1.5 +++ ntservice.cpp 16 Feb 2009 22:20:21 -0000 1.6 @@ -196,34 +196,40 @@
BOOL CNTService::Install() { - // Open the Service Control Manager - SC_HANDLE hSCM = ::OpenSCManager(NULL, // local machine - NULL, // ServicesActive database - SC_MANAGER_ALL_ACCESS); // full access - if (!hSCM) return FALSE; - // Get the executable file path TCHAR szFilePath[_MAX_PATH]; ::GetModuleFileName(NULL, szFilePath, sizeof(szFilePath)/sizeof(*szFilePath));
- // Create the service - SC_HANDLE hService = ::CreateService(hSCM, - m_szServiceName, - m_szServiceName, - SERVICE_ALL_ACCESS, - SERVICE_WIN32_OWN_PROCESS, - SERVICE_DEMAND_START, // start condition - SERVICE_ERROR_NORMAL, - szFilePath, - NULL, - NULL, - NULL, - NULL, - NULL); - if (!hService) { - ::CloseServiceHandle(hSCM); - return FALSE; - } + // install if not already installed + if (!IsInstalled()) { + // Open the Service Control Manager + SC_HANDLE hSCM = ::OpenSCManager(NULL, // local machine + NULL, // ServicesActive database + SC_MANAGER_ALL_ACCESS); // full access + if (!hSCM) return FALSE; + + // Create the service + SC_HANDLE hService = ::CreateService(hSCM, + m_szServiceName, + m_szServiceName, + SERVICE_ALL_ACCESS, + SERVICE_WIN32_OWN_PROCESS, + SERVICE_DEMAND_START, // start condition + SERVICE_ERROR_NORMAL, + szFilePath, + NULL, + NULL, + NULL, + NULL, + NULL); + if (!hService) { + ::CloseServiceHandle(hSCM); + return FALSE; + } + // clean up + ::CloseServiceHandle(hService); + ::CloseServiceHandle(hSCM); + }
// make registry entries to support logging messages // Add the source name as a subkey under the Application @@ -232,12 +238,16 @@ HKEY hKey = NULL; _tcscpy(szKey, _T("SYSTEM\CurrentControlSet\Services\EventLog\Application\")); _tcscat(szKey, GetEventName()); - if (::RegCreateKey(HKEY_LOCAL_MACHINE, szKey, &hKey) != ERROR_SUCCESS) { - ::CloseServiceHandle(hService); - ::CloseServiceHandle(hSCM); - return FALSE; - } - + // see if key exists + int result = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_ALL_ACCESS, &hKey); + if (result == ERROR_FILE_NOT_FOUND) { // create it + if (::RegCreateKey(HKEY_LOCAL_MACHINE, szKey, &hKey) != ERROR_SUCCESS) { + return FALSE; + } + } else if (result != ERROR_SUCCESS) { + // punt + return FALSE; + } // Add the Event ID message-file name to the 'EventMessageFile' subkey. ::RegSetValueEx(hKey, _T("EventMessageFile"), @@ -258,9 +268,6 @@
LogEvent(EVENTLOG_INFORMATION_TYPE, EVMSG_INSTALLED, m_szServiceName);
- // tidy up - ::CloseServiceHandle(hService); - ::CloseServiceHandle(hSCM); return TRUE; }
Index: passsync.mak =================================================================== RCS file: /cvs/dirsec/winsync/passwordsync/passsync/passsync.mak,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- passsync.mak 10 Nov 2005 04:18:09 -0000 1.7 +++ passsync.mak 16 Feb 2009 22:20:21 -0000 1.8 @@ -56,6 +56,8 @@ !MESSAGE "passsync - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE !ERROR An invalid configuration is specified. +!ELSE +!MESSAGE Build flavor is $(CFG) !ENDIF
!IF "$(OS)" == "Windows_NT" @@ -126,7 +128,7 @@ BSC32_SBRS= \ LINK32=link.exe -LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\passsync.pdb" /machine:I386 /out:"$(OUTDIR)\passsync.exe" +LINK32_FLAGS=nss3.lib nssutil3.lib libplc4.lib libnspr4.lib nsldappr32v60.lib nsldapssl32v60.lib nsldap32v60.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\passsync.pdb" /machine:I386 /out:"$(OUTDIR)\passsync.exe" dssynchmsg.res LINK32_OBJS= \ "$(INTDIR)\ntservice.obj" \ "$(INTDIR)\passhand.obj" \ @@ -135,8 +137,7 @@ "$(INTDIR)\syncserv.obj"
"$(OUTDIR)\passsync.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) - $(LINK32) @<< - $(LINK32_FLAGS) $(LINK32_OBJS) + $(LINK32) @<< $(LINK32_FLAGS) $(LINK32_OBJS) <<
!ELSEIF "$(CFG)" == "passsync - Win32 Debug" @@ -204,7 +205,7 @@ BSC32_SBRS= \ LINK32=link.exe -LINK32_FLAGS=nss3.lib libplc4.lib libnspr4.lib nsldappr32v50.lib nsldapssl32v50.lib nsldap32v50.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\passsync.pdb" /debug /machine:I386 /out:"$(OUTDIR)\passsync.exe" +LINK32_FLAGS=nss3.lib nssutil3.lib libplc4.lib libnspr4.lib nsldappr32v60.lib nsldapssl32v60.lib nsldap32v60.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\passsync.pdb" /debug /machine:I386 /out:"$(OUTDIR)\passsync.exe" dssynchmsg.res LINK32_OBJS= \ "$(INTDIR)\ntservice.obj" \ "$(INTDIR)\passhand.obj" \
Index: service.cpp =================================================================== RCS file: /cvs/dirsec/winsync/passwordsync/passsync/service.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- service.cpp 19 Apr 2005 22:07:44 -0000 1.6 +++ service.cpp 16 Feb 2009 22:20:21 -0000 1.7 @@ -245,6 +245,12 @@ break; } } + + if ((result == OPT_START) && (argc == 1)) { + // started from SCM - make sure all installation + // stuff is done, like registering our event messages + pSynch->Install(); + } return result; }
389-commits@lists.fedoraproject.org