VirtualBox

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

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

Main/UnattendedImpl: Updated install.wim todo with some info.

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

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