From f31658317a77346759f165ff13b5dcf77a8b3683 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Wed, 8 Sep 2004 06:52:20 +0000 Subject: [PATCH] windows-misc-20040907 * modify registry.txt to replace QWORD with DWORD ==================== This delta was composed from multiple commits as part of the CVS->Git migration. The checkin message with each commit was inconsistent. The following are the additional commit messages. ==================== * add expanded registry support to "submounts" --- doc/txt/winnotes/registry.txt | 8 +- src/WINNT/afsd/afsd_init.c | 2 +- src/WINNT/afsd/afsshare.c | 2 +- src/WINNT/afsd/cm_ioctl.c | 206 ++++++++++++++++++----------------- src/WINNT/client_config/drivemap.cpp | 53 ++++++++- src/WINNT/client_creds/ipaddrchg.c | 25 +++-- 6 files changed, 173 insertions(+), 123 deletions(-) diff --git a/doc/txt/winnotes/registry.txt b/doc/txt/winnotes/registry.txt index 3d82b2f..25a0800 100644 --- a/doc/txt/winnotes/registry.txt +++ b/doc/txt/winnotes/registry.txt @@ -28,7 +28,7 @@ Variable: LANadapter name will be 'AFS'. Value : CacheSize -Type : QWORD +Type : DWORD Default : 20480 (CM_CONFIGDEFAULT_CACHESIZE) Variable: cm_initParams.cacheSize @@ -58,7 +58,7 @@ Variable: numSvThreads smb_Server in smb.c). Value : Stats -Type : QWORD +Type : DWORD Default : 1000 (CM_CONFIGDEFAULT_STATS) Variable: cm_initParams.nStatCaches @@ -76,7 +76,7 @@ Variable: smb_LogoffTokenTransfer that the tokens remain valid until the profile save is complete. Value : LogoffTokenTransferTimeout -Type : QWORD +Type : DWORD Default : 10 Variable: smb_LogoffTokenTransferTimeout @@ -165,7 +165,7 @@ Variable: reportSessionStartups or various error types to be logged. Value : TraceBufferSize -Type : QWORD +Type : DWORD Default : 5000 (CM_CONFIGDEFAULT_TRACEBUFSIZE) Variable: traceBufSize diff --git a/src/WINNT/afsd/afsd_init.c b/src/WINNT/afsd/afsd_init.c index faf11da..d654aeb 100644 --- a/src/WINNT/afsd/afsd_init.c +++ b/src/WINNT/afsd/afsd_init.c @@ -590,7 +590,7 @@ int afsd_InitCM(char **reasonP) code = RegQueryValueEx(parmKey, "CachePath", NULL, ®Type, buf, &dummyLen); if (code == ERROR_SUCCESS && buf[0]) { - if(regType == REG_EXPAND_SZ) { + if (regType == REG_EXPAND_SZ) { dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath)); if(dummyLen > sizeof(cm_CachePath)) { afsi_log("Cache path [%s] longer than %d after expanding env strings", buf, sizeof(cm_CachePath)); diff --git a/src/WINNT/afsd/afsshare.c b/src/WINNT/afsd/afsshare.c index eb0f83a..6ef60a0 100644 --- a/src/WINNT/afsd/afsshare.c +++ b/src/WINNT/afsd/afsshare.c @@ -65,7 +65,7 @@ main(int argc, char **argv) { else mountstring = argv[2]; - if (RegSetValueEx(hkSubmounts, argv[1], 0, REG_SZ, mountstring, strlen(mountstring)+1)) { + if (RegSetValueEx(hkSubmounts, argv[1], 0, REG_EXPAND_SZ, mountstring, strlen(mountstring)+1)) { fprintf(stderr,"Submount Set failure for [%s]: %lX", argv[1], GetLastError()); RegCloseKey(hkSubmounts); diff --git a/src/WINNT/afsd/cm_ioctl.c b/src/WINNT/afsd/cm_ioctl.c index 1698618..5622645 100644 --- a/src/WINNT/afsd/cm_ioctl.c +++ b/src/WINNT/afsd/cm_ioctl.c @@ -39,6 +39,7 @@ #endif #include "cm_rpc.h" +#include #ifdef _DEBUG #include @@ -1991,32 +1992,32 @@ long cm_IoctlDelAllToken(struct smb_ioctl *ioctlp, struct cm_user *userp) long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp) { - char afspath[MAX_PATH]; - char *submountreqp; - int nextAutoSubmount; + char afspath[MAX_PATH]; + char *submountreqp; + int nextAutoSubmount; HKEY hkSubmounts; DWORD dwType, dwSize; DWORD status; DWORD dwIndex; DWORD dwSubmounts; - cm_SkipIoctlPath(ioctlp); + cm_SkipIoctlPath(ioctlp); - /* Serialize this one, to prevent simultaneous mods - * to afsdsbmt.ini - */ - lock_ObtainMutex(&cm_Afsdsbmt_Lock); + /* Serialize this one, to prevent simultaneous mods + * to afsdsbmt.ini + */ + lock_ObtainMutex(&cm_Afsdsbmt_Lock); - /* 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); + /* 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 - * that submount name is in use... if so, the submount's path - * has to match our path. - */ + /* If the caller supplied a suggested submount name, see if + * that submount name is in use... if so, the submount's path + * has to match our path. + */ RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\OpenAFS\\Client\\Submounts", @@ -2029,22 +2030,22 @@ long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp) NULL ); if (submountreqp && *submountreqp) { - char submountPathNormalized[MAX_PATH]; - char submountPath[MAX_PATH]; + char submountPathNormalized[MAX_PATH]; + char submountPath[MAX_PATH]; dwSize = sizeof(submountPath); status = RegQueryValueEx( hkSubmounts, submountreqp, 0, - &dwType, submountPath, &dwSize); + &dwType, submountPath, &dwSize); - if (status != ERROR_SUCCESS) { + if (status != ERROR_SUCCESS) { - /* The suggested submount name isn't in use now-- - * so we can safely map the requested submount name - * to the supplied path. Remember not to write the - * leading "/afs" when writing out the submount. - */ + /* The suggested submount name isn't in use now-- + * so we can safely map the requested submount name + * to the supplied path. Remember not to write the + * leading "/afs" when writing out the submount. + */ RegSetValueEx( hkSubmounts, submountreqp, 0, - REG_SZ, + REG_EXPAND_SZ, (strlen(&afspath[strlen(cm_mountRoot)])) ? &afspath[strlen(cm_mountRoot)]:"/", (strlen(&afspath[strlen(cm_mountRoot)])) ? @@ -2055,106 +2056,113 @@ long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp) ioctlp->outDatap += strlen(ioctlp->outDatap) +1; lock_ReleaseMutex(&cm_Afsdsbmt_Lock); return 0; - } + } - /* The suggested submount name is already in use--if the - * 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; + /* The suggested submount name is already in use--if the + * 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); + lock_ReleaseMutex(&cm_Afsdsbmt_Lock); return 0; - } - } + } + } RegQueryInfoKey( hkSubmounts, - NULL, /* lpClass */ - NULL, /* lpcClass */ - NULL, /* lpReserved */ - NULL, /* lpcSubKeys */ - NULL, /* lpcMaxSubKeyLen */ - NULL, /* lpcMaxClassLen */ - &dwSubmounts, /* lpcValues */ - NULL, /* lpcMaxValueNameLen */ - NULL, /* lpcMaxValueLen */ - NULL, /* lpcbSecurityDescriptor */ - NULL /* lpftLastWriteTime */ - ); - - - /* Having obtained a list of all available submounts, start - * searching that list for a path which matches the requested - * AFS path. We'll also keep track of the highest "auto15"/"auto47" - * submount, in case we need to add a new one later. - */ + NULL, /* lpClass */ + NULL, /* lpcClass */ + NULL, /* lpReserved */ + NULL, /* lpcSubKeys */ + NULL, /* lpcMaxSubKeyLen */ + NULL, /* lpcMaxClassLen */ + &dwSubmounts, /* lpcValues */ + NULL, /* lpcMaxValueNameLen */ + NULL, /* lpcMaxValueLen */ + NULL, /* lpcbSecurityDescriptor */ + NULL /* lpftLastWriteTime */ + ); + + + /* Having obtained a list of all available submounts, start + * searching that list for a path which matches the requested + * AFS path. We'll also keep track of the highest "auto15"/"auto47" + * submount, in case we need to add a new one later. + */ - nextAutoSubmount = 1; + nextAutoSubmount = 1; for ( dwIndex = 0; dwIndex < dwSubmounts; dwIndex ++ ) { - char submountPathNormalized[MAX_PATH]; - char submountPath[MAX_PATH] = ""; - DWORD submountPathLen = sizeof(submountPath); - char submountName[256]; + char submountPathNormalized[MAX_PATH]; + char submountPath[MAX_PATH] = ""; + DWORD submountPathLen = sizeof(submountPath); + char submountName[MAX_PATH]; DWORD submountNameLen = sizeof(submountName); + dwType = 0; RegEnumValue( hkSubmounts, dwIndex, submountName, &submountNameLen, NULL, - &dwType, submountPath, &submountPathLen); - - /* If this is an Auto### submount, remember its ### value */ - - if ((!strnicmp (submountName, "auto", 4)) && - (isdigit (submountName[strlen("auto")]))) { - int thisAutoSubmount; - thisAutoSubmount = atoi (&submountName[strlen("auto")]); - nextAutoSubmount = max (nextAutoSubmount, - thisAutoSubmount+1); - } + &dwType, submountPath, &submountPathLen); + if (dwType == REG_EXPAND_SZ) { + char buf[MAX_PATH]; + StringCbCopyA(buf, MAX_PATH, submountPath); + submountPathLen = ExpandEnvironmentStrings(buf, submountPath, MAX_PATH); + if (submountPathLen > MAX_PATH) + continue; + } - if ((submountPathLen == 0) || - (submountPathLen == sizeof(submountPath) - 1)) { - continue; - } + /* If this is an Auto### submount, remember its ### value */ + if ((!strnicmp (submountName, "auto", 4)) && + (isdigit (submountName[strlen("auto")]))) { + int thisAutoSubmount; + thisAutoSubmount = atoi (&submountName[strlen("auto")]); + nextAutoSubmount = max (nextAutoSubmount, + thisAutoSubmount+1); + } + + if ((submountPathLen == 0) || + (submountPathLen == sizeof(submountPath) - 1)) { + continue; + } - /* See if the path for this submount matches the path - * 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; + /* See if the path for this submount matches the path + * 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); + lock_ReleaseMutex(&cm_Afsdsbmt_Lock); return 0; - } - } + } + } - /* We've been through the entire list of existing submounts, and - * didn't find any which matched the specified path. So, we'll - * just have to add one. Remember not to write the leading "/afs" - * when writing out the submount. - */ + /* We've been through the entire list of existing submounts, and + * didn't find any which matched the specified path. So, we'll + * just have to add one. Remember not to write the leading "/afs" + * when writing out the submount. + */ - sprintf(ioctlp->outDatap, "auto%ld", nextAutoSubmount); + sprintf(ioctlp->outDatap, "auto%ld", nextAutoSubmount); RegSetValueEx( hkSubmounts, ioctlp->outDatap, 0, - REG_SZ, + REG_EXPAND_SZ, (strlen(&afspath[strlen(cm_mountRoot)])) ? &afspath[strlen(cm_mountRoot)]:"/", (strlen(&afspath[strlen(cm_mountRoot)])) ? strlen(&afspath[strlen(cm_mountRoot)])+1:2); - ioctlp->outDatap += strlen(ioctlp->outDatap) +1; + ioctlp->outDatap += strlen(ioctlp->outDatap) +1; RegCloseKey(hkSubmounts); - lock_ReleaseMutex(&cm_Afsdsbmt_Lock); - return 0; + lock_ReleaseMutex(&cm_Afsdsbmt_Lock); + return 0; } long cm_IoctlGetRxkcrypt(smb_ioctl_t *ioctlp, cm_user_t *userp) diff --git a/src/WINNT/client_config/drivemap.cpp b/src/WINNT/client_config/drivemap.cpp index 2681847..9716c4a 100644 --- a/src/WINNT/client_config/drivemap.cpp +++ b/src/WINNT/client_config/drivemap.cpp @@ -26,6 +26,7 @@ extern "C" { #endif #include #include +#include extern void Config_GetLanAdapter (ULONG *pnLanAdapter); @@ -76,6 +77,28 @@ WriteRegistryString(HKEY key, TCHAR * subkey, LPTSTR lhs, LPTSTR rhs) } static BOOL +WriteExpandedRegistryString(HKEY key, TCHAR * subkey, LPTSTR lhs, LPTSTR rhs) +{ + HKEY hkSub = NULL; + RegCreateKeyEx( key, + subkey, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_WRITE, + NULL, + &hkSub, + NULL); + + DWORD status = RegSetValueEx( hkSub, lhs, 0, REG_EXPAND_SZ, (const BYTE *)rhs, strlen(rhs)+1 ); + + if ( hkSub ) + RegCloseKey( hkSub ); + + return (status == ERROR_SUCCESS); +} + +static BOOL ReadRegistryString(HKEY key, TCHAR * subkey, LPTSTR lhs, LPTSTR rhs, DWORD * size) { HKEY hkSub = NULL; @@ -89,8 +112,19 @@ ReadRegistryString(HKEY key, TCHAR * subkey, LPTSTR lhs, LPTSTR rhs, DWORD * siz &hkSub, NULL); - DWORD dwType; - DWORD status = RegQueryValueEx( hkSub, lhs, 0, &dwType, (LPBYTE)rhs, size ); + DWORD dwType = 0; + DWORD localSize = *size; + + DWORD status = RegQueryValueEx( hkSub, lhs, 0, &dwType, (LPBYTE)rhs, &localSize); + if (status == 0 && dwType == REG_EXPAND_SZ) { + TCHAR * buf = (TCHAR *)malloc((*size) * sizeof(TCHAR)); + memcpy(buf, rhs, (*size) * sizeof(TCHAR)); + localSize = ExpandEnvironmentStrings(buf, rhs, *size); + free(buf); + if ( localSize > *size ) + status = !ERROR_SUCCESS; + } + *size = localSize; if ( hkSub ) RegCloseKey( hkSub ); @@ -112,7 +146,6 @@ DeleteRegistryString(HKEY key, TCHAR * subkey, LPTSTR lhs) &hkSub, NULL); - DWORD dwType; DWORD status = RegDeleteValue( hkSub, lhs ); if ( hkSub ) @@ -385,7 +418,7 @@ void QueryDriveMapList_ReadSubmounts (PDRIVEMAPLIST pList) HKEY hkSubmounts; RegCreateKeyEx( HKEY_LOCAL_MACHINE, - "SOFTWARE\\OpenAFS\\Client\\Submounts", + cszSECTION_SUBMOUNTS, 0, "AFS", REG_OPTION_NON_VOLATILE, @@ -414,11 +447,19 @@ void QueryDriveMapList_ReadSubmounts (PDRIVEMAPLIST pList) DWORD submountPathLen = MAX_PATH; TCHAR submountName[MAX_PATH]; DWORD submountNameLen = MAX_PATH; - DWORD dwType; + DWORD dwType = 0; RegEnumValue( hkSubmounts, dwIndex, submountName, &submountNameLen, NULL, &dwType, (LPBYTE)submountPath, &submountPathLen); + if (dwType == REG_EXPAND_SZ) { + char buf[MAX_PATH]; + StringCbCopyA(buf, MAX_PATH, submountPath); + submountPathLen = ExpandEnvironmentStrings(buf, submountPath, MAX_PATH); + if (submountPathLen > MAX_PATH) + continue; + } + SUBMOUNT Submount; memset (&Submount, 0x00, sizeof(SUBMOUNT)); lstrcpy (Submount.szSubmount, submountName); @@ -805,7 +846,7 @@ void AddSubMount (LPTSTR pszSubmount, LPTSTR pszMapping) if (!szRHS[0]) lstrcpy (szRHS, TEXT("/")); - WriteRegistryString(HKEY_LOCAL_MACHINE, cszSECTION_SUBMOUNTS, pszSubmount, szRHS); + WriteExpandedRegistryString(HKEY_LOCAL_MACHINE, cszSECTION_SUBMOUNTS, pszSubmount, szRHS); } diff --git a/src/WINNT/client_creds/ipaddrchg.c b/src/WINNT/client_creds/ipaddrchg.c index 2d640dc..03feba3 100644 --- a/src/WINNT/client_creds/ipaddrchg.c +++ b/src/WINNT/client_creds/ipaddrchg.c @@ -304,13 +304,13 @@ ObtainTokensFromUserIfNeeded(HWND hWnd) strcpy(aserver.name, "afs"); strcpy(aserver.cell, rootcell); + GetLocalTime (&stNow); + SystemTimeToFileTime (&stNow, &ftNow); + llNow = (((LONGLONG)ftNow.dwHighDateTime) << 32) + (LONGLONG)(ftNow.dwLowDateTime); + llNow /= c100ns1SECOND; + rc = ktc_GetToken(&aserver, &atoken, sizeof(atoken), &aclient); if ( rc == 0 ) { - GetLocalTime (&stNow); - SystemTimeToFileTime (&stNow, &ftNow); - llNow = (((LONGLONG)ftNow.dwHighDateTime) << 32) + (LONGLONG)(ftNow.dwLowDateTime); - llNow /= c100ns1SECOND; - TimeToSystemTime (&stExpires, atoken.endTime); SystemTimeToFileTime (&stExpires, &ftExpires); llExpires = (((LONGLONG)ftExpires.dwHighDateTime) << 32) + (LONGLONG)(ftExpires.dwLowDateTime); @@ -371,14 +371,15 @@ ObtainTokensFromUserIfNeeded(HWND hWnd) KFW_AFS_renew_token_for_cell(rootcell); rc = ktc_GetToken(&aserver, &atoken, sizeof(atoken), &aclient); - - TimeToSystemTime (&stExpires, atoken.endTime); - SystemTimeToFileTime (&stExpires, &ftExpires); - llExpires = (((LONGLONG)ftExpires.dwHighDateTime) << 32) + (LONGLONG)(ftExpires.dwLowDateTime); - llExpires /= c100ns1SECOND; + if ( rc == 0 ) { + TimeToSystemTime (&stExpires, atoken.endTime); + SystemTimeToFileTime (&stExpires, &ftExpires); + llExpires = (((LONGLONG)ftExpires.dwHighDateTime) << 32) + (LONGLONG)(ftExpires.dwLowDateTime); + llExpires /= c100ns1SECOND; - if (!rc && (llNow < llExpires)) - goto cleanup; + if (llNow < llExpires) + goto cleanup; + } } SendMessage(hWnd, WM_OBTAIN_TOKENS, FALSE, (long)rootcell); -- 1.9.4