Changeset 92678 in vbox for trunk/src/VBox
- Timestamp:
- Dec 1, 2021 3:14:12 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/posix/localipc-posix.cpp
r92677 r92678 1048 1048 } 1049 1049 1050 1050 1051 /** 1051 1052 * Get IPC session socket peer credentials. 1052 1053 * 1053 * @return IPRT status code.1054 * @param hSessionIPC session handle.1055 * @param pProcess Output buffer to store remote peerPID (can be NULL).1056 * @param pUid Output buffer to store remote peerUID (can be NULL).1057 * @param pGid Output buffer to store remote peerGID (can be NULL).1054 * @returns IPRT status code. 1055 * @param hSession IPC session handle. 1056 * @param pProcess Where to return the remote peer's PID (can be NULL). 1057 * @param pUid Where to return the remote peer's UID (can be NULL). 1058 * @param pGid Where to return the remote peer's GID (can be NULL). 1058 1059 */ 1059 1060 static int rtLocalIpcSessionQueryUcred(RTLOCALIPCSESSION hSession, PRTPROCESS pProcess, PRTUID pUid, PRTGID pGid) 1060 1061 { 1061 #if defined(RT_OS_LINUX)1062 1062 PRTLOCALIPCSESSIONINT pThis = hSession; 1063 1064 1063 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1065 1064 AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, VERR_INVALID_HANDLE); 1066 1065 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; 1066 #if defined(RT_OS_LINUX) 1067 struct ucred PeerCred = { (pid_t)NIL_RTPROCESS, (uid_t)NIL_RTUID, (gid_t)NIL_RTGID }; 1068 socklen_t cbPeerCred = sizeof(PeerCred); 1069 if (getsockopt(RTSocketToNative(pThis->hSocket), SOL_SOCKET, SO_PEERCRED, &PeerCred, &cbPeerCred) >= 0) 1070 { 1071 if (pProcess) 1072 *pProcess = PeerCred.pid; 1073 if (pUid) 1074 *pUid = PeerCred.uid; 1075 if (pGid) 1076 *pGid = PeerCred.gid; 1077 return VINF_SUCCESS; 1078 } 1079 return RTErrConvertFromErrno(errno); 1080 1084 1081 #else 1085 RT_NOREF4(hSession, pProcess, pUid, pGid); 1082 /** @todo Implement on other platforms too (mostly platform specific this). 1083 * Solaris: getpeerucred? Darwin: LOCALPEERCRED or getpeereid? */ 1084 RT_NOREF(pProcess, pUid, pGid); 1086 1085 return VERR_NOT_SUPPORTED; 1087 1086 #endif 1088 1087 } 1089 1088 1089 1090 1090 RTDECL(int) RTLocalIpcSessionQueryProcess(RTLOCALIPCSESSION hSession, PRTPROCESS pProcess) 1091 1091 {
Note:
See TracChangeset
for help on using the changeset viewer.