1 | /* $Id: VBoxManage.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxManage - VirtualBox command-line interface, internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2024 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 VBOX_INCLUDED_SRC_VBoxManage_VBoxManage_h
|
---|
29 | #define VBOX_INCLUDED_SRC_VBoxManage_VBoxManage_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <VBox/com/com.h>
|
---|
35 | #include <VBox/com/ptr.h>
|
---|
36 | #include <VBox/com/VirtualBox.h>
|
---|
37 | #include <VBox/com/string.h>
|
---|
38 | #include <VBox/com/array.h>
|
---|
39 |
|
---|
40 | #include <iprt/types.h>
|
---|
41 | #include <iprt/message.h>
|
---|
42 | #include <iprt/stream.h>
|
---|
43 | #include <iprt/getopt.h>
|
---|
44 |
|
---|
45 | #include "VBoxManageBuiltInHelp.h"
|
---|
46 | #include "PasswordInput.h"
|
---|
47 |
|
---|
48 | #ifdef VBOX_WITH_VBOXMANAGE_NLS
|
---|
49 | # include "VirtualBoxTranslator.h"
|
---|
50 | #endif
|
---|
51 |
|
---|
52 |
|
---|
53 | ////////////////////////////////////////////////////////////////////////////////
|
---|
54 | //
|
---|
55 | // definitions
|
---|
56 | //
|
---|
57 | ////////////////////////////////////////////////////////////////////////////////
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * This defines a a_CtxName::tr function that gives the translator context as
|
---|
61 | * well as providing a shorter way to call VirtualBoxTranslator::translate.
|
---|
62 | */
|
---|
63 | #ifdef VBOX_WITH_VBOXMANAGE_NLS
|
---|
64 | # define DECLARE_TRANSLATION_CONTEXT(a_CtxName) \
|
---|
65 | struct a_CtxName \
|
---|
66 | { \
|
---|
67 | static const char *tr(const char *pszSource, const char *pszComment = NULL, const size_t uNum = ~(size_t)0) \
|
---|
68 | { \
|
---|
69 | return VirtualBoxTranslator::translate(NULL, #a_CtxName, pszSource, pszComment, uNum); \
|
---|
70 | } \
|
---|
71 | }
|
---|
72 | #else
|
---|
73 | # define DECLARE_TRANSLATION_CONTEXT(a_CtxName) \
|
---|
74 | struct a_CtxName \
|
---|
75 | { \
|
---|
76 | static const char *tr(const char *pszSource, const char *pszComment = NULL, const size_t uNum = ~(size_t)0) \
|
---|
77 | { \
|
---|
78 | RT_NOREF(pszComment, uNum); \
|
---|
79 | return pszSource; \
|
---|
80 | } \
|
---|
81 | }
|
---|
82 | #endif
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Defines an option with two variants, producing two RTGETOPTDEF entries.
|
---|
86 | *
|
---|
87 | * This is mainly for replacing character-soup option names like
|
---|
88 | * --natlocalhostreachable and --biossystemtimeoffset with more easily parsed
|
---|
89 | * ones, like --nat-localhost-reachable and --bios-system-time-offset, without
|
---|
90 | * removing the legacy name.
|
---|
91 | */
|
---|
92 | #define OPT2(a_pszWordDashWord, a_pszWordSoup, a_chOptOrValue, a_fFlags) \
|
---|
93 | { a_pszWordDashWord, a_chOptOrValue, a_fFlags }, \
|
---|
94 | { a_pszWordSoup, a_chOptOrValue, a_fFlags }
|
---|
95 |
|
---|
96 | /** A single option variant of OPT2 for better looking tables. */
|
---|
97 | #define OPT1(a_pszOption, a_chOptOrValue, a_fFlags) \
|
---|
98 | { a_pszOption, a_chOptOrValue, a_fFlags }
|
---|
99 |
|
---|
100 |
|
---|
101 | /** command handler argument */
|
---|
102 | struct HandlerArg
|
---|
103 | {
|
---|
104 | int argc;
|
---|
105 | char **argv;
|
---|
106 |
|
---|
107 | ComPtr<IVirtualBox> virtualBox;
|
---|
108 | ComPtr<ISession> session;
|
---|
109 | };
|
---|
110 |
|
---|
111 |
|
---|
112 | /** showVMInfo details */
|
---|
113 | typedef enum
|
---|
114 | {
|
---|
115 | VMINFO_NONE = 0,
|
---|
116 | VMINFO_STANDARD = 1, /**< standard details */
|
---|
117 | VMINFO_FULL = 2, /**< both */
|
---|
118 | VMINFO_MACHINEREADABLE = 3, /**< both, and make it machine readable */
|
---|
119 | VMINFO_COMPACT = 4
|
---|
120 | } VMINFO_DETAILS;
|
---|
121 |
|
---|
122 |
|
---|
123 | ////////////////////////////////////////////////////////////////////////////////
|
---|
124 | //
|
---|
125 | // global variables
|
---|
126 | //
|
---|
127 | ////////////////////////////////////////////////////////////////////////////////
|
---|
128 |
|
---|
129 | extern bool g_fDetailedProgress; // in VBoxManage.cpp
|
---|
130 |
|
---|
131 |
|
---|
132 | ////////////////////////////////////////////////////////////////////////////////
|
---|
133 | //
|
---|
134 | // prototypes
|
---|
135 | //
|
---|
136 | ////////////////////////////////////////////////////////////////////////////////
|
---|
137 |
|
---|
138 | /* VBoxManageHelp.cpp */
|
---|
139 | void setCurrentCommand(enum HELP_CMD_VBOXMANAGE enmCommand);
|
---|
140 | void setCurrentSubcommand(uint64_t fCurSubcommandScope);
|
---|
141 |
|
---|
142 | void printUsage(PRTSTREAM pStrm);
|
---|
143 | void printHelp(PRTSTREAM pStrm);
|
---|
144 | RTEXITCODE errorNoSubcommand(void);
|
---|
145 | RTEXITCODE errorUnknownSubcommand(const char *pszSubCmd);
|
---|
146 | RTEXITCODE errorTooManyParameters(char **papszArgs);
|
---|
147 | RTEXITCODE errorGetOpt(int rcGetOpt, union RTGETOPTUNION const *pValueUnion);
|
---|
148 | RTEXITCODE errorFetchValue(int iValueNo, const char *pszOption, int rcGetOptFetchValue, union RTGETOPTUNION const *pValueUnion);
|
---|
149 | RTEXITCODE errorSyntax(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
150 | RTEXITCODE errorSyntaxV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
|
---|
151 | HRESULT errorSyntaxHr(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
152 | RTEXITCODE errorArgument(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
153 | HRESULT errorArgumentHr(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
154 |
|
---|
155 | # define SHOW_PROGRESS_NONE 0
|
---|
156 | # define SHOW_PROGRESS_DESC RT_BIT_32(0)
|
---|
157 | # define SHOW_PROGRESS RT_BIT_32(1)
|
---|
158 | /** Shows detailed information of the progress.
|
---|
159 | * Mutually exclusive with SHOW_PROGRESS_OPS. */
|
---|
160 | # define SHOW_PROGRESS_DETAILS RT_BIT_32(2)
|
---|
161 | /** Only shows the operation descriptions without other details.
|
---|
162 | * Mutually exclusive with SHOW_PROGRESS_DETAILS. */
|
---|
163 | # define SHOW_PROGRESS_OPS RT_BIT_32(3)
|
---|
164 | HRESULT showProgress(ComPtr<IProgress> progress, uint32_t fFlags = SHOW_PROGRESS);
|
---|
165 |
|
---|
166 | /* VBoxManage.cpp */
|
---|
167 | void showLogo(PRTSTREAM pStrm);
|
---|
168 |
|
---|
169 | /* VBoxInternalManage.cpp */
|
---|
170 | DECLHIDDEN(void) printUsageInternalCmds(PRTSTREAM pStrm);
|
---|
171 | RTEXITCODE handleInternalCommands(HandlerArg *a);
|
---|
172 |
|
---|
173 | /* VBoxManageControlVM.cpp */
|
---|
174 | RTEXITCODE handleControlVM(HandlerArg *a);
|
---|
175 |
|
---|
176 | /* VBoxManageModifyVM.cpp */
|
---|
177 | void parseGroups(const char *pcszGroups, com::SafeArray<BSTR> *pGroups);
|
---|
178 | #ifdef VBOX_WITH_RECORDING
|
---|
179 | int parseScreens(const char *pcszScreens, com::SafeArray<BOOL> *pScreens);
|
---|
180 | #endif
|
---|
181 | RTEXITCODE handleModifyVM(HandlerArg *a);
|
---|
182 | VMProcPriority_T nameToVMProcPriority(const char *pszName);
|
---|
183 |
|
---|
184 | /* VBoxManageDebugVM.cpp */
|
---|
185 | RTEXITCODE handleDebugVM(HandlerArg *a);
|
---|
186 |
|
---|
187 | /* VBoxManageGuestProp.cpp */
|
---|
188 | RTEXITCODE handleGuestProperty(HandlerArg *a);
|
---|
189 |
|
---|
190 | /* VBoxManageGuestCtrl.cpp */
|
---|
191 | RTEXITCODE handleGuestControl(HandlerArg *a);
|
---|
192 |
|
---|
193 | /* VBoxManageVMInfo.cpp */
|
---|
194 | HRESULT showSnapshots(ComPtr<ISnapshot> &rootSnapshot,
|
---|
195 | ComPtr<ISnapshot> ¤tSnapshot,
|
---|
196 | VMINFO_DETAILS details,
|
---|
197 | const com::Utf8Str &prefix = "",
|
---|
198 | int level = 0);
|
---|
199 | RTEXITCODE handleShowVMInfo(HandlerArg *a);
|
---|
200 | HRESULT showVMInfo(ComPtr<IVirtualBox> pVirtualBox,
|
---|
201 | ComPtr<IMachine> pMachine,
|
---|
202 | ComPtr<ISession> pSession,
|
---|
203 | VMINFO_DETAILS details = VMINFO_NONE);
|
---|
204 | const char *machineStateToName(MachineState_T machineState, bool fShort);
|
---|
205 | HRESULT showBandwidthGroups(ComPtr<IBandwidthControl> &bwCtrl,
|
---|
206 | VMINFO_DETAILS details);
|
---|
207 | void outputMachineReadableString(const char *pszName, const char *pszValue, bool fQuoteName = false, bool fNewline = true);
|
---|
208 | void outputMachineReadableString(const char *pszName, com::Bstr const *pbstrValue, bool fQuoteName = false, bool fNewline = true);
|
---|
209 | void outputMachineReadableStringWithFmtName(const char *pszValue, bool fQuoteName, const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(3, 4);
|
---|
210 | void outputMachineReadableStringWithFmtName(com::Bstr const *pbstrValue, bool fQuoteName, const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(3, 4);
|
---|
211 | void outputMachineReadableBool(const char *pszName, BOOL const *pfValue);
|
---|
212 | void outputMachineReadableBool(const char *pszName, bool const *pfValue);
|
---|
213 | void outputMachineReadableULong(const char *pszName, ULONG *uValue);
|
---|
214 | void outputMachineReadableLong64(const char *pszName, LONG64 *uValue);
|
---|
215 |
|
---|
216 | /* VBoxManageList.cpp */
|
---|
217 | RTEXITCODE handleList(HandlerArg *a);
|
---|
218 |
|
---|
219 | /* VBoxManageMetrics.cpp */
|
---|
220 | RTEXITCODE handleMetrics(HandlerArg *a);
|
---|
221 |
|
---|
222 | /* VBoxManageMisc.cpp */
|
---|
223 | RTEXITCODE handleRegisterVM(HandlerArg *a);
|
---|
224 | RTEXITCODE handleUnregisterVM(HandlerArg *a);
|
---|
225 | RTEXITCODE handleCreateVM(HandlerArg *a);
|
---|
226 | RTEXITCODE handleCloneVM(HandlerArg *a);
|
---|
227 | RTEXITCODE handleStartVM(HandlerArg *a);
|
---|
228 | #ifdef VBOX_WITH_FULL_VM_ENCRYPTION
|
---|
229 | RTEXITCODE handleEncryptVM(HandlerArg *a);
|
---|
230 | #endif
|
---|
231 | RTEXITCODE handleDiscardState(HandlerArg *a);
|
---|
232 | RTEXITCODE handleAdoptState(HandlerArg *a);
|
---|
233 | RTEXITCODE handleGetExtraData(HandlerArg *a);
|
---|
234 | RTEXITCODE handleSetExtraData(HandlerArg *a);
|
---|
235 | RTEXITCODE handleSetProperty(HandlerArg *a);
|
---|
236 | RTEXITCODE handleSharedFolder(HandlerArg *a);
|
---|
237 | RTEXITCODE handleExtPack(HandlerArg *a);
|
---|
238 | RTEXITCODE handleUnattended(HandlerArg *a);
|
---|
239 | RTEXITCODE handleMoveVM(HandlerArg *a);
|
---|
240 | RTEXITCODE handleCloudProfile(HandlerArg *a);
|
---|
241 |
|
---|
242 | /* VBoxManageDisk.cpp */
|
---|
243 | HRESULT openMedium(HandlerArg *a, const char *pszFilenameOrUuid,
|
---|
244 | DeviceType_T enmDevType, AccessMode_T enmAccessMode,
|
---|
245 | ComPtr<IMedium> &pMedium, bool fForceNewUuidOnOpen,
|
---|
246 | bool fSilent);
|
---|
247 | RTEXITCODE handleCreateMedium(HandlerArg *a);
|
---|
248 | RTEXITCODE handleModifyMedium(HandlerArg *a);
|
---|
249 | RTEXITCODE handleCloneMedium(HandlerArg *a);
|
---|
250 | RTEXITCODE handleMediumProperty(HandlerArg *a);
|
---|
251 | RTEXITCODE handleEncryptMedium(HandlerArg *a);
|
---|
252 | RTEXITCODE handleCheckMediumPassword(HandlerArg *a);
|
---|
253 | RTEXITCODE handleConvertFromRaw(HandlerArg *a);
|
---|
254 | HRESULT showMediumInfo(const ComPtr<IVirtualBox> &pVirtualBox,
|
---|
255 | const ComPtr<IMedium> &pMedium,
|
---|
256 | const char *pszParentUUID,
|
---|
257 | bool fOptLong);
|
---|
258 | RTEXITCODE handleShowMediumInfo(HandlerArg *a);
|
---|
259 | RTEXITCODE handleCloseMedium(HandlerArg *a);
|
---|
260 | RTEXITCODE handleMediumIO(HandlerArg *a);
|
---|
261 | int parseMediumType(const char *psz, MediumType_T *penmMediumType);
|
---|
262 | int parseBool(const char *psz, bool *pb);
|
---|
263 |
|
---|
264 | /* VBoxManageStorageController.cpp */
|
---|
265 | RTEXITCODE handleStorageAttach(HandlerArg *a);
|
---|
266 | RTEXITCODE handleStorageController(HandlerArg *a);
|
---|
267 |
|
---|
268 | // VBoxManageAppliance.cpp
|
---|
269 | RTEXITCODE handleImportAppliance(HandlerArg *a);
|
---|
270 | RTEXITCODE handleExportAppliance(HandlerArg *a);
|
---|
271 | RTEXITCODE handleSignAppliance(HandlerArg *a);
|
---|
272 |
|
---|
273 | // VBoxManageSnapshot.cpp
|
---|
274 | RTEXITCODE handleSnapshot(HandlerArg *a);
|
---|
275 |
|
---|
276 | /* VBoxManageUSB.cpp */
|
---|
277 | RTEXITCODE handleUSBFilter(HandlerArg *a);
|
---|
278 | RTEXITCODE handleUSBDevSource(HandlerArg *a);
|
---|
279 |
|
---|
280 | /* VBoxManageHostonly.cpp */
|
---|
281 | RTEXITCODE handleHostonlyIf(HandlerArg *a);
|
---|
282 | #ifdef VBOX_WITH_VMNET
|
---|
283 | RTEXITCODE handleHostonlyNet(HandlerArg *a);
|
---|
284 | #endif /* VBOX_WITH_VMNET */
|
---|
285 |
|
---|
286 | /* VBoxManageDHCPServer.cpp */
|
---|
287 | RTEXITCODE handleDHCPServer(HandlerArg *a);
|
---|
288 |
|
---|
289 | /* VBoxManageNATNetwork.cpp */
|
---|
290 | RTEXITCODE handleNATNetwork(HandlerArg *a);
|
---|
291 | RTEXITCODE listNATNetworks(bool fLong, bool fSorted,
|
---|
292 | const ComPtr<IVirtualBox> &pVirtualBox);
|
---|
293 |
|
---|
294 | /* VBoxManageBandwidthControl.cpp */
|
---|
295 | RTEXITCODE handleBandwidthControl(HandlerArg *a);
|
---|
296 |
|
---|
297 | /* VBoxManageCloud.cpp */
|
---|
298 | RTEXITCODE handleCloud(HandlerArg *a);
|
---|
299 |
|
---|
300 | /* VBoxManageCloudMachine.cpp */
|
---|
301 | RTEXITCODE handleCloudMachine(HandlerArg *a, int iFirst,
|
---|
302 | const char *pcszProviderName,
|
---|
303 | const char *pcszProfileName);
|
---|
304 | RTEXITCODE listCloudMachines(HandlerArg *a, int iFirst,
|
---|
305 | const char *pcszProviderName,
|
---|
306 | const char *pcszProfileName);
|
---|
307 | RTEXITCODE handleCloudShowVMInfo(HandlerArg *a, int iFirst,
|
---|
308 | const char *pcszProviderName,
|
---|
309 | const char *pcszProfileName);
|
---|
310 |
|
---|
311 | #ifdef VBOX_WITH_UPDATE_AGENT
|
---|
312 | /* VBoxManageUpdateCheck.cpp */
|
---|
313 | RTEXITCODE handleUpdateCheck(HandlerArg *a);
|
---|
314 | #endif
|
---|
315 |
|
---|
316 | /* VBoxManageModifyNvram.cpp */
|
---|
317 | RTEXITCODE handleModifyNvram(HandlerArg *a);
|
---|
318 |
|
---|
319 | #endif /* !VBOX_INCLUDED_SRC_VBoxManage_VBoxManage_h */
|
---|