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