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