1 | /* $Id: ExtPackManagerImpl.cpp 69498 2017-10-28 15:07:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Main - interface for Extension Packs, VBoxSVC & VBoxC.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2016 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #include "ExtPackManagerImpl.h"
|
---|
23 | #include "ExtPackUtil.h"
|
---|
24 | #include "ThreadTask.h"
|
---|
25 |
|
---|
26 | #include <iprt/buildconfig.h>
|
---|
27 | #include <iprt/ctype.h>
|
---|
28 | #include <iprt/dir.h>
|
---|
29 | #include <iprt/env.h>
|
---|
30 | #include <iprt/file.h>
|
---|
31 | #include <iprt/ldr.h>
|
---|
32 | #include <iprt/manifest.h>
|
---|
33 | #include <iprt/param.h>
|
---|
34 | #include <iprt/path.h>
|
---|
35 | #include <iprt/pipe.h>
|
---|
36 | #include <iprt/process.h>
|
---|
37 | #include <iprt/string.h>
|
---|
38 |
|
---|
39 | #include <VBox/com/array.h>
|
---|
40 | #include <VBox/com/ErrorInfo.h>
|
---|
41 | #include <VBox/err.h>
|
---|
42 | #include <VBox/log.h>
|
---|
43 | #include <VBox/sup.h>
|
---|
44 | #include <VBox/version.h>
|
---|
45 | #include "AutoCaller.h"
|
---|
46 | #include "Global.h"
|
---|
47 | #include "ProgressImpl.h"
|
---|
48 | #ifdef VBOX_COM_INPROC
|
---|
49 | # include "ConsoleImpl.h"
|
---|
50 | #else
|
---|
51 | # include "VirtualBoxImpl.h"
|
---|
52 | #endif
|
---|
53 |
|
---|
54 |
|
---|
55 | /*********************************************************************************************************************************
|
---|
56 | * Defined Constants And Macros *
|
---|
57 | *********************************************************************************************************************************/
|
---|
58 | /** @def VBOX_EXTPACK_HELPER_NAME
|
---|
59 | * The name of the utility application we employ to install and uninstall the
|
---|
60 | * extension packs. This is a set-uid-to-root binary on unixy platforms, which
|
---|
61 | * is why it has to be a separate application.
|
---|
62 | */
|
---|
63 | #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
|
---|
64 | # define VBOX_EXTPACK_HELPER_NAME "VBoxExtPackHelperApp.exe"
|
---|
65 | #else
|
---|
66 | # define VBOX_EXTPACK_HELPER_NAME "VBoxExtPackHelperApp"
|
---|
67 | #endif
|
---|
68 |
|
---|
69 |
|
---|
70 | /*********************************************************************************************************************************
|
---|
71 | * Structures and Typedefs *
|
---|
72 | *********************************************************************************************************************************/
|
---|
73 | struct ExtPackBaseData
|
---|
74 | {
|
---|
75 | public:
|
---|
76 | /** The extension pack descriptor (loaded from the XML, mostly). */
|
---|
77 | VBOXEXTPACKDESC Desc;
|
---|
78 | /** The file system object info of the XML file.
|
---|
79 | * This is for detecting changes and save time in refresh(). */
|
---|
80 | RTFSOBJINFO ObjInfoDesc;
|
---|
81 | /** Whether it's usable or not. */
|
---|
82 | bool fUsable;
|
---|
83 | /** Why it is unusable. */
|
---|
84 | Utf8Str strWhyUnusable;
|
---|
85 | };
|
---|
86 |
|
---|
87 | #ifndef VBOX_COM_INPROC
|
---|
88 | /**
|
---|
89 | * Private extension pack data.
|
---|
90 | */
|
---|
91 | struct ExtPackFile::Data : public ExtPackBaseData
|
---|
92 | {
|
---|
93 | public:
|
---|
94 | /** The path to the tarball. */
|
---|
95 | Utf8Str strExtPackFile;
|
---|
96 | /** The SHA-256 hash of the file (as string). */
|
---|
97 | Utf8Str strDigest;
|
---|
98 | /** The file handle of the extension pack file. */
|
---|
99 | RTFILE hExtPackFile;
|
---|
100 | /** Our manifest for the tarball. */
|
---|
101 | RTMANIFEST hOurManifest;
|
---|
102 | /** Pointer to the extension pack manager. */
|
---|
103 | ComObjPtr<ExtPackManager> ptrExtPackMgr;
|
---|
104 | /** Pointer to the VirtualBox object so we can create a progress object. */
|
---|
105 | VirtualBox *pVirtualBox;
|
---|
106 |
|
---|
107 | RTMEMEF_NEW_AND_DELETE_OPERATORS();
|
---|
108 | };
|
---|
109 | #endif
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Private extension pack data.
|
---|
113 | */
|
---|
114 | struct ExtPack::Data : public ExtPackBaseData
|
---|
115 | {
|
---|
116 | public:
|
---|
117 | /** Where the extension pack is located. */
|
---|
118 | Utf8Str strExtPackPath;
|
---|
119 | /** The file system object info of the extension pack directory.
|
---|
120 | * This is for detecting changes and save time in refresh(). */
|
---|
121 | RTFSOBJINFO ObjInfoExtPack;
|
---|
122 | /** The full path to the main module. */
|
---|
123 | Utf8Str strMainModPath;
|
---|
124 | /** The file system object info of the main module.
|
---|
125 | * This is used to determin whether to bother try reload it. */
|
---|
126 | RTFSOBJINFO ObjInfoMainMod;
|
---|
127 | /** The module handle of the main extension pack module. */
|
---|
128 | RTLDRMOD hMainMod;
|
---|
129 |
|
---|
130 | /** The helper callbacks for the extension pack. */
|
---|
131 | VBOXEXTPACKHLP Hlp;
|
---|
132 | /** Pointer back to the extension pack object (for Hlp methods). */
|
---|
133 | ExtPack *pThis;
|
---|
134 | #ifndef VBOX_COM_INPROC
|
---|
135 | /** The extension pack main registration structure. */
|
---|
136 | PCVBOXEXTPACKREG pReg;
|
---|
137 | #else
|
---|
138 | /** The extension pack main VM registration structure. */
|
---|
139 | PCVBOXEXTPACKVMREG pReg;
|
---|
140 | #endif
|
---|
141 | /** The current context. */
|
---|
142 | VBOXEXTPACKCTX enmContext;
|
---|
143 | /** Set if we've made the pfnVirtualBoxReady or pfnConsoleReady call. */
|
---|
144 | bool fMadeReadyCall;
|
---|
145 |
|
---|
146 | RTMEMEF_NEW_AND_DELETE_OPERATORS();
|
---|
147 | };
|
---|
148 |
|
---|
149 | /** List of extension packs. */
|
---|
150 | typedef std::list< ComObjPtr<ExtPack> > ExtPackList;
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Private extension pack manager data.
|
---|
154 | */
|
---|
155 | struct ExtPackManager::Data
|
---|
156 | {
|
---|
157 | /** The directory where the extension packs are installed. */
|
---|
158 | Utf8Str strBaseDir;
|
---|
159 | /** The directory where the certificates this installation recognizes are
|
---|
160 | * stored. */
|
---|
161 | Utf8Str strCertificatDirPath;
|
---|
162 | /** The list of installed extension packs. */
|
---|
163 | ExtPackList llInstalledExtPacks;
|
---|
164 | #ifndef VBOX_COM_INPROC
|
---|
165 | /** Pointer to the VirtualBox object, our parent. */
|
---|
166 | VirtualBox *pVirtualBox;
|
---|
167 | #endif
|
---|
168 | /** The current context. */
|
---|
169 | VBOXEXTPACKCTX enmContext;
|
---|
170 |
|
---|
171 | RTMEMEF_NEW_AND_DELETE_OPERATORS();
|
---|
172 | };
|
---|
173 |
|
---|
174 | #ifndef VBOX_COM_INPROC
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * Extension pack installation job.
|
---|
178 | */
|
---|
179 | class ExtPackInstallTask : public ThreadTask
|
---|
180 | {
|
---|
181 | public:
|
---|
182 | explicit ExtPackInstallTask() : ThreadTask("ExtPackInst") { }
|
---|
183 | ~ExtPackInstallTask() { }
|
---|
184 |
|
---|
185 | void handler()
|
---|
186 | {
|
---|
187 | HRESULT hrc = ptrExtPackMgr->i_doInstall(ptrExtPackFile, fReplace, &strDisplayInfo);
|
---|
188 | ptrProgress->i_notifyComplete(hrc);
|
---|
189 | }
|
---|
190 |
|
---|
191 | HRESULT Init(const ComPtr<ExtPackFile> &a_strExtPackFile, bool a_fReplace,
|
---|
192 | const Utf8Str &strDispInfo, const ComPtr<ExtPackManager> &a_ptrExtPackMgr)
|
---|
193 | {
|
---|
194 | ptrExtPackFile = a_strExtPackFile;
|
---|
195 | fReplace = a_fReplace;
|
---|
196 | strDisplayInfo = strDispInfo;
|
---|
197 | ptrExtPackMgr = a_ptrExtPackMgr;
|
---|
198 |
|
---|
199 | HRESULT hrc = ptrProgress.createObject();
|
---|
200 | if (SUCCEEDED(hrc))
|
---|
201 | {
|
---|
202 | Bstr bstrDescription("Installing extension pack");
|
---|
203 | hrc = ptrProgress->init(ptrExtPackFile->m->pVirtualBox,
|
---|
204 | static_cast<IExtPackFile *>(ptrExtPackFile),
|
---|
205 | bstrDescription.raw(),
|
---|
206 | FALSE /*aCancelable*/);
|
---|
207 | }
|
---|
208 |
|
---|
209 | return hrc;
|
---|
210 | }
|
---|
211 |
|
---|
212 | /** Smart pointer to the progress object for this job. */
|
---|
213 | ComObjPtr<Progress> ptrProgress;
|
---|
214 | private:
|
---|
215 | /** Smart pointer to the extension pack file. */
|
---|
216 | ComPtr<ExtPackFile> ptrExtPackFile;
|
---|
217 | /** The replace argument. */
|
---|
218 | bool fReplace;
|
---|
219 | /** The display info argument. */
|
---|
220 | Utf8Str strDisplayInfo;
|
---|
221 | /** Smart pointer to the extension manager. */
|
---|
222 | ComPtr<ExtPackManager> ptrExtPackMgr;
|
---|
223 | };
|
---|
224 |
|
---|
225 | /**
|
---|
226 | * Extension pack uninstallation job.
|
---|
227 | */
|
---|
228 | class ExtPackUninstallTask : public ThreadTask
|
---|
229 | {
|
---|
230 | public:
|
---|
231 | explicit ExtPackUninstallTask() : ThreadTask("ExtPackUninst") { }
|
---|
232 | ~ExtPackUninstallTask() { }
|
---|
233 |
|
---|
234 | void handler()
|
---|
235 | {
|
---|
236 | HRESULT hrc = ptrExtPackMgr->i_doUninstall(&strName, fForcedRemoval, &strDisplayInfo);
|
---|
237 | ptrProgress->i_notifyComplete(hrc);
|
---|
238 | }
|
---|
239 |
|
---|
240 | HRESULT Init(const ComPtr<ExtPackManager> &a_ptrExtPackMgr, const Utf8Str &a_strName,
|
---|
241 | bool a_fForcedRemoval, const Utf8Str &a_strDisplayInfo)
|
---|
242 | {
|
---|
243 | ptrExtPackMgr = a_ptrExtPackMgr;
|
---|
244 | strName = a_strName;
|
---|
245 | fForcedRemoval = a_fForcedRemoval;
|
---|
246 | strDisplayInfo = a_strDisplayInfo;
|
---|
247 |
|
---|
248 | HRESULT hrc = ptrProgress.createObject();
|
---|
249 | if (SUCCEEDED(hrc))
|
---|
250 | {
|
---|
251 | Bstr bstrDescription("Uninstalling extension pack");
|
---|
252 | hrc = ptrProgress->init(ptrExtPackMgr->m->pVirtualBox,
|
---|
253 | static_cast<IExtPackManager *>(ptrExtPackMgr),
|
---|
254 | bstrDescription.raw(),
|
---|
255 | FALSE /*aCancelable*/);
|
---|
256 | }
|
---|
257 |
|
---|
258 | return hrc;
|
---|
259 | }
|
---|
260 |
|
---|
261 | /** Smart pointer to the progress object for this job. */
|
---|
262 | ComObjPtr<Progress> ptrProgress;
|
---|
263 | private:
|
---|
264 | /** Smart pointer to the extension manager. */
|
---|
265 | ComPtr<ExtPackManager> ptrExtPackMgr;
|
---|
266 | /** The name of the extension pack. */
|
---|
267 | Utf8Str strName;
|
---|
268 | /** The replace argument. */
|
---|
269 | bool fForcedRemoval;
|
---|
270 | /** The display info argument. */
|
---|
271 | Utf8Str strDisplayInfo;
|
---|
272 | };
|
---|
273 |
|
---|
274 | DEFINE_EMPTY_CTOR_DTOR(ExtPackFile)
|
---|
275 |
|
---|
276 | /**
|
---|
277 | * Called by ComObjPtr::createObject when creating the object.
|
---|
278 | *
|
---|
279 | * Just initialize the basic object state, do the rest in initWithDir().
|
---|
280 | *
|
---|
281 | * @returns S_OK.
|
---|
282 | */
|
---|
283 | HRESULT ExtPackFile::FinalConstruct()
|
---|
284 | {
|
---|
285 | m = NULL;
|
---|
286 | return BaseFinalConstruct();
|
---|
287 | }
|
---|
288 |
|
---|
289 | /**
|
---|
290 | * Initializes the extension pack by reading its file.
|
---|
291 | *
|
---|
292 | * @returns COM status code.
|
---|
293 | * @param a_pszFile The path to the extension pack file.
|
---|
294 | * @param a_pszDigest The SHA-256 digest of the file. Or an empty string.
|
---|
295 | * @param a_pExtPackMgr Pointer to the extension pack manager.
|
---|
296 | * @param a_pVirtualBox Pointer to the VirtualBox object.
|
---|
297 | */
|
---|
298 | HRESULT ExtPackFile::initWithFile(const char *a_pszFile, const char *a_pszDigest, ExtPackManager *a_pExtPackMgr,
|
---|
299 | VirtualBox *a_pVirtualBox)
|
---|
300 | {
|
---|
301 | AutoInitSpan autoInitSpan(this);
|
---|
302 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
303 |
|
---|
304 | /*
|
---|
305 | * Allocate + initialize our private data.
|
---|
306 | */
|
---|
307 | m = new ExtPackFile::Data;
|
---|
308 | VBoxExtPackInitDesc(&m->Desc);
|
---|
309 | RT_ZERO(m->ObjInfoDesc);
|
---|
310 | m->fUsable = false;
|
---|
311 | m->strWhyUnusable = tr("ExtPack::init failed");
|
---|
312 | m->strExtPackFile = a_pszFile;
|
---|
313 | m->strDigest = a_pszDigest;
|
---|
314 | m->hExtPackFile = NIL_RTFILE;
|
---|
315 | m->hOurManifest = NIL_RTMANIFEST;
|
---|
316 | m->ptrExtPackMgr = a_pExtPackMgr;
|
---|
317 | m->pVirtualBox = a_pVirtualBox;
|
---|
318 |
|
---|
319 | RTCString *pstrTarName = VBoxExtPackExtractNameFromTarballPath(a_pszFile);
|
---|
320 | if (pstrTarName)
|
---|
321 | {
|
---|
322 | m->Desc.strName = *pstrTarName;
|
---|
323 | delete pstrTarName;
|
---|
324 | pstrTarName = NULL;
|
---|
325 | }
|
---|
326 |
|
---|
327 | autoInitSpan.setSucceeded();
|
---|
328 |
|
---|
329 | /*
|
---|
330 | * Try open the extension pack and check that it is a regular file.
|
---|
331 | */
|
---|
332 | int vrc = RTFileOpen(&m->hExtPackFile, a_pszFile,
|
---|
333 | RTFILE_O_READ | RTFILE_O_DENY_WRITE | RTFILE_O_OPEN);
|
---|
334 | if (RT_FAILURE(vrc))
|
---|
335 | {
|
---|
336 | if (vrc == VERR_FILE_NOT_FOUND || vrc == VERR_PATH_NOT_FOUND)
|
---|
337 | return initFailed(tr("'%s' file not found"), a_pszFile);
|
---|
338 | return initFailed(tr("RTFileOpen('%s',,) failed with %Rrc"), a_pszFile, vrc);
|
---|
339 | }
|
---|
340 |
|
---|
341 | RTFSOBJINFO ObjInfo;
|
---|
342 | vrc = RTFileQueryInfo(m->hExtPackFile, &ObjInfo, RTFSOBJATTRADD_UNIX);
|
---|
343 | if (RT_FAILURE(vrc))
|
---|
344 | return initFailed(tr("RTFileQueryInfo failed with %Rrc on '%s'"), vrc, a_pszFile);
|
---|
345 | if (!RTFS_IS_FILE(ObjInfo.Attr.fMode))
|
---|
346 | return initFailed(tr("Not a regular file: %s"), a_pszFile);
|
---|
347 |
|
---|
348 | /*
|
---|
349 | * Validate the tarball and extract the XML file.
|
---|
350 | */
|
---|
351 | char szError[8192];
|
---|
352 | RTVFSFILE hXmlFile;
|
---|
353 | vrc = VBoxExtPackValidateTarball(m->hExtPackFile, NULL /*pszExtPackName*/, a_pszFile, a_pszDigest,
|
---|
354 | szError, sizeof(szError), &m->hOurManifest, &hXmlFile, &m->strDigest);
|
---|
355 | if (RT_FAILURE(vrc))
|
---|
356 | return initFailed(tr("%s"), szError);
|
---|
357 |
|
---|
358 | /*
|
---|
359 | * Parse the XML.
|
---|
360 | */
|
---|
361 | RTCString strSavedName(m->Desc.strName);
|
---|
362 | RTCString *pStrLoadErr = VBoxExtPackLoadDescFromVfsFile(hXmlFile, &m->Desc, &m->ObjInfoDesc);
|
---|
363 | RTVfsFileRelease(hXmlFile);
|
---|
364 | if (pStrLoadErr != NULL)
|
---|
365 | {
|
---|
366 | m->strWhyUnusable.printf(tr("Failed to the xml file: %s"), pStrLoadErr->c_str());
|
---|
367 | m->Desc.strName = strSavedName;
|
---|
368 | delete pStrLoadErr;
|
---|
369 | return S_OK;
|
---|
370 | }
|
---|
371 |
|
---|
372 | /*
|
---|
373 | * Match the tarball name with the name from the XML.
|
---|
374 | */
|
---|
375 | /** @todo drop this restriction after the old install interface is
|
---|
376 | * dropped. */
|
---|
377 | if (!strSavedName.equalsIgnoreCase(m->Desc.strName))
|
---|
378 | return initFailed(tr("Extension pack name mismatch between the downloaded file and the XML inside it (xml='%s' file='%s')"),
|
---|
379 | m->Desc.strName.c_str(), strSavedName.c_str());
|
---|
380 |
|
---|
381 |
|
---|
382 | m->fUsable = true;
|
---|
383 | m->strWhyUnusable.setNull();
|
---|
384 | return S_OK;
|
---|
385 | }
|
---|
386 |
|
---|
387 | /**
|
---|
388 | * Protected helper that formats the strWhyUnusable value.
|
---|
389 | *
|
---|
390 | * @returns S_OK
|
---|
391 | * @param a_pszWhyFmt Why it failed, format string.
|
---|
392 | * @param ... The format arguments.
|
---|
393 | */
|
---|
394 | HRESULT ExtPackFile::initFailed(const char *a_pszWhyFmt, ...)
|
---|
395 | {
|
---|
396 | va_list va;
|
---|
397 | va_start(va, a_pszWhyFmt);
|
---|
398 | m->strWhyUnusable.printfV(a_pszWhyFmt, va);
|
---|
399 | va_end(va);
|
---|
400 | return S_OK;
|
---|
401 | }
|
---|
402 |
|
---|
403 | /**
|
---|
404 | * COM cruft.
|
---|
405 | */
|
---|
406 | void ExtPackFile::FinalRelease()
|
---|
407 | {
|
---|
408 | uninit();
|
---|
409 | BaseFinalRelease();
|
---|
410 | }
|
---|
411 |
|
---|
412 | /**
|
---|
413 | * Do the actual cleanup.
|
---|
414 | */
|
---|
415 | void ExtPackFile::uninit()
|
---|
416 | {
|
---|
417 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
418 | AutoUninitSpan autoUninitSpan(this);
|
---|
419 | if (!autoUninitSpan.uninitDone() && m != NULL)
|
---|
420 | {
|
---|
421 | VBoxExtPackFreeDesc(&m->Desc);
|
---|
422 | RTFileClose(m->hExtPackFile);
|
---|
423 | m->hExtPackFile = NIL_RTFILE;
|
---|
424 | RTManifestRelease(m->hOurManifest);
|
---|
425 | m->hOurManifest = NIL_RTMANIFEST;
|
---|
426 |
|
---|
427 | delete m;
|
---|
428 | m = NULL;
|
---|
429 | }
|
---|
430 | }
|
---|
431 |
|
---|
432 | HRESULT ExtPackFile::getName(com::Utf8Str &aName)
|
---|
433 | {
|
---|
434 | aName = m->Desc.strName;
|
---|
435 | return S_OK;
|
---|
436 | }
|
---|
437 |
|
---|
438 | HRESULT ExtPackFile::getDescription(com::Utf8Str &aDescription)
|
---|
439 | {
|
---|
440 | aDescription = m->Desc.strDescription;
|
---|
441 | return S_OK;
|
---|
442 | }
|
---|
443 |
|
---|
444 | HRESULT ExtPackFile::getVersion(com::Utf8Str &aVersion)
|
---|
445 | {
|
---|
446 | aVersion = m->Desc.strVersion;
|
---|
447 | return S_OK;
|
---|
448 | }
|
---|
449 |
|
---|
450 | HRESULT ExtPackFile::getEdition(com::Utf8Str &aEdition)
|
---|
451 | {
|
---|
452 | aEdition = m->Desc.strEdition;
|
---|
453 | return S_OK;
|
---|
454 | }
|
---|
455 |
|
---|
456 | HRESULT ExtPackFile::getRevision(ULONG *aRevision)
|
---|
457 | {
|
---|
458 | *aRevision = m->Desc.uRevision;
|
---|
459 | return S_OK;
|
---|
460 | }
|
---|
461 |
|
---|
462 | HRESULT ExtPackFile::getVRDEModule(com::Utf8Str &aVRDEModule)
|
---|
463 | {
|
---|
464 | aVRDEModule = m->Desc.strVrdeModule;
|
---|
465 | return S_OK;
|
---|
466 | }
|
---|
467 |
|
---|
468 | HRESULT ExtPackFile::getPlugIns(std::vector<ComPtr<IExtPackPlugIn> > &aPlugIns)
|
---|
469 | {
|
---|
470 | /** @todo implement plug-ins. */
|
---|
471 | #ifdef VBOX_WITH_XPCOM
|
---|
472 | NOREF(aPlugIns);
|
---|
473 | #endif
|
---|
474 | NOREF(aPlugIns);
|
---|
475 | ReturnComNotImplemented();
|
---|
476 | }
|
---|
477 |
|
---|
478 | HRESULT ExtPackFile::getUsable(BOOL *aUsable)
|
---|
479 | {
|
---|
480 | *aUsable = m->fUsable;
|
---|
481 | return S_OK;
|
---|
482 | }
|
---|
483 |
|
---|
484 | HRESULT ExtPackFile::getWhyUnusable(com::Utf8Str &aWhyUnusable)
|
---|
485 | {
|
---|
486 | aWhyUnusable = m->strWhyUnusable;
|
---|
487 | return S_OK;
|
---|
488 | }
|
---|
489 |
|
---|
490 | HRESULT ExtPackFile::getShowLicense(BOOL *aShowLicense)
|
---|
491 | {
|
---|
492 | *aShowLicense = m->Desc.fShowLicense;
|
---|
493 | return S_OK;
|
---|
494 | }
|
---|
495 |
|
---|
496 | HRESULT ExtPackFile::getLicense(com::Utf8Str &aLicense)
|
---|
497 | {
|
---|
498 | Utf8Str strHtml("html");
|
---|
499 | Utf8Str str("");
|
---|
500 | return queryLicense(str, str, strHtml, aLicense);
|
---|
501 | }
|
---|
502 |
|
---|
503 | /* Same as ExtPack::QueryLicense, should really explore the subject of base classes here... */
|
---|
504 | HRESULT ExtPackFile::queryLicense(const com::Utf8Str &aPreferredLocale, const com::Utf8Str &aPreferredLanguage,
|
---|
505 | const com::Utf8Str &aFormat, com::Utf8Str &aLicenseText)
|
---|
506 | {
|
---|
507 | HRESULT hrc = S_OK;
|
---|
508 |
|
---|
509 | /*
|
---|
510 | * Validate input.
|
---|
511 | */
|
---|
512 |
|
---|
513 | if (aPreferredLocale.length() != 2 && aPreferredLocale.length() != 0)
|
---|
514 | return setError(E_FAIL, tr("The preferred locale is a two character string or empty."));
|
---|
515 |
|
---|
516 | if (aPreferredLanguage.length() != 2 && aPreferredLanguage.length() != 0)
|
---|
517 | return setError(E_FAIL, tr("The preferred lanuage is a two character string or empty."));
|
---|
518 |
|
---|
519 | if ( !aFormat.equals("html")
|
---|
520 | && !aFormat.equals("rtf")
|
---|
521 | && !aFormat.equals("txt"))
|
---|
522 | return setError(E_FAIL, tr("The license format can only have the values 'html', 'rtf' and 'txt'."));
|
---|
523 |
|
---|
524 | /*
|
---|
525 | * Combine the options to form a file name before locking down anything.
|
---|
526 | */
|
---|
527 | char szName[sizeof(VBOX_EXTPACK_LICENSE_NAME_PREFIX "-de_DE.html") + 2];
|
---|
528 | if (aPreferredLocale.isNotEmpty() && aPreferredLanguage.isNotEmpty())
|
---|
529 | RTStrPrintf(szName, sizeof(szName), VBOX_EXTPACK_LICENSE_NAME_PREFIX "-%s_%s.%s",
|
---|
530 | aPreferredLocale.c_str(), aPreferredLanguage.c_str(), aFormat.c_str());
|
---|
531 | else if (aPreferredLocale.isNotEmpty())
|
---|
532 | RTStrPrintf(szName, sizeof(szName), VBOX_EXTPACK_LICENSE_NAME_PREFIX "-%s.%s",
|
---|
533 | aPreferredLocale.c_str(), aFormat.c_str());
|
---|
534 | else if (aPreferredLanguage.isNotEmpty())
|
---|
535 | RTStrPrintf(szName, sizeof(szName), VBOX_EXTPACK_LICENSE_NAME_PREFIX "-_%s.%s",
|
---|
536 | aPreferredLocale.c_str(), aFormat.c_str());
|
---|
537 | else
|
---|
538 | RTStrPrintf(szName, sizeof(szName), VBOX_EXTPACK_LICENSE_NAME_PREFIX ".%s",
|
---|
539 | aFormat.c_str());
|
---|
540 | /*
|
---|
541 | * Lock the extension pack. We need a write lock here as there must not be
|
---|
542 | * concurrent accesses to the tar file handle.
|
---|
543 | */
|
---|
544 | AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
545 |
|
---|
546 | /*
|
---|
547 | * Do not permit this query on a pack that isn't considered usable (could
|
---|
548 | * be marked so because of bad license files).
|
---|
549 | */
|
---|
550 | if (!m->fUsable)
|
---|
551 | hrc = setError(E_FAIL, tr("%s"), m->strWhyUnusable.c_str());
|
---|
552 | else
|
---|
553 | {
|
---|
554 | /*
|
---|
555 | * Look it up in the manifest before scanning the tarball for it
|
---|
556 | */
|
---|
557 | if (RTManifestEntryExists(m->hOurManifest, szName))
|
---|
558 | {
|
---|
559 | RTVFSFSSTREAM hTarFss;
|
---|
560 | char szError[8192];
|
---|
561 | int vrc = VBoxExtPackOpenTarFss(m->hExtPackFile, szError, sizeof(szError), &hTarFss, NULL);
|
---|
562 | if (RT_SUCCESS(vrc))
|
---|
563 | {
|
---|
564 | for (;;)
|
---|
565 | {
|
---|
566 | /* Get the first/next. */
|
---|
567 | char *pszName;
|
---|
568 | RTVFSOBJ hVfsObj;
|
---|
569 | RTVFSOBJTYPE enmType;
|
---|
570 | vrc = RTVfsFsStrmNext(hTarFss, &pszName, &enmType, &hVfsObj);
|
---|
571 | if (RT_FAILURE(vrc))
|
---|
572 | {
|
---|
573 | if (vrc != VERR_EOF)
|
---|
574 | hrc = setError(VBOX_E_IPRT_ERROR, tr("RTVfsFsStrmNext failed: %Rrc"), vrc);
|
---|
575 | else
|
---|
576 | hrc = setError(E_UNEXPECTED, tr("'%s' was found in the manifest but not in the tarball"), szName);
|
---|
577 | break;
|
---|
578 | }
|
---|
579 |
|
---|
580 | /* Is this it? */
|
---|
581 | const char *pszAdjName = pszName[0] == '.' && pszName[1] == '/' ? &pszName[2] : pszName;
|
---|
582 | if ( !strcmp(pszAdjName, szName)
|
---|
583 | && ( enmType == RTVFSOBJTYPE_IO_STREAM
|
---|
584 | || enmType == RTVFSOBJTYPE_FILE))
|
---|
585 | {
|
---|
586 | RTVFSIOSTREAM hVfsIos = RTVfsObjToIoStream(hVfsObj);
|
---|
587 | RTVfsObjRelease(hVfsObj);
|
---|
588 | RTStrFree(pszName);
|
---|
589 |
|
---|
590 | /* Load the file into memory. */
|
---|
591 | RTFSOBJINFO ObjInfo;
|
---|
592 | vrc = RTVfsIoStrmQueryInfo(hVfsIos, &ObjInfo, RTFSOBJATTRADD_NOTHING);
|
---|
593 | if (RT_SUCCESS(vrc))
|
---|
594 | {
|
---|
595 | size_t cbFile = (size_t)ObjInfo.cbObject;
|
---|
596 | void *pvFile = RTMemAllocZ(cbFile + 1);
|
---|
597 | if (pvFile)
|
---|
598 | {
|
---|
599 | vrc = RTVfsIoStrmRead(hVfsIos, pvFile, cbFile, true /*fBlocking*/, NULL);
|
---|
600 | if (RT_SUCCESS(vrc))
|
---|
601 | {
|
---|
602 | /* try translate it into a string we can return. */
|
---|
603 | Bstr bstrLicense((const char *)pvFile, cbFile);
|
---|
604 | if (bstrLicense.isNotEmpty())
|
---|
605 | {
|
---|
606 | aLicenseText = Utf8Str(bstrLicense);
|
---|
607 | hrc = S_OK;
|
---|
608 | }
|
---|
609 | else
|
---|
610 | hrc = setError(VBOX_E_IPRT_ERROR,
|
---|
611 | tr("The license file '%s' is empty or contains invalid UTF-8 encoding"),
|
---|
612 | szName);
|
---|
613 | }
|
---|
614 | else
|
---|
615 | hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to read '%s': %Rrc"), szName, vrc);
|
---|
616 | RTMemFree(pvFile);
|
---|
617 | }
|
---|
618 | else
|
---|
619 | hrc = setError(E_OUTOFMEMORY, tr("Failed to allocate %zu bytes for '%s'"), cbFile, szName);
|
---|
620 | }
|
---|
621 | else
|
---|
622 | hrc = setError(VBOX_E_IPRT_ERROR, tr("RTVfsIoStrmQueryInfo on '%s': %Rrc"), szName, vrc);
|
---|
623 | RTVfsIoStrmRelease(hVfsIos);
|
---|
624 | break;
|
---|
625 | }
|
---|
626 |
|
---|
627 | /* Release current. */
|
---|
628 | RTVfsObjRelease(hVfsObj);
|
---|
629 | RTStrFree(pszName);
|
---|
630 | }
|
---|
631 | RTVfsFsStrmRelease(hTarFss);
|
---|
632 | }
|
---|
633 | else
|
---|
634 | hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("%s"), szError);
|
---|
635 | }
|
---|
636 | else
|
---|
637 | hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The license file '%s' was not found in '%s'"),
|
---|
638 | szName, m->strExtPackFile.c_str());
|
---|
639 | }
|
---|
640 | return hrc;
|
---|
641 | }
|
---|
642 |
|
---|
643 | HRESULT ExtPackFile::getFilePath(com::Utf8Str &aFilePath)
|
---|
644 | {
|
---|
645 |
|
---|
646 | aFilePath = m->strExtPackFile;
|
---|
647 | return S_OK;
|
---|
648 | }
|
---|
649 |
|
---|
650 | HRESULT ExtPackFile::install(BOOL aReplace, const com::Utf8Str &aDisplayInfo, ComPtr<IProgress> &aProgress)
|
---|
651 | {
|
---|
652 | HRESULT hrc;
|
---|
653 | if (m->fUsable)
|
---|
654 | {
|
---|
655 | ExtPackInstallTask *pTask = NULL;
|
---|
656 | try
|
---|
657 | {
|
---|
658 | pTask = new ExtPackInstallTask();
|
---|
659 | hrc = pTask->Init(this, aReplace != FALSE, aDisplayInfo, m->ptrExtPackMgr);
|
---|
660 | if (SUCCEEDED(hrc))
|
---|
661 | {
|
---|
662 | ComPtr<Progress> ptrProgress = pTask->ptrProgress;
|
---|
663 | hrc = pTask->createThreadWithType(RTTHREADTYPE_DEFAULT);
|
---|
664 | pTask = NULL; /* The _completely_ _undocumented_ createThread method always consumes pTask. */
|
---|
665 | if (SUCCEEDED(hrc))
|
---|
666 | hrc = ptrProgress.queryInterfaceTo(aProgress.asOutParam());
|
---|
667 | else
|
---|
668 | hrc = setError(VBOX_E_IPRT_ERROR,
|
---|
669 | tr("Starting thread for an extension pack installation failed with %Rrc"), hrc);
|
---|
670 | }
|
---|
671 | else
|
---|
672 | hrc = setError(VBOX_E_IPRT_ERROR,
|
---|
673 | tr("Looks like creating a progress object for ExtraPackInstallTask object failed"));
|
---|
674 | }
|
---|
675 | catch (std::bad_alloc &)
|
---|
676 | {
|
---|
677 | hrc = E_OUTOFMEMORY;
|
---|
678 | }
|
---|
679 | catch (HRESULT hrcXcpt)
|
---|
680 | {
|
---|
681 | LogFlowThisFunc(("Exception was caught in the function ExtPackFile::install() \n"));
|
---|
682 | hrc = hrcXcpt;
|
---|
683 | }
|
---|
684 | if (pTask)
|
---|
685 | delete pTask;
|
---|
686 | }
|
---|
687 | else
|
---|
688 | hrc = setError(E_FAIL, "%s", m->strWhyUnusable.c_str());
|
---|
689 | return hrc;
|
---|
690 | }
|
---|
691 |
|
---|
692 | #endif /* !VBOX_COM_INPROC */
|
---|
693 |
|
---|
694 |
|
---|
695 |
|
---|
696 |
|
---|
697 | DEFINE_EMPTY_CTOR_DTOR(ExtPack)
|
---|
698 |
|
---|
699 | /**
|
---|
700 | * Called by ComObjPtr::createObject when creating the object.
|
---|
701 | *
|
---|
702 | * Just initialize the basic object state, do the rest in initWithDir().
|
---|
703 | *
|
---|
704 | * @returns S_OK.
|
---|
705 | */
|
---|
706 | HRESULT ExtPack::FinalConstruct()
|
---|
707 | {
|
---|
708 | m = NULL;
|
---|
709 | return BaseFinalConstruct();
|
---|
710 | }
|
---|
711 |
|
---|
712 | /**
|
---|
713 | * Initializes the extension pack by reading its file.
|
---|
714 | *
|
---|
715 | * @returns COM status code.
|
---|
716 | * @param a_enmContext The context we're in.
|
---|
717 | * @param a_pszName The name of the extension pack. This is also the
|
---|
718 | * name of the subdirector under @a a_pszParentDir
|
---|
719 | * where the extension pack is installed.
|
---|
720 | * @param a_pszDir The extension pack directory name.
|
---|
721 | */
|
---|
722 | HRESULT ExtPack::initWithDir(VBOXEXTPACKCTX a_enmContext, const char *a_pszName, const char *a_pszDir)
|
---|
723 | {
|
---|
724 | AutoInitSpan autoInitSpan(this);
|
---|
725 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
726 |
|
---|
727 | static const VBOXEXTPACKHLP s_HlpTmpl =
|
---|
728 | {
|
---|
729 | /* u32Version = */ VBOXEXTPACKHLP_VERSION,
|
---|
730 | /* uVBoxFullVersion = */ VBOX_FULL_VERSION,
|
---|
731 | /* uVBoxVersionRevision = */ 0,
|
---|
732 | /* u32Padding = */ 0,
|
---|
733 | /* pszVBoxVersion = */ "",
|
---|
734 | /* pfnFindModule = */ ExtPack::i_hlpFindModule,
|
---|
735 | /* pfnGetFilePath = */ ExtPack::i_hlpGetFilePath,
|
---|
736 | /* pfnGetContext = */ ExtPack::i_hlpGetContext,
|
---|
737 | /* pfnLoadHGCMService = */ ExtPack::i_hlpLoadHGCMService,
|
---|
738 | /* pfnLoadVDPlugin = */ ExtPack::i_hlpLoadVDPlugin,
|
---|
739 | /* pfnUnloadVDPlugin = */ ExtPack::i_hlpUnloadVDPlugin,
|
---|
740 | /* pfnReserved1 = */ ExtPack::i_hlpReservedN,
|
---|
741 | /* pfnReserved2 = */ ExtPack::i_hlpReservedN,
|
---|
742 | /* pfnReserved3 = */ ExtPack::i_hlpReservedN,
|
---|
743 | /* pfnReserved4 = */ ExtPack::i_hlpReservedN,
|
---|
744 | /* pfnReserved5 = */ ExtPack::i_hlpReservedN,
|
---|
745 | /* pfnReserved6 = */ ExtPack::i_hlpReservedN,
|
---|
746 | /* u32EndMarker = */ VBOXEXTPACKHLP_VERSION
|
---|
747 | };
|
---|
748 |
|
---|
749 | /*
|
---|
750 | * Allocate + initialize our private data.
|
---|
751 | */
|
---|
752 | m = new Data;
|
---|
753 | VBoxExtPackInitDesc(&m->Desc);
|
---|
754 | m->Desc.strName = a_pszName;
|
---|
755 | RT_ZERO(m->ObjInfoDesc);
|
---|
756 | m->fUsable = false;
|
---|
757 | m->strWhyUnusable = tr("ExtPack::init failed");
|
---|
758 | m->strExtPackPath = a_pszDir;
|
---|
759 | RT_ZERO(m->ObjInfoExtPack);
|
---|
760 | m->strMainModPath.setNull();
|
---|
761 | RT_ZERO(m->ObjInfoMainMod);
|
---|
762 | m->hMainMod = NIL_RTLDRMOD;
|
---|
763 | m->Hlp = s_HlpTmpl;
|
---|
764 | m->Hlp.pszVBoxVersion = RTBldCfgVersion();
|
---|
765 | m->Hlp.uVBoxInternalRevision = RTBldCfgRevision();
|
---|
766 | m->pThis = this;
|
---|
767 | m->pReg = NULL;
|
---|
768 | m->enmContext = a_enmContext;
|
---|
769 | m->fMadeReadyCall = false;
|
---|
770 |
|
---|
771 | /*
|
---|
772 | * Make sure the SUPR3Hardened API works (ignoring errors for now).
|
---|
773 | */
|
---|
774 | int rc = SUPR3HardenedVerifyInit();
|
---|
775 | if (RT_FAILURE(rc))
|
---|
776 | LogRel(("SUPR3HardenedVerifyInit failed: %Rrc\n", rc));
|
---|
777 |
|
---|
778 | /*
|
---|
779 | * Probe the extension pack (this code is shared with refresh()).
|
---|
780 | */
|
---|
781 | i_probeAndLoad();
|
---|
782 |
|
---|
783 | autoInitSpan.setSucceeded();
|
---|
784 | return S_OK;
|
---|
785 | }
|
---|
786 |
|
---|
787 | /**
|
---|
788 | * COM cruft.
|
---|
789 | */
|
---|
790 | void ExtPack::FinalRelease()
|
---|
791 | {
|
---|
792 | uninit();
|
---|
793 | BaseFinalRelease();
|
---|
794 | }
|
---|
795 |
|
---|
796 | /**
|
---|
797 | * Do the actual cleanup.
|
---|
798 | */
|
---|
799 | void ExtPack::uninit()
|
---|
800 | {
|
---|
801 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
802 | AutoUninitSpan autoUninitSpan(this);
|
---|
803 | if (!autoUninitSpan.uninitDone() && m != NULL)
|
---|
804 | {
|
---|
805 | if (m->hMainMod != NIL_RTLDRMOD)
|
---|
806 | {
|
---|
807 | AssertPtr(m->pReg);
|
---|
808 | if (m->pReg->pfnUnload != NULL)
|
---|
809 | m->pReg->pfnUnload(m->pReg);
|
---|
810 |
|
---|
811 | RTLdrClose(m->hMainMod);
|
---|
812 | m->hMainMod = NIL_RTLDRMOD;
|
---|
813 | m->pReg = NULL;
|
---|
814 | }
|
---|
815 |
|
---|
816 | VBoxExtPackFreeDesc(&m->Desc);
|
---|
817 |
|
---|
818 | delete m;
|
---|
819 | m = NULL;
|
---|
820 | }
|
---|
821 | }
|
---|
822 |
|
---|
823 |
|
---|
824 | #ifndef VBOX_COM_INPROC
|
---|
825 | /**
|
---|
826 | * Calls the installed hook.
|
---|
827 | *
|
---|
828 | * @returns true if we left the lock, false if we didn't.
|
---|
829 | * @param a_pVirtualBox The VirtualBox interface.
|
---|
830 | * @param a_pLock The write lock held by the caller.
|
---|
831 | * @param pErrInfo Where to return error information.
|
---|
832 | */
|
---|
833 | bool ExtPack::i_callInstalledHook(IVirtualBox *a_pVirtualBox, AutoWriteLock *a_pLock, PRTERRINFO pErrInfo)
|
---|
834 | {
|
---|
835 | if ( m != NULL
|
---|
836 | && m->hMainMod != NIL_RTLDRMOD)
|
---|
837 | {
|
---|
838 | if (m->pReg->pfnInstalled)
|
---|
839 | {
|
---|
840 | ComPtr<ExtPack> ptrSelfRef = this;
|
---|
841 | a_pLock->release();
|
---|
842 | pErrInfo->rc = m->pReg->pfnInstalled(m->pReg, a_pVirtualBox, pErrInfo);
|
---|
843 | a_pLock->acquire();
|
---|
844 | return true;
|
---|
845 | }
|
---|
846 | }
|
---|
847 | pErrInfo->rc = VINF_SUCCESS;
|
---|
848 | return false;
|
---|
849 | }
|
---|
850 |
|
---|
851 | /**
|
---|
852 | * Calls the uninstall hook and closes the module.
|
---|
853 | *
|
---|
854 | * @returns S_OK or COM error status with error information.
|
---|
855 | * @param a_pVirtualBox The VirtualBox interface.
|
---|
856 | * @param a_fForcedRemoval When set, we'll ignore complaints from the
|
---|
857 | * uninstall hook.
|
---|
858 | * @remarks The caller holds the manager's write lock, not released.
|
---|
859 | */
|
---|
860 | HRESULT ExtPack::i_callUninstallHookAndClose(IVirtualBox *a_pVirtualBox, bool a_fForcedRemoval)
|
---|
861 | {
|
---|
862 | HRESULT hrc = S_OK;
|
---|
863 |
|
---|
864 | if ( m != NULL
|
---|
865 | && m->hMainMod != NIL_RTLDRMOD)
|
---|
866 | {
|
---|
867 | if (m->pReg->pfnUninstall && !a_fForcedRemoval)
|
---|
868 | {
|
---|
869 | int vrc = m->pReg->pfnUninstall(m->pReg, a_pVirtualBox);
|
---|
870 | if (RT_FAILURE(vrc))
|
---|
871 | {
|
---|
872 | LogRel(("ExtPack pfnUninstall returned %Rrc for %s\n", vrc, m->Desc.strName.c_str()));
|
---|
873 | if (!a_fForcedRemoval)
|
---|
874 | hrc = setError(E_FAIL, tr("pfnUninstall returned %Rrc"), vrc);
|
---|
875 | }
|
---|
876 | }
|
---|
877 | if (SUCCEEDED(hrc))
|
---|
878 | {
|
---|
879 | RTLdrClose(m->hMainMod);
|
---|
880 | m->hMainMod = NIL_RTLDRMOD;
|
---|
881 | m->pReg = NULL;
|
---|
882 | }
|
---|
883 | }
|
---|
884 |
|
---|
885 | return hrc;
|
---|
886 | }
|
---|
887 |
|
---|
888 | /**
|
---|
889 | * Calls the pfnVirtualBoxReady hook.
|
---|
890 | *
|
---|
891 | * @returns true if we left the lock, false if we didn't.
|
---|
892 | * @param a_pVirtualBox The VirtualBox interface.
|
---|
893 | * @param a_pLock The write lock held by the caller.
|
---|
894 | */
|
---|
895 | bool ExtPack::i_callVirtualBoxReadyHook(IVirtualBox *a_pVirtualBox, AutoWriteLock *a_pLock)
|
---|
896 | {
|
---|
897 | if ( m != NULL
|
---|
898 | && m->fUsable
|
---|
899 | && m->hMainMod != NIL_RTLDRMOD
|
---|
900 | && !m->fMadeReadyCall)
|
---|
901 | {
|
---|
902 | m->fMadeReadyCall = true;
|
---|
903 | if (m->pReg->pfnVirtualBoxReady)
|
---|
904 | {
|
---|
905 | ComPtr<ExtPack> ptrSelfRef = this;
|
---|
906 | a_pLock->release();
|
---|
907 | m->pReg->pfnVirtualBoxReady(m->pReg, a_pVirtualBox);
|
---|
908 | a_pLock->acquire();
|
---|
909 | return true;
|
---|
910 | }
|
---|
911 | }
|
---|
912 | return false;
|
---|
913 | }
|
---|
914 | #endif /* !VBOX_COM_INPROC */
|
---|
915 |
|
---|
916 | #ifdef VBOX_COM_INPROC
|
---|
917 | /**
|
---|
918 | * Calls the pfnConsoleReady hook.
|
---|
919 | *
|
---|
920 | * @returns true if we left the lock, false if we didn't.
|
---|
921 | * @param a_pConsole The Console interface.
|
---|
922 | * @param a_pLock The write lock held by the caller.
|
---|
923 | */
|
---|
924 | bool ExtPack::i_callConsoleReadyHook(IConsole *a_pConsole, AutoWriteLock *a_pLock)
|
---|
925 | {
|
---|
926 | if ( m != NULL
|
---|
927 | && m->fUsable
|
---|
928 | && m->hMainMod != NIL_RTLDRMOD
|
---|
929 | && !m->fMadeReadyCall)
|
---|
930 | {
|
---|
931 | m->fMadeReadyCall = true;
|
---|
932 | if (m->pReg->pfnConsoleReady)
|
---|
933 | {
|
---|
934 | ComPtr<ExtPack> ptrSelfRef = this;
|
---|
935 | a_pLock->release();
|
---|
936 | m->pReg->pfnConsoleReady(m->pReg, a_pConsole);
|
---|
937 | a_pLock->acquire();
|
---|
938 | return true;
|
---|
939 | }
|
---|
940 | }
|
---|
941 | return false;
|
---|
942 | }
|
---|
943 | #endif /* VBOX_COM_INPROC */
|
---|
944 |
|
---|
945 | #ifndef VBOX_COM_INPROC
|
---|
946 | /**
|
---|
947 | * Calls the pfnVMCreate hook.
|
---|
948 | *
|
---|
949 | * @returns true if we left the lock, false if we didn't.
|
---|
950 | * @param a_pVirtualBox The VirtualBox interface.
|
---|
951 | * @param a_pMachine The machine interface of the new VM.
|
---|
952 | * @param a_pLock The write lock held by the caller.
|
---|
953 | */
|
---|
954 | bool ExtPack::i_callVmCreatedHook(IVirtualBox *a_pVirtualBox, IMachine *a_pMachine, AutoWriteLock *a_pLock)
|
---|
955 | {
|
---|
956 | if ( m != NULL
|
---|
957 | && m->hMainMod != NIL_RTLDRMOD
|
---|
958 | && m->fUsable)
|
---|
959 | {
|
---|
960 | if (m->pReg->pfnVMCreated)
|
---|
961 | {
|
---|
962 | ComPtr<ExtPack> ptrSelfRef = this;
|
---|
963 | a_pLock->release();
|
---|
964 | m->pReg->pfnVMCreated(m->pReg, a_pVirtualBox, a_pMachine);
|
---|
965 | a_pLock->acquire();
|
---|
966 | return true;
|
---|
967 | }
|
---|
968 | }
|
---|
969 | return false;
|
---|
970 | }
|
---|
971 | #endif /* !VBOX_COM_INPROC */
|
---|
972 |
|
---|
973 | #ifdef VBOX_COM_INPROC
|
---|
974 | /**
|
---|
975 | * Calls the pfnVMConfigureVMM hook.
|
---|
976 | *
|
---|
977 | * @returns true if we left the lock, false if we didn't.
|
---|
978 | * @param a_pConsole The console interface.
|
---|
979 | * @param a_pVM The VM handle.
|
---|
980 | * @param a_pLock The write lock held by the caller.
|
---|
981 | * @param a_pvrc Where to return the status code of the
|
---|
982 | * callback. This is always set. LogRel is
|
---|
983 | * called on if a failure status is returned.
|
---|
984 | */
|
---|
985 | bool ExtPack::i_callVmConfigureVmmHook(IConsole *a_pConsole, PVM a_pVM, AutoWriteLock *a_pLock, int *a_pvrc)
|
---|
986 | {
|
---|
987 | *a_pvrc = VINF_SUCCESS;
|
---|
988 | if ( m != NULL
|
---|
989 | && m->hMainMod != NIL_RTLDRMOD
|
---|
990 | && m->fUsable)
|
---|
991 | {
|
---|
992 | if (m->pReg->pfnVMConfigureVMM)
|
---|
993 | {
|
---|
994 | ComPtr<ExtPack> ptrSelfRef = this;
|
---|
995 | a_pLock->release();
|
---|
996 | int vrc = m->pReg->pfnVMConfigureVMM(m->pReg, a_pConsole, a_pVM);
|
---|
997 | *a_pvrc = vrc;
|
---|
998 | a_pLock->acquire();
|
---|
999 | if (RT_FAILURE(vrc))
|
---|
1000 | LogRel(("ExtPack pfnVMConfigureVMM returned %Rrc for %s\n", vrc, m->Desc.strName.c_str()));
|
---|
1001 | return true;
|
---|
1002 | }
|
---|
1003 | }
|
---|
1004 | return false;
|
---|
1005 | }
|
---|
1006 |
|
---|
1007 | /**
|
---|
1008 | * Calls the pfnVMPowerOn hook.
|
---|
1009 | *
|
---|
1010 | * @returns true if we left the lock, false if we didn't.
|
---|
1011 | * @param a_pConsole The console interface.
|
---|
1012 | * @param a_pVM The VM handle.
|
---|
1013 | * @param a_pLock The write lock held by the caller.
|
---|
1014 | * @param a_pvrc Where to return the status code of the
|
---|
1015 | * callback. This is always set. LogRel is
|
---|
1016 | * called on if a failure status is returned.
|
---|
1017 | */
|
---|
1018 | bool ExtPack::i_callVmPowerOnHook(IConsole *a_pConsole, PVM a_pVM, AutoWriteLock *a_pLock, int *a_pvrc)
|
---|
1019 | {
|
---|
1020 | *a_pvrc = VINF_SUCCESS;
|
---|
1021 | if ( m != NULL
|
---|
1022 | && m->hMainMod != NIL_RTLDRMOD
|
---|
1023 | && m->fUsable)
|
---|
1024 | {
|
---|
1025 | if (m->pReg->pfnVMPowerOn)
|
---|
1026 | {
|
---|
1027 | ComPtr<ExtPack> ptrSelfRef = this;
|
---|
1028 | a_pLock->release();
|
---|
1029 | int vrc = m->pReg->pfnVMPowerOn(m->pReg, a_pConsole, a_pVM);
|
---|
1030 | *a_pvrc = vrc;
|
---|
1031 | a_pLock->acquire();
|
---|
1032 | if (RT_FAILURE(vrc))
|
---|
1033 | LogRel(("ExtPack pfnVMPowerOn returned %Rrc for %s\n", vrc, m->Desc.strName.c_str()));
|
---|
1034 | return true;
|
---|
1035 | }
|
---|
1036 | }
|
---|
1037 | return false;
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 | /**
|
---|
1041 | * Calls the pfnVMPowerOff hook.
|
---|
1042 | *
|
---|
1043 | * @returns true if we left the lock, false if we didn't.
|
---|
1044 | * @param a_pConsole The console interface.
|
---|
1045 | * @param a_pVM The VM handle.
|
---|
1046 | * @param a_pLock The write lock held by the caller.
|
---|
1047 | */
|
---|
1048 | bool ExtPack::i_callVmPowerOffHook(IConsole *a_pConsole, PVM a_pVM, AutoWriteLock *a_pLock)
|
---|
1049 | {
|
---|
1050 | if ( m != NULL
|
---|
1051 | && m->hMainMod != NIL_RTLDRMOD
|
---|
1052 | && m->fUsable)
|
---|
1053 | {
|
---|
1054 | if (m->pReg->pfnVMPowerOff)
|
---|
1055 | {
|
---|
1056 | ComPtr<ExtPack> ptrSelfRef = this;
|
---|
1057 | a_pLock->release();
|
---|
1058 | m->pReg->pfnVMPowerOff(m->pReg, a_pConsole, a_pVM);
|
---|
1059 | a_pLock->acquire();
|
---|
1060 | return true;
|
---|
1061 | }
|
---|
1062 | }
|
---|
1063 | return false;
|
---|
1064 | }
|
---|
1065 | #endif /* !VBOX_COM_INPROC */
|
---|
1066 |
|
---|
1067 | /**
|
---|
1068 | * Check if the extension pack is usable and has an VRDE module.
|
---|
1069 | *
|
---|
1070 | * @returns S_OK or COM error status with error information.
|
---|
1071 | *
|
---|
1072 | * @remarks Caller holds the extension manager lock for reading, no locking
|
---|
1073 | * necessary.
|
---|
1074 | */
|
---|
1075 | HRESULT ExtPack::i_checkVrde(void)
|
---|
1076 | {
|
---|
1077 | HRESULT hrc;
|
---|
1078 | if ( m != NULL
|
---|
1079 | && m->fUsable)
|
---|
1080 | {
|
---|
1081 | if (m->Desc.strVrdeModule.isNotEmpty())
|
---|
1082 | hrc = S_OK;
|
---|
1083 | else
|
---|
1084 | hrc = setError(E_FAIL, tr("The extension pack '%s' does not include a VRDE module"), m->Desc.strName.c_str());
|
---|
1085 | }
|
---|
1086 | else
|
---|
1087 | hrc = setError(E_FAIL, tr("%s"), m->strWhyUnusable.c_str());
|
---|
1088 | return hrc;
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | /**
|
---|
1092 | * Same as checkVrde(), except that it also resolves the path to the module.
|
---|
1093 | *
|
---|
1094 | * @returns S_OK or COM error status with error information.
|
---|
1095 | * @param a_pstrVrdeLibrary Where to return the path on success.
|
---|
1096 | *
|
---|
1097 | * @remarks Caller holds the extension manager lock for reading, no locking
|
---|
1098 | * necessary.
|
---|
1099 | */
|
---|
1100 | HRESULT ExtPack::i_getVrdpLibraryName(Utf8Str *a_pstrVrdeLibrary)
|
---|
1101 | {
|
---|
1102 | HRESULT hrc = i_checkVrde();
|
---|
1103 | if (SUCCEEDED(hrc))
|
---|
1104 | {
|
---|
1105 | if (i_findModule(m->Desc.strVrdeModule.c_str(), NULL, VBOXEXTPACKMODKIND_R3,
|
---|
1106 | a_pstrVrdeLibrary, NULL /*a_pfNative*/, NULL /*a_pObjInfo*/))
|
---|
1107 | hrc = S_OK;
|
---|
1108 | else
|
---|
1109 | hrc = setError(E_FAIL, tr("Failed to locate the VRDE module '%s' in extension pack '%s'"),
|
---|
1110 | m->Desc.strVrdeModule.c_str(), m->Desc.strName.c_str());
|
---|
1111 | }
|
---|
1112 | return hrc;
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | /**
|
---|
1116 | * Resolves the path to the module.
|
---|
1117 | *
|
---|
1118 | * @returns S_OK or COM error status with error information.
|
---|
1119 | * @param a_pszModuleName The library.
|
---|
1120 | * @param a_pstrLibrary Where to return the path on success.
|
---|
1121 | *
|
---|
1122 | * @remarks Caller holds the extension manager lock for reading, no locking
|
---|
1123 | * necessary.
|
---|
1124 | */
|
---|
1125 | HRESULT ExtPack::i_getLibraryName(const char *a_pszModuleName, Utf8Str *a_pstrLibrary)
|
---|
1126 | {
|
---|
1127 | HRESULT hrc;
|
---|
1128 | if (i_findModule(a_pszModuleName, NULL, VBOXEXTPACKMODKIND_R3,
|
---|
1129 | a_pstrLibrary, NULL /*a_pfNative*/, NULL /*a_pObjInfo*/))
|
---|
1130 | hrc = S_OK;
|
---|
1131 | else
|
---|
1132 | hrc = setError(E_FAIL, tr("Failed to locate the module '%s' in extension pack '%s'"),
|
---|
1133 | a_pszModuleName, m->Desc.strName.c_str());
|
---|
1134 | return hrc;
|
---|
1135 | }
|
---|
1136 |
|
---|
1137 | /**
|
---|
1138 | * Check if this extension pack wishes to be the default VRDE provider.
|
---|
1139 | *
|
---|
1140 | * @returns @c true if it wants to and it is in a usable state, otherwise
|
---|
1141 | * @c false.
|
---|
1142 | *
|
---|
1143 | * @remarks Caller holds the extension manager lock for reading, no locking
|
---|
1144 | * necessary.
|
---|
1145 | */
|
---|
1146 | bool ExtPack::i_wantsToBeDefaultVrde(void) const
|
---|
1147 | {
|
---|
1148 | return m->fUsable
|
---|
1149 | && m->Desc.strVrdeModule.isNotEmpty();
|
---|
1150 | }
|
---|
1151 |
|
---|
1152 | /**
|
---|
1153 | * Refreshes the extension pack state.
|
---|
1154 | *
|
---|
1155 | * This is called by the manager so that the on disk changes are picked up.
|
---|
1156 | *
|
---|
1157 | * @returns S_OK or COM error status with error information.
|
---|
1158 | *
|
---|
1159 | * @param a_pfCanDelete Optional can-delete-this-object output indicator.
|
---|
1160 | *
|
---|
1161 | * @remarks Caller holds the extension manager lock for writing.
|
---|
1162 | * @remarks Only called in VBoxSVC.
|
---|
1163 | */
|
---|
1164 | HRESULT ExtPack::i_refresh(bool *a_pfCanDelete)
|
---|
1165 | {
|
---|
1166 | if (a_pfCanDelete)
|
---|
1167 | *a_pfCanDelete = false;
|
---|
1168 |
|
---|
1169 | AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS); /* for the COMGETTERs */
|
---|
1170 |
|
---|
1171 | /*
|
---|
1172 | * Has the module been deleted?
|
---|
1173 | */
|
---|
1174 | RTFSOBJINFO ObjInfoExtPack;
|
---|
1175 | int vrc = RTPathQueryInfoEx(m->strExtPackPath.c_str(), &ObjInfoExtPack, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK);
|
---|
1176 | if ( RT_FAILURE(vrc)
|
---|
1177 | || !RTFS_IS_DIRECTORY(ObjInfoExtPack.Attr.fMode))
|
---|
1178 | {
|
---|
1179 | if (a_pfCanDelete)
|
---|
1180 | *a_pfCanDelete = true;
|
---|
1181 | return S_OK;
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | /*
|
---|
1185 | * We've got a directory, so try query file system object info for the
|
---|
1186 | * files we are interested in as well.
|
---|
1187 | */
|
---|
1188 | RTFSOBJINFO ObjInfoDesc;
|
---|
1189 | char szDescFilePath[RTPATH_MAX];
|
---|
1190 | vrc = RTPathJoin(szDescFilePath, sizeof(szDescFilePath), m->strExtPackPath.c_str(), VBOX_EXTPACK_DESCRIPTION_NAME);
|
---|
1191 | if (RT_SUCCESS(vrc))
|
---|
1192 | vrc = RTPathQueryInfoEx(szDescFilePath, &ObjInfoDesc, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK);
|
---|
1193 | if (RT_FAILURE(vrc))
|
---|
1194 | RT_ZERO(ObjInfoDesc);
|
---|
1195 |
|
---|
1196 | RTFSOBJINFO ObjInfoMainMod;
|
---|
1197 | if (m->strMainModPath.isNotEmpty())
|
---|
1198 | vrc = RTPathQueryInfoEx(m->strMainModPath.c_str(), &ObjInfoMainMod, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK);
|
---|
1199 | if (m->strMainModPath.isEmpty() || RT_FAILURE(vrc))
|
---|
1200 | RT_ZERO(ObjInfoMainMod);
|
---|
1201 |
|
---|
1202 | /*
|
---|
1203 | * If we have a usable module already, just verify that things haven't
|
---|
1204 | * changed since we loaded it.
|
---|
1205 | */
|
---|
1206 | if (m->fUsable)
|
---|
1207 | {
|
---|
1208 | if (m->hMainMod == NIL_RTLDRMOD)
|
---|
1209 | i_probeAndLoad();
|
---|
1210 | else if ( !i_objinfoIsEqual(&ObjInfoDesc, &m->ObjInfoDesc)
|
---|
1211 | || !i_objinfoIsEqual(&ObjInfoMainMod, &m->ObjInfoMainMod)
|
---|
1212 | || !i_objinfoIsEqual(&ObjInfoExtPack, &m->ObjInfoExtPack) )
|
---|
1213 | {
|
---|
1214 | /** @todo not important, so it can wait. */
|
---|
1215 | }
|
---|
1216 | }
|
---|
1217 | /*
|
---|
1218 | * Ok, it is currently not usable. If anything has changed since last time
|
---|
1219 | * reprobe the extension pack.
|
---|
1220 | */
|
---|
1221 | else if ( !i_objinfoIsEqual(&ObjInfoDesc, &m->ObjInfoDesc)
|
---|
1222 | || !i_objinfoIsEqual(&ObjInfoMainMod, &m->ObjInfoMainMod)
|
---|
1223 | || !i_objinfoIsEqual(&ObjInfoExtPack, &m->ObjInfoExtPack) )
|
---|
1224 | i_probeAndLoad();
|
---|
1225 |
|
---|
1226 | return S_OK;
|
---|
1227 | }
|
---|
1228 |
|
---|
1229 | /**
|
---|
1230 | * Probes the extension pack, loading the main dll and calling its registration
|
---|
1231 | * entry point.
|
---|
1232 | *
|
---|
1233 | * This updates the state accordingly, the strWhyUnusable and fUnusable members
|
---|
1234 | * being the most important ones.
|
---|
1235 | */
|
---|
1236 | void ExtPack::i_probeAndLoad(void)
|
---|
1237 | {
|
---|
1238 | m->fUsable = false;
|
---|
1239 | m->fMadeReadyCall = false;
|
---|
1240 |
|
---|
1241 | /*
|
---|
1242 | * Query the file system info for the extension pack directory. This and
|
---|
1243 | * all other file system info we save is for the benefit of refresh().
|
---|
1244 | */
|
---|
1245 | int vrc = RTPathQueryInfoEx(m->strExtPackPath.c_str(), &m->ObjInfoExtPack, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK);
|
---|
1246 | if (RT_FAILURE(vrc))
|
---|
1247 | {
|
---|
1248 | m->strWhyUnusable.printf(tr("RTPathQueryInfoEx on '%s' failed: %Rrc"), m->strExtPackPath.c_str(), vrc);
|
---|
1249 | return;
|
---|
1250 | }
|
---|
1251 | if (!RTFS_IS_DIRECTORY(m->ObjInfoExtPack.Attr.fMode))
|
---|
1252 | {
|
---|
1253 | if (RTFS_IS_SYMLINK(m->ObjInfoExtPack.Attr.fMode))
|
---|
1254 | m->strWhyUnusable.printf(tr("'%s' is a symbolic link, this is not allowed"),
|
---|
1255 | m->strExtPackPath.c_str(), vrc);
|
---|
1256 | else if (RTFS_IS_FILE(m->ObjInfoExtPack.Attr.fMode))
|
---|
1257 | m->strWhyUnusable.printf(tr("'%s' is a symbolic file, not a directory"),
|
---|
1258 | m->strExtPackPath.c_str(), vrc);
|
---|
1259 | else
|
---|
1260 | m->strWhyUnusable.printf(tr("'%s' is not a directory (fMode=%#x)"),
|
---|
1261 | m->strExtPackPath.c_str(), m->ObjInfoExtPack.Attr.fMode);
|
---|
1262 | return;
|
---|
1263 | }
|
---|
1264 |
|
---|
1265 | RTERRINFOSTATIC ErrInfo;
|
---|
1266 | RTErrInfoInitStatic(&ErrInfo);
|
---|
1267 | vrc = SUPR3HardenedVerifyDir(m->strExtPackPath.c_str(), true /*fRecursive*/, true /*fCheckFiles*/, &ErrInfo.Core);
|
---|
1268 | if (RT_FAILURE(vrc))
|
---|
1269 | {
|
---|
1270 | m->strWhyUnusable.printf(tr("%s (rc=%Rrc)"), ErrInfo.Core.pszMsg, vrc);
|
---|
1271 | return;
|
---|
1272 | }
|
---|
1273 |
|
---|
1274 | /*
|
---|
1275 | * Read the description file.
|
---|
1276 | */
|
---|
1277 | RTCString strSavedName(m->Desc.strName);
|
---|
1278 | RTCString *pStrLoadErr = VBoxExtPackLoadDesc(m->strExtPackPath.c_str(), &m->Desc, &m->ObjInfoDesc);
|
---|
1279 | if (pStrLoadErr != NULL)
|
---|
1280 | {
|
---|
1281 | m->strWhyUnusable.printf(tr("Failed to load '%s/%s': %s"),
|
---|
1282 | m->strExtPackPath.c_str(), VBOX_EXTPACK_DESCRIPTION_NAME, pStrLoadErr->c_str());
|
---|
1283 | m->Desc.strName = strSavedName;
|
---|
1284 | delete pStrLoadErr;
|
---|
1285 | return;
|
---|
1286 | }
|
---|
1287 |
|
---|
1288 | /*
|
---|
1289 | * Make sure the XML name and directory matches.
|
---|
1290 | */
|
---|
1291 | if (!m->Desc.strName.equalsIgnoreCase(strSavedName))
|
---|
1292 | {
|
---|
1293 | m->strWhyUnusable.printf(tr("The description name ('%s') and directory name ('%s') does not match"),
|
---|
1294 | m->Desc.strName.c_str(), strSavedName.c_str());
|
---|
1295 | m->Desc.strName = strSavedName;
|
---|
1296 | return;
|
---|
1297 | }
|
---|
1298 |
|
---|
1299 | /*
|
---|
1300 | * Load the main DLL and call the predefined entry point.
|
---|
1301 | */
|
---|
1302 | #ifndef VBOX_COM_INPROC
|
---|
1303 | const char *pszMainModule = m->Desc.strMainModule.c_str();
|
---|
1304 | #else
|
---|
1305 | const char *pszMainModule = m->Desc.strMainVMModule.c_str();
|
---|
1306 | if (m->Desc.strMainVMModule.isEmpty())
|
---|
1307 | {
|
---|
1308 | /*
|
---|
1309 | * We're good! The main module for VM processes is optional.
|
---|
1310 | */
|
---|
1311 | m->fUsable = true;
|
---|
1312 | m->strWhyUnusable.setNull();
|
---|
1313 | return;
|
---|
1314 | }
|
---|
1315 | #endif
|
---|
1316 | bool fIsNative;
|
---|
1317 | if (!i_findModule(pszMainModule, NULL /* default extension */, VBOXEXTPACKMODKIND_R3,
|
---|
1318 | &m->strMainModPath, &fIsNative, &m->ObjInfoMainMod))
|
---|
1319 | {
|
---|
1320 | m->strWhyUnusable.printf(tr("Failed to locate the main module ('%s')"), pszMainModule);
|
---|
1321 | return;
|
---|
1322 | }
|
---|
1323 |
|
---|
1324 | vrc = SUPR3HardenedVerifyPlugIn(m->strMainModPath.c_str(), &ErrInfo.Core);
|
---|
1325 | if (RT_FAILURE(vrc))
|
---|
1326 | {
|
---|
1327 | m->strWhyUnusable.printf(tr("%s"), ErrInfo.Core.pszMsg);
|
---|
1328 | return;
|
---|
1329 | }
|
---|
1330 |
|
---|
1331 | if (fIsNative)
|
---|
1332 | {
|
---|
1333 | vrc = SUPR3HardenedLdrLoadPlugIn(m->strMainModPath.c_str(), &m->hMainMod, &ErrInfo.Core);
|
---|
1334 | if (RT_FAILURE(vrc))
|
---|
1335 | {
|
---|
1336 | m->hMainMod = NIL_RTLDRMOD;
|
---|
1337 | m->strWhyUnusable.printf(tr("Failed to load the main module ('%s'): %Rrc - %s"),
|
---|
1338 | m->strMainModPath.c_str(), vrc, ErrInfo.Core.pszMsg);
|
---|
1339 | return;
|
---|
1340 | }
|
---|
1341 | }
|
---|
1342 | else
|
---|
1343 | {
|
---|
1344 | m->strWhyUnusable.printf(tr("Only native main modules are currently supported"));
|
---|
1345 | return;
|
---|
1346 | }
|
---|
1347 |
|
---|
1348 | /*
|
---|
1349 | * Resolve the predefined entry point.
|
---|
1350 | */
|
---|
1351 | #ifndef VBOX_COM_INPROC
|
---|
1352 | const char *pszMainEntryPoint = VBOX_EXTPACK_MAIN_MOD_ENTRY_POINT;
|
---|
1353 | PFNVBOXEXTPACKREGISTER pfnRegistration;
|
---|
1354 | uint32_t uVersion = VBOXEXTPACKREG_VERSION;
|
---|
1355 | #else
|
---|
1356 | const char *pszMainEntryPoint = VBOX_EXTPACK_MAIN_VM_MOD_ENTRY_POINT;
|
---|
1357 | PFNVBOXEXTPACKVMREGISTER pfnRegistration;
|
---|
1358 | uint32_t uVersion = VBOXEXTPACKVMREG_VERSION;
|
---|
1359 | #endif
|
---|
1360 | vrc = RTLdrGetSymbol(m->hMainMod, pszMainEntryPoint, (void **)&pfnRegistration);
|
---|
1361 | if (RT_SUCCESS(vrc))
|
---|
1362 | {
|
---|
1363 | RTErrInfoClear(&ErrInfo.Core);
|
---|
1364 | vrc = pfnRegistration(&m->Hlp, &m->pReg, &ErrInfo.Core);
|
---|
1365 | if ( RT_SUCCESS(vrc)
|
---|
1366 | && !RTErrInfoIsSet(&ErrInfo.Core)
|
---|
1367 | && VALID_PTR(m->pReg))
|
---|
1368 | {
|
---|
1369 | if ( VBOXEXTPACK_IS_MAJOR_VER_EQUAL(m->pReg->u32Version, uVersion)
|
---|
1370 | && m->pReg->u32EndMarker == m->pReg->u32Version)
|
---|
1371 | {
|
---|
1372 | #ifndef VBOX_COM_INPROC
|
---|
1373 | if ( (!m->pReg->pfnInstalled || RT_VALID_PTR(m->pReg->pfnInstalled))
|
---|
1374 | && (!m->pReg->pfnUninstall || RT_VALID_PTR(m->pReg->pfnUninstall))
|
---|
1375 | && (!m->pReg->pfnVirtualBoxReady || RT_VALID_PTR(m->pReg->pfnVirtualBoxReady))
|
---|
1376 | && (!m->pReg->pfnUnload || RT_VALID_PTR(m->pReg->pfnUnload))
|
---|
1377 | && (!m->pReg->pfnVMCreated || RT_VALID_PTR(m->pReg->pfnVMCreated))
|
---|
1378 | && (!m->pReg->pfnQueryObject || RT_VALID_PTR(m->pReg->pfnQueryObject))
|
---|
1379 | )
|
---|
1380 | {
|
---|
1381 | /*
|
---|
1382 | * We're good!
|
---|
1383 | */
|
---|
1384 | m->fUsable = true;
|
---|
1385 | m->strWhyUnusable.setNull();
|
---|
1386 | return;
|
---|
1387 | }
|
---|
1388 | #else
|
---|
1389 | if ( (!m->pReg->pfnConsoleReady || RT_VALID_PTR(m->pReg->pfnConsoleReady))
|
---|
1390 | && (!m->pReg->pfnUnload || RT_VALID_PTR(m->pReg->pfnUnload))
|
---|
1391 | && (!m->pReg->pfnVMConfigureVMM || RT_VALID_PTR(m->pReg->pfnVMConfigureVMM))
|
---|
1392 | && (!m->pReg->pfnVMPowerOn || RT_VALID_PTR(m->pReg->pfnVMPowerOn))
|
---|
1393 | && (!m->pReg->pfnVMPowerOff || RT_VALID_PTR(m->pReg->pfnVMPowerOff))
|
---|
1394 | && (!m->pReg->pfnQueryObject || RT_VALID_PTR(m->pReg->pfnQueryObject))
|
---|
1395 | )
|
---|
1396 | {
|
---|
1397 | /*
|
---|
1398 | * We're good!
|
---|
1399 | */
|
---|
1400 | m->fUsable = true;
|
---|
1401 | m->strWhyUnusable.setNull();
|
---|
1402 | return;
|
---|
1403 | }
|
---|
1404 | #endif
|
---|
1405 |
|
---|
1406 | m->strWhyUnusable = tr("The registration structure contains one or more invalid function pointers");
|
---|
1407 | }
|
---|
1408 | else
|
---|
1409 | m->strWhyUnusable.printf(tr("Unsupported registration structure version %u.%u"),
|
---|
1410 | RT_HIWORD(m->pReg->u32Version), RT_LOWORD(m->pReg->u32Version));
|
---|
1411 | }
|
---|
1412 | else
|
---|
1413 | m->strWhyUnusable.printf(tr("%s returned %Rrc, pReg=%p ErrInfo='%s'"),
|
---|
1414 | pszMainEntryPoint, vrc, m->pReg, ErrInfo.Core.pszMsg);
|
---|
1415 | m->pReg = NULL;
|
---|
1416 | }
|
---|
1417 | else
|
---|
1418 | m->strWhyUnusable.printf(tr("Failed to resolve exported symbol '%s' in the main module: %Rrc"),
|
---|
1419 | pszMainEntryPoint, vrc);
|
---|
1420 |
|
---|
1421 | RTLdrClose(m->hMainMod);
|
---|
1422 | m->hMainMod = NIL_RTLDRMOD;
|
---|
1423 | }
|
---|
1424 |
|
---|
1425 | /**
|
---|
1426 | * Finds a module.
|
---|
1427 | *
|
---|
1428 | * @returns true if found, false if not.
|
---|
1429 | * @param a_pszName The module base name (no extension).
|
---|
1430 | * @param a_pszExt The extension. If NULL we use default
|
---|
1431 | * extensions.
|
---|
1432 | * @param a_enmKind The kind of module to locate.
|
---|
1433 | * @param a_pStrFound Where to return the path to the module we've
|
---|
1434 | * found.
|
---|
1435 | * @param a_pfNative Where to return whether this is a native module
|
---|
1436 | * or an agnostic one. Optional.
|
---|
1437 | * @param a_pObjInfo Where to return the file system object info for
|
---|
1438 | * the module. Optional.
|
---|
1439 | */
|
---|
1440 | bool ExtPack::i_findModule(const char *a_pszName, const char *a_pszExt, VBOXEXTPACKMODKIND a_enmKind,
|
---|
1441 | Utf8Str *a_pStrFound, bool *a_pfNative, PRTFSOBJINFO a_pObjInfo) const
|
---|
1442 | {
|
---|
1443 | /*
|
---|
1444 | * Try the native path first.
|
---|
1445 | */
|
---|
1446 | char szPath[RTPATH_MAX];
|
---|
1447 | int vrc = RTPathJoin(szPath, sizeof(szPath), m->strExtPackPath.c_str(), RTBldCfgTargetDotArch());
|
---|
1448 | AssertLogRelRCReturn(vrc, false);
|
---|
1449 | vrc = RTPathAppend(szPath, sizeof(szPath), a_pszName);
|
---|
1450 | AssertLogRelRCReturn(vrc, false);
|
---|
1451 | if (!a_pszExt)
|
---|
1452 | {
|
---|
1453 | const char *pszDefExt;
|
---|
1454 | switch (a_enmKind)
|
---|
1455 | {
|
---|
1456 | case VBOXEXTPACKMODKIND_RC: pszDefExt = ".rc"; break;
|
---|
1457 | case VBOXEXTPACKMODKIND_R0: pszDefExt = ".r0"; break;
|
---|
1458 | case VBOXEXTPACKMODKIND_R3: pszDefExt = RTLdrGetSuff(); break;
|
---|
1459 | default:
|
---|
1460 | AssertFailedReturn(false);
|
---|
1461 | }
|
---|
1462 | vrc = RTStrCat(szPath, sizeof(szPath), pszDefExt);
|
---|
1463 | AssertLogRelRCReturn(vrc, false);
|
---|
1464 | }
|
---|
1465 |
|
---|
1466 | RTFSOBJINFO ObjInfo;
|
---|
1467 | if (!a_pObjInfo)
|
---|
1468 | a_pObjInfo = &ObjInfo;
|
---|
1469 | vrc = RTPathQueryInfo(szPath, a_pObjInfo, RTFSOBJATTRADD_UNIX);
|
---|
1470 | if (RT_SUCCESS(vrc) && RTFS_IS_FILE(a_pObjInfo->Attr.fMode))
|
---|
1471 | {
|
---|
1472 | if (a_pfNative)
|
---|
1473 | *a_pfNative = true;
|
---|
1474 | *a_pStrFound = szPath;
|
---|
1475 | return true;
|
---|
1476 | }
|
---|
1477 |
|
---|
1478 | /*
|
---|
1479 | * Try the platform agnostic modules.
|
---|
1480 | */
|
---|
1481 | /* gcc.x86/module.rel */
|
---|
1482 | char szSubDir[32];
|
---|
1483 | RTStrPrintf(szSubDir, sizeof(szSubDir), "%s.%s", RTBldCfgCompiler(), RTBldCfgTargetArch());
|
---|
1484 | vrc = RTPathJoin(szPath, sizeof(szPath), m->strExtPackPath.c_str(), szSubDir);
|
---|
1485 | AssertLogRelRCReturn(vrc, false);
|
---|
1486 | vrc = RTPathAppend(szPath, sizeof(szPath), a_pszName);
|
---|
1487 | AssertLogRelRCReturn(vrc, false);
|
---|
1488 | if (!a_pszExt)
|
---|
1489 | {
|
---|
1490 | vrc = RTStrCat(szPath, sizeof(szPath), ".rel");
|
---|
1491 | AssertLogRelRCReturn(vrc, false);
|
---|
1492 | }
|
---|
1493 | vrc = RTPathQueryInfo(szPath, a_pObjInfo, RTFSOBJATTRADD_UNIX);
|
---|
1494 | if (RT_SUCCESS(vrc) && RTFS_IS_FILE(a_pObjInfo->Attr.fMode))
|
---|
1495 | {
|
---|
1496 | if (a_pfNative)
|
---|
1497 | *a_pfNative = false;
|
---|
1498 | *a_pStrFound = szPath;
|
---|
1499 | return true;
|
---|
1500 | }
|
---|
1501 |
|
---|
1502 | /* x86/module.rel */
|
---|
1503 | vrc = RTPathJoin(szPath, sizeof(szPath), m->strExtPackPath.c_str(), RTBldCfgTargetArch());
|
---|
1504 | AssertLogRelRCReturn(vrc, false);
|
---|
1505 | vrc = RTPathAppend(szPath, sizeof(szPath), a_pszName);
|
---|
1506 | AssertLogRelRCReturn(vrc, false);
|
---|
1507 | if (!a_pszExt)
|
---|
1508 | {
|
---|
1509 | vrc = RTStrCat(szPath, sizeof(szPath), ".rel");
|
---|
1510 | AssertLogRelRCReturn(vrc, false);
|
---|
1511 | }
|
---|
1512 | vrc = RTPathQueryInfo(szPath, a_pObjInfo, RTFSOBJATTRADD_UNIX);
|
---|
1513 | if (RT_SUCCESS(vrc) && RTFS_IS_FILE(a_pObjInfo->Attr.fMode))
|
---|
1514 | {
|
---|
1515 | if (a_pfNative)
|
---|
1516 | *a_pfNative = false;
|
---|
1517 | *a_pStrFound = szPath;
|
---|
1518 | return true;
|
---|
1519 | }
|
---|
1520 |
|
---|
1521 | return false;
|
---|
1522 | }
|
---|
1523 |
|
---|
1524 | /**
|
---|
1525 | * Compares two file system object info structures.
|
---|
1526 | *
|
---|
1527 | * @returns true if equal, false if not.
|
---|
1528 | * @param pObjInfo1 The first.
|
---|
1529 | * @param pObjInfo2 The second.
|
---|
1530 | * @todo IPRT should do this, really.
|
---|
1531 | */
|
---|
1532 | /* static */ bool ExtPack::i_objinfoIsEqual(PCRTFSOBJINFO pObjInfo1, PCRTFSOBJINFO pObjInfo2)
|
---|
1533 | {
|
---|
1534 | if (!RTTimeSpecIsEqual(&pObjInfo1->ModificationTime, &pObjInfo2->ModificationTime))
|
---|
1535 | return false;
|
---|
1536 | if (!RTTimeSpecIsEqual(&pObjInfo1->ChangeTime, &pObjInfo2->ChangeTime))
|
---|
1537 | return false;
|
---|
1538 | if (!RTTimeSpecIsEqual(&pObjInfo1->BirthTime, &pObjInfo2->BirthTime))
|
---|
1539 | return false;
|
---|
1540 | if (pObjInfo1->cbObject != pObjInfo2->cbObject)
|
---|
1541 | return false;
|
---|
1542 | if (pObjInfo1->Attr.fMode != pObjInfo2->Attr.fMode)
|
---|
1543 | return false;
|
---|
1544 | if (pObjInfo1->Attr.enmAdditional == pObjInfo2->Attr.enmAdditional)
|
---|
1545 | {
|
---|
1546 | switch (pObjInfo1->Attr.enmAdditional)
|
---|
1547 | {
|
---|
1548 | case RTFSOBJATTRADD_UNIX:
|
---|
1549 | if (pObjInfo1->Attr.u.Unix.uid != pObjInfo2->Attr.u.Unix.uid)
|
---|
1550 | return false;
|
---|
1551 | if (pObjInfo1->Attr.u.Unix.gid != pObjInfo2->Attr.u.Unix.gid)
|
---|
1552 | return false;
|
---|
1553 | if (pObjInfo1->Attr.u.Unix.INodeIdDevice != pObjInfo2->Attr.u.Unix.INodeIdDevice)
|
---|
1554 | return false;
|
---|
1555 | if (pObjInfo1->Attr.u.Unix.INodeId != pObjInfo2->Attr.u.Unix.INodeId)
|
---|
1556 | return false;
|
---|
1557 | if (pObjInfo1->Attr.u.Unix.GenerationId != pObjInfo2->Attr.u.Unix.GenerationId)
|
---|
1558 | return false;
|
---|
1559 | break;
|
---|
1560 | default:
|
---|
1561 | break;
|
---|
1562 | }
|
---|
1563 | }
|
---|
1564 | return true;
|
---|
1565 | }
|
---|
1566 |
|
---|
1567 |
|
---|
1568 | /**
|
---|
1569 | * @interface_method_impl{VBOXEXTPACKHLP,pfnFindModule}
|
---|
1570 | */
|
---|
1571 | /*static*/ DECLCALLBACK(int)
|
---|
1572 | ExtPack::i_hlpFindModule(PCVBOXEXTPACKHLP pHlp, const char *pszName, const char *pszExt, VBOXEXTPACKMODKIND enmKind,
|
---|
1573 | char *pszFound, size_t cbFound, bool *pfNative)
|
---|
1574 | {
|
---|
1575 | /*
|
---|
1576 | * Validate the input and get our bearings.
|
---|
1577 | */
|
---|
1578 | AssertPtrReturn(pszName, VERR_INVALID_POINTER);
|
---|
1579 | AssertPtrNullReturn(pszExt, VERR_INVALID_POINTER);
|
---|
1580 | AssertPtrReturn(pszFound, VERR_INVALID_POINTER);
|
---|
1581 | AssertPtrNullReturn(pfNative, VERR_INVALID_POINTER);
|
---|
1582 | AssertReturn(enmKind > VBOXEXTPACKMODKIND_INVALID && enmKind < VBOXEXTPACKMODKIND_END, VERR_INVALID_PARAMETER);
|
---|
1583 |
|
---|
1584 | AssertPtrReturn(pHlp, VERR_INVALID_POINTER);
|
---|
1585 | AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VERR_INVALID_POINTER);
|
---|
1586 | ExtPack::Data *m = RT_FROM_CPP_MEMBER(pHlp, Data, Hlp);
|
---|
1587 | AssertPtrReturn(m, VERR_INVALID_POINTER);
|
---|
1588 | ExtPack *pThis = m->pThis;
|
---|
1589 | AssertPtrReturn(pThis, VERR_INVALID_POINTER);
|
---|
1590 |
|
---|
1591 | /*
|
---|
1592 | * This is just a wrapper around findModule.
|
---|
1593 | */
|
---|
1594 | Utf8Str strFound;
|
---|
1595 | if (pThis->i_findModule(pszName, pszExt, enmKind, &strFound, pfNative, NULL))
|
---|
1596 | return RTStrCopy(pszFound, cbFound, strFound.c_str());
|
---|
1597 | return VERR_FILE_NOT_FOUND;
|
---|
1598 | }
|
---|
1599 |
|
---|
1600 | /*static*/ DECLCALLBACK(int)
|
---|
1601 | ExtPack::i_hlpGetFilePath(PCVBOXEXTPACKHLP pHlp, const char *pszFilename, char *pszPath, size_t cbPath)
|
---|
1602 | {
|
---|
1603 | /*
|
---|
1604 | * Validate the input and get our bearings.
|
---|
1605 | */
|
---|
1606 | AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
|
---|
1607 | AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
|
---|
1608 | AssertReturn(cbPath > 0, VERR_BUFFER_OVERFLOW);
|
---|
1609 |
|
---|
1610 | AssertPtrReturn(pHlp, VERR_INVALID_POINTER);
|
---|
1611 | AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VERR_INVALID_POINTER);
|
---|
1612 | ExtPack::Data *m = RT_FROM_CPP_MEMBER(pHlp, Data, Hlp);
|
---|
1613 | AssertPtrReturn(m, VERR_INVALID_POINTER);
|
---|
1614 | ExtPack *pThis = m->pThis;
|
---|
1615 | AssertPtrReturn(pThis, VERR_INVALID_POINTER);
|
---|
1616 |
|
---|
1617 | /*
|
---|
1618 | * This is a simple RTPathJoin, no checking if things exists or anything.
|
---|
1619 | */
|
---|
1620 | int vrc = RTPathJoin(pszPath, cbPath, pThis->m->strExtPackPath.c_str(), pszFilename);
|
---|
1621 | if (RT_FAILURE(vrc))
|
---|
1622 | RT_BZERO(pszPath, cbPath);
|
---|
1623 | return vrc;
|
---|
1624 | }
|
---|
1625 |
|
---|
1626 | /*static*/ DECLCALLBACK(VBOXEXTPACKCTX)
|
---|
1627 | ExtPack::i_hlpGetContext(PCVBOXEXTPACKHLP pHlp)
|
---|
1628 | {
|
---|
1629 | /*
|
---|
1630 | * Validate the input and get our bearings.
|
---|
1631 | */
|
---|
1632 | AssertPtrReturn(pHlp, VBOXEXTPACKCTX_INVALID);
|
---|
1633 | AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VBOXEXTPACKCTX_INVALID);
|
---|
1634 | ExtPack::Data *m = RT_FROM_CPP_MEMBER(pHlp, Data, Hlp);
|
---|
1635 | AssertPtrReturn(m, VBOXEXTPACKCTX_INVALID);
|
---|
1636 | ExtPack *pThis = m->pThis;
|
---|
1637 | AssertPtrReturn(pThis, VBOXEXTPACKCTX_INVALID);
|
---|
1638 |
|
---|
1639 | return pThis->m->enmContext;
|
---|
1640 | }
|
---|
1641 |
|
---|
1642 | /*static*/ DECLCALLBACK(int)
|
---|
1643 | ExtPack::i_hlpLoadHGCMService(PCVBOXEXTPACKHLP pHlp, VBOXEXTPACK_IF_CS(IConsole) *pConsole,
|
---|
1644 | const char *pszServiceLibrary, const char *pszServiceName)
|
---|
1645 | {
|
---|
1646 | #ifdef VBOX_COM_INPROC
|
---|
1647 | /*
|
---|
1648 | * Validate the input and get our bearings.
|
---|
1649 | */
|
---|
1650 | AssertPtrReturn(pszServiceLibrary, VERR_INVALID_POINTER);
|
---|
1651 | AssertPtrReturn(pszServiceName, VERR_INVALID_POINTER);
|
---|
1652 |
|
---|
1653 | AssertPtrReturn(pHlp, VERR_INVALID_POINTER);
|
---|
1654 | AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VERR_INVALID_POINTER);
|
---|
1655 | ExtPack::Data *m = RT_FROM_CPP_MEMBER(pHlp, Data, Hlp);
|
---|
1656 | AssertPtrReturn(m, VERR_INVALID_POINTER);
|
---|
1657 | ExtPack *pThis = m->pThis;
|
---|
1658 | AssertPtrReturn(pThis, VERR_INVALID_POINTER);
|
---|
1659 | AssertPtrReturn(pConsole, VERR_INVALID_POINTER);
|
---|
1660 |
|
---|
1661 | Console *pCon = (Console *)pConsole;
|
---|
1662 | return pCon->i_hgcmLoadService(pszServiceLibrary, pszServiceName);
|
---|
1663 | #else
|
---|
1664 | NOREF(pHlp); NOREF(pConsole); NOREF(pszServiceLibrary); NOREF(pszServiceName);
|
---|
1665 | return VERR_INVALID_STATE;
|
---|
1666 | #endif
|
---|
1667 | }
|
---|
1668 |
|
---|
1669 | /*static*/ DECLCALLBACK(int)
|
---|
1670 | ExtPack::i_hlpLoadVDPlugin(PCVBOXEXTPACKHLP pHlp, VBOXEXTPACK_IF_CS(IVirtualBox) *pVirtualBox, const char *pszPluginLibrary)
|
---|
1671 | {
|
---|
1672 | #ifndef VBOX_COM_INPROC
|
---|
1673 | /*
|
---|
1674 | * Validate the input and get our bearings.
|
---|
1675 | */
|
---|
1676 | AssertPtrReturn(pszPluginLibrary, VERR_INVALID_POINTER);
|
---|
1677 |
|
---|
1678 | AssertPtrReturn(pHlp, VERR_INVALID_POINTER);
|
---|
1679 | AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VERR_INVALID_POINTER);
|
---|
1680 | ExtPack::Data *m = RT_FROM_CPP_MEMBER(pHlp, Data, Hlp);
|
---|
1681 | AssertPtrReturn(m, VERR_INVALID_POINTER);
|
---|
1682 | ExtPack *pThis = m->pThis;
|
---|
1683 | AssertPtrReturn(pThis, VERR_INVALID_POINTER);
|
---|
1684 | AssertPtrReturn(pVirtualBox, VERR_INVALID_POINTER);
|
---|
1685 |
|
---|
1686 | VirtualBox *pVBox = (VirtualBox *)pVirtualBox;
|
---|
1687 | return pVBox->i_loadVDPlugin(pszPluginLibrary);
|
---|
1688 | #else
|
---|
1689 | NOREF(pHlp); NOREF(pVirtualBox); NOREF(pszPluginLibrary);
|
---|
1690 | return VERR_INVALID_STATE;
|
---|
1691 | #endif
|
---|
1692 | }
|
---|
1693 |
|
---|
1694 | /*static*/ DECLCALLBACK(int)
|
---|
1695 | ExtPack::i_hlpUnloadVDPlugin(PCVBOXEXTPACKHLP pHlp, VBOXEXTPACK_IF_CS(IVirtualBox) *pVirtualBox, const char *pszPluginLibrary)
|
---|
1696 | {
|
---|
1697 | #ifndef VBOX_COM_INPROC
|
---|
1698 | /*
|
---|
1699 | * Validate the input and get our bearings.
|
---|
1700 | */
|
---|
1701 | AssertPtrReturn(pszPluginLibrary, VERR_INVALID_POINTER);
|
---|
1702 |
|
---|
1703 | AssertPtrReturn(pHlp, VERR_INVALID_POINTER);
|
---|
1704 | AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VERR_INVALID_POINTER);
|
---|
1705 | ExtPack::Data *m = RT_FROM_CPP_MEMBER(pHlp, Data, Hlp);
|
---|
1706 | AssertPtrReturn(m, VERR_INVALID_POINTER);
|
---|
1707 | ExtPack *pThis = m->pThis;
|
---|
1708 | AssertPtrReturn(pThis, VERR_INVALID_POINTER);
|
---|
1709 | AssertPtrReturn(pVirtualBox, VERR_INVALID_POINTER);
|
---|
1710 |
|
---|
1711 | VirtualBox *pVBox = (VirtualBox *)pVirtualBox;
|
---|
1712 | return pVBox->i_unloadVDPlugin(pszPluginLibrary);
|
---|
1713 | #else
|
---|
1714 | NOREF(pHlp); NOREF(pVirtualBox); NOREF(pszPluginLibrary);
|
---|
1715 | return VERR_INVALID_STATE;
|
---|
1716 | #endif
|
---|
1717 | }
|
---|
1718 |
|
---|
1719 | /*static*/ DECLCALLBACK(int)
|
---|
1720 | ExtPack::i_hlpReservedN(PCVBOXEXTPACKHLP pHlp)
|
---|
1721 | {
|
---|
1722 | /*
|
---|
1723 | * Validate the input and get our bearings.
|
---|
1724 | */
|
---|
1725 | AssertPtrReturn(pHlp, VERR_INVALID_POINTER);
|
---|
1726 | AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VERR_INVALID_POINTER);
|
---|
1727 | ExtPack::Data *m = RT_FROM_CPP_MEMBER(pHlp, Data, Hlp);
|
---|
1728 | AssertPtrReturn(m, VERR_INVALID_POINTER);
|
---|
1729 | ExtPack *pThis = m->pThis;
|
---|
1730 | AssertPtrReturn(pThis, VERR_INVALID_POINTER);
|
---|
1731 |
|
---|
1732 | return VERR_NOT_IMPLEMENTED;
|
---|
1733 | }
|
---|
1734 |
|
---|
1735 |
|
---|
1736 |
|
---|
1737 |
|
---|
1738 | HRESULT ExtPack::getName(com::Utf8Str &aName)
|
---|
1739 | {
|
---|
1740 | aName = m->Desc.strName;
|
---|
1741 | return S_OK;
|
---|
1742 | }
|
---|
1743 |
|
---|
1744 | HRESULT ExtPack::getDescription(com::Utf8Str &aDescription)
|
---|
1745 | {
|
---|
1746 | aDescription = m->Desc.strDescription;
|
---|
1747 | return S_OK;
|
---|
1748 | }
|
---|
1749 |
|
---|
1750 | HRESULT ExtPack::getVersion(com::Utf8Str &aVersion)
|
---|
1751 | {
|
---|
1752 | aVersion = m->Desc.strVersion;
|
---|
1753 | return S_OK;
|
---|
1754 | }
|
---|
1755 |
|
---|
1756 | HRESULT ExtPack::getRevision(ULONG *aRevision)
|
---|
1757 | {
|
---|
1758 | *aRevision = m->Desc.uRevision;
|
---|
1759 | return S_OK;
|
---|
1760 | }
|
---|
1761 |
|
---|
1762 | HRESULT ExtPack::getEdition(com::Utf8Str &aEdition)
|
---|
1763 | {
|
---|
1764 | aEdition = m->Desc.strEdition;
|
---|
1765 | return S_OK;
|
---|
1766 | }
|
---|
1767 |
|
---|
1768 | HRESULT ExtPack::getVRDEModule(com::Utf8Str &aVRDEModule)
|
---|
1769 | {
|
---|
1770 | aVRDEModule = m->Desc.strVrdeModule;
|
---|
1771 | return S_OK;
|
---|
1772 | }
|
---|
1773 |
|
---|
1774 | HRESULT ExtPack::getPlugIns(std::vector<ComPtr<IExtPackPlugIn> > &aPlugIns)
|
---|
1775 | {
|
---|
1776 | /** @todo implement plug-ins. */
|
---|
1777 | NOREF(aPlugIns);
|
---|
1778 | ReturnComNotImplemented();
|
---|
1779 | }
|
---|
1780 |
|
---|
1781 | HRESULT ExtPack::getUsable(BOOL *aUsable)
|
---|
1782 | {
|
---|
1783 | *aUsable = m->fUsable;
|
---|
1784 | return S_OK;
|
---|
1785 | }
|
---|
1786 |
|
---|
1787 | HRESULT ExtPack::getWhyUnusable(com::Utf8Str &aWhyUnusable)
|
---|
1788 | {
|
---|
1789 | aWhyUnusable = m->strWhyUnusable;
|
---|
1790 | return S_OK;
|
---|
1791 | }
|
---|
1792 |
|
---|
1793 | HRESULT ExtPack::getShowLicense(BOOL *aShowLicense)
|
---|
1794 | {
|
---|
1795 | *aShowLicense = m->Desc.fShowLicense;
|
---|
1796 | return S_OK;
|
---|
1797 | }
|
---|
1798 |
|
---|
1799 | HRESULT ExtPack::getLicense(com::Utf8Str &aLicense)
|
---|
1800 | {
|
---|
1801 | Utf8Str strHtml("html");
|
---|
1802 | Utf8Str str("");
|
---|
1803 | return queryLicense(str, str, strHtml, aLicense);
|
---|
1804 | }
|
---|
1805 |
|
---|
1806 | HRESULT ExtPack::queryLicense(const com::Utf8Str &aPreferredLocale, const com::Utf8Str &aPreferredLanguage,
|
---|
1807 | const com::Utf8Str &aFormat, com::Utf8Str &aLicenseText)
|
---|
1808 | {
|
---|
1809 | HRESULT hrc = S_OK;
|
---|
1810 |
|
---|
1811 | /*
|
---|
1812 | * Validate input.
|
---|
1813 | */
|
---|
1814 | if (aPreferredLocale.length() != 2 && aPreferredLocale.length() != 0)
|
---|
1815 | return setError(E_FAIL, tr("The preferred locale is a two character string or empty."));
|
---|
1816 |
|
---|
1817 | if (aPreferredLanguage.length() != 2 && aPreferredLanguage.length() != 0)
|
---|
1818 | return setError(E_FAIL, tr("The preferred lanuage is a two character string or empty."));
|
---|
1819 |
|
---|
1820 | if ( !aFormat.equals("html")
|
---|
1821 | && !aFormat.equals("rtf")
|
---|
1822 | && !aFormat.equals("txt"))
|
---|
1823 | return setError(E_FAIL, tr("The license format can only have the values 'html', 'rtf' and 'txt'."));
|
---|
1824 |
|
---|
1825 | /*
|
---|
1826 | * Combine the options to form a file name before locking down anything.
|
---|
1827 | */
|
---|
1828 | char szName[sizeof(VBOX_EXTPACK_LICENSE_NAME_PREFIX "-de_DE.html") + 2];
|
---|
1829 | if (aPreferredLocale.isNotEmpty() && aPreferredLanguage.isNotEmpty())
|
---|
1830 | RTStrPrintf(szName, sizeof(szName), VBOX_EXTPACK_LICENSE_NAME_PREFIX "-%s_%s.%s",
|
---|
1831 | aPreferredLocale.c_str(), aPreferredLanguage.c_str(), aFormat.c_str());
|
---|
1832 | else if (aPreferredLocale.isNotEmpty())
|
---|
1833 | RTStrPrintf(szName, sizeof(szName), VBOX_EXTPACK_LICENSE_NAME_PREFIX "-%s.%s",
|
---|
1834 | aPreferredLocale.c_str(), aFormat.c_str());
|
---|
1835 | else if (aPreferredLanguage.isNotEmpty())
|
---|
1836 | RTStrPrintf(szName, sizeof(szName), VBOX_EXTPACK_LICENSE_NAME_PREFIX "-_%s.%s",
|
---|
1837 | aPreferredLocale.c_str(), aFormat.c_str());
|
---|
1838 | else
|
---|
1839 | RTStrPrintf(szName, sizeof(szName), VBOX_EXTPACK_LICENSE_NAME_PREFIX ".%s",
|
---|
1840 | aFormat.c_str());
|
---|
1841 |
|
---|
1842 | /*
|
---|
1843 | * Effectuate the query.
|
---|
1844 | */
|
---|
1845 | AutoReadLock autoLock(this COMMA_LOCKVAL_SRC_POS); /* paranoia */
|
---|
1846 |
|
---|
1847 | if (!m->fUsable)
|
---|
1848 | hrc = setError(E_FAIL, tr("%s"), m->strWhyUnusable.c_str());
|
---|
1849 | else
|
---|
1850 | {
|
---|
1851 | char szPath[RTPATH_MAX];
|
---|
1852 | int vrc = RTPathJoin(szPath, sizeof(szPath), m->strExtPackPath.c_str(), szName);
|
---|
1853 | if (RT_SUCCESS(vrc))
|
---|
1854 | {
|
---|
1855 | void *pvFile;
|
---|
1856 | size_t cbFile;
|
---|
1857 | vrc = RTFileReadAllEx(szPath, 0, RTFOFF_MAX, RTFILE_RDALL_O_DENY_READ, &pvFile, &cbFile);
|
---|
1858 | if (RT_SUCCESS(vrc))
|
---|
1859 | {
|
---|
1860 | Bstr bstrLicense((const char *)pvFile, cbFile);
|
---|
1861 | if (bstrLicense.isNotEmpty())
|
---|
1862 | {
|
---|
1863 | aLicenseText = Utf8Str(bstrLicense);
|
---|
1864 | hrc = S_OK;
|
---|
1865 | }
|
---|
1866 | else
|
---|
1867 | hrc = setError(VBOX_E_IPRT_ERROR, tr("The license file '%s' is empty or contains invalid UTF-8 encoding"),
|
---|
1868 | szPath);
|
---|
1869 | RTFileReadAllFree(pvFile, cbFile);
|
---|
1870 | }
|
---|
1871 | else if (vrc == VERR_FILE_NOT_FOUND || vrc == VERR_PATH_NOT_FOUND)
|
---|
1872 | hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The license file '%s' was not found in extension pack '%s'"),
|
---|
1873 | szName, m->Desc.strName.c_str());
|
---|
1874 | else
|
---|
1875 | hrc = setError(VBOX_E_FILE_ERROR, tr("Failed to open the license file '%s': %Rrc"), szPath, vrc);
|
---|
1876 | }
|
---|
1877 | else
|
---|
1878 | hrc = setError(VBOX_E_IPRT_ERROR, tr("RTPathJoin failed: %Rrc"), vrc);
|
---|
1879 | }
|
---|
1880 | return hrc;
|
---|
1881 | }
|
---|
1882 |
|
---|
1883 | HRESULT ExtPack::queryObject(const com::Utf8Str &aObjUuid, ComPtr<IUnknown> &aReturnInterface)
|
---|
1884 | {
|
---|
1885 | com::Guid ObjectId;
|
---|
1886 | CheckComArgGuid(aObjUuid, ObjectId);
|
---|
1887 |
|
---|
1888 | HRESULT hrc S_OK;
|
---|
1889 |
|
---|
1890 | if ( m->pReg
|
---|
1891 | && m->pReg->pfnQueryObject)
|
---|
1892 | {
|
---|
1893 | void *pvUnknown = m->pReg->pfnQueryObject(m->pReg, ObjectId.raw());
|
---|
1894 | if (pvUnknown)
|
---|
1895 | aReturnInterface = (IUnknown *)pvUnknown;
|
---|
1896 | else
|
---|
1897 | hrc = E_NOINTERFACE;
|
---|
1898 | }
|
---|
1899 | else
|
---|
1900 | hrc = E_NOINTERFACE;
|
---|
1901 | return hrc;
|
---|
1902 | }
|
---|
1903 |
|
---|
1904 | DEFINE_EMPTY_CTOR_DTOR(ExtPackManager)
|
---|
1905 |
|
---|
1906 | /**
|
---|
1907 | * Called by ComObjPtr::createObject when creating the object.
|
---|
1908 | *
|
---|
1909 | * Just initialize the basic object state, do the rest in init().
|
---|
1910 | *
|
---|
1911 | * @returns S_OK.
|
---|
1912 | */
|
---|
1913 | HRESULT ExtPackManager::FinalConstruct()
|
---|
1914 | {
|
---|
1915 | m = NULL;
|
---|
1916 | return BaseFinalConstruct();
|
---|
1917 | }
|
---|
1918 |
|
---|
1919 | /**
|
---|
1920 | * Initializes the extension pack manager.
|
---|
1921 | *
|
---|
1922 | * @returns COM status code.
|
---|
1923 | * @param a_pVirtualBox Pointer to the VirtualBox object.
|
---|
1924 | * @param a_enmContext The context we're in.
|
---|
1925 | */
|
---|
1926 | HRESULT ExtPackManager::initExtPackManager(VirtualBox *a_pVirtualBox, VBOXEXTPACKCTX a_enmContext)
|
---|
1927 | {
|
---|
1928 | AutoInitSpan autoInitSpan(this);
|
---|
1929 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
1930 |
|
---|
1931 | /*
|
---|
1932 | * Figure some stuff out before creating the instance data.
|
---|
1933 | */
|
---|
1934 | char szBaseDir[RTPATH_MAX];
|
---|
1935 | int rc = RTPathAppPrivateArchTop(szBaseDir, sizeof(szBaseDir));
|
---|
1936 | AssertLogRelRCReturn(rc, E_FAIL);
|
---|
1937 | rc = RTPathAppend(szBaseDir, sizeof(szBaseDir), VBOX_EXTPACK_INSTALL_DIR);
|
---|
1938 | AssertLogRelRCReturn(rc, E_FAIL);
|
---|
1939 |
|
---|
1940 | char szCertificatDir[RTPATH_MAX];
|
---|
1941 | rc = RTPathAppPrivateNoArch(szCertificatDir, sizeof(szCertificatDir));
|
---|
1942 | AssertLogRelRCReturn(rc, E_FAIL);
|
---|
1943 | rc = RTPathAppend(szCertificatDir, sizeof(szCertificatDir), VBOX_EXTPACK_CERT_DIR);
|
---|
1944 | AssertLogRelRCReturn(rc, E_FAIL);
|
---|
1945 |
|
---|
1946 | /*
|
---|
1947 | * Allocate and initialize the instance data.
|
---|
1948 | */
|
---|
1949 | m = new Data;
|
---|
1950 | m->strBaseDir = szBaseDir;
|
---|
1951 | m->strCertificatDirPath = szCertificatDir;
|
---|
1952 | m->enmContext = a_enmContext;
|
---|
1953 | #ifndef VBOX_COM_INPROC
|
---|
1954 | m->pVirtualBox = a_pVirtualBox;
|
---|
1955 | #else
|
---|
1956 | RT_NOREF_PV(a_pVirtualBox);
|
---|
1957 | #endif
|
---|
1958 |
|
---|
1959 | /*
|
---|
1960 | * Go looking for extensions. The RTDirOpen may fail if nothing has been
|
---|
1961 | * installed yet, or if root is paranoid and has revoked our access to them.
|
---|
1962 | *
|
---|
1963 | * We ASSUME that there are no files, directories or stuff in the directory
|
---|
1964 | * that exceed the max name length in RTDIRENTRYEX.
|
---|
1965 | */
|
---|
1966 | HRESULT hrc = S_OK;
|
---|
1967 | PRTDIR pDir;
|
---|
1968 | int vrc = RTDirOpen(&pDir, szBaseDir);
|
---|
1969 | if (RT_SUCCESS(vrc))
|
---|
1970 | {
|
---|
1971 | for (;;)
|
---|
1972 | {
|
---|
1973 | RTDIRENTRYEX Entry;
|
---|
1974 | vrc = RTDirReadEx(pDir, &Entry, NULL /*pcbDirEntry*/, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
|
---|
1975 | if (RT_FAILURE(vrc))
|
---|
1976 | {
|
---|
1977 | AssertLogRelMsg(vrc == VERR_NO_MORE_FILES, ("%Rrc\n", vrc));
|
---|
1978 | break;
|
---|
1979 | }
|
---|
1980 | if ( RTFS_IS_DIRECTORY(Entry.Info.Attr.fMode)
|
---|
1981 | && strcmp(Entry.szName, ".") != 0
|
---|
1982 | && strcmp(Entry.szName, "..") != 0
|
---|
1983 | && VBoxExtPackIsValidMangledName(Entry.szName) )
|
---|
1984 | {
|
---|
1985 | /*
|
---|
1986 | * All directories are extensions, the shall be nothing but
|
---|
1987 | * extensions in this subdirectory.
|
---|
1988 | */
|
---|
1989 | char szExtPackDir[RTPATH_MAX];
|
---|
1990 | vrc = RTPathJoin(szExtPackDir, sizeof(szExtPackDir), m->strBaseDir.c_str(), Entry.szName);
|
---|
1991 | AssertLogRelRC(vrc);
|
---|
1992 | if (RT_SUCCESS(vrc))
|
---|
1993 | {
|
---|
1994 | RTCString *pstrName = VBoxExtPackUnmangleName(Entry.szName, RTSTR_MAX);
|
---|
1995 | AssertLogRel(pstrName);
|
---|
1996 | if (pstrName)
|
---|
1997 | {
|
---|
1998 | ComObjPtr<ExtPack> NewExtPack;
|
---|
1999 | HRESULT hrc2 = NewExtPack.createObject();
|
---|
2000 | if (SUCCEEDED(hrc2))
|
---|
2001 | hrc2 = NewExtPack->initWithDir(a_enmContext, pstrName->c_str(), szExtPackDir);
|
---|
2002 | delete pstrName;
|
---|
2003 | if (SUCCEEDED(hrc2))
|
---|
2004 | m->llInstalledExtPacks.push_back(NewExtPack);
|
---|
2005 | else if (SUCCEEDED(rc))
|
---|
2006 | hrc = hrc2;
|
---|
2007 | }
|
---|
2008 | else
|
---|
2009 | hrc = E_UNEXPECTED;
|
---|
2010 | }
|
---|
2011 | else
|
---|
2012 | hrc = E_UNEXPECTED;
|
---|
2013 | }
|
---|
2014 | }
|
---|
2015 | RTDirClose(pDir);
|
---|
2016 | }
|
---|
2017 | /* else: ignore, the directory probably does not exist or something. */
|
---|
2018 |
|
---|
2019 | if (SUCCEEDED(hrc))
|
---|
2020 | autoInitSpan.setSucceeded();
|
---|
2021 | return hrc;
|
---|
2022 | }
|
---|
2023 |
|
---|
2024 | /**
|
---|
2025 | * COM cruft.
|
---|
2026 | */
|
---|
2027 | void ExtPackManager::FinalRelease()
|
---|
2028 | {
|
---|
2029 | uninit();
|
---|
2030 | BaseFinalRelease();
|
---|
2031 | }
|
---|
2032 |
|
---|
2033 | /**
|
---|
2034 | * Do the actual cleanup.
|
---|
2035 | */
|
---|
2036 | void ExtPackManager::uninit()
|
---|
2037 | {
|
---|
2038 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
2039 | AutoUninitSpan autoUninitSpan(this);
|
---|
2040 | if (!autoUninitSpan.uninitDone() && m != NULL)
|
---|
2041 | {
|
---|
2042 | delete m;
|
---|
2043 | m = NULL;
|
---|
2044 | }
|
---|
2045 | }
|
---|
2046 |
|
---|
2047 | HRESULT ExtPackManager::getInstalledExtPacks(std::vector<ComPtr<IExtPack> > &aInstalledExtPacks)
|
---|
2048 | {
|
---|
2049 | Assert(m->enmContext == VBOXEXTPACKCTX_PER_USER_DAEMON);
|
---|
2050 |
|
---|
2051 | AutoReadLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2052 |
|
---|
2053 |
|
---|
2054 | SafeIfaceArray<IExtPack> SaExtPacks(m->llInstalledExtPacks);
|
---|
2055 | aInstalledExtPacks.resize(SaExtPacks.size());
|
---|
2056 | for(size_t i = 0; i < SaExtPacks.size(); ++i)
|
---|
2057 | aInstalledExtPacks[i] = SaExtPacks[i];
|
---|
2058 |
|
---|
2059 | return S_OK;
|
---|
2060 | }
|
---|
2061 |
|
---|
2062 | HRESULT ExtPackManager::find(const com::Utf8Str &aName, ComPtr<IExtPack> &aReturnData)
|
---|
2063 | {
|
---|
2064 | HRESULT hrc = S_OK;
|
---|
2065 |
|
---|
2066 | Assert(m->enmContext == VBOXEXTPACKCTX_PER_USER_DAEMON);
|
---|
2067 |
|
---|
2068 | AutoReadLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2069 |
|
---|
2070 | ComPtr<ExtPack> ptrExtPack = i_findExtPack(aName.c_str());
|
---|
2071 | if (!ptrExtPack.isNull())
|
---|
2072 | ptrExtPack.queryInterfaceTo(aReturnData.asOutParam());
|
---|
2073 | else
|
---|
2074 | hrc = VBOX_E_OBJECT_NOT_FOUND;
|
---|
2075 |
|
---|
2076 | return hrc;
|
---|
2077 | }
|
---|
2078 |
|
---|
2079 | HRESULT ExtPackManager::openExtPackFile(const com::Utf8Str &aPath, ComPtr<IExtPackFile> &aFile)
|
---|
2080 | {
|
---|
2081 | AssertReturn(m->enmContext == VBOXEXTPACKCTX_PER_USER_DAEMON, E_UNEXPECTED);
|
---|
2082 |
|
---|
2083 | #ifndef VBOX_COM_INPROC
|
---|
2084 | /* The API can optionally take a ::SHA-256=<hex-digest> attribute at the
|
---|
2085 | end of the file name. This is just a temporary measure for
|
---|
2086 | backporting, in 4.2 we'll add another parameter to the method. */
|
---|
2087 | Utf8Str strTarball;
|
---|
2088 | Utf8Str strDigest;
|
---|
2089 | size_t offSha256 = aPath.find("::SHA-256=");
|
---|
2090 | if (offSha256 == Utf8Str::npos)
|
---|
2091 | strTarball = aPath;
|
---|
2092 | else
|
---|
2093 | {
|
---|
2094 | strTarball = aPath.substr(0, offSha256);
|
---|
2095 | strDigest = aPath.substr(offSha256 + sizeof("::SHA-256=") - 1);
|
---|
2096 | }
|
---|
2097 |
|
---|
2098 | ComObjPtr<ExtPackFile> NewExtPackFile;
|
---|
2099 | HRESULT hrc = NewExtPackFile.createObject();
|
---|
2100 | if (SUCCEEDED(hrc))
|
---|
2101 | hrc = NewExtPackFile->initWithFile(strTarball.c_str(), strDigest.c_str(), this, m->pVirtualBox);
|
---|
2102 | if (SUCCEEDED(hrc))
|
---|
2103 | NewExtPackFile.queryInterfaceTo(aFile.asOutParam());
|
---|
2104 |
|
---|
2105 | return hrc;
|
---|
2106 | #else
|
---|
2107 | RT_NOREF(aPath, aFile);
|
---|
2108 | return E_NOTIMPL;
|
---|
2109 | #endif
|
---|
2110 | }
|
---|
2111 |
|
---|
2112 | HRESULT ExtPackManager::uninstall(const com::Utf8Str &aName, BOOL aForcedRemoval,
|
---|
2113 | const com::Utf8Str &aDisplayInfo, ComPtr<IProgress> &aProgress)
|
---|
2114 | {
|
---|
2115 | Assert(m->enmContext == VBOXEXTPACKCTX_PER_USER_DAEMON);
|
---|
2116 |
|
---|
2117 | #ifndef VBOX_COM_INPROC
|
---|
2118 |
|
---|
2119 | HRESULT hrc;
|
---|
2120 | ExtPackUninstallTask *pTask = NULL;
|
---|
2121 | try
|
---|
2122 | {
|
---|
2123 | pTask = new ExtPackUninstallTask();
|
---|
2124 | hrc = pTask->Init(this, aName, aForcedRemoval != FALSE, aDisplayInfo);
|
---|
2125 | if (SUCCEEDED(hrc))
|
---|
2126 | {
|
---|
2127 | ComPtr<Progress> ptrProgress = pTask->ptrProgress;
|
---|
2128 | hrc = pTask->createThreadWithType(RTTHREADTYPE_DEFAULT);
|
---|
2129 | pTask = NULL; /* always consumed by createThread */
|
---|
2130 | if (SUCCEEDED(hrc))
|
---|
2131 | hrc = ptrProgress.queryInterfaceTo(aProgress.asOutParam());
|
---|
2132 | else
|
---|
2133 | hrc = setError(VBOX_E_IPRT_ERROR,
|
---|
2134 | tr("Starting thread for an extension pack uninstallation failed with %Rrc"), hrc);
|
---|
2135 | }
|
---|
2136 | else
|
---|
2137 | hrc = setError(VBOX_E_IPRT_ERROR,
|
---|
2138 | tr("Looks like creating a progress object for ExtraPackUninstallTask object failed"));
|
---|
2139 | }
|
---|
2140 | catch (std::bad_alloc &)
|
---|
2141 | {
|
---|
2142 | hrc = E_OUTOFMEMORY;
|
---|
2143 | }
|
---|
2144 | catch (HRESULT hrcXcpt)
|
---|
2145 | {
|
---|
2146 | LogFlowThisFunc(("Exception was caught in the function ExtPackManager::uninstall()\n"));
|
---|
2147 | hrc = hrcXcpt;
|
---|
2148 | }
|
---|
2149 | if (pTask)
|
---|
2150 | delete pTask;
|
---|
2151 | return hrc;
|
---|
2152 | #else
|
---|
2153 | RT_NOREF(aName, aForcedRemoval, aDisplayInfo, aProgress);
|
---|
2154 | return E_NOTIMPL;
|
---|
2155 | #endif
|
---|
2156 | }
|
---|
2157 |
|
---|
2158 | HRESULT ExtPackManager::cleanup(void)
|
---|
2159 | {
|
---|
2160 | Assert(m->enmContext == VBOXEXTPACKCTX_PER_USER_DAEMON);
|
---|
2161 |
|
---|
2162 | AutoCaller autoCaller(this);
|
---|
2163 | HRESULT hrc = autoCaller.rc();
|
---|
2164 | if (SUCCEEDED(hrc))
|
---|
2165 | {
|
---|
2166 | /*
|
---|
2167 | * Run the set-uid-to-root binary that performs the cleanup.
|
---|
2168 | *
|
---|
2169 | * Take the write lock to prevent conflicts with other calls to this
|
---|
2170 | * VBoxSVC instance.
|
---|
2171 | */
|
---|
2172 | AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2173 | hrc = i_runSetUidToRootHelper(NULL,
|
---|
2174 | "cleanup",
|
---|
2175 | "--base-dir", m->strBaseDir.c_str(),
|
---|
2176 | (const char *)NULL);
|
---|
2177 | }
|
---|
2178 |
|
---|
2179 | return hrc;
|
---|
2180 | }
|
---|
2181 |
|
---|
2182 | HRESULT ExtPackManager::queryAllPlugInsForFrontend(const com::Utf8Str &aFrontendName, std::vector<com::Utf8Str> &aPlugInModules)
|
---|
2183 | {
|
---|
2184 | NOREF(aFrontendName);
|
---|
2185 | aPlugInModules.resize(0);
|
---|
2186 | return S_OK;
|
---|
2187 | }
|
---|
2188 |
|
---|
2189 | HRESULT ExtPackManager::isExtPackUsable(const com::Utf8Str &aName, BOOL *aUsable)
|
---|
2190 | {
|
---|
2191 | *aUsable = i_isExtPackUsable(aName.c_str());
|
---|
2192 | return S_OK;
|
---|
2193 | }
|
---|
2194 |
|
---|
2195 | /**
|
---|
2196 | * Finds the success indicator string in the stderr output ofr hte helper app.
|
---|
2197 | *
|
---|
2198 | * @returns Pointer to the indicator.
|
---|
2199 | * @param psz The stderr output string. Can be NULL.
|
---|
2200 | * @param cch The size of the string.
|
---|
2201 | */
|
---|
2202 | static char *findSuccessIndicator(char *psz, size_t cch)
|
---|
2203 | {
|
---|
2204 | static const char s_szSuccessInd[] = "rcExit=RTEXITCODE_SUCCESS";
|
---|
2205 | Assert(!cch || strlen(psz) == cch);
|
---|
2206 | if (cch < sizeof(s_szSuccessInd) - 1)
|
---|
2207 | return NULL;
|
---|
2208 | char *pszInd = &psz[cch - sizeof(s_szSuccessInd) + 1];
|
---|
2209 | if (strcmp(s_szSuccessInd, pszInd))
|
---|
2210 | return NULL;
|
---|
2211 | return pszInd;
|
---|
2212 | }
|
---|
2213 |
|
---|
2214 | /**
|
---|
2215 | * Runs the helper application that does the privileged operations.
|
---|
2216 | *
|
---|
2217 | * @returns S_OK or a failure status with error information set.
|
---|
2218 | * @param a_pstrDisplayInfo Platform specific display info hacks.
|
---|
2219 | * @param a_pszCommand The command to execute.
|
---|
2220 | * @param ... The argument strings that goes along with the
|
---|
2221 | * command. Maximum is about 16. Terminated by a
|
---|
2222 | * NULL.
|
---|
2223 | */
|
---|
2224 | HRESULT ExtPackManager::i_runSetUidToRootHelper(Utf8Str const *a_pstrDisplayInfo, const char *a_pszCommand, ...)
|
---|
2225 | {
|
---|
2226 | /*
|
---|
2227 | * Calculate the path to the helper application.
|
---|
2228 | */
|
---|
2229 | char szExecName[RTPATH_MAX];
|
---|
2230 | int vrc = RTPathAppPrivateArch(szExecName, sizeof(szExecName));
|
---|
2231 | AssertLogRelRCReturn(vrc, E_UNEXPECTED);
|
---|
2232 |
|
---|
2233 | vrc = RTPathAppend(szExecName, sizeof(szExecName), VBOX_EXTPACK_HELPER_NAME);
|
---|
2234 | AssertLogRelRCReturn(vrc, E_UNEXPECTED);
|
---|
2235 |
|
---|
2236 | /*
|
---|
2237 | * Convert the variable argument list to a RTProcCreate argument vector.
|
---|
2238 | */
|
---|
2239 | const char *apszArgs[20];
|
---|
2240 | unsigned cArgs = 0;
|
---|
2241 |
|
---|
2242 | LogRel(("ExtPack: Executing '%s'", szExecName));
|
---|
2243 | apszArgs[cArgs++] = &szExecName[0];
|
---|
2244 |
|
---|
2245 | if ( a_pstrDisplayInfo
|
---|
2246 | && a_pstrDisplayInfo->isNotEmpty())
|
---|
2247 | {
|
---|
2248 | LogRel((" '--display-info-hack' '%s'", a_pstrDisplayInfo->c_str()));
|
---|
2249 | apszArgs[cArgs++] = "--display-info-hack";
|
---|
2250 | apszArgs[cArgs++] = a_pstrDisplayInfo->c_str();
|
---|
2251 | }
|
---|
2252 |
|
---|
2253 | LogRel(("'%s'", a_pszCommand));
|
---|
2254 | apszArgs[cArgs++] = a_pszCommand;
|
---|
2255 |
|
---|
2256 | va_list va;
|
---|
2257 | va_start(va, a_pszCommand);
|
---|
2258 | const char *pszLastArg;
|
---|
2259 | for (;;)
|
---|
2260 | {
|
---|
2261 | AssertReturn(cArgs < RT_ELEMENTS(apszArgs) - 1, E_UNEXPECTED);
|
---|
2262 | pszLastArg = va_arg(va, const char *);
|
---|
2263 | if (!pszLastArg)
|
---|
2264 | break;
|
---|
2265 | LogRel((" '%s'", pszLastArg));
|
---|
2266 | apszArgs[cArgs++] = pszLastArg;
|
---|
2267 | };
|
---|
2268 | va_end(va);
|
---|
2269 |
|
---|
2270 | LogRel(("\n"));
|
---|
2271 | apszArgs[cArgs] = NULL;
|
---|
2272 |
|
---|
2273 | /*
|
---|
2274 | * Create a PIPE which we attach to stderr so that we can read the error
|
---|
2275 | * message on failure and report it back to the caller.
|
---|
2276 | */
|
---|
2277 | RTPIPE hPipeR;
|
---|
2278 | RTHANDLE hStdErrPipe;
|
---|
2279 | hStdErrPipe.enmType = RTHANDLETYPE_PIPE;
|
---|
2280 | vrc = RTPipeCreate(&hPipeR, &hStdErrPipe.u.hPipe, RTPIPE_C_INHERIT_WRITE);
|
---|
2281 | AssertLogRelRCReturn(vrc, E_UNEXPECTED);
|
---|
2282 |
|
---|
2283 | /*
|
---|
2284 | * Spawn the process.
|
---|
2285 | */
|
---|
2286 | HRESULT hrc;
|
---|
2287 | RTPROCESS hProcess;
|
---|
2288 | vrc = RTProcCreateEx(szExecName,
|
---|
2289 | apszArgs,
|
---|
2290 | RTENV_DEFAULT,
|
---|
2291 | 0 /*fFlags*/,
|
---|
2292 | NULL /*phStdIn*/,
|
---|
2293 | NULL /*phStdOut*/,
|
---|
2294 | &hStdErrPipe,
|
---|
2295 | NULL /*pszAsUser*/,
|
---|
2296 | NULL /*pszPassword*/,
|
---|
2297 | &hProcess);
|
---|
2298 | if (RT_SUCCESS(vrc))
|
---|
2299 | {
|
---|
2300 | vrc = RTPipeClose(hStdErrPipe.u.hPipe);
|
---|
2301 | hStdErrPipe.u.hPipe = NIL_RTPIPE;
|
---|
2302 |
|
---|
2303 | /*
|
---|
2304 | * Read the pipe output until the process completes.
|
---|
2305 | */
|
---|
2306 | RTPROCSTATUS ProcStatus = { -42, RTPROCEXITREASON_ABEND };
|
---|
2307 | size_t cbStdErrBuf = 0;
|
---|
2308 | size_t offStdErrBuf = 0;
|
---|
2309 | char *pszStdErrBuf = NULL;
|
---|
2310 | do
|
---|
2311 | {
|
---|
2312 | /*
|
---|
2313 | * Service the pipe. Block waiting for output or the pipe breaking
|
---|
2314 | * when the process terminates.
|
---|
2315 | */
|
---|
2316 | if (hPipeR != NIL_RTPIPE)
|
---|
2317 | {
|
---|
2318 | char achBuf[1024];
|
---|
2319 | size_t cbRead;
|
---|
2320 | vrc = RTPipeReadBlocking(hPipeR, achBuf, sizeof(achBuf), &cbRead);
|
---|
2321 | if (RT_SUCCESS(vrc))
|
---|
2322 | {
|
---|
2323 | /* grow the buffer? */
|
---|
2324 | size_t cbBufReq = offStdErrBuf + cbRead + 1;
|
---|
2325 | if ( cbBufReq > cbStdErrBuf
|
---|
2326 | && cbBufReq < _256K)
|
---|
2327 | {
|
---|
2328 | size_t cbNew = RT_ALIGN_Z(cbBufReq, 16); // 1024
|
---|
2329 | void *pvNew = RTMemRealloc(pszStdErrBuf, cbNew);
|
---|
2330 | if (pvNew)
|
---|
2331 | {
|
---|
2332 | pszStdErrBuf = (char *)pvNew;
|
---|
2333 | cbStdErrBuf = cbNew;
|
---|
2334 | }
|
---|
2335 | }
|
---|
2336 |
|
---|
2337 | /* append if we've got room. */
|
---|
2338 | if (cbBufReq <= cbStdErrBuf)
|
---|
2339 | {
|
---|
2340 | memcpy(&pszStdErrBuf[offStdErrBuf], achBuf, cbRead);
|
---|
2341 | offStdErrBuf = offStdErrBuf + cbRead;
|
---|
2342 | pszStdErrBuf[offStdErrBuf] = '\0';
|
---|
2343 | }
|
---|
2344 | }
|
---|
2345 | else
|
---|
2346 | {
|
---|
2347 | AssertLogRelMsg(vrc == VERR_BROKEN_PIPE, ("%Rrc\n", vrc));
|
---|
2348 | RTPipeClose(hPipeR);
|
---|
2349 | hPipeR = NIL_RTPIPE;
|
---|
2350 | }
|
---|
2351 | }
|
---|
2352 |
|
---|
2353 | /*
|
---|
2354 | * Service the process. Block if we have no pipe.
|
---|
2355 | */
|
---|
2356 | if (hProcess != NIL_RTPROCESS)
|
---|
2357 | {
|
---|
2358 | vrc = RTProcWait(hProcess,
|
---|
2359 | hPipeR == NIL_RTPIPE ? RTPROCWAIT_FLAGS_BLOCK : RTPROCWAIT_FLAGS_NOBLOCK,
|
---|
2360 | &ProcStatus);
|
---|
2361 | if (RT_SUCCESS(vrc))
|
---|
2362 | hProcess = NIL_RTPROCESS;
|
---|
2363 | else
|
---|
2364 | AssertLogRelMsgStmt(vrc == VERR_PROCESS_RUNNING, ("%Rrc\n", vrc), hProcess = NIL_RTPROCESS);
|
---|
2365 | }
|
---|
2366 | } while ( hPipeR != NIL_RTPIPE
|
---|
2367 | || hProcess != NIL_RTPROCESS);
|
---|
2368 |
|
---|
2369 | LogRel(("ExtPack: enmReason=%d iStatus=%d stderr='%s'\n",
|
---|
2370 | ProcStatus.enmReason, ProcStatus.iStatus, offStdErrBuf ? pszStdErrBuf : ""));
|
---|
2371 |
|
---|
2372 | /*
|
---|
2373 | * Look for rcExit=RTEXITCODE_SUCCESS at the end of the error output,
|
---|
2374 | * cut it as it is only there to attest the success.
|
---|
2375 | */
|
---|
2376 | if (offStdErrBuf > 0)
|
---|
2377 | {
|
---|
2378 | RTStrStripR(pszStdErrBuf);
|
---|
2379 | offStdErrBuf = strlen(pszStdErrBuf);
|
---|
2380 | }
|
---|
2381 |
|
---|
2382 | char *pszSuccessInd = findSuccessIndicator(pszStdErrBuf, offStdErrBuf);
|
---|
2383 | if (pszSuccessInd)
|
---|
2384 | {
|
---|
2385 | *pszSuccessInd = '\0';
|
---|
2386 | offStdErrBuf = pszSuccessInd - pszStdErrBuf;
|
---|
2387 | }
|
---|
2388 | else if ( ProcStatus.enmReason == RTPROCEXITREASON_NORMAL
|
---|
2389 | && ProcStatus.iStatus == 0)
|
---|
2390 | ProcStatus.iStatus = offStdErrBuf ? 667 : 666;
|
---|
2391 |
|
---|
2392 | /*
|
---|
2393 | * Compose the status code and, on failure, error message.
|
---|
2394 | */
|
---|
2395 | if ( ProcStatus.enmReason == RTPROCEXITREASON_NORMAL
|
---|
2396 | && ProcStatus.iStatus == 0)
|
---|
2397 | hrc = S_OK;
|
---|
2398 | else if (ProcStatus.enmReason == RTPROCEXITREASON_NORMAL)
|
---|
2399 | {
|
---|
2400 | AssertMsg(ProcStatus.iStatus != 0, ("%s\n", pszStdErrBuf));
|
---|
2401 | hrc = setError(E_FAIL, tr("The installer failed with exit code %d: %s"),
|
---|
2402 | ProcStatus.iStatus, offStdErrBuf ? pszStdErrBuf : "");
|
---|
2403 | }
|
---|
2404 | else if (ProcStatus.enmReason == RTPROCEXITREASON_SIGNAL)
|
---|
2405 | hrc = setError(E_UNEXPECTED, tr("The installer was killed by signal #d (stderr: %s)"),
|
---|
2406 | ProcStatus.iStatus, offStdErrBuf ? pszStdErrBuf : "");
|
---|
2407 | else if (ProcStatus.enmReason == RTPROCEXITREASON_ABEND)
|
---|
2408 | hrc = setError(E_UNEXPECTED, tr("The installer aborted abnormally (stderr: %s)"),
|
---|
2409 | offStdErrBuf ? pszStdErrBuf : "");
|
---|
2410 | else
|
---|
2411 | hrc = setError(E_UNEXPECTED, tr("internal error: enmReason=%d iStatus=%d stderr='%s'"),
|
---|
2412 | ProcStatus.enmReason, ProcStatus.iStatus, offStdErrBuf ? pszStdErrBuf : "");
|
---|
2413 |
|
---|
2414 | RTMemFree(pszStdErrBuf);
|
---|
2415 | }
|
---|
2416 | else
|
---|
2417 | hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to launch the helper application '%s' (%Rrc)"), szExecName, vrc);
|
---|
2418 |
|
---|
2419 | RTPipeClose(hPipeR);
|
---|
2420 | RTPipeClose(hStdErrPipe.u.hPipe);
|
---|
2421 |
|
---|
2422 | return hrc;
|
---|
2423 | }
|
---|
2424 |
|
---|
2425 | /**
|
---|
2426 | * Finds an installed extension pack.
|
---|
2427 | *
|
---|
2428 | * @returns Pointer to the extension pack if found, NULL if not. (No reference
|
---|
2429 | * counting problem here since the caller must be holding the lock.)
|
---|
2430 | * @param a_pszName The name of the extension pack.
|
---|
2431 | */
|
---|
2432 | ExtPack *ExtPackManager::i_findExtPack(const char *a_pszName)
|
---|
2433 | {
|
---|
2434 | size_t cchName = strlen(a_pszName);
|
---|
2435 |
|
---|
2436 | for (ExtPackList::iterator it = m->llInstalledExtPacks.begin();
|
---|
2437 | it != m->llInstalledExtPacks.end();
|
---|
2438 | ++it)
|
---|
2439 | {
|
---|
2440 | ExtPack::Data *pExtPackData = (*it)->m;
|
---|
2441 | if ( pExtPackData
|
---|
2442 | && pExtPackData->Desc.strName.length() == cchName
|
---|
2443 | && pExtPackData->Desc.strName.equalsIgnoreCase(a_pszName))
|
---|
2444 | return (*it);
|
---|
2445 | }
|
---|
2446 | return NULL;
|
---|
2447 | }
|
---|
2448 |
|
---|
2449 | /**
|
---|
2450 | * Removes an installed extension pack from the internal list.
|
---|
2451 | *
|
---|
2452 | * The package is expected to exist!
|
---|
2453 | *
|
---|
2454 | * @param a_pszName The name of the extension pack.
|
---|
2455 | */
|
---|
2456 | void ExtPackManager::i_removeExtPack(const char *a_pszName)
|
---|
2457 | {
|
---|
2458 | size_t cchName = strlen(a_pszName);
|
---|
2459 |
|
---|
2460 | for (ExtPackList::iterator it = m->llInstalledExtPacks.begin();
|
---|
2461 | it != m->llInstalledExtPacks.end();
|
---|
2462 | ++it)
|
---|
2463 | {
|
---|
2464 | ExtPack::Data *pExtPackData = (*it)->m;
|
---|
2465 | if ( pExtPackData
|
---|
2466 | && pExtPackData->Desc.strName.length() == cchName
|
---|
2467 | && pExtPackData->Desc.strName.equalsIgnoreCase(a_pszName))
|
---|
2468 | {
|
---|
2469 | m->llInstalledExtPacks.erase(it);
|
---|
2470 | return;
|
---|
2471 | }
|
---|
2472 | }
|
---|
2473 | AssertMsgFailed(("%s\n", a_pszName));
|
---|
2474 | }
|
---|
2475 |
|
---|
2476 | #ifndef VBOX_COM_INPROC
|
---|
2477 |
|
---|
2478 | /**
|
---|
2479 | * Refreshes the specified extension pack.
|
---|
2480 | *
|
---|
2481 | * This may remove the extension pack from the list, so any non-smart pointers
|
---|
2482 | * to the extension pack object may become invalid.
|
---|
2483 | *
|
---|
2484 | * @returns S_OK and *a_ppExtPack on success, COM status code and error
|
---|
2485 | * message on failure. Note that *a_ppExtPack can be NULL.
|
---|
2486 | *
|
---|
2487 | * @param a_pszName The extension to update..
|
---|
2488 | * @param a_fUnusableIsError If @c true, report an unusable extension pack
|
---|
2489 | * as an error.
|
---|
2490 | * @param a_ppExtPack Where to store the pointer to the extension
|
---|
2491 | * pack of it is still around after the refresh.
|
---|
2492 | * This is optional.
|
---|
2493 | *
|
---|
2494 | * @remarks Caller holds the extension manager lock.
|
---|
2495 | * @remarks Only called in VBoxSVC.
|
---|
2496 | */
|
---|
2497 | HRESULT ExtPackManager::i_refreshExtPack(const char *a_pszName, bool a_fUnusableIsError, ExtPack **a_ppExtPack)
|
---|
2498 | {
|
---|
2499 | Assert(m->pVirtualBox != NULL); /* Only called from VBoxSVC. */
|
---|
2500 |
|
---|
2501 | HRESULT hrc;
|
---|
2502 | ExtPack *pExtPack = i_findExtPack(a_pszName);
|
---|
2503 | if (pExtPack)
|
---|
2504 | {
|
---|
2505 | /*
|
---|
2506 | * Refresh existing object.
|
---|
2507 | */
|
---|
2508 | bool fCanDelete;
|
---|
2509 | hrc = pExtPack->i_refresh(&fCanDelete);
|
---|
2510 | if (SUCCEEDED(hrc))
|
---|
2511 | {
|
---|
2512 | if (fCanDelete)
|
---|
2513 | {
|
---|
2514 | i_removeExtPack(a_pszName);
|
---|
2515 | pExtPack = NULL;
|
---|
2516 | }
|
---|
2517 | }
|
---|
2518 | }
|
---|
2519 | else
|
---|
2520 | {
|
---|
2521 | /*
|
---|
2522 | * Do this check here, otherwise VBoxExtPackCalcDir() will fail with a strange
|
---|
2523 | * error.
|
---|
2524 | */
|
---|
2525 | bool fValid = VBoxExtPackIsValidName(a_pszName);
|
---|
2526 | if (!fValid)
|
---|
2527 | return setError(E_FAIL, "Invalid extension pack name specified");
|
---|
2528 |
|
---|
2529 | /*
|
---|
2530 | * Does the dir exist? Make some special effort to deal with case
|
---|
2531 | * sensitivie file systems (a_pszName is case insensitive and mangled).
|
---|
2532 | */
|
---|
2533 | char szDir[RTPATH_MAX];
|
---|
2534 | int vrc = VBoxExtPackCalcDir(szDir, sizeof(szDir), m->strBaseDir.c_str(), a_pszName);
|
---|
2535 | AssertLogRelRCReturn(vrc, E_FAIL);
|
---|
2536 |
|
---|
2537 | RTDIRENTRYEX Entry;
|
---|
2538 | RTFSOBJINFO ObjInfo;
|
---|
2539 | vrc = RTPathQueryInfoEx(szDir, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
|
---|
2540 | bool fExists = RT_SUCCESS(vrc) && RTFS_IS_DIRECTORY(ObjInfo.Attr.fMode);
|
---|
2541 | if (!fExists)
|
---|
2542 | {
|
---|
2543 | PRTDIR pDir;
|
---|
2544 | vrc = RTDirOpen(&pDir, m->strBaseDir.c_str());
|
---|
2545 | if (RT_SUCCESS(vrc))
|
---|
2546 | {
|
---|
2547 | const char *pszMangledName = RTPathFilename(szDir);
|
---|
2548 | for (;;)
|
---|
2549 | {
|
---|
2550 | vrc = RTDirReadEx(pDir, &Entry, NULL /*pcbDirEntry*/, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
|
---|
2551 | if (RT_FAILURE(vrc))
|
---|
2552 | {
|
---|
2553 | AssertLogRelMsg(vrc == VERR_NO_MORE_FILES, ("%Rrc\n", vrc));
|
---|
2554 | break;
|
---|
2555 | }
|
---|
2556 | if ( RTFS_IS_DIRECTORY(Entry.Info.Attr.fMode)
|
---|
2557 | && !RTStrICmp(Entry.szName, pszMangledName))
|
---|
2558 | {
|
---|
2559 | /*
|
---|
2560 | * The installed extension pack has a uses different case.
|
---|
2561 | * Update the name and directory variables.
|
---|
2562 | */
|
---|
2563 | vrc = RTPathJoin(szDir, sizeof(szDir), m->strBaseDir.c_str(), Entry.szName); /* not really necessary */
|
---|
2564 | AssertLogRelRCReturnStmt(vrc, RTDirClose(pDir), E_UNEXPECTED);
|
---|
2565 | a_pszName = Entry.szName;
|
---|
2566 | fExists = true;
|
---|
2567 | break;
|
---|
2568 | }
|
---|
2569 | }
|
---|
2570 | RTDirClose(pDir);
|
---|
2571 | }
|
---|
2572 | }
|
---|
2573 | if (fExists)
|
---|
2574 | {
|
---|
2575 | /*
|
---|
2576 | * We've got something, create a new extension pack object for it.
|
---|
2577 | */
|
---|
2578 | ComObjPtr<ExtPack> ptrNewExtPack;
|
---|
2579 | hrc = ptrNewExtPack.createObject();
|
---|
2580 | if (SUCCEEDED(hrc))
|
---|
2581 | hrc = ptrNewExtPack->initWithDir(m->enmContext, a_pszName, szDir);
|
---|
2582 | if (SUCCEEDED(hrc))
|
---|
2583 | {
|
---|
2584 | m->llInstalledExtPacks.push_back(ptrNewExtPack);
|
---|
2585 | if (ptrNewExtPack->m->fUsable)
|
---|
2586 | LogRel(("ExtPackManager: Found extension pack '%s'.\n", a_pszName));
|
---|
2587 | else
|
---|
2588 | LogRel(("ExtPackManager: Found bad extension pack '%s': %s\n",
|
---|
2589 | a_pszName, ptrNewExtPack->m->strWhyUnusable.c_str() ));
|
---|
2590 | pExtPack = ptrNewExtPack;
|
---|
2591 | }
|
---|
2592 | }
|
---|
2593 | else
|
---|
2594 | hrc = S_OK;
|
---|
2595 | }
|
---|
2596 |
|
---|
2597 | /*
|
---|
2598 | * Report error if not usable, if that is desired.
|
---|
2599 | */
|
---|
2600 | if ( SUCCEEDED(hrc)
|
---|
2601 | && pExtPack
|
---|
2602 | && a_fUnusableIsError
|
---|
2603 | && !pExtPack->m->fUsable)
|
---|
2604 | hrc = setError(E_FAIL, "%s", pExtPack->m->strWhyUnusable.c_str());
|
---|
2605 |
|
---|
2606 | if (a_ppExtPack)
|
---|
2607 | *a_ppExtPack = pExtPack;
|
---|
2608 | return hrc;
|
---|
2609 | }
|
---|
2610 |
|
---|
2611 | /**
|
---|
2612 | * Checks if there are any running VMs.
|
---|
2613 | *
|
---|
2614 | * This is called when uninstalling or replacing an extension pack.
|
---|
2615 | *
|
---|
2616 | * @returns true / false
|
---|
2617 | */
|
---|
2618 | bool ExtPackManager::i_areThereAnyRunningVMs(void) const
|
---|
2619 | {
|
---|
2620 | Assert(m->pVirtualBox != NULL); /* Only called from VBoxSVC. */
|
---|
2621 |
|
---|
2622 | /*
|
---|
2623 | * Get list of machines and their states.
|
---|
2624 | */
|
---|
2625 | com::SafeIfaceArray<IMachine> SaMachines;
|
---|
2626 | HRESULT hrc = m->pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(SaMachines));
|
---|
2627 | if (SUCCEEDED(hrc))
|
---|
2628 | {
|
---|
2629 | com::SafeArray<MachineState_T> SaStates;
|
---|
2630 | hrc = m->pVirtualBox->GetMachineStates(ComSafeArrayAsInParam(SaMachines), ComSafeArrayAsOutParam(SaStates));
|
---|
2631 | if (SUCCEEDED(hrc))
|
---|
2632 | {
|
---|
2633 | /*
|
---|
2634 | * Scan the two parallel arrays for machines in the running state.
|
---|
2635 | */
|
---|
2636 | Assert(SaStates.size() == SaMachines.size());
|
---|
2637 | for (size_t i = 0; i < SaMachines.size(); ++i)
|
---|
2638 | if (SaMachines[i] && Global::IsOnline(SaStates[i]))
|
---|
2639 | return true;
|
---|
2640 | }
|
---|
2641 | }
|
---|
2642 | return false;
|
---|
2643 | }
|
---|
2644 |
|
---|
2645 | /**
|
---|
2646 | * Worker for IExtPackFile::Install.
|
---|
2647 | *
|
---|
2648 | * Called on a worker thread via doInstallThreadProc.
|
---|
2649 | *
|
---|
2650 | * @returns COM status code.
|
---|
2651 | * @param a_pExtPackFile The extension pack file, caller checks that
|
---|
2652 | * it's usable.
|
---|
2653 | * @param a_fReplace Whether to replace any existing extpack or just
|
---|
2654 | * fail.
|
---|
2655 | * @param a_pstrDisplayInfo Host specific display information hacks.
|
---|
2656 | * be NULL.
|
---|
2657 | */
|
---|
2658 | HRESULT ExtPackManager::i_doInstall(ExtPackFile *a_pExtPackFile, bool a_fReplace, Utf8Str const *a_pstrDisplayInfo)
|
---|
2659 | {
|
---|
2660 | AssertReturn(m->enmContext == VBOXEXTPACKCTX_PER_USER_DAEMON, E_UNEXPECTED);
|
---|
2661 | RTCString const * const pStrName = &a_pExtPackFile->m->Desc.strName;
|
---|
2662 | RTCString const * const pStrTarball = &a_pExtPackFile->m->strExtPackFile;
|
---|
2663 | RTCString const * const pStrTarballDigest = &a_pExtPackFile->m->strDigest;
|
---|
2664 |
|
---|
2665 | AutoCaller autoCaller(this);
|
---|
2666 | HRESULT hrc = autoCaller.rc();
|
---|
2667 | if (SUCCEEDED(hrc))
|
---|
2668 | {
|
---|
2669 | AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2670 |
|
---|
2671 | /*
|
---|
2672 | * Refresh the data we have on the extension pack as it
|
---|
2673 | * may be made stale by direct meddling or some other user.
|
---|
2674 | */
|
---|
2675 | ExtPack *pExtPack;
|
---|
2676 | hrc = i_refreshExtPack(pStrName->c_str(), false /*a_fUnusableIsError*/, &pExtPack);
|
---|
2677 | if (SUCCEEDED(hrc))
|
---|
2678 | {
|
---|
2679 | if (pExtPack && a_fReplace)
|
---|
2680 | {
|
---|
2681 | /* We must leave the lock when calling i_areThereAnyRunningVMs,
|
---|
2682 | which means we have to redo the refresh call afterwards. */
|
---|
2683 | autoLock.release();
|
---|
2684 | bool fRunningVMs = i_areThereAnyRunningVMs();
|
---|
2685 | autoLock.acquire();
|
---|
2686 | hrc = i_refreshExtPack(pStrName->c_str(), false /*a_fUnusableIsError*/, &pExtPack);
|
---|
2687 | if (fRunningVMs)
|
---|
2688 | {
|
---|
2689 | LogRel(("Install extension pack '%s' failed because at least one VM is still running.", pStrName->c_str()));
|
---|
2690 | hrc = setError(E_FAIL, tr("Install extension pack '%s' failed because at least one VM is still running"),
|
---|
2691 | pStrName->c_str());
|
---|
2692 | }
|
---|
2693 | else if (SUCCEEDED(hrc) && pExtPack)
|
---|
2694 | hrc = pExtPack->i_callUninstallHookAndClose(m->pVirtualBox, false /*a_ForcedRemoval*/);
|
---|
2695 | }
|
---|
2696 | else if (pExtPack)
|
---|
2697 | hrc = setError(E_FAIL,
|
---|
2698 | tr("Extension pack '%s' is already installed."
|
---|
2699 | " In case of a reinstallation, please uninstall it first"),
|
---|
2700 | pStrName->c_str());
|
---|
2701 | }
|
---|
2702 | if (SUCCEEDED(hrc))
|
---|
2703 | {
|
---|
2704 | /*
|
---|
2705 | * Run the privileged helper binary that performs the actual
|
---|
2706 | * installation. Then create an object for the packet (we do this
|
---|
2707 | * even on failure, to be on the safe side).
|
---|
2708 | */
|
---|
2709 | hrc = i_runSetUidToRootHelper(a_pstrDisplayInfo,
|
---|
2710 | "install",
|
---|
2711 | "--base-dir", m->strBaseDir.c_str(),
|
---|
2712 | "--cert-dir", m->strCertificatDirPath.c_str(),
|
---|
2713 | "--name", pStrName->c_str(),
|
---|
2714 | "--tarball", pStrTarball->c_str(),
|
---|
2715 | "--sha-256", pStrTarballDigest->c_str(),
|
---|
2716 | pExtPack ? "--replace" : (const char *)NULL,
|
---|
2717 | (const char *)NULL);
|
---|
2718 | if (SUCCEEDED(hrc))
|
---|
2719 | {
|
---|
2720 | hrc = i_refreshExtPack(pStrName->c_str(), true /*a_fUnusableIsError*/, &pExtPack);
|
---|
2721 | if (SUCCEEDED(hrc) && pExtPack)
|
---|
2722 | {
|
---|
2723 | RTERRINFOSTATIC ErrInfo;
|
---|
2724 | RTErrInfoInitStatic(&ErrInfo);
|
---|
2725 | pExtPack->i_callInstalledHook(m->pVirtualBox, &autoLock, &ErrInfo.Core);
|
---|
2726 | if (RT_SUCCESS(ErrInfo.Core.rc))
|
---|
2727 | LogRel(("ExtPackManager: Successfully installed extension pack '%s'.\n", pStrName->c_str()));
|
---|
2728 | else
|
---|
2729 | {
|
---|
2730 | LogRel(("ExtPackManager: Installed hook for '%s' failed: %Rrc - %s\n",
|
---|
2731 | pStrName->c_str(), ErrInfo.Core.rc, ErrInfo.Core.pszMsg));
|
---|
2732 |
|
---|
2733 | /*
|
---|
2734 | * Uninstall the extpack if the error indicates that.
|
---|
2735 | */
|
---|
2736 | if (ErrInfo.Core.rc == VERR_EXTPACK_UNSUPPORTED_HOST_UNINSTALL)
|
---|
2737 | i_runSetUidToRootHelper(a_pstrDisplayInfo,
|
---|
2738 | "uninstall",
|
---|
2739 | "--base-dir", m->strBaseDir.c_str(),
|
---|
2740 | "--name", pStrName->c_str(),
|
---|
2741 | "--forced",
|
---|
2742 | (const char *)NULL);
|
---|
2743 | hrc = setError(E_FAIL, tr("The installation hook failed: %Rrc - %s"),
|
---|
2744 | ErrInfo.Core.rc, ErrInfo.Core.pszMsg);
|
---|
2745 | }
|
---|
2746 | }
|
---|
2747 | else if (SUCCEEDED(hrc))
|
---|
2748 | hrc = setError(E_FAIL, tr("Installing extension pack '%s' failed under mysterious circumstances"),
|
---|
2749 | pStrName->c_str());
|
---|
2750 | }
|
---|
2751 | else
|
---|
2752 | {
|
---|
2753 | ErrorInfoKeeper Eik;
|
---|
2754 | i_refreshExtPack(pStrName->c_str(), false /*a_fUnusableIsError*/, NULL);
|
---|
2755 | }
|
---|
2756 | }
|
---|
2757 |
|
---|
2758 | /*
|
---|
2759 | * Do VirtualBoxReady callbacks now for any freshly installed
|
---|
2760 | * extension pack (old ones will not be called).
|
---|
2761 | */
|
---|
2762 | if (m->enmContext == VBOXEXTPACKCTX_PER_USER_DAEMON)
|
---|
2763 | {
|
---|
2764 | autoLock.release();
|
---|
2765 | i_callAllVirtualBoxReadyHooks();
|
---|
2766 | }
|
---|
2767 | }
|
---|
2768 |
|
---|
2769 | return hrc;
|
---|
2770 | }
|
---|
2771 |
|
---|
2772 | /**
|
---|
2773 | * Worker for IExtPackManager::Uninstall.
|
---|
2774 | *
|
---|
2775 | * Called on a worker thread via doUninstallThreadProc.
|
---|
2776 | *
|
---|
2777 | * @returns COM status code.
|
---|
2778 | * @param a_pstrName The name of the extension pack to uninstall.
|
---|
2779 | * @param a_fForcedRemoval Whether to be skip and ignore certain bits of
|
---|
2780 | * the extpack feedback. To deal with misbehaving
|
---|
2781 | * extension pack hooks.
|
---|
2782 | * @param a_pstrDisplayInfo Host specific display information hacks.
|
---|
2783 | */
|
---|
2784 | HRESULT ExtPackManager::i_doUninstall(Utf8Str const *a_pstrName, bool a_fForcedRemoval, Utf8Str const *a_pstrDisplayInfo)
|
---|
2785 | {
|
---|
2786 | Assert(m->enmContext == VBOXEXTPACKCTX_PER_USER_DAEMON);
|
---|
2787 |
|
---|
2788 | AutoCaller autoCaller(this);
|
---|
2789 | HRESULT hrc = autoCaller.rc();
|
---|
2790 | if (SUCCEEDED(hrc))
|
---|
2791 | {
|
---|
2792 | if (a_fForcedRemoval || !i_areThereAnyRunningVMs())
|
---|
2793 | {
|
---|
2794 | AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2795 |
|
---|
2796 | /*
|
---|
2797 | * Refresh the data we have on the extension pack as it may be made
|
---|
2798 | * stale by direct meddling or some other user.
|
---|
2799 | */
|
---|
2800 | ExtPack *pExtPack;
|
---|
2801 | hrc = i_refreshExtPack(a_pstrName->c_str(), false /*a_fUnusableIsError*/, &pExtPack);
|
---|
2802 | if (SUCCEEDED(hrc))
|
---|
2803 | {
|
---|
2804 | if (!pExtPack)
|
---|
2805 | {
|
---|
2806 | LogRel(("ExtPackManager: Extension pack '%s' is not installed, so nothing to uninstall.\n", a_pstrName->c_str()));
|
---|
2807 | hrc = S_OK; /* nothing to uninstall */
|
---|
2808 | }
|
---|
2809 | else
|
---|
2810 | {
|
---|
2811 | /*
|
---|
2812 | * Call the uninstall hook and unload the main dll.
|
---|
2813 | */
|
---|
2814 | hrc = pExtPack->i_callUninstallHookAndClose(m->pVirtualBox, a_fForcedRemoval);
|
---|
2815 | if (SUCCEEDED(hrc))
|
---|
2816 | {
|
---|
2817 | /*
|
---|
2818 | * Run the set-uid-to-root binary that performs the
|
---|
2819 | * uninstallation. Then refresh the object.
|
---|
2820 | *
|
---|
2821 | * This refresh is theorically subject to races, but it's of
|
---|
2822 | * the don't-do-that variety.
|
---|
2823 | */
|
---|
2824 | const char *pszForcedOpt = a_fForcedRemoval ? "--forced" : NULL;
|
---|
2825 | hrc = i_runSetUidToRootHelper(a_pstrDisplayInfo,
|
---|
2826 | "uninstall",
|
---|
2827 | "--base-dir", m->strBaseDir.c_str(),
|
---|
2828 | "--name", a_pstrName->c_str(),
|
---|
2829 | pszForcedOpt, /* Last as it may be NULL. */
|
---|
2830 | (const char *)NULL);
|
---|
2831 | if (SUCCEEDED(hrc))
|
---|
2832 | {
|
---|
2833 | hrc = i_refreshExtPack(a_pstrName->c_str(), false /*a_fUnusableIsError*/, &pExtPack);
|
---|
2834 | if (SUCCEEDED(hrc))
|
---|
2835 | {
|
---|
2836 | if (!pExtPack)
|
---|
2837 | LogRel(("ExtPackManager: Successfully uninstalled extension pack '%s'.\n", a_pstrName->c_str()));
|
---|
2838 | else
|
---|
2839 | hrc = setError(E_FAIL,
|
---|
2840 | tr("Uninstall extension pack '%s' failed under mysterious circumstances"),
|
---|
2841 | a_pstrName->c_str());
|
---|
2842 | }
|
---|
2843 | }
|
---|
2844 | else
|
---|
2845 | {
|
---|
2846 | ErrorInfoKeeper Eik;
|
---|
2847 | i_refreshExtPack(a_pstrName->c_str(), false /*a_fUnusableIsError*/, NULL);
|
---|
2848 | }
|
---|
2849 | }
|
---|
2850 | }
|
---|
2851 | }
|
---|
2852 | }
|
---|
2853 | else
|
---|
2854 | {
|
---|
2855 | LogRel(("Uninstall extension pack '%s' failed because at least one VM is still running.", a_pstrName->c_str()));
|
---|
2856 | hrc = setError(E_FAIL, tr("Uninstall extension pack '%s' failed because at least one VM is still running"),
|
---|
2857 | a_pstrName->c_str());
|
---|
2858 | }
|
---|
2859 |
|
---|
2860 | /*
|
---|
2861 | * Do VirtualBoxReady callbacks now for any freshly installed
|
---|
2862 | * extension pack (old ones will not be called).
|
---|
2863 | */
|
---|
2864 | if (m->enmContext == VBOXEXTPACKCTX_PER_USER_DAEMON)
|
---|
2865 | i_callAllVirtualBoxReadyHooks();
|
---|
2866 | }
|
---|
2867 |
|
---|
2868 | return hrc;
|
---|
2869 | }
|
---|
2870 |
|
---|
2871 |
|
---|
2872 | /**
|
---|
2873 | * Calls the pfnVirtualBoxReady hook for all working extension packs.
|
---|
2874 | *
|
---|
2875 | * @remarks The caller must not hold any locks.
|
---|
2876 | */
|
---|
2877 | void ExtPackManager::i_callAllVirtualBoxReadyHooks(void)
|
---|
2878 | {
|
---|
2879 | AutoCaller autoCaller(this);
|
---|
2880 | HRESULT hrc = autoCaller.rc();
|
---|
2881 | if (FAILED(hrc))
|
---|
2882 | return;
|
---|
2883 | AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2884 | ComPtr<ExtPackManager> ptrSelfRef = this;
|
---|
2885 |
|
---|
2886 | for (ExtPackList::iterator it = m->llInstalledExtPacks.begin();
|
---|
2887 | it != m->llInstalledExtPacks.end();
|
---|
2888 | /* advancing below */)
|
---|
2889 | {
|
---|
2890 | if ((*it)->i_callVirtualBoxReadyHook(m->pVirtualBox, &autoLock))
|
---|
2891 | it = m->llInstalledExtPacks.begin();
|
---|
2892 | else
|
---|
2893 | ++it;
|
---|
2894 | }
|
---|
2895 | }
|
---|
2896 |
|
---|
2897 | #endif /* !VBOX_COM_INPROC */
|
---|
2898 |
|
---|
2899 | #ifdef VBOX_COM_INPROC
|
---|
2900 | /**
|
---|
2901 | * Calls the pfnConsoleReady hook for all working extension packs.
|
---|
2902 | *
|
---|
2903 | * @param a_pConsole The console interface.
|
---|
2904 | * @remarks The caller must not hold any locks.
|
---|
2905 | */
|
---|
2906 | void ExtPackManager::i_callAllConsoleReadyHooks(IConsole *a_pConsole)
|
---|
2907 | {
|
---|
2908 | AutoCaller autoCaller(this);
|
---|
2909 | HRESULT hrc = autoCaller.rc();
|
---|
2910 | if (FAILED(hrc))
|
---|
2911 | return;
|
---|
2912 | AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2913 | ComPtr<ExtPackManager> ptrSelfRef = this;
|
---|
2914 |
|
---|
2915 | for (ExtPackList::iterator it = m->llInstalledExtPacks.begin();
|
---|
2916 | it != m->llInstalledExtPacks.end();
|
---|
2917 | /* advancing below */)
|
---|
2918 | {
|
---|
2919 | if ((*it)->i_callConsoleReadyHook(a_pConsole, &autoLock))
|
---|
2920 | it = m->llInstalledExtPacks.begin();
|
---|
2921 | else
|
---|
2922 | ++it;
|
---|
2923 | }
|
---|
2924 | }
|
---|
2925 | #endif
|
---|
2926 |
|
---|
2927 | #ifndef VBOX_COM_INPROC
|
---|
2928 | /**
|
---|
2929 | * Calls the pfnVMCreated hook for all working extension packs.
|
---|
2930 | *
|
---|
2931 | * @param a_pMachine The machine interface of the new VM.
|
---|
2932 | */
|
---|
2933 | void ExtPackManager::i_callAllVmCreatedHooks(IMachine *a_pMachine)
|
---|
2934 | {
|
---|
2935 | AutoCaller autoCaller(this);
|
---|
2936 | HRESULT hrc = autoCaller.rc();
|
---|
2937 | if (FAILED(hrc))
|
---|
2938 | return;
|
---|
2939 | AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2940 | ComPtr<ExtPackManager> ptrSelfRef = this; /* paranoia */
|
---|
2941 | ExtPackList llExtPacks = m->llInstalledExtPacks;
|
---|
2942 |
|
---|
2943 | for (ExtPackList::iterator it = llExtPacks.begin(); it != llExtPacks.end(); ++it)
|
---|
2944 | (*it)->i_callVmCreatedHook(m->pVirtualBox, a_pMachine, &autoLock);
|
---|
2945 | }
|
---|
2946 | #endif
|
---|
2947 |
|
---|
2948 | #ifdef VBOX_COM_INPROC
|
---|
2949 | /**
|
---|
2950 | * Calls the pfnVMConfigureVMM hook for all working extension packs.
|
---|
2951 | *
|
---|
2952 | * @returns VBox status code. Stops on the first failure, expecting the caller
|
---|
2953 | * to signal this to the caller of the CFGM constructor.
|
---|
2954 | * @param a_pConsole The console interface for the VM.
|
---|
2955 | * @param a_pVM The VM handle.
|
---|
2956 | */
|
---|
2957 | int ExtPackManager::i_callAllVmConfigureVmmHooks(IConsole *a_pConsole, PVM a_pVM)
|
---|
2958 | {
|
---|
2959 | AutoCaller autoCaller(this);
|
---|
2960 | HRESULT hrc = autoCaller.rc();
|
---|
2961 | if (FAILED(hrc))
|
---|
2962 | return Global::vboxStatusCodeFromCOM(hrc);
|
---|
2963 | AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2964 | ComPtr<ExtPackManager> ptrSelfRef = this; /* paranoia */
|
---|
2965 | ExtPackList llExtPacks = m->llInstalledExtPacks;
|
---|
2966 |
|
---|
2967 | for (ExtPackList::iterator it = llExtPacks.begin(); it != llExtPacks.end(); ++it)
|
---|
2968 | {
|
---|
2969 | int vrc;
|
---|
2970 | (*it)->i_callVmConfigureVmmHook(a_pConsole, a_pVM, &autoLock, &vrc);
|
---|
2971 | if (RT_FAILURE(vrc))
|
---|
2972 | return vrc;
|
---|
2973 | }
|
---|
2974 |
|
---|
2975 | return VINF_SUCCESS;
|
---|
2976 | }
|
---|
2977 |
|
---|
2978 | /**
|
---|
2979 | * Calls the pfnVMPowerOn hook for all working extension packs.
|
---|
2980 | *
|
---|
2981 | * @returns VBox status code. Stops on the first failure, expecting the caller
|
---|
2982 | * to not power on the VM.
|
---|
2983 | * @param a_pConsole The console interface for the VM.
|
---|
2984 | * @param a_pVM The VM handle.
|
---|
2985 | */
|
---|
2986 | int ExtPackManager::i_callAllVmPowerOnHooks(IConsole *a_pConsole, PVM a_pVM)
|
---|
2987 | {
|
---|
2988 | AutoCaller autoCaller(this);
|
---|
2989 | HRESULT hrc = autoCaller.rc();
|
---|
2990 | if (FAILED(hrc))
|
---|
2991 | return Global::vboxStatusCodeFromCOM(hrc);
|
---|
2992 | AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2993 | ComPtr<ExtPackManager> ptrSelfRef = this; /* paranoia */
|
---|
2994 | ExtPackList llExtPacks = m->llInstalledExtPacks;
|
---|
2995 |
|
---|
2996 | for (ExtPackList::iterator it = llExtPacks.begin(); it != llExtPacks.end(); ++it)
|
---|
2997 | {
|
---|
2998 | int vrc;
|
---|
2999 | (*it)->i_callVmPowerOnHook(a_pConsole, a_pVM, &autoLock, &vrc);
|
---|
3000 | if (RT_FAILURE(vrc))
|
---|
3001 | return vrc;
|
---|
3002 | }
|
---|
3003 |
|
---|
3004 | return VINF_SUCCESS;
|
---|
3005 | }
|
---|
3006 |
|
---|
3007 | /**
|
---|
3008 | * Calls the pfnVMPowerOff hook for all working extension packs.
|
---|
3009 | *
|
---|
3010 | * @param a_pConsole The console interface for the VM.
|
---|
3011 | * @param a_pVM The VM handle. Can be NULL.
|
---|
3012 | */
|
---|
3013 | void ExtPackManager::i_callAllVmPowerOffHooks(IConsole *a_pConsole, PVM a_pVM)
|
---|
3014 | {
|
---|
3015 | AutoCaller autoCaller(this);
|
---|
3016 | HRESULT hrc = autoCaller.rc();
|
---|
3017 | if (FAILED(hrc))
|
---|
3018 | return;
|
---|
3019 | AutoWriteLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
3020 | ComPtr<ExtPackManager> ptrSelfRef = this; /* paranoia */
|
---|
3021 | ExtPackList llExtPacks = m->llInstalledExtPacks;
|
---|
3022 |
|
---|
3023 | for (ExtPackList::iterator it = llExtPacks.begin(); it != llExtPacks.end(); ++it)
|
---|
3024 | (*it)->i_callVmPowerOffHook(a_pConsole, a_pVM, &autoLock);
|
---|
3025 | }
|
---|
3026 | #endif
|
---|
3027 |
|
---|
3028 |
|
---|
3029 | /**
|
---|
3030 | * Checks that the specified extension pack contains a VRDE module and that it
|
---|
3031 | * is shipshape.
|
---|
3032 | *
|
---|
3033 | * @returns S_OK if ok, appropriate failure status code with details.
|
---|
3034 | * @param a_pstrExtPack The name of the extension pack.
|
---|
3035 | */
|
---|
3036 | HRESULT ExtPackManager::i_checkVrdeExtPack(Utf8Str const *a_pstrExtPack)
|
---|
3037 | {
|
---|
3038 | AutoCaller autoCaller(this);
|
---|
3039 | HRESULT hrc = autoCaller.rc();
|
---|
3040 | if (SUCCEEDED(hrc))
|
---|
3041 | {
|
---|
3042 | AutoReadLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
3043 |
|
---|
3044 | ExtPack *pExtPack = i_findExtPack(a_pstrExtPack->c_str());
|
---|
3045 | if (pExtPack)
|
---|
3046 | hrc = pExtPack->i_checkVrde();
|
---|
3047 | else
|
---|
3048 | hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("No extension pack by the name '%s' was found"), a_pstrExtPack->c_str());
|
---|
3049 | }
|
---|
3050 |
|
---|
3051 | return hrc;
|
---|
3052 | }
|
---|
3053 |
|
---|
3054 | /**
|
---|
3055 | * Gets the full path to the VRDE library of the specified extension pack.
|
---|
3056 | *
|
---|
3057 | * This will do extacly the same as checkVrdeExtPack and then resolve the
|
---|
3058 | * library path.
|
---|
3059 | *
|
---|
3060 | * @returns S_OK if a path is returned, COM error status and message return if
|
---|
3061 | * not.
|
---|
3062 | * @param a_pstrExtPack The extension pack.
|
---|
3063 | * @param a_pstrVrdeLibrary Where to return the path.
|
---|
3064 | */
|
---|
3065 | int ExtPackManager::i_getVrdeLibraryPathForExtPack(Utf8Str const *a_pstrExtPack, Utf8Str *a_pstrVrdeLibrary)
|
---|
3066 | {
|
---|
3067 | AutoCaller autoCaller(this);
|
---|
3068 | HRESULT hrc = autoCaller.rc();
|
---|
3069 | if (SUCCEEDED(hrc))
|
---|
3070 | {
|
---|
3071 | AutoReadLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
3072 |
|
---|
3073 | ExtPack *pExtPack = i_findExtPack(a_pstrExtPack->c_str());
|
---|
3074 | if (pExtPack)
|
---|
3075 | hrc = pExtPack->i_getVrdpLibraryName(a_pstrVrdeLibrary);
|
---|
3076 | else
|
---|
3077 | hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("No extension pack by the name '%s' was found"),
|
---|
3078 | a_pstrExtPack->c_str());
|
---|
3079 | }
|
---|
3080 |
|
---|
3081 | return hrc;
|
---|
3082 | }
|
---|
3083 |
|
---|
3084 | /**
|
---|
3085 | * Gets the full path to the specified library of the specified extension pack.
|
---|
3086 | *
|
---|
3087 | * @returns S_OK if a path is returned, COM error status and message return if
|
---|
3088 | * not.
|
---|
3089 | * @param a_pszModuleName The library.
|
---|
3090 | * @param a_pszExtPack The extension pack.
|
---|
3091 | * @param a_pstrLibrary Where to return the path.
|
---|
3092 | */
|
---|
3093 | HRESULT ExtPackManager::i_getLibraryPathForExtPack(const char *a_pszModuleName, const char *a_pszExtPack, Utf8Str *a_pstrLibrary)
|
---|
3094 | {
|
---|
3095 | AutoCaller autoCaller(this);
|
---|
3096 | HRESULT hrc = autoCaller.rc();
|
---|
3097 | if (SUCCEEDED(hrc))
|
---|
3098 | {
|
---|
3099 | AutoReadLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
3100 |
|
---|
3101 | ExtPack *pExtPack = i_findExtPack(a_pszExtPack);
|
---|
3102 | if (pExtPack)
|
---|
3103 | hrc = pExtPack->i_getLibraryName(a_pszModuleName, a_pstrLibrary);
|
---|
3104 | else
|
---|
3105 | hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("No extension pack by the name '%s' was found"), a_pszExtPack);
|
---|
3106 | }
|
---|
3107 |
|
---|
3108 | return hrc;
|
---|
3109 | }
|
---|
3110 |
|
---|
3111 | /**
|
---|
3112 | * Gets the name of the default VRDE extension pack.
|
---|
3113 | *
|
---|
3114 | * @returns S_OK or some COM error status on red tape failure.
|
---|
3115 | * @param a_pstrExtPack Where to return the extension pack name. Returns
|
---|
3116 | * empty if no extension pack wishes to be the default
|
---|
3117 | * VRDP provider.
|
---|
3118 | */
|
---|
3119 | HRESULT ExtPackManager::i_getDefaultVrdeExtPack(Utf8Str *a_pstrExtPack)
|
---|
3120 | {
|
---|
3121 | a_pstrExtPack->setNull();
|
---|
3122 |
|
---|
3123 | AutoCaller autoCaller(this);
|
---|
3124 | HRESULT hrc = autoCaller.rc();
|
---|
3125 | if (SUCCEEDED(hrc))
|
---|
3126 | {
|
---|
3127 | AutoReadLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
3128 |
|
---|
3129 | for (ExtPackList::iterator it = m->llInstalledExtPacks.begin();
|
---|
3130 | it != m->llInstalledExtPacks.end();
|
---|
3131 | ++it)
|
---|
3132 | {
|
---|
3133 | if ((*it)->i_wantsToBeDefaultVrde())
|
---|
3134 | {
|
---|
3135 | *a_pstrExtPack = (*it)->m->Desc.strName;
|
---|
3136 | break;
|
---|
3137 | }
|
---|
3138 | }
|
---|
3139 | }
|
---|
3140 | return hrc;
|
---|
3141 | }
|
---|
3142 |
|
---|
3143 | /**
|
---|
3144 | * Checks if an extension pack is (present and) usable.
|
---|
3145 | *
|
---|
3146 | * @returns @c true if it is, otherwise @c false.
|
---|
3147 | * @param a_pszExtPack The name of the extension pack.
|
---|
3148 | */
|
---|
3149 | bool ExtPackManager::i_isExtPackUsable(const char *a_pszExtPack)
|
---|
3150 | {
|
---|
3151 | AutoCaller autoCaller(this);
|
---|
3152 | HRESULT hrc = autoCaller.rc();
|
---|
3153 | if (FAILED(hrc))
|
---|
3154 | return false;
|
---|
3155 | AutoReadLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
3156 |
|
---|
3157 | ExtPack *pExtPack = i_findExtPack(a_pszExtPack);
|
---|
3158 | return pExtPack != NULL
|
---|
3159 | && pExtPack->m->fUsable;
|
---|
3160 | }
|
---|
3161 |
|
---|
3162 | /**
|
---|
3163 | * Dumps all extension packs to the release log.
|
---|
3164 | */
|
---|
3165 | void ExtPackManager::i_dumpAllToReleaseLog(void)
|
---|
3166 | {
|
---|
3167 | AutoCaller autoCaller(this);
|
---|
3168 | HRESULT hrc = autoCaller.rc();
|
---|
3169 | if (FAILED(hrc))
|
---|
3170 | return;
|
---|
3171 | AutoReadLock autoLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
3172 |
|
---|
3173 | LogRel(("Installed Extension Packs:\n"));
|
---|
3174 | for (ExtPackList::iterator it = m->llInstalledExtPacks.begin();
|
---|
3175 | it != m->llInstalledExtPacks.end();
|
---|
3176 | ++it)
|
---|
3177 | {
|
---|
3178 | ExtPack::Data *pExtPackData = (*it)->m;
|
---|
3179 | if (pExtPackData)
|
---|
3180 | {
|
---|
3181 | if (pExtPackData->fUsable)
|
---|
3182 | LogRel((" %s (Version: %s r%u%s%s; VRDE Module: %s)\n",
|
---|
3183 | pExtPackData->Desc.strName.c_str(),
|
---|
3184 | pExtPackData->Desc.strVersion.c_str(),
|
---|
3185 | pExtPackData->Desc.uRevision,
|
---|
3186 | pExtPackData->Desc.strEdition.isEmpty() ? "" : " ",
|
---|
3187 | pExtPackData->Desc.strEdition.c_str(),
|
---|
3188 | pExtPackData->Desc.strVrdeModule.c_str() ));
|
---|
3189 | else
|
---|
3190 | LogRel((" %s (Version: %s r%u%s%s; VRDE Module: %s unusable because of '%s')\n",
|
---|
3191 | pExtPackData->Desc.strName.c_str(),
|
---|
3192 | pExtPackData->Desc.strVersion.c_str(),
|
---|
3193 | pExtPackData->Desc.uRevision,
|
---|
3194 | pExtPackData->Desc.strEdition.isEmpty() ? "" : " ",
|
---|
3195 | pExtPackData->Desc.strEdition.c_str(),
|
---|
3196 | pExtPackData->Desc.strVrdeModule.c_str(),
|
---|
3197 | pExtPackData->strWhyUnusable.c_str() ));
|
---|
3198 | }
|
---|
3199 | else
|
---|
3200 | LogRel((" pExtPackData is NULL\n"));
|
---|
3201 | }
|
---|
3202 |
|
---|
3203 | if (!m->llInstalledExtPacks.size())
|
---|
3204 | LogRel((" None installed!\n"));
|
---|
3205 | }
|
---|
3206 |
|
---|
3207 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|