Index: openafs/src/WINNT/afsapplib/NTMakefile diff -c openafs/src/WINNT/afsapplib/NTMakefile:1.5.2.1 openafs/src/WINNT/afsapplib/NTMakefile:1.5.2.3 *** openafs/src/WINNT/afsapplib/NTMakefile:1.5.2.1 Fri Nov 5 14:21:40 2004 --- openafs/src/WINNT/afsapplib/NTMakefile Tue Dec 7 01:00:54 2004 *************** *** 127,133 **** clean:: $(CD) lang ! for /f %l in ('dir /B ??_??') do @$(NTLANG) %l $(MAKECMD) /nologo /f NTMakefile clean $(CD) .. --- 127,133 ---- clean:: $(CD) lang ! for /f %l in ('dir /B ??_??') do ( if exist @$(NTLANG) do @$(NTLANG) %l $(MAKECMD) /nologo /f NTMakefile clean ) $(CD) .. Index: openafs/src/WINNT/afsd/NTMakefile diff -c openafs/src/WINNT/afsd/NTMakefile:1.27.2.2 openafs/src/WINNT/afsd/NTMakefile:1.27.2.6 *** openafs/src/WINNT/afsd/NTMakefile:1.27.2.2 Fri Nov 5 14:21:42 2004 --- openafs/src/WINNT/afsd/NTMakefile Tue Dec 7 01:02:22 2004 *************** *** 337,345 **** AFSD_EXEFILE = $(EXEDIR)\afsd.exe AFSD_SDKLIBS =\ - largeint.lib \ netapi32.lib \ ! dnsapi.lib mpr.lib \ rpcrt4.lib \ user32.lib \ Dbghelp.lib \ --- 337,345 ---- AFSD_EXEFILE = $(EXEDIR)\afsd.exe AFSD_SDKLIBS =\ netapi32.lib \ ! dnsapi.lib \ ! mpr.lib \ rpcrt4.lib \ user32.lib \ Dbghelp.lib \ *************** *** 366,372 **** # afsd_service.exe $(EXEDIR)\afsd_service.exe: $(OUT)\afsd_service.obj $(AFSDOBJS) $(OUT)\afsd_service.res $(RXOBJS) $(AFSD_EXELIBS) ! $(EXECONLINK) $(AFSD_SDKLIBS) /MAP $(EXEPREP) # fs.exe --- 366,372 ---- # afsd_service.exe $(EXEDIR)\afsd_service.exe: $(OUT)\afsd_service.obj $(AFSDOBJS) $(OUT)\afsd_service.res $(RXOBJS) $(AFSD_EXELIBS) ! $(EXECONLINK) $(AFSD_SDKLIBS) /MAP /LARGEADDRESSAWARE $(EXEPREP) # fs.exe Index: openafs/src/WINNT/afsd/afsd.h diff -c openafs/src/WINNT/afsd/afsd.h:1.5 openafs/src/WINNT/afsd/afsd.h:1.5.2.1 *** openafs/src/WINNT/afsd/afsd.h:1.5 Tue Jul 20 10:36:41 2004 --- openafs/src/WINNT/afsd/afsd.h Tue Dec 7 01:01:41 2004 *************** *** 62,67 **** --- 62,68 ---- #include "cm_buf.h" #include "cm_freelance.h" #include "smb_ioctl.h" + #include "afsd_init.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.40.2.6 openafs/src/WINNT/afsd/afsd_init.c:1.40.2.11 *** openafs/src/WINNT/afsd/afsd_init.c:1.40.2.6 Fri Nov 5 14:21:42 2004 --- openafs/src/WINNT/afsd/afsd_init.c Tue Dec 7 07:49:22 2004 *************** *** 16,21 **** --- 16,23 ---- #include #include #include + #include + #include #include #include *************** *** 37,42 **** --- 39,46 ---- char AFSConfigKeyName[] = "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"; + char OpenAFSConfigKeyName[] = + "SOFTWARE\\OpenAFS\\Client"; osi_log_t *afsd_logp; *************** *** 99,123 **** int cm_dnsEnabled = 1; #endif extern initUpperCaseTable(); void afsd_initUpperCaseTable() { ! initUpperCaseTable(); } void afsi_start() { ! char wd[100]; ! 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")) { StringCbCopyA(wd, sizeof(wd), getenv("TEMP")); --- 103,154 ---- int cm_dnsEnabled = 1; #endif + + static int afsi_log_useTimestamp = 1; + + void + afsi_log(char *pattern, ...) + { + char s[256], t[100], d[100], u[512]; + DWORD zilch; + va_list ap; + va_start(ap, pattern); + + StringCbVPrintfA(s, sizeof(s), pattern, ap); + if ( afsi_log_useTimestamp ) { + GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t)); + GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d)); + StringCbPrintfA(u, sizeof(u), "%s %s: %s\n", d, t, s); + if (afsi_file != INVALID_HANDLE_VALUE) + WriteFile(afsi_file, u, strlen(u), &zilch, NULL); + #ifdef NOTSERVICE + printf("%s", u); + #endif + } else { + if (afsi_file != INVALID_HANDLE_VALUE) + WriteFile(afsi_file, s, strlen(s), &zilch, NULL); + } + } + extern initUpperCaseTable(); void afsd_initUpperCaseTable() { ! initUpperCaseTable(); } void afsi_start() { ! char wd[100]; ! 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")) { StringCbCopyA(wd, sizeof(wd), getenv("TEMP")); *************** *** 125,145 **** else { code = GetWindowsDirectory(wd, sizeof(wd)); ! if (code == 0) return; } ! StringCbCatA(wd, sizeof(wd), "\\afsd_init.log"); ! 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 ); --- 156,177 ---- else { code = GetWindowsDirectory(wd, sizeof(wd)); ! if (code == 0) ! return; } ! StringCbCatA(wd, sizeof(wd), "\\afsd_init.log"); ! 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 ); *************** *** 151,192 **** } 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"); ! StringCbCatA(u, sizeof(u), ": Created log file\n"); ! WriteFile(afsi_file, t, strlen(t), &zilch, NULL); ! WriteFile(afsi_file, u, strlen(u), &zilch, NULL); p = "PATH="; path = getenv("PATH"); ! WriteFile(afsi_file, p, strlen(p), &zilch, NULL); ! WriteFile(afsi_file, path, strlen(path), &zilch, NULL); ! WriteFile(afsi_file, "\n", 1, &zilch, NULL); ! } ! ! static int afsi_log_useTimestamp = 1; ! ! void ! afsi_log(char *pattern, ...) ! { ! char s[256], t[100], d[100], u[512]; ! int zilch; ! va_list ap; ! va_start(ap, pattern); ! ! StringCbVPrintfA(s, sizeof(s), pattern, ap); ! if ( afsi_log_useTimestamp ) { ! GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t)); ! GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d)); ! StringCbPrintfA(u, sizeof(u), "%s %s: %s\n", d, t, s); ! if (afsi_file != INVALID_HANDLE_VALUE) ! WriteFile(afsi_file, u, strlen(u), &zilch, NULL); ! #ifdef NOTSERVICE ! printf("%s", u); ! #endif ! } else { ! if (afsi_file != INVALID_HANDLE_VALUE) ! WriteFile(afsi_file, s, strlen(s), &zilch, NULL); ! } } /* --- 183,212 ---- } 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"); ! StringCbCatA(u, sizeof(u), ": Created log file\n"); ! WriteFile(afsi_file, t, strlen(t), &zilch, NULL); ! WriteFile(afsi_file, u, strlen(u), &zilch, NULL); p = "PATH="; path = getenv("PATH"); ! WriteFile(afsi_file, p, strlen(p), &zilch, NULL); ! WriteFile(afsi_file, path, strlen(path), &zilch, NULL); ! WriteFile(afsi_file, "\n", 1, &zilch, NULL); ! ! /* Initialize C RTL Code Page conversion functions */ ! /* All of the path info obtained from the SMB client is in the OEM code page */ ! afsi_log("OEM Code Page = %d", GetOEMCP()); ! afsi_log("locale = %s", setlocale(LC_ALL,NULL)); ! #ifdef COMMENT ! /* Two things to look into. First, should mbstowcs() be performing ! * character set translations from OEM to Unicode in smb3.c; ! * Second, do we need to set this translation in each function ! * due to multi-threading. ! */ ! afsi_log("locale -> %s", setlocale(LC_ALL, ".OCP")); ! afsi_log("_setmbcp = %d -> %d", _setmbcp(_MB_CP_OEM), _getmbcp()); ! #endif /* COMMENT */ } /* *************** *** 195,219 **** void afsd_ForceTrace(BOOL flush) { ! HANDLE handle; ! int len; ! char buf[256]; ! if (!logReady) return; ! len = GetTempPath(sizeof(buf)-10, buf); ! StringCbCopyA(&buf[len], sizeof(buf)-len, "/afsd.log"); ! handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ, ! NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); ! if (handle == INVALID_HANDLE_VALUE) { ! logReady = 0; ! osi_panic("Cannot create log file", __FILE__, __LINE__); ! } ! osi_LogPrint(afsd_logp, handle); ! if (flush) ! FlushFileBuffers(handle); ! CloseHandle(handle); } static void --- 215,239 ---- void afsd_ForceTrace(BOOL flush) { ! HANDLE handle; ! int len; ! char buf[256]; ! if (!logReady) return; ! len = GetTempPath(sizeof(buf)-10, buf); ! StringCbCopyA(&buf[len], sizeof(buf)-len, "/afsd.log"); ! handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ, ! NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); ! if (handle == INVALID_HANDLE_VALUE) { ! logReady = 0; ! osi_panic("Cannot create log file", __FILE__, __LINE__); ! } ! osi_LogPrint(afsd_logp, handle); ! if (flush) ! FlushFileBuffers(handle); ! CloseHandle(handle); } static void *************** *** 250,256 **** DWORD dwType; DWORD dwSize; DWORD dwValue; ! PBYTE pHostNames = NULL, pName; BOOL bNameFound = FALSE; if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, --- 270,276 ---- DWORD dwType; DWORD dwSize; DWORD dwValue; ! PBYTE pHostNames = NULL, pName = NULL; BOOL bNameFound = FALSE; if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, *************** *** 273,284 **** } 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; --- 293,306 ---- } if ( !bNameFound ) { + int size = strlen(cm_NetbiosName) + 2; if ( !pHostNames ) { ! pHostNames = malloc(size); dwSize = 1; } ! pName = pHostNames; ! StringCbCopyA(pName, size, cm_NetbiosName); ! pName += size - 1; *pName = '\0'; /* add a second nul terminator */ dwType = REG_MULTI_SZ; *************** *** 971,982 **** int afsd_InitDaemons(char **reasonP) { ! long code; ! cm_req_t req; ! cm_InitReq(&req); ! /* this should really be in an init daemon from here on down */ if (!cm_freelanceEnabled) { osi_Log0(afsd_logp, "Loading Root Volume from cell"); --- 993,1004 ---- int afsd_InitDaemons(char **reasonP) { ! long code; ! cm_req_t req; ! cm_InitReq(&req); ! /* this should really be in an init daemon from here on down */ if (!cm_freelanceEnabled) { osi_Log0(afsd_logp, "Loading Root Volume from cell"); *************** *** 990,1028 **** } } ! /* compute the root fid */ ! if (!cm_freelanceEnabled) { cm_rootFid.cell = cm_rootCellp->cellID; cm_rootFid.volume = cm_GetROVolumeID(cm_rootVolumep); cm_rootFid.vnode = 1; cm_rootFid.unique = 1; ! } ! else cm_FakeRootFid(&cm_rootFid); code = cm_GetSCache(&cm_rootFid, &cm_rootSCachep, cm_rootUserp, &req); ! afsi_log("cm_GetSCache code %x scache %x", code, (code ? (cm_scache_t *)-1 : cm_rootSCachep)); ! if (code != 0) { ! *reasonP = "unknown error"; ! return -1; ! } ! cm_InitDaemon(numBkgD); ! afsi_log("cm_InitDaemon"); ! return 0; } int afsd_InitSMB(char **reasonP, void *aMBfunc) { ! /* Do this last so that we don't handle requests before init is done. * Here we initialize the SMB listener. */ smb_Init(afsd_logp, cm_NetbiosName, smb_UseV3, LANadapter, numSvThreads, aMBfunc); ! afsi_log("smb_Init"); ! return 0; } #ifdef ReadOnly --- 1012,1066 ---- } } ! /* compute the root fid */ ! if (!cm_freelanceEnabled) { cm_rootFid.cell = cm_rootCellp->cellID; cm_rootFid.volume = cm_GetROVolumeID(cm_rootVolumep); cm_rootFid.vnode = 1; cm_rootFid.unique = 1; ! } ! else cm_FakeRootFid(&cm_rootFid); code = cm_GetSCache(&cm_rootFid, &cm_rootSCachep, cm_rootUserp, &req); ! afsi_log("cm_GetSCache code %x scache %x", code, (code ? (cm_scache_t *)-1 : cm_rootSCachep)); ! if (code != 0) { ! *reasonP = "unknown error"; ! return -1; ! } ! cm_InitDaemon(numBkgD); ! afsi_log("cm_InitDaemon"); ! return 0; } int afsd_InitSMB(char **reasonP, void *aMBfunc) { ! HKEY parmKey; ! DWORD dummyLen; ! DWORD dwValue; ! DWORD code; ! ! code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, OpenAFSConfigKeyName, ! 0, KEY_QUERY_VALUE, &parmKey); ! if (code == ERROR_SUCCESS) { ! dummyLen = sizeof(DWORD); ! code = RegQueryValueEx(parmKey, "StoreAnsiFilenames", NULL, NULL, ! (BYTE *) &dwValue, &dummyLen); ! if (code == ERROR_SUCCESS) ! smb_StoreAnsiFilenames = dwValue ? 1 : 0; ! RegCloseKey (parmKey); ! } ! ! /* Do this last so that we don't handle requests before init is done. * Here we initialize the SMB listener. */ smb_Init(afsd_logp, cm_NetbiosName, smb_UseV3, LANadapter, numSvThreads, aMBfunc); ! afsi_log("smb_Init complete"); ! return 0; } #ifdef ReadOnly Index: openafs/src/WINNT/afsd/afsd_service.c diff -c openafs/src/WINNT/afsd/afsd_service.c:1.28.2.3 openafs/src/WINNT/afsd/afsd_service.c:1.28.2.8 *** openafs/src/WINNT/afsd/afsd_service.c:1.28.2.3 Fri Nov 5 14:21:42 2004 --- openafs/src/WINNT/afsd/afsd_service.c Tue Dec 7 01:02:46 2004 *************** *** 11,16 **** --- 11,19 ---- #include #include + #include + #include + #include #include #include #include "afsd.h" *************** *** 41,46 **** --- 44,52 ---- extern void afsi_log(char *pattern, ...); + static SERVICE_STATUS ServiceStatus; + static SERVICE_STATUS_HANDLE StatusHandle; + HANDLE hAFSDMainThread = NULL; HANDLE WaitToTerminate; *************** *** 93,108 **** smb_DumpVCP(afsi_file, "a"); afsi_log("--- end dump ---"); DebugBreak(); SetEvent(WaitToTerminate); #ifdef JUMP if (GetCurrentThreadId() == MainThreadId) longjmp(notifier_jmp, 1); - else #endif /* JUMP */ ! ExitThread(1); } /* --- 99,123 ---- smb_DumpVCP(afsi_file, "a"); afsi_log("--- end dump ---"); + #ifdef DEBUG DebugBreak(); + #endif SetEvent(WaitToTerminate); #ifdef JUMP if (GetCurrentThreadId() == MainThreadId) longjmp(notifier_jmp, 1); #endif /* JUMP */ ! ! ServiceStatus.dwCurrentState = SERVICE_STOPPED; ! ServiceStatus.dwWin32ExitCode = NO_ERROR; ! ServiceStatus.dwCheckPoint = 0; ! ServiceStatus.dwWaitHint = 0; ! ServiceStatus.dwControlsAccepted = 0; ! SetServiceStatus(StatusHandle, &ServiceStatus); ! ! exit(1); } /* *************** *** 113,121 **** return 0; } - static SERVICE_STATUS ServiceStatus; - static SERVICE_STATUS_HANDLE StatusHandle; - DWORD afsd_ServiceFlushVolume(DWORD dwlpEventData) { --- 128,133 ---- *************** *** 421,426 **** --- 433,957 ---- RegCloseKey(hKey); } + DWORD + GetVersionInfo( CHAR * filename, CHAR * szOutput, DWORD dwOutput ) + { + DWORD dwVersionHandle; + LPVOID pVersionInfo = 0; + DWORD retval = 0; + LPDWORD pLangInfo = 0; + LPTSTR szVersion = 0; + UINT len = 0; + TCHAR szVerQ[] = TEXT("\\StringFileInfo\\12345678\\FileVersion"); + DWORD size = GetFileVersionInfoSize(filename, &dwVersionHandle); + + if (!size) { + afsi_log("GetFileVersionInfoSize failed"); + return GetLastError(); + } + + pVersionInfo = malloc(size); + if (!pVersionInfo) { + afsi_log("out of memory 1"); + return ERROR_NOT_ENOUGH_MEMORY; + } + + GetFileVersionInfo(filename, dwVersionHandle, size, pVersionInfo); + if (retval = GetLastError()) + { + afsi_log("GetFileVersionInfo failed: %d", retval); + goto cleanup; + } + + VerQueryValue(pVersionInfo, TEXT("\\VarFileInfo\\Translation"), + (LPVOID*)&pLangInfo, &len); + if (retval = GetLastError()) + { + afsi_log("VerQueryValue 1 failed: %d", retval); + goto cleanup; + } + + wsprintf(szVerQ, + TEXT("\\StringFileInfo\\%04x%04x\\FileVersion"), + LOWORD(*pLangInfo), HIWORD(*pLangInfo)); + + VerQueryValue(pVersionInfo, szVerQ, (LPVOID*)&szVersion, &len); + if (retval = GetLastError()) + { + /* try again with language 409 since the old binaries were tagged wrong */ + wsprintf(szVerQ, + TEXT("\\StringFileInfo\\0409%04x\\FileVersion"), + HIWORD(*pLangInfo)); + + VerQueryValue(pVersionInfo, szVerQ, (LPVOID*)&szVersion, &len); + if (retval = GetLastError()) { + afsi_log("VerQueryValue 2 failed: [%s] %d", szVerQ, retval); + goto cleanup; + } + } + snprintf(szOutput, dwOutput, TEXT("%s"), szVersion); + szOutput[dwOutput - 1] = 0; + + cleanup: + if (pVersionInfo) + free(pVersionInfo); + + return retval; + } + + static HINSTANCE hCrypt32; + static DWORD (WINAPI *pCertGetNameString)(PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags, + void* pvTypePara, LPTSTR pszNameString, DWORD cchNameString); + static BOOL (WINAPI *pCryptQueryObject)(DWORD dwObjectType, const void* pvObject, DWORD dwExpectedContentTypeFlags, + DWORD dwExpectedFormatTypeFlags, DWORD dwFlags, + DWORD* pdwMsgAndCertEncodingType, DWORD* pdwContentType, + DWORD* pdwFormatType, HCERTSTORE* phCertStore, + HCRYPTMSG* phMsg, const void** ppvContext); + static BOOL (WINAPI *pCryptMsgGetParam)(HCRYPTMSG hCryptMsg, DWORD dwParamType, DWORD dwIndex, + void* pvData, DWORD* pcbData); + static PCCERT_CONTEXT (WINAPI *pCertFindCertificateInStore)(HCERTSTORE hCertStore, DWORD dwCertEncodingType, + DWORD dwFindFlags, DWORD dwFindType, + const void* pvFindPara, + PCCERT_CONTEXT pPrevCertContext); + static BOOL (WINAPI *pCertCloseStore)(HCERTSTORE hCertStore, DWORD dwFlags); + static BOOL (WINAPI *pCryptMsgClose)(HCRYPTMSG hCryptMsg); + static BOOL (WINAPI *pCertCompareCertificate)(DWORD dwCertEncodingType, PCERT_INFO pCertId1, + PCERT_INFO pCertId2); + static BOOL (WINAPI *pCertFreeCertificateContext)(PCCERT_CONTEXT pCertContext); + + void LoadCrypt32(void) + { + hCrypt32 = LoadLibrary("crypt32"); + if ( !hCrypt32 ) + return; + + (FARPROC) pCertGetNameString = GetProcAddress( hCrypt32, "CertGetNameString" ); + (FARPROC) pCryptQueryObject = GetProcAddress( hCrypt32, "CryptQueryObject" ); + (FARPROC) pCryptMsgGetParam = GetProcAddress( hCrypt32, "CryptMsgGetParam" ); + (FARPROC) pCertFindCertificateInStore = GetProcAddress( hCrypt32, "CertFindCertificateInStore" ); + (FARPROC) pCertCloseStore = GetProcAddress( hCrypt32, "CertCloseStore" ); + (FARPROC) pCryptMsgClose = GetProcAddress( hCrypt32, "CryptMsgClose" ); + (FARPROC) pCertCompareCertificate = GetProcAddress( hCrypt32, "CertCompareCertificate" ); + (FARPROC) pCertFreeCertificateContext = GetProcAddress( hCrypt32, "CertFreeCertificateContext" ); + + if ( !pCertGetNameString || + !pCryptQueryObject || + !pCryptMsgGetParam || + !pCertFindCertificateInStore || + !pCertCloseStore || + !pCryptMsgClose || + !pCertCompareCertificate || + !pCertFreeCertificateContext) + { + FreeLibrary(hCrypt32); + hCrypt32 = NULL; + } + } + + void UnloadCrypt32(void) + { + FreeLibrary(hCrypt32); + } + + #define ENCODING (X509_ASN_ENCODING | PKCS_7_ASN_ENCODING) + + PCCERT_CONTEXT GetCertCtx(CHAR * filename) + { + wchar_t wfilename[260]; + BOOL fResult; + DWORD dwEncoding; + DWORD dwContentType; + DWORD dwFormatType; + DWORD dwSignerInfo; + HCERTSTORE hStore = NULL; + HCRYPTMSG hMsg = NULL; + PCMSG_SIGNER_INFO pSignerInfo = NULL; + PCCERT_CONTEXT pCertContext = NULL; + CERT_INFO CertInfo; + + if ( hCrypt32 == NULL ) + return NULL; + + ZeroMemory(&CertInfo, sizeof(CertInfo)); + mbstowcs(wfilename, filename, 260); + + fResult = pCryptQueryObject(CERT_QUERY_OBJECT_FILE, + wfilename, + CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED, + CERT_QUERY_FORMAT_FLAG_BINARY, + 0, + &dwEncoding, + &dwContentType, + &dwFormatType, + &hStore, + &hMsg, + NULL); + + if (!fResult) { + afsi_log("CryptQueryObject failed for [%s] with error 0x%x", + filename, + GetLastError()); + goto __exit; + } + + fResult = pCryptMsgGetParam(hMsg, + CMSG_SIGNER_INFO_PARAM, + 0, + NULL, + &dwSignerInfo); + + if (!fResult) { + afsi_log("CryptMsgGetParam failed for [%s] with error 0x%x", + filename, + GetLastError()); + goto __exit; + } + + pSignerInfo = (PCMSG_SIGNER_INFO)LocalAlloc(LPTR, dwSignerInfo); + + fResult = pCryptMsgGetParam(hMsg, + CMSG_SIGNER_INFO_PARAM, + 0, + (PVOID)pSignerInfo, + &dwSignerInfo); + + if (!fResult) { + afsi_log("CryptMsgGetParam failed for [%s] with error 0x%x", + filename, + GetLastError()); + goto __exit; + } + + CertInfo.Issuer = pSignerInfo->Issuer; + CertInfo.SerialNumber = pSignerInfo->SerialNumber; + + pCertContext = pCertFindCertificateInStore(hStore, + ENCODING, + 0, + CERT_FIND_SUBJECT_CERT, + (PVOID) &CertInfo, + NULL); + + if (!pCertContext) { + afsi_log("CertFindCertificateInStore for file [%s] failed with 0x%x", + filename, + GetLastError()); + goto __exit; + } + + __exit: + if (pSignerInfo) + LocalFree(pSignerInfo); + + /* if (pCertContext) + CertFreeCertificateContext(pCertContext);*/ + + if (hStore) + pCertCloseStore(hStore,0); + + if (hMsg) + pCryptMsgClose(hMsg); + + return pCertContext; + } + + BOOL VerifyTrust(CHAR * filename) + { + WIN_TRUST_ACTDATA_CONTEXT_WITH_SUBJECT fContextWSubject; + WIN_TRUST_SUBJECT_FILE fSubjectFile; + GUID trustAction = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE; + GUID subject = WIN_TRUST_SUBJTYPE_PE_IMAGE; + wchar_t wfilename[260]; + LONG ret; + BOOL success = FALSE; + + LONG (WINAPI *pWinVerifyTrust)(HWND hWnd, GUID* pgActionID, WINTRUST_DATA* pWinTrustData) = NULL; + HINSTANCE hWinTrust; + + if (filename == NULL ) + return FALSE; + + hWinTrust = LoadLibrary("wintrust"); + if ( !hWinTrust ) + return FALSE; + + if (((FARPROC) pWinVerifyTrust = + GetProcAddress( hWinTrust, "WinVerifyTrust" )) == NULL ) + { + FreeLibrary(hWinTrust); + return FALSE; + } + + mbstowcs(wfilename, filename, 260); + + fSubjectFile.hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, + 0, NULL); + fSubjectFile.lpPath = wfilename; + fContextWSubject.hClientToken = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, + FALSE, GetCurrentProcessId()); + fContextWSubject.SubjectType = &subject; + fContextWSubject.Subject = &fSubjectFile; + + ret = pWinVerifyTrust(INVALID_HANDLE_VALUE, &trustAction, (WINTRUST_DATA *)&fContextWSubject); + + if ( fSubjectFile.hFile != INVALID_HANDLE_VALUE ) + CloseHandle( fSubjectFile.hFile ); + if ( fContextWSubject.hClientToken != INVALID_HANDLE_VALUE ) + CloseHandle( fContextWSubject.hClientToken ); + + if (ret == ERROR_SUCCESS) { + success = TRUE; + } else { + DWORD gle = GetLastError(); + switch (gle) { + case TRUST_E_PROVIDER_UNKNOWN: + afsi_log("VerifyTrust failed: \"Generic Verify V2\" Provider Unknown"); + break; + case TRUST_E_NOSIGNATURE: + afsi_log("VerifyTrust failed: Unsigned executable"); + break; + case TRUST_E_EXPLICIT_DISTRUST: + afsi_log("VerifyTrust failed: Certificate Marked as Untrusted by the user"); + break; + case TRUST_E_SUBJECT_NOT_TRUSTED: + afsi_log("VerifyTrust failed: File is not trusted"); + break; + case TRUST_E_BAD_DIGEST: + afsi_log("VerifyTrust failed: Executable has been modified"); + break; + case CRYPT_E_SECURITY_SETTINGS: + afsi_log("VerifyTrust failed: local security options prevent verification"); + break; + default: + afsi_log("VerifyTrust failed: 0x%X", GetLastError()); + } + success = FALSE; + } + FreeLibrary(hWinTrust); + return success; + } + + void LogCertCtx(PCCERT_CONTEXT pCtx) { + DWORD dwData; + LPTSTR szName = NULL; + + if ( hCrypt32 == NULL ) + return; + + // Get Issuer name size. + if (!(dwData = pCertGetNameString(pCtx, + CERT_NAME_SIMPLE_DISPLAY_TYPE, + CERT_NAME_ISSUER_FLAG, + NULL, + NULL, + 0))) { + afsi_log("CertGetNameString failed: 0x%x", GetLastError()); + goto __exit; + } + + // Allocate memory for Issuer name. + szName = (LPTSTR)LocalAlloc(LPTR, dwData * sizeof(TCHAR)); + + // Get Issuer name. + if (!(pCertGetNameString(pCtx, + CERT_NAME_SIMPLE_DISPLAY_TYPE, + CERT_NAME_ISSUER_FLAG, + NULL, + szName, + dwData))) { + afsi_log("CertGetNameString failed: 0x%x", GetLastError()); + goto __exit; + } + + // print Issuer name. + afsi_log("Issuer Name: %s", szName); + LocalFree(szName); + szName = NULL; + + // Get Subject name size. + if (!(dwData = pCertGetNameString(pCtx, + CERT_NAME_SIMPLE_DISPLAY_TYPE, + 0, + NULL, + NULL, + 0))) { + afsi_log("CertGetNameString failed: 0x%x", GetLastError()); + goto __exit; + } + + // Allocate memory for subject name. + szName = (LPTSTR)LocalAlloc(LPTR, dwData * sizeof(TCHAR)); + + // Get subject name. + if (!(pCertGetNameString(pCtx, + CERT_NAME_SIMPLE_DISPLAY_TYPE, + 0, + NULL, + szName, + dwData))) { + afsi_log("CertGetNameString failed: 0x%x", GetLastError()); + goto __exit; + } + + // Print Subject Name. + afsi_log("Subject Name: %s", szName); + + __exit: + + if (szName) + LocalFree(szName); + } + + BOOL AFSModulesVerify(void) + { + CHAR filename[1024]; + CHAR afsdVersion[128]; + CHAR modVersion[128]; + CHAR checkName[1024]; + BOOL trustVerified = FALSE; + HMODULE hMods[1024]; + HANDLE hProcess; + DWORD cbNeeded; + unsigned int i; + BOOL success = TRUE; + PCCERT_CONTEXT pCtxService = NULL; + HINSTANCE hPSAPI; + DWORD (WINAPI *pGetModuleFileNameExA)(HANDLE hProcess, HMODULE hModule, LPTSTR lpFilename, DWORD nSize); + BOOL (WINAPI *pEnumProcessModules)(HANDLE hProcess, HMODULE* lphModule, DWORD cb, LPDWORD lpcbNeeded); + DWORD dummyLen, code; + DWORD cacheSize = CM_CONFIGDEFAULT_CACHESIZE; + DWORD verifyServiceSig = TRUE; + HKEY parmKey; + + hPSAPI = LoadLibrary("psapi"); + + if ( hPSAPI == NULL ) + return FALSE; + + if (!GetModuleFileName(NULL, filename, sizeof(filename))) + return FALSE; + + if (GetVersionInfo(filename, afsdVersion, sizeof(afsdVersion))) + return FALSE; + + afsi_log("%s version %s", filename, afsdVersion); + + if (((FARPROC) pGetModuleFileNameExA = + GetProcAddress( hPSAPI, "GetModuleFileNameExA" )) == NULL || + ((FARPROC) pEnumProcessModules = + GetProcAddress( hPSAPI, "EnumProcessModules" )) == NULL) + { + FreeLibrary(hPSAPI); + return FALSE; + } + + + code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters", + 0, KEY_QUERY_VALUE, &parmKey); + if (code == ERROR_SUCCESS) { + dummyLen = sizeof(cacheSize); + code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL, + (BYTE *) &cacheSize, &dummyLen); + RegCloseKey (parmKey); + } + + code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\OpenAFS\\Client", + 0, KEY_QUERY_VALUE, &parmKey); + if (code == ERROR_SUCCESS) { + dummyLen = sizeof(verifyServiceSig); + code = RegQueryValueEx(parmKey, "VerifyServiceSignature", NULL, NULL, + (BYTE *) &verifyServiceSig, &dummyLen); + RegCloseKey (parmKey); + } + + if (verifyServiceSig && cacheSize < 716800) { + trustVerified = VerifyTrust(filename); + } else { + afsi_log("Signature Verification disabled"); + } + + if (trustVerified) { + LoadCrypt32(); + + // get a certificate context for the signer of afsd_service. + pCtxService = GetCertCtx(filename); + if (pCtxService) + LogCertCtx(pCtxService); + } + + // Get a list of all the modules in this process. + hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, + FALSE, GetCurrentProcessId()); + + if (pEnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) + { + afsi_log("Num of Process Modules: %d", (cbNeeded / sizeof(HMODULE))); + + for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) + { + char szModName[2048]; + + // Get the full path to the module's file. + if (pGetModuleFileNameExA(hProcess, hMods[i], szModName, sizeof(szModName))) + { + lstrcpy(checkName, szModName); + strlwr(checkName); + + if ( strstr(checkName, "afspthread.dll") || + strstr(checkName, "afsauthent.dll") || + strstr(checkName, "afsrpc.dll") || + strstr(checkName, "libafsconf.dll") || + strstr(checkName, "libosi.dll") ) + { + if (GetVersionInfo(szModName, modVersion, sizeof(modVersion))) { + success = FALSE; + continue; + } + + afsi_log("%s version %s", szModName, modVersion); + if (strcmp(afsdVersion,modVersion)) { + afsi_log("Version mismatch: %s", szModName); + success = FALSE; + } + if ( trustVerified ) { + if ( !VerifyTrust(szModName) ) { + afsi_log("Signature Verification failed: %s", szModName); + success = FALSE; + } + else if (pCtxService) { + PCCERT_CONTEXT pCtx = GetCertCtx(szModName); + + if (!pCtx || !pCertCompareCertificate(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, + pCtxService->pCertInfo, + pCtx->pCertInfo)) { + afsi_log("Certificate mismatch: %s", szModName); + if (pCtx) + LogCertCtx(pCtx); + + success = FALSE; + } + + if (pCtx) + pCertFreeCertificateContext(pCtx); + } + } + } + } + } + } + + if (pCtxService) { + pCertFreeCertificateContext(pCtxService); + UnloadCrypt32(); + } + + FreeLibrary(hPSAPI); + + CloseHandle(hProcess); + return success; + } + typedef BOOL ( APIENTRY * AfsdInitHook )(void); #define AFSD_INIT_HOOK "AfsdInitHook" #define AFSD_HOOK_DLL "afsdhook.dll" *************** *** 527,532 **** --- 1058,1076 ---- } #endif + /* Verify the versions of the DLLs which were loaded */ + if (!AFSModulesVerify()) { + ServiceStatus.dwCurrentState = SERVICE_STOPPED; + ServiceStatus.dwWin32ExitCode = NO_ERROR; + ServiceStatus.dwCheckPoint = 0; + ServiceStatus.dwWaitHint = 0; + ServiceStatus.dwControlsAccepted = 0; + SetServiceStatus(StatusHandle, &ServiceStatus); + + /* exit if initialization failed */ + return; + } + /* allow an exit to be called prior to any initialization */ hInitHookDll = LoadLibrary(AFSD_HOOK_DLL); if (hInitHookDll) Index: openafs/src/WINNT/afsd/afsicf.cpp diff -c openafs/src/WINNT/afsd/afsicf.cpp:1.1 openafs/src/WINNT/afsd/afsicf.cpp:1.1.2.1 *** openafs/src/WINNT/afsd/afsicf.cpp:1.1 Wed Jul 14 02:00:18 2004 --- openafs/src/WINNT/afsd/afsicf.cpp Tue Dec 7 00:53:57 2004 *************** *** 135,140 **** --- 135,141 ---- INetFwOpenPort * fwPort = NULL; HRESULT hr; HRESULT rhr = S_OK; /* return value */ + int i = 0; hr = fwProfile->get_GloballyOpenPorts(&fwPorts); if (FAILED(hr)) { *************** *** 145,151 **** } // go through the supplied ports ! for (int i=0; i 1) - // Only supporting non-Unicode strings - return FALSE; - if (uInputString.Buffer && ((LPBYTE) uInputString.Buffer)[1] == '\0') { // Looks like unicode, better translate it --- 550,555 ---- *************** *** 565,570 **** --- 561,567 ---- } else lpszOutputString[0] = '\0'; + return FALSE; } // UnicodeStringToANSI Index: openafs/src/WINNT/afsd/cm_buf.c diff -c openafs/src/WINNT/afsd/cm_buf.c:1.13.2.3 openafs/src/WINNT/afsd/cm_buf.c:1.13.2.5 *** openafs/src/WINNT/afsd/cm_buf.c:1.13.2.3 Fri Nov 5 14:21:43 2004 --- openafs/src/WINNT/afsd/cm_buf.c Tue Dec 7 01:01:41 2004 *************** *** 339,344 **** --- 339,345 ---- 0, 0, buf_nbuffers * buf_bufferSize); if (data == NULL) { + afsi_log("Error mapping view of file: 0x%X", GetLastError()); if (hf != INVALID_HANDLE_VALUE) CloseHandle(hf); CloseHandle(hm); *************** *** 1464,1480 **** lock_ObtainRead(&buf_globalLock); ! sprintf(output, "%s - dumping buf_HashTable - buf_hashSize=%d\n", cookie, buf_hashSize); WriteFile(outputFile, output, strlen(output), &zilch, NULL); for (i = 0; i < buf_hashSize; i++) { ! for(bp = buf_hashTablepp[i]; bp; bp=bp->hashp) { if (bp->refCount) { ! sprintf(output, "%s bp=0x%08X, hash=%d, fid (cell=%d, volume=%d," ! "vnode=%d, unique=%d), size=%d refCount=%d\n", cookie, (void *)bp, i, bp->fid.cell, bp->fid.volume, bp->fid.vnode, bp->fid.unique, bp->size, bp->refCount); WriteFile(outputFile, output, strlen(output), &zilch, NULL); --- 1465,1480 ---- lock_ObtainRead(&buf_globalLock); ! StringCbPrintfA(output, sizeof(output), "%s - dumping buf_HashTable - buf_hashSize=%d\n", cookie, buf_hashSize); WriteFile(outputFile, output, strlen(output), &zilch, NULL); for (i = 0; i < buf_hashSize; i++) { ! for (bp = buf_hashTablepp[i]; bp; bp=bp->hashp) { if (bp->refCount) { ! StringCbPrintfA(output, sizeof(output), "vnode=%d, unique=%d), size=%d refCount=%d\n", cookie, (void *)bp, i, bp->fid.cell, bp->fid.volume, bp->fid.vnode, bp->fid.unique, bp->size, bp->refCount); WriteFile(outputFile, output, strlen(output), &zilch, NULL); *************** *** 1482,1488 **** } } ! sprintf(output, "%s - Done dumping buf_HashTable.\n", cookie); WriteFile(outputFile, output, strlen(output), &zilch, NULL); lock_ReleaseRead(&buf_globalLock); --- 1482,1488 ---- } } ! StringCbPrintfA(output, sizeof(output), "%s - Done dumping buf_HashTable.\n", cookie); WriteFile(outputFile, output, strlen(output), &zilch, NULL); lock_ReleaseRead(&buf_globalLock); Index: openafs/src/WINNT/afsd/cm_callback.c diff -c openafs/src/WINNT/afsd/cm_callback.c:1.20.2.5 openafs/src/WINNT/afsd/cm_callback.c:1.20.2.6 *** openafs/src/WINNT/afsd/cm_callback.c:1.20.2.5 Mon Oct 18 00:09:25 2004 --- openafs/src/WINNT/afsd/cm_callback.c Tue Dec 7 00:58:20 2004 *************** *** 160,166 **** if (scp->fid.volume == tfid.volume && scp->fid.vnode == tfid.vnode && scp->fid.unique == tfid.unique) { ! scp->refCount++; lock_ReleaseWrite(&cm_scacheLock); osi_Log1(afsd_logp, "Discarding SCache scp %x", scp); lock_ObtainMutex(&scp->mx); --- 160,166 ---- if (scp->fid.volume == tfid.volume && scp->fid.vnode == tfid.vnode && scp->fid.unique == tfid.unique) { ! cm_HoldSCacheNoLock(scp); lock_ReleaseWrite(&cm_scacheLock); osi_Log1(afsd_logp, "Discarding SCache scp %x", scp); lock_ObtainMutex(&scp->mx); *************** *** 168,174 **** lock_ReleaseMutex(&scp->mx); cm_CallbackNotifyChange(scp); lock_ObtainWrite(&cm_scacheLock); ! scp->refCount--; } } lock_ReleaseWrite(&cm_scacheLock); --- 168,174 ---- lock_ReleaseMutex(&scp->mx); cm_CallbackNotifyChange(scp); lock_ObtainWrite(&cm_scacheLock); ! cm_ReleaseSCacheNoLock(scp); } } lock_ReleaseWrite(&cm_scacheLock); *************** *** 201,207 **** for (hash = 0; hash < cm_hashTableSize; hash++) { for(scp=cm_hashTablep[hash]; scp; scp=scp->nextp) { if (scp->fid.volume == fidp->Volume) { ! scp->refCount++; lock_ReleaseWrite(&cm_scacheLock); lock_ObtainMutex(&scp->mx); osi_Log1(afsd_logp, "Discarding SCache scp %x", scp); --- 201,207 ---- for (hash = 0; hash < cm_hashTableSize; hash++) { for(scp=cm_hashTablep[hash]; scp; scp=scp->nextp) { if (scp->fid.volume == fidp->Volume) { ! cm_HoldSCacheNoLock(scp); lock_ReleaseWrite(&cm_scacheLock); lock_ObtainMutex(&scp->mx); osi_Log1(afsd_logp, "Discarding SCache scp %x", scp); *************** *** 209,215 **** lock_ReleaseMutex(&scp->mx); cm_CallbackNotifyChange(scp); lock_ObtainWrite(&cm_scacheLock); ! scp->refCount--; } } /* search one hash bucket */ } /* search all hash buckets */ --- 209,215 ---- lock_ReleaseMutex(&scp->mx); cm_CallbackNotifyChange(scp); lock_ObtainWrite(&cm_scacheLock); ! cm_ReleaseSCacheNoLock(scp); } } /* search one hash bucket */ } /* search all hash buckets */ *************** *** 290,296 **** lock_ObtainWrite(&cm_scacheLock); for (hash = 0; hash < cm_hashTableSize; hash++) { for (scp=cm_hashTablep[hash]; scp; scp=scp->nextp) { ! scp->refCount++; lock_ReleaseWrite(&cm_scacheLock); lock_ObtainMutex(&scp->mx); discarded = 0; --- 290,296 ---- lock_ObtainWrite(&cm_scacheLock); for (hash = 0; hash < cm_hashTableSize; hash++) { for (scp=cm_hashTablep[hash]; scp; scp=scp->nextp) { ! cm_HoldSCacheNoLock(scp); lock_ReleaseWrite(&cm_scacheLock); lock_ObtainMutex(&scp->mx); discarded = 0; *************** *** 306,312 **** if (discarded) cm_CallbackNotifyChange(scp); lock_ObtainWrite(&cm_scacheLock); ! scp->refCount--; } /* search one hash bucket */ } /* search all hash buckets */ --- 306,312 ---- if (discarded) cm_CallbackNotifyChange(scp); lock_ObtainWrite(&cm_scacheLock); ! cm_ReleaseSCacheNoLock(scp); } /* search one hash bucket */ } /* search all hash buckets */ *************** *** 909,925 **** lock_ObtainWrite(&cm_scacheLock); for (i=0; inextp) { ! scp->refCount++; lock_ReleaseWrite(&cm_scacheLock); if (scp->cbExpires > 0 && (scp->cbServerp == NULL || now > scp->cbExpires)) { osi_Log1(afsd_logp, "Callback Expiration Discarding SCache scp %x", scp); - cm_CallbackNotifyChange(scp); lock_ObtainMutex(&scp->mx); cm_DiscardSCache(scp); lock_ReleaseMutex(&scp->mx); } lock_ObtainWrite(&cm_scacheLock); ! osi_assert(scp->refCount-- > 0); } } lock_ReleaseWrite(&cm_scacheLock); --- 909,925 ---- lock_ObtainWrite(&cm_scacheLock); for (i=0; inextp) { ! cm_HoldSCacheNoLock(scp); lock_ReleaseWrite(&cm_scacheLock); if (scp->cbExpires > 0 && (scp->cbServerp == NULL || now > scp->cbExpires)) { osi_Log1(afsd_logp, "Callback Expiration Discarding SCache scp %x", scp); lock_ObtainMutex(&scp->mx); cm_DiscardSCache(scp); lock_ReleaseMutex(&scp->mx); + cm_CallbackNotifyChange(scp); } lock_ObtainWrite(&cm_scacheLock); ! cm_ReleaseSCacheNoLock(scp); } } lock_ReleaseWrite(&cm_scacheLock); Index: openafs/src/WINNT/afsd/cm_callback.h diff -c openafs/src/WINNT/afsd/cm_callback.h:1.3.16.1 openafs/src/WINNT/afsd/cm_callback.h:1.3.16.2 *** openafs/src/WINNT/afsd/cm_callback.h:1.3.16.1 Tue Aug 17 00:28:38 2004 --- openafs/src/WINNT/afsd/cm_callback.h Tue Dec 7 01:01:41 2004 *************** *** 66,69 **** --- 66,71 ---- extern osi_rwlock_t cm_callbackLock; + extern void cm_CallbackNotifyChange(cm_scache_t *scp); + #endif /* _CM_CALLBACK_H_ENV__ */ Index: openafs/src/WINNT/afsd/cm_config.c diff -c openafs/src/WINNT/afsd/cm_config.c:1.20 openafs/src/WINNT/afsd/cm_config.c:1.20.2.1 *** openafs/src/WINNT/afsd/cm_config.c:1.20 Thu Jul 22 05:23:52 2004 --- openafs/src/WINNT/afsd/cm_config.c Tue Dec 7 01:01:41 2004 *************** *** 738,744 **** void cm_GetConfigDir(char *dir) { ! char wdir[256]; int tlen; #ifdef AFS_WIN95_ENV char *afsconf_path; --- 738,744 ---- void cm_GetConfigDir(char *dir) { ! char wdir[256]; int tlen; #ifdef AFS_WIN95_ENV char *afsconf_path; Index: openafs/src/WINNT/afsd/cm_config.h diff -c openafs/src/WINNT/afsd/cm_config.h:1.6 openafs/src/WINNT/afsd/cm_config.h:1.6.2.1 *** openafs/src/WINNT/afsd/cm_config.h:1.6 Tue Aug 3 13:27:52 2004 --- openafs/src/WINNT/afsd/cm_config.h Tue Dec 7 01:01:41 2004 *************** *** 55,60 **** --- 55,62 ---- extern long cm_GetCellServDB(char *cellNamep); + extern void cm_GetConfigDir(char *dir); + #endif /* __CM_CONFIG_INTERFACES_ONLY__ */ #endif /* __CONFIG_H_ENV_ */ Index: openafs/src/WINNT/afsd/cm_freelance.c diff -c openafs/src/WINNT/afsd/cm_freelance.c:1.15.2.3 openafs/src/WINNT/afsd/cm_freelance.c:1.15.2.10 *** openafs/src/WINNT/afsd/cm_freelance.c:1.15.2.3 Fri Nov 5 14:21:44 2004 --- openafs/src/WINNT/afsd/cm_freelance.c Tue Dec 7 01:14:52 2004 *************** *** 332,338 **** /* called directly from ioctl */ /* called while not holding freelance lock */ ! int cm_noteLocalMountPointChange() { lock_ObtainMutex(&cm_Freelance_Lock); cm_fakeDirVersion++; cm_localMountPointChangeFlag = 1; --- 332,338 ---- /* called directly from ioctl */ /* called while not holding freelance lock */ ! int cm_noteLocalMountPointChange(void) { lock_ObtainMutex(&cm_Freelance_Lock); cm_fakeDirVersion++; cm_localMountPointChangeFlag = 1; *************** *** 377,389 **** ) { // mark the scp to be reused lock_ReleaseWrite(&cm_scacheLock); lock_ObtainMutex(&scp->mx); cm_DiscardSCache(scp); lock_ReleaseMutex(&scp->mx); cm_CallbackNotifyChange(scp); lock_ObtainWrite(&cm_scacheLock); ! scp->refCount--; // take the scp out of the hash lscpp = &cm_hashTablep[hash]; --- 377,390 ---- ) { // mark the scp to be reused + cm_HoldSCacheNoLock(scp); lock_ReleaseWrite(&cm_scacheLock); lock_ObtainMutex(&scp->mx); cm_DiscardSCache(scp); lock_ReleaseMutex(&scp->mx); cm_CallbackNotifyChange(scp); lock_ObtainWrite(&cm_scacheLock); ! cm_ReleaseSCacheNoLock(scp); // take the scp out of the hash lscpp = &cm_hashTablep[hash]; *************** *** 451,460 **** #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 */ --- 452,461 ---- #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 */ *************** *** 473,486 **** smb_UnixTimeFromLargeSearchTime(&FakeFreelanceModTime, &ftLastWriteTime); 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; } if (RegCreateKeyEx( HKEY_LOCAL_MACHINE, --- 474,486 ---- smb_UnixTimeFromLargeSearchTime(&FakeFreelanceModTime, &ftLastWriteTime); if ( dwMountPoints == 0 ) { ! rootCellName[0] = '.'; ! code = cm_GetRootCellName(&rootCellName[1]); ! if (code == 0) { ! cm_FreelanceAddMount(&rootCellName[1], &rootCellName[1], "root.cell", 0, NULL); ! cm_FreelanceAddMount(rootCellName, &rootCellName[1], "root.cell", 1, NULL); ! dwMountPoints = 2; ! } } if (RegCreateKeyEx( HKEY_LOCAL_MACHINE, *************** *** 527,534 **** TCHAR szValueName[16]; DWORD dwValueSize = 16; dwSize = sizeof(line); ! RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL, ! &dwType, line, &dwSize); /* find the trailing dot; null terminate after it */ t2 = strrchr(line, '.'); --- 527,541 ---- TCHAR szValueName[16]; DWORD dwValueSize = 16; dwSize = sizeof(line); ! if (RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL, ! &dwType, line, &dwSize)) ! { ! afsi_log("RegEnumValue(hkFreelance) failed"); ! cm_noLocalMountPoints--; ! continue; ! } ! ! afsi_log("Mountpoint[%d] = %s",dwIndex, line); /* find the trailing dot; null terminate after it */ t2 = strrchr(line, '.'); *************** *** 568,575 **** TCHAR szValueName[16]; DWORD dwValueSize = 16; dwSize = sizeof(line); ! RegEnumValue( hkFreelanceSymlinks, dwIndex, szValueName, &dwValueSize, NULL, ! &dwType, line, &dwSize); /* find the trailing dot; null terminate after it */ t2 = strrchr(line, '.'); --- 575,589 ---- TCHAR szValueName[16]; DWORD dwValueSize = 16; dwSize = sizeof(line); ! if (RegEnumValue( hkFreelanceSymlinks, dwIndex, szValueName, &dwValueSize, NULL, ! &dwType, line, &dwSize)) ! { ! afsi_log("RegEnumValue(hkFreelanceSymlinks) failed"); ! cm_noLocalMountPoints--; ! continue; ! } ! ! afsi_log("Symlink[%d] = %s",dwIndex, line); /* find the trailing dot; null terminate after it */ t2 = strrchr(line, '.'); *************** *** 618,644 **** strcat(hdir, AFS_FREELANCE_INI); // open the ini file for reading fp = fopen(hdir, "r"); - - // 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); ! 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", --- 632,645 ---- strcat(hdir, AFS_FREELANCE_INI); // open the ini file for reading fp = fopen(hdir, "r"); if (!fp) { ! /* look in the Windows directory where we used to store the file */ ! GetWindowsDirectory(hdir, sizeof(hdir)); ! strcat(hdir,"\\"); ! strcat(hdir, AFS_FREELANCE_INI); ! fp = fopen(hdir, "r"); } #if !defined(DJGPP) RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\OpenAFS\\Client\\Freelance", *************** *** 652,657 **** --- 653,674 ---- dwIndex = 0; #endif + if (!fp) { + #if !defined(DJGPP) + RegCloseKey(hkFreelance); + #endif + rootCellName[0] = '.'; + code = cm_GetRootCellName(&rootCellName[1]); + if (code == 0) { + cm_FreelanceAddMount(&rootCellName[1], &rootCellName[1], "root.cell", 0, NULL); + cm_FreelanceAddMount(rootCellName, &rootCellName[1], "root.cell", 1, NULL); + } + return 0; + } + + // 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, sizeof(line), fp); *************** *** 668,676 **** // that we read cm_noLocalMountPoints = atoi(line); ! // 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 --- 685,695 ---- // that we read cm_noLocalMountPoints = atoi(line); ! if (cm_noLocalMountPoints > 0) { ! // 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 *************** *** 688,693 **** --- 707,717 ---- return -1; } + /* find the trailing dot; null terminate after it */ + t2 = strrchr(line, '.'); + if (t2) + *(t2+1) = '\0'; + #if !defined(DJGPP) if ( hkFreelance ) { char szIndex[16]; *************** *** 714,721 **** *(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, --- 738,745 ---- *(aLocalMountPoint->namep + (t-line)) = 0; aLocalMountPoint->mountPointStringp=malloc(strlen(line) - (t-line) + 1); ! memcpy(aLocalMountPoint->mountPointStringp, t, strlen(line)-(t-line)-1); ! *(aLocalMountPoint->mountPointStringp + (strlen(line)-(t-line)-1)) = 0; osi_Log2(afsd_logp,"found mount point: name %s, string %s", aLocalMountPoint->namep, *************** *** 737,742 **** --- 761,918 ---- return cm_noLocalMountPoints; } + #if !defined(DJGPP) + long cm_FreelanceMountPointExists(char * filename) + { + char* cp; + char line[512]; + char shortname[200]; + int found = 0; + HKEY hkFreelance = 0; + DWORD dwType, dwSize; + DWORD dwMountPoints; + DWORD dwIndex; + + lock_ObtainMutex(&cm_Freelance_Lock); + + if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, + "SOFTWARE\\OpenAFS\\Client\\Freelance", + 0, + KEY_READ|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, filename)) { + found = 1; + break; + } + } + 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 (!stricmp(shortname, filename)) { + found = 1; + break; + } + } + RegCloseKey(hkFreelance); + } + + lock_ReleaseMutex(&cm_Freelance_Lock); + + return found; + } + + long cm_FreelanceSymlinkExists(char * filename) + { + char* cp; + char line[512]; + char shortname[200]; + int found = 0; + HKEY hkFreelance = 0; + DWORD dwType, dwSize; + DWORD dwSymlinks; + DWORD dwIndex; + + lock_ObtainMutex(&cm_Freelance_Lock); + + if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, + "SOFTWARE\\OpenAFS\\Client\\Freelance\\Symlinks", + 0, + KEY_READ|KEY_QUERY_VALUE, + &hkFreelance) == ERROR_SUCCESS) + { + RegQueryInfoKey( hkFreelance, + NULL, /* lpClass */ + NULL, /* lpcClass */ + NULL, /* lpReserved */ + NULL, /* lpcSubKeys */ + NULL, /* lpcMaxSubKeyLen */ + NULL, /* lpcMaxClassLen */ + &dwSymlinks, /* lpcValues */ + NULL, /* lpcMaxValueNameLen */ + NULL, /* lpcMaxValueLen */ + NULL, /* lpcbSecurityDescriptor */ + NULL /* lpftLastWriteTime */ + ); + + for ( dwIndex = 0; dwIndex < dwSymlinks; dwIndex++ ) { + TCHAR szValueName[16]; + DWORD dwValueSize = 16; + dwSize = sizeof(line); + RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL, + &dwType, line, &dwSize); + + cp=strchr(line, ':'); + memcpy(shortname, line, cp-line); + shortname[cp-line]=0; + + if (!strcmp(shortname, filename)) { + found = 1; + break; + } + } + for ( dwIndex = 0; dwIndex < dwSymlinks; dwIndex++ ) { + TCHAR szValueName[16]; + DWORD dwValueSize = 16; + dwSize = sizeof(line); + RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL, + &dwType, line, &dwSize); + + cp=strchr(line, ':'); + memcpy(shortname, line, cp-line); + shortname[cp-line]=0; + + if (!stricmp(shortname, filename)) { + found = 1; + break; + } + } + RegCloseKey(hkFreelance); + } + + lock_ReleaseMutex(&cm_Freelance_Lock); + + return found; + } + #endif + long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, int rw, cm_fid_t *fidp) { FILE *fp; *************** *** 761,766 **** --- 937,946 ---- osi_LogSaveString(afsd_logp,cellname), osi_LogSaveString(afsd_logp,volume), rw ? "rw" : "ro"); + + if ( filename[0] == '\0' || cellname[0] == '\0' || volume[0] == '\0' ) + return -1; + if (cellname[0] == '.') { if (!cm_GetCell_Gen(&cellname[1], fullname, CM_FLAG_CREATE)) return -1; *************** *** 768,773 **** --- 948,959 ---- if (!cm_GetCell_Gen(cellname, fullname, CM_FLAG_CREATE)) return -1; } + + #if !defined(DJGPP) + if ( cm_FreelanceMountPointExists(filename) || + cm_FreelanceSymlinkExists(filename) ) + return -1; + #endif osi_Log1(afsd_logp,"Freelance Adding Mount for Cell: %s", osi_LogSaveString(afsd_logp,cellname)); *************** *** 816,824 **** RegSetValueEx( hkFreelance, szIndex, 0, dwType, line, dwSize); break; } else { ! int len = strlen(filename); ! if ( dwType == REG_SZ && !strncmp(filename, szMount, len) && ! (szMount[len] == '%' || szMount[len] == '#')) { /* Replace the existing value */ dwType = REG_SZ; dwSize = strlen(line) + 1; --- 1002,1010 ---- RegSetValueEx( hkFreelance, szIndex, 0, dwType, line, dwSize); break; } else { ! int len = strlen(filename); ! if ( dwType == REG_SZ && !strncmp(filename, szMount, len) && ! (szMount[len] == '%' || szMount[len] == '#')) { /* Replace the existing value */ dwType = REG_SZ; dwSize = strlen(line) + 1; *************** *** 877,883 **** lock_ObtainMutex(&cm_Freelance_Lock); - #if !defined(DJGPP) if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\OpenAFS\\Client\\Freelance", --- 1063,1068 ---- *************** *** 970,980 **** long cm_FreelanceAddSymlink(char *filename, char *destination, cm_fid_t *fidp) { - FILE *fp; - char hfile[120]; char line[512]; char fullname[200]; - int n; int alias = 0; #if !defined(DJGPP) HKEY hkFreelanceSymlinks = 0; --- 1155,1162 ---- *************** *** 983,996 **** DWORD dwIndex; #endif ! /* 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_Log2(afsd_logp,"Freelance Add Symlink request: filename=%s destination=%s", osi_LogSaveString(afsd_logp,filename), osi_LogSaveString(afsd_logp,destination)); lock_ObtainMutex(&cm_Freelance_Lock); #if !defined(DJGPP) --- 1165,1197 ---- DWORD dwIndex; #endif ! /* before adding, verify the filename. If it is already in use, either as ! * as mount point or a cellname, do not permit the creation of the symlink. ! */ osi_Log2(afsd_logp,"Freelance Add Symlink request: filename=%s destination=%s", osi_LogSaveString(afsd_logp,filename), osi_LogSaveString(afsd_logp,destination)); + if ( filename[0] == '\0' || destination[0] == '\0' ) + return -1; + + fullname[0] = '\0'; + if (filename[0] == '.') { + cm_GetCell_Gen(&filename[1], fullname, CM_FLAG_CREATE); + if (stricmp(&filename[1],fullname) == 0) + return -1; + } else { + cm_GetCell_Gen(filename, fullname, CM_FLAG_CREATE); + if (stricmp(filename,fullname) == 0) + return -1; + } + + #if !defined(DJGPP) + if ( cm_FreelanceMountPointExists(filename) || + cm_FreelanceSymlinkExists(filename) ) + return -1; + #endif + lock_ObtainMutex(&cm_Freelance_Lock); #if !defined(DJGPP) *************** *** 1036,1043 **** RegSetValueEx( hkFreelanceSymlinks, szIndex, 0, dwType, line, dwSize); break; } else { ! int len = strlen(filename); ! if ( dwType == REG_SZ && !strncmp(filename, szLink, len) && szLink[len] == ':') { /* Replace the existing value */ dwType = REG_SZ; dwSize = strlen(line) + 1; --- 1237,1244 ---- RegSetValueEx( hkFreelanceSymlinks, szIndex, 0, dwType, line, dwSize); break; } else { ! int len = strlen(filename); ! if ( dwType == REG_SZ && !strncmp(filename, szLink, len) && szLink[len] == ':') { /* Replace the existing value */ dwType = REG_SZ; dwSize = strlen(line) + 1; *************** *** 1062,1073 **** long cm_FreelanceRemoveSymlink(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 hkFreelanceSymlinks = 0; --- 1263,1271 ---- *************** *** 1078,1084 **** lock_ObtainMutex(&cm_Freelance_Lock); - #if !defined(DJGPP) if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\OpenAFS\\Client\\Freelance\\Symlinks", --- 1276,1281 ---- Index: openafs/src/WINNT/afsd/cm_freelance.h diff -c openafs/src/WINNT/afsd/cm_freelance.h:1.6.2.2 openafs/src/WINNT/afsd/cm_freelance.h:1.6.2.3 *** openafs/src/WINNT/afsd/cm_freelance.h:1.6.2.2 Fri Nov 5 14:21:44 2004 --- openafs/src/WINNT/afsd/cm_freelance.h Tue Dec 7 01:01:41 2004 *************** *** 14,19 **** --- 14,20 ---- extern int cm_getLocalMountPointChange(); extern int cm_reInitLocalMountPoints(); extern void cm_InitFreelance(); + extern int cm_noteLocalMountPointChange(void); extern long cm_FreelanceRemoveMount(char *toremove); extern long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, int rw, cm_fid_t *fidp); extern long cm_FreelanceRemoveSymlink(char *toremove); Index: openafs/src/WINNT/afsd/cm_ioctl.c diff -c openafs/src/WINNT/afsd/cm_ioctl.c:1.33.2.5 openafs/src/WINNT/afsd/cm_ioctl.c:1.33.2.7 *** openafs/src/WINNT/afsd/cm_ioctl.c:1.33.2.5 Fri Nov 5 14:21:44 2004 --- openafs/src/WINNT/afsd/cm_ioctl.c Tue Dec 7 00:58:20 2004 *************** *** 91,103 **** lock_ObtainWrite(&cm_scacheLock); for (hash=0; hash < cm_hashTableSize; hash++) { for (scp=cm_hashTablep[hash]; scp; scp=scp->nextp) { ! scp->refCount++; lock_ReleaseWrite(&cm_scacheLock); lock_ObtainMutex(&scp->mx); cm_InvalidateACLUser(scp, userp); lock_ReleaseMutex(&scp->mx); lock_ObtainWrite(&cm_scacheLock); ! scp->refCount--; } } lock_ReleaseWrite(&cm_scacheLock); --- 91,103 ---- lock_ObtainWrite(&cm_scacheLock); for (hash=0; hash < cm_hashTableSize; hash++) { for (scp=cm_hashTablep[hash]; scp; scp=scp->nextp) { ! cm_HoldSCacheNoLock(scp); lock_ReleaseWrite(&cm_scacheLock); lock_ObtainMutex(&scp->mx); cm_InvalidateACLUser(scp, userp); lock_ReleaseMutex(&scp->mx); lock_ObtainWrite(&cm_scacheLock); ! cm_ReleaseSCacheNoLock(scp); } } lock_ReleaseWrite(&cm_scacheLock); *************** *** 259,265 **** * easier (because we can always jump past the initial "/afs" to find * the AFS path that should be written into afsdsbmt.ini). */ ! void cm_NormalizeAfsPath (char *outpathp, char *inpathp) { char *cp; char bslash_mountRoot[256]; --- 259,265 ---- * easier (because we can always jump past the initial "/afs" to find * the AFS path that should be written into afsdsbmt.ini). */ ! void cm_NormalizeAfsPath(char *outpathp, long outlen, char *inpathp) { char *cp; char bslash_mountRoot[256]; *************** *** 268,280 **** bslash_mountRoot[0] = '\\'; if (!strnicmp (inpathp, cm_mountRoot, strlen(cm_mountRoot))) ! lstrcpy (outpathp, inpathp); else if (!strnicmp (inpathp, bslash_mountRoot, strlen(bslash_mountRoot))) ! lstrcpy (outpathp, inpathp); else if ((inpathp[0] == '/') || (inpathp[0] == '\\')) ! sprintf (outpathp, "%s%s", cm_mountRoot, inpathp); else // inpathp looks like "/usr" ! sprintf (outpathp, "%s/%s", cm_mountRoot, inpathp); for (cp = outpathp; *cp != 0; ++cp) { if (*cp == '\\') --- 268,280 ---- bslash_mountRoot[0] = '\\'; if (!strnicmp (inpathp, cm_mountRoot, strlen(cm_mountRoot))) ! StringCbCopy(outpathp, outlen, inpathp); else if (!strnicmp (inpathp, bslash_mountRoot, strlen(bslash_mountRoot))) ! StringCbCopy(outpathp, outlen, inpathp); else if ((inpathp[0] == '/') || (inpathp[0] == '\\')) ! StringCbPrintfA(outpathp, outlen, "%s%s", cm_mountRoot, inpathp); else // inpathp looks like "/usr" ! StringCbPrintfA(outpathp, outlen, "%s/%s", cm_mountRoot, inpathp); for (cp = outpathp; *cp != 0; ++cp) { if (*cp == '\\') *************** *** 286,295 **** } if (!strcmpi (outpathp, cm_mountRoot)) { ! strcpy (outpathp, cm_mountRoot); } } /* parse the passed-in file name and do a namei on its parent. If we fail, * return an error code, otherwise return the vnode located in *scpp. */ --- 286,296 ---- } if (!strcmpi (outpathp, cm_mountRoot)) { ! StringCbCopy(outpathp, outlen, cm_mountRoot); } } + #define LEAF_SIZE 256 /* parse the passed-in file name and do a namei on its parent. If we fail, * return an error code, otherwise return the vnode located in *scpp. */ *************** *** 301,307 **** char *tp, *jp; cm_scache_t *substRootp; ! strcpy(tbuffer, ioctlp->inDatap); tp = strrchr(tbuffer, '\\'); jp = strrchr(tbuffer, '/'); if (!tp) --- 302,308 ---- char *tp, *jp; cm_scache_t *substRootp; ! StringCbCopyA(tbuffer, sizeof(tbuffer), ioctlp->inDatap); tp = strrchr(tbuffer, '\\'); jp = strrchr(tbuffer, '/'); if (!tp) *************** *** 309,322 **** else if (jp && (tp - tbuffer) < (jp - tbuffer)) tp = jp; if (!tp) { ! strcpy(tbuffer, "\\"); if (leafp) ! strcpy(leafp, ioctlp->inDatap); } else { *tp = 0; if (leafp) ! strcpy(leafp, tp+1); } if (tbuffer[0] == tbuffer[1] && --- 310,323 ---- else if (jp && (tp - tbuffer) < (jp - tbuffer)) tp = jp; if (!tp) { ! StringCbCopyA(tbuffer, sizeof(tbuffer), "\\"); if (leafp) ! StringCbCopyA(leafp, LEAF_SIZE, ioctlp->inDatap); } else { *tp = 0; if (leafp) ! StringCbCopyA(leafp, LEAF_SIZE, tp+1); } if (tbuffer[0] == tbuffer[1] && *************** *** 463,469 **** scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID && scp->fid.vnode==0x1 && scp->fid.unique==0x1 ) { ! strcpy(ioctlp->outDatap, "Freelance.Local.Root"); ioctlp->outDatap += strlen(ioctlp->outDatap) + 1; code = 0; } else --- 464,470 ---- scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID && scp->fid.vnode==0x1 && scp->fid.unique==0x1 ) { ! StringCbCopyA(ioctlp->outDatap, 999999, "Freelance.Local.Root"); ioctlp->outDatap += strlen(ioctlp->outDatap) + 1; code = 0; } else *************** *** 471,477 **** { cellp = cm_FindCellByID(scp->fid.cell); if (cellp) { ! strcpy(ioctlp->outDatap, cellp->namep); ioctlp->outDatap += strlen(ioctlp->outDatap) + 1; code = 0; } --- 472,478 ---- { cellp = cm_FindCellByID(scp->fid.cell); if (cellp) { ! StringCbCopyA(ioctlp->outDatap, 999999, cellp->namep); ioctlp->outDatap += strlen(ioctlp->outDatap) + 1; code = 0; } *************** *** 547,553 **** for (i=0; inextp) { if (scp->fid.volume == volume) { ! scp->refCount++; lock_ReleaseWrite(&cm_scacheLock); /* now flush the file */ --- 548,554 ---- for (i=0; inextp) { if (scp->fid.volume == volume) { ! cm_HoldSCacheNoLock(scp); lock_ReleaseWrite(&cm_scacheLock); /* now flush the file */ *************** *** 555,561 **** if ( code ) afsi_log("cm_FlushFile returns error: [%x]",code); lock_ObtainWrite(&cm_scacheLock); ! scp->refCount--; } } } --- 556,562 ---- if ( code ) afsi_log("cm_FlushFile returns error: [%x]",code); lock_ObtainWrite(&cm_scacheLock); ! cm_ReleaseSCacheNoLock(scp); } } } *************** *** 620,630 **** cp = ioctlp->inDatap; memcpy((char *)&volStat, cp, sizeof(AFSFetchVolumeStatus)); cp += sizeof(AFSFetchVolumeStatus); ! strcpy(volName, cp); cp += strlen(volName)+1; ! strcpy(offLineMsg, cp); cp += strlen(offLineMsg)+1; ! strcpy(motd, cp); storeStat.Mask = 0; if (volStat.MinQuota != -1) { storeStat.MinQuota = volStat.MinQuota; --- 621,631 ---- cp = ioctlp->inDatap; memcpy((char *)&volStat, cp, sizeof(AFSFetchVolumeStatus)); cp += sizeof(AFSFetchVolumeStatus); ! StringCbCopyA(volName, sizeof(volName), cp); cp += strlen(volName)+1; ! StringCbCopyA(offLineMsg, sizeof(offLineMsg), cp); cp += strlen(offLineMsg)+1; ! StringCbCopyA(motd, sizeof(motd), cp); storeStat.Mask = 0; if (volStat.MinQuota != -1) { storeStat.MinQuota = volStat.MinQuota; *************** *** 660,670 **** cp = ioctlp->outDatap; memcpy(cp, (char *)&volStat, sizeof(VolumeStatus)); cp += sizeof(VolumeStatus); ! strcpy(cp, volName); cp += strlen(volName)+1; ! strcpy(cp, offLineMsg); cp += strlen(offLineMsg)+1; ! strcpy(cp, motd); cp += strlen(motd)+1; /* now return updated return data pointer */ --- 661,671 ---- cp = ioctlp->outDatap; memcpy(cp, (char *)&volStat, sizeof(VolumeStatus)); cp += sizeof(VolumeStatus); ! StringCbCopyA(cp, 999999, volName); cp += strlen(volName)+1; ! StringCbCopyA(cp, 999999, offLineMsg); cp += strlen(offLineMsg)+1; ! StringCbCopyA(cp, 999999, motd); cp += strlen(motd)+1; /* now return updated return data pointer */ *************** *** 716,726 **** cp = ioctlp->outDatap; memcpy(cp, (char *)&volStat, sizeof(AFSFetchVolumeStatus)); cp += sizeof(AFSFetchVolumeStatus); ! strcpy(cp, volName); cp += strlen(volName)+1; ! strcpy(cp, offLineMsg); cp += strlen(offLineMsg)+1; ! strcpy(cp, motd); cp += strlen(motd)+1; /* return new size */ --- 717,727 ---- cp = ioctlp->outDatap; memcpy(cp, (char *)&volStat, sizeof(AFSFetchVolumeStatus)); cp += sizeof(AFSFetchVolumeStatus); ! StringCbCopyA(cp, 999999, volName); cp += strlen(volName)+1; ! StringCbCopyA(cp, 999999, offLineMsg); cp += strlen(offLineMsg)+1; ! StringCbCopyA(cp, 999999, motd); cp += strlen(motd)+1; /* return new size */ *************** *** 811,817 **** code = cm_ReadMountPoint(scp, userp, &req); if (code == 0) { cp = ioctlp->outDatap; ! strcpy(cp, scp->mountPointStringp); cp += strlen(cp) + 1; ioctlp->outDatap = cp; } --- 812,818 ---- code = cm_ReadMountPoint(scp, userp, &req); if (code == 0) { cp = ioctlp->outDatap; ! StringCbCopyA(cp, 999999, scp->mountPointStringp); cp += strlen(cp) + 1; ioctlp->outDatap = cp; } *************** *** 1096,1102 **** } lock_ReleaseRead(&cm_serverLock); cp = basep + max * sizeof(afs_int32); ! strcpy(cp, tcellp->namep); cp += strlen(tcellp->namep)+1; ioctlp->outDatap = cp; } --- 1097,1103 ---- } lock_ReleaseRead(&cm_serverLock); cp = basep + max * sizeof(afs_int32); ! StringCbCopyA(cp, 999999, tcellp->namep); cp += strlen(tcellp->namep)+1; ioctlp->outDatap = cp; } *************** *** 1169,1175 **** } /* return the default cellname to the caller */ ! strcpy(ioctlp->outDatap, cm_rootCellp->namep); ioctlp->outDatap += strlen(ioctlp->outDatap) +1; /* done: success */ --- 1170,1176 ---- } /* return the default cellname to the caller */ ! StringCbCopyA(ioctlp->outDatap, 999999, cm_rootCellp->namep); ioctlp->outDatap += strlen(ioctlp->outDatap) +1; /* done: success */ *************** *** 1218,1224 **** osi_panic("cm_IoctlSysName: !cm_sysName\n", __FILE__, __LINE__); if (!setSysName) { /* user just wants the info */ ! strcpy(outname, cm_sysName); foundname = cm_sysNameCount; *sysnamelist = cm_sysNameList; } else { --- 1219,1225 ---- osi_panic("cm_IoctlSysName: !cm_sysName\n", __FILE__, __LINE__); if (!setSysName) { /* user just wants the info */ ! StringCbCopyA(outname, sizeof(outname), cm_sysName); foundname = cm_sysNameCount; *sysnamelist = cm_sysNameList; } else { *************** *** 1226,1233 **** /* clear @sys entries from the dnlc, once afs_lookup can * do lookups of @sys entries and thinks it can trust them */ /* privs ok, store the entry, ... */ ! strcpy(cm_sysName, inname); ! strcpy(cm_sysNameList[0], inname); if (setSysName > 1) { /* ... or list */ cp = ioctlp->inDatap; for (count = 1; count < setSysName; ++count) { --- 1227,1234 ---- /* clear @sys entries from the dnlc, once afs_lookup can * do lookups of @sys entries and thinks it can trust them */ /* privs ok, store the entry, ... */ ! StringCbCopyA(cm_sysName, sizeof(cm_sysName), inname); ! StringCbCopyA(cm_sysNameList[0], MAXSYSNAME, inname); if (setSysName > 1) { /* ... or list */ cp = ioctlp->inDatap; for (count = 1; count < setSysName; ++count) { *************** *** 1235,1241 **** osi_panic("cm_IoctlSysName: no cm_sysNameList entry to write\n", __FILE__, __LINE__); t = strlen(cp); ! strcpy(cm_sysNameList[count], cp); cp += t + 1; } } --- 1236,1242 ---- osi_panic("cm_IoctlSysName: no cm_sysNameList entry to write\n", __FILE__, __LINE__); t = strlen(cp); ! StringCbCopyA(cm_sysNameList[count], MAXSYSNAME, cp); cp += t + 1; } } *************** *** 1248,1254 **** memcpy(cp, (char *)&foundname, sizeof(afs_int32)); cp += sizeof(afs_int32); /* skip found flag */ if (foundname) { ! strcpy(cp, outname); cp += strlen(outname) + 1; /* skip name and terminating null char */ for ( count=1; count < foundname ; ++count) { /* ... or list */ if ( !(*sysnamelist)[count] ) --- 1249,1255 ---- memcpy(cp, (char *)&foundname, sizeof(afs_int32)); cp += sizeof(afs_int32); /* skip found flag */ if (foundname) { ! StringCbCopyA(cp, 999999, outname); cp += strlen(outname) + 1; /* skip name and terminating null char */ for ( count=1; count < foundname ; ++count) { /* ... or list */ if ( !(*sysnamelist)[count] ) *************** *** 1258,1264 **** if (t >= MAXSYSNAME) osi_panic("cm_IoctlSysName: sysname entry garbled\n", __FILE__, __LINE__); ! strcpy(cp, (*sysnamelist)[count]); cp += t + 1; } } --- 1259,1265 ---- if (t >= MAXSYSNAME) osi_panic("cm_IoctlSysName: sysname entry garbled\n", __FILE__, __LINE__); ! StringCbCopyA(cp, 999999, (*sysnamelist)[count]); cp += t + 1; } } *************** *** 1426,1432 **** long cm_IoctlCreateMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp) { ! char leaf[256]; long code; cm_scache_t *dscp; cm_attr_t tattr; --- 1427,1433 ---- long cm_IoctlCreateMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp) { ! char leaf[LEAF_SIZE]; long code; cm_scache_t *dscp; cm_attr_t tattr; *************** *** 1453,1464 **** */ /* Extract the possibly partial cell name */ ! strcpy(cell, ioctlp->inDatap + 1); /* Skip the mp type character */ if (cp = strchr(cell, ':')) { /* Extract the volume name */ *cp = 0; ! strcpy(volume, cp + 1); /* Get the full name for this cell */ code = cm_SearchCellFile(cell, fullCell, 0, 0); --- 1454,1465 ---- */ /* Extract the possibly partial cell name */ ! StringCbCopyA(cell, sizeof(cell), ioctlp->inDatap + 1); /* Skip the mp type character */ if (cp = strchr(cell, ':')) { /* Extract the volume name */ *cp = 0; ! StringCbCopyA(volume, sizeof(volume), cp + 1); /* Get the full name for this cell */ code = cm_SearchCellFile(cell, fullCell, 0, 0); *************** *** 1469,1478 **** if (code) return CM_ERROR_NOSUCHCELL; ! sprintf(mpInfo, "%c%s:%s", *ioctlp->inDatap, fullCell, volume); } else { /* No cell name specified */ ! strcpy(mpInfo, ioctlp->inDatap); } #ifdef AFS_FREELANCE_CLIENT --- 1470,1479 ---- if (code) return CM_ERROR_NOSUCHCELL; ! StringCbPrintfA(mpInfo, sizeof(mpInfo), "%c%s:%s", *ioctlp->inDatap, fullCell, volume); } else { /* No cell name specified */ ! StringCbCopyA(mpInfo, sizeof(mpInfo), ioctlp->inDatap); } #ifdef AFS_FREELANCE_CLIENT *************** *** 1504,1510 **** long cm_IoctlSymlink(struct smb_ioctl *ioctlp, struct cm_user *userp) { ! char leaf[256]; long code; cm_scache_t *dscp; cm_attr_t tattr; --- 1505,1511 ---- long cm_IoctlSymlink(struct smb_ioctl *ioctlp, struct cm_user *userp) { ! char leaf[LEAF_SIZE]; long code; cm_scache_t *dscp; cm_attr_t tattr; *************** *** 1596,1606 **** if (code == 0) { cp = ioctlp->outDatap; if (newRootScp != NULL) { ! strcpy(cp, cm_mountRoot); ! strcat(cp, "/"); cp += strlen(cp); } ! strcpy(cp, spacep->data); cp += strlen(cp) + 1; ioctlp->outDatap = cp; cm_FreeSpace(spacep); --- 1597,1607 ---- if (code == 0) { cp = ioctlp->outDatap; if (newRootScp != NULL) { ! StringCbCopyA(cp, 999999, cm_mountRoot); ! StringCbCatA(cp, 999999, "/"); cp += strlen(cp); } ! StringCbCopyA(cp, 999999, spacep->data); cp += strlen(cp) + 1; ioctlp->outDatap = cp; cm_FreeSpace(spacep); *************** *** 1814,1820 **** ucellp->kvno = ct.AuthHandle; ucellp->expirationTime = ct.EndTimestamp; ucellp->gen++; ! if (uname) strcpy(ucellp->userName, uname); ucellp->flags |= CM_UCELLFLAG_RXKAD; lock_ReleaseMutex(&userp->mx); --- 1815,1822 ---- ucellp->kvno = ct.AuthHandle; ucellp->expirationTime = ct.EndTimestamp; ucellp->gen++; ! if (uname) ! StringCbCopyA(ucellp->userName, MAXKTCNAMELEN, uname); ucellp->flags |= CM_UCELLFLAG_RXKAD; lock_ReleaseMutex(&userp->mx); *************** *** 1900,1910 **** cp += sizeof(temp); /* cell name */ ! strcpy(cp, ucellp->cellp->namep); cp += strlen(cp) + 1; /* user name */ ! strcpy(cp, ucellp->userName); cp += strlen(cp) + 1; ioctlp->outDatap = cp; --- 1902,1912 ---- cp += sizeof(temp); /* cell name */ ! StringCbCopyA(cp, 999999, ucellp->cellp->namep); cp += strlen(cp) + 1; /* user name */ ! StringCbCopyA(cp, 999999, ucellp->userName); cp += strlen(cp) + 1; ioctlp->outDatap = cp; *************** *** 1988,1998 **** cp += sizeof(temp); /* cell name */ ! strcpy(cp, ucellp->cellp->namep); cp += strlen(cp) + 1; /* user name */ ! strcpy(cp, ucellp->userName); cp += strlen(cp) + 1; ioctlp->outDatap = cp; --- 1990,2000 ---- cp += sizeof(temp); /* cell name */ ! StringCbCopyA(cp, 999999, ucellp->cellp->namep); cp += strlen(cp) + 1; /* user name */ ! StringCbCopyA(cp, 999999, ucellp->userName); cp += strlen(cp) + 1; ioctlp->outDatap = cp; *************** *** 2084,2090 **** /* Parse the input parameters--first the required afs path, * then the requested submount name (which may be ""). */ ! cm_NormalizeAfsPath (afspath, ioctlp->inDatap); submountreqp = ioctlp->inDatap + (strlen(ioctlp->inDatap)+1); /* If the caller supplied a suggested submount name, see if --- 2086,2092 ---- /* Parse the input parameters--first the required afs path, * then the requested submount name (which may be ""). */ ! cm_NormalizeAfsPath (afspath, sizeof(afspath), ioctlp->inDatap); submountreqp = ioctlp->inDatap + (strlen(ioctlp->inDatap)+1); /* If the caller supplied a suggested submount name, see if *************** *** 2125,2133 **** strlen(&afspath[strlen(cm_mountRoot)])+1:2); RegCloseKey( hkSubmounts ); ! strcpy(ioctlp->outDatap, submountreqp); ! ioctlp->outDatap += strlen(ioctlp->outDatap) +1; ! lock_ReleaseMutex(&cm_Afsdsbmt_Lock); return 0; } --- 2127,2135 ---- strlen(&afspath[strlen(cm_mountRoot)])+1:2); RegCloseKey( hkSubmounts ); ! StringCbCopyA(ioctlp->outDatap, 999999, submountreqp); ! ioctlp->outDatap += strlen(ioctlp->outDatap) +1; ! lock_ReleaseMutex(&cm_Afsdsbmt_Lock); return 0; } *************** *** 2135,2143 **** * supplied path matches the submount's path, we can still * use the suggested submount name. */ ! cm_NormalizeAfsPath (submountPathNormalized, submountPath); if (!strcmp (submountPathNormalized, afspath)) { ! strcpy(ioctlp->outDatap, submountreqp); ioctlp->outDatap += strlen(ioctlp->outDatap) +1; RegCloseKey( hkSubmounts ); lock_ReleaseMutex(&cm_Afsdsbmt_Lock); --- 2137,2145 ---- * supplied path matches the submount's path, we can still * use the suggested submount name. */ ! cm_NormalizeAfsPath (submountPathNormalized, sizeof(submountPathNormalized), submountPath); if (!strcmp (submountPathNormalized, afspath)) { ! StringCbCopyA(ioctlp->outDatap, 999999, submountreqp); ioctlp->outDatap += strlen(ioctlp->outDatap) +1; RegCloseKey( hkSubmounts ); lock_ReleaseMutex(&cm_Afsdsbmt_Lock); *************** *** 2204,2212 **** * that our caller specified. If so, we can return * this submount. */ ! cm_NormalizeAfsPath (submountPathNormalized, submountPath); if (!strcmp (submountPathNormalized, afspath)) { ! strcpy(ioctlp->outDatap, submountName); ioctlp->outDatap += strlen(ioctlp->outDatap) +1; RegCloseKey(hkSubmounts); lock_ReleaseMutex(&cm_Afsdsbmt_Lock); --- 2206,2214 ---- * that our caller specified. If so, we can return * this submount. */ ! cm_NormalizeAfsPath (submountPathNormalized, sizeof(submountPathNormalized), submountPath); if (!strcmp (submountPathNormalized, afspath)) { ! StringCbCopyA(ioctlp->outDatap, 999999, submountName); ioctlp->outDatap += strlen(ioctlp->outDatap) +1; RegCloseKey(hkSubmounts); lock_ReleaseMutex(&cm_Afsdsbmt_Lock); *************** *** 2221,2227 **** * when writing out the submount. */ ! sprintf(ioctlp->outDatap, "auto%ld", nextAutoSubmount); RegSetValueEx( hkSubmounts, ioctlp->outDatap, --- 2223,2229 ---- * when writing out the submount. */ ! StringCbPrintfA(ioctlp->outDatap, 999999, "auto%ld", nextAutoSubmount); RegSetValueEx( hkSubmounts, ioctlp->outDatap, Index: openafs/src/WINNT/afsd/cm_scache.c diff -c openafs/src/WINNT/afsd/cm_scache.c:1.14.2.2 openafs/src/WINNT/afsd/cm_scache.c:1.14.2.3 *** openafs/src/WINNT/afsd/cm_scache.c:1.14.2.2 Fri Nov 5 14:21:44 2004 --- openafs/src/WINNT/afsd/cm_scache.c Tue Dec 7 00:58:20 2004 *************** *** 235,241 **** lock_ObtainWrite(&cm_scacheLock); for(scp=cm_hashTablep[hash]; scp; scp=scp->nextp) { if (cm_FidCmp(fidp, &scp->fid) == 0) { ! scp->refCount++; cm_AdjustLRU(scp); lock_ReleaseWrite(&cm_scacheLock); return scp; --- 235,241 ---- lock_ObtainWrite(&cm_scacheLock); for(scp=cm_hashTablep[hash]; scp; scp=scp->nextp) { if (cm_FidCmp(fidp, &scp->fid) == 0) { ! cm_HoldSCacheNoLock(scp); cm_AdjustLRU(scp); lock_ReleaseWrite(&cm_scacheLock); return scp; *************** *** 272,280 **** // yj: check if we have the scp, if so, we don't need // to do anything else lock_ObtainWrite(&cm_scacheLock); ! for(scp=cm_hashTablep[hash]; scp; scp=scp->nextp) { if (cm_FidCmp(fidp, &scp->fid) == 0) { ! scp->refCount++; *outScpp = scp; cm_AdjustLRU(scp); lock_ReleaseWrite(&cm_scacheLock); --- 272,280 ---- // yj: check if we have the scp, if so, we don't need // to do anything else lock_ObtainWrite(&cm_scacheLock); ! for (scp=cm_hashTablep[hash]; scp; scp=scp->nextp) { if (cm_FidCmp(fidp, &scp->fid) == 0) { ! cm_HoldSCacheNoLock(scp); *outScpp = scp; cm_AdjustLRU(scp); lock_ReleaseWrite(&cm_scacheLock); *************** *** 369,377 **** /* otherwise, we have the volume, now reverify that the scp doesn't * exist, and proceed. */ ! for(scp=cm_hashTablep[hash]; scp; scp=scp->nextp) { if (cm_FidCmp(fidp, &scp->fid) == 0) { ! scp->refCount++; cm_AdjustLRU(scp); lock_ReleaseWrite(&cm_scacheLock); if (volp) --- 369,378 ---- /* otherwise, we have the volume, now reverify that the scp doesn't * exist, and proceed. */ ! for (scp=cm_hashTablep[hash]; scp; scp=scp->nextp) { if (cm_FidCmp(fidp, &scp->fid) == 0) { ! osi_assert(scp->volp == volp); ! cm_HoldSCacheNoLock(scp); cm_AdjustLRU(scp); lock_ReleaseWrite(&cm_scacheLock); if (volp) *************** *** 978,983 **** --- 979,992 ---- afsFidp->Unique = fidp->unique; } + void cm_HoldSCacheNoLock(cm_scache_t *scp) + { + #ifdef NOLOCK_ASSERT + osi_assert(scp->refCount > 0); + #endif + scp->refCount++; + } + void cm_HoldSCache(cm_scache_t *scp) { lock_ObtainWrite(&cm_scacheLock); *************** *** 986,991 **** --- 995,1005 ---- lock_ReleaseWrite(&cm_scacheLock); } + void cm_ReleaseSCacheNoLock(cm_scache_t *scp) + { + osi_assert(scp->refCount-- > 0); + } + void cm_ReleaseSCache(cm_scache_t *scp) { lock_ObtainWrite(&cm_scacheLock); *************** *** 1033,1041 **** for (scp = cm_scacheLRULastp; scp; scp = (cm_scache_t *) osi_QPrev(&scp->q)) { ! if (scp->refCount != 0) { ! sprintf(output, "%s fid (cell=%d, volume=%d, vnode=%d, unique=%d) refCount=%d\n", cookie, scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique, scp->refCount); WriteFile(outputFile, output, strlen(output), &zilch, NULL); --- 1047,1055 ---- for (scp = cm_scacheLRULastp; scp; scp = (cm_scache_t *) osi_QPrev(&scp->q)) { ! if (scp->refCount > 0) { ! sprintf(output, "%s fid (cell=%d, volume=%d, vnode=%d, unique=%d) refCount=%u\n", cookie, scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique, scp->refCount); WriteFile(outputFile, output, strlen(output), &zilch, NULL); *************** *** 1051,1059 **** { if (scp) { ! if (scp->refCount) { ! sprintf(output, "%s scp=0x%08X, hash=%d, fid (cell=%d, volume=%d, vnode=%d, unique=%d) refCount=%d\n", cookie, (void *)scp, i, scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique, scp->refCount); WriteFile(outputFile, output, strlen(output), &zilch, NULL); --- 1065,1073 ---- { if (scp) { ! if (scp->refCount > 0) { ! sprintf(output, "%s scp=0x%08X, hash=%d, fid (cell=%d, volume=%d, vnode=%d, unique=%d) refCount=%u\n", cookie, (void *)scp, i, scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique, scp->refCount); WriteFile(outputFile, output, strlen(output), &zilch, NULL); Index: openafs/src/WINNT/afsd/cm_scache.h diff -c openafs/src/WINNT/afsd/cm_scache.h:1.4.2.3 openafs/src/WINNT/afsd/cm_scache.h:1.4.2.5 *** openafs/src/WINNT/afsd/cm_scache.h:1.4.2.3 Fri Nov 5 14:21:44 2004 --- openafs/src/WINNT/afsd/cm_scache.h Tue Dec 7 01:01:41 2004 *************** *** 58,64 **** * write-locked to prevent buffers from * being created during a truncate op, etc. */ ! unsigned long refCount; /* reference count; cm_scacheLock */ osi_queueData_t *bufReadsp; /* queue of buffers being read */ osi_queueData_t *bufWritesp; /* queue of buffers being written */ --- 58,64 ---- * write-locked to prevent buffers from * being created during a truncate op, etc. */ ! long refCount; /* reference count; cm_scacheLock */ osi_queueData_t *bufReadsp; /* queue of buffers being read */ osi_queueData_t *bufWritesp; /* queue of buffers being written */ *************** *** 240,247 **** --- 240,251 ---- extern void cm_AFSFidFromFid(struct AFSFid *, cm_fid_t *); + extern void cm_HoldSCacheNoLock(cm_scache_t *); + extern void cm_HoldSCache(cm_scache_t *); + extern void cm_ReleaseSCacheNoLock(cm_scache_t *); + extern void cm_ReleaseSCache(cm_scache_t *); extern cm_scache_t *cm_FindSCache(cm_fid_t *fidp); *************** *** 256,259 **** --- 260,265 ---- extern void cm_DiscardSCache(cm_scache_t *scp); + extern int cm_FindFileType(cm_fid_t *fidp); + #endif /* __CM_SCACHE_H_ENV__ */ Index: openafs/src/WINNT/afsd/cm_user.c diff -c openafs/src/WINNT/afsd/cm_user.c:1.5 openafs/src/WINNT/afsd/cm_user.c:1.5.2.1 *** openafs/src/WINNT/afsd/cm_user.c:1.5 Sun Apr 4 22:16:11 2004 --- openafs/src/WINNT/afsd/cm_user.c Tue Dec 7 00:58:20 2004 *************** *** 27,121 **** void cm_InitUser(void) { ! static osi_once_t once; ! if (osi_Once(&once)) { ! lock_InitializeRWLock(&cm_userLock, "cm_userLock"); ! osi_EndOnce(&once); ! } ! cm_rootUserp = cm_NewUser(); } cm_user_t *cm_NewUser(void) { ! cm_user_t *up; ! up = malloc(sizeof(*up)); ! memset(up, 0, sizeof(*up)); ! up->refCount = 1; ! up->vcRefs = 1; /* from caller */ ! lock_InitializeMutex(&up->mx, "cm_user_t"); ! return up; } /* must be called with locked userp */ cm_ucell_t *cm_GetUCell(cm_user_t *userp, cm_cell_t *cellp) { ! cm_ucell_t *ucp; ! lock_AssertMutex(&userp->mx); ! for(ucp = userp->cellInfop; ucp; ucp=ucp->nextp) { ! if (ucp->cellp == cellp) break; ! } ! if (!ucp) { ! ucp = malloc(sizeof(*ucp)); ! memset(ucp, 0, sizeof(*ucp)); ! ucp->nextp = userp->cellInfop; ! if (userp->cellInfop) ! ucp->iterator = userp->cellInfop->iterator + 1; ! else ! ucp->iterator = 1; ! userp->cellInfop = ucp; ! ucp->cellp = cellp; ! } ! return ucp; } cm_ucell_t *cm_FindUCell(cm_user_t *userp, int iterator) { ! cm_ucell_t *ucp; ! cm_ucell_t *best; ! best = NULL; ! lock_AssertMutex(&userp->mx); ! for (ucp = userp->cellInfop; ucp; ucp = ucp->nextp) { ! if (ucp->iterator >= iterator) ! best = ucp; ! else ! break; ! } ! return best; } void cm_HoldUser(cm_user_t *up) { ! lock_ObtainWrite(&cm_userLock); ! up->refCount++; ! lock_ReleaseWrite(&cm_userLock); } void cm_ReleaseUser(cm_user_t *up) { ! cm_ucell_t *ucp; cm_ucell_t *ncp; ! if (up == NULL) return; ! lock_ObtainWrite(&cm_userLock); ! osi_assert(up->refCount-- > 0); ! if (up->refCount == 0) { ! lock_FinalizeMutex(&up->mx); ! for(ucp = up->cellInfop; ucp; ucp = ncp) { ! ncp = ucp->nextp; ! if (ucp->ticketp) free(ucp->ticketp); free(ucp); } free(up); } ! lock_ReleaseWrite(&cm_userLock); } /* release the count of the # of connections that use this user structure. --- 27,124 ---- void cm_InitUser(void) { ! static osi_once_t once; ! if (osi_Once(&once)) { ! lock_InitializeRWLock(&cm_userLock, "cm_userLock"); ! osi_EndOnce(&once); ! } ! cm_rootUserp = cm_NewUser(); } cm_user_t *cm_NewUser(void) { ! cm_user_t *up; ! up = malloc(sizeof(*up)); ! memset(up, 0, sizeof(*up)); ! up->refCount = 1; ! up->vcRefs = 1; /* from caller */ ! lock_InitializeMutex(&up->mx, "cm_user_t"); ! return up; } /* must be called with locked userp */ cm_ucell_t *cm_GetUCell(cm_user_t *userp, cm_cell_t *cellp) { ! cm_ucell_t *ucp; ! lock_AssertMutex(&userp->mx); ! for (ucp = userp->cellInfop; ucp; ucp=ucp->nextp) { ! if (ucp->cellp == cellp) ! break; ! } ! if (!ucp) { ! ucp = malloc(sizeof(*ucp)); ! memset(ucp, 0, sizeof(*ucp)); ! ucp->nextp = userp->cellInfop; ! if (userp->cellInfop) ! ucp->iterator = userp->cellInfop->iterator + 1; ! else ! ucp->iterator = 1; ! userp->cellInfop = ucp; ! ucp->cellp = cellp; ! } ! return ucp; } cm_ucell_t *cm_FindUCell(cm_user_t *userp, int iterator) { ! cm_ucell_t *ucp; ! cm_ucell_t *best; ! best = NULL; ! lock_AssertMutex(&userp->mx); ! for (ucp = userp->cellInfop; ucp; ucp = ucp->nextp) { ! if (ucp->iterator >= iterator) ! best = ucp; ! else ! break; ! } ! return best; } void cm_HoldUser(cm_user_t *up) { ! lock_ObtainWrite(&cm_userLock); ! up->refCount++; ! lock_ReleaseWrite(&cm_userLock); } void cm_ReleaseUser(cm_user_t *up) { ! cm_ucell_t *ucp; cm_ucell_t *ncp; ! if (up == NULL) ! return; ! lock_ObtainWrite(&cm_userLock); ! osi_assert(up->refCount-- > 0); ! if (up->refCount == 0) { ! lock_FinalizeMutex(&up->mx); ! for (ucp = up->cellInfop; ucp; ucp = ncp) { ! ncp = ucp->nextp; ! if (ucp->ticketp) ! free(ucp->ticketp); free(ucp); } free(up); } ! lock_ReleaseWrite(&cm_userLock); } /* release the count of the # of connections that use this user structure. *************** *** 126,135 **** */ void cm_ReleaseUserVCRef(cm_user_t *userp) { ! lock_ObtainMutex(&userp->mx); ! osi_assert(userp->vcRefs-- > 0); ! lock_ReleaseMutex(&userp->mx); ! } /* --- 129,138 ---- */ void cm_ReleaseUserVCRef(cm_user_t *userp) { ! lock_ObtainMutex(&userp->mx); ! osi_assert(userp->vcRefs-- > 0); ! lock_ReleaseMutex(&userp->mx); ! } /* *************** *** 142,187 **** */ void cm_CheckTokenCache(long now) { ! extern smb_vc_t *smb_allVCsp; /* global vcp list */ ! smb_vc_t *vcp; ! smb_user_t *usersp; ! cm_user_t *userp = NULL; ! cm_ucell_t *ucellp; ! BOOL bExpired=FALSE; ! ! /* ! * For every vcp, get the user and check his tokens ! */ ! lock_ObtainWrite(&smb_rctLock); ! for(vcp=smb_allVCsp; vcp; vcp=vcp->nextp) { ! for(usersp=vcp->usersp; usersp; usersp=usersp->nextp) { ! if (usersp->unp) { ! if ((userp=usersp->unp->userp)==0) ! continue; ! } else ! continue; ! lock_ObtainMutex(&userp->mx); ! for(ucellp=userp->cellInfop; ucellp; ucellp=ucellp->nextp) { ! if(ucellp->flags & CM_UCELLFLAG_RXKAD) { ! if(ucellp->expirationTime < now) { ! /* this guy's tokens have expired */ ! osi_Log3(afsd_logp, "cm_CheckTokens: Tokens for user:%s have expired expiration time:0x%x ucellp:%x", ucellp->userName, ucellp->expirationTime, ucellp); ! if (ucellp->ticketp) { ! free(ucellp->ticketp); ! ucellp->ticketp = NULL; ! } ! ucellp->flags &= ~CM_UCELLFLAG_RXKAD; ! ucellp->gen++; ! bExpired=TRUE; ! } ! } ! } ! lock_ReleaseMutex(&userp->mx); ! if(bExpired) { ! bExpired=FALSE; ! cm_ResetACLCache(userp); ! } ! } ! } ! lock_ReleaseWrite(&smb_rctLock); } --- 145,191 ---- */ void cm_CheckTokenCache(long now) { ! extern smb_vc_t *smb_allVCsp; /* global vcp list */ ! smb_vc_t *vcp; ! smb_user_t *usersp; ! cm_user_t *userp = NULL; ! cm_ucell_t *ucellp; ! BOOL bExpired=FALSE; ! ! /* ! * For every vcp, get the user and check his tokens ! */ ! lock_ObtainWrite(&smb_rctLock); ! for (vcp=smb_allVCsp; vcp; vcp=vcp->nextp) { ! for (usersp=vcp->usersp; usersp; usersp=usersp->nextp) { ! if (usersp->unp) { ! if ((userp=usersp->unp->userp)==0) ! continue; ! } else ! continue; ! lock_ObtainMutex(&userp->mx); ! for (ucellp=userp->cellInfop; ucellp; ucellp=ucellp->nextp) { ! if (ucellp->flags & CM_UCELLFLAG_RXKAD) { ! if (ucellp->expirationTime < now) { ! /* this guy's tokens have expired */ ! osi_Log3(afsd_logp, "cm_CheckTokens: Tokens for user:%s have expired expiration time:0x%x ucellp:%x", ! ucellp->userName, ucellp->expirationTime, ucellp); ! if (ucellp->ticketp) { ! free(ucellp->ticketp); ! ucellp->ticketp = NULL; ! } ! ucellp->flags &= ~CM_UCELLFLAG_RXKAD; ! ucellp->gen++; ! bExpired=TRUE; ! } ! } ! } ! lock_ReleaseMutex(&userp->mx); ! if (bExpired) { ! bExpired=FALSE; ! cm_ResetACLCache(userp); ! } ! } ! } ! lock_ReleaseWrite(&smb_rctLock); } Index: openafs/src/WINNT/afsd/cm_user.h diff -c openafs/src/WINNT/afsd/cm_user.h:1.2.20.1 openafs/src/WINNT/afsd/cm_user.h:1.2.20.2 *** openafs/src/WINNT/afsd/cm_user.h:1.2.20.1 Mon Oct 18 00:09:26 2004 --- openafs/src/WINNT/afsd/cm_user.h Tue Dec 7 00:58:20 2004 *************** *** 21,49 **** * corresponding userp's userp->mx mutex. */ typedef struct cm_ucell { ! struct cm_ucell *nextp; /* next cell in the list */ ! struct cm_cell *cellp; /* the cell this applies to */ ! char *ticketp; /* locked by mx */ ! int ticketLen; /* by mx */ ! struct ktc_encryptionKey sessionKey; /* by mx */ ! long kvno; /* key version in ticket */ ! long expirationTime; /* when tix expire */ ! int gen; /* generation number */ ! int iterator; /* for use as ListTokens cookie */ ! long flags; /* flags */ ! char userName[MAXKTCNAMELEN]; /* user name */ } cm_ucell_t; #define CM_UCELLFLAG_HASTIX 1 /* has Kerberos tickets */ #define CM_UCELLFLAG_RXKAD 2 /* an rxkad connection */ #define CM_UCELLFLAG_BADTIX 4 /* tickets are bad or expired */ typedef struct cm_user { ! unsigned long refCount; /* ref count */ ! cm_ucell_t *cellInfop; /* list of cell info */ ! osi_mutex_t mx; /* mutex */ ! int vcRefs; /* count of references from virtual circuits */ ! long flags; } cm_user_t; #define CM_USERFLAG_DELETE 1 /* delete on last reference */ --- 21,50 ---- * corresponding userp's userp->mx mutex. */ typedef struct cm_ucell { ! struct cm_ucell *nextp; /* next cell in the list */ ! struct cm_cell *cellp; /* the cell this applies to */ ! char *ticketp; /* locked by mx */ ! int ticketLen; /* by mx */ ! struct ktc_encryptionKey sessionKey;/* by mx */ ! long kvno; /* key version in ticket */ ! long expirationTime; /* when tix expire */ ! int gen; /* generation number */ ! int iterator; /* for use as ListTokens cookie */ ! long flags; /* flags */ ! char userName[MAXKTCNAMELEN]; /* user name */ } cm_ucell_t; #define CM_UCELLFLAG_HASTIX 1 /* has Kerberos tickets */ #define CM_UCELLFLAG_RXKAD 2 /* an rxkad connection */ #define CM_UCELLFLAG_BADTIX 4 /* tickets are bad or expired */ + #define CM_UCELLFLAG_RXGK 8 /* an rxgk connection */ typedef struct cm_user { ! unsigned long refCount; /* ref count - cm_userLock */ ! cm_ucell_t *cellInfop; /* list of cell info */ ! osi_mutex_t mx; /* mutex */ ! int vcRefs; /* count of references from virtual circuits */ ! long flags; } cm_user_t; #define CM_USERFLAG_DELETE 1 /* delete on last reference */ Index: openafs/src/WINNT/afsd/cm_vnodeops.c diff -c openafs/src/WINNT/afsd/cm_vnodeops.c:1.19.2.5 openafs/src/WINNT/afsd/cm_vnodeops.c:1.19.2.7 *** openafs/src/WINNT/afsd/cm_vnodeops.c:1.19.2.5 Fri Nov 5 14:21:44 2004 --- openafs/src/WINNT/afsd/cm_vnodeops.c Tue Dec 7 01:16:22 2004 *************** *** 552,561 **** lock_ObtainRead(&scp->bufCreateLock); code = buf_Get(scp, &thyper, &bufferp); lock_ReleaseRead(&scp->bufCreateLock); lock_ObtainMutex(&bufferp->mx); - if (code) - break; bufferOffset = thyper; /* now get the data in the cache */ --- 552,564 ---- lock_ObtainRead(&scp->bufCreateLock); code = buf_Get(scp, &thyper, &bufferp); lock_ReleaseRead(&scp->bufCreateLock); + if (code) { + /* if buf_Get() fails we do not have a buffer object to lock */ + bufferp = NULL; + break; + } lock_ObtainMutex(&bufferp->mx); bufferOffset = thyper; /* now get the data in the cache */ *************** *** 1004,1013 **** return CM_ERROR_NOSUCHFILE; } else { /* nonexistent dir on freelance root, so add it */ osi_Log1(afsd_logp,"cm_Lookup adding mount for non-existent directory: %s", osi_LogSaveString(afsd_logp,namep)); ! code = cm_FreelanceAddMount(namep, namep, "root.cell.", namep[0] == '.', &rock.fid); ! if (code < 0) { /* add mount point failed, so give up */ if (flags & CM_FLAG_CHECKPATH) return CM_ERROR_NOSUCHPATH; else --- 1007,1034 ---- return CM_ERROR_NOSUCHFILE; } else { /* nonexistent dir on freelance root, so add it */ + char fullname[200] = "."; + int found = 0; + osi_Log1(afsd_logp,"cm_Lookup adding mount for non-existent directory: %s", osi_LogSaveString(afsd_logp,namep)); ! if (namep[0] == '.') { ! if (cm_GetCell_Gen(&namep[1], &fullname[1], CM_FLAG_CREATE)) { ! found = 1; ! if ( stricmp(&namep[1], &fullname[1]) ) ! code = cm_FreelanceAddSymlink(namep, fullname, &rock.fid); ! else ! code = cm_FreelanceAddMount(namep, &fullname[1], "root.cell.", 1, &rock.fid); ! } ! } else { ! if (cm_GetCell_Gen(namep, fullname, CM_FLAG_CREATE)) ! found = 1; ! if ( stricmp(namep, fullname) ) ! code = cm_FreelanceAddSymlink(namep, fullname, &rock.fid); ! else ! code = cm_FreelanceAddMount(namep, fullname, "root.cell.", 0, &rock.fid); ! } ! if (!found || code < 0) { /* add mount point failed, so give up */ if (flags & CM_FLAG_CHECKPATH) return CM_ERROR_NOSUCHPATH; else Index: openafs/src/WINNT/afsd/cm_volume.c diff -c openafs/src/WINNT/afsd/cm_volume.c:1.8.2.1 openafs/src/WINNT/afsd/cm_volume.c:1.8.2.2 *** openafs/src/WINNT/afsd/cm_volume.c:1.8.2.1 Tue Aug 17 00:28:39 2004 --- openafs/src/WINNT/afsd/cm_volume.c Tue Dec 7 00:53:57 2004 *************** *** 39,161 **** /* * Update a volume. Caller holds volume's lock (volp->mx). */ long cm_UpdateVolume(struct cm_cell *cellp, cm_user_t *userp, cm_req_t *reqp, cm_volume_t *volp) { cm_conn_t *connp; int i; ! cm_serverRef_t *tsrp; cm_server_t *tsp; struct sockaddr_in tsockAddr; long tflags; u_long tempAddr; ! struct vldbentry vldbEntry; /* don't use NVLDB yet; they're not common */ ! int ROcount = 0; ! long code; ! /* clear out old bindings */ cm_FreeServerList(&volp->rwServersp); cm_FreeServerList(&volp->roServersp); cm_FreeServerList(&volp->bkServersp); /* now we have volume structure locked and held; make RPC to fill it */ do { ! code = cm_ConnByMServers(cellp->vlServersp, userp, reqp, ! &connp); ! if (code) continue; ! osi_Log1(afsd_logp, "CALL VL_GetEntryByNameO name %s", ! volp->namep); ! code = VL_GetEntryByNameO(connp->callp, volp->namep, &vldbEntry); ! } while (cm_Analyze(connp, userp, reqp, NULL, NULL, cellp->vlServersp, NULL, code)); code = cm_MapVLRPCError(code, reqp); if (code == 0) { ! /* decode the response */ ! lock_ObtainWrite(&cm_volumeLock); ! if (vldbEntry.flags & VLF_RWEXISTS) ! volp->rwID = vldbEntry.volumeId[0]; ! else volp->rwID = 0; ! if (vldbEntry.flags & VLF_ROEXISTS) ! volp->roID = vldbEntry.volumeId[1]; else volp->roID = 0; ! if (vldbEntry.flags & VLF_BACKEXISTS) ! volp->bkID = vldbEntry.volumeId[2]; ! else volp->bkID = 0; ! lock_ReleaseWrite(&cm_volumeLock); ! for(i=0; icellp ) ! tsp->cellp = cellp; osi_assert(tsp != NULL); /* and add it to the list(s). */ ! /* * Each call to cm_NewServerRef() increments the * ref count of tsp. These reference will be dropped, ! * if and when the volume is reset; see reset code ! * earlier in this function. ! */ ! if ((tflags & VLSF_RWVOL) ! && (vldbEntry.flags & VLF_RWEXISTS)) { ! tsrp = cm_NewServerRef(tsp); cm_InsertServerList(&volp->rwServersp, tsrp); lock_ObtainWrite(&cm_serverLock); tsrp->refCount--; /* drop allocation reference */ lock_ReleaseWrite(&cm_serverLock); ! } ! if ((tflags & VLSF_ROVOL) ! && (vldbEntry.flags & VLF_ROEXISTS)) { ! tsrp = cm_NewServerRef(tsp); ! cm_InsertServerList(&volp->roServersp, tsrp); lock_ObtainWrite(&cm_serverLock); tsrp->refCount--; /* drop allocation reference */ lock_ReleaseWrite(&cm_serverLock); ! ROcount++; } ! /* We don't use VLSF_BACKVOL !?! */ ! if ((tflags & VLSF_RWVOL) ! && (vldbEntry.flags & VLF_BACKEXISTS)) { ! tsrp = cm_NewServerRef(tsp); cm_InsertServerList(&volp->bkServersp, tsrp); lock_ObtainWrite(&cm_serverLock); tsrp->refCount--; /* drop allocation reference */ lock_ReleaseWrite(&cm_serverLock); ! } ! /* Drop the reference obtained by cm_FindServer() */ ! cm_PutServer(tsp); } ! ! /* ! * Randomize RO list ! * ! * If the first n servers have the same ipRank, then we ! * randomly pick one among them and move it to the beginning. ! * We don't bother to re-order the whole list because ! * the rest of the list is used only if the first server is ! * down. We only do this for the RO list; we assume the other ! * lists are length 1. ! */ ! if (ROcount > 1) { ! cm_RandomizeServer(&volp->roServersp); ! } ! } ! return code; } long cm_GetVolumeByID(cm_cell_t *cellp, long volumeID, cm_user_t *userp, --- 39,250 ---- /* * Update a volume. Caller holds volume's lock (volp->mx). + * + * + * shadow / openafs / jhutz@CS.CMU.EDU {ANDREW.CMU.EDU} 01:38 (JHutz) + * Yes, we support multihomed fileservers. + * Since before we got the code from IBM. + * But to find out about multiple addresses on a multihomed server, you need + * to use VL_GetEntryByNameU and VL_GetAddrsU. If you use + * VL_GetEntryByNameO or VL_GetEntryByNameN, the vlserver just gives you one + * address per server. + * shadow / openafs / jhutz@CS.CMU.EDU {ANDREW.CMU.EDU} 01:39 (JHutz) + * see src/afs/afs_volume.c, paying particular attention to + * afs_NewVolumeByName, afs_SetupVolume, and InstallUVolumeEntry + * shadow / openafs / jaltman {ANDREW.CMU.EDU} 01:40 (Jeffrey Altman) + * thanks. The windows client calls the 0 versions. + * shadow / openafs / jhutz@CS.CMU.EDU {ANDREW.CMU.EDU} 01:51 (JHutz) + * Oh. Ew. + * By not using the N versions, you only get up to 8 sites instead of 13. + * By not using the U versions, you don't get to know about multihomed serve + * shadow / openafs / jhutz@CS.CMU.EDU {ANDREW.CMU.EDU} 01:52 (JHutz) + * Of course, you probably want to support the older versions for backward + * compatibility. If you do that, you need to call the newest interface + * first, and fall back to successively older versions if you get + * RXGEN_OPCODE. */ long cm_UpdateVolume(struct cm_cell *cellp, cm_user_t *userp, cm_req_t *reqp, cm_volume_t *volp) { cm_conn_t *connp; int i; ! cm_serverRef_t *tsrp; cm_server_t *tsp; struct sockaddr_in tsockAddr; long tflags; u_long tempAddr; ! struct vldbentry vldbEntry; ! struct nvldbentry nvldbEntry; ! #ifdef MULTIHOMED ! struct uvldbentry uvldbEntry; ! #endif ! int type = -1; ! int ROcount = 0; ! long code; ! /* clear out old bindings */ cm_FreeServerList(&volp->rwServersp); cm_FreeServerList(&volp->roServersp); cm_FreeServerList(&volp->bkServersp); /* now we have volume structure locked and held; make RPC to fill it */ do { ! code = cm_ConnByMServers(cellp->vlServersp, userp, reqp, &connp); ! if (code) ! continue; ! osi_Log1(afsd_logp, "CALL VL_GetEntryByName{UNO} name %s", volp->namep); ! #ifdef MULTIHOMED ! code = VL_GetEntryByNameU(connp->callp, volp->namep, &uvldbEntry); ! if ( code == RXGEN_OPCODE ) ! #endif ! { ! code = VL_GetEntryByNameN(connp->callp, volp->namep, &nvldbEntry); ! type = 1; ! } ! if ( code == RXGEN_OPCODE ) { ! code = VL_GetEntryByNameO(connp->callp, volp->namep, &vldbEntry); ! type = 0; ! } ! } while (cm_Analyze(connp, userp, reqp, NULL, NULL, cellp->vlServersp, NULL, code)); code = cm_MapVLRPCError(code, reqp); if (code == 0) { ! afs_int32 flags; ! afs_int32 nServers; ! afs_int32 rwID; ! afs_int32 roID; ! afs_int32 bkID; ! afs_int32 serverNumber[NMAXNSERVERS]; ! afs_int32 serverFlags[NMAXNSERVERS]; ! ! switch ( type ) { ! case 0: ! flags = vldbEntry.flags; ! nServers = vldbEntry.nServers; ! rwID = vldbEntry.volumeId[0]; ! roID = vldbEntry.volumeId[1]; ! bkID = vldbEntry.volumeId[2]; ! for ( i=0; irwID = rwID; ! else volp->rwID = 0; ! if (flags & VLF_ROEXISTS) ! volp->roID = roID; else volp->roID = 0; ! if (flags & VLF_BACKEXISTS) ! volp->bkID = bkID; ! else volp->bkID = 0; ! lock_ReleaseWrite(&cm_volumeLock); ! for (i=0; icellp ) ! tsp->cellp = cellp; osi_assert(tsp != NULL); /* and add it to the list(s). */ ! /* * Each call to cm_NewServerRef() increments the * ref count of tsp. These reference will be dropped, ! * if and when the volume is reset; see reset code ! * earlier in this function. ! */ ! if ((tflags & VLSF_RWVOL) && (flags & VLF_RWEXISTS)) { ! tsrp = cm_NewServerRef(tsp); cm_InsertServerList(&volp->rwServersp, tsrp); lock_ObtainWrite(&cm_serverLock); tsrp->refCount--; /* drop allocation reference */ lock_ReleaseWrite(&cm_serverLock); ! } ! if ((tflags & VLSF_ROVOL) && (flags & VLF_ROEXISTS)) { ! tsrp = cm_NewServerRef(tsp); ! cm_InsertServerList(&volp->roServersp, tsrp); lock_ObtainWrite(&cm_serverLock); tsrp->refCount--; /* drop allocation reference */ lock_ReleaseWrite(&cm_serverLock); ! ROcount++; } ! /* We don't use VLSF_BACKVOL !?! */ ! if ((tflags & VLSF_RWVOL) && (flags & VLF_BACKEXISTS)) { ! tsrp = cm_NewServerRef(tsp); cm_InsertServerList(&volp->bkServersp, tsrp); lock_ObtainWrite(&cm_serverLock); tsrp->refCount--; /* drop allocation reference */ lock_ReleaseWrite(&cm_serverLock); ! } ! /* Drop the reference obtained by cm_FindServer() */ ! cm_PutServer(tsp); ! } ! ! /* ! * Randomize RO list ! * ! * If the first n servers have the same ipRank, then we ! * randomly pick one among them and move it to the beginning. ! * We don't bother to re-order the whole list because ! * the rest of the list is used only if the first server is ! * down. We only do this for the RO list; we assume the other ! * lists are length 1. ! */ ! if (ROcount > 1) { ! cm_RandomizeServer(&volp->roServersp); } ! } ! return code; } long cm_GetVolumeByID(cm_cell_t *cellp, long volumeID, cm_user_t *userp, Index: openafs/src/WINNT/afsd/smb.c diff -c openafs/src/WINNT/afsd/smb.c:1.55.2.4 openafs/src/WINNT/afsd/smb.c:1.55.2.9 *** openafs/src/WINNT/afsd/smb.c:1.55.2.4 Fri Nov 5 14:21:45 2004 --- openafs/src/WINNT/afsd/smb.c Tue Dec 7 07:49:31 2004 *************** *** 51,56 **** --- 51,58 ---- int smb_LogoffTokenTransfer; time_t smb_LogoffTransferTimeout; + int smb_StoreAnsiFilenames = 0; + DWORD last_msg_time = 0; long ongoingOps = 0; *************** *** 95,100 **** --- 97,103 ---- #define NCBmax MAXIMUM_WAIT_OBJECTS EVENT_HANDLE NCBavails[NCBmax], NCBevents[NCBmax]; EVENT_HANDLE **NCBreturns; + EVENT_HANDLE *smb_ServerShutdown; DWORD NCBsessions[NCBmax]; NCB *NCBs[NCBmax]; struct smb_packet *bufs[NCBmax]; *************** *** 157,163 **** * Time in Unix format of midnight, 1/1/1970 local time. * When added to dosUTime, gives Unix (AFS) time. */ ! long smb_localZero = 0; /* Time difference for converting to kludge-GMT */ int smb_NowTZ; --- 160,166 ---- * Time in Unix format of midnight, 1/1/1970 local time. * When added to dosUTime, gives Unix (AFS) time. */ ! time_t smb_localZero = 0; /* Time difference for converting to kludge-GMT */ int smb_NowTZ; *************** *** 362,367 **** --- 365,374 ---- return "S(0d)_ReceiveTran2CreateDirectory"; case 14: return "S(0e)_ReceiveTran2SessionSetup"; + case 16: + return "S(10)_ReceiveTran2GetDfsReferral"; + case 17: + return "S(11)_ReceiveTran2ReportDfsInconsistency"; } } *************** *** 392,405 **** { attrs = SMB_ATTR_DIRECTORY; #ifdef SPECIAL_FOLDERS ! #ifdef AFS_FREELANCE_CLIENT ! if ( cm_freelanceEnabled && ! scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && ! scp->fid.volume==AFS_FAKE_ROOT_VOL_ID && ! scp->fid.vnode==0x1 && scp->fid.unique==0x1) { ! attrs |= SMB_ATTR_SYSTEM; /* FILE_ATTRIBUTE_SYSTEM */ ! } ! #endif /* AFS_FREELANCE_CLIENT */ #endif /* SPECIAL_FOLDERS */ } else attrs = 0; --- 399,405 ---- { attrs = SMB_ATTR_DIRECTORY; #ifdef SPECIAL_FOLDERS ! attrs |= SMB_ATTR_SYSTEM; /* FILE_ATTRIBUTE_SYSTEM */ #endif /* SPECIAL_FOLDERS */ } else attrs = 0; *************** *** 713,719 **** } #endif /* !DJGPP */ ! void smb_SearchTimeFromUnixTime(long *dosTimep, time_t unixTime) { struct tm *ltp; int dosDate; --- 713,719 ---- } #endif /* !DJGPP */ ! void smb_SearchTimeFromUnixTime(time_t *dosTimep, time_t unixTime) { struct tm *ltp; int dosDate; *************** *** 745,752 **** unsigned short dosTime; struct tm localTm; ! dosDate = searchTime & 0xffff; ! dosTime = (searchTime >> 16) & 0xffff; localTm.tm_year = 80 + ((dosDate>>9) & 0x3f); localTm.tm_mon = ((dosDate >> 5) & 0xf) - 1; /* January is 0 in localTm */ --- 745,752 ---- unsigned