VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/hardenedmain.cpp

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: hardenedmain.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Hardened main().
4 */
5
6/*
7 * Copyright (C) 2008-2023 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#include <VBox/sup.h>
29
30
31/**
32 * No CRT on windows, so cook our own strcmp.
33 *
34 * @returns See man strcmp.
35 * @param psz1 The first string.
36 * @param psz2 The second string.
37 */
38static int MyStrCmp(const char *psz1, const char *psz2)
39{
40 for (;;)
41 {
42 char ch1 = *psz1++;
43 char ch2 = *psz2++;
44 if (ch1 != ch2)
45 return ch1 < ch2 ? -1 : 1;
46 if (!ch1)
47 return 0;
48 }
49}
50
51
52int main(int argc, char **argv, char **envp)
53{
54 /*
55 * Do partial option parsing to see if we're starting a VM and how we're
56 * going about that.
57 *
58 * Note! This must must match the corresponding parsing in main.cpp and
59 * UICommon.cpp exactly, otherwise there will be weird error messages.
60 *
61 * Note! ASSUMES that argv is in an ASCII compatible codeset.
62 */
63 unsigned cOptionsLeft = 4;
64 bool fStartVM = false;
65 bool fSeparateProcess = false;
66 bool fExecuteAllInIem = false;
67 bool fDriverless = false;
68 for (int i = 1; i < argc && cOptionsLeft > 0; ++i)
69 {
70 if ( !MyStrCmp(argv[i], "--startvm")
71 || !MyStrCmp(argv[i], "-startvm"))
72 {
73 cOptionsLeft -= fStartVM == false;
74 fStartVM = true;
75 i++;
76 }
77 else if ( !MyStrCmp(argv[i], "--separate")
78 || !MyStrCmp(argv[i], "-separate"))
79 {
80 cOptionsLeft -= fSeparateProcess == false;
81 fSeparateProcess = true;
82 }
83 else if (!MyStrCmp(argv[i], "--execute-all-in-iem"))
84 {
85 cOptionsLeft -= fExecuteAllInIem == false;
86 fExecuteAllInIem = true;
87 }
88 else if (!MyStrCmp(argv[i], "--driverless"))
89 {
90 cOptionsLeft -= fDriverless == false;
91 fDriverless = true;
92 }
93 }
94
95 /*
96 * Convert the command line options to SUPSECMAIN_FLAGS_XXX flags
97 * and call the hardened main code.
98 */
99 uint32_t fFlags = SUPSECMAIN_FLAGS_TRUSTED_ERROR;
100#ifdef RT_OS_DARWIN
101 fFlags |= SUPSECMAIN_FLAGS_LOC_OSX_HLP_APP;
102#endif
103 if (!fStartVM || fSeparateProcess)
104 fFlags |= SUPSECMAIN_FLAGS_DONT_OPEN_DEV;
105 else
106 {
107 if (fExecuteAllInIem)
108 fFlags |= SUPSECMAIN_FLAGS_DRIVERLESS_IEM_ALLOWED;
109#ifdef VBOX_WITH_DRIVERLESS_NEM_FALLBACK
110 else
111 fFlags |= SUPSECMAIN_FLAGS_DRIVERLESS_NEM_FALLBACK;
112#endif
113 if (fDriverless)
114 fFlags |= SUPSECMAIN_FLAGS_DRIVERLESS;
115 }
116
117 return SUPR3HardenedMain("VirtualBoxVM", fFlags, argc, argv, envp);
118}
119
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use