summaryrefslogtreecommitdiffstats
path: root/src/VBox/Main/include/UnattendedImpl.h
blob: de78c2bf6103c5e30c386b3d0651c9debf5bea40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/* $Id: UnattendedImpl.h $ */
/** @file
 * Unattended class header
 */

/*
 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses>.
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#ifndef MAIN_INCLUDED_UnattendedImpl_h
#define MAIN_INCLUDED_UnattendedImpl_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif

#include <VBox/ostypes.h>
#include <iprt/time.h>
#include "UnattendedWrap.h"

/* Forward declarations. */
class UnattendedInstaller;
struct UnattendedInstallationDisk;
struct ControllerSlot;

/**
 * A data type to store image data which is read from intall.wim file.
 * Currently relevant only for Windows OSs.
 */
struct WIMImage
{
    Utf8Str  mName;
    Utf8Str  mVersion;
    Utf8Str  mArch;
    Utf8Str  mFlavor;
    RTCList<RTCString, RTCString *> mLanguages;
    Utf8Str  mDefaultLanguage;
    uint32_t mImageIndex;
    VBOXOSTYPE mOSType;
    WIMImage() : mImageIndex(0), mOSType(VBOXOSTYPE_Unknown) { }
    const Utf8Str &formatName(Utf8Str &r_strName) const;
    VBOXOSTYPE mEnmOsType;
};

/**
 * Class implementing the IUnattended interface.
 *
 * This class is instantiated on the request by IMachine::getUnattended.
 */
