- Timestamp:
- Mar 13, 2018 3:51:14 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/HostServices/GuestControlSvc.h
r69107 r71314 5 5 6 6 /* 7 * Copyright (C) 2011-201 7Oracle Corporation7 * Copyright (C) 2011-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 193 193 * Renames a path on the guest. 194 194 */ 195 HOST_PATH_RENAME = 330 195 HOST_PATH_RENAME = 330, 196 /** 197 * Retrieves the user's documents directory. 198 */ 199 HOST_PATH_USER_DOCUMENTS = 331, 200 /** 201 * Retrieves the user's home directory. 202 */ 203 HOST_PATH_USER_HOME = 332 196 204 }; 197 205 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp
r69500 r71314 5 5 6 6 /* 7 * Copyright (C) 2013-201 7Oracle Corporation7 * Copyright (C) 2013-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 625 625 #ifdef DEBUG 626 626 VGSvcVerbose(4, "Renaming '%s' to '%s' returned rc=%Rrc\n", szSource, szDest, rc); 627 #endif 628 return rc; 629 } 630 631 632 static int vgsvcGstCtrlSessionHandlePathUserDocuments(PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx) 633 { 634 AssertPtrReturn(pSession, VERR_INVALID_POINTER); 635 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER); 636 637 char szPath[RTPATH_MAX]; 638 int rc = RTPathUserDocuments(szPath, sizeof(szPath)); 639 640 /* Report back in any case. */ 641 int rc2 = VbglR3GuestCtrlMsgReplyEx(pHostCtx, rc, 0 /* Type */, 642 szPath, strlen(szPath) + 1 /* Include terminating zero */); 643 if (RT_FAILURE(rc2)) 644 VGSvcError("Failed to report user documents, rc=%Rrc\n", rc2); 645 if (RT_SUCCESS(rc)) 646 rc = rc2; 647 648 #ifdef DEBUG 649 VGSvcVerbose(4, "User documents is '%s', rc=%Rrc\n", szPath, rc); 650 #endif 651 return rc; 652 } 653 654 655 static int vgsvcGstCtrlSessionHandlePathUserHome(PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx) 656 { 657 AssertPtrReturn(pSession, VERR_INVALID_POINTER); 658 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER); 659 660 char szPath[RTPATH_MAX]; 661 int rc = RTPathUserHome(szPath, sizeof(szPath)); 662 663 /* Report back in any case. */ 664 int rc2 = VbglR3GuestCtrlMsgReplyEx(pHostCtx, rc, 0 /* Type */, 665 szPath, strlen(szPath) + 1 /* Include terminating zero */); 666 if (RT_FAILURE(rc2)) 667 VGSvcError("Failed to report user home, rc=%Rrc\n", rc2); 668 if (RT_SUCCESS(rc)) 669 rc = rc2; 670 671 #ifdef DEBUG 672 VGSvcVerbose(4, "User home is '%s', rc=%Rrc\n", szPath, rc); 627 673 #endif 628 674 return rc; … … 1026 1072 break; 1027 1073 1074 case HOST_PATH_USER_DOCUMENTS: 1075 if (fImpersonated) 1076 rc = vgsvcGstCtrlSessionHandlePathUserDocuments(pSession, pHostCtx); 1077 else 1078 rc = VERR_NOT_SUPPORTED; 1079 break; 1080 1081 case HOST_PATH_USER_HOME: 1082 if (fImpersonated) 1083 rc = vgsvcGstCtrlSessionHandlePathUserHome(pSession, pHostCtx); 1084 else 1085 rc = VERR_NOT_SUPPORTED; 1086 break; 1087 1028 1088 default: 1029 1089 rc = VbglR3GuestCtrlMsgSkip(pHostCtx->uClientID); -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r71257 r71314 11858 11858 <interface 11859 11859 name="IGuestSession" extends="$unknown" 11860 uuid=" 049af4e1-9732-4815-b01a-d64d21c064fe"11860 uuid="8d3485b3-64a9-4995-998e-6c602b91abd2" 11861 11861 wsmap="managed" 11862 11862 reservedMethods="8" reservedAttributes="8" … … 11980 11980 <attribute name="currentDirectory" type="wstring"> 11981 11981 <desc> 11982 The current directory of the session. Guest path style.11982 Gets or sets the current directory of the session. Guest path style. 11983 11983 <result name="E_NOTIMPL"> 11984 11984 This attribute is not implemented yet. 11985 11985 </result> 11986 </desc> 11987 </attribute> 11988 <attribute name="userHome" type="wstring" readonly="yes"> 11989 <desc> 11990 Returns the user's home / profile directory. Guest path style. 11991 </desc> 11992 </attribute> 11993 <attribute name="userDocuments" type="wstring" readonly="yes"> 11994 <desc> 11995 Returns the user's documents directory. Guest path style. 11986 11996 </desc> 11987 11997 </attribute> -
trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h
r71264 r71314 984 984 void* MutableRaw(void) { return pvData; } 985 985 986 Utf8Str ToString(void) 987 { 988 const char *pszStr = (const char *)pvData; 989 size_t cbStr = cbData; 990 991 if (!RTStrValidateEncodingEx(pszStr, cbStr, 992 RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED | RTSTR_VALIDATE_ENCODING_EXACT_LENGTH)) 993 return ""; 994 995 return Utf8Str(pszStr, cbStr); 996 } 997 986 998 protected: 987 999 -
trunk/src/VBox/Main/include/GuestSessionImpl.h
r71251 r71314 350 350 HRESULT getCurrentDirectory(com::Utf8Str &aCurrentDirectory); 351 351 HRESULT setCurrentDirectory(const com::Utf8Str &aCurrentDirectory); 352 HRESULT getUserDocuments(com::Utf8Str &aUserDocuments); 353 HRESULT getUserHome(com::Utf8Str &aUserHome); 352 354 HRESULT getDirectories(std::vector<ComPtr<IGuestDirectory> > &aDirectories); 353 355 HRESULT getFiles(std::vector<ComPtr<IGuestFile> > &aFiles); … … 533 535 int i_pathRenameInternal(const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags, 534 536 int *pGuestRc); 537 int i_pathUserDocuments(Utf8Str &strPath, int *prcGuest); 538 int i_pathUserHome(Utf8Str &strPath, int *prcGuest); 535 539 int i_processRemoveFromList(GuestProcess *pProcess); 536 540 int i_processCreateExInternal(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProgress); -
trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
r71304 r71314 544 544 } 545 545 546 HRESULT GuestSession::getUserHome(com::Utf8Str &aUserHome) 547 { 548 HRESULT hr = i_isReadyExternal(); 549 if (FAILED(hr)) 550 return hr; 551 552 int rcGuest; 553 int vrc = i_pathUserHome(aUserHome, &rcGuest); 554 if (RT_FAILURE(vrc)) 555 { 556 switch (vrc) 557 { 558 case VERR_NOT_SUPPORTED: 559 hr = setError(VBOX_E_IPRT_ERROR, tr("Getting the user's home path is not supported by installed Guest Additions")); 560 break; 561 562 case VERR_GSTCTL_GUEST_ERROR: 563 hr = setError(VBOX_E_IPRT_ERROR, tr("Getting the user's home path failed: %Rrc"), rcGuest); 564 break; 565 566 default: 567 hr = setError(VBOX_E_IPRT_ERROR, tr("Getting the user's home path failed: %Rrc"), vrc); 568 break; 569 } 570 } 571 572 return hr; 573 } 574 575 HRESULT GuestSession::getUserDocuments(com::Utf8Str &aUserDocuments) 576 { 577 HRESULT hr = i_isReadyExternal(); 578 if (FAILED(hr)) 579 return hr; 580 581 int rcGuest; 582 int vrc = i_pathUserDocuments(aUserDocuments, &rcGuest); 583 if (RT_FAILURE(vrc)) 584 { 585 switch (vrc) 586 { 587 case VERR_NOT_SUPPORTED: 588 hr = setError(VBOX_E_IPRT_ERROR, tr("Getting the user's documents path is not supported by installed Guest Additions")); 589 break; 590 591 case VERR_GSTCTL_GUEST_ERROR: 592 hr = setError(VBOX_E_IPRT_ERROR, tr("Getting the user's documents path failed: %Rrc"), rcGuest); 593 break; 594 595 default: 596 hr = setError(VBOX_E_IPRT_ERROR, tr("Getting the user's documents path failed: %Rrc"), vrc); 597 break; 598 } 599 } 600 601 return hr; 602 } 603 546 604 HRESULT GuestSession::getDirectories(std::vector<ComPtr<IGuestDirectory> > &aDirectories) 547 605 { … … 650 708 if (RT_SUCCESS(vrc)) 651 709 vrc = i_waitForStatusChange(pEvent, GuestSessionWaitForFlag_Terminate, uTimeoutMS, 652 NULL /* Session status */, prcGuest);710 NULL /* Session status */, prcGuest); 653 711 654 712 unregisterWaitEvent(pEvent); … … 1798 1856 } 1799 1857 1800 int GuestSession::i_pathRenameInternal(const Utf8Str &strSource, const Utf8Str &strDest, 1801 uint32_t uFlags, int *prcGuest) 1858 int GuestSession::i_pathRenameInternal(const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags, int *prcGuest) 1802 1859 { 1803 1860 AssertReturn(!(uFlags & ~PATHRENAME_FLAG_VALID_MASK), VERR_INVALID_PARAMETER); … … 1833 1890 && prcGuest) 1834 1891 *prcGuest = pEvent->GuestResult(); 1892 } 1893 1894 unregisterWaitEvent(pEvent); 1895 1896 LogFlowFuncLeaveRC(vrc); 1897 return vrc; 1898 } 1899 1900 /** 1901 * Returns the user's absolute documents path, if any. 1902 * 1903 * @return VBox status code. 1904 * @param strPath Where to store the user's document path. 1905 * @param prcGuest Guest rc, when returning VERR_GSTCTL_GUEST_ERROR. 1906 * Any other return code indicates some host side error. 1907 */ 1908 int GuestSession::i_pathUserDocuments(Utf8Str &strPath, int *prcGuest) 1909 { 1910 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1911 1912 /** @todo Cache the user's document path? */ 1913 1914 GuestWaitEvent *pEvent = NULL; 1915 int vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */, &pEvent); 1916 if (RT_FAILURE(vrc)) 1917 return vrc; 1918 1919 /* Prepare HGCM call. */ 1920 VBOXHGCMSVCPARM paParms[2]; 1921 int i = 0; 1922 paParms[i++].setUInt32(pEvent->ContextID()); 1923 1924 alock.release(); /* Drop write lock before sending. */ 1925 1926 vrc = i_sendCommand(HOST_PATH_USER_DOCUMENTS, i, paParms); 1927 if (RT_SUCCESS(vrc)) 1928 { 1929 vrc = pEvent->Wait(30 * 1000); 1930 if (RT_SUCCESS(vrc)) 1931 { 1932 strPath = pEvent->Payload().ToString(); 1933 } 1934 else 1935 { 1936 if (vrc == VERR_GSTCTL_GUEST_ERROR) 1937 { 1938 if (prcGuest) 1939 *prcGuest = pEvent->GuestResult(); 1940 } 1941 } 1942 } 1943 1944 unregisterWaitEvent(pEvent); 1945 1946 LogFlowFuncLeaveRC(vrc); 1947 return vrc; 1948 } 1949 1950 /** 1951 * Returns the user's absolute home path, if any. 1952 * 1953 * @return VBox status code. 1954 * @param strPath Where to store the user's home path. 1955 * @param prcGuest Guest rc, when returning VERR_GSTCTL_GUEST_ERROR. 1956 * Any other return code indicates some host side error. 1957 */ 1958 int GuestSession::i_pathUserHome(Utf8Str &strPath, int *prcGuest) 1959 { 1960 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1961 1962 /** @todo Cache the user's home path? */ 1963 1964 GuestWaitEvent *pEvent = NULL; 1965 int vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */, &pEvent); 1966 if (RT_FAILURE(vrc)) 1967 return vrc; 1968 1969 /* Prepare HGCM call. */ 1970 VBOXHGCMSVCPARM paParms[2]; 1971 int i = 0; 1972 paParms[i++].setUInt32(pEvent->ContextID()); 1973 1974 alock.release(); /* Drop write lock before sending. */ 1975 1976 vrc = i_sendCommand(HOST_PATH_USER_HOME, i, paParms); 1977 if (RT_SUCCESS(vrc)) 1978 { 1979 vrc = pEvent->Wait(30 * 1000); 1980 if (RT_SUCCESS(vrc)) 1981 { 1982 strPath = pEvent->Payload().ToString(); 1983 } 1984 else 1985 { 1986 if (vrc == VERR_GSTCTL_GUEST_ERROR) 1987 { 1988 if (prcGuest) 1989 *prcGuest = pEvent->GuestResult(); 1990 } 1991 } 1835 1992 } 1836 1993
Note:
See TracChangeset
for help on using the changeset viewer.