diff options
| author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-03-26 19:21:20 +0000 |
|---|---|---|
| committer | <> | 2014-05-08 15:03:54 +0000 |
| commit | fb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch) | |
| tree | c2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/HostServices/SharedFolders | |
| parent | 58ed4748338f9466599adfc8a9171280ed99e23f (diff) | |
| download | VirtualBox-master.tar.gz | |
Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2.HEADVirtualBox-4.3.10master
Diffstat (limited to 'src/VBox/HostServices/SharedFolders')
11 files changed, 82 insertions, 59 deletions
diff --git a/src/VBox/HostServices/SharedFolders/mappings.cpp b/src/VBox/HostServices/SharedFolders/mappings.cpp index 166dd049..30310909 100644 --- a/src/VBox/HostServices/SharedFolders/mappings.cpp +++ b/src/VBox/HostServices/SharedFolders/mappings.cpp @@ -3,7 +3,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -191,7 +191,7 @@ void testMappingsAdd(RTTEST hTest) * We are always executed from one specific HGCM thread. So thread safe. */ int vbsfMappingsAdd(PSHFLSTRING pFolderName, PSHFLSTRING pMapName, - bool fWritable, bool fAutoMount, bool fSymlinksCreate) + bool fWritable, bool fAutoMount, bool fSymlinksCreate, bool fMissing) { unsigned i; @@ -236,6 +236,7 @@ int vbsfMappingsAdd(PSHFLSTRING pFolderName, PSHFLSTRING pMapName, FolderMapping[i].fWritable = fWritable; FolderMapping[i].fAutoMount = fAutoMount; FolderMapping[i].fSymlinksCreate = fSymlinksCreate; + FolderMapping[i].fMissing = fMissing; /* Check if the host file system is case sensitive */ RTFSPROPERTIES prop; @@ -317,6 +318,8 @@ const char* vbsfMappingsQueryHostRoot(SHFLROOT root) { MAPPING *pFolderMapping = vbsfMappingGetByRoot(root); AssertReturn(pFolderMapping, NULL); + if (pFolderMapping->fMissing) + return NULL; return pFolderMapping->pszFolderName; } @@ -459,7 +462,8 @@ int vbsfMappingsQueryWritable(PSHFLCLIENTDATA pClient, SHFLROOT root, bool *fWri MAPPING *pFolderMapping = vbsfMappingGetByRoot(root); AssertReturn(pFolderMapping, VERR_INVALID_PARAMETER); - if (pFolderMapping->fValid == true) + if ( pFolderMapping->fValid + && !pFolderMapping->fMissing) *fWritable = pFolderMapping->fWritable; else rc = VERR_FILE_NOT_FOUND; diff --git a/src/VBox/HostServices/SharedFolders/mappings.h b/src/VBox/HostServices/SharedFolders/mappings.h index f920e617..c0a2989f 100644 --- a/src/VBox/HostServices/SharedFolders/mappings.h +++ b/src/VBox/HostServices/SharedFolders/mappings.h @@ -3,7 +3,7 @@ */ /* - * Copyright (C) 2006-2010 Oracle Corporation + * Copyright (C) 2006-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -31,6 +31,8 @@ typedef struct bool fWritable; /**< folder is writable for the guest */ bool fAutoMount; /**< folder will be auto-mounted by the guest */ bool fSymlinksCreate; /**< guest is able to create symlinks */ + bool fMissing; /**< mapping not invalid but host path does not exist. + Any guest operation on such a folder fails! */ } MAPPING; /** Pointer to a MAPPING structure. */ typedef MAPPING *PMAPPING; @@ -40,7 +42,7 @@ void vbsfMappingInit(void); bool vbsfMappingQuery(uint32_t iMapping, PMAPPING *pMapping); int vbsfMappingsAdd(PSHFLSTRING pFolderName, PSHFLSTRING pMapName, - bool fWritable, bool fAutoMount, bool fCreateSymlinks); + bool fWritable, bool fAutoMount, bool fCreateSymlinks, bool fMissing); int vbsfMappingsRemove(PSHFLSTRING pMapName); int vbsfMappingsQuery(PSHFLCLIENTDATA pClient, PSHFLMAPPING pMappings, uint32_t *pcMappings); diff --git a/src/VBox/HostServices/SharedFolders/service.cpp b/src/VBox/HostServices/SharedFolders/service.cpp index bc390aeb..0c724f33 100644 --- a/src/VBox/HostServices/SharedFolders/service.cpp +++ b/src/VBox/HostServices/SharedFolders/service.cpp @@ -3,7 +3,7 @@ */ /* - * Copyright (C) 2006-2010 Oracle Corporation + * Copyright (C) 2006-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -1313,18 +1313,20 @@ static DECLCALLBACK(int) svcHostCall (void *, uint32_t u32Function, uint32_t cPa } else { - LogRel((" Host path '%ls', map name '%ls', %s, automount=%s, create_symlinks=%s\n", + LogRel((" Host path '%ls', map name '%ls', %s, automount=%s, create_symlinks=%s, missing=%s\n", ((SHFLSTRING *)paParms[0].u.pointer.addr)->String.ucs2, ((SHFLSTRING *)paParms[1].u.pointer.addr)->String.ucs2, RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_WRITABLE) ? "writable" : "read-only", RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_AUTOMOUNT) ? "true" : "false", - RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_CREATE_SYMLINKS) ? "true" : "false")); + RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_CREATE_SYMLINKS) ? "true" : "false", + RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_MISSING) ? "true" : "false")); /* Execute the function. */ rc = vbsfMappingsAdd(pFolderName, pMapName, RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_WRITABLE), RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_AUTOMOUNT), - RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_CREATE_SYMLINKS)); + RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_CREATE_SYMLINKS), + RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_MISSING)); if (RT_SUCCESS(rc)) { /* Update parameters.*/ diff --git a/src/VBox/HostServices/SharedFolders/shflhandle.cpp b/src/VBox/HostServices/SharedFolders/shflhandle.cpp index cd67057b..1a5f71bd 100644 --- a/src/VBox/HostServices/SharedFolders/shflhandle.cpp +++ b/src/VBox/HostServices/SharedFolders/shflhandle.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostServices/SharedFolders/shflhandle.h b/src/VBox/HostServices/SharedFolders/shflhandle.h index 625c0102..59638b91 100644 --- a/src/VBox/HostServices/SharedFolders/shflhandle.h +++ b/src/VBox/HostServices/SharedFolders/shflhandle.h @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostServices/SharedFolders/testcase/Makefile.kmk b/src/VBox/HostServices/SharedFolders/testcase/Makefile.kmk index a6f327ef..a2f6120d 100644 --- a/src/VBox/HostServices/SharedFolders/testcase/Makefile.kmk +++ b/src/VBox/HostServices/SharedFolders/testcase/Makefile.kmk @@ -54,12 +54,7 @@ tstShflCase_LIBS = $(LIB_RUNTIME) # HGCM service testcase. # -# As there are differences between the Windows build of the service and others, -# we do an additional build with RT_OS_WINDOWS defined on non-Windows targets. -PROGRAMS += \ - tstSharedFolderService \ - $(if $(eq $(KBUILD_TARGET),win),,tstSharedFolderService-win) - +PROGRAMS += tstSharedFolderService tstSharedFolderService_TEMPLATE = VBOXR3TSTEXE tstSharedFolderService_DEFS = VBOX_WITH_HGCM UNITTEST tstSharedFolderService_INCS = .. @@ -73,6 +68,12 @@ tstSharedFolderService_LDFLAGS.darwin = \ -framework Carbon tstSharedFolderService_LIBS = $(LIB_RUNTIME) +if 0 # Cannot define two RT_OS_XXX macros! +# As there are differences between the Windows build of the service and others, +# we do an additional build with RT_OS_WINDOWS defined on non-Windows targets. +PROGRAMS += \ + tstSharedFolderService \ + $(if $(eq $(KBUILD_TARGET),win),,tstSharedFolderService-win) tstSharedFolderService-win_TEMPLATE = $(tstSharedFolderService_TEMPLATE) tstSharedFolderService-win_DEFS = \ $(tstSharedFolderService_DEFS) \ @@ -82,6 +83,7 @@ tstSharedFolderService-win_SOURCES = $(tstSharedFolderService_SOURCES) tstSharedFolderService-win_LDFLAGS.darwin = \ $(tstSharedFolderService_LDFLAGS.darwin) tstSharedFolderService-win_LIBS = $(tstSharedFolderService_LIBS) +endif endif # VBOX_WITH_TESTCASES diff --git a/src/VBox/HostServices/SharedFolders/testcase/tstSharedFolderService.cpp b/src/VBox/HostServices/SharedFolders/testcase/tstSharedFolderService.cpp index b72e724b..1215090a 100644 --- a/src/VBox/HostServices/SharedFolders/testcase/tstSharedFolderService.cpp +++ b/src/VBox/HostServices/SharedFolders/testcase/tstSharedFolderService.cpp @@ -1,6 +1,5 @@ /* $Id: tstSharedFolderService.cpp $ */ /** @file - * * Testcase for the shared folder service vbsf API. * * Note that this is still very threadbare (there is an awful lot which should @@ -11,7 +10,7 @@ */ /* - * Copyright (C) 2011 Oracle Corporation + * Copyright (C) 2011-2013 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -39,17 +38,19 @@ #include "teststubs.h" + /****************************************************************************** * Global Variables * ******************************************************************************/ static RTTEST g_hTest = NIL_RTTEST; + /****************************************************************************** * Declarations * ******************************************************************************/ - extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad (VBOXHGCMSVCFNTABLE *ptable); + /****************************************************************************** * Helpers * ******************************************************************************/ @@ -102,14 +103,15 @@ static void bufferFromPath(void *pvDest, size_t cb, const char *pcszSrc) } #define ARRAY_FROM_PATH(a, b) \ -do { \ - Assert((a) == (a)); /* Constant parameter */ \ - Assert(sizeof((a)) > 0); \ - bufferFromPath(a, sizeof(a), b); \ -} while(0) + do { \ + Assert((a) == (a)); /* Constant parameter */ \ + Assert(sizeof((a)) > 0); \ + bufferFromPath(a, sizeof(a), b); \ + } while (0) + /****************************************************************************** -* Stub functions * +* Stub functions and data * ******************************************************************************/ static PRTDIR testRTDirClosepDir; @@ -306,7 +308,7 @@ static uint64_t testRTFileSetFMode; extern int testRTFileSetMode(RTFILE File, RTFMODE fMode) { /* RTPrintf("%s: fMode=%llu\n", __PRETTY_FUNCTION__, LLUIFY(fMode)); */ - testRTFileSetFMode = fMode; + testRTFileSetFMode = fMode; return VINF_SUCCESS; } @@ -369,7 +371,7 @@ extern int testRTFileWrite(RTFILE File, const void *pvBuf, size_t cbToWrite, *pcbWritten = strlen(testRTFileWriteData) + 1; return VINF_SUCCESS; } - + extern int testRTFsQueryProperties(const char *pszFsPath, PRTFSPROPERTIES pProperties) { @@ -383,7 +385,7 @@ extern int testRTFsQueryProperties(const char *pszFsPath, extern int testRTFsQuerySerial(const char *pszFsPath, uint32_t *pu32Serial) { RTPrintf("%s\n", __PRETTY_FUNCTION__); return 0; } extern int testRTFsQuerySizes(const char *pszFsPath, PRTFOFF pcbTotal, - RTFOFF *pcbFree, uint32_t *pcbBlock, + RTFOFF *pcbFree, uint32_t *pcbBlock, uint32_t *pcbSector) { RTPrintf("%s\n", __PRETTY_FUNCTION__); return 0; } extern int testRTPathQueryInfoEx(const char *pszPath, @@ -398,12 +400,13 @@ extern int testRTPathQueryInfoEx(const char *pszPath, return VINF_SUCCESS; } -extern int testRTSymlinkDelete(const char *pszSymlink, uint32_t fDelete) +extern int testRTSymlinkDelete(const char *pszSymlink, uint32_t fDelete) { RTPrintf("%s\n", __PRETTY_FUNCTION__); return 0; } extern int testRTSymlinkRead(const char *pszSymlink, char *pszTarget, size_t cbTarget, uint32_t fRead) { RTPrintf("%s\n", __PRETTY_FUNCTION__); return 0; } + /****************************************************************************** * Tests * ******************************************************************************/ @@ -484,13 +487,11 @@ struct TESTSHFLSTRING static void fillTestShflString(struct TESTSHFLSTRING *pDest, const char *pcszSource) { - unsigned i; - - AssertRelease( strlen(pcszSource) * 2 + 2 < sizeof(*pDest) - - RT_UOFFSETOF(SHFLSTRING, String)); - pDest->string.u16Size = (uint16_t)strlen(pcszSource) * 2 + 2; - pDest->string.u16Length = (uint16_t)strlen(pcszSource); - for (i = 0; i < strlen(pcszSource) + 1; ++i) + AssertRelease( strlen(pcszSource) * 2 + 2 + < sizeof(*pDest) - RT_UOFFSETOF(SHFLSTRING, String)); + pDest->string.u16Length = (uint16_t)(strlen(pcszSource) * sizeof(RTUTF16)); + pDest->string.u16Size = pDest->string.u16Length + sizeof(RTUTF16); + for (unsigned i = 0; i <= pDest->string.u16Length; ++i) pDest->string.String.ucs2[i] = (uint16_t)pcszSource[i]; } diff --git a/src/VBox/HostServices/SharedFolders/testcase/tstShflSizes.cpp b/src/VBox/HostServices/SharedFolders/testcase/tstShflSizes.cpp index 96d27cfa..ce94fdb4 100644 --- a/src/VBox/HostServices/SharedFolders/testcase/tstShflSizes.cpp +++ b/src/VBox/HostServices/SharedFolders/testcase/tstShflSizes.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2010 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostServices/SharedFolders/teststubs.h b/src/VBox/HostServices/SharedFolders/teststubs.h index 3be52fcc..54c9ef4a 100644 --- a/src/VBox/HostServices/SharedFolders/teststubs.h +++ b/src/VBox/HostServices/SharedFolders/teststubs.h @@ -3,7 +3,7 @@ */ /* - * Copyright (C) 2011 Oracle Corporation + * Copyright (C) 2011-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostServices/SharedFolders/vbsf.cpp b/src/VBox/HostServices/SharedFolders/vbsf.cpp index 617239b8..935e94ce 100644 --- a/src/VBox/HostServices/SharedFolders/vbsf.cpp +++ b/src/VBox/HostServices/SharedFolders/vbsf.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2011 Oracle Corporation + * Copyright (C) 2006-2013 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -183,15 +183,24 @@ end: } /** - * Do a simple path check given by pUtf8Path. Verify that the path is within - * the root directory of the mapping. Count '..' and other path components - * and check that we do not go over the root. + * Check the given UTF-8 path for root escapes. + * + * Verify that the path is within the root directory of the mapping. Count '..' + * and other path components and check that we do not go over the root. + * + * @returns VBox status code. + * @retval VINF_SUCCESS + * @retval VERR_INVALID_NAME + * + * @param pUtf8Path The path to check. + * @param cchPath The length of the path in chars (not code points, but + * the C type) excluding the string terminator. * * @remarks This function assumes that the path will be appended to the root - * directory of the shared folder mapping. Keep that in mind when checking - * absolute pathes! + * directory of the shared folder mapping. Keep that in mind when + * checking absolute paths! */ -static int vbsfPathCheck(const char *pUtf8Path, size_t cbPath) +static int vbsfPathCheck(const char *pUtf8Path, size_t cchPath) { int rc = VINF_SUCCESS; @@ -202,42 +211,42 @@ static int vbsfPathCheck(const char *pUtf8Path, size_t cbPath) for (;;) { /* Skip leading path delimiters. */ - while ( i < cbPath + while ( i < cchPath && (pUtf8Path[i] == '\\' || pUtf8Path[i] == '/')) i++; - if (i >= cbPath) + if (i >= cchPath) break; /* Check if that is a dot component. */ int cDots = 0; - while (i < cbPath && pUtf8Path[i] == '.') + while (i < cchPath && pUtf8Path[i] == '.') { cDots++; i++; } if ( cDots >= 2 /* Consider all multidots sequences as a 'parent dir'. */ - && (i >= cbPath || (pUtf8Path[i] == '\\' || pUtf8Path[i] == '/'))) + && (i >= cchPath || (pUtf8Path[i] == '\\' || pUtf8Path[i] == '/'))) { cParentDirs++; } else if ( cDots == 1 - && (i >= cbPath || (pUtf8Path[i] == '\\' || pUtf8Path[i] == '/'))) + && (i >= cchPath || (pUtf8Path[i] == '\\' || pUtf8Path[i] == '/'))) { /* Single dot, nothing changes. */ } else { /* Skip this component. */ - while ( i < cbPath + while ( i < cchPath && (pUtf8Path[i] != '\\' && pUtf8Path[i] != '/')) i++; cComponents++; } - Assert(i >= cbPath || (pUtf8Path[i] == '\\' || pUtf8Path[i] == '/')); + Assert(i >= cchPath || (pUtf8Path[i] == '\\' || pUtf8Path[i] == '/')); /* Verify counters for every component. */ if (cParentDirs > cComponents) @@ -283,6 +292,7 @@ static int vbsfBuildFullPath(SHFLCLIENTDATA *pClient, SHFLROOT root, PSHFLSTRING } else { + /** @todo r-bird: Pardon me for asking, but who validates the UTF-8 encoding?*/ memcpy(utf8FullPath, pszRoot, cbRoot); utf8FullPath[cbRoot] = '/'; memcpy(utf8FullPath + cbRoot + 1, &pPath->String.utf8[0], pPath->u16Length); @@ -295,7 +305,7 @@ static int vbsfBuildFullPath(SHFLCLIENTDATA *pClient, SHFLROOT root, PSHFLSTRING } else { - Log(("vbsfBuildFullPath: RTUtf16ToUtf8 failed with %Rrc\n", rc)); + Log(("vbsfBuildFullPath: vbsfPathCheck failed with %Rrc\n", rc)); } } else @@ -368,6 +378,7 @@ static int vbsfBuildFullPath(SHFLCLIENTDATA *pClient, SHFLROOT root, PSHFLSTRING if (pPath->u16Length) { /* Convert and copy components. */ + size_t cwcSrc = pPath->u16Length / sizeof(RTUTF16); PRTUTF16 pwszSrc = &pPath->String.ucs2[0]; /* Correct path delimiters */ @@ -384,9 +395,12 @@ static int vbsfBuildFullPath(SHFLCLIENTDATA *pClient, SHFLROOT root, PSHFLSTRING LogFlow(("Corrected string %ls\n", pwszSrc)); } if (*pwszSrc == RTPATH_DELIMITER) + { pwszSrc++; /* we already appended a delimiter to the first part */ + cwcSrc--; + } - rc = RTUtf16ToUtf8Ex(pwszSrc, RTSTR_MAX, &pszDst, cb, NULL); + rc = RTUtf16ToUtf8Ex(pwszSrc, cwcSrc, &pszDst, cb, &cbDst); if (RT_FAILURE(rc)) { AssertFailed(); @@ -396,8 +410,7 @@ static int vbsfBuildFullPath(SHFLCLIENTDATA *pClient, SHFLROOT root, PSHFLSTRING #endif return rc; } - - cbDst = (uint32_t)strlen(pszDst); + Assert(cbDst == strlen(pszDst)); /* Verify that the path is under the root directory. */ rc = vbsfPathCheck(pszDst, cbDst); @@ -405,7 +418,6 @@ static int vbsfBuildFullPath(SHFLCLIENTDATA *pClient, SHFLROOT root, PSHFLSTRING { #ifdef RT_OS_DARWIN RTMemFree(pPath); - pPath = pPathParameter; #endif return rc; } diff --git a/src/VBox/HostServices/SharedFolders/vbsf.h b/src/VBox/HostServices/SharedFolders/vbsf.h index 76979681..0151a223 100644 --- a/src/VBox/HostServices/SharedFolders/vbsf.h +++ b/src/VBox/HostServices/SharedFolders/vbsf.h @@ -3,7 +3,7 @@ */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; |
