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