1 | /* $Id: UnattendedImpl.h 101683 2023-10-31 12:38:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Unattended class header
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 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. */
|
---|
39 | class UnattendedInstaller;
|
---|
40 | struct UnattendedInstallationDisk;
|
---|
41 | struct 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 | */
|
---|
47 | struct 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 | VBOXOSTYPE mEnmOsType;
|
---|
60 | };
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Class implementing the IUnattended interface.
|
---|
64 | *
|
---|
65 | * This class is instantiated on the request by IMachine::getUnattended.
|
---|
66 | */
|
---|
67 | class ATL_NO_VTABLE Unattended
|
---|
68 | : public UnattendedWrap
|
---|
69 | {
|
---|
70 | public:
|
---|
71 | DECLARE_COMMON_CLASS_METHODS(Unattended)
|
---|
72 |
|
---|
73 | HRESULT FinalConstruct();
|
---|
74 | void FinalRelease();
|
---|
75 |
|
---|
76 | // public initializer/uninitializer for internal purposes only
|
---|
77 | HRESULT initUnattended(VirtualBox *aParent);
|
---|
78 | void uninit();
|
---|
79 |
|
---|
80 | // public methods for internal purposes
|
---|
81 | Utf8Str const &i_getIsoPath() const;
|
---|
82 | Utf8Str const &i_getUser() const;
|
---|
83 | Utf8Str const &i_getPassword() 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_getTimeZone() const;
|
---|
92 | PCRTTIMEZONEINFO i_getTimeZoneInfo() const;
|
---|
93 | Utf8Str const &i_getLocale() const;
|
---|
94 | Utf8Str const &i_getLanguage() const;
|
---|
95 | Utf8Str const &i_getCountry() const;
|
---|
96 | bool i_isMinimalInstallation() const;
|
---|
97 | Utf8Str const &i_getHostname() const;
|
---|
98 | Utf8Str const &i_getAuxiliaryBasePath() const;
|
---|
99 | ULONG i_getImageIndex() const;
|
---|
100 | Utf8Str const &i_getScriptTemplatePath() const;
|
---|
101 | Utf8Str const &i_getPostInstallScriptTemplatePath() const;
|
---|
102 | Utf8Str const &i_getPostInstallCommand() const;
|
---|
103 | /** The directory where the unattended install config and script is
|
---|
104 | * located, from the perspective of the running unattended install. */
|
---|
105 | Utf8Str const &i_getAuxiliaryInstallDir() const;
|
---|
106 | Utf8Str const &i_getExtraInstallKernelParameters() const;
|
---|
107 | Utf8Str const &i_getAdditionsInstallPackage() const;
|
---|
108 |
|
---|
109 | bool i_isRtcUsingUtc() const;
|
---|
110 | bool i_isGuestOs64Bit() const;
|
---|
111 | bool i_isFirmwareEFI() const;
|
---|
112 | Utf8Str const &i_getDetectedOSVersion();
|
---|
113 | bool i_getAvoidUpdatesOverNetwork() const;
|
---|
114 |
|
---|
115 | private:
|
---|
116 | ComPtr<VirtualBox> const mParent; /**< Strong reference to the parent object (VirtualBox/IMachine). */
|
---|
117 | ComPtr<Machine> mMachine; /**< Strong reference to the machine object (Machine/IMachine). */
|
---|
118 | Guid mMachineUuid; /**< The machine UUID. */
|
---|
119 | RTNATIVETHREAD mhThreadReconfigureVM; /**< Set when reconfigureVM is running. */
|
---|
120 | Utf8Str mStrGuestOsTypeId; /**< Guest OS type ID (set by prepare). */
|
---|
121 | bool mfRtcUseUtc; /**< Copy of IMachine::RTCUseUTC (locking reasons). */
|
---|
122 | bool mfGuestOs64Bit; /**< 64-bit (true) or 32-bit guest OS (set by prepare). */
|
---|
123 | FirmwareType_T menmFirmwareType; /**< Firmware type BIOS/EFI (set by prepare). */
|
---|
124 | UnattendedInstaller *mpInstaller; /**< The installer instance (set by prepare, deleted by done). */
|
---|
125 |
|
---|
126 | /** @name Values of the IUnattended attributes.
|
---|
127 | * @{ */
|
---|
128 | Utf8Str mStrUser;
|
---|
129 | Utf8Str mStrPassword;
|
---|
130 | Utf8Str mStrFullUserName;
|
---|
131 | Utf8Str mStrProductKey;
|
---|
132 | Utf8Str mStrIsoPath;
|
---|
133 | Utf8Str mStrAdditionsIsoPath;
|
---|
134 | bool mfInstallGuestAdditions;
|
---|
135 | bool mfInstallTestExecService;
|
---|
136 | Utf8Str mStrValidationKitIsoPath;
|
---|
137 | Utf8Str mStrTimeZone;
|
---|
138 | PCRTTIMEZONEINFO mpTimeZoneInfo;
|
---|
139 | Utf8Str mStrLocale;
|
---|
140 | Utf8Str mStrLanguage; /**< (only relevant for windows at the moment) */
|
---|
141 | Utf8Str mStrCountry;
|
---|
142 | RTCList<RTCString, RTCString *> mPackageSelectionAdjustments;
|
---|
143 | Utf8Str mStrHostname;
|
---|
144 | Utf8Str mStrAuxiliaryBasePath;
|
---|
145 | bool mfIsDefaultAuxiliaryBasePath;
|
---|
146 | ULONG midxImage;
|
---|
147 | Utf8Str mStrScriptTemplatePath;
|
---|
148 | Utf8Str mStrPostInstallScriptTemplatePath;
|
---|
149 | Utf8Str mStrPostInstallCommand;
|
---|
150 | Utf8Str mStrExtraInstallKernelParameters;
|
---|
151 | Utf8Str mStrProxy;
|
---|
152 | Utf8Str mStrAdditionsInstallPackage;
|
---|
153 |
|
---|
154 | bool mfDoneDetectIsoOS; /**< Set by detectIsoOS(), cleared by setIsoPath(). */
|
---|
155 | Utf8Str mStrDetectedOSTypeId;
|
---|
156 | Utf8Str mStrDetectedOSVersion;
|
---|
157 | Utf8Str mStrDetectedOSFlavor;
|
---|
158 | VBOXOSTYPE mEnmOsType;
|
---|
159 | RTCList<RTCString, RTCString *> mDetectedOSLanguages; /**< (only relevant for windows at the moment) */
|
---|
160 | Utf8Str mStrDetectedOSHints;
|
---|
161 | RTCList<WIMImage> mDetectedImages;
|
---|
162 | bool mfAvoidUpdatesOverNetwork;
|
---|
163 | /** @} */
|
---|
164 |
|
---|
165 | // wrapped IUnattended functions:
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * Checks what mStrIsoPath points to and sets the detectedOS* properties.
|
---|
169 | */
|
---|
170 | HRESULT detectIsoOS();
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * Prepare any data, environment, etc.
|
---|
174 | */
|
---|
175 | HRESULT prepare();
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * Prepare installation ISO/floppy.
|
---|
179 | */
|
---|
180 | HRESULT constructMedia();
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Prepare a VM to run an unattended installation
|
---|
184 | */
|
---|
185 | HRESULT reconfigureVM();
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * Done with all media construction and VM configuration and stuff.
|
---|
189 | */
|
---|
190 | HRESULT done();
|
---|
191 |
|
---|
192 | // wrapped IUnattended attributes:
|
---|
193 | HRESULT getIsoPath(com::Utf8Str &isoPath);
|
---|
194 | HRESULT setIsoPath(const com::Utf8Str &isoPath);
|
---|
195 | HRESULT getUser(com::Utf8Str &user);
|
---|
196 | HRESULT setUser(const com::Utf8Str &user);
|
---|
197 | HRESULT getPassword(com::Utf8Str &password);
|
---|
198 | HRESULT setPassword(const com::Utf8Str &password);
|
---|
199 | HRESULT getFullUserName(com::Utf8Str &user);
|
---|
200 | HRESULT setFullUserName(const com::Utf8Str &user);
|
---|
201 | HRESULT getProductKey(com::Utf8Str &productKey);
|
---|
202 | HRESULT setProductKey(const com::Utf8Str &productKey);
|
---|
203 | HRESULT getAdditionsIsoPath(com::Utf8Str &additionsIsoPath);
|
---|
204 | HRESULT setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath);
|
---|
205 | HRESULT getInstallGuestAdditions(BOOL *installGuestAdditions);
|
---|
206 | HRESULT setInstallGuestAdditions(BOOL installGuestAdditions);
|
---|
207 | HRESULT getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath);
|
---|
208 | HRESULT setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath);
|
---|
209 | HRESULT getInstallTestExecService(BOOL *aInstallTestExecService);
|
---|
210 | HRESULT setInstallTestExecService(BOOL aInstallTestExecService);
|
---|
211 | HRESULT getTimeZone(com::Utf8Str &aTimezone);
|
---|
212 | HRESULT setTimeZone(const com::Utf8Str &aTimezone);
|
---|
213 | HRESULT getLocale(com::Utf8Str &aLocale);
|
---|
214 | HRESULT setLocale(const com::Utf8Str &aLocale);
|
---|
215 | HRESULT getLanguage(com::Utf8Str &aLanguage);
|
---|
216 | HRESULT setLanguage(const com::Utf8Str &aLanguage);
|
---|
217 | HRESULT getCountry(com::Utf8Str &aCountry);
|
---|
218 | HRESULT setCountry(const com::Utf8Str &aCountry);
|
---|
219 | HRESULT getProxy(com::Utf8Str &aProxy);
|
---|
220 | HRESULT setProxy(const com::Utf8Str &aProxy);
|
---|
221 | HRESULT getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments);
|
---|
222 | HRESULT setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments);
|
---|
223 | HRESULT getHostname(com::Utf8Str &aHostname);
|
---|
224 | HRESULT setHostname(const com::Utf8Str &aHostname);
|
---|
225 | HRESULT getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath);
|
---|
226 | HRESULT setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath);
|
---|
227 | HRESULT getImageIndex(ULONG *index);
|
---|
228 | HRESULT setImageIndex(ULONG index);
|
---|
229 | HRESULT getMachine(ComPtr<IMachine> &aMachine);
|
---|
230 | HRESULT setMachine(const ComPtr<IMachine> &aMachine);
|
---|
231 | HRESULT getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath);
|
---|
232 | HRESULT setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath);
|
---|
233 | HRESULT getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath);
|
---|
234 | HRESULT setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath);
|
---|
235 | HRESULT getPostInstallCommand(com::Utf8Str &aPostInstallCommand);
|
---|
236 | HRESULT setPostInstallCommand(const com::Utf8Str &aPostInstallCommand);
|
---|
237 | HRESULT getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters);
|
---|
238 | HRESULT setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters);
|
---|
239 | HRESULT getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId);
|
---|
240 | HRESULT getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion);
|
---|
241 | HRESULT getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages);
|
---|
242 | HRESULT getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor);
|
---|
243 | HRESULT getDetectedOSHints(com::Utf8Str &aDetectedOSHints);
|
---|
244 | HRESULT getDetectedImageNames(std::vector<com::Utf8Str> &aDetectedImageNames);
|
---|
245 | HRESULT getDetectedImageIndices(std::vector<ULONG> &aDetectedImageIndices);
|
---|
246 | HRESULT getIsUnattendedInstallSupported(BOOL *aIsUnattendedInstallSupported);
|
---|
247 | HRESULT getAvoidUpdatesOverNetwork(BOOL *aAvoidUpdatesOverNetwork);
|
---|
248 | HRESULT setAvoidUpdatesOverNetwork(BOOL aAvoidUpdatesOverNetwork);
|
---|
249 | //internal functions
|
---|
250 |
|
---|
251 | /**
|
---|
252 | * Worker for detectIsoOs().
|
---|
253 | *
|
---|
254 | * @returns COM status code.
|
---|
255 | * @retval S_OK if detected.
|
---|
256 | * @retval S_FALSE if not detected.
|
---|
257 | *
|
---|
258 | * @param hVfsIso The ISO file system handle.
|
---|
259 | */
|
---|
260 | HRESULT i_innerDetectIsoOS(RTVFS hVfsIso);
|
---|
261 | typedef union DETECTBUFFER
|
---|
262 | {
|
---|
263 | char sz[4096];
|
---|
264 | char ach[4096];
|
---|
265 | uint8_t ab[4096];
|
---|
266 | uint32_t au32[1024];
|
---|
267 | } DETECTBUFFER;
|
---|
268 | HRESULT i_innerDetectIsoOSWindows(RTVFS hVfsIso, DETECTBUFFER *puBuf);
|
---|
269 | HRESULT i_innerDetectIsoOSLinux(RTVFS hVfsIso, DETECTBUFFER *puBuf);
|
---|
270 | HRESULT i_innerDetectIsoOSLinuxFedora(RTVFS hVfsIso, DETECTBUFFER *puBuf, char *pszVolId);
|
---|
271 | HRESULT i_innerDetectIsoOSOs2(RTVFS hVfsIso, DETECTBUFFER *puBuf);
|
---|
272 | HRESULT i_innerDetectIsoOSFreeBsd(RTVFS hVfsIso, DETECTBUFFER *puBuf);
|
---|
273 |
|
---|
274 | /**
|
---|
275 | * Worker for reconfigureVM().
|
---|
276 | * The caller makes sure to close the session whatever happens.
|
---|
277 | */
|
---|
278 | HRESULT i_innerReconfigureVM(AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus,
|
---|
279 | ComPtr<IMachine> const &rPtrSessionMachine);
|
---|
280 | HRESULT i_reconfigureFloppy(com::SafeIfaceArray<IStorageController> &rControllers,
|
---|
281 | std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
|
---|
282 | ComPtr<IMachine> const &rPtrSessionMachine,
|
---|
283 | AutoMultiWriteLock2 &rAutoLock);
|
---|
284 | HRESULT i_reconfigureIsos(com::SafeIfaceArray<IStorageController> &rControllers,
|
---|
285 | std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
|
---|
286 | ComPtr<IMachine> const &rPtrSessionMachine,
|
---|
287 | AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus);
|
---|
288 |
|
---|
289 | /**
|
---|
290 | * Adds all free slots on the controller to @a rOutput.
|
---|
291 | */
|
---|
292 | HRESULT i_findOrCreateNeededFreeSlots(const Utf8Str &rStrControllerName, StorageBus_T enmStorageBus,
|
---|
293 | ComPtr<IMachine> const &rPtrSessionMachine, uint32_t cSlotsNeeded,
|
---|
294 | std::list<ControllerSlot> &rDvdSlots);
|
---|
295 |
|
---|
296 | /**
|
---|
297 | * Attach to VM a disk
|
---|
298 | */
|
---|
299 | HRESULT i_attachImage(UnattendedInstallationDisk const *pImage, ComPtr<IMachine> const &rPtrSessionMachine,
|
---|
300 | AutoMultiWriteLock2 &rLock);
|
---|
301 |
|
---|
302 | /*
|
---|
303 | * Wrapper functions
|
---|
304 | */
|
---|
305 |
|
---|
306 | /**
|
---|
307 | * Check whether guest is 64bit platform or not
|
---|
308 | */
|
---|
309 | bool i_isGuestOSArchX64(Utf8Str const &rStrGuestOsTypeId);
|
---|
310 |
|
---|
311 | /**
|
---|
312 | * Updates the detected attributes when the image index or image list changes.
|
---|
313 | *
|
---|
314 | * @returns true if we've got all necessary stuff for a successful detection.
|
---|
315 | */
|
---|
316 | bool i_updateDetectedAttributeForImage(WIMImage const &rImage);
|
---|
317 |
|
---|
318 | };
|
---|
319 |
|
---|
320 | #endif /* !MAIN_INCLUDED_UnattendedImpl_h */
|
---|