VirtualBox

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

Last change on this file since 93311 was 93311, checked in by vboxsync, 3 years ago

bugref:10182. Adding the code path necessary to parse info file of debian based distros to determine OS type and architecture. Some related GUI changes are done too.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 124.1 KB
Line 
1/* $Id: UnattendedImpl.cpp 93311 2022-01-18 12:19:06Z vboxsync $ */
2/** @file
3 * Unattended class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2022 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#include <iprt/vfs.h>
41
42using namespace std;
43
44
45/*********************************************************************************************************************************
46* Structures and Typedefs *
47*********************************************************************************************************************************/
48/**
49 * Controller slot for a DVD drive.
50 *
51 * The slot can be free and needing a drive to be attached along with the ISO
52 * image, or it may already be there and only need mounting the ISO. The
53 * ControllerSlot::fFree member indicates which it is.
54 */
55struct ControllerSlot
56{
57 StorageBus_T enmBus;
58 Utf8Str strControllerName;
59 LONG iPort;
60 LONG iDevice;
61 bool fFree;
62
63 ControllerSlot(StorageBus_T a_enmBus, const Utf8Str &a_rName, LONG a_iPort, LONG a_iDevice, bool a_fFree)
64 : enmBus(a_enmBus), strControllerName(a_rName), iPort(a_iPort), iDevice(a_iDevice), fFree(a_fFree)
65 {}
66
67 bool operator<(const ControllerSlot &rThat) const
68 {
69 if (enmBus == rThat.enmBus)
70 {
71 if (strControllerName == rThat.strControllerName)
72 {
73 if (iPort == rThat.iPort)
74 return iDevice < rThat.iDevice;
75 return iPort < rThat.iPort;
76 }
77 return strControllerName < rThat.strControllerName;
78 }
79
80 /*
81 * Bus comparsion in boot priority order.
82 */
83 /* IDE first. */
84 if (enmBus == StorageBus_IDE)
85 return true;
86 if (rThat.enmBus == StorageBus_IDE)
87 return false;
88 /* SATA next */
89 if (enmBus == StorageBus_SATA)
90 return true;
91 if (rThat.enmBus == StorageBus_SATA)
92 return false;
93 /* SCSI next */
94 if (enmBus == StorageBus_SCSI)
95 return true;
96 if (rThat.enmBus == StorageBus_SCSI)
97 return false;
98 /* numerical */
99 return (int)enmBus < (int)rThat.enmBus;
100 }
101
102 bool operator==(const ControllerSlot &rThat) const
103 {
104 return enmBus == rThat.enmBus
105 && strControllerName == rThat.strControllerName
106 && iPort == rThat.iPort
107 && iDevice == rThat.iDevice;
108 }
109};
110
111/**
112 * Installation disk.
113 *
114 * Used when reconfiguring the VM.
115 */
116typedef struct UnattendedInstallationDisk
117{
118 StorageBus_T enmBusType; /**< @todo nobody is using this... */
119 Utf8Str strControllerName;
120 DeviceType_T enmDeviceType;
121 AccessMode_T enmAccessType;
122 LONG iPort;
123 LONG iDevice;
124 bool fMountOnly;
125 Utf8Str strImagePath;
126
127 UnattendedInstallationDisk(StorageBus_T a_enmBusType, Utf8Str const &a_rBusName, DeviceType_T a_enmDeviceType,
128 AccessMode_T a_enmAccessType, LONG a_iPort, LONG a_iDevice, bool a_fMountOnly,
129 Utf8Str const &a_rImagePath)
130 : enmBusType(a_enmBusType), strControllerName(a_rBusName), enmDeviceType(a_enmDeviceType), enmAccessType(a_enmAccessType)
131 , iPort(a_iPort), iDevice(a_iDevice), fMountOnly(a_fMountOnly), strImagePath(a_rImagePath)
132 {
133 Assert(strControllerName.length() > 0);
134 }
135
136 UnattendedInstallationDisk(std::list<ControllerSlot>::const_iterator const &itDvdSlot, Utf8Str const &a_rImagePath)
137 : enmBusType(itDvdSlot->enmBus), strControllerName(itDvdSlot->strControllerName), enmDeviceType(DeviceType_DVD)
138 , enmAccessType(AccessMode_ReadOnly), iPort(itDvdSlot->iPort), iDevice(itDvdSlot->iDevice)
139 , fMountOnly(!itDvdSlot->fFree), strImagePath(a_rImagePath)
140 {
141 Assert(strControllerName.length() > 0);
142 }
143} UnattendedInstallationDisk;
144
145
146/**
147 * OS/2 syslevel file header.
148 */
149#pragma pack(1)
150typedef struct OS2SYSLEVELHDR
151{
152 uint16_t uMinusOne; /**< 0x00: UINT16_MAX */
153 char achSignature[8]; /**< 0x02: "SYSLEVEL" */
154 uint8_t abReserved1[5]; /**< 0x0a: Usually zero. Ignore. */
155 uint16_t uSyslevelFileVer; /**< 0x0f: The syslevel file version: 1. */
156 uint8_t abReserved2[16]; /**< 0x11: Zero. Ignore. */
157 uint32_t offTable; /**< 0x21: Offset of the syslevel table. */
158} OS2SYSLEVELHDR;
159#pragma pack()
160AssertCompileSize(OS2SYSLEVELHDR, 0x25);
161
162/**
163 * OS/2 syslevel table entry.
164 */
165#pragma pack(1)
166typedef struct OS2SYSLEVELENTRY
167{
168 uint16_t id; /**< 0x00: ? */
169 uint8_t bEdition; /**< 0x02: The OS/2 edition: 0=standard, 1=extended, x=component defined */
170 uint8_t bVersion; /**< 0x03: 0x45 = 4.5 */
171 uint8_t bModify; /**< 0x04: Lower nibble is added to bVersion, so 0x45 0x02 => 4.52 */
172 uint8_t abReserved1[2]; /**< 0x05: Zero. Ignore. */
173 char achCsdLevel[8]; /**< 0x07: The current CSD level. */
174 char achCsdPrior[8]; /**< 0x0f: The prior CSD level. */
175 char szName[80]; /**< 0x5f: System/component name. */
176 char achId[9]; /**< 0x67: System/component ID. */
177 uint8_t bRefresh; /**< 0x70: Single digit refresh version, ignored if zero. */
178 char szType[9]; /**< 0x71: Some kind of type string. Optional */
179 uint8_t abReserved2[6]; /**< 0x7a: Zero. Ignore. */
180} OS2SYSLEVELENTRY;
181#pragma pack()
182AssertCompileSize(OS2SYSLEVELENTRY, 0x80);
183
184
185//////////////////////////////////////////////////////////////////////////////////////////////////////
186/*
187*
188*
189* Implementation Unattended functions
190*
191*/
192//////////////////////////////////////////////////////////////////////////////////////////////////////
193
194Unattended::Unattended()
195 : mhThreadReconfigureVM(NIL_RTNATIVETHREAD), mfRtcUseUtc(false), mfGuestOs64Bit(false)
196 , mpInstaller(NULL), mpTimeZoneInfo(NULL), mfIsDefaultAuxiliaryBasePath(true), mfDoneDetectIsoOS(false)
197{ }
198
199Unattended::~Unattended()
200{
201 if (mpInstaller)
202 {
203 delete mpInstaller;
204 mpInstaller = NULL;
205 }
206}
207
208HRESULT Unattended::FinalConstruct()
209{
210 return BaseFinalConstruct();
211}
212
213void Unattended::FinalRelease()
214{
215 uninit();
216
217 BaseFinalRelease();
218}
219
220void Unattended::uninit()
221{
222 /* Enclose the state transition Ready->InUninit->NotReady */
223 AutoUninitSpan autoUninitSpan(this);
224 if (autoUninitSpan.uninitDone())
225 return;
226
227 unconst(mParent) = NULL;
228 mMachine.setNull();
229}
230
231/**
232 * Initializes the unattended object.
233 *
234 * @param aParent Pointer to the parent object.
235 */
236HRESULT Unattended::initUnattended(VirtualBox *aParent)
237{
238 LogFlowThisFunc(("aParent=%p\n", aParent));
239 ComAssertRet(aParent, E_INVALIDARG);
240
241 /* Enclose the state transition NotReady->InInit->Ready */
242 AutoInitSpan autoInitSpan(this);
243 AssertReturn(autoInitSpan.isOk(), E_FAIL);
244
245 unconst(mParent) = aParent;
246
247 /*
248 * Fill public attributes (IUnattended) with useful defaults.
249 */
250 try
251 {
252 mStrUser = "vboxuser";
253 mStrPassword = "changeme";
254 mfInstallGuestAdditions = false;
255 mfInstallTestExecService = false;
256 midxImage = 1;
257
258 HRESULT hrc = mParent->i_getSystemProperties()->i_getDefaultAdditionsISO(mStrAdditionsIsoPath);
259 ComAssertComRCRet(hrc, hrc);
260 }
261 catch (std::bad_alloc &)
262 {
263 return E_OUTOFMEMORY;
264 }
265
266 /*
267 * Confirm a successful initialization
268 */
269 autoInitSpan.setSucceeded();
270
271 return S_OK;
272}
273
274HRESULT Unattended::detectIsoOS()
275{
276 HRESULT hrc;
277 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
278
279/** @todo once UDF is implemented properly and we've tested this code a lot
280 * more, replace E_NOTIMPL with E_FAIL. */
281
282
283 /*
284 * Open the ISO.
285 */
286 RTVFSFILE hVfsFileIso;
287 int vrc = RTVfsFileOpenNormal(mStrIsoPath.c_str(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFileIso);
288 if (RT_FAILURE(vrc))
289 return setErrorBoth(E_NOTIMPL, vrc, tr("Failed to open '%s' (%Rrc)"), mStrIsoPath.c_str(), vrc);
290
291 RTERRINFOSTATIC ErrInfo;
292 RTVFS hVfsIso;
293 vrc = RTFsIso9660VolOpen(hVfsFileIso, 0 /*fFlags*/, &hVfsIso, RTErrInfoInitStatic(&ErrInfo));
294 if (RT_SUCCESS(vrc))
295 {
296 /*
297 * Try do the detection. Repeat for different file system variations (nojoliet, noudf).
298 */
299 hrc = i_innerDetectIsoOS(hVfsIso);
300
301 RTVfsRelease(hVfsIso);
302 if (hrc != S_FALSE) /** @todo Finish the linux and windows detection code. Only OS/2 returns S_OK right now. */
303 hrc = E_NOTIMPL;
304 }
305 else if (RTErrInfoIsSet(&ErrInfo.Core))
306 hrc = setErrorBoth(E_NOTIMPL, vrc, tr("Failed to open '%s' as ISO FS (%Rrc) - %s"),
307 mStrIsoPath.c_str(), vrc, ErrInfo.Core.pszMsg);
308 else
309 hrc = setErrorBoth(E_NOTIMPL, vrc, tr("Failed to open '%s' as ISO FS (%Rrc)"), mStrIsoPath.c_str(), vrc);
310 RTVfsFileRelease(hVfsFileIso);
311
312 /*
313 * Just fake up some windows installation media locale (for <UILanguage>).
314 * Note! The translation here isn't perfect. Feel free to send us a patch.
315 */
316 if (mDetectedOSLanguages.size() == 0)
317 {
318 char szTmp[16];
319 const char *pszFilename = RTPathFilename(mStrIsoPath.c_str());
320 if ( pszFilename
321 && RT_C_IS_ALPHA(pszFilename[0])
322 && RT_C_IS_ALPHA(pszFilename[1])
323 && (pszFilename[2] == '-' || pszFilename[2] == '_') )
324 {
325 szTmp[0] = (char)RT_C_TO_LOWER(pszFilename[0]);
326 szTmp[1] = (char)RT_C_TO_LOWER(pszFilename[1]);
327 szTmp[2] = '-';
328 if (szTmp[0] == 'e' && szTmp[1] == 'n')
329 strcpy(&szTmp[3], "US");
330 else if (szTmp[0] == 'a' && szTmp[1] == 'r')
331 strcpy(&szTmp[3], "SA");
332 else if (szTmp[0] == 'd' && szTmp[1] == 'a')
333 strcpy(&szTmp[3], "DK");
334 else if (szTmp[0] == 'e' && szTmp[1] == 't')
335 strcpy(&szTmp[3], "EE");
336 else if (szTmp[0] == 'e' && szTmp[1] == 'l')
337 strcpy(&szTmp[3], "GR");
338 else if (szTmp[0] == 'h' && szTmp[1] == 'e')
339 strcpy(&szTmp[3], "IL");
340 else if (szTmp[0] == 'j' && szTmp[1] == 'a')
341 strcpy(&szTmp[3], "JP");
342 else if (szTmp[0] == 's' && szTmp[1] == 'v')
343 strcpy(&szTmp[3], "SE");
344 else if (szTmp[0] == 'u' && szTmp[1] == 'k')
345 strcpy(&szTmp[3], "UA");
346 else if (szTmp[0] == 'c' && szTmp[1] == 's')
347 strcpy(szTmp, "cs-CZ");
348 else if (szTmp[0] == 'n' && szTmp[1] == 'o')
349 strcpy(szTmp, "nb-NO");
350 else if (szTmp[0] == 'p' && szTmp[1] == 'p')
351 strcpy(szTmp, "pt-PT");
352 else if (szTmp[0] == 'p' && szTmp[1] == 't')
353 strcpy(szTmp, "pt-BR");
354 else if (szTmp[0] == 'c' && szTmp[1] == 'n')
355 strcpy(szTmp, "zh-CN");
356 else if (szTmp[0] == 'h' && szTmp[1] == 'k')
357 strcpy(szTmp, "zh-HK");
358 else if (szTmp[0] == 't' && szTmp[1] == 'w')
359 strcpy(szTmp, "zh-TW");
360 else if (szTmp[0] == 's' && szTmp[1] == 'r')
361 strcpy(szTmp, "sr-Latn-CS"); /* hmm */
362 else
363 {
364 szTmp[3] = (char)RT_C_TO_UPPER(pszFilename[0]);
365 szTmp[4] = (char)RT_C_TO_UPPER(pszFilename[1]);
366 szTmp[5] = '\0';
367 }
368 }
369 else
370 strcpy(szTmp, "en-US");
371 try
372 {
373 mDetectedOSLanguages.append(szTmp);
374 }
375 catch (std::bad_alloc &)
376 {
377 return E_OUTOFMEMORY;
378 }
379 }
380
381 /** @todo implement actual detection logic. */
382 return hrc;
383}
384
385HRESULT Unattended::i_innerDetectIsoOS(RTVFS hVfsIso)
386{
387 DETECTBUFFER uBuf;
388 VBOXOSTYPE enmOsType = VBOXOSTYPE_Unknown;
389 HRESULT hrc = i_innerDetectIsoOSWindows(hVfsIso, &uBuf, &enmOsType);
390 if (hrc == S_FALSE && enmOsType == VBOXOSTYPE_Unknown)
391 hrc = i_innerDetectIsoOSLinux(hVfsIso, &uBuf, &enmOsType);
392 if (hrc == S_FALSE && enmOsType == VBOXOSTYPE_Unknown)
393 hrc = i_innerDetectIsoOSOs2(hVfsIso, &uBuf, &enmOsType);
394 if (enmOsType != VBOXOSTYPE_Unknown)
395 {
396 try { mStrDetectedOSTypeId = Global::OSTypeId(enmOsType); }
397 catch (std::bad_alloc &) { hrc = E_OUTOFMEMORY; }
398 }
399 return hrc;
400}
401
402/**
403 * Detect Windows ISOs.
404 *
405 * @returns COM status code.
406 * @retval S_OK if detected
407 * @retval S_FALSE if not fully detected.
408 *
409 * @param hVfsIso The ISO file system.
410 * @param pBuf Read buffer.
411 * @param penmOsType Where to return the OS type. This is initialized to
412 * VBOXOSTYPE_Unknown.
413 */
414HRESULT Unattended::i_innerDetectIsoOSWindows(RTVFS hVfsIso, DETECTBUFFER *pBuf, VBOXOSTYPE *penmOsType)
415{
416 /** @todo The 'sources/' path can differ. */
417
418 // globalinstallorder.xml - vista beta2
419 // sources/idwbinfo.txt - ditto.
420 // sources/lang.ini - ditto.
421
422 /*
423 * Try look for the 'sources/idwbinfo.txt' file containing windows build info.
424 * This file appeared with Vista beta 2 from what we can tell. Before windows 10
425 * it contains easily decodable branch names, after that things goes weird.
426 */
427 const char *pszVersion = NULL;
428 const char *pszProduct = NULL;
429 RTVFSFILE hVfsFile;
430 int vrc = RTVfsFileOpen(hVfsIso, "sources/idwbinfo.txt", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
431 if (RT_SUCCESS(vrc))
432 {
433 *penmOsType = VBOXOSTYPE_WinNT_x64;
434
435 RTINIFILE hIniFile;
436 vrc = RTIniFileCreateFromVfsFile(&hIniFile, hVfsFile, RTINIFILE_F_READONLY);
437 RTVfsFileRelease(hVfsFile);
438 if (RT_SUCCESS(vrc))
439 {
440 vrc = RTIniFileQueryValue(hIniFile, "BUILDINFO", "BuildArch", pBuf->sz, sizeof(*pBuf), NULL);
441 if (RT_SUCCESS(vrc))
442 {
443 LogRelFlow(("Unattended: sources/idwbinfo.txt: BuildArch=%s\n", pBuf->sz));
444 if ( RTStrNICmp(pBuf->sz, RT_STR_TUPLE("amd64")) == 0
445 || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("x64")) == 0 /* just in case */ )
446 *penmOsType = VBOXOSTYPE_WinNT_x64;
447 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("x86")) == 0)
448 *penmOsType = VBOXOSTYPE_WinNT;
449 else
450 {
451 LogRel(("Unattended: sources/idwbinfo.txt: Unknown: BuildArch=%s\n", pBuf->sz));
452 *penmOsType = VBOXOSTYPE_WinNT_x64;
453 }
454 }
455
456 vrc = RTIniFileQueryValue(hIniFile, "BUILDINFO", "BuildBranch", pBuf->sz, sizeof(*pBuf), NULL);
457 if (RT_SUCCESS(vrc))
458 {
459 LogRelFlow(("Unattended: sources/idwbinfo.txt: BuildBranch=%s\n", pBuf->sz));
460 if ( RTStrNICmp(pBuf->sz, RT_STR_TUPLE("vista")) == 0
461 || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("winmain_beta")) == 0)
462 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_WinVista);
463 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("lh_sp2rtm")) == 0)
464 {
465 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_WinVista);
466 pszVersion = "sp2";
467 }
468 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("longhorn_rtm")) == 0)
469 {
470 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_WinVista);
471 pszVersion = "sp1";
472 }
473 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("win7")) == 0)
474 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win7);
475 else if ( RTStrNICmp(pBuf->sz, RT_STR_TUPLE("winblue")) == 0
476 || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("winmain_blue")) == 0
477 || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("win81")) == 0 /* not seen, but just in case its out there */ )
478 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win81);
479 else if ( RTStrNICmp(pBuf->sz, RT_STR_TUPLE("win8")) == 0
480 || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("winmain_win8")) == 0 )
481 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win8);
482 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("th1")) == 0)
483 {
484 pszVersion = "1507"; // aka. GA, retroactively 1507
485 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
486 }
487 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("th2")) == 0)
488 {
489 pszVersion = "1511"; // aka. threshold 2
490 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
491 }
492 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("rs1_release")) == 0)
493 {
494 pszVersion = "1607"; // aka. anniversay update; rs=redstone
495 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
496 }
497 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("rs2_release")) == 0)
498 {
499 pszVersion = "1703"; // aka. creators update
500 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
501 }
502 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("rs3_release")) == 0)
503 {
504 pszVersion = "1709"; // aka. fall creators update
505 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
506 }
507 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("rs4_release")) == 0)
508 {
509 pszVersion = "1803";
510 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
511 }
512 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("rs5_release")) == 0)
513 {
514 pszVersion = "1809";
515 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
516 }
517 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("19h1_release")) == 0)
518 {
519 pszVersion = "1903";
520 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
521 }
522 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("19h2_release")) == 0)
523 {
524 pszVersion = "1909"; // ??
525 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
526 }
527 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("20h1_release")) == 0)
528 {
529 pszVersion = "2003"; // ??
530 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
531 }
532 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("vb_release")) == 0)
533 {
534 pszVersion = "2004"; // ?? vb=Vibranium
535 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
536 }
537 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("20h2_release")) == 0)
538 {
539 pszVersion = "2009"; // ??
540 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
541 }
542 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("21h1_release")) == 0)
543 {
544 pszVersion = "2103"; // ??
545 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
546 }
547 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("21h2_release")) == 0)
548 {
549 pszVersion = "2109"; // ??
550 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win10);
551 }
552 else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("co_release")) == 0)
553 {
554 pszVersion = "21H2"; // ??
555 *penmOsType = VBOXOSTYPE_Win11_x64;
556 }
557 else
558 LogRel(("Unattended: sources/idwbinfo.txt: Unknown: BuildBranch=%s\n", pBuf->sz));
559 }
560 RTIniFileRelease(hIniFile);
561 }
562 }
563 bool fClarifyProd = false;
564 if (RT_FAILURE(vrc))
565 {
566 /*
567 * Check a INF file with a DriverVer that is updated with each service pack.
568 * DriverVer=10/01/2002,5.2.3790.3959
569 */
570 vrc = RTVfsFileOpen(hVfsIso, "AMD64/HIVESYS.INF", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
571 if (RT_SUCCESS(vrc))
572 *penmOsType = VBOXOSTYPE_WinNT_x64;
573 else
574 {
575 vrc = RTVfsFileOpen(hVfsIso, "I386/HIVESYS.INF", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
576 if (RT_SUCCESS(vrc))
577 *penmOsType = VBOXOSTYPE_WinNT;
578 }
579 if (RT_SUCCESS(vrc))
580 {
581 RTINIFILE hIniFile;
582 vrc = RTIniFileCreateFromVfsFile(&hIniFile, hVfsFile, RTINIFILE_F_READONLY);
583 RTVfsFileRelease(hVfsFile);
584 if (RT_SUCCESS(vrc))
585 {
586 vrc = RTIniFileQueryValue(hIniFile, "Version", "DriverVer", pBuf->sz, sizeof(*pBuf), NULL);
587 if (RT_SUCCESS(vrc))
588 {
589 LogRelFlow(("Unattended: HIVESYS.INF: DriverVer=%s\n", pBuf->sz));
590 const char *psz = strchr(pBuf->sz, ',');
591 psz = psz ? psz + 1 : pBuf->sz;
592 if (RTStrVersionCompare(psz, "6.0.0") >= 0)
593 LogRel(("Unattended: HIVESYS.INF: unknown: DriverVer=%s\n", psz));
594 else if (RTStrVersionCompare(psz, "5.2.0") >= 0) /* W2K3, XP64 */
595 {
596 fClarifyProd = true;
597 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win2k3);
598 if (RTStrVersionCompare(psz, "5.2.3790.3959") >= 0)
599 pszVersion = "sp2";
600 else if (RTStrVersionCompare(psz, "5.2.3790.1830") >= 0)
601 pszVersion = "sp1";
602 }
603 else if (RTStrVersionCompare(psz, "5.1.0") >= 0) /* XP */
604 {
605 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_WinXP);
606 if (RTStrVersionCompare(psz, "5.1.2600.5512") >= 0)
607 pszVersion = "sp3";
608 else if (RTStrVersionCompare(psz, "5.1.2600.2180") >= 0)
609 pszVersion = "sp2";
610 else if (RTStrVersionCompare(psz, "5.1.2600.1105") >= 0)
611 pszVersion = "sp1";
612 }
613 else if (RTStrVersionCompare(psz, "5.0.0") >= 0)
614 {
615 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win2k);
616 if (RTStrVersionCompare(psz, "5.0.2195.6717") >= 0)
617 pszVersion = "sp4";
618 else if (RTStrVersionCompare(psz, "5.0.2195.5438") >= 0)
619 pszVersion = "sp3";
620 else if (RTStrVersionCompare(psz, "5.0.2195.1620") >= 0)
621 pszVersion = "sp1";
622 }
623 else
624 LogRel(("Unattended: HIVESYS.INF: unknown: DriverVer=%s\n", psz));
625 }
626 RTIniFileRelease(hIniFile);
627 }
628 }
629 }
630 if (RT_FAILURE(vrc) || fClarifyProd)
631 {
632 /*
633 * NT 4 and older does not have DriverVer entries, we consult the PRODSPEC.INI, which
634 * works for NT4 & W2K. It does usually not reflect the service pack.
635 */
636 vrc = RTVfsFileOpen(hVfsIso, "AMD64/PRODSPEC.INI", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
637 if (RT_SUCCESS(vrc))
638 *penmOsType = VBOXOSTYPE_WinNT_x64;
639 else
640 {
641 vrc = RTVfsFileOpen(hVfsIso, "I386/PRODSPEC.INI", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
642 if (RT_SUCCESS(vrc))
643 *penmOsType = VBOXOSTYPE_WinNT;
644 }
645 if (RT_SUCCESS(vrc))
646 {
647
648 RTINIFILE hIniFile;
649 vrc = RTIniFileCreateFromVfsFile(&hIniFile, hVfsFile, RTINIFILE_F_READONLY);
650 RTVfsFileRelease(hVfsFile);
651 if (RT_SUCCESS(vrc))
652 {
653 vrc = RTIniFileQueryValue(hIniFile, "Product Specification", "Version", pBuf->sz, sizeof(*pBuf), NULL);
654 if (RT_SUCCESS(vrc))
655 {
656 LogRelFlow(("Unattended: PRODSPEC.INI: Version=%s\n", pBuf->sz));
657 if (RTStrVersionCompare(pBuf->sz, "5.1") >= 0) /* Shipped with XP + W2K3, but version stuck at 5.0. */
658 LogRel(("Unattended: PRODSPEC.INI: unknown: DriverVer=%s\n", pBuf->sz));
659 else if (RTStrVersionCompare(pBuf->sz, "5.0") >= 0) /* 2000 */
660 {
661 vrc = RTIniFileQueryValue(hIniFile, "Product Specification", "Product", pBuf->sz, sizeof(*pBuf), NULL);
662 if (RT_SUCCESS(vrc) && RTStrNICmp(pBuf->sz, RT_STR_TUPLE("Windows XP")) == 0)
663 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_WinXP);
664 else if (RT_SUCCESS(vrc) && RTStrNICmp(pBuf->sz, RT_STR_TUPLE("Windows Server 2003")) == 0)
665 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win2k3);
666 else
667 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win2k);
668
669 if (RT_SUCCESS(vrc) && (strstr(pBuf->sz, "Server") || strstr(pBuf->sz, "server")))
670 pszProduct = "Server";
671 }
672 else if (RTStrVersionCompare(pBuf->sz, "4.0") >= 0) /* NT4 */
673 *penmOsType = VBOXOSTYPE_WinNT4;
674 else
675 LogRel(("Unattended: PRODSPEC.INI: unknown: DriverVer=%s\n", pBuf->sz));
676
677 vrc = RTIniFileQueryValue(hIniFile, "Product Specification", "ProductType", pBuf->sz, sizeof(*pBuf), NULL);
678 if (RT_SUCCESS(vrc))
679 pszProduct = strcmp(pBuf->sz, "0") == 0 ? "Workstation" : /* simplification: */ "Server";
680 }
681 RTIniFileRelease(hIniFile);
682 }
683 }
684 if (fClarifyProd)
685 vrc = VINF_SUCCESS;
686 }
687 if (RT_FAILURE(vrc))
688 {
689 /*
690 * NT 3.x we look at the LoadIdentifier (boot manager) string in TXTSETUP.SIF/TXT.
691 */
692 vrc = RTVfsFileOpen(hVfsIso, "I386/TXTSETUP.SIF", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
693 if (RT_FAILURE(vrc))
694 vrc = RTVfsFileOpen(hVfsIso, "I386/TXTSETUP.INF", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
695 if (RT_SUCCESS(vrc))
696 {
697 *penmOsType = VBOXOSTYPE_WinNT;
698
699 RTINIFILE hIniFile;
700 vrc = RTIniFileCreateFromVfsFile(&hIniFile, hVfsFile, RTINIFILE_F_READONLY);
701 RTVfsFileRelease(hVfsFile);
702 if (RT_SUCCESS(vrc))
703 {
704 vrc = RTIniFileQueryValue(hIniFile, "SetupData", "ProductType", pBuf->sz, sizeof(*pBuf), NULL);
705 if (RT_SUCCESS(vrc))
706 pszProduct = strcmp(pBuf->sz, "0") == 0 ? "Workstation" : /* simplification: */ "Server";
707
708 vrc = RTIniFileQueryValue(hIniFile, "SetupData", "LoadIdentifier", pBuf->sz, sizeof(*pBuf), NULL);
709 if (RT_SUCCESS(vrc))
710 {
711 LogRelFlow(("Unattended: TXTSETUP.SIF: LoadIdentifier=%s\n", pBuf->sz));
712 char *psz = pBuf->sz;
713 while (!RT_C_IS_DIGIT(*psz) && *psz)
714 psz++;
715 char *psz2 = psz;
716 while (RT_C_IS_DIGIT(*psz2) || *psz2 == '.')
717 psz2++;
718 *psz2 = '\0';
719 if (RTStrVersionCompare(psz, "6.0") >= 0)
720 LogRel(("Unattended: TXTSETUP.SIF: unknown: LoadIdentifier=%s\n", pBuf->sz));
721 else if (RTStrVersionCompare(psz, "4.0") >= 0)
722 *penmOsType = VBOXOSTYPE_WinNT4;
723 else if (RTStrVersionCompare(psz, "3.1") >= 0)
724 {
725 *penmOsType = VBOXOSTYPE_WinNT3x;
726 pszVersion = psz;
727 }
728 else
729 LogRel(("Unattended: TXTSETUP.SIF: unknown: LoadIdentifier=%s\n", pBuf->sz));
730 }
731 RTIniFileRelease(hIniFile);
732 }
733 }
734 }
735
736 if (pszVersion)
737 try { mStrDetectedOSVersion = pszVersion; }
738 catch (std::bad_alloc &) { return E_OUTOFMEMORY; }
739 if (pszProduct)
740 try { mStrDetectedOSFlavor = pszProduct; }
741 catch (std::bad_alloc &) { return E_OUTOFMEMORY; }
742
743 /*
744 * Look for sources/lang.ini and try parse it to get the languages out of it.
745 */
746 /** @todo We could also check sources/??-* and boot/??-* if lang.ini is not
747 * found or unhelpful. */
748 vrc = RTVfsFileOpen(hVfsIso, "sources/lang.ini", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
749 if (RT_SUCCESS(vrc))
750 {
751 RTINIFILE hIniFile;
752 vrc = RTIniFileCreateFromVfsFile(&hIniFile, hVfsFile, RTINIFILE_F_READONLY);
753 RTVfsFileRelease(hVfsFile);
754 if (RT_SUCCESS(vrc))
755 {
756 mDetectedOSLanguages.clear();
757
758 uint32_t idxPair;
759 for (idxPair = 0; idxPair < 256; idxPair++)
760 {
761 size_t cbHalf = sizeof(*pBuf) / 2;
762 char *pszKey = pBuf->sz;
763 char *pszValue = &pBuf->sz[cbHalf];
764 vrc = RTIniFileQueryPair(hIniFile, "Available UI Languages", idxPair,
765 pszKey, cbHalf, NULL, pszValue, cbHalf, NULL);
766 if (RT_SUCCESS(vrc))
767 {
768 try
769 {
770 mDetectedOSLanguages.append(pszKey);
771 }
772 catch (std::bad_alloc &)
773 {
774 RTIniFileRelease(hIniFile);
775 return E_OUTOFMEMORY;
776 }
777 }
778 else if (vrc == VERR_NOT_FOUND)
779 break;
780 else
781 Assert(vrc == VERR_BUFFER_OVERFLOW);
782 }
783 if (idxPair == 0)
784 LogRel(("Unattended: Warning! Empty 'Available UI Languages' section in sources/lang.ini\n"));
785 RTIniFileRelease(hIniFile);
786 }
787 }
788
789 /** @todo look at the install.wim file too, extracting the XML (easy) and
790 * figure out the available image numbers and such. The format is
791 * documented. It would also provide really accurate Windows
792 * version information without the need to guess. The current
793 * content of mStrDetectedOSVersion is mostly useful for human
794 * consumption. ~~Long term it should be possible to have version
795 * conditionals (expr style, please) in the templates, which
796 * would make them a lot easier to write and more flexible at the
797 * same time. - done already~~
798 *
799 * Here is how to list images inside an install.wim file from powershell:
800 * https://docs.microsoft.com/en-us/powershell/module/dism/get-windowsimage?view=windowsserver2022-ps
801 *
802 * Unfortunately, powershell is available by default on non-windows hosts, so we
803 * have to do it ourselves of course, but this can help when coding & testing.
804 */
805
806 return S_FALSE;
807}
808
809/**
810 * Detects linux architecture.
811 *
812 * @returns true if detected, false if not.
813 * @param pszArch The architecture string.
814 * @param penmOsType Where to return the arch and type on success.
815 * @param enmBaseOsType The base (x86) OS type to return.
816 */
817static bool detectLinuxArch(const char *pszArch, VBOXOSTYPE *penmOsType, VBOXOSTYPE enmBaseOsType)
818{
819 if ( RTStrNICmp(pszArch, RT_STR_TUPLE("amd64")) == 0
820 || RTStrNICmp(pszArch, RT_STR_TUPLE("x86_64")) == 0
821 || RTStrNICmp(pszArch, RT_STR_TUPLE("x86-64")) == 0 /* just in case */
822 || RTStrNICmp(pszArch, RT_STR_TUPLE("x64")) == 0 /* ditto */ )
823 {
824 *penmOsType = (VBOXOSTYPE)(enmBaseOsType | VBOXOSTYPE_x64);
825 return true;
826 }
827
828 if ( RTStrNICmp(pszArch, RT_STR_TUPLE("x86")) == 0
829 || RTStrNICmp(pszArch, RT_STR_TUPLE("i386")) == 0
830 || RTStrNICmp(pszArch, RT_STR_TUPLE("i486")) == 0
831 || RTStrNICmp(pszArch, RT_STR_TUPLE("i586")) == 0
832 || RTStrNICmp(pszArch, RT_STR_TUPLE("i686")) == 0
833 || RTStrNICmp(pszArch, RT_STR_TUPLE("i786")) == 0
834 || RTStrNICmp(pszArch, RT_STR_TUPLE("i886")) == 0
835 || RTStrNICmp(pszArch, RT_STR_TUPLE("i986")) == 0)
836 {
837 *penmOsType = enmBaseOsType;
838 return true;
839 }
840
841 /** @todo check for 'noarch' since source CDs have been seen to use that. */
842 return false;
843}
844
845/**
846 * Detects linux architecture by searching for the architecture substring in @p pszArch.
847 *
848 * @returns true if detected, false if not.
849 * @param pszArch The architecture string.
850 * @param penmOsType Where to return the arch and type on success.
851 * @param enmBaseOsType The base (x86) OS type to return.
852 */
853static bool detectLinuxArchII(const char *pszArch, VBOXOSTYPE *penmOsType, VBOXOSTYPE enmBaseOsType)
854{
855 if ( RTStrIStr(pszArch, "amd64") != NULL
856 || RTStrIStr(pszArch, "x86_64") != NULL
857 || RTStrIStr(pszArch, "x86-64") != NULL /* just in case */
858 || RTStrIStr(pszArch, "x64") != NULL /* ditto */ )
859 {
860 *penmOsType = (VBOXOSTYPE)(enmBaseOsType | VBOXOSTYPE_x64);
861 return true;
862 }
863
864 if ( RTStrIStr(pszArch, "x86") != NULL
865 || RTStrIStr(pszArch, "i386") != NULL
866 || RTStrIStr(pszArch, "i486") != NULL
867 || RTStrIStr(pszArch, "i586") != NULL
868 || RTStrIStr(pszArch, "i686") != NULL
869 || RTStrIStr(pszArch, "i786") != NULL
870 || RTStrIStr(pszArch, "i886") != NULL
871 || RTStrIStr(pszArch, "i986") != NULL)
872 {
873 *penmOsType = enmBaseOsType;
874 return true;
875 }
876 return false;
877}
878
879static bool detectLinuxDistroName(const char *pszOsAndVersion, VBOXOSTYPE *penmOsType, const char **ppszNext)
880{
881 bool fRet = true;
882
883 if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Red")) == 0
884 && !RT_C_IS_ALNUM(pszOsAndVersion[3]))
885
886 {
887 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 3);
888 if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Hat")) == 0
889 && !RT_C_IS_ALNUM(pszOsAndVersion[3]))
890 {
891 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_RedHat);
892 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 3);
893 }
894 else
895 fRet = false;
896 }
897 else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Oracle")) == 0
898 && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
899 {
900 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Oracle);
901 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
902 }
903 else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("CentOS")) == 0
904 && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
905 {
906 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_RedHat);
907 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
908 }
909 else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Fedora")) == 0
910 && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
911 {
912 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_FedoraCore);
913 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
914 }
915 else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Ubuntu")) == 0
916 && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
917 {
918 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Ubuntu);
919 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
920 }
921 else if ( ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Xubuntu")) == 0
922 || RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Kubuntu")) == 0)
923 && !RT_C_IS_ALNUM(pszOsAndVersion[7]))
924 {
925 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Ubuntu);
926 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 7);
927 }
928 else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Debian")) == 0
929 && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
930 {
931 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Debian);
932 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
933 }
934 else
935 fRet = false;
936
937 /*
938 * Skip forward till we get a number.
939 */
940 if (ppszNext)
941 {
942 *ppszNext = pszOsAndVersion;
943 char ch;
944 for (const char *pszVersion = pszOsAndVersion; (ch = *pszVersion) != '\0'; pszVersion++)
945 if (RT_C_IS_DIGIT(ch))
946 {
947 *ppszNext = pszVersion;
948 break;
949 }
950 }
951 return fRet;
952}
953
954
955/**
956 * Detect Linux distro ISOs.
957 *
958 * @returns COM status code.
959 * @retval S_OK if detected
960 * @retval S_FALSE if not fully detected.
961 *
962 * @param hVfsIso The ISO file system.
963 * @param pBuf Read buffer.
964 * @param penmOsType Where to return the OS type. This is initialized to
965 * VBOXOSTYPE_Unknown.
966 */
967HRESULT Unattended::i_innerDetectIsoOSLinux(RTVFS hVfsIso, DETECTBUFFER *pBuf, VBOXOSTYPE *penmOsType)
968{
969 /*
970 * Redhat and derivatives may have a .treeinfo (ini-file style) with useful info
971 * or at least a barebone .discinfo file.
972 */
973
974 /*
975 * Start with .treeinfo: https://release-engineering.github.io/productmd/treeinfo-1.0.html
976 */
977 RTVFSFILE hVfsFile;
978 int vrc = RTVfsFileOpen(hVfsIso, ".treeinfo", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
979 if (RT_SUCCESS(vrc))
980 {
981 RTINIFILE hIniFile;
982 vrc = RTIniFileCreateFromVfsFile(&hIniFile, hVfsFile, RTINIFILE_F_READONLY);
983 RTVfsFileRelease(hVfsFile);
984 if (RT_SUCCESS(vrc))
985 {
986 /* Try figure the architecture first (like with windows). */
987 vrc = RTIniFileQueryValue(hIniFile, "tree", "arch", pBuf->sz, sizeof(*pBuf), NULL);
988 if (RT_FAILURE(vrc) || !pBuf->sz[0])
989 vrc = RTIniFileQueryValue(hIniFile, "general", "arch", pBuf->sz, sizeof(*pBuf), NULL);
990 if (RT_SUCCESS(vrc))
991 {
992 LogRelFlow(("Unattended: .treeinfo: arch=%s\n", pBuf->sz));
993 if (!detectLinuxArch(pBuf->sz, penmOsType, VBOXOSTYPE_RedHat))
994 LogRel(("Unattended: .treeinfo: Unknown: arch='%s'\n", pBuf->sz));
995 }
996 else
997 LogRel(("Unattended: .treeinfo: No 'arch' property.\n"));
998
999 /* Try figure the release name, it doesn't have to be redhat. */
1000 vrc = RTIniFileQueryValue(hIniFile, "release", "name", pBuf->sz, sizeof(*pBuf), NULL);
1001 if (RT_FAILURE(vrc) || !pBuf->sz[0])
1002 vrc = RTIniFileQueryValue(hIniFile, "product", "name", pBuf->sz, sizeof(*pBuf), NULL);
1003 if (RT_FAILURE(vrc) || !pBuf->sz[0])
1004 vrc = RTIniFileQueryValue(hIniFile, "general", "family", pBuf->sz, sizeof(*pBuf), NULL);
1005 if (RT_SUCCESS(vrc))
1006 {
1007 LogRelFlow(("Unattended: .treeinfo: name/family=%s\n", pBuf->sz));
1008 if (!detectLinuxDistroName(pBuf->sz, penmOsType, NULL))
1009 {
1010 LogRel(("Unattended: .treeinfo: Unknown: name/family='%s', assuming Red Hat\n", pBuf->sz));
1011 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_RedHat);
1012 }
1013 }
1014
1015 /* Try figure the version. */
1016 vrc = RTIniFileQueryValue(hIniFile, "release", "version", pBuf->sz, sizeof(*pBuf), NULL);
1017 if (RT_FAILURE(vrc) || !pBuf->sz[0])
1018 vrc = RTIniFileQueryValue(hIniFile, "product", "version", pBuf->sz, sizeof(*pBuf), NULL);
1019 if (RT_FAILURE(vrc) || !pBuf->sz[0])
1020 vrc = RTIniFileQueryValue(hIniFile, "general", "version", pBuf->sz, sizeof(*pBuf), NULL);
1021 if (RT_SUCCESS(vrc))
1022 {
1023 LogRelFlow(("Unattended: .treeinfo: version=%s\n", pBuf->sz));
1024 try { mStrDetectedOSVersion = RTStrStrip(pBuf->sz); }
1025 catch (std::bad_alloc &) { return E_OUTOFMEMORY; }
1026 }
1027
1028 RTIniFileRelease(hIniFile);
1029 }
1030
1031 if (*penmOsType != VBOXOSTYPE_Unknown)
1032 return S_FALSE;
1033 }
1034
1035 /*
1036 * Try .discinfo next: https://release-engineering.github.io/productmd/discinfo-1.0.html
1037 * We will probably need additional info here...
1038 */
1039 vrc = RTVfsFileOpen(hVfsIso, ".discinfo", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1040 if (RT_SUCCESS(vrc))
1041 {
1042 size_t cchIgn;
1043 vrc = RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(*pBuf) - 1, &cchIgn);
1044 pBuf->sz[RT_SUCCESS(vrc) ? cchIgn : 0] = '\0';
1045 RTVfsFileRelease(hVfsFile);
1046
1047 /* Parse and strip the first 5 lines. */
1048 const char *apszLines[5];
1049 char *psz = pBuf->sz;
1050 for (unsigned i = 0; i < RT_ELEMENTS(apszLines); i++)
1051 {
1052 apszLines[i] = psz;
1053 if (*psz)
1054 {
1055 char *pszEol = (char *)strchr(psz, '\n');
1056 if (!pszEol)
1057 psz = strchr(psz, '\0');
1058 else
1059 {
1060 *pszEol = '\0';
1061 apszLines[i] = RTStrStrip(psz);
1062 psz = pszEol + 1;
1063 }
1064 }
1065 }
1066
1067 /* Do we recognize the architecture? */
1068 LogRelFlow(("Unattended: .discinfo: arch=%s\n", apszLines[2]));
1069 if (!detectLinuxArch(apszLines[2], penmOsType, VBOXOSTYPE_RedHat))
1070 LogRel(("Unattended: .discinfo: Unknown: arch='%s'\n", apszLines[2]));
1071
1072 /* Do we recognize the release string? */
1073 LogRelFlow(("Unattended: .discinfo: product+version=%s\n", apszLines[1]));
1074 const char *pszVersion = NULL;
1075 if (!detectLinuxDistroName(apszLines[1], penmOsType, &pszVersion))
1076 LogRel(("Unattended: .discinfo: Unknown: release='%s'\n", apszLines[1]));
1077
1078 if (*pszVersion)
1079 {
1080 LogRelFlow(("Unattended: .discinfo: version=%s\n", pszVersion));
1081 try { mStrDetectedOSVersion = RTStrStripL(pszVersion); }
1082 catch (std::bad_alloc &) { return E_OUTOFMEMORY; }
1083
1084 /* CentOS likes to call their release 'Final' without mentioning the actual version
1085 number (e.g. CentOS-4.7-x86_64-binDVD.iso), so we need to go look elsewhere.
1086 This is only important for centos 4.x and 3.x releases. */
1087 if (RTStrNICmp(pszVersion, RT_STR_TUPLE("Final")) == 0)
1088 {
1089 static const char * const s_apszDirs[] = { "CentOS/RPMS/", "RedHat/RPMS", "Server", "Workstation" };
1090 for (unsigned iDir = 0; iDir < RT_ELEMENTS(s_apszDirs); iDir++)
1091 {
1092 RTVFSDIR hVfsDir;
1093 vrc = RTVfsDirOpen(hVfsIso, s_apszDirs[iDir], 0, &hVfsDir);
1094 if (RT_FAILURE(vrc))
1095 continue;
1096 char szRpmDb[128];
1097 char szReleaseRpm[128];
1098 szRpmDb[0] = '\0';
1099 szReleaseRpm[0] = '\0';
1100 for (;;)
1101 {
1102 RTDIRENTRYEX DirEntry;
1103 size_t cbDirEntry = sizeof(DirEntry);
1104 vrc = RTVfsDirReadEx(hVfsDir, &DirEntry, &cbDirEntry, RTFSOBJATTRADD_NOTHING);
1105 if (RT_FAILURE(vrc))
1106 break;
1107
1108 /* redhat-release-4WS-2.4.i386.rpm
1109 centos-release-4-7.x86_64.rpm, centos-release-4-4.3.i386.rpm
1110 centos-release-5-3.el5.centos.1.x86_64.rpm */
1111 if ( (psz = strstr(DirEntry.szName, "-release-")) != NULL
1112 || (psz = strstr(DirEntry.szName, "-RELEASE-")) != NULL)
1113 {
1114 psz += 9;
1115 if (RT_C_IS_DIGIT(*psz))
1116 RTStrCopy(szReleaseRpm, sizeof(szReleaseRpm), psz);
1117 }
1118 /* rpmdb-redhat-4WS-2.4.i386.rpm,
1119 rpmdb-CentOS-4.5-0.20070506.i386.rpm,
1120 rpmdb-redhat-3.9-0.20070703.i386.rpm. */
1121 else if ( ( RTStrStartsWith(DirEntry.szName, "rpmdb-")
1122 || RTStrStartsWith(DirEntry.szName, "RPMDB-"))
1123 && RT_C_IS_DIGIT(DirEntry.szName[6]) )
1124 RTStrCopy(szRpmDb, sizeof(szRpmDb), &DirEntry.szName[6]);
1125 }
1126 RTVfsDirRelease(hVfsDir);
1127
1128 /* Did we find anything relvant? */
1129 psz = szRpmDb;
1130 if (!RT_C_IS_DIGIT(*psz))
1131 psz = szReleaseRpm;
1132 if (RT_C_IS_DIGIT(*psz))
1133 {
1134 /* Convert '-' to '.' and strip stuff which doesn't look like a version string. */
1135 char *pszCur = psz + 1;
1136 for (char ch = *pszCur; ch != '\0'; ch = *++pszCur)
1137 if (ch == '-')
1138 *pszCur = '.';
1139 else if (ch != '.' && !RT_C_IS_DIGIT(ch))
1140 {
1141 *pszCur = '\0';
1142 break;
1143 }
1144 while (&pszCur[-1] != psz && pszCur[-1] == '.')
1145 *--pszCur = '\0';
1146
1147 /* Set it and stop looking. */
1148 try { mStrDetectedOSVersion = psz; }
1149 catch (std::bad_alloc &) { return E_OUTOFMEMORY; }
1150 break;
1151 }
1152 }
1153 }
1154 }
1155
1156 if (*penmOsType != VBOXOSTYPE_Unknown)
1157 return S_FALSE;
1158 }
1159
1160 /*
1161 * Ubuntu has a README.diskdefins file on their ISO (already on 4.10 / warty warthog).
1162 * Example content:
1163 * #define DISKNAME Ubuntu 4.10 "Warty Warthog" - Preview amd64 Binary-1
1164 * #define TYPE binary
1165 * #define TYPEbinary 1
1166 * #define ARCH amd64
1167 * #define ARCHamd64 1
1168 * #define DISKNUM 1
1169 * #define DISKNUM1 1
1170 * #define TOTALNUM 1
1171 * #define TOTALNUM1 1
1172 */
1173 vrc = RTVfsFileOpen(hVfsIso, "README.diskdefines", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1174 if (RT_SUCCESS(vrc))
1175 {
1176 size_t cchIgn;
1177 vrc = RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(*pBuf) - 1, &cchIgn);
1178 pBuf->sz[RT_SUCCESS(vrc) ? cchIgn : 0] = '\0';
1179 RTVfsFileRelease(hVfsFile);
1180
1181 /* Find the DISKNAME and ARCH defines. */
1182 const char *pszDiskName = NULL;
1183 const char *pszArch = NULL;
1184 char *psz = pBuf->sz;
1185 for (unsigned i = 0; *psz != '\0'; i++)
1186 {
1187 while (RT_C_IS_BLANK(*psz))
1188 psz++;
1189
1190 /* Match #define: */
1191 static const char s_szDefine[] = "#define";
1192 if ( strncmp(psz, s_szDefine, sizeof(s_szDefine) - 1) == 0
1193 && RT_C_IS_BLANK(psz[sizeof(s_szDefine) - 1]))
1194 {
1195 psz = &psz[sizeof(s_szDefine) - 1];
1196 while (RT_C_IS_BLANK(*psz))
1197 psz++;
1198
1199 /* Match the identifier: */
1200 char *pszIdentifier = psz;
1201 if (RT_C_IS_ALPHA(*psz) || *psz == '_')
1202 {
1203 do
1204 psz++;
1205 while (RT_C_IS_ALNUM(*psz) || *psz == '_');
1206 size_t cchIdentifier = (size_t)(psz - pszIdentifier);
1207
1208 /* Skip to the value. */
1209 while (RT_C_IS_BLANK(*psz))
1210 psz++;
1211 char *pszValue = psz;
1212
1213 /* Skip to EOL and strip the value. */
1214 char *pszEol = psz = strchr(psz, '\n');
1215 if (psz)
1216 *psz++ = '\0';
1217 else
1218 pszEol = strchr(pszValue, '\0');
1219 while (pszEol > pszValue && RT_C_IS_SPACE(pszEol[-1]))
1220 *--pszEol = '\0';
1221
1222 LogRelFlow(("Unattended: README.diskdefines: %.*s=%s\n", cchIdentifier, pszIdentifier, pszValue));
1223
1224 /* Do identifier matching: */
1225 if (cchIdentifier == sizeof("DISKNAME") - 1 && strncmp(pszIdentifier, RT_STR_TUPLE("DISKNAME")) == 0)
1226 pszDiskName = pszValue;
1227 else if (cchIdentifier == sizeof("ARCH") - 1 && strncmp(pszIdentifier, RT_STR_TUPLE("ARCH")) == 0)
1228 pszArch = pszValue;
1229 else
1230 continue;
1231 if (pszDiskName == NULL || pszArch == NULL)
1232 continue;
1233 break;
1234 }
1235 }
1236
1237 /* Next line: */
1238 psz = strchr(psz, '\n');
1239 if (!psz)
1240 break;
1241 psz++;
1242 }
1243
1244 /* Did we find both of them? */
1245 if (pszDiskName && pszArch)
1246 {
1247 if (!detectLinuxArch(pszArch, penmOsType, VBOXOSTYPE_Ubuntu))
1248 LogRel(("Unattended: README.diskdefines: Unknown: arch='%s'\n", pszArch));
1249
1250 const char *pszVersion = NULL;
1251 if (detectLinuxDistroName(pszDiskName, penmOsType, &pszVersion))
1252 {
1253 LogRelFlow(("Unattended: README.diskdefines: version=%s\n", pszVersion));
1254 try { mStrDetectedOSVersion = RTStrStripL(pszVersion); }
1255 catch (std::bad_alloc &) { return E_OUTOFMEMORY; }
1256 }
1257 else
1258 LogRel(("Unattended: README.diskdefines: Unknown: diskname='%s'\n", pszDiskName));
1259 }
1260 else
1261 LogRel(("Unattended: README.diskdefines: Did not find both DISKNAME and ARCH. :-/\n"));
1262
1263 if (*penmOsType != VBOXOSTYPE_Unknown)
1264 return S_FALSE;
1265 }
1266
1267 /*
1268 * All of the debian based distro versions I checked have a single line ./disk/info file.
1269 * Only info I could find related to .disk folder is: https://lists.debian.org/debian-cd/2004/01/msg00069.html
1270 * Some example content from several install ISOs is as follows:
1271 * Ubuntu 4.10 "Warty Warthog" - Preview amd64 Binary-1 (20041020)
1272 * Linux Mint 20.3 "Una" - Release amd64 20220104
1273 * Debian GNU/Linux 11.2.0 "Bullseye" - Official amd64 NETINST 20211218-11:12
1274 * Debian GNU/Linux 9.13.0 "Stretch" - Official amd64 DVD Binary-1 20200718-11:07
1275 * Xubuntu 20.04.2.0 LTS "Focal Fossa" - Release amd64 (20210209.1)
1276 * Ubuntu 17.10 "Artful Aardvark" - Release amd64 (20180105.1)
1277 * Ubuntu 16.04.6 LTS "Xenial Xerus" - Release i386 (20190227.1)
1278 * Debian GNU/Linux 8.11.1 "Jessie" - Official amd64 CD Binary-1 20190211-02:10
1279 * Kali GNU/Linux 2021.3a "Kali-last-snapshot" - Official amd64 BD Binary-1 with firmware 20211015-16:55
1280 */
1281 vrc = RTVfsFileOpen(hVfsIso, ".disk/info", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1282 if (RT_SUCCESS(vrc))
1283 {
1284 size_t cchIgn;
1285 vrc = RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(*pBuf) - 1, &cchIgn);
1286 pBuf->sz[RT_SUCCESS(vrc) ? cchIgn : 0] = '\0';
1287
1288 pBuf->sz[sizeof(*pBuf) - 1] = '\0';
1289 RTVfsFileRelease(hVfsFile);
1290
1291 char *psz = pBuf->sz;
1292 char *pszDiskName = psz;
1293 char *pszArch = NULL;
1294
1295 /* Only care about the first line of the file even if it is multi line and assume disk name ended with ' - '.*/
1296 psz = RTStrStr(pBuf->sz, " - ");
1297 if (psz && memchr(pBuf->sz, '\n', (size_t)(psz - pBuf->sz)) == NULL)
1298 {
1299 *psz = '\0';
1300 psz += 3;
1301 if (*psz)
1302 pszArch = psz;
1303 }
1304
1305 if (pszDiskName && pszArch)
1306 {
1307 if (!detectLinuxArchII(pszArch, penmOsType, VBOXOSTYPE_Ubuntu))
1308 LogRel(("Unattended: README.diskdefines: Unknown: arch='%s'\n", pszArch));
1309
1310 const char *pszVersion = NULL;
1311 if (detectLinuxDistroName(pszDiskName, penmOsType, &pszVersion))
1312 {
1313 LogRelFlow(("Unattended: README.diskdefines: version=%s\n", pszVersion));
1314 try { mStrDetectedOSVersion = RTStrStripL(pszVersion); }
1315 catch (std::bad_alloc &) { return E_OUTOFMEMORY; }
1316 }
1317 else
1318 LogRel(("Unattended: README.diskdefines: Unknown: diskname='%s'\n", pszDiskName));
1319 }
1320 else
1321 LogRel(("Unattended: README.diskdefines: Did not find both DISKNAME and ARCH. :-/\n"));
1322
1323 if (*penmOsType != VBOXOSTYPE_Unknown)
1324 return S_FALSE;
1325 }
1326
1327 return S_FALSE;
1328}
1329
1330
1331/**
1332 * Detect OS/2 installation ISOs.
1333 *
1334 * Mainly aiming at ACP2/MCP2 as that's what we currently use in our testing.
1335 *
1336 * @returns COM status code.
1337 * @retval S_OK if detected
1338 * @retval S_FALSE if not fully detected.
1339 *
1340 * @param hVfsIso The ISO file system.
1341 * @param pBuf Read buffer.
1342 * @param penmOsType Where to return the OS type. This is initialized to
1343 * VBOXOSTYPE_Unknown.
1344 */
1345HRESULT Unattended::i_innerDetectIsoOSOs2(RTVFS hVfsIso, DETECTBUFFER *pBuf, VBOXOSTYPE *penmOsType)
1346{
1347 /*
1348 * The OS2SE20.SRC contains the location of the tree with the diskette
1349 * images, typically "\OS2IMAGE".
1350 */
1351 RTVFSFILE hVfsFile;
1352 int vrc = RTVfsFileOpen(hVfsIso, "OS2SE20.SRC", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1353 if (RT_SUCCESS(vrc))
1354 {
1355 size_t cbRead = 0;
1356 vrc = RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(pBuf->sz) - 1, &cbRead);
1357 RTVfsFileRelease(hVfsFile);
1358 if (RT_SUCCESS(vrc))
1359 {
1360 pBuf->sz[cbRead] = '\0';
1361 RTStrStrip(pBuf->sz);
1362 vrc = RTStrValidateEncoding(pBuf->sz);
1363 if (RT_SUCCESS(vrc))
1364 LogRelFlow(("Unattended: OS2SE20.SRC=%s\n", pBuf->sz));
1365 else
1366 LogRel(("Unattended: OS2SE20.SRC invalid encoding: %Rrc, %.*Rhxs\n", vrc, cbRead, pBuf->sz));
1367 }
1368 else
1369 LogRel(("Unattended: Error reading OS2SE20.SRC: %\n", vrc));
1370 }
1371 /*
1372 * ArcaOS has dropped the file, assume it's \OS2IMAGE and see if it's there.
1373 */
1374 else if (vrc == VERR_FILE_NOT_FOUND)
1375 RTStrCopy(pBuf->sz, sizeof(pBuf->sz), "\\OS2IMAGE");
1376 else
1377 return S_FALSE;
1378
1379 /*
1380 * Check that the directory directory exists and has a DISK_0 under it
1381 * with an OS2LDR on it.
1382 */
1383 size_t const cchOs2Image = strlen(pBuf->sz);
1384 vrc = RTPathAppend(pBuf->sz, sizeof(pBuf->sz), "DISK_0/OS2LDR");
1385 RTFSOBJINFO ObjInfo = {0};
1386 vrc = RTVfsQueryPathInfo(hVfsIso, pBuf->sz, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
1387 if (vrc == VERR_FILE_NOT_FOUND)
1388 {
1389 RTStrCat(pBuf->sz, sizeof(pBuf->sz), "."); /* eCS 2.0 image includes the dot from the 8.3 name. */
1390 vrc = RTVfsQueryPathInfo(hVfsIso, pBuf->sz, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
1391 }
1392 if ( RT_FAILURE(vrc)
1393 || !RTFS_IS_FILE(ObjInfo.Attr.fMode))
1394 {
1395 LogRel(("Unattended: RTVfsQueryPathInfo(, '%s' (from OS2SE20.SRC),) -> %Rrc, fMode=%#x\n",
1396 pBuf->sz, vrc, ObjInfo.Attr.fMode));
1397 return S_FALSE;
1398 }
1399
1400 /*
1401 * So, it's some kind of OS/2 2.x or later ISO alright.
1402 */
1403 *penmOsType = VBOXOSTYPE_OS2;
1404 mStrDetectedOSHints.printf("OS2SE20.SRC=%.*s", cchOs2Image, pBuf->sz);
1405
1406 /*
1407 * ArcaOS ISOs seems to have a AOSBOOT dir on them.
1408 * This contains a ARCANOAE.FLG file with content we can use for the version:
1409 * ArcaOS 5.0.7 EN
1410 * Built 2021-12-07 18:34:34
1411 * We drop the "ArcaOS" bit, as it's covered by penmOsType. Then we pull up
1412 * the second line.
1413 *
1414 * Note! Yet to find a way to do unattended install of ArcaOS, as it comes
1415 * with no CD-boot floppy images, only simple .PF archive files for
1416 * unpacking onto the ram disk or whatever. Modifying these is
1417 * possible (ibsen's aPLib v0.36 compression with some simple custom
1418 * headers), but it would probably be a royal pain. Could perhaps
1419 * cook something from OS2IMAGE\DISK_0 thru 3...
1420 */
1421 vrc = RTVfsQueryPathInfo(hVfsIso, "AOSBOOT", &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
1422 if ( RT_SUCCESS(vrc)
1423 && RTFS_IS_DIRECTORY(ObjInfo.Attr.fMode))
1424 {
1425 *penmOsType = VBOXOSTYPE_ArcaOS;
1426
1427 /* Read the version file: */
1428 vrc = RTVfsFileOpen(hVfsIso, "SYS/ARCANOAE.FLG", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1429 if (RT_SUCCESS(vrc))
1430 {
1431 size_t cbRead = 0;
1432 vrc = RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(pBuf->sz) - 1, &cbRead);
1433 RTVfsFileRelease(hVfsFile);
1434 pBuf->sz[cbRead] = '\0';
1435 if (RT_SUCCESS(vrc))
1436 {
1437 /* Strip the OS name: */
1438 char *pszVersion = RTStrStrip(pBuf->sz);
1439 static char s_szArcaOS[] = "ArcaOS";
1440 if (RTStrStartsWith(pszVersion, s_szArcaOS))
1441 pszVersion = RTStrStripL(pszVersion + sizeof(s_szArcaOS) - 1);
1442
1443 /* Pull up the 2nd line if it, condensing the \r\n into a single space. */
1444 char *pszNewLine = strchr(pszVersion, '\n');
1445 if (pszNewLine && RTStrStartsWith(pszNewLine + 1, "Built 20"))
1446 {
1447 size_t offRemove = 0;
1448 while (RT_C_IS_SPACE(pszNewLine[-1 - (ssize_t)offRemove]))
1449 offRemove++;
1450 if (offRemove > 0)
1451 {
1452 pszNewLine -= offRemove;
1453 memmove(pszNewLine, pszNewLine + offRemove, strlen(pszNewLine + offRemove) - 1);
1454 }
1455 *pszNewLine = ' ';
1456 }
1457
1458 /* Drop any additional lines: */
1459 pszNewLine = strchr(pszVersion, '\n');
1460 if (pszNewLine)
1461 *pszNewLine = '\0';
1462 RTStrStripR(pszVersion);
1463
1464 /* Done (hope it makes some sense). */
1465 mStrDetectedOSVersion = pszVersion;
1466 }
1467 else
1468 LogRel(("Unattended: failed to read AOSBOOT/ARCANOAE.FLG: %Rrc\n", vrc));
1469 }
1470 else
1471 LogRel(("Unattended: failed to open AOSBOOT/ARCANOAE.FLG for reading: %Rrc\n", vrc));
1472 }
1473 /*
1474 * Similarly, eCS has an ECS directory and it typically contains a
1475 * ECS_INST.FLG file with the version info. Content differs a little:
1476 * eComStation 2.0 EN_US Thu May 13 10:27:54 pm 2010
1477 * Built on ECS60441318
1478 * Here we drop the "eComStation" bit and leave the 2nd line as it.
1479 *
1480 * Note! At least 2.0 has a DISKIMGS folder with what looks like boot
1481 * disks, so we could probably get something going here without
1482 * needing to write an OS2 boot sector...
1483 */
1484 else
1485 {
1486 vrc = RTVfsQueryPathInfo(hVfsIso, "ECS", &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
1487 if ( RT_SUCCESS(vrc)
1488 && RTFS_IS_DIRECTORY(ObjInfo.Attr.fMode))
1489 {
1490 *penmOsType = VBOXOSTYPE_ECS;
1491
1492 /* Read the version file: */
1493 vrc = RTVfsFileOpen(hVfsIso, "ECS/ECS_INST.FLG", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1494 if (RT_SUCCESS(vrc))
1495 {
1496 size_t cbRead = 0;
1497 vrc = RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(pBuf->sz) - 1, &cbRead);
1498 RTVfsFileRelease(hVfsFile);
1499 pBuf->sz[cbRead] = '\0';
1500 if (RT_SUCCESS(vrc))
1501 {
1502 /* Strip the OS name: */
1503 char *pszVersion = RTStrStrip(pBuf->sz);
1504 static char s_szECS[] = "eComStation";
1505 if (RTStrStartsWith(pszVersion, s_szECS))
1506 pszVersion = RTStrStripL(pszVersion + sizeof(s_szECS) - 1);
1507
1508 /* Drop any additional lines: */
1509 char *pszNewLine = strchr(pszVersion, '\n');
1510 if (pszNewLine)
1511 *pszNewLine = '\0';
1512 RTStrStripR(pszVersion);
1513
1514 /* Done (hope it makes some sense). */
1515 mStrDetectedOSVersion = pszVersion;
1516 }
1517 else
1518 LogRel(("Unattended: failed to read ECS/ECS_INST.FLG: %Rrc\n", vrc));
1519 }
1520 else
1521 LogRel(("Unattended: failed to open ECS/ECS_INST.FLG for reading: %Rrc\n", vrc));
1522 }
1523 else
1524 {
1525 /*
1526 * Official IBM OS/2 builds doesn't have any .FLG file on them,
1527 * so need to pry the information out in some other way. Best way
1528 * is to read the SYSLEVEL.OS2 file, which is typically on disk #2,
1529 * though on earlier versions (warp3) it was disk #1.
1530 */
1531 vrc = RTPathJoin(pBuf->sz, sizeof(pBuf->sz), strchr(mStrDetectedOSHints.c_str(), '=') + 1,
1532 "/DISK_2/SYSLEVEL.OS2");
1533 if (RT_SUCCESS(vrc))
1534 {
1535 vrc = RTVfsFileOpen(hVfsIso, pBuf->sz, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1536 if (vrc == VERR_FILE_NOT_FOUND)
1537 {
1538 RTPathJoin(pBuf->sz, sizeof(pBuf->sz), strchr(mStrDetectedOSHints.c_str(), '=') + 1, "/DISK_1/SYSLEVEL.OS2");
1539 vrc = RTVfsFileOpen(hVfsIso, pBuf->sz, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1540 }
1541 if (RT_SUCCESS(vrc))
1542 {
1543 RT_ZERO(pBuf->ab);
1544 size_t cbRead = 0;
1545 vrc = RTVfsFileRead(hVfsFile, pBuf->ab, sizeof(pBuf->ab), &cbRead);
1546 RTVfsFileRelease(hVfsFile);
1547 if (RT_SUCCESS(vrc))
1548 {
1549 /* Check the header. */
1550 OS2SYSLEVELHDR const *pHdr = (OS2SYSLEVELHDR const *)&pBuf->ab[0];
1551 if ( pHdr->uMinusOne == UINT16_MAX
1552 && pHdr->uSyslevelFileVer == 1
1553 && memcmp(pHdr->achSignature, RT_STR_TUPLE("SYSLEVEL")) == 0
1554 && pHdr->offTable < cbRead
1555 && pHdr->offTable + sizeof(OS2SYSLEVELENTRY) <= cbRead)
1556 {
1557 OS2SYSLEVELENTRY *pEntry = (OS2SYSLEVELENTRY *)&pBuf->ab[pHdr->offTable];
1558 if ( RT_SUCCESS(RTStrValidateEncodingEx(pEntry->szName, sizeof(pEntry->szName),
1559 RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED))
1560 && RT_SUCCESS(RTStrValidateEncodingEx(pEntry->achCsdLevel, sizeof(pEntry->achCsdLevel), 0))
1561 && pEntry->bVersion != 0
1562 && ((pEntry->bVersion >> 4) & 0xf) < 10
1563 && (pEntry->bVersion & 0xf) < 10
1564 && pEntry->bModify < 10
1565 && pEntry->bRefresh < 10)
1566 {
1567 /* Flavor: */
1568 char *pszName = RTStrStrip(pEntry->szName);
1569 if (pszName)
1570 mStrDetectedOSFlavor = pszName;
1571
1572 /* Version: */
1573 if (pEntry->bRefresh != 0)
1574 mStrDetectedOSVersion.printf("%d.%d%d.%d", pEntry->bVersion >> 4, pEntry->bVersion & 0xf,
1575 pEntry->bModify, pEntry->bRefresh);
1576 else
1577 mStrDetectedOSVersion.printf("%d.%d%d", pEntry->bVersion >> 4, pEntry->bVersion & 0xf,
1578 pEntry->bModify);
1579 pEntry->achCsdLevel[sizeof(pEntry->achCsdLevel) - 1] = '\0';
1580 char *pszCsd = RTStrStrip(pEntry->achCsdLevel);
1581 if (*pszCsd != '\0')
1582 {
1583 mStrDetectedOSVersion.append(' ');
1584 mStrDetectedOSVersion.append(pszCsd);
1585 }
1586 if (RTStrVersionCompare(mStrDetectedOSVersion.c_str(), "4.50") >= 0)
1587 *penmOsType = VBOXOSTYPE_OS2Warp45;
1588 else if (RTStrVersionCompare(mStrDetectedOSVersion.c_str(), "4.00") >= 0)
1589 *penmOsType = VBOXOSTYPE_OS2Warp4;
1590 else if (RTStrVersionCompare(mStrDetectedOSVersion.c_str(), "3.00") >= 0)
1591 *penmOsType = VBOXOSTYPE_OS2Warp3;
1592 }
1593 else
1594 LogRel(("Unattended: bogus SYSLEVEL.OS2 file entry: %.128Rhxd\n", pEntry));
1595 }
1596 else
1597 LogRel(("Unattended: bogus SYSLEVEL.OS2 file header: uMinusOne=%#x uSyslevelFileVer=%#x achSignature=%.8Rhxs offTable=%#x vs cbRead=%#zx\n",
1598 pHdr->uMinusOne, pHdr->uSyslevelFileVer, pHdr->achSignature, pHdr->offTable, cbRead));
1599 }
1600 else
1601 LogRel(("Unattended: failed to read SYSLEVEL.OS2: %Rrc\n", vrc));
1602 }
1603 else
1604 LogRel(("Unattended: failed to open '%s' for reading: %Rrc\n", pBuf->sz, vrc));
1605 }
1606 }
1607 }
1608
1609 /** @todo language detection? */
1610
1611 /*
1612 * Only tested ACP2, so only return S_OK for it.
1613 */
1614 if ( *penmOsType == VBOXOSTYPE_OS2Warp45
1615 && RTStrVersionCompare(mStrDetectedOSVersion.c_str(), "4.52") >= 0
1616 && mStrDetectedOSFlavor.contains("Server", RTCString::CaseInsensitive))
1617 return S_OK;
1618
1619 return S_FALSE;
1620}
1621
1622
1623HRESULT Unattended::prepare()
1624{
1625 LogFlow(("Unattended::prepare: enter\n"));
1626
1627 /*
1628 * Must have a machine.
1629 */
1630 ComPtr<Machine> ptrMachine;
1631 Guid MachineUuid;
1632 {
1633 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1634 ptrMachine = mMachine;
1635 if (ptrMachine.isNull())
1636 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("No machine associated with this IUnatteded instance"));
1637 MachineUuid = mMachineUuid;
1638 }
1639
1640 /*
1641 * Before we write lock ourselves, we must get stuff from Machine and
1642 * VirtualBox because their locks have higher priorities than ours.
1643 */
1644 Utf8Str strGuestOsTypeId;
1645 Utf8Str strMachineName;
1646 Utf8Str strDefaultAuxBasePath;
1647 HRESULT hrc;
1648 try
1649 {
1650 Bstr bstrTmp;
1651 hrc = ptrMachine->COMGETTER(OSTypeId)(bstrTmp.asOutParam());
1652 if (SUCCEEDED(hrc))
1653 {
1654 strGuestOsTypeId = bstrTmp;
1655 hrc = ptrMachine->COMGETTER(Name)(bstrTmp.asOutParam());
1656 if (SUCCEEDED(hrc))
1657 strMachineName = bstrTmp;
1658 }
1659 int vrc = ptrMachine->i_calculateFullPath(Utf8StrFmt("Unattended-%RTuuid-", MachineUuid.raw()), strDefaultAuxBasePath);
1660 if (RT_FAILURE(vrc))
1661 return setErrorBoth(E_FAIL, vrc);
1662 }
1663 catch (std::bad_alloc &)
1664 {
1665 return E_OUTOFMEMORY;
1666 }
1667 bool const fIs64Bit = i_isGuestOSArchX64(strGuestOsTypeId);
1668
1669 BOOL fRtcUseUtc = FALSE;
1670 hrc = ptrMachine->COMGETTER(RTCUseUTC)(&fRtcUseUtc);
1671 if (FAILED(hrc))
1672 return hrc;
1673
1674 FirmwareType_T enmFirmware = FirmwareType_BIOS;
1675 hrc = ptrMachine->COMGETTER(FirmwareType)(&enmFirmware);
1676 if (FAILED(hrc))
1677 return hrc;
1678
1679 /*
1680 * Write lock this object and set attributes we got from IMachine.
1681 */
1682 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1683
1684 mStrGuestOsTypeId = strGuestOsTypeId;
1685 mfGuestOs64Bit = fIs64Bit;
1686 mfRtcUseUtc = RT_BOOL(fRtcUseUtc);
1687 menmFirmwareType = enmFirmware;
1688
1689 /*
1690 * Do some state checks.
1691 */
1692 if (mpInstaller != NULL)
1693 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("The prepare method has been called (must call done to restart)"));
1694 if ((Machine *)ptrMachine != (Machine *)mMachine)
1695 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("The 'machine' while we were using it - please don't do that"));
1696
1697 /*
1698 * Check if the specified ISOs and files exist.
1699 */
1700 if (!RTFileExists(mStrIsoPath.c_str()))
1701 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the installation ISO file '%s'"),
1702 mStrIsoPath.c_str());
1703 if (mfInstallGuestAdditions && !RTFileExists(mStrAdditionsIsoPath.c_str()))
1704 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the Guest Additions ISO file '%s'"),
1705 mStrAdditionsIsoPath.c_str());
1706 if (mfInstallTestExecService && !RTFileExists(mStrValidationKitIsoPath.c_str()))
1707 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the validation kit ISO file '%s'"),
1708 mStrValidationKitIsoPath.c_str());
1709 if (mStrScriptTemplatePath.isNotEmpty() && !RTFileExists(mStrScriptTemplatePath.c_str()))
1710 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate unattended installation script template '%s'"),
1711 mStrScriptTemplatePath.c_str());
1712
1713 /*
1714 * Do media detection if it haven't been done yet.
1715 */
1716 if (!mfDoneDetectIsoOS)
1717 {
1718 hrc = detectIsoOS();
1719 if (FAILED(hrc) && hrc != E_NOTIMPL)
1720 return hrc;
1721 }
1722
1723 /*
1724 * Do some default property stuff and check other properties.
1725 */
1726 try
1727 {
1728 char szTmp[128];
1729
1730 if (mStrLocale.isEmpty())
1731 {
1732 int vrc = RTLocaleQueryNormalizedBaseLocaleName(szTmp, sizeof(szTmp));
1733 if ( RT_SUCCESS(vrc)
1734 && RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(szTmp))
1735 mStrLocale.assign(szTmp, 5);
1736 else
1737 mStrLocale = "en_US";
1738 Assert(RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(mStrLocale));
1739 }
1740
1741 if (mStrLanguage.isEmpty())
1742 {
1743 if (mDetectedOSLanguages.size() > 0)
1744 mStrLanguage = mDetectedOSLanguages[0];
1745 else
1746 mStrLanguage.assign(mStrLocale).findReplace('_', '-');
1747 }
1748
1749 if (mStrCountry.isEmpty())
1750 {
1751 int vrc = RTLocaleQueryUserCountryCode(szTmp);
1752 if (RT_SUCCESS(vrc))
1753 mStrCountry = szTmp;
1754 else if ( mStrLocale.isNotEmpty()
1755 && RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(mStrLocale))
1756 mStrCountry.assign(mStrLocale, 3, 2);
1757 else
1758 mStrCountry = "US";
1759 }
1760
1761 if (mStrTimeZone.isEmpty())
1762 {
1763 int vrc = RTTimeZoneGetCurrent(szTmp, sizeof(szTmp));
1764 if ( RT_SUCCESS(vrc)
1765 && strcmp(szTmp, "localtime") != 0 /* Typcial solaris TZ that isn't very helpful. */)
1766 mStrTimeZone = szTmp;
1767 else
1768 mStrTimeZone = "Etc/UTC";
1769 Assert(mStrTimeZone.isNotEmpty());
1770 }
1771 mpTimeZoneInfo = RTTimeZoneGetInfoByUnixName(mStrTimeZone.c_str());
1772 if (!mpTimeZoneInfo)
1773 mpTimeZoneInfo = RTTimeZoneGetInfoByWindowsName(mStrTimeZone.c_str());
1774 Assert(mpTimeZoneInfo || mStrTimeZone != "Etc/UTC");
1775 if (!mpTimeZoneInfo)
1776 LogRel(("Unattended::prepare: warning: Unknown time zone '%s'\n", mStrTimeZone.c_str()));
1777
1778 if (mStrHostname.isEmpty())
1779 {
1780 /* Mangle the VM name into a valid hostname. */
1781 for (size_t i = 0; i < strMachineName.length(); i++)
1782 {
1783 char ch = strMachineName[i];
1784 if ( (unsigned)ch < 127
1785 && RT_C_IS_ALNUM(ch))
1786 mStrHostname.append(ch);
1787 else if (mStrHostname.isNotEmpty() && RT_C_IS_PUNCT(ch) && !mStrHostname.endsWith("-"))
1788 mStrHostname.append('-');
1789 }
1790 if (mStrHostname.length() == 0)
1791 mStrHostname.printf("%RTuuid-vm", MachineUuid.raw());
1792 else if (mStrHostname.length() < 3)
1793 mStrHostname.append("-vm");
1794 mStrHostname.append(".myguest.virtualbox.org");
1795 }
1796
1797 if (mStrAuxiliaryBasePath.isEmpty())
1798 {
1799 mStrAuxiliaryBasePath = strDefaultAuxBasePath;
1800 mfIsDefaultAuxiliaryBasePath = true;
1801 }
1802 }
1803 catch (std::bad_alloc &)
1804 {
1805 return E_OUTOFMEMORY;
1806 }
1807
1808 /*
1809 * Get the guest OS type info and instantiate the appropriate installer.
1810 */
1811 uint32_t const idxOSType = Global::getOSTypeIndexFromId(mStrGuestOsTypeId.c_str());
1812 meGuestOsType = idxOSType < Global::cOSTypes ? Global::sOSTypes[idxOSType].osType : VBOXOSTYPE_Unknown;
1813
1814 mpInstaller = UnattendedInstaller::createInstance(meGuestOsType, mStrGuestOsTypeId, mStrDetectedOSVersion,
1815 mStrDetectedOSFlavor, mStrDetectedOSHints, this);
1816 if (mpInstaller != NULL)
1817 {
1818 hrc = mpInstaller->initInstaller();
1819 if (SUCCEEDED(hrc))
1820 {
1821 /*
1822 * Do the script preps (just reads them).
1823 */
1824 hrc = mpInstaller->prepareUnattendedScripts();
1825 if (SUCCEEDED(hrc))
1826 {
1827 LogFlow(("Unattended::prepare: returns S_OK\n"));
1828 return S_OK;
1829 }
1830 }
1831
1832 /* Destroy the installer instance. */
1833 delete mpInstaller;
1834 mpInstaller = NULL;
1835 }
1836 else
1837 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND,
1838 tr("Unattended installation is not supported for guest type '%s'"), mStrGuestOsTypeId.c_str());
1839 LogRelFlow(("Unattended::prepare: failed with %Rhrc\n", hrc));
1840 return hrc;
1841}
1842
1843HRESULT Unattended::constructMedia()
1844{
1845 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1846
1847 LogFlow(("===========================================================\n"));
1848 LogFlow(("Call Unattended::constructMedia()\n"));
1849
1850 if (mpInstaller == NULL)
1851 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, "prepare() not yet called");
1852
1853 return mpInstaller->prepareMedia();
1854}
1855
1856HRESULT Unattended::reconfigureVM()
1857{
1858 LogFlow(("===========================================================\n"));
1859 LogFlow(("Call Unattended::reconfigureVM()\n"));
1860
1861 /*
1862 * Interrogate VirtualBox/IGuestOSType before we lock stuff and create ordering issues.
1863 */
1864 StorageBus_T enmRecommendedStorageBus = StorageBus_IDE;
1865 {
1866 Bstr bstrGuestOsTypeId;
1867 {
1868 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1869 bstrGuestOsTypeId = mStrGuestOsTypeId;
1870 }
1871 ComPtr<IGuestOSType> ptrGuestOSType;
1872 HRESULT hrc = mParent->GetGuestOSType(bstrGuestOsTypeId.raw(), ptrGuestOSType.asOutParam());
1873 if (SUCCEEDED(hrc))
1874 {
1875 if (!ptrGuestOSType.isNull())
1876 hrc = ptrGuestOSType->COMGETTER(RecommendedDVDStorageBus)(&enmRecommendedStorageBus);
1877 }
1878 if (FAILED(hrc))
1879 return hrc;
1880 }
1881
1882 /*
1883 * Take write lock (for lock order reasons, write lock our parent object too)
1884 * then make sure we're the only caller of this method.
1885 */
1886 AutoMultiWriteLock2 alock(mMachine, this COMMA_LOCKVAL_SRC_POS);
1887 HRESULT hrc;
1888 if (mhThreadReconfigureVM == NIL_RTNATIVETHREAD)
1889 {
1890 RTNATIVETHREAD const hNativeSelf = RTThreadNativeSelf();
1891 mhThreadReconfigureVM = hNativeSelf;
1892
1893 /*
1894 * Create a new session, lock the machine and get the session machine object.
1895 * Do the locking without pinning down the write locks, just to be on the safe side.
1896 */
1897 ComPtr<ISession> ptrSession;
1898 try
1899 {
1900 hrc = ptrSession.createInprocObject(CLSID_Session);
1901 }
1902 catch (std::bad_alloc &)
1903 {
1904 hrc = E_OUTOFMEMORY;
1905 }
1906 if (SUCCEEDED(hrc))
1907 {
1908 alock.release();
1909 hrc = mMachine->LockMachine(ptrSession, LockType_Shared);
1910 alock.acquire();
1911 if (SUCCEEDED(hrc))
1912 {
1913 ComPtr<IMachine> ptrSessionMachine;
1914 hrc = ptrSession->COMGETTER(Machine)(ptrSessionMachine.asOutParam());
1915 if (SUCCEEDED(hrc))
1916 {
1917 /*
1918 * Hand the session to the inner work and let it do it job.
1919 */
1920 try
1921 {
1922 hrc = i_innerReconfigureVM(alock, enmRecommendedStorageBus, ptrSessionMachine);
1923 }
1924 catch (...)
1925 {
1926 hrc = E_UNEXPECTED;
1927 }
1928 }
1929
1930 /* Paranoia: release early in case we it a bump below. */
1931 Assert(mhThreadReconfigureVM == hNativeSelf);
1932 mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
1933
1934 /*
1935 * While unlocking the machine we'll have to drop the locks again.
1936 */
1937 alock.release();
1938
1939 ptrSessionMachine.setNull();
1940 HRESULT hrc2 = ptrSession->UnlockMachine();
1941 AssertLogRelMsg(SUCCEEDED(hrc2), ("UnlockMachine -> %Rhrc\n", hrc2));
1942
1943 ptrSession.setNull();
1944
1945 alock.acquire();
1946 }
1947 else
1948 mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
1949 }
1950 else
1951 mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
1952 }
1953 else
1954 hrc = setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("reconfigureVM running on other thread"));
1955 return hrc;
1956}
1957
1958
1959HRESULT Unattended::i_innerReconfigureVM(AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus,
1960 ComPtr<IMachine> const &rPtrSessionMachine)
1961{
1962 if (mpInstaller == NULL)
1963 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("prepare() not yet called"));
1964
1965 // Fetch all available storage controllers
1966 com::SafeIfaceArray<IStorageController> arrayOfControllers;
1967 HRESULT hrc = rPtrSessionMachine->COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(arrayOfControllers));
1968 AssertComRCReturn(hrc, hrc);
1969
1970 /*
1971 * Figure out where the images are to be mounted, adding controllers/ports as needed.
1972 */
1973 std::vector<UnattendedInstallationDisk> vecInstallationDisks;
1974 if (mpInstaller->isAuxiliaryFloppyNeeded())
1975 {
1976 hrc = i_reconfigureFloppy(arrayOfControllers, vecInstallationDisks, rPtrSessionMachine, rAutoLock);
1977 if (FAILED(hrc))
1978 return hrc;
1979 }
1980
1981 hrc = i_reconfigureIsos(arrayOfControllers, vecInstallationDisks, rPtrSessionMachine, rAutoLock, enmRecommendedStorageBus);
1982 if (FAILED(hrc))
1983 return hrc;
1984
1985 /*
1986 * Mount the images.
1987 */
1988 for (size_t idxImage = 0; idxImage < vecInstallationDisks.size(); idxImage++)
1989 {
1990 UnattendedInstallationDisk const *pImage = &vecInstallationDisks.at(idxImage);
1991 Assert(pImage->strImagePath.isNotEmpty());
1992 hrc = i_attachImage(pImage, rPtrSessionMachine, rAutoLock);
1993 if (FAILED(hrc))
1994 return hrc;
1995 }
1996
1997 /*
1998 * Set the boot order.
1999 *
2000 * ASSUME that the HD isn't bootable when we start out, but it will be what
2001 * we boot from after the first stage of the installation is done. Setting
2002 * it first prevents endless reboot cylces.
2003 */
2004 /** @todo consider making 100% sure the disk isn't bootable (edit partition
2005 * table active bits and EFI stuff). */
2006 Assert( mpInstaller->getBootableDeviceType() == DeviceType_DVD
2007 || mpInstaller->getBootableDeviceType() == DeviceType_Floppy);
2008 hrc = rPtrSessionMachine->SetBootOrder(1, DeviceType_HardDisk);
2009 if (SUCCEEDED(hrc))
2010 hrc = rPtrSessionMachine->SetBootOrder(2, mpInstaller->getBootableDeviceType());
2011 if (SUCCEEDED(hrc))
2012 hrc = rPtrSessionMachine->SetBootOrder(3, mpInstaller->getBootableDeviceType() == DeviceType_DVD
2013 ? DeviceType_Floppy : DeviceType_DVD);
2014 if (FAILED(hrc))
2015 return hrc;
2016
2017 /*
2018 * Essential step.
2019 *
2020 * HACK ALERT! We have to release the lock here or we'll get into trouble with
2021 * the VirtualBox lock (via i_saveHardware/NetworkAdaptger::i_hasDefaults/VirtualBox::i_findGuestOSType).
2022 */
2023 if (SUCCEEDED(hrc))
2024 {
2025 rAutoLock.release();
2026 hrc = rPtrSessionMachine->SaveSettings();
2027 rAutoLock.acquire();
2028 }
2029
2030 return hrc;
2031}
2032
2033/**
2034 * Makes sure we've got a floppy drive attached to a floppy controller, adding
2035 * the auxiliary floppy image to the installation disk vector.
2036 *
2037 * @returns COM status code.
2038 * @param rControllers The existing controllers.
2039 * @param rVecInstallatationDisks The list of image to mount.
2040 * @param rPtrSessionMachine The session machine smart pointer.
2041 * @param rAutoLock The lock.
2042 */
2043HRESULT Unattended::i_reconfigureFloppy(com::SafeIfaceArray<IStorageController> &rControllers,
2044 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
2045 ComPtr<IMachine> const &rPtrSessionMachine,
2046 AutoMultiWriteLock2 &rAutoLock)
2047{
2048 Assert(mpInstaller->isAuxiliaryFloppyNeeded());
2049
2050 /*
2051 * Look for a floppy controller with a primary drive (A:) we can "insert"
2052 * the auxiliary floppy image. Add a controller and/or a drive if necessary.
2053 */
2054 bool fFoundPort0Dev0 = false;
2055 Bstr bstrControllerName;
2056 Utf8Str strControllerName;
2057
2058 for (size_t i = 0; i < rControllers.size(); ++i)
2059 {
2060 StorageBus_T enmStorageBus;
2061 HRESULT hrc = rControllers[i]->COMGETTER(Bus)(&enmStorageBus);
2062 AssertComRCReturn(hrc, hrc);
2063 if (enmStorageBus == StorageBus_Floppy)
2064 {
2065
2066 /*
2067 * Found a floppy controller.
2068 */
2069 hrc = rControllers[i]->COMGETTER(Name)(bstrControllerName.asOutParam());
2070 AssertComRCReturn(hrc, hrc);
2071
2072 /*
2073 * Check the attchments to see if we've got a device 0 attached on port 0.
2074 *
2075 * While we're at it we eject flppies from all floppy drives we encounter,
2076 * we don't want any confusion at boot or during installation.
2077 */
2078 com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
2079 hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(bstrControllerName.raw(),
2080 ComSafeArrayAsOutParam(arrayOfMediumAttachments));
2081 AssertComRCReturn(hrc, hrc);
2082 strControllerName = bstrControllerName;
2083 AssertLogRelReturn(strControllerName.isNotEmpty(), setErrorBoth(E_UNEXPECTED, VERR_INTERNAL_ERROR_2));
2084
2085 for (size_t j = 0; j < arrayOfMediumAttachments.size(); j++)
2086 {
2087 LONG iPort = -1;
2088 hrc = arrayOfMediumAttachments[j]->COMGETTER(Port)(&iPort);
2089 AssertComRCReturn(hrc, hrc);
2090
2091 LONG iDevice = -1;
2092 hrc = arrayOfMediumAttachments[j]->COMGETTER(Device)(&iDevice);
2093 AssertComRCReturn(hrc, hrc);
2094
2095 DeviceType_T enmType;
2096 hrc = arrayOfMediumAttachments[j]->COMGETTER(Type)(&enmType);
2097 AssertComRCReturn(hrc, hrc);
2098
2099 if (enmType == DeviceType_Floppy)
2100 {
2101 ComPtr<IMedium> ptrMedium;
2102 hrc = arrayOfMediumAttachments[j]->COMGETTER(Medium)(ptrMedium.asOutParam());
2103 AssertComRCReturn(hrc, hrc);
2104
2105 if (ptrMedium.isNotNull())
2106 {
2107 ptrMedium.setNull();
2108 rAutoLock.release();
2109 hrc = rPtrSessionMachine->UnmountMedium(bstrControllerName.raw(), iPort, iDevice, TRUE /*fForce*/);
2110 rAutoLock.acquire();
2111 }
2112
2113 if (iPort == 0 && iDevice == 0)
2114 fFoundPort0Dev0 = true;
2115 }
2116 else if (iPort == 0 && iDevice == 0)
2117 return setError(E_FAIL,
2118 tr("Found non-floppy device attached to port 0 device 0 on the floppy controller '%ls'"),
2119 bstrControllerName.raw());
2120 }
2121 }
2122 }
2123
2124 /*
2125 * Add a floppy controller if we need to.
2126 */
2127 if (strControllerName.isEmpty())
2128 {
2129 bstrControllerName = strControllerName = "Floppy";
2130 ComPtr<IStorageController> ptrControllerIgnored;
2131 HRESULT hrc = rPtrSessionMachine->AddStorageController(bstrControllerName.raw(), StorageBus_Floppy,
2132 ptrControllerIgnored.asOutParam());
2133 LogRelFunc(("Machine::addStorageController(Floppy) -> %Rhrc \n", hrc));
2134 if (FAILED(hrc))
2135 return hrc;
2136 }
2137
2138 /*
2139 * Adding a floppy drive (if needed) and mounting the auxiliary image is
2140 * done later together with the ISOs.
2141 */
2142 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(StorageBus_Floppy, strControllerName,
2143 DeviceType_Floppy, AccessMode_ReadWrite,
2144 0, 0,
2145 fFoundPort0Dev0 /*fMountOnly*/,
2146 mpInstaller->getAuxiliaryFloppyFilePath()));
2147 return S_OK;
2148}
2149
2150/**
2151 * Reconfigures DVD drives of the VM to mount all the ISOs we need.
2152 *
2153 * This will umount all DVD media.
2154 *
2155 * @returns COM status code.
2156 * @param rControllers The existing controllers.
2157 * @param rVecInstallatationDisks The list of image to mount.
2158 * @param rPtrSessionMachine The session machine smart pointer.
2159 * @param rAutoLock The lock.
2160 * @param enmRecommendedStorageBus The recommended storage bus type for adding
2161 * DVD drives on.
2162 */
2163HRESULT Unattended::i_reconfigureIsos(com::SafeIfaceArray<IStorageController> &rControllers,
2164 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
2165 ComPtr<IMachine> const &rPtrSessionMachine,
2166 AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus)
2167{
2168 /*
2169 * Enumerate the attachements of every controller, looking for DVD drives,
2170 * ASSUMEING all drives are bootable.
2171 *
2172 * Eject the medium from all the drives (don't want any confusion) and look
2173 * for the recommended storage bus in case we need to add more drives.
2174 */
2175 HRESULT hrc;
2176 std::list<ControllerSlot> lstControllerDvdSlots;
2177 Utf8Str strRecommendedControllerName; /* non-empty if recommended bus found. */
2178 Utf8Str strControllerName;
2179 Bstr bstrControllerName;
2180 for (size_t i = 0; i < rControllers.size(); ++i)
2181 {
2182 hrc = rControllers[i]->COMGETTER(Name)(bstrControllerName.asOutParam());
2183 AssertComRCReturn(hrc, hrc);
2184 strControllerName = bstrControllerName;
2185
2186 /* Look for recommended storage bus. */
2187 StorageBus_T enmStorageBus;
2188 hrc = rControllers[i]->COMGETTER(Bus)(&enmStorageBus);
2189 AssertComRCReturn(hrc, hrc);
2190 if (enmStorageBus == enmRecommendedStorageBus)
2191 {
2192 strRecommendedControllerName = bstrControllerName;
2193 AssertLogRelReturn(strControllerName.isNotEmpty(), setErrorBoth(E_UNEXPECTED, VERR_INTERNAL_ERROR_2));
2194 }
2195
2196 /* Scan the controller attachments. */
2197 com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
2198 hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(bstrControllerName.raw(),
2199 ComSafeArrayAsOutParam(arrayOfMediumAttachments));
2200 AssertComRCReturn(hrc, hrc);
2201
2202 for (size_t j = 0; j < arrayOfMediumAttachments.size(); j++)
2203 {
2204 DeviceType_T enmType;
2205 hrc = arrayOfMediumAttachments[j]->COMGETTER(Type)(&enmType);
2206 AssertComRCReturn(hrc, hrc);
2207 if (enmType == DeviceType_DVD)
2208 {
2209 LONG iPort = -1;
2210 hrc = arrayOfMediumAttachments[j]->COMGETTER(Port)(&iPort);
2211 AssertComRCReturn(hrc, hrc);
2212
2213 LONG iDevice = -1;
2214 hrc = arrayOfMediumAttachments[j]->COMGETTER(Device)(&iDevice);
2215 AssertComRCReturn(hrc, hrc);
2216
2217 /* Remeber it. */
2218 lstControllerDvdSlots.push_back(ControllerSlot(enmStorageBus, strControllerName, iPort, iDevice, false /*fFree*/));
2219
2220 /* Eject the medium, if any. */
2221 ComPtr<IMedium> ptrMedium;
2222 hrc = arrayOfMediumAttachments[j]->COMGETTER(Medium)(ptrMedium.asOutParam());
2223 AssertComRCReturn(hrc, hrc);
2224 if (ptrMedium.isNotNull())
2225 {
2226 ptrMedium.setNull();
2227
2228 rAutoLock.release();
2229 hrc = rPtrSessionMachine->UnmountMedium(bstrControllerName.raw(), iPort, iDevice, TRUE /*fForce*/);
2230 rAutoLock.acquire();
2231 }
2232 }
2233 }
2234 }
2235
2236 /*
2237 * How many drives do we need? Add more if necessary.
2238 */
2239 ULONG cDvdDrivesNeeded = 0;
2240 if (mpInstaller->isAuxiliaryIsoNeeded())
2241 cDvdDrivesNeeded++;
2242 if (mpInstaller->isOriginalIsoNeeded())
2243 cDvdDrivesNeeded++;
2244#if 0 /* These are now in the AUX VISO. */
2245 if (mpInstaller->isAdditionsIsoNeeded())
2246 cDvdDrivesNeeded++;
2247 if (mpInstaller->isValidationKitIsoNeeded())
2248 cDvdDrivesNeeded++;
2249#endif
2250 Assert(cDvdDrivesNeeded > 0);
2251 if (cDvdDrivesNeeded > lstControllerDvdSlots.size())
2252 {
2253 /* Do we need to add the recommended controller? */
2254 if (strRecommendedControllerName.isEmpty())
2255 {
2256 switch (enmRecommendedStorageBus)
2257 {
2258 case StorageBus_IDE: strRecommendedControllerName = "IDE"; break;
2259 case StorageBus_SATA: strRecommendedControllerName = "SATA"; break;
2260 case StorageBus_SCSI: strRecommendedControllerName = "SCSI"; break;
2261 case StorageBus_SAS: strRecommendedControllerName = "SAS"; break;
2262 case StorageBus_USB: strRecommendedControllerName = "USB"; break;
2263 case StorageBus_PCIe: strRecommendedControllerName = "PCIe"; break;
2264 default:
2265 return setError(E_FAIL, tr("Support for recommended storage bus %d not implemented"),
2266 (int)enmRecommendedStorageBus);
2267 }
2268 ComPtr<IStorageController> ptrControllerIgnored;
2269 hrc = rPtrSessionMachine->AddStorageController(Bstr(strRecommendedControllerName).raw(), enmRecommendedStorageBus,
2270 ptrControllerIgnored.asOutParam());
2271 LogRelFunc(("Machine::addStorageController(%s) -> %Rhrc \n", strRecommendedControllerName.c_str(), hrc));
2272 if (FAILED(hrc))
2273 return hrc;
2274 }
2275
2276 /* Add free controller slots, maybe raising the port limit on the controller if we can. */
2277 hrc = i_findOrCreateNeededFreeSlots(strRecommendedControllerName, enmRecommendedStorageBus, rPtrSessionMachine,
2278 cDvdDrivesNeeded, lstControllerDvdSlots);
2279 if (FAILED(hrc))
2280 return hrc;
2281 if (cDvdDrivesNeeded > lstControllerDvdSlots.size())
2282 {
2283 /* We could in many cases create another controller here, but it's not worth the effort. */
2284 return setError(E_FAIL, tr("Not enough free slots on controller '%s' to add %u DVD drive(s)", "",
2285 cDvdDrivesNeeded - lstControllerDvdSlots.size()),
2286 strRecommendedControllerName.c_str(), cDvdDrivesNeeded - lstControllerDvdSlots.size());
2287 }
2288 Assert(cDvdDrivesNeeded == lstControllerDvdSlots.size());
2289 }
2290
2291 /*
2292 * Sort the DVD slots in boot order.
2293 */
2294 lstControllerDvdSlots.sort();
2295
2296 /*
2297 * Prepare ISO mounts.
2298 *
2299 * Boot order depends on bootFromAuxiliaryIso() and we must grab DVD slots
2300 * according to the boot order.
2301 */
2302 std::list<ControllerSlot>::const_iterator itDvdSlot = lstControllerDvdSlots.begin();
2303 if (mpInstaller->isAuxiliaryIsoNeeded() && mpInstaller->bootFromAuxiliaryIso())
2304 {
2305 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath()));
2306 ++itDvdSlot;
2307 }
2308
2309 if (mpInstaller->isOriginalIsoNeeded())
2310 {
2311 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getIsoPath()));
2312 ++itDvdSlot;
2313 }
2314
2315 if (mpInstaller->isAuxiliaryIsoNeeded() && !mpInstaller->bootFromAuxiliaryIso())
2316 {
2317 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath()));
2318 ++itDvdSlot;
2319 }
2320
2321#if 0 /* These are now in the AUX VISO. */
2322 if (mpInstaller->isAdditionsIsoNeeded())
2323 {
2324 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getAdditionsIsoPath()));
2325 ++itDvdSlot;
2326 }
2327
2328 if (mpInstaller->isValidationKitIsoNeeded())
2329 {
2330 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getValidationKitIsoPath()));
2331 ++itDvdSlot;
2332 }
2333#endif
2334
2335 return S_OK;
2336}
2337
2338/**
2339 * Used to find more free slots for DVD drives during VM reconfiguration.
2340 *
2341 * This may modify the @a portCount property of the given controller.
2342 *
2343 * @returns COM status code.
2344 * @param rStrControllerName The name of the controller to find/create
2345 * free slots on.
2346 * @param enmStorageBus The storage bus type.
2347 * @param rPtrSessionMachine Reference to the session machine.
2348 * @param cSlotsNeeded Total slots needed (including those we've
2349 * already found).
2350 * @param rDvdSlots The slot collection for DVD drives to add
2351 * free slots to as we find/create them.
2352 */
2353HRESULT Unattended::i_findOrCreateNeededFreeSlots(const Utf8Str &rStrControllerName, StorageBus_T enmStorageBus,
2354 ComPtr<IMachine> const &rPtrSessionMachine, uint32_t cSlotsNeeded,
2355 std::list<ControllerSlot> &rDvdSlots)
2356{
2357 Assert(cSlotsNeeded > rDvdSlots.size());
2358
2359 /*
2360 * Get controlleer stats.
2361 */
2362 ComPtr<IStorageController> pController;
2363 HRESULT hrc = rPtrSessionMachine->GetStorageControllerByName(Bstr(rStrControllerName).raw(), pController.asOutParam());
2364 AssertComRCReturn(hrc, hrc);
2365
2366 ULONG cMaxDevicesPerPort = 1;
2367 hrc = pController->COMGETTER(MaxDevicesPerPortCount)(&cMaxDevicesPerPort);
2368 AssertComRCReturn(hrc, hrc);
2369 AssertLogRelReturn(cMaxDevicesPerPort > 0, E_UNEXPECTED);
2370
2371 ULONG cPorts = 0;
2372 hrc = pController->COMGETTER(PortCount)(&cPorts);
2373 AssertComRCReturn(hrc, hrc);
2374
2375 /*
2376 * Get the attachment list and turn into an internal list for lookup speed.
2377 */
2378 com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
2379 hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(Bstr(rStrControllerName).raw(),
2380 ComSafeArrayAsOutParam(arrayOfMediumAttachments));
2381 AssertComRCReturn(hrc, hrc);
2382
2383 std::vector<ControllerSlot> arrayOfUsedSlots;
2384 for (size_t i = 0; i < arrayOfMediumAttachments.size(); i++)
2385 {
2386 LONG iPort = -1;
2387 hrc = arrayOfMediumAttachments[i]->COMGETTER(Port)(&iPort);
2388 AssertComRCReturn(hrc, hrc);
2389
2390 LONG iDevice = -1;
2391 hrc = arrayOfMediumAttachments[i]->COMGETTER(Device)(&iDevice);
2392 AssertComRCReturn(hrc, hrc);
2393
2394 arrayOfUsedSlots.push_back(ControllerSlot(enmStorageBus, Utf8Str::Empty, iPort, iDevice, false /*fFree*/));
2395 }
2396
2397 /*
2398 * Iterate thru all possible slots, adding those not found in arrayOfUsedSlots.
2399 */
2400 for (int32_t iPort = 0; iPort < (int32_t)cPorts; iPort++)
2401 for (int32_t iDevice = 0; iDevice < (int32_t)cMaxDevicesPerPort; iDevice++)
2402 {
2403 bool fFound = false;
2404 for (size_t i = 0; i < arrayOfUsedSlots.size(); i++)
2405 if ( arrayOfUsedSlots[i].iPort == iPort
2406 && arrayOfUsedSlots[i].iDevice == iDevice)
2407 {
2408 fFound = true;
2409 break;
2410 }
2411 if (!fFound)
2412 {
2413 rDvdSlots.push_back(ControllerSlot(enmStorageBus, rStrControllerName, iPort, iDevice, true /*fFree*/));
2414 if (rDvdSlots.size() >= cSlotsNeeded)
2415 return S_OK;
2416 }
2417 }
2418
2419 /*
2420 * Okay we still need more ports. See if increasing the number of controller
2421 * ports would solve it.
2422 */
2423 ULONG cMaxPorts = 1;
2424 hrc = pController->COMGETTER(MaxPortCount)(&cMaxPorts);
2425 AssertComRCReturn(hrc, hrc);
2426 if (cMaxPorts <= cPorts)
2427 return S_OK;
2428 size_t cNewPortsNeeded = (cSlotsNeeded - rDvdSlots.size() + cMaxDevicesPerPort - 1) / cMaxDevicesPerPort;
2429 if (cPorts + cNewPortsNeeded > cMaxPorts)
2430 return S_OK;
2431
2432 /*
2433 * Raise the port count and add the free slots we've just created.
2434 */
2435 hrc = pController->COMSETTER(PortCount)(cPorts + (ULONG)cNewPortsNeeded);
2436 AssertComRCReturn(hrc, hrc);
2437 int32_t const cPortsNew = (int32_t)(cPorts + cNewPortsNeeded);
2438 for (int32_t iPort = (int32_t)cPorts; iPort < cPortsNew; iPort++)
2439 for (int32_t iDevice = 0; iDevice < (int32_t)cMaxDevicesPerPort; iDevice++)
2440 {
2441 rDvdSlots.push_back(ControllerSlot(enmStorageBus, rStrControllerName, iPort, iDevice, true /*fFree*/));
2442 if (rDvdSlots.size() >= cSlotsNeeded)
2443 return S_OK;
2444 }
2445
2446 /* We should not get here! */
2447 AssertLogRelFailedReturn(E_UNEXPECTED);
2448}
2449
2450HRESULT Unattended::done()
2451{
2452 LogFlow(("Unattended::done\n"));
2453 if (mpInstaller)
2454 {
2455 LogRelFlow(("Unattended::done: Deleting installer object (%p)\n", mpInstaller));
2456 delete mpInstaller;
2457 mpInstaller = NULL;
2458 }
2459 return S_OK;
2460}
2461
2462HRESULT Unattended::getIsoPath(com::Utf8Str &isoPath)
2463{
2464 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2465 isoPath = mStrIsoPath;
2466 return S_OK;
2467}
2468
2469HRESULT Unattended::setIsoPath(const com::Utf8Str &isoPath)
2470{
2471 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2472 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2473 mStrIsoPath = isoPath;
2474 mfDoneDetectIsoOS = false;
2475 return S_OK;
2476}
2477
2478HRESULT Unattended::getUser(com::Utf8Str &user)
2479{
2480 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2481 user = mStrUser;
2482 return S_OK;
2483}
2484
2485
2486HRESULT Unattended::setUser(const com::Utf8Str &user)
2487{
2488 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2489 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2490 mStrUser = user;
2491 return S_OK;
2492}
2493
2494HRESULT Unattended::getPassword(com::Utf8Str &password)
2495{
2496 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2497 password = mStrPassword;
2498 return S_OK;
2499}
2500
2501HRESULT Unattended::setPassword(const com::Utf8Str &password)
2502{
2503 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2504 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2505 mStrPassword = password;
2506 return S_OK;
2507}
2508
2509HRESULT Unattended::getFullUserName(com::Utf8Str &fullUserName)
2510{
2511 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2512 fullUserName = mStrFullUserName;
2513 return S_OK;
2514}
2515
2516HRESULT Unattended::setFullUserName(const com::Utf8Str &fullUserName)
2517{
2518 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2519 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2520 mStrFullUserName = fullUserName;
2521 return S_OK;
2522}
2523
2524HRESULT Unattended::getProductKey(com::Utf8Str &productKey)
2525{
2526 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2527 productKey = mStrProductKey;
2528 return S_OK;
2529}
2530
2531HRESULT Unattended::setProductKey(const com::Utf8Str &productKey)
2532{
2533 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2534 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2535 mStrProductKey = productKey;
2536 return S_OK;
2537}
2538
2539HRESULT Unattended::getAdditionsIsoPath(com::Utf8Str &additionsIsoPath)
2540{
2541 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2542 additionsIsoPath = mStrAdditionsIsoPath;
2543 return S_OK;
2544}
2545
2546HRESULT Unattended::setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath)
2547{
2548 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2549 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2550 mStrAdditionsIsoPath = additionsIsoPath;
2551 return S_OK;
2552}
2553
2554HRESULT Unattended::getInstallGuestAdditions(BOOL *installGuestAdditions)
2555{
2556 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2557 *installGuestAdditions = mfInstallGuestAdditions;
2558 return S_OK;
2559}
2560
2561HRESULT Unattended::setInstallGuestAdditions(BOOL installGuestAdditions)
2562{
2563 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2564 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2565 mfInstallGuestAdditions = installGuestAdditions != FALSE;
2566 return S_OK;
2567}
2568
2569HRESULT Unattended::getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath)
2570{
2571 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2572 aValidationKitIsoPath = mStrValidationKitIsoPath;
2573 return S_OK;
2574}
2575
2576HRESULT Unattended::setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath)
2577{
2578 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2579 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2580 mStrValidationKitIsoPath = aValidationKitIsoPath;
2581 return S_OK;
2582}
2583
2584HRESULT Unattended::getInstallTestExecService(BOOL *aInstallTestExecService)
2585{
2586 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2587 *aInstallTestExecService = mfInstallTestExecService;
2588 return S_OK;
2589}
2590
2591HRESULT Unattended::setInstallTestExecService(BOOL aInstallTestExecService)
2592{
2593 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2594 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2595 mfInstallTestExecService = aInstallTestExecService != FALSE;
2596 return S_OK;
2597}
2598
2599HRESULT Unattended::getTimeZone(com::Utf8Str &aTimeZone)
2600{
2601 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2602 aTimeZone = mStrTimeZone;
2603 return S_OK;
2604}
2605
2606HRESULT Unattended::setTimeZone(const com::Utf8Str &aTimezone)
2607{
2608 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2609 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2610 mStrTimeZone = aTimezone;
2611 return S_OK;
2612}
2613
2614HRESULT Unattended::getLocale(com::Utf8Str &aLocale)
2615{
2616 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2617 aLocale = mStrLocale;
2618 return S_OK;
2619}
2620
2621HRESULT Unattended::setLocale(const com::Utf8Str &aLocale)
2622{
2623 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2624 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2625 if ( aLocale.isEmpty() /* use default */
2626 || ( aLocale.length() == 5
2627 && RT_C_IS_LOWER(aLocale[0])
2628 && RT_C_IS_LOWER(aLocale[1])
2629 && aLocale[2] == '_'
2630 && RT_C_IS_UPPER(aLocale[3])
2631 && RT_C_IS_UPPER(aLocale[4])) )
2632 {
2633 mStrLocale = aLocale;
2634 return S_OK;
2635 }
2636 return setError(E_INVALIDARG, tr("Expected two lower cased letters, an underscore, and two upper cased letters"));
2637}
2638
2639HRESULT Unattended::getLanguage(com::Utf8Str &aLanguage)
2640{
2641 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2642 aLanguage = mStrLanguage;
2643 return S_OK;
2644}
2645
2646HRESULT Unattended::setLanguage(const com::Utf8Str &aLanguage)
2647{
2648 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2649 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2650 mStrLanguage = aLanguage;
2651 return S_OK;
2652}
2653
2654HRESULT Unattended::getCountry(com::Utf8Str &aCountry)
2655{
2656 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2657 aCountry = mStrCountry;
2658 return S_OK;
2659}
2660
2661HRESULT Unattended::setCountry(const com::Utf8Str &aCountry)
2662{
2663 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2664 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2665 if ( aCountry.isEmpty()
2666 || ( aCountry.length() == 2
2667 && RT_C_IS_UPPER(aCountry[0])
2668 && RT_C_IS_UPPER(aCountry[1])) )
2669 {
2670 mStrCountry = aCountry;
2671 return S_OK;
2672 }
2673 return setError(E_INVALIDARG, tr("Expected two upper cased letters"));
2674}
2675
2676HRESULT Unattended::getProxy(com::Utf8Str &aProxy)
2677{
2678 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2679 aProxy = mStrProxy; /// @todo turn schema map into string or something.
2680 return S_OK;
2681}
2682
2683HRESULT Unattended::setProxy(const com::Utf8Str &aProxy)
2684{
2685 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2686 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2687 if (aProxy.isEmpty())
2688 {
2689 /* set default proxy */
2690 /** @todo BUGBUG! implement this */
2691 }
2692 else if (aProxy.equalsIgnoreCase("none"))
2693 {
2694 /* clear proxy config */
2695 mStrProxy.setNull();
2696 }
2697 else
2698 {
2699 /** @todo Parse and set proxy config into a schema map or something along those lines. */
2700 /** @todo BUGBUG! implement this */
2701 // return E_NOTIMPL;
2702 mStrProxy = aProxy;
2703 }
2704 return S_OK;
2705}
2706
2707HRESULT Unattended::getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments)
2708{
2709 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2710 aPackageSelectionAdjustments = RTCString::join(mPackageSelectionAdjustments, ";");
2711 return S_OK;
2712}
2713
2714HRESULT Unattended::setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments)
2715{
2716 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2717 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2718 if (aPackageSelectionAdjustments.isEmpty())
2719 mPackageSelectionAdjustments.clear();
2720 else
2721 {
2722 RTCList<RTCString, RTCString *> arrayStrSplit = aPackageSelectionAdjustments.split(";");
2723 for (size_t i = 0; i < arrayStrSplit.size(); i++)
2724 {
2725 if (arrayStrSplit[i].equals("minimal"))
2726 { /* okay */ }
2727 else
2728 return setError(E_INVALIDARG, tr("Unknown keyword: %s"), arrayStrSplit[i].c_str());
2729 }
2730 mPackageSelectionAdjustments = arrayStrSplit;
2731 }
2732 return S_OK;
2733}
2734
2735HRESULT Unattended::getHostname(com::Utf8Str &aHostname)
2736{
2737 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2738 aHostname = mStrHostname;
2739 return S_OK;
2740}
2741
2742HRESULT Unattended::setHostname(const com::Utf8Str &aHostname)
2743{
2744 /*
2745 * Validate input.
2746 */
2747 if (aHostname.length() > (aHostname.endsWith(".") ? 254U : 253U))
2748 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2749 tr("Hostname '%s' is %zu bytes long, max is 253 (excluding trailing dot)", "", aHostname.length()),
2750 aHostname.c_str(), aHostname.length());
2751 size_t cLabels = 0;
2752 const char *pszSrc = aHostname.c_str();
2753 for (;;)
2754 {
2755 size_t cchLabel = 1;
2756 char ch = *pszSrc++;
2757 if (RT_C_IS_ALNUM(ch))
2758 {
2759 cLabels++;
2760 while ((ch = *pszSrc++) != '.' && ch != '\0')
2761 {
2762 if (RT_C_IS_ALNUM(ch) || ch == '-')
2763 {
2764 if (cchLabel < 63)
2765 cchLabel++;
2766 else
2767 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2768 tr("Invalid hostname '%s' - label %u is too long, max is 63."),
2769 aHostname.c_str(), cLabels);
2770 }
2771 else
2772 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2773 tr("Invalid hostname '%s' - illegal char '%c' at position %zu"),
2774 aHostname.c_str(), ch, pszSrc - aHostname.c_str() - 1);
2775 }
2776 if (cLabels == 1 && cchLabel < 2)
2777 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2778 tr("Invalid hostname '%s' - the name part must be at least two characters long"),
2779 aHostname.c_str());
2780 if (ch == '\0')
2781 break;
2782 }
2783 else if (ch != '\0')
2784 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2785 tr("Invalid hostname '%s' - illegal lead char '%c' at position %zu"),
2786 aHostname.c_str(), ch, pszSrc - aHostname.c_str() - 1);
2787 else
2788 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2789 tr("Invalid hostname '%s' - trailing dot not permitted"), aHostname.c_str());
2790 }
2791 if (cLabels < 2)
2792 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2793 tr("Incomplete hostname '%s' - must include both a name and a domain"), aHostname.c_str());
2794
2795 /*
2796 * Make the change.
2797 */
2798 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2799 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2800 mStrHostname = aHostname;
2801 return S_OK;
2802}
2803
2804HRESULT Unattended::getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath)
2805{
2806 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2807 aAuxiliaryBasePath = mStrAuxiliaryBasePath;
2808 return S_OK;
2809}
2810
2811HRESULT Unattended::setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath)
2812{
2813 if (aAuxiliaryBasePath.isEmpty())
2814 return setError(E_INVALIDARG, tr("Empty base path is not allowed"));
2815 if (!RTPathStartsWithRoot(aAuxiliaryBasePath.c_str()))
2816 return setError(E_INVALIDARG, tr("Base path must be absolute"));
2817
2818 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2819 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2820 mStrAuxiliaryBasePath = aAuxiliaryBasePath;
2821 mfIsDefaultAuxiliaryBasePath = mStrAuxiliaryBasePath.isEmpty();
2822 return S_OK;
2823}
2824
2825HRESULT Unattended::getImageIndex(ULONG *index)
2826{
2827 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2828 *index = midxImage;
2829 return S_OK;
2830}
2831
2832HRESULT Unattended::setImageIndex(ULONG index)
2833{
2834 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2835 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2836 midxImage = index;
2837 return S_OK;
2838}
2839
2840HRESULT Unattended::getMachine(ComPtr<IMachine> &aMachine)
2841{
2842 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2843 return mMachine.queryInterfaceTo(aMachine.asOutParam());
2844}
2845
2846HRESULT Unattended::setMachine(const ComPtr<IMachine> &aMachine)
2847{
2848 /*
2849 * Lookup the VM so we can safely get the Machine instance.
2850 * (Don't want to test how reliable XPCOM and COM are with finding
2851 * the local object instance when a client passes a stub back.)
2852 */
2853 Bstr bstrUuidMachine;
2854 HRESULT hrc = aMachine->COMGETTER(Id)(bstrUuidMachine.asOutParam());
2855 if (SUCCEEDED(hrc))
2856 {
2857 Guid UuidMachine(bstrUuidMachine);
2858 ComObjPtr<Machine> ptrMachine;
2859 hrc = mParent->i_findMachine(UuidMachine, false /*fPermitInaccessible*/, true /*aSetError*/, &ptrMachine);
2860 if (SUCCEEDED(hrc))
2861 {
2862 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2863 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER,
2864 tr("Cannot change after prepare() has been called")));
2865 mMachine = ptrMachine;
2866 mMachineUuid = UuidMachine;
2867 if (mfIsDefaultAuxiliaryBasePath)
2868 mStrAuxiliaryBasePath.setNull();
2869 hrc = S_OK;
2870 }
2871 }
2872 return hrc;
2873}
2874
2875HRESULT Unattended::getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath)
2876{
2877 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2878 if ( mStrScriptTemplatePath.isNotEmpty()
2879 || mpInstaller == NULL)
2880 aScriptTemplatePath = mStrScriptTemplatePath;
2881 else
2882 aScriptTemplatePath = mpInstaller->getTemplateFilePath();
2883 return S_OK;
2884}
2885
2886HRESULT Unattended::setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath)
2887{
2888 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2889 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2890 mStrScriptTemplatePath = aScriptTemplatePath;
2891 return S_OK;
2892}
2893
2894HRESULT Unattended::getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath)
2895{
2896 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2897 if ( mStrPostInstallScriptTemplatePath.isNotEmpty()
2898 || mpInstaller == NULL)
2899 aPostInstallScriptTemplatePath = mStrPostInstallScriptTemplatePath;
2900 else
2901 aPostInstallScriptTemplatePath = mpInstaller->getPostTemplateFilePath();
2902 return S_OK;
2903}
2904
2905HRESULT Unattended::setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath)
2906{
2907 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2908 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2909 mStrPostInstallScriptTemplatePath = aPostInstallScriptTemplatePath;
2910 return S_OK;
2911}
2912
2913HRESULT Unattended::getPostInstallCommand(com::Utf8Str &aPostInstallCommand)
2914{
2915 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2916 aPostInstallCommand = mStrPostInstallCommand;
2917 return S_OK;
2918}
2919
2920HRESULT Unattended::setPostInstallCommand(const com::Utf8Str &aPostInstallCommand)
2921{
2922 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2923 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2924 mStrPostInstallCommand = aPostInstallCommand;
2925 return S_OK;
2926}
2927
2928HRESULT Unattended::getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters)
2929{
2930 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2931 if ( mStrExtraInstallKernelParameters.isNotEmpty()
2932 || mpInstaller == NULL)
2933 aExtraInstallKernelParameters = mStrExtraInstallKernelParameters;
2934 else
2935 aExtraInstallKernelParameters = mpInstaller->getDefaultExtraInstallKernelParameters();
2936 return S_OK;
2937}
2938
2939HRESULT Unattended::setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters)
2940{
2941 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2942 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2943 mStrExtraInstallKernelParameters = aExtraInstallKernelParameters;
2944 return S_OK;
2945}
2946
2947HRESULT Unattended::getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId)
2948{
2949 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2950 aDetectedOSTypeId = mStrDetectedOSTypeId;
2951 return S_OK;
2952}
2953
2954HRESULT Unattended::getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion)
2955{
2956 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2957 aDetectedOSVersion = mStrDetectedOSVersion;
2958 return S_OK;
2959}
2960
2961HRESULT Unattended::getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor)
2962{
2963 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2964 aDetectedOSFlavor = mStrDetectedOSFlavor;
2965 return S_OK;
2966}
2967
2968HRESULT Unattended::getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages)
2969{
2970 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2971 aDetectedOSLanguages = RTCString::join(mDetectedOSLanguages, " ");
2972 return S_OK;
2973}
2974
2975HRESULT Unattended::getDetectedOSHints(com::Utf8Str &aDetectedOSHints)
2976{
2977 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2978 aDetectedOSHints = mStrDetectedOSHints;
2979 return S_OK;
2980}
2981
2982/*
2983 * Getters that the installer and script classes can use.
2984 */
2985Utf8Str const &Unattended::i_getIsoPath() const
2986{
2987 Assert(isReadLockedOnCurrentThread());
2988 return mStrIsoPath;
2989}
2990
2991Utf8Str const &Unattended::i_getUser() const
2992{
2993 Assert(isReadLockedOnCurrentThread());
2994 return mStrUser;
2995}
2996
2997Utf8Str const &Unattended::i_getPassword() const
2998{
2999 Assert(isReadLockedOnCurrentThread());
3000 return mStrPassword;
3001}
3002
3003Utf8Str const &Unattended::i_getFullUserName() const
3004{
3005 Assert(isReadLockedOnCurrentThread());
3006 return mStrFullUserName.isNotEmpty() ? mStrFullUserName : mStrUser;
3007}
3008
3009Utf8Str const &Unattended::i_getProductKey() const
3010{
3011 Assert(isReadLockedOnCurrentThread());
3012 return mStrProductKey;
3013}
3014
3015Utf8Str const &Unattended::i_getProxy() const
3016{
3017 Assert(isReadLockedOnCurrentThread());
3018 return mStrProxy;
3019}
3020
3021Utf8Str const &Unattended::i_getAdditionsIsoPath() const
3022{
3023 Assert(isReadLockedOnCurrentThread());
3024 return mStrAdditionsIsoPath;
3025}
3026
3027bool Unattended::i_getInstallGuestAdditions() const
3028{
3029 Assert(isReadLockedOnCurrentThread());
3030 return mfInstallGuestAdditions;
3031}
3032
3033Utf8Str const &Unattended::i_getValidationKitIsoPath() const
3034{
3035 Assert(isReadLockedOnCurrentThread());
3036 return mStrValidationKitIsoPath;
3037}
3038
3039bool Unattended::i_getInstallTestExecService() const
3040{
3041 Assert(isReadLockedOnCurrentThread());
3042 return mfInstallTestExecService;
3043}
3044
3045Utf8Str const &Unattended::i_getTimeZone() const
3046{
3047 Assert(isReadLockedOnCurrentThread());
3048 return mStrTimeZone;
3049}
3050
3051PCRTTIMEZONEINFO Unattended::i_getTimeZoneInfo() const
3052{
3053 Assert(isReadLockedOnCurrentThread());
3054 return mpTimeZoneInfo;
3055}
3056
3057Utf8Str const &Unattended::i_getLocale() const
3058{
3059 Assert(isReadLockedOnCurrentThread());
3060 return mStrLocale;
3061}
3062
3063Utf8Str const &Unattended::i_getLanguage() const
3064{
3065 Assert(isReadLockedOnCurrentThread());
3066 return mStrLanguage;
3067}
3068
3069Utf8Str const &Unattended::i_getCountry() const
3070{
3071 Assert(isReadLockedOnCurrentThread());
3072 return mStrCountry;
3073}
3074
3075bool Unattended::i_isMinimalInstallation() const
3076{
3077 size_t i = mPackageSelectionAdjustments.size();
3078 while (i-- > 0)
3079 if (mPackageSelectionAdjustments[i].equals("minimal"))
3080 return true;
3081 return false;
3082}
3083
3084Utf8Str const &Unattended::i_getHostname() const
3085{
3086 Assert(isReadLockedOnCurrentThread());
3087 return mStrHostname;
3088}
3089
3090Utf8Str const &Unattended::i_getAuxiliaryBasePath() const
3091{
3092 Assert(isReadLockedOnCurrentThread());
3093 return mStrAuxiliaryBasePath;
3094}
3095
3096ULONG Unattended::i_getImageIndex() const
3097{
3098 Assert(isReadLockedOnCurrentThread());
3099 return midxImage;
3100}
3101
3102Utf8Str const &Unattended::i_getScriptTemplatePath() const
3103{
3104 Assert(isReadLockedOnCurrentThread());
3105 return mStrScriptTemplatePath;
3106}
3107
3108Utf8Str const &Unattended::i_getPostInstallScriptTemplatePath() const
3109{
3110 Assert(isReadLockedOnCurrentThread());
3111 return mStrPostInstallScriptTemplatePath;
3112}
3113
3114Utf8Str const &Unattended::i_getPostInstallCommand() const
3115{
3116 Assert(isReadLockedOnCurrentThread());
3117 return mStrPostInstallCommand;
3118}
3119
3120Utf8Str const &Unattended::i_getAuxiliaryInstallDir() const
3121{
3122 Assert(isReadLockedOnCurrentThread());
3123 /* Only the installer knows, forward the call. */
3124 AssertReturn(mpInstaller != NULL, Utf8Str::Empty);
3125 return mpInstaller->getAuxiliaryInstallDir();
3126}
3127
3128Utf8Str const &Unattended::i_getExtraInstallKernelParameters() const
3129{
3130 Assert(isReadLockedOnCurrentThread());
3131 return mStrExtraInstallKernelParameters;
3132}
3133
3134bool Unattended::i_isRtcUsingUtc() const
3135{
3136 Assert(isReadLockedOnCurrentThread());
3137 return mfRtcUseUtc;
3138}
3139
3140bool Unattended::i_isGuestOs64Bit() const
3141{
3142 Assert(isReadLockedOnCurrentThread());
3143 return mfGuestOs64Bit;
3144}
3145
3146bool Unattended::i_isFirmwareEFI() const
3147{
3148 Assert(isReadLockedOnCurrentThread());
3149 return menmFirmwareType != FirmwareType_BIOS;
3150}
3151
3152VBOXOSTYPE Unattended::i_getGuestOsType() const
3153{
3154 Assert(isReadLockedOnCurrentThread());
3155 return meGuestOsType;
3156}
3157
3158Utf8Str const &Unattended::i_getDetectedOSVersion()
3159{
3160 Assert(isReadLockedOnCurrentThread());
3161 return mStrDetectedOSVersion;
3162}
3163
3164HRESULT Unattended::i_attachImage(UnattendedInstallationDisk const *pImage, ComPtr<IMachine> const &rPtrSessionMachine,
3165 AutoMultiWriteLock2 &rLock)
3166{
3167 /*
3168 * Attach the disk image
3169 * HACK ALERT! Temporarily release the Unattended lock.
3170 */
3171 rLock.release();
3172
3173 ComPtr<IMedium> ptrMedium;
3174 HRESULT rc = mParent->OpenMedium(Bstr(pImage->strImagePath).raw(),
3175 pImage->enmDeviceType,
3176 pImage->enmAccessType,
3177 true,
3178 ptrMedium.asOutParam());
3179 LogRelFlowFunc(("VirtualBox::openMedium -> %Rhrc\n", rc));
3180 if (SUCCEEDED(rc))
3181 {
3182 if (pImage->fMountOnly)
3183 {
3184 // mount the opened disk image
3185 rc = rPtrSessionMachine->MountMedium(Bstr(pImage->strControllerName).raw(), pImage->iPort,
3186 pImage->iDevice, ptrMedium, TRUE /*fForce*/);
3187 LogRelFlowFunc(("Machine::MountMedium -> %Rhrc\n", rc));
3188 }
3189 else
3190 {
3191 //attach the opened disk image to the controller
3192 rc = rPtrSessionMachine->AttachDevice(Bstr(pImage->strControllerName).raw(), pImage->iPort,
3193 pImage->iDevice, pImage->enmDeviceType, ptrMedium);
3194 LogRelFlowFunc(("Machine::AttachDevice -> %Rhrc\n", rc));
3195 }
3196 }
3197
3198 rLock.acquire();
3199 return rc;
3200}
3201
3202bool Unattended::i_isGuestOSArchX64(Utf8Str const &rStrGuestOsTypeId)
3203{
3204 ComPtr<IGuestOSType> pGuestOSType;
3205 HRESULT hrc = mParent->GetGuestOSType(Bstr(rStrGuestOsTypeId).raw(), pGuestOSType.asOutParam());
3206 if (SUCCEEDED(hrc))
3207 {
3208 BOOL fIs64Bit = FALSE;
3209 if (!pGuestOSType.isNull())
3210 hrc = pGuestOSType->COMGETTER(Is64Bit)(&fIs64Bit);
3211 if (SUCCEEDED(hrc))
3212 return fIs64Bit != FALSE;
3213 }
3214 return false;
3215}
Note: See TracBrowser for help on using the repository browser.

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