Changeset 105087 in vbox for trunk/src/VBox/HostServices
- Timestamp:
- Jul 1, 2024 11:27:59 PM (8 months ago)
- svn:sync-xref-src-repo-rev:
- 163708
- Location:
- trunk/src/VBox/HostServices/SharedFolders
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedFolders/Makefile.kmk
r105018 r105087 39 39 VBoxSharedFolders_NAME.os2 = VBoxSFld 40 40 VBoxSharedFolders_DEFS = VBOX_WITH_HGCM RTSHFL 41 VBoxSharedFolders_INCS.win = \ 42 $(VBOX_PATH_SDK) 41 ifdef VBOX_WITH_XPCOM 42 VBoxSharedFolders_DEFS += VBOX_WITH_XPCOM 43 VBoxSharedFolders_INCS += $(VBOX_XPCOM_INCS) 44 ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP 45 VBoxSharedFolders_DEFS += VBOX_WITH_XPCOM_NAMESPACE_CLEANUP 46 endif 47 else # COM 48 VBoxSharedFolders_INCS += \ 49 $(VBOX_PATH_SDK) \ 50 $(VBOX_PATH_SDK)/bindings/mscom/include 51 endif 43 52 44 53 VBoxSharedFolders_LDFLAGS.darwin = \ -
trunk/src/VBox/HostServices/SharedFolders/VBoxSharedFoldersSvc.cpp
r105018 r105087 164 164 165 165 166 static DECLCALLBACK(int) svcUnload 166 static DECLCALLBACK(int) svcUnload(void *) 167 167 { 168 168 int rc = VINF_SUCCESS; … … 176 176 } 177 177 178 static DECLCALLBACK(int) svcConnect 178 static DECLCALLBACK(int) svcConnect(void *, uint32_t u32ClientID, void *pvClient, uint32_t fRequestor, bool fRestoring) 179 179 { 180 180 RT_NOREF(u32ClientID, fRequestor, fRestoring); … … 187 187 } 188 188 189 static DECLCALLBACK(int) svcDisconnect 189 static DECLCALLBACK(int) svcDisconnect(void *, uint32_t u32ClientID, void *pvClient) 190 190 { 191 191 RT_NOREF1(u32ClientID); … … 455 455 } 456 456 457 static DECLCALLBACK(void) svcCall 458 457 static DECLCALLBACK(void) svcCall(void *, VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID, void *pvClient, 458 uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival) 459 459 { 460 460 RT_NOREF(u32ClientID, tsArrival); … … 618 618 ) 619 619 { 620 AssertMsgFailed 620 AssertMsgFailed(("Invalid parameters cbPath or cbParms (%x, %x - expected >=%x, %x)\n", 621 621 cbPath, cbParms, sizeof(SHFLSTRING), sizeof (SHFLCREATEPARMS))); 622 622 rc = VERR_INVALID_PARAMETER; … … 631 631 632 632 /* Execute the function. */ 633 rc = vbsfCreate 633 rc = vbsfCreate(pClient, root, pPath, cbPath, pParms); 634 634 635 635 if (RT_SUCCESS(rc)) … … 680 680 { 681 681 /* Execute the function. */ 682 rc = vbsfClose 682 rc = vbsfClose(pClient, root, Handle); 683 683 684 684 if (RT_SUCCESS(rc)) … … 845 845 * completed, the another thread must call 846 846 * 847 * g_pHelpers->pfnCallComplete 847 * g_pHelpers->pfnCallComplete(callHandle, rc); 848 848 * 849 849 * The operation is async. … … 939 939 940 940 /* Execute the function. */ 941 rc = vbsfDirList 941 rc = vbsfDirList(pClient, root, Handle, pPath, flags, &length, pBuffer, &resumePoint, &cFiles); 942 942 943 943 if (g_pStatusLed) … … 1002 1002 { 1003 1003 /* Execute the function. */ 1004 rc = vbsfReadLink 1004 rc = vbsfReadLink(pClient, root, pPath, cbPath, pBuffer, cbBuffer); 1005 1005 1006 1006 if (RT_SUCCESS(rc)) … … 1048 1048 { 1049 1049 /* Execute the function. */ 1050 rc = vbsfMapFolder 1050 rc = vbsfMapFolder(pClient, pszMapName, delimiter, false, &root); 1051 1051 1052 1052 if (RT_SUCCESS(rc)) … … 1118 1118 /* Execute the function. */ 1119 1119 if (RT_SUCCESS(rc)) 1120 rc = vbsfMapFolder 1120 rc = vbsfMapFolder(pClient, pszMapName, delimiter, fCaseSensitive, &root); 1121 1121 1122 1122 if (RT_SUCCESS(rc)) … … 1156 1156 1157 1157 /* Execute the function. */ 1158 rc = vbsfUnmapFolder 1158 rc = vbsfUnmapFolder(pClient, root); 1159 1159 1160 1160 if (RT_SUCCESS(rc)) … … 1208 1208 if (flags & SHFL_INFO_SET) 1209 1209 { 1210 rc = vbsfSetFSInfo 1210 rc = vbsfSetFSInfo(pClient, root, Handle, flags, &length, pBuffer); 1211 1211 1212 1212 if (flags & SHFL_INFO_FILE) … … 1223 1223 else /* SHFL_INFO_GET */ 1224 1224 { 1225 rc = vbsfQueryFSInfo 1225 rc = vbsfQueryFSInfo(pClient, root, Handle, flags, &length, pBuffer); 1226 1226 1227 1227 if (flags & SHFL_INFO_FILE) … … 1339 1339 { 1340 1340 /* Execute the function. */ 1341 rc = vbsfRename 1341 rc = vbsfRename(pClient, root, pSrc, pDest, flags); 1342 1342 if (RT_SUCCESS(rc)) 1343 1343 { … … 1389 1389 /* Execute the function. */ 1390 1390 1391 rc = vbsfFlush 1391 rc = vbsfFlush(pClient, root, Handle); 1392 1392 1393 1393 if (RT_SUCCESS(rc)) … … 1447 1447 { 1448 1448 /* Execute the function. */ 1449 rc = vbsfSymlink 1449 rc = vbsfSymlink(pClient, root, pNewPath, pOldPath, pInfo); 1450 1450 if (RT_SUCCESS(rc)) 1451 1451 { … … 1646 1646 * it was processed synchronously. 1647 1647 */ 1648 g_pHelpers->pfnCallComplete 1648 g_pHelpers->pfnCallComplete(callHandle, rc); 1649 1649 } 1650 1650 … … 1668 1668 * security reasons. 1669 1669 */ 1670 static DECLCALLBACK(int) svcHostCall 1670 static DECLCALLBACK(int) svcHostCall(void *, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) 1671 1671 { 1672 1672 int rc = VINF_SUCCESS; … … 1700 1700 || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* fFlags */ 1701 1701 || paParms[3].type != VBOX_HGCM_SVC_PARM_PTR /* auto mount point */ 1702 || paParms[4].type != VBOX_HGCM_SVC_PARM_32BIT /* symlink policy */ 1702 1703 ) 1703 1704 { … … 1711 1712 uint32_t fFlags = paParms[2].u.uint32; 1712 1713 SHFLSTRING *pAutoMountPoint = (SHFLSTRING *)paParms[3].u.pointer.addr; 1714 SymlinkPolicy_T enmSymlinkPolicy = (SymlinkPolicy_T)paParms[4].u.uint32; 1713 1715 1714 1716 /* Verify parameters values. */ … … 1741 1743 RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_CREATE_SYMLINKS), 1742 1744 RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_MISSING), 1743 /* fPlaceholder = */ false); 1745 /* fPlaceholder = */ false, 1746 enmSymlinkPolicy); 1744 1747 if (RT_SUCCESS(rc)) 1745 1748 { … … 1785 1788 { 1786 1789 /* Execute the function. */ 1787 rc = vbsfMappingsRemove 1790 rc = vbsfMappingsRemove(pString); 1788 1791 1789 1792 if (RT_SUCCESS(rc)) … … 1844 1847 } 1845 1848 1846 extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad 1849 extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad(VBOXHGCMSVCFNTABLE *ptable) 1847 1850 { 1848 1851 int rc = VINF_SUCCESS; -
trunk/src/VBox/HostServices/SharedFolders/mappings.cpp
r105018 r105087 186 186 return vbsfMappingsAdd(pLoadedMapping->pszFolderName, pLoadedMapping->pMapName, 187 187 pLoadedMapping->fWritable, pLoadedMapping->fAutoMount, pLoadedMapping->pAutoMountPoint, 188 pLoadedMapping->fSymlinksCreate, /* fMissing = */ true, /* fPlaceholder = */ true); 188 pLoadedMapping->fSymlinksCreate, /* fMissing = */ true, /* fPlaceholder = */ true, 189 pLoadedMapping->enmSymlinkPolicy); 189 190 } 190 191 … … 340 341 */ 341 342 int vbsfMappingsAdd(const char *pszFolderName, PSHFLSTRING pMapName, bool fWritable, 342 bool fAutoMount, PSHFLSTRING pAutoMountPoint, bool fSymlinksCreate, bool fMissing, bool fPlaceholder) 343 bool fAutoMount, PSHFLSTRING pAutoMountPoint, bool fSymlinksCreate, bool fMissing, bool fPlaceholder, 344 SymlinkPolicy_T enmSymlinkPolicy) 343 345 { 344 346 unsigned i; … … 369 371 for (i = 0; i < SHFL_MAX_MAPPINGS; i++) 370 372 { 371 if ( g_FolderMapping[i].fValid == false)373 if (!g_FolderMapping[i].fValid) 372 374 { 373 375 /* Make sure the folder name is an absolute path, otherwise we're … … 398 400 g_FolderMapping[i].fPlaceholder = fPlaceholder; 399 401 g_FolderMapping[i].fLoadedRootId = false; 402 g_FolderMapping[i].enmSymlinkPolicy = enmSymlinkPolicy; 400 403 401 404 /* Check if the host file system is case sensitive */ … … 446 449 for (unsigned i = 0; i < SHFL_MAX_MAPPINGS; i++) 447 450 { 448 if (g_FolderMapping[i].fValid == true)451 if (g_FolderMapping[i].fValid) 449 452 { 450 453 if (!RTUtf16LocaleICmp(g_FolderMapping[i].pMapName->String.utf16, pMapName->String.utf16)) … … 599 602 int vbsfMappingsQueryName(PSHFLCLIENTDATA pClient, SHFLROOT root, SHFLSTRING *pString) 600 603 { 601 LogFlow(("vbsfMappingsQuery : pClient = %p, root = %d, *pString = %p\n", pClient, root, pString));604 LogFlow(("vbsfMappingsQueryName: pClient = %p, root = %d, *pString = %p\n", pClient, root, pString)); 602 605 603 606 int rc; … … 633 636 rc = VERR_INVALID_PARAMETER; 634 637 635 LogFlow(("vbsfMappingsQuery :Name returnrc = %Rrc\n", rc));638 LogFlow(("vbsfMappingsQueryName returns rc = %Rrc\n", rc)); 636 639 return rc; 637 640 } … … 655 658 rc = VERR_FILE_NOT_FOUND; 656 659 657 LogFlow(("vbsfMappingsQuery :Writable returnrc = %Rrc\n", rc));660 LogFlow(("vbsfMappingsQueryWritable returns rc = %Rrc\n", rc)); 658 661 659 662 return rc; … … 670 673 AssertReturn(pFolderMapping, VERR_INVALID_PARAMETER); 671 674 672 if (pFolderMapping->fValid == true)675 if (pFolderMapping->fValid) 673 676 *fAutoMount = pFolderMapping->fAutoMount; 674 677 else 675 678 rc = VERR_FILE_NOT_FOUND; 676 679 677 LogFlow(("vbsfMappingsQueryAutoMount :Writable returnrc = %Rrc\n", rc));680 LogFlow(("vbsfMappingsQueryAutoMount returns rc = %Rrc\n", rc)); 678 681 679 682 return rc; … … 685 688 int rc = VINF_SUCCESS; 686 689 687 LogFlow(("vbsfMappingsQuery AutoMount: pClient = %p, root = %d\n", pClient, root));690 LogFlow(("vbsfMappingsQuerySymlinksCreate: pClient = %p, root = %d\n", pClient, root)); 688 691 689 692 MAPPING *pFolderMapping = vbsfMappingGetByRoot(root); 690 693 AssertReturn(pFolderMapping, VERR_INVALID_PARAMETER); 691 694 692 if (pFolderMapping->fValid == true)695 if (pFolderMapping->fValid) 693 696 *fSymlinksCreate = pFolderMapping->fSymlinksCreate; 694 697 else 695 698 rc = VERR_FILE_NOT_FOUND; 696 699 697 LogFlow(("vbsfMappingsQueryAutoMount:SymlinksCreate return rc = %Rrc\n", rc)); 700 LogFlow(("vbsfMappingsQuerySymlinksCreate returns rc = %Rrc\n", rc)); 701 702 return rc; 703 } 704 705 int vbsfMappingsQuerySymlinkPolicy(PSHFLCLIENTDATA pClient, SHFLROOT root, SymlinkPolicy_T *enmSymlinkPolicy) 706 { 707 RT_NOREF1(pClient); 708 int rc = VINF_SUCCESS; 709 710 LogFlow(("vbsfMappingsQuerySymlinkPolicy: pClient = %p, root = %d\n", pClient, root)); 711 712 MAPPING *pFolderMapping = vbsfMappingGetByRoot(root); 713 AssertReturn(pFolderMapping, VERR_INVALID_PARAMETER); 714 715 if (pFolderMapping->fValid) 716 *enmSymlinkPolicy = pFolderMapping->enmSymlinkPolicy; 717 else 718 rc = VERR_FILE_NOT_FOUND; 719 720 LogFlow(("vbsfMappingsQuerySymlinkPolicy returns rc = %Rrc\n", rc)); 698 721 699 722 return rc; … … 879 902 return VERR_FILE_NOT_FOUND; 880 903 } 881 Assert(pFolderMapping->fValid == true&& pFolderMapping->cMappings > 0);904 Assert(pFolderMapping->fValid && pFolderMapping->cMappings > 0); 882 905 883 906 AssertLogRelReturn(root < RT_ELEMENTS(pClient->acMappings), VERR_INTERNAL_ERROR); -
trunk/src/VBox/HostServices/SharedFolders/mappings.h
r105018 r105087 52 52 still has. fMissing is always true for this mapping. */ 53 53 bool fLoadedRootId; /**< Set if vbsfMappingLoaded has found this mapping already. */ 54 SymlinkPolicy_T enmSymlinkPolicy; /**< Symbolic link creation policy within the guest. */ 54 55 } MAPPING; 55 56 /** Pointer to a MAPPING structure. */ … … 61 62 62 63 int vbsfMappingsAdd(const char *pszFolderName, PSHFLSTRING pMapName, bool fWritable, 63 bool fAutoMount, PSHFLSTRING pAutoMountPoint, bool fCreateSymlinks, bool fMissing, bool fPlaceholder); 64 bool fAutoMount, PSHFLSTRING pAutoMountPoint, bool fCreateSymlinks, bool fMissing, bool fPlaceholder, 65 SymlinkPolicy_T enmSymlinkPolicy); 64 66 int vbsfMappingsRemove(PSHFLSTRING pMapName); 65 67 … … 69 71 int vbsfMappingsQueryAutoMount(PSHFLCLIENTDATA pClient, SHFLROOT root, bool *fAutoMount); 70 72 int vbsfMappingsQuerySymlinksCreate(PSHFLCLIENTDATA pClient, SHFLROOT root, bool *fSymlinksCreate); 73 int vbsfMappingsQuerySymlinkPolicy(PSHFLCLIENTDATA pClient, SHFLROOT root, SymlinkPolicy_T *enmSymlinkPolicy); 71 74 int vbsfMappingsQueryInfo(PSHFLCLIENTDATA pClient, SHFLROOT root, PSHFLSTRING pNameBuf, PSHFLSTRING pMntPtBuf, 72 75 uint64_t *pfFlags, uint32_t *puVersion); -
trunk/src/VBox/HostServices/SharedFolders/shfl.h
r105018 r105087 76 76 typedef SHFLCLIENTDATA *PSHFLCLIENTDATA; 77 77 78 /** This enum is included here to avoid a build dependency on the VirtualBox 79 * COM definitions pulled in by VBox/com/VirtualBox.h. */ 80 typedef enum SymlinkPolicy_T { 81 SymlinkPolicy_None, 82 SymlinkPolicy_Forbidden, 83 SymlinkPolicy_AllowedInShareSubtree, 84 SymlinkPolicy_AllowedToRelativeTargets, 85 SymlinkPolicy_AllowedToAnyTarget, 86 #ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK 87 SymlinkPolicy_32BitHack = 0x7fffffff 88 #endif /* VBOX_WITH_XPCOM_CPP_ENUM_HACK */ 89 } SymlinkPolicy_T; 78 90 79 91 /** @def SHFL_CLIENT_NEED_WINDOWS_ERROR_STYLE_ADJUST_ON_POSIX -
trunk/src/VBox/HostServices/SharedFolders/testcase/Makefile.kmk
r105018 r105087 69 69 tstSharedFolderService_DEFS = VBOX_WITH_HGCM UNITTEST 70 70 tstSharedFolderService_INCS = .. 71 ifneq ($(KBUILD_TARGET),win) 72 tstSharedFolderService_DEFS += VBOX_WITH_XPCOM 73 tstSharedFolderService_INCS += $(VBOX_XPCOM_INCS) 74 endif 75 tstSharedFolderService_INCS.win += $(VBOX_PATH_SDK)/bindings/mscom/include 71 76 tstSharedFolderService_SOURCES = \ 72 77 tstSharedFolderService.cpp \ -
trunk/src/VBox/HostServices/SharedFolders/testcase/tstSharedFolderService.cpp
r105018 r105087 587 587 } 588 588 589 extern int testRTSymlinkCreate(const char *pszSymlink, const char *pszTarget, RTSYMLINKTYPE enmType, uint32_t fCreate) 590 { 591 if (g_fFailIfNotLowercase && !RTStrIsLowerCased(strpbrk(pszSymlink, "/\\"))) 592 return VERR_FILE_NOT_FOUND; 593 RT_NOREF4(pszSymlink, pszTarget, enmType, fCreate); 594 return 0; 595 } 596 589 597 590 598 /********************************************************************************************************************************* … … 678 686 } 679 687 688 static void fillTestShflStringUtf8(union TESTSHFLSTRING *pDest, 689 const char *pcszSource) 690 { 691 const size_t cchSource = strlen(pcszSource); 692 AssertRelease( cchSource * 2 + 2 693 < sizeof(*pDest) - RT_UOFFSETOF(SHFLSTRING, String)); 694 pDest->string.u16Length = (uint16_t)cchSource; 695 pDest->string.u16Size = pDest->string.u16Length + 1; 696 memcpy(pDest->string.String.utf8, pcszSource, pDest->string.u16Size); 697 } 698 680 699 static SHFLROOT initWithWritableMapping(RTTEST hTest, 681 700 VBOXHGCMSVCFNTABLE *psvcTable, … … 683 702 const char *pcszFolderName, 684 703 const char *pcszMapping, 685 bool fCaseSensitive = true) 704 bool fCaseSensitive = true, 705 SymlinkPolicy_T enmSymlinkPolicy = SymlinkPolicy_AllowedToAnyTarget) 686 706 { 687 707 VBOXHGCMSVCPARM aParms[RT_MAX(SHFL_CPARMS_ADD_MAPPING, … … 706 726 HGCMSvcSetPv(&aParms[1], &Mapping, RT_UOFFSETOF(SHFLSTRING, String) 707 727 + Mapping.string.u16Size); 708 HGCMSvcSetU32(&aParms[2], 1);728 HGCMSvcSetU32(&aParms[2], SHFL_ADD_MAPPING_F_WRITABLE | SHFL_ADD_MAPPING_F_CREATE_SYMLINKS); 709 729 HGCMSvcSetPv(&aParms[3], &AutoMountPoint, SHFLSTRING_HEADER_SIZE + AutoMountPoint.string.u16Size); 730 HGCMSvcSetU32(&aParms[4], enmSymlinkPolicy); 710 731 rc = psvcTable->pfnHostCall(psvcTable->pvService, SHFL_FN_ADD_MAPPING, 711 732 SHFL_CPARMS_ADD_MAPPING, aParms); … … 774 795 *pResult = CreateParms.Result; 775 796 return VINF_SUCCESS; 797 } 798 799 static int createSymlink(VBOXHGCMSVCFNTABLE *psvcTable, SHFLROOT Root, 800 const char *pcszSourcePath, const char *pcszSymlinkPath) 801 { 802 VBOXHGCMSVCPARM aParms[SHFL_CPARMS_SYMLINK]; 803 union TESTSHFLSTRING sourcePath; 804 union TESTSHFLSTRING symlinkPath; 805 SHFLFSOBJINFO ObjInfo; 806 VBOXHGCMCALLHANDLE_TYPEDEF callHandle = { VINF_SUCCESS }; 807 808 /* vbsfSymlink() only supports UTF-8 */ 809 fillTestShflStringUtf8(&sourcePath, pcszSourcePath); 810 fillTestShflStringUtf8(&symlinkPath, pcszSymlinkPath); 811 psvcTable->pfnCall(psvcTable->pvService, &callHandle, 0, 812 psvcTable->pvService, SHFL_FN_SET_UTF8, 813 RT_ELEMENTS(aParms), aParms, 0); 814 815 RT_ZERO(ObjInfo); 816 HGCMSvcSetU32(&aParms[0], Root); 817 HGCMSvcSetPv(&aParms[1], &symlinkPath, RT_UOFFSETOF(SHFLSTRING, String) 818 + symlinkPath.string.u16Size); 819 HGCMSvcSetPv(&aParms[2], &sourcePath, RT_UOFFSETOF(SHFLSTRING, String) 820 + sourcePath.string.u16Size); 821 HGCMSvcSetPv(&aParms[3], &ObjInfo, sizeof(ObjInfo)); 822 psvcTable->pfnCall(psvcTable->pvService, &callHandle, 0, 823 psvcTable->pvService, SHFL_FN_SYMLINK, 824 RT_ELEMENTS(aParms), aParms, 0); 825 return callHandle.rc; 776 826 } 777 827 … … 1006 1056 } 1007 1057 1058 static int testSymlinkCreationForSpecificPolicy(RTTEST hTest, SymlinkPolicy_T enmSymlinkPolicy) 1059 { 1060 VBOXHGCMSVCFNTABLE svcTable; 1061 VBOXHGCMSVCHELPERS svcHelpers; 1062 SHFLROOT Root; 1063 const RTFILE hFile = (RTFILE) 0x10000; 1064 SHFLCREATERESULT Result; 1065 int rc; 1066 1067 Root = initWithWritableMapping(hTest, &svcTable, &svcHelpers, 1068 "/test/mapping", "testname", 1069 true, enmSymlinkPolicy); 1070 g_testRTFileOpen_hFile = hFile; 1071 rc = createFile(&svcTable, Root, "file", SHFL_CF_ACCESS_READ, NULL, &Result); 1072 RTTEST_CHECK_RC_OK(hTest, rc); 1073 RTTEST_CHECK_MSG(hTest, 1074 !strcmp(&g_testRTFileOpen_szName[RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS ? 2 : 0], 1075 "/test/mapping/file"), 1076 (hTest, "pszFilename=%s\n", &g_testRTFileOpen_szName[RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS ? 2 : 0])); 1077 RTTEST_CHECK_MSG(hTest, g_testRTFileOpen_fOpen == 0x181, 1078 (hTest, "fOpen=%llu\n", LLUIFY(g_testRTFileOpen_fOpen))); 1079 RTTEST_CHECK_MSG(hTest, Result == SHFL_FILE_CREATED, 1080 (hTest, "Result=%d\n", (int)Result)); 1081 1082 /* regular symlink creation should succeed unless no symlinks allowed */ 1083 rc = createSymlink(&svcTable, Root, "file", "symlink"); 1084 if (enmSymlinkPolicy == SymlinkPolicy_Forbidden) 1085 RTTEST_CHECK_MSG(hTest, rc == VERR_WRITE_PROTECT, 1086 (hTest, "enmSymlinkPolicy=SymlinkPolicy_Forbidden 'ln -s file symlink' failed: rc=%Rrc\n", rc)); 1087 else 1088 RTTEST_CHECK_RC_OK(hTest, rc); 1089 1090 /* absolute path to symlink sources only allowed for the 'any' policy */ 1091 rc = createSymlink(&svcTable, Root, "/path/to/file", "abs-symlink"); 1092 if (enmSymlinkPolicy == SymlinkPolicy_AllowedToAnyTarget) 1093 RTTEST_CHECK_RC_OK(hTest, rc); 1094 else 1095 RTTEST_CHECK_MSG(hTest, rc == VERR_WRITE_PROTECT, 1096 (hTest, "enmSymlinkPolicy=%d 'ln -s file /absolute/path/symlink' failed: rc=%Rrc\n", 1097 enmSymlinkPolicy, rc)); 1098 1099 /* relative path symlink sources with '..' components allowed only with 'relative' policy */ 1100 rc = createSymlink(&svcTable, Root, "./directory/../file", "rel-symlink"); 1101 if ( enmSymlinkPolicy == SymlinkPolicy_Forbidden 1102 || enmSymlinkPolicy == SymlinkPolicy_AllowedInShareSubtree) 1103 RTTEST_CHECK_MSG(hTest, rc == VERR_WRITE_PROTECT, 1104 (hTest, "enmSymlinkPolicy=%d 'ln -s ./path/../symlink' failed: rc=%Rrc\n", 1105 enmSymlinkPolicy, rc)); 1106 else 1107 RTTEST_CHECK_RC_OK(hTest, rc); 1108 1109 /* relative path symlink source with no '..' components always OK */ 1110 rc = createSymlink(&svcTable, Root, "./directory/file", "dotslash-symlink"); 1111 if (enmSymlinkPolicy == SymlinkPolicy_Forbidden) 1112 RTTEST_CHECK_MSG(hTest, rc == VERR_WRITE_PROTECT, 1113 (hTest, "enmSymlinkPolicy=%d 'ln -s ./path/../symlink' failed: rc=%Rrc\n", 1114 enmSymlinkPolicy, rc)); 1115 else 1116 RTTEST_CHECK_RC_OK(hTest, rc); 1117 1118 unmapAndRemoveMapping(hTest, &svcTable, Root, "testname"); 1119 rc = svcTable.pfnDisconnect(NULL, 0, svcTable.pvService); 1120 AssertReleaseRC(rc); 1121 rc = svcTable.pfnUnload(NULL); 1122 AssertReleaseRC(rc); 1123 RTTestGuardedFree(hTest, svcTable.pvService); 1124 RTTEST_CHECK_MSG(hTest, g_testRTFileClose_hFile == hFile, 1125 (hTest, "File=%u\n", (uintptr_t)g_testRTFileClose_hFile)); 1126 1127 return rc; 1128 } 1129 1130 void testSymlinkCreation(RTTEST hTest) 1131 { 1132 SymlinkPolicy_T aEnmSymlinkPolicy[4] = { 1133 SymlinkPolicy_AllowedToAnyTarget, 1134 SymlinkPolicy_AllowedInShareSubtree, 1135 SymlinkPolicy_AllowedToRelativeTargets, 1136 SymlinkPolicy_Forbidden 1137 }; 1138 1139 RTTestSub(hTest, "Create variety of symlinks with different symlink policies"); 1140 for (size_t i = 0; i < RT_ELEMENTS(aEnmSymlinkPolicy); i++) 1141 testSymlinkCreationForSpecificPolicy(hTest, aEnmSymlinkPolicy[i]); 1142 } 1143 1008 1144 void testReadFileSimple(RTTEST hTest) 1009 1145 { -
trunk/src/VBox/HostServices/SharedFolders/testcase/tstSharedFolderService.h
r105018 r105087 123 123 /* Sub-tests for testSymlink(). */ 124 124 void testSymlinkBadParameters(RTTEST hTest); 125 void testSymlinkCreation(RTTEST hTest); 125 126 126 127 void testMappingsAdd(RTTEST hTest); -
trunk/src/VBox/HostServices/SharedFolders/teststubs.h
r105018 r105087 101 101 #define RTSymlinkRead testRTSymlinkRead 102 102 extern int testRTSymlinkRead(const char *pszSymlink, char *pszTarget, size_t cbTarget, uint32_t fRead); 103 #define RTSymlinkCreate testRTSymlinkCreate 104 extern int testRTSymlinkCreate(const char *pszSymlink, const char *pszTarget, RTSYMLINKTYPE enmType, uint32_t fCreate); 103 105 104 106 #endif /* !VBOX_INCLUDED_SRC_SharedFolders_teststubs_h */ -
trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp
r105018 r105087 256 256 uint32_t fu32PathFlags = 0; 257 257 uint32_t fu32Options = VBSF_O_PATH_CHECK_ROOT_ESCAPE 258 | (fWildCard ? VBSF_O_PATH_WILDCARD: 0)259 | (fPreserveLastComponent ? VBSF_O_PATH_PRESERVE_LAST_COMPONENT: 0);258 | (fWildCard ? VBSF_O_PATH_WILDCARD : 0) 259 | (fPreserveLastComponent ? VBSF_O_PATH_PRESERVE_LAST_COMPONENT : 0); 260 260 261 261 int rc = vbsfPathGuestToHost(pClient, root, pPath, cbPath, … … 2598 2598 testSymlinkBadParameters(hTest); 2599 2599 /* Add tests as required... */ 2600 } 2601 #endif 2602 int vbsfSymlink(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pNewPath, SHFLSTRING *pOldPath, SHFLFSOBJINFO *pInfo) 2600 testSymlinkCreation(hTest); 2601 } 2602 #endif 2603 2604 int vbsfSymlink(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pSymlinkPath, SHFLSTRING *pSourcePath, SHFLFSOBJINFO *pInfo) 2603 2605 { 2604 2606 int rc = VINF_SUCCESS; 2605 2607 2606 char *pszFull NewPath = NULL;2607 char *pszFull OldPath = NULL;2608 char *pszFullSymlinkPath = NULL; 2609 char *pszFullSourcePath = NULL; 2608 2610 2609 2611 /* XXX: no support for UCS2 at the moment. */ … … 2617 2619 return VERR_WRITE_PROTECT; /* XXX or VERR_TOO_MANY_SYMLINKS? */ 2618 2620 2619 rc = vbsfBuildFullPath(pClient, root, pNewPath, pNewPath->u16Size + SHFLSTRING_HEADER_SIZE, &pszFullNewPath, NULL); 2620 AssertRCReturn(rc, rc); 2621 2622 /* Verify that the link target can be a valid host path, i.e. does not contain invalid characters. */ 2621 rc = vbsfBuildFullPath(pClient, root, pSymlinkPath, pSymlinkPath->u16Size + SHFLSTRING_HEADER_SIZE, &pszFullSymlinkPath, 2622 NULL); 2623 if (RT_FAILURE(rc)) 2624 return rc; 2625 2626 /* 2627 * The symbolic link source path may be located outside of the shared folder so thus 2628 * we don't call vbsfBuildFullPath() which includes VBSF_O_PATH_CHECK_ROOT_ESCAPE to 2629 * verify that the pathname resides within the shared folder. Instead we call the 2630 * heart of vbsfBuildFullPath() which is vbsfPathGuestToHost() to perform a subset 2631 * of its checks to verify that the symbolic link source is a valid path by checking 2632 * for invalid characters, replacing path delimiters if the guest uses a different 2633 * slash than the host, and evaluating the symbolic link policy if one has been set. 2634 * We don't collapse path components of '..' for example or alter the path otherwise 2635 * as this is the documented behavior of symbolic links: the source pathname can be 2636 * any pathname and isn't required to exist. 2637 */ 2623 2638 uint32_t fu32PathFlags = 0; 2624 uint32_t fu32Options = 0;2625 rc = vbsfPathGuestToHost(pClient, root, p OldPath, pOldPath->u16Size + SHFLSTRING_HEADER_SIZE,2626 &pszFull OldPath, NULL, fu32Options, &fu32PathFlags);2639 uint32_t fu32Options = VBSF_O_PATH_CHECK_SYMLINK_POLICY; 2640 rc = vbsfPathGuestToHost(pClient, root, pSourcePath, pSourcePath->u16Size + SHFLSTRING_HEADER_SIZE, 2641 &pszFullSourcePath, NULL, fu32Options, &fu32PathFlags); 2627 2642 if (RT_FAILURE(rc)) 2628 2643 { 2629 vbsfFreeFullPath(pszFull NewPath);2644 vbsfFreeFullPath(pszFullSymlinkPath); 2630 2645 return rc; 2631 2646 } 2632 2647 2633 /** @todo r=bird: We _must_ perform slash conversion on the target (what this 2634 * code calls 'pOldPath' for some peculiar reason)! */ 2635 2636 rc = RTSymlinkCreate(pszFullNewPath, (const char *)pOldPath->String.utf8, 2637 RTSYMLINKTYPE_UNKNOWN, 0); 2648 rc = RTSymlinkCreate(pszFullSymlinkPath, pszFullSourcePath, RTSYMLINKTYPE_UNKNOWN, 0); 2638 2649 if (RT_SUCCESS(rc)) 2639 2650 { 2640 2651 RTFSOBJINFO info; 2641 rc = RTPathQueryInfoEx(pszFull NewPath, &info, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);2652 rc = RTPathQueryInfoEx(pszFullSymlinkPath, &info, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK); 2642 2653 if (RT_SUCCESS(rc)) 2643 2654 vbfsCopyFsObjInfoFromIprt(pInfo, &info); 2644 2655 } 2645 2656 2646 vbsfFreeFullPath(pszFull OldPath);2647 vbsfFreeFullPath(pszFull NewPath);2657 vbsfFreeFullPath(pszFullSourcePath); 2658 vbsfFreeFullPath(pszFullSymlinkPath); 2648 2659 2649 2660 return rc; -
trunk/src/VBox/HostServices/SharedFolders/vbsfpath.cpp
r105018 r105087 54 54 # include <Carbon/Carbon.h> 55 55 #endif 56 #include <VBox/com/defs.h> /* For S_OK. */ 56 57 57 58 #ifdef UNITTEST … … 438 439 } 439 440 441 /** 442 * Validate the symbolic link creation policy inside a guest operating in a shared folder. 443 * 444 * @returns S_OK or VERR_WRITE_PROTECT. 445 * @param pchSymlinkPath The pathname of the symbolic link within the guest. 446 * @param enmSymlinkPolicy The symbolic link creation policy being evaluated. 447 * 448 * The enmSymlinkPolicy symlink creation policies are: 449 * - @a none: no policy set 450 * - @a any: no restrictions 451 * - @a forbidden: no symlinks allowed 452 * - @a relative: relative paths only ('..' path components allowed) 453 * - @a subtree: relative paths only within the shared folder (no '..' path components allowed) 454 */ 455 static int vbsfPathEvalSymlinkPolicy(const char *pchSymlinkPath, SymlinkPolicy_T enmSymlinkPolicy) 456 { 457 /* If no symlink policy has been set we continue the historical behaviour of applying no 458 * additional restrictions. The "any" policy also has no symlink path limitations. */ 459 if ( enmSymlinkPolicy == SymlinkPolicy_None 460 || enmSymlinkPolicy == SymlinkPolicy_AllowedToAnyTarget) 461 return S_OK; 462 463 /* No absolute paths allowed except for the "any" policy. The symlink path can't 464 * contain '..' components if the "subtree" policy in effect. */ 465 if ( RTPathStartsWithRoot(pchSymlinkPath) 466 || enmSymlinkPolicy == SymlinkPolicy_Forbidden 467 || ( enmSymlinkPolicy == SymlinkPolicy_AllowedInShareSubtree 468 && RTStrStr(pchSymlinkPath, ".."))) 469 return VERR_WRITE_PROTECT; 470 471 return S_OK; 472 } 473 440 474 int vbsfPathGuestToHost(SHFLCLIENTDATA *pClient, SHFLROOT hRoot, 441 475 PCSHFLSTRING pGuestString, uint32_t cbGuestString, … … 565 599 const char *pchSrc = pchGuestPath; 566 600 567 /* Strip leading delimiters from the path the guest specified. */ 568 while ( cbSrc > 0 569 && *pchSrc == pClient->PathDelimiter) 570 { 571 ++pchSrc; 572 --cbSrc; 601 /* when validating source file pathnames for symbolic links we don't modify the path */ 602 if (!(fu32Options & VBSF_O_PATH_CHECK_SYMLINK_POLICY)) 603 { 604 /* Strip leading delimiters from the path the guest specified. */ 605 while ( cbSrc > 0 606 && *pchSrc == pClient->PathDelimiter) 607 { 608 ++pchSrc; 609 --cbSrc; 610 } 573 611 } 574 612 … … 615 653 *pchDst++ = 0; 616 654 617 /* Construct the full host path removing '.' and '..'. */ 618 rc = vbsfPathAbs(pszRoot, pchVerifiedPath, pszFullPath, cbFullPathAlloc); 655 /* check if a symbolic link creation policy has been set */ 656 if (fu32Options & VBSF_O_PATH_CHECK_SYMLINK_POLICY) 657 { 658 /* copy the verified symlink source file path to be returned to the caller */ 659 rc = RTStrCopy(pszFullPath, cbFullPathAlloc, pchVerifiedPath); 660 if (RT_SUCCESS(rc)) 661 { 662 SymlinkPolicy_T enmSymlinkPolicy; 663 rc = vbsfMappingsQuerySymlinkPolicy(pClient, hRoot, &enmSymlinkPolicy); 664 if (RT_SUCCESS(rc)) 665 rc = vbsfPathEvalSymlinkPolicy(pchVerifiedPath, enmSymlinkPolicy); 666 } 667 } 668 else 669 { 670 /* Construct the full host path removing '.' and '..'. */ 671 rc = vbsfPathAbs(pszRoot, pchVerifiedPath, pszFullPath, cbFullPathAlloc); 672 } 619 673 if (RT_SUCCESS(rc)) 620 674 { … … 667 721 else 668 722 { 669 LogFunc(("vbsfPathAbs %Rrc\n", rc)); 723 if (fu32Options & VBSF_O_PATH_CHECK_SYMLINK_POLICY) 724 LogFunc(("vbsfPathEvalSymlinkPolicy() returns rc=%Rrc\n", rc)); 725 else 726 LogFunc(("vbsfPathAbs %Rrc\n", rc)); 670 727 } 671 728 } -
trunk/src/VBox/HostServices/SharedFolders/vbsfpath.h
r105018 r105087 38 38 #define VBSF_O_PATH_PRESERVE_LAST_COMPONENT UINT32_C(0x00000002) 39 39 #define VBSF_O_PATH_CHECK_ROOT_ESCAPE UINT32_C(0x00000004) 40 #define VBSF_O_PATH_CHECK_SYMLINK_POLICY UINT32_C(0x00000008) 40 41 41 42 #define VBSF_F_PATH_HAS_WILDCARD_IN_PREFIX UINT32_C(0x00000001) /* A component before the last one contains a wildcard. */
Note:
See TracChangeset
for help on using the changeset viewer.