[40435] | 1 | /* $Id: VBoxCredProvUtils.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * VBoxCredProvUtils - Misc. utility functions for VBoxCredProv.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
[40435] | 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
|
---|
[40435] | 26 | */
|
---|
| 27 |
|
---|
[57358] | 28 |
|
---|
| 29 | /*********************************************************************************************************************************
|
---|
| 30 | * Header Files *
|
---|
| 31 | *********************************************************************************************************************************/
|
---|
[62679] | 32 | #include <iprt/win/windows.h>
|
---|
[67772] | 33 |
|
---|
[67787] | 34 | #include <iprt/string.h>
|
---|
| 35 | #include <VBox/log.h>
|
---|
[67772] | 36 | #ifdef LOG_ENABLED
|
---|
| 37 | # include <iprt/stream.h>
|
---|
| 38 | #endif
|
---|
[50323] | 39 | #include <VBox/VBoxGuestLib.h>
|
---|
[40435] | 40 |
|
---|
| 41 |
|
---|
[57358] | 42 | /*********************************************************************************************************************************
|
---|
| 43 | * Global Variables *
|
---|
| 44 | *********************************************************************************************************************************/
|
---|
[40435] | 45 | /** Verbosity flag for guest logging. */
|
---|
| 46 | DWORD g_dwVerbosity = 0;
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | /**
|
---|
| 50 | * Displays a verbose message.
|
---|
| 51 | *
|
---|
[65122] | 52 | * @param dwLevel Minimum log level required to display this message.
|
---|
[40435] | 53 | * @param pszFormat The message text.
|
---|
| 54 | * @param ... Format arguments.
|
---|
| 55 | */
|
---|
| 56 | void VBoxCredProvVerbose(DWORD dwLevel, const char *pszFormat, ...)
|
---|
| 57 | {
|
---|
| 58 | if (dwLevel <= g_dwVerbosity)
|
---|
| 59 | {
|
---|
| 60 | va_list args;
|
---|
| 61 | va_start(args, pszFormat);
|
---|
| 62 | char *psz = NULL;
|
---|
| 63 | RTStrAPrintfV(&psz, pszFormat, args);
|
---|
| 64 | va_end(args);
|
---|
| 65 |
|
---|
| 66 | AssertPtr(psz);
|
---|
| 67 | LogRel(("%s", psz));
|
---|
| 68 |
|
---|
[67772] | 69 | #ifdef LOG_ENABLED
|
---|
| 70 | PRTSTREAM pStream;
|
---|
| 71 | int rc2 = RTStrmOpen("C:\\VBoxCredProvLog.txt", "a", &pStream);
|
---|
| 72 | if (RT_SUCCESS(rc2))
|
---|
| 73 | {
|
---|
| 74 | RTStrmPrintf(pStream, "%s", psz);
|
---|
| 75 | RTStrmClose(pStream);
|
---|
| 76 | }
|
---|
| 77 | #endif
|
---|
[40435] | 78 | RTStrFree(psz);
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | /**
|
---|
| 84 | * Reports VBoxGINA's status to the host (treated as a guest facility).
|
---|
| 85 | *
|
---|
| 86 | * @return IPRT status code.
|
---|
| 87 | * @param enmStatus Status to report to the host.
|
---|
| 88 | */
|
---|
| 89 | int VBoxCredProvReportStatus(VBoxGuestFacilityStatus enmStatus)
|
---|
| 90 | {
|
---|
| 91 | VBoxCredProvVerbose(0, "VBoxCredProv: reporting status %d\n", enmStatus);
|
---|
| 92 |
|
---|
| 93 | int rc = VbglR3AutoLogonReportStatus(enmStatus);
|
---|
| 94 | if (RT_FAILURE(rc))
|
---|
| 95 | VBoxCredProvVerbose(0, "VBoxCredProv: failed to report status %d, rc=%Rrc\n", enmStatus, rc);
|
---|
| 96 | return rc;
|
---|
| 97 | }
|
---|
| 98 |
|
---|