Changeset 95274 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Jun 14, 2022 10:48:33 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/win/svcmain.cpp
r95120 r95274 333 333 if (SUCCEEDED(hrc)) 334 334 { 335 /* 336 * Create VBoxSVCRegistration object and hand that to VBoxSDS. 337 */ 338 m_pVBoxSVC = new VBoxSVCRegistration(this); 339 hrc = m_ptrVirtualBoxSDS->RegisterVBoxSVC(m_pVBoxSVC, GetCurrentProcessId(), ppOtherVirtualBox); 335 /* By default the RPC_C_IMP_LEVEL_IDENTIFY is used for impersonation the client. It allows 336 ACL checking but restricts an access to system objects e.g. files. Call to CoSetProxyBlanket 337 elevates the impersonation level up to RPC_C_IMP_LEVEL_IMPERSONATE allowing the VBoxSDS 338 service to access the files. */ 339 hrc = CoSetProxyBlanket(m_ptrVirtualBoxSDS, 340 RPC_C_AUTHN_DEFAULT, 341 RPC_C_AUTHZ_DEFAULT, 342 COLE_DEFAULT_PRINCIPAL, 343 RPC_C_AUTHN_LEVEL_DEFAULT, 344 RPC_C_IMP_LEVEL_IMPERSONATE, 345 NULL, 346 EOAC_DEFAULT); 340 347 if (SUCCEEDED(hrc)) 341 348 { 342 g_fRegisteredWithVBoxSDS = !*ppOtherVirtualBox; 343 return hrc; 344 } 345 m_pVBoxSVC->Release(); 349 /* 350 * Create VBoxSVCRegistration object and hand that to VBoxSDS. 351 */ 352 m_pVBoxSVC = new VBoxSVCRegistration(this); 353 hrc = E_PENDING; 354 /* we try to register IVirtualBox 10 times */ 355 for (int regTimes = 0; hrc == E_PENDING && regTimes < 10; --regTimes) 356 { 357 hrc = m_ptrVirtualBoxSDS->RegisterVBoxSVC(m_pVBoxSVC, GetCurrentProcessId(), ppOtherVirtualBox); 358 if (SUCCEEDED(hrc)) 359 { 360 g_fRegisteredWithVBoxSDS = !*ppOtherVirtualBox; 361 return hrc; 362 } 363 /* sleep to give a time for windows session 0 registration */ 364 if (hrc == E_PENDING) 365 RTThreadSleep(1000); 366 } 367 m_pVBoxSVC->Release(); 368 } 346 369 } 347 370 m_ptrVirtualBoxSDS.setNull(); … … 687 710 break; 688 711 } 689 690 712 case WM_DESTROY: 691 713 { … … 823 845 { 824 846 /* never called, just need to be here */ 847 } 848 849 850 /* thread for registering the VBoxSVC started in session 0 */ 851 static DWORD WINAPI threadRegisterVirtualBox(LPVOID lpParam) throw() 852 { 853 HANDLE hEvent = (HANDLE)lpParam; 854 HRESULT hrc = CoInitializeEx(NULL, COINIT_MULTITHREADED); 855 if (SUCCEEDED(hrc)) 856 { 857 /* create IVirtualBox instance */ 858 ComPtr<IVirtualBox> pVirtualBox; 859 hrc = CoCreateInstance(CLSID_VirtualBox, NULL, CLSCTX_INPROC_SERVER /*CLSCTX_LOCAL_SERVER */, IID_IVirtualBox, 860 (void **)pVirtualBox.asOutParam()); 861 if (SUCCEEDED(hrc)) 862 { 863 /* wait a minute allowing clients to connect to the instance */ 864 WaitForSingleObject(hEvent, 60 * 1000); 865 /* remove reference. If anybody connected to IVirtualBox it will stay alive. */ 866 pVirtualBox.setNull(); 867 } 868 CoUninitialize(); 869 } 870 return 0L; 825 871 } 826 872 … … 891 937 { "-loginterval", 'I', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, 892 938 { "/loginterval", 'I', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, 939 { "--registervbox", 'b', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 940 { "-registervbox", 'b', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 941 { "/registervbox", 'b', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 893 942 }; 894 943 … … 901 950 uint32_t uHistoryFileTime = RT_SEC_1DAY; // max 1 day per file 902 951 uint64_t uHistoryFileSize = 100 * _1M; // max 100MB per file 952 bool fRegisterVBox = false; 903 953 904 954 RTGETOPTSTATE GetOptState; … … 981 1031 } 982 1032 1033 case 'b': 1034 fRegisterVBox = true; 1035 break; 1036 983 1037 default: 984 1038 /** @todo this assumes that stderr is visible, which is not … … 1101 1155 Log(("SVCMain: Failed to create main window\n")); 1102 1156 1157 /* create thread to register IVirtualBox in VBoxSDS 1158 * It is used for starting the VBoxSVC in the windows 1159 * session 0. */ 1160 HANDLE hWaitEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 1161 HANDLE hRegisterVBoxThread = NULL; 1162 if (fRegisterVBox) 1163 { 1164 DWORD dwThreadId = 0; 1165 hRegisterVBoxThread = CreateThread(NULL, 0, threadRegisterVirtualBox, (LPVOID)hWaitEvent, 1166 0, &dwThreadId); 1167 } 1168 1103 1169 MSG msg; 1104 1170 while (GetMessage(&msg, 0, 0, 0) > 0) … … 1109 1175 1110 1176 DestroyMainWindow(); 1177 1178 if (fRegisterVBox) 1179 { 1180 SetEvent(hWaitEvent); 1181 WaitForSingleObject(hRegisterVBoxThread, INFINITE); 1182 CloseHandle(hRegisterVBoxThread); 1183 CloseHandle(hWaitEvent); 1184 } 1111 1185 1112 1186 g_pModule->RevokeClassObjects();
Note:
See TracChangeset
for help on using the changeset viewer.