- Timestamp:
- Jan 27, 2022 9:25:39 PM (3 years ago)
- Location:
- trunk/src/VBox/Additions/x11/VBoxClient
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/x11/VBoxClient/Makefile.kmk
r93385 r93469 103 103 VBoxClient_SOURCES += \ 104 104 hostversion.cpp 105 VBoxDRMClient_DEFS += VBOX_WITH_GUEST_PROPS 105 106 endif 106 107 -
trunk/src/VBox/Additions/x11/VBoxClient/display-drm.cpp
r93423 r93469 38 38 * back to host, so host and guest will have the same screen layout representation. 39 39 * 40 * By default, access to IPC server socket is granted to all users. It can be restricted to 41 * only root and users from group 'vboxdrmipc' if '/VirtualBox/GuestAdd/DRMIpcRestricted' guest 42 * property is set and READ-ONLY for guest. User group 'vboxdrmipc' is created during Guest 43 * Additions installation. If this group is removed (or not found due to any reason) prior to 44 * service start, access to IPC server socket will be granted to root only regardless 45 * if '/VirtualBox/GuestAdd/DRMIpcRestricted' guest property is set or not. If guest property 46 * is set, but is not READ-ONLY for guest, property is ignored and IPC socket access is granted 47 * to all users. 48 * 40 49 * Logging is implemented in a way that errors are always printed out, VBClLogVerbose(1) and 41 50 * VBClLogVerbose(2) are used for debugging purposes. Verbosity level 1 is for messages related … … 66 75 * 67 76 * 68 * The following lo ackare utilized:77 * The following locks are utilized: 69 78 * 70 79 * #g_ipcClientConnectionsListCritSect - protects access to list of IPC client connections. … … 79 88 80 89 #include <VBox/VBoxGuestLib.h> 90 #include <VBox/HostServices/GuestPropertySvc.h> 81 91 82 92 #include <iprt/getopt.h> … … 133 143 /** IPC client connections counter. */ 134 144 static volatile uint32_t g_cDrmIpcConnections = 0; 145 /* A flag which indicates whether access to IPC socket should be restricted. 146 * This flag caches '/VirtualBox/GuestAdd/DRMIpcRestricted' guest property 147 * in order to prevent its retrieving from the host side each time a new IPC 148 * client connects to server. This flag is updated each time when property is 149 * changed on the host side. */ 150 static volatile bool g_fDrmIpcRestricted; 135 151 136 152 /** DRM version structure. */ … … 920 936 { 921 937 /* Authenticate remote peer. */ 922 rc = vbDrmIpcAuth(hClientSession); 938 if (ASMAtomicReadBool(&g_fDrmIpcRestricted)) 939 rc = vbDrmIpcAuth(hClientSession); 940 923 941 if (RT_SUCCESS(rc)) 924 942 { … … 970 988 } 971 989 990 /** 991 * Grant access to DRM IPC server socket depending on VM configuration. 992 * 993 * If VM has '/VirtualBox/GuestAdd/DRMIpcRestricted' guest property set 994 * and this property is READ-ONLY for the guest side, access will be 995 * granted to root and users from 'vboxdrmipc' group only. If group does 996 * not exists, only root will have access to the socket. When property is 997 * not set or not READ-ONLY, all users will have access to the socket. 998 * 999 * @param hIpcServer IPC server handle. 1000 */ 1001 static void vbDrmSetIpcServerAccessPermissions(RTLOCALIPCSERVER hIpcServer) 1002 { 1003 int rc; 1004 1005 ASMAtomicWriteBool(&g_fDrmIpcRestricted, VbglR3DrmRestrictedIpcAccessIsNeeded()); 1006 1007 if (g_fDrmIpcRestricted) 1008 { 1009 struct group *pGrp; 1010 pGrp = getgrnam(VBOX_DRMIPC_USER_GROUP); 1011 if (pGrp) 1012 { 1013 rc = RTLocalIpcServerGrantGroupAccess(hIpcServer, pGrp->gr_gid); 1014 if (RT_SUCCESS(rc)) 1015 VBClLogInfo("IPC server socket access granted to '" VBOX_DRMIPC_USER_GROUP "' users\n"); 1016 else 1017 VBClLogError("unable to grant IPC server socket access to '" VBOX_DRMIPC_USER_GROUP "' users, rc=%Rrc\n", rc); 1018 1019 } 1020 else 1021 VBClLogError("unable to grant IPC server socket access to '" VBOX_DRMIPC_USER_GROUP "', group does not exist\n"); 1022 } 1023 else 1024 { 1025 rc = RTLocalIpcServerSetAccessMode(hIpcServer, 1026 RTFS_UNIX_IRUSR | RTFS_UNIX_IWUSR | 1027 RTFS_UNIX_IRGRP | RTFS_UNIX_IWGRP | 1028 RTFS_UNIX_IROTH | RTFS_UNIX_IWOTH); 1029 if (RT_SUCCESS(rc)) 1030 VBClLogInfo("IPC server socket access granted to all users\n"); 1031 else 1032 VBClLogError("unable to grant IPC server socket access to all users, rc=%Rrc\n", rc); 1033 } 1034 } 1035 1036 /** 1037 * Wait and handle '/VirtualBox/GuestAdd/DRMIpcRestricted' guest property change. 1038 * 1039 * This function is executed in context of main(). 1040 * 1041 * @param hIpcServer IPC server handle. 1042 */ 1043 static void vbDrmPollIpcServerAccessMode(RTLOCALIPCSERVER hIpcServer) 1044 { 1045 HGCMCLIENTID idClient; 1046 int rc; 1047 1048 rc = VbglR3GuestPropConnect(&idClient); 1049 if (RT_SUCCESS(rc)) 1050 { 1051 do 1052 { 1053 /* Buffer should be big enough to fit guest property data layout: Name\0Value\0Flags\0. */ 1054 static char achBuf[GUEST_PROP_MAX_NAME_LEN]; 1055 uint64_t u64Timestamp = 0; 1056 1057 rc = VbglR3GuestPropWait(idClient, VBGLR3DRMIPCPROPRESTRICT, achBuf, sizeof(achBuf), u64Timestamp, 1058 VBOX_DRMIPC_RX_TIMEOUT_MS, NULL, NULL, &u64Timestamp, NULL, NULL); 1059 if (RT_SUCCESS(rc)) 1060 vbDrmSetIpcServerAccessPermissions(hIpcServer); 1061 else if (rc != VERR_TIMEOUT) 1062 { 1063 VBClLogError("error on waiting guest property notification, rc=%Rrc\n", rc); 1064 RTThreadSleep(VBOX_DRMIPC_RX_RELAX_MS); 1065 } 1066 1067 } while (!ASMAtomicReadBool(&g_fShutdown)); 1068 1069 VbglR3GuestPropDisconnect(idClient); 1070 } 1071 else 1072 VBClLogError("cannot connect to VM guest properties service, rc=%Rrc\n", rc); 1073 } 1074 972 1075 int main(int argc, char *argv[]) 973 1076 { … … 1093 1196 } 1094 1197 1095 struct group *pGrp; 1096 pGrp = getgrnam(VBOX_DRMIPC_USER_GROUP); 1097 if (pGrp) 1098 { 1099 rc = RTLocalIpcServerGrantGroupAccess(hIpcServer, pGrp->gr_gid); 1100 if (RT_FAILURE(rc)) 1101 VBClLogError("unable to grant IPC server socket access to '" VBOX_DRMIPC_USER_GROUP "', rc=%Rrc\n", rc); 1102 } 1103 else 1104 VBClLogError("unable to grant IPC server socket access to '" VBOX_DRMIPC_USER_GROUP "', group does not exist\n"); 1198 /* Set IPC server socket access permissions according to VM configuration. */ 1199 vbDrmSetIpcServerAccessPermissions(hIpcServer); 1105 1200 1106 1201 /* Attempt to start DRM resize task. */ … … 1114 1209 if (RT_SUCCESS(rc)) 1115 1210 { 1211 /* Poll for host notification about IPC server socket access mode change. */ 1212 vbDrmPollIpcServerAccessMode(hIpcServer); 1213 1116 1214 /* HACK ALERT! 1117 1215 * The sequence of RTThreadWait(drmResizeThread) -> RTLocalIpcServerDestroy() -> RTThreadWait(vbDrmIpcThread)
Note:
See TracChangeset
for help on using the changeset viewer.