[40415] | 1 | /* $Id: VBoxGuestR3LibAutoLogon.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
[40211] | 2 | /** @file
|
---|
| 3 | * VBoxGuestR3LibAutoLogon - Ring-3 utility functions for auto-logon modules
|
---|
[40415] | 4 | * (VBoxGINA / VBoxCredProv / pam_vbox).
|
---|
[40211] | 5 | */
|
---|
| 6 |
|
---|
| 7 | /*
|
---|
[98103] | 8 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
[40211] | 9 | *
|
---|
[96407] | 10 | * This file is part of VirtualBox base platform packages, as
|
---|
| 11 | * available from https://www.virtualbox.org.
|
---|
[40211] | 12 | *
|
---|
[96407] | 13 | * This program is free software; you can redistribute it and/or
|
---|
| 14 | * modify it under the terms of the GNU General Public License
|
---|
| 15 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 16 | * License.
|
---|
| 17 | *
|
---|
| 18 | * This program is distributed in the hope that it will be useful, but
|
---|
| 19 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 21 | * General Public License for more details.
|
---|
| 22 | *
|
---|
| 23 | * You should have received a copy of the GNU General Public License
|
---|
| 24 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 25 | *
|
---|
[40211] | 26 | * The contents of this file may alternatively be used under the terms
|
---|
| 27 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 28 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 29 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
[40211] | 30 | * CDDL are applicable instead of those of the GPL.
|
---|
| 31 | *
|
---|
| 32 | * You may elect to license modified versions of this file under the
|
---|
| 33 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[96407] | 34 | *
|
---|
| 35 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[40211] | 36 | */
|
---|
| 37 |
|
---|
| 38 |
|
---|
[57358] | 39 | /*********************************************************************************************************************************
|
---|
| 40 | * Header Files *
|
---|
| 41 | *********************************************************************************************************************************/
|
---|
[40415] | 42 | #ifdef RT_OS_WINDOWS
|
---|
[62679] | 43 | # include <iprt/win/windows.h>
|
---|
[40415] | 44 | #endif
|
---|
[40211] | 45 |
|
---|
[68650] | 46 | #include "VBoxGuestR3LibInternal.h"
|
---|
[76474] | 47 | #include <iprt/errcore.h>
|
---|
[40211] | 48 |
|
---|
| 49 |
|
---|
| 50 | /**
|
---|
| 51 | * Reports the current auto-logon status to the host.
|
---|
| 52 | *
|
---|
| 53 | * This makes sure that the Failed state is sticky.
|
---|
| 54 | *
|
---|
| 55 | * @return IPRT status code.
|
---|
| 56 | * @param enmStatus Status to report to the host.
|
---|
| 57 | */
|
---|
| 58 | VBGLR3DECL(int) VbglR3AutoLogonReportStatus(VBoxGuestFacilityStatus enmStatus)
|
---|
| 59 | {
|
---|
| 60 | /*
|
---|
| 61 | * VBoxGuestFacilityStatus_Failed is sticky.
|
---|
| 62 | */
|
---|
| 63 | static VBoxGuestFacilityStatus s_enmLastStatus = VBoxGuestFacilityStatus_Inactive;
|
---|
| 64 | if (s_enmLastStatus != VBoxGuestFacilityStatus_Failed)
|
---|
| 65 | {
|
---|
[58183] | 66 | int rc = VbglR3ReportAdditionsStatus(VBoxGuestFacilityType_AutoLogon, enmStatus, 0 /* Flags */);
|
---|
[40414] | 67 | if (rc == VERR_NOT_SUPPORTED)
|
---|
| 68 | {
|
---|
| 69 | /*
|
---|
| 70 | * To maintain backwards compatibility to older hosts which don't have
|
---|
| 71 | * VMMDevReportGuestStatus implemented we set the appropriate status via
|
---|
| 72 | * guest property to have at least something.
|
---|
| 73 | */
|
---|
[41474] | 74 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
[58183] | 75 | HGCMCLIENTID idClient = 0;
|
---|
| 76 | rc = VbglR3GuestPropConnect(&idClient);
|
---|
[40414] | 77 | if (RT_SUCCESS(rc))
|
---|
| 78 | {
|
---|
[40415] | 79 | const char *pszStatus;
|
---|
[40414] | 80 | switch (enmStatus)
|
---|
| 81 | {
|
---|
[40415] | 82 | case VBoxGuestFacilityStatus_Inactive: pszStatus = "Inactive"; break;
|
---|
| 83 | case VBoxGuestFacilityStatus_Paused: pszStatus = "Disabled"; break;
|
---|
| 84 | case VBoxGuestFacilityStatus_PreInit: pszStatus = "PreInit"; break;
|
---|
| 85 | case VBoxGuestFacilityStatus_Init: pszStatus = "Init"; break;
|
---|
| 86 | case VBoxGuestFacilityStatus_Active: pszStatus = "Active"; break;
|
---|
| 87 | case VBoxGuestFacilityStatus_Terminating: pszStatus = "Terminating"; break;
|
---|
| 88 | case VBoxGuestFacilityStatus_Terminated: pszStatus = "Terminated"; break;
|
---|
| 89 | case VBoxGuestFacilityStatus_Failed: pszStatus = "Failed"; break;
|
---|
| 90 | default: pszStatus = NULL;
|
---|
[40414] | 91 | }
|
---|
[40415] | 92 | if (pszStatus)
|
---|
[40414] | 93 | {
|
---|
| 94 | /*
|
---|
[40415] | 95 | * Use TRANSRESET when possible, fall back to TRANSIENT
|
---|
| 96 | * (generally sufficient unless the guest misbehaves).
|
---|
[40414] | 97 | */
|
---|
[40415] | 98 | static const char s_szPath[] = "/VirtualBox/GuestInfo/OS/AutoLogonStatus";
|
---|
[58183] | 99 | rc = VbglR3GuestPropWrite(idClient, s_szPath, pszStatus, "TRANSRESET");
|
---|
[40414] | 100 | if (rc == VERR_PARSE_ERROR)
|
---|
[58183] | 101 | rc = VbglR3GuestPropWrite(idClient, s_szPath, pszStatus, "TRANSIENT");
|
---|
[40414] | 102 | }
|
---|
| 103 | else
|
---|
| 104 | rc = VERR_INVALID_PARAMETER;
|
---|
| 105 |
|
---|
[58183] | 106 | VbglR3GuestPropDisconnect(idClient);
|
---|
[40414] | 107 | }
|
---|
[41474] | 108 | #endif
|
---|
[40414] | 109 | }
|
---|
| 110 |
|
---|
[40211] | 111 | s_enmLastStatus = enmStatus;
|
---|
| 112 | }
|
---|
| 113 | return VINF_SUCCESS;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 |
|
---|
| 117 | /**
|
---|
| 118 | * Detects whether our process is running in a remote session or not.
|
---|
| 119 | *
|
---|
| 120 | * @return bool true if running in a remote session, false if not.
|
---|
| 121 | */
|
---|
| 122 | VBGLR3DECL(bool) VbglR3AutoLogonIsRemoteSession(void)
|
---|
| 123 | {
|
---|
| 124 | #ifdef RT_OS_WINDOWS
|
---|
[40415] | 125 | return GetSystemMetrics(SM_REMOTESESSION) != 0 ? true : false;
|
---|
[40211] | 126 | #else
|
---|
| 127 | return false; /* Not implemented. */
|
---|
| 128 | #endif
|
---|
| 129 | }
|
---|
| 130 |
|
---|