summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <Alan.Coopersmith@sun.com>2004-04-17 18:47:05 +0000
committerAlan Coopersmith <Alan.Coopersmith@sun.com>2004-04-17 18:47:05 +0000
commit425251a752805affb6ce14baa58d92c384f39501 (patch)
tree128bf976e19c7a6ad57e50bf8f4bab5a5dfa09ea
parent7215fb186f076a24d0a04c9c20ac9b92cae1f49b (diff)
Bugzilla #495: LocalClientCred should use getpeerucred on Solaris 10
-rw-r--r--os/access.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/os/access.c b/os/access.c
index 123a28d0a..2877373c7 100644
--- a/os/access.c
+++ b/os/access.c
@@ -1,5 +1,5 @@
/* $Xorg: access.c,v 1.5 2001/02/09 02:05:23 xorgcvs Exp $ */
-/* $XdotOrg$ */
+/* $XdotOrg: xc/programs/Xserver/os/access.c,v 1.1.4.3.2.3 2004/03/22 11:57:11 ago Exp $ */
/***********************************************************
Copyright 1987, 1998 The Open Group
@@ -88,6 +88,9 @@ SOFTWARE.
#include <netdnet/dnetdb.h>
#endif
+#ifdef HAS_GETPEERUCRED
+# include <ucred.h>
+#endif
#if defined(DGUX)
#include <sys/ioctl.h>
@@ -1365,12 +1368,14 @@ Bool LocalClient(ClientPtr client)
int
LocalClientCred(ClientPtr client, int *pUid, int *pGid)
{
-#if defined(HAS_GETPEEREID) || defined(SO_PEERCRED)
+#if defined(HAS_GETPEEREID) || defined(HAS_GETPEERUCRED) || defined(SO_PEERCRED)
int fd;
XtransConnInfo ci;
#ifdef HAS_GETPEEREID
uid_t uid;
gid_t gid;
+#elif defined(HAS_GETPEERUCRED)
+ ucred_t *peercred = NULL;
#elif defined(SO_PEERCRED)
struct ucred peercred;
socklen_t so_len = sizeof(peercred);
@@ -1379,10 +1384,15 @@ LocalClientCred(ClientPtr client, int *pUid, int *pGid)
if (client == NULL)
return -1;
ci = ((OsCommPtr)client->osPrivate)->trans_conn;
- /* We can only determine peer credentials for Unix domain sockets */
+#if !(defined(sun) && defined(HAS_GETPEERUCRED))
+ /* Most implementations can only determine peer credentials for Unix
+ * domain sockets - Solaris getpeerucred can work with a bit more, so
+ * we just let it tell us if the connection type is supported or not
+ */
if (!_XSERVTransIsLocal(ci)) {
return -1;
}
+#endif
fd = _XSERVTransGetConnectionNumber(ci);
#ifdef HAS_GETPEEREID
if (getpeereid(fd, &uid, &gid) == -1)
@@ -1392,6 +1402,15 @@ LocalClientCred(ClientPtr client, int *pUid, int *pGid)
if (pGid != NULL)
*pGid = gid;
return 0;
+#elif defined(HAS_GETPEERUCRED)
+ if (getpeerucred(fd, &peercred) < 0)
+ return -1;
+ if (pUid != NULL)
+ *pUid = ucred_geteuid(peercred);
+ if (pGid != NULL)
+ *pGid = ucred_getegid(peercred);
+ ucred_free(peercred);
+ return 0;
#elif defined(SO_PEERCRED)
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &peercred, &so_len) == -1)
return -1;