VirtualBox

Changeset 92678 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 1, 2021 3:14:12 PM (3 years ago)
Author:
vboxsync
Message:

IPRT/localipc/posix: Some minor adjustments to rtLocalIpcSessionQueryUcred and some clues for the other plaforms. bugref:10134

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/localipc-posix.cpp

    r92677 r92678  
    10481048}
    10491049
     1050
    10501051/**
    10511052 * Get IPC session socket peer credentials.
    10521053 *
    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).
     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).
    10581059 */
    10591060static int rtLocalIpcSessionQueryUcred(RTLOCALIPCSESSION hSession, PRTPROCESS pProcess, PRTUID pUid, PRTGID pGid)
    10601061{
    1061 #if defined(RT_OS_LINUX)
    10621062    PRTLOCALIPCSESSIONINT pThis = hSession;
    1063 
    10641063    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    10651064    AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, VERR_INVALID_HANDLE);
    10661065
    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
    10841081#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);
    10861085    return VERR_NOT_SUPPORTED;
    10871086#endif
    10881087}
    10891088
     1089
    10901090RTDECL(int) RTLocalIpcSessionQueryProcess(RTLOCALIPCSESSION hSession, PRTPROCESS pProcess)
    10911091{
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette