[11725] | 1 | /* $Id: hardenedmain.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[52722] | 3 | * VBox Qt GUI - Hardened main().
|
---|
[11725] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2008-2023 Oracle and/or its affiliates.
|
---|
[11725] | 8 | *
|
---|
[96407] | 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
|
---|
[11725] | 26 | */
|
---|
| 27 |
|
---|
| 28 | #include <VBox/sup.h>
|
---|
| 29 |
|
---|
| 30 |
|
---|
[49892] | 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 | */
|
---|
| 38 | static 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 |
|
---|
[11725] | 52 | int main(int argc, char **argv, char **envp)
|
---|
| 53 | {
|
---|
[92613] | 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 | */
|
---|
[92699] | 63 | unsigned cOptionsLeft = 4;
|
---|
[92613] | 64 | bool fStartVM = false;
|
---|
| 65 | bool fSeparateProcess = false;
|
---|
| 66 | bool fExecuteAllInIem = false;
|
---|
[92699] | 67 | bool fDriverless = false;
|
---|
[92613] | 68 | for (int i = 1; i < argc && cOptionsLeft > 0; ++i)
|
---|
[52894] | 69 | {
|
---|
[49892] | 70 | if ( !MyStrCmp(argv[i], "--startvm")
|
---|
| 71 | || !MyStrCmp(argv[i], "-startvm"))
|
---|
[11725] | 72 | {
|
---|
[92613] | 73 | cOptionsLeft -= fStartVM == false;
|
---|
[52894] | 74 | fStartVM = true;
|
---|
[92613] | 75 | i++;
|
---|
[11725] | 76 | }
|
---|
[52894] | 77 | else if ( !MyStrCmp(argv[i], "--separate")
|
---|
| 78 | || !MyStrCmp(argv[i], "-separate"))
|
---|
| 79 | {
|
---|
[92613] | 80 | cOptionsLeft -= fSeparateProcess == false;
|
---|
[52902] | 81 | fSeparateProcess = true;
|
---|
[52894] | 82 | }
|
---|
[92613] | 83 | else if (!MyStrCmp(argv[i], "--execute-all-in-iem"))
|
---|
| 84 | {
|
---|
| 85 | cOptionsLeft -= fExecuteAllInIem == false;
|
---|
| 86 | fExecuteAllInIem = true;
|
---|
| 87 | }
|
---|
[92699] | 88 | else if (!MyStrCmp(argv[i], "--driverless"))
|
---|
| 89 | {
|
---|
| 90 | cOptionsLeft -= fDriverless == false;
|
---|
| 91 | fDriverless = true;
|
---|
| 92 | }
|
---|
[52894] | 93 | }
|
---|
[11725] | 94 |
|
---|
[92613] | 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;
|
---|
[83033] | 100 | #ifdef RT_OS_DARWIN
|
---|
| 101 | fFlags |= SUPSECMAIN_FLAGS_LOC_OSX_HLP_APP;
|
---|
| 102 | #endif
|
---|
[92613] | 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
|
---|
[92699] | 113 | if (fDriverless)
|
---|
| 114 | fFlags |= SUPSECMAIN_FLAGS_DRIVERLESS;
|
---|
[92613] | 115 | }
|
---|
[52894] | 116 |
|
---|
[92613] | 117 | return SUPR3HardenedMain("VirtualBoxVM", fFlags, argc, argv, envp);
|
---|
[11725] | 118 | }
|
---|
| 119 |
|
---|