VirtualBox

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

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

Main,Installer: Made unattended installation of rhel5 and friends work. Fixed TXS bug in post-install script.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 81.1 KB
Line 
1/* $Id: UnattendedImpl.cpp 71007 2018-02-14 12:46:17Z 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
716 if (*penmOsType != VBOXOSTYPE_Unknown)
717 return S_FALSE;
718 }
719
720 return S_FALSE;
721}
722
723
724HRESULT Unattended::prepare()
725{
726 LogFlow(("Unattended::prepare: enter\n"));
727
728 /*
729 * Must have a machine.
730 */
731 ComPtr<Machine> ptrMachine;
732 Guid MachineUuid;
733 {
734 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
735 ptrMachine = mMachine;
736 if (ptrMachine.isNull())
737 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("No machine associated with this IUnatteded instance"));
738 MachineUuid = mMachineUuid;
739 }
740
741 /*
742 * Before we write lock ourselves, we must get stuff from Machine and
743 * VirtualBox because their locks have higher priorities than ours.
744 */
745 Utf8Str strGuestOsTypeId;
746 Utf8Str strMachineName;
747 Utf8Str strDefaultAuxBasePath;
748 HRESULT hrc;
749 try
750 {
751 Bstr bstrTmp;
752 hrc = ptrMachine->COMGETTER(OSTypeId)(bstrTmp.asOutParam());
753 if (SUCCEEDED(hrc))
754 {
755 strGuestOsTypeId = bstrTmp;
756 hrc = ptrMachine->COMGETTER(Name)(bstrTmp.asOutParam());
757 if (SUCCEEDED(hrc))
758 strMachineName = bstrTmp;
759 }
760 int vrc = ptrMachine->i_calculateFullPath(Utf8StrFmt("Unattended-%RTuuid-", MachineUuid.raw()), strDefaultAuxBasePath);
761 if (RT_FAILURE(vrc))
762 return setErrorBoth(E_FAIL, vrc);
763 }
764 catch (std::bad_alloc)
765 {
766 return E_OUTOFMEMORY;
767 }
768 bool const fIs64Bit = i_isGuestOSArchX64(strGuestOsTypeId);
769
770 BOOL fRtcUseUtc = FALSE;
771 hrc = ptrMachine->COMGETTER(RTCUseUTC)(&fRtcUseUtc);
772 if (FAILED(hrc))
773 return hrc;
774
775 /*
776 * Write lock this object and set attributes we got from IMachine.
777 */
778 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
779
780 mStrGuestOsTypeId = strGuestOsTypeId;
781 mfGuestOs64Bit = fIs64Bit;
782 mfRtcUseUtc = RT_BOOL(fRtcUseUtc);
783
784 /*
785 * Do some state checks.
786 */
787 if (mpInstaller != NULL)
788 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("The prepare method has been called (must call done to restart)"));
789 if ((Machine *)ptrMachine != (Machine *)mMachine)
790 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("The 'machine' while we were using it - please don't do that"));
791
792 /*
793 * Check if the specified ISOs and files exist.
794 */
795 if (!RTFileExists(mStrIsoPath.c_str()))
796 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the installation ISO file '%s'"),
797 mStrIsoPath.c_str());
798 if (mfInstallGuestAdditions && !RTFileExists(mStrAdditionsIsoPath.c_str()))
799 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the guest additions ISO file '%s'"),
800 mStrAdditionsIsoPath.c_str());
801 if (mfInstallTestExecService && !RTFileExists(mStrValidationKitIsoPath.c_str()))
802 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the validation kit ISO file '%s'"),
803 mStrValidationKitIsoPath.c_str());
804 if (mStrScriptTemplatePath.isNotEmpty() && !RTFileExists(mStrScriptTemplatePath.c_str()))
805 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate unattended installation script template '%s'"),
806 mStrScriptTemplatePath.c_str());
807
808 /*
809 * Do media detection if it haven't been done yet.
810 */
811 if (!mfDoneDetectIsoOS)
812 {
813 hrc = detectIsoOS();
814 if (FAILED(hrc) && hrc != E_NOTIMPL)
815 return hrc;
816 }
817
818 /*
819 * Do some default property stuff and check other properties.
820 */
821 try
822 {
823 char szTmp[128];
824
825 if (mStrLocale.isEmpty())
826 {
827 int vrc = RTLocaleQueryNormalizedBaseLocaleName(szTmp, sizeof(szTmp));
828 if ( RT_SUCCESS(vrc)
829 && RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(szTmp))
830 mStrLocale.assign(szTmp, 5);
831 else
832 mStrLocale = "en_US";
833 Assert(RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(mStrLocale));
834 }
835
836 if (mStrLanguage.isEmpty())
837 {
838 if (mDetectedOSLanguages.size() > 0)
839 mStrLanguage = mDetectedOSLanguages[0];
840 else
841 mStrLanguage.assign(mStrLocale).findReplace('_', '-');
842 }
843
844 if (mStrCountry.isEmpty())
845 {
846 int vrc = RTLocaleQueryUserCountryCode(szTmp);
847 if (RT_SUCCESS(vrc))
848 mStrCountry = szTmp;
849 else if ( mStrLocale.isNotEmpty()
850 && RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(mStrLocale))
851 mStrCountry.assign(mStrLocale, 3, 2);
852 else
853 mStrCountry = "US";
854 }
855
856 if (mStrTimeZone.isEmpty())
857 {
858 int vrc = RTTimeZoneGetCurrent(szTmp, sizeof(szTmp));
859 if (RT_SUCCESS(vrc))
860 mStrTimeZone = szTmp;
861 else
862 mStrTimeZone = "Etc/UTC";
863 Assert(mStrTimeZone.isNotEmpty());
864 }
865 mpTimeZoneInfo = RTTimeZoneGetInfoByUnixName(mStrTimeZone.c_str());
866 if (!mpTimeZoneInfo)
867 mpTimeZoneInfo = RTTimeZoneGetInfoByWindowsName(mStrTimeZone.c_str());
868 Assert(mpTimeZoneInfo || mStrTimeZone != "Etc/UTC");
869 if (!mpTimeZoneInfo)
870 LogRel(("Unattended::prepare: warning: Unknown time zone '%s'\n", mStrTimeZone.c_str()));
871
872 if (mStrHostname.isEmpty())
873 {
874 /* Mangle the VM name into a valid hostname. */
875 for (size_t i = 0; i < strMachineName.length(); i++)
876 {
877 char ch = strMachineName[i];
878 if ( (unsigned)ch < 127
879 && RT_C_IS_ALNUM(ch))
880 mStrHostname.append(ch);
881 else if (mStrHostname.isNotEmpty() && RT_C_IS_PUNCT(ch) && !mStrHostname.endsWith("-"))
882 mStrHostname.append('-');
883 }
884 if (mStrHostname.length() == 0)
885 mStrHostname.printf("%RTuuid-vm", MachineUuid.raw());
886 else if (mStrHostname.length() < 3)
887 mStrHostname.append("-vm");
888 mStrHostname.append(".myguest.virtualbox.org");
889 }
890
891 if (mStrAuxiliaryBasePath.isEmpty())
892 {
893 mStrAuxiliaryBasePath = strDefaultAuxBasePath;
894 mfIsDefaultAuxiliaryBasePath = true;
895 }
896 }
897 catch (std::bad_alloc)
898 {
899 return E_OUTOFMEMORY;
900 }
901
902 /*
903 * Get the guest OS type info and instantiate the appropriate installer.
904 */
905 uint32_t const idxOSType = Global::getOSTypeIndexFromId(mStrGuestOsTypeId.c_str());
906 meGuestOsType = idxOSType < Global::cOSTypes ? Global::sOSTypes[idxOSType].osType : VBOXOSTYPE_Unknown;
907
908 mpInstaller = UnattendedInstaller::createInstance(meGuestOsType, mStrGuestOsTypeId, mStrDetectedOSVersion,
909 mStrDetectedOSFlavor, mStrDetectedOSHints, this);
910 if (mpInstaller != NULL)
911 {
912 hrc = mpInstaller->initInstaller();
913 if (SUCCEEDED(hrc))
914 {
915 /*
916 * Do the script preps (just reads them).
917 */
918 hrc = mpInstaller->prepareUnattendedScripts();
919 if (SUCCEEDED(hrc))
920 {
921 LogFlow(("Unattended::prepare: returns S_OK\n"));
922 return S_OK;
923 }
924 }
925
926 /* Destroy the installer instance. */
927 delete mpInstaller;
928 mpInstaller = NULL;
929 }
930 else
931 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND,
932 tr("Unattended installation is not supported for guest type '%s'"), mStrGuestOsTypeId.c_str());
933 LogRelFlow(("Unattended::prepare: failed with %Rhrc\n", hrc));
934 return hrc;
935}
936
937HRESULT Unattended::constructMedia()
938{
939 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
940
941 LogFlow(("===========================================================\n"));
942 LogFlow(("Call Unattended::constructMedia()\n"));
943
944 if (mpInstaller == NULL)
945 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, "prepare() not yet called");
946
947 return mpInstaller->prepareMedia();
948}
949
950HRESULT Unattended::reconfigureVM()
951{
952 LogFlow(("===========================================================\n"));
953 LogFlow(("Call Unattended::reconfigureVM()\n"));
954
955 /*
956 * Interrogate VirtualBox/IGuestOSType before we lock stuff and create ordering issues.
957 */
958 StorageBus_T enmRecommendedStorageBus = StorageBus_IDE;
959 {
960 Bstr bstrGuestOsTypeId;
961 {
962 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
963 bstrGuestOsTypeId = mStrGuestOsTypeId;
964 }
965 ComPtr<IGuestOSType> ptrGuestOSType;
966 HRESULT hrc = mParent->GetGuestOSType(bstrGuestOsTypeId.raw(), ptrGuestOSType.asOutParam());
967 if (SUCCEEDED(hrc))
968 hrc = ptrGuestOSType->COMGETTER(RecommendedDVDStorageBus)(&enmRecommendedStorageBus);
969 if (FAILED(hrc))
970 return hrc;
971 }
972
973 /*
974 * Take write lock (for lock order reasons, write lock our parent object too)
975 * then make sure we're the only caller of this method.
976 */
977 AutoMultiWriteLock2 alock(mMachine, this COMMA_LOCKVAL_SRC_POS);
978 HRESULT hrc;
979 if (mhThreadReconfigureVM == NIL_RTNATIVETHREAD)
980 {
981 RTNATIVETHREAD const hNativeSelf = RTThreadNativeSelf();
982 mhThreadReconfigureVM = hNativeSelf;
983
984 /*
985 * Create a new session, lock the machine and get the session machine object.
986 * Do the locking without pinning down the write locks, just to be on the safe side.
987 */
988 ComPtr<ISession> ptrSession;
989 try
990 {
991 hrc = ptrSession.createInprocObject(CLSID_Session);
992 }
993 catch (std::bad_alloc)
994 {
995 hrc = E_OUTOFMEMORY;
996 }
997 if (SUCCEEDED(hrc))
998 {
999 alock.release();
1000 hrc = mMachine->LockMachine(ptrSession, LockType_Shared);
1001 alock.acquire();
1002 if (SUCCEEDED(hrc))
1003 {
1004 ComPtr<IMachine> ptrSessionMachine;
1005 hrc = ptrSession->COMGETTER(Machine)(ptrSessionMachine.asOutParam());
1006 if (SUCCEEDED(hrc))
1007 {
1008 /*
1009 * Hand the session to the inner work and let it do it job.
1010 */
1011 try
1012 {
1013 hrc = i_innerReconfigureVM(alock, enmRecommendedStorageBus, ptrSessionMachine);
1014 }
1015 catch (...)
1016 {
1017 hrc = E_UNEXPECTED;
1018 }
1019 }
1020
1021 /* Paranoia: release early in case we it a bump below. */
1022 Assert(mhThreadReconfigureVM == hNativeSelf);
1023 mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
1024
1025 /*
1026 * While unlocking the machine we'll have to drop the locks again.
1027 */
1028 alock.release();
1029
1030 ptrSessionMachine.setNull();
1031 HRESULT hrc2 = ptrSession->UnlockMachine();
1032 AssertLogRelMsg(SUCCEEDED(hrc2), ("UnlockMachine -> %Rhrc\n", hrc2));
1033
1034 ptrSession.setNull();
1035
1036 alock.acquire();
1037 }
1038 else
1039 mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
1040 }
1041 else
1042 mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
1043 }
1044 else
1045 hrc = setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("reconfigureVM running on other thread"));
1046 return hrc;
1047}
1048
1049
1050HRESULT Unattended::i_innerReconfigureVM(AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus,
1051 ComPtr<IMachine> const &rPtrSessionMachine)
1052{
1053 if (mpInstaller == NULL)
1054 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, "prepare() not yet called");
1055
1056 // Fetch all available storage controllers
1057 com::SafeIfaceArray<IStorageController> arrayOfControllers;
1058 HRESULT hrc = rPtrSessionMachine->COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(arrayOfControllers));
1059 AssertComRCReturn(hrc, hrc);
1060
1061 /*
1062 * Figure out where the images are to be mounted, adding controllers/ports as needed.
1063 */
1064 std::vector<UnattendedInstallationDisk> vecInstallationDisks;
1065 if (mpInstaller->isAuxiliaryFloppyNeeded())
1066 {
1067 hrc = i_reconfigureFloppy(arrayOfControllers, vecInstallationDisks, rPtrSessionMachine, rAutoLock);
1068 if (FAILED(hrc))
1069 return hrc;
1070 }
1071
1072 hrc = i_reconfigureIsos(arrayOfControllers, vecInstallationDisks, rPtrSessionMachine, rAutoLock, enmRecommendedStorageBus);
1073 if (FAILED(hrc))
1074 return hrc;
1075
1076 /*
1077 * Mount the images.
1078 */
1079 for (size_t idxImage = 0; idxImage < vecInstallationDisks.size(); idxImage++)
1080 {
1081 UnattendedInstallationDisk const *pImage = &vecInstallationDisks.at(idxImage);
1082 Assert(pImage->strImagePath.isNotEmpty());
1083 hrc = i_attachImage(pImage, rPtrSessionMachine, rAutoLock);
1084 if (FAILED(hrc))
1085 return hrc;
1086 }
1087
1088 /*
1089 * Set the boot order.
1090 *
1091 * ASSUME that the HD isn't bootable when we start out, but it will be what
1092 * we boot from after the first stage of the installation is done. Setting
1093 * it first prevents endless reboot cylces.
1094 */
1095 /** @todo consider making 100% sure the disk isn't bootable (edit partition
1096 * table active bits and EFI stuff). */
1097 Assert( mpInstaller->getBootableDeviceType() == DeviceType_DVD
1098 || mpInstaller->getBootableDeviceType() == DeviceType_Floppy);
1099 hrc = rPtrSessionMachine->SetBootOrder(1, DeviceType_HardDisk);
1100 if (SUCCEEDED(hrc))
1101 hrc = rPtrSessionMachine->SetBootOrder(2, mpInstaller->getBootableDeviceType());
1102 if (SUCCEEDED(hrc))
1103 hrc = rPtrSessionMachine->SetBootOrder(3, mpInstaller->getBootableDeviceType() == DeviceType_DVD
1104 ? (DeviceType_T)DeviceType_Floppy : (DeviceType_T)DeviceType_DVD);
1105 if (FAILED(hrc))
1106 return hrc;
1107
1108 /*
1109 * Essential step.
1110 *
1111 * HACK ALERT! We have to release the lock here or we'll get into trouble with
1112 * the VirtualBox lock (via i_saveHardware/NetworkAdaptger::i_hasDefaults/VirtualBox::i_findGuestOSType).
1113 */
1114 if (SUCCEEDED(hrc))
1115 {
1116 rAutoLock.release();
1117 hrc = rPtrSessionMachine->SaveSettings();
1118 rAutoLock.acquire();
1119 }
1120
1121 return hrc;
1122}
1123
1124/**
1125 * Makes sure we've got a floppy drive attached to a floppy controller, adding
1126 * the auxiliary floppy image to the installation disk vector.
1127 *
1128 * @returns COM status code.
1129 * @param rControllers The existing controllers.
1130 * @param rVecInstallatationDisks The list of image to mount.
1131 * @param rPtrSessionMachine The session machine smart pointer.
1132 * @param rAutoLock The lock.
1133 */
1134HRESULT Unattended::i_reconfigureFloppy(com::SafeIfaceArray<IStorageController> &rControllers,
1135 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
1136 ComPtr<IMachine> const &rPtrSessionMachine,
1137 AutoMultiWriteLock2 &rAutoLock)
1138{
1139 Assert(mpInstaller->isAuxiliaryFloppyNeeded());
1140
1141 /*
1142 * Look for a floppy controller with a primary drive (A:) we can "insert"
1143 * the auxiliary floppy image. Add a controller and/or a drive if necessary.
1144 */
1145 bool fFoundPort0Dev0 = false;
1146 Bstr bstrControllerName;
1147 Utf8Str strControllerName;
1148
1149 for (size_t i = 0; i < rControllers.size(); ++i)
1150 {
1151 StorageBus_T enmStorageBus;
1152 HRESULT hrc = rControllers[i]->COMGETTER(Bus)(&enmStorageBus);
1153 AssertComRCReturn(hrc, hrc);
1154 if (enmStorageBus == StorageBus_Floppy)
1155 {
1156
1157 /*
1158 * Found a floppy controller.
1159 */
1160 hrc = rControllers[i]->COMGETTER(Name)(bstrControllerName.asOutParam());
1161 AssertComRCReturn(hrc, hrc);
1162
1163 /*
1164 * Check the attchments to see if we've got a device 0 attached on port 0.
1165 *
1166 * While we're at it we eject flppies from all floppy drives we encounter,
1167 * we don't want any confusion at boot or during installation.
1168 */
1169 com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
1170 hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(bstrControllerName.raw(),
1171 ComSafeArrayAsOutParam(arrayOfMediumAttachments));
1172 AssertComRCReturn(hrc, hrc);
1173 strControllerName = bstrControllerName;
1174 AssertLogRelReturn(strControllerName.isNotEmpty(), setErrorBoth(E_UNEXPECTED, VERR_INTERNAL_ERROR_2));
1175
1176 for (size_t j = 0; j < arrayOfMediumAttachments.size(); j++)
1177 {
1178 LONG iPort = -1;
1179 hrc = arrayOfMediumAttachments[j]->COMGETTER(Port)(&iPort);
1180 AssertComRCReturn(hrc, hrc);
1181
1182 LONG iDevice = -1;
1183 hrc = arrayOfMediumAttachments[j]->COMGETTER(Device)(&iDevice);
1184 AssertComRCReturn(hrc, hrc);
1185
1186 DeviceType_T enmType;
1187 hrc = arrayOfMediumAttachments[j]->COMGETTER(Type)(&enmType);
1188 AssertComRCReturn(hrc, hrc);
1189
1190 if (enmType == DeviceType_Floppy)
1191 {
1192 ComPtr<IMedium> ptrMedium;
1193 hrc = arrayOfMediumAttachments[j]->COMGETTER(Medium)(ptrMedium.asOutParam());
1194 AssertComRCReturn(hrc, hrc);
1195
1196 if (ptrMedium.isNotNull())
1197 {
1198 ptrMedium.setNull();
1199 rAutoLock.release();
1200 hrc = rPtrSessionMachine->UnmountMedium(bstrControllerName.raw(), iPort, iDevice, TRUE /*fForce*/);
1201 rAutoLock.acquire();
1202 }
1203
1204 if (iPort == 0 && iDevice == 0)
1205 fFoundPort0Dev0 = true;
1206 }
1207 else if (iPort == 0 && iDevice == 0)
1208 return setError(E_FAIL,
1209 tr("Found non-floppy device attached to port 0 device 0 on the floppy controller '%ls'"),
1210 bstrControllerName.raw());
1211 }
1212 }
1213 }
1214
1215 /*
1216 * Add a floppy controller if we need to.
1217 */
1218 if (strControllerName.isEmpty())
1219 {
1220 bstrControllerName = strControllerName = "Floppy";
1221 ComPtr<IStorageController> ptrControllerIgnored;
1222 HRESULT hrc = rPtrSessionMachine->AddStorageController(bstrControllerName.raw(), StorageBus_Floppy,
1223 ptrControllerIgnored.asOutParam());
1224 LogRelFunc(("Machine::addStorageController(Floppy) -> %Rhrc \n", hrc));
1225 if (FAILED(hrc))
1226 return hrc;
1227 }
1228
1229 /*
1230 * Adding a floppy drive (if needed) and mounting the auxiliary image is
1231 * done later together with the ISOs.
1232 */
1233 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(StorageBus_Floppy, strControllerName,
1234 DeviceType_Floppy, AccessMode_ReadWrite,
1235 0, 0,
1236 fFoundPort0Dev0 /*fMountOnly*/,
1237 mpInstaller->getAuxiliaryFloppyFilePath()));
1238 return S_OK;
1239}
1240
1241/**
1242 * Reconfigures DVD drives of the VM to mount all the ISOs we need.
1243 *
1244 * This will umount all DVD media.
1245 *
1246 * @returns COM status code.
1247 * @param rControllers The existing controllers.
1248 * @param rVecInstallatationDisks The list of image to mount.
1249 * @param rPtrSessionMachine The session machine smart pointer.
1250 * @param rAutoLock The lock.
1251 * @param enmRecommendedStorageBus The recommended storage bus type for adding
1252 * DVD drives on.
1253 */
1254HRESULT Unattended::i_reconfigureIsos(com::SafeIfaceArray<IStorageController> &rControllers,
1255 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
1256 ComPtr<IMachine> const &rPtrSessionMachine,
1257 AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus)
1258{
1259 /*
1260 * Enumerate the attachements of every controller, looking for DVD drives,
1261 * ASSUMEING all drives are bootable.
1262 *
1263 * Eject the medium from all the drives (don't want any confusion) and look
1264 * for the recommended storage bus in case we need to add more drives.
1265 */
1266 HRESULT hrc;
1267 std::list<ControllerSlot> lstControllerDvdSlots;
1268 Utf8Str strRecommendedControllerName; /* non-empty if recommended bus found. */
1269 Utf8Str strControllerName;
1270 Bstr bstrControllerName;
1271 for (size_t i = 0; i < rControllers.size(); ++i)
1272 {
1273 hrc = rControllers[i]->COMGETTER(Name)(bstrControllerName.asOutParam());
1274 AssertComRCReturn(hrc, hrc);
1275 strControllerName = bstrControllerName;
1276
1277 /* Look for recommended storage bus. */
1278 StorageBus_T enmStorageBus;
1279 hrc = rControllers[i]->COMGETTER(Bus)(&enmStorageBus);
1280 AssertComRCReturn(hrc, hrc);
1281 if (enmStorageBus == enmRecommendedStorageBus)
1282 {
1283 strRecommendedControllerName = bstrControllerName;
1284 AssertLogRelReturn(strControllerName.isNotEmpty(), setErrorBoth(E_UNEXPECTED, VERR_INTERNAL_ERROR_2));
1285 }
1286
1287 /* Scan the controller attachments. */
1288 com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
1289 hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(bstrControllerName.raw(),
1290 ComSafeArrayAsOutParam(arrayOfMediumAttachments));
1291 AssertComRCReturn(hrc, hrc);
1292
1293 for (size_t j = 0; j < arrayOfMediumAttachments.size(); j++)
1294 {
1295 DeviceType_T enmType;
1296 hrc = arrayOfMediumAttachments[j]->COMGETTER(Type)(&enmType);
1297 AssertComRCReturn(hrc, hrc);
1298 if (enmType == DeviceType_DVD)
1299 {
1300 LONG iPort = -1;
1301 hrc = arrayOfMediumAttachments[j]->COMGETTER(Port)(&iPort);
1302 AssertComRCReturn(hrc, hrc);
1303
1304 LONG iDevice = -1;
1305 hrc = arrayOfMediumAttachments[j]->COMGETTER(Device)(&iDevice);
1306 AssertComRCReturn(hrc, hrc);
1307
1308 /* Remeber it. */
1309 lstControllerDvdSlots.push_back(ControllerSlot(enmStorageBus, strControllerName, iPort, iDevice, false /*fFree*/));
1310
1311 /* Eject the medium, if any. */
1312 ComPtr<IMedium> ptrMedium;
1313 hrc = arrayOfMediumAttachments[j]->COMGETTER(Medium)(ptrMedium.asOutParam());
1314 AssertComRCReturn(hrc, hrc);
1315 if (ptrMedium.isNotNull())
1316 {
1317 ptrMedium.setNull();
1318
1319 rAutoLock.release();
1320 hrc = rPtrSessionMachine->UnmountMedium(bstrControllerName.raw(), iPort, iDevice, TRUE /*fForce*/);
1321 rAutoLock.acquire();
1322 }
1323 }
1324 }
1325 }
1326
1327 /*
1328 * How many drives do we need? Add more if necessary.
1329 */
1330 ULONG cDvdDrivesNeeded = 0;
1331 if (mpInstaller->isAuxiliaryIsoNeeded())
1332 cDvdDrivesNeeded++;
1333 if (mpInstaller->isOriginalIsoNeeded())
1334 cDvdDrivesNeeded++;
1335#if 0 /* These are now in the AUX VISO. */
1336 if (mpInstaller->isAdditionsIsoNeeded())
1337 cDvdDrivesNeeded++;
1338 if (mpInstaller->isValidationKitIsoNeeded())
1339 cDvdDrivesNeeded++;
1340#endif
1341 Assert(cDvdDrivesNeeded > 0);
1342 if (cDvdDrivesNeeded > lstControllerDvdSlots.size())
1343 {
1344 /* Do we need to add the recommended controller? */
1345 if (strRecommendedControllerName.isEmpty())
1346 {
1347 switch (enmRecommendedStorageBus)
1348 {
1349 case StorageBus_IDE: strRecommendedControllerName = "IDE"; break;
1350 case StorageBus_SATA: strRecommendedControllerName = "SATA"; break;
1351 case StorageBus_SCSI: strRecommendedControllerName = "SCSI"; break;
1352 case StorageBus_SAS: strRecommendedControllerName = "SAS"; break;
1353 case StorageBus_USB: strRecommendedControllerName = "USB"; break;
1354 case StorageBus_PCIe: strRecommendedControllerName = "PCIe"; break;
1355 default:
1356 return setError(E_FAIL, tr("Support for recommended storage bus %d not implemented"),
1357 (int)enmRecommendedStorageBus);
1358 }
1359 ComPtr<IStorageController> ptrControllerIgnored;
1360 hrc = rPtrSessionMachine->AddStorageController(Bstr(strRecommendedControllerName).raw(), enmRecommendedStorageBus,
1361 ptrControllerIgnored.asOutParam());
1362 LogRelFunc(("Machine::addStorageController(%s) -> %Rhrc \n", strRecommendedControllerName.c_str(), hrc));
1363 if (FAILED(hrc))
1364 return hrc;
1365 }
1366
1367 /* Add free controller slots, maybe raising the port limit on the controller if we can. */
1368 hrc = i_findOrCreateNeededFreeSlots(strRecommendedControllerName, enmRecommendedStorageBus, rPtrSessionMachine,
1369 cDvdDrivesNeeded, lstControllerDvdSlots);
1370 if (FAILED(hrc))
1371 return hrc;
1372 if (cDvdDrivesNeeded > lstControllerDvdSlots.size())
1373 {
1374 /* We could in many cases create another controller here, but it's not worth the effort. */
1375 return setError(E_FAIL, tr("Not enough free slots on controller '%s' to add %u DVD drive(s)"),
1376 strRecommendedControllerName.c_str(), cDvdDrivesNeeded - lstControllerDvdSlots.size());
1377 }
1378 Assert(cDvdDrivesNeeded == lstControllerDvdSlots.size());
1379 }
1380
1381 /*
1382 * Sort the DVD slots in boot order.
1383 */
1384 lstControllerDvdSlots.sort();
1385
1386 /*
1387 * Prepare ISO mounts.
1388 *
1389 * Boot order depends on bootFromAuxiliaryIso() and we must grab DVD slots
1390 * according to the boot order.
1391 */
1392 std::list<ControllerSlot>::const_iterator itDvdSlot = lstControllerDvdSlots.begin();
1393 if (mpInstaller->isAuxiliaryIsoNeeded() && mpInstaller->bootFromAuxiliaryIso())
1394 {
1395 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath()));
1396 ++itDvdSlot;
1397 }
1398
1399 if (mpInstaller->isOriginalIsoNeeded())
1400 {
1401 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getIsoPath()));
1402 ++itDvdSlot;
1403 }
1404
1405 if (mpInstaller->isAuxiliaryIsoNeeded() && !mpInstaller->bootFromAuxiliaryIso())
1406 {
1407 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath()));
1408 ++itDvdSlot;
1409 }
1410
1411#if 0 /* These are now in the AUX VISO. */
1412 if (mpInstaller->isAdditionsIsoNeeded())
1413 {
1414 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getAdditionsIsoPath()));
1415 ++itDvdSlot;
1416 }
1417
1418 if (mpInstaller->isValidationKitIsoNeeded())
1419 {
1420 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getValidationKitIsoPath()));
1421 ++itDvdSlot;
1422 }
1423#endif
1424
1425 return S_OK;
1426}
1427
1428/**
1429 * Used to find more free slots for DVD drives during VM reconfiguration.
1430 *
1431 * This may modify the @a portCount property of the given controller.
1432 *
1433 * @returns COM status code.
1434 * @param rStrControllerName The name of the controller to find/create
1435 * free slots on.
1436 * @param enmStorageBus The storage bus type.
1437 * @param rPtrSessionMachine Reference to the session machine.
1438 * @param cSlotsNeeded Total slots needed (including those we've
1439 * already found).
1440 * @param rDvdSlots The slot collection for DVD drives to add
1441 * free slots to as we find/create them.
1442 */
1443HRESULT Unattended::i_findOrCreateNeededFreeSlots(const Utf8Str &rStrControllerName, StorageBus_T enmStorageBus,
1444 ComPtr<IMachine> const &rPtrSessionMachine, uint32_t cSlotsNeeded,
1445 std::list<ControllerSlot> &rDvdSlots)
1446{
1447 Assert(cSlotsNeeded > rDvdSlots.size());
1448
1449 /*
1450 * Get controlleer stats.
1451 */
1452 ComPtr<IStorageController> pController;
1453 HRESULT hrc = rPtrSessionMachine->GetStorageControllerByName(Bstr(rStrControllerName).raw(), pController.asOutParam());
1454 AssertComRCReturn(hrc, hrc);
1455
1456 ULONG cMaxDevicesPerPort = 1;
1457 hrc = pController->COMGETTER(MaxDevicesPerPortCount)(&cMaxDevicesPerPort);
1458 AssertComRCReturn(hrc, hrc);
1459 AssertLogRelReturn(cMaxDevicesPerPort > 0, E_UNEXPECTED);
1460
1461 ULONG cPorts = 0;
1462 hrc = pController->COMGETTER(PortCount)(&cPorts);
1463 AssertComRCReturn(hrc, hrc);
1464
1465 /*
1466 * Get the attachment list and turn into an internal list for lookup speed.
1467 */
1468 com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
1469 hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(Bstr(rStrControllerName).raw(),
1470 ComSafeArrayAsOutParam(arrayOfMediumAttachments));
1471 AssertComRCReturn(hrc, hrc);
1472
1473 std::vector<ControllerSlot> arrayOfUsedSlots;
1474 for (size_t i = 0; i < arrayOfMediumAttachments.size(); i++)
1475 {
1476 LONG iPort = -1;
1477 hrc = arrayOfMediumAttachments[i]->COMGETTER(Port)(&iPort);
1478 AssertComRCReturn(hrc, hrc);
1479
1480 LONG iDevice = -1;
1481 hrc = arrayOfMediumAttachments[i]->COMGETTER(Device)(&iDevice);
1482 AssertComRCReturn(hrc, hrc);
1483
1484 arrayOfUsedSlots.push_back(ControllerSlot(enmStorageBus, Utf8Str::Empty, iPort, iDevice, false /*fFree*/));
1485 }
1486
1487 /*
1488 * Iterate thru all possible slots, adding those not found in arrayOfUsedSlots.
1489 */
1490 for (uint32_t iPort = 0; iPort < cPorts; iPort++)
1491 for (uint32_t iDevice = 0; iDevice < cMaxDevicesPerPort; iDevice++)
1492 {
1493 bool fFound = false;
1494 for (size_t i = 0; i < arrayOfUsedSlots.size(); i++)
1495 if ( arrayOfUsedSlots[i].uPort == iPort
1496 && arrayOfUsedSlots[i].uDevice == iDevice)
1497 {
1498 fFound = true;
1499 break;
1500 }
1501 if (!fFound)
1502 {
1503 rDvdSlots.push_back(ControllerSlot(enmStorageBus, rStrControllerName, iPort, iDevice, true /*fFree*/));
1504 if (rDvdSlots.size() >= cSlotsNeeded)
1505 return S_OK;
1506 }
1507 }
1508
1509 /*
1510 * Okay we still need more ports. See if increasing the number of controller
1511 * ports would solve it.
1512 */
1513 ULONG cMaxPorts = 1;
1514 hrc = pController->COMGETTER(MaxPortCount)(&cMaxPorts);
1515 AssertComRCReturn(hrc, hrc);
1516 if (cMaxPorts <= cPorts)
1517 return S_OK;
1518 size_t cNewPortsNeeded = (cSlotsNeeded - rDvdSlots.size() + cMaxDevicesPerPort - 1) / cMaxDevicesPerPort;
1519 if (cPorts + cNewPortsNeeded > cMaxPorts)
1520 return S_OK;
1521
1522 /*
1523 * Raise the port count and add the free slots we've just created.
1524 */
1525 hrc = pController->COMSETTER(PortCount)(cPorts + (ULONG)cNewPortsNeeded);
1526 AssertComRCReturn(hrc, hrc);
1527 for (uint32_t iPort = cPorts; iPort < cPorts + cNewPortsNeeded; iPort++)
1528 for (uint32_t iDevice = 0; iDevice < cMaxDevicesPerPort; iDevice++)
1529 {
1530 rDvdSlots.push_back(ControllerSlot(enmStorageBus, rStrControllerName, iPort, iDevice, true /*fFree*/));
1531 if (rDvdSlots.size() >= cSlotsNeeded)
1532 return S_OK;
1533 }
1534
1535 /* We should not get here! */
1536 AssertLogRelFailedReturn(E_UNEXPECTED);
1537}
1538
1539HRESULT Unattended::done()
1540{
1541 LogFlow(("Unattended::done\n"));
1542 if (mpInstaller)
1543 {
1544 LogRelFlow(("Unattended::done: Deleting installer object (%p)\n", mpInstaller));
1545 delete mpInstaller;
1546 mpInstaller = NULL;
1547 }
1548 return S_OK;
1549}
1550
1551HRESULT Unattended::getIsoPath(com::Utf8Str &isoPath)
1552{
1553 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1554 isoPath = mStrIsoPath;
1555 return S_OK;
1556}
1557
1558HRESULT Unattended::setIsoPath(const com::Utf8Str &isoPath)
1559{
1560 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1561 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1562 mStrIsoPath = isoPath;
1563 mfDoneDetectIsoOS = false;
1564 return S_OK;
1565}
1566
1567HRESULT Unattended::getUser(com::Utf8Str &user)
1568{
1569 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1570 user = mStrUser;
1571 return S_OK;
1572}
1573
1574
1575HRESULT Unattended::setUser(const com::Utf8Str &user)
1576{
1577 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1578 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1579 mStrUser = user;
1580 return S_OK;
1581}
1582
1583HRESULT Unattended::getPassword(com::Utf8Str &password)
1584{
1585 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1586 password = mStrPassword;
1587 return S_OK;
1588}
1589
1590HRESULT Unattended::setPassword(const com::Utf8Str &password)
1591{
1592 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1593 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1594 mStrPassword = password;
1595 return S_OK;
1596}
1597
1598HRESULT Unattended::getFullUserName(com::Utf8Str &fullUserName)
1599{
1600 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1601 fullUserName = mStrFullUserName;
1602 return S_OK;
1603}
1604
1605HRESULT Unattended::setFullUserName(const com::Utf8Str &fullUserName)
1606{
1607 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1608 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1609 mStrFullUserName = fullUserName;
1610 return S_OK;
1611}
1612
1613HRESULT Unattended::getProductKey(com::Utf8Str &productKey)
1614{
1615 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1616 productKey = mStrProductKey;
1617 return S_OK;
1618}
1619
1620HRESULT Unattended::setProductKey(const com::Utf8Str &productKey)
1621{
1622 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1623 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1624 mStrProductKey = productKey;
1625 return S_OK;
1626}
1627
1628HRESULT Unattended::getAdditionsIsoPath(com::Utf8Str &additionsIsoPath)
1629{
1630 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1631 additionsIsoPath = mStrAdditionsIsoPath;
1632 return S_OK;
1633}
1634
1635HRESULT Unattended::setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath)
1636{
1637 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1638 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1639 mStrAdditionsIsoPath = additionsIsoPath;
1640 return S_OK;
1641}
1642
1643HRESULT Unattended::getInstallGuestAdditions(BOOL *installGuestAdditions)
1644{
1645 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1646 *installGuestAdditions = mfInstallGuestAdditions;
1647 return S_OK;
1648}
1649
1650HRESULT Unattended::setInstallGuestAdditions(BOOL installGuestAdditions)
1651{
1652 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1653 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1654 mfInstallGuestAdditions = installGuestAdditions != FALSE;
1655 return S_OK;
1656}
1657
1658HRESULT Unattended::getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath)
1659{
1660 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1661 aValidationKitIsoPath = mStrValidationKitIsoPath;
1662 return S_OK;
1663}
1664
1665HRESULT Unattended::setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath)
1666{
1667 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1668 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1669 mStrValidationKitIsoPath = aValidationKitIsoPath;
1670 return S_OK;
1671}
1672
1673HRESULT Unattended::getInstallTestExecService(BOOL *aInstallTestExecService)
1674{
1675 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1676 *aInstallTestExecService = mfInstallTestExecService;
1677 return S_OK;
1678}
1679
1680HRESULT Unattended::setInstallTestExecService(BOOL aInstallTestExecService)
1681{
1682 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1683 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1684 mfInstallTestExecService = aInstallTestExecService != FALSE;
1685 return S_OK;
1686}
1687
1688HRESULT Unattended::getTimeZone(com::Utf8Str &aTimeZone)
1689{
1690 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1691 aTimeZone = mStrTimeZone;
1692 return S_OK;
1693}
1694
1695HRESULT Unattended::setTimeZone(const com::Utf8Str &aTimezone)
1696{
1697 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1698 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1699 mStrTimeZone = aTimezone;
1700 return S_OK;
1701}
1702
1703HRESULT Unattended::getLocale(com::Utf8Str &aLocale)
1704{
1705 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1706 aLocale = mStrLocale;
1707 return S_OK;
1708}
1709
1710HRESULT Unattended::setLocale(const com::Utf8Str &aLocale)
1711{
1712 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1713 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1714 if ( aLocale.isEmpty() /* use default */
1715 || ( aLocale.length() == 5
1716 && RT_C_IS_LOWER(aLocale[0])
1717 && RT_C_IS_LOWER(aLocale[1])
1718 && aLocale[2] == '_'
1719 && RT_C_IS_UPPER(aLocale[3])
1720 && RT_C_IS_UPPER(aLocale[4])) )
1721 {
1722 mStrLocale = aLocale;
1723 return S_OK;
1724 }
1725 return setError(E_INVALIDARG, tr("Expected two lower cased letters, an underscore, and two upper cased letters"));
1726}
1727
1728HRESULT Unattended::getLanguage(com::Utf8Str &aLanguage)
1729{
1730 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1731 aLanguage = mStrLanguage;
1732 return S_OK;
1733}
1734
1735HRESULT Unattended::setLanguage(const com::Utf8Str &aLanguage)
1736{
1737 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1738 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1739 mStrLanguage = aLanguage;
1740 return S_OK;
1741}
1742
1743HRESULT Unattended::getCountry(com::Utf8Str &aCountry)
1744{
1745 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1746 aCountry = mStrCountry;
1747 return S_OK;
1748}
1749
1750HRESULT Unattended::setCountry(const com::Utf8Str &aCountry)
1751{
1752 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1753 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1754 if ( aCountry.isEmpty()
1755 || ( aCountry.length() == 2
1756 && RT_C_IS_UPPER(aCountry[0])
1757 && RT_C_IS_UPPER(aCountry[1])) )
1758 {
1759 mStrCountry = aCountry;
1760 return S_OK;
1761 }
1762 return setError(E_INVALIDARG, tr("Expected two upper cased letters"));
1763}
1764
1765HRESULT Unattended::getProxy(com::Utf8Str &aProxy)
1766{
1767 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1768 aProxy = ""; /// @todo turn schema map into string or something.
1769 return S_OK;
1770}
1771
1772HRESULT Unattended::setProxy(const com::Utf8Str &aProxy)
1773{
1774 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1775 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1776 if (aProxy.isEmpty())
1777 {
1778 /* set default proxy */
1779 }
1780 else if (aProxy.equalsIgnoreCase("none"))
1781 {
1782 /* clear proxy config */
1783 }
1784 else
1785 {
1786 /* Parse and set proxy config into a schema map or something along those lines. */
1787 return E_NOTIMPL;
1788 }
1789 return S_OK;
1790}
1791
1792HRESULT Unattended::getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments)
1793{
1794 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1795 aPackageSelectionAdjustments = RTCString::join(mPackageSelectionAdjustments, ";");
1796 return S_OK;
1797}
1798
1799HRESULT Unattended::setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments)
1800{
1801 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1802 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1803 if (aPackageSelectionAdjustments.isEmpty())
1804 mPackageSelectionAdjustments.clear();
1805 else
1806 {
1807 RTCList<RTCString, RTCString *> arrayStrSplit = aPackageSelectionAdjustments.split(";");
1808 for (size_t i = 0; i < arrayStrSplit.size(); i++)
1809 {
1810 if (arrayStrSplit[i].equals("minimal"))
1811 { /* okay */ }
1812 else
1813 return setError(E_INVALIDARG, tr("Unknown keyword: %s"), arrayStrSplit[i].c_str());
1814 }
1815 mPackageSelectionAdjustments = arrayStrSplit;
1816 }
1817 return S_OK;
1818}
1819
1820HRESULT Unattended::getHostname(com::Utf8Str &aHostname)
1821{
1822 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1823 aHostname = mStrHostname;
1824 return S_OK;
1825}
1826
1827HRESULT Unattended::setHostname(const com::Utf8Str &aHostname)
1828{
1829 /*
1830 * Validate input.
1831 */
1832 if (aHostname.length() > (aHostname.endsWith(".") ? 254U : 253U))
1833 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1834 tr("Hostname '%s' is %zu bytes long, max is 253 (excluing trailing dot)"),
1835 aHostname.c_str(), aHostname.length());
1836 size_t cLabels = 0;
1837 const char *pszSrc = aHostname.c_str();
1838 for (;;)
1839 {
1840 size_t cchLabel = 1;
1841 char ch = *pszSrc++;
1842 if (RT_C_IS_ALNUM(ch))
1843 {
1844 cLabels++;
1845 while ((ch = *pszSrc++) != '.' && ch != '\0')
1846 {
1847 if (RT_C_IS_ALNUM(ch) || ch == '-')
1848 {
1849 if (cchLabel < 63)
1850 cchLabel++;
1851 else
1852 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1853 tr("Invalid hostname '%s' - label %u is too long, max is 63."),
1854 aHostname.c_str(), cLabels);
1855 }
1856 else
1857 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1858 tr("Invalid hostname '%s' - illegal char '%c' at position %zu"),
1859 aHostname.c_str(), ch, pszSrc - aHostname.c_str() - 1);
1860 }
1861 if (cLabels == 1 && cchLabel < 2)
1862 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1863 tr("Invalid hostname '%s' - the name part must be at least two characters long"),
1864 aHostname.c_str());
1865 if (ch == '\0')
1866 break;
1867 }
1868 else if (ch != '\0')
1869 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1870 tr("Invalid hostname '%s' - illegal lead char '%c' at position %zu"),
1871 aHostname.c_str(), ch, pszSrc - aHostname.c_str() - 1);
1872 else
1873 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1874 tr("Invalid hostname '%s' - trailing dot not permitted"), aHostname.c_str());
1875 }
1876 if (cLabels < 2)
1877 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
1878 tr("Incomplete hostname '%s' - must include both a name and a domain"), aHostname.c_str());
1879
1880 /*
1881 * Make the change.
1882 */
1883 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1884 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1885 mStrHostname = aHostname;
1886 return S_OK;
1887}
1888
1889HRESULT Unattended::getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath)
1890{
1891 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1892 aAuxiliaryBasePath = mStrAuxiliaryBasePath;
1893 return S_OK;
1894}
1895
1896HRESULT Unattended::setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath)
1897{
1898 if (aAuxiliaryBasePath.isEmpty())
1899 return setError(E_INVALIDARG, "Empty base path is not allowed");
1900 if (!RTPathStartsWithRoot(aAuxiliaryBasePath.c_str()))
1901 return setError(E_INVALIDARG, "Base path must be absolute");
1902
1903 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1904 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1905 mStrAuxiliaryBasePath = aAuxiliaryBasePath;
1906 mfIsDefaultAuxiliaryBasePath = mStrAuxiliaryBasePath.isEmpty();
1907 return S_OK;
1908}
1909
1910HRESULT Unattended::getImageIndex(ULONG *index)
1911{
1912 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1913 *index = midxImage;
1914 return S_OK;
1915}
1916
1917HRESULT Unattended::setImageIndex(ULONG index)
1918{
1919 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1920 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1921 midxImage = index;
1922 return S_OK;
1923}
1924
1925HRESULT Unattended::getMachine(ComPtr<IMachine> &aMachine)
1926{
1927 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1928 return mMachine.queryInterfaceTo(aMachine.asOutParam());
1929}
1930
1931HRESULT Unattended::setMachine(const ComPtr<IMachine> &aMachine)
1932{
1933 /*
1934 * Lookup the VM so we can safely get the Machine instance.
1935 * (Don't want to test how reliable XPCOM and COM are with finding
1936 * the local object instance when a client passes a stub back.)
1937 */
1938 Bstr bstrUuidMachine;
1939 HRESULT hrc = aMachine->COMGETTER(Id)(bstrUuidMachine.asOutParam());
1940 if (SUCCEEDED(hrc))
1941 {
1942 Guid UuidMachine(bstrUuidMachine);
1943 ComObjPtr<Machine> ptrMachine;
1944 hrc = mParent->i_findMachine(UuidMachine, false /*fPermitInaccessible*/, true /*aSetError*/, &ptrMachine);
1945 if (SUCCEEDED(hrc))
1946 {
1947 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1948 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER,
1949 tr("Cannot change after prepare() has been called")));
1950 mMachine = ptrMachine;
1951 mMachineUuid = UuidMachine;
1952 if (mfIsDefaultAuxiliaryBasePath)
1953 mStrAuxiliaryBasePath.setNull();
1954 hrc = S_OK;
1955 }
1956 }
1957 return hrc;
1958}
1959
1960HRESULT Unattended::getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath)
1961{
1962 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1963 if ( mStrScriptTemplatePath.isNotEmpty()
1964 || mpInstaller == NULL)
1965 aScriptTemplatePath = mStrScriptTemplatePath;
1966 else
1967 aScriptTemplatePath = mpInstaller->getTemplateFilePath();
1968 return S_OK;
1969}
1970
1971HRESULT Unattended::setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath)
1972{
1973 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1974 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1975 mStrScriptTemplatePath = aScriptTemplatePath;
1976 return S_OK;
1977}
1978
1979HRESULT Unattended::getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath)
1980{
1981 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1982 if ( mStrPostInstallScriptTemplatePath.isNotEmpty()
1983 || mpInstaller == NULL)
1984 aPostInstallScriptTemplatePath = mStrPostInstallScriptTemplatePath;
1985 else
1986 aPostInstallScriptTemplatePath = mpInstaller->getPostTemplateFilePath();
1987 return S_OK;
1988}
1989
1990HRESULT Unattended::setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath)
1991{
1992 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1993 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
1994 mStrPostInstallScriptTemplatePath = aPostInstallScriptTemplatePath;
1995 return S_OK;
1996}
1997
1998HRESULT Unattended::getPostInstallCommand(com::Utf8Str &aPostInstallCommand)
1999{
2000 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2001 aPostInstallCommand = mStrPostInstallCommand;
2002 return S_OK;
2003}
2004
2005HRESULT Unattended::setPostInstallCommand(const com::Utf8Str &aPostInstallCommand)
2006{
2007 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2008 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2009 mStrPostInstallCommand = aPostInstallCommand;
2010 return S_OK;
2011}
2012
2013HRESULT Unattended::getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters)
2014{
2015 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2016 if ( mStrExtraInstallKernelParameters.isNotEmpty()
2017 || mpInstaller == NULL)
2018 aExtraInstallKernelParameters = mStrExtraInstallKernelParameters;
2019 else
2020 aExtraInstallKernelParameters = mpInstaller->getDefaultExtraInstallKernelParameters();
2021 return S_OK;
2022}
2023
2024HRESULT Unattended::setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters)
2025{
2026 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2027 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2028 mStrExtraInstallKernelParameters = aExtraInstallKernelParameters;
2029 return S_OK;
2030}
2031
2032HRESULT Unattended::getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId)
2033{
2034 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2035 aDetectedOSTypeId = mStrDetectedOSTypeId;
2036 return S_OK;
2037}
2038
2039HRESULT Unattended::getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion)
2040{
2041 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2042 aDetectedOSVersion = mStrDetectedOSVersion;
2043 return S_OK;
2044}
2045
2046HRESULT Unattended::getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor)
2047{
2048 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2049 aDetectedOSFlavor = mStrDetectedOSFlavor;
2050 return S_OK;
2051}
2052
2053HRESULT Unattended::getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages)
2054{
2055 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2056 aDetectedOSLanguages = RTCString::join(mDetectedOSLanguages, " ");
2057 return S_OK;
2058}
2059
2060HRESULT Unattended::getDetectedOSHints(com::Utf8Str &aDetectedOSHints)
2061{
2062 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2063 aDetectedOSHints = mStrDetectedOSHints;
2064 return S_OK;
2065}
2066
2067/*
2068 * Getters that the installer and script classes can use.
2069 */
2070Utf8Str const &Unattended::i_getIsoPath() const
2071{
2072 Assert(isReadLockedOnCurrentThread());
2073 return mStrIsoPath;
2074}
2075
2076Utf8Str const &Unattended::i_getUser() const
2077{
2078 Assert(isReadLockedOnCurrentThread());
2079 return mStrUser;
2080}
2081
2082Utf8Str const &Unattended::i_getPassword() const
2083{
2084 Assert(isReadLockedOnCurrentThread());
2085 return mStrPassword;
2086}
2087
2088Utf8Str const &Unattended::i_getFullUserName() const
2089{
2090 Assert(isReadLockedOnCurrentThread());
2091 return mStrFullUserName.isNotEmpty() ? mStrFullUserName : mStrUser;
2092}
2093
2094Utf8Str const &Unattended::i_getProductKey() const
2095{
2096 Assert(isReadLockedOnCurrentThread());
2097 return mStrProductKey;
2098}
2099
2100Utf8Str const &Unattended::i_getAdditionsIsoPath() const
2101{
2102 Assert(isReadLockedOnCurrentThread());
2103 return mStrAdditionsIsoPath;
2104}
2105
2106bool Unattended::i_getInstallGuestAdditions() const
2107{
2108 Assert(isReadLockedOnCurrentThread());
2109 return mfInstallGuestAdditions;
2110}
2111
2112Utf8Str const &Unattended::i_getValidationKitIsoPath() const
2113{
2114 Assert(isReadLockedOnCurrentThread());
2115 return mStrValidationKitIsoPath;
2116}
2117
2118bool Unattended::i_getInstallTestExecService() const
2119{
2120 Assert(isReadLockedOnCurrentThread());
2121 return mfInstallTestExecService;
2122}
2123
2124Utf8Str const &Unattended::i_getTimeZone() const
2125{
2126 Assert(isReadLockedOnCurrentThread());
2127 return mStrTimeZone;
2128}
2129
2130PCRTTIMEZONEINFO Unattended::i_getTimeZoneInfo() const
2131{
2132 Assert(isReadLockedOnCurrentThread());
2133 return mpTimeZoneInfo;
2134}
2135
2136Utf8Str const &Unattended::i_getLocale() const
2137{
2138 Assert(isReadLockedOnCurrentThread());
2139 return mStrLocale;
2140}
2141
2142Utf8Str const &Unattended::i_getLanguage() const
2143{
2144 Assert(isReadLockedOnCurrentThread());
2145 return mStrLanguage;
2146}
2147
2148Utf8Str const &Unattended::i_getCountry() const
2149{
2150 Assert(isReadLockedOnCurrentThread());
2151 return mStrCountry;
2152}
2153
2154bool Unattended::i_isMinimalInstallation() const
2155{
2156 size_t i = mPackageSelectionAdjustments.size();
2157 while (i-- > 0)
2158 if (mPackageSelectionAdjustments[i].equals("minimal"))
2159 return true;
2160 return false;
2161}
2162
2163Utf8Str const &Unattended::i_getHostname() const
2164{
2165 Assert(isReadLockedOnCurrentThread());
2166 return mStrHostname;
2167}
2168
2169Utf8Str const &Unattended::i_getAuxiliaryBasePath() const
2170{
2171 Assert(isReadLockedOnCurrentThread());
2172 return mStrAuxiliaryBasePath;
2173}
2174
2175ULONG Unattended::i_getImageIndex() const
2176{
2177 Assert(isReadLockedOnCurrentThread());
2178 return midxImage;
2179}
2180
2181Utf8Str const &Unattended::i_getScriptTemplatePath() const
2182{
2183 Assert(isReadLockedOnCurrentThread());
2184 return mStrScriptTemplatePath;
2185}
2186
2187Utf8Str const &Unattended::i_getPostInstallScriptTemplatePath() const
2188{
2189 Assert(isReadLockedOnCurrentThread());
2190 return mStrPostInstallScriptTemplatePath;
2191}
2192
2193Utf8Str const &Unattended::i_getPostInstallCommand() const
2194{
2195 Assert(isReadLockedOnCurrentThread());
2196 return mStrPostInstallCommand;
2197}
2198
2199Utf8Str const &Unattended::i_getExtraInstallKernelParameters() const
2200{
2201 Assert(isReadLockedOnCurrentThread());
2202 return mStrExtraInstallKernelParameters;
2203}
2204
2205bool Unattended::i_isRtcUsingUtc() const
2206{
2207 Assert(isReadLockedOnCurrentThread());
2208 return mfRtcUseUtc;
2209}
2210
2211bool Unattended::i_isGuestOs64Bit() const
2212{
2213 Assert(isReadLockedOnCurrentThread());
2214 return mfGuestOs64Bit;
2215}
2216
2217VBOXOSTYPE Unattended::i_getGuestOsType() const
2218{
2219 Assert(isReadLockedOnCurrentThread());
2220 return meGuestOsType;
2221}
2222
2223HRESULT Unattended::i_attachImage(UnattendedInstallationDisk const *pImage, ComPtr<IMachine> const &rPtrSessionMachine,
2224 AutoMultiWriteLock2 &rLock)
2225{
2226 /*
2227 * Attach the disk image
2228 * HACK ALERT! Temporarily release the Unattended lock.
2229 */
2230 rLock.release();
2231
2232 ComPtr<IMedium> ptrMedium;
2233 HRESULT rc = mParent->OpenMedium(Bstr(pImage->strImagePath).raw(),
2234 pImage->enmDeviceType,
2235 pImage->enmAccessType,
2236 true,
2237 ptrMedium.asOutParam());
2238 LogRelFlowFunc(("VirtualBox::openMedium -> %Rhrc\n", rc));
2239 if (SUCCEEDED(rc))
2240 {
2241 if (pImage->fMountOnly)
2242 {
2243 // mount the opened disk image
2244 rc = rPtrSessionMachine->MountMedium(Bstr(pImage->strControllerName).raw(), pImage->uPort,
2245 pImage->uDevice, ptrMedium, TRUE /*fForce*/);
2246 LogRelFlowFunc(("Machine::MountMedium -> %Rhrc\n", rc));
2247 }
2248 else
2249 {
2250 //attach the opened disk image to the controller
2251 rc = rPtrSessionMachine->AttachDevice(Bstr(pImage->strControllerName).raw(), pImage->uPort,
2252 pImage->uDevice, pImage->enmDeviceType, ptrMedium);
2253 LogRelFlowFunc(("Machine::AttachDevice -> %Rhrc\n", rc));
2254 }
2255 }
2256
2257 rLock.acquire();
2258 return rc;
2259}
2260
2261bool Unattended::i_isGuestOSArchX64(Utf8Str const &rStrGuestOsTypeId)
2262{
2263 ComPtr<IGuestOSType> pGuestOSType;
2264 HRESULT hrc = mParent->GetGuestOSType(Bstr(rStrGuestOsTypeId).raw(), pGuestOSType.asOutParam());
2265 if (SUCCEEDED(hrc))
2266 {
2267 BOOL fIs64Bit = FALSE;
2268 hrc = pGuestOSType->COMGETTER(Is64Bit)(&fIs64Bit);
2269 if (SUCCEEDED(hrc))
2270 return fIs64Bit != FALSE;
2271 }
2272 return false;
2273}
2274
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