From 9a0b3da255032f177dfedb650c7a0b65cff24fba Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Mon, 6 Apr 2009 22:47:49 +0000 Subject: [PATCH] windows-pioctl-subst-unc-20090407 LICENSE MIT Add code to support determining if a drive substitution refers to a UNC path. --- src/sys/pioctl_nt.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/sys/pioctl_nt.c b/src/sys/pioctl_nt.c index 4cd31ca..43f5c35 100644 --- a/src/sys/pioctl_nt.c +++ b/src/sys/pioctl_nt.c @@ -402,7 +402,7 @@ GetLSAPrincipalName(char * szUser, DWORD *dwSize) // dos drive letter to which the source is mapped. // static BOOL -DriveSubstitution(char *drivestr, char *subststr) +DriveSubstitution(char *drivestr, char *subststr, size_t substlen) { char device[MAX_PATH]; @@ -418,7 +418,7 @@ DriveSubstitution(char *drivestr, char *subststr) device[0] = device[4]; device[1] = ':'; device[2] = '\0'; - if ( DriveSubstitution(device, subststr) ) + if ( DriveSubstitution(device, subststr, substlen) ) { return TRUE; } else { @@ -427,6 +427,20 @@ DriveSubstitution(char *drivestr, char *subststr) subststr[2] = '\0'; return TRUE; } + } else + if ( device[0] == '\\' && + device[1] == '?' && + device[2] == '?' && + device[3] == '\\' && + device[4] == 'U' && + device[5] == 'N' && + device[6] == 'C' && + device[7] == '\\') + { + subststr[0] = '\\'; + strncpy(&subststr[1], &device[7], substlen-1); + subststr[substlen-1] = '\0'; + return TRUE; } } @@ -446,15 +460,23 @@ DriveIsMappedToAFS(char *drivestr, char *NetbiosName) LPNETRESOURCE lpnrLocal; // pointer to enumerated structures DWORD i; BOOL bIsAFS = FALSE; - char subststr[3]; + char subststr[MAX_PATH]; // // Handle drive letter substitution created with "SUBST ". // If a substitution has occurred, use the target drive letter instead // of the source. // - if ( DriveSubstitution(drivestr, subststr) ) + if ( DriveSubstitution(drivestr, subststr, MAX_PATH) ) { + if (subststr[0] == '\\' && + subststr[1] == '\\') + { + if (_strnicmp( &subststr[2], NetbiosName, strlen(NetbiosName)) == 0) + return TRUE; + else + return FALSE; + } drivestr = subststr; } -- 1.9.4