VirtualBox

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

最後變更 在這個檔案從93339是 93339,由 vboxsync 提交於 3 年 前

Main/UnattendedImpl: bugref:10182. Adding the string aarch64 to linux architecture detection code. Needed to detect arch. of OL 7.8 Server for example.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 124.2 KB
 
1/* $Id: UnattendedImpl.cpp 93339 2022-01-19 08:38:19Z 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.alldomusa.eu.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 || RTStrNICmp(pszArch, RT_STR_TUPLE("aarch64")) == 0 /* as seen in OL 7.8 Server */)
824 {
825 *penmOsType = (VBOXOSTYPE)(enmBaseOsType | VBOXOSTYPE_x64);
826 return true;
827 }
828
829 if ( RTStrNICmp(pszArch, RT_STR_TUPLE("x86")) == 0
830 || RTStrNICmp(pszArch, RT_STR_TUPLE("i386")) == 0
831 || RTStrNICmp(pszArch, RT_STR_TUPLE("i486")) == 0
832 || RTStrNICmp(pszArch, RT_STR_TUPLE("i586")) == 0
833 || RTStrNICmp(pszArch, RT_STR_TUPLE("i686")) == 0
834 || RTStrNICmp(pszArch, RT_STR_TUPLE("i786")) == 0
835 || RTStrNICmp(pszArch, RT_STR_TUPLE("i886")) == 0
836 || RTStrNICmp(pszArch, RT_STR_TUPLE("i986")) == 0)
837 {
838 *penmOsType = enmBaseOsType;
839 return true;
840 }
841
842 /** @todo check for 'noarch' since source CDs have been seen to use that. */
843 return false;
844}
845
846/**
847 * Detects linux architecture by searching for the architecture substring in @p pszArch.
848 *
849 * @returns true if detected, false if not.
850 * @param pszArch The architecture string.
851 * @param penmOsType Where to return the arch and type on success.
852 * @param enmBaseOsType The base (x86) OS type to return.
853 */
854static bool detectLinuxArchII(const char *pszArch, VBOXOSTYPE *penmOsType, VBOXOSTYPE enmBaseOsType)
855{
856 if ( RTStrIStr(pszArch, "amd64") != NULL
857 || RTStrIStr(pszArch, "x86_64") != NULL
858 || RTStrIStr(pszArch, "x86-64") != NULL /* just in case */
859 || RTStrIStr(pszArch, "x64") != NULL /* ditto */
860 || RTStrIStr(pszArch, "aarch64") != NULL /* as seen in OL 7.8 Server */)
861 {
862 *penmOsType = (VBOXOSTYPE)(enmBaseOsType | VBOXOSTYPE_x64);
863 return true;
864 }
865
866 if ( RTStrIStr(pszArch, "x86") != NULL
867 || RTStrIStr(pszArch, "i386") != NULL
868 || RTStrIStr(pszArch, "i486") != NULL
869 || RTStrIStr(pszArch, "i586") != NULL
870 || RTStrIStr(pszArch, "i686") != NULL
871 || RTStrIStr(pszArch, "i786") != NULL
872 || RTStrIStr(pszArch, "i886") != NULL
873 || RTStrIStr(pszArch, "i986") != NULL)
874 {
875 *penmOsType = enmBaseOsType;
876 return true;
877 }
878 return false;
879}
880
881static bool detectLinuxDistroName(const char *pszOsAndVersion, VBOXOSTYPE *penmOsType, const char **ppszNext)
882{
883 bool fRet = true;
884
885 if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Red")) == 0
886 && !RT_C_IS_ALNUM(pszOsAndVersion[3]))
887
888 {
889 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 3);
890 if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Hat")) == 0
891 && !RT_C_IS_ALNUM(pszOsAndVersion[3]))
892 {
893 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_RedHat);
894 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 3);
895 }
896 else
897 fRet = false;
898 }
899 else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Oracle")) == 0
900 && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
901 {
902 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Oracle);
903 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
904 }
905 else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("CentOS")) == 0
906 && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
907 {
908 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_RedHat);
909 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
910 }
911 else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Fedora")) == 0
912 && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
913 {
914 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_FedoraCore);
915 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
916 }
917 else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Ubuntu")) == 0
918 && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
919 {
920 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Ubuntu);
921 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
922 }
923 else if ( ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Xubuntu")) == 0
924 || RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Kubuntu")) == 0)
925 && !RT_C_IS_ALNUM(pszOsAndVersion[7]))
926 {
927 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Ubuntu);
928 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 7);
929 }
930 else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Debian")) == 0
931 && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
932 {
933 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Debian);
934 pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
935 }
936 else
937 fRet = false;
938
939 /*
940 * Skip forward till we get a number.
941 */
942 if (ppszNext)
943 {
944 *ppszNext = pszOsAndVersion;
945 char ch;
946 for (const char *pszVersion = pszOsAndVersion; (ch = *pszVersion) != '\0'; pszVersion++)
947 if (RT_C_IS_DIGIT(ch))
948 {
949 *ppszNext = pszVersion;
950 break;
951 }
952 }
953 return fRet;
954}
955
956
957/**
958 * Detect Linux distro ISOs.
959 *
960 * @returns COM status code.
961 * @retval S_OK if detected
962 * @retval S_FALSE if not fully detected.
963 *
964 * @param hVfsIso The ISO file system.
965 * @param pBuf Read buffer.
966 * @param penmOsType Where to return the OS type. This is initialized to
967 * VBOXOSTYPE_Unknown.
968 */
969HRESULT Unattended::i_innerDetectIsoOSLinux(RTVFS hVfsIso, DETECTBUFFER *pBuf, VBOXOSTYPE *penmOsType)
970{
971 /*
972 * Redhat and derivatives may have a .treeinfo (ini-file style) with useful info
973 * or at least a barebone .discinfo file.
974 */
975
976 /*
977 * Start with .treeinfo: https://release-engineering.github.io/productmd/treeinfo-1.0.html
978 */
979 RTVFSFILE hVfsFile;
980 int vrc = RTVfsFileOpen(hVfsIso, ".treeinfo", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
981 if (RT_SUCCESS(vrc))
982 {
983 RTINIFILE hIniFile;
984 vrc = RTIniFileCreateFromVfsFile(&hIniFile, hVfsFile, RTINIFILE_F_READONLY);
985 RTVfsFileRelease(hVfsFile);
986 if (RT_SUCCESS(vrc))
987 {
988 /* Try figure the architecture first (like with windows). */
989 vrc = RTIniFileQueryValue(hIniFile, "tree", "arch", pBuf->sz, sizeof(*pBuf), NULL);
990 if (RT_FAILURE(vrc) || !pBuf->sz[0])
991 vrc = RTIniFileQueryValue(hIniFile, "general", "arch", pBuf->sz, sizeof(*pBuf), NULL);
992 if (RT_SUCCESS(vrc))
993 {
994 LogRelFlow(("Unattended: .treeinfo: arch=%s\n", pBuf->sz));
995 if (!detectLinuxArch(pBuf->sz, penmOsType, VBOXOSTYPE_RedHat))
996 LogRel(("Unattended: .treeinfo: Unknown: arch='%s'\n", pBuf->sz));
997 }
998 else
999 LogRel(("Unattended: .treeinfo: No 'arch' property.\n"));
1000
1001 /* Try figure the release name, it doesn't have to be redhat. */
1002 vrc = RTIniFileQueryValue(hIniFile, "release", "name", pBuf->sz, sizeof(*pBuf), NULL);
1003 if (RT_FAILURE(vrc) || !pBuf->sz[0])
1004 vrc = RTIniFileQueryValue(hIniFile, "product", "name", pBuf->sz, sizeof(*pBuf), NULL);
1005 if (RT_FAILURE(vrc) || !pBuf->sz[0])
1006 vrc = RTIniFileQueryValue(hIniFile, "general", "family", pBuf->sz, sizeof(*pBuf), NULL);
1007 if (RT_SUCCESS(vrc))
1008 {
1009 LogRelFlow(("Unattended: .treeinfo: name/family=%s\n", pBuf->sz));
1010 if (!detectLinuxDistroName(pBuf->sz, penmOsType, NULL))
1011 {
1012 LogRel(("Unattended: .treeinfo: Unknown: name/family='%s', assuming Red Hat\n", pBuf->sz));
1013 *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_RedHat);
1014 }
1015 }
1016
1017 /* Try figure the version. */
1018 vrc = RTIniFileQueryValue(hIniFile, "release", "version", pBuf->sz, sizeof(*pBuf), NULL);
1019 if (RT_FAILURE(vrc) || !pBuf->sz[0])
1020 vrc = RTIniFileQueryValue(hIniFile, "product", "version", pBuf->sz, sizeof(*pBuf), NULL);
1021 if (RT_FAILURE(vrc) || !pBuf->sz[0])
1022 vrc = RTIniFileQueryValue(hIniFile, "general", "version", pBuf->sz, sizeof(*pBuf), NULL);
1023 if (RT_SUCCESS(vrc))
1024 {
1025 LogRelFlow(("Unattended: .treeinfo: version=%s\n", pBuf->sz));
1026 try { mStrDetectedOSVersion = RTStrStrip(pBuf->sz); }
1027 catch (std::bad_alloc &) { return E_OUTOFMEMORY; }
1028 }
1029
1030 RTIniFileRelease(hIniFile);
1031 }
1032
1033 if (*penmOsType != VBOXOSTYPE_Unknown)
1034 return S_FALSE;
1035 }
1036
1037 /*
1038 * Try .discinfo next: https://release-engineering.github.io/productmd/discinfo-1.0.html
1039 * We will probably need additional info here...
1040 */
1041 vrc = RTVfsFileOpen(hVfsIso, ".discinfo", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1042 if (RT_SUCCESS(vrc))
1043 {
1044 size_t cchIgn;
1045 vrc = RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(*pBuf) - 1, &cchIgn);
1046 pBuf->sz[RT_SUCCESS(vrc) ? cchIgn : 0] = '\0';
1047 RTVfsFileRelease(hVfsFile);
1048
1049 /* Parse and strip the first 5 lines. */
1050 const char *apszLines[5];
1051 char *psz = pBuf->sz;
1052 for (unsigned i = 0; i < RT_ELEMENTS(apszLines); i++)
1053 {
1054 apszLines[i] = psz;
1055 if (*psz)
1056 {
1057 char *pszEol = (char *)strchr(psz, '\n');
1058 if (!pszEol)
1059 psz = strchr(psz, '\0');
1060 else
1061 {
1062 *pszEol = '\0';
1063 apszLines[i] = RTStrStrip(psz);
1064 psz = pszEol + 1;
1065 }
1066 }
1067 }
1068
1069 /* Do we recognize the architecture? */
1070 LogRelFlow(("Unattended: .discinfo: arch=%s\n", apszLines[2]));
1071 if (!detectLinuxArch(apszLines[2], penmOsType, VBOXOSTYPE_RedHat))
1072 LogRel(("Unattended: .discinfo: Unknown: arch='%s'\n", apszLines[2]));
1073
1074 /* Do we recognize the release string? */
1075 LogRelFlow(("Unattended: .discinfo: product+version=%s\n", apszLines[1]));
1076 const char *pszVersion = NULL;
1077 if (!detectLinuxDistroName(apszLines[1], penmOsType, &pszVersion))
1078 LogRel(("Unattended: .discinfo: Unknown: release='%s'\n", apszLines[1]));
1079
1080 if (*pszVersion)
1081 {
1082 LogRelFlow(("Unattended: .discinfo: version=%s\n", pszVersion));
1083 try { mStrDetectedOSVersion = RTStrStripL(pszVersion); }
1084 catch (std::bad_alloc &) { return E_OUTOFMEMORY; }
1085
1086 /* CentOS likes to call their release 'Final' without mentioning the actual version
1087 number (e.g. CentOS-4.7-x86_64-binDVD.iso), so we need to go look elsewhere.
1088 This is only important for centos 4.x and 3.x releases. */
1089 if (RTStrNICmp(pszVersion, RT_STR_TUPLE("Final")) == 0)
1090 {
1091 static const char * const s_apszDirs[] = { "CentOS/RPMS/", "RedHat/RPMS", "Server", "Workstation" };
1092 for (unsigned iDir = 0; iDir < RT_ELEMENTS(s_apszDirs); iDir++)
1093 {
1094 RTVFSDIR hVfsDir;
1095 vrc = RTVfsDirOpen(hVfsIso, s_apszDirs[iDir], 0, &hVfsDir);
1096 if (RT_FAILURE(vrc))
1097 continue;
1098 char szRpmDb[128];
1099 char szReleaseRpm[128];
1100 szRpmDb[0] = '\0';
1101 szReleaseRpm[0] = '\0';
1102 for (;;)
1103 {
1104 RTDIRENTRYEX DirEntry;
1105 size_t cbDirEntry = sizeof(DirEntry);
1106 vrc = RTVfsDirReadEx(hVfsDir, &DirEntry, &cbDirEntry, RTFSOBJATTRADD_NOTHING);
1107 if (RT_FAILURE(vrc))
1108 break;
1109
1110 /* redhat-release-4WS-2.4.i386.rpm
1111 centos-release-4-7.x86_64.rpm, centos-release-4-4.3.i386.rpm
1112 centos-release-5-3.el5.centos.1.x86_64.rpm */
1113 if ( (psz = strstr(DirEntry.szName, "-release-")) != NULL
1114 || (psz = strstr(DirEntry.szName, "-RELEASE-")) != NULL)
1115 {
1116 psz += 9;
1117 if (RT_C_IS_DIGIT(*psz))
1118 RTStrCopy(szReleaseRpm, sizeof(szReleaseRpm), psz);
1119 }
1120 /* rpmdb-redhat-4WS-2.4.i386.rpm,
1121 rpmdb-CentOS-4.5-0.20070506.i386.rpm,
1122 rpmdb-redhat-3.9-0.20070703.i386.rpm. */
1123 else if ( ( RTStrStartsWith(DirEntry.szName, "rpmdb-")
1124 || RTStrStartsWith(DirEntry.szName, "RPMDB-"))
1125 && RT_C_IS_DIGIT(DirEntry.szName[6]) )
1126 RTStrCopy(szRpmDb, sizeof(szRpmDb), &DirEntry.szName[6]);
1127 }
1128 RTVfsDirRelease(hVfsDir);
1129
1130 /* Did we find anything relvant? */
1131 psz = szRpmDb;
1132 if (!RT_C_IS_DIGIT(*psz))
1133 psz = szReleaseRpm;
1134 if (RT_C_IS_DIGIT(*psz))
1135 {
1136 /* Convert '-' to '.' and strip stuff which doesn't look like a version string. */
1137 char *pszCur = psz + 1;
1138 for (char ch = *pszCur; ch != '\0'; ch = *++pszCur)
1139 if (ch == '-')
1140 *pszCur = '.';
1141 else if (ch != '.' && !RT_C_IS_DIGIT(ch))
1142 {
1143 *pszCur = '\0';
1144 break;
1145 }
1146 while (&pszCur[-1] != psz && pszCur[-1] == '.')
1147 *--pszCur = '\0';
1148
1149 /* Set it and stop looking. */
1150 try { mStrDetectedOSVersion = psz; }
1151 catch (std::bad_alloc &) { return E_OUTOFMEMORY; }
1152 break;
1153 }
1154 }
1155 }
1156 }
1157
1158 if (*penmOsType != VBOXOSTYPE_Unknown)
1159 return S_FALSE;
1160 }
1161
1162 /*
1163 * Ubuntu has a README.diskdefins file on their ISO (already on 4.10 / warty warthog).
1164 * Example content:
1165 * #define DISKNAME Ubuntu 4.10 "Warty Warthog" - Preview amd64 Binary-1
1166 * #define TYPE binary
1167 * #define TYPEbinary 1
1168 * #define ARCH amd64
1169 * #define ARCHamd64 1
1170 * #define DISKNUM 1
1171 * #define DISKNUM1 1
1172 * #define TOTALNUM 1
1173 * #define TOTALNUM1 1
1174 */
1175 vrc = RTVfsFileOpen(hVfsIso, "README.diskdefines", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1176 if (RT_SUCCESS(vrc))
1177 {
1178 size_t cchIgn;
1179 vrc = RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(*pBuf) - 1, &cchIgn);
1180 pBuf->sz[RT_SUCCESS(vrc) ? cchIgn : 0] = '\0';
1181 RTVfsFileRelease(hVfsFile);
1182
1183 /* Find the DISKNAME and ARCH defines. */
1184 const char *pszDiskName = NULL;
1185 const char *pszArch = NULL;
1186 char *psz = pBuf->sz;
1187 for (unsigned i = 0; *psz != '\0'; i++)
1188 {
1189 while (RT_C_IS_BLANK(*psz))
1190 psz++;
1191
1192 /* Match #define: */
1193 static const char s_szDefine[] = "#define";
1194 if ( strncmp(psz, s_szDefine, sizeof(s_szDefine) - 1) == 0
1195 && RT_C_IS_BLANK(psz[sizeof(s_szDefine) - 1]))
1196 {
1197 psz = &psz[sizeof(s_szDefine) - 1];
1198 while (RT_C_IS_BLANK(*psz))
1199 psz++;
1200
1201 /* Match the identifier: */
1202 char *pszIdentifier = psz;
1203 if (RT_C_IS_ALPHA(*psz) || *psz == '_')
1204 {
1205 do
1206 psz++;
1207 while (RT_C_IS_ALNUM(*psz) || *psz == '_');
1208 size_t cchIdentifier = (size_t)(psz - pszIdentifier);
1209
1210 /* Skip to the value. */
1211 while (RT_C_IS_BLANK(*psz))
1212 psz++;
1213 char *pszValue = psz;
1214
1215 /* Skip to EOL and strip the value. */
1216 char *pszEol = psz = strchr(psz, '\n');
1217 if (psz)
1218 *psz++ = '\0';
1219 else
1220 pszEol = strchr(pszValue, '\0');
1221 while (pszEol > pszValue && RT_C_IS_SPACE(pszEol[-1]))
1222 *--pszEol = '\0';
1223
1224 LogRelFlow(("Unattended: README.diskdefines: %.*s=%s\n", cchIdentifier, pszIdentifier, pszValue));
1225
1226 /* Do identifier matching: */
1227 if (cchIdentifier == sizeof("DISKNAME") - 1 && strncmp(pszIdentifier, RT_STR_TUPLE("DISKNAME")) == 0)
1228 pszDiskName = pszValue;
1229 else if (cchIdentifier == sizeof("ARCH") - 1 && strncmp(pszIdentifier, RT_STR_TUPLE("ARCH")) == 0)
1230 pszArch = pszValue;
1231 else
1232 continue;
1233 if (pszDiskName == NULL || pszArch == NULL)
1234 continue;
1235 break;
1236 }
1237 }
1238
1239 /* Next line: */
1240 psz = strchr(psz, '\n');
1241 if (!psz)
1242 break;
1243 psz++;
1244 }
1245
1246 /* Did we find both of them? */
1247 if (pszDiskName && pszArch)
1248 {
1249 if (!detectLinuxArch(pszArch, penmOsType, VBOXOSTYPE_Ubuntu))
1250 LogRel(("Unattended: README.diskdefines: Unknown: arch='%s'\n", pszArch));
1251
1252 const char *pszVersion = NULL;
1253 if (detectLinuxDistroName(pszDiskName, penmOsType, &pszVersion))
1254 {
1255 LogRelFlow(("Unattended: README.diskdefines: version=%s\n", pszVersion));
1256 try { mStrDetectedOSVersion = RTStrStripL(pszVersion); }
1257 catch (std::bad_alloc &) { return E_OUTOFMEMORY; }
1258 }
1259 else
1260 LogRel(("Unattended: README.diskdefines: Unknown: diskname='%s'\n", pszDiskName));
1261 }
1262 else
1263 LogRel(("Unattended: README.diskdefines: Did not find both DISKNAME and ARCH. :-/\n"));
1264
1265 if (*penmOsType != VBOXOSTYPE_Unknown)
1266 return S_FALSE;
1267 }
1268
1269 /*
1270 * All of the debian based distro versions I checked have a single line ./disk/info file.
1271 * Only info I could find related to .disk folder is: https://lists.debian.org/debian-cd/2004/01/msg00069.html
1272 * Some example content from several install ISOs is as follows:
1273 * Ubuntu 4.10 "Warty Warthog" - Preview amd64 Binary-1 (20041020)
1274 * Linux Mint 20.3 "Una" - Release amd64 20220104
1275 * Debian GNU/Linux 11.2.0 "Bullseye" - Official amd64 NETINST 20211218-11:12
1276 * Debian GNU/Linux 9.13.0 "Stretch" - Official amd64 DVD Binary-1 20200718-11:07
1277 * Xubuntu 20.04.2.0 LTS "Focal Fossa" - Release amd64 (20210209.1)
1278 * Ubuntu 17.10 "Artful Aardvark" - Release amd64 (20180105.1)
1279 * Ubuntu 16.04.6 LTS "Xenial Xerus" - Release i386 (20190227.1)
1280 * Debian GNU/Linux 8.11.1 "Jessie" - Official amd64 CD Binary-1 20190211-02:10
1281 * Kali GNU/Linux 2021.3a "Kali-last-snapshot" - Official amd64 BD Binary-1 with firmware 20211015-16:55
1282 */
1283 vrc = RTVfsFileOpen(hVfsIso, ".disk/info", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1284 if (RT_SUCCESS(vrc))
1285 {
1286 size_t cchIgn;
1287 vrc = RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(*pBuf) - 1, &cchIgn);
1288 pBuf->sz[RT_SUCCESS(vrc) ? cchIgn : 0] = '\0';
1289
1290 pBuf->sz[sizeof(*pBuf) - 1] = '\0';
1291 RTVfsFileRelease(hVfsFile);
1292
1293 char *psz = pBuf->sz;
1294 char *pszDiskName = psz;
1295 char *pszArch = NULL;
1296
1297 /* Only care about the first line of the file even if it is multi line and assume disk name ended with ' - '.*/
1298 psz = RTStrStr(pBuf->sz, " - ");
1299 if (psz && memchr(pBuf->sz, '\n', (size_t)(psz - pBuf->sz)) == NULL)
1300 {
1301 *psz = '\0';
1302 psz += 3;
1303 if (*psz)
1304 pszArch = psz;
1305 }
1306
1307 if (pszDiskName && pszArch)
1308 {
1309 if (!detectLinuxArchII(pszArch, penmOsType, VBOXOSTYPE_Ubuntu))
1310 LogRel(("Unattended: README.diskdefines: Unknown: arch='%s'\n", pszArch));
1311
1312 const char *pszVersion = NULL;
1313 if (detectLinuxDistroName(pszDiskName, penmOsType, &pszVersion))
1314 {
1315 LogRelFlow(("Unattended: README.diskdefines: version=%s\n", pszVersion));
1316 try { mStrDetectedOSVersion = RTStrStripL(pszVersion); }
1317 catch (std::bad_alloc &) { return E_OUTOFMEMORY; }
1318 }
1319 else
1320 LogRel(("Unattended: README.diskdefines: Unknown: diskname='%s'\n", pszDiskName));
1321 }
1322 else
1323 LogRel(("Unattended: README.diskdefines: Did not find both DISKNAME and ARCH. :-/\n"));
1324
1325 if (*penmOsType != VBOXOSTYPE_Unknown)
1326 return S_FALSE;
1327 }
1328
1329 return S_FALSE;
1330}
1331
1332
1333/**
1334 * Detect OS/2 installation ISOs.
1335 *
1336 * Mainly aiming at ACP2/MCP2 as that's what we currently use in our testing.
1337 *
1338 * @returns COM status code.
1339 * @retval S_OK if detected
1340 * @retval S_FALSE if not fully detected.
1341 *
1342 * @param hVfsIso The ISO file system.
1343 * @param pBuf Read buffer.
1344 * @param penmOsType Where to return the OS type. This is initialized to
1345 * VBOXOSTYPE_Unknown.
1346 */
1347HRESULT Unattended::i_innerDetectIsoOSOs2(RTVFS hVfsIso, DETECTBUFFER *pBuf, VBOXOSTYPE *penmOsType)
1348{
1349 /*
1350 * The OS2SE20.SRC contains the location of the tree with the diskette
1351 * images, typically "\OS2IMAGE".
1352 */
1353 RTVFSFILE hVfsFile;
1354 int vrc = RTVfsFileOpen(hVfsIso, "OS2SE20.SRC", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1355 if (RT_SUCCESS(vrc))
1356 {
1357 size_t cbRead = 0;
1358 vrc = RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(pBuf->sz) - 1, &cbRead);
1359 RTVfsFileRelease(hVfsFile);
1360 if (RT_SUCCESS(vrc))
1361 {
1362 pBuf->sz[cbRead] = '\0';
1363 RTStrStrip(pBuf->sz);
1364 vrc = RTStrValidateEncoding(pBuf->sz);
1365 if (RT_SUCCESS(vrc))
1366 LogRelFlow(("Unattended: OS2SE20.SRC=%s\n", pBuf->sz));
1367 else
1368 LogRel(("Unattended: OS2SE20.SRC invalid encoding: %Rrc, %.*Rhxs\n", vrc, cbRead, pBuf->sz));
1369 }
1370 else
1371 LogRel(("Unattended: Error reading OS2SE20.SRC: %\n", vrc));
1372 }
1373 /*
1374 * ArcaOS has dropped the file, assume it's \OS2IMAGE and see if it's there.
1375 */
1376 else if (vrc == VERR_FILE_NOT_FOUND)
1377 RTStrCopy(pBuf->sz, sizeof(pBuf->sz), "\\OS2IMAGE");
1378 else
1379 return S_FALSE;
1380
1381 /*
1382 * Check that the directory directory exists and has a DISK_0 under it
1383 * with an OS2LDR on it.
1384 */
1385 size_t const cchOs2Image = strlen(pBuf->sz);
1386 vrc = RTPathAppend(pBuf->sz, sizeof(pBuf->sz), "DISK_0/OS2LDR");
1387 RTFSOBJINFO ObjInfo = {0};
1388 vrc = RTVfsQueryPathInfo(hVfsIso, pBuf->sz, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
1389 if (vrc == VERR_FILE_NOT_FOUND)
1390 {
1391 RTStrCat(pBuf->sz, sizeof(pBuf->sz), "."); /* eCS 2.0 image includes the dot from the 8.3 name. */
1392 vrc = RTVfsQueryPathInfo(hVfsIso, pBuf->sz, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
1393 }
1394 if ( RT_FAILURE(vrc)
1395 || !RTFS_IS_FILE(ObjInfo.Attr.fMode))
1396 {
1397 LogRel(("Unattended: RTVfsQueryPathInfo(, '%s' (from OS2SE20.SRC),) -> %Rrc, fMode=%#x\n",
1398 pBuf->sz, vrc, ObjInfo.Attr.fMode));
1399 return S_FALSE;
1400 }
1401
1402 /*
1403 * So, it's some kind of OS/2 2.x or later ISO alright.
1404 */
1405 *penmOsType = VBOXOSTYPE_OS2;
1406 mStrDetectedOSHints.printf("OS2SE20.SRC=%.*s", cchOs2Image, pBuf->sz);
1407
1408 /*
1409 * ArcaOS ISOs seems to have a AOSBOOT dir on them.
1410 * This contains a ARCANOAE.FLG file with content we can use for the version:
1411 * ArcaOS 5.0.7 EN
1412 * Built 2021-12-07 18:34:34
1413 * We drop the "ArcaOS" bit, as it's covered by penmOsType. Then we pull up
1414 * the second line.
1415 *
1416 * Note! Yet to find a way to do unattended install of ArcaOS, as it comes
1417 * with no CD-boot floppy images, only simple .PF archive files for
1418 * unpacking onto the ram disk or whatever. Modifying these is
1419 * possible (ibsen's aPLib v0.36 compression with some simple custom
1420 * headers), but it would probably be a royal pain. Could perhaps
1421 * cook something from OS2IMAGE\DISK_0 thru 3...
1422 */
1423 vrc = RTVfsQueryPathInfo(hVfsIso, "AOSBOOT", &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
1424 if ( RT_SUCCESS(vrc)
1425 && RTFS_IS_DIRECTORY(ObjInfo.Attr.fMode))
1426 {
1427 *penmOsType = VBOXOSTYPE_ArcaOS;
1428
1429 /* Read the version file: */
1430 vrc = RTVfsFileOpen(hVfsIso, "SYS/ARCANOAE.FLG", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1431 if (RT_SUCCESS(vrc))
1432 {
1433 size_t cbRead = 0;
1434 vrc = RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(pBuf->sz) - 1, &cbRead);
1435 RTVfsFileRelease(hVfsFile);
1436 pBuf->sz[cbRead] = '\0';
1437 if (RT_SUCCESS(vrc))
1438 {
1439 /* Strip the OS name: */
1440 char *pszVersion = RTStrStrip(pBuf->sz);
1441 static char s_szArcaOS[] = "ArcaOS";
1442 if (RTStrStartsWith(pszVersion, s_szArcaOS))
1443 pszVersion = RTStrStripL(pszVersion + sizeof(s_szArcaOS) - 1);
1444
1445 /* Pull up the 2nd line if it, condensing the \r\n into a single space. */
1446 char *pszNewLine = strchr(pszVersion, '\n');
1447 if (pszNewLine && RTStrStartsWith(pszNewLine + 1, "Built 20"))
1448 {
1449 size_t offRemove = 0;
1450 while (RT_C_IS_SPACE(pszNewLine[-1 - (ssize_t)offRemove]))
1451 offRemove++;
1452 if (offRemove > 0)
1453 {
1454 pszNewLine -= offRemove;
1455 memmove(pszNewLine, pszNewLine + offRemove, strlen(pszNewLine + offRemove) - 1);
1456 }
1457 *pszNewLine = ' ';
1458 }
1459
1460 /* Drop any additional lines: */
1461 pszNewLine = strchr(pszVersion, '\n');
1462 if (pszNewLine)
1463 *pszNewLine = '\0';
1464 RTStrStripR(pszVersion);
1465
1466 /* Done (hope it makes some sense). */
1467 mStrDetectedOSVersion = pszVersion;
1468 }
1469 else
1470 LogRel(("Unattended: failed to read AOSBOOT/ARCANOAE.FLG: %Rrc\n", vrc));
1471 }
1472 else
1473 LogRel(("Unattended: failed to open AOSBOOT/ARCANOAE.FLG for reading: %Rrc\n", vrc));
1474 }
1475 /*
1476 * Similarly, eCS has an ECS directory and it typically contains a
1477 * ECS_INST.FLG file with the version info. Content differs a little:
1478 * eComStation 2.0 EN_US Thu May 13 10:27:54 pm 2010
1479 * Built on ECS60441318
1480 * Here we drop the "eComStation" bit and leave the 2nd line as it.
1481 *
1482 * Note! At least 2.0 has a DISKIMGS folder with what looks like boot
1483 * disks, so we could probably get something going here without
1484 * needing to write an OS2 boot sector...
1485 */
1486 else
1487 {
1488 vrc = RTVfsQueryPathInfo(hVfsIso, "ECS", &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
1489 if ( RT_SUCCESS(vrc)
1490 && RTFS_IS_DIRECTORY(ObjInfo.Attr.fMode))
1491 {
1492 *penmOsType = VBOXOSTYPE_ECS;
1493
1494 /* Read the version file: */
1495 vrc = RTVfsFileOpen(hVfsIso, "ECS/ECS_INST.FLG", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1496 if (RT_SUCCESS(vrc))
1497 {
1498 size_t cbRead = 0;
1499 vrc = RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(pBuf->sz) - 1, &cbRead);
1500 RTVfsFileRelease(hVfsFile);
1501 pBuf->sz[cbRead] = '\0';
1502 if (RT_SUCCESS(vrc))
1503 {
1504 /* Strip the OS name: */
1505 char *pszVersion = RTStrStrip(pBuf->sz);
1506 static char s_szECS[] = "eComStation";
1507 if (RTStrStartsWith(pszVersion, s_szECS))
1508 pszVersion = RTStrStripL(pszVersion + sizeof(s_szECS) - 1);
1509
1510 /* Drop any additional lines: */
1511 char *pszNewLine = strchr(pszVersion, '\n');
1512 if (pszNewLine)
1513 *pszNewLine = '\0';
1514 RTStrStripR(pszVersion);
1515
1516 /* Done (hope it makes some sense). */
1517 mStrDetectedOSVersion = pszVersion;
1518 }
1519 else
1520 LogRel(("Unattended: failed to read ECS/ECS_INST.FLG: %Rrc\n", vrc));
1521 }
1522 else
1523 LogRel(("Unattended: failed to open ECS/ECS_INST.FLG for reading: %Rrc\n", vrc));
1524 }
1525 else
1526 {
1527 /*
1528 * Official IBM OS/2 builds doesn't have any .FLG file on them,
1529 * so need to pry the information out in some other way. Best way
1530 * is to read the SYSLEVEL.OS2 file, which is typically on disk #2,
1531 * though on earlier versions (warp3) it was disk #1.
1532 */
1533 vrc = RTPathJoin(pBuf->sz, sizeof(pBuf->sz), strchr(mStrDetectedOSHints.c_str(), '=') + 1,
1534 "/DISK_2/SYSLEVEL.OS2");
1535 if (RT_SUCCESS(vrc))
1536 {
1537 vrc = RTVfsFileOpen(hVfsIso, pBuf->sz, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1538 if (vrc == VERR_FILE_NOT_FOUND)
1539 {
1540 RTPathJoin(pBuf->sz, sizeof(pBuf->sz), strchr(mStrDetectedOSHints.c_str(), '=') + 1, "/DISK_1/SYSLEVEL.OS2");
1541 vrc = RTVfsFileOpen(hVfsIso, pBuf->sz, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
1542 }
1543 if (RT_SUCCESS(vrc))
1544 {
1545 RT_ZERO(pBuf->ab);
1546 size_t cbRead = 0;
1547 vrc = RTVfsFileRead(hVfsFile, pBuf->ab, sizeof(pBuf->ab), &cbRead);
1548 RTVfsFileRelease(hVfsFile);
1549 if (RT_SUCCESS(vrc))
1550 {
1551 /* Check the header. */
1552 OS2SYSLEVELHDR const *pHdr = (OS2SYSLEVELHDR const *)&pBuf->ab[0];
1553 if ( pHdr->uMinusOne == UINT16_MAX
1554 && pHdr->uSyslevelFileVer == 1
1555 && memcmp(pHdr->achSignature, RT_STR_TUPLE("SYSLEVEL")) == 0
1556 && pHdr->offTable < cbRead
1557 && pHdr->offTable + sizeof(OS2SYSLEVELENTRY) <= cbRead)
1558 {
1559 OS2SYSLEVELENTRY *pEntry = (OS2SYSLEVELENTRY *)&pBuf->ab[pHdr->offTable];
1560 if ( RT_SUCCESS(RTStrValidateEncodingEx(pEntry->szName, sizeof(pEntry->szName),
1561 RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED))
1562 && RT_SUCCESS(RTStrValidateEncodingEx(pEntry->achCsdLevel, sizeof(pEntry->achCsdLevel), 0))
1563 && pEntry->bVersion != 0
1564 && ((pEntry->bVersion >> 4) & 0xf) < 10
1565 && (pEntry->bVersion & 0xf) < 10
1566 && pEntry->bModify < 10
1567 && pEntry->bRefresh < 10)
1568 {
1569 /* Flavor: */
1570 char *pszName = RTStrStrip(pEntry->szName);
1571 if (pszName)
1572 mStrDetectedOSFlavor = pszName;
1573
1574 /* Version: */
1575 if (pEntry->bRefresh != 0)
1576 mStrDetectedOSVersion.printf("%d.%d%d.%d", pEntry->bVersion >> 4, pEntry->bVersion & 0xf,
1577 pEntry->bModify, pEntry->bRefresh);
1578 else
1579 mStrDetectedOSVersion.printf("%d.%d%d", pEntry->bVersion >> 4, pEntry->bVersion & 0xf,
1580 pEntry->bModify);
1581 pEntry->achCsdLevel[sizeof(pEntry->achCsdLevel) - 1] = '\0';
1582 char *pszCsd = RTStrStrip(pEntry->achCsdLevel);
1583 if (*pszCsd != '\0')
1584 {
1585 mStrDetectedOSVersion.append(' ');
1586 mStrDetectedOSVersion.append(pszCsd);
1587 }
1588 if (RTStrVersionCompare(mStrDetectedOSVersion.c_str(), "4.50") >= 0)
1589 *penmOsType = VBOXOSTYPE_OS2Warp45;
1590 else if (RTStrVersionCompare(mStrDetectedOSVersion.c_str(), "4.00") >= 0)
1591 *penmOsType = VBOXOSTYPE_OS2Warp4;
1592 else if (RTStrVersionCompare(mStrDetectedOSVersion.c_str(), "3.00") >= 0)
1593 *penmOsType = VBOXOSTYPE_OS2Warp3;
1594 }
1595 else
1596 LogRel(("Unattended: bogus SYSLEVEL.OS2 file entry: %.128Rhxd\n", pEntry));
1597 }
1598 else
1599 LogRel(("Unattended: bogus SYSLEVEL.OS2 file header: uMinusOne=%#x uSyslevelFileVer=%#x achSignature=%.8Rhxs offTable=%#x vs cbRead=%#zx\n",
1600 pHdr->uMinusOne, pHdr->uSyslevelFileVer, pHdr->achSignature, pHdr->offTable, cbRead));
1601 }
1602 else
1603 LogRel(("Unattended: failed to read SYSLEVEL.OS2: %Rrc\n", vrc));
1604 }
1605 else
1606 LogRel(("Unattended: failed to open '%s' for reading: %Rrc\n", pBuf->sz, vrc));
1607 }
1608 }
1609 }
1610
1611 /** @todo language detection? */
1612
1613 /*
1614 * Only tested ACP2, so only return S_OK for it.
1615 */
1616 if ( *penmOsType == VBOXOSTYPE_OS2Warp45
1617 && RTStrVersionCompare(mStrDetectedOSVersion.c_str(), "4.52") >= 0
1618 && mStrDetectedOSFlavor.contains("Server", RTCString::CaseInsensitive))
1619 return S_OK;
1620
1621 return S_FALSE;
1622}
1623
1624
1625HRESULT Unattended::prepare()
1626{
1627 LogFlow(("Unattended::prepare: enter\n"));
1628
1629 /*
1630 * Must have a machine.
1631 */
1632 ComPtr<Machine> ptrMachine;
1633 Guid MachineUuid;
1634 {
1635 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1636 ptrMachine = mMachine;
1637 if (ptrMachine.isNull())
1638 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("No machine associated with this IUnatteded instance"));
1639 MachineUuid = mMachineUuid;
1640 }
1641
1642 /*
1643 * Before we write lock ourselves, we must get stuff from Machine and
1644 * VirtualBox because their locks have higher priorities than ours.
1645 */
1646 Utf8Str strGuestOsTypeId;
1647 Utf8Str strMachineName;
1648 Utf8Str strDefaultAuxBasePath;
1649 HRESULT hrc;
1650 try
1651 {
1652 Bstr bstrTmp;
1653 hrc = ptrMachine->COMGETTER(OSTypeId)(bstrTmp.asOutParam());
1654 if (SUCCEEDED(hrc))
1655 {
1656 strGuestOsTypeId = bstrTmp;
1657 hrc = ptrMachine->COMGETTER(Name)(bstrTmp.asOutParam());
1658 if (SUCCEEDED(hrc))
1659 strMachineName = bstrTmp;
1660 }
1661 int vrc = ptrMachine->i_calculateFullPath(Utf8StrFmt("Unattended-%RTuuid-", MachineUuid.raw()), strDefaultAuxBasePath);
1662 if (RT_FAILURE(vrc))
1663 return setErrorBoth(E_FAIL, vrc);
1664 }
1665 catch (std::bad_alloc &)
1666 {
1667 return E_OUTOFMEMORY;
1668 }
1669 bool const fIs64Bit = i_isGuestOSArchX64(strGuestOsTypeId);
1670
1671 BOOL fRtcUseUtc = FALSE;
1672 hrc = ptrMachine->COMGETTER(RTCUseUTC)(&fRtcUseUtc);
1673 if (FAILED(hrc))
1674 return hrc;
1675
1676 FirmwareType_T enmFirmware = FirmwareType_BIOS;
1677 hrc = ptrMachine->COMGETTER(FirmwareType)(&enmFirmware);
1678 if (FAILED(hrc))
1679 return hrc;
1680
1681 /*
1682 * Write lock this object and set attributes we got from IMachine.
1683 */
1684 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1685
1686 mStrGuestOsTypeId = strGuestOsTypeId;
1687 mfGuestOs64Bit = fIs64Bit;
1688 mfRtcUseUtc = RT_BOOL(fRtcUseUtc);
1689 menmFirmwareType = enmFirmware;
1690
1691 /*
1692 * Do some state checks.
1693 */
1694 if (mpInstaller != NULL)
1695 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("The prepare method has been called (must call done to restart)"));
1696 if ((Machine *)ptrMachine != (Machine *)mMachine)
1697 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("The 'machine' while we were using it - please don't do that"));
1698
1699 /*
1700 * Check if the specified ISOs and files exist.
1701 */
1702 if (!RTFileExists(mStrIsoPath.c_str()))
1703 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the installation ISO file '%s'"),
1704 mStrIsoPath.c_str());
1705 if (mfInstallGuestAdditions && !RTFileExists(mStrAdditionsIsoPath.c_str()))
1706 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the Guest Additions ISO file '%s'"),
1707 mStrAdditionsIsoPath.c_str());
1708 if (mfInstallTestExecService && !RTFileExists(mStrValidationKitIsoPath.c_str()))
1709 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the validation kit ISO file '%s'"),
1710 mStrValidationKitIsoPath.c_str());
1711 if (mStrScriptTemplatePath.isNotEmpty() && !RTFileExists(mStrScriptTemplatePath.c_str()))
1712 return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate unattended installation script template '%s'"),
1713 mStrScriptTemplatePath.c_str());
1714
1715 /*
1716 * Do media detection if it haven't been done yet.
1717 */
1718 if (!mfDoneDetectIsoOS)
1719 {
1720 hrc = detectIsoOS();
1721 if (FAILED(hrc) && hrc != E_NOTIMPL)
1722 return hrc;
1723 }
1724
1725 /*
1726 * Do some default property stuff and check other properties.
1727 */
1728 try
1729 {
1730 char szTmp[128];
1731
1732 if (mStrLocale.isEmpty())
1733 {
1734 int vrc = RTLocaleQueryNormalizedBaseLocaleName(szTmp, sizeof(szTmp));
1735 if ( RT_SUCCESS(vrc)
1736 && RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(szTmp))
1737 mStrLocale.assign(szTmp, 5);
1738 else
1739 mStrLocale = "en_US";
1740 Assert(RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(mStrLocale));
1741 }
1742
1743 if (mStrLanguage.isEmpty())
1744 {
1745 if (mDetectedOSLanguages.size() > 0)
1746 mStrLanguage = mDetectedOSLanguages[0];
1747 else
1748 mStrLanguage.assign(mStrLocale).findReplace('_', '-');
1749 }
1750
1751 if (mStrCountry.isEmpty())
1752 {
1753 int vrc = RTLocaleQueryUserCountryCode(szTmp);
1754 if (RT_SUCCESS(vrc))
1755 mStrCountry = szTmp;
1756 else if ( mStrLocale.isNotEmpty()
1757 && RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(mStrLocale))
1758 mStrCountry.assign(mStrLocale, 3, 2);
1759 else
1760 mStrCountry = "US";
1761 }
1762
1763 if (mStrTimeZone.isEmpty())
1764 {
1765 int vrc = RTTimeZoneGetCurrent(szTmp, sizeof(szTmp));
1766 if ( RT_SUCCESS(vrc)
1767 && strcmp(szTmp, "localtime") != 0 /* Typcial solaris TZ that isn't very helpful. */)
1768 mStrTimeZone = szTmp;
1769 else
1770 mStrTimeZone = "Etc/UTC";
1771 Assert(mStrTimeZone.isNotEmpty());
1772 }
1773 mpTimeZoneInfo = RTTimeZoneGetInfoByUnixName(mStrTimeZone.c_str());
1774 if (!mpTimeZoneInfo)
1775 mpTimeZoneInfo = RTTimeZoneGetInfoByWindowsName(mStrTimeZone.c_str());
1776 Assert(mpTimeZoneInfo || mStrTimeZone != "Etc/UTC");
1777 if (!mpTimeZoneInfo)
1778 LogRel(("Unattended::prepare: warning: Unknown time zone '%s'\n", mStrTimeZone.c_str()));
1779
1780 if (mStrHostname.isEmpty())
1781 {
1782 /* Mangle the VM name into a valid hostname. */
1783 for (size_t i = 0; i < strMachineName.length(); i++)
1784 {
1785 char ch = strMachineName[i];
1786 if ( (unsigned)ch < 127
1787 && RT_C_IS_ALNUM(ch))
1788 mStrHostname.append(ch);
1789 else if (mStrHostname.isNotEmpty() && RT_C_IS_PUNCT(ch) && !mStrHostname.endsWith("-"))
1790 mStrHostname.append('-');
1791 }
1792 if (mStrHostname.length() == 0)
1793 mStrHostname.printf("%RTuuid-vm", MachineUuid.raw());
1794 else if (mStrHostname.length() < 3)
1795 mStrHostname.append("-vm");
1796 mStrHostname.append(".myguest.virtualbox.org");
1797 }
1798
1799 if (mStrAuxiliaryBasePath.isEmpty())
1800 {
1801 mStrAuxiliaryBasePath = strDefaultAuxBasePath;
1802 mfIsDefaultAuxiliaryBasePath = true;
1803 }
1804 }
1805 catch (std::bad_alloc &)
1806 {
1807 return E_OUTOFMEMORY;
1808 }
1809
1810 /*
1811 * Get the guest OS type info and instantiate the appropriate installer.
1812 */
1813 uint32_t const idxOSType = Global::getOSTypeIndexFromId(mStrGuestOsTypeId.c_str());
1814 meGuestOsType = idxOSType < Global::cOSTypes ? Global::sOSTypes[idxOSType].osType : VBOXOSTYPE_Unknown;
1815
1816 mpInstaller = UnattendedInstaller::createInstance(meGuestOsType, mStrGuestOsTypeId, mStrDetectedOSVersion,
1817 mStrDetectedOSFlavor, mStrDetectedOSHints, this);
1818 if (mpInstaller != NULL)
1819 {
1820 hrc = mpInstaller->initInstaller();
1821 if (SUCCEEDED(hrc))
1822 {
1823 /*
1824 * Do the script preps (just reads them).
1825 */
1826 hrc = mpInstaller->prepareUnattendedScripts();
1827 if (SUCCEEDED(hrc))
1828 {
1829 LogFlow(("Unattended::prepare: returns S_OK\n"));
1830 return S_OK;
1831 }
1832 }
1833
1834 /* Destroy the installer instance. */
1835 delete mpInstaller;
1836 mpInstaller = NULL;
1837 }
1838 else
1839 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND,
1840 tr("Unattended installation is not supported for guest type '%s'"), mStrGuestOsTypeId.c_str());
1841 LogRelFlow(("Unattended::prepare: failed with %Rhrc\n", hrc));
1842 return hrc;
1843}
1844
1845HRESULT Unattended::constructMedia()
1846{
1847 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1848
1849 LogFlow(("===========================================================\n"));
1850 LogFlow(("Call Unattended::constructMedia()\n"));
1851
1852 if (mpInstaller == NULL)
1853 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, "prepare() not yet called");
1854
1855 return mpInstaller->prepareMedia();
1856}
1857
1858HRESULT Unattended::reconfigureVM()
1859{
1860 LogFlow(("===========================================================\n"));
1861 LogFlow(("Call Unattended::reconfigureVM()\n"));
1862
1863 /*
1864 * Interrogate VirtualBox/IGuestOSType before we lock stuff and create ordering issues.
1865 */
1866 StorageBus_T enmRecommendedStorageBus = StorageBus_IDE;
1867 {
1868 Bstr bstrGuestOsTypeId;
1869 {
1870 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1871 bstrGuestOsTypeId = mStrGuestOsTypeId;
1872 }
1873 ComPtr<IGuestOSType> ptrGuestOSType;
1874 HRESULT hrc = mParent->GetGuestOSType(bstrGuestOsTypeId.raw(), ptrGuestOSType.asOutParam());
1875 if (SUCCEEDED(hrc))
1876 {
1877 if (!ptrGuestOSType.isNull())
1878 hrc = ptrGuestOSType->COMGETTER(RecommendedDVDStorageBus)(&enmRecommendedStorageBus);
1879 }
1880 if (FAILED(hrc))
1881 return hrc;
1882 }
1883
1884 /*
1885 * Take write lock (for lock order reasons, write lock our parent object too)
1886 * then make sure we're the only caller of this method.
1887 */
1888 AutoMultiWriteLock2 alock(mMachine, this COMMA_LOCKVAL_SRC_POS);
1889 HRESULT hrc;
1890 if (mhThreadReconfigureVM == NIL_RTNATIVETHREAD)
1891 {
1892 RTNATIVETHREAD const hNativeSelf = RTThreadNativeSelf();
1893 mhThreadReconfigureVM = hNativeSelf;
1894
1895 /*
1896 * Create a new session, lock the machine and get the session machine object.
1897 * Do the locking without pinning down the write locks, just to be on the safe side.
1898 */
1899 ComPtr<ISession> ptrSession;
1900 try
1901 {
1902 hrc = ptrSession.createInprocObject(CLSID_Session);
1903 }
1904 catch (std::bad_alloc &)
1905 {
1906 hrc = E_OUTOFMEMORY;
1907 }
1908 if (SUCCEEDED(hrc))
1909 {
1910 alock.release();
1911 hrc = mMachine->LockMachine(ptrSession, LockType_Shared);
1912 alock.acquire();
1913 if (SUCCEEDED(hrc))
1914 {
1915 ComPtr<IMachine> ptrSessionMachine;
1916 hrc = ptrSession->COMGETTER(Machine)(ptrSessionMachine.asOutParam());
1917 if (SUCCEEDED(hrc))
1918 {
1919 /*
1920 * Hand the session to the inner work and let it do it job.
1921 */
1922 try
1923 {
1924 hrc = i_innerReconfigureVM(alock, enmRecommendedStorageBus, ptrSessionMachine);
1925 }
1926 catch (...)
1927 {
1928 hrc = E_UNEXPECTED;
1929 }
1930 }
1931
1932 /* Paranoia: release early in case we it a bump below. */
1933 Assert(mhThreadReconfigureVM == hNativeSelf);
1934 mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
1935
1936 /*
1937 * While unlocking the machine we'll have to drop the locks again.
1938 */
1939 alock.release();
1940
1941 ptrSessionMachine.setNull();
1942 HRESULT hrc2 = ptrSession->UnlockMachine();
1943 AssertLogRelMsg(SUCCEEDED(hrc2), ("UnlockMachine -> %Rhrc\n", hrc2));
1944
1945 ptrSession.setNull();
1946
1947 alock.acquire();
1948 }
1949 else
1950 mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
1951 }
1952 else
1953 mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
1954 }
1955 else
1956 hrc = setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("reconfigureVM running on other thread"));
1957 return hrc;
1958}
1959
1960
1961HRESULT Unattended::i_innerReconfigureVM(AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus,
1962 ComPtr<IMachine> const &rPtrSessionMachine)
1963{
1964 if (mpInstaller == NULL)
1965 return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("prepare() not yet called"));
1966
1967 // Fetch all available storage controllers
1968 com::SafeIfaceArray<IStorageController> arrayOfControllers;
1969 HRESULT hrc = rPtrSessionMachine->COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(arrayOfControllers));
1970 AssertComRCReturn(hrc, hrc);
1971
1972 /*
1973 * Figure out where the images are to be mounted, adding controllers/ports as needed.
1974 */
1975 std::vector<UnattendedInstallationDisk> vecInstallationDisks;
1976 if (mpInstaller->isAuxiliaryFloppyNeeded())
1977 {
1978 hrc = i_reconfigureFloppy(arrayOfControllers, vecInstallationDisks, rPtrSessionMachine, rAutoLock);
1979 if (FAILED(hrc))
1980 return hrc;
1981 }
1982
1983 hrc = i_reconfigureIsos(arrayOfControllers, vecInstallationDisks, rPtrSessionMachine, rAutoLock, enmRecommendedStorageBus);
1984 if (FAILED(hrc))
1985 return hrc;
1986
1987 /*
1988 * Mount the images.
1989 */
1990 for (size_t idxImage = 0; idxImage < vecInstallationDisks.size(); idxImage++)
1991 {
1992 UnattendedInstallationDisk const *pImage = &vecInstallationDisks.at(idxImage);
1993 Assert(pImage->strImagePath.isNotEmpty());
1994 hrc = i_attachImage(pImage, rPtrSessionMachine, rAutoLock);
1995 if (FAILED(hrc))
1996 return hrc;
1997 }
1998
1999 /*
2000 * Set the boot order.
2001 *
2002 * ASSUME that the HD isn't bootable when we start out, but it will be what
2003 * we boot from after the first stage of the installation is done. Setting
2004 * it first prevents endless reboot cylces.
2005 */
2006 /** @todo consider making 100% sure the disk isn't bootable (edit partition
2007 * table active bits and EFI stuff). */
2008 Assert( mpInstaller->getBootableDeviceType() == DeviceType_DVD
2009 || mpInstaller->getBootableDeviceType() == DeviceType_Floppy);
2010 hrc = rPtrSessionMachine->SetBootOrder(1, DeviceType_HardDisk);
2011 if (SUCCEEDED(hrc))
2012 hrc = rPtrSessionMachine->SetBootOrder(2, mpInstaller->getBootableDeviceType());
2013 if (SUCCEEDED(hrc))
2014 hrc = rPtrSessionMachine->SetBootOrder(3, mpInstaller->getBootableDeviceType() == DeviceType_DVD
2015 ? DeviceType_Floppy : DeviceType_DVD);
2016 if (FAILED(hrc))
2017 return hrc;
2018
2019 /*
2020 * Essential step.
2021 *
2022 * HACK ALERT! We have to release the lock here or we'll get into trouble with
2023 * the VirtualBox lock (via i_saveHardware/NetworkAdaptger::i_hasDefaults/VirtualBox::i_findGuestOSType).
2024 */
2025 if (SUCCEEDED(hrc))
2026 {
2027 rAutoLock.release();
2028 hrc = rPtrSessionMachine->SaveSettings();
2029 rAutoLock.acquire();
2030 }
2031
2032 return hrc;
2033}
2034
2035/**
2036 * Makes sure we've got a floppy drive attached to a floppy controller, adding
2037 * the auxiliary floppy image to the installation disk vector.
2038 *
2039 * @returns COM status code.
2040 * @param rControllers The existing controllers.
2041 * @param rVecInstallatationDisks The list of image to mount.
2042 * @param rPtrSessionMachine The session machine smart pointer.
2043 * @param rAutoLock The lock.
2044 */
2045HRESULT Unattended::i_reconfigureFloppy(com::SafeIfaceArray<IStorageController> &rControllers,
2046 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
2047 ComPtr<IMachine> const &rPtrSessionMachine,
2048 AutoMultiWriteLock2 &rAutoLock)
2049{
2050 Assert(mpInstaller->isAuxiliaryFloppyNeeded());
2051
2052 /*
2053 * Look for a floppy controller with a primary drive (A:) we can "insert"
2054 * the auxiliary floppy image. Add a controller and/or a drive if necessary.
2055 */
2056 bool fFoundPort0Dev0 = false;
2057 Bstr bstrControllerName;
2058 Utf8Str strControllerName;
2059
2060 for (size_t i = 0; i < rControllers.size(); ++i)
2061 {
2062 StorageBus_T enmStorageBus;
2063 HRESULT hrc = rControllers[i]->COMGETTER(Bus)(&enmStorageBus);
2064 AssertComRCReturn(hrc, hrc);
2065 if (enmStorageBus == StorageBus_Floppy)
2066 {
2067
2068 /*
2069 * Found a floppy controller.
2070 */
2071 hrc = rControllers[i]->COMGETTER(Name)(bstrControllerName.asOutParam());
2072 AssertComRCReturn(hrc, hrc);
2073
2074 /*
2075 * Check the attchments to see if we've got a device 0 attached on port 0.
2076 *
2077 * While we're at it we eject flppies from all floppy drives we encounter,
2078 * we don't want any confusion at boot or during installation.
2079 */
2080 com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
2081 hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(bstrControllerName.raw(),
2082 ComSafeArrayAsOutParam(arrayOfMediumAttachments));
2083 AssertComRCReturn(hrc, hrc);
2084 strControllerName = bstrControllerName;
2085 AssertLogRelReturn(strControllerName.isNotEmpty(), setErrorBoth(E_UNEXPECTED, VERR_INTERNAL_ERROR_2));
2086
2087 for (size_t j = 0; j < arrayOfMediumAttachments.size(); j++)
2088 {
2089 LONG iPort = -1;
2090 hrc = arrayOfMediumAttachments[j]->COMGETTER(Port)(&iPort);
2091 AssertComRCReturn(hrc, hrc);
2092
2093 LONG iDevice = -1;
2094 hrc = arrayOfMediumAttachments[j]->COMGETTER(Device)(&iDevice);
2095 AssertComRCReturn(hrc, hrc);
2096
2097 DeviceType_T enmType;
2098 hrc = arrayOfMediumAttachments[j]->COMGETTER(Type)(&enmType);
2099 AssertComRCReturn(hrc, hrc);
2100
2101 if (enmType == DeviceType_Floppy)
2102 {
2103 ComPtr<IMedium> ptrMedium;
2104 hrc = arrayOfMediumAttachments[j]->COMGETTER(Medium)(ptrMedium.asOutParam());
2105 AssertComRCReturn(hrc, hrc);
2106
2107 if (ptrMedium.isNotNull())
2108 {
2109 ptrMedium.setNull();
2110 rAutoLock.release();
2111 hrc = rPtrSessionMachine->UnmountMedium(bstrControllerName.raw(), iPort, iDevice, TRUE /*fForce*/);
2112 rAutoLock.acquire();
2113 }
2114
2115 if (iPort == 0 && iDevice == 0)
2116 fFoundPort0Dev0 = true;
2117 }
2118 else if (iPort == 0 && iDevice == 0)
2119 return setError(E_FAIL,
2120 tr("Found non-floppy device attached to port 0 device 0 on the floppy controller '%ls'"),
2121 bstrControllerName.raw());
2122 }
2123 }
2124 }
2125
2126 /*
2127 * Add a floppy controller if we need to.
2128 */
2129 if (strControllerName.isEmpty())
2130 {
2131 bstrControllerName = strControllerName = "Floppy";
2132 ComPtr<IStorageController> ptrControllerIgnored;
2133 HRESULT hrc = rPtrSessionMachine->AddStorageController(bstrControllerName.raw(), StorageBus_Floppy,
2134 ptrControllerIgnored.asOutParam());
2135 LogRelFunc(("Machine::addStorageController(Floppy) -> %Rhrc \n", hrc));
2136 if (FAILED(hrc))
2137 return hrc;
2138 }
2139
2140 /*
2141 * Adding a floppy drive (if needed) and mounting the auxiliary image is
2142 * done later together with the ISOs.
2143 */
2144 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(StorageBus_Floppy, strControllerName,
2145 DeviceType_Floppy, AccessMode_ReadWrite,
2146 0, 0,
2147 fFoundPort0Dev0 /*fMountOnly*/,
2148 mpInstaller->getAuxiliaryFloppyFilePath()));
2149 return S_OK;
2150}
2151
2152/**
2153 * Reconfigures DVD drives of the VM to mount all the ISOs we need.
2154 *
2155 * This will umount all DVD media.
2156 *
2157 * @returns COM status code.
2158 * @param rControllers The existing controllers.
2159 * @param rVecInstallatationDisks The list of image to mount.
2160 * @param rPtrSessionMachine The session machine smart pointer.
2161 * @param rAutoLock The lock.
2162 * @param enmRecommendedStorageBus The recommended storage bus type for adding
2163 * DVD drives on.
2164 */
2165HRESULT Unattended::i_reconfigureIsos(com::SafeIfaceArray<IStorageController> &rControllers,
2166 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
2167 ComPtr<IMachine> const &rPtrSessionMachine,
2168 AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus)
2169{
2170 /*
2171 * Enumerate the attachements of every controller, looking for DVD drives,
2172 * ASSUMEING all drives are bootable.
2173 *
2174 * Eject the medium from all the drives (don't want any confusion) and look
2175 * for the recommended storage bus in case we need to add more drives.
2176 */
2177 HRESULT hrc;
2178 std::list<ControllerSlot> lstControllerDvdSlots;
2179 Utf8Str strRecommendedControllerName; /* non-empty if recommended bus found. */
2180 Utf8Str strControllerName;
2181 Bstr bstrControllerName;
2182 for (size_t i = 0; i < rControllers.size(); ++i)
2183 {
2184 hrc = rControllers[i]->COMGETTER(Name)(bstrControllerName.asOutParam());
2185 AssertComRCReturn(hrc, hrc);
2186 strControllerName = bstrControllerName;
2187
2188 /* Look for recommended storage bus. */
2189 StorageBus_T enmStorageBus;
2190 hrc = rControllers[i]->COMGETTER(Bus)(&enmStorageBus);
2191 AssertComRCReturn(hrc, hrc);
2192 if (enmStorageBus == enmRecommendedStorageBus)
2193 {
2194 strRecommendedControllerName = bstrControllerName;
2195 AssertLogRelReturn(strControllerName.isNotEmpty(), setErrorBoth(E_UNEXPECTED, VERR_INTERNAL_ERROR_2));
2196 }
2197
2198 /* Scan the controller attachments. */
2199 com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
2200 hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(bstrControllerName.raw(),
2201 ComSafeArrayAsOutParam(arrayOfMediumAttachments));
2202 AssertComRCReturn(hrc, hrc);
2203
2204 for (size_t j = 0; j < arrayOfMediumAttachments.size(); j++)
2205 {
2206 DeviceType_T enmType;
2207 hrc = arrayOfMediumAttachments[j]->COMGETTER(Type)(&enmType);
2208 AssertComRCReturn(hrc, hrc);
2209 if (enmType == DeviceType_DVD)
2210 {
2211 LONG iPort = -1;
2212 hrc = arrayOfMediumAttachments[j]->COMGETTER(Port)(&iPort);
2213 AssertComRCReturn(hrc, hrc);
2214
2215 LONG iDevice = -1;
2216 hrc = arrayOfMediumAttachments[j]->COMGETTER(Device)(&iDevice);
2217 AssertComRCReturn(hrc, hrc);
2218
2219 /* Remeber it. */
2220 lstControllerDvdSlots.push_back(ControllerSlot(enmStorageBus, strControllerName, iPort, iDevice, false /*fFree*/));
2221
2222 /* Eject the medium, if any. */
2223 ComPtr<IMedium> ptrMedium;
2224 hrc = arrayOfMediumAttachments[j]->COMGETTER(Medium)(ptrMedium.asOutParam());
2225 AssertComRCReturn(hrc, hrc);
2226 if (ptrMedium.isNotNull())
2227 {
2228 ptrMedium.setNull();
2229
2230 rAutoLock.release();
2231 hrc = rPtrSessionMachine->UnmountMedium(bstrControllerName.raw(), iPort, iDevice, TRUE /*fForce*/);
2232 rAutoLock.acquire();
2233 }
2234 }
2235 }
2236 }
2237
2238 /*
2239 * How many drives do we need? Add more if necessary.
2240 */
2241 ULONG cDvdDrivesNeeded = 0;
2242 if (mpInstaller->isAuxiliaryIsoNeeded())
2243 cDvdDrivesNeeded++;
2244 if (mpInstaller->isOriginalIsoNeeded())
2245 cDvdDrivesNeeded++;
2246#if 0 /* These are now in the AUX VISO. */
2247 if (mpInstaller->isAdditionsIsoNeeded())
2248 cDvdDrivesNeeded++;
2249 if (mpInstaller->isValidationKitIsoNeeded())
2250 cDvdDrivesNeeded++;
2251#endif
2252 Assert(cDvdDrivesNeeded > 0);
2253 if (cDvdDrivesNeeded > lstControllerDvdSlots.size())
2254 {
2255 /* Do we need to add the recommended controller? */
2256 if (strRecommendedControllerName.isEmpty())
2257 {
2258 switch (enmRecommendedStorageBus)
2259 {
2260 case StorageBus_IDE: strRecommendedControllerName = "IDE"; break;
2261 case StorageBus_SATA: strRecommendedControllerName = "SATA"; break;
2262 case StorageBus_SCSI: strRecommendedControllerName = "SCSI"; break;
2263 case StorageBus_SAS: strRecommendedControllerName = "SAS"; break;
2264 case StorageBus_USB: strRecommendedControllerName = "USB"; break;
2265 case StorageBus_PCIe: strRecommendedControllerName = "PCIe"; break;
2266 default:
2267 return setError(E_FAIL, tr("Support for recommended storage bus %d not implemented"),
2268 (int)enmRecommendedStorageBus);
2269 }
2270 ComPtr<IStorageController> ptrControllerIgnored;
2271 hrc = rPtrSessionMachine->AddStorageController(Bstr(strRecommendedControllerName).raw(), enmRecommendedStorageBus,
2272 ptrControllerIgnored.asOutParam());
2273 LogRelFunc(("Machine::addStorageController(%s) -> %Rhrc \n", strRecommendedControllerName.c_str(), hrc));
2274 if (FAILED(hrc))
2275 return hrc;
2276 }
2277
2278 /* Add free controller slots, maybe raising the port limit on the controller if we can. */
2279 hrc = i_findOrCreateNeededFreeSlots(strRecommendedControllerName, enmRecommendedStorageBus, rPtrSessionMachine,
2280 cDvdDrivesNeeded, lstControllerDvdSlots);
2281 if (FAILED(hrc))
2282 return hrc;
2283 if (cDvdDrivesNeeded > lstControllerDvdSlots.size())
2284 {
2285 /* We could in many cases create another controller here, but it's not worth the effort. */
2286 return setError(E_FAIL, tr("Not enough free slots on controller '%s' to add %u DVD drive(s)", "",
2287 cDvdDrivesNeeded - lstControllerDvdSlots.size()),
2288 strRecommendedControllerName.c_str(), cDvdDrivesNeeded - lstControllerDvdSlots.size());
2289 }
2290 Assert(cDvdDrivesNeeded == lstControllerDvdSlots.size());
2291 }
2292
2293 /*
2294 * Sort the DVD slots in boot order.
2295 */
2296 lstControllerDvdSlots.sort();
2297
2298 /*
2299 * Prepare ISO mounts.
2300 *
2301 * Boot order depends on bootFromAuxiliaryIso() and we must grab DVD slots
2302 * according to the boot order.
2303 */
2304 std::list<ControllerSlot>::const_iterator itDvdSlot = lstControllerDvdSlots.begin();
2305 if (mpInstaller->isAuxiliaryIsoNeeded() && mpInstaller->bootFromAuxiliaryIso())
2306 {
2307 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath()));
2308 ++itDvdSlot;
2309 }
2310
2311 if (mpInstaller->isOriginalIsoNeeded())
2312 {
2313 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getIsoPath()));
2314 ++itDvdSlot;
2315 }
2316
2317 if (mpInstaller->isAuxiliaryIsoNeeded() && !mpInstaller->bootFromAuxiliaryIso())
2318 {
2319 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath()));
2320 ++itDvdSlot;
2321 }
2322
2323#if 0 /* These are now in the AUX VISO. */
2324 if (mpInstaller->isAdditionsIsoNeeded())
2325 {
2326 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getAdditionsIsoPath()));
2327 ++itDvdSlot;
2328 }
2329
2330 if (mpInstaller->isValidationKitIsoNeeded())
2331 {
2332 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getValidationKitIsoPath()));
2333 ++itDvdSlot;
2334 }
2335#endif
2336
2337 return S_OK;
2338}
2339
2340/**
2341 * Used to find more free slots for DVD drives during VM reconfiguration.
2342 *
2343 * This may modify the @a portCount property of the given controller.
2344 *
2345 * @returns COM status code.
2346 * @param rStrControllerName The name of the controller to find/create
2347 * free slots on.
2348 * @param enmStorageBus The storage bus type.
2349 * @param rPtrSessionMachine Reference to the session machine.
2350 * @param cSlotsNeeded Total slots needed (including those we've
2351 * already found).
2352 * @param rDvdSlots The slot collection for DVD drives to add
2353 * free slots to as we find/create them.
2354 */
2355HRESULT Unattended::i_findOrCreateNeededFreeSlots(const Utf8Str &rStrControllerName, StorageBus_T enmStorageBus,
2356 ComPtr<IMachine> const &rPtrSessionMachine, uint32_t cSlotsNeeded,
2357 std::list<ControllerSlot> &rDvdSlots)
2358{
2359 Assert(cSlotsNeeded > rDvdSlots.size());
2360
2361 /*
2362 * Get controlleer stats.
2363 */
2364 ComPtr<IStorageController> pController;
2365 HRESULT hrc = rPtrSessionMachine->GetStorageControllerByName(Bstr(rStrControllerName).raw(), pController.asOutParam());
2366 AssertComRCReturn(hrc, hrc);
2367
2368 ULONG cMaxDevicesPerPort = 1;
2369 hrc = pController->COMGETTER(MaxDevicesPerPortCount)(&cMaxDevicesPerPort);
2370 AssertComRCReturn(hrc, hrc);
2371 AssertLogRelReturn(cMaxDevicesPerPort > 0, E_UNEXPECTED);
2372
2373 ULONG cPorts = 0;
2374 hrc = pController->COMGETTER(PortCount)(&cPorts);
2375 AssertComRCReturn(hrc, hrc);
2376
2377 /*
2378 * Get the attachment list and turn into an internal list for lookup speed.
2379 */
2380 com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
2381 hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(Bstr(rStrControllerName).raw(),
2382 ComSafeArrayAsOutParam(arrayOfMediumAttachments));
2383 AssertComRCReturn(hrc, hrc);
2384
2385 std::vector<ControllerSlot> arrayOfUsedSlots;
2386 for (size_t i = 0; i < arrayOfMediumAttachments.size(); i++)
2387 {
2388 LONG iPort = -1;
2389 hrc = arrayOfMediumAttachments[i]->COMGETTER(Port)(&iPort);
2390 AssertComRCReturn(hrc, hrc);
2391
2392 LONG iDevice = -1;
2393 hrc = arrayOfMediumAttachments[i]->COMGETTER(Device)(&iDevice);
2394 AssertComRCReturn(hrc, hrc);
2395
2396 arrayOfUsedSlots.push_back(ControllerSlot(enmStorageBus, Utf8Str::Empty, iPort, iDevice, false /*fFree*/));
2397 }
2398
2399 /*
2400 * Iterate thru all possible slots, adding those not found in arrayOfUsedSlots.
2401 */
2402 for (int32_t iPort = 0; iPort < (int32_t)cPorts; iPort++)
2403 for (int32_t iDevice = 0; iDevice < (int32_t)cMaxDevicesPerPort; iDevice++)
2404 {
2405 bool fFound = false;
2406 for (size_t i = 0; i < arrayOfUsedSlots.size(); i++)
2407 if ( arrayOfUsedSlots[i].iPort == iPort
2408 && arrayOfUsedSlots[i].iDevice == iDevice)
2409 {
2410 fFound = true;
2411 break;
2412 }
2413 if (!fFound)
2414 {
2415 rDvdSlots.push_back(ControllerSlot(enmStorageBus, rStrControllerName, iPort, iDevice, true /*fFree*/));
2416 if (rDvdSlots.size() >= cSlotsNeeded)
2417 return S_OK;
2418 }
2419 }
2420
2421 /*
2422 * Okay we still need more ports. See if increasing the number of controller
2423 * ports would solve it.
2424 */
2425 ULONG cMaxPorts = 1;
2426 hrc = pController->COMGETTER(MaxPortCount)(&cMaxPorts);
2427 AssertComRCReturn(hrc, hrc);
2428 if (cMaxPorts <= cPorts)
2429 return S_OK;
2430 size_t cNewPortsNeeded = (cSlotsNeeded - rDvdSlots.size() + cMaxDevicesPerPort - 1) / cMaxDevicesPerPort;
2431 if (cPorts + cNewPortsNeeded > cMaxPorts)
2432 return S_OK;
2433
2434 /*
2435 * Raise the port count and add the free slots we've just created.
2436 */
2437 hrc = pController->COMSETTER(PortCount)(cPorts + (ULONG)cNewPortsNeeded);
2438 AssertComRCReturn(hrc, hrc);
2439 int32_t const cPortsNew = (int32_t)(cPorts + cNewPortsNeeded);
2440 for (int32_t iPort = (int32_t)cPorts; iPort < cPortsNew; iPort++)
2441 for (int32_t iDevice = 0; iDevice < (int32_t)cMaxDevicesPerPort; iDevice++)
2442 {
2443 rDvdSlots.push_back(ControllerSlot(enmStorageBus, rStrControllerName, iPort, iDevice, true /*fFree*/));
2444 if (rDvdSlots.size() >= cSlotsNeeded)
2445 return S_OK;
2446 }
2447
2448 /* We should not get here! */
2449 AssertLogRelFailedReturn(E_UNEXPECTED);
2450}
2451
2452HRESULT Unattended::done()
2453{
2454 LogFlow(("Unattended::done\n"));
2455 if (mpInstaller)
2456 {
2457 LogRelFlow(("Unattended::done: Deleting installer object (%p)\n", mpInstaller));
2458 delete mpInstaller;
2459 mpInstaller = NULL;
2460 }
2461 return S_OK;
2462}
2463
2464HRESULT Unattended::getIsoPath(com::Utf8Str &isoPath)
2465{
2466 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2467 isoPath = mStrIsoPath;
2468 return S_OK;
2469}
2470
2471HRESULT Unattended::setIsoPath(const com::Utf8Str &isoPath)
2472{
2473 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2474 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2475 mStrIsoPath = isoPath;
2476 mfDoneDetectIsoOS = false;
2477 return S_OK;
2478}
2479
2480HRESULT Unattended::getUser(com::Utf8Str &user)
2481{
2482 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2483 user = mStrUser;
2484 return S_OK;
2485}
2486
2487
2488HRESULT Unattended::setUser(const com::Utf8Str &user)
2489{
2490 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2491 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2492 mStrUser = user;
2493 return S_OK;
2494}
2495
2496HRESULT Unattended::getPassword(com::Utf8Str &password)
2497{
2498 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2499 password = mStrPassword;
2500 return S_OK;
2501}
2502
2503HRESULT Unattended::setPassword(const com::Utf8Str &password)
2504{
2505 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2506 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2507 mStrPassword = password;
2508 return S_OK;
2509}
2510
2511HRESULT Unattended::getFullUserName(com::Utf8Str &fullUserName)
2512{
2513 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2514 fullUserName = mStrFullUserName;
2515 return S_OK;
2516}
2517
2518HRESULT Unattended::setFullUserName(const com::Utf8Str &fullUserName)
2519{
2520 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2521 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2522 mStrFullUserName = fullUserName;
2523 return S_OK;
2524}
2525
2526HRESULT Unattended::getProductKey(com::Utf8Str &productKey)
2527{
2528 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2529 productKey = mStrProductKey;
2530 return S_OK;
2531}
2532
2533HRESULT Unattended::setProductKey(const com::Utf8Str &productKey)
2534{
2535 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2536 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2537 mStrProductKey = productKey;
2538 return S_OK;
2539}
2540
2541HRESULT Unattended::getAdditionsIsoPath(com::Utf8Str &additionsIsoPath)
2542{
2543 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2544 additionsIsoPath = mStrAdditionsIsoPath;
2545 return S_OK;
2546}
2547
2548HRESULT Unattended::setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath)
2549{
2550 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2551 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2552 mStrAdditionsIsoPath = additionsIsoPath;
2553 return S_OK;
2554}
2555
2556HRESULT Unattended::getInstallGuestAdditions(BOOL *installGuestAdditions)
2557{
2558 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2559 *installGuestAdditions = mfInstallGuestAdditions;
2560 return S_OK;
2561}
2562
2563HRESULT Unattended::setInstallGuestAdditions(BOOL installGuestAdditions)
2564{
2565 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2566 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2567 mfInstallGuestAdditions = installGuestAdditions != FALSE;
2568 return S_OK;
2569}
2570
2571HRESULT Unattended::getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath)
2572{
2573 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2574 aValidationKitIsoPath = mStrValidationKitIsoPath;
2575 return S_OK;
2576}
2577
2578HRESULT Unattended::setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath)
2579{
2580 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2581 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2582 mStrValidationKitIsoPath = aValidationKitIsoPath;
2583 return S_OK;
2584}
2585
2586HRESULT Unattended::getInstallTestExecService(BOOL *aInstallTestExecService)
2587{
2588 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2589 *aInstallTestExecService = mfInstallTestExecService;
2590 return S_OK;
2591}
2592
2593HRESULT Unattended::setInstallTestExecService(BOOL aInstallTestExecService)
2594{
2595 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2596 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2597 mfInstallTestExecService = aInstallTestExecService != FALSE;
2598 return S_OK;
2599}
2600
2601HRESULT Unattended::getTimeZone(com::Utf8Str &aTimeZone)
2602{
2603 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2604 aTimeZone = mStrTimeZone;
2605 return S_OK;
2606}
2607
2608HRESULT Unattended::setTimeZone(const com::Utf8Str &aTimezone)
2609{
2610 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2611 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2612 mStrTimeZone = aTimezone;
2613 return S_OK;
2614}
2615
2616HRESULT Unattended::getLocale(com::Utf8Str &aLocale)
2617{
2618 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2619 aLocale = mStrLocale;
2620 return S_OK;
2621}
2622
2623HRESULT Unattended::setLocale(const com::Utf8Str &aLocale)
2624{
2625 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2626 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2627 if ( aLocale.isEmpty() /* use default */
2628 || ( aLocale.length() == 5
2629 && RT_C_IS_LOWER(aLocale[0])
2630 && RT_C_IS_LOWER(aLocale[1])
2631 && aLocale[2] == '_'
2632 && RT_C_IS_UPPER(aLocale[3])
2633 && RT_C_IS_UPPER(aLocale[4])) )
2634 {
2635 mStrLocale = aLocale;
2636 return S_OK;
2637 }
2638 return setError(E_INVALIDARG, tr("Expected two lower cased letters, an underscore, and two upper cased letters"));
2639}
2640
2641HRESULT Unattended::getLanguage(com::Utf8Str &aLanguage)
2642{
2643 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2644 aLanguage = mStrLanguage;
2645 return S_OK;
2646}
2647
2648HRESULT Unattended::setLanguage(const com::Utf8Str &aLanguage)
2649{
2650 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2651 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2652 mStrLanguage = aLanguage;
2653 return S_OK;
2654}
2655
2656HRESULT Unattended::getCountry(com::Utf8Str &aCountry)
2657{
2658 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2659 aCountry = mStrCountry;
2660 return S_OK;
2661}
2662
2663HRESULT Unattended::setCountry(const com::Utf8Str &aCountry)
2664{
2665 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2666 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2667 if ( aCountry.isEmpty()
2668 || ( aCountry.length() == 2
2669 && RT_C_IS_UPPER(aCountry[0])
2670 && RT_C_IS_UPPER(aCountry[1])) )
2671 {
2672 mStrCountry = aCountry;
2673 return S_OK;
2674 }
2675 return setError(E_INVALIDARG, tr("Expected two upper cased letters"));
2676}
2677
2678HRESULT Unattended::getProxy(com::Utf8Str &aProxy)
2679{
2680 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2681 aProxy = mStrProxy; /// @todo turn schema map into string or something.
2682 return S_OK;
2683}
2684
2685HRESULT Unattended::setProxy(const com::Utf8Str &aProxy)
2686{
2687 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2688 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2689 if (aProxy.isEmpty())
2690 {
2691 /* set default proxy */
2692 /** @todo BUGBUG! implement this */
2693 }
2694 else if (aProxy.equalsIgnoreCase("none"))
2695 {
2696 /* clear proxy config */
2697 mStrProxy.setNull();
2698 }
2699 else
2700 {
2701 /** @todo Parse and set proxy config into a schema map or something along those lines. */
2702 /** @todo BUGBUG! implement this */
2703 // return E_NOTIMPL;
2704 mStrProxy = aProxy;
2705 }
2706 return S_OK;
2707}
2708
2709HRESULT Unattended::getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments)
2710{
2711 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2712 aPackageSelectionAdjustments = RTCString::join(mPackageSelectionAdjustments, ";");
2713 return S_OK;
2714}
2715
2716HRESULT Unattended::setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments)
2717{
2718 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2719 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2720 if (aPackageSelectionAdjustments.isEmpty())
2721 mPackageSelectionAdjustments.clear();
2722 else
2723 {
2724 RTCList<RTCString, RTCString *> arrayStrSplit = aPackageSelectionAdjustments.split(";");
2725 for (size_t i = 0; i < arrayStrSplit.size(); i++)
2726 {
2727 if (arrayStrSplit[i].equals("minimal"))
2728 { /* okay */ }
2729 else
2730 return setError(E_INVALIDARG, tr("Unknown keyword: %s"), arrayStrSplit[i].c_str());
2731 }
2732 mPackageSelectionAdjustments = arrayStrSplit;
2733 }
2734 return S_OK;
2735}
2736
2737HRESULT Unattended::getHostname(com::Utf8Str &aHostname)
2738{
2739 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2740 aHostname = mStrHostname;
2741 return S_OK;
2742}
2743
2744HRESULT Unattended::setHostname(const com::Utf8Str &aHostname)
2745{
2746 /*
2747 * Validate input.
2748 */
2749 if (aHostname.length() > (aHostname.endsWith(".") ? 254U : 253U))
2750 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2751 tr("Hostname '%s' is %zu bytes long, max is 253 (excluding trailing dot)", "", aHostname.length()),
2752 aHostname.c_str(), aHostname.length());
2753 size_t cLabels = 0;
2754 const char *pszSrc = aHostname.c_str();
2755 for (;;)
2756 {
2757 size_t cchLabel = 1;
2758 char ch = *pszSrc++;
2759 if (RT_C_IS_ALNUM(ch))
2760 {
2761 cLabels++;
2762 while ((ch = *pszSrc++) != '.' && ch != '\0')
2763 {
2764 if (RT_C_IS_ALNUM(ch) || ch == '-')
2765 {
2766 if (cchLabel < 63)
2767 cchLabel++;
2768 else
2769 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2770 tr("Invalid hostname '%s' - label %u is too long, max is 63."),
2771 aHostname.c_str(), cLabels);
2772 }
2773 else
2774 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2775 tr("Invalid hostname '%s' - illegal char '%c' at position %zu"),
2776 aHostname.c_str(), ch, pszSrc - aHostname.c_str() - 1);
2777 }
2778 if (cLabels == 1 && cchLabel < 2)
2779 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2780 tr("Invalid hostname '%s' - the name part must be at least two characters long"),
2781 aHostname.c_str());
2782 if (ch == '\0')
2783 break;
2784 }
2785 else if (ch != '\0')
2786 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2787 tr("Invalid hostname '%s' - illegal lead char '%c' at position %zu"),
2788 aHostname.c_str(), ch, pszSrc - aHostname.c_str() - 1);
2789 else
2790 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2791 tr("Invalid hostname '%s' - trailing dot not permitted"), aHostname.c_str());
2792 }
2793 if (cLabels < 2)
2794 return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
2795 tr("Incomplete hostname '%s' - must include both a name and a domain"), aHostname.c_str());
2796
2797 /*
2798 * Make the change.
2799 */
2800 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2801 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2802 mStrHostname = aHostname;
2803 return S_OK;
2804}
2805
2806HRESULT Unattended::getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath)
2807{
2808 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2809 aAuxiliaryBasePath = mStrAuxiliaryBasePath;
2810 return S_OK;
2811}
2812
2813HRESULT Unattended::setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath)
2814{
2815 if (aAuxiliaryBasePath.isEmpty())
2816 return setError(E_INVALIDARG, tr("Empty base path is not allowed"));
2817 if (!RTPathStartsWithRoot(aAuxiliaryBasePath.c_str()))
2818 return setError(E_INVALIDARG, tr("Base path must be absolute"));
2819
2820 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2821 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2822 mStrAuxiliaryBasePath = aAuxiliaryBasePath;
2823 mfIsDefaultAuxiliaryBasePath = mStrAuxiliaryBasePath.isEmpty();
2824 return S_OK;
2825}
2826
2827HRESULT Unattended::getImageIndex(ULONG *index)
2828{
2829 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2830 *index = midxImage;
2831 return S_OK;
2832}
2833
2834HRESULT Unattended::setImageIndex(ULONG index)
2835{
2836 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2837 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2838 midxImage = index;
2839 return S_OK;
2840}
2841
2842HRESULT Unattended::getMachine(ComPtr<IMachine> &aMachine)
2843{
2844 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2845 return mMachine.queryInterfaceTo(aMachine.asOutParam());
2846}
2847
2848HRESULT Unattended::setMachine(const ComPtr<IMachine> &aMachine)
2849{
2850 /*
2851 * Lookup the VM so we can safely get the Machine instance.
2852 * (Don't want to test how reliable XPCOM and COM are with finding
2853 * the local object instance when a client passes a stub back.)
2854 */
2855 Bstr bstrUuidMachine;
2856 HRESULT hrc = aMachine->COMGETTER(Id)(bstrUuidMachine.asOutParam());
2857 if (SUCCEEDED(hrc))
2858 {
2859 Guid UuidMachine(bstrUuidMachine);
2860 ComObjPtr<Machine> ptrMachine;
2861 hrc = mParent->i_findMachine(UuidMachine, false /*fPermitInaccessible*/, true /*aSetError*/, &ptrMachine);
2862 if (SUCCEEDED(hrc))
2863 {
2864 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2865 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER,
2866 tr("Cannot change after prepare() has been called")));
2867 mMachine = ptrMachine;
2868 mMachineUuid = UuidMachine;
2869 if (mfIsDefaultAuxiliaryBasePath)
2870 mStrAuxiliaryBasePath.setNull();
2871 hrc = S_OK;
2872 }
2873 }
2874 return hrc;
2875}
2876
2877HRESULT Unattended::getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath)
2878{
2879 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2880 if ( mStrScriptTemplatePath.isNotEmpty()
2881 || mpInstaller == NULL)
2882 aScriptTemplatePath = mStrScriptTemplatePath;
2883 else
2884 aScriptTemplatePath = mpInstaller->getTemplateFilePath();
2885 return S_OK;
2886}
2887
2888HRESULT Unattended::setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath)
2889{
2890 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2891 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2892 mStrScriptTemplatePath = aScriptTemplatePath;
2893 return S_OK;
2894}
2895
2896HRESULT Unattended::getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath)
2897{
2898 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2899 if ( mStrPostInstallScriptTemplatePath.isNotEmpty()
2900 || mpInstaller == NULL)
2901 aPostInstallScriptTemplatePath = mStrPostInstallScriptTemplatePath;
2902 else
2903 aPostInstallScriptTemplatePath = mpInstaller->getPostTemplateFilePath();
2904 return S_OK;
2905}
2906
2907HRESULT Unattended::setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath)
2908{
2909 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2910 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2911 mStrPostInstallScriptTemplatePath = aPostInstallScriptTemplatePath;
2912 return S_OK;
2913}
2914
2915HRESULT Unattended::getPostInstallCommand(com::Utf8Str &aPostInstallCommand)
2916{
2917 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2918 aPostInstallCommand = mStrPostInstallCommand;
2919 return S_OK;
2920}
2921
2922HRESULT Unattended::setPostInstallCommand(const com::Utf8Str &aPostInstallCommand)
2923{
2924 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2925 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2926 mStrPostInstallCommand = aPostInstallCommand;
2927 return S_OK;
2928}
2929
2930HRESULT Unattended::getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters)
2931{
2932 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2933 if ( mStrExtraInstallKernelParameters.isNotEmpty()
2934 || mpInstaller == NULL)
2935 aExtraInstallKernelParameters = mStrExtraInstallKernelParameters;
2936 else
2937 aExtraInstallKernelParameters = mpInstaller->getDefaultExtraInstallKernelParameters();
2938 return S_OK;
2939}
2940
2941HRESULT Unattended::setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters)
2942{
2943 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2944 AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
2945 mStrExtraInstallKernelParameters = aExtraInstallKernelParameters;
2946 return S_OK;
2947}
2948
2949HRESULT Unattended::getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId)
2950{
2951 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2952 aDetectedOSTypeId = mStrDetectedOSTypeId;
2953 return S_OK;
2954}
2955
2956HRESULT Unattended::getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion)
2957{
2958 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2959 aDetectedOSVersion = mStrDetectedOSVersion;
2960 return S_OK;
2961}
2962
2963HRESULT Unattended::getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor)
2964{
2965 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2966 aDetectedOSFlavor = mStrDetectedOSFlavor;
2967 return S_OK;
2968}
2969
2970HRESULT Unattended::getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages)
2971{
2972 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2973 aDetectedOSLanguages = RTCString::join(mDetectedOSLanguages, " ");
2974 return S_OK;
2975}
2976
2977HRESULT Unattended::getDetectedOSHints(com::Utf8Str &aDetectedOSHints)
2978{
2979 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2980 aDetectedOSHints = mStrDetectedOSHints;
2981 return S_OK;
2982}
2983
2984/*
2985 * Getters that the installer and script classes can use.
2986 */
2987Utf8Str const &Unattended::i_getIsoPath() const
2988{
2989 Assert(isReadLockedOnCurrentThread());
2990 return mStrIsoPath;
2991}
2992
2993Utf8Str const &Unattended::i_getUser() const
2994{
2995 Assert(isReadLockedOnCurrentThread());
2996 return mStrUser;
2997}
2998
2999Utf8Str const &Unattended::i_getPassword() const
3000{
3001 Assert(isReadLockedOnCurrentThread());
3002 return mStrPassword;
3003}
3004
3005Utf8Str const &Unattended::i_getFullUserName() const
3006{
3007 Assert(isReadLockedOnCurrentThread());
3008 return mStrFullUserName.isNotEmpty() ? mStrFullUserName : mStrUser;
3009}
3010
3011Utf8Str const &Unattended::i_getProductKey() const
3012{
3013 Assert(isReadLockedOnCurrentThread());
3014 return mStrProductKey;
3015}
3016
3017Utf8Str const &Unattended::i_getProxy() const
3018{
3019 Assert(isReadLockedOnCurrentThread());
3020 return mStrProxy;
3021}
3022
3023Utf8Str const &Unattended::i_getAdditionsIsoPath() const
3024{
3025 Assert(isReadLockedOnCurrentThread());
3026 return mStrAdditionsIsoPath;
3027}
3028
3029bool Unattended::i_getInstallGuestAdditions() const
3030{
3031 Assert(isReadLockedOnCurrentThread());
3032 return mfInstallGuestAdditions;
3033}
3034
3035Utf8Str const &Unattended::i_getValidationKitIsoPath() const
3036{
3037 Assert(isReadLockedOnCurrentThread());
3038 return mStrValidationKitIsoPath;
3039}
3040
3041bool Unattended::i_getInstallTestExecService() const
3042{
3043 Assert(isReadLockedOnCurrentThread());
3044 return mfInstallTestExecService;
3045}
3046
3047Utf8Str const &Unattended::i_getTimeZone() const
3048{
3049 Assert(isReadLockedOnCurrentThread());
3050 return mStrTimeZone;
3051}
3052
3053PCRTTIMEZONEINFO Unattended::i_getTimeZoneInfo() const
3054{
3055 Assert(isReadLockedOnCurrentThread());
3056 return mpTimeZoneInfo;
3057}
3058
3059Utf8Str const &Unattended::i_getLocale() const
3060{
3061 Assert(isReadLockedOnCurrentThread());
3062 return mStrLocale;
3063}
3064
3065Utf8Str const &Unattended::i_getLanguage() const
3066{
3067 Assert(isReadLockedOnCurrentThread());
3068 return mStrLanguage;
3069}
3070
3071Utf8Str const &Unattended::i_getCountry() const
3072{
3073 Assert(isReadLockedOnCurrentThread());
3074 return mStrCountry;
3075}
3076
3077bool Unattended::i_isMinimalInstallation() const
3078{
3079 size_t i = mPackageSelectionAdjustments.size();
3080 while (i-- > 0)
3081 if (mPackageSelectionAdjustments[i].equals("minimal"))
3082 return true;
3083 return false;
3084}
3085
3086Utf8Str const &Unattended::i_getHostname() const
3087{
3088 Assert(isReadLockedOnCurrentThread());
3089 return mStrHostname;
3090}
3091
3092Utf8Str const &Unattended::i_getAuxiliaryBasePath() const
3093{
3094 Assert(isReadLockedOnCurrentThread());
3095 return mStrAuxiliaryBasePath;
3096}
3097
3098ULONG Unattended::i_getImageIndex() const
3099{
3100 Assert(isReadLockedOnCurrentThread());
3101 return midxImage;
3102}
3103
3104Utf8Str const &Unattended::i_getScriptTemplatePath() const
3105{
3106 Assert(isReadLockedOnCurrentThread());
3107 return mStrScriptTemplatePath;
3108}
3109
3110Utf8Str const &Unattended::i_getPostInstallScriptTemplatePath() const
3111{
3112 Assert(isReadLockedOnCurrentThread());
3113 return mStrPostInstallScriptTemplatePath;
3114}
3115
3116Utf8Str const &Unattended::i_getPostInstallCommand() const
3117{
3118 Assert(isReadLockedOnCurrentThread());
3119 return mStrPostInstallCommand;
3120}
3121
3122Utf8Str const &Unattended::i_getAuxiliaryInstallDir() const
3123{
3124 Assert(isReadLockedOnCurrentThread());
3125 /* Only the installer knows, forward the call. */
3126 AssertReturn(mpInstaller != NULL, Utf8Str::Empty);
3127 return mpInstaller->getAuxiliaryInstallDir();
3128}
3129
3130Utf8Str const &Unattended::i_getExtraInstallKernelParameters() const
3131{
3132 Assert(isReadLockedOnCurrentThread());
3133 return mStrExtraInstallKernelParameters;
3134}
3135
3136bool Unattended::i_isRtcUsingUtc() const
3137{
3138 Assert(isReadLockedOnCurrentThread());
3139 return mfRtcUseUtc;
3140}
3141
3142bool Unattended::i_isGuestOs64Bit() const
3143{
3144 Assert(isReadLockedOnCurrentThread());
3145 return mfGuestOs64Bit;
3146}
3147
3148bool Unattended::i_isFirmwareEFI() const
3149{
3150 Assert(isReadLockedOnCurrentThread());
3151 return menmFirmwareType != FirmwareType_BIOS;
3152}
3153
3154VBOXOSTYPE Unattended::i_getGuestOsType() const
3155{
3156 Assert(isReadLockedOnCurrentThread());
3157 return meGuestOsType;
3158}
3159
3160Utf8Str const &Unattended::i_getDetectedOSVersion()
3161{
3162 Assert(isReadLockedOnCurrentThread());
3163 return mStrDetectedOSVersion;
3164}
3165
3166HRESULT Unattended::i_attachImage(UnattendedInstallationDisk const *pImage, ComPtr<IMachine> const &rPtrSessionMachine,
3167 AutoMultiWriteLock2 &rLock)
3168{
3169 /*
3170 * Attach the disk image
3171 * HACK ALERT! Temporarily release the Unattended lock.
3172 */
3173 rLock.release();
3174
3175 ComPtr<IMedium> ptrMedium;
3176 HRESULT rc = mParent->OpenMedium(Bstr(pImage->strImagePath).raw(),
3177 pImage->enmDeviceType,
3178 pImage->enmAccessType,
3179 true,
3180 ptrMedium.asOutParam());
3181 LogRelFlowFunc(("VirtualBox::openMedium -> %Rhrc\n", rc));
3182 if (SUCCEEDED(rc))
3183 {
3184 if (pImage->fMountOnly)
3185 {
3186 // mount the opened disk image
3187 rc = rPtrSessionMachine->MountMedium(Bstr(pImage->strControllerName).raw(), pImage->iPort,
3188 pImage->iDevice, ptrMedium, TRUE /*fForce*/);
3189 LogRelFlowFunc(("Machine::MountMedium -> %Rhrc\n", rc));
3190 }
3191 else
3192 {
3193 //attach the opened disk image to the controller
3194 rc = rPtrSessionMachine->AttachDevice(Bstr(pImage->strControllerName).raw(), pImage->iPort,
3195 pImage->iDevice, pImage->enmDeviceType, ptrMedium);
3196 LogRelFlowFunc(("Machine::AttachDevice -> %Rhrc\n", rc));
3197 }
3198 }
3199
3200 rLock.acquire();
3201 return rc;
3202}
3203
3204bool Unattended::i_isGuestOSArchX64(Utf8Str const &rStrGuestOsTypeId)
3205{
3206 ComPtr<IGuestOSType> pGuestOSType;
3207 HRESULT hrc = mParent->GetGuestOSType(Bstr(rStrGuestOsTypeId).raw(), pGuestOSType.asOutParam());
3208 if (SUCCEEDED(hrc))
3209 {
3210 BOOL fIs64Bit = FALSE;
3211 if (!pGuestOSType.isNull())
3212 hrc = pGuestOSType->COMGETTER(Is64Bit)(&fIs64Bit);
3213 if (SUCCEEDED(hrc))
3214 return fIs64Bit != FALSE;
3215 }
3216 return false;
3217}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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