Changeset 78467 in vbox
- Timestamp:
- May 11, 2019 1:04:24 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/shflsvc.h
r77858 r78467 148 148 * @since VBox 6.0.6 */ 149 149 #define SHFL_FN_COPY_FILE_PART (27) 150 /** Close handle to (optional) and remove object by path. 151 * This function is tailored for Windows guests. 152 * @since VBox 6.0.8 */ 153 #define SHFL_FN_CLOSE_AND_REMOVE (28) 150 154 /** The last function number. */ 151 #define SHFL_FN_LAST SHFL_FN_C OPY_FILE_PART155 #define SHFL_FN_LAST SHFL_FN_CLOSE_AND_REMOVE 152 156 /** @} */ 153 157 … … 1780 1784 1781 1785 1786 /** @name SHFL_FN_CLOSE_AND_REMOVE 1787 * Extends SHFL_FN_REMOVE with a 4th handle parameter that can be nil. 1788 * @{ 1789 */ 1790 /** SHFL_FN_CLOSE_AND_REMOVE parameters. */ 1791 typedef struct VBoxSFParmCloseAndRemove 1792 #ifdef __cplusplus 1793 : public VBoxSFParmRemove 1794 #endif 1795 { 1796 #ifndef __cplusplus 1797 VBoxSFParmRemove Core; 1798 #endif 1799 /** value64, in: SHFLHANDLE to the object to be removed & close, optional. */ 1800 HGCMFunctionParameter u64Handle; 1801 } VBoxSFParmCloseAndRemove; 1802 /** Number of parameters */ 1803 #define SHFL_CPARMS_CLOSE_AND_REMOVE (4) 1804 AssertCompileSize(VBoxSFParmCloseAndRemove, SHFL_CPARMS_CLOSE_AND_REMOVE * sizeof(HGCMFunctionParameter)); 1805 /** @} */ 1806 1807 1782 1808 /** @name SHFL_FN_RENAME 1783 1809 * @{ -
trunk/src/VBox/HostServices/SharedFolders/VBoxSharedFoldersSvc.cpp
r77852 r78467 86 86 static STAMPROFILE g_StatRemove; 87 87 static STAMPROFILE g_StatRemoveFail; 88 static STAMPROFILE g_StatCloseAndRemove; 89 static STAMPROFILE g_StatCloseAndRemoveFail; 88 90 static STAMPROFILE g_StatRename; 89 91 static STAMPROFILE g_StatRenameFail; … … 1214 1216 1215 1217 /* Verify parameter count and types. */ 1216 if (cParms != SHFL_CPARMS_REMOVE) 1217 { 1218 rc = VERR_INVALID_PARAMETER; 1219 } 1220 else if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* root */ 1221 || paParms[1].type != VBOX_HGCM_SVC_PARM_PTR /* path */ 1222 || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* flags */ 1223 ) 1224 { 1225 rc = VERR_INVALID_PARAMETER; 1226 } 1227 else 1228 { 1229 /* Fetch parameters. */ 1230 SHFLROOT root = (SHFLROOT)paParms[0].u.uint32; 1231 SHFLSTRING *pPath = (SHFLSTRING *)paParms[1].u.pointer.addr; 1232 uint32_t cbPath = paParms[1].u.pointer.size; 1233 uint32_t flags = paParms[2].u.uint32; 1234 1235 /* Verify parameters values. */ 1236 if (!ShflStringIsValidIn(pPath, cbPath, RT_BOOL(pClient->fu32Flags & SHFL_CF_UTF8))) 1237 { 1238 rc = VERR_INVALID_PARAMETER; 1239 } 1240 else 1241 { 1242 /* Execute the function. */ 1243 rc = vbsfRemove (pClient, root, pPath, cbPath, flags); 1244 if (RT_SUCCESS(rc)) 1245 { 1246 /* Update parameters.*/ 1247 ; /* none */ 1248 } 1249 } 1250 } 1218 ASSERT_GUEST_STMT_BREAK(cParms == SHFL_CPARMS_REMOVE, rc = VERR_WRONG_PARAMETER_COUNT); 1219 ASSERT_GUEST_STMT_BREAK(paParms[0].type == VBOX_HGCM_SVC_PARM_32BIT, rc = VERR_WRONG_PARAMETER_TYPE); /* root */ 1220 ASSERT_GUEST_STMT_BREAK(paParms[1].type == VBOX_HGCM_SVC_PARM_PTR, rc = VERR_WRONG_PARAMETER_TYPE); /* path */ 1221 PCSHFLSTRING pStrPath = (PCSHFLSTRING)paParms[1].u.pointer.addr; 1222 ASSERT_GUEST_STMT_BREAK(ShflStringIsValidIn(pStrPath, paParms[1].u.pointer.size, 1223 RT_BOOL(pClient->fu32Flags & SHFL_CF_UTF8)), 1224 rc = VERR_INVALID_PARAMETER); 1225 ASSERT_GUEST_STMT_BREAK(paParms[2].type == VBOX_HGCM_SVC_PARM_32BIT, rc = VERR_WRONG_PARAMETER_TYPE); /* flags */ 1226 uint32_t const fFlags = paParms[2].u.uint32; 1227 ASSERT_GUEST_STMT_BREAK(!(fFlags & ~(SHFL_REMOVE_FILE | SHFL_REMOVE_DIR | SHFL_REMOVE_SYMLINK)), 1228 rc = VERR_INVALID_FLAGS); 1229 1230 /* Execute the function. */ 1231 rc = vbsfRemove(pClient, paParms[0].u.uint32, pStrPath, paParms[1].u.pointer.size, fFlags, SHFL_HANDLE_NIL); 1232 break; 1233 } 1234 1235 case SHFL_FN_CLOSE_AND_REMOVE: 1236 { 1237 pStat = &g_StatCloseAndRemove; 1238 pStatFail = &g_StatCloseAndRemoveFail; 1239 Log(("SharedFolders host service: svcCall: SHFL_FN_CLOSE_AND_REMOVE\n")); 1240 1241 /* Verify parameter count and types. */ 1242 ASSERT_GUEST_STMT_BREAK(cParms == SHFL_CPARMS_CLOSE_AND_REMOVE, rc = VERR_WRONG_PARAMETER_COUNT); 1243 ASSERT_GUEST_STMT_BREAK(paParms[0].type == VBOX_HGCM_SVC_PARM_32BIT, rc = VERR_WRONG_PARAMETER_TYPE); /* root */ 1244 ASSERT_GUEST_STMT_BREAK(paParms[1].type == VBOX_HGCM_SVC_PARM_PTR, rc = VERR_WRONG_PARAMETER_TYPE); /* path */ 1245 PCSHFLSTRING pStrPath = (PCSHFLSTRING)paParms[1].u.pointer.addr; 1246 ASSERT_GUEST_STMT_BREAK(ShflStringIsValidIn(pStrPath, paParms[1].u.pointer.size, 1247 RT_BOOL(pClient->fu32Flags & SHFL_CF_UTF8)), 1248 rc = VERR_INVALID_PARAMETER); 1249 ASSERT_GUEST_STMT_BREAK(paParms[2].type == VBOX_HGCM_SVC_PARM_32BIT, rc = VERR_WRONG_PARAMETER_TYPE); /* flags */ 1250 uint32_t const fFlags = paParms[2].u.uint32; 1251 ASSERT_GUEST_STMT_BREAK(!(fFlags & ~(SHFL_REMOVE_FILE | SHFL_REMOVE_DIR | SHFL_REMOVE_SYMLINK)), 1252 rc = VERR_INVALID_FLAGS); 1253 SHFLHANDLE const hToClose = paParms[3].u.uint64; 1254 ASSERT_GUEST_STMT_BREAK(hToClose != SHFL_HANDLE_ROOT, rc = VERR_INVALID_HANDLE); 1255 1256 /* Execute the function. */ 1257 rc = vbsfRemove(pClient, paParms[0].u.uint32, pStrPath, paParms[1].u.pointer.size, fFlags, hToClose); 1251 1258 break; 1252 1259 } … … 1860 1867 HGCMSvcHlpStamRegister(g_pHelpers, &g_StatRemove, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "SHFL_FN_REMOVE successes", "/HGCM/VBoxSharedFolders/FnRemove"); 1861 1868 HGCMSvcHlpStamRegister(g_pHelpers, &g_StatRemoveFail, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "SHFL_FN_REMOVE failures", "/HGCM/VBoxSharedFolders/FnRemoveFail"); 1869 HGCMSvcHlpStamRegister(g_pHelpers, &g_StatCloseAndRemove, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "SHFL_FN_CLOSE_AND_REMOVE successes", "/HGCM/VBoxSharedFolders/FnCloseAndRemove"); 1870 HGCMSvcHlpStamRegister(g_pHelpers, &g_StatCloseAndRemoveFail, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "SHFL_FN_CLOSE_AND_REMOVE failures", "/HGCM/VBoxSharedFolders/FnCloseAndRemoveFail"); 1862 1871 HGCMSvcHlpStamRegister(g_pHelpers, &g_StatRename, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "SHFL_FN_RENAME successes", "/HGCM/VBoxSharedFolders/FnRename"); 1863 1872 HGCMSvcHlpStamRegister(g_pHelpers, &g_StatRenameFail, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS, "SHFL_FN_RENAME failures", "/HGCM/VBoxSharedFolders/FnRenameFail"); -
trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp
r77861 r78467 2181 2181 } 2182 2182 #endif 2183 int vbsfRemove(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pPath, uint32_t cbPath, uint32_t flags) 2184 { 2183 int vbsfRemove(SHFLCLIENTDATA *pClient, SHFLROOT root, PCSHFLSTRING pPath, uint32_t cbPath, uint32_t flags, SHFLHANDLE hToClose) 2184 { 2185 2186 /* Validate input */ 2187 Assert(pPath); 2188 AssertReturn(pPath->u16Size > 0, VERR_INVALID_PARAMETER); 2189 2190 /* 2191 * Close the handle if specified. 2192 */ 2185 2193 int rc = VINF_SUCCESS; 2186 2187 /* Validate input */ 2188 if ( flags & ~(SHFL_REMOVE_FILE|SHFL_REMOVE_DIR|SHFL_REMOVE_SYMLINK) 2189 || cbPath == 0 2190 || pPath == 0) 2191 { 2192 AssertFailed(); 2193 return VERR_INVALID_PARAMETER; 2194 } 2195 2196 /* Build a host full path for the given path 2197 * and convert ucs2 to utf8 if necessary. 2198 */ 2199 char *pszFullPath = NULL; 2200 2201 rc = vbsfBuildFullPath(pClient, root, pPath, cbPath, &pszFullPath, NULL); 2194 if (hToClose != SHFL_HANDLE_NIL) 2195 rc = vbsfClose(pClient, root, hToClose); 2202 2196 if (RT_SUCCESS(rc)) 2203 2197 { 2204 /* is the guest allowed to write to this share? */ 2205 bool fWritable; 2206 rc = vbsfMappingsQueryWritable(pClient, root, &fWritable); 2207 if (RT_FAILURE(rc) || !fWritable) 2208 rc = VERR_WRITE_PROTECT; 2209 2198 /* 2199 * Build a host full path for the given path and convert ucs2 to utf8 if necessary. 2200 */ 2201 char *pszFullPath = NULL; 2202 rc = vbsfBuildFullPath(pClient, root, pPath, cbPath, &pszFullPath, NULL); 2210 2203 if (RT_SUCCESS(rc)) 2211 2204 { 2212 if (flags & SHFL_REMOVE_SYMLINK) 2213 rc = RTSymlinkDelete(pszFullPath, 0); 2214 else if (flags & SHFL_REMOVE_FILE) 2215 rc = RTFileDelete(pszFullPath); 2205 /* 2206 * Is the guest allowed to write to this share? 2207 */ 2208 bool fWritable; 2209 rc = vbsfMappingsQueryWritable(pClient, root, &fWritable); 2210 if (RT_SUCCESS(rc) && fWritable) 2211 { 2212 /* 2213 * Do the removal/deletion according to the type flags. 2214 */ 2215 if (flags & SHFL_REMOVE_SYMLINK) 2216 rc = RTSymlinkDelete(pszFullPath, 0); 2217 else if (flags & SHFL_REMOVE_FILE) 2218 rc = RTFileDelete(pszFullPath); 2219 else 2220 rc = RTDirRemove(pszFullPath); 2221 } 2216 2222 else 2217 rc = RTDirRemove(pszFullPath); 2218 } 2219 2220 #ifndef DEBUG_dmik 2221 // VERR_ACCESS_DENIED for example? 2222 // Assert(rc == VINF_SUCCESS || rc == VERR_DIR_NOT_EMPTY); 2223 #endif 2224 /* free the path string */ 2225 vbsfFreeFullPath(pszFullPath); 2223 rc = VERR_WRITE_PROTECT; 2224 2225 /* free the path string */ 2226 vbsfFreeFullPath(pszFullPath); 2227 } 2226 2228 } 2227 2229 return rc; -
trunk/src/VBox/HostServices/SharedFolders/vbsf.h
r77848 r78467 40 40 int vbsfLock(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint64_t length, uint32_t flags); 41 41 int vbsfUnlock(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint64_t length, uint32_t flags); 42 int vbsfRemove(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pPath, uint32_t cbPath, uint32_t flags);42 int vbsfRemove(SHFLCLIENTDATA *pClient, SHFLROOT root, PCSHFLSTRING pPath, uint32_t cbPath, uint32_t flags, SHFLHANDLE hToClose); 43 43 int vbsfRename(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pSrc, SHFLSTRING *pDest, uint32_t flags); 44 44 int vbsfCopyFile(SHFLCLIENTDATA *pClient, SHFLROOT idRootSrc, PCSHFLSTRING pStrPathSrc,
Note:
See TracChangeset
for help on using the changeset viewer.