VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibDrmClient.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: 6.5 KB
Line 
1/* $Id: VBoxGuestR3LibDrmClient.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, DRM client handling.
4 */
5
6/*
7 * Copyright (C) 2020-2023 Oracle and/or its affiliates.
8 *
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 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include "VBoxGuestR3LibInternal.h"
42
43#include <iprt/env.h>
44#include <iprt/path.h>
45#include <iprt/process.h>
46
47#if defined(RT_OS_LINUX)
48# include <VBox/HostServices/GuestPropertySvc.h>
49
50/** Defines the DRM client executable (image). */
51# define VBOX_DRMCLIENT_EXECUTABLE "/usr/bin/VBoxDRMClient"
52# define VBOX_DRMCLIENT_LEGACY_EXECUTABLE "/usr/bin/VBoxClient"
53/** Defines the guest property that defines if the DRM resizing client needs to be active or not. */
54# define VBOX_DRMCLIENT_GUEST_PROP_RESIZE "/VirtualBox/GuestAdd/DRMResize"
55
56/**
57 * Check if specified guest property exist.
58 *
59 * @returns \c true if the property exists and its flags do match, \c false otherwise.
60 * @param pszPropName Guest property name.
61 * @param fPropFlags Guest property flags mask to verify if property exist.
62 * If \p fPropFlags is 0, flags verification is omitted.
63 */
64static bool vbglR3DrmClientCheckProp(const char *pszPropName, uint32_t fPropFlags)
65{
66 bool fExist = false;
67# if defined(VBOX_WITH_GUEST_PROPS)
68 uint32_t idClient;
69
70 int rc = VbglR3GuestPropConnect(&idClient);
71 if (RT_SUCCESS(rc))
72 {
73 char *pcszFlags = NULL;
74
75 rc = VbglR3GuestPropReadEx(idClient, pszPropName, NULL /* ppszValue */, &pcszFlags, NULL);
76 if (RT_SUCCESS(rc))
77 {
78 /* Check property flags match. */
79 if (fPropFlags)
80 {
81 uint32_t fFlags = 0;
82
83 rc = GuestPropValidateFlags(pcszFlags, &fFlags);
84 fExist = RT_SUCCESS(rc) && (fFlags == fPropFlags);
85 }
86 else
87 fExist = true;
88
89 RTStrFree(pcszFlags);
90 }
91
92 VbglR3GuestPropDisconnect(idClient);
93 }
94# endif /* VBOX_WITH_GUEST_PROPS */
95 return fExist;
96}
97#endif /* RT_OS_LINUX */
98
99/**
100 * Returns true if the DRM resizing client is needed.
101 * This is achieved by querying existence of a guest property.
102 *
103 * @returns \c true if the DRM resizing client is needed, \c false if not.
104 */
105VBGLR3DECL(bool) VbglR3DrmClientIsNeeded(void)
106{
107#if defined(RT_OS_LINUX)
108 return vbglR3DrmClientCheckProp(VBOX_DRMCLIENT_GUEST_PROP_RESIZE, 0);
109#else
110 return false;
111#endif
112}
113
114/**
115 * Returns true if the DRM IPC server socket access should be restricted.
116 *
117 * Restricted access means that only users from a certain group should
118 * be granted with read and write access permission to IPC socket. Check
119 * is done by examining \c VBGLR3DRMIPCPROPRESTRICT guest property. Property
120 * is only considered valid if is read-only for guest. I.e., the following
121 * property should be set on the host side:
122 *
123 * VBoxManage guestproperty set <VM> /VirtualBox/GuestAdd/DRMIpcRestricted 1 --flags RDONLYGUEST
124 *
125 * @returns \c true if restricted socket access is required, \c false otherwise.
126 */
127VBGLR3DECL(bool) VbglR3DrmRestrictedIpcAccessIsNeeded(void)
128{
129#if defined(RT_OS_LINUX)
130 return vbglR3DrmClientCheckProp(VBGLR3DRMIPCPROPRESTRICT, GUEST_PROP_F_RDONLYGUEST);
131#else
132 return false;
133#endif
134}
135
136/**
137 * Returns true if the DRM resizing client already is running.
138 * This is achieved by querying existence of a guest property.
139 *
140 * @returns \c true if the DRM resizing client is running, \c false if not.
141 */
142VBGLR3DECL(bool) VbglR3DrmClientIsRunning(void)
143{
144 return VbglR3DrmClientIsNeeded();
145}
146
147#if defined(RT_OS_LINUX)
148static int VbglR3DrmStart(const char *pszCmd, const char **apszArgs)
149{
150 return RTProcCreate(pszCmd, apszArgs, RTENV_DEFAULT,
151 RTPROC_FLAGS_DETACHED | RTPROC_FLAGS_SEARCH_PATH, NULL);
152}
153#endif
154
155/**
156 * Starts (executes) the DRM resizing client process ("VBoxDRMClient").
157 *
158 * @returns VBox status code.
159 */
160VBGLR3DECL(int) VbglR3DrmClientStart(void)
161{
162#if defined(RT_OS_LINUX)
163 const char *apszArgs[2] = { VBOX_DRMCLIENT_EXECUTABLE, NULL }; /** @todo r=andy Pass path + process name as argv0? */
164 return VbglR3DrmStart(VBOX_DRMCLIENT_EXECUTABLE, apszArgs);
165#else
166 return VERR_NOT_SUPPORTED;
167#endif
168}
169
170/**
171 * Starts (executes) the legacy DRM resizing client process ("VBoxClient --vmsvga").
172 *
173 * @returns VBox status code.
174 */
175VBGLR3DECL(int) VbglR3DrmLegacyClientStart(void)
176{
177#if defined(RT_OS_LINUX)
178 const char *apszArgs[3] = { VBOX_DRMCLIENT_LEGACY_EXECUTABLE, "--vmsvga", NULL };
179 return VbglR3DrmStart(VBOX_DRMCLIENT_LEGACY_EXECUTABLE, apszArgs);
180#else
181 return VERR_NOT_SUPPORTED;
182#endif
183}
184
185/**
186 * Starts (executes) the legacy X11 resizing agent process ("VBoxClient --display").
187 *
188 * @returns VBox status code.
189 */
190VBGLR3DECL(int) VbglR3DrmLegacyX11AgentStart(void)
191{
192#if defined(RT_OS_LINUX)
193 const char *apszArgs[3] = { VBOX_DRMCLIENT_LEGACY_EXECUTABLE, "--display", NULL };
194 return VbglR3DrmStart(VBOX_DRMCLIENT_LEGACY_EXECUTABLE, apszArgs);
195#else
196 return VERR_NOT_SUPPORTED;
197#endif
198}
199
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use