VirtualBox

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

Last change on this file since 96861 was 96861, checked in by vboxsync, 2 years ago

IPRT/Vfs,Main/Unattended: Detect fedora ISOs, various code cleanups. Added a parameter to RTVfsQueryLabel so we can get the primary volume ID of an ISO (required for fedora ISOs, as the joliet version is truncated). bugref:9781

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