diff options
author | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2021-08-11 05:44:02 +0000 |
---|---|---|
committer | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2021-08-11 05:44:02 +0000 |
commit | cc17a17e3525af002948cf27e2defc545cf99ae2 (patch) | |
tree | cb04124014cd4df9d0456e975f0395afe7364778 /xserver/os | |
parent | 5e2153ecc70122af618246293dbada84e359c159 (diff) |
GetLocalClientCreds: prefer getsockopt(,SO_PEERCRED,) to getpeereid()
This adds the pid of the local clients to LocalLientCred.
ok espie@
Diffstat (limited to 'xserver/os')
-rw-r--r-- | xserver/os/access.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/xserver/os/access.c b/xserver/os/access.c index 24a2ff7b6..6f13c6d15 100644 --- a/xserver/os/access.c +++ b/xserver/os/access.c @@ -1168,15 +1168,19 @@ GetLocalClientCreds(ClientPtr client, LocalClientCredRec ** lccp) XtransConnInfo ci; LocalClientCredRec *lcc; -#ifdef HAVE_GETPEEREID +#if defined(SO_PEERCRED) +#ifndef __OpenBSD__ + struct ucred peercred; +#else + struct sockpeercred peercred; +#endif + socklen_t so_len = sizeof(peercred); +#elif defined(HAVE_GETPEEREID) uid_t uid; gid_t gid; #elif defined(HAVE_GETPEERUCRED) ucred_t *peercred = NULL; const gid_t *gids; -#elif defined(SO_PEERCRED) - struct ucred peercred; - socklen_t so_len = sizeof(peercred); #endif if (client == NULL) @@ -1198,7 +1202,17 @@ GetLocalClientCreds(ClientPtr client, LocalClientCredRec ** lccp) lcc = *lccp; fd = _XSERVTransGetConnectionNumber(ci); -#ifdef HAVE_GETPEEREID +#if defined(SO_PEERCRED) + if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &peercred, &so_len) == -1) { + FreeLocalClientCreds(lcc); + return -1; + } + lcc->euid = peercred.uid; + lcc->egid = peercred.gid; + lcc->pid = peercred.pid; + lcc->fieldsSet = LCC_UID_SET | LCC_GID_SET | LCC_PID_SET; + return 0; +#elif defined(HAVE_GETPEEREID) if (getpeereid(fd, &uid, &gid) == -1) { FreeLocalClientCreds(lcc); return -1; @@ -1245,16 +1259,6 @@ GetLocalClientCreds(ClientPtr client, LocalClientCredRec ** lccp) } ucred_free(peercred); return 0; -#elif defined(SO_PEERCRED) - if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &peercred, &so_len) == -1) { - FreeLocalClientCreds(lcc); - return -1; - } - lcc->euid = peercred.uid; - lcc->egid = peercred.gid; - lcc->pid = peercred.pid; - lcc->fieldsSet = LCC_UID_SET | LCC_GID_SET | LCC_PID_SET; - return 0; #endif #else /* No system call available to get the credentials of the peer */ |