VirtualBox

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

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

Main/UnattendedImpl.cpp: More old RHEL/OEL detection.

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