Changeset 98713 in vbox
- Timestamp:
- Feb 24, 2023 10:15:30 AM (2 years ago)
- svn:sync-xref-src-repo-rev:
- 156013
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/GuestSessionImpl.h
r98665 r98713 357 357 /** @} */ 358 358 359 /** @name Public internal methods for supporting older Guest Additions via 360 VBoxService' built-in toolbox (< 7.1). */ 361 int i_directoryCreateViaToolbox(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pvrcGuest); 362 int i_fileRemoveViaToolbox(const Utf8Str &strPath, int *pvrcGuest); 363 int i_fsCreateTempViaToolbox(const Utf8Str &strTemplate, const Utf8Str &strPath, bool fDirectory, Utf8Str &strName, 364 uint32_t fMode, bool fSecure, int *pvrcGuest); 365 int i_fsQueryInfoViaToolbox(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pvrcGuest); 366 /** @} */ 367 359 368 public: 360 369 -
trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
r98709 r98713 934 934 } 935 935 936 #ifdef VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT 937 /** 938 * Creates a directory on the guest. 939 * 940 * @returns VBox status code. 941 * @param strPath Path on guest to directory to create. 942 * @param uMode Creation mode to use (octal, 0777 max). 943 * @param uFlags Directory creation flags to use. 944 * @param pvrcGuest Where to return the guest error when 945 * VERR_GSTCTL_GUEST_ERROR was returned. 946 */ 947 int GuestSession::i_directoryCreateViaToolbox(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pvrcGuest) 948 { 949 int vrc = VINF_SUCCESS; 950 951 GuestProcessStartupInfo procInfo; 952 procInfo.mFlags = ProcessCreateFlag_Hidden; 953 procInfo.mExecutable = VBOXSERVICE_TOOL_MKDIR; 954 955 try 956 { 957 procInfo.mArguments.push_back(procInfo.mExecutable); /* Set argv0. */ 958 959 /* Construct arguments. */ 960 if (uFlags) 961 { 962 if (uFlags & DirectoryCreateFlag_Parents) 963 procInfo.mArguments.push_back(Utf8Str("--parents")); /* We also want to create the parent directories. */ 964 else 965 vrc = VERR_INVALID_PARAMETER; 966 } 967 968 if ( RT_SUCCESS(vrc) 969 && uMode) 970 { 971 procInfo.mArguments.push_back(Utf8Str("--mode")); /* Set the creation mode. */ 972 973 char szMode[16]; 974 if (RTStrPrintf(szMode, sizeof(szMode), "%o", uMode)) 975 procInfo.mArguments.push_back(Utf8Str(szMode)); 976 else 977 vrc = VERR_BUFFER_OVERFLOW; 978 } 979 980 procInfo.mArguments.push_back("--"); /* '--version' is a valid directory name. */ 981 procInfo.mArguments.push_back(strPath); /* The directory we want to create. */ 982 } 983 catch (std::bad_alloc &) 984 { 985 vrc = VERR_NO_MEMORY; 986 } 987 988 if (RT_SUCCESS(vrc)) 989 vrc = GuestProcessToolbox::runTool(this, procInfo, pvrcGuest); 990 991 return vrc; 992 } 993 #endif /* VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT */ 994 936 995 /** 937 996 * Creates a directory on the guest. … … 992 1051 #endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */ 993 1052 { 994 GuestProcessStartupInfo procInfo; 995 procInfo.mFlags = ProcessCreateFlag_Hidden; 996 procInfo.mExecutable = VBOXSERVICE_TOOL_MKDIR; 997 998 try 999 { 1000 procInfo.mArguments.push_back(procInfo.mExecutable); /* Set argv0. */ 1001 1002 /* Construct arguments. */ 1003 if (uFlags) 1004 { 1005 if (uFlags & DirectoryCreateFlag_Parents) 1006 procInfo.mArguments.push_back(Utf8Str("--parents")); /* We also want to create the parent directories. */ 1007 else 1008 vrc = VERR_INVALID_PARAMETER; 1009 } 1010 1011 if ( RT_SUCCESS(vrc) 1012 && uMode) 1013 { 1014 procInfo.mArguments.push_back(Utf8Str("--mode")); /* Set the creation mode. */ 1015 1016 char szMode[16]; 1017 if (RTStrPrintf(szMode, sizeof(szMode), "%o", uMode)) 1018 procInfo.mArguments.push_back(Utf8Str(szMode)); 1019 else 1020 vrc = VERR_BUFFER_OVERFLOW; 1021 } 1022 1023 procInfo.mArguments.push_back("--"); /* '--version' is a valid directory name. */ 1024 procInfo.mArguments.push_back(strPath); /* The directory we want to create. */ 1025 } 1026 catch (std::bad_alloc &) 1027 { 1028 vrc = VERR_NO_MEMORY; 1029 } 1030 1031 if (RT_SUCCESS(vrc)) 1032 vrc = GuestProcessToolbox::runTool(this, procInfo, pvrcGuest); 1053 vrc = i_directoryCreateViaToolbox(strPath, uMode, uFlags, pvrcGuest); 1033 1054 } 1034 1055 … … 1191 1212 1192 1213 LogFlowFuncLeaveRC(vrc); 1214 return vrc; 1215 } 1216 1217 /** 1218 * Creates a temporary directory / file on the guest (legacy version). 1219 * 1220 * @returns VBox status code. 1221 * @returns VERR_GSTCTL_GUEST_ERROR on received guest error. 1222 * @param strTemplate Name template to use. 1223 * \sa RTDirCreateTemp / RTDirCreateTempSecure. 1224 * @param strPath Path where to create the temporary directory / file. 1225 * @param fDirectory Whether to create a temporary directory or file. 1226 * @param strName Where to return the created temporary name on success. 1227 * @param fMode File mode to use for creation (octal, umask-style). 1228 * Ignored when \a fSecure is specified. 1229 * @param fSecure Whether to perform a secure creation or not. 1230 * @param pvrcGuest Guest VBox status code, when returning 1231 * VERR_GSTCTL_GUEST_ERROR. 1232 */ 1233 int GuestSession::i_fsCreateTempViaToolbox(const Utf8Str &strTemplate, const Utf8Str &strPath, bool fDirectory, Utf8Str &strName, 1234 uint32_t fMode, bool fSecure, int *pvrcGuest) 1235 { 1236 int vrc; 1237 1238 GuestProcessStartupInfo procInfo; 1239 procInfo.mFlags = ProcessCreateFlag_WaitForStdOut; 1240 try 1241 { 1242 procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_MKTEMP); 1243 procInfo.mArguments.push_back(procInfo.mExecutable); /* Set argv0. */ 1244 procInfo.mArguments.push_back(Utf8Str("--machinereadable")); 1245 if (fDirectory) 1246 procInfo.mArguments.push_back(Utf8Str("-d")); 1247 if (strPath.length()) /* Otherwise use /tmp or equivalent. */ 1248 { 1249 procInfo.mArguments.push_back(Utf8Str("-t")); 1250 procInfo.mArguments.push_back(strPath); 1251 } 1252 /* Note: Secure flag and mode cannot be specified at the same time. */ 1253 if (fSecure) 1254 { 1255 procInfo.mArguments.push_back(Utf8Str("--secure")); 1256 } 1257 else 1258 { 1259 procInfo.mArguments.push_back(Utf8Str("--mode")); 1260 1261 /* Note: Pass the mode unmodified down to the guest. See @ticketref{21394}. */ 1262 char szMode[16]; 1263 vrc = RTStrPrintf2(szMode, sizeof(szMode), "%d", fMode); 1264 AssertRCReturn(vrc, vrc); 1265 procInfo.mArguments.push_back(szMode); 1266 } 1267 procInfo.mArguments.push_back("--"); /* strTemplate could be '--help'. */ 1268 procInfo.mArguments.push_back(strTemplate); 1269 } 1270 catch (std::bad_alloc &) 1271 { 1272 Log(("Out of memory!\n")); 1273 return VERR_NO_MEMORY; 1274 } 1275 1276 GuestCtrlStreamObjects stdOut; 1277 int vrcGuest; 1278 vrc = GuestProcessToolbox::runTool(this, procInfo, &vrcGuest, &stdOut); 1279 if (!GuestProcess::i_isGuestError(vrc)) 1280 { 1281 GuestFsObjData objData; 1282 if (!stdOut.empty()) 1283 { 1284 vrc = objData.FromToolboxMkTemp(stdOut.at(0)); 1285 if (RT_FAILURE(vrc)) 1286 { 1287 vrcGuest = vrc; 1288 if (pvrcGuest) 1289 *pvrcGuest = vrcGuest; 1290 vrc = VERR_GSTCTL_GUEST_ERROR; 1291 } 1292 } 1293 else 1294 vrc = VERR_BROKEN_PIPE; 1295 1296 if (RT_SUCCESS(vrc)) 1297 strName = objData.mName; 1298 } 1299 else if (pvrcGuest) 1300 *pvrcGuest = vrcGuest; 1301 1193 1302 return vrc; 1194 1303 } … … 1282 1391 #endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */ 1283 1392 { 1284 GuestProcessStartupInfo procInfo; 1285 procInfo.mFlags = ProcessCreateFlag_WaitForStdOut; 1286 try 1287 { 1288 procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_MKTEMP); 1289 procInfo.mArguments.push_back(procInfo.mExecutable); /* Set argv0. */ 1290 procInfo.mArguments.push_back(Utf8Str("--machinereadable")); 1291 if (fDirectory) 1292 procInfo.mArguments.push_back(Utf8Str("-d")); 1293 if (strPath.length()) /* Otherwise use /tmp or equivalent. */ 1294 { 1295 procInfo.mArguments.push_back(Utf8Str("-t")); 1296 procInfo.mArguments.push_back(strPath); 1297 } 1298 /* Note: Secure flag and mode cannot be specified at the same time. */ 1299 if (fSecure) 1300 { 1301 procInfo.mArguments.push_back(Utf8Str("--secure")); 1302 } 1303 else 1304 { 1305 procInfo.mArguments.push_back(Utf8Str("--mode")); 1306 1307 /* Note: Pass the mode unmodified down to the guest. See @ticketref{21394}. */ 1308 char szMode[16]; 1309 vrc = RTStrPrintf2(szMode, sizeof(szMode), "%d", fMode); 1310 AssertRCReturn(vrc, vrc); 1311 procInfo.mArguments.push_back(szMode); 1312 } 1313 procInfo.mArguments.push_back("--"); /* strTemplate could be '--help'. */ 1314 procInfo.mArguments.push_back(strTemplate); 1315 } 1316 catch (std::bad_alloc &) 1317 { 1318 Log(("Out of memory!\n")); 1319 return VERR_NO_MEMORY; 1320 } 1321 1322 GuestCtrlStreamObjects stdOut; 1323 vrc = GuestProcessToolbox::runTool(this, procInfo, &vrcGuest, &stdOut); 1324 if (!GuestProcess::i_isGuestError(vrc)) 1325 { 1326 GuestFsObjData objData; 1327 if (!stdOut.empty()) 1328 { 1329 vrc = objData.FromToolboxMkTemp(stdOut.at(0)); 1330 if (RT_FAILURE(vrc)) 1331 { 1332 vrcGuest = vrc; 1333 if (pvrcGuest) 1334 *pvrcGuest = vrcGuest; 1335 vrc = VERR_GSTCTL_GUEST_ERROR; 1336 } 1337 } 1338 else 1339 vrc = VERR_BROKEN_PIPE; 1340 1341 if (RT_SUCCESS(vrc)) 1342 strName = objData.mName; 1343 } 1344 else if (pvrcGuest) 1345 *pvrcGuest = vrcGuest; 1393 vrc = i_fsCreateTempViaToolbox(strTemplate, strPath, fDirectory, strName, fMode, fSecure, pvrcGuest); 1346 1394 } 1347 1395 … … 1686 1734 1687 1735 /** 1736 * Removes a file from the guest (legacy version). 1737 * 1738 * @returns VBox status code. 1739 * @returns VERR_GSTCTL_GUEST_ERROR on received guest error. 1740 * @param strPath Path of file on guest to remove. 1741 * @param pvrcGuest Where to return the guest error when 1742 * VERR_GSTCTL_GUEST_ERROR was returned. Optional. 1743 */ 1744 int GuestSession::i_fileRemoveViaToolbox(const Utf8Str &strPath, int *pvrcGuest) 1745 { 1746 GuestProcessStartupInfo procInfo; 1747 GuestToolboxStream streamOut; 1748 1749 procInfo.mFlags = ProcessCreateFlag_WaitForStdOut; 1750 procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_RM); 1751 1752 try 1753 { 1754 procInfo.mArguments.push_back(procInfo.mExecutable); /* Set argv0. */ 1755 procInfo.mArguments.push_back(Utf8Str("--machinereadable")); 1756 procInfo.mArguments.push_back("--"); /* strPath could be '--help', which is a valid filename. */ 1757 procInfo.mArguments.push_back(strPath); /* The file we want to remove. */ 1758 } 1759 catch (std::bad_alloc &) 1760 { 1761 return VERR_NO_MEMORY; 1762 } 1763 1764 GuestCtrlStreamObjects stdOut; 1765 int vrcGuest; 1766 int vrc = GuestProcessToolbox::runTool(this, procInfo, &vrcGuest, &stdOut); 1767 if (!GuestProcess::i_isGuestError(vrc)) 1768 { 1769 if (!stdOut.empty()) 1770 { 1771 GuestFsObjData objData; 1772 vrc = objData.FromToolboxRm(stdOut.at(0)); 1773 if (RT_FAILURE(vrc)) 1774 { 1775 vrcGuest = vrc; 1776 if (pvrcGuest) 1777 *pvrcGuest = vrcGuest; 1778 vrc = VERR_GSTCTL_GUEST_ERROR; 1779 } 1780 } 1781 else 1782 vrc = VERR_BROKEN_PIPE; 1783 } 1784 else if (pvrcGuest) 1785 *pvrcGuest = vrcGuest; 1786 1787 return vrc; 1788 } 1789 1790 /** 1688 1791 * Removes a file from the guest. 1689 1792 * … … 1733 1836 #endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */ 1734 1837 { 1735 GuestProcessStartupInfo procInfo; 1736 GuestToolboxStream streamOut; 1737 1738 procInfo.mFlags = ProcessCreateFlag_WaitForStdOut; 1739 procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_RM); 1740 1741 try 1742 { 1743 procInfo.mArguments.push_back(procInfo.mExecutable); /* Set argv0. */ 1744 procInfo.mArguments.push_back(Utf8Str("--machinereadable")); 1745 procInfo.mArguments.push_back("--"); /* strPath could be '--help', which is a valid filename. */ 1746 procInfo.mArguments.push_back(strPath); /* The file we want to remove. */ 1747 } 1748 catch (std::bad_alloc &) 1749 { 1750 return VERR_NO_MEMORY; 1751 } 1752 1753 GuestCtrlStreamObjects stdOut; 1754 vrc = GuestProcessToolbox::runTool(this, procInfo, &vrcGuest, &stdOut); 1755 if (!GuestProcess::i_isGuestError(vrc)) 1756 { 1757 if (!stdOut.empty()) 1758 { 1759 GuestFsObjData objData; 1760 vrc = objData.FromToolboxRm(stdOut.at(0)); 1761 if (RT_FAILURE(vrc)) 1762 { 1763 vrcGuest = vrc; 1764 if (pvrcGuest) 1765 *pvrcGuest = vrcGuest; 1766 vrc = VERR_GSTCTL_GUEST_ERROR; 1767 } 1768 } 1769 else 1770 vrc = VERR_BROKEN_PIPE; 1771 } 1772 else if (pvrcGuest) 1773 *pvrcGuest = vrcGuest; 1838 vrc = i_fileRemoveViaToolbox(strPath, pvrcGuest); 1774 1839 } 1775 1840 … … 1947 2012 if (RT_SUCCESS(vrc)) 1948 2013 *pllSize = objData.mObjectSize; 2014 2015 return vrc; 2016 } 2017 2018 /** 2019 * Queries information of a file system object (file, directory, ...). Legacy version. 2020 * 2021 * @return IPRT status code. 2022 * @param strPath Path to file system object to query information for. 2023 * @param fFollowSymlinks Whether to follow symbolic links or not. 2024 * @param objData Where to return the file system object data, if found. 2025 * @param pvrcGuest Guest VBox status code, when returning 2026 * VERR_GSTCTL_GUEST_ERROR. Any other return code 2027 * indicates some host side error. 2028 */ 2029 int GuestSession::i_fsQueryInfoViaToolbox(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pvrcGuest) 2030 { 2031 /** @todo Merge this with IGuestFile::queryInfo(). */ 2032 GuestProcessStartupInfo procInfo; 2033 procInfo.mFlags = ProcessCreateFlag_WaitForStdOut; 2034 try 2035 { 2036 procInfo.mExecutable = VBOXSERVICE_TOOL_STAT; 2037 procInfo.mArguments.push_back(procInfo.mExecutable); /* Set argv0. */ 2038 procInfo.mArguments.push_back(Utf8Str("--machinereadable")); 2039 if (fFollowSymlinks) 2040 procInfo.mArguments.push_back(Utf8Str("-L")); 2041 procInfo.mArguments.push_back("--"); /* strPath could be '--help', which is a valid filename. */ 2042 procInfo.mArguments.push_back(strPath); 2043 } 2044 catch (std::bad_alloc &) 2045 { 2046 Log(("Out of memory!\n")); 2047 return VERR_NO_MEMORY; 2048 } 2049 2050 GuestCtrlStreamObjects stdOut; 2051 int vrcGuest; 2052 int vrc = GuestProcessToolbox::runTool(this, procInfo, &vrcGuest, &stdOut); 2053 if (!GuestProcess::i_isGuestError(vrc)) 2054 { 2055 if (!stdOut.empty()) 2056 { 2057 vrc = objData.FromToolboxStat(stdOut.at(0)); 2058 if (RT_FAILURE(vrc)) 2059 { 2060 vrcGuest = vrc; 2061 if (pvrcGuest) 2062 *pvrcGuest = vrcGuest; 2063 vrc = VERR_GSTCTL_GUEST_ERROR; 2064 } 2065 } 2066 else 2067 vrc = VERR_BROKEN_PIPE; 2068 } 2069 else if (pvrcGuest) 2070 *pvrcGuest = vrcGuest; 1949 2071 1950 2072 return vrc; … … 2026 2148 #endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */ 2027 2149 { 2028 /** @todo Merge this with IGuestFile::queryInfo(). */ 2029 GuestProcessStartupInfo procInfo; 2030 procInfo.mFlags = ProcessCreateFlag_WaitForStdOut; 2031 try 2032 { 2033 procInfo.mExecutable = VBOXSERVICE_TOOL_STAT; 2034 procInfo.mArguments.push_back(procInfo.mExecutable); /* Set argv0. */ 2035 procInfo.mArguments.push_back(Utf8Str("--machinereadable")); 2036 if (fFollowSymlinks) 2037 procInfo.mArguments.push_back(Utf8Str("-L")); 2038 procInfo.mArguments.push_back("--"); /* strPath could be '--help', which is a valid filename. */ 2039 procInfo.mArguments.push_back(strPath); 2040 } 2041 catch (std::bad_alloc &) 2042 { 2043 Log(("Out of memory!\n")); 2044 return VERR_NO_MEMORY; 2045 } 2046 2047 GuestCtrlStreamObjects stdOut; 2048 vrc = GuestProcessToolbox::runTool(this, procInfo, &vrcGuest, &stdOut); 2049 if (!GuestProcess::i_isGuestError(vrc)) 2050 { 2051 if (!stdOut.empty()) 2052 { 2053 vrc = objData.FromToolboxStat(stdOut.at(0)); 2054 if (RT_FAILURE(vrc)) 2055 { 2056 vrcGuest = vrc; 2057 if (pvrcGuest) 2058 *pvrcGuest = vrcGuest; 2059 vrc = VERR_GSTCTL_GUEST_ERROR; 2060 } 2061 } 2062 else 2063 vrc = VERR_BROKEN_PIPE; 2064 } 2065 else if (pvrcGuest) 2066 *pvrcGuest = vrcGuest; 2150 vrc = i_fsQueryInfoViaToolbox(strPath, fFollowSymlinks, objData, pvrcGuest); 2067 2151 } 2068 2152
Note:
See TracChangeset
for help on using the changeset viewer.