From 5697e58a07e39eba9609685695e1718cbc9794e4 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Wed, 26 Nov 2008 07:15:01 +0000 Subject: [PATCH] windows-pioctl-global-auto-mapper-20081125 LICENSE MIT FIXES 123726 drive letters mapped to \\afs by the global auto mapper do not show up as mapped drives. Add a check for the drive mapping based upon the registry configuration. --- src/sys/pioctl_nt.c | 58 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/src/sys/pioctl_nt.c b/src/sys/pioctl_nt.c index 22125fc06c..0460e26150 100644 --- a/src/sys/pioctl_nt.c +++ b/src/sys/pioctl_nt.c @@ -478,6 +478,32 @@ DriveIsMappedToAFS(char *drivestr, char *NetbiosName) return bIsAFS; } +static BOOL +DriveIsGlobalAutoMapped(char *drivestr) +{ + DWORD dwResult; + HKEY hKey; + DWORD dwSubMountSize; + char szSubMount[260]; + DWORD dwType; + + dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + AFSREG_CLT_SVC_PARAM_SUBKEY "\\GlobalAutoMapper", + 0, KEY_QUERY_VALUE, &hKey); + if (dwResult != ERROR_SUCCESS) + return FALSE; + + dwSubMountSize = sizeof(szSubMount); + dwType = REG_SZ; + dwResult = RegQueryValueEx(hKey, drivestr, 0, &dwType, szSubMount, &dwSubMountSize); + RegCloseKey(hKey); + + if (dwResult == ERROR_SUCCESS && dwType == REG_SZ) + return TRUE; + else + return FALSE; +} + static long GetIoctlHandle(char *fileNamep, HANDLE * handlep) { @@ -497,6 +523,7 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep) DWORD gle; DWORD dwSize = sizeof(szUser); int saveerrno; + UINT driveType; memset(HostName, '\0', sizeof(HostName)); gethostname(HostName, sizeof(HostName)); @@ -511,23 +538,25 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep) if (fileNamep) { drivep = strchr(fileNamep, ':'); if (drivep && (drivep - fileNamep) >= 1) { - UINT driveType; tbuffer[0] = *(drivep - 1); tbuffer[1] = ':'; - tbuffer[2] = '\\'; - tbuffer[3] = '\0'; + tbuffer[2] = '\0'; driveType = GetDriveType(tbuffer); switch (driveType) { case DRIVE_UNKNOWN: case DRIVE_REMOTE: - if (DriveIsMappedToAFS(tbuffer, netbiosName)) + if (DriveIsMappedToAFS(tbuffer, netbiosName) || + DriveIsGlobalAutoMapped(tbuffer)) strcpy(&tbuffer[2], SMB_IOCTL_FILENAME); else return -1; break; default: - return -1; + if (DriveIsGlobalAutoMapped(tbuffer)) + strcpy(&tbuffer[2], SMB_IOCTL_FILENAME); + else + return -1; } } else if (fileNamep[0] == fileNamep[1] && (fileNamep[0] == '\\' || fileNamep[0] == '/')) @@ -552,7 +581,24 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep) if ( curdir[1] == ':' ) { tbuffer[0] = curdir[0]; tbuffer[1] = ':'; - strcpy(tbuffer + 2, SMB_IOCTL_FILENAME); + tbuffer[2] = '\0'; + + driveType = GetDriveType(tbuffer); + switch (driveType) { + case DRIVE_UNKNOWN: + case DRIVE_REMOTE: + if (DriveIsMappedToAFS(tbuffer, netbiosName) || + DriveIsGlobalAutoMapped(tbuffer)) + strcpy(&tbuffer[2], SMB_IOCTL_FILENAME); + else + return -1; + break; + default: + if (DriveIsGlobalAutoMapped(tbuffer)) + strcpy(&tbuffer[2], SMB_IOCTL_FILENAME); + else + return -1; + } } else if (curdir[0] == curdir[1] && (curdir[0] == '\\' || curdir[0] == '/')) {