VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibAutoLogon.cpp@ 40415

Last change on this file since 40415 was 40415, checked in by vboxsync, 13 years ago

VbgR3AutoLogonReportStatus: Drop the unnecessary RTStrPrintf and RTPATH_MAX buffering, just use a pointer to a const string.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: VBoxGuestR3LibAutoLogon.cpp 40415 2012-03-09 15:44:31Z 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 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * The contents of this file may alternatively be used under the terms
19 * of the Common Development and Distribution License Version 1.0
20 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
21 * VirtualBox OSE distribution, in which case the provisions of the
22 * CDDL are applicable instead of those of the GPL.
23 *
24 * You may elect to license modified versions of this file under the
25 * terms and conditions of either the GPL or the CDDL or both.
26 */
27
28
29/*******************************************************************************
30* Header Files *
31*******************************************************************************/
32#ifdef RT_OS_WINDOWS
33# include <Windows.h>
34#endif
35
36#include "VBGLR3Internal.h"
37
38
39/**
40 * Reports the current auto-logon status to the host.
41 *
42 * This makes sure that the Failed state is sticky.
43 *
44 * @return IPRT status code.
45 * @param enmStatus Status to report to the host.
46 */
47VBGLR3DECL(int) VbglR3AutoLogonReportStatus(VBoxGuestFacilityStatus enmStatus)
48{
49 /*
50 * VBoxGuestFacilityStatus_Failed is sticky.
51 */
52 static VBoxGuestFacilityStatus s_enmLastStatus = VBoxGuestFacilityStatus_Inactive;
53 if (s_enmLastStatus != VBoxGuestFacilityStatus_Failed)
54 {
55 int rc = VbglR3ReportAdditionsStatus(VBoxGuestFacilityType_AutoLogon,
56 enmStatus, 0 /* Flags */);
57 if (rc == VERR_NOT_SUPPORTED)
58 {
59 /*
60 * To maintain backwards compatibility to older hosts which don't have
61 * VMMDevReportGuestStatus implemented we set the appropriate status via
62 * guest property to have at least something.
63 */
64 uint32_t u32ClientId = 0;
65 rc = VbglR3GuestPropConnect(&u32ClientId);
66 if (RT_SUCCESS(rc))
67 {
68 const char *pszStatus;
69 switch (enmStatus)
70 {
71 case VBoxGuestFacilityStatus_Inactive: pszStatus = "Inactive"; break;
72 case VBoxGuestFacilityStatus_Paused: pszStatus = "Disabled"; break;
73 case VBoxGuestFacilityStatus_PreInit: pszStatus = "PreInit"; break;
74 case VBoxGuestFacilityStatus_Init: pszStatus = "Init"; break;
75 case VBoxGuestFacilityStatus_Active: pszStatus = "Active"; break;
76 case VBoxGuestFacilityStatus_Terminating: pszStatus = "Terminating"; break;
77 case VBoxGuestFacilityStatus_Terminated: pszStatus = "Terminated"; break;
78 case VBoxGuestFacilityStatus_Failed: pszStatus = "Failed"; break;
79 default: pszStatus = NULL;
80 }
81 if (pszStatus)
82 {
83 /*
84 * Use TRANSRESET when possible, fall back to TRANSIENT
85 * (generally sufficient unless the guest misbehaves).
86 */
87 static const char s_szPath[] = "/VirtualBox/GuestInfo/OS/AutoLogonStatus";
88 rc = VbglR3GuestPropWrite(u32ClientId, s_szPath, pszStatus, "TRANSRESET");
89 if (rc == VERR_PARSE_ERROR)
90 rc = VbglR3GuestPropWrite(u32ClientId, s_szPath, pszStatus, "TRANSIENT");
91 }
92 else
93 rc = VERR_INVALID_PARAMETER;
94
95 VbglR3GuestPropDisconnect(u32ClientId);
96 }
97 }
98
99 s_enmLastStatus = enmStatus;
100 }
101 return VINF_SUCCESS;
102}
103
104
105/**
106 * Detects whether our process is running in a remote session or not.
107 *
108 * @return bool true if running in a remote session, false if not.
109 */
110VBGLR3DECL(bool) VbglR3AutoLogonIsRemoteSession(void)
111{
112#ifdef RT_OS_WINDOWS
113 return GetSystemMetrics(SM_REMOTESESSION) != 0 ? true : false;
114#else
115 return false; /* Not implemented. */
116#endif
117}
118
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette