Index: openafs/src/WINNT/afsd/afsd_flushvol.c diff -c openafs/src/WINNT/afsd/afsd_flushvol.c:1.6 openafs/src/WINNT/afsd/afsd_flushvol.c:1.6.2.1 *** openafs/src/WINNT/afsd/afsd_flushvol.c:1.6 Fri Jun 18 00:52:25 2004 --- openafs/src/WINNT/afsd/afsd_flushvol.c Sun Oct 3 09:35:15 2004 *************** *** 27,32 **** --- 27,35 ---- #include "afsd_flushvol.h" #include "afsd_eventlog.h" + #include "lanahelper.h" + + extern void afsi_log(char *pattern, ...); static FLUSHVOLTHREADINFO gThreadInfo = {0}; static HANDLE gThreadHandle = NULL; *************** *** 45,189 **** afs_int32 afsd_ServicePerformFlushVolumeCmd(char *data) { ! register afs_int32 code; ! struct ViceIoctl blob; ! memset(&blob, '\0', sizeof(blob)); ! code = pioctl(data, VIOC_FLUSHVOLUME, &blob, 0); ! return code; } BOOL afsd_ServicePerformFlushVolumes() ! { ! CONST CHAR COLON = ':'; ! CONST CHAR SLASH = '\\'; ! CONST DWORD NETRESBUFSIZE = 16384; ! CHAR bufMessage[1024]; ! UINT i; ! DWORD dwServerSize; ! DWORD dwRet; ! DWORD dwCount; ! DWORD dwNetResBufSize; ! DWORD dwTotalVols = 0; ! DWORD dwVolBegin, dwVolEnd; ! DWORD dwFlushBegin, dwFlushEnd; ! HANDLE hEnum; ! LPNETRESOURCE lpNetResBuf, lpnr; ! PCHAR pszShareName, pc; ! afs_int32 afsRet = 0; ! ! // Determine the root share name (\\AFS\ALL or \\-AFS\ALL), ! // and the length of the server name prefix. ! pszShareName = smb_GetSharename(); ! if (pszShareName == NULL) ! { ! LogEvent(EVENTLOG_ERROR_TYPE, MSG_FLUSH_NO_SHARE_NAME, NULL); ! return FALSE; ! } ! pc = strrchr(pszShareName, SLASH); ! if ((pc == NULL) || ((dwServerSize = pc - pszShareName) < 3)) ! { ! LogEvent(EVENTLOG_ERROR_TYPE, MSG_FLUSH_BAD_SHARE_NAME, ! pszShareName, NULL); ! free(pszShareName); ! return FALSE; ! } ! ! // Allocate a buffer to hold network resources returned by ! // WNetEnumResource(). ! lpNetResBuf = malloc(NETRESBUFSIZE); ! if (lpNetResBuf == NULL) ! { ! // Out of memory, give up now. ! LogEvent(EVENTLOG_ERROR_TYPE, MSG_FLUSH_NO_MEMORY, NULL); ! free(pszShareName); ! return FALSE; ! } ! ! // Initialize the flush timer. Note that GetTickCount() returns ! // the number of milliseconds since the system started, in a DWORD, ! // so that the value wraps around every 49.7 days. We do not bother ! // to handle the case where the flush elapsed time is greater than ! // that. ! dwFlushBegin = GetTickCount(); ! ! dwRet = WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_ANY, 0, NULL, ! &hEnum); ! if (dwRet != NO_ERROR) ! { ! LogEventMessage(EVENTLOG_ERROR_TYPE, MSG_FLUSH_OPEN_ENUM_ERROR, ! dwRet); ! free(pszShareName); ! return FALSE; ! } ! ! // Loop to enumerate network resources, and flush those associated ! // with AFS volumes. ! while (1) ! { ! dwCount = -1; ! memset(lpNetResBuf, 0, NETRESBUFSIZE); ! dwNetResBufSize = NETRESBUFSIZE; ! dwRet = WNetEnumResource(hEnum, &dwCount, ! lpNetResBuf, &dwNetResBufSize); ! if (dwRet != NO_ERROR) ! break; ! // Iterate over the returned network resources. ! for (i = 0, lpnr = lpNetResBuf; i < dwCount; i++, lpnr++) ! { ! // Ensure resource has a remote name, and is connected. ! if ((lpnr->lpRemoteName == NULL) || ! (lpnr->dwScope != RESOURCE_CONNECTED)) ! continue; ! if ((_strnicmp(lpnr->lpRemoteName, pszShareName, ! dwServerSize) == 0) && ! (lpnr->lpRemoteName[dwServerSize] == SLASH)) ! { ! // got one! ! // but we don't want to flush '\\[...]afs\all' ! if (_stricmp(lpnr->lpRemoteName, ! pszShareName) == 0) ! continue; ! ++dwTotalVols; ! ! dwVolBegin = GetTickCount(); ! afsRet = afsd_ServicePerformFlushVolumeCmd(lpnr->lpRemoteName); ! dwVolEnd = GetTickCount(); ! if (afsRet == 0) ! { ! LogTimingEvent(MSG_TIME_FLUSH_PER_VOLUME, ! lpnr->lpRemoteName, ! dwVolEnd - dwVolBegin); ! } ! else ! { ! LogEvent(EVENTLOG_WARNING_TYPE, ! MSG_FLUSH_FAILED, ! lpnr->lpRemoteName, NULL); ! } ! } ! } ! } ! WNetCloseEnum(hEnum); ! free(lpNetResBuf); ! free(pszShareName); ! if (dwRet != ERROR_NO_MORE_ITEMS) ! { ! LogEventMessage(EVENTLOG_ERROR_TYPE, MSG_FLUSH_ENUM_ERROR, ! dwRet); ! return FALSE; ! } ! dwFlushEnd = GetTickCount(); ! // display total volume count in Event Logger ! sprintf(bufMessage, "%d", dwTotalVols); ! LogTimingEvent(MSG_TIME_FLUSH_TOTAL, bufMessage, ! dwFlushEnd - dwFlushBegin); ! return TRUE; } // Report a timing event to the system event log. --- 48,197 ---- afs_int32 afsd_ServicePerformFlushVolumeCmd(char *data) { ! register afs_int32 code; ! struct ViceIoctl blob; ! afsi_log("Flushing Volume \"%s\"",data); ! memset(&blob, '\0', sizeof(blob)); ! code = pioctl(data, VIOC_FLUSHVOLUME, &blob, 0); ! return code; } BOOL afsd_ServicePerformFlushVolumes() ! { ! CONST CHAR COLON = ':'; ! CONST CHAR SLASH = '\\'; ! CONST DWORD NETRESBUFSIZE = 16384; ! CHAR bufMessage[1024]; ! UINT i; ! DWORD dwServerSize; ! DWORD dwRet; ! DWORD dwCount; ! DWORD dwNetResBufSize; ! DWORD dwTotalVols = 0; ! DWORD dwVolBegin, dwVolEnd; ! DWORD dwFlushBegin, dwFlushEnd; ! HANDLE hEnum; ! LPNETRESOURCE lpNetResBuf, lpnr; ! PCHAR pszShareName, pc; ! afs_int32 afsRet = 0; ! ! if ( lana_OnlyLoopback() ) { ! // Nothing to do if we only have a loopback interface ! return TRUE; ! } ! ! // Determine the root share name (\\AFS\ALL or \\-AFS\ALL), ! // and the length of the server name prefix. ! pszShareName = smb_GetSharename(); ! if (pszShareName == NULL) ! { ! LogEvent(EVENTLOG_ERROR_TYPE, MSG_FLUSH_NO_SHARE_NAME, NULL); ! return FALSE; ! } ! pc = strrchr(pszShareName, SLASH); ! if ((pc == NULL) || ((dwServerSize = pc - pszShareName) < 3)) ! { ! LogEvent(EVENTLOG_ERROR_TYPE, MSG_FLUSH_BAD_SHARE_NAME, ! pszShareName, NULL); ! free(pszShareName); ! return FALSE; ! } ! ! // Allocate a buffer to hold network resources returned by ! // WNetEnumResource(). ! lpNetResBuf = malloc(NETRESBUFSIZE); ! if (lpNetResBuf == NULL) ! { ! // Out of memory, give up now. ! LogEvent(EVENTLOG_ERROR_TYPE, MSG_FLUSH_NO_MEMORY, NULL); ! free(pszShareName); ! return FALSE; ! } ! ! // Initialize the flush timer. Note that GetTickCount() returns ! // the number of milliseconds since the system started, in a DWORD, ! // so that the value wraps around every 49.7 days. We do not bother ! // to handle the case where the flush elapsed time is greater than ! // that. ! dwFlushBegin = GetTickCount(); ! ! dwRet = WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_ANY, 0, NULL, ! &hEnum); ! if (dwRet != NO_ERROR) ! { ! LogEventMessage(EVENTLOG_ERROR_TYPE, MSG_FLUSH_OPEN_ENUM_ERROR, ! dwRet); ! free(pszShareName); ! return FALSE; ! } ! ! // Loop to enumerate network resources, and flush those associated ! // with AFS volumes. ! while (1) ! { ! dwCount = -1; ! memset(lpNetResBuf, 0, NETRESBUFSIZE); ! dwNetResBufSize = NETRESBUFSIZE; ! dwRet = WNetEnumResource(hEnum, &dwCount, ! lpNetResBuf, &dwNetResBufSize); ! if (dwRet != NO_ERROR) ! break; ! // Iterate over the returned network resources. ! for (i = 0, lpnr = lpNetResBuf; i < dwCount; i++, lpnr++) ! { ! // Ensure resource has a remote name, and is connected. ! if ((lpnr->lpRemoteName == NULL) || ! (lpnr->dwScope != RESOURCE_CONNECTED)) ! continue; ! if ((_strnicmp(lpnr->lpRemoteName, pszShareName, ! dwServerSize) == 0) && ! (lpnr->lpRemoteName[dwServerSize] == SLASH)) ! { ! // got one! ! // but we don't want to flush '\\[...]afs\all' ! if (_stricmp(lpnr->lpRemoteName, pszShareName) == 0) ! continue; ! ++dwTotalVols; ! ! dwVolBegin = GetTickCount(); ! afsRet = afsd_ServicePerformFlushVolumeCmd(lpnr->lpRemoteName); ! dwVolEnd = GetTickCount(); ! if (afsRet == 0) ! { ! LogTimingEvent(MSG_TIME_FLUSH_PER_VOLUME, ! lpnr->lpRemoteName, ! dwVolEnd - dwVolBegin); ! } ! else ! { ! LogEvent(EVENTLOG_WARNING_TYPE, ! MSG_FLUSH_FAILED, ! lpnr->lpRemoteName, NULL); ! } ! } ! } ! } ! WNetCloseEnum(hEnum); ! free(lpNetResBuf); ! free(pszShareName); ! if (dwRet != ERROR_NO_MORE_ITEMS) ! { ! LogEventMessage(EVENTLOG_ERROR_TYPE, MSG_FLUSH_ENUM_ERROR, ! dwRet); ! return FALSE; ! } ! dwFlushEnd = GetTickCount(); ! // display total volume count in Event Logger ! sprintf(bufMessage, "%d", dwTotalVols); ! LogTimingEvent(MSG_TIME_FLUSH_TOTAL, bufMessage, ! dwFlushEnd - dwFlushBegin); ! return TRUE; } // Report a timing event to the system event log. *************** *** 193,203 **** static VOID LogTimingEvent(DWORD dwEventID, LPTSTR lpString1, DWORD dwTime) { ! CHAR szTime[16]; ! sprintf(szTime, "%lu", dwTime); ! LogEvent(EVENTLOG_INFORMATION_TYPE, dwEventID, lpString1, szTime, ! NULL); } --- 201,211 ---- static VOID LogTimingEvent(DWORD dwEventID, LPTSTR lpString1, DWORD dwTime) { ! CHAR szTime[16]; ! sprintf(szTime, "%lu", dwTime); ! LogEvent(EVENTLOG_INFORMATION_TYPE, dwEventID, lpString1, szTime, ! NULL); } *************** *** 223,313 **** // HANDLE GetUserToken(DWORD access) { ! HANDLE hTok = NULL; ! DWORD pid = 0, tid = 0; ! ! // Try it the easy way first - look for a window owned by the shell on ! // our current desktop. If we find one, use that to get the process id. ! HWND shell = FindWindowEx(NULL, NULL, "Progman", NULL); ! if (shell != NULL) ! { ! tid = GetWindowThreadProcessId(shell, &pid); ! } ! ! // We are possibly running on a private window station and desktop: we must ! // switch to the default (which we suppose is where we will find the ! // running shell). ! else ! { ! HWINSTA saveWinSta = GetProcessWindowStation(); ! HDESK saveDesk = GetThreadDesktop(GetCurrentThreadId()); ! HWINSTA winSta = NULL; ! HDESK desk = NULL; ! BOOL changeFlag = FALSE; ! BOOL dummy = saveWinSta != NULL && ! saveDesk != NULL && ! (winSta = OpenWindowStation("WinSta0", FALSE, ! MAXIMUM_ALLOWED)) != NULL && ! (changeFlag = SetProcessWindowStation(winSta)) != 0 && ! (desk = OpenDesktop("Default", 0, FALSE, ! MAXIMUM_ALLOWED)) != NULL && ! SetThreadDesktop(desk) != 0; ! ! // Now find the window and process on this desktop ! shell = FindWindowEx(NULL, NULL, "Progman", NULL); ! if (shell != NULL) ! { ! tid = GetWindowThreadProcessId(shell, &pid); ! } ! ! // Restore our own window station and desktop ! if (changeFlag) ! { ! SetProcessWindowStation(saveWinSta); ! SetThreadDesktop(saveDesk); ! } ! ! // Close temporary objects ! if (winSta != NULL) ! CloseWindowStation(winSta); ! if (desk != NULL) ! CloseDesktop(desk); ! } ! ! // ! // If we have a process id, use that to get the process handle and ! // from there the process' access token. ! // ! if (pid != 0) ! { ! HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); ! if (hProc != NULL) ! { ! OpenProcessToken(hProc, access, &hTok) || (hTok = NULL); ! CloseHandle(hProc); ! } ! } ! // Return token if we got one ! return hTok; ! } // impersonate logged-on user as client BOOL ImpersonateClient() { ! DWORD dwDesiredAccess = TOKEN_ALL_ACCESS; ! HANDLE hUserToken = GetUserToken(dwDesiredAccess); ! if (hUserToken == NULL) ! return FALSE; ! if (ImpersonateLoggedOnUser(hUserToken) == 0) ! { ! LogEvent(EVENTLOG_ERROR_TYPE, MSG_FLUSH_IMPERSONATE_ERROR, ! NULL); ! return FALSE; ! } ! return TRUE; } ///////////////////////////////////////////////////////////////////// --- 231,321 ---- // HANDLE GetUserToken(DWORD access) { ! HANDLE hTok = NULL; ! DWORD pid = 0, tid = 0; ! // Try it the easy way first - look for a window owned by the shell on ! // our current desktop. If we find one, use that to get the process id. ! HWND shell = FindWindowEx(NULL, NULL, "Progman", NULL); ! if (shell != NULL) ! { ! tid = GetWindowThreadProcessId(shell, &pid); ! } ! ! // We are possibly running on a private window station and desktop: we must ! // switch to the default (which we suppose is where we will find the ! // running shell). ! else ! { ! HWINSTA saveWinSta = GetProcessWindowStation(); ! HDESK saveDesk = GetThreadDesktop(GetCurrentThreadId()); ! HWINSTA winSta = NULL; ! HDESK desk = NULL; ! BOOL changeFlag = FALSE; ! BOOL dummy = saveWinSta != NULL && ! saveDesk != NULL && ! (winSta = OpenWindowStation("WinSta0", FALSE, ! MAXIMUM_ALLOWED)) != NULL && ! (changeFlag = SetProcessWindowStation(winSta)) != 0 && ! (desk = OpenDesktop("Default", 0, FALSE, ! MAXIMUM_ALLOWED)) != NULL && ! SetThreadDesktop(desk) != 0; ! ! // Now find the window and process on this desktop ! shell = FindWindowEx(NULL, NULL, "Progman", NULL); ! if (shell != NULL) ! { ! tid = GetWindowThreadProcessId(shell, &pid); ! } ! ! // Restore our own window station and desktop ! if (changeFlag) ! { ! SetProcessWindowStation(saveWinSta); ! SetThreadDesktop(saveDesk); ! } ! ! // Close temporary objects ! if (winSta != NULL) ! CloseWindowStation(winSta); ! if (desk != NULL) ! CloseDesktop(desk); ! } ! ! // ! // If we have a process id, use that to get the process handle and ! // from there the process' access token. ! // ! if (pid != 0) ! { ! HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); ! if (hProc != NULL) ! { ! OpenProcessToken(hProc, access, &hTok) || (hTok = NULL); ! CloseHandle(hProc); ! } ! } ! ! // Return token if we got one ! return hTok; ! } // impersonate logged-on user as client BOOL ImpersonateClient() { ! DWORD dwDesiredAccess = TOKEN_ALL_ACCESS; ! HANDLE hUserToken = GetUserToken(dwDesiredAccess); ! if (hUserToken == NULL) ! return FALSE; ! if (ImpersonateLoggedOnUser(hUserToken) == 0) ! { ! LogEvent(EVENTLOG_ERROR_TYPE, MSG_FLUSH_IMPERSONATE_ERROR, ! NULL); ! return FALSE; ! } ! return TRUE; } ///////////////////////////////////////////////////////////////////// *************** *** 317,383 **** DWORD WINAPI afsd_ServiceFlushVolumesThreadProc(LPVOID lpParam) { ! FLUSHVOLTHREADINFO ThreadInfo; ! PFLUSHVOLTHREADINFO pThreadInfo = (PFLUSHVOLTHREADINFO) lpParam; ! HANDLE arHandles[2] = {0}; ! DWORD dwWaitState = 0; ! ! // thread running - get handles ! ThreadInfo.hEventPowerEvent = pThreadInfo->hEventPowerEvent; ! ThreadInfo.hEventResumeMain = pThreadInfo->hEventResumeMain; ! ThreadInfo.hEventTerminate = pThreadInfo->hEventTerminate; ! ! // setup to wait ! arHandles[0] = ThreadInfo.hEventTerminate; ! arHandles[1] = ThreadInfo.hEventPowerEvent; ! ! // do stuff .. ! while (1) ! { ! // wait for an event to happen ! dwWaitState = WaitForMultipleObjectsEx(2, arHandles, FALSE, INFINITE, FALSE); ! ! switch (dwWaitState) ! { ! case WAIT_OBJECT_0: ! // termination signaled ! RevertToSelf(); CheckAndCloseHandle(ThreadInfo.hEventPowerEvent); CheckAndCloseHandle(ThreadInfo.hEventResumeMain); CheckAndCloseHandle(ThreadInfo.hEventTerminate); ! ExitThread(0); ! break; ! case WAIT_OBJECT_0+1: ! // Power event ! // - flush 'em! ! if (ImpersonateClient()) ! { ! afsd_ServicePerformFlushVolumes(); ! } ! // acknowledge event ! ResetEvent(ThreadInfo.hEventPowerEvent); ! break; ! ! case WAIT_ABANDONED_0: ! case WAIT_ABANDONED_0+1: ! case WAIT_IO_COMPLETION: ! case WAIT_TIMEOUT: ! // sno* ! LogEvent(EVENTLOG_WARNING_TYPE, ! MSG_FLUSH_UNEXPECTED_EVENT, NULL); ! break; ! ! } // end switch ! ! // signal back to waiting mainline ! SetEvent(ThreadInfo.hEventResumeMain); ! ! } // end while ! ! // I suppose we never get here ! ExitThread(0); ! } ///////////////////////////////////////////////////////////////////// // --- 325,391 ---- DWORD WINAPI afsd_ServiceFlushVolumesThreadProc(LPVOID lpParam) { ! FLUSHVOLTHREADINFO ThreadInfo; ! PFLUSHVOLTHREADINFO pThreadInfo = (PFLUSHVOLTHREADINFO) lpParam; ! HANDLE arHandles[2] = {0}; ! DWORD dwWaitState = 0; ! ! // thread running - get handles ! ThreadInfo.hEventPowerEvent = pThreadInfo->hEventPowerEvent; ! ThreadInfo.hEventResumeMain = pThreadInfo->hEventResumeMain; ! ThreadInfo.hEventTerminate = pThreadInfo->hEventTerminate; ! ! // setup to wait ! arHandles[0] = ThreadInfo.hEventTerminate; ! arHandles[1] = ThreadInfo.hEventPowerEvent; ! ! // do stuff .. ! while (1) ! { ! // wait for an event to happen ! dwWaitState = WaitForMultipleObjectsEx(2, arHandles, FALSE, INFINITE, FALSE); ! ! switch (dwWaitState) ! { ! case WAIT_OBJECT_0: ! // termination signaled ! RevertToSelf(); CheckAndCloseHandle(ThreadInfo.hEventPowerEvent); CheckAndCloseHandle(ThreadInfo.hEventResumeMain); CheckAndCloseHandle(ThreadInfo.hEventTerminate); ! ExitThread(0); ! break; ! case WAIT_OBJECT_0+1: ! // Power event ! // - flush 'em! ! if (ImpersonateClient()) ! { ! afsd_ServicePerformFlushVolumes(); ! } ! // acknowledge event ! ResetEvent(ThreadInfo.hEventPowerEvent); ! break; ! ! case WAIT_ABANDONED_0: ! case WAIT_ABANDONED_0+1: ! case WAIT_IO_COMPLETION: ! case WAIT_TIMEOUT: ! // sno* ! LogEvent(EVENTLOG_WARNING_TYPE, ! MSG_FLUSH_UNEXPECTED_EVENT, NULL); ! break; ! ! } // end switch ! ! // signal back to waiting mainline ! SetEvent(ThreadInfo.hEventResumeMain); ! ! } // end while ! ! // I suppose we never get here ! ExitThread(0); ! } ///////////////////////////////////////////////////////////////////// // *************** *** 387,397 **** VOID CheckAndCloseHandle(HANDLE thisHandle) { ! if (thisHandle != NULL) ! { ! CloseHandle(thisHandle); ! thisHandle = NULL; ! } } // --- 395,405 ---- VOID CheckAndCloseHandle(HANDLE thisHandle) { ! if (thisHandle != NULL) ! { ! CloseHandle(thisHandle); ! thisHandle = NULL; ! } } // *************** *** 400,461 **** BOOL PowerNotificationThreadCreate() { ! BOOL bSuccess = FALSE; ! DWORD dwThreadId = 0; char eventName[MAX_PATH]; ! do ! { ! // create power event notification event ! // bManualReset=TRUE, bInitialState=FALSE ! gThreadInfo.hEventPowerEvent = CreateEvent(NULL, TRUE, FALSE, TEXT("afsd_flushvol_EventPowerEvent")); if ( GetLastError() == ERROR_ALREADY_EXISTS ) afsi_log("Event Object Already Exists: %s", eventName); ! if (gThreadInfo.hEventPowerEvent == NULL) ! break; ! // create mainline resume event ! // bManualReset=FALSE, bInitialState=FALSE ! gThreadInfo.hEventResumeMain = CreateEvent(NULL, FALSE, FALSE, TEXT("afsd_flushvol_EventResumeMain")); if ( GetLastError() == ERROR_ALREADY_EXISTS ) afsi_log("Event Object Already Exists: %s", eventName); ! if (gThreadInfo.hEventResumeMain == NULL) ! break; ! // create thread terminate event ! // bManualReset=FALSE, bInitialState=FALSE ! gThreadInfo.hEventTerminate = CreateEvent(NULL, FALSE, FALSE, TEXT("afsd_flushvol_EventTerminate")); if ( GetLastError() == ERROR_ALREADY_EXISTS ) afsi_log("Event Object Already Exists: %s", eventName); ! if (gThreadInfo.hEventTerminate == NULL) ! break; ! // good so far - create thread ! gThreadHandle = CreateThread(NULL, 0, ! afsd_ServiceFlushVolumesThreadProc, ! (LPVOID) &gThreadInfo, ! 0, &dwThreadId); ! if (!gThreadHandle) ! break; ! bSuccess = TRUE; ! } while (0); ! if (!bSuccess) ! { ! CheckAndCloseHandle(gThreadInfo.hEventPowerEvent); ! CheckAndCloseHandle(gThreadInfo.hEventResumeMain); ! CheckAndCloseHandle(gThreadInfo.hEventTerminate); ! CheckAndCloseHandle(gThreadHandle); ! } ! return bSuccess; } // --- 408,469 ---- BOOL PowerNotificationThreadCreate() { ! BOOL bSuccess = FALSE; ! DWORD dwThreadId = 0; char eventName[MAX_PATH]; ! do ! { ! // create power event notification event ! // bManualReset=TRUE, bInitialState=FALSE ! gThreadInfo.hEventPowerEvent = CreateEvent(NULL, TRUE, FALSE, TEXT("afsd_flushvol_EventPowerEvent")); if ( GetLastError() == ERROR_ALREADY_EXISTS ) afsi_log("Event Object Already Exists: %s", eventName); ! if (gThreadInfo.hEventPowerEvent == NULL) ! break; ! // create mainline resume event ! // bManualReset=FALSE, bInitialState=FALSE ! gThreadInfo.hEventResumeMain = CreateEvent(NULL, FALSE, FALSE, TEXT("afsd_flushvol_EventResumeMain")); if ( GetLastError() == ERROR_ALREADY_EXISTS ) afsi_log("Event Object Already Exists: %s", eventName); ! if (gThreadInfo.hEventResumeMain == NULL) ! break; ! // create thread terminate event ! // bManualReset=FALSE, bInitialState=FALSE ! gThreadInfo.hEventTerminate = CreateEvent(NULL, FALSE, FALSE, TEXT("afsd_flushvol_EventTerminate")); if ( GetLastError() == ERROR_ALREADY_EXISTS ) afsi_log("Event Object Already Exists: %s", eventName); ! if (gThreadInfo.hEventTerminate == NULL) ! break; ! // good so far - create thread ! gThreadHandle = CreateThread(NULL, 0, ! afsd_ServiceFlushVolumesThreadProc, ! (LPVOID) &gThreadInfo, ! 0, &dwThreadId); ! if (!gThreadHandle) ! break; ! bSuccess = TRUE; ! } while (0); ! if (!bSuccess) ! { ! CheckAndCloseHandle(gThreadInfo.hEventPowerEvent); ! CheckAndCloseHandle(gThreadInfo.hEventResumeMain); ! CheckAndCloseHandle(gThreadInfo.hEventTerminate); ! CheckAndCloseHandle(gThreadHandle); ! } ! return bSuccess; } // *************** *** 464,484 **** BOOL PowerNotificationThreadNotify() { ! DWORD dwRet = 0; ! BOOL bRet = FALSE; ! // Notify thread of power event, and wait for the HardDead timeout period ! dwRet = SignalObjectAndWait( ! gThreadInfo.hEventPowerEvent, // object to signal ! gThreadInfo.hEventResumeMain, // object to watch ! HardDeadtimeout*1000, // timeout (ms) ! FALSE // alertable ! ); ! if (dwRet == WAIT_OBJECT_0) ! bRet = TRUE; ! return bRet; } // --- 472,492 ---- BOOL PowerNotificationThreadNotify() { ! DWORD dwRet = 0; ! BOOL bRet = FALSE; ! // Notify thread of power event, and wait for the HardDead timeout period ! dwRet = SignalObjectAndWait( ! gThreadInfo.hEventPowerEvent, // object to signal ! gThreadInfo.hEventResumeMain, // object to watch ! HardDeadtimeout*1000, // timeout (ms) ! FALSE // alertable ! ); ! if (dwRet == WAIT_OBJECT_0) ! bRet = TRUE; ! return bRet; } // *************** *** 487,498 **** VOID PowerNotificationThreadExit() { ! // ExitThread ! if (gThreadHandle) ! { ! SetEvent(gThreadInfo.hEventTerminate); WaitForSingleObject(gThreadHandle, INFINITE); ! CloseHandle(gThreadHandle); ! } } --- 495,506 ---- VOID PowerNotificationThreadExit() { ! // ExitThread ! if (gThreadHandle) ! { ! SetEvent(gThreadInfo.hEventTerminate); WaitForSingleObject(gThreadHandle, INFINITE); ! CloseHandle(gThreadHandle); ! } } Index: openafs/src/WINNT/afsd/afsd_init.c diff -c openafs/src/WINNT/afsd/afsd_init.c:1.40.2.2 openafs/src/WINNT/afsd/afsd_init.c:1.40.2.5 *** openafs/src/WINNT/afsd/afsd_init.c:1.40.2.2 Tue Aug 17 00:28:38 2004 --- openafs/src/WINNT/afsd/afsd_init.c Mon Oct 18 00:09:25 2004 *************** *** 81,87 **** cm_initparams_v1 cm_initParams; char *cm_sysName = 0; ! int cm_sysNameCount = 0; char *cm_sysNameList[MAXNUMSYSNAMES]; DWORD TraceOption = 0; --- 81,87 ---- cm_initparams_v1 cm_initParams; char *cm_sysName = 0; ! unsigned int cm_sysNameCount = 0; char *cm_sysNameList[MAXNUMSYSNAMES]; DWORD TraceOption = 0; *************** *** 358,429 **** int afsd_InitCM(char **reasonP) { ! osi_uid_t debugID; ! long cacheBlocks; ! long cacheSize; ! long logChunkSize; ! long stats; ! long traceBufSize; long maxcpus; ! long ltt, ltto; long rx_mtu, rx_nojumbo; long virtualCache; ! char rootCellName[256]; ! struct rx_service *serverp; ! static struct rx_securityClass *nullServerSecurityClassp; ! struct hostent *thp; ! char *msgBuf; ! char buf[200]; ! HKEY parmKey; ! DWORD dummyLen; DWORD regType; ! long code; ! /*int freelanceEnabled;*/ ! WSADATA WSAjunk; lana_number_t lanaNum; int i; ! WSAStartup(0x0101, &WSAjunk); afsd_initUpperCaseTable(); ! /* setup osidebug server at RPC slot 1000 */ ! osi_LongToUID(1000, &debugID); ! code = osi_InitDebug(&debugID); ! afsi_log("osi_InitDebug code %d", code); // osi_LockTypeSetDefault("stat"); /* comment this out for speed * ! if (code != 0) { ! *reasonP = "unknown error"; ! return -1; ! } ! /* who are we ? */ ! gethostname(cm_HostName, sizeof(cm_HostName)); ! afsi_log("gethostname %s", cm_HostName); ! thp = gethostbyname(cm_HostName); ! memcpy(&cm_HostAddr, thp->h_addr_list[0], 4); ! ! /* seed random number generator */ ! srand(ntohl(cm_HostAddr)); ! ! /* Look up configuration parameters in Registry */ ! code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName, ! 0, KEY_QUERY_VALUE, &parmKey); ! if (code != ERROR_SUCCESS) { ! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM ! | FORMAT_MESSAGE_ALLOCATE_BUFFER, ! NULL, code, 0, (LPTSTR)&msgBuf, 0, NULL); ! StringCbPrintfA(buf, sizeof(buf), ! "Failure in configuration while opening Registry: %s", ! msgBuf); ! osi_panic(buf, __FILE__, __LINE__); ! } dummyLen = sizeof(maxcpus); ! code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL, ! (BYTE *) &maxcpus, &dummyLen); ! if (code == ERROR_SUCCESS) { HANDLE hProcess; DWORD_PTR processAffinityMask, systemAffinityMask; --- 358,429 ---- int afsd_InitCM(char **reasonP) { ! osi_uid_t debugID; ! long cacheBlocks; ! long cacheSize; ! long logChunkSize; ! long stats; ! long traceBufSize; long maxcpus; ! long ltt, ltto; long rx_mtu, rx_nojumbo; long virtualCache; ! char rootCellName[256]; ! struct rx_service *serverp; ! static struct rx_securityClass *nullServerSecurityClassp; ! struct hostent *thp; ! char *msgBuf; ! char buf[1024]; ! HKEY parmKey; ! DWORD dummyLen; DWORD regType; ! long code; ! /*int freelanceEnabled;*/ ! WSADATA WSAjunk; lana_number_t lanaNum; int i; ! WSAStartup(0x0101, &WSAjunk); afsd_initUpperCaseTable(); ! /* setup osidebug server at RPC slot 1000 */ ! osi_LongToUID(1000, &debugID); ! code = osi_InitDebug(&debugID); ! afsi_log("osi_InitDebug code %d", code); // osi_LockTypeSetDefault("stat"); /* comment this out for speed * ! if (code != 0) { ! *reasonP = "unknown error"; ! return -1; ! } ! /* who are we ? */ ! gethostname(cm_HostName, sizeof(cm_HostName)); ! afsi_log("gethostname %s", cm_HostName); ! thp = gethostbyname(cm_HostName); ! memcpy(&cm_HostAddr, thp->h_addr_list[0], 4); ! ! /* seed random number generator */ ! srand(ntohl(cm_HostAddr)); ! ! /* Look up configuration parameters in Registry */ ! code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName, ! 0, KEY_QUERY_VALUE, &parmKey); ! if (code != ERROR_SUCCESS) { ! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM ! | FORMAT_MESSAGE_ALLOCATE_BUFFER, ! NULL, code, 0, (LPTSTR)&msgBuf, 0, NULL); ! StringCbPrintfA(buf, sizeof(buf), ! "Failure in configuration while opening Registry: %s", ! msgBuf); ! osi_panic(buf, __FILE__, __LINE__); ! } dummyLen = sizeof(maxcpus); ! code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL, ! (BYTE *) &maxcpus, &dummyLen); ! if (code == ERROR_SUCCESS) { HANDLE hProcess; DWORD_PTR processAffinityMask, systemAffinityMask; *************** *** 456,596 **** } } ! dummyLen = sizeof(TraceOption); ! code = RegQueryValueEx(parmKey, "TraceOption", NULL, NULL, ! (BYTE *) &TraceOption, &dummyLen); afsi_log("Event Log Tracing = %lX", TraceOption); ! dummyLen = sizeof(traceBufSize); ! code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL, ! (BYTE *) &traceBufSize, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Trace Buffer size %d", traceBufSize); ! else { ! traceBufSize = CM_CONFIGDEFAULT_TRACEBUFSIZE; ! afsi_log("Default trace buffer size %d", traceBufSize); ! } ! /* setup and enable debug log */ ! afsd_logp = osi_LogCreate("afsd", traceBufSize); ! afsi_log("osi_LogCreate log addr %x", (int)afsd_logp); osi_LogEnable(afsd_logp); ! logReady = 1; osi_Log0(afsd_logp, "Log init"); ! dummyLen = sizeof(cacheSize); ! code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL, ! (BYTE *) &cacheSize, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Cache size %d", cacheSize); ! else { ! cacheSize = CM_CONFIGDEFAULT_CACHESIZE; ! afsi_log("Default cache size %d", cacheSize); ! } ! dummyLen = sizeof(logChunkSize); ! code = RegQueryValueEx(parmKey, "ChunkSize", NULL, NULL, ! (BYTE *) &logChunkSize, &dummyLen); ! if (code == ERROR_SUCCESS) { ! if (logChunkSize < 12 || logChunkSize > 30) { ! afsi_log("Invalid chunk size %d, using default", ! logChunkSize); ! logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE; ! } ! afsi_log("Chunk size %d", logChunkSize); ! } else { ! logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE; ! afsi_log("Default chunk size %d", logChunkSize); ! } ! cm_logChunkSize = logChunkSize; ! cm_chunkSize = 1 << logChunkSize; ! dummyLen = sizeof(numBkgD); ! code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL, ! (BYTE *) &numBkgD, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("%d background daemons", numBkgD); ! else { ! numBkgD = CM_CONFIGDEFAULT_DAEMONS; ! afsi_log("Defaulting to %d background daemons", numBkgD); ! } ! dummyLen = sizeof(numSvThreads); ! code = RegQueryValueEx(parmKey, "ServerThreads", NULL, NULL, ! (BYTE *) &numSvThreads, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("%d server threads", numSvThreads); ! else { ! numSvThreads = CM_CONFIGDEFAULT_SVTHREADS; ! afsi_log("Defaulting to %d server threads", numSvThreads); ! } ! dummyLen = sizeof(stats); ! code = RegQueryValueEx(parmKey, "Stats", NULL, NULL, ! (BYTE *) &stats, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Status cache size %d", stats); ! else { ! stats = CM_CONFIGDEFAULT_STATS; ! afsi_log("Default status cache size %d", stats); ! } ! dummyLen = sizeof(ltt); ! code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL, ! (BYTE *) <t, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Logoff token transfer %s", (ltt ? "on" : "off")); ! else { ! ltt = 1; ! afsi_log("Logoff token transfer on by default"); ! } smb_LogoffTokenTransfer = ltt; afsi_log("Logoff token transfer is currently ignored"); ! if (ltt) { ! dummyLen = sizeof(ltto); ! code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout", ! NULL, NULL, (BYTE *) <to, &dummyLen); ! if (code == ERROR_SUCCESS) afsi_log("Logoff token tranfer timeout %d seconds", ltto); ! else { ! ltto = 10; ! afsi_log("Default logoff token transfer timeout 10 seconds"); ! } ! } else { ltto = 0; ! } smb_LogoffTransferTimeout = ltto; afsi_log("Default logoff token is currently ignored"); ! dummyLen = sizeof(cm_rootVolumeName); ! code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL, ! cm_rootVolumeName, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Root volume %s", cm_rootVolumeName); ! else { ! StringCbCopyA(cm_rootVolumeName, sizeof(cm_rootVolumeName), "root.afs"); ! afsi_log("Default root volume name root.afs"); ! } ! cm_mountRootLen = sizeof(cm_mountRoot); ! code = RegQueryValueEx(parmKey, "MountRoot", NULL, NULL, ! cm_mountRoot, &cm_mountRootLen); ! if (code == ERROR_SUCCESS) { ! afsi_log("Mount root %s", cm_mountRoot); ! cm_mountRootLen = strlen(cm_mountRoot); ! } else { ! StringCbCopyA(cm_mountRoot, sizeof(cm_mountRoot), "/afs"); ! cm_mountRootLen = 4; ! /* Don't log */ ! } ! dummyLen = sizeof(buf); ! code = RegQueryValueEx(parmKey, "CachePath", NULL, ®Type, ! buf, &dummyLen); if (code == ERROR_SUCCESS && buf[0]) { ! if(regType == REG_EXPAND_SZ) { dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath)); if(dummyLen > sizeof(cm_CachePath)) { afsi_log("Cache path [%s] longer than %d after expanding env strings", buf, sizeof(cm_CachePath)); --- 456,596 ---- } } ! dummyLen = sizeof(TraceOption); ! code = RegQueryValueEx(parmKey, "TraceOption", NULL, NULL, ! (BYTE *) &TraceOption, &dummyLen); afsi_log("Event Log Tracing = %lX", TraceOption); ! dummyLen = sizeof(traceBufSize); ! code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL, ! (BYTE *) &traceBufSize, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Trace Buffer size %d", traceBufSize); ! else { ! traceBufSize = CM_CONFIGDEFAULT_TRACEBUFSIZE; ! afsi_log("Default trace buffer size %d", traceBufSize); ! } ! /* setup and enable debug log */ ! afsd_logp = osi_LogCreate("afsd", traceBufSize); ! afsi_log("osi_LogCreate log addr %x", (int)afsd_logp); osi_LogEnable(afsd_logp); ! logReady = 1; osi_Log0(afsd_logp, "Log init"); ! dummyLen = sizeof(cacheSize); ! code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL, ! (BYTE *) &cacheSize, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Cache size %d", cacheSize); ! else { ! cacheSize = CM_CONFIGDEFAULT_CACHESIZE; ! afsi_log("Default cache size %d", cacheSize); ! } ! dummyLen = sizeof(logChunkSize); ! code = RegQueryValueEx(parmKey, "ChunkSize", NULL, NULL, ! (BYTE *) &logChunkSize, &dummyLen); ! if (code == ERROR_SUCCESS) { ! if (logChunkSize < 12 || logChunkSize > 30) { ! afsi_log("Invalid chunk size %d, using default", ! logChunkSize); ! logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE; ! } ! afsi_log("Chunk size %d", logChunkSize); ! } else { ! logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE; ! afsi_log("Default chunk size %d", logChunkSize); ! } ! cm_logChunkSize = logChunkSize; ! cm_chunkSize = 1 << logChunkSize; ! dummyLen = sizeof(numBkgD); ! code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL, ! (BYTE *) &numBkgD, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("%d background daemons", numBkgD); ! else { ! numBkgD = CM_CONFIGDEFAULT_DAEMONS; ! afsi_log("Defaulting to %d background daemons", numBkgD); ! } ! dummyLen = sizeof(numSvThreads); ! code = RegQueryValueEx(parmKey, "ServerThreads", NULL, NULL, ! (BYTE *) &numSvThreads, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("%d server threads", numSvThreads); ! else { ! numSvThreads = CM_CONFIGDEFAULT_SVTHREADS; ! afsi_log("Defaulting to %d server threads", numSvThreads); ! } ! dummyLen = sizeof(stats); ! code = RegQueryValueEx(parmKey, "Stats", NULL, NULL, ! (BYTE *) &stats, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Status cache size %d", stats); ! else { ! stats = CM_CONFIGDEFAULT_STATS; ! afsi_log("Default status cache size %d", stats); ! } ! dummyLen = sizeof(ltt); ! code = RegQueryValueEx(parmKey, "LogoffTokenTransfer", NULL, NULL, ! (BYTE *) <t, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Logoff token transfer %s", (ltt ? "on" : "off")); ! else { ! ltt = 1; ! afsi_log("Logoff token transfer on by default"); ! } smb_LogoffTokenTransfer = ltt; afsi_log("Logoff token transfer is currently ignored"); ! if (ltt) { ! dummyLen = sizeof(ltto); ! code = RegQueryValueEx(parmKey, "LogoffTokenTransferTimeout", ! NULL, NULL, (BYTE *) <to, &dummyLen); ! if (code == ERROR_SUCCESS) afsi_log("Logoff token tranfer timeout %d seconds", ltto); ! else { ! ltto = 10; ! afsi_log("Default logoff token transfer timeout 10 seconds"); ! } ! } else { ltto = 0; ! } smb_LogoffTransferTimeout = ltto; afsi_log("Default logoff token is currently ignored"); ! dummyLen = sizeof(cm_rootVolumeName); ! code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL, ! cm_rootVolumeName, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Root volume %s", cm_rootVolumeName); ! else { ! StringCbCopyA(cm_rootVolumeName, sizeof(cm_rootVolumeName), "root.afs"); ! afsi_log("Default root volume name root.afs"); ! } ! cm_mountRootLen = sizeof(cm_mountRoot); ! code = RegQueryValueEx(parmKey, "MountRoot", NULL, NULL, ! cm_mountRoot, &cm_mountRootLen); ! if (code == ERROR_SUCCESS) { ! afsi_log("Mount root %s", cm_mountRoot); ! cm_mountRootLen = strlen(cm_mountRoot); ! } else { ! StringCbCopyA(cm_mountRoot, sizeof(cm_mountRoot), "/afs"); ! cm_mountRootLen = 4; ! /* Don't log */ ! } ! dummyLen = sizeof(buf); ! code = RegQueryValueEx(parmKey, "CachePath", NULL, ®Type, ! buf, &dummyLen); if (code == ERROR_SUCCESS && buf[0]) { ! if (regType == REG_EXPAND_SZ) { dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath)); if(dummyLen > sizeof(cm_CachePath)) { afsi_log("Cache path [%s] longer than %d after expanding env strings", buf, sizeof(cm_CachePath)); *************** *** 599,615 **** } else { StringCbCopyA(cm_CachePath, sizeof(cm_CachePath), buf); } ! afsi_log("Cache path %s", cm_CachePath); } else { ! GetWindowsDirectory(cm_CachePath, sizeof(cm_CachePath)); ! cm_CachePath[2] = 0; /* get drive letter only */ ! StringCbCatA(cm_CachePath, sizeof(cm_CachePath), "\\AFSCache"); ! afsi_log("Default cache path %s", cm_CachePath); ! } dummyLen = sizeof(virtualCache); code = RegQueryValueEx(parmKey, "NonPersistentCaching", NULL, NULL, ! &virtualCache, &dummyLen); if (code == ERROR_SUCCESS && virtualCache) { buf_cacheType = CM_BUF_CACHETYPE_VIRTUAL; } else { --- 599,615 ---- } else { StringCbCopyA(cm_CachePath, sizeof(cm_CachePath), buf); } ! afsi_log("Cache path %s", cm_CachePath); } else { ! GetWindowsDirectory(cm_CachePath, sizeof(cm_CachePath)); ! cm_CachePath[2] = 0; /* get drive letter only */ ! StringCbCatA(cm_CachePath, sizeof(cm_CachePath), "\\AFSCache"); ! afsi_log("Default cache path %s", cm_CachePath); ! } dummyLen = sizeof(virtualCache); code = RegQueryValueEx(parmKey, "NonPersistentCaching", NULL, NULL, ! &virtualCache, &dummyLen); if (code == ERROR_SUCCESS && virtualCache) { buf_cacheType = CM_BUF_CACHETYPE_VIRTUAL; } else { *************** *** 617,643 **** } afsi_log("Cache type is %s", ((buf_cacheType == CM_BUF_CACHETYPE_FILE)?"FILE":"VIRTUAL")); ! dummyLen = sizeof(traceOnPanic); ! code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL, ! (BYTE *) &traceOnPanic, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Set to %s on panic", ! traceOnPanic ? "trap" : "not trap"); ! else { ! traceOnPanic = 0; ! /* Don't log */ ! } ! ! dummyLen = sizeof(reportSessionStartups); ! code = RegQueryValueEx(parmKey, "ReportSessionStartups", NULL, NULL, ! (BYTE *) &reportSessionStartups, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Session startups %s be recorded in the Event Log", ! reportSessionStartups ? "will" : "will not"); ! else { ! reportSessionStartups = 0; ! /* Don't log */ ! } for ( i=0; i < MAXNUMSYSNAMES; i++ ) { cm_sysNameList[i] = osi_Alloc(MAXSYSNAME); --- 617,643 ---- } afsi_log("Cache type is %s", ((buf_cacheType == CM_BUF_CACHETYPE_FILE)?"FILE":"VIRTUAL")); ! dummyLen = sizeof(traceOnPanic); ! code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL, ! (BYTE *) &traceOnPanic, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Set to %s on panic", ! traceOnPanic ? "trap" : "not trap"); ! else { ! traceOnPanic = 0; ! /* Don't log */ ! } ! ! dummyLen = sizeof(reportSessionStartups); ! code = RegQueryValueEx(parmKey, "ReportSessionStartups", NULL, NULL, ! (BYTE *) &reportSessionStartups, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Session startups %s be recorded in the Event Log", ! reportSessionStartups ? "will" : "will not"); ! else { ! reportSessionStartups = 0; ! /* Don't log */ ! } for ( i=0; i < MAXNUMSYSNAMES; i++ ) { cm_sysNameList[i] = osi_Alloc(MAXSYSNAME); *************** *** 645,697 **** } cm_sysName = cm_sysNameList[0]; ! dummyLen = MAXSYSNAME; ! code = RegQueryValueEx(parmKey, "SysName", NULL, NULL, cm_sysName, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("Sys name %s", cm_sysName); ! else { ! StringCbCopyA(cm_sysName, MAXSYSNAME, "i386_nt40"); ! afsi_log("Default sys name %s", cm_sysName); ! } ! cm_sysNameCount = 1; ! dummyLen = sizeof(cryptall); ! code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL, ! (BYTE *) &cryptall, &dummyLen); ! if (code == ERROR_SUCCESS) ! afsi_log("SecurityLevel is %s", cryptall?"crypt":"clear"); ! else { ! cryptall = rxkad_clear; ! afsi_log("Default SecurityLevel is clear"); ! } #ifdef AFS_AFSDB_ENV ! dummyLen = sizeof(cm_dnsEnabled); ! code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL, ! (BYTE *) &cm_dnsEnabled, &dummyLen); ! if (code == ERROR_SUCCESS) { ! afsi_log("DNS %s be used to find AFS cell servers", ! cm_dnsEnabled ? "will" : "will not"); ! } ! else { ! cm_dnsEnabled = 1; /* default on */ ! afsi_log("Default to use DNS to find AFS cell servers"); ! } #else /* AFS_AFSDB_ENV */ ! afsi_log("AFS not built with DNS support to find AFS cell servers"); #endif /* AFS_AFSDB_ENV */ #ifdef AFS_FREELANCE_CLIENT ! dummyLen = sizeof(cm_freelanceEnabled); ! code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL, ! (BYTE *) &cm_freelanceEnabled, &dummyLen); ! if (code == ERROR_SUCCESS) { ! afsi_log("Freelance client feature %s activated", ! cm_freelanceEnabled ? "is" : "is not"); ! } ! else { ! cm_freelanceEnabled = 0; /* default off */ ! } #endif /* AFS_FREELANCE_CLIENT */ #ifdef COMMENT --- 645,719 ---- } cm_sysName = cm_sysNameList[0]; ! dummyLen = sizeof(buf); ! code = RegQueryValueEx(parmKey, "SysName", NULL, NULL, buf, &dummyLen); ! if (code == ERROR_SUCCESS && buf[0]) { ! char * p, *q; ! afsi_log("Sys name %s", buf); ! for (p = q = buf; p < cm_sysName + dummyLen; p++) ! { ! if (*p == '\0' || isspace(*p)) { ! memcpy(cm_sysNameList[cm_sysNameCount],q,p-q); ! cm_sysNameList[cm_sysNameCount][p-q] = '\0'; ! cm_sysNameCount++; ! ! do { ! if (*p == '\0') ! goto done_sysname; ! ! p++; ! } while (*p == '\0' || isspace(*p)); ! q = p; ! p--; ! } ! } ! done_sysname: ! StringCbCopyA(cm_sysName, MAXSYSNAME, cm_sysNameList[0]); ! } else { ! cm_sysNameCount = 1; ! StringCbCopyA(cm_sysName, MAXSYSNAME, "i386_nt40"); ! StringCbCopyA(cm_sysNameList[0], MAXSYSNAME, "i386_nt40"); ! afsi_log("Default sys name %s", cm_sysName); ! } ! ! dummyLen = sizeof(cryptall); ! code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL, ! (BYTE *) &cryptall, &dummyLen); ! if (code == ERROR_SUCCESS) { ! afsi_log("SecurityLevel is %s", cryptall?"crypt":"clear"); ! } else { ! cryptall = 0; ! afsi_log("Default SecurityLevel is clear"); ! } #ifdef AFS_AFSDB_ENV ! dummyLen = sizeof(cm_dnsEnabled); ! code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL, ! (BYTE *) &cm_dnsEnabled, &dummyLen); ! if (code == ERROR_SUCCESS) { ! afsi_log("DNS %s be used to find AFS cell servers", ! cm_dnsEnabled ? "will" : "will not"); ! } ! else { ! cm_dnsEnabled = 1; /* default on */ ! afsi_log("Default to use DNS to find AFS cell servers"); ! } #else /* AFS_AFSDB_ENV */ ! afsi_log("AFS not built with DNS support to find AFS cell servers"); #endif /* AFS_AFSDB_ENV */ #ifdef AFS_FREELANCE_CLIENT ! dummyLen = sizeof(cm_freelanceEnabled); ! code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL, ! (BYTE *) &cm_freelanceEnabled, &dummyLen); ! if (code == ERROR_SUCCESS) { ! afsi_log("Freelance client feature %s activated", ! cm_freelanceEnabled ? "is" : "is not"); ! } ! else { ! cm_freelanceEnabled = 0; /* default off */ ! } #endif /* AFS_FREELANCE_CLIENT */ #ifdef COMMENT *************** *** 738,752 **** } afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer); ! dummyLen = sizeof(smb_authType); ! code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL, ! (BYTE *) &smb_authType, &dummyLen); ! ! if (code != ERROR_SUCCESS || ! (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) { ! smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */ ! } ! afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM"))); dummyLen = sizeof(rx_nojumbo); code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL, --- 760,774 ---- } afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer); ! dummyLen = sizeof(smb_authType); ! code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL, ! (BYTE *) &smb_authType, &dummyLen); ! ! if (code != ERROR_SUCCESS || ! (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) { ! smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */ ! } ! afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM"))); dummyLen = sizeof(rx_nojumbo); code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL, *************** *** 754,760 **** if (code != ERROR_SUCCESS) { rx_nojumbo = 0; } ! if(rx_nojumbo) afsi_log("RX Jumbograms are disabled"); dummyLen = sizeof(rx_mtu); --- 776,782 ---- if (code != ERROR_SUCCESS) { rx_nojumbo = 0; } ! if (rx_nojumbo) afsi_log("RX Jumbograms are disabled"); dummyLen = sizeof(rx_mtu); *************** *** 763,769 **** if (code != ERROR_SUCCESS || !rx_mtu) { rx_mtu = -1; } ! if(rx_mtu != -1) afsi_log("RX maximum MTU is %d", rx_mtu); dummyLen = sizeof(ConnDeadtimeout); --- 785,791 ---- if (code != ERROR_SUCCESS || !rx_mtu) { rx_mtu = -1; } ! if (rx_mtu != -1) afsi_log("RX maximum MTU is %d", rx_mtu); dummyLen = sizeof(ConnDeadtimeout); *************** *** 776,793 **** (BYTE *) &HardDeadtimeout, &dummyLen); afsi_log("HardDeadTimeout is %d", HardDeadtimeout); ! RegCloseKey (parmKey); /* Call lanahelper to get Netbios name, lan adapter number and gateway flag */ if(SUCCEEDED(code = lana_GetUncServerNameEx(cm_NetbiosName, &lanaNum, &isGateway, LANA_NETBIOS_NAME_FULL))) { LANadapter = (lanaNum == LANA_INVALID)? -1: lanaNum; ! if(LANadapter != -1) afsi_log("LAN adapter number %d", LANadapter); else afsi_log("LAN adapter number not determined"); ! if(isGateway) afsi_log("Set for gateway service"); afsi_log("Using >%s< as SMB server name", cm_NetbiosName); --- 798,815 ---- (BYTE *) &HardDeadtimeout, &dummyLen); afsi_log("HardDeadTimeout is %d", HardDeadtimeout); ! RegCloseKey (parmKey); /* Call lanahelper to get Netbios name, lan adapter number and gateway flag */ if(SUCCEEDED(code = lana_GetUncServerNameEx(cm_NetbiosName, &lanaNum, &isGateway, LANA_NETBIOS_NAME_FULL))) { LANadapter = (lanaNum == LANA_INVALID)? -1: lanaNum; ! if (LANadapter != -1) afsi_log("LAN adapter number %d", LANadapter); else afsi_log("LAN adapter number not determined"); ! if (isGateway) afsi_log("Set for gateway service"); afsi_log("Using >%s< as SMB server name", cm_NetbiosName); *************** *** 797,834 **** osi_panic(buf, __FILE__, __LINE__); } ! /* setup early variables */ ! /* These both used to be configurable. */ ! smb_UseV3 = 1; buf_bufferSize = CM_CONFIGDEFAULT_BLOCKSIZE; ! /* turn from 1024 byte units into memory blocks */ cacheBlocks = (cacheSize * 1024) / buf_bufferSize; ! /* get network related info */ ! cm_noIPAddr = CM_MAXINTERFACE_ADDR; ! code = syscfg_GetIFInfo(&cm_noIPAddr, ! cm_IPAddr, cm_SubnetMask, ! cm_NetMtu, cm_NetFlags); ! if ( (cm_noIPAddr <= 0) || (code <= 0 ) ) ! afsi_log("syscfg_GetIFInfo error code %d", code); ! else ! afsi_log("First Network address %x SubnetMask %x", ! cm_IPAddr[0], cm_SubnetMask[0]); ! /* ! * Save client configuration for GetCacheConfig requests ! */ ! cm_initParams.nChunkFiles = 0; ! cm_initParams.nStatCaches = stats; ! cm_initParams.nDataCaches = 0; ! cm_initParams.nVolumeCaches = 0; ! cm_initParams.firstChunkSize = cm_chunkSize; ! cm_initParams.otherChunkSize = cm_chunkSize; ! cm_initParams.cacheSize = cacheSize; ! cm_initParams.setTime = 0; ! cm_initParams.memCache = 0; /* Set RX parameters before initializing RX */ if ( rx_nojumbo ) { --- 819,856 ---- osi_panic(buf, __FILE__, __LINE__); } ! /* setup early variables */ ! /* These both used to be configurable. */ ! smb_UseV3 = 1; buf_bufferSize = CM_CONFIGDEFAULT_BLOCKSIZE; ! /* turn from 1024 byte units into memory blocks */ cacheBlocks = (cacheSize * 1024) / buf_bufferSize; ! /* get network related info */ ! cm_noIPAddr = CM_MAXINTERFACE_ADDR; ! code = syscfg_GetIFInfo(&cm_noIPAddr, ! cm_IPAddr, cm_SubnetMask, ! cm_NetMtu, cm_NetFlags); ! if ( (cm_noIPAddr <= 0) || (code <= 0 ) ) ! afsi_log("syscfg_GetIFInfo error code %d", code); ! else ! afsi_log("First Network address %x SubnetMask %x", ! cm_IPAddr[0], cm_SubnetMask[0]); ! /* ! * Save client configuration for GetCacheConfig requests ! */ ! cm_initParams.nChunkFiles = 0; ! cm_initParams.nStatCaches = stats; ! cm_initParams.nDataCaches = 0; ! cm_initParams.nVolumeCaches = 0; ! cm_initParams.firstChunkSize = cm_chunkSize; ! cm_initParams.otherChunkSize = cm_chunkSize; ! cm_initParams.cacheSize = cacheSize; ! cm_initParams.setTime = 0; ! cm_initParams.memCache = 0; /* Set RX parameters before initializing RX */ if ( rx_nojumbo ) { *************** *** 847,894 **** /* Ensure the AFS Netbios Name is registered to allow loopback access */ configureBackConnectionHostNames(); ! /* initialize RX, and tell it to listen to port 7001, which is used for * callback RPC messages. */ ! code = rx_Init(htons(7001)); ! afsi_log("rx_Init code %x", code); ! if (code != 0) { ! *reasonP = "afsd: failed to init rx client on port 7001"; ! return -1; ! } ! /* Initialize the RPC server for session keys */ ! RpcInit(); ! /* create an unauthenticated service #1 for callbacks */ ! nullServerSecurityClassp = rxnull_NewServerSecurityObject(); serverp = rx_NewService(0, 1, "AFS", &nullServerSecurityClassp, 1, ! RXAFSCB_ExecuteRequest); ! afsi_log("rx_NewService addr %x", (int)serverp); ! if (serverp == NULL) { ! *reasonP = "unknown error"; ! return -1; ! } ! nullServerSecurityClassp = rxnull_NewServerSecurityObject(); serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", ! &nullServerSecurityClassp, 1, RXSTATS_ExecuteRequest); ! afsi_log("rx_NewService addr %x", (int)serverp); ! if (serverp == NULL) { ! *reasonP = "unknown error"; ! return -1; ! } /* start server threads, *not* donating this one to the pool */ rx_StartServer(0); ! afsi_log("rx_StartServer"); ! /* init user daemon, and other packages */ ! cm_InitUser(); ! cm_InitACLCache(2*stats); ! cm_InitConn(); cm_InitCell(); --- 869,916 ---- /* Ensure the AFS Netbios Name is registered to allow loopback access */ configureBackConnectionHostNames(); ! /* initialize RX, and tell it to listen to port 7001, which is used for * callback RPC messages. */ ! code = rx_Init(htons(7001)); ! afsi_log("rx_Init code %x", code); ! if (code != 0) { ! *reasonP = "afsd: failed to init rx client on port 7001"; ! return -1; ! } ! /* Initialize the RPC server for session keys */ ! RpcInit(); ! /* create an unauthenticated service #1 for callbacks */ ! nullServerSecurityClassp = rxnull_NewServerSecurityObject(); serverp = rx_NewService(0, 1, "AFS", &nullServerSecurityClassp, 1, ! RXAFSCB_ExecuteRequest); ! afsi_log("rx_NewService addr %x", (int)serverp); ! if (serverp == NULL) { ! *reasonP = "unknown error"; ! return -1; ! } ! nullServerSecurityClassp = rxnull_NewServerSecurityObject(); serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", ! &nullServerSecurityClassp, 1, RXSTATS_ExecuteRequest); ! afsi_log("rx_NewService addr %x", (int)serverp); ! if (serverp == NULL) { ! *reasonP = "unknown error"; ! return -1; ! } /* start server threads, *not* donating this one to the pool */ rx_StartServer(0); ! afsi_log("rx_StartServer"); ! /* init user daemon, and other packages */ ! cm_InitUser(); ! cm_InitACLCache(2*stats); ! cm_InitConn(); cm_InitCell(); *************** *** 905,932 **** cm_InitSCache(stats); code = cm_InitDCache(0, cacheBlocks); ! afsi_log("cm_InitDCache code %x", code); ! if (code != 0) { ! *reasonP = "error initializing cache"; ! return -1; ! } #ifdef AFS_AFSDB_ENV #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500) ! if (cm_InitDNS(cm_dnsEnabled) == -1) ! cm_dnsEnabled = 0; /* init failed, so deactivate */ ! afsi_log("cm_InitDNS %d", cm_dnsEnabled); #endif #endif ! code = cm_GetRootCellName(rootCellName); ! afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s", ! code, cm_freelanceEnabled, (code ? "" : rootCellName)); ! if (code != 0 && !cm_freelanceEnabled) { ! *reasonP = "can't find root cell name in afsd.ini"; ! return -1; ! } else if (cm_freelanceEnabled) cm_rootCellp = NULL; --- 927,954 ---- cm_InitSCache(stats); code = cm_InitDCache(0, cacheBlocks); ! afsi_log("cm_InitDCache code %x", code); ! if (code != 0) { ! *reasonP = "error initializing cache"; ! return -1; ! } #ifdef AFS_AFSDB_ENV #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500) ! if (cm_InitDNS(cm_dnsEnabled) == -1) ! cm_dnsEnabled = 0; /* init failed, so deactivate */ ! afsi_log("cm_InitDNS %d", cm_dnsEnabled); #endif #endif ! code = cm_GetRootCellName(rootCellName); ! afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s", ! code, cm_freelanceEnabled, (code ? "" : rootCellName)); ! if (code != 0 && !cm_freelanceEnabled) { ! *reasonP = "can't find root cell name in afsd.ini"; ! return -1; ! } else if (cm_freelanceEnabled) cm_rootCellp = NULL; *************** *** 939,952 **** *reasonP = "can't find root cell in afsdcell.ini"; return -1; } ! } ! #ifdef AFS_FREELANCE_CLIENT ! if (cm_freelanceEnabled) ! cm_InitFreelance(); #endif ! return 0; } int afsd_InitDaemons(char **reasonP) --- 961,973 ---- *reasonP = "can't find root cell in afsdcell.ini"; return -1; } ! } #ifdef AFS_FREELANCE_CLIENT ! if (cm_freelanceEnabled) ! cm_InitFreelance(); #endif ! return 0; } int afsd_InitDaemons(char **reasonP) Index: openafs/src/WINNT/afsd/afsd_service.c diff -c openafs/src/WINNT/afsd/afsd_service.c:1.28 openafs/src/WINNT/afsd/afsd_service.c:1.28.2.2 *** openafs/src/WINNT/afsd/afsd_service.c:1.28 Sat Jul 24 11:25:35 2004 --- openafs/src/WINNT/afsd/afsd_service.c Mon Oct 18 00:09:25 2004 *************** *** 32,38 **** // The following is defined if you want to receive Power notifications, // including Hibernation, and also subsequent flushing of AFS volumes // ! #define REGISTER_POWER_NOTIFICATIONS // // Check */ --- 32,39 ---- // The following is defined if you want to receive Power notifications, // including Hibernation, and also subsequent flushing of AFS volumes // ! #define REGISTER_POWER_NOTIFICATIONS 1 ! #define FLUSH_VOLUME 1 // // Check */ *************** *** 54,84 **** extern int traceOnPanic; extern HANDLE afsi_file; /* * Notifier function for use by osi_panic */ static void afsd_notifier(char *msgp, char *filep, long line) { ! char tbuffer[512]; ! char *ptbuf[1]; ! HANDLE h; ! ! if (filep) ! sprintf(tbuffer, "Error at file %s, line %d: %s", ! filep, line, msgp); ! else ! sprintf(tbuffer, "Error at unknown location: %s", msgp); ! h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); ! ptbuf[0] = tbuffer; ! ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, line, NULL, 1, 0, ptbuf, NULL); ! DeregisterEventSource(h); ! GlobalStatus = line; ! osi_LogEnable(afsd_logp); ! afsd_ForceTrace(TRUE); afsi_log("--- begin dump ---"); cm_DumpSCache(afsi_file, "a"); --- 55,87 ---- extern int traceOnPanic; extern HANDLE afsi_file; + int powerEventsRegistered = 0; + /* * Notifier function for use by osi_panic */ static void afsd_notifier(char *msgp, char *filep, long line) { ! char tbuffer[512]; ! char *ptbuf[1]; ! HANDLE h; ! ! if (filep) ! sprintf(tbuffer, "Error at file %s, line %d: %s", ! filep, line, msgp); ! else ! sprintf(tbuffer, "Error at unknown location: %s", msgp); ! h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); ! ptbuf[0] = tbuffer; ! ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, line, NULL, 1, 0, ptbuf, NULL); ! DeregisterEventSource(h); ! GlobalStatus = line; ! osi_LogEnable(afsd_logp); ! afsd_ForceTrace(TRUE); afsi_log("--- begin dump ---"); cm_DumpSCache(afsi_file, "a"); *************** *** 91,104 **** DebugBreak(); ! SetEvent(WaitToTerminate); #ifdef JUMP ! if (GetCurrentThreadId() == MainThreadId) ! longjmp(notifier_jmp, 1); ! else #endif /* JUMP */ ! ExitThread(1); } /* --- 94,107 ---- DebugBreak(); ! SetEvent(WaitToTerminate); #ifdef JUMP ! if (GetCurrentThreadId() == MainThreadId) ! longjmp(notifier_jmp, 1); ! else #endif /* JUMP */ ! ExitThread(1); } /* *************** *** 106,112 **** */ static int _stdcall DummyMessageBox(HWND h, LPCTSTR l1, LPCTSTR l2, UINT ui) { ! return 0; } static SERVICE_STATUS ServiceStatus; --- 109,115 ---- */ static int _stdcall DummyMessageBox(HWND h, LPCTSTR l1, LPCTSTR l2, UINT ui) { ! return 0; } static SERVICE_STATUS ServiceStatus; *************** *** 130,136 **** { dwRet = NO_ERROR; } - else { /* flush was unsuccessful, or timeout - deny shutdown */ --- 133,138 ---- *************** *** 151,203 **** 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 */ ! } ! } /* --- 153,205 ---- 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 */ ! } ! } /* *************** *** 212,223 **** LPVOID lpContext ) { ! HKEY parmKey; ! DWORD dummyLen, doTrace; ! long code; DWORD dwRet = ERROR_CALL_NOT_IMPLEMENTED; ! switch (ctrlCode) { case SERVICE_CONTROL_STOP: /* Shutdown RPC */ --- 214,225 ---- LPVOID lpContext ) { ! HKEY parmKey; ! DWORD dummyLen, doTrace; ! long code; DWORD dwRet = ERROR_CALL_NOT_IMPLEMENTED; ! switch (ctrlCode) { case SERVICE_CONTROL_STOP: /* Shutdown RPC */ *************** *** 261,305 **** dwRet = NO_ERROR; break; ! /* XXX handle system shutdown */ ! /* XXX handle pause & continue */ ! case SERVICE_CONTROL_POWEREVENT: ! { ! /* ** dwEventType of this notification == WPARAM of WM_POWERBROADCAST ! ** Return NO_ERROR == return TRUE for that message, i.e. accept request ! ** Return any error code to deny request, ! ** i.e. as if returning BROADCAST_QUERY_DENY ! */ ! switch((int) dwEventType) ! { ! case PBT_APMQUERYSUSPEND: ! case PBT_APMQUERYSTANDBY: ! ! #ifdef REGISTER_POWER_NOTIFICATIONS ! /* handle event */ ! dwRet = afsd_ServiceFlushVolume((DWORD) lpEventData); #else ! dwRet = NO_ERROR; #endif ! break; ! /* allow remaining case PBT_WhatEver */ ! case PBT_APMSUSPEND: ! case PBT_APMSTANDBY: ! case PBT_APMRESUMECRITICAL: ! case PBT_APMRESUMESUSPEND: ! case PBT_APMRESUMESTANDBY: ! case PBT_APMBATTERYLOW: ! case PBT_APMPOWERSTATUSCHANGE: ! case PBT_APMOEMEVENT: ! case PBT_APMRESUMEAUTOMATIC: ! default: ! dwRet = NO_ERROR; } } } /* end switch(ctrlCode) */ ! return dwRet; } /* There is similar code in client_config\drivemap.cpp GlobalMountDrive() --- 263,309 ---- dwRet = NO_ERROR; break; ! /* XXX handle system shutdown */ ! /* XXX handle pause & continue */ ! case SERVICE_CONTROL_POWEREVENT: ! { ! /* ** dwEventType of this notification == WPARAM of WM_POWERBROADCAST ! ** Return NO_ERROR == return TRUE for that message, i.e. accept request ! ** Return any error code to deny request, ! ** i.e. as if returning BROADCAST_QUERY_DENY ! */ ! if (powerEventsRegistered) { ! switch((int) dwEventType) ! { ! case PBT_APMQUERYSUSPEND: ! case PBT_APMQUERYSTANDBY: ! ! #ifdef FLUSH_VOLUME ! /* handle event */ ! dwRet = afsd_ServiceFlushVolume((DWORD) lpEventData); #else ! dwRet = NO_ERROR; #endif ! break; ! /* allow remaining case PBT_WhatEver */ ! case PBT_APMSUSPEND: ! case PBT_APMSTANDBY: ! case PBT_APMRESUMECRITICAL: ! case PBT_APMRESUMESUSPEND: ! case PBT_APMRESUMESTANDBY: ! case PBT_APMBATTERYLOW: ! case PBT_APMPOWERSTATUSCHANGE: ! case PBT_APMOEMEVENT: ! case PBT_APMRESUMEAUTOMATIC: ! default: ! dwRet = NO_ERROR; ! } } } } /* end switch(ctrlCode) */ ! return dwRet; } /* There is similar code in client_config\drivemap.cpp GlobalMountDrive() *************** *** 308,314 **** */ /* DEE Could check first if we are run as SYSTEM */ #define MAX_RETRIES 30 ! static void MountGlobalDrives() { char szAfsPath[_MAX_PATH]; char szDriveToMapTo[5]; --- 312,318 ---- */ /* DEE Could check first if we are run as SYSTEM */ #define MAX_RETRIES 30 ! static void MountGlobalDrives(void) { char szAfsPath[_MAX_PATH]; char szDriveToMapTo[5]; *************** *** 323,330 **** sprintf(szKeyName, "%s\\GlobalAutoMapper", AFSConfigKeyName); ! dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_QUERY_VALUE, &hKey); ! if (dwResult != ERROR_SUCCESS) return; while (dwRetry < MAX_RETRIES) { --- 327,334 ---- sprintf(szKeyName, "%s\\GlobalAutoMapper", AFSConfigKeyName); ! dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_QUERY_VALUE, &hKey); ! if (dwResult != ERROR_SUCCESS) return; while (dwRetry < MAX_RETRIES) { *************** *** 385,392 **** sprintf(szKeyName, "%s\\GlobalAutoMapper", AFSConfigKeyName); ! dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_QUERY_VALUE, &hKey); ! if (dwResult != ERROR_SUCCESS) return; while (1) { --- 389,396 ---- sprintf(szKeyName, "%s\\GlobalAutoMapper", AFSConfigKeyName); ! dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_QUERY_VALUE, &hKey); ! if (dwResult != ERROR_SUCCESS) return; while (1) { *************** *** 428,437 **** void afsd_Main(DWORD argc, LPTSTR *argv) { ! long code; ! char *reason; #ifdef JUMP ! int jmpret; #endif /* JUMP */ HANDLE hInitHookDll; HANDLE hAdvApi32; --- 432,441 ---- void afsd_Main(DWORD argc, LPTSTR *argv) { ! long code; ! char *reason; #ifdef JUMP ! int jmpret; #endif /* JUMP */ HANDLE hInitHookDll; HANDLE hAdvApi32; *************** *** 443,455 **** #endif osi_InitPanic(afsd_notifier); ! osi_InitTraceOption(); ! GlobalStatus = 0; ! afsi_start(); ! WaitToTerminate = CreateEvent(NULL, TRUE, FALSE, TEXT("afsd_service_WaitToTerminate")); if ( GetLastError() == ERROR_ALREADY_EXISTS ) afsi_log("Event Object Already Exists: %s", TEXT("afsd_service_WaitToTerminate")); --- 447,459 ---- #endif osi_InitPanic(afsd_notifier); ! osi_InitTraceOption(); ! GlobalStatus = 0; ! afsi_start(); ! WaitToTerminate = CreateEvent(NULL, TRUE, FALSE, TEXT("afsd_service_WaitToTerminate")); if ( GetLastError() == ERROR_ALREADY_EXISTS ) afsi_log("Event Object Already Exists: %s", TEXT("afsd_service_WaitToTerminate")); *************** *** 472,486 **** StatusHandle = RegisterServiceCtrlHandler(AFS_DAEMON_SERVICE_NAME, afsd_ServiceControlHandler); } ! ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; ! ServiceStatus.dwServiceSpecificExitCode = 0; ! ServiceStatus.dwCurrentState = SERVICE_START_PENDING; ! ServiceStatus.dwWin32ExitCode = NO_ERROR; ! ServiceStatus.dwCheckPoint = 1; ! ServiceStatus.dwWaitHint = 30000; /* accept Power Events */ ! ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_POWEREVENT; ! SetServiceStatus(StatusHandle, &ServiceStatus); #endif { --- 476,490 ---- StatusHandle = RegisterServiceCtrlHandler(AFS_DAEMON_SERVICE_NAME, afsd_ServiceControlHandler); } ! ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; ! ServiceStatus.dwServiceSpecificExitCode = 0; ! ServiceStatus.dwCurrentState = SERVICE_START_PENDING; ! ServiceStatus.dwWin32ExitCode = NO_ERROR; ! ServiceStatus.dwCheckPoint = 1; ! ServiceStatus.dwWaitHint = 30000; /* accept Power Events */ ! ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_POWEREVENT; ! SetServiceStatus(StatusHandle, &ServiceStatus); #endif { *************** *** 492,499 **** } #ifdef REGISTER_POWER_NOTIFICATIONS ! /* create thread used to flush cache */ ! PowerNotificationThreadCreate(); #endif /* allow an exit to be called prior to any initialization */ --- 496,525 ---- } #ifdef REGISTER_POWER_NOTIFICATIONS ! { ! HKEY hkParm; ! DWORD code; ! DWORD dummyLen; ! int bpower = TRUE; ! ! /* see if we should handle power notifications */ ! code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName, 0, KEY_QUERY_VALUE, &hkParm); ! if (code == ERROR_SUCCESS) { ! dummyLen = sizeof(bpower); ! code = RegQueryValueEx(hkParm, "FlushOnHibernate", NULL, NULL, ! (BYTE *) &bpower, &dummyLen); ! ! if(code != ERROR_SUCCESS) ! bpower = TRUE; ! ! RegCloseKey(hkParm); ! } ! /* create thread used to flush cache */ ! if (bpower) { ! PowerNotificationThreadCreate(); ! powerEventsRegistered = 1; ! } ! } #endif /* allow an exit to be called prior to any initialization */ *************** *** 538,552 **** #ifdef JUMP MainThreadId = GetCurrentThreadId(); ! jmpret = setjmp(notifier_jmp); ! if (jmpret == 0) #endif /* JUMP */ { ! code = afsd_InitCM(&reason); ! if (code != 0) { afsi_log("afsd_InitCM failed: %s (code = %d)", reason, code); ! osi_panic(reason, __FILE__, __LINE__); } #ifndef NOTSERVICE --- 564,578 ---- #ifdef JUMP MainThreadId = GetCurrentThreadId(); ! jmpret = setjmp(notifier_jmp); ! if (jmpret == 0) #endif /* JUMP */ { ! code = afsd_InitCM(&reason); ! if (code != 0) { afsi_log("afsd_InitCM failed: %s (code = %d)", reason, code); ! osi_panic(reason, __FILE__, __LINE__); } #ifndef NOTSERVICE *************** *** 554,561 **** ServiceStatus.dwWaitHint -= 5000; SetServiceStatus(StatusHandle, &ServiceStatus); #endif ! code = afsd_InitDaemons(&reason); ! if (code != 0) { afsi_log("afsd_InitDaemons failed: %s (code = %d)", reason, code); osi_panic(reason, __FILE__, __LINE__); } --- 580,587 ---- ServiceStatus.dwWaitHint -= 5000; SetServiceStatus(StatusHandle, &ServiceStatus); #endif ! code = afsd_InitDaemons(&reason); ! if (code != 0) { afsi_log("afsd_InitDaemons failed: %s (code = %d)", reason, code); osi_panic(reason, __FILE__, __LINE__); } *************** *** 565,606 **** ServiceStatus.dwWaitHint -= 5000; SetServiceStatus(StatusHandle, &ServiceStatus); #endif ! code = afsd_InitSMB(&reason, MessageBox); ! if (code != 0) { afsi_log("afsd_InitSMB failed: %s (code = %d)", reason, code); ! osi_panic(reason, __FILE__, __LINE__); } MountGlobalDrives(); #ifndef NOTSERVICE ! ServiceStatus.dwCurrentState = SERVICE_RUNNING; ! ServiceStatus.dwWin32ExitCode = NO_ERROR; ! ServiceStatus.dwCheckPoint = 0; ! ServiceStatus.dwWaitHint = 0; /* accept Power events */ ! ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_POWEREVENT; ! SetServiceStatus(StatusHandle, &ServiceStatus); ! #endif { HANDLE h; char *ptbuf[1]; ! h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); ! ptbuf[0] = "AFS running"; ! ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, ptbuf, NULL); ! DeregisterEventSource(h); } ! } ! WaitForSingleObject(WaitToTerminate, INFINITE); { ! HANDLE h; char *ptbuf[1]; h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); ptbuf[0] = "AFS quitting"; ReportEvent(h, GlobalStatus ? EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, ptbuf, NULL); ! DeregisterEventSource(h); } DismountGlobalDrives(); --- 591,632 ---- ServiceStatus.dwWaitHint -= 5000; SetServiceStatus(StatusHandle, &ServiceStatus); #endif ! code = afsd_InitSMB(&reason, MessageBox); ! if (code != 0) { afsi_log("afsd_InitSMB failed: %s (code = %d)", reason, code); ! osi_panic(reason, __FILE__, __LINE__); } MountGlobalDrives(); #ifndef NOTSERVICE ! ServiceStatus.dwCurrentState = SERVICE_RUNNING; ! ServiceStatus.dwWin32ExitCode = NO_ERROR; ! ServiceStatus.dwCheckPoint = 0; ! ServiceStatus.dwWaitHint = 0; /* accept Power events */ ! ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_POWEREVENT; ! SetServiceStatus(StatusHandle, &ServiceStatus); ! #endif { HANDLE h; char *ptbuf[1]; ! h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); ! ptbuf[0] = "AFS running"; ! ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, ptbuf, NULL); ! DeregisterEventSource(h); } ! } ! WaitForSingleObject(WaitToTerminate, INFINITE); { ! HANDLE h; char *ptbuf[1]; h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); ptbuf[0] = "AFS quitting"; ReportEvent(h, GlobalStatus ? EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, ptbuf, NULL); ! DeregisterEventSource(h); } DismountGlobalDrives(); *************** *** 608,627 **** rx_Finalize(); #ifdef REGISTER_POWER_NOTIFICATIONS ! /* terminate thread used to flush cache */ ! PowerNotificationThreadExit(); #endif /* Remove the ExceptionFilter */ SetUnhandledExceptionFilter(NULL); 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) { --- 634,654 ---- rx_Finalize(); #ifdef REGISTER_POWER_NOTIFICATIONS ! /* terminate thread used to flush cache */ ! if (powerEventsRegistered) ! PowerNotificationThreadExit(); #endif /* Remove the ExceptionFilter */ SetUnhandledExceptionFilter(NULL); 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) { *************** *** 633,647 **** int main(void) { ! static SERVICE_TABLE_ENTRY dispatchTable[] = { ! {AFS_DAEMON_SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION) afsd_Main}, ! {NULL, NULL} ! }; ! if (!StartServiceCtrlDispatcher(dispatchTable)) { LONG status = GetLastError(); ! if (status == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) { DWORD tid; hAFSDMainThread = CreateThread(NULL, 0, afsdMain_thread, 0, 0, &tid); --- 660,674 ---- int main(void) { ! static SERVICE_TABLE_ENTRY dispatchTable[] = { ! {AFS_DAEMON_SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION) afsd_Main}, ! {NULL, NULL} ! }; ! if (!StartServiceCtrlDispatcher(dispatchTable)) { LONG status = GetLastError(); ! if (status == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) { DWORD tid; hAFSDMainThread = CreateThread(NULL, 0, afsdMain_thread, 0, 0, &tid); Index: openafs/src/WINNT/afsd/afskfw.c diff -c openafs/src/WINNT/afsd/afskfw.c:1.8.2.1 openafs/src/WINNT/afsd/afskfw.c:1.8.2.4 *** openafs/src/WINNT/afsd/afskfw.c:1.8.2.1 Tue Aug 17 00:28:38 2004 --- openafs/src/WINNT/afsd/afskfw.c Mon Oct 18 00:09:25 2004 *************** *** 444,471 **** static char OpenAFSConfigKeyName[] = "SOFTWARE\\OpenAFS\\Client"; int KFW_is_available(void) { HKEY parmKey; ! DWORD code, len; DWORD enableKFW = 1; code = RegOpenKeyEx(HKEY_CURRENT_USER, OpenAFSConfigKeyName, 0, KEY_QUERY_VALUE, &parmKey); ! if (code != ERROR_SUCCESS) ! code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, OpenAFSConfigKeyName, ! 0, KEY_QUERY_VALUE, &parmKey); ! if (code == ERROR_SUCCESS) { len = sizeof(enableKFW); code = RegQueryValueEx(parmKey, "EnableKFW", NULL, NULL, (BYTE *) &enableKFW, &len); if (code != ERROR_SUCCESS) { ! enableKFW = 1; } RegCloseKey (parmKey); ! } ! if ( !enableKFW ) return FALSE; --- 444,508 ---- static char OpenAFSConfigKeyName[] = "SOFTWARE\\OpenAFS\\Client"; + int + KFW_use_krb524(void) + { + HKEY parmKey; + DWORD code, len; + DWORD use524 = 0; + + code = RegOpenKeyEx(HKEY_CURRENT_USER, OpenAFSConfigKeyName, + 0, KEY_QUERY_VALUE, &parmKey); + if (code == ERROR_SUCCESS) { + len = sizeof(use524); + code = RegQueryValueEx(parmKey, "Use524", NULL, NULL, + (BYTE *) &use524, &len); + if (code != ERROR_SUCCESS) { + RegCloseKey(parmKey); + + code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, OpenAFSConfigKeyName, + 0, KEY_QUERY_VALUE, &parmKey); + if (code == ERROR_SUCCESS) { + len = sizeof(use524); + code = RegQueryValueEx(parmKey, "Use524", NULL, NULL, + (BYTE *) &use524, &len); + if (code != ERROR_SUCCESS) + use524 = 0; + } + } + RegCloseKey (parmKey); + } + return use524; + } + int KFW_is_available(void) { HKEY parmKey; ! DWORD code, len; DWORD enableKFW = 1; code = RegOpenKeyEx(HKEY_CURRENT_USER, OpenAFSConfigKeyName, 0, KEY_QUERY_VALUE, &parmKey); ! if (code == ERROR_SUCCESS) { len = sizeof(enableKFW); code = RegQueryValueEx(parmKey, "EnableKFW", NULL, NULL, (BYTE *) &enableKFW, &len); if (code != ERROR_SUCCESS) { ! RegCloseKey(parmKey); ! ! code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, OpenAFSConfigKeyName, ! 0, KEY_QUERY_VALUE, &parmKey); ! if (code == ERROR_SUCCESS) { ! len = sizeof(enableKFW); ! code = RegQueryValueEx(parmKey, "EnableKFW", NULL, NULL, ! (BYTE *) &enableKFW, &len); ! if (code != ERROR_SUCCESS) ! enableKFW = 1; ! } } RegCloseKey (parmKey); ! } if ( !enableKFW ) return FALSE; *************** *** 890,900 **** princ_realm = krb5_princ_realm(ctx, princ); for ( i=0; ilength; i++ ) { ! realm[i] = princ_realm->data[i]; cell[i] = tolower(princ_realm->data[i]); } ! cell[i] = '\0'; ! realm[i] = '\0'; code = KFW_AFS_klog(ctx, cc, "afs", cell, realm, pLeash_get_default_lifetime(),NULL); if ( IsDebuggerPresent() ) { --- 927,937 ---- princ_realm = krb5_princ_realm(ctx, princ); for ( i=0; ilength; i++ ) { ! realm[i] = princ_realm->data[i]; cell[i] = tolower(princ_realm->data[i]); } ! cell[i] = '\0'; ! realm[i] = '\0'; code = KFW_AFS_klog(ctx, cc, "afs", cell, realm, pLeash_get_default_lifetime(),NULL); if ( IsDebuggerPresent() ) { *************** *** 2546,2555 **** memset(ServiceName, '\0', sizeof(ServiceName)); memset(realm_of_user, '\0', sizeof(realm_of_user)); memset(realm_of_cell, '\0', sizeof(realm_of_cell)); ! if (cell && cell[0]) ! strcpy(Dmycell, cell); ! else ! memset(Dmycell, '\0', sizeof(Dmycell)); // NULL or empty cell returns information on local cell if (rc = KFW_AFS_get_cellconfig(Dmycell, &ak_cellconfig, local_cell)) --- 2583,2592 ---- memset(ServiceName, '\0', sizeof(ServiceName)); memset(realm_of_user, '\0', sizeof(realm_of_user)); memset(realm_of_cell, '\0', sizeof(realm_of_cell)); ! if (cell && cell[0]) ! strcpy(Dmycell, cell); ! else ! memset(Dmycell, '\0', sizeof(Dmycell)); // NULL or empty cell returns information on local cell if (rc = KFW_AFS_get_cellconfig(Dmycell, &ak_cellconfig, local_cell)) *************** *** 2575,2587 **** memset((char *)&increds, 0, sizeof(increds)); code = pkrb5_cc_get_principal(ctx, cc, &client_principal); ! if (code) { if ( code == KRB5_CC_NOTFOUND && IsDebuggerPresent() ) { OutputDebugString("Principal Not Found for ccache\n"); } goto skip_krb5_init; } i = krb5_princ_realm(ctx, client_principal)->length; if (i > REALM_SZ-1) i = REALM_SZ-1; --- 2612,2632 ---- memset((char *)&increds, 0, sizeof(increds)); code = pkrb5_cc_get_principal(ctx, cc, &client_principal); ! if (code) { if ( code == KRB5_CC_NOTFOUND && IsDebuggerPresent() ) { OutputDebugString("Principal Not Found for ccache\n"); } goto skip_krb5_init; } + + if ( strchr(krb5_princ_component(ctx,client_principal,0),'.') != NULL ) + { + OutputDebugString("Illegal Principal name contains dot in first component\n"); + rc = KRB5KRB_ERR_GENERIC; + goto cleanup; + } + i = krb5_princ_realm(ctx, client_principal)->length; if (i > REALM_SZ-1) i = REALM_SZ-1; *************** *** 2761,2767 **** * No need to perform a krb524 translation which is * commented out in the code below */ ! if (k5creds->ticket.length > MAXKTCTICKETLEN) goto try_krb524d; memset(&aserver, '\0', sizeof(aserver)); --- 2806,2813 ---- * No need to perform a krb524 translation which is * commented out in the code below */ ! if (KFW_use_krb524() || ! k5creds->ticket.length > MAXKTCTICKETLEN) goto try_krb524d; memset(&aserver, '\0', sizeof(aserver)); Index: openafs/src/WINNT/afsd/afsshare.c diff -c openafs/src/WINNT/afsd/afsshare.c:1.5 openafs/src/WINNT/afsd/afsshare.c:1.5.2.1 *** openafs/src/WINNT/afsd/afsshare.c:1.5 Tue Jul 20 10:36:41 2004 --- openafs/src/WINNT/afsd/afsshare.c Wed Sep 8 01:58:33 2004 *************** *** 65,71 **** else mountstring = argv[2]; ! if (RegSetValueEx(hkSubmounts, argv[1], 0, REG_SZ, mountstring, strlen(mountstring)+1)) { fprintf(stderr,"Submount Set failure for [%s]: %lX", argv[1], GetLastError()); RegCloseKey(hkSubmounts); --- 65,71 ---- else mountstring = argv[2]; ! if (RegSetValueEx(hkSubmounts, argv[1], 0, REG_EXPAND_SZ, mountstring, strlen(mountstring)+1)) { fprintf(stderr,"Submount Set failure for [%s]: %lX", argv[1], GetLastError()); RegCloseKey(hkSubmounts); Index: openafs/src/WINNT/afsd/cm_buf.c diff -c openafs/src/WINNT/afsd/cm_buf.c:1.13.2.1 openafs/src/WINNT/afsd/cm_buf.c:1.13.2.2 *** openafs/src/WINNT/afsd/cm_buf.c:1.13.2.1 Tue Aug 17 00:28:38 2004 --- openafs/src/WINNT/afsd/cm_buf.c Sun Oct 10 19:52:04 2004 *************** *** 110,167 **** /* hold a reference to an already held buffer */ void buf_Hold(cm_buf_t *bp) { ! lock_ObtainWrite(&buf_globalLock); ! bp->refCount++; ! lock_ReleaseWrite(&buf_globalLock); } /* incremental sync daemon. Writes 1/10th of all the buffers every 5000 ms */ void buf_IncrSyncer(long parm) { ! cm_buf_t *bp; /* buffer we're hacking on; held */ ! long i; /* counter */ ! long nAtOnce; /* how many to do at once */ ! cm_req_t req; ! ! lock_ObtainWrite(&buf_globalLock); ! bp = buf_allp; ! bp->refCount++; ! lock_ReleaseWrite(&buf_globalLock); ! nAtOnce = buf_nbuffers / 10; ! while (1) { #ifndef DJGPP ! i = SleepEx(5000, 1); ! if (i != 0) continue; #else ! thrd_Sleep(5000); #endif /* DJGPP */ ! /* now go through our percentage of the buffers */ ! for(i=0; iallp; ! if (!bp) bp = buf_allp; ! bp->refCount++; ! lock_ReleaseWrite(&buf_globalLock); ! } /* for loop over a bunch of buffers */ ! } /* whole daemon's while loop */ } #ifndef DJGPP --- 110,167 ---- /* hold a reference to an already held buffer */ void buf_Hold(cm_buf_t *bp) { ! lock_ObtainWrite(&buf_globalLock); ! bp->refCount++; ! lock_ReleaseWrite(&buf_globalLock); } /* incremental sync daemon. Writes 1/10th of all the buffers every 5000 ms */ void buf_IncrSyncer(long parm) { ! cm_buf_t *bp; /* buffer we're hacking on; held */ ! long i; /* counter */ ! long nAtOnce; /* how many to do at once */ ! cm_req_t req; ! ! lock_ObtainWrite(&buf_globalLock); ! bp = buf_allp; ! bp->refCount++; ! lock_ReleaseWrite(&buf_globalLock); ! nAtOnce = buf_nbuffers / 10; ! while (1) { #ifndef DJGPP ! i = SleepEx(5000, 1); ! if (i != 0) continue; #else ! thrd_Sleep(5000); #endif /* DJGPP */ ! /* now go through our percentage of the buffers */ ! for(i=0; iallp; ! if (!bp) bp = buf_allp; ! bp->refCount++; ! lock_ReleaseWrite(&buf_globalLock); ! } /* for loop over a bunch of buffers */ ! } /* whole daemon's while loop */ } #ifndef DJGPP *************** *** 172,229 **** */ PSECURITY_ATTRIBUTES CreateCacheFileSA() { ! PSECURITY_ATTRIBUTES psa; ! PSECURITY_DESCRIPTOR psd; ! SID_IDENTIFIER_AUTHORITY authority = SECURITY_NT_AUTHORITY; ! PSID AdminSID; ! DWORD AdminSIDlength; ! PACL AdminOnlyACL; ! DWORD ACLlength; ! ! /* Get Administrator SID */ ! AllocateAndInitializeSid(&authority, 2, ! SECURITY_BUILTIN_DOMAIN_RID, ! DOMAIN_ALIAS_RID_ADMINS, ! 0, 0, 0, 0, 0, 0, ! &AdminSID); ! ! /* Create Administrator-only ACL */ ! AdminSIDlength = GetLengthSid(AdminSID); ! ACLlength = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) ! + AdminSIDlength - sizeof(DWORD); ! AdminOnlyACL = GlobalAlloc(GMEM_FIXED, ACLlength); ! InitializeAcl(AdminOnlyACL, ACLlength, ACL_REVISION); ! AddAccessAllowedAce(AdminOnlyACL, ACL_REVISION, ! STANDARD_RIGHTS_ALL | SPECIFIC_RIGHTS_ALL, ! AdminSID); ! ! /* Create security descriptor */ ! psd = GlobalAlloc(GMEM_FIXED, sizeof(SECURITY_DESCRIPTOR)); ! InitializeSecurityDescriptor(psd, SECURITY_DESCRIPTOR_REVISION); ! SetSecurityDescriptorDacl(psd, TRUE, AdminOnlyACL, FALSE); ! ! /* Create security attributes structure */ ! psa = GlobalAlloc(GMEM_FIXED, sizeof(SECURITY_ATTRIBUTES)); ! psa->nLength = sizeof(SECURITY_ATTRIBUTES); ! psa->lpSecurityDescriptor = psd; ! psa->bInheritHandle = TRUE; ! return psa; ! } #endif /* !DJGPP */ #ifndef DJGPP /* Free a security attribute structure created by CreateCacheFileSA() */ VOID FreeCacheFileSA(PSECURITY_ATTRIBUTES psa) { ! BOOL b1, b2; ! PACL pAcl; ! GetSecurityDescriptorDacl(psa->lpSecurityDescriptor, &b1, &pAcl, &b2); ! GlobalFree(pAcl); ! GlobalFree(psa->lpSecurityDescriptor); ! GlobalFree(psa); ! } #endif /* !DJGPP */ /* initialize the buffer package; called with no locks --- 172,229 ---- */ PSECURITY_ATTRIBUTES CreateCacheFileSA() { ! PSECURITY_ATTRIBUTES psa; ! PSECURITY_DESCRIPTOR psd; ! SID_IDENTIFIER_AUTHORITY authority = SECURITY_NT_AUTHORITY; ! PSID AdminSID; ! DWORD AdminSIDlength; ! PACL AdminOnlyACL; ! DWORD ACLlength; ! ! /* Get Administrator SID */ ! AllocateAndInitializeSid(&authority, 2, ! SECURITY_BUILTIN_DOMAIN_RID, ! DOMAIN_ALIAS_RID_ADMINS, ! 0, 0, 0, 0, 0, 0, ! &AdminSID); ! ! /* Create Administrator-only ACL */ ! AdminSIDlength = GetLengthSid(AdminSID); ! ACLlength = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) ! + AdminSIDlength - sizeof(DWORD); ! AdminOnlyACL = GlobalAlloc(GMEM_FIXED, ACLlength); ! InitializeAcl(AdminOnlyACL, ACLlength, ACL_REVISION); ! AddAccessAllowedAce(AdminOnlyACL, ACL_REVISION, ! STANDARD_RIGHTS_ALL | SPECIFIC_RIGHTS_ALL, ! AdminSID); ! ! /* Create security descriptor */ ! psd = GlobalAlloc(GMEM_FIXED, sizeof(SECURITY_DESCRIPTOR)); ! InitializeSecurityDescriptor(psd, SECURITY_DESCRIPTOR_REVISION); ! SetSecurityDescriptorDacl(psd, TRUE, AdminOnlyACL, FALSE); ! ! /* Create security attributes structure */ ! psa = GlobalAlloc(GMEM_FIXED, sizeof(SECURITY_ATTRIBUTES)); ! psa->nLength = sizeof(SECURITY_ATTRIBUTES); ! psa->lpSecurityDescriptor = psd; ! psa->bInheritHandle = TRUE; ! return psa; ! } #endif /* !DJGPP */ #ifndef DJGPP /* Free a security attribute structure created by CreateCacheFileSA() */ VOID FreeCacheFileSA(PSECURITY_ATTRIBUTES psa) { ! BOOL b1, b2; ! PACL pAcl; ! GetSecurityDescriptorDacl(psa->lpSecurityDescriptor, &b1, &pAcl, &b2); ! GlobalFree(pAcl); ! GlobalFree(psa->lpSecurityDescriptor); ! GlobalFree(psa); ! } #endif /* !DJGPP */ /* initialize the buffer package; called with no locks *************** *** 231,397 **** */ long buf_Init(cm_buf_ops_t *opsp) { ! static osi_once_t once; ! cm_buf_t *bp; ! long sectorSize; ! thread_t phandle; #ifndef DJGPP ! HANDLE hf, hm; ! PSECURITY_ATTRIBUTES psa; #endif /* !DJGPP */ ! long i; ! unsigned long pid; ! char *data; ! long cs; #ifndef DJGPP ! /* Get system info; all we really want is the allocation granularity */ ! GetSystemInfo(&sysInfo); #endif /* !DJGPP */ ! /* Have to be able to reserve a whole chunk */ ! if (((buf_nbuffers - 3) * buf_bufferSize) < cm_chunkSize) ! return CM_ERROR_TOOFEWBUFS; ! ! /* recall for callouts */ ! cm_buf_opsp = opsp; ! ! if (osi_Once(&once)) { ! /* initialize global locks */ ! lock_InitializeRWLock(&buf_globalLock, "Global buffer lock"); #ifndef DJGPP ! /* ! * Cache file mapping constrained by ! * system allocation granularity; ! * round up, assuming granularity is a power of two ! */ ! cs = buf_nbuffers * buf_bufferSize; ! cs = (cs + (sysInfo.dwAllocationGranularity - 1)) ! & ~(sysInfo.dwAllocationGranularity - 1); ! if (cs != buf_nbuffers * buf_bufferSize) { ! buf_nbuffers = cs / buf_bufferSize; ! afsi_log("Cache size rounded up to %d buffers", ! buf_nbuffers); ! } #endif /* !DJGPP */ ! /* remember this for those who want to reset it */ ! buf_nOrigBuffers = buf_nbuffers; ! /* lower hash size to a prime number */ ! buf_hashSize = osi_PrimeLessThan(buf_hashSize); ! /* create hash table */ ! buf_hashTablepp = malloc(buf_hashSize * sizeof(cm_buf_t *)); ! memset((void *)buf_hashTablepp, 0, ! buf_hashSize * sizeof(cm_buf_t *)); ! ! /* another hash table */ ! buf_fileHashTablepp = malloc(buf_hashSize * sizeof(cm_buf_t *)); ! memset((void *)buf_fileHashTablepp, 0, ! buf_hashSize * sizeof(cm_buf_t *)); ! /* min value for which this works */ ! sectorSize = 1; #ifndef DJGPP ! if(buf_cacheType == CM_BUF_CACHETYPE_FILE) { ! /* Reserve buffer space by mapping cache file */ ! psa = CreateCacheFileSA(); ! hf = CreateFile(cm_CachePath, ! GENERIC_READ | GENERIC_WRITE, ! FILE_SHARE_READ | FILE_SHARE_WRITE, ! psa, ! OPEN_ALWAYS, ! FILE_ATTRIBUTE_NORMAL, ! NULL); ! if (hf == INVALID_HANDLE_VALUE) { ! afsi_log("create file error %d", GetLastError()); ! return CM_ERROR_INVAL; ! } ! FreeCacheFileSA(psa); } else { /* buf_cacheType == CM_BUF_CACHETYPE_VIRTUAL */ hf = INVALID_HANDLE_VALUE; } ! CacheHandle = hf; ! hm = CreateFileMapping(hf, ! NULL, ! PAGE_READWRITE, ! 0, buf_nbuffers * buf_bufferSize, ! NULL); ! if (hm == NULL) { ! if (GetLastError() == ERROR_DISK_FULL) { ! afsi_log("Error creating cache file mapping: disk full"); ! return CM_ERROR_TOOMANYBUFS; ! } ! return CM_ERROR_INVAL; ! } ! data = MapViewOfFile(hm, ! FILE_MAP_ALL_ACCESS, ! 0, 0, ! buf_nbuffers * buf_bufferSize); ! if (data == NULL) { ! if(hf != INVALID_HANDLE_VALUE) CloseHandle(hf); ! CloseHandle(hm); ! return CM_ERROR_INVAL; ! } ! CloseHandle(hm); ! #else ! /* djgpp doesn't support memory mapped files */ ! data = malloc(buf_nbuffers * buf_bufferSize); #endif /* !DJGPP */ ! /* create buffer headers and put in free list */ ! bp = malloc(buf_nbuffers * sizeof(cm_buf_t)); ! buf_allp = NULL; ! for(i=0; iallp = buf_allp; ! buf_allp = bp; ! ! osi_QAdd((osi_queue_t **)&buf_freeListp, &bp->q); ! bp->flags |= CM_BUF_INLRU; ! lock_InitializeMutex(&bp->mx, "Buffer mutex"); ! ! /* grab appropriate number of bytes from aligned zone */ ! bp->datap = data; ! ! /* setup last buffer pointer */ ! if (i == 0) ! buf_freeListEndp = bp; ! ! /* next */ ! bp++; ! data += buf_bufferSize; ! } ! ! /* none reserved at first */ ! buf_reservedBufs = 0; ! ! /* just for safety's sake */ ! buf_maxReservedBufs = buf_nbuffers - 3; ! ! /* init the buffer trace log */ ! buf_logp = osi_LogCreate("buffer", 10); ! osi_EndOnce(&once); ! ! /* and create the incr-syncer */ ! phandle = thrd_Create(0, 0, ! (ThreadFunc) buf_IncrSyncer, 0, 0, &pid, ! "buf_IncrSyncer"); ! osi_assertx(phandle != NULL, "buf: can't create incremental sync proc"); #ifndef DJGPP ! CloseHandle(phandle); #endif /* !DJGPP */ ! } ! return 0; } /* add nbuffers to the buffer pool, if possible. --- 231,400 ---- */ long buf_Init(cm_buf_ops_t *opsp) { ! static osi_once_t once; ! cm_buf_t *bp; ! long sectorSize; ! thread_t phandle; #ifndef DJGPP ! HANDLE hf, hm; ! PSECURITY_ATTRIBUTES psa; #endif /* !DJGPP */ ! long i; ! unsigned long pid; ! char *data; ! long cs; #ifndef DJGPP ! /* Get system info; all we really want is the allocation granularity */ ! GetSystemInfo(&sysInfo); #endif /* !DJGPP */ ! /* Have to be able to reserve a whole chunk */ ! if (((buf_nbuffers - 3) * buf_bufferSize) < cm_chunkSize) ! return CM_ERROR_TOOFEWBUFS; ! ! /* recall for callouts */ ! cm_buf_opsp = opsp; ! ! if (osi_Once(&once)) { ! /* initialize global locks */ ! lock_InitializeRWLock(&buf_globalLock, "Global buffer lock"); #ifndef DJGPP ! /* ! * Cache file mapping constrained by ! * system allocation granularity; ! * round up, assuming granularity is a power of two ! */ ! cs = buf_nbuffers * buf_bufferSize; ! cs = (cs + (sysInfo.dwAllocationGranularity - 1)) ! & ~(sysInfo.dwAllocationGranularity - 1); ! if (cs != buf_nbuffers * buf_bufferSize) { ! buf_nbuffers = cs / buf_bufferSize; ! afsi_log("Cache size rounded up to %d buffers", ! buf_nbuffers); ! } #endif /* !DJGPP */ ! /* remember this for those who want to reset it */ ! buf_nOrigBuffers = buf_nbuffers; ! /* lower hash size to a prime number */ ! buf_hashSize = osi_PrimeLessThan(buf_hashSize); ! /* create hash table */ ! buf_hashTablepp = malloc(buf_hashSize * sizeof(cm_buf_t *)); ! memset((void *)buf_hashTablepp, 0, ! buf_hashSize * sizeof(cm_buf_t *)); ! ! /* another hash table */ ! buf_fileHashTablepp = malloc(buf_hashSize * sizeof(cm_buf_t *)); ! memset((void *)buf_fileHashTablepp, 0, ! buf_hashSize * sizeof(cm_buf_t *)); ! /* min value for which this works */ ! sectorSize = 1; #ifndef DJGPP ! if (buf_cacheType == CM_BUF_CACHETYPE_FILE) { ! /* Reserve buffer space by mapping cache file */ ! psa = CreateCacheFileSA(); ! hf = CreateFile(cm_CachePath, ! GENERIC_READ | GENERIC_WRITE, ! FILE_SHARE_READ | FILE_SHARE_WRITE, ! psa, ! OPEN_ALWAYS, ! FILE_ATTRIBUTE_NORMAL, ! NULL); ! if (hf == INVALID_HANDLE_VALUE) { ! afsi_log("Error creating cache file \"%s\" error %d", ! cm_CachePath, GetLastError()); ! return CM_ERROR_INVAL; ! } ! FreeCacheFileSA(psa); } else { /* buf_cacheType == CM_BUF_CACHETYPE_VIRTUAL */ hf = INVALID_HANDLE_VALUE; } ! CacheHandle = hf; ! hm = CreateFileMapping(hf, ! NULL, ! PAGE_READWRITE, ! 0, buf_nbuffers * buf_bufferSize, ! NULL); ! if (hm == NULL) { ! if (GetLastError() == ERROR_DISK_FULL) { ! afsi_log("Error creating cache file \"%s\" mapping: disk full", ! cm_CachePath); ! return CM_ERROR_TOOMANYBUFS; ! } ! return CM_ERROR_INVAL; ! } ! data = MapViewOfFile(hm, ! FILE_MAP_ALL_ACCESS, ! 0, 0, ! buf_nbuffers * buf_bufferSize); ! if (data == NULL) { ! if (hf != INVALID_HANDLE_VALUE) ! CloseHandle(hf); ! CloseHandle(hm); ! return CM_ERROR_INVAL; ! } ! CloseHandle(hm); ! #else ! /* djgpp doesn't support memory mapped files */ ! data = malloc(buf_nbuffers * buf_bufferSize); #endif /* !DJGPP */ ! /* create buffer headers and put in free list */ ! bp = malloc(buf_nbuffers * sizeof(cm_buf_t)); ! buf_allp = NULL; ! for(i=0; iallp = buf_allp; ! buf_allp = bp; ! ! osi_QAdd((osi_queue_t **)&buf_freeListp, &bp->q); ! bp->flags |= CM_BUF_INLRU; ! lock_InitializeMutex(&bp->mx, "Buffer mutex"); ! ! /* grab appropriate number of bytes from aligned zone */ ! bp->datap = data; ! ! /* setup last buffer pointer */ ! if (i == 0) ! buf_freeListEndp = bp; ! ! /* next */ ! bp++; ! data += buf_bufferSize; ! } ! /* none reserved at first */ ! buf_reservedBufs = 0; ! ! /* just for safety's sake */ ! buf_maxReservedBufs = buf_nbuffers - 3; ! ! /* init the buffer trace log */ ! buf_logp = osi_LogCreate("buffer", 10); ! ! osi_EndOnce(&once); ! ! /* and create the incr-syncer */ ! phandle = thrd_Create(0, 0, ! (ThreadFunc) buf_IncrSyncer, 0, 0, &pid, ! "buf_IncrSyncer"); ! osi_assertx(phandle != NULL, "buf: can't create incremental sync proc"); #ifndef DJGPP ! CloseHandle(phandle); #endif /* !DJGPP */ ! } ! return 0; } /* add nbuffers to the buffer pool, if possible. *************** *** 399,410 **** */ long buf_AddBuffers(long nbuffers) { ! cm_buf_t *bp; ! int i; ! char *data; #ifndef DJGPP ! HANDLE hm; ! long cs; afsi_log("%d buffers being added to the existing cache of size %d", nbuffers, buf_nbuffers); --- 402,413 ---- */ long buf_AddBuffers(long nbuffers) { ! cm_buf_t *bp; ! int i; ! char *data; #ifndef DJGPP ! HANDLE hm; ! long cs; afsi_log("%d buffers being added to the existing cache of size %d", nbuffers, buf_nbuffers); *************** *** 418,490 **** return CM_ERROR_INVAL; } ! /* ! * Cache file mapping constrained by ! * system allocation granularity; ! * round up, assuming granularity is a power of two; ! * assume existing cache size is already rounded ! */ ! cs = nbuffers * buf_bufferSize; ! cs = (cs + (sysInfo.dwAllocationGranularity - 1)) ! & ~(sysInfo.dwAllocationGranularity - 1); ! if (cs != nbuffers * buf_bufferSize) { ! nbuffers = cs / buf_bufferSize; ! } ! ! /* Reserve additional buffer space by remapping cache file */ ! hm = CreateFileMapping(CacheHandle, ! NULL, ! PAGE_READWRITE, ! 0, (buf_nbuffers + nbuffers) * buf_bufferSize, ! NULL); ! if (hm == NULL) { ! if (GetLastError() == ERROR_DISK_FULL) ! return CM_ERROR_TOOMANYBUFS; ! else ! return CM_ERROR_INVAL; ! } ! data = MapViewOfFile(hm, ! FILE_MAP_ALL_ACCESS, ! 0, buf_nbuffers * buf_bufferSize, ! nbuffers * buf_bufferSize); ! if (data == NULL) { ! CloseHandle(hm); ! return CM_ERROR_INVAL; ! } ! CloseHandle(hm); #else ! data = malloc(buf_nbuffers * buf_bufferSize); #endif /* DJGPP */ ! /* Create buffer headers and put in free list */ ! bp = malloc(nbuffers * sizeof(*bp)); ! for(i=0; imx, "cm_buf_t"); ! /* grab appropriate number of bytes from aligned zone */ ! bp->datap = data; ! bp->flags |= CM_BUF_INLRU; ! ! lock_ObtainWrite(&buf_globalLock); ! /* note that buf_allp chain is covered by buf_globalLock now */ ! bp->allp = buf_allp; ! buf_allp = bp; ! osi_QAdd((osi_queue_t **) &buf_freeListp, &bp->q); ! if (!buf_freeListEndp) buf_freeListEndp = bp; ! buf_nbuffers++; ! lock_ReleaseWrite(&buf_globalLock); ! bp++; ! data += buf_bufferSize; ! } /* for loop over all buffers */ ! return 0; ! } /* interface to set the number of buffers to an exact figure. * Called with no locks held. --- 421,493 ---- return CM_ERROR_INVAL; } ! /* ! * Cache file mapping constrained by ! * system allocation granularity; ! * round up, assuming granularity is a power of two; ! * assume existing cache size is already rounded ! */ ! cs = nbuffers * buf_bufferSize; ! cs = (cs + (sysInfo.dwAllocationGranularity - 1)) ! & ~(sysInfo.dwAllocationGranularity - 1); ! if (cs != nbuffers * buf_bufferSize) { ! nbuffers = cs / buf_bufferSize; ! } ! ! /* Reserve additional buffer space by remapping cache file */ ! hm = CreateFileMapping(CacheHandle, ! NULL, ! PAGE_READWRITE, ! 0, (buf_nbuffers + nbuffers) * buf_bufferSize, ! NULL); ! if (hm == NULL) { ! if (GetLastError() == ERROR_DISK_FULL) ! return CM_ERROR_TOOMANYBUFS; ! else ! return CM_ERROR_INVAL; ! } ! data = MapViewOfFile(hm, ! FILE_MAP_ALL_ACCESS, ! 0, buf_nbuffers * buf_bufferSize, ! nbuffers * buf_bufferSize); ! if (data == NULL) { ! CloseHandle(hm); ! return CM_ERROR_INVAL; ! } ! CloseHandle(hm); #else ! data = malloc(buf_nbuffers * buf_bufferSize); #endif /* DJGPP */ ! /* Create buffer headers and put in free list */ ! bp = malloc(nbuffers * sizeof(*bp)); ! for(i=0; imx, "cm_buf_t"); ! /* grab appropriate number of bytes from aligned zone */ ! bp->datap = data; ! bp->flags |= CM_BUF_INLRU; ! ! lock_ObtainWrite(&buf_globalLock); ! /* note that buf_allp chain is covered by buf_globalLock now */ ! bp->allp = buf_allp; ! buf_allp = bp; ! osi_QAdd((osi_queue_t **) &buf_freeListp, &bp->q); ! if (!buf_freeListEndp) buf_freeListEndp = bp; ! buf_nbuffers++; ! lock_ReleaseWrite(&buf_globalLock); ! bp++; ! data += buf_bufferSize; ! } /* for loop over all buffers */ ! return 0; ! } /* interface to set the number of buffers to an exact figure. * Called with no locks held. *************** *** 495,502 **** return CM_ERROR_INVAL; if (nbuffers == buf_nbuffers) return 0; ! else if (nbuffers > buf_nbuffers) ! return buf_AddBuffers(nbuffers - buf_nbuffers); else return CM_ERROR_INVAL; } --- 498,505 ---- return CM_ERROR_INVAL; if (nbuffers == buf_nbuffers) return 0; ! else if (nbuffers > buf_nbuffers) ! return buf_AddBuffers(nbuffers - buf_nbuffers); else return CM_ERROR_INVAL; } *************** *** 504,512 **** /* release a buffer. Buffer must be referenced, but unlocked. */ void buf_Release(cm_buf_t *bp) { ! lock_ObtainWrite(&buf_globalLock); ! buf_LockedRelease(bp); ! lock_ReleaseWrite(&buf_globalLock); } /* wait for reading or writing to clear; called with write-locked --- 507,515 ---- /* release a buffer. Buffer must be referenced, but unlocked. */ void buf_Release(cm_buf_t *bp) { ! lock_ObtainWrite(&buf_globalLock); ! buf_LockedRelease(bp); ! lock_ReleaseWrite(&buf_globalLock); } /* wait for reading or writing to clear; called with write-locked *************** *** 514,523 **** */ void buf_WaitIO(cm_buf_t *bp) { ! while (1) { ! /* if no IO is happening, we're done */ ! if (!(bp->flags & (CM_BUF_READING | CM_BUF_WRITING))) ! break; /* otherwise I/O is happening, but some other thread is waiting for * the I/O already. Wait for that guy to figure out what happened, --- 517,526 ---- */ void buf_WaitIO(cm_buf_t *bp) { ! while (1) { ! /* if no IO is happening, we're done */ ! if (!(bp->flags & (CM_BUF_READING | CM_BUF_WRITING))) ! break; /* otherwise I/O is happening, but some other thread is waiting for * the I/O already. Wait for that guy to figure out what happened, *************** *** 536,542 **** * the I/O to complete. Do so. */ if (bp->flags & CM_BUF_WAITING) { ! bp->flags &= ~CM_BUF_WAITING; osi_Wakeup((long) bp); } osi_Log1(buf_logp, "WaitIO finished wait for bp 0x%x", (long) bp); --- 539,545 ---- * the I/O to complete. Do so. */ if (bp->flags & CM_BUF_WAITING) { ! bp->flags &= ~CM_BUF_WAITING; osi_Wakeup((long) bp); } osi_Log1(buf_logp, "WaitIO finished wait for bp 0x%x", (long) bp); *************** *** 545,584 **** /* code to drop reference count while holding buf_globalLock */ void buf_LockedRelease(cm_buf_t *bp) { ! /* ensure that we're in the LRU queue if our ref count is 0 */ ! osi_assert(bp->refCount > 0); ! if (--bp->refCount == 0) { ! if (!(bp->flags & CM_BUF_INLRU)) { ! osi_QAdd((osi_queue_t **) &buf_freeListp, &bp->q); ! ! /* watch for transition from empty to one element */ ! if (!buf_freeListEndp) ! buf_freeListEndp = buf_freeListp; ! bp->flags |= CM_BUF_INLRU; ! } } ! } /* find a buffer, if any, for a particular file ID and offset. Assumes * that buf_globalLock is write locked when called. */ cm_buf_t *buf_LockedFind(struct cm_scache *scp, osi_hyper_t *offsetp) { ! long i; ! cm_buf_t *bp; ! ! i = BUF_HASH(&scp->fid, offsetp); ! for(bp = buf_hashTablepp[i]; bp; bp=bp->hashp) { ! if (cm_FidCmp(&scp->fid, &bp->fid) == 0 ! && offsetp->LowPart == bp->offset.LowPart ! && offsetp->HighPart == bp->offset.HighPart) { ! bp->refCount++; ! break; ! } } ! /* return whatever we found, if anything */ ! return bp; } /* find a buffer with offset *offsetp for vnode *scp. Called --- 548,587 ---- /* code to drop reference count while holding buf_globalLock */ void buf_LockedRelease(cm_buf_t *bp) { ! /* ensure that we're in the LRU queue if our ref count is 0 */ ! osi_assert(bp->refCount > 0); ! if (--bp->refCount == 0) { ! if (!(bp->flags & CM_BUF_INLRU)) { ! osi_QAdd((osi_queue_t **) &buf_freeListp, &bp->q); ! ! /* watch for transition from empty to one element */ ! if (!buf_freeListEndp) ! buf_freeListEndp = buf_freeListp; ! bp->flags |= CM_BUF_INLRU; } ! } ! } /* find a buffer, if any, for a particular file ID and offset. Assumes * that buf_globalLock is write locked when called. */ cm_buf_t *buf_LockedFind(struct cm_scache *scp, osi_hyper_t *offsetp) { ! long i; ! cm_buf_t *bp; ! ! i = BUF_HASH(&scp->fid, offsetp); ! for(bp = buf_hashTablepp[i]; bp; bp=bp->hashp) { ! if (cm_FidCmp(&scp->fid, &bp->fid) == 0 ! && offsetp->LowPart == bp->offset.LowPart ! && offsetp->HighPart == bp->offset.HighPart) { ! bp->refCount++; ! break; } + } ! /* return whatever we found, if anything */ ! return bp; } /* find a buffer with offset *offsetp for vnode *scp. Called *************** *** 586,599 **** */ cm_buf_t *buf_Find(struct cm_scache *scp, osi_hyper_t *offsetp) { ! cm_buf_t *bp; ! lock_ObtainWrite(&buf_globalLock); ! bp = buf_LockedFind(scp, offsetp); ! lock_ReleaseWrite(&buf_globalLock); ! return bp; ! } /* start cleaning I/O on this buffer. Buffer must be write locked, and is returned * write-locked. --- 589,602 ---- */ cm_buf_t *buf_Find(struct cm_scache *scp, osi_hyper_t *offsetp) { ! cm_buf_t *bp; ! lock_ObtainWrite(&buf_globalLock); ! bp = buf_LockedFind(scp, offsetp); ! lock_ReleaseWrite(&buf_globalLock); ! return bp; ! } /* start cleaning I/O on this buffer. Buffer must be write locked, and is returned * write-locked. *************** *** 604,640 **** */ void buf_LockedCleanAsync(cm_buf_t *bp, cm_req_t *reqp) { ! long code; ! code = 0; ! while ((bp->flags & (CM_BUF_WRITING | CM_BUF_DIRTY)) == CM_BUF_DIRTY) { ! lock_ReleaseMutex(&bp->mx); ! ! code = (*cm_buf_opsp->Writep)(&bp->fid, &bp->offset, ! buf_bufferSize, 0, bp->userp, ! reqp); ! lock_ObtainMutex(&bp->mx); ! if (code) break; #ifdef DISKCACHE95 ! /* Disk cache support */ ! /* write buffer to disk cache (synchronous for now) */ ! diskcache_Update(bp->dcp, bp->datap, buf_bufferSize, bp->dataVersion); #endif /* DISKCACHE95 */ ! }; ! /* do logging after call to GetLastError, or else */ ! osi_Log2(buf_logp, "buf_CleanAsync starts I/O on 0x%x, done=%d", bp, code); ! /* if someone was waiting for the I/O that just completed or failed, ! * wake them up. ! */ ! if (bp->flags & CM_BUF_WAITING) { ! /* turn off flags and wakeup users */ ! bp->flags &= ~CM_BUF_WAITING; ! osi_Wakeup((long) bp); ! } } /* Called with a zero-ref count buffer and with the buf_globalLock write locked. --- 607,644 ---- */ void buf_LockedCleanAsync(cm_buf_t *bp, cm_req_t *reqp) { ! long code; ! ! code = 0; ! while ((bp->flags & (CM_BUF_WRITING | CM_BUF_DIRTY)) == CM_BUF_DIRTY) { ! lock_ReleaseMutex(&bp->mx); ! code = (*cm_buf_opsp->Writep)(&bp->fid, &bp->offset, ! buf_bufferSize, 0, bp->userp, ! reqp); ! lock_ObtainMutex(&bp->mx); ! if (code) ! break; #ifdef DISKCACHE95 ! /* Disk cache support */ ! /* write buffer to disk cache (synchronous for now) */ ! diskcache_Update(bp->dcp, bp->datap, buf_bufferSize, bp->dataVersion); #endif /* DISKCACHE95 */ ! }; ! /* do logging after call to GetLastError, or else */ ! osi_Log2(buf_logp, "buf_CleanAsync starts I/O on 0x%x, done=%d", bp, code); ! /* if someone was waiting for the I/O that just completed or failed, ! * wake them up. ! */ ! if (bp->flags & CM_BUF_WAITING) { ! /* turn off flags and wakeup users */ ! bp->flags &= ~CM_BUF_WAITING; ! osi_Wakeup((long) bp); ! } } /* Called with a zero-ref count buffer and with the buf_globalLock write locked. *************** *** 643,705 **** */ void buf_Recycle(cm_buf_t *bp) { ! int i; ! cm_buf_t **lbpp; ! cm_buf_t *tbp; ! cm_buf_t *prevBp, *nextBp; ! ! /* if we get here, we know that the buffer still has a 0 ref count, ! * and that it is clean and has no currently pending I/O. This is ! * the dude to return. ! * Remember that as long as the ref count is 0, we know that we won't ! * have any lock conflicts, so we can grab the buffer lock out of ! * order in the locking hierarchy. ! */ osi_Log2( buf_logp, "buf_Recycle recycles 0x%x, off 0x%x", ! bp, bp->offset.LowPart); ! osi_assert(bp->refCount == 0); ! osi_assert(!(bp->flags & (CM_BUF_READING | CM_BUF_WRITING | CM_BUF_DIRTY))); ! lock_AssertWrite(&buf_globalLock); ! ! if (bp->flags & CM_BUF_INHASH) { ! /* Remove from hash */ ! ! i = BUF_HASH(&bp->fid, &bp->offset); ! lbpp = &(buf_hashTablepp[i]); ! for(tbp = *lbpp; tbp; lbpp = &tbp->hashp, tbp = *lbpp) { ! if (tbp == bp) break; ! } ! ! /* we better find it */ ! osi_assertx(tbp != NULL, "buf_GetNewLocked: hash table screwup"); ! ! *lbpp = bp->hashp; /* hash out */ ! ! /* Remove from file hash */ ! ! i = BUF_FILEHASH(&bp->fid); ! prevBp = bp->fileHashBackp; ! nextBp = bp->fileHashp; ! if (prevBp) ! prevBp->fileHashp = nextBp; ! else ! buf_fileHashTablepp[i] = nextBp; ! if (nextBp) ! nextBp->fileHashBackp = prevBp; ! bp->flags &= ~CM_BUF_INHASH; ! } ! ! /* bump the soft reference counter now, to invalidate softRefs; no ! * wakeup is required since people don't sleep waiting for this ! * counter to change. ! */ ! bp->idCounter++; ! /* make the fid unrecognizable */ ! memset(&bp->fid, 0, sizeof(bp->fid)); ! } /* recycle a buffer, removing it from the free list, hashing in its new identity * and returning it write-locked so that no one can use it. Called without --- 647,709 ---- */ void buf_Recycle(cm_buf_t *bp) { ! int i; ! cm_buf_t **lbpp; ! cm_buf_t *tbp; ! cm_buf_t *prevBp, *nextBp; ! ! /* if we get here, we know that the buffer still has a 0 ref count, ! * and that it is clean and has no currently pending I/O. This is ! * the dude to return. ! * Remember that as long as the ref count is 0, we know that we won't ! * have any lock conflicts, so we can grab the buffer lock out of ! * order in the locking hierarchy. ! */ osi_Log2( buf_logp, "buf_Recycle recycles 0x%x, off 0x%x", ! bp, bp->offset.LowPart); ! osi_assert(bp->refCount == 0); ! osi_assert(!(bp->flags & (CM_BUF_READING | CM_BUF_WRITING | CM_BUF_DIRTY))); ! lock_AssertWrite(&buf_globalLock); ! ! if (bp->flags & CM_BUF_INHASH) { ! /* Remove from hash */ ! ! i =