In article <agwkfzwhxdys1...@exadelic.gatalith.at>,
Thomas Klausner  <w...@netbsd.org> wrote:
>Hi!
>
>wayland 1.24.0 would like to read the credentials of the other side of a 
>socket.
>
>The code for FreeBSD and OpenBSD looks like this:
>
>#if defined(__FreeBSD__)
>int
>wl_os_socket_peercred(int sockfd, uid_t *uid, gid_t *gid, pid_t *pid)
>{
>        socklen_t len;
>        struct xucred ucred;
>
>        len = sizeof(ucred);
>        if (getsockopt(sockfd, SOL_LOCAL, LOCAL_PEERCRED, &ucred, &len) < 0 ||
>            ucred.cr_version != XUCRED_VERSION)
>                return -1;
>        *uid = ucred.cr_uid;
>        *gid = ucred.cr_gid;
>#if HAVE_XUCRED_CR_PID
>        /* Since https://cgit.freebsd.org/src/commit/?id=c5afec6e895a */
>        *pid = ucred.cr_pid;
>#else
>        *pid = 0;
>#endif
>        return 0;
>}
>#elif defined(SO_PEERCRED)
>int
>wl_os_socket_peercred(int sockfd, uid_t *uid, gid_t *gid, pid_t *pid)
>{
>        socklen_t len;
>#if defined(__OpenBSD__)
>        struct sockpeercred ucred;
>#else
>        struct ucred ucred;
>#endif
>
>        len = sizeof(ucred);
>        if (getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) < 0)
>                return -1;
>        *uid = ucred.uid;
>        *gid = ucred.gid;
>        *pid = ucred.pid;
>        return 0;
>}
>
>
>but I can't find neither LOCAL_PEERCRED nor SO_PEERCRED in the NetBSD
>headers.
>
>Is this supported in NetBSD in a different way, or is it missing this
>feature?

Missing, but can be added.

christos

Reply via email to