From 7a46d3a0766a34816c468f5e00b720994778466b Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Wed, 2 Jun 2004 06:21:16 +0000 Subject: [PATCH] unc-enable-fs-20040601 * modify cm_ParseIoctlPath() to be able to handle arbitrary UNC paths of the form \\netbiosname\mount\path. This enables all of the fs commands and the shell extension to be able to work with UNC paths. ==================== 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 support for UNC paths --- src/WINNT/afsd/cm_ioctl.c | 62 +++++++++++++++++++++++++++++---------- src/sys/pioctl_nt.c | 21 ++++++++----- 2 files changed, 60 insertions(+), 23 deletions(-) diff --git a/src/WINNT/afsd/cm_ioctl.c b/src/WINNT/afsd/cm_ioctl.c index 187b9cf77..ebafa9144 100644 --- a/src/WINNT/afsd/cm_ioctl.c +++ b/src/WINNT/afsd/cm_ioctl.c @@ -135,30 +135,62 @@ void TranslateExtendedChars(char *str) long cm_ParseIoctlPath(smb_ioctl_t *ioctlp, cm_user_t *userp, cm_req_t *reqp, cm_scache_t **scpp) { + extern char cm_NetbiosName[]; long code; cm_scache_t *substRootp; + char * relativePath = ioctlp->inDatap; + + /* This is usually the file name, but for StatMountPoint it is the path. */ + /* ioctlp->inDatap can be either of the form: + * \path\. + * \path\file + * \\netbios-name\submount\path\. + * \\netbios-name\submount\path\file + */ + TranslateExtendedChars(relativePath); - /* This is usually the file name, but for StatMountPoint it is the path. */ - TranslateExtendedChars(ioctlp->inDatap); - - code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data, - CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW, - userp, ioctlp->tidPathp, reqp, &substRootp); - if (code) return code; + if (relativePath[0] == relativePath[1] && + relativePath[1] == '\\' && + !_strnicmp(cm_NetbiosName,relativePath+2,strlen(cm_NetbiosName))) + { + /* We may have found a UNC path. + * If the first component is the NetbiosName, + * then throw out the second component (the submount) + * since it had better expand into the value of ioctl->tidPathp + */ + char * p; + p = relativePath + 2 + strlen(cm_NetbiosName) + 1; + if ( !_strnicmp("all", p, 3) ) + p += 4; + + code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data, + CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW, + userp, p, reqp, &substRootp); + if (code) return code; - code = cm_NameI(substRootp, ioctlp->inDatap, CM_FLAG_FOLLOW, - userp, NULL, reqp, scpp); - if (code) return code; + code = cm_NameI(substRootp, ".", CM_FLAG_FOLLOW, + userp, NULL, reqp, scpp); + if (code) return code; + } else { + code = cm_NameI(cm_rootSCachep, ioctlp->prefix->data, + CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW, + userp, ioctlp->tidPathp, reqp, &substRootp); + if (code) return code; + code = cm_NameI(substRootp, relativePath, CM_FLAG_FOLLOW, + userp, NULL, reqp, scpp); + if (code) return code; + } + /* # of bytes of path */ - code = strlen(ioctlp->inDatap) + 1; - ioctlp->inDatap += code; + code = strlen(ioctlp->inDatap) + 1; + ioctlp->inDatap += code; - /* This is usually nothing, but for StatMountPoint it is the file name. */ - TranslateExtendedChars(ioctlp->inDatap); + /* This is usually nothing, but for StatMountPoint it is the file name. */ + TranslateExtendedChars(ioctlp->inDatap); /* and return success */ - return 0; + return 0; } void cm_SkipIoctlPath(smb_ioctl_t *ioctlp) diff --git a/src/sys/pioctl_nt.c b/src/sys/pioctl_nt.c index 499e513ed..8fac4d497 100644 --- a/src/sys/pioctl_nt.c +++ b/src/sys/pioctl_nt.c @@ -103,7 +103,7 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep) { char *drivep; char netbiosName[MAX_NB_NAME_LENGTH]; - char tbuffer[100]; + char tbuffer[100]=""; HANDLE fh; if (fileNamep) { @@ -112,10 +112,10 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep) tbuffer[0] = *(drivep - 1); tbuffer[1] = ':'; strcpy(tbuffer + 2, SMB_IOCTL_FILENAME); - } else - strcpy(tbuffer, SMB_IOCTL_FILENAME); - } else { - /* No file name specified, use UNC name */ + } + } + if (!tbuffer[0]) { + /* No file name starting with drive colon specified, use UNC name */ lana_GetNetbiosName(netbiosName,LANA_NETBIOS_NAME_FULL); sprintf(tbuffer,"\\\\%s\\all%s",netbiosName,SMB_IOCTL_FILENAME); } @@ -256,11 +256,16 @@ fs_GetFullPath(char *pathp, char *outPathp, long outSize) /* now get the absolute path to the current wdir in this drive */ GetCurrentDirectory(sizeof(tpath), tpath); - strcpy(outPathp, tpath + 2); /* skip drive letter */ + if (tpath[1] == ':') + strcpy(outPathp, tpath + 2); /* skip drive letter */ + else + strcpy(outPathp, tpath); /* copy entire UNC path */ /* if there is a non-null name after the drive, append it */ if (*firstp != 0) { - strcat(outPathp, "\\"); - strcat(outPathp, firstp); + int len = strlen(outPathp); + if (outPathp[len-1] != '\\' && outPathp[len-1] != '/') + strcat(outPathp, "\\"); + strcat(outPathp, firstp); } /* finally, if necessary, switch back to our home drive letter */ -- 2.39.5