VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibAutoLogon.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: 5.1 KB
Line 
1/* $Id: VBoxGuestR3LibAutoLogon.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBoxGuestR3LibAutoLogon - Ring-3 utility functions for auto-logon modules
4 * (VBoxGINA / VBoxCredProv / pam_vbox).
5 */
6
7/*
8 * Copyright (C) 2012-2023 Oracle and/or its affiliates.
9 *
10 * This file is part of VirtualBox base platform packages, as
11 * available from https://www.virtualbox.org.
12 *
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 *
26 * The contents of this file may alternatively be used under the terms
27 * of the Common Development and Distribution License Version 1.0
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
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.
34 *
35 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
36 */
37
38
39/*********************************************************************************************************************************
40* Header Files *
41*********************************************************************************************************************************/
42#ifdef RT_OS_WINDOWS
43# include <iprt/win/windows.h>
44#endif
45
46#include "VBoxGuestR3LibInternal.h"
47#include <iprt/errcore.h>
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 */
58VBGLR3DECL(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 {
66 int rc = VbglR3ReportAdditionsStatus(VBoxGuestFacilityType_AutoLogon, enmStatus, 0 /* Flags */);
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 */
74#ifdef VBOX_WITH_GUEST_PROPS
75 HGCMCLIENTID idClient = 0;
76 rc = VbglR3GuestPropConnect(&idClient);
77 if (RT_SUCCESS(rc))
78 {
79 const char *pszStatus;
80 switch (enmStatus)
81 {
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;
91 }
92 if (pszStatus)
93 {
94 /*
95 * Use TRANSRESET when possible, fall back to TRANSIENT
96 * (generally sufficient unless the guest misbehaves).
97 */
98 static const char s_szPath[] = "/VirtualBox/GuestInfo/OS/AutoLogonStatus";
99 rc = VbglR3GuestPropWrite(idClient, s_szPath, pszStatus, "TRANSRESET");
100 if (rc == VERR_PARSE_ERROR)
101 rc = VbglR3GuestPropWrite(idClient, s_szPath, pszStatus, "TRANSIENT");
102 }
103 else
104 rc = VERR_INVALID_PARAMETER;
105
106 VbglR3GuestPropDisconnect(idClient);
107 }
108#endif
109 }
110
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 */
122VBGLR3DECL(bool) VbglR3AutoLogonIsRemoteSession(void)
123{
124#ifdef RT_OS_WINDOWS
125 return GetSystemMetrics(SM_REMOTESESSION) != 0 ? true : false;
126#else
127 return false; /* Not implemented. */
128#endif
129}
130
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use