1 | /* $Id: UnattendedImpl.cpp 71012 2018-02-14 16:14:36Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Unattended class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_MAIN_UNATTENDED
|
---|
23 | #include "LoggingNew.h"
|
---|
24 | #include "VirtualBoxBase.h"
|
---|
25 | #include "UnattendedImpl.h"
|
---|
26 | #include "UnattendedInstaller.h"
|
---|
27 | #include "UnattendedScript.h"
|
---|
28 | #include "VirtualBoxImpl.h"
|
---|
29 | #include "SystemPropertiesImpl.h"
|
---|
30 | #include "MachineImpl.h"
|
---|
31 | #include "Global.h"
|
---|
32 |
|
---|
33 | #include <VBox/err.h>
|
---|
34 | #include <iprt/ctype.h>
|
---|
35 | #include <iprt/file.h>
|
---|
36 | #include <iprt/fsvfs.h>
|
---|
37 | #include <iprt/inifile.h>
|
---|
38 | #include <iprt/locale.h>
|
---|
39 | #include <iprt/path.h>
|
---|
40 |
|
---|
41 | using namespace std;
|
---|
42 |
|
---|
43 | /* XPCOM doesn't define S_FALSE. */
|
---|
44 | #ifndef S_FALSE
|
---|
45 | # define S_FALSE ((HRESULT)1)
|
---|
46 | #endif
|
---|
47 |
|
---|
48 |
|
---|
49 | /*********************************************************************************************************************************
|
---|
50 | * Structures and Typedefs *
|
---|
51 | *********************************************************************************************************************************/
|
---|
52 | /**
|
---|
53 | * Controller slot for a DVD drive.
|
---|
54 | *
|
---|
55 | * The slot can be free and needing a drive to be attached along with the ISO
|
---|
56 | * image, or it may already be there and only need mounting the ISO. The
|
---|
57 | * ControllerSlot::fFree member indicates which it is.
|
---|
58 | */
|
---|
59 | struct ControllerSlot
|
---|
60 | {
|
---|
61 | StorageBus_T enmBus;
|
---|
62 | Utf8Str strControllerName;
|
---|
63 | ULONG uPort;
|
---|
64 | ULONG uDevice;
|
---|
65 | bool fFree;
|
---|
66 |
|
---|
67 | ControllerSlot(StorageBus_T a_enmBus, const Utf8Str &a_rName, ULONG a_uPort, ULONG a_uDevice, bool a_fFree)
|
---|
68 | : enmBus(a_enmBus), strControllerName(a_rName), uPort(a_uPort), uDevice(a_uDevice), fFree(a_fFree)
|
---|
69 | {}
|
---|
70 |
|
---|
71 | bool operator<(const ControllerSlot &rThat) const
|
---|
72 | {
|
---|
73 | if (enmBus == rThat.enmBus)
|
---|
74 | {
|
---|
75 | if (strControllerName == rThat.strControllerName)
|
---|
76 | {
|
---|
77 | if (uPort == rThat.uPort)
|
---|
78 | return uDevice < rThat.uDevice;
|
---|
79 | return uPort < rThat.uPort;
|
---|
80 | }
|
---|
81 | return strControllerName < rThat.strControllerName;
|
---|
82 | }
|
---|
83 |
|
---|
84 | /*
|
---|
85 | * Bus comparsion in boot priority order.
|
---|
86 | */
|
---|
87 | /* IDE first. */
|
---|
88 | if (enmBus == StorageBus_IDE)
|
---|
89 | return true;
|
---|
90 | if (rThat.enmBus == StorageBus_IDE)
|
---|
91 | return false;
|
---|
92 | /* SATA next */
|
---|
93 | if (enmBus == StorageBus_SATA)
|
---|
94 | return true;
|
---|
95 | if (rThat.enmBus == StorageBus_SATA)
|
---|
96 | return false;
|
---|
97 | /* SCSI next */
|
---|
98 | if (enmBus == StorageBus_SCSI)
|
---|
99 | return true;
|
---|
100 | if (rThat.enmBus == StorageBus_SCSI)
|
---|
101 | return false;
|
---|
102 | /* numerical */
|
---|
103 | return (int)enmBus < (int)rThat.enmBus;
|
---|
104 | }
|
---|
105 |
|
---|
106 | bool operator==(const ControllerSlot &rThat) const
|
---|
107 | {
|
---|
108 | return enmBus == rThat.enmBus
|
---|
109 | && strControllerName == rThat.strControllerName
|
---|
110 | && uPort == rThat.uPort
|
---|
111 | && uDevice == rThat.uDevice;
|
---|
112 | }
|
---|
113 | };
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Installation disk.
|
---|
117 | *
|
---|
118 | * Used when reconfiguring the VM.
|
---|
119 | */
|
---|
120 | typedef struct UnattendedInstallationDisk
|
---|
121 | {
|
---|
122 | StorageBus_T enmBusType; /**< @todo nobody is using this... */
|
---|
123 | Utf8Str strControllerName;
|
---|
124 | DeviceType_T enmDeviceType;
|
---|
125 | AccessMode_T enmAccessType;
|
---|
126 | ULONG uPort;
|
---|
127 | ULONG uDevice;
|
---|
128 | bool fMountOnly;
|
---|
129 | Utf8Str strImagePath;
|
---|
130 |
|
---|
131 | UnattendedInstallationDisk(StorageBus_T a_enmBusType, Utf8Str const &a_rBusName, DeviceType_T a_enmDeviceType,
|
---|
132 | AccessMode_T a_enmAccessType, ULONG a_uPort, ULONG a_uDevice, bool a_fMountOnly,
|
---|
133 | Utf8Str const &a_rImagePath)
|
---|
134 | : enmBusType(a_enmBusType), strControllerName(a_rBusName), enmDeviceType(a_enmDeviceType), enmAccessType(a_enmAccessType)
|
---|
135 | , uPort(a_uPort), uDevice(a_uDevice), fMountOnly(a_fMountOnly), strImagePath(a_rImagePath)
|
---|
136 | {
|
---|
137 | Assert(strControllerName.length() > 0);
|
---|
138 | }
|
---|
139 |
|
---|
140 | UnattendedInstallationDisk(std::list<ControllerSlot>::const_iterator const &itDvdSlot, Utf8Str const &a_rImagePath)
|
---|
141 | : enmBusType(itDvdSlot->enmBus), strControllerName(itDvdSlot->strControllerName), enmDeviceType(DeviceType_DVD)
|
---|
142 | , enmAccessType(AccessMode_ReadOnly), uPort(itDvdSlot->uPort), uDevice(itDvdSlot->uDevice)
|
---|
143 | , fMountOnly(!itDvdSlot->fFree), strImagePath(a_rImagePath)
|
---|
144 | {
|
---|
145 | Assert(strControllerName.length() > 0);
|
---|
146 | }
|
---|
147 | } UnattendedInstallationDisk;
|
---|
148 |
|
---|
149 |
|
---|
150 | //////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
151 | /*
|
---|
152 | *
|
---|
153 | *
|
---|
154 | * Implementation Unattended functions
|
---|
155 | *
|
---|
156 | */
|
---|
157 | //////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
158 |
|
---|
159 | Unattended::Unattended()
|
---|
160 | : mhThreadReconfigureVM(NIL_RTNATIVETHREAD), mfRtcUseUtc(false), mfGuestOs64Bit(false)
|
---|
161 | , mpInstaller(NULL), mpTimeZoneInfo(NULL), mfIsDefaultAuxiliaryBasePath(true), mfDoneDetectIsoOS(false)
|
---|
162 | { }
|
---|
163 |
|
---|
164 | Unattended::~Unattended()
|
---|
165 | {
|
---|
166 | if (mpInstaller)
|
---|
167 | {
|
---|
168 | delete mpInstaller;
|
---|
169 | mpInstaller = NULL;
|
---|
170 | }
|
---|
171 | }
|
---|
172 |
|
---|
173 | HRESULT Unattended::FinalConstruct()
|
---|
174 | {
|
---|
175 | return BaseFinalConstruct();
|
---|
176 | }
|
---|
177 |
|
---|
178 | void Unattended::FinalRelease()
|
---|
179 | {
|
---|
180 | uninit();
|
---|
181 |
|
---|
182 | BaseFinalRelease();
|
---|
183 | }
|
---|
184 |
|
---|
185 | void Unattended::uninit()
|
---|
186 | {
|
---|
187 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
188 | AutoUninitSpan autoUninitSpan(this);
|
---|
189 | if (autoUninitSpan.uninitDone())
|
---|
190 | return;
|
---|
191 |
|
---|
192 | unconst(mParent) = NULL;
|
---|
193 | mMachine.setNull();
|
---|
194 | }
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * Initializes the unattended object.
|
---|
198 | *
|
---|
199 | * @param aParent Pointer to the parent object.
|
---|
200 | */
|
---|
201 | HRESULT Unattended::initUnattended(VirtualBox *aParent)
|
---|
202 | {
|
---|
203 | LogFlowThisFunc(("aParent=%p\n", aParent));
|
---|
204 | ComAssertRet(aParent, E_INVALIDARG);
|
---|
205 |
|
---|
206 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
207 | AutoInitSpan autoInitSpan(this);
|
---|
208 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
209 |
|
---|
210 | unconst(mParent) = aParent;
|
---|
211 |
|
---|
212 | /*
|
---|
213 | * Fill public attributes (IUnattended) with useful defaults.
|
---|
214 | */
|
---|
215 | try
|
---|
216 | {
|
---|
217 | mStrUser = "vboxuser";
|
---|
218 | mStrPassword = "changeme";
|
---|
219 | mfInstallGuestAdditions = false;
|
---|
220 | mfInstallTestExecService = false;
|
---|
221 | midxImage = 1;
|
---|
222 |
|
---|
223 | HRESULT hrc = mParent->i_getSystemProperties()->i_getDefaultAdditionsISO(mStrAdditionsIsoPath);
|
---|
224 | ComAssertComRCRet(hrc, hrc);
|
---|
225 | }
|
---|
226 | catch (std::bad_alloc)
|
---|
227 | {
|
---|
228 | return E_OUTOFMEMORY;
|
---|
229 | }
|
---|
230 |
|
---|
231 | /*
|
---|
232 | * Confirm a successful initialization
|
---|
233 | */
|
---|
234 | autoInitSpan.setSucceeded();
|
---|
235 |
|
---|
236 | return S_OK;
|
---|
237 | }
|
---|
238 |
|
---|
239 | HRESULT Unattended::detectIsoOS()
|
---|
240 | {
|
---|
241 | HRESULT hrc;
|
---|
242 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
243 |
|
---|
244 | /** @todo once UDF is implemented properly and we've tested this code a lot
|
---|
245 | * more, replace E_NOTIMPL with E_FAIL. */
|
---|
246 |
|
---|
247 |
|
---|
248 | /*
|
---|
249 | * Open the ISO.
|
---|
250 | */
|
---|
251 | RTVFSFILE hVfsFileIso;
|
---|
252 | int vrc = RTVfsFileOpenNormal(mStrIsoPath.c_str(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFileIso);
|
---|
253 | if (RT_FAILURE(vrc))
|
---|
254 | return setErrorBoth(E_NOTIMPL, vrc, tr("Failed to open '%s' (%Rrc)"), mStrIsoPath.c_str(), vrc);
|
---|
255 |
|
---|
256 | RTERRINFOSTATIC ErrInfo;
|
---|
257 | RTVFS hVfsIso;
|
---|
258 | vrc = RTFsIso9660VolOpen(hVfsFileIso, 0 /*fFlags*/, &hVfsIso, RTErrInfoInitStatic(&ErrInfo));
|
---|
259 | if (RT_SUCCESS(vrc))
|
---|
260 | {
|
---|
261 | /*
|
---|
262 | * Try do the detection. Repeat for different file system variations (nojoliet, noudf).
|
---|
263 | */
|
---|
264 | hrc = i_innerDetectIsoOS(hVfsIso);
|
---|
265 |
|
---|
266 | RTVfsRelease(hVfsIso);
|
---|
267 | hrc = E_NOTIMPL;
|
---|
268 | }
|
---|
269 | else if (RTErrInfoIsSet(&ErrInfo.Core))
|
---|
270 | hrc = setErrorBoth(E_NOTIMPL, vrc, tr("Failed to open '%s' as ISO FS (%Rrc) - %s"),
|
---|
271 | mStrIsoPath.c_str(), vrc, ErrInfo.Core.pszMsg);
|
---|
272 | else
|
---|
273 | hrc = setErrorBoth(E_NOTIMPL, vrc, tr("Failed to open '%s' as ISO FS (%Rrc)"), mStrIsoPath.c_str(), vrc);
|
---|
274 | RTVfsFileRelease(hVfsFileIso);
|
---|
275 |
|
---|
276 | /*
|
---|
277 | * Just fake up some windows installation media locale (for <UILanguage>).
|
---|
278 | * Note! The translation here isn't perfect. Feel free to send us a patch.
|
---|
279 | */
|
---|
280 | if (mDetectedOSLanguages.size() == 0)
|
---|
281 | {
|
---|
282 | char szTmp[16];
|
---|
283 | const char *pszFilename = RTPathFilename(mStrIsoPath.c_str());
|
---|
284 | if ( pszFilename
|
---|
285 | && RT_C_IS_ALPHA(pszFilename[0])
|
---|
286 | && RT_C_IS_ALPHA(pszFilename[1])
|
---|
287 | && (pszFilename[2] == '-' || pszFilename[2] == '_') )
|
---|
288 | {
|
---|
289 | szTmp[0] = (char)RT_C_TO_LOWER(pszFilename[0]);
|
---|
290 | szTmp[1] = (char)RT_C_TO_LOWER(pszFilename[1]);
|
---|
291 | szTmp[2] = '-';
|
---|
292 | if (szTmp[0] == 'e' && szTmp[1] == 'n')
|
---|
293 | strcpy(&szTmp[3], "US");
|
---|
294 | else if (szTmp[0] == 'a' && szTmp[1] == 'r')
|
---|
295 | strcpy(&szTmp[3], "SA");
|
---|
296 | else if (szTmp[0] == 'd' && szTmp[1] == 'a')
|
---|
297 | strcpy(&szTmp[3], "DK");
|
---|
298 | else if (szTmp[0] == 'e' && szTmp[1] == 't')
|
---|
299 | strcpy(&szTmp[3], "EE");
|
---|
300 | else if (szTmp[0] == 'e' && szTmp[1] == 'l')
|
---|
301 | strcpy(&szTmp[3], "GR");
|
---|
302 | else if (szTmp[0] == 'h' && szTmp[1] == 'e')
|
---|
303 | strcpy(&szTmp[3], "IL");
|
---|
304 | else if (szTmp[0] == 'j' && szTmp[1] == 'a')
|
---|
305 | strcpy(&szTmp[3], "JP");
|
---|
306 | else if (szTmp[0] == 's' && szTmp[1] == 'v')
|
---|
307 | strcpy(&szTmp[3], "SE");
|
---|
308 | else if (szTmp[0] == 'u' && szTmp[1] == 'k')
|
---|
309 | strcpy(&szTmp[3], "UA");
|
---|
310 | else if (szTmp[0] == 'c' && szTmp[1] == 's')
|
---|
311 | strcpy(szTmp, "cs-CZ");
|
---|
312 | else if (szTmp[0] == 'n' && szTmp[1] == 'o')
|
---|
313 | strcpy(szTmp, "nb-NO");
|
---|
314 | else if (szTmp[0] == 'p' && szTmp[1] == 'p')
|
---|
315 | strcpy(szTmp, "pt-PT");
|
---|
316 | else if (szTmp[0] == 'p' && szTmp[1] == 't')
|
---|
317 | strcpy(szTmp, "pt-BR");
|
---|
318 | else if (szTmp[0] == 'c' && szTmp[1] == 'n')
|
---|
319 | strcpy(szTmp, "zh-CN");
|
---|
320 | else if (szTmp[0] == 'h' && szTmp[1] == 'k')
|
---|
321 | strcpy(szTmp, "zh-HK");
|
---|
322 | else if (szTmp[0] == 't' && szTmp[1] == 'w')
|
---|
323 | strcpy(szTmp, "zh-TW");
|
---|
324 | else if (szTmp[0] == 's' && szTmp[1] == 'r')
|
---|
325 | strcpy(szTmp, "sr-Latn-CS"); /* hmm */
|
---|
326 | else
|
---|
327 | {
|
---|
328 | szTmp[3] = (char)RT_C_TO_UPPER(pszFilename[0]);
|
---|
329 | szTmp[4] = (char)RT_C_TO_UPPER(pszFilename[1]);
|
---|
330 | szTmp[5] = '\0';
|
---|
331 | }
|
---|
332 | }
|
---|
333 | else
|
---|
334 | strcpy(szTmp, "en-US");
|
---|
335 | try
|
---|
336 | {
|
---|
337 | mDetectedOSLanguages.append(szTmp);
|
---|
338 | }
|
---|
339 | catch (std::bad_alloc)
|
---|
340 | {
|
---|
341 | return E_OUTOFMEMORY;
|
---|
342 | }
|
---|
343 | }
|
---|
344 |
|
---|
345 | /** @todo implement actual detection logic. */
|
---|
346 | return hrc;
|
---|
347 | }
|
---|
348 |
|
---|
349 | HRESULT Unattended::i_innerDetectIsoOS(RTVFS hVfsIso)
|
---|
350 | {
|
---|
351 | DETECTBUFFER uBuf;
|
---|
352 | VBOXOSTYPE enmOsType = VBOXOSTYPE_Unknown;
|
---|
353 | HRESULT hrc = i_innerDetectIsoOSWindows(hVfsIso, &uBuf, &enmOsType);
|
---|
354 | if (hrc == S_FALSE && enmOsType == VBOXOSTYPE_Unknown)
|
---|
355 | hrc = i_innerDetectIsoOSLinux(hVfsIso, &uBuf, &enmOsType);
|
---|
356 | if (enmOsType != VBOXOSTYPE_Unknown)
|
---|
357 | {
|
---|
358 | try { mStrDetectedOSTypeId = Global::OSTypeId(enmOsType); }
|
---|
359 | catch (std::bad_alloc) { hrc = E_OUTOFMEMORY; }
|
---|
360 | }
|
---|
361 | return hrc;
|
---|
362 | }
|
---|
363 |
|
---|
364 | /**
|
---|
365 | * Detect Windows ISOs.
|
---|
366 | *
|
---|
367 | * @returns COM status code.
|
---|
368 | * @retval S_OK if detected
|
---|
369 | * @retval S_FALSE if not fully detected.
|
---|
370 | *
|
---|
371 | * @param hVfsIso The ISO file system.
|
---|
372 | * @param pBuf Read buffer.
|
---|
373 | * @param penmOsType Where to return the OS type. This is initialized to
|
---|
374 | * VBOXOSTYPE_Unknown.
|
---|
375 | */
|
---|
376 | HRESULT Unattended::i_innerDetectIsoOSWindows(RTVFS hVfsIso, DETECTBUFFER *pBuf, VBOXOSTYPE *penmOsType)
|
---|
377 | {
|
---|
378 | /** @todo The 'sources/' path can differ. */
|
---|
379 |
|
---|
380 | // globalinstallorder.xml - vista beta2
|
---|
381 | // sources/idwbinfo.txt - ditto.
|
---|
382 | // sources/lang.ini - ditto.
|
---|
383 |
|
---|
384 | /*
|
---|
385 | * Try look for the 'sources/idwbinfo.txt' file containing windows build info.
|
---|
386 | * This file appeared with Vista beta 2 from what we can tell. Before windows 10
|
---|
387 | * it contains easily decodable branch names, after that things goes weird.
|
---|
388 | */
|
---|
389 | RTVFSFILE hVfsFile;
|
---|
390 | int vrc = RTVfsFileOpen(hVfsIso, "sources/idwbinfo.txt", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
|
---|
391 | if (RT_SUCCESS(vrc))
|
---|
392 | {
|
---|
393 | *penmOsType = VBOXOSTYPE_WinNT_x64;
|
---|
394 |
|
---|
395 | RTINIFILE hIniFile;
|
---|
396 | vrc = RTIniFileCreateFromVfsFile(&hIniFile, hVfsFile, RTINIFILE_F_READONLY);
|
---|
397 | RTVfsFileRelease(hVfsFile);
|
---|
398 | if (RT_SUCCESS(vrc))
|
---|
399 | {
|
---|
400 | vrc = RTIniFileQueryValue(hIniFile, "BUILDINFO", "BuildArch", pBuf->sz, sizeof(*pBuf), NULL);
|
---|
401 | if (RT_SUCCESS(vrc))
|
---|
402 | {
|
---|
403 | LogRelFlow(("Unattended: sources/idwbinfo.txt: BuildArch=%s\n", pBuf->sz));
|
---|
404 | if ( RTStrNICmp(pBuf->sz, RT_STR_TUPLE("amd64")) == 0
|
---|
405 | || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("x64")) == 0 /* just in case */ )
|
---|
406 | *penmOsType = VBOXOSTYPE_WinNT_x64;
|
---|
407 | else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("x86")) == 0)
|
---|
408 | *penmOsType = VBOXOSTYPE_WinNT;
|
---|
409 | else
|
---|
410 | {
|
---|
411 | LogRel(("Unattended: sources/idwbinfo.txt: Unknown: BuildArch=%s\n", pBuf->sz));
|
---|
412 | *penmOsType = VBOXOSTYPE_WinNT_x64;
|
---|
413 | }
|
---|
414 | }
|
---|
415 |
|
---|
416 | vrc = RTIniFileQueryValue(hIniFile, "BUILDINFO", "BuildBranch", pBuf->sz, sizeof(*pBuf), NULL);
|
---|
417 | if (RT_SUCCESS(vrc))
|
---|
418 | {
|
---|
419 | LogRelFlow(("Unattended: sources/idwbinfo.txt: BuildBranch=%s\n", pBuf->sz));
|
---|
420 | if ( RTStrNICmp(pBuf->sz, RT_STR_TUPLE("vista")) == 0
|
---|
421 | || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("winmain_beta")) == 0)
|
---|
422 | *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_WinVista);
|
---|
423 | else if (RTStrNICmp(pBuf->sz, RT_STR_TUPLE("win7")) == 0)
|
---|
424 | *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win7);
|
---|
425 | else if ( RTStrNICmp(pBuf->sz, RT_STR_TUPLE("winblue")) == 0
|
---|
426 | || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("winmain_blue")) == 0
|
---|
427 | || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("win81")) == 0 /* not seen, but just in case its out there */ )
|
---|
428 | *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win81);
|
---|
429 | else if ( RTStrNICmp(pBuf->sz, RT_STR_TUPLE("win8")) == 0
|
---|
430 | || RTStrNICmp(pBuf->sz, RT_STR_TUPLE("winmain_win8")) == 0 )
|
---|
431 | *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Win8);
|
---|
432 | else
|
---|
433 | LogRel(("Unattended: sources/idwbinfo.txt: Unknown: BuildBranch=%s\n", pBuf->sz));
|
---|
434 | }
|
---|
435 | RTIniFileRelease(hIniFile);
|
---|
436 | }
|
---|
437 | }
|
---|
438 |
|
---|
439 | /*
|
---|
440 | * Look for sources/lang.ini and try parse it to get the languages out of it.
|
---|
441 | */
|
---|
442 | /** @todo We could also check sources/??-* and boot/??-* if lang.ini is not
|
---|
443 | * found or unhelpful. */
|
---|
444 | vrc = RTVfsFileOpen(hVfsIso, "sources/lang.ini", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
|
---|
445 | if (RT_SUCCESS(vrc))
|
---|
446 | {
|
---|
447 | RTINIFILE hIniFile;
|
---|
448 | vrc = RTIniFileCreateFromVfsFile(&hIniFile, hVfsFile, RTINIFILE_F_READONLY);
|
---|
449 | RTVfsFileRelease(hVfsFile);
|
---|
450 | if (RT_SUCCESS(vrc))
|
---|
451 | {
|
---|
452 | mDetectedOSLanguages.clear();
|
---|
453 |
|
---|
454 | uint32_t idxPair;
|
---|
455 | for (idxPair = 0; idxPair < 256; idxPair++)
|
---|
456 | {
|
---|
457 | size_t cbHalf = sizeof(*pBuf) / 2;
|
---|
458 | char *pszKey = pBuf->sz;
|
---|
459 | char *pszValue = &pBuf->sz[cbHalf];
|
---|
460 | vrc = RTIniFileQueryPair(hIniFile, "Available UI Languages", idxPair,
|
---|
461 | pszKey, cbHalf, NULL, pszValue, cbHalf, NULL);
|
---|
462 | if (RT_SUCCESS(vrc))
|
---|
463 | {
|
---|
464 | try
|
---|
465 | {
|
---|
466 | mDetectedOSLanguages.append(pszKey);
|
---|
467 | }
|
---|
468 | catch (std::bad_alloc)
|
---|
469 | {
|
---|
470 | RTIniFileRelease(hIniFile);
|
---|
471 | return E_OUTOFMEMORY;
|
---|
472 | }
|
---|
473 | }
|
---|
474 | else if (vrc == VERR_NOT_FOUND)
|
---|
475 | break;
|
---|
476 | else
|
---|
477 | Assert(vrc == VERR_BUFFER_OVERFLOW);
|
---|
478 | }
|
---|
479 | if (idxPair == 0)
|
---|
480 | LogRel(("Unattended: Warning! Empty 'Available UI Languages' section in sources/lang.ini\n"));
|
---|
481 | RTIniFileRelease(hIniFile);
|
---|
482 | }
|
---|
483 | }
|
---|
484 |
|
---|
485 | /** @todo look at the install.wim file too, extracting the XML (easy) and
|
---|
486 | * figure out the available image numbers and such. The format is
|
---|
487 | * documented. */
|
---|
488 |
|
---|
489 | return S_FALSE;
|
---|
490 | }
|
---|
491 |
|
---|
492 | /**
|
---|
493 | * Detects linux architecture.
|
---|
494 | *
|
---|
495 | * @returns true if detected, false if not.
|
---|
496 | * @param pszArch The architecture string.
|
---|
497 | * @param penmOsType Where to return the arch and type on success.
|
---|
498 | * @param enmBaseOsType The base (x86) OS type to return.
|
---|
499 | */
|
---|
500 | static bool detectLinuxArch(const char *pszArch, VBOXOSTYPE *penmOsType, VBOXOSTYPE enmBaseOsType)
|
---|
501 | {
|
---|
502 | if ( RTStrNICmp(pszArch, RT_STR_TUPLE("amd64")) == 0
|
---|
503 | || RTStrNICmp(pszArch, RT_STR_TUPLE("x86_64")) == 0
|
---|
504 | || RTStrNICmp(pszArch, RT_STR_TUPLE("x86-64")) == 0 /* just in case */
|
---|
505 | || RTStrNICmp(pszArch, RT_STR_TUPLE("x64")) == 0 /* ditto */ )
|
---|
506 | {
|
---|
507 | *penmOsType = (VBOXOSTYPE)(enmBaseOsType | VBOXOSTYPE_x64);
|
---|
508 | return true;
|
---|
509 | }
|
---|
510 |
|
---|
511 | if ( RTStrNICmp(pszArch, RT_STR_TUPLE("x86")) == 0
|
---|
512 | || RTStrNICmp(pszArch, RT_STR_TUPLE("i386")) == 0
|
---|
513 | || RTStrNICmp(pszArch, RT_STR_TUPLE("i486")) == 0
|
---|
514 | || RTStrNICmp(pszArch, RT_STR_TUPLE("i586")) == 0
|
---|
515 | || RTStrNICmp(pszArch, RT_STR_TUPLE("i686")) == 0
|
---|
516 | || RTStrNICmp(pszArch, RT_STR_TUPLE("i786")) == 0
|
---|
517 | || RTStrNICmp(pszArch, RT_STR_TUPLE("i886")) == 0
|
---|
518 | || RTStrNICmp(pszArch, RT_STR_TUPLE("i986")) == 0)
|
---|
519 | {
|
---|
520 | *penmOsType = enmBaseOsType;
|
---|
521 | return true;
|
---|
522 | }
|
---|
523 |
|
---|
524 | /** @todo check for 'noarch' since source CDs have been seen to use that. */
|
---|
525 | return false;
|
---|
526 | }
|
---|
527 |
|
---|
528 | static bool detectLinuxDistroName(const char *pszOsAndVersion, VBOXOSTYPE *penmOsType, const char **ppszNext)
|
---|
529 | {
|
---|
530 | bool fRet = true;
|
---|
531 |
|
---|
532 | if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Red")) == 0
|
---|
533 | && !RT_C_IS_ALNUM(pszOsAndVersion[3]))
|
---|
534 |
|
---|
535 | {
|
---|
536 | pszOsAndVersion = RTStrStripL(pszOsAndVersion + 3);
|
---|
537 | if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Hat")) == 0
|
---|
538 | && !RT_C_IS_ALNUM(pszOsAndVersion[3]))
|
---|
539 | {
|
---|
540 | *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_RedHat);
|
---|
541 | pszOsAndVersion = RTStrStripL(pszOsAndVersion + 3);
|
---|
542 | }
|
---|
543 | else
|
---|
544 | fRet = false;
|
---|
545 | }
|
---|
546 | else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Oracle")) == 0
|
---|
547 | && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
|
---|
548 | {
|
---|
549 | *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_Oracle);
|
---|
550 | pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
|
---|
551 | }
|
---|
552 | else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("CentOS")) == 0
|
---|
553 | && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
|
---|
554 | {
|
---|
555 | *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_RedHat);
|
---|
556 | pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
|
---|
557 | }
|
---|
558 | else if ( RTStrNICmp(pszOsAndVersion, RT_STR_TUPLE("Fedora")) == 0
|
---|
559 | && !RT_C_IS_ALNUM(pszOsAndVersion[6]))
|
---|
560 | {
|
---|
561 | *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_FedoraCore);
|
---|
562 | pszOsAndVersion = RTStrStripL(pszOsAndVersion + 6);
|
---|
563 | }
|
---|
564 | else
|
---|
565 | fRet = false;
|
---|
566 |
|
---|
567 | /*
|
---|
568 | * Skip forward till we get a number.
|
---|
569 | */
|
---|
570 | if (ppszNext)
|
---|
571 | {
|
---|
572 | *ppszNext = pszOsAndVersion;
|
---|
573 | char ch;
|
---|
574 | for (const char *pszVersion = pszOsAndVersion; (ch = *pszVersion) != '\0'; pszVersion++)
|
---|
575 | if (RT_C_IS_DIGIT(ch))
|
---|
576 | {
|
---|
577 | *ppszNext = pszVersion;
|
---|
578 | break;
|
---|
579 | }
|
---|
580 | }
|
---|
581 | return fRet;
|
---|
582 | }
|
---|
583 |
|
---|
584 |
|
---|
585 | /**
|
---|
586 | * Detect Linux distro ISOs.
|
---|
587 | *
|
---|
588 | * @returns COM status code.
|
---|
589 | * @retval S_OK if detected
|
---|
590 | * @retval S_FALSE if not fully detected.
|
---|
591 | *
|
---|
592 | * @param hVfsIso The ISO file system.
|
---|
593 | * @param pBuf Read buffer.
|
---|
594 | * @param penmOsType Where to return the OS type. This is initialized to
|
---|
595 | * VBOXOSTYPE_Unknown.
|
---|
596 | */
|
---|
597 | HRESULT Unattended::i_innerDetectIsoOSLinux(RTVFS hVfsIso, DETECTBUFFER *pBuf, VBOXOSTYPE *penmOsType)
|
---|
598 | {
|
---|
599 | /*
|
---|
600 | * Redhat and derivatives may have a .treeinfo (ini-file style) with useful info
|
---|
601 | * or at least a barebone .discinfo file.
|
---|
602 | */
|
---|
603 |
|
---|
604 | /*
|
---|
605 | * Start with .treeinfo: https://release-engineering.github.io/productmd/treeinfo-1.0.html
|
---|
606 | */
|
---|
607 | RTVFSFILE hVfsFile;
|
---|
608 | int vrc = RTVfsFileOpen(hVfsIso, ".treeinfo", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
|
---|
609 | if (RT_SUCCESS(vrc))
|
---|
610 | {
|
---|
611 | RTINIFILE hIniFile;
|
---|
612 | vrc = RTIniFileCreateFromVfsFile(&hIniFile, hVfsFile, RTINIFILE_F_READONLY);
|
---|
613 | RTVfsFileRelease(hVfsFile);
|
---|
614 | if (RT_SUCCESS(vrc))
|
---|
615 | {
|
---|
616 | /* Try figure the architecture first (like with windows). */
|
---|
617 | vrc = RTIniFileQueryValue(hIniFile, "tree", "arch", pBuf->sz, sizeof(*pBuf), NULL);
|
---|
618 | if (RT_FAILURE(vrc) || !pBuf->sz[0])
|
---|
619 | vrc = RTIniFileQueryValue(hIniFile, "general", "arch", pBuf->sz, sizeof(*pBuf), NULL);
|
---|
620 | if (RT_SUCCESS(vrc))
|
---|
621 | {
|
---|
622 | LogRelFlow(("Unattended: .treeinfo: arch=%s\n", pBuf->sz));
|
---|
623 | if (!detectLinuxArch(pBuf->sz, penmOsType, VBOXOSTYPE_RedHat))
|
---|
624 | LogRel(("Unattended: .treeinfo: Unknown: arch='%s'\n", pBuf->sz));
|
---|
625 | }
|
---|
626 | else
|
---|
627 | LogRel(("Unattended: .treeinfo: No 'arch' property.\n"));
|
---|
628 |
|
---|
629 | /* Try figure the release name, it doesn't have to be redhat. */
|
---|
630 | vrc = RTIniFileQueryValue(hIniFile, "release", "name", pBuf->sz, sizeof(*pBuf), NULL);
|
---|
631 | if (RT_FAILURE(vrc) || !pBuf->sz[0])
|
---|
632 | vrc = RTIniFileQueryValue(hIniFile, "product", "name", pBuf->sz, sizeof(*pBuf), NULL);
|
---|
633 | if (RT_FAILURE(vrc) || !pBuf->sz[0])
|
---|
634 | vrc = RTIniFileQueryValue(hIniFile, "general", "family", pBuf->sz, sizeof(*pBuf), NULL);
|
---|
635 | if (RT_SUCCESS(vrc))
|
---|
636 | {
|
---|
637 | LogRelFlow(("Unattended: .treeinfo: name/family=%s\n", pBuf->sz));
|
---|
638 | if (!detectLinuxDistroName(pBuf->sz, penmOsType, NULL))
|
---|
639 | {
|
---|
640 | LogRel(("Unattended: .treeinfo: Unknown: name/family='%s', assuming Red Hat\n", pBuf->sz));
|
---|
641 | *penmOsType = (VBOXOSTYPE)((*penmOsType & VBOXOSTYPE_x64) | VBOXOSTYPE_RedHat);
|
---|
642 | }
|
---|
643 | }
|
---|
644 |
|
---|
645 | /* Try figure the version. */
|
---|
646 | vrc = RTIniFileQueryValue(hIniFile, "release", "version", pBuf->sz, sizeof(*pBuf), NULL);
|
---|
647 | if (RT_FAILURE(vrc) || !pBuf->sz[0])
|
---|
648 | vrc = RTIniFileQueryValue(hIniFile, "product", "version", pBuf->sz, sizeof(*pBuf), NULL);
|
---|
649 | if (RT_FAILURE(vrc) || !pBuf->sz[0])
|
---|
650 | vrc = RTIniFileQueryValue(hIniFile, "general", "version", pBuf->sz, sizeof(*pBuf), NULL);
|
---|
651 | if (RT_SUCCESS(vrc))
|
---|
652 | {
|
---|
653 | LogRelFlow(("Unattended: .treeinfo: version=%s\n", pBuf->sz));
|
---|
654 | try { mStrDetectedOSVersion = RTStrStrip(pBuf->sz); }
|
---|
655 | catch (std::bad_alloc) { return E_OUTOFMEMORY; }
|
---|
656 | }
|
---|
657 |
|
---|
658 | RTIniFileRelease(hIniFile);
|
---|
659 | }
|
---|
660 |
|
---|
661 | if (*penmOsType != VBOXOSTYPE_Unknown)
|
---|
662 | return S_FALSE;
|
---|
663 | }
|
---|
664 |
|
---|
665 | /*
|
---|
666 | * Try .discinfo next: https://release-engineering.github.io/productmd/discinfo-1.0.html
|
---|
667 | * We will probably need additional info here...
|
---|
668 | */
|
---|
669 | vrc = RTVfsFileOpen(hVfsIso, ".discinfo", RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
|
---|
670 | if (RT_SUCCESS(vrc))
|
---|
671 | {
|
---|
672 | RT_ZERO(*pBuf);
|
---|
673 | size_t cchIgn;
|
---|
674 | RTVfsFileRead(hVfsFile, pBuf->sz, sizeof(*pBuf) - 1, &cchIgn);
|
---|
675 | pBuf->sz[sizeof(*pBuf) - 1] = '\0';
|
---|
676 | RTVfsFileRelease(hVfsFile);
|
---|
677 |
|
---|
678 | /* Parse and strip the first 5 lines. */
|
---|
679 | const char *apszLines[5];
|
---|
680 | char *psz = pBuf->sz;
|
---|
681 | for (unsigned i = 0; i < RT_ELEMENTS(apszLines); i++)
|
---|
682 | {
|
---|
683 | apszLines[i] = psz;
|
---|
684 | if (*psz)
|
---|
685 | {
|
---|
686 | char *pszEol = (char *)strchr(psz, '\n');
|
---|
687 | if (!pszEol)
|
---|
688 | psz = strchr(psz, '\0');
|
---|
689 | else
|
---|
690 | {
|
---|
691 | *pszEol = '\0';
|
---|
692 | apszLines[i] = RTStrStrip(psz);
|
---|
693 | psz = pszEol + 1;
|
---|
694 | }
|
---|
695 | }
|
---|
696 | }
|
---|
697 |
|
---|
698 | /* Do we recognize the architecture? */
|
---|
699 | LogRelFlow(("Unattended: .discinfo: arch=%s\n", apszLines[2]));
|
---|
700 | if (!detectLinuxArch(apszLines[2], penmOsType, VBOXOSTYPE_RedHat))
|
---|
701 | LogRel(("Unattended: .discinfo: Unknown: arch='%s'\n", apszLines[2]));
|
---|
702 |
|
---|
703 | /* Do we recognize the release string? */
|
---|
704 | LogRelFlow(("Unattended: .discinfo: product+version=%s\n", apszLines[1]));
|
---|
705 | const char *pszVersion = NULL;
|
---|
706 | if (!detectLinuxDistroName(apszLines[1], penmOsType, &pszVersion))
|
---|
707 | LogRel(("Unattended: .discinfo: Unknown: release='%s'\n", apszLines[1]));
|
---|
708 |
|
---|
709 | if (*pszVersion)
|
---|
710 | {
|
---|
711 | LogRelFlow(("Unattended: .discinfo: version=%s\n", pszVersion));
|
---|
712 | try { mStrDetectedOSVersion = RTStrStripL(pszVersion); }
|
---|
713 | catch (std::bad_alloc) { return E_OUTOFMEMORY; }
|
---|
714 |
|
---|
715 | /* CentOS likes to call their release 'Final' without mentioning the actual version
|
---|
716 | number (e.g. CentOS-4.7-x86_64-binDVD.iso), so we need to go look elsewhere.
|
---|
717 | This is only important for centos 4.x and 3.x releases. */
|
---|
718 | if (RTStrNICmp(pszVersion, RT_STR_TUPLE("Final")) == 0)
|
---|
719 | {
|
---|
720 | static const char * const s_apszDirs[] = { "CentOS/RPMS/", "RedHat/RPMS", "Server", "Workstation" };
|
---|
721 | for (unsigned iDir = 0; iDir < RT_ELEMENTS(s_apszDirs); iDir++)
|
---|
722 | {
|
---|
723 | RTVFSDIR hVfsDir;
|
---|
724 | vrc = RTVfsDirOpen(hVfsIso, s_apszDirs[iDir], 0, &hVfsDir);
|
---|
725 | if (RT_FAILURE(vrc))
|
---|
726 | continue;
|
---|
727 | char szRpmDb[128];
|
---|
728 | char szReleaseRpm[128];
|
---|
729 | szRpmDb[0] = '\0';
|
---|
730 | szReleaseRpm[0] = '\0';
|
---|
731 | for (;;)
|
---|
732 | {
|
---|
733 | RTDIRENTRYEX DirEntry;
|
---|
734 | size_t cbDirEntry = sizeof(DirEntry);
|
---|
735 | vrc = RTVfsDirReadEx(hVfsDir, &DirEntry, &cbDirEntry, RTFSOBJATTRADD_NOTHING);
|
---|
736 | if (RT_FAILURE(vrc))
|
---|
737 | break;
|
---|
738 |
|
---|
739 | /* redhat-release-4WS-2.4.i386.rpm
|
---|
740 | centos-release-4-7.x86_64.rpm, centos-release-4-4.3.i386.rpm
|
---|
741 | centos-release-5-3.el5.centos.1.x86_64.rpm */
|
---|
742 | if ( (psz = strstr(DirEntry.szName, "-release-")) != NULL
|
---|
743 | || (psz = strstr(DirEntry.szName, "-RELEASE-")) != NULL)
|
---|
744 | {
|
---|
745 | psz += 9;
|
---|
746 | if (RT_C_IS_DIGIT(*psz))
|
---|
747 | RTStrCopy(szReleaseRpm, sizeof(szReleaseRpm), psz);
|
---|
748 | }
|
---|
749 | /* rpmdb-redhat-4WS-2.4.i386.rpm,
|
---|
750 | rpmdb-CentOS-4.5-0.20070506.i386.rpm,
|
---|
751 | rpmdb-redhat-3.9-0.20070703.i386.rpm. */
|
---|
752 | else if ( ( RTStrStartsWith(DirEntry.szName, "rpmdb-")
|
---|
753 | || RTStrStartsWith(DirEntry.szName, "RPMDB-"))
|
---|
754 | && RT_C_IS_DIGIT(DirEntry.szName[6]) )
|
---|
755 | RTStrCopy(szRpmDb, sizeof(szRpmDb), &DirEntry.szName[6]);
|
---|
756 | }
|
---|
757 | RTVfsDirRelease(hVfsDir);
|
---|
758 |
|
---|
759 | /* Did we find anything relvant? */
|
---|
760 | psz = szRpmDb;
|
---|
761 | if (!RT_C_IS_DIGIT(*psz))
|
---|
762 | psz = szReleaseRpm;
|
---|
763 | if (RT_C_IS_DIGIT(*psz))
|
---|
764 | {
|
---|
765 | /* Convert '-' to '.' and strip stuff which doesn't look like a version string. */
|
---|
766 | char *pszCur = psz + 1;
|
---|
767 | for (char ch = *pszCur; ch != '\0'; ch = *++pszCur)
|
---|
768 | if (ch == '-')
|
---|
769 | *pszCur = '.';
|
---|
770 | else if (ch != '.' && !RT_C_IS_DIGIT(ch))
|
---|
771 | {
|
---|
772 | *pszCur = '\0';
|
---|
773 | break;
|
---|
774 | }
|
---|
775 | while (&pszCur[-1] != psz && pszCur[-1] == '.')
|
---|
776 | *--pszCur = '\0';
|
---|
777 |
|
---|
778 | /* Set it and stop looking. */
|
---|
779 | try { mStrDetectedOSVersion = psz; }
|
---|
780 | catch (std::bad_alloc) { return E_OUTOFMEMORY; }
|
---|
781 | break;
|
---|
782 | }
|
---|
783 | }
|
---|
784 | }
|
---|
785 | }
|
---|
786 |
|
---|
787 | if (*penmOsType != VBOXOSTYPE_Unknown)
|
---|
788 | return S_FALSE;
|
---|
789 | }
|
---|
790 |
|
---|
791 | return S_FALSE;
|
---|
792 | }
|
---|
793 |
|
---|
794 |
|
---|
795 | HRESULT Unattended::prepare()
|
---|
796 | {
|
---|
797 | LogFlow(("Unattended::prepare: enter\n"));
|
---|
798 |
|
---|
799 | /*
|
---|
800 | * Must have a machine.
|
---|
801 | */
|
---|
802 | ComPtr<Machine> ptrMachine;
|
---|
803 | Guid MachineUuid;
|
---|
804 | {
|
---|
805 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
806 | ptrMachine = mMachine;
|
---|
807 | if (ptrMachine.isNull())
|
---|
808 | return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("No machine associated with this IUnatteded instance"));
|
---|
809 | MachineUuid = mMachineUuid;
|
---|
810 | }
|
---|
811 |
|
---|
812 | /*
|
---|
813 | * Before we write lock ourselves, we must get stuff from Machine and
|
---|
814 | * VirtualBox because their locks have higher priorities than ours.
|
---|
815 | */
|
---|
816 | Utf8Str strGuestOsTypeId;
|
---|
817 | Utf8Str strMachineName;
|
---|
818 | Utf8Str strDefaultAuxBasePath;
|
---|
819 | HRESULT hrc;
|
---|
820 | try
|
---|
821 | {
|
---|
822 | Bstr bstrTmp;
|
---|
823 | hrc = ptrMachine->COMGETTER(OSTypeId)(bstrTmp.asOutParam());
|
---|
824 | if (SUCCEEDED(hrc))
|
---|
825 | {
|
---|
826 | strGuestOsTypeId = bstrTmp;
|
---|
827 | hrc = ptrMachine->COMGETTER(Name)(bstrTmp.asOutParam());
|
---|
828 | if (SUCCEEDED(hrc))
|
---|
829 | strMachineName = bstrTmp;
|
---|
830 | }
|
---|
831 | int vrc = ptrMachine->i_calculateFullPath(Utf8StrFmt("Unattended-%RTuuid-", MachineUuid.raw()), strDefaultAuxBasePath);
|
---|
832 | if (RT_FAILURE(vrc))
|
---|
833 | return setErrorBoth(E_FAIL, vrc);
|
---|
834 | }
|
---|
835 | catch (std::bad_alloc)
|
---|
836 | {
|
---|
837 | return E_OUTOFMEMORY;
|
---|
838 | }
|
---|
839 | bool const fIs64Bit = i_isGuestOSArchX64(strGuestOsTypeId);
|
---|
840 |
|
---|
841 | BOOL fRtcUseUtc = FALSE;
|
---|
842 | hrc = ptrMachine->COMGETTER(RTCUseUTC)(&fRtcUseUtc);
|
---|
843 | if (FAILED(hrc))
|
---|
844 | return hrc;
|
---|
845 |
|
---|
846 | /*
|
---|
847 | * Write lock this object and set attributes we got from IMachine.
|
---|
848 | */
|
---|
849 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
850 |
|
---|
851 | mStrGuestOsTypeId = strGuestOsTypeId;
|
---|
852 | mfGuestOs64Bit = fIs64Bit;
|
---|
853 | mfRtcUseUtc = RT_BOOL(fRtcUseUtc);
|
---|
854 |
|
---|
855 | /*
|
---|
856 | * Do some state checks.
|
---|
857 | */
|
---|
858 | if (mpInstaller != NULL)
|
---|
859 | return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("The prepare method has been called (must call done to restart)"));
|
---|
860 | if ((Machine *)ptrMachine != (Machine *)mMachine)
|
---|
861 | return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("The 'machine' while we were using it - please don't do that"));
|
---|
862 |
|
---|
863 | /*
|
---|
864 | * Check if the specified ISOs and files exist.
|
---|
865 | */
|
---|
866 | if (!RTFileExists(mStrIsoPath.c_str()))
|
---|
867 | return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the installation ISO file '%s'"),
|
---|
868 | mStrIsoPath.c_str());
|
---|
869 | if (mfInstallGuestAdditions && !RTFileExists(mStrAdditionsIsoPath.c_str()))
|
---|
870 | return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the guest additions ISO file '%s'"),
|
---|
871 | mStrAdditionsIsoPath.c_str());
|
---|
872 | if (mfInstallTestExecService && !RTFileExists(mStrValidationKitIsoPath.c_str()))
|
---|
873 | return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the validation kit ISO file '%s'"),
|
---|
874 | mStrValidationKitIsoPath.c_str());
|
---|
875 | if (mStrScriptTemplatePath.isNotEmpty() && !RTFileExists(mStrScriptTemplatePath.c_str()))
|
---|
876 | return setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate unattended installation script template '%s'"),
|
---|
877 | mStrScriptTemplatePath.c_str());
|
---|
878 |
|
---|
879 | /*
|
---|
880 | * Do media detection if it haven't been done yet.
|
---|
881 | */
|
---|
882 | if (!mfDoneDetectIsoOS)
|
---|
883 | {
|
---|
884 | hrc = detectIsoOS();
|
---|
885 | if (FAILED(hrc) && hrc != E_NOTIMPL)
|
---|
886 | return hrc;
|
---|
887 | }
|
---|
888 |
|
---|
889 | /*
|
---|
890 | * Do some default property stuff and check other properties.
|
---|
891 | */
|
---|
892 | try
|
---|
893 | {
|
---|
894 | char szTmp[128];
|
---|
895 |
|
---|
896 | if (mStrLocale.isEmpty())
|
---|
897 | {
|
---|
898 | int vrc = RTLocaleQueryNormalizedBaseLocaleName(szTmp, sizeof(szTmp));
|
---|
899 | if ( RT_SUCCESS(vrc)
|
---|
900 | && RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(szTmp))
|
---|
901 | mStrLocale.assign(szTmp, 5);
|
---|
902 | else
|
---|
903 | mStrLocale = "en_US";
|
---|
904 | Assert(RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(mStrLocale));
|
---|
905 | }
|
---|
906 |
|
---|
907 | if (mStrLanguage.isEmpty())
|
---|
908 | {
|
---|
909 | if (mDetectedOSLanguages.size() > 0)
|
---|
910 | mStrLanguage = mDetectedOSLanguages[0];
|
---|
911 | else
|
---|
912 | mStrLanguage.assign(mStrLocale).findReplace('_', '-');
|
---|
913 | }
|
---|
914 |
|
---|
915 | if (mStrCountry.isEmpty())
|
---|
916 | {
|
---|
917 | int vrc = RTLocaleQueryUserCountryCode(szTmp);
|
---|
918 | if (RT_SUCCESS(vrc))
|
---|
919 | mStrCountry = szTmp;
|
---|
920 | else if ( mStrLocale.isNotEmpty()
|
---|
921 | && RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(mStrLocale))
|
---|
922 | mStrCountry.assign(mStrLocale, 3, 2);
|
---|
923 | else
|
---|
924 | mStrCountry = "US";
|
---|
925 | }
|
---|
926 |
|
---|
927 | if (mStrTimeZone.isEmpty())
|
---|
928 | {
|
---|
929 | int vrc = RTTimeZoneGetCurrent(szTmp, sizeof(szTmp));
|
---|
930 | if (RT_SUCCESS(vrc))
|
---|
931 | mStrTimeZone = szTmp;
|
---|
932 | else
|
---|
933 | mStrTimeZone = "Etc/UTC";
|
---|
934 | Assert(mStrTimeZone.isNotEmpty());
|
---|
935 | }
|
---|
936 | mpTimeZoneInfo = RTTimeZoneGetInfoByUnixName(mStrTimeZone.c_str());
|
---|
937 | if (!mpTimeZoneInfo)
|
---|
938 | mpTimeZoneInfo = RTTimeZoneGetInfoByWindowsName(mStrTimeZone.c_str());
|
---|
939 | Assert(mpTimeZoneInfo || mStrTimeZone != "Etc/UTC");
|
---|
940 | if (!mpTimeZoneInfo)
|
---|
941 | LogRel(("Unattended::prepare: warning: Unknown time zone '%s'\n", mStrTimeZone.c_str()));
|
---|
942 |
|
---|
943 | if (mStrHostname.isEmpty())
|
---|
944 | {
|
---|
945 | /* Mangle the VM name into a valid hostname. */
|
---|
946 | for (size_t i = 0; i < strMachineName.length(); i++)
|
---|
947 | {
|
---|
948 | char ch = strMachineName[i];
|
---|
949 | if ( (unsigned)ch < 127
|
---|
950 | && RT_C_IS_ALNUM(ch))
|
---|
951 | mStrHostname.append(ch);
|
---|
952 | else if (mStrHostname.isNotEmpty() && RT_C_IS_PUNCT(ch) && !mStrHostname.endsWith("-"))
|
---|
953 | mStrHostname.append('-');
|
---|
954 | }
|
---|
955 | if (mStrHostname.length() == 0)
|
---|
956 | mStrHostname.printf("%RTuuid-vm", MachineUuid.raw());
|
---|
957 | else if (mStrHostname.length() < 3)
|
---|
958 | mStrHostname.append("-vm");
|
---|
959 | mStrHostname.append(".myguest.virtualbox.org");
|
---|
960 | }
|
---|
961 |
|
---|
962 | if (mStrAuxiliaryBasePath.isEmpty())
|
---|
963 | {
|
---|
964 | mStrAuxiliaryBasePath = strDefaultAuxBasePath;
|
---|
965 | mfIsDefaultAuxiliaryBasePath = true;
|
---|
966 | }
|
---|
967 | }
|
---|
968 | catch (std::bad_alloc)
|
---|
969 | {
|
---|
970 | return E_OUTOFMEMORY;
|
---|
971 | }
|
---|
972 |
|
---|
973 | /*
|
---|
974 | * Get the guest OS type info and instantiate the appropriate installer.
|
---|
975 | */
|
---|
976 | uint32_t const idxOSType = Global::getOSTypeIndexFromId(mStrGuestOsTypeId.c_str());
|
---|
977 | meGuestOsType = idxOSType < Global::cOSTypes ? Global::sOSTypes[idxOSType].osType : VBOXOSTYPE_Unknown;
|
---|
978 |
|
---|
979 | mpInstaller = UnattendedInstaller::createInstance(meGuestOsType, mStrGuestOsTypeId, mStrDetectedOSVersion,
|
---|
980 | mStrDetectedOSFlavor, mStrDetectedOSHints, this);
|
---|
981 | if (mpInstaller != NULL)
|
---|
982 | {
|
---|
983 | hrc = mpInstaller->initInstaller();
|
---|
984 | if (SUCCEEDED(hrc))
|
---|
985 | {
|
---|
986 | /*
|
---|
987 | * Do the script preps (just reads them).
|
---|
988 | */
|
---|
989 | hrc = mpInstaller->prepareUnattendedScripts();
|
---|
990 | if (SUCCEEDED(hrc))
|
---|
991 | {
|
---|
992 | LogFlow(("Unattended::prepare: returns S_OK\n"));
|
---|
993 | return S_OK;
|
---|
994 | }
|
---|
995 | }
|
---|
996 |
|
---|
997 | /* Destroy the installer instance. */
|
---|
998 | delete mpInstaller;
|
---|
999 | mpInstaller = NULL;
|
---|
1000 | }
|
---|
1001 | else
|
---|
1002 | hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND,
|
---|
1003 | tr("Unattended installation is not supported for guest type '%s'"), mStrGuestOsTypeId.c_str());
|
---|
1004 | LogRelFlow(("Unattended::prepare: failed with %Rhrc\n", hrc));
|
---|
1005 | return hrc;
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | HRESULT Unattended::constructMedia()
|
---|
1009 | {
|
---|
1010 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1011 |
|
---|
1012 | LogFlow(("===========================================================\n"));
|
---|
1013 | LogFlow(("Call Unattended::constructMedia()\n"));
|
---|
1014 |
|
---|
1015 | if (mpInstaller == NULL)
|
---|
1016 | return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, "prepare() not yet called");
|
---|
1017 |
|
---|
1018 | return mpInstaller->prepareMedia();
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | HRESULT Unattended::reconfigureVM()
|
---|
1022 | {
|
---|
1023 | LogFlow(("===========================================================\n"));
|
---|
1024 | LogFlow(("Call Unattended::reconfigureVM()\n"));
|
---|
1025 |
|
---|
1026 | /*
|
---|
1027 | * Interrogate VirtualBox/IGuestOSType before we lock stuff and create ordering issues.
|
---|
1028 | */
|
---|
1029 | StorageBus_T enmRecommendedStorageBus = StorageBus_IDE;
|
---|
1030 | {
|
---|
1031 | Bstr bstrGuestOsTypeId;
|
---|
1032 | {
|
---|
1033 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1034 | bstrGuestOsTypeId = mStrGuestOsTypeId;
|
---|
1035 | }
|
---|
1036 | ComPtr<IGuestOSType> ptrGuestOSType;
|
---|
1037 | HRESULT hrc = mParent->GetGuestOSType(bstrGuestOsTypeId.raw(), ptrGuestOSType.asOutParam());
|
---|
1038 | if (SUCCEEDED(hrc))
|
---|
1039 | hrc = ptrGuestOSType->COMGETTER(RecommendedDVDStorageBus)(&enmRecommendedStorageBus);
|
---|
1040 | if (FAILED(hrc))
|
---|
1041 | return hrc;
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | /*
|
---|
1045 | * Take write lock (for lock order reasons, write lock our parent object too)
|
---|
1046 | * then make sure we're the only caller of this method.
|
---|
1047 | */
|
---|
1048 | AutoMultiWriteLock2 alock(mMachine, this COMMA_LOCKVAL_SRC_POS);
|
---|
1049 | HRESULT hrc;
|
---|
1050 | if (mhThreadReconfigureVM == NIL_RTNATIVETHREAD)
|
---|
1051 | {
|
---|
1052 | RTNATIVETHREAD const hNativeSelf = RTThreadNativeSelf();
|
---|
1053 | mhThreadReconfigureVM = hNativeSelf;
|
---|
1054 |
|
---|
1055 | /*
|
---|
1056 | * Create a new session, lock the machine and get the session machine object.
|
---|
1057 | * Do the locking without pinning down the write locks, just to be on the safe side.
|
---|
1058 | */
|
---|
1059 | ComPtr<ISession> ptrSession;
|
---|
1060 | try
|
---|
1061 | {
|
---|
1062 | hrc = ptrSession.createInprocObject(CLSID_Session);
|
---|
1063 | }
|
---|
1064 | catch (std::bad_alloc)
|
---|
1065 | {
|
---|
1066 | hrc = E_OUTOFMEMORY;
|
---|
1067 | }
|
---|
1068 | if (SUCCEEDED(hrc))
|
---|
1069 | {
|
---|
1070 | alock.release();
|
---|
1071 | hrc = mMachine->LockMachine(ptrSession, LockType_Shared);
|
---|
1072 | alock.acquire();
|
---|
1073 | if (SUCCEEDED(hrc))
|
---|
1074 | {
|
---|
1075 | ComPtr<IMachine> ptrSessionMachine;
|
---|
1076 | hrc = ptrSession->COMGETTER(Machine)(ptrSessionMachine.asOutParam());
|
---|
1077 | if (SUCCEEDED(hrc))
|
---|
1078 | {
|
---|
1079 | /*
|
---|
1080 | * Hand the session to the inner work and let it do it job.
|
---|
1081 | */
|
---|
1082 | try
|
---|
1083 | {
|
---|
1084 | hrc = i_innerReconfigureVM(alock, enmRecommendedStorageBus, ptrSessionMachine);
|
---|
1085 | }
|
---|
1086 | catch (...)
|
---|
1087 | {
|
---|
1088 | hrc = E_UNEXPECTED;
|
---|
1089 | }
|
---|
1090 | }
|
---|
1091 |
|
---|
1092 | /* Paranoia: release early in case we it a bump below. */
|
---|
1093 | Assert(mhThreadReconfigureVM == hNativeSelf);
|
---|
1094 | mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
|
---|
1095 |
|
---|
1096 | /*
|
---|
1097 | * While unlocking the machine we'll have to drop the locks again.
|
---|
1098 | */
|
---|
1099 | alock.release();
|
---|
1100 |
|
---|
1101 | ptrSessionMachine.setNull();
|
---|
1102 | HRESULT hrc2 = ptrSession->UnlockMachine();
|
---|
1103 | AssertLogRelMsg(SUCCEEDED(hrc2), ("UnlockMachine -> %Rhrc\n", hrc2));
|
---|
1104 |
|
---|
1105 | ptrSession.setNull();
|
---|
1106 |
|
---|
1107 | alock.acquire();
|
---|
1108 | }
|
---|
1109 | else
|
---|
1110 | mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
|
---|
1111 | }
|
---|
1112 | else
|
---|
1113 | mhThreadReconfigureVM = NIL_RTNATIVETHREAD;
|
---|
1114 | }
|
---|
1115 | else
|
---|
1116 | hrc = setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("reconfigureVM running on other thread"));
|
---|
1117 | return hrc;
|
---|
1118 | }
|
---|
1119 |
|
---|
1120 |
|
---|
1121 | HRESULT Unattended::i_innerReconfigureVM(AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus,
|
---|
1122 | ComPtr<IMachine> const &rPtrSessionMachine)
|
---|
1123 | {
|
---|
1124 | if (mpInstaller == NULL)
|
---|
1125 | return setErrorBoth(E_FAIL, VERR_WRONG_ORDER, "prepare() not yet called");
|
---|
1126 |
|
---|
1127 | // Fetch all available storage controllers
|
---|
1128 | com::SafeIfaceArray<IStorageController> arrayOfControllers;
|
---|
1129 | HRESULT hrc = rPtrSessionMachine->COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(arrayOfControllers));
|
---|
1130 | AssertComRCReturn(hrc, hrc);
|
---|
1131 |
|
---|
1132 | /*
|
---|
1133 | * Figure out where the images are to be mounted, adding controllers/ports as needed.
|
---|
1134 | */
|
---|
1135 | std::vector<UnattendedInstallationDisk> vecInstallationDisks;
|
---|
1136 | if (mpInstaller->isAuxiliaryFloppyNeeded())
|
---|
1137 | {
|
---|
1138 | hrc = i_reconfigureFloppy(arrayOfControllers, vecInstallationDisks, rPtrSessionMachine, rAutoLock);
|
---|
1139 | if (FAILED(hrc))
|
---|
1140 | return hrc;
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 | hrc = i_reconfigureIsos(arrayOfControllers, vecInstallationDisks, rPtrSessionMachine, rAutoLock, enmRecommendedStorageBus);
|
---|
1144 | if (FAILED(hrc))
|
---|
1145 | return hrc;
|
---|
1146 |
|
---|
1147 | /*
|
---|
1148 | * Mount the images.
|
---|
1149 | */
|
---|
1150 | for (size_t idxImage = 0; idxImage < vecInstallationDisks.size(); idxImage++)
|
---|
1151 | {
|
---|
1152 | UnattendedInstallationDisk const *pImage = &vecInstallationDisks.at(idxImage);
|
---|
1153 | Assert(pImage->strImagePath.isNotEmpty());
|
---|
1154 | hrc = i_attachImage(pImage, rPtrSessionMachine, rAutoLock);
|
---|
1155 | if (FAILED(hrc))
|
---|
1156 | return hrc;
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 | /*
|
---|
1160 | * Set the boot order.
|
---|
1161 | *
|
---|
1162 | * ASSUME that the HD isn't bootable when we start out, but it will be what
|
---|
1163 | * we boot from after the first stage of the installation is done. Setting
|
---|
1164 | * it first prevents endless reboot cylces.
|
---|
1165 | */
|
---|
1166 | /** @todo consider making 100% sure the disk isn't bootable (edit partition
|
---|
1167 | * table active bits and EFI stuff). */
|
---|
1168 | Assert( mpInstaller->getBootableDeviceType() == DeviceType_DVD
|
---|
1169 | || mpInstaller->getBootableDeviceType() == DeviceType_Floppy);
|
---|
1170 | hrc = rPtrSessionMachine->SetBootOrder(1, DeviceType_HardDisk);
|
---|
1171 | if (SUCCEEDED(hrc))
|
---|
1172 | hrc = rPtrSessionMachine->SetBootOrder(2, mpInstaller->getBootableDeviceType());
|
---|
1173 | if (SUCCEEDED(hrc))
|
---|
1174 | hrc = rPtrSessionMachine->SetBootOrder(3, mpInstaller->getBootableDeviceType() == DeviceType_DVD
|
---|
1175 | ? (DeviceType_T)DeviceType_Floppy : (DeviceType_T)DeviceType_DVD);
|
---|
1176 | if (FAILED(hrc))
|
---|
1177 | return hrc;
|
---|
1178 |
|
---|
1179 | /*
|
---|
1180 | * Essential step.
|
---|
1181 | *
|
---|
1182 | * HACK ALERT! We have to release the lock here or we'll get into trouble with
|
---|
1183 | * the VirtualBox lock (via i_saveHardware/NetworkAdaptger::i_hasDefaults/VirtualBox::i_findGuestOSType).
|
---|
1184 | */
|
---|
1185 | if (SUCCEEDED(hrc))
|
---|
1186 | {
|
---|
1187 | rAutoLock.release();
|
---|
1188 | hrc = rPtrSessionMachine->SaveSettings();
|
---|
1189 | rAutoLock.acquire();
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | return hrc;
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | /**
|
---|
1196 | * Makes sure we've got a floppy drive attached to a floppy controller, adding
|
---|
1197 | * the auxiliary floppy image to the installation disk vector.
|
---|
1198 | *
|
---|
1199 | * @returns COM status code.
|
---|
1200 | * @param rControllers The existing controllers.
|
---|
1201 | * @param rVecInstallatationDisks The list of image to mount.
|
---|
1202 | * @param rPtrSessionMachine The session machine smart pointer.
|
---|
1203 | * @param rAutoLock The lock.
|
---|
1204 | */
|
---|
1205 | HRESULT Unattended::i_reconfigureFloppy(com::SafeIfaceArray<IStorageController> &rControllers,
|
---|
1206 | std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
|
---|
1207 | ComPtr<IMachine> const &rPtrSessionMachine,
|
---|
1208 | AutoMultiWriteLock2 &rAutoLock)
|
---|
1209 | {
|
---|
1210 | Assert(mpInstaller->isAuxiliaryFloppyNeeded());
|
---|
1211 |
|
---|
1212 | /*
|
---|
1213 | * Look for a floppy controller with a primary drive (A:) we can "insert"
|
---|
1214 | * the auxiliary floppy image. Add a controller and/or a drive if necessary.
|
---|
1215 | */
|
---|
1216 | bool fFoundPort0Dev0 = false;
|
---|
1217 | Bstr bstrControllerName;
|
---|
1218 | Utf8Str strControllerName;
|
---|
1219 |
|
---|
1220 | for (size_t i = 0; i < rControllers.size(); ++i)
|
---|
1221 | {
|
---|
1222 | StorageBus_T enmStorageBus;
|
---|
1223 | HRESULT hrc = rControllers[i]->COMGETTER(Bus)(&enmStorageBus);
|
---|
1224 | AssertComRCReturn(hrc, hrc);
|
---|
1225 | if (enmStorageBus == StorageBus_Floppy)
|
---|
1226 | {
|
---|
1227 |
|
---|
1228 | /*
|
---|
1229 | * Found a floppy controller.
|
---|
1230 | */
|
---|
1231 | hrc = rControllers[i]->COMGETTER(Name)(bstrControllerName.asOutParam());
|
---|
1232 | AssertComRCReturn(hrc, hrc);
|
---|
1233 |
|
---|
1234 | /*
|
---|
1235 | * Check the attchments to see if we've got a device 0 attached on port 0.
|
---|
1236 | *
|
---|
1237 | * While we're at it we eject flppies from all floppy drives we encounter,
|
---|
1238 | * we don't want any confusion at boot or during installation.
|
---|
1239 | */
|
---|
1240 | com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
|
---|
1241 | hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(bstrControllerName.raw(),
|
---|
1242 | ComSafeArrayAsOutParam(arrayOfMediumAttachments));
|
---|
1243 | AssertComRCReturn(hrc, hrc);
|
---|
1244 | strControllerName = bstrControllerName;
|
---|
1245 | AssertLogRelReturn(strControllerName.isNotEmpty(), setErrorBoth(E_UNEXPECTED, VERR_INTERNAL_ERROR_2));
|
---|
1246 |
|
---|
1247 | for (size_t j = 0; j < arrayOfMediumAttachments.size(); j++)
|
---|
1248 | {
|
---|
1249 | LONG iPort = -1;
|
---|
1250 | hrc = arrayOfMediumAttachments[j]->COMGETTER(Port)(&iPort);
|
---|
1251 | AssertComRCReturn(hrc, hrc);
|
---|
1252 |
|
---|
1253 | LONG iDevice = -1;
|
---|
1254 | hrc = arrayOfMediumAttachments[j]->COMGETTER(Device)(&iDevice);
|
---|
1255 | AssertComRCReturn(hrc, hrc);
|
---|
1256 |
|
---|
1257 | DeviceType_T enmType;
|
---|
1258 | hrc = arrayOfMediumAttachments[j]->COMGETTER(Type)(&enmType);
|
---|
1259 | AssertComRCReturn(hrc, hrc);
|
---|
1260 |
|
---|
1261 | if (enmType == DeviceType_Floppy)
|
---|
1262 | {
|
---|
1263 | ComPtr<IMedium> ptrMedium;
|
---|
1264 | hrc = arrayOfMediumAttachments[j]->COMGETTER(Medium)(ptrMedium.asOutParam());
|
---|
1265 | AssertComRCReturn(hrc, hrc);
|
---|
1266 |
|
---|
1267 | if (ptrMedium.isNotNull())
|
---|
1268 | {
|
---|
1269 | ptrMedium.setNull();
|
---|
1270 | rAutoLock.release();
|
---|
1271 | hrc = rPtrSessionMachine->UnmountMedium(bstrControllerName.raw(), iPort, iDevice, TRUE /*fForce*/);
|
---|
1272 | rAutoLock.acquire();
|
---|
1273 | }
|
---|
1274 |
|
---|
1275 | if (iPort == 0 && iDevice == 0)
|
---|
1276 | fFoundPort0Dev0 = true;
|
---|
1277 | }
|
---|
1278 | else if (iPort == 0 && iDevice == 0)
|
---|
1279 | return setError(E_FAIL,
|
---|
1280 | tr("Found non-floppy device attached to port 0 device 0 on the floppy controller '%ls'"),
|
---|
1281 | bstrControllerName.raw());
|
---|
1282 | }
|
---|
1283 | }
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 | /*
|
---|
1287 | * Add a floppy controller if we need to.
|
---|
1288 | */
|
---|
1289 | if (strControllerName.isEmpty())
|
---|
1290 | {
|
---|
1291 | bstrControllerName = strControllerName = "Floppy";
|
---|
1292 | ComPtr<IStorageController> ptrControllerIgnored;
|
---|
1293 | HRESULT hrc = rPtrSessionMachine->AddStorageController(bstrControllerName.raw(), StorageBus_Floppy,
|
---|
1294 | ptrControllerIgnored.asOutParam());
|
---|
1295 | LogRelFunc(("Machine::addStorageController(Floppy) -> %Rhrc \n", hrc));
|
---|
1296 | if (FAILED(hrc))
|
---|
1297 | return hrc;
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 | /*
|
---|
1301 | * Adding a floppy drive (if needed) and mounting the auxiliary image is
|
---|
1302 | * done later together with the ISOs.
|
---|
1303 | */
|
---|
1304 | rVecInstallatationDisks.push_back(UnattendedInstallationDisk(StorageBus_Floppy, strControllerName,
|
---|
1305 | DeviceType_Floppy, AccessMode_ReadWrite,
|
---|
1306 | 0, 0,
|
---|
1307 | fFoundPort0Dev0 /*fMountOnly*/,
|
---|
1308 | mpInstaller->getAuxiliaryFloppyFilePath()));
|
---|
1309 | return S_OK;
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 | /**
|
---|
1313 | * Reconfigures DVD drives of the VM to mount all the ISOs we need.
|
---|
1314 | *
|
---|
1315 | * This will umount all DVD media.
|
---|
1316 | *
|
---|
1317 | * @returns COM status code.
|
---|
1318 | * @param rControllers The existing controllers.
|
---|
1319 | * @param rVecInstallatationDisks The list of image to mount.
|
---|
1320 | * @param rPtrSessionMachine The session machine smart pointer.
|
---|
1321 | * @param rAutoLock The lock.
|
---|
1322 | * @param enmRecommendedStorageBus The recommended storage bus type for adding
|
---|
1323 | * DVD drives on.
|
---|
1324 | */
|
---|
1325 | HRESULT Unattended::i_reconfigureIsos(com::SafeIfaceArray<IStorageController> &rControllers,
|
---|
1326 | std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
|
---|
1327 | ComPtr<IMachine> const &rPtrSessionMachine,
|
---|
1328 | AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus)
|
---|
1329 | {
|
---|
1330 | /*
|
---|
1331 | * Enumerate the attachements of every controller, looking for DVD drives,
|
---|
1332 | * ASSUMEING all drives are bootable.
|
---|
1333 | *
|
---|
1334 | * Eject the medium from all the drives (don't want any confusion) and look
|
---|
1335 | * for the recommended storage bus in case we need to add more drives.
|
---|
1336 | */
|
---|
1337 | HRESULT hrc;
|
---|
1338 | std::list<ControllerSlot> lstControllerDvdSlots;
|
---|
1339 | Utf8Str strRecommendedControllerName; /* non-empty if recommended bus found. */
|
---|
1340 | Utf8Str strControllerName;
|
---|
1341 | Bstr bstrControllerName;
|
---|
1342 | for (size_t i = 0; i < rControllers.size(); ++i)
|
---|
1343 | {
|
---|
1344 | hrc = rControllers[i]->COMGETTER(Name)(bstrControllerName.asOutParam());
|
---|
1345 | AssertComRCReturn(hrc, hrc);
|
---|
1346 | strControllerName = bstrControllerName;
|
---|
1347 |
|
---|
1348 | /* Look for recommended storage bus. */
|
---|
1349 | StorageBus_T enmStorageBus;
|
---|
1350 | hrc = rControllers[i]->COMGETTER(Bus)(&enmStorageBus);
|
---|
1351 | AssertComRCReturn(hrc, hrc);
|
---|
1352 | if (enmStorageBus == enmRecommendedStorageBus)
|
---|
1353 | {
|
---|
1354 | strRecommendedControllerName = bstrControllerName;
|
---|
1355 | AssertLogRelReturn(strControllerName.isNotEmpty(), setErrorBoth(E_UNEXPECTED, VERR_INTERNAL_ERROR_2));
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 | /* Scan the controller attachments. */
|
---|
1359 | com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
|
---|
1360 | hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(bstrControllerName.raw(),
|
---|
1361 | ComSafeArrayAsOutParam(arrayOfMediumAttachments));
|
---|
1362 | AssertComRCReturn(hrc, hrc);
|
---|
1363 |
|
---|
1364 | for (size_t j = 0; j < arrayOfMediumAttachments.size(); j++)
|
---|
1365 | {
|
---|
1366 | DeviceType_T enmType;
|
---|
1367 | hrc = arrayOfMediumAttachments[j]->COMGETTER(Type)(&enmType);
|
---|
1368 | AssertComRCReturn(hrc, hrc);
|
---|
1369 | if (enmType == DeviceType_DVD)
|
---|
1370 | {
|
---|
1371 | LONG iPort = -1;
|
---|
1372 | hrc = arrayOfMediumAttachments[j]->COMGETTER(Port)(&iPort);
|
---|
1373 | AssertComRCReturn(hrc, hrc);
|
---|
1374 |
|
---|
1375 | LONG iDevice = -1;
|
---|
1376 | hrc = arrayOfMediumAttachments[j]->COMGETTER(Device)(&iDevice);
|
---|
1377 | AssertComRCReturn(hrc, hrc);
|
---|
1378 |
|
---|
1379 | /* Remeber it. */
|
---|
1380 | lstControllerDvdSlots.push_back(ControllerSlot(enmStorageBus, strControllerName, iPort, iDevice, false /*fFree*/));
|
---|
1381 |
|
---|
1382 | /* Eject the medium, if any. */
|
---|
1383 | ComPtr<IMedium> ptrMedium;
|
---|
1384 | hrc = arrayOfMediumAttachments[j]->COMGETTER(Medium)(ptrMedium.asOutParam());
|
---|
1385 | AssertComRCReturn(hrc, hrc);
|
---|
1386 | if (ptrMedium.isNotNull())
|
---|
1387 | {
|
---|
1388 | ptrMedium.setNull();
|
---|
1389 |
|
---|
1390 | rAutoLock.release();
|
---|
1391 | hrc = rPtrSessionMachine->UnmountMedium(bstrControllerName.raw(), iPort, iDevice, TRUE /*fForce*/);
|
---|
1392 | rAutoLock.acquire();
|
---|
1393 | }
|
---|
1394 | }
|
---|
1395 | }
|
---|
1396 | }
|
---|
1397 |
|
---|
1398 | /*
|
---|
1399 | * How many drives do we need? Add more if necessary.
|
---|
1400 | */
|
---|
1401 | ULONG cDvdDrivesNeeded = 0;
|
---|
1402 | if (mpInstaller->isAuxiliaryIsoNeeded())
|
---|
1403 | cDvdDrivesNeeded++;
|
---|
1404 | if (mpInstaller->isOriginalIsoNeeded())
|
---|
1405 | cDvdDrivesNeeded++;
|
---|
1406 | #if 0 /* These are now in the AUX VISO. */
|
---|
1407 | if (mpInstaller->isAdditionsIsoNeeded())
|
---|
1408 | cDvdDrivesNeeded++;
|
---|
1409 | if (mpInstaller->isValidationKitIsoNeeded())
|
---|
1410 | cDvdDrivesNeeded++;
|
---|
1411 | #endif
|
---|
1412 | Assert(cDvdDrivesNeeded > 0);
|
---|
1413 | if (cDvdDrivesNeeded > lstControllerDvdSlots.size())
|
---|
1414 | {
|
---|
1415 | /* Do we need to add the recommended controller? */
|
---|
1416 | if (strRecommendedControllerName.isEmpty())
|
---|
1417 | {
|
---|
1418 | switch (enmRecommendedStorageBus)
|
---|
1419 | {
|
---|
1420 | case StorageBus_IDE: strRecommendedControllerName = "IDE"; break;
|
---|
1421 | case StorageBus_SATA: strRecommendedControllerName = "SATA"; break;
|
---|
1422 | case StorageBus_SCSI: strRecommendedControllerName = "SCSI"; break;
|
---|
1423 | case StorageBus_SAS: strRecommendedControllerName = "SAS"; break;
|
---|
1424 | case StorageBus_USB: strRecommendedControllerName = "USB"; break;
|
---|
1425 | case StorageBus_PCIe: strRecommendedControllerName = "PCIe"; break;
|
---|
1426 | default:
|
---|
1427 | return setError(E_FAIL, tr("Support for recommended storage bus %d not implemented"),
|
---|
1428 | (int)enmRecommendedStorageBus);
|
---|
1429 | }
|
---|
1430 | ComPtr<IStorageController> ptrControllerIgnored;
|
---|
1431 | hrc = rPtrSessionMachine->AddStorageController(Bstr(strRecommendedControllerName).raw(), enmRecommendedStorageBus,
|
---|
1432 | ptrControllerIgnored.asOutParam());
|
---|
1433 | LogRelFunc(("Machine::addStorageController(%s) -> %Rhrc \n", strRecommendedControllerName.c_str(), hrc));
|
---|
1434 | if (FAILED(hrc))
|
---|
1435 | return hrc;
|
---|
1436 | }
|
---|
1437 |
|
---|
1438 | /* Add free controller slots, maybe raising the port limit on the controller if we can. */
|
---|
1439 | hrc = i_findOrCreateNeededFreeSlots(strRecommendedControllerName, enmRecommendedStorageBus, rPtrSessionMachine,
|
---|
1440 | cDvdDrivesNeeded, lstControllerDvdSlots);
|
---|
1441 | if (FAILED(hrc))
|
---|
1442 | return hrc;
|
---|
1443 | if (cDvdDrivesNeeded > lstControllerDvdSlots.size())
|
---|
1444 | {
|
---|
1445 | /* We could in many cases create another controller here, but it's not worth the effort. */
|
---|
1446 | return setError(E_FAIL, tr("Not enough free slots on controller '%s' to add %u DVD drive(s)"),
|
---|
1447 | strRecommendedControllerName.c_str(), cDvdDrivesNeeded - lstControllerDvdSlots.size());
|
---|
1448 | }
|
---|
1449 | Assert(cDvdDrivesNeeded == lstControllerDvdSlots.size());
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 | /*
|
---|
1453 | * Sort the DVD slots in boot order.
|
---|
1454 | */
|
---|
1455 | lstControllerDvdSlots.sort();
|
---|
1456 |
|
---|
1457 | /*
|
---|
1458 | * Prepare ISO mounts.
|
---|
1459 | *
|
---|
1460 | * Boot order depends on bootFromAuxiliaryIso() and we must grab DVD slots
|
---|
1461 | * according to the boot order.
|
---|
1462 | */
|
---|
1463 | std::list<ControllerSlot>::const_iterator itDvdSlot = lstControllerDvdSlots.begin();
|
---|
1464 | if (mpInstaller->isAuxiliaryIsoNeeded() && mpInstaller->bootFromAuxiliaryIso())
|
---|
1465 | {
|
---|
1466 | rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath()));
|
---|
1467 | ++itDvdSlot;
|
---|
1468 | }
|
---|
1469 |
|
---|
1470 | if (mpInstaller->isOriginalIsoNeeded())
|
---|
1471 | {
|
---|
1472 | rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getIsoPath()));
|
---|
1473 | ++itDvdSlot;
|
---|
1474 | }
|
---|
1475 |
|
---|
1476 | if (mpInstaller->isAuxiliaryIsoNeeded() && !mpInstaller->bootFromAuxiliaryIso())
|
---|
1477 | {
|
---|
1478 | rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath()));
|
---|
1479 | ++itDvdSlot;
|
---|
1480 | }
|
---|
1481 |
|
---|
1482 | #if 0 /* These are now in the AUX VISO. */
|
---|
1483 | if (mpInstaller->isAdditionsIsoNeeded())
|
---|
1484 | {
|
---|
1485 | rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getAdditionsIsoPath()));
|
---|
1486 | ++itDvdSlot;
|
---|
1487 | }
|
---|
1488 |
|
---|
1489 | if (mpInstaller->isValidationKitIsoNeeded())
|
---|
1490 | {
|
---|
1491 | rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getValidationKitIsoPath()));
|
---|
1492 | ++itDvdSlot;
|
---|
1493 | }
|
---|
1494 | #endif
|
---|
1495 |
|
---|
1496 | return S_OK;
|
---|
1497 | }
|
---|
1498 |
|
---|
1499 | /**
|
---|
1500 | * Used to find more free slots for DVD drives during VM reconfiguration.
|
---|
1501 | *
|
---|
1502 | * This may modify the @a portCount property of the given controller.
|
---|
1503 | *
|
---|
1504 | * @returns COM status code.
|
---|
1505 | * @param rStrControllerName The name of the controller to find/create
|
---|
1506 | * free slots on.
|
---|
1507 | * @param enmStorageBus The storage bus type.
|
---|
1508 | * @param rPtrSessionMachine Reference to the session machine.
|
---|
1509 | * @param cSlotsNeeded Total slots needed (including those we've
|
---|
1510 | * already found).
|
---|
1511 | * @param rDvdSlots The slot collection for DVD drives to add
|
---|
1512 | * free slots to as we find/create them.
|
---|
1513 | */
|
---|
1514 | HRESULT Unattended::i_findOrCreateNeededFreeSlots(const Utf8Str &rStrControllerName, StorageBus_T enmStorageBus,
|
---|
1515 | ComPtr<IMachine> const &rPtrSessionMachine, uint32_t cSlotsNeeded,
|
---|
1516 | std::list<ControllerSlot> &rDvdSlots)
|
---|
1517 | {
|
---|
1518 | Assert(cSlotsNeeded > rDvdSlots.size());
|
---|
1519 |
|
---|
1520 | /*
|
---|
1521 | * Get controlleer stats.
|
---|
1522 | */
|
---|
1523 | ComPtr<IStorageController> pController;
|
---|
1524 | HRESULT hrc = rPtrSessionMachine->GetStorageControllerByName(Bstr(rStrControllerName).raw(), pController.asOutParam());
|
---|
1525 | AssertComRCReturn(hrc, hrc);
|
---|
1526 |
|
---|
1527 | ULONG cMaxDevicesPerPort = 1;
|
---|
1528 | hrc = pController->COMGETTER(MaxDevicesPerPortCount)(&cMaxDevicesPerPort);
|
---|
1529 | AssertComRCReturn(hrc, hrc);
|
---|
1530 | AssertLogRelReturn(cMaxDevicesPerPort > 0, E_UNEXPECTED);
|
---|
1531 |
|
---|
1532 | ULONG cPorts = 0;
|
---|
1533 | hrc = pController->COMGETTER(PortCount)(&cPorts);
|
---|
1534 | AssertComRCReturn(hrc, hrc);
|
---|
1535 |
|
---|
1536 | /*
|
---|
1537 | * Get the attachment list and turn into an internal list for lookup speed.
|
---|
1538 | */
|
---|
1539 | com::SafeIfaceArray<IMediumAttachment> arrayOfMediumAttachments;
|
---|
1540 | hrc = rPtrSessionMachine->GetMediumAttachmentsOfController(Bstr(rStrControllerName).raw(),
|
---|
1541 | ComSafeArrayAsOutParam(arrayOfMediumAttachments));
|
---|
1542 | AssertComRCReturn(hrc, hrc);
|
---|
1543 |
|
---|
1544 | std::vector<ControllerSlot> arrayOfUsedSlots;
|
---|
1545 | for (size_t i = 0; i < arrayOfMediumAttachments.size(); i++)
|
---|
1546 | {
|
---|
1547 | LONG iPort = -1;
|
---|
1548 | hrc = arrayOfMediumAttachments[i]->COMGETTER(Port)(&iPort);
|
---|
1549 | AssertComRCReturn(hrc, hrc);
|
---|
1550 |
|
---|
1551 | LONG iDevice = -1;
|
---|
1552 | hrc = arrayOfMediumAttachments[i]->COMGETTER(Device)(&iDevice);
|
---|
1553 | AssertComRCReturn(hrc, hrc);
|
---|
1554 |
|
---|
1555 | arrayOfUsedSlots.push_back(ControllerSlot(enmStorageBus, Utf8Str::Empty, iPort, iDevice, false /*fFree*/));
|
---|
1556 | }
|
---|
1557 |
|
---|
1558 | /*
|
---|
1559 | * Iterate thru all possible slots, adding those not found in arrayOfUsedSlots.
|
---|
1560 | */
|
---|
1561 | for (uint32_t iPort = 0; iPort < cPorts; iPort++)
|
---|
1562 | for (uint32_t iDevice = 0; iDevice < cMaxDevicesPerPort; iDevice++)
|
---|
1563 | {
|
---|
1564 | bool fFound = false;
|
---|
1565 | for (size_t i = 0; i < arrayOfUsedSlots.size(); i++)
|
---|
1566 | if ( arrayOfUsedSlots[i].uPort == iPort
|
---|
1567 | && arrayOfUsedSlots[i].uDevice == iDevice)
|
---|
1568 | {
|
---|
1569 | fFound = true;
|
---|
1570 | break;
|
---|
1571 | }
|
---|
1572 | if (!fFound)
|
---|
1573 | {
|
---|
1574 | rDvdSlots.push_back(ControllerSlot(enmStorageBus, rStrControllerName, iPort, iDevice, true /*fFree*/));
|
---|
1575 | if (rDvdSlots.size() >= cSlotsNeeded)
|
---|
1576 | return S_OK;
|
---|
1577 | }
|
---|
1578 | }
|
---|
1579 |
|
---|
1580 | /*
|
---|
1581 | * Okay we still need more ports. See if increasing the number of controller
|
---|
1582 | * ports would solve it.
|
---|
1583 | */
|
---|
1584 | ULONG cMaxPorts = 1;
|
---|
1585 | hrc = pController->COMGETTER(MaxPortCount)(&cMaxPorts);
|
---|
1586 | AssertComRCReturn(hrc, hrc);
|
---|
1587 | if (cMaxPorts <= cPorts)
|
---|
1588 | return S_OK;
|
---|
1589 | size_t cNewPortsNeeded = (cSlotsNeeded - rDvdSlots.size() + cMaxDevicesPerPort - 1) / cMaxDevicesPerPort;
|
---|
1590 | if (cPorts + cNewPortsNeeded > cMaxPorts)
|
---|
1591 | return S_OK;
|
---|
1592 |
|
---|
1593 | /*
|
---|
1594 | * Raise the port count and add the free slots we've just created.
|
---|
1595 | */
|
---|
1596 | hrc = pController->COMSETTER(PortCount)(cPorts + (ULONG)cNewPortsNeeded);
|
---|
1597 | AssertComRCReturn(hrc, hrc);
|
---|
1598 | for (uint32_t iPort = cPorts; iPort < cPorts + cNewPortsNeeded; iPort++)
|
---|
1599 | for (uint32_t iDevice = 0; iDevice < cMaxDevicesPerPort; iDevice++)
|
---|
1600 | {
|
---|
1601 | rDvdSlots.push_back(ControllerSlot(enmStorageBus, rStrControllerName, iPort, iDevice, true /*fFree*/));
|
---|
1602 | if (rDvdSlots.size() >= cSlotsNeeded)
|
---|
1603 | return S_OK;
|
---|
1604 | }
|
---|
1605 |
|
---|
1606 | /* We should not get here! */
|
---|
1607 | AssertLogRelFailedReturn(E_UNEXPECTED);
|
---|
1608 | }
|
---|
1609 |
|
---|
1610 | HRESULT Unattended::done()
|
---|
1611 | {
|
---|
1612 | LogFlow(("Unattended::done\n"));
|
---|
1613 | if (mpInstaller)
|
---|
1614 | {
|
---|
1615 | LogRelFlow(("Unattended::done: Deleting installer object (%p)\n", mpInstaller));
|
---|
1616 | delete mpInstaller;
|
---|
1617 | mpInstaller = NULL;
|
---|
1618 | }
|
---|
1619 | return S_OK;
|
---|
1620 | }
|
---|
1621 |
|
---|
1622 | HRESULT Unattended::getIsoPath(com::Utf8Str &isoPath)
|
---|
1623 | {
|
---|
1624 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1625 | isoPath = mStrIsoPath;
|
---|
1626 | return S_OK;
|
---|
1627 | }
|
---|
1628 |
|
---|
1629 | HRESULT Unattended::setIsoPath(const com::Utf8Str &isoPath)
|
---|
1630 | {
|
---|
1631 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1632 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1633 | mStrIsoPath = isoPath;
|
---|
1634 | mfDoneDetectIsoOS = false;
|
---|
1635 | return S_OK;
|
---|
1636 | }
|
---|
1637 |
|
---|
1638 | HRESULT Unattended::getUser(com::Utf8Str &user)
|
---|
1639 | {
|
---|
1640 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1641 | user = mStrUser;
|
---|
1642 | return S_OK;
|
---|
1643 | }
|
---|
1644 |
|
---|
1645 |
|
---|
1646 | HRESULT Unattended::setUser(const com::Utf8Str &user)
|
---|
1647 | {
|
---|
1648 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1649 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1650 | mStrUser = user;
|
---|
1651 | return S_OK;
|
---|
1652 | }
|
---|
1653 |
|
---|
1654 | HRESULT Unattended::getPassword(com::Utf8Str &password)
|
---|
1655 | {
|
---|
1656 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1657 | password = mStrPassword;
|
---|
1658 | return S_OK;
|
---|
1659 | }
|
---|
1660 |
|
---|
1661 | HRESULT Unattended::setPassword(const com::Utf8Str &password)
|
---|
1662 | {
|
---|
1663 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1664 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1665 | mStrPassword = password;
|
---|
1666 | return S_OK;
|
---|
1667 | }
|
---|
1668 |
|
---|
1669 | HRESULT Unattended::getFullUserName(com::Utf8Str &fullUserName)
|
---|
1670 | {
|
---|
1671 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1672 | fullUserName = mStrFullUserName;
|
---|
1673 | return S_OK;
|
---|
1674 | }
|
---|
1675 |
|
---|
1676 | HRESULT Unattended::setFullUserName(const com::Utf8Str &fullUserName)
|
---|
1677 | {
|
---|
1678 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1679 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1680 | mStrFullUserName = fullUserName;
|
---|
1681 | return S_OK;
|
---|
1682 | }
|
---|
1683 |
|
---|
1684 | HRESULT Unattended::getProductKey(com::Utf8Str &productKey)
|
---|
1685 | {
|
---|
1686 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1687 | productKey = mStrProductKey;
|
---|
1688 | return S_OK;
|
---|
1689 | }
|
---|
1690 |
|
---|
1691 | HRESULT Unattended::setProductKey(const com::Utf8Str &productKey)
|
---|
1692 | {
|
---|
1693 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1694 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1695 | mStrProductKey = productKey;
|
---|
1696 | return S_OK;
|
---|
1697 | }
|
---|
1698 |
|
---|
1699 | HRESULT Unattended::getAdditionsIsoPath(com::Utf8Str &additionsIsoPath)
|
---|
1700 | {
|
---|
1701 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1702 | additionsIsoPath = mStrAdditionsIsoPath;
|
---|
1703 | return S_OK;
|
---|
1704 | }
|
---|
1705 |
|
---|
1706 | HRESULT Unattended::setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath)
|
---|
1707 | {
|
---|
1708 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1709 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1710 | mStrAdditionsIsoPath = additionsIsoPath;
|
---|
1711 | return S_OK;
|
---|
1712 | }
|
---|
1713 |
|
---|
1714 | HRESULT Unattended::getInstallGuestAdditions(BOOL *installGuestAdditions)
|
---|
1715 | {
|
---|
1716 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1717 | *installGuestAdditions = mfInstallGuestAdditions;
|
---|
1718 | return S_OK;
|
---|
1719 | }
|
---|
1720 |
|
---|
1721 | HRESULT Unattended::setInstallGuestAdditions(BOOL installGuestAdditions)
|
---|
1722 | {
|
---|
1723 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1724 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1725 | mfInstallGuestAdditions = installGuestAdditions != FALSE;
|
---|
1726 | return S_OK;
|
---|
1727 | }
|
---|
1728 |
|
---|
1729 | HRESULT Unattended::getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath)
|
---|
1730 | {
|
---|
1731 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1732 | aValidationKitIsoPath = mStrValidationKitIsoPath;
|
---|
1733 | return S_OK;
|
---|
1734 | }
|
---|
1735 |
|
---|
1736 | HRESULT Unattended::setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath)
|
---|
1737 | {
|
---|
1738 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1739 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1740 | mStrValidationKitIsoPath = aValidationKitIsoPath;
|
---|
1741 | return S_OK;
|
---|
1742 | }
|
---|
1743 |
|
---|
1744 | HRESULT Unattended::getInstallTestExecService(BOOL *aInstallTestExecService)
|
---|
1745 | {
|
---|
1746 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1747 | *aInstallTestExecService = mfInstallTestExecService;
|
---|
1748 | return S_OK;
|
---|
1749 | }
|
---|
1750 |
|
---|
1751 | HRESULT Unattended::setInstallTestExecService(BOOL aInstallTestExecService)
|
---|
1752 | {
|
---|
1753 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1754 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1755 | mfInstallTestExecService = aInstallTestExecService != FALSE;
|
---|
1756 | return S_OK;
|
---|
1757 | }
|
---|
1758 |
|
---|
1759 | HRESULT Unattended::getTimeZone(com::Utf8Str &aTimeZone)
|
---|
1760 | {
|
---|
1761 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1762 | aTimeZone = mStrTimeZone;
|
---|
1763 | return S_OK;
|
---|
1764 | }
|
---|
1765 |
|
---|
1766 | HRESULT Unattended::setTimeZone(const com::Utf8Str &aTimezone)
|
---|
1767 | {
|
---|
1768 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1769 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1770 | mStrTimeZone = aTimezone;
|
---|
1771 | return S_OK;
|
---|
1772 | }
|
---|
1773 |
|
---|
1774 | HRESULT Unattended::getLocale(com::Utf8Str &aLocale)
|
---|
1775 | {
|
---|
1776 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1777 | aLocale = mStrLocale;
|
---|
1778 | return S_OK;
|
---|
1779 | }
|
---|
1780 |
|
---|
1781 | HRESULT Unattended::setLocale(const com::Utf8Str &aLocale)
|
---|
1782 | {
|
---|
1783 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1784 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1785 | if ( aLocale.isEmpty() /* use default */
|
---|
1786 | || ( aLocale.length() == 5
|
---|
1787 | && RT_C_IS_LOWER(aLocale[0])
|
---|
1788 | && RT_C_IS_LOWER(aLocale[1])
|
---|
1789 | && aLocale[2] == '_'
|
---|
1790 | && RT_C_IS_UPPER(aLocale[3])
|
---|
1791 | && RT_C_IS_UPPER(aLocale[4])) )
|
---|
1792 | {
|
---|
1793 | mStrLocale = aLocale;
|
---|
1794 | return S_OK;
|
---|
1795 | }
|
---|
1796 | return setError(E_INVALIDARG, tr("Expected two lower cased letters, an underscore, and two upper cased letters"));
|
---|
1797 | }
|
---|
1798 |
|
---|
1799 | HRESULT Unattended::getLanguage(com::Utf8Str &aLanguage)
|
---|
1800 | {
|
---|
1801 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1802 | aLanguage = mStrLanguage;
|
---|
1803 | return S_OK;
|
---|
1804 | }
|
---|
1805 |
|
---|
1806 | HRESULT Unattended::setLanguage(const com::Utf8Str &aLanguage)
|
---|
1807 | {
|
---|
1808 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1809 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1810 | mStrLanguage = aLanguage;
|
---|
1811 | return S_OK;
|
---|
1812 | }
|
---|
1813 |
|
---|
1814 | HRESULT Unattended::getCountry(com::Utf8Str &aCountry)
|
---|
1815 | {
|
---|
1816 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1817 | aCountry = mStrCountry;
|
---|
1818 | return S_OK;
|
---|
1819 | }
|
---|
1820 |
|
---|
1821 | HRESULT Unattended::setCountry(const com::Utf8Str &aCountry)
|
---|
1822 | {
|
---|
1823 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1824 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1825 | if ( aCountry.isEmpty()
|
---|
1826 | || ( aCountry.length() == 2
|
---|
1827 | && RT_C_IS_UPPER(aCountry[0])
|
---|
1828 | && RT_C_IS_UPPER(aCountry[1])) )
|
---|
1829 | {
|
---|
1830 | mStrCountry = aCountry;
|
---|
1831 | return S_OK;
|
---|
1832 | }
|
---|
1833 | return setError(E_INVALIDARG, tr("Expected two upper cased letters"));
|
---|
1834 | }
|
---|
1835 |
|
---|
1836 | HRESULT Unattended::getProxy(com::Utf8Str &aProxy)
|
---|
1837 | {
|
---|
1838 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1839 | aProxy = ""; /// @todo turn schema map into string or something.
|
---|
1840 | return S_OK;
|
---|
1841 | }
|
---|
1842 |
|
---|
1843 | HRESULT Unattended::setProxy(const com::Utf8Str &aProxy)
|
---|
1844 | {
|
---|
1845 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1846 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1847 | if (aProxy.isEmpty())
|
---|
1848 | {
|
---|
1849 | /* set default proxy */
|
---|
1850 | }
|
---|
1851 | else if (aProxy.equalsIgnoreCase("none"))
|
---|
1852 | {
|
---|
1853 | /* clear proxy config */
|
---|
1854 | }
|
---|
1855 | else
|
---|
1856 | {
|
---|
1857 | /* Parse and set proxy config into a schema map or something along those lines. */
|
---|
1858 | return E_NOTIMPL;
|
---|
1859 | }
|
---|
1860 | return S_OK;
|
---|
1861 | }
|
---|
1862 |
|
---|
1863 | HRESULT Unattended::getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments)
|
---|
1864 | {
|
---|
1865 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1866 | aPackageSelectionAdjustments = RTCString::join(mPackageSelectionAdjustments, ";");
|
---|
1867 | return S_OK;
|
---|
1868 | }
|
---|
1869 |
|
---|
1870 | HRESULT Unattended::setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments)
|
---|
1871 | {
|
---|
1872 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1873 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1874 | if (aPackageSelectionAdjustments.isEmpty())
|
---|
1875 | mPackageSelectionAdjustments.clear();
|
---|
1876 | else
|
---|
1877 | {
|
---|
1878 | RTCList<RTCString, RTCString *> arrayStrSplit = aPackageSelectionAdjustments.split(";");
|
---|
1879 | for (size_t i = 0; i < arrayStrSplit.size(); i++)
|
---|
1880 | {
|
---|
1881 | if (arrayStrSplit[i].equals("minimal"))
|
---|
1882 | { /* okay */ }
|
---|
1883 | else
|
---|
1884 | return setError(E_INVALIDARG, tr("Unknown keyword: %s"), arrayStrSplit[i].c_str());
|
---|
1885 | }
|
---|
1886 | mPackageSelectionAdjustments = arrayStrSplit;
|
---|
1887 | }
|
---|
1888 | return S_OK;
|
---|
1889 | }
|
---|
1890 |
|
---|
1891 | HRESULT Unattended::getHostname(com::Utf8Str &aHostname)
|
---|
1892 | {
|
---|
1893 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1894 | aHostname = mStrHostname;
|
---|
1895 | return S_OK;
|
---|
1896 | }
|
---|
1897 |
|
---|
1898 | HRESULT Unattended::setHostname(const com::Utf8Str &aHostname)
|
---|
1899 | {
|
---|
1900 | /*
|
---|
1901 | * Validate input.
|
---|
1902 | */
|
---|
1903 | if (aHostname.length() > (aHostname.endsWith(".") ? 254U : 253U))
|
---|
1904 | return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
|
---|
1905 | tr("Hostname '%s' is %zu bytes long, max is 253 (excluing trailing dot)"),
|
---|
1906 | aHostname.c_str(), aHostname.length());
|
---|
1907 | size_t cLabels = 0;
|
---|
1908 | const char *pszSrc = aHostname.c_str();
|
---|
1909 | for (;;)
|
---|
1910 | {
|
---|
1911 | size_t cchLabel = 1;
|
---|
1912 | char ch = *pszSrc++;
|
---|
1913 | if (RT_C_IS_ALNUM(ch))
|
---|
1914 | {
|
---|
1915 | cLabels++;
|
---|
1916 | while ((ch = *pszSrc++) != '.' && ch != '\0')
|
---|
1917 | {
|
---|
1918 | if (RT_C_IS_ALNUM(ch) || ch == '-')
|
---|
1919 | {
|
---|
1920 | if (cchLabel < 63)
|
---|
1921 | cchLabel++;
|
---|
1922 | else
|
---|
1923 | return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
|
---|
1924 | tr("Invalid hostname '%s' - label %u is too long, max is 63."),
|
---|
1925 | aHostname.c_str(), cLabels);
|
---|
1926 | }
|
---|
1927 | else
|
---|
1928 | return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
|
---|
1929 | tr("Invalid hostname '%s' - illegal char '%c' at position %zu"),
|
---|
1930 | aHostname.c_str(), ch, pszSrc - aHostname.c_str() - 1);
|
---|
1931 | }
|
---|
1932 | if (cLabels == 1 && cchLabel < 2)
|
---|
1933 | return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
|
---|
1934 | tr("Invalid hostname '%s' - the name part must be at least two characters long"),
|
---|
1935 | aHostname.c_str());
|
---|
1936 | if (ch == '\0')
|
---|
1937 | break;
|
---|
1938 | }
|
---|
1939 | else if (ch != '\0')
|
---|
1940 | return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
|
---|
1941 | tr("Invalid hostname '%s' - illegal lead char '%c' at position %zu"),
|
---|
1942 | aHostname.c_str(), ch, pszSrc - aHostname.c_str() - 1);
|
---|
1943 | else
|
---|
1944 | return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
|
---|
1945 | tr("Invalid hostname '%s' - trailing dot not permitted"), aHostname.c_str());
|
---|
1946 | }
|
---|
1947 | if (cLabels < 2)
|
---|
1948 | return setErrorBoth(E_INVALIDARG, VERR_INVALID_NAME,
|
---|
1949 | tr("Incomplete hostname '%s' - must include both a name and a domain"), aHostname.c_str());
|
---|
1950 |
|
---|
1951 | /*
|
---|
1952 | * Make the change.
|
---|
1953 | */
|
---|
1954 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1955 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1956 | mStrHostname = aHostname;
|
---|
1957 | return S_OK;
|
---|
1958 | }
|
---|
1959 |
|
---|
1960 | HRESULT Unattended::getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath)
|
---|
1961 | {
|
---|
1962 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1963 | aAuxiliaryBasePath = mStrAuxiliaryBasePath;
|
---|
1964 | return S_OK;
|
---|
1965 | }
|
---|
1966 |
|
---|
1967 | HRESULT Unattended::setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath)
|
---|
1968 | {
|
---|
1969 | if (aAuxiliaryBasePath.isEmpty())
|
---|
1970 | return setError(E_INVALIDARG, "Empty base path is not allowed");
|
---|
1971 | if (!RTPathStartsWithRoot(aAuxiliaryBasePath.c_str()))
|
---|
1972 | return setError(E_INVALIDARG, "Base path must be absolute");
|
---|
1973 |
|
---|
1974 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1975 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1976 | mStrAuxiliaryBasePath = aAuxiliaryBasePath;
|
---|
1977 | mfIsDefaultAuxiliaryBasePath = mStrAuxiliaryBasePath.isEmpty();
|
---|
1978 | return S_OK;
|
---|
1979 | }
|
---|
1980 |
|
---|
1981 | HRESULT Unattended::getImageIndex(ULONG *index)
|
---|
1982 | {
|
---|
1983 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1984 | *index = midxImage;
|
---|
1985 | return S_OK;
|
---|
1986 | }
|
---|
1987 |
|
---|
1988 | HRESULT Unattended::setImageIndex(ULONG index)
|
---|
1989 | {
|
---|
1990 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1991 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
1992 | midxImage = index;
|
---|
1993 | return S_OK;
|
---|
1994 | }
|
---|
1995 |
|
---|
1996 | HRESULT Unattended::getMachine(ComPtr<IMachine> &aMachine)
|
---|
1997 | {
|
---|
1998 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1999 | return mMachine.queryInterfaceTo(aMachine.asOutParam());
|
---|
2000 | }
|
---|
2001 |
|
---|
2002 | HRESULT Unattended::setMachine(const ComPtr<IMachine> &aMachine)
|
---|
2003 | {
|
---|
2004 | /*
|
---|
2005 | * Lookup the VM so we can safely get the Machine instance.
|
---|
2006 | * (Don't want to test how reliable XPCOM and COM are with finding
|
---|
2007 | * the local object instance when a client passes a stub back.)
|
---|
2008 | */
|
---|
2009 | Bstr bstrUuidMachine;
|
---|
2010 | HRESULT hrc = aMachine->COMGETTER(Id)(bstrUuidMachine.asOutParam());
|
---|
2011 | if (SUCCEEDED(hrc))
|
---|
2012 | {
|
---|
2013 | Guid UuidMachine(bstrUuidMachine);
|
---|
2014 | ComObjPtr<Machine> ptrMachine;
|
---|
2015 | hrc = mParent->i_findMachine(UuidMachine, false /*fPermitInaccessible*/, true /*aSetError*/, &ptrMachine);
|
---|
2016 | if (SUCCEEDED(hrc))
|
---|
2017 | {
|
---|
2018 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2019 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER,
|
---|
2020 | tr("Cannot change after prepare() has been called")));
|
---|
2021 | mMachine = ptrMachine;
|
---|
2022 | mMachineUuid = UuidMachine;
|
---|
2023 | if (mfIsDefaultAuxiliaryBasePath)
|
---|
2024 | mStrAuxiliaryBasePath.setNull();
|
---|
2025 | hrc = S_OK;
|
---|
2026 | }
|
---|
2027 | }
|
---|
2028 | return hrc;
|
---|
2029 | }
|
---|
2030 |
|
---|
2031 | HRESULT Unattended::getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath)
|
---|
2032 | {
|
---|
2033 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2034 | if ( mStrScriptTemplatePath.isNotEmpty()
|
---|
2035 | || mpInstaller == NULL)
|
---|
2036 | aScriptTemplatePath = mStrScriptTemplatePath;
|
---|
2037 | else
|
---|
2038 | aScriptTemplatePath = mpInstaller->getTemplateFilePath();
|
---|
2039 | return S_OK;
|
---|
2040 | }
|
---|
2041 |
|
---|
2042 | HRESULT Unattended::setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath)
|
---|
2043 | {
|
---|
2044 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2045 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
2046 | mStrScriptTemplatePath = aScriptTemplatePath;
|
---|
2047 | return S_OK;
|
---|
2048 | }
|
---|
2049 |
|
---|
2050 | HRESULT Unattended::getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath)
|
---|
2051 | {
|
---|
2052 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2053 | if ( mStrPostInstallScriptTemplatePath.isNotEmpty()
|
---|
2054 | || mpInstaller == NULL)
|
---|
2055 | aPostInstallScriptTemplatePath = mStrPostInstallScriptTemplatePath;
|
---|
2056 | else
|
---|
2057 | aPostInstallScriptTemplatePath = mpInstaller->getPostTemplateFilePath();
|
---|
2058 | return S_OK;
|
---|
2059 | }
|
---|
2060 |
|
---|
2061 | HRESULT Unattended::setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath)
|
---|
2062 | {
|
---|
2063 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2064 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
2065 | mStrPostInstallScriptTemplatePath = aPostInstallScriptTemplatePath;
|
---|
2066 | return S_OK;
|
---|
2067 | }
|
---|
2068 |
|
---|
2069 | HRESULT Unattended::getPostInstallCommand(com::Utf8Str &aPostInstallCommand)
|
---|
2070 | {
|
---|
2071 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2072 | aPostInstallCommand = mStrPostInstallCommand;
|
---|
2073 | return S_OK;
|
---|
2074 | }
|
---|
2075 |
|
---|
2076 | HRESULT Unattended::setPostInstallCommand(const com::Utf8Str &aPostInstallCommand)
|
---|
2077 | {
|
---|
2078 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2079 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
2080 | mStrPostInstallCommand = aPostInstallCommand;
|
---|
2081 | return S_OK;
|
---|
2082 | }
|
---|
2083 |
|
---|
2084 | HRESULT Unattended::getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters)
|
---|
2085 | {
|
---|
2086 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2087 | if ( mStrExtraInstallKernelParameters.isNotEmpty()
|
---|
2088 | || mpInstaller == NULL)
|
---|
2089 | aExtraInstallKernelParameters = mStrExtraInstallKernelParameters;
|
---|
2090 | else
|
---|
2091 | aExtraInstallKernelParameters = mpInstaller->getDefaultExtraInstallKernelParameters();
|
---|
2092 | return S_OK;
|
---|
2093 | }
|
---|
2094 |
|
---|
2095 | HRESULT Unattended::setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters)
|
---|
2096 | {
|
---|
2097 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2098 | AssertReturn(mpInstaller == NULL, setErrorBoth(E_FAIL, VERR_WRONG_ORDER, tr("Cannot change after prepare() has been called")));
|
---|
2099 | mStrExtraInstallKernelParameters = aExtraInstallKernelParameters;
|
---|
2100 | return S_OK;
|
---|
2101 | }
|
---|
2102 |
|
---|
2103 | HRESULT Unattended::getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId)
|
---|
2104 | {
|
---|
2105 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2106 | aDetectedOSTypeId = mStrDetectedOSTypeId;
|
---|
2107 | return S_OK;
|
---|
2108 | }
|
---|
2109 |
|
---|
2110 | HRESULT Unattended::getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion)
|
---|
2111 | {
|
---|
2112 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2113 | aDetectedOSVersion = mStrDetectedOSVersion;
|
---|
2114 | return S_OK;
|
---|
2115 | }
|
---|
2116 |
|
---|
2117 | HRESULT Unattended::getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor)
|
---|
2118 | {
|
---|
2119 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2120 | aDetectedOSFlavor = mStrDetectedOSFlavor;
|
---|
2121 | return S_OK;
|
---|
2122 | }
|
---|
2123 |
|
---|
2124 | HRESULT Unattended::getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages)
|
---|
2125 | {
|
---|
2126 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2127 | aDetectedOSLanguages = RTCString::join(mDetectedOSLanguages, " ");
|
---|
2128 | return S_OK;
|
---|
2129 | }
|
---|
2130 |
|
---|
2131 | HRESULT Unattended::getDetectedOSHints(com::Utf8Str &aDetectedOSHints)
|
---|
2132 | {
|
---|
2133 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2134 | aDetectedOSHints = mStrDetectedOSHints;
|
---|
2135 | return S_OK;
|
---|
2136 | }
|
---|
2137 |
|
---|
2138 | /*
|
---|
2139 | * Getters that the installer and script classes can use.
|
---|
2140 | */
|
---|
2141 | Utf8Str const &Unattended::i_getIsoPath() const
|
---|
2142 | {
|
---|
2143 | Assert(isReadLockedOnCurrentThread());
|
---|
2144 | return mStrIsoPath;
|
---|
2145 | }
|
---|
2146 |
|
---|
2147 | Utf8Str const &Unattended::i_getUser() const
|
---|
2148 | {
|
---|
2149 | Assert(isReadLockedOnCurrentThread());
|
---|
2150 | return mStrUser;
|
---|
2151 | }
|
---|
2152 |
|
---|
2153 | Utf8Str const &Unattended::i_getPassword() const
|
---|
2154 | {
|
---|
2155 | Assert(isReadLockedOnCurrentThread());
|
---|
2156 | return mStrPassword;
|
---|
2157 | }
|
---|
2158 |
|
---|
2159 | Utf8Str const &Unattended::i_getFullUserName() const
|
---|
2160 | {
|
---|
2161 | Assert(isReadLockedOnCurrentThread());
|
---|
2162 | return mStrFullUserName.isNotEmpty() ? mStrFullUserName : mStrUser;
|
---|
2163 | }
|
---|
2164 |
|
---|
2165 | Utf8Str const &Unattended::i_getProductKey() const
|
---|
2166 | {
|
---|
2167 | Assert(isReadLockedOnCurrentThread());
|
---|
2168 | return mStrProductKey;
|
---|
2169 | }
|
---|
2170 |
|
---|
2171 | Utf8Str const &Unattended::i_getAdditionsIsoPath() const
|
---|
2172 | {
|
---|
2173 | Assert(isReadLockedOnCurrentThread());
|
---|
2174 | return mStrAdditionsIsoPath;
|
---|
2175 | }
|
---|
2176 |
|
---|
2177 | bool Unattended::i_getInstallGuestAdditions() const
|
---|
2178 | {
|
---|
2179 | Assert(isReadLockedOnCurrentThread());
|
---|
2180 | return mfInstallGuestAdditions;
|
---|
2181 | }
|
---|
2182 |
|
---|
2183 | Utf8Str const &Unattended::i_getValidationKitIsoPath() const
|
---|
2184 | {
|
---|
2185 | Assert(isReadLockedOnCurrentThread());
|
---|
2186 | return mStrValidationKitIsoPath;
|
---|
2187 | }
|
---|
2188 |
|
---|
2189 | bool Unattended::i_getInstallTestExecService() const
|
---|
2190 | {
|
---|
2191 | Assert(isReadLockedOnCurrentThread());
|
---|
2192 | return mfInstallTestExecService;
|
---|
2193 | }
|
---|
2194 |
|
---|
2195 | Utf8Str const &Unattended::i_getTimeZone() const
|
---|
2196 | {
|
---|
2197 | Assert(isReadLockedOnCurrentThread());
|
---|
2198 | return mStrTimeZone;
|
---|
2199 | }
|
---|
2200 |
|
---|
2201 | PCRTTIMEZONEINFO Unattended::i_getTimeZoneInfo() const
|
---|
2202 | {
|
---|
2203 | Assert(isReadLockedOnCurrentThread());
|
---|
2204 | return mpTimeZoneInfo;
|
---|
2205 | }
|
---|
2206 |
|
---|
2207 | Utf8Str const &Unattended::i_getLocale() const
|
---|
2208 | {
|
---|
2209 | Assert(isReadLockedOnCurrentThread());
|
---|
2210 | return mStrLocale;
|
---|
2211 | }
|
---|
2212 |
|
---|
2213 | Utf8Str const &Unattended::i_getLanguage() const
|
---|
2214 | {
|
---|
2215 | Assert(isReadLockedOnCurrentThread());
|
---|
2216 | return mStrLanguage;
|
---|
2217 | }
|
---|
2218 |
|
---|
2219 | Utf8Str const &Unattended::i_getCountry() const
|
---|
2220 | {
|
---|
2221 | Assert(isReadLockedOnCurrentThread());
|
---|
2222 | return mStrCountry;
|
---|
2223 | }
|
---|
2224 |
|
---|
2225 | bool Unattended::i_isMinimalInstallation() const
|
---|
2226 | {
|
---|
2227 | size_t i = mPackageSelectionAdjustments.size();
|
---|
2228 | while (i-- > 0)
|
---|
2229 | if (mPackageSelectionAdjustments[i].equals("minimal"))
|
---|
2230 | return true;
|
---|
2231 | return false;
|
---|
2232 | }
|
---|
2233 |
|
---|
2234 | Utf8Str const &Unattended::i_getHostname() const
|
---|
2235 | {
|
---|
2236 | Assert(isReadLockedOnCurrentThread());
|
---|
2237 | return mStrHostname;
|
---|
2238 | }
|
---|
2239 |
|
---|
2240 | Utf8Str const &Unattended::i_getAuxiliaryBasePath() const
|
---|
2241 | {
|
---|
2242 | Assert(isReadLockedOnCurrentThread());
|
---|
2243 | return mStrAuxiliaryBasePath;
|
---|
2244 | }
|
---|
2245 |
|
---|
2246 | ULONG Unattended::i_getImageIndex() const
|
---|
2247 | {
|
---|
2248 | Assert(isReadLockedOnCurrentThread());
|
---|
2249 | return midxImage;
|
---|
2250 | }
|
---|
2251 |
|
---|
2252 | Utf8Str const &Unattended::i_getScriptTemplatePath() const
|
---|
2253 | {
|
---|
2254 | Assert(isReadLockedOnCurrentThread());
|
---|
2255 | return mStrScriptTemplatePath;
|
---|
2256 | }
|
---|
2257 |
|
---|
2258 | Utf8Str const &Unattended::i_getPostInstallScriptTemplatePath() const
|
---|
2259 | {
|
---|
2260 | Assert(isReadLockedOnCurrentThread());
|
---|
2261 | return mStrPostInstallScriptTemplatePath;
|
---|
2262 | }
|
---|
2263 |
|
---|
2264 | Utf8Str const &Unattended::i_getPostInstallCommand() const
|
---|
2265 | {
|
---|
2266 | Assert(isReadLockedOnCurrentThread());
|
---|
2267 | return mStrPostInstallCommand;
|
---|
2268 | }
|
---|
2269 |
|
---|
2270 | Utf8Str const &Unattended::i_getExtraInstallKernelParameters() const
|
---|
2271 | {
|
---|
2272 | Assert(isReadLockedOnCurrentThread());
|
---|
2273 | return mStrExtraInstallKernelParameters;
|
---|
2274 | }
|
---|
2275 |
|
---|
2276 | bool Unattended::i_isRtcUsingUtc() const
|
---|
2277 | {
|
---|
2278 | Assert(isReadLockedOnCurrentThread());
|
---|
2279 | return mfRtcUseUtc;
|
---|
2280 | }
|
---|
2281 |
|
---|
2282 | bool Unattended::i_isGuestOs64Bit() const
|
---|
2283 | {
|
---|
2284 | Assert(isReadLockedOnCurrentThread());
|
---|
2285 | return mfGuestOs64Bit;
|
---|
2286 | }
|
---|
2287 |
|
---|
2288 | VBOXOSTYPE Unattended::i_getGuestOsType() const
|
---|
2289 | {
|
---|
2290 | Assert(isReadLockedOnCurrentThread());
|
---|
2291 | return meGuestOsType;
|
---|
2292 | }
|
---|
2293 |
|
---|
2294 | HRESULT Unattended::i_attachImage(UnattendedInstallationDisk const *pImage, ComPtr<IMachine> const &rPtrSessionMachine,
|
---|
2295 | AutoMultiWriteLock2 &rLock)
|
---|
2296 | {
|
---|
2297 | /*
|
---|
2298 | * Attach the disk image
|
---|
2299 | * HACK ALERT! Temporarily release the Unattended lock.
|
---|
2300 | */
|
---|
2301 | rLock.release();
|
---|
2302 |
|
---|
2303 | ComPtr<IMedium> ptrMedium;
|
---|
2304 | HRESULT rc = mParent->OpenMedium(Bstr(pImage->strImagePath).raw(),
|
---|
2305 | pImage->enmDeviceType,
|
---|
2306 | pImage->enmAccessType,
|
---|
2307 | true,
|
---|
2308 | ptrMedium.asOutParam());
|
---|
2309 | LogRelFlowFunc(("VirtualBox::openMedium -> %Rhrc\n", rc));
|
---|
2310 | if (SUCCEEDED(rc))
|
---|
2311 | {
|
---|
2312 | if (pImage->fMountOnly)
|
---|
2313 | {
|
---|
2314 | // mount the opened disk image
|
---|
2315 | rc = rPtrSessionMachine->MountMedium(Bstr(pImage->strControllerName).raw(), pImage->uPort,
|
---|
2316 | pImage->uDevice, ptrMedium, TRUE /*fForce*/);
|
---|
2317 | LogRelFlowFunc(("Machine::MountMedium -> %Rhrc\n", rc));
|
---|
2318 | }
|
---|
2319 | else
|
---|
2320 | {
|
---|
2321 | //attach the opened disk image to the controller
|
---|
2322 | rc = rPtrSessionMachine->AttachDevice(Bstr(pImage->strControllerName).raw(), pImage->uPort,
|
---|
2323 | pImage->uDevice, pImage->enmDeviceType, ptrMedium);
|
---|
2324 | LogRelFlowFunc(("Machine::AttachDevice -> %Rhrc\n", rc));
|
---|
2325 | }
|
---|
2326 | }
|
---|
2327 |
|
---|
2328 | rLock.acquire();
|
---|
2329 | return rc;
|
---|
2330 | }
|
---|
2331 |
|
---|
2332 | bool Unattended::i_isGuestOSArchX64(Utf8Str const &rStrGuestOsTypeId)
|
---|
2333 | {
|
---|
2334 | ComPtr<IGuestOSType> pGuestOSType;
|
---|
2335 | HRESULT hrc = mParent->GetGuestOSType(Bstr(rStrGuestOsTypeId).raw(), pGuestOSType.asOutParam());
|
---|
2336 | if (SUCCEEDED(hrc))
|
---|
2337 | {
|
---|
2338 | BOOL fIs64Bit = FALSE;
|
---|
2339 | hrc = pGuestOSType->COMGETTER(Is64Bit)(&fIs64Bit);
|
---|
2340 | if (SUCCEEDED(hrc))
|
---|
2341 | return fIs64Bit != FALSE;
|
---|
2342 | }
|
---|
2343 | return false;
|
---|
2344 | }
|
---|
2345 |
|
---|