VirtualBox

source: vbox/trunk/src/VBox/Main/src-all/ExtPackManagerImpl.cpp@ 35550

Last change on this file since 35550 was 35523, checked in by vboxsync, 14 years ago

Main,VBoxManage: Implemented the progress objects for ExtPackManager::Uninstall and ExtPackFile::Install. Fixed a bug in ExtPackFile wrt cleaning up on failure.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette