Changeset 39626 in vbox
- Timestamp:
- Dec 15, 2011 11:33:47 AM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 75420
- Location:
- trunk
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/dir.h
r39612 r39626 305 305 * @{ */ 306 306 /** Don't allow symbolic links as part of the path. */ 307 #define RTDIROPEN FILTERED_FLAGS_NO_SYMLINKS RT_BIT(0)307 #define RTDIROPEN_FLAGS_NO_SYMLINKS RT_BIT(0) 308 308 /** @} */ 309 309 -
trunk/include/iprt/path.h
r39612 r39626 127 127 /** Last component: Follow if link. */ 128 128 #define RTPATH_F_FOLLOW_LINK RT_BIT_32(1) 129 /** Don't allow symbolic links as part of the path. */ 130 #define RTPATH_F_NO_SYMLINKS RT_BIT_32(2) 129 131 /** @} */ 130 132 … … 133 135 * @remarks The parameters will be referenced multiple times. */ 134 136 #define RTPATH_F_IS_VALID(fFlags, fIgnore) \ 135 ( ((fFlags) & ~(uint32_t)(fIgnore )) == RTPATH_F_ON_LINK \136 || ((fFlags) & ~(uint32_t)(fIgnore )) == RTPATH_F_FOLLOW_LINK )137 ( ((fFlags) & ~(uint32_t)(fIgnore | RTPATH_F_NO_SYMLINKS)) == RTPATH_F_ON_LINK \ 138 || ((fFlags) & ~(uint32_t)(fIgnore | RTPATH_F_NO_SYMLINKS)) == RTPATH_F_FOLLOW_LINK ) 137 139 138 140 -
trunk/src/VBox/HostServices/SharedFolders/service.cpp
r39607 r39626 244 244 else 245 245 { 246 pszFolderName = (char*)RTStrAlloc(cbFolderName );246 pszFolderName = (char*)RTStrAlloc(cbFolderName + 1); 247 247 AssertReturn(pszFolderName, VERR_NO_MEMORY); 248 248 249 rc = SSMR3GetStrZ(pSSM, mapping.pszFolderName, cbFolderName);249 rc = SSMR3GetStrZ(pSSM, pszFolderName, cbFolderName + 1); 250 250 AssertRCReturn(rc, rc); 251 251 mapping.pszFolderName = pszFolderName; -
trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp
r39612 r39626 42 42 #endif 43 43 44 // never follow symbolic links */45 //#define SHFL_RT_LINK(pClient) ((pClient)->fu32Flags & SHFL_CF_SYMLINKS ? RTPATH_F_ON_LINK : RTPATH_F_FOLLOW_LINK)46 #define SHFL_RT_LINK(pClient) (RTPATH_F_ON_LINK)47 48 44 /** 49 45 * @todo find a better solution for supporting the execute bit for non-windows … … 139 135 strcat(pDirEntry->szName, szWildCard); 140 136 141 rc = RTDirOpenFiltered(&hSearch, pDirEntry->szName, RTDIRFILTER_WINNT, RTDIROPEN FILTERED_FLAGS_NO_SYMLINKS);137 rc = RTDirOpenFiltered(&hSearch, pDirEntry->szName, RTDIRFILTER_WINNT, RTDIROPEN_FLAGS_NO_SYMLINKS); 142 138 *(pszStartComponent-1) = RTPATH_DELIMITER; 143 139 if (RT_FAILURE(rc)) … … 148 144 size_t cbDirEntrySize = cbDirEntry; 149 145 150 rc = RTDirReadEx(hSearch, pDirEntry, &cbDirEntrySize, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient)); 146 rc = RTDirReadEx(hSearch, pDirEntry, &cbDirEntrySize, RTFSOBJATTRADD_NOTHING, 147 RTPATH_F_ON_LINK | RTPATH_F_NO_SYMLINKS); 151 148 if (rc == VERR_NO_MORE_FILES) 152 149 break; … … 426 423 if (RT_SUCCESS(rc)) 427 424 { 428 /* When the host file system is case sensitive and the guest expects a case insensitive fs, then problems can occur */ 425 /* When the host file system is case sensitive and the guest expects 426 * a case insensitive fs, then problems can occur */ 429 427 if ( vbsfIsHostMappingCaseSensitive(root) 430 428 && !vbsfIsGuestMappingCaseSensitive(root)) … … 435 433 if (fWildCard || fPreserveLastComponent) 436 434 { 437 /* strip off the last path component, that has to be preserved: contains the wildcard(s) or a 'rename' target. */ 435 /* strip off the last path component, that has to be preserved: 436 * contains the wildcard(s) or a 'rename' target. */ 438 437 size_t cb = strlen(pszFullPath); 439 438 char *pszSrc = pszFullPath + cb - 1; … … 470 469 471 470 /** @todo don't check when creating files or directories; waste of time */ 472 rc = RTPathQueryInfoEx(pszFullPath, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient)); 471 rc = RTPathQueryInfoEx(pszFullPath, &info, RTFSOBJATTRADD_NOTHING, 472 RTPATH_F_ON_LINK | RTPATH_F_NO_SYMLINKS); 473 473 if (rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND) 474 474 { … … 484 484 { 485 485 *pszSrc = 0; 486 rc = RTPathQueryInfoEx(pszFullPath, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient)); 486 rc = RTPathQueryInfoEx(pszFullPath, &info, RTFSOBJATTRADD_NOTHING, 487 RTPATH_F_ON_LINK | RTPATH_F_NO_SYMLINKS); 487 488 *pszSrc = RTPATH_DELIMITER; 488 489 if (rc == VINF_SUCCESS) … … 520 521 fEndOfString = false; 521 522 *pszEnd = 0; 522 rc = RTPathQueryInfoEx(pszSrc, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient)); 523 rc = RTPathQueryInfoEx(pszSrc, &info, RTFSOBJATTRADD_NOTHING, 524 RTPATH_F_ON_LINK | RTPATH_F_NO_SYMLINKS); 523 525 Assert(rc == VINF_SUCCESS || rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND); 524 526 } … … 860 862 861 863 /** @todo Possible race left here. */ 862 if (RT_SUCCESS(RTPathQueryInfoEx(pszPath, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient)))) 864 if (RT_SUCCESS(RTPathQueryInfoEx(pszPath, &info, RTFSOBJATTRADD_NOTHING, 865 RTPATH_F_ON_LINK | RTPATH_F_NO_SYMLINKS))) 863 866 { 864 867 #ifdef RT_OS_WINDOWS … … 1032 1035 /* Open the directory now */ 1033 1036 rc = RTDirOpenFiltered(&pHandle->dir.Handle, pszPath, 1034 RTDIRFILTER_NONE, RTDIROPEN FILTERED_FLAGS_NO_SYMLINKS);1037 RTDIRFILTER_NONE, RTDIROPEN_FLAGS_NO_SYMLINKS); 1035 1038 if (RT_SUCCESS(rc)) 1036 1039 { … … 1130 1133 * @retval pParms->Info On success, information returned about the file 1131 1134 */ 1132 static int vbsfLookupFile(SHFLCLIENTDATA *pClient, char *pszPath, SHFLCREATEPARMS *pParms)1135 static int vbsfLookupFile(SHFLCLIENTDATA *pClient, SHFLROOT root, char *pszPath, SHFLCREATEPARMS *pParms) 1133 1136 { 1134 1137 RTFSOBJINFO info; 1135 1138 int rc; 1136 1139 1137 rc = RTPathQueryInfoEx(pszPath, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient)); 1140 char szRealPath[RTPATH_MAX + 1]; 1141 const char *pszRoot = vbsfMappingsQueryHostRoot(root); 1142 AssertReturn(pszRoot, VERR_INVALID_PARAMETER); 1143 rc = RTPathReal(pszPath, szRealPath, sizeof(szRealPath)); 1144 AssertRCReturn(rc, rc); 1145 if (!RTPathStartsWith(szRealPath, pszRoot)) 1146 return VERR_TOO_MANY_SYMLINKS; 1147 1148 rc = RTPathQueryInfoEx(pszPath, &info, RTFSOBJATTRADD_NOTHING, 1149 RTPATH_F_ON_LINK | RTPATH_F_NO_SYMLINKS); 1138 1150 LogFlow(("SHFL_CF_LOOKUP\n")); 1139 1151 /* Client just wants to know if the object exists. */ … … 1234 1246 if (BIT_FLAG(pParms->CreateFlags, SHFL_CF_LOOKUP)) 1235 1247 { 1236 rc = vbsfLookupFile(pClient, pszFullPath, pParms);1248 rc = vbsfLookupFile(pClient, root, pszFullPath, pParms); 1237 1249 } 1238 1250 else … … 1241 1253 RTFSOBJINFO info; 1242 1254 1243 rc = RTPathQueryInfoEx(pszFullPath, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient)); 1255 rc = RTPathQueryInfoEx(pszFullPath, &info, RTFSOBJATTRADD_NOTHING, 1256 RTPATH_F_ON_LINK | RTPATH_F_NO_SYMLINKS); 1244 1257 LogFlow(("RTPathQueryInfoEx returned %Rrc\n", rc)); 1245 1258 … … 1295 1308 { 1296 1309 if (BIT_FLAG(pParms->CreateFlags, SHFL_CF_DIRECTORY)) 1297 {1298 1310 rc = vbsfOpenDir(pClient, pszFullPath, pParms); 1299 }1300 1311 else 1301 {1302 1312 rc = vbsfOpenFile(pClient, pszFullPath, pParms); 1303 }1304 1313 } 1305 1314 else … … 1505 1514 PRTDIR DirHandle; 1506 1515 bool fUtf8; 1507 1516 1508 1517 fUtf8 = BIT_FLAG(pClient->fu32Flags, SHFL_CF_UTF8) != 0; 1509 1518 … … 1546 1555 if (RT_SUCCESS(rc)) 1547 1556 { 1557 #if 0 1558 const char *pszRoot = vbsfMappingsQueryHostRoot(root); 1559 if (!pszRoot) 1560 { 1561 rc = VERR_INVALID_PARAMETER; 1562 goto end; 1563 } 1564 char szRealPath[RTPATH_MAX + 1]; 1565 rc = RTPathReal(pszFullPath, szRealPath, sizeof(szRealPath)); 1566 if (RT_FAILURE(rc)) 1567 goto end; 1568 if (!RTPathStartsWith(szRealPath, pszRoot)) 1569 { 1570 rc = VERR_TOO_MANY_SYMLINKS; 1571 goto end; 1572 } 1573 #endif 1548 1574 rc = RTDirOpenFiltered(&pHandle->dir.SearchHandle, pszFullPath, 1549 RTDIRFILTER_WINNT, RTDIROPEN FILTERED_FLAGS_NO_SYMLINKS);1575 RTDIRFILTER_WINNT, RTDIROPEN_FLAGS_NO_SYMLINKS); 1550 1576 1551 1577 /* free the path string */ … … 1576 1602 pDirEntry = pDirEntryOrg; 1577 1603 1578 rc = RTDirReadEx(DirHandle, pDirEntry, &cbDirEntrySize, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient)); 1604 rc = RTDirReadEx(DirHandle, pDirEntry, &cbDirEntrySize, RTFSOBJATTRADD_NOTHING, 1605 RTPATH_F_ON_LINK | RTPATH_F_NO_SYMLINKS); 1579 1606 if (rc == VERR_NO_MORE_FILES) 1580 1607 { … … 2295 2322 { 2296 2323 RTFSOBJINFO info; 2297 rc = RTPathQueryInfoEx(pszFullNewPath, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient)); 2324 rc = RTPathQueryInfoEx(pszFullNewPath, &info, RTFSOBJATTRADD_NOTHING, 2325 RTPATH_F_ON_LINK | RTPATH_F_NO_SYMLINKS); 2298 2326 if (RT_SUCCESS(rc)) 2299 2327 vbfsCopyFsObjInfoFromIprt(pInfo, &info); -
trunk/src/VBox/Runtime/Makefile.kmk
r39500 r39626 615 615 r3/posix/RTTimeSet-posix.cpp \ 616 616 r3/posix/rtmempage-exec-mmap-heap-posix.cpp \ 617 r3/posix/rtPathOpenPathFh.cpp \ 617 618 r3/posix/dir-posix.cpp \ 618 619 r3/posix/env-posix.cpp \ … … 1173 1174 r3/posix/env-posix.cpp \ 1174 1175 r3/posix/fileio-posix.cpp \ 1176 r3/posix/rtPathOpenPathFh.cpp \ 1175 1177 r3/posix/fileio2-posix.cpp \ 1176 1178 r3/posix/path-posix.cpp \ -
trunk/src/VBox/Runtime/include/internal/dir.h
r28918 r39626 129 129 * wildcard expression. 130 130 */ 131 int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf );131 int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf, uint32_t fOpen); 132 132 133 133 #endif -
trunk/src/VBox/Runtime/include/internal/path.h
r33540 r39626 48 48 DECLHIDDEN(int) rtPathPosixRename(const char *pszSrc, const char *pszDst, unsigned fRename, RTFMODE fFileType); 49 49 DECLHIDDEN(int) rtPathWin32MoveRename(const char *pszSrc, const char *pszDst, uint32_t fFlags, RTFMODE fFileType); 50 50 DECLHIDDEN(int) rtPathOpenPathNoFollowFh(const char *pszPath, int *fh, const char **ppszName); 51 51 52 52 /** -
trunk/src/VBox/Runtime/r3/dir.cpp
r39612 r39626 517 517 * @param pszFilter Pointer to where the filter start in the path. NULL if no filter. 518 518 * @param enmFilter The type of filter to apply. 519 */ 520 static int rtDirOpenCommon(PRTDIR *ppDir, const char *pszPath, const char *pszFilter, RTDIRFILTER enmFilter) 519 * @param fOpen Open flags, RTDIROPENFILTERED_FLAGS_*. 520 */ 521 static int rtDirOpenCommon(PRTDIR *ppDir, const char *pszPath, const char *pszFilter, RTDIRFILTER enmFilter, uint32_t fOpen) 521 522 { 522 523 /* … … 646 647 * Hand it over to the native part. 647 648 */ 648 rc = rtDirNativeOpen(pDir, szRealPath );649 rc = rtDirNativeOpen(pDir, szRealPath, fOpen); 649 650 if (RT_SUCCESS(rc)) 650 651 *ppDir = pDir; … … 668 669 * Take common cause with RTDirOpenFiltered(). 669 670 */ 670 int rc = rtDirOpenCommon(ppDir, pszPath, NULL, RTDIRFILTER_NONE );671 int rc = rtDirOpenCommon(ppDir, pszPath, NULL, RTDIRFILTER_NONE, 0); 671 672 LogFlow(("RTDirOpen(%p:{%p}, %p:{%s}): return %Rrc\n", ppDir, *ppDir, pszPath, pszPath, rc)); 672 673 return rc; … … 711 712 * and initialize the handle, and finally call the backend. 712 713 */ 713 int rc = rtDirOpenCommon(ppDir, pszPath, pszFilter, enmFilter );714 int rc = rtDirOpenCommon(ppDir, pszPath, pszFilter, enmFilter, fOpen); 714 715 715 716 LogFlow(("RTDirOpenFiltered(%p:{%p}, %p:{%s}, %d): return %Rrc\n", -
trunk/src/VBox/Runtime/r3/posix/dir-posix.cpp
r39612 r39626 194 194 195 195 196 int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf )196 int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf, uint32_t fOpen) 197 197 { 198 198 NOREF(pszPathBuf); /* only used on windows */ … … 205 205 if (RT_SUCCESS(rc)) 206 206 { 207 pDir->pDir = opendir(pszNativePath); 207 #if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) 208 /* XXX Darwin? */ 209 if (fOpen & RTDIROPEN_FLAGS_NO_SYMLINKS) 210 { 211 const char *pszName; 212 int fhDir; 213 rc = rtPathOpenPathNoFollowFh(pszNativePath, &fhDir, &pszName); 214 printf("rtPathOpenPathNoFollowFh '%s' => %d\n", pszNativePath, rc); 215 AssertRCReturn(rc, rc); 216 if (pszName != NULL) 217 { 218 AssertMsgFailed(("Path name '%s' contains filename\n", pszNativePath)); 219 return VERR_INVALID_PARAMETER; 220 } 221 pDir->pDir = fdopendir(fhDir); 222 /* 223 * do NOT close fhDir, it will be closed implicitely when closing pDir! 224 */ 225 } 226 else 227 #endif 228 { 229 pDir->pDir = opendir(pszNativePath); 230 } 208 231 if (pDir->pDir) 209 232 { -
trunk/src/VBox/Runtime/r3/posix/fileio-posix.cpp
r39083 r39626 204 204 return (rc); 205 205 206 int fh = open(pszNativeFilename, fOpenMode, fMode); 206 int fh; 207 #if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) 208 /* XXX Darwin? */ 209 if (fOpen & RTFILE_O_NO_SYMLINKS) 210 { 211 const char *pszName; 212 int fhDir; 213 rc = rtPathOpenPathNoFollowFh(pszNativeFilename, &fhDir, &pszName); 214 if (RT_FAILURE(rc)) 215 { 216 rtPathFreeNative(pszNativeFilename, pszFilename); 217 return rc; 218 } 219 fh = openat(fhDir, pszName, fOpenMode, fMode | O_NOFOLLOW); 220 close(fhDir); 221 } 222 else 223 #endif 224 { 225 fh = open(pszNativeFilename, fOpenMode, fMode); 226 } 207 227 int iErr = errno; 208 228 -
trunk/src/VBox/Runtime/r3/win/dir-win.cpp
r39612 r39626 130 130 131 131 132 int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf )132 int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf, uint32_t fOpen) 133 133 { 134 134 /*
Note:
See TracChangeset
for help on using the changeset viewer.