- Timestamp:
- Jun 4, 2019 12:39:03 AM (6 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedFolders/testcase/tstSharedFolderService.cpp
r77685 r78947 302 302 } 303 303 304 static uint64_t testRTDirSetFMode; 305 306 extern int testRTDirSetMode(RTDIR hDir, RTFMODE fMode) 307 { 308 RT_NOREF1(hDir); 309 /* RTPrintf("%s: fMode=%llu\n", __PRETTY_FUNCTION__, LLUIFY(fMode)); */ 310 testRTDirSetFMode = fMode; 311 return VINF_SUCCESS; 312 } 313 304 314 static RTTIMESPEC testRTDirSetTimesATime; 305 315 -
trunk/src/VBox/HostServices/SharedFolders/teststubs.h
r77685 r78947 45 45 #define RTDirReadEx testRTDirReadEx 46 46 extern int testRTDirReadEx(RTDIR hDir, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags); 47 #define RTDirSetMode testRTDirSetMode 48 extern int testRTDirSetMode(RTDIR hDir, RTFMODE fMode); 47 49 #define RTDirSetTimes testRTDirSetTimes 48 50 extern int testRTDirSetTimes(RTDIR hDir, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime, PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime); -
trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp
r78704 r78947 1955 1955 Assert(flags == (SHFL_INFO_SET | SHFL_INFO_FILE)); 1956 1956 1957 /* Change only the time values that are not zero */ 1958 if (type == SHFL_HF_TYPE_DIR) 1959 { 1960 SHFLFILEHANDLE *pHandle = vbsfQueryDirHandle(pClient, Handle); 1957 /* 1958 * Get the handle. 1959 */ 1960 SHFLFILEHANDLE *pHandle; 1961 if (type == SHFL_HF_TYPE_FILE) 1962 { 1963 pHandle = vbsfQueryFileHandle(pClient, Handle); 1961 1964 rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE); 1962 if (RT_SUCCESS(rc))1963 rc = RTDirSetTimes(pHandle->dir.Handle,1964 (RTTimeSpecGetNano(&pSFDEntry->AccessTime)) ? &pSFDEntry->AccessTime : NULL,1965 (RTTimeSpecGetNano(&pSFDEntry->ModificationTime)) ? &pSFDEntry->ModificationTime: NULL,1966 (RTTimeSpecGetNano(&pSFDEntry->ChangeTime)) ? &pSFDEntry->ChangeTime: NULL,1967 (RTTimeSpecGetNano(&pSFDEntry->BirthTime)) ? &pSFDEntry->BirthTime: NULL1968 );1969 1965 } 1970 1966 else 1971 1967 { 1972 SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle); 1968 Assert(type == SHFL_HF_TYPE_DIR); 1969 pHandle = vbsfQueryDirHandle(pClient, Handle); 1973 1970 rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE); 1974 if (RT_SUCCESS(rc)) 1975 rc = RTFileSetTimes(pHandle->file.Handle, 1976 (RTTimeSpecGetNano(&pSFDEntry->AccessTime)) ? &pSFDEntry->AccessTime : NULL, 1977 (RTTimeSpecGetNano(&pSFDEntry->ModificationTime)) ? &pSFDEntry->ModificationTime: NULL, 1978 (RTTimeSpecGetNano(&pSFDEntry->ChangeTime)) ? &pSFDEntry->ChangeTime: NULL, 1979 (RTTimeSpecGetNano(&pSFDEntry->BirthTime)) ? &pSFDEntry->BirthTime: NULL 1980 ); 1981 } 1982 if (rc != VINF_SUCCESS) 1983 { 1984 Log(("RTFileSetTimes failed with %Rrc\n", rc)); 1985 Log(("AccessTime %RX64\n", RTTimeSpecGetNano(&pSFDEntry->AccessTime))); 1986 Log(("ModificationTime %RX64\n", RTTimeSpecGetNano(&pSFDEntry->ModificationTime))); 1987 Log(("ChangeTime %RX64\n", RTTimeSpecGetNano(&pSFDEntry->ChangeTime))); 1988 Log(("BirthTime %RX64\n", RTTimeSpecGetNano(&pSFDEntry->BirthTime))); 1989 /* temporary hack */ 1990 rc = VINF_SUCCESS; 1991 } 1992 1993 if (type == SHFL_HF_TYPE_FILE) 1994 { 1995 SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle); 1996 rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE); 1997 if (RT_SUCCESS(rc)) 1998 { 1999 /* Change file attributes if necessary */ 2000 if (pSFDEntry->Attr.fMode) 2001 { 2002 RTFMODE fMode = pSFDEntry->Attr.fMode; 2003 1971 } 1972 if (RT_SUCCESS(rc)) 1973 { 1974 /* 1975 * Any times to set? 1976 */ 1977 if ( RTTimeSpecGetNano(&pSFDEntry->AccessTime) 1978 || RTTimeSpecGetNano(&pSFDEntry->ModificationTime) 1979 || RTTimeSpecGetNano(&pSFDEntry->ChangeTime) 1980 || RTTimeSpecGetNano(&pSFDEntry->BirthTime)) 1981 { 1982 1983 /* Change only the time values that are not zero */ 1984 if (type == SHFL_HF_TYPE_FILE) 1985 rc = RTFileSetTimes(pHandle->file.Handle, 1986 RTTimeSpecGetNano(&pSFDEntry->AccessTime) ? &pSFDEntry->AccessTime : NULL, 1987 RTTimeSpecGetNano(&pSFDEntry->ModificationTime) ? &pSFDEntry->ModificationTime : NULL, 1988 RTTimeSpecGetNano(&pSFDEntry->ChangeTime) ? &pSFDEntry->ChangeTime : NULL, 1989 RTTimeSpecGetNano(&pSFDEntry->BirthTime) ? &pSFDEntry->BirthTime : NULL); 1990 else 1991 rc = RTDirSetTimes( pHandle->dir.Handle, 1992 RTTimeSpecGetNano(&pSFDEntry->AccessTime) ? &pSFDEntry->AccessTime : NULL, 1993 RTTimeSpecGetNano(&pSFDEntry->ModificationTime) ? &pSFDEntry->ModificationTime : NULL, 1994 RTTimeSpecGetNano(&pSFDEntry->ChangeTime) ? &pSFDEntry->ChangeTime : NULL, 1995 RTTimeSpecGetNano(&pSFDEntry->BirthTime) ? &pSFDEntry->BirthTime : NULL); 1996 if (RT_FAILURE(rc)) 1997 { 1998 Log(("RT%sSetTimes failed with %Rrc\n", type == SHFL_HF_TYPE_FILE ? "File" : "Dir", rc)); 1999 Log(("AccessTime %#RX64\n", RTTimeSpecGetNano(&pSFDEntry->AccessTime))); 2000 Log(("ModificationTime %#RX64\n", RTTimeSpecGetNano(&pSFDEntry->ModificationTime))); 2001 Log(("ChangeTime %#RX64\n", RTTimeSpecGetNano(&pSFDEntry->ChangeTime))); 2002 Log(("BirthTime %#RX64\n", RTTimeSpecGetNano(&pSFDEntry->BirthTime))); 2003 /* "temporary" hack */ 2004 rc = VINF_SUCCESS; 2005 } 2006 } 2007 2008 /* 2009 * Any mode changes? 2010 */ 2011 if (pSFDEntry->Attr.fMode) 2012 { 2013 RTFMODE fMode = pSFDEntry->Attr.fMode; 2014 2015 if (type == SHFL_HF_TYPE_FILE) 2016 { 2004 2017 #ifndef RT_OS_WINDOWS 2005 /* Don't allow the guest to clear the own bit, otherwise the guest wouldn't be2006 * able to access this file anymore. Only for guests, which set the UNIX mode.2018 /* Don't allow the guest to clear the read own bit, otherwise the guest wouldn't 2019 * be able to access this file anymore. Only for guests, which set the UNIX mode. 2007 2020 * Also, clear bits which we don't pass through for security reasons. */ 2008 2021 if (fMode & RTFS_UNIX_MASK) … … 2012 2025 } 2013 2026 #endif 2014 2015 2027 rc = RTFileSetMode(pHandle->file.Handle, fMode); 2016 if (rc != VINF_SUCCESS) 2028 } 2029 else 2030 { 2031 #ifndef RT_OS_WINDOWS 2032 /* Don't allow the guest to clear the read+execute own bits, otherwise the guest 2033 * wouldn't be able to access this directory anymore. Only for guests, which set 2034 * the UNIX mode. Also, clear bits which we don't pass through for security reasons. */ 2035 if (fMode & RTFS_UNIX_MASK) 2017 2036 { 2018 Log(("RTFileSetMode %x failed with %Rrc\n", fMode, rc)); 2019 /* silent failure, because this tends to fail with e.g. windows guest & linux host */ 2020 rc = VINF_SUCCESS; 2037 fMode |= RTFS_UNIX_IRUSR | RTFS_UNIX_IXUSR; 2038 fMode &= ~(RTFS_UNIX_ISUID | RTFS_UNIX_ISGID | RTFS_UNIX_ISTXT /*?*/); 2021 2039 } 2022 } 2023 } 2024 } 2025 /** @todo mode for directories */ 2026 2027 if (rc == VINF_SUCCESS) 2028 { 2029 uint32_t bufsize = sizeof(*pSFDEntry); 2030 2031 rc = vbsfQueryFileInfo(pClient, root, Handle, SHFL_INFO_GET|SHFL_INFO_FILE, &bufsize, (uint8_t *)pSFDEntry); 2032 if (rc == VINF_SUCCESS) 2033 { 2034 *pcbBuffer = sizeof(SHFLFSOBJINFO); 2035 } 2036 else 2037 AssertFailed(); 2038 } 2039 2040 #endif 2041 rc = RTDirSetMode(pHandle->dir.Handle, fMode); 2042 } 2043 if (RT_FAILURE(rc)) 2044 { 2045 Log(("RT%sSetMode %#x (%#x) failed with %Rrc\n", type == SHFL_HF_TYPE_FILE ? "File" : "Dir", 2046 fMode, pSFDEntry->Attr.fMode, rc)); 2047 /* silent failure, because this tends to fail with e.g. windows guest & linux host */ 2048 rc = VINF_SUCCESS; 2049 } 2050 } 2051 2052 /* 2053 * Return the current file info on success. 2054 */ 2055 if (RT_SUCCESS(rc)) 2056 { 2057 uint32_t bufsize = sizeof(*pSFDEntry); 2058 rc = vbsfQueryFileInfo(pClient, root, Handle, SHFL_INFO_GET | SHFL_INFO_FILE, &bufsize, (uint8_t *)pSFDEntry); 2059 if (RT_SUCCESS(rc)) 2060 *pcbBuffer = sizeof(SHFLFSOBJINFO); 2061 else 2062 AssertFailed(); 2063 } 2064 } 2040 2065 return rc; 2041 2066 } -
trunk/src/VBox/Runtime/Makefile.kmk
r78732 r78947 820 820 generic/cdrom-generic.cpp \ 821 821 generic/RTDirExists-generic.cpp \ 822 generic/RTDirSetMode-generic.cpp \ 822 823 generic/RTDirSetTimes-generic.cpp \ 823 824 generic/fileio-sg-generic.cpp \ … … 914 915 generic/RTCrStoreCreateSnapshotById-generic.cpp \ 915 916 generic/RTDirQueryInfo-generic.cpp \ 917 generic/RTDirSetMode-generic.cpp \ 916 918 generic/RTDirSetTimes-generic.cpp \ 917 919 generic/RTFileMove-generic.cpp \ … … 1015 1017 generic/RTCrStoreCreateSnapshotById-generic.cpp \ 1016 1018 generic/RTDirQueryInfo-generic.cpp \ 1019 generic/RTDirSetMode-generic.cpp \ 1017 1020 generic/RTDirSetTimes-generic.cpp \ 1018 1021 generic/fileio-at-generic.cpp \ … … 1100 1103 generic/cdrom-generic.cpp \ 1101 1104 generic/RTDirQueryInfo-generic.cpp \ 1105 generic/RTDirSetMode-generic.cpp \ 1102 1106 generic/RTDirSetTimes-generic.cpp \ 1103 1107 generic/RTFileCopyPartEx-generic.cpp \ … … 1185 1189 generic/RTCrStoreCreateSnapshotById-generic.cpp \ 1186 1190 generic/RTDirQueryInfo-generic.cpp \ 1191 generic/RTDirSetMode-generic.cpp \ 1187 1192 generic/RTDirSetTimes-generic.cpp \ 1188 1193 generic/RTFileCopyPartEx-generic.cpp \ … … 1268 1273 generic/cdrom-generic.cpp \ 1269 1274 generic/RTDirQueryInfo-generic.cpp \ 1275 generic/RTDirSetMode-generic.cpp \ 1270 1276 generic/RTDirSetTimes-generic.cpp \ 1271 1277 generic/RTFileCopyPartEx-generic.cpp \ … … 1349 1355 generic/RTCrStoreCreateSnapshotById-generic.cpp \ 1350 1356 generic/RTDirQueryInfo-generic.cpp \ 1357 generic/RTDirSetMode-generic.cpp \ 1351 1358 generic/RTDirSetTimes-generic.cpp \ 1352 1359 generic/RTFileCopyPartEx-generic.cpp \ … … 1441 1448 generic/RTCrStoreCreateSnapshotById-generic.cpp \ 1442 1449 generic/RTDirQueryInfo-generic.cpp \ 1450 generic/RTDirSetMode-generic.cpp \ 1443 1451 generic/RTDirSetTimes-generic.cpp \ 1444 1452 generic/fileio-at-generic.cpp \ -
trunk/src/VBox/Runtime/generic/RTDirSetMode-generic.cpp
r78932 r78947 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - RTDirSet Times, generic implementation.3 * IPRT - RTDirSetMode, generic implementation. 4 4 */ 5 5 … … 46 46 47 47 48 RTR3DECL(int) RTDirSetTimes(RTDIR hDir, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime, 49 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime) 48 RTR3DECL(int) RTDirSetMode(RTDIR hDir, RTFMODE fMode) 50 49 { 51 50 /* … … 54 53 if (!rtDirValidHandle(hDir)) 55 54 return VERR_INVALID_PARAMETER; 56 return RTPathSet Times(hDir->pszPath, pAccessTime, pModificationTime, pChangeTime, pBirthTime);55 return RTPathSetMode(hDir->pszPath, fMode); 57 56 } 58 57
Note:
See TracChangeset
for help on using the changeset viewer.