VirtualBox

source: vbox/trunk/src/VBox/Main/include/UnattendedImpl.h@ 106297

Last change on this file since 106297 was 106062, checked in by vboxsync, 2 months ago

Unattended: ​bugref:10511. Avoid tripping lock order assert when Unattended::prepare is called.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.2 KB
Line 
1/* $Id: UnattendedImpl.h 106062 2024-09-16 15:48:55Z vboxsync $ */
2/** @file
3 * Unattended class header
4 */
5
6/*
7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef MAIN_INCLUDED_UnattendedImpl_h
29#define MAIN_INCLUDED_UnattendedImpl_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include <VBox/ostypes.h>
35#include <iprt/time.h>
36#include "UnattendedWrap.h"
37
38/* Forward declarations. */
39class UnattendedInstaller;
40struct UnattendedInstallationDisk;
41struct ControllerSlot;
42
43/**
44 * A data type to store image data which is read from intall.wim file.
45 * Currently relevant only for Windows OSs.
46 */
47struct WIMImage
48{
49 Utf8Str mName;
50 Utf8Str mVersion;
51 Utf8Str mArch;
52 Utf8Str mFlavor;
53 RTCList<RTCString, RTCString *> mLanguages;
54 Utf8Str mDefaultLanguage;
55 uint32_t mImageIndex;
56 VBOXOSTYPE mOSType;
57 WIMImage() : mImageIndex(0), mOSType(VBOXOSTYPE_Unknown) { }
58 const Utf8Str &formatName(Utf8Str &r_strName) const;
59};
60
61/**
62 * Class implementing the IUnattended interface.
63 *
64 * This class is instantiated on the request by IMachine::getUnattended.
65 */
66class ATL_NO_VTABLE Unattended
67 : public UnattendedWrap
68{
69public:
70 DECLARE_COMMON_CLASS_METHODS(Unattended)
71
72 HRESULT FinalConstruct();
73 void FinalRelease();
74
75 // public initializer/uninitializer for internal purposes only
76 HRESULT initUnattended(VirtualBox *aParent);
77 void uninit();
78
79 // public methods for internal purposes
80 Utf8Str const &i_getIsoPath() const;
81 Utf8Str const &i_getUser() const;
82 Utf8Str const &i_getUserPassword() const;
83 Utf8Str const &i_getAdminPassword() const;
84 Utf8Str const &i_getFullUserName() const;
85 Utf8Str const &i_getProductKey() const;
86 Utf8Str const &i_getProxy() const;
87 Utf8Str const &i_getAdditionsIsoPath() const;
88 bool i_getInstallGuestAdditions() const;
89 Utf8Str const &i_getValidationKitIsoPath() const;
90 bool i_getInstallTestExecService() const;
91 Utf8Str const &i_getUserPayloadIsoPath() const;
92 bool i_getInstallUserPayload() const;
93 Utf8Str const &i_getTimeZone() const;
94 PCRTTIMEZONEINFO i_getTimeZoneInfo() const;
95 Utf8Str const &i_getLocale() const;
96 Utf8Str const &i_getLanguage() const;
97 Utf8Str const &i_getCountry() const;
98 bool i_isMinimalInstallation() const;
99 Utf8Str const &i_getHostname() const;
100 Utf8Str const &i_getAuxiliaryBasePath() const;
101 ULONG i_getImageIndex() const;
102 Utf8Str const &i_getScriptTemplatePath() const;
103 Utf8Str const &i_getPostInstallScriptTemplatePath() const;
104 Utf8Str const &i_getPostInstallCommand() const;
105 /** The directory where the unattended install config and script is
106 * located, from the perspective of the running unattended install. */
107 Utf8Str const &i_getAuxiliaryInstallDir() const;
108 Utf8Str const &i_getExtraInstallKernelParameters() const;
109 Utf8Str const &i_getAdditionsInstallPackage() const;
110
111 bool i_isRtcUsingUtc() const;
112 bool i_isGuestOs64Bit() const;
113 bool i_isFirmwareEFI() const;
114 Utf8Str const &i_getDetectedOSVersion();
115 bool i_getAvoidUpdatesOverNetwork() const;
116
117private:
118 ComPtr<VirtualBox> const mParent; /**< Strong reference to the parent object (VirtualBox/IMachine). */
119 ComPtr<Machine> mMachine; /**< Strong reference to the machine object (Machine/IMachine). */
120 Guid mMachineUuid; /**< The machine UUID. */
121 RTNATIVETHREAD mhThreadReconfigureVM; /**< Set when reconfigureVM is running. */
122 Utf8Str mStrGuestOsTypeId; /**< Guest OS type ID (set by prepare). */
123 bool mfRtcUseUtc; /**< Copy of IMachine::RTCUseUTC (locking reasons). */
124 bool mfGuestOs64Bit; /**< 64-bit (true) or 32-bit guest OS (set by prepare). */
125 FirmwareType_T menmFirmwareType; /**< Firmware type BIOS/EFI (set by prepare). */
126 UnattendedInstaller *mpInstaller; /**< The installer instance (set by prepare, deleted by done). */
127
128 /** @name Values of the IUnattended attributes.
129 * @{ */
130 Utf8Str mStrUser;
131 Utf8Str mStrUserPassword;
132 Utf8Str mStrAdminPassword;
133 Utf8Str mStrFullUserName;
134 Utf8Str mStrProductKey;
135 Utf8Str mStrIsoPath;
136 Utf8Str mStrAdditionsIsoPath;
137 bool mfInstallGuestAdditions;
138 bool mfInstallTestExecService;
139 Utf8Str mStrValidationKitIsoPath;
140 Utf8Str mStrUserPayloadIsoPath;
141 bool mfInstallUserPayload;
142 Utf8Str mStrTimeZone;
143 PCRTTIMEZONEINFO mpTimeZoneInfo;
144 Utf8Str mStrLocale;
145 Utf8Str mStrLanguage; /**< (only relevant for windows at the moment) */
146 Utf8Str mStrCountry;
147 RTCList<RTCString, RTCString *> mPackageSelectionAdjustments;
148 Utf8Str mStrHostname;
149 Utf8Str mStrAuxiliaryBasePath;
150 bool mfIsDefaultAuxiliaryBasePath;
151 ULONG midxImage;
152 Utf8Str mStrScriptTemplatePath;
153 Utf8Str mStrPostInstallScriptTemplatePath;
154 Utf8Str mStrPostInstallCommand;
155 Utf8Str mStrExtraInstallKernelParameters;
156 Utf8Str mStrProxy;
157 Utf8Str mStrAdditionsInstallPackage;
158
159 bool mfDoneDetectIsoOS; /**< Set by detectIsoOS(), cleared by setIsoPath(). */
160 Utf8Str mStrDetectedOSTypeId;
161 Utf8Str mStrDetectedOSVersion;
162 Utf8Str mStrDetectedOSFlavor;
163 VBOXOSTYPE mEnmOsType;
164 RTCList<RTCString, RTCString *> mDetectedOSLanguages; /**< (only relevant for windows at the moment) */
165 Utf8Str mStrDetectedOSHints;
166 RTCList<WIMImage> mDetectedImages;
167 bool mfAvoidUpdatesOverNetwork;
168 com::SafeIfaceArray<IGuestOSType> mSupportedGuestOSTypes;
169 bool mfDoneSupportedGuestOSList;
170 /** @} */
171
172 // wrapped IUnattended functions:
173
174 /**
175 * Checks what mStrIsoPath points to and sets the detectedOS* properties.
176 */
177 HRESULT detectIsoOS();
178
179 /**
180 * Prepare any data, environment, etc.
181 */
182 HRESULT prepare();
183
184 /**
185 * Prepare installation ISO/floppy.
186 */
187 HRESULT constructMedia();
188
189 /**
190 * Prepare a VM to run an unattended installation
191 */
192 HRESULT reconfigureVM();
193
194 /**
195 * Done with all media construction and VM configuration and stuff.
196 */
197 HRESULT done();
198
199 // wrapped IUnattended attributes:
200 HRESULT getIsoPath(com::Utf8Str &isoPath);
201 HRESULT setIsoPath(const com::Utf8Str &isoPath);
202 HRESULT getUser(com::Utf8Str &user);
203 HRESULT setUser(const com::Utf8Str &user);
204 HRESULT getUserPassword(com::Utf8Str &password);
205 HRESULT setUserPassword(const com::Utf8Str &password);
206 HRESULT getAdminPassword(com::Utf8Str &password);
207 HRESULT setAdminPassword(const com::Utf8Str &password);
208 HRESULT getFullUserName(com::Utf8Str &user);
209 HRESULT setFullUserName(const com::Utf8Str &user);
210 HRESULT getProductKey(com::Utf8Str &productKey);
211 HRESULT setProductKey(const com::Utf8Str &productKey);
212 HRESULT getAdditionsIsoPath(com::Utf8Str &additionsIsoPath);
213 HRESULT setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath);
214 HRESULT getInstallGuestAdditions(BOOL *installGuestAdditions);
215 HRESULT setInstallGuestAdditions(BOOL installGuestAdditions);
216 HRESULT getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath);
217 HRESULT setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath);
218 HRESULT getInstallTestExecService(BOOL *aInstallTestExecService);
219 HRESULT setInstallTestExecService(BOOL aInstallTestExecService);
220 HRESULT getUserPayloadIsoPath(com::Utf8Str &aUserPayloadIsoPath);
221 HRESULT setUserPayloadIsoPath(const com::Utf8Str &aUserPayloadIsoPath);
222 HRESULT getInstallUserPayload(BOOL *aInstallUserPayload);
223 HRESULT setInstallUserPayload(BOOL aInstallUserPayload);
224 HRESULT getTimeZone(com::Utf8Str &aTimezone);
225 HRESULT setTimeZone(const com::Utf8Str &aTimezone);
226 HRESULT getKeyboardLayout(com::Utf8Str &aKeyboardLayout);
227 HRESULT setKeyboardLayout(const com::Utf8Str &aKeyboardLayout);
228 HRESULT getKeyboardVariant(com::Utf8Str &aKeyboardVariant);
229 HRESULT setKeyboardVariant(const com::Utf8Str &aKeyboardVariant);
230 HRESULT getLocale(com::Utf8Str &aLocale);
231 HRESULT setLocale(const com::Utf8Str &aLocale);
232 HRESULT getLanguage(com::Utf8Str &aLanguage);
233 HRESULT setLanguage(const com::Utf8Str &aLanguage);
234 HRESULT getCountry(com::Utf8Str &aCountry);
235 HRESULT setCountry(const com::Utf8Str &aCountry);
236 HRESULT getProxy(com::Utf8Str &aProxy);
237 HRESULT setProxy(const com::Utf8Str &aProxy);
238 HRESULT getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments);
239 HRESULT setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments);
240 HRESULT getHostname(com::Utf8Str &aHostname);
241 HRESULT setHostname(const com::Utf8Str &aHostname);
242 HRESULT getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath);
243 HRESULT setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath);
244 HRESULT getImageIndex(ULONG *index);
245 HRESULT setImageIndex(ULONG index);
246 HRESULT getMachine(ComPtr<IMachine> &aMachine);
247 HRESULT setMachine(const ComPtr<IMachine> &aMachine);
248 HRESULT getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath);
249 HRESULT setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath);
250 HRESULT getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath);
251 HRESULT setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath);
252 HRESULT getPostInstallCommand(com::Utf8Str &aPostInstallCommand);
253 HRESULT setPostInstallCommand(const com::Utf8Str &aPostInstallCommand);
254 HRESULT getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters);
255 HRESULT setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters);
256 HRESULT getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId);
257 HRESULT getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion);
258 HRESULT getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages);
259 HRESULT getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor);
260 HRESULT getDetectedOSHints(com::Utf8Str &aDetectedOSHints);
261 HRESULT getDetectedImageNames(std::vector<com::Utf8Str> &aDetectedImageNames);
262 HRESULT getDetectedImageIndices(std::vector<ULONG> &aDetectedImageIndices);
263 HRESULT getIsUnattendedInstallSupported(BOOL *aIsUnattendedInstallSupported);
264 HRESULT getAvoidUpdatesOverNetwork(BOOL *aAvoidUpdatesOverNetwork);
265 HRESULT setAvoidUpdatesOverNetwork(BOOL aAvoidUpdatesOverNetwork);
266 //internal functions
267
268 /**
269 * Worker for detectIsoOs().
270 *
271 * @returns COM status code.
272 * @retval S_OK if detected.
273 * @retval S_FALSE if not detected.
274 *
275 * @param hVfsIso The ISO file system handle.
276 */
277 HRESULT i_innerDetectIsoOS(RTVFS hVfsIso);
278 typedef union DETECTBUFFER
279 {
280 char sz[4096];
281 char ach[4096];
282 uint8_t ab[4096];
283 uint32_t au32[1024];
284 } DETECTBUFFER;
285 HRESULT i_innerDetectIsoOSWindows(RTVFS hVfsIso, DETECTBUFFER *puBuf);
286 HRESULT i_innerDetectIsoOSLinux(RTVFS hVfsIso, DETECTBUFFER *puBuf);
287 HRESULT i_innerDetectIsoOSLinuxFedora(RTVFS hVfsIso, DETECTBUFFER *puBuf, char *pszVolId);
288 HRESULT i_innerDetectIsoOSOs2(RTVFS hVfsIso, DETECTBUFFER *puBuf);
289 HRESULT i_innerDetectIsoOSFreeBsd(RTVFS hVfsIso, DETECTBUFFER *puBuf);
290
291 /**
292 * Worker for reconfigureVM().
293 * The caller makes sure to close the session whatever happens.
294 */
295 HRESULT i_innerReconfigureVM(AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus,
296 ComPtr<IMachine> const &rPtrSessionMachine);
297 HRESULT i_reconfigureFloppy(com::SafeIfaceArray<IStorageController> &rControllers,
298 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
299 ComPtr<IMachine> const &rPtrSessionMachine,
300 AutoMultiWriteLock2 &rAutoLock);
301 HRESULT i_reconfigureIsos(com::SafeIfaceArray<IStorageController> &rControllers,
302 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
303 ComPtr<IMachine> const &rPtrSessionMachine,
304 AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus);
305
306 /**
307 * Adds all free slots on the controller to @a rOutput.
308 */
309 HRESULT i_findOrCreateNeededFreeSlots(const Utf8Str &rStrControllerName, StorageBus_T enmStorageBus,
310 ComPtr<IMachine> const &rPtrSessionMachine, uint32_t cSlotsNeeded,
311 std::list<ControllerSlot> &rDvdSlots);
312
313 /**
314 * Attach to VM a disk
315 */
316 HRESULT i_attachImage(UnattendedInstallationDisk const *pImage, ComPtr<IMachine> const &rPtrSessionMachine,
317 AutoMultiWriteLock2 &rLock);
318
319 /*
320 * Wrapper functions
321 */
322
323 /**
324 * Check whether guest is 64bit platform or not
325 */
326 bool i_isGuestOSArchX64(Utf8Str const &rStrGuestOsTypeId);
327
328 /**
329 * Updates the detected attributes when the image index or image list changes.
330 *
331 * @returns true if we've got all necessary stuff for a successful detection.
332 */
333 bool i_updateDetectedAttributeForImage(WIMImage const &rImage);
334
335 /**
336 * Gets the list of guest OS type IDs supported by the current host.
337 */
338 HRESULT i_getListOfSupportedGuestOS();
339
340};
341
342#endif /* !MAIN_INCLUDED_UnattendedImpl_h */
Note: See TracBrowser for help on using the repository browser.

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