VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibDrmClient.cpp@ 94563

Last change on this file since 94563 was 94563, checked in by vboxsync, 3 years ago

Additions: Linux: Guest Lib: fix VBoxDRMClient arguments when starting it, bugref:10134.

Make VBoxDRMClient visible in ps(1) output.

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