From: Jeffrey Altman Date: Sat, 3 Apr 2004 20:50:37 +0000 (+0000) Subject: afsd-improvements-20040403 X-Git-Tag: openafs-devel-1_3_63~11 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=086376b593f78d390d4031b2840b38dea1c1a2f2;p=packages%2Fo%2Fopenafs.git afsd-improvements-20040403 continuing attempts to identify the cause of the crash after the service shuts down successfully. (without success) Add shutdown logic for SMB and RX daemons. Fix Global Drive Mapping Add Global Drive Unmapping --- diff --git a/src/WINNT/afsd/afsd_init.c b/src/WINNT/afsd/afsd_init.c index 1d4ca3e94..6f90c6f0c 100644 --- a/src/WINNT/afsd/afsd_init.c +++ b/src/WINNT/afsd/afsd_init.c @@ -577,14 +577,14 @@ int afsd_InitCM(char **reasonP) DWORD dwDisp; TCHAR value = TEXT("7001:UDP:*:Enabled:AFS Cache Manager Callback"); if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, - "SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile\GloballyOpenP", + "SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\DomainProfile\\GloballyOpenP", 0, TEXT("container"), 0, KEY_SET_VALUE, NULL, &hk, &dwDisp) == ERROR_SUCCESS) { RegSetValueEx (hk, TEXT("7001:UDP"), NULL, REG_SZ, (PBYTE)value, sizeof(TCHAR) * (1+lstrlen(value))); RegCloseKey (hk); } if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, - "SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\GloballyOpenP", + "SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\\GloballyOpenP", 0, TEXT("container"), 0, KEY_SET_VALUE, NULL, &hk, &dwDisp) == ERROR_SUCCESS) { RegSetValueEx (hk, TEXT("7001:UDP"), NULL, REG_SZ, (PBYTE)value, sizeof(TCHAR) * (1+lstrlen(value))); diff --git a/src/WINNT/afsd/afsd_init.h b/src/WINNT/afsd/afsd_init.h index 0f09fd643..123bd385b 100644 --- a/src/WINNT/afsd/afsd_init.h +++ b/src/WINNT/afsd/afsd_init.h @@ -21,4 +21,4 @@ void afsd_ForceTrace(BOOL flush); void afsd_SetUnhandledExceptionFilter(); extern char cm_HostName[]; - +extern char cm_NetbiosName[]; diff --git a/src/WINNT/afsd/afsd_service.c b/src/WINNT/afsd/afsd_service.c index 2ef249dc6..f4c8193ed 100644 --- a/src/WINNT/afsd/afsd_service.c +++ b/src/WINNT/afsd/afsd_service.c @@ -248,51 +248,47 @@ afsd_ServiceControlHandlerEx( return dwRet; } -#if 1 -/* This code was moved to Drivemap.cpp*/ -/* Mount a drive into AFS if the user wants us to */ +/* There is similar code in client_config\drivemap.cpp GlobalMountDrive() + * + * Mount a drive into AFS if there global mapping + */ /* DEE Could check first if we are run as SYSTEM */ -void CheckMountDrive() +static void MountGlobalDrives() { - char szAfsPath[_MAX_PATH]; - char szDriveToMapTo[5]; - DWORD dwResult; - char szKeyName[256]; - HKEY hKey; - DWORD dwIndex = 0; - DWORD dwDriveSize; - DWORD dwSubMountSize; - char szSubMount[256]; - DWORD dwType; - - sprintf(szKeyName, "%s\\GlobalAutoMapper", AFSConfigKeyName); + char szAfsPath[_MAX_PATH]; + char szDriveToMapTo[5]; + DWORD dwResult; + char szKeyName[256]; + HKEY hKey; + DWORD dwIndex = 0; + DWORD dwDriveSize; + DWORD dwSubMountSize; + char szSubMount[256]; + DWORD dwType; + + sprintf(szKeyName, "%s\\GlobalAutoMapper", AFSConfigKeyName); dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_QUERY_VALUE, &hKey); if (dwResult != ERROR_SUCCESS) - return; - - while (1) { - dwDriveSize = sizeof(szDriveToMapTo); - dwSubMountSize = sizeof(szSubMount); - dwResult = RegEnumValue(hKey, dwIndex++, szDriveToMapTo, &dwDriveSize, 0, &dwType, szSubMount, &dwSubMountSize); - if (dwResult != ERROR_MORE_DATA) { - if (dwResult != ERROR_SUCCESS) { - if (dwResult != ERROR_NO_MORE_ITEMS) - afsi_log("Failed to read GlobalAutoMapper values: %d\n", dwResult); - break; - } - } - -#if 0 - sprintf(szAfsPath, "\\Device\\LanmanRedirector\\%s\\%s-AFS\\%s", szDriveToMapTo, cm_HostName, szSubMount); - - dwResult = DefineDosDevice(DDD_RAW_TARGET_PATH, szDriveToMapTo, szAfsPath); -#else + return; + + while (1) { + dwDriveSize = sizeof(szDriveToMapTo); + dwSubMountSize = sizeof(szSubMount); + dwResult = RegEnumValue(hKey, dwIndex++, szDriveToMapTo, &dwDriveSize, 0, &dwType, szSubMount, &dwSubMountSize); + if (dwResult != ERROR_MORE_DATA) { + if (dwResult != ERROR_SUCCESS) { + if (dwResult != ERROR_NO_MORE_ITEMS) + afsi_log("Failed to read GlobalAutoMapper values: %d\n", dwResult); + break; + } + } + { NETRESOURCE nr; memset (&nr, 0x00, sizeof(NETRESOURCE)); - sprintf(szAfsPath,"\\\\%s-AFS\\%s",cm_HostName,szSubMount); + sprintf(szAfsPath,"\\\\%s\\%s",cm_NetbiosName,szSubMount); nr.dwScope = RESOURCE_GLOBALNET; nr.dwType=RESOURCETYPE_DISK; @@ -303,13 +299,52 @@ void CheckMountDrive() dwResult = WNetAddConnection2(&nr,NULL,NULL,FALSE); } -#endif - afsi_log("GlobalAutoMap of %s to %s %s", szDriveToMapTo, szSubMount, dwResult ? "succeeded" : "failed"); - } + afsi_log("GlobalAutoMap of %s to %s %s", szDriveToMapTo, szSubMount, dwResult ? "succeeded" : "failed"); + } - RegCloseKey(hKey); + RegCloseKey(hKey); +} + +static void DismountGlobalDrives() +{ + char szAfsPath[_MAX_PATH]; + char szDriveToMapTo[5]; + DWORD dwResult; + char szKeyName[256]; + HKEY hKey; + DWORD dwIndex = 0; + DWORD dwDriveSize; + DWORD dwSubMountSize; + char szSubMount[256]; + DWORD dwType; + + sprintf(szKeyName, "%s\\GlobalAutoMapper", AFSConfigKeyName); + + dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_QUERY_VALUE, &hKey); + if (dwResult != ERROR_SUCCESS) + return; + + while (1) { + dwDriveSize = sizeof(szDriveToMapTo); + dwSubMountSize = sizeof(szSubMount); + dwResult = RegEnumValue(hKey, dwIndex++, szDriveToMapTo, &dwDriveSize, 0, &dwType, szSubMount, &dwSubMountSize); + if (dwResult != ERROR_MORE_DATA) { + if (dwResult != ERROR_SUCCESS) { + if (dwResult != ERROR_NO_MORE_ITEMS) + afsi_log("Failed to read GlobalAutoMapper values: %d\n", dwResult); + break; + } + } + + sprintf(szAfsPath,"\\\\%s\\%s",cm_NetbiosName,szSubMount); + + dwResult = WNetCancelConnection(szAfsPath, TRUE); + + afsi_log("Disconnect from GlobalAutoMap of %s to %s %s", szDriveToMapTo, szSubMount, dwResult ? "succeeded" : "failed"); + } + + RegCloseKey(hKey); } -#endif typedef BOOL ( APIENTRY * AfsdInitHook )(void); #define AFSD_INIT_HOOK "AfsdInitHook" @@ -330,7 +365,7 @@ void afsd_Main(DWORD argc, LPTSTR *argv) _CRTDBG_CHECK_CRT_DF /* | _CRTDBG_DELAY_FREE_MEM_DF */ ); #endif - osi_InitPanic(afsd_notifier); + osi_InitPanic(afsd_notifier); osi_InitTraceOption(); GlobalStatus = 0; @@ -342,7 +377,7 @@ void afsd_Main(DWORD argc, LPTSTR *argv) afsi_log("Event Object Already Exists: %s", TEXT("afsd_service_WaitToTerminate")); #ifndef NOTSERVICE - StatusHandle = RegisterServiceCtrlHandlerEx(AFS_DAEMON_SERVICE_NAME, + StatusHandle = RegisterServiceCtrlHandlerEx(argv[0] /* AFS_DAEMON_SERVICE_NAME */, (LPHANDLER_FUNCTION_EX) afsd_ServiceControlHandlerEx, NULL /* user context */ ); @@ -445,6 +480,8 @@ void afsd_Main(DWORD argc, LPTSTR *argv) osi_panic(reason, __FILE__, __LINE__); } + MountGlobalDrives(); + #ifndef NOTSERVICE ServiceStatus.dwCurrentState = SERVICE_RUNNING; ServiceStatus.dwWin32ExitCode = NO_ERROR; @@ -464,9 +501,6 @@ void afsd_Main(DWORD argc, LPTSTR *argv) } } - /* Check if we should mount a drive into AFS */ - CheckMountDrive(); - WaitForSingleObject(WaitToTerminate, INFINITE); { @@ -478,6 +512,10 @@ void afsd_Main(DWORD argc, LPTSTR *argv) DeregisterEventSource(h); } + DismountGlobalDrives(); + smb_Shutdown(); + rx_Finalize(); + #ifdef REGISTER_POWER_NOTIFICATIONS /* terminate thread used to flush cache */ PowerNotificationThreadExit(); @@ -489,18 +527,21 @@ void afsd_Main(DWORD argc, LPTSTR *argv) if ( hInitHookDll ) FreeLibrary(hInitHookDll); + Sleep(5000); + ServiceStatus.dwCurrentState = SERVICE_STOPPED; ServiceStatus.dwWin32ExitCode = GlobalStatus ? ERROR_EXCEPTION_IN_SERVICE : NO_ERROR; ServiceStatus.dwCheckPoint = 0; ServiceStatus.dwWaitHint = 0; ServiceStatus.dwControlsAccepted = 0; SetServiceStatus(StatusHandle, &ServiceStatus); + } DWORD __stdcall afsdMain_thread(void* notUsed) { afsd_Main(0, (LPTSTR*)NULL); - exit(0); + return(0); } int @@ -520,7 +561,7 @@ main(void) hAFSDMainThread = CreateThread(NULL, 0, afsdMain_thread, 0, 0, &tid); printf("Hit to terminate OpenAFS Client Service\n"); - getchar(); + getchar(); SetEvent(WaitToTerminate); } } diff --git a/src/WINNT/afsd/afslogon.c b/src/WINNT/afsd/afslogon.c index db4d54a04..71d5354af 100644 --- a/src/WINNT/afsd/afslogon.c +++ b/src/WINNT/afsd/afslogon.c @@ -377,15 +377,15 @@ DWORD APIENTRY NPLogonNotify( RegCloseKey (NPKey); if ((code!=0) || (LSPtype!=REG_DWORD)) LogonOption=LOGON_OPTION_INTEGRATED; /*default to integrated logon only*/ - DebugEvent("AFS AfsLogon - NPLogonNotify","LogonOption[%x], Service AutoStart[%d]", - LogonOption,AFSWillAutoStart()); + afsWillAutoStart = AFSWillAutoStart(); + + DebugEvent("AFS AfsLogon - NPLogonNotify","LogonOption[%x], Service AutoStart[%d]", + LogonOption,afsWillAutoStart); /* Get local machine specified login behavior (or defaults) */ GetLoginBehavior(&retryInterval, &failSilently); - afsWillAutoStart = AFSWillAutoStart(); - /* Check for zero length password if integrated logon*/ if ( ISLOGONINTEGRATED(LogonOption) ) { if ( password[0] == 0 ) { diff --git a/src/WINNT/afsd/smb.c b/src/WINNT/afsd/smb.c index 73c5ef5a3..3fb72c68d 100644 --- a/src/WINNT/afsd/smb.c +++ b/src/WINNT/afsd/smb.c @@ -46,9 +46,7 @@ char *loggedOutName = NULL; smb_user_t *loggedOutUserp = NULL; unsigned long loggedOutTime; int loggedOut = 0; -#ifdef DJGPP int smbShutdownFlag = 0; -#endif /* DJGPP */ int smb_LogoffTokenTransfer; unsigned long smb_LogoffTransferTimeout; @@ -1024,7 +1022,7 @@ void smb_ReleaseFID(smb_fid_t *fidp) smb_ioctl_t *ioctlp; if (!fidp) - return NULL; + return; scp = NULL; lock_ObtainWrite(&smb_rctLock); @@ -6348,11 +6346,6 @@ void smb_Listener(void *parmp) while (1) { memset(ncbp, 0, sizeof(NCB)); flags = 0; -#ifdef DJGPP - /* terminate if shutdown flag is set */ - if (smbShutdownFlag == 1) - thrd_Exit(1); -#endif /* DJGPP */ #ifndef NOEXPIRE /* check for demo expiration */ @@ -6362,7 +6355,11 @@ void smb_Listener(void *parmp) (*smb_MBfunc)(NULL, "AFS demo expiration", "afsd listener", MB_OK|MB_ICONSTOP|MB_SETFOREGROUND); - ExitThread(1); +#ifndef DJGPP + ExitThread(1); +#else + thrd_Exit(1); +#endif } } #endif /* !NOEXPIRE */ @@ -6385,9 +6382,22 @@ void smb_Listener(void *parmp) code = Netbios(ncbp); #else /* DJGPP */ code = Netbios(ncbp, dos_ncb); +#endif if (code != 0) { + /* terminate if shutdown flag is set */ + if (smbShutdownFlag == 1) { +#ifndef DJGPP + ExitThread(1); +#else + thrd_Exit(1); +#endif + } + +#ifndef DJGPP + osi_assert(0); +#else fprintf(stderr, "NCBLISTEN lana=%d failed with code %d\n", ncbp->ncb_lana_num, code); osi_Log2(0, "NCBLISTEN lana=%d failed with code %d", @@ -6396,10 +6406,8 @@ void smb_Listener(void *parmp) "(possibly due to power-saving mode)\n"); fprintf(stderr, "Please restart client.\n"); afs_exit(AFS_EXITCODE_NETWORK_FAILURE); - } #endif /* !DJGPP */ - - osi_assert(code == 0); + } /* check for remote conns */ /* first get remote name and insert null terminator */ @@ -6507,7 +6515,7 @@ void smb_Listener(void *parmp) /* unlock */ lock_ReleaseMutex(&smb_ListenerLock); - } /* dispatch while loop */ + } /* dispatch while loop */ } /* initialize Netbios */ @@ -6972,11 +6980,12 @@ void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt, return; } -#ifdef DJGPP void smb_Shutdown(void) { NCB *ncbp; +#ifdef DJGPP dos_ptr dos_ncb; +#endif long code; int i; @@ -6984,37 +6993,49 @@ void smb_Shutdown(void) /* setup the NCB system */ ncbp = GetNCB(); +#ifdef DJGPP dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb; +#endif /* Block new sessions by setting shutdown flag */ - /*smbShutdownFlag = 1;*/ + smbShutdownFlag = 1; /* Hang up all sessions */ + memset((char *)ncbp, 0, sizeof(NCB)); for (i = 1; i < numSessions; i++) { if (dead_sessions[i]) continue; - + /*fprintf(stderr, "NCBHANGUP session %d LSN %d\n", i, LSNs[i]);*/ ncbp->ncb_command = NCBHANGUP; ncbp->ncb_lana_num = lanas[i]; /*smb_LANadapter;*/ ncbp->ncb_lsn = LSNs[i]; - code = Netbios(ncbp, dos_ncb); +#ifndef DJGPP + code = Netbios(ncbp); +#else + code = Netbios(ncbp, dos_ncb); +#endif /*fprintf(stderr, "returned from NCBHANGUP session %d LSN %d\n", i, LSNs[i]);*/ if (code == 0) code = ncbp->ncb_retcode; if (code != 0) { + osi_Log1(afsd_logp, "Netbios NCBHANGUP error code %d", code); fprintf(stderr, "Session %d Netbios NCBHANGUP error code %d", i, code); } - } + } -#if 1 /* Delete Netbios name */ + memset((char *)ncbp, 0, sizeof(NCB)); for (i = 0; i < lana_list.length; i++) { if (lana_list.lana[i] == 255) continue; ncbp->ncb_command = NCBDELNAME; ncbp->ncb_lana_num = lana_list.lana[i]; memcpy(ncbp->ncb_name,smb_sharename,NCBNAMSZ); +#ifndef DJGPP + code = Netbios(ncbp); +#else code = Netbios(ncbp, dos_ncb); +#endif if (code == 0) code = ncbp->ncb_retcode; if (code != 0) { fprintf(stderr, "Netbios NCBDELNAME lana %d error code %d", @@ -7022,9 +7043,7 @@ void smb_Shutdown(void) } fflush(stderr); } -#endif } -#endif /* DJGPP */ /* Get the UNC \\\ prefix. */ char *smb_GetSharename()