1 | /* $Id */
|
---|
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 | #include <iprt/asm.h>
|
---|
33 | #include <iprt/mem.h>
|
---|
34 | #include <iprt/rand.h>
|
---|
35 | #include <iprt/string.h>
|
---|
36 | #include <VBox/log.h>
|
---|
37 |
|
---|
38 | #include "VBGLR3Internal.h"
|
---|
39 |
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Reports the current auto-logon status to the host.
|
---|
43 | *
|
---|
44 | * This makes sure that the Failed state is sticky.
|
---|
45 | *
|
---|
46 | * @return IPRT status code.
|
---|
47 | * @param enmStatus Status to report to the host.
|
---|
48 | */
|
---|
49 | VBGLR3DECL(int) VbglR3AutoLogonReportStatus(VBoxGuestFacilityStatus enmStatus)
|
---|
50 | {
|
---|
51 | /*
|
---|
52 | * VBoxGuestFacilityStatus_Failed is sticky.
|
---|
53 | */
|
---|
54 | static VBoxGuestFacilityStatus s_enmLastStatus = VBoxGuestFacilityStatus_Inactive;
|
---|
55 | if (s_enmLastStatus != VBoxGuestFacilityStatus_Failed)
|
---|
56 | {
|
---|
57 | int rc = VbglR3ReportAdditionsStatus(VBoxGuestFacilityType_AutoLogon,
|
---|
58 | enmStatus, 0 /* Flags */);
|
---|
59 | if (rc == VERR_NOT_SUPPORTED)
|
---|
60 | {
|
---|
61 | /*
|
---|
62 | * To maintain backwards compatibility to older hosts which don't have
|
---|
63 | * VMMDevReportGuestStatus implemented we set the appropriate status via
|
---|
64 | * guest property to have at least something.
|
---|
65 | */
|
---|
66 | uint32_t u32ClientId = 0;
|
---|
67 | rc = VbglR3GuestPropConnect(&u32ClientId);
|
---|
68 | if (RT_SUCCESS(rc))
|
---|
69 | {
|
---|
70 | /** @todo Move VBoxGuestStatusCurrent -> const char* to an own function. */
|
---|
71 | char szStatus[RTPATH_MAX];
|
---|
72 | size_t cbRet = 0;
|
---|
73 | switch (enmStatus)
|
---|
74 | {
|
---|
75 | case VBoxGuestFacilityStatus_Inactive:
|
---|
76 | cbRet = RTStrPrintf(szStatus, sizeof(szStatus), "Inactive");
|
---|
77 | break;
|
---|
78 | case VBoxGuestFacilityStatus_Paused:
|
---|
79 | cbRet = RTStrPrintf(szStatus, sizeof(szStatus), "Disabled");
|
---|
80 | break;
|
---|
81 | case VBoxGuestFacilityStatus_PreInit:
|
---|
82 | cbRet = RTStrPrintf(szStatus, sizeof(szStatus), "PreInit");
|
---|
83 | break;
|
---|
84 | case VBoxGuestFacilityStatus_Init:
|
---|
85 | cbRet = RTStrPrintf(szStatus, sizeof(szStatus), "Init");
|
---|
86 | break;
|
---|
87 | case VBoxGuestFacilityStatus_Active:
|
---|
88 | cbRet = RTStrPrintf(szStatus, sizeof(szStatus), "Active");
|
---|
89 | break;
|
---|
90 | case VBoxGuestFacilityStatus_Terminating:
|
---|
91 | cbRet = RTStrPrintf(szStatus, sizeof(szStatus), "Terminating");
|
---|
92 | break;
|
---|
93 | case VBoxGuestFacilityStatus_Terminated:
|
---|
94 | cbRet = RTStrPrintf(szStatus, sizeof(szStatus), "Terminated");
|
---|
95 | break;
|
---|
96 | case VBoxGuestFacilityStatus_Failed:
|
---|
97 | cbRet = RTStrPrintf(szStatus, sizeof(szStatus), "Failed");
|
---|
98 | break;
|
---|
99 | default:
|
---|
100 | /* cbRet will be 0. */
|
---|
101 | break;
|
---|
102 | }
|
---|
103 |
|
---|
104 | if (cbRet)
|
---|
105 | {
|
---|
106 | const char szPath[] = "/VirtualBox/GuestInfo/OS/AutoLogonStatus";
|
---|
107 |
|
---|
108 | /*
|
---|
109 | * Because a value can be temporary we have to make sure it also
|
---|
110 | * gets deleted when the property cache did not have the chance to
|
---|
111 | * gracefully clean it up (due to a hard VM reset etc), so set this
|
---|
112 | * guest property using the TRANSRESET flag..
|
---|
113 | */
|
---|
114 | rc = VbglR3GuestPropWrite(u32ClientId, szPath, szStatus, "TRANSRESET");
|
---|
115 | if (rc == VERR_PARSE_ERROR)
|
---|
116 | {
|
---|
117 | /* Host does not support the "TRANSRESET" flag, so only
|
---|
118 | * use the "TRANSIENT" flag -- better than nothing :-). */
|
---|
119 | rc = VbglR3GuestPropWrite(u32ClientId, szPath, szStatus, "TRANSIENT");
|
---|
120 | }
|
---|
121 | }
|
---|
122 | else
|
---|
123 | rc = VERR_INVALID_PARAMETER;
|
---|
124 |
|
---|
125 | VbglR3GuestPropDisconnect(u32ClientId);
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | s_enmLastStatus = enmStatus;
|
---|
130 | }
|
---|
131 | return VINF_SUCCESS;
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * Detects whether our process is running in a remote session or not.
|
---|
137 | *
|
---|
138 | * @return bool true if running in a remote session, false if not.
|
---|
139 | */
|
---|
140 | VBGLR3DECL(bool) VbglR3AutoLogonIsRemoteSession(void)
|
---|
141 | {
|
---|
142 | #ifdef RT_OS_WINDOWS
|
---|
143 | return (0 != GetSystemMetrics(SM_REMOTESESSION)) ? true : false;
|
---|
144 | #else
|
---|
145 | return false; /* Not implemented. */
|
---|
146 | #endif
|
---|
147 | }
|
---|
148 |
|
---|
149 |
|
---|