VirtualBox

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

Last change on this file since 94173 was 94079, checked in by vboxsync, 3 years ago

Main/Unattended: ​​bugref:9781. Return false from IUnattended::isUnattendedSupported() for Ubuntus < 11.04.

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