diff --git a/src/WINNT/afsd/NTMakefile b/src/WINNT/afsd/NTMakefile index 5bbfd42074..52bca3931c 100644 --- a/src/WINNT/afsd/NTMakefile +++ b/src/WINNT/afsd/NTMakefile @@ -139,7 +139,7 @@ $(INCFILEDIR)\afsd_eventmessages.h: afsd_eventmessages.mc # Flags for linking LOGON DLL'S # -LOGONLINKFLAGS = -entry:DllEntryPoint /NODEFAULTLIB:msvcr70d.lib /NODEFAULTLIB:msvcrtd.lib msvcrt.lib +LOGONLINKFLAGS = -entry:DllEntryPoint ############################################################################ @@ -328,7 +328,7 @@ $(AFSD_EXEFILE): $(OUT)\afsd.obj $(AFSDOBJS) $(OUT)\afsd.res $(RXOBJS) $(AFSD_E # afsd_service.exe $(EXEDIR)\afsd_service.exe: $(OUT)\afsd_service.obj $(AFSDOBJS) $(OUT)\afsd_service.res $(RXOBJS) $(AFSD_EXELIBS) - $(EXECONLINK) $(AFSD_SDKLIBS) /NODEFAULTLIB:libc.lib /MAP + $(EXECONLINK) $(AFSD_SDKLIBS) /MAP $(EXEPREP) # fs.exe diff --git a/src/WINNT/afsd/afsd_service.c b/src/WINNT/afsd/afsd_service.c index 0185691392..4291b1c11a 100644 --- a/src/WINNT/afsd/afsd_service.c +++ b/src/WINNT/afsd/afsd_service.c @@ -146,11 +146,65 @@ afsd_ServiceFlushVolume(DWORD dwlpEventData) return dwRet; } + +/* service control handler used in nt4 only for backward compat. */ +VOID WINAPI +afsd_ServiceControlHandler(DWORD ctrlCode) +{ + HKEY parmKey; + DWORD dummyLen, doTrace; + long code; + + switch (ctrlCode) { + case SERVICE_CONTROL_STOP: + /* Shutdown RPC */ + RpcMgmtStopServerListening(NULL); + + /* Force trace if requested */ + code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + AFSConfigKeyName, + 0, KEY_QUERY_VALUE, &parmKey); + if (code != ERROR_SUCCESS) + goto doneTrace; + + dummyLen = sizeof(doTrace); + code = RegQueryValueEx(parmKey, "TraceOnShutdown", + NULL, NULL, + (BYTE *) &doTrace, &dummyLen); + RegCloseKey (parmKey); + if (code != ERROR_SUCCESS) + doTrace = 0; + if (doTrace) + afsd_ForceTrace(FALSE); + +doneTrace: + ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING; + ServiceStatus.dwWin32ExitCode = NO_ERROR; + ServiceStatus.dwCheckPoint = 1; + ServiceStatus.dwWaitHint = 10000; + ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; + SetServiceStatus(StatusHandle, &ServiceStatus); + SetEvent(WaitToTerminate); + break; + case SERVICE_CONTROL_INTERROGATE: + ServiceStatus.dwCurrentState = SERVICE_RUNNING; + ServiceStatus.dwWin32ExitCode = NO_ERROR; + ServiceStatus.dwCheckPoint = 0; + ServiceStatus.dwWaitHint = 0; + ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; + SetServiceStatus(StatusHandle, &ServiceStatus); + break; + /* XXX handle system shutdown */ + /* XXX handle pause & continue */ + } +} + + /* ** Extended ServiceControlHandler that provides Event types ** for monitoring Power events, for example. */ -DWORD +DWORD WINAPI afsd_ServiceControlHandlerEx( DWORD ctrlCode, DWORD dwEventType, @@ -350,6 +404,16 @@ typedef BOOL ( APIENTRY * AfsdInitHook )(void); #define AFSD_INIT_HOOK "AfsdInitHook" #define AFSD_HOOK_DLL "afsdhook.dll" +/* +control serviceex exists only on 2000/xp. These functions will be loaded dynamically. +*/ + +typedef SERVICE_STATUS_HANDLE ( * RegisterServiceCtrlHandlerExFunc )( LPCTSTR , LPHANDLER_FUNCTION_EX , LPVOID ); +typedef SERVICE_STATUS_HANDLE ( * RegisterServiceCtrlHandlerFunc )( LPCTSTR , LPHANDLER_FUNCTION ); + +RegisterServiceCtrlHandlerExFunc pRegisterServiceCtrlHandlerEx = NULL; +RegisterServiceCtrlHandlerFunc pRegisterServiceCtrlHandler = NULL; + void afsd_Main(DWORD argc, LPTSTR *argv) { long code; @@ -358,6 +422,7 @@ void afsd_Main(DWORD argc, LPTSTR *argv) int jmpret; #endif /* JUMP */ HANDLE hInitHookDll; + HANDLE hAdvApi32; AfsdInitHook initHook; #ifdef _DEBUG @@ -377,10 +442,23 @@ void afsd_Main(DWORD argc, LPTSTR *argv) afsi_log("Event Object Already Exists: %s", TEXT("afsd_service_WaitToTerminate")); #ifndef NOTSERVICE - StatusHandle = RegisterServiceCtrlHandlerEx(argv[0] /* AFS_DAEMON_SERVICE_NAME */, - (LPHANDLER_FUNCTION_EX) afsd_ServiceControlHandlerEx, - NULL /* user context */ - ); + hAdvApi32 = LoadLibrary("advapi32.dll"); + if (hAdvApi32 == NULL) + { + afsi_log("Fatal: cannot load advapi32.dll"); + return; + } + + pRegisterServiceCtrlHandlerEx = (RegisterServiceCtrlHandlerExFunc)GetProcAddress(hAdvApi32, "RegisterServiceCtrlHandlerExA"); + if (pRegisterServiceCtrlHandlerEx) + { + afsi_log("running on 2000+ - using RegisterServiceCtrlHandlerEx"); + StatusHandle = RegisterServiceCtrlHandlerEx(AFS_DAEMON_SERVICE_NAME, afsd_ServiceControlHandlerEx, NULL ); + } + else + { + StatusHandle = RegisterServiceCtrlHandler(AFS_DAEMON_SERVICE_NAME, afsd_ServiceControlHandler); + } ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; ServiceStatus.dwServiceSpecificExitCode = 0; @@ -417,7 +495,8 @@ void afsd_Main(DWORD argc, LPTSTR *argv) hookRc = initHook(); } FreeLibrary(hInitHookDll); - + hInitHookDll = NULL; + if (hookRc == FALSE) { ServiceStatus.dwCurrentState = SERVICE_STOPPED; @@ -524,18 +603,12 @@ void afsd_Main(DWORD argc, LPTSTR *argv) /* Remove the ExceptionFilter */ SetUnhandledExceptionFilter(NULL); - if ( hInitHookDll ) - FreeLibrary(hInitHookDll); - - Sleep(5000); - ServiceStatus.dwCurrentState = SERVICE_STOPPED; ServiceStatus.dwWin32ExitCode = GlobalStatus ? ERROR_EXCEPTION_IN_SERVICE : NO_ERROR; ServiceStatus.dwCheckPoint = 0; ServiceStatus.dwWaitHint = 0; ServiceStatus.dwControlsAccepted = 0; SetServiceStatus(StatusHandle, &ServiceStatus); - } DWORD __stdcall afsdMain_thread(void* notUsed) diff --git a/src/WINNT/afsd/smb.c b/src/WINNT/afsd/smb.c index 3512ef51dc..21122e40d5 100644 --- a/src/WINNT/afsd/smb.c +++ b/src/WINNT/afsd/smb.c @@ -530,7 +530,14 @@ smb_CalculateNowTZ() local_tm = *(localtime(&t)); days = local_tm.tm_yday - gmt_tm.tm_yday; - hours = 24 * days + local_tm.tm_hour - gmt_tm.tm_hour - (local_tm.tm_isdst ? 1 : 0); + hours = 24 * days + local_tm.tm_hour - gmt_tm.tm_hour +#ifdef COMMENT + /* There is a problem with DST immediately after the time change + * which may continue to exist until the machine is rebooted + */ + - (local_tm.tm_isdst ? 1 : 0) +#endif /* COMMENT */ + ; minutes = 60 * hours + local_tm.tm_min - gmt_tm.tm_min; seconds = 60 * minutes + local_tm.tm_sec - gmt_tm.tm_sec;