class ATL_NO_VTABLE Unattended
    : public UnattendedWrap
{
public:
    DECLARE_COMMON_CLASS_METHODS(Unattended)

    HRESULT FinalConstruct();
    void FinalRelease();

    // public initializer/uninitializer for internal purposes only
    HRESULT initUnattended(VirtualBox *aParent);
    void uninit();

    // public methods for internal purposes
    Utf8Str const &i_getIsoPath() const;
    Utf8Str const &i_getUser() const;
    Utf8Str const &i_getPassword() const;
    Utf8Str const &i_getFullUserName() const;
    Utf8Str const &i_getProductKey() const;
    Utf8Str const &i_getProxy() const;
    Utf8Str const &i_getAdditionsIsoPath() const;
    bool           i_getInstallGuestAdditions() const;
    Utf8Str const &i_getValidationKitIsoPath() const;
    bool           i_getInstallTestExecService() const;
    Utf8Str const &i_getTimeZone() const;
    PCRTTIMEZONEINFO i_getTimeZoneInfo() const;
    Utf8Str const &i_getLocale() const;
    Utf8Str const &i_getLanguage() const;
    Utf8Str const &i_getCountry() const;
    bool           i_isMinimalInstallation() const;
    Utf8Str const &i_getHostname() const;
    Utf8Str const &i_getAuxiliaryBasePath() const;
    ULONG          i_getImageIndex() const;
    Utf8Str const &i_getScriptTemplatePath() const;
    Utf8Str const &i_getPostInstallScriptTemplatePath() const;
    Utf8Str const &i_getPostInstallCommand() const;
    /** The directory where the unattended install config and script is
     * located, from the perspective of the running unattended install. */
    Utf8Str const &i_getAuxiliaryInstallDir() const;
    Utf8Str const &i_getExtraInstallKernelParameters() const;

    bool           i_isRtcUsingUtc() const;
    bool           i_isGuestOs64Bit() const;
    bool           i_isFirmwareEFI() const;
    Utf8Str const &i_getDetectedOSVersion();
    bool           i_getAvoidUpdatesOverNetwork() const;

private:
    ComPtr<VirtualBox> const mParent;       /**< Strong reference to the parent object (VirtualBox/IMachine). */
    ComPtr<Machine> mMachine;               /**< Strong reference to the machine object (Machine/IMachine). */
    Guid            mMachineUuid;           /**< The machine UUID. */
    RTNATIVETHREAD  mhThreadReconfigureVM;  /**< Set when reconfigureVM is running. */
    Utf8Str         mStrGuestOsTypeId;      /**< Guest OS type ID (set by prepare). */
    bool            mfRtcUseUtc;            /**< Copy of IMachine::RTCUseUTC (locking reasons). */
    bool            mfGuestOs64Bit;         /**< 64-bit (true) or 32-bit guest OS (set by prepare). */
    FirmwareType_T  menmFirmwareType;       /**< Firmware type BIOS/EFI (set by prepare). */
    UnattendedInstaller *mpInstaller;       /**< The installer instance (set by prepare, deleted by done). */

    /** @name Values of the IUnattended attributes.
     * @{ */
    Utf8Str         mStrUser;
    Utf8Str         mStrPassword;
    Utf8Str         mStrFullUserName;
    Utf8Str         mStrProductKey;
    Utf8Str         mStrIsoPath;
    Utf8Str         mStrAdditionsIsoPath;
    bool            mfInstallGuestAdditions;
    bool            mfInstallTestExecService;
    Utf8Str         mStrValidationKitIsoPath;
    Utf8Str         mStrTimeZone;
    PCRTTIMEZONEINFO mpTimeZoneInfo;
    Utf8Str         mStrLocale;
    Utf8Str         mStrLanguage;           /**< (only relevant for windows at the moment) */
    Utf8Str         mStrCountry;
    RTCList<RTCString, RTCString *> mPackageSelectionAdjustments;
    Utf8Str         mStrHostname;
    Utf8Str         mStrAuxiliaryBasePath;
    bool            mfIsDefaultAuxiliaryBasePath;
    ULONG           midxImage;
    Utf8Str         mStrScriptTemplatePath;
    Utf8Str         mStrPostInstallScriptTemplatePath;
    Utf8Str         mStrPostInstallCommand;
    Utf8Str         mStrExtraInstallKernelParameters;
    Utf8Str         mStrProxy;

    bool            mfDoneDetectIsoOS;         /**< Set by detectIsoOS(), cleared by setIsoPath(). */
    Utf8Str         mStrDetectedOSTypeId;
    Utf8Str         mStrDetectedOSVersion;
    Utf8Str         mStrDetectedOSFlavor;
    VBOXOSTYPE      mEnmOsType;
    RTCList<RTCString, RTCString *> mDetectedOSLanguages; /**< (only relevant for windows at the moment) */
    Utf8Str         mStrDetectedOSHints;
    RTCList<WIMImage> mDetectedImages;
    bool            mfAvoidUpdatesOverNetwork;
    /** @} */

    // wrapped IUnattended functions:

    /**
     * Checks what mStrIsoPath points to and sets the detectedOS* properties.
     */
    HRESULT detectIsoOS();

    /**
     * Prepare any data, environment, etc.
     */
    HRESULT prepare();

    /**
     * Prepare installation ISO/floppy.
     */
    HRESULT constructMedia();

    /**
     * Prepare a VM to run an unattended installation
     */
    HRESULT reconfigureVM();

    /**
     * Done with all media construction and VM configuration and stuff.
     */
    HRESULT done();

    // wrapped IUnattended attributes:
    HRESULT getIsoPath(com::Utf8Str &isoPath);
    HRESULT setIsoPath(const com::Utf8Str &isoPath);
    HRESULT getUser(com::Utf8Str &user);
    HRESULT setUser(const com::Utf8Str &user);
    HRESULT getPassword(com::Utf8Str &password);
    HRESULT setPassword(const com::Utf8Str &password);
    HRESULT getFullUserName(com::Utf8Str &user);
    HRESULT setFullUserName(const com::Utf8Str &user);
    HRESULT getProductKey(com::Utf8Str &productKey);
    HRESULT setProductKey(const com::Utf8Str &productKey);
    HRESULT getAdditionsIsoPath(com::Utf8Str &additionsIsoPath);
    HRESULT setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath);
    HRESULT getInstallGuestAdditions(BOOL *installGuestAdditions);
    HRESULT setInstallGuestAdditions(BOOL installGuestAdditions);
    HRESULT getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath);
    HRESULT setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath);
    HRESULT getInstallTestExecService(BOOL *aInstallTestExecService);
    HRESULT setInstallTestExecService(BOOL aInstallTestExecService);
    HRESULT getTimeZone(com::Utf8Str &aTimezone);
    HRESULT setTimeZone(const com::Utf8Str &aTimezone);
    HRESULT getLocale(com::Utf8Str &aLocale);
    HRESULT setLocale(const com::Utf8Str &aLocale);
    HRESULT getLanguage(com::Utf8Str &aLanguage);
    HRESULT setLanguage(const com::Utf8Str &aLanguage);
    HRESULT getCountry(com::Utf8Str &aCountry);
    HRESULT setCountry(const com::Utf8Str &aCountry);
    HRESULT getProxy(com::Utf8Str &aProxy);
    HRESULT setProxy(const com::Utf8Str &aProxy);
    HRESULT getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments);
    HRESULT setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments);
    HRESULT getHostname(com::Utf8Str &aHostname);
    HRESULT setHostname(const com::Utf8Str &aHostname);
    HRESULT getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath);
    HRESULT setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath);
    HRESULT getImageIndex(ULONG *index);
    HRESULT setImageIndex(ULONG index);
    HRESULT getMachine(ComPtr<IMachine> &aMachine);
    HRESULT setMachine(const ComPtr<IMachine> &aMachine);
    HRESULT getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath);
    HRESULT setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath);
    HRESULT getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath);
    HRESULT setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath);
    HRESULT getPostInstallCommand(com::Utf8Str &aPostInstallCommand);
    HRESULT setPostInstallCommand(const com::Utf8Str &aPostInstallCommand);
    HRESULT getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters);
    HRESULT setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters);
    HRESULT getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId);
    HRESULT getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion);
    HRESULT getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages);
    HRESULT getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor);
    HRESULT getDetectedOSHints(com::Utf8Str &aDetectedOSHints);
    HRESULT getDetectedImageNames(std::vector<com::Utf8Str> &aDetectedImageNames);
    HRESULT getDetectedImageIndices(std::vector<ULONG> &aDetectedImageIndices);
    HRESULT getIsUnattendedInstallSupported(BOOL *aIsUnattendedInstallSupported);
    HRESULT getAvoidUpdatesOverNetwork(BOOL *aAvoidUpdatesOverNetwork);
    HRESULT setAvoidUpdatesOverNetwork(BOOL aAvoidUpdatesOverNetwork);
    //internal functions

    /**
     * Worker for detectIsoOs().
     *
     * @returns COM status code.
     * @retval  S_OK if detected.
     * @retval  S_FALSE if not detected.
     *
     * @param   hVfsIso     The ISO file system handle.
     */
    HRESULT i_innerDetectIsoOS(RTVFS hVfsIso);
    typedef union DETECTBUFFER
    {
        char        sz[4096];
        char        ach[4096];
        uint8_t     ab[4096];
        uint32_t    au32[1024];
    } DETECTBUFFER;
    HRESULT i_innerDetectIsoOSWindows(RTVFS hVfsIso, DETECTBUFFER *puBuf);
    HRESULT i_innerDetectIsoOSLinux(RTVFS hVfsIso, DETECTBUFFER *puBuf);
    HRESULT i_innerDetectIsoOSLinuxFedora(RTVFS hVfsIso, DETECTBUFFER *puBuf, char *pszVolId);
    HRESULT i_innerDetectIsoOSOs2(RTVFS hVfsIso, DETECTBUFFER *puBuf);
    HRESULT i_innerDetectIsoOSFreeBsd(RTVFS hVfsIso, DETECTBUFFER *puBuf);

    /**
     * Worker for reconfigureVM().
     * The caller makes sure to close the session whatever happens.
     */
    HRESULT i_innerReconfigureVM(AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus,
                                 ComPtr<IMachine> const &rPtrSessionMachine);
    HRESULT i_reconfigureFloppy(com::SafeIfaceArray<IStorageController> &rControllers,
                                std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
                                ComPtr<IMachine> const &rPtrSessionMachine,
                                AutoMultiWriteLock2 &rAutoLock);
    HRESULT i_reconfigureIsos(com::SafeIfaceArray<IStorageController> &rControllers,
                              std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
                              ComPtr<IMachine> const &rPtrSessionMachine,
                              AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus);

    /**
     * Adds all free slots on the controller to @a rOutput.
     */
    HRESULT i_findOrCreateNeededFreeSlots(const Utf8Str &rStrControllerName, StorageBus_T enmStorageBus,
                                          ComPtr<IMachine> const &rPtrSessionMachine, uint32_t cSlotsNeeded,
                                          std::list<ControllerSlot> &rDvdSlots);

    /**
     * Attach to VM a disk
     */
    HRESULT i_attachImage(UnattendedInstallationDisk const *pImage, ComPtr<IMachine> const &rPtrSessionMachine,
                          AutoMultiWriteLock2 &rLock);

    /*
     * Wrapper functions
     */

    /**
     * Check whether guest is 64bit platform or not
     */
    bool i_isGuestOSArchX64(Utf8Str const &rStrGuestOsTypeId);

    /**
     * Updates the detected attributes when the image index or image list changes.
     *
     * @returns true if we've got all necessary stuff for a successful detection.
     */
    bool i_updateDetectedAttributeForImage(WIMImage const &rImage);

};

#endif /* !MAIN_INCLUDED_UnattendedImpl_h */