Changeset 92676 in vbox
- Timestamp:
- Dec 1, 2021 2:59:59 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/posix/localipc-posix.cpp
r82968 r92676 1048 1048 } 1049 1049 1050 /** 1051 * Get IPC session socket peer credentials. 1052 * 1053 * @return IPRT status code. 1054 * @param hSession IPC session handle. 1055 * @param pProcess Output buffer to store remote peer PID (can be NULL). 1056 * @param pUid Output buffer to store remote peer UID (can be NULL). 1057 * @param pGid Output buffer to store remote peer GID (can be NULL). 1058 */ 1059 static int rtLocalIpcSessionQueryUcred(RTLOCALIPCSESSION hSession, PRTPROCESS pProcess, PRTUID pUid, PRTGID pGid) 1060 { 1061 #if defined(RT_OS_LINUX) 1062 PRTLOCALIPCSESSIONINT pThis = hSession; 1063 1064 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1065 AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, VERR_INVALID_HANDLE); 1066 1067 struct ucred PeerCred; 1068 socklen_t cbPeerCred = sizeof(PeerCred); 1069 int iSock = RTSocketToNative(pThis->hSocket); 1070 1071 RT_ZERO(PeerCred); 1072 1073 if (getsockopt(iSock, SOL_SOCKET, SO_PEERCRED, &PeerCred, &cbPeerCred) == -1) 1074 return RTErrConvertFromErrno(errno); 1075 1076 if (pProcess) 1077 *pProcess = PeerCred.pid; 1078 if (pUid) 1079 *pUid = PeerCred.uid; 1080 if (pGid) 1081 *pGid = PeerCred.gid; 1082 1083 return VINF_SUCCESS; 1084 #else 1085 return VERR_NOT_SUPPORTED; 1086 #endif 1087 } 1050 1088 1051 1089 RTDECL(int) RTLocalIpcSessionQueryProcess(RTLOCALIPCSESSION hSession, PRTPROCESS pProcess) 1052 1090 { 1053 RT_NOREF_PV(hSession); RT_NOREF_PV(pProcess); 1054 return VERR_NOT_SUPPORTED; 1091 return rtLocalIpcSessionQueryUcred(hSession, pProcess, NULL, NULL); 1055 1092 } 1056 1093 … … 1058 1095 RTDECL(int) RTLocalIpcSessionQueryUserId(RTLOCALIPCSESSION hSession, PRTUID pUid) 1059 1096 { 1060 RT_NOREF_PV(hSession); RT_NOREF_PV(pUid); 1061 return VERR_NOT_SUPPORTED; 1062 } 1063 1097 return rtLocalIpcSessionQueryUcred(hSession, NULL, pUid, NULL); 1098 } 1064 1099 1065 1100 RTDECL(int) RTLocalIpcSessionQueryGroupId(RTLOCALIPCSESSION hSession, PRTGID pGid) 1066 1101 { 1067 RT_NOREF_PV(hSession); RT_NOREF_PV(pGid); 1068 return VERR_NOT_SUPPORTED; 1069 } 1070 1102 return rtLocalIpcSessionQueryUcred(hSession, NULL, NULL, pGid); 1103 } 1104
Note:
See TracChangeset
for help on using the changeset viewer.