summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xserver/os/access.c34
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 */