Index: openafs/src/WINNT/afs_setup_utils/afs_setup_utils.cpp diff -c openafs/src/WINNT/afs_setup_utils/afs_setup_utils.cpp:1.8 openafs/src/WINNT/afs_setup_utils/afs_setup_utils.cpp:1.9 *** openafs/src/WINNT/afs_setup_utils/afs_setup_utils.cpp:1.8 Mon Aug 25 14:23:49 2003 --- openafs/src/WINNT/afs_setup_utils/afs_setup_utils.cpp Tue Jul 13 23:28:36 2004 *************** *** 234,244 **** TARGETDIR"\\Common\\*.gid\0" TARGETDIR"\\Common\\*.fts\0" WINDIR"\\..\\AFSCache\0" ! WINDIR"\\afsd.log\0" ! WINDIR"\\afsd.ini\0" ! WINDIR"\\afsdsbmt.ini\0" ! WINDIR"\\afsdcell.ini\0" ! WINDIR"\\afsd_init.log\0", clientRegValues, clientWinNTRegValues, --- 234,244 ---- TARGETDIR"\\Common\\*.gid\0" TARGETDIR"\\Common\\*.fts\0" WINDIR"\\..\\AFSCache\0" ! WINDIR"\\TEMP\\afsd.log\0" ! TARGETDIR"\\Client\\afsd.ini\0" ! TARGETDIR"\\Client\\afsdsbmt.ini\0" ! TARGETDIR"\\Client\\afsdcell.ini\0" ! WINDIR"\\TEMP\\afsd_init.log\0", clientRegValues, clientWinNTRegValues, Index: openafs/src/WINNT/afs_setup_utils/forceremove.c diff -c openafs/src/WINNT/afs_setup_utils/forceremove.c:1.2 openafs/src/WINNT/afs_setup_utils/forceremove.c:1.3 *** openafs/src/WINNT/afs_setup_utils/forceremove.c:1.2 Sat Nov 4 05:01:10 2000 --- openafs/src/WINNT/afs_setup_utils/forceremove.c Tue Jul 13 23:28:36 2004 *************** *** 119,131 **** } } ! sprintf(filePath, "%s\\%s", winPath, "afsd.log"); status = FileForceRemove(filePath); if (status != ERROR_SUCCESS && status != ERROR_FILE_NOT_FOUND) { rc = status; } ! sprintf(filePath, "%s\\%s", winPath, "afsd_init.log"); status = FileForceRemove(filePath); if (status != ERROR_SUCCESS && status != ERROR_FILE_NOT_FOUND) { rc = status; --- 119,131 ---- } } ! sprintf(filePath, "%s\\%s", winPath, "temp\\afsd.log"); status = FileForceRemove(filePath); if (status != ERROR_SUCCESS && status != ERROR_FILE_NOT_FOUND) { rc = status; } ! sprintf(filePath, "%s\\%s", winPath, "temp\\afsd_init.log"); status = FileForceRemove(filePath); if (status != ERROR_SUCCESS && status != ERROR_FILE_NOT_FOUND) { rc = status; *************** *** 144,162 **** } if (!keepConfig) { ! sprintf(filePath, "%s\\%s", winPath, "afsdcell.ini"); status = FileForceRemove(filePath); if (status != ERROR_SUCCESS && status != ERROR_FILE_NOT_FOUND) { rc = status; } ! sprintf(filePath, "%s\\%s", winPath, "afsdsbmt.ini"); status = FileForceRemove(filePath); if (status != ERROR_SUCCESS && status != ERROR_FILE_NOT_FOUND) { rc = status; } ! sprintf(filePath, "%s\\%s", winPath, "afsd.ini"); status = FileForceRemove(filePath); if (status != ERROR_SUCCESS && status != ERROR_FILE_NOT_FOUND) { rc = status; --- 144,162 ---- } if (!keepConfig) { ! sprintf(filePath, "%s\\%s", installPath, "Client\\afsdcell.ini"); status = FileForceRemove(filePath); if (status != ERROR_SUCCESS && status != ERROR_FILE_NOT_FOUND) { rc = status; } ! sprintf(filePath, "%s\\%s", installPath, "Client\\afsdsbmt.ini"); status = FileForceRemove(filePath); if (status != ERROR_SUCCESS && status != ERROR_FILE_NOT_FOUND) { rc = status; } ! sprintf(filePath, "%s\\%s", installPath, "Client\\afsd.ini"); status = FileForceRemove(filePath); if (status != ERROR_SUCCESS && status != ERROR_FILE_NOT_FOUND) { rc = status; Index: openafs/src/WINNT/afsd/NTMakefile diff -c openafs/src/WINNT/afsd/NTMakefile:1.21 openafs/src/WINNT/afsd/NTMakefile:1.26 *** openafs/src/WINNT/afsd/NTMakefile:1.21 Sat Jun 19 11:18:58 2004 --- openafs/src/WINNT/afsd/NTMakefile Thu Jul 22 18:15:47 2004 *************** *** 64,70 **** $(INCFILEDIR)\cm_freelance.h \ $(INCFILEDIR)\afsd_eventlog.h \ $(INCFILEDIR)\afsd_eventmessages.h \ ! $(INCFILEDIR)\afskfw.h IDLFILES =\ afsrpc.h $(OUT)\afsrpc_c.obj --- 64,71 ---- $(INCFILEDIR)\cm_freelance.h \ $(INCFILEDIR)\afsd_eventlog.h \ $(INCFILEDIR)\afsd_eventmessages.h \ ! $(INCFILEDIR)\afskfw.h \ ! $(INCFILEDIR)\afsicf.h IDLFILES =\ afsrpc.h $(OUT)\afsrpc_c.obj *************** *** 116,122 **** !ENDIF $(OUT)\cm_freelance.obj \ $(OUT)\afsd_eventlog.obj \ ! $(OUT)\afsd_flushvol.obj $(AFSDOBJS): --- 117,124 ---- !ENDIF $(OUT)\cm_freelance.obj \ $(OUT)\afsd_eventlog.obj \ ! $(OUT)\afsd_flushvol.obj \ ! $(OUT)\afsicf.obj $(AFSDOBJS): *************** *** 208,213 **** --- 210,216 ---- LOGON_DLLOBJS =\ $(OUT)\afslogon.obj \ + $(OUT)\logon_ad.obj \ $(OUT)\afslogon.res LOGON_DLLLIBS =\ *************** *** 217,224 **** $(DESTDIR)\lib\afsdes.lib \ $(AFSKFWLIB) $(LOGON_DLLFILE): $(LOGON_DLLOBJS) $(LOGON_DLLLIBS) ! $(DLLGUILINK) $(LOGONLINKFLAGS) -def:afslogon.def dnsapi.lib secur32.lib $(DLLPREP) $(COPY) $*.lib $(DESTDIR)\lib $(DEL) $*.lib $*.exp --- 220,238 ---- $(DESTDIR)\lib\afsdes.lib \ $(AFSKFWLIB) + LOGON_DLLSDKLIBS =\ + dnsapi.lib \ + advapi32.lib \ + secur32.lib \ + strsafe.lib \ + oleaut32.lib \ + ole32.lib \ + adsiid.lib \ + activeds.lib \ + userenv.lib + $(LOGON_DLLFILE): $(LOGON_DLLOBJS) $(LOGON_DLLLIBS) ! $(DLLGUILINK) $(LOGONLINKFLAGS) -def:afslogon.def $(LOGON_DLLSDKLIBS) $(DLLPREP) $(COPY) $*.lib $(DESTDIR)\lib $(DEL) $*.lib $*.exp *************** *** 245,253 **** ############################################################################ # Install target; primary makefile target ! install_objs: $(OUT)\cm_dns.obj $(OUT)\cm_config.obj $(LANAHELPERLIB) $(COPY) $(OUT)\cm_dns.obj $(DESTDIR)\lib $(COPY) $(OUT)\cm_config.obj $(DESTDIR)\lib install_headers: $(IDLFILES) $(INCFILES) --- 259,268 ---- ############################################################################ # Install target; primary makefile target ! install_objs: $(OUT)\cm_dns.obj $(OUT)\cm_config.obj $(LANAHELPERLIB) $(OUT)\afsicf.obj $(COPY) $(OUT)\cm_dns.obj $(DESTDIR)\lib $(COPY) $(OUT)\cm_config.obj $(DESTDIR)\lib + $(COPY) $(OUT)\afsicf.obj $(DESTDIR)\lib install_headers: $(IDLFILES) $(INCFILES) *************** *** 322,333 **** AFSD_SDKLIBS =\ largeint.lib \ netapi32.lib \ - mpr.lib \ dnsapi.lib \ rpcrt4.lib \ user32.lib \ Dbghelp.lib \ ! strsafe.lib AFSD_EXELIBS =\ $(DESTDIR)\lib\libosi.lib \ --- 337,351 ---- AFSD_SDKLIBS =\ largeint.lib \ netapi32.lib \ dnsapi.lib \ rpcrt4.lib \ user32.lib \ Dbghelp.lib \ ! strsafe.lib \ ! mpr.lib \ ! secur32.lib \ ! ole32.lib \ ! oleaut32.lib AFSD_EXELIBS =\ $(DESTDIR)\lib\libosi.lib \ Index: openafs/src/WINNT/afsd/afsd.h diff -c openafs/src/WINNT/afsd/afsd.h:1.4 openafs/src/WINNT/afsd/afsd.h:1.5 *** openafs/src/WINNT/afsd/afsd.h:1.4 Fri Oct 5 17:40:47 2001 --- openafs/src/WINNT/afsd/afsd.h Tue Jul 20 10:36:41 2004 *************** *** 61,66 **** --- 61,67 ---- #include "cm_dnlc.h" #include "cm_buf.h" #include "cm_freelance.h" + #include "smb_ioctl.h" #ifdef DJGPP #include "afs/afsmsg95.h" #endif Index: openafs/src/WINNT/afsd/afsd_init.c diff -c openafs/src/WINNT/afsd/afsd_init.c:1.31 openafs/src/WINNT/afsd/afsd_init.c:1.37 *** openafs/src/WINNT/afsd/afsd_init.c:1.31 Sat Jun 19 11:18:59 2004 --- openafs/src/WINNT/afsd/afsd_init.c Sun Jul 25 16:53:12 2004 *************** *** 29,34 **** --- 29,35 ---- #include "smb.h" #include "cm_rpc.h" #include "lanahelper.h" + #include "afsicf.h" extern int RXAFSCB_ExecuteRequest(struct rx_call *z_call); extern int RXSTATS_ExecuteRequest(struct rx_call *z_call); *************** *** 83,88 **** --- 84,91 ---- int cm_sysNameCount = 0; char *cm_sysNameList[MAXNUMSYSNAMES]; + DWORD TraceOption = 0; + /* * AFSD Initialization Log * *************** *** 112,117 **** --- 115,124 ---- char t[100], u[100], *p, *path; int zilch; int code; + DWORD dwLow, dwHigh; + HKEY parmKey; + DWORD dummyLen; + DWORD maxLogSize = 100 * 1024; afsi_file = INVALID_HANDLE_VALUE; if (getenv("TEMP")) *************** *** 127,132 **** --- 134,158 ---- GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t)); afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL); + + code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName, + 0, KEY_QUERY_VALUE, &parmKey); + if (code == ERROR_SUCCESS) { + dummyLen = sizeof(maxLogSize); + code = RegQueryValueEx(parmKey, "MaxLogSize", NULL, NULL, + (BYTE *) &maxLogSize, &dummyLen); + RegCloseKey (parmKey); + } + + if (maxLogSize) { + dwLow = GetFileSize( afsi_file, &dwHigh ); + if ( dwHigh > 0 || dwLow >= maxLogSize ) { + CloseHandle(afsi_file); + afsi_file = CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL, + CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL); + } + } + SetFilePointer(afsi_file, 0, NULL, FILE_END); GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u)); StringCbCatA(t, sizeof(t), ": Create log file\n"); *************** *** 193,198 **** --- 219,359 ---- CloseHandle(handle); } + static void + configureBackConnectionHostNames(void) + { + /* On Windows XP SP2, Windows 2003 SP1, and all future Windows operating systems + * there is a restriction on the use of SMB authentication on loopback connections. + * There are two work arounds available: + * + * (1) We can disable the check for matching host names. This does not + * require a reboot: + * [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa] + * "DisableLoopbackCheck"=dword:00000001 + * + * (2) We can add the AFS SMB/CIFS service name to an approved list. This + * does require a reboot: + * [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0] + * "BackConnectionHostNames"=multi-sz + * + * The algorithm will be: + * (1) Check to see if cm_NetbiosName exists in the BackConnectionHostNames list + * (2a) If not, add it to the list. (This will not take effect until the next reboot.) + * (2b1) and check to see if DisableLoopbackCheck is set. + * (2b2) If not set, set the DisableLoopbackCheck value to 0x1 + * (2b3) and create HKLM\SOFTWARE\OpenAFS\Client UnsetDisableLoopbackCheck + * (2c) else If cm_NetbiosName exists in the BackConnectionHostNames list, + * check for the UnsetDisableLoopbackCheck value. + * If set, set the DisableLoopbackCheck flag to 0x0 + * and delete the UnsetDisableLoopbackCheck value + */ + HKEY hkLsa; + HKEY hkMSV10; + HKEY hkClient; + DWORD dwType; + DWORD dwSize; + DWORD dwValue; + PBYTE pHostNames = NULL, pName; + BOOL bNameFound = FALSE; + + if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, + "SYSTEM\\CurrentControlSet\\Control\\Lsa\\MSV1_0", + 0, + KEY_READ|KEY_WRITE, + &hkMSV10) == ERROR_SUCCESS ) + { + if (RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType, NULL, &dwSize) == ERROR_SUCCESS) { + pHostNames = malloc(dwSize + strlen(cm_NetbiosName) + 1); + RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType, pHostNames, &dwSize); + + for (pName = pHostNames; *pName ; pName += strlen(pName) + 1) + { + if ( !stricmp(pName, cm_NetbiosName) ) { + bNameFound = TRUE; + break; + } + } + } + + if ( !bNameFound ) { + if ( !pHostNames ) { + pName = pHostNames = malloc(strlen(cm_NetbiosName) + 2); + dwSize = 1; + } + strcpy(pName, cm_NetbiosName); + pName += strlen(cm_NetbiosName) + 1; + *pName = '\0'; /* add a second nul terminator */ + + dwType = REG_MULTI_SZ; + dwSize += strlen(cm_NetbiosName) + 1; + RegSetValueEx( hkMSV10, "BackConnectionHostNames", 0, dwType, pHostNames, dwSize); + + if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, + "SYSTEM\\CurrentControlSet\\Control\\Lsa", + 0, + KEY_READ|KEY_WRITE, + &hkLsa) == ERROR_SUCCESS ) + { + dwSize = sizeof(DWORD); + if ( RegQueryValueEx( hkLsa, "DisableLoopbackCheck", 0, &dwType, &dwValue, &dwSize) != ERROR_SUCCESS || + dwValue == 0 ) { + dwType = REG_DWORD; + dwSize = sizeof(DWORD); + dwValue = 1; + RegSetValueEx( hkLsa, "DisableLoopbackCheck", 0, dwType, &dwValue, dwSize); + + if (RegCreateKeyEx( HKEY_LOCAL_MACHINE, + "SOFTWARE\\OpenAFS\\Client", + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_READ|KEY_WRITE, + NULL, + &hkClient, + NULL) == ERROR_SUCCESS) { + + dwType = REG_DWORD; + dwSize = sizeof(DWORD); + dwValue = 1; + RegSetValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, dwType, &dwValue, dwSize); + RegCloseKey(hkClient); + } + RegCloseKey(hkLsa); + } + } + } else { + if (RegCreateKeyEx( HKEY_LOCAL_MACHINE, + "SOFTWARE\\OpenAFS\\Client", + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_READ|KEY_WRITE, + NULL, + &hkClient, + NULL) == ERROR_SUCCESS) { + + dwSize = sizeof(DWORD); + if ( RegQueryValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, &dwType, &dwValue, &dwSize) == ERROR_SUCCESS && + dwValue == 1 ) { + if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, + "SYSTEM\\CurrentControlSet\\Control\\Lsa", + 0, + KEY_READ|KEY_WRITE, + &hkLsa) == ERROR_SUCCESS ) + { + RegDeleteValue(hkLsa, "DisableLoopbackCheck"); + RegCloseKey(hkLsa); + } + } + RegDeleteValue(hkClient, "RemoveDisableLoopbackCheck"); + RegCloseKey(hkClient); + } + } + RegCloseKey(hkMSV10); + } + } + + /* * AFSD Initialization */ *************** *** 205,210 **** --- 366,372 ---- long logChunkSize; long stats; long traceBufSize; + long maxcpus; long ltt, ltto; long rx_mtu, rx_nojumbo; char rootCellName[256]; *************** *** 258,263 **** --- 420,466 ---- 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; + + hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION, + FALSE, GetCurrentProcessId()); + if ( hProcess != NULL && + GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) ) + { + int i, n, bits; + DWORD_PTR mask, newAffinityMask; + + #if defined(_WIN64) + bits = 64; + #else + bits = 32; + #endif + for ( i=0, n=0, mask=1, newAffinityMask=0; i + #include + #include + #include + #include "afsicf.h" + + //#define TESTMAIN + + #ifdef TESTMAIN + #include + #pragma comment(lib,"ole32.lib") + #pragma comment(lib,"oleaut32.lib") + #define DEBUGOUT(x) printf x + #else + #define DEBUGOUT(x) + #endif + + /* an IPv4, enabled port with global scope */ + struct global_afs_port_type { + LPWSTR name; + LONG port; + NET_FW_IP_PROTOCOL protocol; + }; + + typedef struct global_afs_port_type global_afs_port_t; + + global_afs_port_t afs_clientPorts[] = { + { L"AFS CacheManager Callback (UDP)", 7001, NET_FW_IP_PROTOCOL_UDP }, + { L"AFS CacheManager Callback (TCP)", 7001, NET_FW_IP_PROTOCOL_TCP } + }; + + global_afs_port_t afs_serverPorts[] = { + { L"AFS File Server (UDP)", 7000, NET_FW_IP_PROTOCOL_UDP }, + { L"AFS File Server (TCP)", 7000, NET_FW_IP_PROTOCOL_TCP }, + { L"AFS User & Group Database (UDP)", 7002, NET_FW_IP_PROTOCOL_UDP }, + { L"AFS User & Group Database (TCP)", 7002, NET_FW_IP_PROTOCOL_TCP }, + { L"AFS Volume Location Database (UDP)", 7003, NET_FW_IP_PROTOCOL_UDP }, + { L"AFS Volume Location Database (TCP)", 7003, NET_FW_IP_PROTOCOL_TCP }, + { L"AFS/Kerberos Authentication (UDP)", 7004, NET_FW_IP_PROTOCOL_UDP }, + { L"AFS/Kerberos Authentication (TCP)", 7004, NET_FW_IP_PROTOCOL_TCP }, + { L"AFS Volume Mangement (UDP)", 7005, NET_FW_IP_PROTOCOL_UDP }, + { L"AFS Volume Mangement (TCP)", 7005, NET_FW_IP_PROTOCOL_TCP }, + { L"AFS Error Interpretation (UDP)", 7006, NET_FW_IP_PROTOCOL_UDP }, + { L"AFS Error Interpretation (TCP)", 7006, NET_FW_IP_PROTOCOL_TCP }, + { L"AFS Basic Overseer (UDP)", 7007, NET_FW_IP_PROTOCOL_UDP }, + { L"AFS Basic Overseer (TCP)", 7007, NET_FW_IP_PROTOCOL_TCP }, + { L"AFS Server-to-server Updater (UDP)", 7008, NET_FW_IP_PROTOCOL_UDP }, + { L"AFS Server-to-server Updater (TCP)", 7008, NET_FW_IP_PROTOCOL_TCP }, + { L"AFS Remote Cache Manager (UDP)", 7009, NET_FW_IP_PROTOCOL_UDP }, + { L"AFS Remote Cache Manager (TCP)", 7009, NET_FW_IP_PROTOCOL_TCP } + }; + + HRESULT icf_OpenFirewallProfile(INetFwProfile ** fwProfile) { + HRESULT hr = S_OK; + INetFwMgr* fwMgr = NULL; + INetFwPolicy* fwPolicy = NULL; + + *fwProfile = NULL; + + // Create an instance of the firewall settings manager. + hr = CoCreateInstance( + __uuidof(NetFwMgr), + NULL, + CLSCTX_INPROC_SERVER, + __uuidof(INetFwMgr), + reinterpret_cast(static_cast(&fwMgr)) + ); + if (FAILED(hr)) + { + DEBUGOUT(("Can't create fwMgr\n")); + goto error; + } + + // Retrieve the local firewall policy. + hr = fwMgr->get_LocalPolicy(&fwPolicy); + if (FAILED(hr)) + { + DEBUGOUT(("Cant get local policy\n")); + goto error; + } + + // Retrieve the firewall profile currently in effect. + hr = fwPolicy->get_CurrentProfile(fwProfile); + if (FAILED(hr)) + { + DEBUGOUT(("Can't get current profile\n")); + goto error; + } + + error: + + // Release the local firewall policy. + if (fwPolicy != NULL) + { + fwPolicy->Release(); + } + + // Release the firewall settings manager. + if (fwMgr != NULL) + { + fwMgr->Release(); + } + + return hr; + } + + HRESULT icf_CheckAndAddPorts(INetFwProfile * fwProfile, global_afs_port_t * ports, int nPorts) { + INetFwOpenPorts * fwPorts = NULL; + INetFwOpenPort * fwPort = NULL; + HRESULT hr; + HRESULT rhr = S_OK; /* return value */ + + hr = fwProfile->get_GloballyOpenPorts(&fwPorts); + if (FAILED(hr)) { + // Abort! + DEBUGOUT(("Can't get globallyOpenPorts\n")); + rhr = hr; + goto cleanup; + } + + // go through the supplied ports + for (int i=0; iItem(ports[i].port, ports[i].protocol, &fwPort); + if (SUCCEEDED(hr)) { + DEBUGOUT(("Found port for %S\n",ports[i].name)); + hr = fwPort->get_Enabled(&vbEnabled); + if (SUCCEEDED(hr)) { + if ( vbEnabled == VARIANT_FALSE ) { + hr = fwPort->put_Enabled(VARIANT_TRUE); + if (FAILED(hr)) { + // failed. Mark as failure. Don't try to create the port either. + rhr = hr; + } + } // else we are fine + } else { + // Something is wrong with the port. + // We try to create a new one thus overriding this faulty one. + bCreate = TRUE; + } + fwPort->Release(); + fwPort = NULL; + } else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) { + DEBUGOUT(("Port not found for %S\n", ports[i].name)); + bCreate = TRUE; + } + + if (bCreate) { + DEBUGOUT(("Trying to create port %S\n",ports[i].name)); + hr = CoCreateInstance( + __uuidof(NetFwOpenPort), + NULL, + CLSCTX_INPROC_SERVER, + __uuidof(INetFwOpenPort), + reinterpret_cast + (static_cast(&fwPort)) + ); + + if (FAILED(hr)) { + DEBUGOUT(("Can't create port\n")); + rhr = hr; + } else { + DEBUGOUT(("Created port\n")); + hr = fwPort->put_IpVersion( NET_FW_IP_VERSION_ANY ); + if (FAILED(hr)) { + DEBUGOUT(("Can't set IpVersion\n")); + rhr = hr; + goto abandon_port; + } + + hr = fwPort->put_Port( ports[i].port ); + if (FAILED(hr)) { + DEBUGOUT(("Can't set Port\n")); + rhr = hr; + goto abandon_port; + } + + hr = fwPort->put_Protocol( ports[i].protocol ); + if (FAILED(hr)) { + DEBUGOUT(("Can't set Protocol\n")); + rhr = hr; + goto abandon_port; + } + + hr = fwPort->put_Scope( NET_FW_SCOPE_ALL ); + if (FAILED(hr)) { + DEBUGOUT(("Can't set Scope\n")); + rhr = hr; + goto abandon_port; + } + + bstName = SysAllocString( ports[i].name ); + + if (SysStringLen(bstName) == 0) { + rhr = E_OUTOFMEMORY; + } else { + hr = fwPort->put_Name( bstName ); + if (FAILED(hr)) { + DEBUGOUT(("Can't set Name\n")); + rhr = hr; + SysFreeString( bstName ); + goto abandon_port; + } + } + + SysFreeString( bstName ); + + hr = fwPorts->Add( fwPort ); + if (FAILED(hr)) { + DEBUGOUT(("Can't add port\n")); + rhr = hr; + } else + DEBUGOUT(("Added port\n")); + + abandon_port: + fwPort->Release(); + } + } + } // loop through ports + + fwPorts->Release(); + + cleanup: + + if (fwPorts != NULL) + fwPorts->Release(); + + return rhr; + } + + long icf_CheckAndAddAFSPorts(int portset) { + HRESULT hr; + BOOL coInitialized = FALSE; + INetFwProfile * fwProfile = NULL; + global_afs_port_t * ports; + int nports; + long code = 0; + + if (portset == AFS_PORTSET_CLIENT) { + ports = afs_clientPorts; + nports = sizeof(afs_clientPorts) / sizeof(*afs_clientPorts); + } else if (portset == AFS_PORTSET_SERVER) { + ports = afs_serverPorts; + nports = sizeof(afs_serverPorts) / sizeof(*afs_serverPorts); + } else + return 1; /* Invalid port set */ + + hr = CoInitializeEx( + NULL, + COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE + ); + + if (SUCCEEDED(hr) || RPC_E_CHANGED_MODE == hr) + { + coInitialized = TRUE; + } + // not necessarily catastrophic if the call failed. We'll try to + // continue as if it succeeded. + + hr = icf_OpenFirewallProfile(&fwProfile); + if (FAILED(hr)) { + // Ok. That didn't work. This could be because the machine we + // are running on doesn't have Windows Firewall. We'll return + // a failure to the caller, which shouldn't be taken to mean + // it's catastrophic. + DEBUGOUT(("Can't open Firewall profile\n")); + code = 1; + goto cleanup; + } + + // Now that we have a firewall profile, we can start checking + // and adding the ports that we want. + hr = icf_CheckAndAddPorts(fwProfile, ports, nports); + if (FAILED(hr)) + code = 1; + + cleanup: + if (coInitialized) { + CoUninitialize(); + } + + return code; + } + + + #ifdef TESTMAIN + int main(int argc, char **argv) { + printf("Starting...\n"); + if (icf_CheckAndAddAFSPorts(AFS_PORTSET_CLIENT)) + printf("Failed\n"); + else + printf("Succeeded\n"); + printf("Done\n"); + return 0; + } + #endif \ No newline at end of file Index: openafs/src/WINNT/afsd/afsicf.h diff -c /dev/null openafs/src/WINNT/afsd/afsicf.h:1.1 *** /dev/null Tue Jul 27 19:19:43 2004 --- openafs/src/WINNT/afsd/afsicf.h Wed Jul 14 02:00:18 2004 *************** *** 0 **** --- 1,40 ---- + /* + + Copyright 2004 by the Massachusetts Institute of Technology + + All rights reserved. + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose and without fee is hereby granted, + provided that the above copyright notice appear in all copies and that + both that copyright notice and this permission notice appear in + supporting documentation, and that the name of the Massachusetts + Institute of Technology (M.I.T.) not be used in advertising or publicity + pertaining to distribution of the software without specific, written + prior permission. + + M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + SOFTWARE. + + */ + + #pragma once + + #ifdef __cplusplus + extern "C" { + #endif + + long icf_CheckAndAddAFSPorts(int portset); + + #ifdef __cplusplus + } + #endif + + #define AFS_PORTSET_CLIENT 1 + #define AFS_PORTSET_SERVER 2 + Index: openafs/src/WINNT/afsd/afskfw-int.h diff -c openafs/src/WINNT/afsd/afskfw-int.h:1.2 openafs/src/WINNT/afsd/afskfw-int.h:1.3 *** openafs/src/WINNT/afsd/afskfw-int.h:1.2 Sun May 30 11:54:13 2004 --- openafs/src/WINNT/afsd/afskfw-int.h Thu Jul 22 18:41:27 2004 *************** *** 247,251 **** int KFW_AFS_klog(krb5_context, krb5_ccache, char*, char*, char*, int, char*); void KFW_import_ccache_data(void); BOOL MSLSA_IsKerberosLogon(); ! char *afs_realm_of_cell(struct afsconf_cell *); #endif /* AFSKFW_INT_H */ --- 247,251 ---- int KFW_AFS_klog(krb5_context, krb5_ccache, char*, char*, char*, int, char*); void KFW_import_ccache_data(void); BOOL MSLSA_IsKerberosLogon(); ! char *afs_realm_of_cell(krb5_context, struct afsconf_cell *); #endif /* AFSKFW_INT_H */ Index: openafs/src/WINNT/afsd/afskfw.c diff -c openafs/src/WINNT/afsd/afskfw.c:1.6 openafs/src/WINNT/afsd/afskfw.c:1.8 *** openafs/src/WINNT/afsd/afskfw.c:1.6 Fri Jun 18 13:36:33 2004 --- openafs/src/WINNT/afsd/afskfw.c Sun Jul 11 17:23:07 2004 *************** *** 1197,1219 **** if ( lifetime == 0 ) lifetime = pLeash_get_default_lifetime(); ! code = KFW_kinit(ctx, cc, HWND_DESKTOP, ! pname, ! password, ! lifetime, ! pLeash_get_default_forwardable(), ! pLeash_get_default_proxiable(), ! pLeash_get_default_renewable() ? pLeash_get_default_renew_till() : 0, ! pLeash_get_default_noaddresses(), ! pLeash_get_default_publicip()); ! if ( IsDebuggerPresent() ) { ! char message[256]; ! sprintf(message,"KFW_kinit() returns: %d\n",code); ! OutputDebugString(message); } - if ( code ) goto cleanup; - - KFW_AFS_update_princ_ccache_data(ctx, cc, FALSE); code = KFW_AFS_klog(ctx, cc, "afs", cell, realm, lifetime,smbname); if ( IsDebuggerPresent() ) { --- 1197,1221 ---- if ( lifetime == 0 ) lifetime = pLeash_get_default_lifetime(); ! if ( password && password[0] ) { ! code = KFW_kinit( ctx, cc, HWND_DESKTOP, ! pname, ! password, ! lifetime, ! pLeash_get_default_forwardable(), ! pLeash_get_default_proxiable(), ! pLeash_get_default_renewable() ? pLeash_get_default_renew_till() : 0, ! pLeash_get_default_noaddresses(), ! pLeash_get_default_publicip()); ! if ( IsDebuggerPresent() ) { ! char message[256]; ! sprintf(message,"KFW_kinit() returns: %d\n",code); ! OutputDebugString(message); ! } ! if ( code ) goto cleanup; ! ! KFW_AFS_update_princ_ccache_data(ctx, cc, FALSE); } code = KFW_AFS_klog(ctx, cc, "afs", cell, realm, lifetime,smbname); if ( IsDebuggerPresent() ) { *************** *** 2716,2728 **** } if ( smbname ) { ! strncpy(aclient.smbname, smbname, MAXRANDOMNAMELEN); ! aclient.smbname[MAXRANDOMNAMELEN-1] = '\0'; } else { aclient.smbname[0] = '\0'; } ! rc = ktc_SetToken(&aserver, &atoken, &aclient, 0); if (!rc) goto cleanup; /* We have successfully inserted the token */ --- 2718,2730 ---- } if ( smbname ) { ! strncpy(aclient.smbname, smbname, sizeof(aclient.smbname)); ! aclient.smbname[sizeof(aclient.smbname)-1] = '\0'; } else { aclient.smbname[0] = '\0'; } ! rc = ktc_SetToken(&aserver, &atoken, &aclient, (aclient.smbname[0]?AFS_SETTOK_LOGON:0)); if (!rc) goto cleanup; /* We have successfully inserted the token */ *************** *** 2834,2846 **** strcpy(aclient.cell, CellName); if ( smbname ) { ! strncpy(aclient.smbname, smbname, MAXRANDOMNAMELEN); ! aclient.smbname[MAXRANDOMNAMELEN-1] = '\0'; } else { aclient.smbname[0] = '\0'; } ! if (rc = ktc_SetToken(&aserver, &atoken, &aclient, 0)) { KFW_AFS_error(rc, "ktc_SetToken()"); code = rc; --- 2836,2848 ---- strcpy(aclient.cell, CellName); if ( smbname ) { ! strncpy(aclient.smbname, smbname, sizeof(aclient.smbname)); ! aclient.smbname[sizeof(aclient.smbname)-1] = '\0'; } else { aclient.smbname[0] = '\0'; } ! if (rc = ktc_SetToken(&aserver, &atoken, &aclient, (aclient.smbname[0]?AFS_SETTOK_LOGON:0))) { KFW_AFS_error(rc, "ktc_SetToken()"); code = rc; Index: openafs/src/WINNT/afsd/afslogon.c diff -c openafs/src/WINNT/afsd/afslogon.c:1.14 openafs/src/WINNT/afsd/afslogon.c:1.23 *** openafs/src/WINNT/afsd/afslogon.c:1.14 Thu May 6 16:46:31 2004 --- openafs/src/WINNT/afsd/afslogon.c Mon Jul 26 19:14:42 2004 *************** *** 7,95 **** * directory or online at http://www.openafs.org/dl/license10.html */ ! #include ! #include - #include - #include #include ! #include "afsd.h" #include #include #include "cm_config.h" #include "krb.h" ! #include ! #include ! #include ! #include ! ! DWORD LogonOption,TraceOption; HANDLE hDLL; WSADATA WSAjunk; ! ! #define REG_CLIENT_PARMS_KEY "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters" ! #define REG_CLIENT_PROVIDER_KEY "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\NetworkProvider" ! #define REG_CLIENT_RETRY_INTERVAL_PARM "LoginRetryInterval" ! #define REG_CLIENT_FAIL_SILENTLY_PARM "FailLoginsSilently" ! #define DEFAULT_RETRY_INTERVAL 30 /* seconds*/ ! #define DEFAULT_FAIL_SILENTLY FALSE ! #define DEFAULT_SLEEP_INTERVAL 5 /* seconds*/ ! ! #define ISLOGONINTEGRATED(v) ( ((v) & LOGON_OPTION_INTEGRATED)==LOGON_OPTION_INTEGRATED) ! #define ISHIGHSECURITY(v) ( ((v) & LOGON_OPTION_HIGHSECURITY)==LOGON_OPTION_HIGHSECURITY) ! ! #define TRACE_OPTION_EVENT 1 ! #define ISLOGONTRACE(v) ( ((v) & TRACE_OPTION_EVENT)==TRACE_OPTION_EVENT) ! ! /* Structure def copied from DDK (NTDEF.H) */ ! typedef struct UNICODE_STRING { ! USHORT Length; /* number of bytes of Buffer actually used */ ! USHORT MaximumLength; /* sizeof buffer in bytes */ ! WCHAR *Buffer; /* 16 bit characters */ ! } UNICODE_STRING; ! ! /* Structure def copied from NP API documentation */ ! typedef struct _MSV1_0_INTERACTIVE_LOGON { ! DWORD MessageType; /* Actually this is an enum; ignored */ ! UNICODE_STRING LogonDomainName; ! UNICODE_STRING UserName; ! UNICODE_STRING Password; ! } MSV1_0_INTERACTIVE_LOGON; ! ! /* ! * GetLogonScript ! * ! * We get a logon script pathname from the HKEY_LOCAL_MACHINE registry. ! * I don't know what good this does; I just copied it from DFS. ! * ! * Returns NULL on failure. ! */ ! void DebugEvent0(char *a) { HANDLE h; char *ptbuf[1]; if (!ISLOGONTRACE(TraceOption)) return; ! h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); ptbuf[0] = a; ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL); DeregisterEventSource(h); } ! #define MAXBUF_ 131 ! void DebugEvent(char *a,char *b,...) { HANDLE h; char *ptbuf[1],buf[MAXBUF_+1]; va_list marker; if (!ISLOGONTRACE(TraceOption)) return; ! h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); va_start(marker,b); ! _vsnprintf(buf,MAXBUF_,b,marker); buf[MAXBUF_] = '\0'; ptbuf[0] = buf; ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL);\ --- 7,61 ---- * directory or online at http://www.openafs.org/dl/license10.html */ ! #include "afslogon.h" ! ! #include ! #include ! #include ! #include #include ! ! #include ! #include #include #include + + #include "afsd.h" #include "cm_config.h" #include "krb.h" + #include "afskfw.h" ! DWORD TraceOption = 0; HANDLE hDLL; WSADATA WSAjunk; ! #define AFS_LOGON_EVENT_NAME TEXT("AFS Logon") void DebugEvent0(char *a) { HANDLE h; char *ptbuf[1]; if (!ISLOGONTRACE(TraceOption)) return; ! h = RegisterEventSource(NULL, AFS_LOGON_EVENT_NAME); ptbuf[0] = a; ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL); DeregisterEventSource(h); } ! #define MAXBUF_ 512 ! void DebugEvent(char *b,...) { HANDLE h; char *ptbuf[1],buf[MAXBUF_+1]; va_list marker; + if (!ISLOGONTRACE(TraceOption)) return; ! ! h = RegisterEventSource(NULL, AFS_LOGON_EVENT_NAME); va_start(marker,b); ! StringCbVPrintf(buf, MAXBUF_+1,b,marker); buf[MAXBUF_] = '\0'; ptbuf[0] = buf; ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL);\ *************** *** 107,172 **** return pbuf; } - WCHAR *GetLogonScript(CHAR *pname) - { - WCHAR *script,*buf; - DWORD code; - DWORD LSPtype, LSPsize; - HKEY NPKey; - WCHAR randomName[MAXRANDOMNAMELEN]; - - /* - * Get Network Provider key. - * Assume this works or we wouldn't be here. - */ - (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PROVIDER_KEY, - 0, KEY_QUERY_VALUE, &NPKey); - - /* - * Get Logon Script pathname length - */ - - code = RegQueryValueExW(NPKey, L"LogonScript", NULL, - &LSPtype, NULL, &LSPsize); - - if (code) { - RegCloseKey (NPKey); - return NULL; - } - - if (LSPtype != REG_SZ) { /* Maybe handle REG_EXPAND_SZ? */ - RegCloseKey (NPKey); - return NULL; - } - - buf=(WCHAR *)LocalAlloc(LMEM_FIXED,LSPsize); - script=(WCHAR *)LocalAlloc(LMEM_FIXED,LSPsize+(MAXRANDOMNAMELEN)*sizeof(WCHAR)); - /* - * Explicitly call UNICODE version - * Assume it will succeed since it did before - */ - (void) RegQueryValueExW(NPKey, L"LogonScript", NULL, - &LSPtype, (LPBYTE)buf, &LSPsize); - MultiByteToWideChar(CP_ACP,0,pname,strlen(pname)+1,randomName,(strlen(pname)+1)*sizeof(WCHAR)); - swprintf(script,buf,randomName); - LocalFree(buf); - - #ifdef DEBUG_VERBOSE - { - HANDLE h; char *ptbuf[1],buf[132],tbuf[255]; - WideCharToMultiByte(CP_ACP,0,script,LSPsize,tbuf,255,NULL,NULL); - h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); - sprintf(buf, "Script[%s,%d] Return Code[%x]",tbuf,LSPsize,code); - ptbuf[0] = buf; - ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, ptbuf, NULL); - DeregisterEventSource(h); - } - #endif - - RegCloseKey (NPKey); - return script; - } - BOOLEAN AFSWillAutoStart(void) { SC_HANDLE scm; --- 73,78 ---- *************** *** 178,184 **** LONG status; /* Open services manager */ ! scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (!scm) return FALSE; /* Open AFSD service */ --- 84,90 ---- LONG status; /* Open services manager */ ! scm = OpenSCManager(NULL, NULL, GENERIC_READ); if (!scm) return FALSE; /* Open AFSD service */ *************** *** 220,230 **** DWORD MapAuthError(DWORD code) { switch (code) { ! case KTC_NOCM: case KTC_NOCMRPC: ! return WN_NO_NETWORK; ! /* case INTK_BADPW: return WN_BAD_PASSWORD;*/ ! /* case KERB_ERR_PRINCIPAL_UNKNOWN: return WN_BAD_USER;*/ default: return WN_SUCCESS; } } --- 126,140 ---- DWORD MapAuthError(DWORD code) { switch (code) { ! /* Unfortunately, returning WN_NO_NETWORK results in the MPR abandoning ! * logon scripts for all credential managers, although they will still ! * receive logon notifications. Since we don't want this, we return ! * WN_SUCCESS. This is highly undesirable, but we also don't want to ! * break other network providers. ! */ ! /* case KTC_NOCM: case KTC_NOCMRPC: ! return WN_NO_NETWORK; */ default: return WN_SUCCESS; } } *************** *** 257,294 **** case WNNC_NET_TYPE: /* Don't have our own type; use somebody else's. */ return WNNC_NET_SUN_PC_NFS; default: return 0; } } - static void GetLoginBehavior(int *pRetryInterval, BOOLEAN *pFailSilently) - { - long result; - HKEY hKey; - DWORD dummyLen; - - result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PARMS_KEY, 0, KEY_QUERY_VALUE, &hKey); - if (result != ERROR_SUCCESS) { - *pRetryInterval = DEFAULT_RETRY_INTERVAL; - *pFailSilently = DEFAULT_FAIL_SILENTLY; - return; - } - - result = RegQueryValueEx(hKey, REG_CLIENT_RETRY_INTERVAL_PARM, 0, 0, (BYTE *)pRetryInterval, &dummyLen); - if (result != ERROR_SUCCESS) - *pRetryInterval = DEFAULT_RETRY_INTERVAL; - - result = RegQueryValueEx(hKey, REG_CLIENT_FAIL_SILENTLY_PARM, 0, 0, (BYTE *)pFailSilently, &dummyLen); - if (result != ERROR_SUCCESS) - *pFailSilently = DEFAULT_FAIL_SILENTLY; - - /* Make sure this is really a bool value in the strict sense*/ - *pFailSilently = !!*pFailSilently; - - RegCloseKey(hKey); - } - BOOL IsServiceRunning (void) { SERVICE_STATUS Status; --- 167,182 ---- case WNNC_NET_TYPE: /* Don't have our own type; use somebody else's. */ return WNNC_NET_SUN_PC_NFS; + + case WNNC_START: + /* Say we are already started, even though we might wait after we receive NPLogonNotify */ + return 1; + default: return 0; } } BOOL IsServiceRunning (void) { SERVICE_STATUS Status; *************** *** 311,316 **** --- 199,517 ---- return (Status.dwCurrentState == SERVICE_RUNNING); } + /* LOOKUPKEYCHAIN: macro to look up the value in the list of keys in order until it's found + v:variable to receive value (reference type) + t:type + d:default, in case the value isn't on any of the keys + n:name of value */ + #define LOOKUPKEYCHAIN(v,t,d,n) \ + do { \ + rv = ~ERROR_SUCCESS; \ + dwType = t; \ + if(hkDom) { \ + dwSize = sizeof(v); \ + rv = RegQueryValueEx(hkDom, n, 0, &dwType, (LPBYTE) &(v), &dwSize); \ + if(rv == ERROR_SUCCESS) DebugEvent(#v " found in hkDom with type [%d]", dwType); \ + } \ + if(hkDoms && (rv != ERROR_SUCCESS || dwType != t)) { \ + dwSize = sizeof(v); \ + rv = RegQueryValueEx(hkDoms, n, 0, &dwType, (LPBYTE) &(v), &dwSize); \ + if(rv == ERROR_SUCCESS) DebugEvent(#v " found in hkDoms with type [%d]", dwType); \ + } \ + if(hkNp && (rv != ERROR_SUCCESS || dwType != t)) { \ + dwSize = sizeof(v); \ + rv = RegQueryValueEx(hkNp, n, 0, &dwType, (LPBYTE) &(v), &dwSize); \ + if(rv == ERROR_SUCCESS) DebugEvent(#v " found in hkNp with type [%d]", dwType); \ + } \ + if(rv != ERROR_SUCCESS || dwType != t) { \ + v = d; \ + DebugEvent(#v " being set to default"); \ + } \ + } while(0) + + /* Get domain specific configuration info. We are returning void because if anything goes wrong + we just return defaults. + */ + void GetDomainLogonOptions( PLUID lpLogonId, char * username, char * domain, LogonOptions_t *opt ) { + HKEY hkParm = NULL; /* Service parameter */ + HKEY hkNp = NULL; /* network provider key */ + HKEY hkDoms = NULL; /* domains key */ + HKEY hkDom = NULL; /* DOMAINS/domain key */ + HKEY hkTemp = NULL; + LONG rv; + DWORD dwSize; + DWORD dwType; + DWORD dwDummy; + char computerName[MAX_COMPUTERNAME_LENGTH + 1]; + char *effDomain; + + DebugEvent("In GetDomainLogonOptions for user [%s] in domain [%s]", username, domain); + /* If the domain is the same as the Netbios computer name, we use the LOCALHOST domain name*/ + opt->flags = LOGON_FLAG_REMOTE; + if(domain) { + dwSize = MAX_COMPUTERNAME_LENGTH; + if(GetComputerName(computerName, &dwSize)) { + if(!stricmp(computerName, domain)) { + effDomain = "LOCALHOST"; + opt->flags = LOGON_FLAG_LOCAL; + } + else + effDomain = domain; + } + } else + effDomain = NULL; + + rv = RegOpenKeyEx( HKEY_LOCAL_MACHINE, REG_CLIENT_PARMS_KEY, 0, KEY_READ, &hkParm ); + if(rv != ERROR_SUCCESS) { + hkParm = NULL; + DebugEvent("GetDomainLogonOption: Can't open parms key [%d]", rv); + } + + rv = RegOpenKeyEx( HKEY_LOCAL_MACHINE, REG_CLIENT_PROVIDER_KEY, 0, KEY_READ, &hkNp ); + if(rv != ERROR_SUCCESS) { + hkNp = NULL; + DebugEvent("GetDomainLogonOptions: Can't open NP key [%d]", rv); + } + + if(hkNp) { + rv = RegOpenKeyEx( hkNp, REG_CLIENT_DOMAINS_SUBKEY, 0, KEY_READ, &hkDoms ); + if( rv != ERROR_SUCCESS ) { + hkDoms = NULL; + DebugEvent("GetDomainLogonOptions: Can't open Domains key [%d]", rv); + } + } + + if(hkDoms && effDomain) { + rv = RegOpenKeyEx( hkDoms, effDomain, 0, KEY_READ, &hkDom ); + if( rv != ERROR_SUCCESS ) { + hkDom = NULL; + DebugEvent("GetDomainLogonOptions: Can't open domain key for [%s] [%d]", effDomain, rv); + /* If none of the domains match, we shouldn't use the domain key either */ + RegCloseKey(hkDoms); + hkDoms = NULL; + } + } else + DebugEvent("Not opening domain key for [%s]", effDomain); + + /* Each individual can either be specified on the domain key, the domains key or in the + net provider key. They fail over in that order. If none is found, we just use the + defaults. */ + + /* LogonOption */ + LOOKUPKEYCHAIN(opt->LogonOption, REG_DWORD, DEFAULT_LOGON_OPTION, REG_CLIENT_LOGON_OPTION_PARM); + + /* FailLoginsSilently */ + dwSize = sizeof(dwDummy); + rv = RegQueryValueEx(hkParm, REG_CLIENT_FAIL_SILENTLY_PARM, 0, &dwType, (LPBYTE) &dwDummy, &dwSize); + if(rv != ERROR_SUCCESS) + LOOKUPKEYCHAIN(dwDummy, REG_DWORD, DEFAULT_FAIL_SILENTLY, REG_CLIENT_FAIL_SILENTLY_PARM); + opt->failSilently = !!dwDummy; + + /* Retry interval */ + LOOKUPKEYCHAIN(opt->retryInterval, REG_DWORD, DEFAULT_RETRY_INTERVAL, REG_CLIENT_RETRY_INTERVAL_PARM); + + /* Sleep interval */ + LOOKUPKEYCHAIN(opt->sleepInterval, REG_DWORD, DEFAULT_SLEEP_INTERVAL, REG_CLIENT_SLEEP_INTERVAL_PARM); + + opt->logonScript = NULL; + opt->smbName = NULL; + + if(!ISLOGONINTEGRATED(opt->LogonOption)) { + goto cleanup; /* no need to lookup the logon script */ + } + + /* come up with SMB username */ + if(ISHIGHSECURITY(opt->LogonOption)) { + opt->smbName = malloc( MAXRANDOMNAMELEN ); + GenRandomName(opt->smbName); + } else { + /* username and domain for logon session is not necessarily the same as + username and domain passed into network provider. */ + PSECURITY_LOGON_SESSION_DATA plsd; + char lsaUsername[MAX_USERNAME_LENGTH]; + char lsaDomain[MAX_DOMAIN_LENGTH]; + size_t len, tlen; + + LsaGetLogonSessionData(lpLogonId, &plsd); + + UnicodeStringToANSI(plsd->UserName, lsaUsername, MAX_USERNAME_LENGTH); + UnicodeStringToANSI(plsd->LogonDomain, lsaDomain, MAX_DOMAIN_LENGTH); + + DebugEvent("PLSD username[%s] domain[%s]",lsaUsername,lsaDomain); + + if(SUCCEEDED(StringCbLength(lsaUsername, MAX_USERNAME_LENGTH, &tlen))) + len = tlen; + else + goto bad_strings; + + if(SUCCEEDED(StringCbLength(lsaDomain, MAX_DOMAIN_LENGTH, &tlen))) + len += tlen; + else + goto bad_strings; + + len += 2; + + opt->smbName = malloc(len); + + StringCbCopy(opt->smbName, len, lsaDomain); + StringCbCat(opt->smbName, len, "\\"); + StringCbCat(opt->smbName, len, lsaUsername); + + strlwr(opt->smbName); + + bad_strings: + LsaFreeReturnBuffer(plsd); + } + + DebugEvent("Looking up logon script"); + /* Logon script */ + /* First find out where the key is */ + hkTemp = NULL; + rv = ~ERROR_SUCCESS; + dwType = 0; + if(hkDom) + rv = RegQueryValueExW(hkDom, REG_CLIENT_LOGON_SCRIPT_PARMW, 0, &dwType, NULL, &dwSize); + if(rv == ERROR_SUCCESS && (dwType == REG_SZ || dwType == REG_EXPAND_SZ)) { + hkTemp = hkDom; + DebugEvent("Located logon script in hkDom"); + } + else if(hkDoms) + rv = RegQueryValueExW(hkDoms, REG_CLIENT_LOGON_SCRIPT_PARMW, 0, &dwType, NULL, &dwSize); + if(rv == ERROR_SUCCESS && !hkTemp && (dwType == REG_SZ || dwType == REG_EXPAND_SZ)) { + hkTemp = hkDoms; + DebugEvent("Located logon script in hkDoms"); + } + /* Note that the LogonScript in the NP key is only used if we are doing high security. */ + else if(hkNp && ISHIGHSECURITY(opt->LogonOption)) + rv = RegQueryValueExW(hkNp, REG_CLIENT_LOGON_SCRIPT_PARMW, 0, &dwType, NULL, &dwSize); + if(rv == ERROR_SUCCESS && !hkTemp && (dwType == REG_SZ || dwType == REG_EXPAND_SZ)) { + hkTemp = hkNp; + DebugEvent("Located logon script in hkNp"); + } + + if(hkTemp) { + WCHAR *regscript = NULL; + WCHAR *regexscript = NULL; + WCHAR *regexuscript = NULL; + WCHAR *wuname = NULL; + HRESULT hr; + + size_t len; + + StringCbLength(opt->smbName, MAX_USERNAME_LENGTH, &len); + len ++; + + wuname = malloc(len * sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP,0,opt->smbName,-1,wuname,len*sizeof(WCHAR)); + + DebugEvent("Username is set for [%S]", wuname); + + /* dwSize still has the size of the required buffer in bytes. */ + regscript = malloc(dwSize); + rv = RegQueryValueExW(hkTemp, REG_CLIENT_LOGON_SCRIPT_PARMW, 0, &dwType, (LPBYTE) regscript, &dwSize); + if(rv != ERROR_SUCCESS) {/* what the ..? */ + DebugEvent("Can't look up logon script [%d]",rv); + goto doneLogonScript; + } + + DebugEvent("Found logon script [%S]", regscript); + + if(dwType == REG_EXPAND_SZ) { + DWORD dwReq; + + dwSize += MAX_PATH * sizeof(WCHAR); /* make room for environment expansion. */ + regexscript = malloc(dwSize); + dwReq = ExpandEnvironmentStringsW(regscript, regexscript, dwSize / sizeof(WCHAR)); + free(regscript); + regscript = regexscript; + regexscript = NULL; + if(dwReq > (dwSize / sizeof(WCHAR))) { + DebugEvent("Overflow while expanding environment strings."); + goto doneLogonScript; + } + } + + DebugEvent("After expanding env strings [%S]", regscript); + + if(wcsstr(regscript, L"%s")) { + dwSize += len * sizeof(WCHAR); /* make room for username expansion */ + regexuscript = (WCHAR *) LocalAlloc(LMEM_FIXED, dwSize); + hr = StringCbPrintfW(regexuscript, dwSize, regscript, wuname); + } else { + regexuscript = (WCHAR *) LocalAlloc(LMEM_FIXED, dwSize); + hr = StringCbCopyW(regexuscript, dwSize, regscript); + } + + DebugEvent("After expanding username [%S]", regexuscript); + + if(hr == S_OK) + opt->logonScript = regexuscript; + else + LocalFree(regexuscript); + + doneLogonScript: + if(wuname) free(wuname); + if(regscript) free(regscript); + if(regexscript) free(regexscript); + } + + cleanup: + if(hkNp) RegCloseKey(hkNp); + if(hkDom) RegCloseKey(hkDom); + if(hkDoms) RegCloseKey(hkDoms); + if(hkParm) RegCloseKey(hkParm); + } + + #undef LOOKUPKEYCHAIN + + /* Try to find out which cell the given path is in. We must retain + the contents of *cell in case of failure. *cell is assumed to be + at least cellLen chars */ + DWORD GetFileCellName(char * path, char * cell, size_t cellLen) { + struct ViceIoctl blob; + char tcell[MAX_PATH]; + DWORD code; + + blob.in_size = 0; + blob.out_size = MAX_PATH; + blob.out = tcell; + + code = pioctl(path, VIOC_FILE_CELL_NAME, &blob, 1); + + if(!code) { + strncpy(cell, tcell, cellLen); + cell[cellLen - 1] = '\0'; + } + return code; + } + + + static BOOL + WINAPI + UnicodeStringToANSI(UNICODE_STRING uInputString, LPSTR lpszOutputString, int nOutStringLen) + { + CPINFO CodePageInfo; + + GetCPInfo(CP_ACP, &CodePageInfo); + + if (CodePageInfo.MaxCharSize > 1) + // Only supporting non-Unicode strings + return FALSE; + + if (uInputString.Buffer && ((LPBYTE) uInputString.Buffer)[1] == '\0') + { + // Looks like unicode, better translate it + // UNICODE_STRING specifies the length of the buffer string in Bytes not WCHARS + WideCharToMultiByte(CP_ACP, 0, (LPCWSTR) uInputString.Buffer, uInputString.Length/2, + lpszOutputString, nOutStringLen-1, NULL, NULL); + lpszOutputString[min(uInputString.Length/2,nOutStringLen-1)] = '\0'; + return TRUE; + } + else + lpszOutputString[0] = '\0'; + return FALSE; + } // UnicodeStringToANSI + DWORD APIENTRY NPLogonNotify( PLUID lpLogonId, LPCWSTR lpAuthentInfoType, *************** *** 321,357 **** LPVOID StationHandle, LPWSTR *lpLogonScript) { ! char uname[256]=""; ! char *ctemp; ! char password[256]=""; char cell[256]=""; MSV1_0_INTERACTIVE_LOGON *IL; DWORD code; int pw_exp; char *reason; BOOLEAN interactive; BOOLEAN flag; DWORD LSPtype, LSPsize; HKEY NPKey; HWND hwndOwner = (HWND)StationHandle; ! BOOLEAN failSilently; ! int retryInterval; ! int sleepInterval = DEFAULT_SLEEP_INTERVAL; /* seconds */ ! BOOLEAN afsWillAutoStart; ! CHAR RandomName[MAXRANDOMNAMELEN]; BOOLEAN uppercased_name = TRUE; /* Initialize Logon Script to none */ *lpLogonScript=NULL; ! IL = (MSV1_0_INTERACTIVE_LOGON *) lpAuthentInfo; /* Are we interactive? */ interactive = (wcscmp(lpStationName, L"WinSta0") == 0); /* Convert from Unicode to ANSI */ ! wcstombs(uname, IL->UserName.Buffer, 256); ! wcstombs(password, IL->Password.Buffer, 256); /* Make sure AD-DOMANS sent from login that is sent to us is striped */ ctemp = strchr(uname, '@'); --- 522,573 ---- LPVOID StationHandle, LPWSTR *lpLogonScript) { ! char uname[MAX_USERNAME_LENGTH]=""; ! char password[MAX_PASSWORD_LENGTH]=""; ! char logonDomain[MAX_DOMAIN_LENGTH]=""; char cell[256]=""; + char homePath[MAX_PATH]=""; + MSV1_0_INTERACTIVE_LOGON *IL; + DWORD code; + int pw_exp; char *reason; + char *ctemp; + BOOLEAN interactive; BOOLEAN flag; DWORD LSPtype, LSPsize; HKEY NPKey; + HWND hwndOwner = (HWND)StationHandle; ! ! BOOLEAN afsWillAutoStart; ! BOOLEAN uppercased_name = TRUE; + LogonOptions_t opt; /* domain specific logon options */ + int retryInterval; + int sleepInterval; + /* Initialize Logon Script to none */ *lpLogonScript=NULL; ! ! /* TODO: We should check the value of lpAuthentInfoType before assuming that it is ! MSV1_0_INTERACTIVE_LOGON though for our purposes KERB_INTERACTIVE_LOGON is ! co-incidentally equivalent. */ IL = (MSV1_0_INTERACTIVE_LOGON *) lpAuthentInfo; /* Are we interactive? */ interactive = (wcscmp(lpStationName, L"WinSta0") == 0); /* Convert from Unicode to ANSI */ ! ! /*TODO: Use SecureZeroMemory to erase passwords */ ! UnicodeStringToANSI(IL->UserName, uname, MAX_USERNAME_LENGTH); ! UnicodeStringToANSI(IL->Password, password, MAX_PASSWORD_LENGTH); ! UnicodeStringToANSI(IL->LogonDomainName, logonDomain, MAX_DOMAIN_LENGTH); /* Make sure AD-DOMANS sent from login that is sent to us is striped */ ctemp = strchr(uname, '@'); *************** *** 368,440 **** (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PARMS_KEY, 0, KEY_QUERY_VALUE, &NPKey); LSPsize=sizeof(TraceOption); ! RegQueryValueEx(NPKey, "TraceOption", NULL, &LSPtype, (LPBYTE)&TraceOption, &LSPsize); ! RegCloseKey (NPKey); ! /* ! * Get Logon OPTIONS */ ! (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PROVIDER_KEY, ! 0, KEY_QUERY_VALUE, &NPKey); ! ! LSPsize=sizeof(LogonOption); ! code = RegQueryValueEx(NPKey, "LogonOptions", NULL, ! &LSPtype, (LPBYTE)&LogonOption, &LSPsize); ! RegCloseKey (NPKey); ! if ((code!=0) || (LSPtype!=REG_DWORD)) ! LogonOption=LOGON_OPTION_INTEGRATED; /*default to integrated logon only*/ afsWillAutoStart = AFSWillAutoStart(); ! ! DebugEvent("AFS AfsLogon - NPLogonNotify","LogonOption[%x], Service AutoStart[%d]", ! LogonOption,afsWillAutoStart); - /* Get local machine specified login behavior (or defaults) */ - GetLoginBehavior(&retryInterval, &failSilently); - /* Check for zero length password if integrated logon*/ ! if ( ISLOGONINTEGRATED(LogonOption) ) { if ( password[0] == 0 ) { code = GT_PW_NULL; reason = "zero length password is illegal"; code=0; } ! /* Get cell name if doing integrated logon */ code = cm_GetRootCellName(cell); if (code < 0) { code = KTC_NOCELL; reason = "unknown cell"; code=0; ! } ! /*only do if high security option is on*/ ! if (ISHIGHSECURITY(LogonOption)) ! *lpLogonScript = GetLogonScript(GenRandomName(RandomName)); } /* loop until AFS is started. */ while (TRUE) { ! code=0; ! ! /* is service started yet?*/ ! DebugEvent("AFS AfsLogon - ka_UserAuthenticateGeneral2","Code[%x] uname[%s] Cell[%s]", ! code,uname,cell); ! /* if Integrated Logon only */ ! if (ISLOGONINTEGRATED(LogonOption) && !ISHIGHSECURITY(LogonOption)) { ! if ( KFW_is_available() ) ! code = KFW_AFS_get_cred(uname, cell, password, 0, uname, &reason); ! else code = ka_UserAuthenticateGeneral2(KA_USERAUTH_VERSION+KA_USERAUTH_AUTHENT_LOGON, ! uname, "", cell, password, uname, 0, &pw_exp, 0, &reason); ! DebugEvent("AFS AfsLogon - (INTEGRATED only)ka_UserAuthenticateGeneral2","Code[%x]", ! code); if ( code && code != KTC_NOCM && code != KTC_NOCMRPC && uppercased_name ) { for ( ctemp = uname; *ctemp ; ctemp++) { *ctemp = tolower(*ctemp); --- 584,672 ---- (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PARMS_KEY, 0, KEY_QUERY_VALUE, &NPKey); LSPsize=sizeof(TraceOption); ! RegQueryValueEx(NPKey, REG_CLIENT_TRACE_OPTION_PARM, NULL, &LSPtype, (LPBYTE)&TraceOption, &LSPsize); ! ! RegCloseKey (NPKey); ! /* ! * Get Logon options */ ! GetDomainLogonOptions( lpLogonId, uname, logonDomain, &opt ); ! retryInterval = opt.retryInterval; ! sleepInterval = opt.sleepInterval; ! *lpLogonScript = opt.logonScript; ! DebugEvent("Got logon script: %S",opt.logonScript); afsWillAutoStart = AFSWillAutoStart(); ! ! DebugEvent("LogonOption[%x], Service AutoStart[%d]", ! opt.LogonOption,afsWillAutoStart); /* Check for zero length password if integrated logon*/ ! if ( ISLOGONINTEGRATED(opt.LogonOption) ) { if ( password[0] == 0 ) { + DebugEvent("Password is the empty string"); code = GT_PW_NULL; reason = "zero length password is illegal"; code=0; } ! /* Get cell name if doing integrated logon. ! We might overwrite this if we are logging into an AD realm and we find out that ! the user's home dir is in some other cell. */ ! DebugEvent("About to call cm_GetRootCellName(%s)",cell); code = cm_GetRootCellName(cell); if (code < 0) { + DebugEvent("Unable to obtain Root Cell"); code = KTC_NOCELL; reason = "unknown cell"; code=0; ! } else { ! DebugEvent("Cell is %s",cell); ! } ! /* We get the user's home directory path, if applicable, though we can't lookup the ! cell right away because the client service may not have started yet. This call ! also sets the AD_REALM flag in opt.flags if applicable. */ ! if(ISREMOTE(opt.flags)) { ! DebugEvent("Is Remote"); ! GetAdHomePath(homePath,MAX_PATH,lpLogonId,&opt); ! } } /* loop until AFS is started. */ while (TRUE) { ! DebugEvent("while(TRUE) LogonOption[%x], Service AutoStart[%d]", ! opt.LogonOption,afsWillAutoStart); ! if(ISADREALM(opt.flags)) { ! code = GetFileCellName(homePath,cell,256); ! if(!code) { ! DebugEvent("profile path [%s] is in cell [%s]",homePath,cell); ! } ! /* Don't bail out if GetFileCellName failed. ! * The home dir may not be in AFS after all. ! */ ! } else ! code=0; ! ! /* if Integrated Logon */ ! if (ISLOGONINTEGRATED(opt.LogonOption)) { ! if ( KFW_is_available() ) { ! code = KFW_AFS_get_cred(uname, cell, password, 0, opt.smbName, &reason); ! DebugEvent("KFW_AFS_get_cred uname=[%s] smbname=[%s] cell=[%s] code=[%d]",uname,opt.smbName,cell,code); ! } ! else { code = ka_UserAuthenticateGeneral2(KA_USERAUTH_VERSION+KA_USERAUTH_AUTHENT_LOGON, ! uname, "", cell, password, opt.smbName, 0, &pw_exp, 0, &reason); ! DebugEvent("AFS AfsLogon - (INTEGRATED only)ka_UserAuthenticateGeneral2","Code[%x]", ! code); ! } if ( code && code != KTC_NOCM && code != KTC_NOCMRPC && uppercased_name ) { for ( ctemp = uname; *ctemp ; ctemp++) { *ctemp = tolower(*ctemp); *************** *** 442,468 **** uppercased_name = FALSE; continue; } ! } ! /* if Integrated Logon and High Security pass random generated name*/ ! else if (ISLOGONINTEGRATED(LogonOption) && ISHIGHSECURITY(LogonOption)) ! { ! if ( KFW_is_available() ) ! code = KFW_AFS_get_cred(uname, cell, password, 0, RandomName, &reason); ! else ! code = ka_UserAuthenticateGeneral2(KA_USERAUTH_VERSION+KA_USERAUTH_AUTHENT_LOGON, ! uname, "", cell, password,RandomName, 0, &pw_exp, 0, ! &reason); ! DebugEvent("AFS AfsLogon - (Both)ka_UserAuthenticateGeneral2","Code[%x] RandomName[%s]", ! code, RandomName); ! ! if ( code && code != KTC_NOCM && code != KTC_NOCMRPC && uppercased_name ) { ! for ( ctemp = uname; *ctemp ; ctemp++) { ! *ctemp = tolower(*ctemp); ! } ! uppercased_name = FALSE; ! continue; ! } ! } else { /*JUST check to see if its running*/ if (IsServiceRunning()) break; --- 674,681 ---- uppercased_name = FALSE; continue; } ! } ! else { /*JUST check to see if its running*/ if (IsServiceRunning()) break; *************** *** 471,476 **** --- 684,693 ---- break; } + /* is service started yet?*/ + DebugEvent("AFS AfsLogon - ka_UserAuthenticateGeneral2","Code[%x] uname[%s] Cell[%s]", + code,uname,cell); + /* If we've failed because the client isn't running yet and the * client is set to autostart (and therefore it makes sense for * us to wait for it to start) then sleep a while and try again. *************** *** 484,490 **** * user know we failed and give them a chance to try again. */ if (retryInterval <= 0) { reason = "AFS not running"; ! if (!interactive || failSilently) break; flag = MessageBox(hwndOwner, "AFS is still starting. Retry?", --- 701,707 ---- * user know we failed and give them a chance to try again. */ if (retryInterval <= 0) { reason = "AFS not running"; ! if (!interactive || opt.failSilently) break; flag = MessageBox(hwndOwner, "AFS is still starting. Retry?", *************** *** 505,534 **** retryInterval -= sleepInterval; } /* remove any kerberos 5 tickets currently held by the SYSTEM account */ if ( KFW_is_available() ) KFW_AFS_destroy_tickets_for_cell(cell); if (code) { char msg[128]; ! sprintf(msg, "Integrated login failed: %s", reason); ! if (interactive && !failSilently) MessageBox(hwndOwner, msg, "AFS Logon", MB_OK); ! else { ! HANDLE h; ! char *ptbuf[1]; ! ! h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); ! ptbuf[0] = msg; ! ReportEvent(h, EVENTLOG_WARNING_TYPE, 0, 1008, NULL, ! 1, 0, ptbuf, NULL); ! DeregisterEventSource(h); ! } ! code = MapAuthError(code); SetLastError(code); ! if (ISLOGONINTEGRATED(LogonOption) && (code!=0)) { if (*lpLogonScript) LocalFree(*lpLogonScript); --- 722,752 ---- retryInterval -= sleepInterval; } + DebugEvent("while loop exited"); /* remove any kerberos 5 tickets currently held by the SYSTEM account */ if ( KFW_is_available() ) KFW_AFS_destroy_tickets_for_cell(cell); if (code) { char msg[128]; ! HANDLE h; ! char *ptbuf[1]; ! StringCbPrintf(msg, sizeof(msg), "Integrated login failed: %s", reason); ! ! if (ISLOGONINTEGRATED(opt.LogonOption) && interactive && !opt.failSilently) MessageBox(hwndOwner, msg, "AFS Logon", MB_OK); ! ! h = RegisterEventSource(NULL, AFS_LOGON_EVENT_NAME); ! ptbuf[0] = msg; ! ReportEvent(h, EVENTLOG_WARNING_TYPE, 0, 1008, NULL, ! 1, 0, ptbuf, NULL); ! DeregisterEventSource(h); ! ! code = MapAuthError(code); SetLastError(code); ! if (ISLOGONINTEGRATED(opt.LogonOption) && (code!=0)) { if (*lpLogonScript) LocalFree(*lpLogonScript); *************** *** 539,544 **** --- 757,764 ---- } } + if(opt.smbName) free(opt.smbName); + DebugEvent("AFS AfsLogon - Exit","Return Code[%x]",code); return code; } *************** *** 556,558 **** --- 776,878 ---- return 0; } + #include + #include + #include + #include + + BOOL IsPathInAfs(const CHAR *strPath) + { + char space[2048]; + struct ViceIoctl blob; + int code; + + blob.in_size = 0; + blob.out_size = 2048; + blob.out = space; + + code = pioctl((LPTSTR)((LPCTSTR)strPath), VIOC_FILE_CELL_NAME, &blob, 1); + if (code) + return FALSE; + return TRUE; + } + + #ifdef COMMENT + typedef struct _WLX_NOTIFICATION_INFO { + ULONG Size; + ULONG Flags; + PWSTR UserName; + PWSTR Domain; + PWSTR WindowStation; + HANDLE hToken; + HDESK hDesktop; + PFNMSGECALLBACK pStatusCallback; + } WLX_NOTIFICATION_INFO, *PWLX_NOTIFICATION_INFO; + #endif + + VOID AFS_Startup_Event( PWLX_NOTIFICATION_INFO pInfo ) + { + DWORD LSPtype, LSPsize; + HKEY NPKey; + + (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PARMS_KEY, + 0, KEY_QUERY_VALUE, &NPKey); + LSPsize=sizeof(TraceOption); + RegQueryValueEx(NPKey, REG_CLIENT_TRACE_OPTION_PARM, NULL, + &LSPtype, (LPBYTE)&TraceOption, &LSPsize); + + RegCloseKey (NPKey); + DebugEvent0("AFS_Startup_Event"); + } + + VOID AFS_Logoff_Event( PWLX_NOTIFICATION_INFO pInfo ) + { + DWORD code; + TCHAR profileDir[256] = TEXT(""); + DWORD len = 256; + PTOKEN_USER tokenUser = NULL; + DWORD retLen; + HANDLE hToken; + + DebugEvent0("AFS_Logoff_Event - Starting"); + + if (!GetTokenInformation(pInfo->hToken, TokenUser, NULL, 0, &retLen)) + { + if ( GetLastError() == ERROR_INSUFFICIENT_BUFFER ) { + tokenUser = (PTOKEN_USER) LocalAlloc(LPTR, retLen); + + if (!GetTokenInformation(pInfo->hToken, TokenUser, tokenUser, retLen, &retLen)) + { + DebugEvent("GetTokenInformation failed: GLE = %lX", GetLastError()); + } + } + } + + /* We can't use pInfo->Domain for the domain since in the cross realm case + * this is source domain and not the destination domain. + */ + if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, pInfo->Domain)) { + WCHAR Domain[64]=L""; + GetLocalShortDomain(Domain); + if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, Domain)) + GetUserProfileDirectory(pInfo->hToken, profileDir, &len); + } + + if (strlen(profileDir)) { + DebugEvent("Profile Directory: %s", profileDir); + if (!IsPathInAfs(profileDir)) { + if (code = ktc_ForgetAllTokens()) + DebugEvent("AFS_Logoff_Event - ForgetAllTokens failed [%lX]",code); + else + DebugEvent0("AFS_Logoff_Event - ForgetAllTokens succeeded"); + } else { + DebugEvent0("AFS_Logoff_Event - Tokens left in place; profile in AFS"); + } + } else { + DebugEvent0("AFS_Logoff_Event - Unable to load profile"); + } + + if ( tokenUser ) + LocalFree(tokenUser); + } + Index: openafs/src/WINNT/afsd/afslogon.def diff -c openafs/src/WINNT/afsd/afslogon.def:1.1 openafs/src/WINNT/afsd/afslogon.def:1.3 *** openafs/src/WINNT/afsd/afslogon.def:1.1 Fri Nov 3 21:14:12 2000 --- openafs/src/WINNT/afsd/afslogon.def Thu Jul 22 05:23:52 2004 *************** *** 8,11 **** --- 8,14 ---- NPGetCaps NPLogonNotify NPPasswordChangeNotify + AFS_Startup_Event + AFS_Logoff_Event + Index: openafs/src/WINNT/afsd/afslogon.h diff -c /dev/null openafs/src/WINNT/afsd/afslogon.h:1.4 *** /dev/null Tue Jul 27 19:19:44 2004 --- openafs/src/WINNT/afsd/afslogon.h Thu Jul 22 18:15:47 2004 *************** *** 0 **** --- 1,127 ---- + /* + + Copyright 2004 by the Massachusetts Institute of Technology + + All rights reserved. + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose and without fee is hereby granted, + provided that the above copyright notice appear in all copies and that + both that copyright notice and this permission notice appear in + supporting documentation, and that the name of the Massachusetts + Institute of Technology (M.I.T.) not be used in advertising or publicity + pertaining to distribution of the software without specific, written + prior permission. + + M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + SOFTWARE. + + */ + + /* We only support VC 1200 and above anyway */ + #pragma once + + #include + #include + #include + #include + + + #define REG_CLIENT_PARMS_KEY "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters" + #define REG_CLIENT_PROVIDER_KEY "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\NetworkProvider" + #define REG_CLIENT_DOMAINS_SUBKEY "Domain" + #define REG_CLIENT_RETRY_INTERVAL_PARM "LoginRetryInterval" + #define REG_CLIENT_SLEEP_INTERVAL_PARM "LoginSleepInterval" + #define REG_CLIENT_FAIL_SILENTLY_PARM "FailLoginsSilently" + #define REG_CLIENT_TRACE_OPTION_PARM "TraceOption" + #define REG_CLIENT_LOGON_OPTION_PARM "LogonOptions" + #define REG_CLIENT_LOGON_SCRIPT_PARMW L"LogonScript" + #define DEFAULT_RETRY_INTERVAL 30 /* seconds*/ + #define DEFAULT_FAIL_SILENTLY FALSE + #define DEFAULT_SLEEP_INTERVAL 5 /* seconds*/ + #define DEFAULT_LOGON_OPTION 1 + + #define TRACE_OPTION_EVENT 1 + + #define ISLOGONTRACE(v) ( ((v) & TRACE_OPTION_EVENT)==TRACE_OPTION_EVENT) + + #define ISLOGONINTEGRATED(v) ( ((v) & LOGON_OPTION_INTEGRATED)==LOGON_OPTION_INTEGRATED) + #define ISHIGHSECURITY(v) ( ((v) & LOGON_OPTION_HIGHSECURITY)==LOGON_OPTION_HIGHSECURITY) + + #define ISREMOTE(v) ( ((v) & LOGON_FLAG_REMOTE)==LOGON_FLAG_REMOTE) + #define ISADREALM(v) ( ((v) & LOGON_FLAG_AD_REALM)==LOGON_FLAG_AD_REALM) + extern DWORD TraceOption; + + #define LOGON_FLAG_LOCAL 0 + #define LOGON_FLAG_REMOTE 1 + #define LOGON_FLAG_AD_REALM 2 + + typedef struct LogonOptions_type { + DWORD LogonOption; + BOOLEAN failSilently; + int retryInterval; + int sleepInterval; + char * smbName; + LPWSTR logonScript; + DWORD flags; /* LOGON_FLAG_* */ + } LogonOptions_t; + + /* */ + #define MAX_USERNAME_LENGTH 256 + #define MAX_PASSWORD_LENGTH 256 + #define MAX_DOMAIN_LENGTH 256 + + BOOLEAN APIENTRY DllEntryPoint(HANDLE dll, DWORD reason, PVOID reserved); + + DWORD APIENTRY NPGetCaps(DWORD index); + + DWORD APIENTRY NPLogonNotify( + PLUID lpLogonId, + LPCWSTR lpAuthentInfoType, + LPVOID lpAuthentInfo, + LPCWSTR lpPreviousAuthentInfoType, + LPVOID lpPreviousAuthentInfo, + LPWSTR lpStationName, + LPVOID StationHandle, + LPWSTR *lpLogonScript); + + DWORD APIENTRY NPPasswordChangeNotify( + LPCWSTR lpAuthentInfoType, + LPVOID lpAuthentInfo, + LPCWSTR lpPreviousAuthentInfoType, + LPVOID lpPreviousAuthentInfo, + LPWSTR lpStationName, + LPVOID StationHandle, + DWORD dwChangeInfo); + + #ifdef __cplusplus + extern "C" { + #endif + + void DebugEvent0(char *a); + void DebugEvent(char *b,...); + + CHAR *GenRandomName(CHAR *pbuf); + + BOOLEAN AFSWillAutoStart(void); + + DWORD MapAuthError(DWORD code); + + BOOL IsServiceRunning (void); + + static BOOL WINAPI UnicodeStringToANSI(UNICODE_STRING uInputString, LPSTR lpszOutputString, int nOutStringLen); + + void GetDomainLogonOptions( PLUID lpLogonId, char * username, char * domain, LogonOptions_t *opt ); + DWORD GetFileCellName(char * path, char * cell, size_t cellLen); + DWORD GetAdHomePath(char * homePath, size_t homePathLen, PLUID lpLogonId, LogonOptions_t * opt); + DWORD QueryAdHomePathFromSid(char * homePath, size_t homePathLen, PSID psid, PWSTR domain); + BOOL GetLocalShortDomain(PWSTR Domain); + + #ifdef __cplusplus + } + #endif Index: openafs/src/WINNT/afsd/afsshare.c diff -c openafs/src/WINNT/afsd/afsshare.c:1.2 openafs/src/WINNT/afsd/afsshare.c:1.5 *** openafs/src/WINNT/afsd/afsshare.c:1.2 Sat Nov 4 05:01:36 2000 --- openafs/src/WINNT/afsd/afsshare.c Tue Jul 20 10:36:41 2004 *************** *** 13,30 **** #include #include main(int argc, char **argv) { BOOL res; if (argc < 2 || argc > 3) { ! fprintf(stderr, "Incorrect arguments\n"); ! exit(1); } - res = WritePrivateProfileString("AFS Submounts", - argv[1], - (argc == 3) ? argv[2] : NULL, - "afsdsbmt.ini"); - if (res == FALSE) - fprintf(stderr, "Failed, error code %d\n", GetLastError()); return 0; } --- 13,81 ---- #include #include + int main(int argc, char **argv) { BOOL res; + HKEY hkSubmounts; + HKEY hkParameters; + char mountRoot[64]="/afs"; + char * mountstring; + if (argc < 2 || argc > 3) { ! fprintf(stderr, "afsshare.exe []\n"); ! exit(1); } + if (RegCreateKeyEx( HKEY_LOCAL_MACHINE, + "SOFTWARE\\OpenAFS\\Client\\Submounts", + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_READ|KEY_WRITE, + NULL, + &hkSubmounts, + NULL) == ERROR_SUCCESS) + { + if ( argc == 2 ) { + if (RegDeleteValue(hkSubmounts, argv[1])) { + fprintf(stderr,"Submount Deletion failure for [%s]: %lX", + argv[1], GetLastError()); + RegCloseKey(hkSubmounts); + return 1; + } + } else { + if (RegCreateKeyEx( HKEY_LOCAL_MACHINE, + "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters", + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_READ, + NULL, + &hkParameters, + NULL) == ERROR_SUCCESS) + { + DWORD dwSize = sizeof(mountRoot); + RegQueryValueEx (hkParameters, "MountRoot", NULL, NULL, (PBYTE)mountRoot, &dwSize); + RegCloseKey(hkParameters); + } + + + if ( !strncmp(mountRoot, argv[2], strlen(mountRoot)) ) + mountstring = argv[2] + strlen(mountRoot); + 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); + return 2; + } + } + RegCloseKey(hkSubmounts); + } else { + fprintf(stderr,"Submount access denied: %lX", GetLastError()); + return 3; + } return 0; } Index: openafs/src/WINNT/afsd/cm.h diff -c openafs/src/WINNT/afsd/cm.h:1.7 openafs/src/WINNT/afsd/cm.h:1.9 *** openafs/src/WINNT/afsd/cm.h:1.7 Thu May 6 11:17:29 2004 --- openafs/src/WINNT/afsd/cm.h Mon Jul 26 19:22:20 2004 *************** *** 219,225 **** #define CM_ERROR_EXISTS (CM_ERROR_BASE+11) #define CM_ERROR_CROSSDEVLINK (CM_ERROR_BASE+12) #define CM_ERROR_BADOP (CM_ERROR_BASE+13) ! /* CM_ERROR_BADPASSWORD used to be here */ #define CM_ERROR_NOTDIR (CM_ERROR_BASE+15) #define CM_ERROR_ISDIR (CM_ERROR_BASE+16) #define CM_ERROR_READONLY (CM_ERROR_BASE+17) --- 219,225 ---- #define CM_ERROR_EXISTS (CM_ERROR_BASE+11) #define CM_ERROR_CROSSDEVLINK (CM_ERROR_BASE+12) #define CM_ERROR_BADOP (CM_ERROR_BASE+13) ! #define CM_ERROR_BADPASSWORD (CM_ERROR_BASE+14) #define CM_ERROR_NOTDIR (CM_ERROR_BASE+15) #define CM_ERROR_ISDIR (CM_ERROR_BASE+16) #define CM_ERROR_READONLY (CM_ERROR_BASE+17) *************** *** 246,249 **** --- 246,252 ---- #define CM_ERROR_RENAME_IDENTICAL (CM_ERROR_BASE+39) #define CM_ERROR_ALLOFFLINE (CM_ERROR_BASE+40) #define CM_ERROR_AMBIGUOUS_FILENAME (CM_ERROR_BASE+41) + #define CM_ERROR_BADLOGONTYPE (CM_ERROR_BASE+42) + #define CM_ERROR_GSSCONTINUE (CM_ERROR_BASE+43) + #define CM_ERROR_TIDIPC (CM_ERROR_BASE+44) #endif /* __CM_H_ENV__ */ Index: openafs/src/WINNT/afsd/cm_callback.c diff -c openafs/src/WINNT/afsd/cm_callback.c:1.14 openafs/src/WINNT/afsd/cm_callback.c:1.15 *** openafs/src/WINNT/afsd/cm_callback.c:1.14 Mon Jun 7 02:22:57 2004 --- openafs/src/WINNT/afsd/cm_callback.c Mon Jul 26 15:08:42 2004 *************** *** 600,606 **** // good shape and we simply return true, provided no change is detected. int fdc, fgc; ! if (cm_freelanceEnabled && scp->fid.cell==0x1 && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) { // if it's something on /afs if (!(scp->fid.vnode==0x1 && scp->fid.unique==0x1)) // if it's not root.afs return 1; else { --- 600,608 ---- // good shape and we simply return true, provided no change is detected. int fdc, fgc; ! if (cm_freelanceEnabled && ! scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && ! scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) { // if it's something on /afs if (!(scp->fid.vnode==0x1 && scp->fid.unique==0x1)) // if it's not root.afs return 1; else { *************** *** 757,763 **** // specially. We need to fetch the status by calling // cm_MergeStatus and mark that cm_fakeDirCallback is 2 if (cm_freelanceEnabled && ! scp->fid.cell==0x1 && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID && scp->fid.unique==0x1 && scp->fid.vnode==0x1) { --- 759,765 ---- // specially. We need to fetch the status by calling // cm_MergeStatus and mark that cm_fakeDirCallback is 2 if (cm_freelanceEnabled && ! scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID && scp->fid.unique==0x1 && scp->fid.vnode==0x1) { Index: openafs/src/WINNT/afsd/cm_cell.c diff -c openafs/src/WINNT/afsd/cm_cell.c:1.10 openafs/src/WINNT/afsd/cm_cell.c:1.12 *** openafs/src/WINNT/afsd/cm_cell.c:1.10 Sat Jun 5 02:02:39 2004 --- openafs/src/WINNT/afsd/cm_cell.c Mon Jul 19 18:40:12 2004 *************** *** 68,73 **** --- 68,76 ---- int ttl; char fullname[200]=""; + if (!strcmp(namep,SMB_IOCTL_FILENAME_NOSLASH)) + return NULL; + lock_ObtainWrite(&cm_cellLock); for (cp = cm_allCellsp; cp; cp=cp->nextp) { if (strcmp(namep, cp->namep) == 0) { *************** *** 85,92 **** ) { int dns_expired = 0; if (!cp) { ! cp = malloc(sizeof(*cp)); ! memset(cp, 0, sizeof(*cp)); } else { dns_expired = 1; --- 88,95 ---- ) { int dns_expired = 0; if (!cp) { ! cp = malloc(sizeof(cm_cell_t)); ! memset(cp, 0, sizeof(cm_cell_t)); } else { dns_expired = 1; *************** *** 109,114 **** --- 112,118 ---- if (dns_expired) { cp->flags |= CM_CELLFLAG_VLSERVER_INVALID; cp = NULL; /* set cp to NULL to indicate error */ + goto done; } } else { /* got cell from DNS */ *************** *** 126,132 **** } /* randomise among those vlservers having the same rank*/ ! cm_RandomizeServer(&cp->vlServersp); #ifdef AFS_AFSDB_ENV if (dns_expired) { --- 130,136 ---- } /* randomise among those vlservers having the same rank*/ ! cm_RandomizeServer(&cp->vlServersp); #ifdef AFS_AFSDB_ENV if (dns_expired) { Index: openafs/src/WINNT/afsd/cm_config.c diff -c openafs/src/WINNT/afsd/cm_config.c:1.16 openafs/src/WINNT/afsd/cm_config.c:1.20 *** openafs/src/WINNT/afsd/cm_config.c:1.16 Sat May 29 19:47:59 2004 --- openafs/src/WINNT/afsd/cm_config.c Thu Jul 22 05:23:52 2004 *************** *** 23,28 **** --- 23,29 ---- #include #include "cm_config.h" + #include #ifdef AFS_AFSDB_ENV #include "cm_dns.h" #include *************** *** 30,38 **** --- 31,42 ---- char AFSConfigKeyName[] = "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"; + char AFSLocalMachineKeyName[] = "SOFTWARE\\OpenAFS\\Client"; /* TODO: these should be pulled in from dirpath.h */ + #if !defined(DJGPP) && !defined(AFS_WIN95_ENV) #define AFS_THISCELL "ThisCell" + #endif #define AFS_CELLSERVDB_UNIX "CellServDB" #define AFS_CELLSERVDB_NT "afsdcell.ini" #ifndef AFSDIR_CLIENT_ETC_DIRPATH *************** *** 45,63 **** extern int errno; #endif /* DJGPP */ #else ! #define AFS_CELLSERVDB AFS_CELLSERVDB_NT #endif /* DJGPP || WIN95 */ ! #ifdef DEBUG ! DWORD TraceOption=1; ! #define TRACE_OPTION_EVENT 1 ! #define ISLOGONTRACE(v) ( ((v) & TRACE_OPTION_EVENT)==TRACE_OPTION_EVENT) void DebugEvent0_local(char *a) { HANDLE h; char *ptbuf[1]; ! if (!ISLOGONTRACE(TraceOption)) return; h = RegisterEventSource(NULL, a); ptbuf[0] = a; --- 49,68 ---- extern int errno; #endif /* DJGPP */ #else ! #define AFS_CELLSERVDB AFS_CELLSERVDB_UNIX #endif /* DJGPP || WIN95 */ ! static DWORD TraceOption = 0; ! ! /* This really needs to be initialized at DLL Init */ ! #define TRACE_OPTION_EVENT 4 ! #define ISCONFIGTRACE(v) ( ((v) & TRACE_OPTION_EVENT)==TRACE_OPTION_EVENT) void DebugEvent0_local(char *a) { HANDLE h; char *ptbuf[1]; ! if (!ISCONFIGTRACE(TraceOption)) return; h = RegisterEventSource(NULL, a); ptbuf[0] = a; *************** *** 71,77 **** { HANDLE h; char *ptbuf[1],buf[MAXBUF_+1]; va_list marker; ! if (!ISLOGONTRACE(TraceOption)) return; h = RegisterEventSource(NULL, a); va_start(marker,b); --- 76,82 ---- { HANDLE h; char *ptbuf[1],buf[MAXBUF_+1]; va_list marker; ! if (!ISCONFIGTRACE(TraceOption)) return; h = RegisterEventSource(NULL, a); va_start(marker,b); *************** *** 81,87 **** DeregisterEventSource(h); va_end(marker); } ! #endif /* DEBUG */ static long cm_ParsePair(char *lineBufferp, char *leftp, char *rightp) { --- 86,130 ---- DeregisterEventSource(h); va_end(marker); } ! ! #define REG_CLIENT_PARMS_KEY TEXT("SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters") ! #define REG_CLIENT_TRACE_OPTION_PARM TEXT("TraceOption") ! ! #ifdef COMMENT ! BOOL WINAPI DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved) ! { ! switch (fdwReason) ! { ! case DLL_PROCESS_ATTACH: { ! DWORD LSPtype, LSPsize; ! HKEY NPKey; ! ! (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PARMS_KEY, ! 0, KEY_QUERY_VALUE, &NPKey); ! LSPsize=sizeof(TraceOption); ! RegQueryValueEx(NPKey, REG_CLIENT_TRACE_OPTION_PARM, NULL, ! &LSPtype, (LPBYTE)&TraceOption, &LSPsize); ! ! RegCloseKey (NPKey); ! break; ! } ! ! case DLL_THREAD_ATTACH: ! break; ! ! case DLL_THREAD_DETACH: ! break; ! ! case DLL_PROCESS_DETACH: ! break; ! ! default: ! return FALSE; ! } ! ! return TRUE; // successful DLL_PROCESS_ATTACH ! } ! #endif /* COMMENT */ static long cm_ParsePair(char *lineBufferp, char *leftp, char *rightp) { *************** *** 149,186 **** cm_configProc_t *procp, void *rockp) { char wdir[257]; ! int tlen; ! FILE *tfilep, *bestp, *tempp; char *tp; char lineBuffer[257]; struct hostent *thp; char *valuep; struct sockaddr_in vlSockAddr; int inRightCell; ! int foundCell; long code; int tracking = 1, partial = 0; #if defined(DJGPP) || defined(AFS_WIN95_ENV) char *afsconf_path; #endif ! foundCell = 0; ! ! #if !defined(DJGPP) ! code = GetWindowsDirectory(wdir, sizeof(wdir)); ! if (code == 0 || code > sizeof(wdir)) ! return -1; ! ! /* add trailing backslash, if required */ ! tlen = strlen(wdir); ! if (wdir[tlen-1] != '\\') strcat(wdir, "\\"); ! #else ! strcpy(wdir, cm_confDir); ! strcat(wdir,"/"); ! #endif /* !DJGPP */ ! ! strcat(wdir, AFS_CELLSERVDB); ! tfilep = fopen(wdir, "r"); #if defined(DJGPP) || defined(AFS_WIN95_ENV) --- 192,212 ---- cm_configProc_t *procp, void *rockp) { char wdir[257]; ! FILE *tfilep = NULL, *bestp, *tempp; char *tp; char lineBuffer[257]; struct hostent *thp; char *valuep; struct sockaddr_in vlSockAddr; int inRightCell; ! int foundCell = 0; long code; int tracking = 1, partial = 0; #if defined(DJGPP) || defined(AFS_WIN95_ENV) char *afsconf_path; #endif ! cm_GetCellServDB(wdir); tfilep = fopen(wdir, "r"); #if defined(DJGPP) || defined(AFS_WIN95_ENV) *************** *** 195,201 **** else strcpy(wdir, afsconf_path); strcat(wdir, "/"); ! strcat(wdir, AFS_CELLSERVDB_UNIX); /*fprintf(stderr, "opening cellservdb file %s\n", wdir);*/ tfilep = fopen(wdir, "r"); if (!tfilep) return -2; --- 221,227 ---- else strcpy(wdir, afsconf_path); strcat(wdir, "/"); ! strcat(wdir, AFS_CELLSERVDB); /*fprintf(stderr, "opening cellservdb file %s\n", wdir);*/ tfilep = fopen(wdir, "r"); if (!tfilep) return -2; *************** *** 397,402 **** --- 423,466 ---- } #if !defined(DJGPP) && !defined(AFS_WIN95_ENV) + /* look up the CellServDBDir's name in the Registry + * or use the Client Dirpath value to produce a CellServDB + * filename + */ + long cm_GetCellServDB(char *cellNamep) + { + #if !defined(DJGPP) + DWORD code, dummyLen; + HKEY parmKey; + int tlen; + + code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSLocalMachineKeyName, + 0, KEY_QUERY_VALUE, &parmKey); + if (code != ERROR_SUCCESS) + goto dirpath; + + dummyLen = 256; + code = RegQueryValueEx(parmKey, "CellServDBDir", NULL, NULL, + cellNamep, &dummyLen); + RegCloseKey (parmKey); + + dirpath: + if (code != ERROR_SUCCESS || cellNamep[0] == 0) + strcpy(cellNamep, AFSDIR_CLIENT_ETC_DIRPATH); + + /* add trailing backslash, if required */ + tlen = strlen(cellNamep); + if (cellNamep[tlen-1] != '\\') + strcat(cellNamep, "\\"); + #else + strcpy(cellNamep, cm_confDir); + strcat(cellNamep,"/"); + #endif /* !DJGPP */ + + strcat(cellNamep, AFS_CELLSERVDB); + return 0; + } + /* look up the root cell's name in the Registry */ long cm_GetRootCellName(char *cellNamep) { *************** *** 458,471 **** cm_configFile_t *cm_CommonOpen(char *namep, char *rwp) { char wdir[256]; - long code; long tlen; FILE *tfilep; #if !defined(DJGPP) && !defined(AFS_WIN95_ENV) ! code = GetWindowsDirectory(wdir, sizeof(wdir)); ! if (code == 0 || code > sizeof(wdir)) ! return 0; /* add trailing backslash, if required */ tlen = strlen(wdir); --- 522,532 ---- cm_configFile_t *cm_CommonOpen(char *namep, char *rwp) { char wdir[256]; long tlen; FILE *tfilep; #if !defined(DJGPP) && !defined(AFS_WIN95_ENV) ! strcpy(wdir, AFSDIR_CLIENT_ETC_DIRPATH); /* add trailing backslash, if required */ tlen = strlen(wdir); *************** *** 635,709 **** closeCode = fclose((FILE *)filep); #if !defined(DJGPP) && !defined(AFS_WIN95_ENV) ! code = GetWindowsDirectory(wdir, sizeof(wdir)); ! if (code == 0 || code > sizeof(wdir)) ! return closeCode; /* add trailing backslash, if required */ ! tlen = strlen(wdir); ! if (wdir[tlen-1] != '\\') strcat(wdir, "\\"); #else #ifdef DJGPP ! strcpy(wdir,cm_confDir); #else ! afsconf_path = getenv("AFSCONF"); ! if (!afsconf_path) ! strcpy(wdir, AFSDIR_CLIENT_ETC_DIRPATH); ! else ! strcpy(wdir, afsconf_path); #endif /* !DJGPP */ ! strcat(wdir,"/"); #endif /* DJGPP || WIN95 */ ! strcpy(sdir, wdir); if (closeCode != 0) { /* something went wrong, preserve original database */ ! strcat(wdir, "afsdcel2.ini"); ! unlink(wdir); ! return closeCode; ! } ! strcat(wdir, AFS_CELLSERVDB); ! strcat(sdir, "afsdcel2.ini"); /* new file */ ! ! unlink(wdir); /* delete old file */ ! ! code = rename(sdir, wdir); /* do the rename */ ! ! if (code) ! code = errno; ! ! return code; ! } void cm_GetConfigDir(char *dir) { char wdir[256]; - int code; int tlen; #ifdef AFS_WIN95_ENV char *afsconf_path; #endif #if !defined(DJGPP) && !defined(AFS_WIN95_ENV) ! code = GetWindowsDirectory(wdir, sizeof(wdir)); ! if (code == 0 || code > sizeof(wdir)) wdir[0] = 0; /* add trailing backslash, if required */ ! tlen = strlen(wdir); ! if (wdir[tlen-1] != '\\') strcat(wdir, "\\"); #else #ifdef DJGPP ! strcpy(wdir,cm_confDir); #else ! afsconf_path = getenv("AFSCONF"); ! if (!afsconf_path) ! strcpy(wdir, AFSDIR_CLIENT_ETC_DIRPATH); ! else ! strcpy(wdir, afsconf_path); #endif /* !DJGPP */ ! strcat(wdir,"\\"); #endif /* DJGPP || WIN95 */ ! strcpy(dir, wdir); } --- 696,766 ---- closeCode = fclose((FILE *)filep); #if !defined(DJGPP) && !defined(AFS_WIN95_ENV) ! strcpy(wdir, AFSDIR_CLIENT_ETC_DIRPATH); /* add trailing backslash, if required */ ! tlen = strlen(wdir); ! if (wdir[tlen-1] != '\\') strcat(wdir, "\\"); #else #ifdef DJGPP ! strcpy(wdir,cm_confDir); #else ! afsconf_path = getenv("AFSCONF"); ! if (!afsconf_path) ! strcpy(wdir, AFSDIR_CLIENT_ETC_DIRPATH); ! else ! strcpy(wdir, afsconf_path); #endif /* !DJGPP */ ! strcat(wdir,"/"); #endif /* DJGPP || WIN95 */ ! strcpy(sdir, wdir); if (closeCode != 0) { /* something went wrong, preserve original database */ ! strcat(wdir, "afsdcel2.ini"); ! unlink(wdir); ! return closeCode; ! } ! strcat(wdir, AFS_CELLSERVDB); ! strcat(sdir, "afsdcel2.ini"); /* new file */ ! ! unlink(wdir); /* delete old file */ ! ! code = rename(sdir, wdir); /* do the rename */ ! ! if (code) ! code = errno; ! ! return code; ! } void cm_GetConfigDir(char *dir) { char wdir[256]; int tlen; #ifdef AFS_WIN95_ENV char *afsconf_path; #endif #if !defined(DJGPP) && !defined(AFS_WIN95_ENV) ! strcpy(wdir, AFSDIR_CLIENT_ETC_DIRPATH); /* add trailing backslash, if required */ ! tlen = strlen(wdir); ! if (wdir[tlen-1] != '\\') strcat(wdir, "\\"); #else #ifdef DJGPP ! strcpy(wdir,cm_confDir); #else ! afsconf_path = getenv("AFSCONF"); ! if (!afsconf_path) ! strcpy(wdir, AFSDIR_CLIENT_ETC_DIRPATH); ! else ! strcpy(wdir, afsconf_path); #endif /* !DJGPP */ ! strcat(wdir,"\\"); #endif /* DJGPP || WIN95 */ ! strcpy(dir, wdir); } Index: openafs/src/WINNT/afsd/cm_config.h diff -c openafs/src/WINNT/afsd/cm_config.h:1.4 openafs/src/WINNT/afsd/cm_config.h:1.5 *** openafs/src/WINNT/afsd/cm_config.h:1.4 Fri Oct 5 17:40:47 2001 --- openafs/src/WINNT/afsd/cm_config.h Wed Jul 21 10:06:11 2004 *************** *** 53,58 **** --- 53,60 ---- extern long cm_CloseCellFile(cm_configFile_t *filep); + extern long cm_GetCellServDB(char *cellNamep); + #endif /* __CM_CONFIG_INTERFACES_ONLY__ */ #endif /* __CONFIG_H_ENV_ */ Index: openafs/src/WINNT/afsd/cm_conn.c diff -c openafs/src/WINNT/afsd/cm_conn.c:1.16 openafs/src/WINNT/afsd/cm_conn.c:1.20 *** openafs/src/WINNT/afsd/cm_conn.c:1.16 Sat Jun 5 14:57:58 2004 --- openafs/src/WINNT/afsd/cm_conn.c Sun Jul 25 22:48:47 2004 *************** *** 201,217 **** osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLOFFLINE."); thrd_Sleep(5000); /* cm_ForceUpdateVolume marks all servers as non_busy */ ! cm_ForceUpdateVolume(fidp, userp, reqp); ! retry = 1; } /* if all servers are busy, mark them non-busy and start over */ if (errorCode == CM_ERROR_ALLBUSY) { cm_GetServerList(fidp, userp, reqp, &serversp); for (tsrp = serversp; tsrp; tsrp=tsrp->next) { if (tsrp->status == busy) tsrp->status = not_busy; } thrd_Sleep(5000); retry = 1; } --- 201,236 ---- osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLOFFLINE."); thrd_Sleep(5000); /* cm_ForceUpdateVolume marks all servers as non_busy */ ! /* No it doesn't and it won't do anything if all of the ! * the servers are marked as DOWN. So clear the DOWN ! * flag and reset the busy state as well. ! */ ! cm_GetServerList(fidp, userp, reqp, &serversp); ! if (serversp) { ! lock_ObtainWrite(&cm_serverLock); ! for (tsrp = serversp; tsrp; tsrp=tsrp->next) { ! tsrp->server->flags &= ~CM_SERVERFLAG_DOWN; ! if (tsrp->status == busy) ! tsrp->status = not_busy; ! } ! lock_ReleaseWrite(&cm_serverLock); ! ! retry = 1; ! } ! ! if (fidp != NULL) /* Not a VLDB call */ ! cm_ForceUpdateVolume(fidp, userp, reqp); } /* if all servers are busy, mark them non-busy and start over */ if (errorCode == CM_ERROR_ALLBUSY) { cm_GetServerList(fidp, userp, reqp, &serversp); + lock_ObtainWrite(&cm_serverLock); for (tsrp = serversp; tsrp; tsrp=tsrp->next) { if (tsrp->status == busy) tsrp->status = not_busy; } + lock_ReleaseWrite(&cm_serverLock); thrd_Sleep(5000); retry = 1; } *************** *** 219,224 **** --- 238,244 ---- /* special codes: VBUSY and VRESTARTING */ if (errorCode == VBUSY || errorCode == VRESTARTING) { cm_GetServerList(fidp, userp, reqp, &serversp); + lock_ObtainWrite(&cm_serverLock); for (tsrp = serversp; tsrp; tsrp=tsrp->next) { if (tsrp->server == serverp && tsrp->status == not_busy) { *************** *** 226,231 **** --- 246,252 ---- break; } } + lock_ReleaseWrite(&cm_serverLock); retry = 1; } *************** *** 328,334 **** cm_serverRef_t *tsrp; cm_server_t *tsp; long firstError = 0; ! int someBusy = 0, someOffline = 0, allDown = 1; long timeUsed, timeLeft, hardTimeLeft; #ifdef DJGPP struct timeval now; --- 349,355 ---- cm_serverRef_t *tsrp; cm_server_t *tsp; long firstError = 0; ! int someBusy = 0, someOffline = 0, allBusy = 1, allDown = 1; long timeUsed, timeLeft, hardTimeLeft; #ifdef DJGPP struct timeval now; *************** *** 360,365 **** --- 381,387 ---- else if (tsrp->status == offline) someOffline = 1; else { + allBusy = 0; code = cm_ConnByServer(tsp, usersp, connpp); if (code == 0) { cm_PutServer(tsp); *************** *** 389,404 **** lock_ReleaseWrite(&cm_serverLock); if (firstError == 0) { ! if (someBusy) ! firstError = CM_ERROR_ALLBUSY; ! else if (someOffline) firstError = CM_ERROR_ALLOFFLINE; ! else if (!allDown && serversp) firstError = CM_ERROR_TIMEDOUT; - /* Only return CM_ERROR_NOSUCHVOLUME if there are no - servers for this volume */ - else - firstError = CM_ERROR_NOSUCHVOLUME; } osi_Log1(afsd_logp, "cm_ConnByMServers returning %x", firstError); return firstError; --- 411,424 ---- lock_ReleaseWrite(&cm_serverLock); if (firstError == 0) { ! if (serversp == NULL) ! firstError = CM_ERROR_NOSUCHVOLUME; ! else if (allDown) firstError = CM_ERROR_ALLOFFLINE; ! else if (allBusy) ! firstError = CM_ERROR_ALLBUSY; ! else firstError = CM_ERROR_TIMEDOUT; } osi_Log1(afsd_logp, "cm_ConnByMServers returning %x", firstError); return firstError; Index: openafs/src/WINNT/afsd/cm_dcache.c diff -c openafs/src/WINNT/afsd/cm_dcache.c:1.8 openafs/src/WINNT/afsd/cm_dcache.c:1.9 *** openafs/src/WINNT/afsd/cm_dcache.c:1.8 Mon Jun 7 02:22:58 2004 --- openafs/src/WINNT/afsd/cm_dcache.c Sun Jul 25 16:53:12 2004 *************** *** 153,167 **** /* write out wbytes of data from bufferp */ temp = rx_Write(callp, bufferp, wbytes); if (temp != wbytes) { code = -1; break; ! } nbytes -= wbytes; } /* while more bytes to write */ } /* if RPC started successfully */ ! ! if (code == 0) code = EndRXAFS_StoreData(callp, &outStatus, &volSync); code = rx_EndCall(callp, code); osi_Log0(afsd_logp, "CALL StoreData DONE"); --- 153,175 ---- /* write out wbytes of data from bufferp */ temp = rx_Write(callp, bufferp, wbytes); if (temp != wbytes) { + osi_Log2(afsd_logp, "rx_Write failed %d != %d",temp,wbytes); code = -1; break; ! } else { ! osi_Log1(afsd_logp, "rx_Write succeeded %d",temp); ! } nbytes -= wbytes; } /* while more bytes to write */ } /* if RPC started successfully */ ! else { ! osi_Log1(afsd_logp, "StartRXAFS_StoreData failed (%lX)",code); ! } ! if (code == 0) { code = EndRXAFS_StoreData(callp, &outStatus, &volSync); + if (code) + osi_Log1(afsd_logp, "EndRXAFS_StoreData failed (%lX)",code); + } code = rx_EndCall(callp, code); osi_Log0(afsd_logp, "CALL StoreData DONE"); Index: openafs/src/WINNT/afsd/cm_freelance.c diff -c openafs/src/WINNT/afsd/cm_freelance.c:1.9 openafs/src/WINNT/afsd/cm_freelance.c:1.14 *** openafs/src/WINNT/afsd/cm_freelance.c:1.9 Mon Jun 7 02:22:58 2004 --- openafs/src/WINNT/afsd/cm_freelance.c Tue Jul 27 17:34:46 2004 *************** *** 3,8 **** --- 3,9 ---- #ifndef DJGPP #include + #include #include #else #include *************** *** 33,51 **** void cm_InitFakeRootDir(); void cm_InitFreelance() { - - #ifdef COMMENT - while ( !IsDebuggerPresent() ) { - Sleep(1000); - } - #endif - lock_InitializeMutex(&cm_Freelance_Lock, "Freelance Lock"); // yj: first we make a call to cm_initLocalMountPoints // to read all the local mount points from an ini file cm_InitLocalMountPoints(); ! // then we make a call to InitFakeRootDir to create // a fake root directory based on the local mount points cm_InitFakeRootDir(); --- 34,45 ---- void cm_InitFakeRootDir(); void cm_InitFreelance() { lock_InitializeMutex(&cm_Freelance_Lock, "Freelance Lock"); // yj: first we make a call to cm_initLocalMountPoints // to read all the local mount points from an ini file cm_InitLocalMountPoints(); ! // then we make a call to InitFakeRootDir to create // a fake root directory based on the local mount points cm_InitFakeRootDir(); *************** *** 231,237 **** int cm_FakeRootFid(cm_fid_t *fidp) { ! fidp->cell = 0x1; /* root cell */ fidp->volume = AFS_FAKE_ROOT_VOL_ID; /* root.afs ? */ fidp->vnode = 0x1; fidp->unique = 0x1; --- 225,231 ---- int cm_FakeRootFid(cm_fid_t *fidp) { ! fidp->cell = AFS_FAKE_ROOT_CELL_ID; /* root cell */ fidp->volume = AFS_FAKE_ROOT_VOL_ID; /* root.afs ? */ fidp->vnode = 0x1; fidp->unique = 0x1; *************** *** 270,276 **** osi_Log0(afsd_logp,"Invalidating local mount point scp... "); ! aFid.cell = 0x1; aFid.volume=AFS_FAKE_ROOT_VOL_ID; aFid.unique=0x1; aFid.vnode=0x2; --- 264,270 ---- osi_Log0(afsd_logp,"Invalidating local mount point scp... "); ! aFid.cell = AFS_FAKE_ROOT_CELL_ID; aFid.volume=AFS_FAKE_ROOT_VOL_ID; aFid.unique=0x1; aFid.vnode=0x2; *************** *** 344,356 **** // process for the freelance client. /* to be called while holding freelance lock unless during init. */ long cm_InitLocalMountPoints() { - FILE *fp; ! char line[200]; int i; char* t; cm_localMountPoint_t* aLocalMountPoint; char hdir[120]; cm_GetConfigDir(hdir); strcat(hdir, AFS_FREELANCE_INI); --- 338,441 ---- // process for the freelance client. /* to be called while holding freelance lock unless during init. */ long cm_InitLocalMountPoints() { FILE *fp; ! char line[512]; int i; char* t; cm_localMountPoint_t* aLocalMountPoint; char hdir[120]; + long code; + char rootCellName[256]; + #if !defined(DJGPP) + HKEY hkFreelance = 0; + DWORD dwType, dwSize; + DWORD dwMountPoints; + DWORD dwIndex; + #endif + + #if !defined(DJGPP) + if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, + "SOFTWARE\\OpenAFS\\Client\\Freelance", + 0, + KEY_READ|KEY_WRITE|KEY_QUERY_VALUE, + &hkFreelance) == ERROR_SUCCESS) { + + RegQueryInfoKey( hkFreelance, + NULL, /* lpClass */ + NULL, /* lpcClass */ + NULL, /* lpReserved */ + NULL, /* lpcSubKeys */ + NULL, /* lpcMaxSubKeyLen */ + NULL, /* lpcMaxClassLen */ + &dwMountPoints, /* lpcValues */ + NULL, /* lpcMaxValueNameLen */ + NULL, /* lpcMaxValueLen */ + NULL, /* lpcbSecurityDescriptor */ + NULL /* lpftLastWriteTime */ + ); + + if ( dwMountPoints == 0 ) { + sprintf(line,"%s#%s:root.cell.\n",rootCellName,rootCellName); + dwType = REG_SZ; + dwSize = strlen(line) + 1; + RegSetValueEx( hkFreelance, "0", 0, dwType, line, dwSize); + sprintf(line,".%s%%%s:root.cell.\n",rootCellName,rootCellName); + dwSize = strlen(line) + 1; + RegSetValueEx( hkFreelance, "1", 0, dwType, line, dwSize); + dwMountPoints = 2; + } + + // get the number of entries there are from the first line + // that we read + cm_noLocalMountPoints = dwMountPoints; + + // create space to store the local mount points + cm_localMountPoints = malloc(sizeof(cm_localMountPoint_t) * cm_noLocalMountPoints); + aLocalMountPoint = cm_localMountPoints; + + // now we read n lines and parse them into local mount points + // where n is the number of local mount points there are, as + // determined above. + // Each line in the ini file represents 1 local mount point and + // is in the format xxx#yyy:zzz, where xxx is the directory + // entry name, yyy is the cell name and zzz is the volume name. + // #yyy:zzz together make up the mount point. + for ( dwIndex = 0 ; dwIndex < dwMountPoints; dwIndex++ ) { + TCHAR szValueName[16]; + DWORD dwValueSize = 16; + dwSize = sizeof(line); + RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL, + &dwType, line, &dwSize); + + // line is not empty, so let's parse it + t = strchr(line, '#'); + if (!t) + t = strchr(line, '%'); + // make sure that there is a '#' or '%' separator in the line + if (!t) { + afsi_log("error occurred while parsing entry in %s: no # or %% separator in line %d", AFS_FREELANCE_INI, i); + fprintf(stderr, "error occurred while parsing entry in afs_freelance.ini: no # or %% separator in line %d", i); + return -1; + } + aLocalMountPoint->namep=malloc(t-line+1); + memcpy(aLocalMountPoint->namep, line, t-line); + *(aLocalMountPoint->namep + (t-line)) = 0; + + aLocalMountPoint->mountPointStringp=malloc(strlen(line) - (t-line) + 1); + memcpy(aLocalMountPoint->mountPointStringp, t, strlen(line)-(t-line)-2); + *(aLocalMountPoint->mountPointStringp + (strlen(line)-(t-line)-2)) = 0; + + osi_Log2(afsd_logp,"found mount point: name %s, string %s", + osi_LogSaveString(afsd_logp,aLocalMountPoint->namep), + osi_LogSaveString(afsd_logp,aLocalMountPoint->mountPointStringp)); + + aLocalMountPoint++; + } + + RegCloseKey(hkFreelance); + return 0; + } + #endif cm_GetConfigDir(hdir); strcat(hdir, AFS_FREELANCE_INI); *************** *** 359,376 **** // if we fail to open the file, create an empty one if (!fp) { ! fp = fopen(hdir, "w"); ! fputs("0\n", fp); ! fclose(fp); ! return 0; /* success */ } // we successfully opened the file osi_Log0(afsd_logp,"opened afs_freelance.ini"); // now we read the first line to see how many entries // there are ! fgets(line, 200, fp); // if the line is empty at any point when we're reading // we're screwed. report error and return. --- 444,484 ---- // if we fail to open the file, create an empty one if (!fp) { ! fp = fopen(hdir, "w"); ! code = cm_GetRootCellName(rootCellName); ! if (code == 0) { ! fputs("1\n", fp); ! fprintf(fp,"%s#%s:root.cell.\n",rootCellName,rootCellName); ! fprintf(fp,".%s%%%s:root.cell.\n",rootCellName,rootCellName); ! fclose(fp); ! fopen(hdir, "r"); ! } else { ! fputs("0\n", fp); ! fclose(fp); ! return 0; /* success */ ! } } // we successfully opened the file osi_Log0(afsd_logp,"opened afs_freelance.ini"); + + #if !defined(DJGPP) + RegCreateKeyEx( HKEY_LOCAL_MACHINE, + "SOFTWARE\\OpenAFS\\Client\\Freelance", + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_READ|KEY_WRITE, + NULL, + &hkFreelance, + NULL); + dwIndex = 0; + #endif + // now we read the first line to see how many entries // there are ! fgets(line, sizeof(line), fp); // if the line is empty at any point when we're reading // we're screwed. report error and return. *************** *** 396,434 **** // entry name, yyy is the cell name and zzz is the volume name. // #yyy:zzz together make up the mount point. for (i=0; inamep=malloc(t-line+1); memcpy(aLocalMountPoint->namep, line, t-line); *(aLocalMountPoint->namep + (t-line)) = 0; ! aLocalMountPoint->mountPointStringp=malloc(strlen(line) - (t-line) + 1); memcpy(aLocalMountPoint->mountPointStringp, t, strlen(line)-(t-line)-2); *(aLocalMountPoint->mountPointStringp + (strlen(line)-(t-line)-2)) = 0; osi_Log2(afsd_logp,"found mount point: name %s, string %s", ! aLocalMountPoint->namep, ! aLocalMountPoint->mountPointStringp); aLocalMountPoint++; } fclose(fp); return 0; } - int cm_getNoLocalMountPoints() { return cm_noLocalMountPoints; } --- 504,562 ---- // entry name, yyy is the cell name and zzz is the volume name. // #yyy:zzz together make up the mount point. for (i=0; inamep=malloc(t-line+1); memcpy(aLocalMountPoint->namep, line, t-line); *(aLocalMountPoint->namep + (t-line)) = 0; ! ! aLocalMountPoint->mountPointStringp=malloc(strlen(line) - (t-line) + 1); memcpy(aLocalMountPoint->mountPointStringp, t, strlen(line)-(t-line)-2); *(aLocalMountPoint->mountPointStringp + (strlen(line)-(t-line)-2)) = 0; osi_Log2(afsd_logp,"found mount point: name %s, string %s", ! aLocalMountPoint->namep, ! aLocalMountPoint->mountPointStringp); aLocalMountPoint++; } fclose(fp); + #if !defined(DJGPP) + if ( hkFreelance ) { + RegCloseKey(hkFreelance); + DeleteFile(hdir); + } + #endif return 0; } int cm_getNoLocalMountPoints() { return cm_noLocalMountPoints; } *************** *** 437,550 **** return 0; } ! long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, cm_fid_t *fidp) { FILE *fp; char hfile[120]; ! char line[200]; char fullname[200]; int n; int alias = 0; /* before adding, verify the cell name; if it is not a valid cell, don't add the mount point. allow partial matches as a means of poor man's alias. */ /* major performance issue? */ ! osi_Log3(afsd_logp,"Freelance Add Mount request: filename=%s cellname=%s volume=%s", ! filename, cellname, volume); if (cellname[0] == '.') { ! if (!cm_GetCell_Gen(&cellname[1], &fullname[1], CM_FLAG_CREATE)) return -1; - fullname[0]='.'; } else { if (!cm_GetCell_Gen(cellname, fullname, CM_FLAG_CREATE)) return -1; } ! osi_Log1(afsd_logp,"Freelance Adding Mount for Cell: %s", cellname); lock_ObtainMutex(&cm_Freelance_Lock); ! cm_GetConfigDir(hfile); ! strcat(hfile, AFS_FREELANCE_INI); ! fp = fopen(hfile, "r+"); ! if (!fp) ! return CM_ERROR_INVAL; ! fgets(line, 200, fp); ! n = atoi(line); ! n++; ! fseek(fp, 0, SEEK_SET); ! fprintf(fp, "%d", n); ! fseek(fp, 0, SEEK_END); ! fprintf(fp, "%s#%s:%s\n", filename, fullname, volume); ! fclose(fp); ! lock_ReleaseMutex(&cm_Freelance_Lock); ! ! /* cm_reInitLocalMountPoints(); */ ! if (fidp) { ! fidp->unique = 1; ! fidp->vnode = cm_noLocalMountPoints + 1; /* vnode value of last mt pt */ ! } ! cm_noteLocalMountPointChange(); ! ! return 0; } long cm_FreelanceRemoveMount(char *toremove) { ! int i, n; ! char* cp; ! char line[200]; ! char shortname[200]; ! char hfile[120], hfile2[120]; ! FILE *fp1, *fp2; ! int found=0; lock_ObtainMutex(&cm_Freelance_Lock); - cm_GetConfigDir(hfile); - strcat(hfile, AFS_FREELANCE_INI); - strcpy(hfile2, hfile); - strcat(hfile2, "2"); - fp1=fopen(hfile, "r+"); - if (!fp1) - return CM_ERROR_INVAL; - fp2=fopen(hfile2, "w+"); - if (!fp2) { - fclose(fp1); - return CM_ERROR_INVAL; - } - - fgets(line, 200, fp1); - n=atoi(line); - fprintf(fp2, "%d\n", n-1); - - for (i=0; iunique = 1; ! fidp->vnode = cm_noLocalMountPoints + 1; /* vnode value of last mt pt */ ! } ! cm_noteLocalMountPointChange(); ! return 0; } long cm_FreelanceRemoveMount(char *toremove) { ! int i, n; ! char* cp; ! char line[512]; ! char shortname[200]; ! char hfile[120], hfile2[120]; ! FILE *fp1, *fp2; ! int found=0; ! #if !defined(DJGPP) ! HKEY hkFreelance = 0; ! DWORD dwType, dwSize; ! DWORD dwMountPoints; ! DWORD dwIndex; ! #endif lock_ObtainMutex(&cm_Freelance_Lock); ! #if !defined(DJGPP) ! if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, ! "SOFTWARE\\OpenAFS\\Client\\Freelance", ! 0, ! KEY_READ|KEY_WRITE|KEY_QUERY_VALUE, ! &hkFreelance) == ERROR_SUCCESS) { ! ! RegQueryInfoKey( hkFreelance, ! NULL, /* lpClass */ ! NULL, /* lpcClass */ ! NULL, /* lpReserved */ ! NULL, /* lpcSubKeys */ ! NULL, /* lpcMaxSubKeyLen */ ! NULL, /* lpcMaxClassLen */ ! &dwMountPoints, /* lpcValues */ ! NULL, /* lpcMaxValueNameLen */ ! NULL, /* lpcMaxValueLen */ ! NULL, /* lpcbSecurityDescriptor */ ! NULL /* lpftLastWriteTime */ ! ); ! ! for ( dwIndex = 0; dwIndex < dwMountPoints; dwIndex++ ) { ! TCHAR szValueName[16]; ! DWORD dwValueSize = 16; ! dwSize = sizeof(line); ! RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL, ! &dwType, line, &dwSize); ! ! cp=strchr(line, '#'); ! if (!cp) ! cp=strchr(line, '%'); ! memcpy(shortname, line, cp-line); ! shortname[cp-line]=0; ! ! if (!strcmp(shortname, toremove)) { ! RegDeleteValue( hkFreelance, szValueName ); ! break; ! } ! } ! RegCloseKey(hkFreelance); ! } else ! #endif ! { ! cm_GetConfigDir(hfile); ! strcat(hfile, AFS_FREELANCE_INI); ! strcpy(hfile2, hfile); ! strcat(hfile2, "2"); ! fp1=fopen(hfile, "r+"); ! if (!fp1) ! return CM_ERROR_INVAL; ! fp2=fopen(hfile2, "w+"); ! if (!fp2) { ! fclose(fp1); ! return CM_ERROR_INVAL; ! } ! ! fgets(line, sizeof(line), fp1); ! n=atoi(line); ! fprintf(fp2, "%d\n", n-1); ! ! for (i=0; i