VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/UnattendedImpl.cpp@ 71011

Last change on this file since 71011 was 71011, checked in by vboxsync, 7 years ago

Main,Installer: Made unattended installation work for rhel4 and friends. Special tweak needed for centos version detection.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 84.7 KB
Line 
1/* $Id: UnattendedImpl.cpp 71011 2018-02-14 16:11:18Z vboxsync $ */
2/** @file
3 * Unattended class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2017 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#define LOG_GROUP LOG_GROUP_MAIN_UNATTENDED
23#include "LoggingNew.h"
24#include "VirtualBoxBase.h"
25#include "UnattendedImpl.h"
26#include "UnattendedInstaller.h"
27#include "UnattendedScript.h"
28#include "VirtualBoxImpl.h"
29#include "SystemPropertiesImpl.h"
30#include "MachineImpl.h"
31#include "Global.h"
32
33#include <VBox/err.h>
34#include <iprt/ctype.h>
35#include <iprt/file.h>
36#include <iprt/fsvfs.h>
37#include <iprt/inifile.h>
38#include <iprt/locale.h>
39#include <iprt/path.h>
40
41using namespace std;
42
43/* XPCOM doesn't define S_FALSE. */
44#ifndef S_FALSE
45# define S_FALSE ((HRESULT)1)
46#endif
47
48
49/*********************************************************************************************************************************
50* Structures and Typedefs *
51*********************************************************************************************************************************/
52/**
53 * Controller slot for a DVD drive.
54 *
55 * The slot can be free and needing a drive to be attached along with the ISO
56 * image, or it may already be there and only need mounting the ISO. The
57 * ControllerSlot::fFree member indicates which it is.
58 */
59struct ControllerSlot
60{
61 StorageBus_T enmBus;
62 Utf8Str strControllerName;
63 ULONG uPort;
64 ULONG uDevice;
65 bool fFree;
66
67 ControllerSlot(StorageBus_T a_enmBus, const Utf8Str &a_rName, ULONG a_uPort, ULONG a_uDevice, bool a_fFree)
68 : enmBus(a_enmBus), strControllerName(a_rName), uPort(a_uPort), uDevice(a_uDevice), fFree(a_fFree)
69 {}
70
71 bool operator<(const ControllerSlot &rThat) const
72 {
73 if (enmBus == rThat.enmBus)
74 {
75 if (strControllerName == rThat.strControllerName)
76 {
77 if (uPort == rThat.uPort)
78 return uDevice < rThat.uDevice;
79 return uPort < rThat.uPort;
80 }
81 return strControllerName < rThat.strControllerName;
82 }
83
84 /*
85 * Bus comparsion in boot priority order.
86 */
87 /* IDE first. */
88 if (enmBus == StorageBus_IDE)
89 return true;
90 if (rThat.enmBus == StorageBus_IDE)
91 return false;
92 /* SATA next */
93 if (enmBus == StorageBus_SATA)
94 return true;
95 if (rThat.enmBus == StorageBus_SATA)
96 return false;
97 /* SCSI next */
98 if (enmBus == StorageBus_SCSI)
99 return true;
100 if (rThat.enmBus == StorageBus_SCSI)
101 return false;
102 /* numerical */
103 return (int)enmBus < (int)rThat.enmBus;
104 }
105
106 bool operator==(const ControllerSlot &rThat) const
107 {
108 return enmBus == rThat.enmBus
109 && strControllerName == rThat.strControllerName
110 && uPort == rThat.uPort
111 && uDevice == rThat.uDevice;
112 }
113};
114
115/**
116 * Installation disk.
117 *
118 * Used when reconfiguring the VM.
119 */
120typedef struct UnattendedInstallationDisk
121{
122 StorageBus_T enmBusType; /**< @todo nobody is using this... */
123 Utf8Str strControllerName;
124 DeviceType_T enmDeviceType;
125 AccessMode_T enmAccessType;
126 ULONG uPort;
127 ULONG uDevice;
128 bool fMountOnly;
129 Utf8Str strImagePath;
130
131 UnattendedInstallationDisk(StorageBus_T a_enmBusType, Utf8Str const &a_rBusName, DeviceType_T a_enmDeviceType,
132 AccessMode_T a_enmAccessType, ULONG a_uPort, ULONG a_uDevice, bool a_fMountOnly,
133 Utf8Str const &a_rImagePath)
134 : enmBusType(a_enmBusType), strControllerName(a_rBusName), enmDeviceType(a_enmDeviceType), enmAccessType(a_enmAccessType)
135 , uPort(a_uPort), uDevice(a_uDevice), fMountOnly(a_fMountOnly), strImagePath(a_rImagePath)
136 {
137 Assert(strControllerName.length() > 0);
138 }
139
140 UnattendedInstallationDisk(std::list<ControllerSlot>::const_iterator const &itDvdSlot, Utf8Str const &a_rImagePath)
141 : enmBusType(itDvdSlot->enmBus), strControllerName(itDvdSlot->strControllerName), enmDeviceType(DeviceType_DVD)
142 , enmAccessType(AccessMode_ReadOnly), uPort(itDvdSlot->uPort), uDevice(itDvdSlot->uDevice)
143 , fMountOnly(!itDvdSlot->fFree), strImagePath(a_rImagePath)
144 {
145 Assert(strControllerName.length() > 0);
146 }
147} UnattendedInstallationDisk;
148
149
150//////////////////////////////////////////////////////////////////////////////////////////////////////
151/*
152*
153*
154* Implementation Unattended functions
155*
156*/
157//////////////////////////////////////////////////////////////////////////////////////////////////////
158
159Unattended::Unattended()
160 : mhThreadReconfigureVM(NIL_RTNATIVETHREAD), mfRtcUseUtc(false), mfGuestOs64Bit(false)
161 , mpInstaller(NULL), mpTimeZoneInfo(NULL), mfIsDefaultAuxiliaryBasePath(true), mfDoneDetectIsoOS(false)
162{ }
163
164Unattended::~Unattended()
165{
166 if (mpInstaller)
167 {
168 delete mpInstaller;
169 mpInstaller = NULL;
170 }
171}
172
173HRESULT Unattended::FinalConstruct()
174{
175 return BaseFinalConstruct();
176}
177
178void Unattended::FinalRelease()
179{
180 uninit();
181
182 BaseFinalRelease();
183}
184
185void Unattended::uninit()
186{
187 /* Enclose the state transition Ready->InUninit->NotReady */
188 AutoUninitSpan autoUninitSpan(this);
189 if (autoUninitSpan.uninitDone())
190 return;
191
192 unconst(mParent) = NULL;
193 mMachine.setNull();
194}
195
196/**
197 * Initializes the unattended object.
198 *
199 * @param aParent Pointer to the parent object.
200 */
201HRESULT Unattended::initUnattended(VirtualBox *aParent)
202{
203 LogFlowThisFunc(("aParent=%p\n", aParent));
204 ComAssertRet(aParent, E_INVALIDARG);
205
206 /* Enclose the state transition NotReady->InInit->Ready */
207 AutoInitSpan autoInitSpan(this);
208 AssertReturn(autoInitSpan.isOk(), E_FAIL);
209
210 unconst(mParent) = aParent;
211
212 /*
213 * Fill public attributes (IUnattended) with useful defaults.
214 */
215 try
216 {
217 mStrUser = "vboxuser";
218 mStrPassword = "changeme";
219 mfInstallGuestAdditions = false;
220 mfInstallTestExecService = false;
221 midxImage = 1;
222
223 HRESULT hrc = mParent->i_getSystemProperties()->i_getDefaultAdditionsISO(mStrAdditionsIsoPath);
224 ComAssertComRCRet(hrc, hrc);
225 }
226 catch (std::bad_alloc)
227 {
228 return E_OUTOFMEMORY;
229 }
230
231 /*
232 * Confirm a successful initialization
233 */
234 autoInitSpan.setSucceeded();
235
236 return S_OK;
237}
238
239HRESULT Unattended::detectIsoOS()
240{
241 HRESULT hrc;
242 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
243
244/** @todo once UDF is implemented properly and we've tested this code a lot
245 * more, replace E_NOTIMPL with E_FAIL. */
246
247
248 /*
249 * Open the ISO.
250 */
251 RTVFSFILE hVfsFileIso;
252 int vrc = RTVfsFileOpenNormal(mStrIsoPath.c_str(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFileIso);
253 if (RT_FAILURE(vrc))
254 return setErrorBoth(E_NOTIMPL, vrc, tr("Failed to open '%s' (%Rrc)"), mStrIsoPath.c_str(), vrc);
255
256 RTERRINFOSTATIC ErrInfo;
257 RTVFS hVfsIso;
258 vrc = RTFsIso9660VolOpen(hVfsFileIso, 0 /*fFlags*/, &hVfsIso, RTErrInfoInitStatic(&ErrInfo));
259 if (RT_SUCCESS(vrc))
260 {
261 /*
262 * Try do the detection. Repeat for different file system variations (nojoliet, noudf).
263 */
264 hrc = i_innerDetectIsoOS(hVfsIso);
265
266 RTVfsRelease(hVfsIso);
267 hrc = E_NOTIMPL;
268 }
269 else if (RTErrInfoIsSet(&ErrInfo.Core))
270 hrc = setErrorBoth(E_NOTIMPL, vrc, tr("Failed to open '%s' as ISO FS (%Rrc) - %s"),
271 mStrIsoPath.c_str(), vrc, ErrInfo.Core.pszMsg);
272 else
273 hrc = setErrorBoth(E_NOTIMPL, vrc, tr("Failed to open '%s' as ISO FS (%Rrc)"), mStrIsoPath.c_str(), vrc);
274 RTVfsFileRelease(hVfsFileIso);
275
276 /*
277 * Just fake up some windows installation media locale (for <UILanguage>).
278 * Note! The translation here isn't perfect. Feel free to send us a patch.
279 */
280 if (mDetectedOSLanguages.size() == 0)
281 {
282 char szTmp[16];
283 const char *pszFilename = RTPathFilename(mStrIsoPath.c_str());
284 if ( pszFilename
285 && RT_C_IS_ALPHA(pszFilename[0])
286 && RT_C_IS_ALPHA(pszFilename[1])
287 && (pszFilename[2] == '-' || pszFilename[2] == '_') )
288 {
289 szTmp[0] = (char)RT_C_TO_LOWER(pszFilename[0]);
290 szTmp[1] = (char)RT_C_TO_LOWER(pszFilename[1]);
291 szTmp[2] = '-';
292 if (szTmp[0] == 'e' && szTmp[1] == 'n')
293 strcpy(&szTmp[3], "US");
294 else if (szTmp[0] == 'a' && szTmp[1] == 'r')
295 strcpy(&szTmp[3], "SA");
296 else if (szTmp[0] == 'd' && szTmp[1] == 'a')
297 strcpy(&szTmp[3], "DK");
298 else if (szTmp[0] == 'e' && szTmp[1] == 't')
299 strcpy(&szTmp[3], "EE");
300 else if (szTmp[0] == 'e' && szTmp[1] == 'l')
301 strcpy(&szTmp[3], "GR");
302 else if (szTmp[0] == 'h' && szTmp[1] == 'e')
303 strcpy(&szTmp[3], "IL");
304 else if (szTmp[0] == 'j' && szTmp[1] == 'a')
305 strcpy(&szTmp[3], "JP");
306 else if (szTmp[0] == 's' && szTmp[1] == 'v')
307 strcpy(&szTmp[3], "SE");
308 else if (szTmp[0] == 'u' && szTmp[1] == 'k')
309 strcpy(&szTmp[3], "UA");
310 else if (szTmp[0] == 'c' && szTmp[1] == 's')
311 strcpy(szTmp, "cs-CZ");
312 else if (szTmp[0] == 'n' && szTmp[1] == 'o')
313 strcpy(szTmp, "nb-NO");
314 else if (szTmp[0] == 'p' && szTmp[1] == 'p')
315 strcpy(szTmp, "pt-PT");
316 else if (szTmp[0] == 'p' && szTmp[1] == 't')
317 strcpy(szTmp, "pt-BR");
318 else if (szTmp[0] == 'c' && szTmp[1] == 'n')
319 strcpy(szTmp, "zh-CN");
320 else if (szTmp[0] == 'h' && szTmp[1] == 'k')
321 strcpy(szTmp, "zh-HK");
322 else if (szTmp[0] == 't' && szTmp[1] == 'w')
323 strcpy(szTmp, "zh-TW");
324 else if (szTmp[0] == 's' && szTmp[1] == 'r')
325 strcpy(szTmp, "sr-Latn-CS"); /* hmm */
326 else
327 {
328 szTmp[3] = (char)RT_C_TO_UPPER(pszFilename[0]);
329 szTmp[4] = (char)RT_C_TO_UPPER(pszFilename[1]);
330 szTmp[5] = '\0';
331 }
332 }
333 else
334 strcpy(szTmp, "en-US");
335 try
336 {
337 mDetectedOSLanguages.append(szTmp);
338 }
339 catch (std::bad_alloc)
340 {
341 return E_OUTOFMEMORY;
342 }
343 }
344
345 /** @todo implement actual detection logic. */
346 return hrc;
347}
348
349HRESULT Unattended::i_innerDetectIsoOS(RTVFS hVfsIso)
350{
351 DETECTBUFFER uBuf;
352 VBOXOSTYPE enmOsType = VBOXOSTYPE_Unknown;
353 HRESULT hrc = i_innerDetectIsoOSWindows(hVfsIso, &uBuf, &enmOsType);
354 if (hrc == S_FALSE && enmOsType == VBOXOSTYPE_Unknown)
355 hrc = i_innerDetectIsoOSLinux(hVfsIso, &uBuf, &enmOsType);
356 if (enmOsType != VBOXOSTYPE_Unknown)
357 {
358 try { mStrDetectedOSTypeId = Global::OSTypeId(enmOsType); }
359 catch (std::bad_alloc) { hrc = E_OUTOFMEMORY; }
360 }
361 return hrc;
362}
363
364/**
365 * Detect Windows ISOs.
366 *
367 * @returns COM status code.
368 * @retval S_OK if detected
369 * @retval S_FALSE if not fully detected.
370 *
371 * @param hVfsIso The ISO file system.
372 * @param pBuf Read buffer.
373 * @param penmOsType Where to return the OS type. This is initialized to
374 * VBOXOSTYPE_Unknown.
375 */
376HRESULT Unattended::i_innerDetectIsoOSWindows(RTVFS hVfsIso, DETECTBUFFER *pBuf, VBOXOSTYPE *penmOsType)
377{
378 /** @todo The 'sources/' path can differ. */
379
380 // globalinstallorder.xml - vista beta2
381 // sources/idwbinfo.txt - ditto.
382 // sources/lang.ini - ditto.
383
384 /*
385 * Try look for the 'sources/idwbinfo.txt' file containing windows build info.
386 * This file appeared with Vista beta 2 from what we can tell. Before windows 10
387 * it contains easily decodable branch names, after that things goes weird.
388 */
389 RTVFSFILE hVfsFile;
390 int vrc = RTVfsFileOpen(hVfsIso, "sources/idwbinfo.txt", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
391 if (RT_SUCCESS(vrc))
392 {
393 *penmOsType = VBOXOSTYPE_WinNT_x64;
394
395 RTINIFILE hIniFile;
396 vrc = RTIniFileCreateFromVfsFile(&hIniFile, hVfsFile, RTINIFILE_F_READONLY);
397 RTVfsFileRelease(hVfsFile);
398 if (RT_SUCCESS(vrc))
399 {
400 vrc = RTIniFileQueryValue(hIniFile, "BUILDINFO", "BuildArch", pBuf->sz, sizeof(*pBuf), NULL);
401 if (RT_SUCCESS(vrc))
402 {
403 LogRelFlow(("Unattended: sources/idwbinfo.txt: BuildArch=%s\n", pBuf->sz));
404 if ( RTStrNICmp(pBuf->sz, RT_STR_TUPLE("amd64")) == 0
405 || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("x64")) == 0 /* just in case */ )
406 *penmOsType = VBOXOSTYPE_WinNT_x64;
407 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("x86")) == 0)
408 *penmOsType = VBOXOSTYPE_WinNT;
409 else
410 {
411 LogRel(("Unattended: sources/idwbinfo.txt: Unknown: BuildArch=%s\n", pBuf->sz));
412 *penmOsType = VBOXOSTYPE_WinNT_x64;
413 }
414 }
415
416 vrc = RTIniFileQueryValue(hIniFile, "BUILDINFO", "BuildBranch", pBuf->sz, sizeof(*pBuf), NULL);
417 if (RT_SUCCESS(vrc))
418 {
419 LogRelFlow(("Unattended: sources/idwbinfo.txt: BuildBranch=%s\n", pBuf->sz));
420 if ( RTStrNICmp(pBuf->sz, RT_STR_TUPLE("vista")) == 0
421 || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("winmain_beta")) == 0)
422 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_WinVista);
423 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("win7")) == 0)
424 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win7);
425 else if ( RTStrNICmp(pBuf->sz, RT_STR_TUPLE("winblue")) == 0
426 || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("winmain_blue")) == 0
427 || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("win81")) == 0 /* not seen, but just in case its out there */ )
428 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win81);
429 else if ( RTStrNICmp(pBuf->sz, RT_STR_TUPLE("win8")) == 0
430 || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("winmain_win8")) == 0 )
431 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win8);
432 else
433 LogRel(("Unattended: sources/idwbinfo.txt: Unknown: BuildBranch=%s\n", pBuf->sz));
434 }
435 RTIniFileRelease(hIniFile);
436 }
437 }
438
439 /*
440 * Look for sources/lang.ini and try parse it to get the languages out of it.
441 */
442 /** @todo We could also check sources/??-* and boot/??-* if lang.ini is not
443 * found or unhelpful. */
444 vrc = RTVfsFileOpen(hVfsIso, "sources/lang.ini", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
445 if (RT_SUCCESS(vrc))
446 {
447 RTINIFILE hIniFile;
448 vrc = RTIniFileCreateFromVfsFile(&hIniFile, hVfsFile, RTINIFILE_F_READONLY);
449 RTVfsFileRelease(hVfsFile);
450 if (RT_SUCCESS(vrc))
451 {
452 mDetectedOSLanguages.clear();
453
454 uint32_t idxPair;
455 for (idxPair = 0; idxPair < 256; idxPair++)
456 {
457 size_t cbHalf = sizeof(*pBuf) / 2;
458 char *pszKey = pBuf->sz;
459 char *pszValue = &pBuf->sz[cbHalf];
460 vrc = RTIniFileQueryPair(hIniFile, "Available UI Languages", idxPair,
461 pszKey, cbHalf, NULL, pszValue, cbHalf, NULL);
462 if (RT_SUCCESS(vrc))
463 {
464 try
465 {
466 mDetectedOSLanguages.append(pszKey);
467 }
468 catch (std::bad_alloc)
469 {
470 RTIniFileRelease(hIniFile);
471 return E_OUTOFMEMORY;
472 }
473 }
474 else if (vrc == VERR_NOT_FOUND)
475 break;
476 else
477 Assert(vrc == VERR_BUFFER_OVERFLOW);
478 }
479 if (idxPair == 0)
480 LogRel(("Unattended: Warning! Empty 'Available UI Languages' section in sources/lang.ini\n"));
481 RTIniFileRelease(hIniFile);
482 }
483 }
484
485 /** @todo look at the install.wim file too, extracting the XML (easy) and
486 * figure out the available image numbers and such. The format is
487 * documented. */
488
489 return S_FALSE;
490}
491
492/**
493 * Detects linux architecture.
494 *
495 * @returns true if detected, false if not.
496 * @param pszArch The architecture string.
497 * @param penmOsType Where to return the arch and type on success.
498 * @param enmBaseOsType The base (x86) OS type to return.
499 */
500static bool detectLinuxArch(const char *pszArch, VBOXOSTYPE *penmOsType, VBOXOSTYPE enmBaseOsType)
501{
502 if ( RTStrNICmp(pszArch, RT_STR_TUPLE("amd64")) == 0
503 || RTStrNICmp(pszArch, RT_STR_TUPLE("x86_64")) == 0
504 || RTStrNICmp(pszArch, RT_STR_TUPLE("x86-64")) == 0 /* just in case */
505 || RTStrNICmp(pszArch, RT_STR_TUPLE("x64")) == 0 /* ditto */ )
506 {
507 *penmOsType = (VBOXOSTYPE)(enmBaseOsType | VBOXOSTYPE_x64);
508 return true;
509 }
510
511 if ( RTStrNICmp(pszArch, RT_STR_TUPLE("x86")) == 0
512 || RTStrNICmp(pszArch, RT_STR_TUPLE("i386")) == 0
513 || RTStrNICmp(pszArch, RT_STR_TUPLE("i486")) == 0
514 || RTStrNICmp(pszArch, RT_STR_TUPLE("i586")) == 0
515 || RTStrNICmp(pszArch, RT_STR_TUPLE("i686")) == 0
516 || RTStrNICmp(pszArch, RT_STR_TUPLE("i786")) == 0
517 || RTStrNICmp(pszArch, RT_STR_TUPLE("i886")) == 0
518 || RTStrNICmp(pszArch, RT_STR_TUPLE("i986")) == 0)
519 {
520 *penmOsType = enmBaseOsType;
521 return true;
522 }
523
524 /** @todo check for 'noarch' since source CDs have been seen to use that. */
525 return false;
526}
527
528static bool detectLinuxDistroName(const char *pszOsAndVersion, VBOXOSTYPE *penmOsType, const char **ppszNext)
529{
530 bool fRet = true;
531
532 if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Red")) == 0
533 && !RT_C_IS_ALNUM(pszOsAndVersion[3]))
534
535 {
536 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 3);
537 if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Hat")) == 0
538 && !RT_C_IS_ALNUM(pszOsAndVersion[3]))
539 {
540 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_RedHat);
541 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 3);
542 }
543 else
544 fRet = false;
545 }
546 else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Oracle")) == 0
547 && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
548 {
549 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Oracle);
550 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
551 }
552 else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("CentOS")) == 0
553 && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
554 {
555 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_RedHat);
556 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
557 }
558 else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Fedora")) == 0
559 && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
560 {
561 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_FedoraCore);
562 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
563 }
564 else
565 fRet = false;
566
567 /*
568 * Skip forward till we get a number.
569 */
570 if (ppszNext)
571 {
572 *ppszNext = pszOsAndVersion;
573 char ch;
574 for (const char *pszVersion = pszOsAndVersion; (ch = *pszVersion) != '\0'; pszVersion++)
575 if (RT_C_IS_DIGIT(ch))
576 {
577 *ppszNext = pszVersion;
578 break;
579 }
580 }
581 return fRet;
582}
583
584
585/**
586 * Detect Linux distro ISOs.
587 *
588 * @returns COM status code.
589 * @retval S_OK if detected
590 * @retval S_FALSE if not fully detected.
591 *
592 * @param hVfsIso The ISO file system.
593 * @param pBuf Read buffer.
594 * @param penmOsType Where to return the OS type. This is initialized to
595 * VBOXOSTYPE_Unknown.
596 */
597HRESULT Unattended::i_innerDetectIsoOSLinux(RTVFS hVfsIso, DETECTBUFFER *pBuf, VBOXOSTYPE *penmOsType)
598{
599 /*
600 * Redhat and derivatives may have a .treeinfo (ini-file style) with useful info
601 * or at least a barebone .discinfo file.
602 */
603
604 /*
605 * Start with .treeinfo: https://release-engineering.github.io/productmd/treeinfo-1.0.html
606 */
607 RTVFSFILE hVfsFile;
608 int vrc = RTVfsFileOpen(hVfsIso, ".treeinfo", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
609 if (RT_SUCCESS(vrc))
610 {
611 RTINIFILE hIniFile;
612 vrc = RTIniFileCreateFromVfsFile(&hIniFile, hVfsFile, RTINIFILE_F_READONLY);
613 RTVfsFileRelease(hVfsFile);
614 if (RT_SUCCESS(vrc))
615 {
616 /* Try figure the architecture first (like with windows). */
617 vrc = RTIniFileQueryValue(hIniFile, "tree", "arch", pBuf->sz, sizeof(*pBuf), NULL);
618 if (RT_FAILURE(vrc) || !pBuf->sz[0])
619 vrc = RTIniFileQueryValue(hIniFile, "general", "arch", pBuf->sz, sizeof(*pBuf), NULL);
620 if (RT_SUCCESS(vrc))
621 {
622 LogRelFlow(("Unattended: .treeinfo: arch=%s\n", pBuf->sz));
623 if (!detectLinuxArch(pBuf->sz, penmOsType, VBOXOSTYPE_RedHat))
624 LogRel(("Unattended: .treeinfo: Unknown: arch='%s'\n", pBuf->sz));
625 }
626 else
627 LogRel(("Unattended: .treeinfo: No 'arch' property.\n"));
628
629 /* Try figure the release name, it doesn't have to be redhat. */
630 vrc = RTIniFileQueryValue(hIniFile, "release", "name", pBuf->sz, sizeof(*pBuf), NULL);
631 if (RT_FAILURE(vrc) || !pBuf->sz[0])
632 vrc = RTIniFileQueryValue(hIniFile, "product", "name", pBuf->sz, sizeof(*pBuf), NULL);
633 if (RT_FAILURE(vrc) || !pBuf->sz[0])
634 vrc = RTIniFileQueryValue(hIniFile, "general", "family", pBuf->sz, sizeof(*pBuf), NULL);
635 if (RT_SUCCESS(vrc))
636 {
637 LogRelFlow(("Unattended: .treeinfo: name/family=%s\n", pBuf->sz));
638 if (!detectLinuxDistroName(pBuf->sz, penmOsType, NULL))
639 {
640 LogRel(("Unattended: .treeinfo: Unknown: name/family='%s', assuming Red Hat\n", pBuf->sz));
641 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_RedHat);
642 }
643 }
644
645 /* Try figure the version. */
646 vrc = RTIniFileQueryValue(hIniFile, "release", "version", pBuf->sz, sizeof(*pBuf), NULL);
647 if (RT_FAILURE(vrc) || !pBuf->sz[0])
648 vrc = RTIniFileQueryValue(hIniFile, "product", "version", pBuf->sz, sizeof(*pBuf), NULL);
649 if (RT_FAILURE(vrc) || !pBuf->sz[0])
650 vrc = RTIniFileQueryValue(hIniFile, "general", "version", pBuf->sz, sizeof(*pBuf), NULL);
651 if (RT_SUCCESS(vrc))
652 {
653 LogRelFlow(("Unattended: .treeinfo: version=%s\n", pBuf->sz));
654 try { mStrDetectedOSVersion = RTStrStrip(pBuf->sz); }
655 catch (std::bad_alloc) { return E_OUTOFMEMORY; }
656 }
657
658 RTIniFileRelease(hIniFile);
659 }
660
661 if (*penmOsType != VBOXOSTYPE_Unknown)
662 return S_FALSE;
663 }
664
665 /*
666 * Try .discinfo next: https://release-engineering.github.io/productmd/discinfo-1.0.html
667 * We will probably need additional info here...
668 */
669 vrc = RTVfsFileOpen(hVfsIso, ".discinfo", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
670 if (RT_SUCCESS(vrc))
671 {
672 RT_ZERO(*pBuf);
673 size_t cchIgn;
674 RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(*pBuf) - 1, &cchIgn);
675 pBuf->sz[sizeof(*pBuf) - 1] = '\0';
676 RTVfsFileRelease(hVfsFile);
677
678 /* Parse and strip the first 5 lines. */
679 const char *apszLines[5];
680 char *psz = pBuf->sz;
681 for (unsigned i = 0; i < RT_ELEMENTS(apszLines); i++)
682 {
683 apszLines[i] = psz;
684 if (*psz)
685 {
686 char *pszEol = (char *)strchr(psz, '\n');
687 if (!pszEol)
688 psz = strchr(psz, '\0');
689 else
690 {
691 *pszEol = '\0';
692 apszLines[i] = RTStrStrip(psz);
693 psz = pszEol + 1;
694 }
695 }
696 }
697
698 /* Do we recognize the architecture? */
699 LogRelFlow(("Unattended: .discinfo: arch=%s\n", apszLines[2]));
700 if (!detectLinuxArch(apszLines[2], penmOsType, VBOXOSTYPE_RedHat))
701 LogRel(("Unattended: .discinfo: Unknown: arch='%s'\n", apszLines[2]));
702
703 /* Do we recognize the release string? */
704 LogRelFlow(("Unattended: .discinfo: product+version=%s\n", apszLines[1]));
705 const char *pszVersion = NULL;
706 if (!detectLinuxDistroName(apszLines[1], penmOsType, &pszVersion))
707 LogRel(("Unattended: .discinfo: Unknown: release='%s'\n", apszLines[1]));
708
709 if (*pszVersion)
710 {
711 LogRelFlow(("Unattended: .discinfo: version=%s\n", pszVersion));
712 try { mStrDetectedOSVersion = RTStrStripL(pszVersion); }
713 catch (std::bad_alloc) { return E_OUTOFMEMORY; }
714
715 /* CentOS likes to call their release 'Final' without mentioning the actual version
716 number (e.g. CentOS-4.7-x86_64-binDVD.iso), so we need to go look elsewhere.
717 This is only important for centos 4.x and 3.x releases. */
718 if (RTStrNICmp(pszVersion, RT_STR_TUPLE("Final")) == 0)
719 {
720 static const char * const s_apszDirs[] = { "CentOS/RPMS/", "RedHat/RPMS", "Server", "Workstation" };
721 for (unsigned iDir = 0; iDir < RT_ELEMENTS(s_apszDirs); iDir++)
722 {
723 RTVFSDIR hVfsDir;
724 vrc = RTVfsDirOpen(hVfsIso, s_apszDirs[iDir], 0, &hVfsDir);
725 if (RT_FAILURE(vrc))
726 continue;
727 char szRpmDb[128];
728 char szReleaseRpm[128];
729 szRpmDb[0] = '\0';
730 szReleaseRpm[0] = '\0';
731 for (;;)
732 {
733 RTDIRENTRYEX DirEntry;
734 size_t cbDirEntry = sizeof(DirEntry);
735 vrc = RTVfsDirReadEx(hVfsDir, &DirEntry, &cbDirEntry, RTFSOBJATTRADD_NOTHING);
736 if (RT_FAILURE(vrc))
737 break;
738
739 /* redhat-release-4WS-2.4.i386.rpm
740 centos-release-4-7.x86_64.rpm, centos-release-4-4.3.i386.rpm
741 centos-release-5-3.el5.centos.1.x86_64.rpm */
742 char *psz;
743 if ( (psz = strstr(DirEntry.szName, "-release-")) != NULL
744 || (psz = strstr(DirEntry.szName, "-RELEASE-")) != NULL)
745 {
746 psz += 9;
747 if (RT_C_IS_DIGIT(*psz))
748 RTStrCopy(szReleaseRpm, sizeof(szReleaseRpm), psz);
749 }
750 /* rpmdb-redhat-4WS-2.4.i386.rpm,
751 rpmdb-CentOS-4.5-0.20070506.i386.rpm,
752 rpmdb-redhat-3.9-0.20070703.i386.rpm. */
753 else if ( ( RTStrStartsWith(DirEntry.szName, "rpmdb-")
754 || RTStrStartsWith(DirEntry.szName, "RPMDB-"))
755 && RT_C_IS_DIGIT(DirEntry.szName[6]) )
756 RTStrCopy(szRpmDb, sizeof(szRpmDb), &DirEntry.szName[6]);
757 }
758 RTVfsDirRelease(hVfsDir);
759
760 /* Did we find anything relvant? */
761 char *pszVersion = szRpmDb;
762 if (!RT_C_IS_DIGIT(*pszVersion))
763 pszVersion = szReleaseRpm;
764 if (RT_C_IS_DIGIT(*pszVersion))
765 {
766 /* Convert '-' to '.' and strip stuff which doesn't look like a version string. */
767 char *pszCur = pszVersion + 1;
768 for (char ch = *pszCur; ch != '\0'; ch = *++pszCur)
769 if (ch == '-')
770 *pszCur = '.';
771 else if (ch != '.' && !RT_C_IS_DIGIT(ch))
772 {
773 *pszCur = '\0';
774 break;
775 }
776 while (&pszCur[-1] != pszVersion && pszCur[-1] == '.')
777 *--pszCur = '\0';
778
779 /* Set it and stop looking. */
780 try { mStrDetectedOSVersion = pszVersion; }
781 catch (std::bad_alloc) { return E_OUTOFMEMORY; }
782 break;
783 }
784 }
785 }
786 }
787
788 if (*penmOsType != VBOXOSTYPE_Unknown)
789 return S_FALSE;
790 }
791
792 return S_FALSE;
793}
794
795
796HRESULT Unattended::prepare()
797{
798 LogFlow(("Unattended::prepare: enter\n"));
799
800 /*
801 * Must have a machine.
802 */
803 ComPtr<Machine> ptrMachine;
804 Guid MachineUuid;
805 {
806 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
807 ptrMachine = mMachine;
808 if (ptrMachine.isNull())
809 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("No machine associated with this IUnatteded instance"));
810 MachineUuid = mMachineUuid;
811 }
812
813 /*
814 * Before we write lock ourselves, we must get stuff from Machine and
815 * VirtualBox because their locks have higher priorities than ours.
816 */
817 Utf8Str strGuestOsTypeId;
818 Utf8Str strMachineName;
819 Utf8Str strDefaultAuxBasePath;
820 HRESULT hrc;
821 try
822 {
823 Bstr bstrTmp;
824 hrc = ptrMachine->COMGETTER(OSTypeId)(bstrTmp.asOutParam());
825 if (SUCCEEDED(hrc))
826 {
827 strGuestOsTypeId = bstrTmp;
828 hrc = ptrMachine->COMGETTER(Name)(bstrTmp.asOutParam());
829 if (SUCCEEDED(hrc))
830 strMachineName = bstrTmp;
831 }
832 int vrc = ptrMachine->i_calculateFullPath(Utf8StrFmt("Unattended-%RTuuid-", MachineUuid.raw()), strDefaultAuxBasePath);
833 if (RT_FAILURE(vrc))
834 return setErrorBoth(E_FAIL, vrc);
835 }
836 catch (std::bad_alloc)
837 {
838 return E_OUTOFMEMORY;
839 }
840 bool const fIs64Bit = i_isGuestOSArchX64(strGuestOsTypeId);
841
842 BOOL fRtcUseUtc = FALSE;
843 hrc = ptrMachine->COMGETTER(RTCUseUTC)(&fRtcUseUtc);
844 if (FAILED(hrc))
845 return hrc;
846
847 /*
848 * Write lock this object and set attributes we got from IMachine.
849 */
850 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
851
852 mStrGuestOsTypeId = strGuestOsTypeId;
853 mfGuestOs64Bit = fIs64Bit;
854 mfRtcUseUtc = RT_BOOL(fRtcUseUtc);
855
856 /*
857 * Do some state checks.
858 */
859 if (mpInstaller != NULL)
860 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("The prepare method has been called (must call done to restart)"));
861 if ((Machine *)ptrMachine != (Machine *)mMachine)
862 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("The 'machine' while we were using it - please don't do that"));
863
864 /*
865 * Check if the specified ISOs and files exist.
866 */
867 if (!RTFileExists(mStrIsoPath.c_str()))
868 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the installation ISO file '%s'"),
869 mStrIsoPath.c_str());
870 if (mfInstallGuestAdditions && !RTFileExists(mStrAdditionsIsoPath.c_str()))
871 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the guest additions ISO file '%s'"),
872 mStrAdditionsIsoPath.c_str());
873 if (mfInstallTestExecService && !RTFileExists(mStrValidationKitIsoPath.c_str()))
874 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the validation kit ISO file '%s'"),
875 mStrValidationKitIsoPath.c_str());
876 if (mStrScriptTemplatePath.isNotEmpty() && !RTFileExists(mStrScriptTemplatePath.c_str()))
877 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate unattended installation script template '%s'"),
878 mStrScriptTemplatePath.c_str());
879
880 /*
881 * Do media detection if it haven't been done yet.
882 */
883 if (!mfDoneDetectIsoOS)
884 {
885 hrc = detectIsoOS();
886 if (FAILED(hrc) && hrc != E_NOTIMPL)
887 return hrc;
888 }
889
890 /*
891 * Do some default property stuff and check other properties.
892 */
893 try
894 {
895 char szTmp[128];
896
897 if (mStrLocale.isEmpty())
898 {
899 int vrc = RTLocaleQueryNormalizedBaseLocaleName(szTmp, sizeof(szTmp));
900 if ( RT_SUCCESS(vrc)
901 && RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(szTmp))
902 mStrLocale.assign(szTmp, 5);
903 else
904 mStrLocale = "en_US";
905 Assert(RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(mStrLocale));
906 }
907
908 if (mStrLanguage.isEmpty())
909 {
910 if (mDetectedOSLanguages.size() > 0)
911 mStrLanguage = mDetectedOSLanguages[0];
912 else
913 mStrLanguage.assign(mStrLocale).findReplace('_', '-');
914 }
915
916 if (mStrCountry.isEmpty())
917 {
918 int vrc = RTLocaleQueryUserCountryCode(szTmp);
919 if (RT_SUCCESS(vrc))
920 mStrCountry = szTmp;
921 else if ( mStrLocale.isNotEmpty()
922 && RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(mStrLocale))
923 mStrCountry.assign(mStrLocale, 3, 2);
924 else
925 mStrCountry = "US";
926 }
927
928 if (mStrTimeZone.isEmpty())
929 {
930 int vrc = RTTimeZoneGetCurrent(szTmp, sizeof(szTmp));
931 if (RT_SUCCESS(vrc))
932 mStrTimeZone = szTmp;
933 else
934 mStrTimeZone = "Etc/UTC";
935 Assert(mStrTimeZone.isNotEmpty());
936 }
937 mpTimeZoneInfo = RTTimeZoneGetInfoByUnixName(mStrTimeZone.c_str());
938 if (!mpTimeZoneInfo)
939 mpTimeZoneInfo = RTTimeZoneGetInfoByWindowsName(mStrTimeZone.c_str());
940 Assert(mpTimeZoneInfo || mStrTimeZone != "Etc/UTC");
941 if (!mpTimeZoneInfo)
942 LogRel(("Unattended::prepare: warning: Unknown time zone '%s'\n", mStrTimeZone.c_str()));
943
944 if (mStrHostname.isEmpty())
945 {
946 /* Mangle the VM name into a valid hostname. */
947 for (size_t i = 0; i < strMachineName.length(); i++)
948 {
949 char ch = strMachineName[i];
950 if ( (unsigned)ch < 127
951 && RT_C_IS_ALNUM(ch))
952 mStrHostname.append(ch);
953 else if (mStrHostname.isNotEmpty() && RT_C_IS_PUNCT(ch) && !mStrHostname.endsWith("-"))
954 mStrHostname.append('-');
955 }
956 if (mStrHostname.length() == 0)
957 mStrHostname.printf("%RTuuid-vm", MachineUuid.raw());
958 else if (mStrHostname.length() < 3)
959 mStrHostname.append("-vm");
960 mStrHostname.append(".myguest.virtualbox.org");
961 }
962
963 if (mStrAuxiliaryBasePath.isEmpty())
964 {
965 mStrAuxiliaryBasePath = strDefaultAuxBasePath;
966 mfIsDefaultAuxiliaryBasePath = true;
967 }
968 }
969 catch (std::bad_alloc)
970 {
971 return E_OUTOFMEMORY;
972 }
973
974 /*
975 * Get the guest OS type info and instantiate the appropriate installer.
976 */
977 uint32_t const idxOSType = Global::getOSTypeIndexFromId(mStrGuestOsTypeId.c_str());
978 meGuestOsType = idxOSType < Global::cOSTypes ? Global::sOSTypes[idxOSType].osType : VBOXOSTYPE_Unknown;
979
980 mpInstaller = UnattendedInstaller::createInstance(meGuestOsType, mStrGuestOsTypeId, mStrDetectedOSVersion,
981 mStrDetectedOSFlavor, mStrDetectedOSHints, this);
982 if (mpInstaller != NULL)
983 {
984 hrc = mpInstaller->initInstaller();
985 if (SUCCEEDED(hrc))
986 {
987 /*
988 * Do the script preps (just reads them).
989 */
990 hrc = mpInstaller->prepareUnattendedScripts();
991 if (SUCCEEDED(hrc))
992 {
993 LogFlow(("Unattended::prepare: returns S_OK\n"));
994 return S_OK;
995 }
996 }
997
998 /* Destroy the installer instance. */
999 delete mpInstaller;
1000 mpInstaller = NULL;
1001 }
1002 else
1003 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND,
1004 tr("Unattended installation is not supported for guest type '%s'"), mStrGuestOsTypeId.c_str());
1005 LogRelFlow(("Unattended::prepare: failed with %Rhrc\n", hrc));
1006 return hrc;
1007}
1008
1009HRESULT Unattended::constructMedia()
1010{
1011 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1012
1013 LogFlow(("===========================================================\n"));
1014 LogFlow(("Call Unattended::constructMedia()\n"));
1015
1016 if (mpInstaller == NULL)
1017 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, "prepare() not yet called");
1018
1019 return mpInstaller->prepareMedia();
1020}
1021
1022HRESULT Unattended::reconfigureVM()
1023{
1024 LogFlow(("===========================================================\n"));
1025 LogFlow(("Call Unattended::reconfigureVM()\n"));
1026
1027 /*
1028 * Interrogate VirtualBox/IGuestOSType before we lock stuff and create ordering issues.
1029 */
1030 StorageBus_T enmRecommendedStorageBus = StorageBus_IDE;
1031 {
1032 Bstr bstrGuestOsTypeId;
1033 {
1034 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1035 bstrGuestOsTypeId = mStrGuestOsTypeId;
1036 }
1037 ComPtr<IGuestOSType> ptrGuestOSType;
1038 HRESULT hrc = mParent->GetGuestOSType(bstrGuestOsTypeId.raw(), ptrGuestOSType.asOutParam());
1039 if (SUCCEEDED(hrc))
1040 hrc = ptrGuestOSType->COMGETTER(RecommendedDVDStorageBus)(&enmRecommendedStorageBus);
1041 if (FAILED(hrc))
1042 return hrc;
1043 }
1044
1045 /*
1046 * Take write lock (for lock order reasons, write lock our parent object too)
1047 * then make sure we're the only caller of this method.
1048 */
1049 AutoMultiWriteLock2 alock(mMachine, this COMMA_LOCKVAL_SRC_POS);
1050 HRESULT hrc;
1051 if (mhThreadReconfigureVM == NIL_RTNATIVETHREAD)
1052 {
1053 RTNATIVETHREAD const hNativeSelf = RTThreadNativeSelf();
1054 mhThreadReconfigureVM = hNativeSelf;
1055
1056 /*
1057 * Create a new session, lock the machine and get the session machine object.
1058 * Do the locking without pinning down the write locks, just to be on the safe side.
1059 */
1060 ComPtr<ISession> ptrSession;
1061 try
1062 {
1063 hrc = ptrSession.createInprocObject(CLSID_Session);
1064 }
1065 catch (std::bad_alloc)
1066 {
1067 hrc = E_OUTOFMEMORY;
1068 }
1069 if (SUCCEEDED(hrc))
1070 {
1071 alock.release();
1072 hrc = mMachine->LockMachine(ptrSession, LockType_Shared);
1073 alock.acquire();
1074 if (SUCCEEDED(hrc))
1075 {
1076 ComPtr<IMachine> ptrSessionMachine;
1077 hrc = ptrSession->COMGETTER(Machine)(ptrSessionMachine.asOutParam());
1078 if (SUCCEEDED(hrc))
1079 {
1080 /*
1081 * Hand the session to the inner work and let it do it job.
1082 */
1083 try
1084 {
1085 hrc = i_innerReconfigureVM(alock, enmRecommendedStorageBus, ptrSessionMachine);
1086 }
1087 catch (...)
1088 {
1089 hrc = E_UNEXPECTED;
1090 }
1091 }
1092
1093 /* Paranoia: release early in case we it a bump below. */
1094 Assert(mhThreadReconfigureVM == hNativeSelf);
1095 mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
1096
1097 /*
1098 * While unlocking the machine we'll have to drop the locks again.
1099 */
1100 alock.release();
1101
1102 ptrSessionMachine.setNull();
1103 HRESULT hrc2 = ptrSession->UnlockMachine();
1104 AssertLogRelMsg(SUCCEEDED(hrc2), ("UnlockMachine -> %Rhrc\n", hrc2));
1105
1106 ptrSession.setNull();
1107
1108 alock.acquire();
1109 }
1110 else
1111 mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
1112 }
1113 else
1114 mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
1115 }
1116 else
1117 hrc = setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("reconfigureVM running on other thread"));
1118 return hrc;
1119}
1120
1121
1122HRESULT Unattended::i_innerReconfigureVM(AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus,
1123 ComPtr<IMachine> const &rPtrSessionMachine)
1124{
1125 if (mpInstaller == NULL)
1126 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, "prepare() not yet called");
1127
1128 // Fetch all available storage controllers
1129 com::SafeIfaceArray<IStorageController> arrayOfControllers;
1130 HRESULT hrc = rPtrSessionMachine->COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(arrayOfControllers));
1131 AssertComRCReturn(hrc, hrc);
1132
1133 /*
1134 * Figure out where the images are to be mounted, adding controllers/ports as needed.
1135 */
1136 std::vector<UnattendedInstallationDisk> vecInstallationDisks;
1137 if (mpInstaller->isAuxiliaryFloppyNeeded())
1138 {
1139 hrc = i_reconfigureFloppy(arrayOfControllers, vecInstallationDisks, rPtrSessionMachine, rAutoLock);
1140 if (FAILED(hrc))
1141 return hrc;
1142 }
1143
1144 hrc = i_reconfigureIsos(arrayOfControllers, vecInstallationDisks, rPtrSessionMachine, rAutoLock, enmRecommendedStorageBus);
1145 if (FAILED(hrc))
1146 return hrc;
1147
1148 /*
1149 * Mount the images.
1150 */
1151 for (size_t idxImage = 0; idxImage < vecInstallationDisks.size(); idxImage++)
1152 {
1153 UnattendedInstallationDisk const *pImage = &vecInstallationDisks.at(idxImage);
1154 Assert(pImage->strImagePath.isNotEmpty());
1155 hrc = i_attachImage(pImage, rPtrSessionMachine, rAutoLock);
1156 if (FAILED(hrc))
1157 return hrc;
1158 }
1159
1160 /*
1161 * Set the boot order.
1162 *
1163 * ASSUME that the HD isn't bootable when we start out, but it will be what
1164 * we boot from after the first stage of the installation is done. Setting
1165 * it first prevents endless reboot cylces.
1166 */
1167 /** @todo consider making 100% sure the disk isn't bootable (edit partition
1168 * table active bits and EFI stuff). */
1169 Assert( mpInstaller->getBootableDeviceType() == DeviceType_DVD
1170 || mpInstaller->getBootableDeviceType() == DeviceType_Floppy);
1171 hrc = rPtrSessionMachine->SetBootOrder(1, DeviceType_HardDisk);
1172 if (SUCCEEDED(hrc))
1173 hrc = rPtrSessionMachine->SetBootOrder(2, mpInstaller->getBootableDeviceType());
1174 if (SUCCEEDED(hrc))
1175 hrc = rPtrSessionMachine->SetBootOrder(3, mpInstaller->getBootableDeviceType() == DeviceType_DVD
1176 ? (DeviceType_T)DeviceType_Floppy : (DeviceType_T)DeviceType_DVD);
1177 if (FAILED(hrc))
1178 return hrc;
1179
1180 /*
1181 * Essential step.
1182 *
1183 * HACK ALERT! We have to release the lock here or we'll get into trouble with
1184 * the VirtualBox lock (via i_saveHardware/NetworkAdaptger::i_hasDefaults/VirtualBox::i_findGuestOSType).
1185 */
1186 if (SUCCEEDED(hrc))
1187 {
1188 rAutoLock.release();
1189 hrc = rPtrSessionMachine->SaveSettings();
1190 rAutoLock.acquire();
1191 }
1192
1193 return hrc;
1194}
1195
1196/**
1197 * Makes sure we've got a floppy drive attached to a floppy controller, adding
1198 * the auxiliary floppy image to the installation disk vector.
1199 *
1200 * @returns COM status code.
1201 * @param rControllers The existing controllers.
1202 * @param rVecInstallatationDisks The list of image to mount.
1203 * @param rPtrSessionMachine The session machine smart pointer.
1204 * @param rAutoLock The lock.
1205 */
1206HRESULT Unattended::i_reconfigureFloppy(com::SafeIfaceArray<IStorageController> &rControllers,
1207 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
1208 ComPtr<IMachine> const &rPtrSessionMachine,
1209 AutoMultiWriteLock2 &rAutoLock)
1210{
1211 Assert(mpInstaller->isAuxiliaryFloppyNeeded());
1212
1213 /*
1214 * Look for a floppy controller with a primary drive (A:) we can "insert"
1215 * the auxiliary floppy image. Add a controller and/or a drive if necessary.
1216 */
1217 bool fFoundPort0Dev0 = false;
1218 Bstr bstrControllerName;
1219 Utf8Str strControllerName;
1220
1221 for (size_t i = 0; i < rControllers.size(); ++i)
1222 {
1223 StorageBus_T enmStorageBus;
1224 HRESULT hrc = rControllers[i]->COMGETTER(Bus)(&enmStorageBus);
1225 AssertComRCReturn(hrc, hrc);
1226 if (enmStorageBus == StorageBus_Floppy)
1227 {
1228
1229 /*
1230 * Found a floppy controller.
1231 */
1232 hrc = rControllers[i]->COMGETTER(Name)(bstrControllerName.asOutParam());
1233 AssertComRCReturn(hrc, hrc);
1234
1235 /*
1236 * Check the attchments to see if we've got a device 0 attached on port 0.
1237 *
1238 * While we're at it we eject flppies from all floppy drives we encounter,
1239 * we don't want any confusion at boot or during installation.
1240 */
1241 com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
1242 hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(bstrControllerName.raw(),
1243 ComSafeArrayAsOutParam(arrayOfMediumAttachments));
1244 AssertComRCReturn(hrc, hrc);
1245 strControllerName = bstrControllerName;
1246 AssertLogRelReturn(strControllerName.isNotEmpty(), setErrorBoth(E_UNEXPECTED, VERR_INTERNAL_ERROR_2));
1247
1248 for (size_t j = 0; j < arrayOfMediumAttachments.size(); j++)
1249 {
1250 LONG iPort = -1;
1251 hrc = arrayOfMediumAttachments[j]->COMGETTER(Port)(&iPort);
1252 AssertComRCReturn(hrc, hrc);
1253
1254 LONG iDevice = -1;
1255 hrc = arrayOfMediumAttachments[j]->COMGETTER(Device)(&iDevice);
1256 AssertComRCReturn(hrc, hrc);
1257
1258 DeviceType_T enmType;
1259 hrc = arrayOfMediumAttachments[j]->COMGETTER(Type)(&enmType);
1260 AssertComRCReturn(hrc, hrc);
1261
1262 if (enmType == DeviceType_Floppy)
1263 {
1264 ComPtr<IMedium> ptrMedium;
1265 hrc = arrayOfMediumAttachments[j]->COMGETTER(Medium)(ptrMedium.asOutParam());
1266 AssertComRCReturn(hrc, hrc);
1267
1268 if (ptrMedium.isNotNull())
1269 {
1270 ptrMedium.setNull();
1271 rAutoLock.release();
1272 hrc = rPtrSessionMachine->UnmountMedium(bstrControllerName.raw(), iPort, iDevice, TRUE /*fForce*/);
1273 rAutoLock.acquire();
1274 }
1275
1276 if (iPort == 0 && iDevice == 0)
1277 fFoundPort0Dev0 = true;
1278 }
1279 else if (iPort == 0 && iDevice == 0)
1280 return setError(E_FAIL,
1281 tr("Found non-floppy device attached to port 0 device 0 on the floppy controller '%ls'"),
1282 bstrControllerName.raw());
1283 }
1284 }
1285 }
1286
1287 /*
1288 * Add a floppy controller if we need to.
1289 */
1290 if (strControllerName.isEmpty())
1291 {
1292 bstrControllerName = strControllerName = "Floppy";
1293 ComPtr<IStorageController> ptrControllerIgnored;
1294 HRESULT hrc = rPtrSessionMachine->AddStorageController(bstrControllerName.raw(), StorageBus_Floppy,
1295 ptrControllerIgnored.asOutParam());
1296 LogRelFunc(("Machine::addStorageController(Floppy) -> %Rhrc \n", hrc));
1297 if (FAILED(hrc))
1298 return hrc;
1299 }
1300
1301 /*
1302 * Adding a floppy drive (if needed) and mounting the auxiliary image is
1303 * done later together with the ISOs.
1304 */
1305 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(StorageBus_Floppy, strControllerName,
1306 DeviceType_Floppy, AccessMode_ReadWrite,
1307 0, 0,
1308 fFoundPort0Dev0 /*fMountOnly*/,
1309 mpInstaller->getAuxiliaryFloppyFilePath()));
1310 return S_OK;
1311}
1312
1313/**
1314 * Reconfigures DVD drives of the VM to mount all the ISOs we need.
1315 *
1316 * This will umount all DVD media.
1317 *
1318 * @returns COM status code.
1319 * @param rControllers The existing controllers.
1320 * @param rVecInstallatationDisks The list of image to mount.
1321 * @param rPtrSessionMachine The session machine smart pointer.
1322 * @param rAutoLock The lock.
1323 * @param enmRecommendedStorageBus The recommended storage bus type for adding
1324 * DVD drives on.
1325 */
1326HRESULT Unattended::i_reconfigureIsos(com::SafeIfaceArray<IStorageController> &rControllers,
1327 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
1328 ComPtr<IMachine> const &rPtrSessionMachine,
1329 AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus)
1330{
1331 /*
1332 * Enumerate the attachements of every controller, looking for DVD drives,
1333 * ASSUMEING all drives are bootable.
1334 *
1335 * Eject the medium from all the drives (don't want any confusion) and look
1336 * for the recommended storage bus in case we need to add more drives.
1337 */
1338 HRESULT hrc;
1339 std::list<ControllerSlot> lstControllerDvdSlots;
1340 Utf8Str strRecommendedControllerName; /* non-empty if recommended bus found. */
1341 Utf8Str strControllerName;
1342 Bstr bstrControllerName;
1343 for (size_t i = 0; i < rControllers.size(); ++i)
1344 {
1345 hrc = rControllers[i]->COMGETTER(Name)(bstrControllerName.asOutParam());
1346 AssertComRCReturn(hrc, hrc);
1347 strControllerName = bstrControllerName;
1348
1349 /* Look for recommended storage bus. */
1350 StorageBus_T enmStorageBus;
1351 hrc = rControllers[i]->COMGETTER(Bus)(&enmStorageBus);
1352 AssertComRCReturn(hrc, hrc);
1353 if (enmStorageBus == enmRecommendedStorageBus)
1354 {
1355 strRecommendedControllerName = bstrControllerName;
1356 AssertLogRelReturn(strControllerName.isNotEmpty(), setErrorBoth(E_UNEXPECTED, VERR_INTERNAL_ERROR_2));
1357 }
1358
1359 /* Scan the controller attachments. */
1360 com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
1361 hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(bstrControllerName.raw(),
1362 ComSafeArrayAsOutParam(arrayOfMediumAttachments));
1363 AssertComRCReturn(hrc, hrc);
1364
1365 for (size_t j = 0; j < arrayOfMediumAttachments.size(); j++)
1366 {
1367 DeviceType_T enmType;
1368 hrc = arrayOfMediumAttachments[j]->COMGETTER(Type)(&enmType);
1369 AssertComRCReturn(hrc, hrc);
1370 if (enmType == DeviceType_DVD)
1371 {
1372 LONG iPort = -1;
1373 hrc = arrayOfMediumAttachments[j]->COMGETTER(Port)(&iPort);
1374 AssertComRCReturn(hrc, hrc);
1375
1376 LONG iDevice = -1;
1377 hrc = arrayOfMediumAttachments[j]->COMGETTER(Device)(&iDevice);
1378 AssertComRCReturn(hrc, hrc);
1379
1380 /* Remeber it. */
1381 lstControllerDvdSlots.push_back(ControllerSlot(enmStorageBus, strControllerName, iPort, iDevice, false /*fFree*/));
1382
1383 /* Eject the medium, if any. */
1384 ComPtr<IMedium> ptrMedium;
1385 hrc = arrayOfMediumAttachments[j]->COMGETTER(Medium)(ptrMedium.asOutParam());
1386 AssertComRCReturn(hrc, hrc);
1387 if (ptrMedium.isNotNull())
1388 {
1389 ptrMedium.setNull();
1390
1391 rAutoLock.release();
1392 hrc = rPtrSessionMachine->UnmountMedium(bstrControllerName.raw(), iPort, iDevice, TRUE /*fForce*/);
1393 rAutoLock.acquire();
1394 }
1395 }
1396 }
1397 }
1398
1399 /*
1400 * How many drives do we need? Add more if necessary.
1401 */
1402 ULONG cDvdDrivesNeeded = 0;
1403 if (mpInstaller->isAuxiliaryIsoNeeded())
1404 cDvdDrivesNeeded++;
1405 if (mpInstaller->isOriginalIsoNeeded())
1406 cDvdDrivesNeeded++;
1407#if 0 /* These are now in the AUX VISO. */
1408 if (mpInstaller->isAdditionsIsoNeeded())
1409 cDvdDrivesNeeded++;
1410 if (mpInstaller->isValidationKitIsoNeeded())
1411 cDvdDrivesNeeded++;
1412#endif
1413 Assert(cDvdDrivesNeeded > 0);
1414 if (cDvdDrivesNeeded > lstControllerDvdSlots.size())
1415 {
1416 /* Do we need to add the recommended controller? */
1417 if (strRecommendedControllerName.isEmpty())
1418 {
1419 switch (enmRecommendedStorageBus)
1420 {
1421 case StorageBus_IDE: strRecommendedControllerName = "IDE"; break;
1422 case StorageBus_SATA: strRecommendedControllerName = "SATA"; break;
1423 case StorageBus_SCSI: strRecommendedControllerName = "SCSI"; break;
1424 case StorageBus_SAS: strRecommendedControllerName = "SAS"; break;
1425 case StorageBus_USB: strRecommendedControllerName = "USB"; break;
1426 case StorageBus_PCIe: strRecommendedControllerName = "PCIe"; break;
1427 default:
1428 return setError(E_FAIL, tr("Support for recommended storage bus %d not implemented"),
1429 (int)enmRecommendedStorageBus);
1430 }
1431 ComPtr<IStorageController> ptrControllerIgnored;
1432 hrc = rPtrSessionMachine->AddStorageController(Bstr(strRecommendedControllerName).raw(), enmRecommendedStorageBus,
1433 ptrControllerIgnored.asOutParam());
1434 LogRelFunc(("Machine::addStorageController(%s) -> %Rhrc \n", strRecommendedControllerName.c_str(), hrc));
1435 if (FAILED(hrc))
1436 return hrc;
1437 }
1438
1439 /* Add free controller slots, maybe raising the port limit on the controller if we can. */
1440 hrc = i_findOrCreateNeededFreeSlots(strRecommendedControllerName, enmRecommendedStorageBus, rPtrSessionMachine,
1441 cDvdDrivesNeeded, lstControllerDvdSlots);
1442 if (FAILED(hrc))
1443 return hrc;
1444 if (cDvdDrivesNeeded > lstControllerDvdSlots.size())
1445 {
1446 /* We could in many cases create another controller here, but it's not worth the effort. */
1447 return setError(E_FAIL, tr("Not enough free slots on controller '%s' to add %u DVD drive(s)"),
1448 strRecommendedControllerName.c_str(), cDvdDrivesNeeded - lstControllerDvdSlots.size());
1449 }
1450 Assert(cDvdDrivesNeeded == lstControllerDvdSlots.size());
1451 }
1452
1453 /*
1454 * Sort the DVD slots in boot order.
1455 */
1456 lstControllerDvdSlots.sort();
1457
1458 /*
1459 * Prepare ISO mounts.
1460 *
1461 * Boot order depends on bootFromAuxiliaryIso() and we must grab DVD slots
1462 * according to the boot order.
1463 */
1464 std::list<ControllerSlot>::const_iterator itDvdSlot = lstControllerDvdSlots.begin();
1465 if (mpInstaller->isAuxiliaryIsoNeeded() && mpInstaller->bootFromAuxiliaryIso())
1466 {
1467 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath()));
1468 ++itDvdSlot;
1469 }
1470
1471 if (mpInstaller->isOriginalIsoNeeded())
1472 {
1473 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getIsoPath()));
1474 ++itDvdSlot;
1475 }
1476
1477 if (mpInstaller->isAuxiliaryIsoNeeded() && !mpInstaller->bootFromAuxiliaryIso())
1478 {
1479 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath()));
1480 ++itDvdSlot;
1481 }
1482
1483#if 0 /* These are now in the AUX VISO. */
1484 if (mpInstaller->isAdditionsIsoNeeded())
1485 {
1486 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getAdditionsIsoPath()));
1487 ++itDvdSlot;
1488 }
1489
1490 if (mpInstaller->isValidationKitIsoNeeded())
1491 {
1492 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getValidationKitIsoPath()));
1493 ++itDvdSlot;
1494 }
1495#endif
1496
1497 return S_OK;
1498}
1499
1500/**
1501 * Used to find more free slots for DVD drives during VM reconfiguration.
1502 *
1503 * This may modify the @a portCount property of the given controller.
1504 *
1505 * @returns COM status code.
1506 * @param rStrControllerName The name of the controller to find/create
1507 * free slots on.
1508 * @param enmStorageBus The storage bus type.
1509 * @param rPtrSessionMachine Reference to the session machine.
1510 * @param cSlotsNeeded Total slots needed (including those we've
1511 * already found).
1512 * @param rDvdSlots The slot collection for DVD drives to add
1513 * free slots to as we find/create them.
1514 */
1515HRESULT Unattended::i_findOrCreateNeededFreeSlots(const Utf8Str &rStrControllerName, StorageBus_T enmStorageBus,
1516 ComPtr<IMachine> const &rPtrSessionMachine, uint32_t cSlotsNeeded,
1517 std::list<ControllerSlot> &rDvdSlots)
1518{
1519 Assert(cSlotsNeeded > rDvdSlots.size());
1520
1521 /*
1522 * Get controlleer stats.
1523 */
1524 ComPtr<IStorageController> pController;
1525 HRESULT hrc = rPtrSessionMachine->GetStorageControllerByName(Bstr(rStrControllerName).raw(), pController.asOutParam());
1526 AssertComRCReturn(hrc, hrc);
1527
1528 ULONG cMaxDevicesPerPort = 1;
1529 hrc = pController->COMGETTER(MaxDevicesPerPortCount)(&cMaxDevicesPerPort);
1530 AssertComRCReturn(hrc, hrc);
1531 AssertLogRelReturn(cMaxDevicesPerPort > 0, E_UNEXPECTED);
1532
1533 ULONG cPorts = 0;
1534 hrc = pController->COMGETTER(PortCount)(&cPorts);
1535 AssertComRCReturn(hrc, hrc);
1536
1537 /*
1538 * Get the attachment list and turn into an internal list for lookup speed.
1539 */
1540 com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
1541 hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(Bstr(rStrControllerName).raw(),
1542 ComSafeArrayAsOutParam(arrayOfMediumAttachments));
1543 AssertComRCReturn(hrc, hrc);
1544
1545 std::vector<ControllerSlot> arrayOfUsedSlots;
1546 for (size_t i = 0; i < arrayOfMediumAttachments.size(); i++)
1547 {
1548 LONG iPort = -1;
1549 hrc = arrayOfMediumAttachments[i]->COMGETTER(Port)(&iPort);
1550 AssertComRCReturn(hrc, hrc);
1551
1552 LONG iDevice = -1;
1553 hrc = arrayOfMediumAttachments[i]->COMGETTER(Device)(&iDevice);
1554 AssertComRCReturn(hrc, hrc);
1555
1556 arrayOfUsedSlots.push_back(ControllerSlot(enmStorageBus, Utf8Str::Empty, iPort, iDevice, false /*fFree*/));
1557 }
1558
1559 /*
1560 * Iterate thru all possible slots, adding those not found in arrayOfUsedSlots.
1561 */
1562 for (uint32_t iPort = 0; iPort < cPorts; iPort++)
1563 for (uint32_t iDevice = 0; iDevice < cMaxDevicesPerPort; iDevice++)
1564 {
1565 bool fFound = false;
1566 for (size_t i = 0; i < arrayOfUsedSlots.size(); i++)
1567 if ( arrayOfUsedSlots[i].uPort == iPort
1568 && arrayOfUsedSlots[i].uDevice == iDevice)
1569 {
1570 fFound = true;
1571 break;
1572 }
1573 if (!fFound)
1574 {
1575 rDvdSlots.push_back(ControllerSlot(enmStorageBus, rStrControllerName, iPort, iDevice, true /*fFree*/));
1576 if (rDvdSlots.size() >= cSlotsNeeded)
1577 return S_OK;
1578 }
1579 }
1580
1581 /*
1582 * Okay we still need more ports. See if increasing the number of controller
1583 * ports would solve it.
1584 */
1585 ULONG cMaxPorts = 1;
1586 hrc = pController->COMGETTER(MaxPortCount)(&cMaxPorts);
1587 AssertComRCReturn(hrc, hrc);
1588 if (cMaxPorts <= cPorts)
1589 return S_OK;
1590 size_t cNewPortsNeeded = (cSlotsNeeded - rDvdSlots.size() + cMaxDevicesPerPort - 1) / cMaxDevicesPerPort;
1591 if (cPorts + cNewPortsNeeded > cMaxPorts)
1592 return S_OK;
1593
1594 /*
1595 * Raise the port count and add the free slots we've just created.
1596 */
1597 hrc = pController->COMSETTER(PortCount)(cPorts + (ULONG)cNewPortsNeeded);
1598 AssertComRCReturn(hrc, hrc);
1599 for (uint32_t iPort = cPorts; iPort < cPorts + cNewPortsNeeded; iPort++)
1600 for (uint32_t iDevice = 0; iDevice < cMaxDevicesPerPort; iDevice++)
1601 {
1602 rDvdSlots.push_back(ControllerSlot(enmStorageBus, rStrControllerName, iPort, iDevice, true /*fFree*/));
1603 if (rDvdSlots.size() >= cSlotsNeeded)
1604 return S_OK;
1605 }
1606
1607 /* We should not get here! */
1608 AssertLogRelFailedReturn(E_UNEXPECTED);
1609}
1610
1611HRESULT Unattended::done()
1612{
1613 LogFlow(("Unattended::done\n"));
1614 if (mpInstaller)
1615 {
1616 LogRelFlow(("Unattended::done: Deleting installer object (%p)\n", mpInstaller));
1617 delete mpInstaller;
1618 mpInstaller = NULL;
1619 }
1620 return S_OK;
1621}
1622
1623HRESULT Unattended::getIsoPath(com::Utf8Str &isoPath)
1624{
1625 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1626 isoPath = mStrIsoPath;
1627 return S_OK;
1628}
1629
1630HRESULT Unattended::setIsoPath(const com::Utf8Str &isoPath)
1631{
1632 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1633 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1634 mStrIsoPath = isoPath;
1635 mfDoneDetectIsoOS = false;
1636 return S_OK;
1637}
1638
1639HRESULT Unattended::getUser(com::Utf8Str &user)
1640{
1641 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1642 user = mStrUser;
1643 return S_OK;
1644}
1645
1646
1647HRESULT Unattended::setUser(const com::Utf8Str &user)
1648{
1649 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1650 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1651 mStrUser = user;
1652 return S_OK;
1653}
1654
1655HRESULT Unattended::getPassword(com::Utf8Str &password)
1656{
1657 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1658 password = mStrPassword;
1659 return S_OK;
1660}
1661
1662HRESULT Unattended::setPassword(const com::Utf8Str &password)
1663{
1664 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1665 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1666 mStrPassword = password;
1667 return S_OK;
1668}
1669
1670HRESULT Unattended::getFullUserName(com::Utf8Str &fullUserName)
1671{
1672 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1673 fullUserName = mStrFullUserName;
1674 return S_OK;
1675}
1676
1677HRESULT Unattended::setFullUserName(const com::Utf8Str &fullUserName)
1678{
1679 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1680 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1681 mStrFullUserName = fullUserName;
1682 return S_OK;
1683}
1684
1685HRESULT Unattended::getProductKey(com::Utf8Str &productKey)
1686{
1687 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1688 productKey = mStrProductKey;
1689 return S_OK;
1690}
1691
1692HRESULT Unattended::setProductKey(const com::Utf8Str &productKey)
1693{
1694 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1695 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1696 mStrProductKey = productKey;
1697 return S_OK;
1698}
1699
1700HRESULT Unattended::getAdditionsIsoPath(com::Utf8Str &additionsIsoPath)
1701{
1702 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1703 additionsIsoPath = mStrAdditionsIsoPath;
1704 return S_OK;
1705}
1706
1707HRESULT Unattended::setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath)
1708{
1709 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1710 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1711 mStrAdditionsIsoPath = additionsIsoPath;
1712 return S_OK;
1713}
1714
1715HRESULT Unattended::getInstallGuestAdditions(BOOL *installGuestAdditions)
1716{
1717 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1718 *installGuestAdditions = mfInstallGuestAdditions;
1719 return S_OK;
1720}
1721
1722HRESULT Unattended::setInstallGuestAdditions(BOOL installGuestAdditions)
1723{
1724 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1725 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1726 mfInstallGuestAdditions = installGuestAdditions != FALSE;
1727 return S_OK;
1728}
1729
1730HRESULT Unattended::getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath)
1731{
1732 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1733 aValidationKitIsoPath = mStrValidationKitIsoPath;
1734 return S_OK;
1735}
1736
1737HRESULT Unattended::setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath)
1738{
1739 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1740 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1741 mStrValidationKitIsoPath = aValidationKitIsoPath;
1742 return S_OK;
1743}
1744
1745HRESULT Unattended::getInstallTestExecService(BOOL *aInstallTestExecService)
1746{
1747 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1748 *aInstallTestExecService = mfInstallTestExecService;
1749 return S_OK;
1750}
1751
1752HRESULT Unattended::setInstallTestExecService(BOOL aInstallTestExecService)
1753{
1754 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1755 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1756 mfInstallTestExecService = aInstallTestExecService != FALSE;
1757 return S_OK;
1758}
1759
1760HRESULT Unattended::getTimeZone(com::Utf8Str &aTimeZone)
1761{
1762 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1763 aTimeZone = mStrTimeZone;
1764 return S_OK;
1765}
1766
1767HRESULT Unattended::setTimeZone(const com::Utf8Str &aTimezone)
1768{
1769 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1770 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1771 mStrTimeZone = aTimezone;
1772 return S_OK;
1773}
1774
1775HRESULT Unattended::getLocale(com::Utf8Str &aLocale)
1776{
1777 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1778 aLocale = mStrLocale;
1779 return S_OK;
1780}
1781
1782HRESULT Unattended::setLocale(const com::Utf8Str &aLocale)
1783{
1784 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1785 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1786 if ( aLocale.isEmpty() /* use default */
1787 || ( aLocale.length() == 5
1788 && RT_C_IS_LOWER(aLocale[0])
1789 && RT_C_IS_LOWER(aLocale[1])
1790 && aLocale[2] == '_'
1791 && RT_C_IS_UPPER(aLocale[3])
1792 && RT_C_IS_UPPER(aLocale[4])) )
1793 {
1794 mStrLocale = aLocale;
1795 return S_OK;
1796 }
1797 return setError(E_INVALIDARG, tr("Expected two lower cased letters, an underscore, and two upper cased letters"));
1798}
1799
1800HRESULT Unattended::getLanguage(com::Utf8Str &aLanguage)
1801{
1802 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1803 aLanguage = mStrLanguage;
1804 return S_OK;
1805}
1806
1807HRESULT Unattended::setLanguage(const com::Utf8Str &aLanguage)
1808{
1809 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1810 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1811 mStrLanguage = aLanguage;
1812 return S_OK;
1813}
1814
1815HRESULT Unattended::getCountry(com::Utf8Str &aCountry)
1816{
1817 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1818 aCountry = mStrCountry;
1819 return S_OK;
1820}
1821
1822HRESULT Unattended::setCountry(const com::Utf8Str &aCountry)
1823{
1824 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1825 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1826 if ( aCountry.isEmpty()
1827 || ( aCountry.length() == 2
1828 && RT_C_IS_UPPER(aCountry[0])
1829 && RT_C_IS_UPPER(aCountry[1])) )
1830 {
1831 mStrCountry = aCountry;
1832 return S_OK;
1833 }
1834 return setError(E_INVALIDARG, tr("Expected two upper cased letters"));
1835}
1836
1837HRESULT Unattended::getProxy(com::Utf8Str &aProxy)
1838{
1839 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1840 aProxy = ""; /// @todo turn schema map into string or something.
1841 return S_OK;
1842}
1843
1844HRESULT Unattended::setProxy(const com::Utf8Str &aProxy)
1845{
1846 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1847 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1848 if (aProxy.isEmpty())
1849 {
1850 /* set default proxy */
1851 }
1852 else if (aProxy.equalsIgnoreCase("none"))
1853 {
1854 /* clear proxy config */
1855 }
1856 else
1857 {
1858 /* Parse and set proxy config into a schema map or something along those lines. */
1859 return E_NOTIMPL;
1860 }
1861 return S_OK;
1862}
1863
1864HRESULT Unattended::getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments)
1865{
1866 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1867 aPackageSelectionAdjustments = RTCString::join(mPackageSelectionAdjustments, ";");
1868 return S_OK;
1869}
1870
1871HRESULT Unattended::setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments)
1872{
1873 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1874 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1875 if (aPackageSelectionAdjustments.isEmpty())
1876 mPackageSelectionAdjustments.clear();
1877 else
1878 {
1879 RTCList<RTCString, RTCString *> arrayStrSplit = aPackageSelectionAdjustments.split(";");
1880 for (size_t i = 0; i < arrayStrSplit.size(); i++)
1881 {
1882 if (arrayStrSplit[i].equals("minimal"))
1883 { /* okay */ }
1884 else
1885 return setError(E_INVALIDARG, tr("Unknown keyword: %s"), arrayStrSplit[i].c_str());
1886 }
1887 mPackageSelectionAdjustments = arrayStrSplit;
1888 }
1889 return S_OK;
1890}
1891
1892HRESULT Unattended::getHostname(com::Utf8Str &aHostname)
1893{
1894 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1895 aHostname = mStrHostname;
1896 return S_OK;
1897}
1898
1899HRESULT Unattended::setHostname(const com::Utf8Str &aHostname)
1900{
1901 /*
1902 * Validate input.
1903 */
1904 if (aHostname.length() > (aHostname.endsWith(".") ? 254U : 253U))
1905 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1906 tr("Hostname '%s' is %zu bytes long, max is 253 (excluing trailing dot)"),
1907 aHostname.c_str(), aHostname.length());
1908 size_t cLabels = 0;
1909 const char *pszSrc = aHostname.c_str();
1910 for (;;)
1911 {
1912 size_t cchLabel = 1;
1913 char ch = *pszSrc++;
1914 if (RT_C_IS_ALNUM(ch))
1915 {
1916 cLabels++;
1917 while ((ch = *pszSrc++) != '.' && ch != '\0')
1918 {
1919 if (RT_C_IS_ALNUM(ch) || ch == '-')
1920 {
1921 if (cchLabel < 63)
1922 cchLabel++;
1923 else
1924 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1925 tr("Invalid hostname '%s' - label %u is too long, max is 63."),
1926 aHostname.c_str(), cLabels);
1927 }
1928 else
1929 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1930 tr("Invalid hostname '%s' - illegal char '%c' at position %zu"),
1931 aHostname.c_str(), ch, pszSrc - aHostname.c_str() - 1);
1932 }
1933 if (cLabels == 1 && cchLabel < 2)
1934 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1935 tr("Invalid hostname '%s' - the name part must be at least two characters long"),
1936 aHostname.c_str());
1937 if (ch == '\0')
1938 break;
1939 }
1940 else if (ch != '\0')
1941 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1942 tr("Invalid hostname '%s' - illegal lead char '%c' at position %zu"),
1943 aHostname.c_str(), ch, pszSrc - aHostname.c_str() - 1);
1944 else
1945 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1946 tr("Invalid hostname '%s' - trailing dot not permitted"), aHostname.c_str());
1947 }
1948 if (cLabels < 2)
1949 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1950 tr("Incomplete hostname '%s' - must include both a name and a domain"), aHostname.c_str());
1951
1952 /*
1953 * Make the change.
1954 */
1955 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1956 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1957 mStrHostname = aHostname;
1958 return S_OK;
1959}
1960
1961HRESULT Unattended::getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath)
1962{
1963 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1964 aAuxiliaryBasePath = mStrAuxiliaryBasePath;
1965 return S_OK;
1966}
1967
1968HRESULT Unattended::setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath)
1969{
1970 if (aAuxiliaryBasePath.isEmpty())
1971 return setError(E_INVALIDARG, "Empty base path is not allowed");
1972 if (!RTPathStartsWithRoot(aAuxiliaryBasePath.c_str()))
1973 return setError(E_INVALIDARG, "Base path must be absolute");
1974
1975 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1976 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1977 mStrAuxiliaryBasePath = aAuxiliaryBasePath;
1978 mfIsDefaultAuxiliaryBasePath = mStrAuxiliaryBasePath.isEmpty();
1979 return S_OK;
1980}
1981
1982HRESULT Unattended::getImageIndex(ULONG *index)
1983{
1984 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1985 *index = midxImage;
1986 return S_OK;
1987}
1988
1989HRESULT Unattended::setImageIndex(ULONG index)
1990{
1991 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1992 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1993 midxImage = index;
1994 return S_OK;
1995}
1996
1997HRESULT Unattended::getMachine(ComPtr<IMachine> &aMachine)
1998{
1999 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2000 return mMachine.queryInterfaceTo(aMachine.asOutParam());
2001}
2002
2003HRESULT Unattended::setMachine(const ComPtr<IMachine> &aMachine)
2004{
2005 /*
2006 * Lookup the VM so we can safely get the Machine instance.
2007 * (Don't want to test how reliable XPCOM and COM are with finding
2008 * the local object instance when a client passes a stub back.)
2009 */
2010 Bstr bstrUuidMachine;
2011 HRESULT hrc = aMachine->COMGETTER(Id)(bstrUuidMachine.asOutParam());
2012 if (SUCCEEDED(hrc))
2013 {
2014 Guid UuidMachine(bstrUuidMachine);
2015 ComObjPtr<Machine> ptrMachine;
2016 hrc = mParent->i_findMachine(UuidMachine, false /*fPermitInaccessible*/, true /*aSetError*/, &ptrMachine);
2017 if (SUCCEEDED(hrc))
2018 {
2019 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2020 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER,
2021 tr("Cannot change after prepare() has been called")));
2022 mMachine = ptrMachine;
2023 mMachineUuid = UuidMachine;
2024 if (mfIsDefaultAuxiliaryBasePath)
2025 mStrAuxiliaryBasePath.setNull();
2026 hrc = S_OK;
2027 }
2028 }
2029 return hrc;
2030}
2031
2032HRESULT Unattended::getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath)
2033{
2034 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2035 if ( mStrScriptTemplatePath.isNotEmpty()
2036 || mpInstaller == NULL)
2037 aScriptTemplatePath = mStrScriptTemplatePath;
2038 else
2039 aScriptTemplatePath = mpInstaller->getTemplateFilePath();
2040 return S_OK;
2041}
2042
2043HRESULT Unattended::setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath)
2044{
2045 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2046 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2047 mStrScriptTemplatePath = aScriptTemplatePath;
2048 return S_OK;
2049}
2050
2051HRESULT Unattended::getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath)
2052{
2053 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2054 if ( mStrPostInstallScriptTemplatePath.isNotEmpty()
2055 || mpInstaller == NULL)
2056 aPostInstallScriptTemplatePath = mStrPostInstallScriptTemplatePath;
2057 else
2058 aPostInstallScriptTemplatePath = mpInstaller->getPostTemplateFilePath();
2059 return S_OK;
2060}
2061
2062HRESULT Unattended::setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath)
2063{
2064 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2065 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2066 mStrPostInstallScriptTemplatePath = aPostInstallScriptTemplatePath;
2067 return S_OK;
2068}
2069
2070HRESULT Unattended::getPostInstallCommand(com::Utf8Str &aPostInstallCommand)
2071{
2072 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2073 aPostInstallCommand = mStrPostInstallCommand;
2074 return S_OK;
2075}
2076
2077HRESULT Unattended::setPostInstallCommand(const com::Utf8Str &aPostInstallCommand)
2078{
2079 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2080 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2081 mStrPostInstallCommand = aPostInstallCommand;
2082 return S_OK;
2083}
2084
2085HRESULT Unattended::getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters)
2086{
2087 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2088 if ( mStrExtraInstallKernelParameters.isNotEmpty()
2089 || mpInstaller == NULL)
2090 aExtraInstallKernelParameters = mStrExtraInstallKernelParameters;
2091 else
2092 aExtraInstallKernelParameters = mpInstaller->getDefaultExtraInstallKernelParameters();
2093 return S_OK;
2094}
2095
2096HRESULT Unattended::setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters)
2097{
2098 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2099 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2100 mStrExtraInstallKernelParameters = aExtraInstallKernelParameters;
2101 return S_OK;
2102}
2103
2104HRESULT Unattended::getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId)
2105{
2106 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2107 aDetectedOSTypeId = mStrDetectedOSTypeId;
2108 return S_OK;
2109}
2110
2111HRESULT Unattended::getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion)
2112{
2113 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2114 aDetectedOSVersion = mStrDetectedOSVersion;
2115 return S_OK;
2116}
2117
2118HRESULT Unattended::getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor)
2119{
2120 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2121 aDetectedOSFlavor = mStrDetectedOSFlavor;
2122 return S_OK;
2123}
2124
2125HRESULT Unattended::getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages)
2126{
2127 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2128 aDetectedOSLanguages = RTCString::join(mDetectedOSLanguages, " ");
2129 return S_OK;
2130}
2131
2132HRESULT Unattended::getDetectedOSHints(com::Utf8Str &aDetectedOSHints)
2133{
2134 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2135 aDetectedOSHints = mStrDetectedOSHints;
2136 return S_OK;
2137}
2138
2139/*
2140 * Getters that the installer and script classes can use.
2141 */
2142Utf8Str const &Unattended::i_getIsoPath() const
2143{
2144 Assert(isReadLockedOnCurrentThread());
2145 return mStrIsoPath;
2146}
2147
2148Utf8Str const &Unattended::i_getUser() const
2149{
2150 Assert(isReadLockedOnCurrentThread());
2151 return mStrUser;
2152}
2153
2154Utf8Str const &Unattended::i_getPassword() const
2155{
2156 Assert(isReadLockedOnCurrentThread());
2157 return mStrPassword;
2158}
2159
2160Utf8Str const &Unattended::i_getFullUserName() const
2161{
2162 Assert(isReadLockedOnCurrentThread());
2163 return mStrFullUserName.isNotEmpty() ? mStrFullUserName : mStrUser;
2164}
2165
2166Utf8Str const &Unattended::i_getProductKey() const
2167{
2168 Assert(isReadLockedOnCurrentThread());
2169 return mStrProductKey;
2170}
2171
2172Utf8Str const &Unattended::i_getAdditionsIsoPath() const
2173{
2174 Assert(isReadLockedOnCurrentThread());
2175 return mStrAdditionsIsoPath;
2176}
2177
2178bool Unattended::i_getInstallGuestAdditions() const
2179{
2180 Assert(isReadLockedOnCurrentThread());
2181 return mfInstallGuestAdditions;
2182}
2183
2184Utf8Str const &Unattended::i_getValidationKitIsoPath() const
2185{
2186 Assert(isReadLockedOnCurrentThread());
2187 return mStrValidationKitIsoPath;
2188}
2189
2190bool Unattended::i_getInstallTestExecService() const
2191{
2192 Assert(isReadLockedOnCurrentThread());
2193 return mfInstallTestExecService;
2194}
2195
2196Utf8Str const &Unattended::i_getTimeZone() const
2197{
2198 Assert(isReadLockedOnCurrentThread());
2199 return mStrTimeZone;
2200}
2201
2202PCRTTIMEZONEINFO Unattended::i_getTimeZoneInfo() const
2203{
2204 Assert(isReadLockedOnCurrentThread());
2205 return mpTimeZoneInfo;
2206}
2207
2208Utf8Str const &Unattended::i_getLocale() const
2209{
2210 Assert(isReadLockedOnCurrentThread());
2211 return mStrLocale;
2212}
2213
2214Utf8Str const &Unattended::i_getLanguage() const
2215{
2216 Assert(isReadLockedOnCurrentThread());
2217 return mStrLanguage;
2218}
2219
2220Utf8Str const &Unattended::i_getCountry() const
2221{
2222 Assert(isReadLockedOnCurrentThread());
2223 return mStrCountry;
2224}
2225
2226bool Unattended::i_isMinimalInstallation() const
2227{
2228 size_t i = mPackageSelectionAdjustments.size();
2229 while (i-- > 0)
2230 if (mPackageSelectionAdjustments[i].equals("minimal"))
2231 return true;
2232 return false;
2233}
2234
2235Utf8Str const &Unattended::i_getHostname() const
2236{
2237 Assert(isReadLockedOnCurrentThread());
2238 return mStrHostname;
2239}
2240
2241Utf8Str const &Unattended::i_getAuxiliaryBasePath() const
2242{
2243 Assert(isReadLockedOnCurrentThread());
2244 return mStrAuxiliaryBasePath;
2245}
2246
2247ULONG Unattended::i_getImageIndex() const
2248{
2249 Assert(isReadLockedOnCurrentThread());
2250 return midxImage;
2251}
2252
2253Utf8Str const &Unattended::i_getScriptTemplatePath() const
2254{
2255 Assert(isReadLockedOnCurrentThread());
2256 return mStrScriptTemplatePath;
2257}
2258
2259Utf8Str const &Unattended::i_getPostInstallScriptTemplatePath() const
2260{
2261 Assert(isReadLockedOnCurrentThread());
2262 return mStrPostInstallScriptTemplatePath;
2263}
2264
2265Utf8Str const &Unattended::i_getPostInstallCommand() const
2266{
2267 Assert(isReadLockedOnCurrentThread());
2268 return mStrPostInstallCommand;
2269}
2270
2271Utf8Str const &Unattended::i_getExtraInstallKernelParameters() const
2272{
2273 Assert(isReadLockedOnCurrentThread());
2274 return mStrExtraInstallKernelParameters;
2275}
2276
2277bool Unattended::i_isRtcUsingUtc() const
2278{
2279 Assert(isReadLockedOnCurrentThread());
2280 return mfRtcUseUtc;
2281}
2282
2283bool Unattended::i_isGuestOs64Bit() const
2284{
2285 Assert(isReadLockedOnCurrentThread());
2286 return mfGuestOs64Bit;
2287}
2288
2289VBOXOSTYPE Unattended::i_getGuestOsType() const
2290{
2291 Assert(isReadLockedOnCurrentThread());
2292 return meGuestOsType;
2293}
2294
2295HRESULT Unattended::i_attachImage(UnattendedInstallationDisk const *pImage, ComPtr<IMachine> const &rPtrSessionMachine,
2296 AutoMultiWriteLock2 &rLock)
2297{
2298 /*
2299 * Attach the disk image
2300 * HACK ALERT! Temporarily release the Unattended lock.
2301 */
2302 rLock.release();
2303
2304 ComPtr<IMedium> ptrMedium;
2305 HRESULT rc = mParent->OpenMedium(Bstr(pImage->strImagePath).raw(),
2306 pImage->enmDeviceType,
2307 pImage->enmAccessType,
2308 true,
2309 ptrMedium.asOutParam());
2310 LogRelFlowFunc(("VirtualBox::openMedium -> %Rhrc\n", rc));
2311 if (SUCCEEDED(rc))
2312 {
2313 if (pImage->fMountOnly)
2314 {
2315 // mount the opened disk image
2316 rc = rPtrSessionMachine->MountMedium(Bstr(pImage->strControllerName).raw(), pImage->uPort,
2317 pImage->uDevice, ptrMedium, TRUE /*fForce*/);
2318 LogRelFlowFunc(("Machine::MountMedium -> %Rhrc\n", rc));
2319 }
2320 else
2321 {
2322 //attach the opened disk image to the controller
2323 rc = rPtrSessionMachine->AttachDevice(Bstr(pImage->strControllerName).raw(), pImage->uPort,
2324 pImage->uDevice, pImage->enmDeviceType, ptrMedium);
2325 LogRelFlowFunc(("Machine::AttachDevice -> %Rhrc\n", rc));
2326 }
2327 }
2328
2329 rLock.acquire();
2330 return rc;
2331}
2332
2333bool Unattended::i_isGuestOSArchX64(Utf8Str const &rStrGuestOsTypeId)
2334{
2335 ComPtr<IGuestOSType> pGuestOSType;
2336 HRESULT hrc = mParent->GetGuestOSType(Bstr(rStrGuestOsTypeId).raw(), pGuestOSType.asOutParam());
2337 if (SUCCEEDED(hrc))
2338 {
2339 BOOL fIs64Bit = FALSE;
2340 hrc = pGuestOSType->COMGETTER(Is64Bit)(&fIs64Bit);
2341 if (SUCCEEDED(hrc))
2342 return fIs64Bit != FALSE;
2343 }
2344 return false;
2345}
2346
Note: See TracBrowser for help on using the repository browser.

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