VirtualBox

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

Last change on this file since 108355 was 108355, checked in by vboxsync, 2 weeks ago

Unattended: bugref:10864. For Windows11 the product key is required.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.3 KB
Line 
1/* $Id: UnattendedImpl.h 108355 2025-02-24 15:20:00Z 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 bool mfProductKeyRequired;
161 Utf8Str mStrDetectedOSTypeId;
162 Utf8Str mStrDetectedOSVersion;
163 Utf8Str mStrDetectedOSFlavor;
164 VBOXOSTYPE mEnmOsType;
165 RTCList<RTCString, RTCString *> mDetectedOSLanguages; /**< (only relevant for windows at the moment) */
166 Utf8Str mStrDetectedOSHints;
167 RTCList<WIMImage> mDetectedImages;
168 bool mfAvoidUpdatesOverNetwork;
169 com::SafeIfaceArray<IGuestOSType> mSupportedGuestOSTypes;
170 bool mfDoneSupportedGuestOSList;
171 /** @} */
172
173 // wrapped IUnattended functions:
174
175 /**
176 * Checks what mStrIsoPath points to and sets the detectedOS* properties.
177 */
178 HRESULT detectIsoOS();
179
180 /**
181 * Prepare any data, environment, etc.
182 */
183 HRESULT prepare();
184
185 /**
186 * Prepare installation ISO/floppy.
187 */
188 HRESULT constructMedia();
189
190 /**
191 * Prepare a VM to run an unattended installation
192 */
193 HRESULT reconfigureVM();
194
195 /**
196 * Done with all media construction and VM configuration and stuff.
197 */
198 HRESULT done();
199
200 // wrapped IUnattended attributes:
201 HRESULT getIsoPath(com::Utf8Str &isoPath);
202 HRESULT setIsoPath(const com::Utf8Str &isoPath);
203 HRESULT getUser(com::Utf8Str &user);
204 HRESULT setUser(const com::Utf8Str &user);
205 HRESULT getUserPassword(com::Utf8Str &password);
206 HRESULT setUserPassword(const com::Utf8Str &password);
207 HRESULT getAdminPassword(com::Utf8Str &password);
208 HRESULT setAdminPassword(const com::Utf8Str &password);
209 HRESULT getFullUserName(com::Utf8Str &user);
210 HRESULT setFullUserName(const com::Utf8Str &user);
211 HRESULT getProductKey(com::Utf8Str &productKey);
212 HRESULT setProductKey(const com::Utf8Str &productKey);
213 HRESULT getAdditionsIsoPath(com::Utf8Str &additionsIsoPath);
214 HRESULT setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath);
215 HRESULT getInstallGuestAdditions(BOOL *installGuestAdditions);
216 HRESULT setInstallGuestAdditions(BOOL installGuestAdditions);
217 HRESULT getProductKeyRequired(BOOL *productKeyRequired);
218 HRESULT getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath);
219 HRESULT setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath);
220 HRESULT getInstallTestExecService(BOOL *aInstallTestExecService);
221 HRESULT setInstallTestExecService(BOOL aInstallTestExecService);
222 HRESULT getUserPayloadIsoPath(com::Utf8Str &aUserPayloadIsoPath);
223 HRESULT setUserPayloadIsoPath(const com::Utf8Str &aUserPayloadIsoPath);
224 HRESULT getInstallUserPayload(BOOL *aInstallUserPayload);
225 HRESULT setInstallUserPayload(BOOL aInstallUserPayload);
226 HRESULT getTimeZone(com::Utf8Str &aTimezone);
227 HRESULT setTimeZone(const com::Utf8Str &aTimezone);
228 HRESULT getKeyboardLayout(com::Utf8Str &aKeyboardLayout);
229 HRESULT setKeyboardLayout(const com::Utf8Str &aKeyboardLayout);
230 HRESULT getKeyboardVariant(com::Utf8Str &aKeyboardVariant);
231 HRESULT setKeyboardVariant(const com::Utf8Str &aKeyboardVariant);
232 HRESULT getLocale(com::Utf8Str &aLocale);
233 HRESULT setLocale(const com::Utf8Str &aLocale);
234 HRESULT getLanguage(com::Utf8Str &aLanguage);
235 HRESULT setLanguage(const com::Utf8Str &aLanguage);
236 HRESULT getCountry(com::Utf8Str &aCountry);
237 HRESULT setCountry(const com::Utf8Str &aCountry);
238 HRESULT getProxy(com::Utf8Str &aProxy);
239 HRESULT setProxy(const com::Utf8Str &aProxy);
240 HRESULT getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments);
241 HRESULT setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments);
242 HRESULT getHostname(com::Utf8Str &aHostname);
243 HRESULT setHostname(const com::Utf8Str &aHostname);
244 HRESULT getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath);
245 HRESULT setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath);
246 HRESULT getImageIndex(ULONG *index);
247 HRESULT setImageIndex(ULONG index);
248 HRESULT getMachine(ComPtr<IMachine> &aMachine);
249 HRESULT setMachine(const ComPtr<IMachine> &aMachine);
250 HRESULT getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath);
251 HRESULT setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath);
252 HRESULT getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath);
253 HRESULT setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath);
254 HRESULT getPostInstallCommand(com::Utf8Str &aPostInstallCommand);
255 HRESULT setPostInstallCommand(const com::Utf8Str &aPostInstallCommand);
256 HRESULT getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters);
257 HRESULT setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters);
258 HRESULT getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId);
259 HRESULT getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion);
260 HRESULT getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages);
261 HRESULT getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor);
262 HRESULT getDetectedOSHints(com::Utf8Str &aDetectedOSHints);
263 HRESULT getDetectedImageNames(std::vector<com::Utf8Str> &aDetectedImageNames);
264 HRESULT getDetectedImageIndices(std::vector<ULONG> &aDetectedImageIndices);
265 HRESULT getIsUnattendedInstallSupported(BOOL *aIsUnattendedInstallSupported);
266 HRESULT getAvoidUpdatesOverNetwork(BOOL *aAvoidUpdatesOverNetwork);
267 HRESULT setAvoidUpdatesOverNetwork(BOOL aAvoidUpdatesOverNetwork);
268 //internal functions
269
270 /**
271 * Worker for detectIsoOs().
272 *
273 * @returns COM status code.
274 * @retval S_OK if detected.
275 * @retval S_FALSE if not detected.
276 *
277 * @param hVfsIso The ISO file system handle.
278 */
279 HRESULT i_innerDetectIsoOS(RTVFS hVfsIso);
280 typedef union DETECTBUFFER
281 {
282 char sz[4096];
283 char ach[4096];
284 uint8_t ab[4096];
285 uint32_t au32[1024];
286 } DETECTBUFFER;
287 HRESULT i_innerDetectIsoOSWindows(RTVFS hVfsIso, DETECTBUFFER *puBuf);
288 HRESULT i_innerDetectIsoOSLinux(RTVFS hVfsIso, DETECTBUFFER *puBuf);
289 HRESULT i_innerDetectIsoOSLinuxFedora(RTVFS hVfsIso, DETECTBUFFER *puBuf, char *pszVolId);
290 HRESULT i_innerDetectIsoOSOs2(RTVFS hVfsIso, DETECTBUFFER *puBuf);
291 HRESULT i_innerDetectIsoOSFreeBsd(RTVFS hVfsIso, DETECTBUFFER *puBuf);
292
293 /**
294 * Worker for reconfigureVM().
295 * The caller makes sure to close the session whatever happens.
296 */
297 HRESULT i_innerReconfigureVM(AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus,
298 ComPtr<IMachine> const &rPtrSessionMachine);
299 HRESULT i_reconfigureFloppy(com::SafeIfaceArray<IStorageController> &rControllers,
300 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
301 ComPtr<IMachine> const &rPtrSessionMachine,
302 AutoMultiWriteLock2 &rAutoLock);
303 HRESULT i_reconfigureIsos(com::SafeIfaceArray<IStorageController> &rControllers,
304 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
305 ComPtr<IMachine> const &rPtrSessionMachine,
306 AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus);
307
308 /**
309 * Adds all free slots on the controller to @a rOutput.
310 */
311 HRESULT i_findOrCreateNeededFreeSlots(const Utf8Str &rStrControllerName, StorageBus_T enmStorageBus,
312 ComPtr<IMachine> const &rPtrSessionMachine, uint32_t cSlotsNeeded,
313 std::list<ControllerSlot> &rDvdSlots);
314
315 /**
316 * Attach to VM a disk
317 */
318 HRESULT i_attachImage(UnattendedInstallationDisk const *pImage, ComPtr<IMachine> const &rPtrSessionMachine,
319 AutoMultiWriteLock2 &rLock);
320
321 /*
322 * Wrapper functions
323 */
324
325 /**
326 * Check whether guest is 64bit platform or not
327 */
328 bool i_isGuestOSArchX64(Utf8Str const &rStrGuestOsTypeId);
329
330 /**
331 * Updates the detected attributes when the image index or image list changes.
332 *
333 * @returns true if we've got all necessary stuff for a successful detection.
334 */
335 bool i_updateDetectedAttributeForImage(WIMImage const &rImage);
336
337 /**
338 * Gets the list of guest OS type IDs supported by the current host.
339 */
340 HRESULT i_getListOfSupportedGuestOS();
341
342};
343
344#endif /* !MAIN_INCLUDED_UnattendedImpl_h */
Note: See TracBrowser for help on using the repository browser.

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