VirtualBox

vbox的更動 65288 路徑 trunk/src/VBox/HostServices


忽略:
時間撮記:
2017-1-13 下午03:51:16 (8 年 以前)
作者:
vboxsync
訊息:

SharedFolders: helper to check file handles, cleanup.

位置:
trunk/src/VBox/HostServices/SharedFolders
檔案:
修改 2 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/HostServices/SharedFolders/shflhandle.h

    r62489 r65288  
    4444{
    4545    SHFLHANDLEHDR Header;
     46    SHFLROOT root; /* Where the handle has been opened. */
    4647    union
    4748    {
  • trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp

    r65279 r65288  
    141141{
    142142    vbsfFreeHostPath(pszFullPath);
     143}
     144
     145typedef enum VBSFCHECKACCESS
     146{
     147    VBSF_CHECK_ACCESS_READ = 0,
     148    VBSF_CHECK_ACCESS_WRITE = 1
     149} VBSFCHECKACCESS;
     150
     151/**
     152 * Check if the handle data is valid and the operation is allowed on the shared folder.
     153 *
     154 * @returns IPRT status code
     155 * @param  pClient               Data structure describing the client accessing the shared folder
     156 * @param  root                  The index of the shared folder in the table of mappings.
     157 * @param  pHandle               Information about the file or directory object.
     158 * @param  enmCheckAccess        Whether the operation needs read only or write access.
     159 */
     160static int vbsfCheckHandleAccess(SHFLCLIENTDATA *pClient, SHFLROOT root,
     161                                 SHFLFILEHANDLE *pHandle, VBSFCHECKACCESS enmCheckAccess)
     162{
     163    /* Handle from the same 'root' index? */
     164    if (RT_LIKELY(RT_VALID_PTR(pHandle) && root == pHandle->root))
     165    { /* likely */ }
     166    else
     167        return VERR_INVALID_HANDLE;
     168
     169    /* Check if the guest is still allowed to access this share.
     170     * vbsfMappingsQueryWritable returns error if the shared folder has been removed from the VM settings.
     171     */
     172    bool fWritable;
     173    int rc = vbsfMappingsQueryWritable(pClient, root, &fWritable);
     174    if (RT_SUCCESS(rc))
     175    { /* likely */ }
     176    else
     177        return VERR_ACCESS_DENIED;
     178
     179    if (enmCheckAccess == VBSF_CHECK_ACCESS_WRITE)
     180    {
     181        /* Operation requires write access. Check if the shared folder is writable too. */
     182        if (RT_LIKELY(fWritable))
     183        { /* likely */ }
     184        else
     185            return VERR_WRITE_PROTECT;
     186    }
     187
     188    return VINF_SUCCESS;
    143189}
    144190
     
    421467            if (pHandle)
    422468            {
     469                pHandle->root = root;
    423470                rc = RTFileOpen(&pHandle->file.Handle, pszPath, fOpen);
    424471            }
     
    564611 * @returns IPRT status code
    565612 * @param  pClient               Data structure describing the client accessing the shared folder
     613 * @param  root                  The index of the shared folder in the table of mappings.
    566614 * @param  pszPath               Path to the file or folder on the host.
    567615 * @param  pParms @a CreateFlags Creation or open parameters, see include/VBox/shflsvc.h
     
    573621 * @note folders are created with fMode = 0777
    574622 */
    575 static int vbsfOpenDir(SHFLCLIENTDATA *pClient, const char *pszPath,
     623static int vbsfOpenDir(SHFLCLIENTDATA *pClient, SHFLROOT root, const char *pszPath,
    576624                       SHFLCREATEPARMS *pParms)
    577625{
     
    584632    if (0 != pHandle)
    585633    {
     634        pHandle->root = root;
    586635        rc = VINF_SUCCESS;
    587636        pParms->Result = SHFL_FILE_EXISTS;  /* May be overwritten with SHFL_FILE_CREATED. */
     
    885934                if (BIT_FLAG(pParms->CreateFlags, SHFL_CF_DIRECTORY))
    886935                {
    887                     rc = vbsfOpenDir(pClient, pszFullPath, pParms);
     936                    rc = vbsfOpenDir(pClient, root, pszFullPath, pParms);
    888937                }
    889938                else
     
    920969int vbsfClose(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle)
    921970{
    922     RT_NOREF1(root);
    923     int rc = VINF_SUCCESS;
    924 
    925     LogFlow(("vbsfClose: pClient = %p, Handle = %RX64\n",
    926              pClient, Handle));
    927 
     971    LogFunc(("pClient = %p, root 0x%RX32, Handle = 0x%RX64\n",
     972             pClient, root, Handle));
     973
     974    int rc = VERR_INVALID_HANDLE;
    928975    uint32_t type = vbsfQueryHandleType(pClient, Handle);
    929976    Assert((type & ~(SHFL_HF_TYPE_DIR | SHFL_HF_TYPE_FILE)) == 0);
    930 
    931977    switch (type & (SHFL_HF_TYPE_DIR | SHFL_HF_TYPE_FILE))
    932978    {
    933979        case SHFL_HF_TYPE_DIR:
    934980        {
    935             rc = vbsfCloseDir(vbsfQueryDirHandle(pClient, Handle));
     981            SHFLFILEHANDLE *pHandle = vbsfQueryDirHandle(pClient, Handle);
     982            if (RT_LIKELY(pHandle && root == pHandle->root))
     983            {
     984                rc = vbsfCloseDir(pHandle);
     985                vbsfFreeFileHandle(pClient, Handle);
     986            }
    936987            break;
    937988        }
    938989        case SHFL_HF_TYPE_FILE:
    939990        {
    940             rc = vbsfCloseFile(vbsfQueryFileHandle(pClient, Handle));
     991            SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle);
     992            if (RT_LIKELY(pHandle && root == pHandle->root))
     993            {
     994                rc = vbsfCloseFile(pHandle);
     995                vbsfFreeFileHandle(pClient, Handle);
     996            }
    941997            break;
    942998        }
    943999        default:
    944             return VERR_INVALID_HANDLE;
    945     }
    946     vbsfFreeFileHandle(pClient, Handle);
    947 
    948     Log(("vbsfClose: rc = %Rrc\n", rc));
    949 
     1000            break;
     1001    }
     1002
     1003    LogFunc(("rc = %Rrc\n", rc));
    9501004    return rc;
    9511005}
     
    9631017}
    9641018#endif
    965 int vbsfRead  (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer)
    966 {
     1019int vbsfRead(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer)
     1020{
     1021    LogFunc(("pClient %p, root 0x%RX32, Handle 0x%RX64, offset 0x%RX64, bytes 0x%RX32\n",
     1022             pClient, root, Handle, offset, pcbBuffer? *pcbBuffer: 0));
     1023
     1024    AssertPtrReturn(pClient, VERR_INVALID_PARAMETER);
     1025
    9671026    SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle);
    968     size_t count = 0;
    969     int rc;
    970 
    971     if (pHandle == 0 || pcbBuffer == 0 || pBuffer == 0)
    972     {
    973         AssertFailed();
    974         return VERR_INVALID_PARAMETER;
    975     }
    976 
    977     Log(("vbsfRead %RX64 offset %RX64 bytes %x\n", Handle, offset, *pcbBuffer));
    978 
    979     /* Is the guest allowed to access this share?
    980      * Checked here because the shared folder can be removed from the VM settings. */
    981     bool fWritable;
    982     rc = vbsfMappingsQueryWritable(pClient, root, &fWritable);
    983     if (RT_FAILURE(rc))
    984         return VERR_ACCESS_DENIED;
    985 
    986     if (*pcbBuffer == 0)
    987         return VINF_SUCCESS; /** @todo correct? */
    988 
    989 
    990     rc = RTFileSeek(pHandle->file.Handle, offset, RTFILE_SEEK_BEGIN, NULL);
    991     if (rc != VINF_SUCCESS)
    992     {
    993         AssertRC(rc);
     1027    int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_READ);
     1028    if (RT_SUCCESS(rc))
     1029    { /* likely */ }
     1030    else
    9941031        return rc;
    995     }
    996 
    997     rc = RTFileRead(pHandle->file.Handle, pBuffer, *pcbBuffer, &count);
    998     *pcbBuffer = (uint32_t)count;
    999     Log(("RTFileRead returned %Rrc bytes read %x\n", rc, count));
     1032
     1033    if (RT_LIKELY(*pcbBuffer != 0))
     1034    {
     1035        rc = RTFileSeek(pHandle->file.Handle, offset, RTFILE_SEEK_BEGIN, NULL);
     1036        if (RT_SUCCESS(rc))
     1037        {
     1038            size_t count = 0;
     1039            rc = RTFileRead(pHandle->file.Handle, pBuffer, *pcbBuffer, &count);
     1040            *pcbBuffer = (uint32_t)count;
     1041        }
     1042        else
     1043            AssertRC(rc);
     1044    }
     1045    else
     1046    {
     1047        /* Reading zero bytes always succeeds. */
     1048        rc = VINF_SUCCESS;
     1049    }
     1050
     1051    LogFunc(("%Rrc bytes read 0x%RX32\n", rc, *pcbBuffer));
    10001052    return rc;
    10011053}
     
    10151067int vbsfWrite(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer)
    10161068{
     1069    LogFunc(("pClient %p, root 0x%RX32, Handle 0x%RX64, offset 0x%RX64, bytes 0x%RX32\n",
     1070             pClient, root, Handle, offset, pcbBuffer? *pcbBuffer: 0));
     1071
     1072    AssertPtrReturn(pClient, VERR_INVALID_PARAMETER);
     1073
    10171074    SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle);
    1018     size_t count = 0;
    1019     int rc;
    1020 
    1021     if (pHandle == 0 || pcbBuffer == 0 || pBuffer == 0)
    1022     {
    1023         AssertFailed();
    1024         return VERR_INVALID_PARAMETER;
    1025     }
    1026 
    1027     Log(("vbsfWrite %RX64 offset %RX64 bytes %x\n", Handle, offset, *pcbBuffer));
    1028 
    1029     /* Is the guest allowed to write to this share?
    1030      * Checked here because the shared folder can be removed from the VM settings. */
    1031     bool fWritable;
    1032     rc = vbsfMappingsQueryWritable(pClient, root, &fWritable);
    1033     if (RT_FAILURE(rc) || !fWritable)
    1034         return VERR_WRITE_PROTECT;
    1035 
    1036     if (*pcbBuffer == 0)
    1037         return VINF_SUCCESS; /** @todo correct? */
    1038 
    1039     rc = RTFileSeek(pHandle->file.Handle, offset, RTFILE_SEEK_BEGIN, NULL);
    1040     if (rc != VINF_SUCCESS)
    1041     {
    1042         AssertRC(rc);
     1075    int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE);
     1076    if (RT_SUCCESS(rc))
     1077    { /* likely */ }
     1078    else
    10431079        return rc;
    1044     }
    1045 
    1046     rc = RTFileWrite(pHandle->file.Handle, pBuffer, *pcbBuffer, &count);
    1047     *pcbBuffer = (uint32_t)count;
    1048     Log(("RTFileWrite returned %Rrc bytes written %x\n", rc, count));
     1080
     1081    if (RT_LIKELY(*pcbBuffer != 0))
     1082    {
     1083        rc = RTFileSeek(pHandle->file.Handle, offset, RTFILE_SEEK_BEGIN, NULL);
     1084        if (RT_SUCCESS(rc))
     1085        {
     1086            size_t count = 0;
     1087            rc = RTFileWrite(pHandle->file.Handle, pBuffer, *pcbBuffer, &count);
     1088            *pcbBuffer = (uint32_t)count;
     1089        }
     1090        else
     1091            AssertRC(rc);
     1092    }
     1093    else
     1094    {
     1095        /** @todo: What writing zero bytes should do? */
     1096        rc = VINF_SUCCESS;
     1097    }
     1098
     1099    LogFunc(("%Rrc bytes written 0x%RX32\n", rc, *pcbBuffer));
    10491100    return rc;
    10501101}
     
    10661117int vbsfFlush(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle)
    10671118{
    1068     RT_NOREF1(root);
     1119    LogFunc(("pClient %p, root 0x%RX32, Handle 0x%RX64\n",
     1120             pClient, root, Handle));
     1121
     1122    AssertPtrReturn(pClient, VERR_INVALID_PARAMETER);
     1123
    10691124    SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle);
    1070     int rc = VINF_SUCCESS;
    1071 
    1072     if (pHandle == 0)
    1073     {
    1074         AssertFailed();
    1075         return VERR_INVALID_HANDLE;
    1076     }
    1077 
    1078     Log(("vbsfFlush %RX64\n", Handle));
     1125    int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE);
     1126    if (RT_SUCCESS(rc))
     1127    { /* likely */ }
     1128    else
     1129        return rc;
     1130
    10791131    rc = RTFileFlush(pHandle->file.Handle);
    1080     AssertRC(rc);
     1132
     1133    LogFunc(("%Rrc\n", rc));
    10811134    return rc;
    10821135}
     
    10971150                uint32_t *pcbBuffer, uint8_t *pBuffer, uint32_t *pIndex, uint32_t *pcFiles)
    10981151{
    1099     SHFLFILEHANDLE *pHandle = vbsfQueryDirHandle(pClient, Handle);
    11001152    PRTDIRENTRYEX  pDirEntry = 0, pDirEntryOrg;
    11011153    uint32_t       cbDirEntry, cbBufferOrg;
    1102     int            rc = VINF_SUCCESS;
    11031154    PSHFLDIRINFO   pSFDEntry;
    11041155    PRTUTF16       pwszString;
    11051156    PRTDIR         DirHandle;
    1106     bool           fUtf8;
    1107 
    1108     fUtf8 = BIT_FLAG(pClient->fu32Flags, SHFL_CF_UTF8) != 0;
    1109 
    1110     if (pHandle == 0 || pcbBuffer == 0 || pBuffer == 0)
    1111     {
    1112         AssertFailed();
    1113         return VERR_INVALID_PARAMETER;
    1114     }
    1115 
    1116     /* Is the guest allowed to access this share?
    1117      * Checked here because the shared folder can be removed from the VM settings. */
    1118     bool fWritable;
    1119     rc = vbsfMappingsQueryWritable(pClient, root, &fWritable);
    1120     if (RT_FAILURE(rc))
    1121         return VERR_ACCESS_DENIED;
    1122 
    1123     Assert(pIndex && *pIndex == 0);
     1157    const bool     fUtf8 = BIT_FLAG(pClient->fu32Flags, SHFL_CF_UTF8) != 0;
     1158
     1159    AssertPtrReturn(pClient, VERR_INVALID_PARAMETER);
     1160
     1161    SHFLFILEHANDLE *pHandle = vbsfQueryDirHandle(pClient, Handle);
     1162    int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_READ);
     1163    if (RT_SUCCESS(rc))
     1164    { /* likely */ }
     1165    else
     1166        return rc;
     1167
     1168    Assert(*pIndex == 0);
    11241169    DirHandle = pHandle->dir.Handle;
    11251170
     
    13601405                      uint32_t *pcbBuffer, uint8_t *pBuffer)
    13611406{
    1362     RT_NOREF2(root, flags);
     1407    RT_NOREF1(flags);
    13631408    uint32_t type = vbsfQueryHandleType(pClient, Handle);
    13641409    int            rc = VINF_SUCCESS;
     
    13841429    {
    13851430        SHFLFILEHANDLE *pHandle = vbsfQueryDirHandle(pClient, Handle);
    1386         rc = RTDirQueryInfo(pHandle->dir.Handle, &fileinfo, RTFSOBJATTRADD_NOTHING);
     1431        rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_READ);
     1432        if (RT_SUCCESS(rc))
     1433            rc = RTDirQueryInfo(pHandle->dir.Handle, &fileinfo, RTFSOBJATTRADD_NOTHING);
    13871434    }
    13881435    else
    13891436    {
    13901437        SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle);
    1391         rc = RTFileQueryInfo(pHandle->file.Handle, &fileinfo, RTFSOBJATTRADD_NOTHING);
     1438        rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_READ);
     1439        if (RT_SUCCESS(rc))
     1440            rc = RTFileQueryInfo(pHandle->file.Handle, &fileinfo, RTFSOBJATTRADD_NOTHING);
    13921441#ifdef RT_OS_WINDOWS
    13931442        if (RT_SUCCESS(rc) && RTFS_IS_FILE(pObjInfo->Attr.fMode))
     
    14091458                           uint32_t *pcbBuffer, uint8_t *pBuffer)
    14101459{
    1411     RT_NOREF2(root, flags);
     1460    RT_NOREF1(flags);
    14121461    uint32_t type = vbsfQueryHandleType(pClient, Handle);
    14131462    int             rc = VINF_SUCCESS;
     
    14321481    {
    14331482        SHFLFILEHANDLE *pHandle = vbsfQueryDirHandle(pClient, Handle);
    1434         rc = RTDirSetTimes(pHandle->dir.Handle,
    1435                             (RTTimeSpecGetNano(&pSFDEntry->AccessTime)) ?       &pSFDEntry->AccessTime : NULL,
    1436                             (RTTimeSpecGetNano(&pSFDEntry->ModificationTime)) ? &pSFDEntry->ModificationTime: NULL,
    1437                             (RTTimeSpecGetNano(&pSFDEntry->ChangeTime)) ?       &pSFDEntry->ChangeTime: NULL,
    1438                             (RTTimeSpecGetNano(&pSFDEntry->BirthTime)) ?        &pSFDEntry->BirthTime: NULL
    1439                             );
     1483        rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE);
     1484        if (RT_SUCCESS(rc))
     1485            rc = RTDirSetTimes(pHandle->dir.Handle,
     1486                                (RTTimeSpecGetNano(&pSFDEntry->AccessTime)) ?       &pSFDEntry->AccessTime : NULL,
     1487                                (RTTimeSpecGetNano(&pSFDEntry->ModificationTime)) ? &pSFDEntry->ModificationTime: NULL,
     1488                                (RTTimeSpecGetNano(&pSFDEntry->ChangeTime)) ?       &pSFDEntry->ChangeTime: NULL,
     1489                                (RTTimeSpecGetNano(&pSFDEntry->BirthTime)) ?        &pSFDEntry->BirthTime: NULL
     1490                                );
    14401491    }
    14411492    else
    14421493    {
    14431494        SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle);
    1444         rc = RTFileSetTimes(pHandle->file.Handle,
    1445                             (RTTimeSpecGetNano(&pSFDEntry->AccessTime)) ?       &pSFDEntry->AccessTime : NULL,
    1446                             (RTTimeSpecGetNano(&pSFDEntry->ModificationTime)) ? &pSFDEntry->ModificationTime: NULL,
    1447                             (RTTimeSpecGetNano(&pSFDEntry->ChangeTime)) ?       &pSFDEntry->ChangeTime: NULL,
    1448                             (RTTimeSpecGetNano(&pSFDEntry->BirthTime)) ?        &pSFDEntry->BirthTime: NULL
    1449                             );
     1495        rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE);
     1496        if (RT_SUCCESS(rc))
     1497            rc = RTFileSetTimes(pHandle->file.Handle,
     1498                                 (RTTimeSpecGetNano(&pSFDEntry->AccessTime)) ?       &pSFDEntry->AccessTime : NULL,
     1499                                 (RTTimeSpecGetNano(&pSFDEntry->ModificationTime)) ? &pSFDEntry->ModificationTime: NULL,
     1500                                 (RTTimeSpecGetNano(&pSFDEntry->ChangeTime)) ?       &pSFDEntry->ChangeTime: NULL,
     1501                                 (RTTimeSpecGetNano(&pSFDEntry->BirthTime)) ?        &pSFDEntry->BirthTime: NULL
     1502                                 );
    14501503    }
    14511504    if (rc != VINF_SUCCESS)
     
    14631516    {
    14641517        SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle);
    1465         /* Change file attributes if necessary */
    1466         if (pSFDEntry->Attr.fMode)
    1467         {
    1468             RTFMODE fMode = pSFDEntry->Attr.fMode;
     1518        rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE);
     1519        if (RT_SUCCESS(rc))
     1520        {
     1521            /* Change file attributes if necessary */
     1522            if (pSFDEntry->Attr.fMode)
     1523            {
     1524                RTFMODE fMode = pSFDEntry->Attr.fMode;
    14691525
    14701526#ifndef RT_OS_WINDOWS
    1471             /* Don't allow the guest to clear the own bit, otherwise the guest wouldn't be
    1472              * able to access this file anymore. Only for guests, which set the UNIX mode. */
    1473             if (fMode & RTFS_UNIX_MASK)
    1474                 fMode |= RTFS_UNIX_IRUSR;
    1475 #endif
    1476 
    1477             rc = RTFileSetMode(pHandle->file.Handle, fMode);
    1478             if (rc != VINF_SUCCESS)
    1479             {
    1480                 Log(("RTFileSetMode %x failed with %Rrc\n", fMode, rc));
    1481                 /* silent failure, because this tends to fail with e.g. windows guest & linux host */
    1482                 rc = VINF_SUCCESS;
     1527                /* Don't allow the guest to clear the own bit, otherwise the guest wouldn't be
     1528                 * able to access this file anymore. Only for guests, which set the UNIX mode. */
     1529                if (fMode & RTFS_UNIX_MASK)
     1530                    fMode |= RTFS_UNIX_IRUSR;
     1531#endif
     1532
     1533                rc = RTFileSetMode(pHandle->file.Handle, fMode);
     1534                if (rc != VINF_SUCCESS)
     1535                {
     1536                    Log(("RTFileSetMode %x failed with %Rrc\n", fMode, rc));
     1537                    /* silent failure, because this tends to fail with e.g. windows guest & linux host */
     1538                    rc = VINF_SUCCESS;
     1539                }
    14831540            }
    14841541        }
     
    15061563                            uint32_t *pcbBuffer, uint8_t *pBuffer)
    15071564{
    1508     RT_NOREF2(root, flags);
     1565    RT_NOREF1(flags);
    15091566    SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle);
    1510     int             rc = VINF_SUCCESS;
    15111567    SHFLFSOBJINFO  *pSFDEntry;
    15121568
     
    15161572        return VERR_INVALID_PARAMETER;
    15171573    }
     1574
     1575    int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE);
     1576    if (RT_SUCCESS(rc))
     1577    { /* likely */ }
     1578    else
     1579        return rc;
    15181580
    15191581    *pcbBuffer  = 0;
     
    16481710    }
    16491711
    1650     /* is the guest allowed to write to this share? */
    1651     bool fWritable;
    1652     int rc = vbsfMappingsQueryWritable(pClient, root, &fWritable);
    1653     if (RT_FAILURE(rc) || !fWritable)
    1654         return VERR_WRITE_PROTECT;
    1655 
    16561712    if (flags & SHFL_INFO_FILE)
    16571713        return vbsfSetFileInfo(pClient, root, Handle, flags, pcbBuffer, pBuffer);
     
    16811737int vbsfLock(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint64_t length, uint32_t flags)
    16821738{
    1683     RT_NOREF1(root);
    16841739    SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle);
    16851740    uint32_t        fRTLock = 0;
    1686     int             rc;
    16871741
    16881742    Assert((flags & SHFL_LOCK_MODE_MASK) != SHFL_LOCK_CANCEL);
    16891743
    1690     if (pHandle == 0)
    1691     {
    1692         AssertFailed();
    1693         return VERR_INVALID_HANDLE;
    1694     }
     1744    int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_READ);
     1745    if (RT_SUCCESS(rc))
     1746    { /* likely */ }
     1747    else
     1748        return rc;
     1749
    16951750    if (   ((flags & SHFL_LOCK_MODE_MASK) == SHFL_LOCK_CANCEL)
    16961751        || (flags & SHFL_LOCK_ENTIRE)
     
    17371792int vbsfUnlock(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint64_t length, uint32_t flags)
    17381793{
    1739     RT_NOREF1(root);
    17401794    SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle);
    1741     int             rc;
    17421795
    17431796    Assert((flags & SHFL_LOCK_MODE_MASK) == SHFL_LOCK_CANCEL);
    17441797
    1745     if (pHandle == 0)
    1746     {
    1747         return VERR_INVALID_HANDLE;
    1748     }
     1798    int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_READ);
     1799    if (RT_SUCCESS(rc))
     1800    { /* likely */ }
     1801    else
     1802        return rc;
     1803
    17491804    if (   ((flags & SHFL_LOCK_MODE_MASK) != SHFL_LOCK_CANCEL)
    17501805        || (flags & SHFL_LOCK_ENTIRE)
     
    19562011int vbsfDisconnect(SHFLCLIENTDATA *pClient)
    19572012{
    1958     for (int i=0; i<SHFLHANDLE_MAX; i++)
    1959     {
     2013    for (int i = 0; i < SHFLHANDLE_MAX; ++i)
     2014    {
     2015        SHFLFILEHANDLE *pHandle = NULL;
    19602016        SHFLHANDLE Handle = (SHFLHANDLE)i;
    1961         if (vbsfQueryHandleType(pClient, Handle))
    1962         {
    1963             Log(("Open handle %08x\n", i));
    1964             vbsfClose(pClient, SHFL_HANDLE_ROOT /* incorrect, but it's not important */, (SHFLHANDLE)i);
     2017
     2018        uint32_t type = vbsfQueryHandleType(pClient, Handle);
     2019        switch (type & (SHFL_HF_TYPE_DIR | SHFL_HF_TYPE_FILE))
     2020        {
     2021            case SHFL_HF_TYPE_DIR:
     2022            {
     2023                pHandle = vbsfQueryDirHandle(pClient, Handle);
     2024                break;
     2025            }
     2026            case SHFL_HF_TYPE_FILE:
     2027            {
     2028                pHandle = vbsfQueryFileHandle(pClient, Handle);
     2029                break;
     2030            }
     2031            default:
     2032                break;
     2033        }
     2034
     2035        if (pHandle)
     2036        {
     2037            LogFunc(("Opened handle 0x%08x\n", i));
     2038            vbsfClose(pClient, pHandle->root, Handle);
    19652039        }
    19662040    }
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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