VirtualBox

Changeset 39626 in vbox


Ignore:
Timestamp:
Dec 15, 2011 11:33:47 AM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
75420
Message:

more symlink stuff

Location:
trunk
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/dir.h

    r39612 r39626  
    305305 * @{ */
    306306/** Don't allow symbolic links as part of the path. */
    307 #define RTDIROPENFILTERED_FLAGS_NO_SYMLINKS  RT_BIT(0)
     307#define RTDIROPEN_FLAGS_NO_SYMLINKS  RT_BIT(0)
    308308/** @} */
    309309
  • trunk/include/iprt/path.h

    r39612 r39626  
    127127/** Last component: Follow if link. */
    128128#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)
    129131/** @} */
    130132
     
    133135 * @remarks The parameters will be referenced multiple times. */
    134136#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 )
    137139
    138140
  • trunk/src/VBox/HostServices/SharedFolders/service.cpp

    r39607 r39626  
    244244            else
    245245            {
    246                 pszFolderName = (char*)RTStrAlloc(cbFolderName);
     246                pszFolderName = (char*)RTStrAlloc(cbFolderName + 1);
    247247                AssertReturn(pszFolderName, VERR_NO_MEMORY);
    248248
    249                 rc = SSMR3GetStrZ(pSSM, mapping.pszFolderName, cbFolderName);
     249                rc = SSMR3GetStrZ(pSSM, pszFolderName, cbFolderName + 1);
    250250                AssertRCReturn(rc, rc);
    251251                mapping.pszFolderName = pszFolderName;
  • trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp

    r39612 r39626  
    4242#endif
    4343
    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 
    4844/**
    4945 * @todo find a better solution for supporting the execute bit for non-windows
     
    139135    strcat(pDirEntry->szName, szWildCard);
    140136
    141     rc = RTDirOpenFiltered(&hSearch, pDirEntry->szName, RTDIRFILTER_WINNT, RTDIROPENFILTERED_FLAGS_NO_SYMLINKS);
     137    rc = RTDirOpenFiltered(&hSearch, pDirEntry->szName, RTDIRFILTER_WINNT, RTDIROPEN_FLAGS_NO_SYMLINKS);
    142138    *(pszStartComponent-1) = RTPATH_DELIMITER;
    143139    if (RT_FAILURE(rc))
     
    148144        size_t cbDirEntrySize = cbDirEntry;
    149145
    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);
    151148        if (rc == VERR_NO_MORE_FILES)
    152149            break;
     
    426423    if (RT_SUCCESS(rc))
    427424    {
    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 */
    429427        if (     vbsfIsHostMappingCaseSensitive(root)
    430428            &&  !vbsfIsGuestMappingCaseSensitive(root))
     
    435433            if (fWildCard || fPreserveLastComponent)
    436434            {
    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. */
    438437                size_t cb = strlen(pszFullPath);
    439438                char *pszSrc = pszFullPath + cb - 1;
     
    470469
    471470            /** @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);
    473473            if (rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND)
    474474            {
     
    484484                    {
    485485                        *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);
    487488                        *pszSrc = RTPATH_DELIMITER;
    488489                        if (rc == VINF_SUCCESS)
     
    520521                            fEndOfString = false;
    521522                            *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);
    523525                            Assert(rc == VINF_SUCCESS || rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND);
    524526                        }
     
    860862
    861863            /** @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)))
    863866            {
    864867#ifdef RT_OS_WINDOWS
     
    10321035            /* Open the directory now */
    10331036            rc = RTDirOpenFiltered(&pHandle->dir.Handle, pszPath,
    1034                                    RTDIRFILTER_NONE, RTDIROPENFILTERED_FLAGS_NO_SYMLINKS);
     1037                                   RTDIRFILTER_NONE, RTDIROPEN_FLAGS_NO_SYMLINKS);
    10351038            if (RT_SUCCESS(rc))
    10361039            {
     
    11301133 * @retval  pParms->Info   On success, information returned about the file
    11311134 */
    1132 static int vbsfLookupFile(SHFLCLIENTDATA *pClient, char *pszPath, SHFLCREATEPARMS *pParms)
     1135static int vbsfLookupFile(SHFLCLIENTDATA *pClient, SHFLROOT root, char *pszPath, SHFLCREATEPARMS *pParms)
    11331136{
    11341137    RTFSOBJINFO info;
    11351138    int rc;
    11361139
    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);
    11381150    LogFlow(("SHFL_CF_LOOKUP\n"));
    11391151    /* Client just wants to know if the object exists. */
     
    12341246        if (BIT_FLAG(pParms->CreateFlags, SHFL_CF_LOOKUP))
    12351247        {
    1236             rc = vbsfLookupFile(pClient, pszFullPath, pParms);
     1248            rc = vbsfLookupFile(pClient, root, pszFullPath, pParms);
    12371249        }
    12381250        else
     
    12411253            RTFSOBJINFO info;
    12421254
    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);
    12441257            LogFlow(("RTPathQueryInfoEx returned %Rrc\n", rc));
    12451258
     
    12951308            {
    12961309                if (BIT_FLAG(pParms->CreateFlags, SHFL_CF_DIRECTORY))
    1297                 {
    12981310                    rc = vbsfOpenDir(pClient, pszFullPath, pParms);
    1299                 }
    13001311                else
    1301                 {
    13021312                    rc = vbsfOpenFile(pClient, pszFullPath, pParms);
    1303                 }
    13041313            }
    13051314            else
     
    15051514    PRTDIR         DirHandle;
    15061515    bool           fUtf8;
    1507 
     1516   
    15081517    fUtf8 = BIT_FLAG(pClient->fu32Flags, SHFL_CF_UTF8) != 0;
    15091518
     
    15461555            if (RT_SUCCESS(rc))
    15471556            {
     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
    15481574                rc = RTDirOpenFiltered(&pHandle->dir.SearchHandle, pszFullPath,
    1549                                        RTDIRFILTER_WINNT, RTDIROPENFILTERED_FLAGS_NO_SYMLINKS);
     1575                                       RTDIRFILTER_WINNT, RTDIROPEN_FLAGS_NO_SYMLINKS);
    15501576
    15511577                /* free the path string */
     
    15761602            pDirEntry = pDirEntryOrg;
    15771603
    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);
    15791606            if (rc == VERR_NO_MORE_FILES)
    15801607            {
     
    22952322    {
    22962323        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);
    22982326        if (RT_SUCCESS(rc))
    22992327            vbfsCopyFsObjInfoFromIprt(pInfo, &info);
  • trunk/src/VBox/Runtime/Makefile.kmk

    r39500 r39626  
    615615        r3/posix/RTTimeSet-posix.cpp \
    616616        r3/posix/rtmempage-exec-mmap-heap-posix.cpp \
     617        r3/posix/rtPathOpenPathFh.cpp \
    617618        r3/posix/dir-posix.cpp \
    618619        r3/posix/env-posix.cpp \
     
    11731174        r3/posix/env-posix.cpp \
    11741175        r3/posix/fileio-posix.cpp \
     1176        r3/posix/rtPathOpenPathFh.cpp \
    11751177        r3/posix/fileio2-posix.cpp \
    11761178        r3/posix/path-posix.cpp \
  • trunk/src/VBox/Runtime/include/internal/dir.h

    r28918 r39626  
    129129 *                      wildcard expression.
    130130 */
    131 int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf);
     131int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf, uint32_t fOpen);
    132132
    133133#endif
  • trunk/src/VBox/Runtime/include/internal/path.h

    r33540 r39626  
    4848DECLHIDDEN(int)     rtPathPosixRename(const char *pszSrc, const char *pszDst, unsigned fRename, RTFMODE fFileType);
    4949DECLHIDDEN(int)     rtPathWin32MoveRename(const char *pszSrc, const char *pszDst, uint32_t fFlags, RTFMODE fFileType);
    50 
     50DECLHIDDEN(int)     rtPathOpenPathNoFollowFh(const char *pszPath, int *fh, const char **ppszName);
    5151
    5252/**
  • trunk/src/VBox/Runtime/r3/dir.cpp

    r39612 r39626  
    517517 * @param   pszFilter   Pointer to where the filter start in the path. NULL if no filter.
    518518 * @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 */
     521static int rtDirOpenCommon(PRTDIR *ppDir, const char *pszPath, const char *pszFilter, RTDIRFILTER enmFilter, uint32_t fOpen)
    521522{
    522523    /*
     
    646647     * Hand it over to the native part.
    647648     */
    648     rc = rtDirNativeOpen(pDir, szRealPath);
     649    rc = rtDirNativeOpen(pDir, szRealPath, fOpen);
    649650    if (RT_SUCCESS(rc))
    650651        *ppDir = pDir;
     
    668669     * Take common cause with RTDirOpenFiltered().
    669670     */
    670     int rc = rtDirOpenCommon(ppDir, pszPath, NULL,  RTDIRFILTER_NONE);
     671    int rc = rtDirOpenCommon(ppDir, pszPath, NULL,  RTDIRFILTER_NONE, 0);
    671672    LogFlow(("RTDirOpen(%p:{%p}, %p:{%s}): return %Rrc\n", ppDir, *ppDir, pszPath, pszPath, rc));
    672673    return rc;
     
    711712     * and initialize the handle, and finally call the backend.
    712713     */
    713     int rc = rtDirOpenCommon(ppDir, pszPath, pszFilter, enmFilter);
     714    int rc = rtDirOpenCommon(ppDir, pszPath, pszFilter, enmFilter, fOpen);
    714715
    715716    LogFlow(("RTDirOpenFiltered(%p:{%p}, %p:{%s}, %d): return %Rrc\n",
  • trunk/src/VBox/Runtime/r3/posix/dir-posix.cpp

    r39612 r39626  
    194194
    195195
    196 int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf)
     196int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf, uint32_t fOpen)
    197197{
    198198    NOREF(pszPathBuf); /* only used on windows */
     
    205205    if (RT_SUCCESS(rc))
    206206    {
    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        }
    208231        if (pDir->pDir)
    209232        {
  • trunk/src/VBox/Runtime/r3/posix/fileio-posix.cpp

    r39083 r39626  
    204204        return (rc);
    205205
    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    }
    207227    int iErr = errno;
    208228
  • trunk/src/VBox/Runtime/r3/win/dir-win.cpp

    r39612 r39626  
    130130
    131131
    132 int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf)
     132int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf, uint32_t fOpen)
    133133{
    134134    /*
Note: See TracChangeset for help on using the changeset viewer.

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