VirtualBox

Ignore:
Timestamp:
Dec 16, 2011 10:54:38 AM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
75443
Message:

SharedFolders: more fixes

Location:
trunk/src/VBox/HostServices/SharedFolders
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedFolders/mappings.cpp

    r39607 r39643  
    192192 */
    193193int vbsfMappingsAdd(PSHFLSTRING pFolderName, PSHFLSTRING pMapName,
    194                     uint32_t fWritable, uint32_t fAutoMount)
     194                    bool fWritable, bool fAutoMount, bool fSymlinksCreate)
    195195{
    196196    unsigned i;
     
    232232            memcpy(FolderMapping[i].pMapName->String.ucs2, pMapName->String.ucs2, pMapName->u16Size);
    233233
    234             FolderMapping[i].fValid     = true;
    235             FolderMapping[i].cMappings  = 0;
    236             FolderMapping[i].fWritable  = !!fWritable;
    237             FolderMapping[i].fAutoMount = !!fAutoMount;
     234            FolderMapping[i].fValid          = true;
     235            FolderMapping[i].cMappings       = 0;
     236            FolderMapping[i].fWritable       = fWritable;
     237            FolderMapping[i].fAutoMount      = fAutoMount;
     238            FolderMapping[i].fSymlinksCreate = fSymlinksCreate;
    238239
    239240            /* Check if the host file system is case sensitive */
     
    444445    int rc = VINF_SUCCESS;
    445446
    446     LogFlow(("vbsfMappingsQueryWritable: pClient = %p, root = %d\n",
    447              pClient, root));
    448 
    449     MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
    450     if (pFolderMapping == NULL)
    451     {
    452         return VERR_INVALID_PARAMETER;
    453     }
     447    LogFlow(("vbsfMappingsQueryWritable: pClient = %p, root = %d\n", pClient, root));
     448
     449    MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
     450    AssertReturn(pFolderMapping, VERR_INVALID_PARAMETER);
    454451
    455452    if (pFolderMapping->fValid == true)
     
    467464    int rc = VINF_SUCCESS;
    468465
    469     LogFlow(("vbsfMappingsQueryAutoMount: pClient = %p, root = %d\n",
    470              pClient, root));
    471 
    472     MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
    473     if (pFolderMapping == NULL)
    474     {
    475         return VERR_INVALID_PARAMETER;
    476     }
     466    LogFlow(("vbsfMappingsQueryAutoMount: pClient = %p, root = %d\n", pClient, root));
     467
     468    MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
     469    AssertReturn(pFolderMapping, VERR_INVALID_PARAMETER);
    477470
    478471    if (pFolderMapping->fValid == true)
     
    482475
    483476    LogFlow(("vbsfMappingsQueryAutoMount:Writable return rc = %Rrc\n", rc));
     477
     478    return rc;
     479}
     480
     481int vbsfMappingsQuerySymlinksCreate(PSHFLCLIENTDATA pClient, SHFLROOT root, bool *fSymlinksCreate)
     482{
     483    int rc = VINF_SUCCESS;
     484
     485    LogFlow(("vbsfMappingsQueryAutoMount: pClient = %p, root = %d\n", pClient, root));
     486
     487    MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
     488    AssertReturn(pFolderMapping, VERR_INVALID_PARAMETER);
     489
     490    if (pFolderMapping->fValid == true)
     491        *fSymlinksCreate = pFolderMapping->fSymlinksCreate;
     492    else
     493        rc = VERR_FILE_NOT_FOUND;
     494
     495    LogFlow(("vbsfMappingsQueryAutoMount:SymlinksCreate return rc = %Rrc\n", rc));
    484496
    485497    return rc;
  • trunk/src/VBox/HostServices/SharedFolders/mappings.h

    r39607 r39643  
    2323typedef struct
    2424{
    25     char        *pszFolderName;
    26     PSHFLSTRING pMapName;
    27     uint32_t    cMappings;
    28     bool        fValid;
    29     bool        fHostCaseSensitive;
    30     bool        fGuestCaseSensitive;
    31     bool        fWritable;
    32     bool        fAutoMount;
     25    char        *pszFolderName;       /**< directory at the host to share with the guest */
     26    PSHFLSTRING pMapName;             /**< share name for the guest */
     27    uint32_t    cMappings;            /**< number of mappings */
     28    bool        fValid;               /**< mapping entry is used/valid */
     29    bool        fHostCaseSensitive;   /**< host file name space is case-sensitive */
     30    bool        fGuestCaseSensitive;  /**< guest file name space is case-sensitive */
     31    bool        fWritable;            /**< folder is writable for the guest */
     32    bool        fAutoMount;           /**< folder will be auto-mounted by the guest */
     33    bool        fSymlinksCreate;      /**< guest is able to create symlinks */
    3334} MAPPING;
    3435/** Pointer to a MAPPING structure. */
     
    3940bool vbsfMappingQuery(uint32_t iMapping, PMAPPING *pMapping);
    4041
    41 int vbsfMappingsAdd(PSHFLSTRING pFolderName, PSHFLSTRING pMapName, uint32_t fWritable, uint32_t fAutoMount);
     42int vbsfMappingsAdd(PSHFLSTRING pFolderName, PSHFLSTRING pMapName,
     43                    bool fWritable, bool fAutoMount, bool fCreateSymlinks);
    4244int vbsfMappingsRemove(PSHFLSTRING pMapName);
    4345
     
    4547int vbsfMappingsQueryName(PSHFLCLIENTDATA pClient, SHFLROOT root, SHFLSTRING *pString);
    4648int vbsfMappingsQueryWritable(PSHFLCLIENTDATA pClient, SHFLROOT root, bool *fWritable);
     49int vbsfMappingsQueryAutoMount(PSHFLCLIENTDATA pClient, SHFLROOT root, bool *fAutoMount);
     50int vbsfMappingsQuerySymlinksCreate(PSHFLCLIENTDATA pClient, SHFLROOT root, bool *fSymlinksCreate);
    4751
    48 int vbsfMapFolder(PSHFLCLIENTDATA pClient, PSHFLSTRING pszMapName, RTUTF16 delimiter, bool fCaseSensitive, SHFLROOT *pRoot);
     52int vbsfMapFolder(PSHFLCLIENTDATA pClient, PSHFLSTRING pszMapName, RTUTF16 delimiter,
     53                  bool fCaseSensitive, SHFLROOT *pRoot);
    4954int vbsfUnmapFolder(PSHFLCLIENTDATA pClient, SHFLROOT root);
    5055
  • trunk/src/VBox/HostServices/SharedFolders/service.cpp

    r39628 r39643  
    12591259
    12601260/*
    1261  * We differentiate between a function handler for the guest and one for the host. The guest is not allowed to add or remove mappings for obvious security reasons.
     1261 * We differentiate between a function handler for the guest (svcCall) and one
     1262 * for the host. The guest is not allowed to add or remove mappings for obvious
     1263 * security reasons.
    12621264 */
    12631265static DECLCALLBACK(int) svcHostCall (void *, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
     
    12831285        Log(("SharedFolders host service: svcCall: SHFL_FN_ADD_MAPPING\n"));
    12841286        LogRel(("SharedFolders host service: adding host mapping\n"));
    1285         LogRel(("    Host path '%ls', map name '%ls', %s\n",
    1286                 ((SHFLSTRING *)paParms[0].u.pointer.addr)->String.ucs2,
    1287                 ((SHFLSTRING *)paParms[1].u.pointer.addr)->String.ucs2,
    1288                 paParms[2].u.uint32 ? "writable" : "read-only"));
    1289 
    12901287        /* Verify parameter count and types. */
    12911288        if (   (cParms != SHFL_CPARMS_ADD_MAPPING)
    1292             && (cParms != SHFL_CPARMS_ADD_MAPPING2) /* With auto-mount flag. */
    12931289           )
    12941290        {
     
    12971293        else if (   paParms[0].type != VBOX_HGCM_SVC_PARM_PTR     /* host folder name */
    12981294                 || paParms[1].type != VBOX_HGCM_SVC_PARM_PTR     /* guest map name */
    1299                  || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT   /* fWritable */
    1300                  /* With auto-mount flag? */
    1301                  || (   cParms == SHFL_CPARMS_ADD_MAPPING2
    1302                      && paParms[3].type != VBOX_HGCM_SVC_PARM_32BIT))
     1295                 || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT   /* fFlags */
     1296                )
    13031297        {
    13041298            rc = VERR_INVALID_PARAMETER;
     
    13091303            SHFLSTRING *pFolderName = (SHFLSTRING *)paParms[0].u.pointer.addr;
    13101304            SHFLSTRING *pMapName    = (SHFLSTRING *)paParms[1].u.pointer.addr;
    1311             uint32_t fWritable      = paParms[2].u.uint32;
    1312             uint32_t fAutoMount     = 0; /* Disabled by default. */
    1313 
    1314             /* Handle auto-mount flag if present. */
    1315             if (cParms == SHFL_CPARMS_ADD_MAPPING2)
    1316                 fAutoMount = paParms[3].u.uint32;
     1305            uint32_t fFlags         = paParms[2].u.uint32;
    13171306
    13181307            /* Verify parameters values. */
     
    13251314            else
    13261315            {
     1316                LogRel(("    Host path '%ls', map name '%ls', %s, automount=%s, create_symlinks=%s\n",
     1317                        ((SHFLSTRING *)paParms[0].u.pointer.addr)->String.ucs2,
     1318                        ((SHFLSTRING *)paParms[1].u.pointer.addr)->String.ucs2,
     1319                        RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_WRITABLE) ? "writable" : "read-only",
     1320                        RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_AUTOMOUNT) ? "true" : "false",
     1321                        RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_CREATE_SYMLINKS) ? "true" : "false"));
     1322
    13271323                /* Execute the function. */
    1328                 rc = vbsfMappingsAdd(pFolderName, pMapName, fWritable, fAutoMount);
     1324                rc = vbsfMappingsAdd(pFolderName, pMapName,
     1325                                     RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_WRITABLE),
     1326                                     RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_AUTOMOUNT),
     1327                                     RT_BOOL(fFlags & SHFL_ADD_MAPPING_F_CREATE_SYMLINKS));
    13291328                if (RT_SUCCESS(rc))
    13301329                {
  • trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp

    r39630 r39643  
    4242#endif
    4343
     44#define SHFL_RT_LINK(pClient) ((pClient)->fu32Flags & SHFL_CF_SYMLINKS ? RTPATH_F_ON_LINK : RTPATH_F_FOLLOW_LINK)
    4445
    4546/**
     
    136137    strcat(pDirEntry->szName, szWildCard);
    137138
    138     rc = RTDirOpenFiltered(&hSearch, pDirEntry->szName, RTDIRFILTER_WINNT, RTDIROPEN_FLAGS_NO_SYMLINKS);
     139    rc = RTDirOpenFiltered(&hSearch, pDirEntry->szName, RTDIRFILTER_WINNT, 0);
    139140    *(pszStartComponent-1) = RTPATH_DELIMITER;
    140141    if (RT_FAILURE(rc))
     
    145146        size_t cbDirEntrySize = cbDirEntry;
    146147
    147         rc = RTDirReadEx(hSearch, pDirEntry, &cbDirEntrySize, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
     148        rc = RTDirReadEx(hSearch, pDirEntry, &cbDirEntrySize, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient));
    148149        if (rc == VERR_NO_MORE_FILES)
    149150            break;
     
    473474
    474475            /** @todo don't check when creating files or directories; waste of time */
    475             rc = RTPathQueryInfoEx(pszFullPath, &info, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
     476            rc = RTPathQueryInfoEx(pszFullPath, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient));
    476477            if (rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND)
    477478            {
     
    487488                    {
    488489                        *pszSrc = 0;
    489                         rc = RTPathQueryInfoEx(pszFullPath, &info, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
     490                        rc = RTPathQueryInfoEx(pszFullPath, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient));
    490491                        *pszSrc = RTPATH_DELIMITER;
    491492                        if (RT_SUCCESS(rc))
     
    523524                            fEndOfString = false;
    524525                            *pszEnd = 0;
    525                             rc = RTPathQueryInfoEx(pszSrc, &info, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
     526                            rc = RTPathQueryInfoEx(pszSrc, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient));
    526527                            Assert(rc == VINF_SUCCESS || rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND);
    527528                        }
     
    585586static int vbsfConvertFileOpenFlags(unsigned fShflFlags, RTFMODE fMode, SHFLHANDLE handleInitial, uint32_t *pfOpen)
    586587{
    587     uint32_t fOpen = RTFILE_O_NO_SYMLINKS;
     588    uint32_t fOpen = 0;
    588589    int rc = VINF_SUCCESS;
    589590
     
    863864
    864865            /** @todo Possible race left here. */
    865             if (RT_SUCCESS(RTPathQueryInfoEx(pszPath, &info, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK)))
     866            if (RT_SUCCESS(RTPathQueryInfoEx(pszPath, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient))))
    866867            {
    867868#ifdef RT_OS_WINDOWS
     
    10141015
    10151016            pParms->Result = SHFL_FILE_CREATED;
    1016             rc = RTDirCreate(pszPath, fMode, RTDIRCREATE_FLAGS_NO_SYMLINKS);
     1017            rc = RTDirCreate(pszPath, fMode, 0);
    10171018            if (RT_FAILURE(rc))
    10181019            {
     
    10341035        {
    10351036            /* Open the directory now */
    1036             rc = RTDirOpenFiltered(&pHandle->dir.Handle, pszPath,
    1037                                    RTDIRFILTER_NONE, RTDIROPEN_FLAGS_NO_SYMLINKS);
     1037            rc = RTDirOpenFiltered(&pHandle->dir.Handle, pszPath, RTDIRFILTER_NONE, 0);
    10381038            if (RT_SUCCESS(rc))
    10391039            {
     
    11381138    int rc;
    11391139
    1140     rc = RTPathQueryInfoEx(pszPath, &info, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
     1140    rc = RTPathQueryInfoEx(pszPath, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient));
    11411141    LogFlow(("SHFL_CF_LOOKUP\n"));
    11421142    /* Client just wants to know if the object exists. */
     
    12431243            RTFSOBJINFO info;
    12441244
    1245             rc = RTPathQueryInfoEx(pszFullPath, &info, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
     1245            rc = RTPathQueryInfoEx(pszFullPath, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient));
    12461246            LogFlow(("RTPathQueryInfoEx returned %Rrc\n", rc));
    12471247
     
    15481548            if (RT_SUCCESS(rc))
    15491549            {
    1550                 rc = RTDirOpenFiltered(&pHandle->dir.SearchHandle, pszFullPath,
    1551                                        RTDIRFILTER_WINNT, RTDIROPEN_FLAGS_NO_SYMLINKS);
     1550                rc = RTDirOpenFiltered(&pHandle->dir.SearchHandle, pszFullPath, RTDIRFILTER_WINNT, 0);
    15521551
    15531552                /* free the path string */
     
    15781577            pDirEntry = pDirEntryOrg;
    15791578
    1580             rc = RTDirReadEx(DirHandle, pDirEntry, &cbDirEntrySize, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
     1579            rc = RTDirReadEx(DirHandle, pDirEntry, &cbDirEntrySize, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient));
    15811580            if (rc == VERR_NO_MORE_FILES)
    15821581            {
     
    17321731    if (RT_SUCCESS(rc))
    17331732    {
    1734         rc = RTSymlinkRead(pszFullPath, (char *) pBuffer, cbBuffer, RTSYMLINKREAD_FLAGS_NO_SYMLINKS);
     1733        rc = RTSymlinkRead(pszFullPath, (char *) pBuffer, cbBuffer, 0);
    17351734
    17361735        /* free the path string */
     
    21792178        {
    21802179            if (flags & SHFL_REMOVE_SYMLINK)
    2181                 rc = RTSymlinkDelete(pszFullPath, RTSYMLINKDELETE_FLAGS_NO_SYMLINKS);
     2180                rc = RTSymlinkDelete(pszFullPath, 0);
    21822181            else if (flags & SHFL_REMOVE_FILE)
    21832182                rc = RTFileDelete(pszFullPath);
     
    22462245            {
    22472246                rc = RTFileMove(pszFullPathSrc, pszFullPathDest,
    2248                                   ((flags & SHFL_RENAME_REPLACE_IF_EXISTS) ? RTFILEMOVE_FLAGS_REPLACE : 0)
    2249                                 | RTFILEMOVE_FLAGS_NO_SYMLINKS);
     2247                                  ((flags & SHFL_RENAME_REPLACE_IF_EXISTS) ? RTFILEMOVE_FLAGS_REPLACE : 0));
    22502248            }
    22512249            else
     
    22532251                /* NT ignores the REPLACE flag and simply return and already exists error. */
    22542252                rc = RTDirRename(pszFullPathSrc, pszFullPathDest,
    2255                                    ((flags & SHFL_RENAME_REPLACE_IF_EXISTS) ? RTPATHRENAME_FLAGS_REPLACE : 0)
    2256                                  | RTPATHRENAME_FLAGS_NO_SYMLINKS);
     2253                                   ((flags & SHFL_RENAME_REPLACE_IF_EXISTS) ? RTPATHRENAME_FLAGS_REPLACE : 0));
    22572254            }
    22582255        }
     
    22932290    if (RTPathStartsWithRoot(pszOldPath))
    22942291        return VERR_INVALID_NAME;
    2295    
    2296     /* Force relative pathes to be inside the shared folder. Don't allow the target to go up */
    2297     rc = vbsfPathCheck(pszOldPath, pOldPath->u16Length);
     2292
     2293    bool fSymlinksCreate;
     2294    rc = vbsfMappingsQuerySymlinksCreate(pClient, root, &fSymlinksCreate);
    22982295    AssertRCReturn(rc, rc);
     2296    if (!fSymlinksCreate)
     2297        return VERR_WRITE_PROTECT; /* XXX or VERR_TOO_MANY_SYMLINKS? */
    22992298
    23002299    rc = vbsfBuildFullPath(pClient, root, pNewPath, pNewPath->u16Size, &pszFullNewPath, NULL);
     
    23022301
    23032302    rc = RTSymlinkCreate(pszFullNewPath, (const char *)pOldPath->String.utf8,
    2304                          RTSYMLINKTYPE_UNKNOWN, RTSYMLINKCREATE_FLAGS_NO_SYMLINKS);
     2303                         RTSYMLINKTYPE_UNKNOWN, 0);
    23052304    if (RT_SUCCESS(rc))
    23062305    {
    23072306        RTFSOBJINFO info;
    2308         rc = RTPathQueryInfoEx(pszFullNewPath, &info, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
     2307        rc = RTPathQueryInfoEx(pszFullNewPath, &info, RTFSOBJATTRADD_NOTHING, SHFL_RT_LINK(pClient));
    23092308        if (RT_SUCCESS(rc))
    23102309            vbfsCopyFsObjInfoFromIprt(pInfo, &info);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette