[xorg-commit-diffs] xc/programs/Xserver/os Imakefile, 1.1.4.3, 1.1.4.4 access.c, 1.1.4.5, 1.1.4.6

Alan Coopersmith xorg-commit at pdx.freedesktop.org
Sun Apr 18 04:47:08 EST 2004


Committed by: alanc

Update of /cvs/xorg/xc/programs/Xserver/os
In directory pdx:/tmp/cvs-serv28826/programs/Xserver/os

Modified Files:
      Tag: XORG-CURRENT
	Imakefile access.c 
Log Message:
Bugzilla #495: LocalClientCred should use getpeerucred on Solaris 10


Index: Imakefile
===================================================================
RCS file: /cvs/xorg/xc/programs/Xserver/os/Imakefile,v
retrieving revision 1.1.4.3
retrieving revision 1.1.4.4
diff -u -d -r1.1.4.3 -r1.1.4.4
--- a/Imakefile	5 Mar 2004 13:41:11 -0000	1.1.4.3
+++ b/Imakefile	17 Apr 2004 18:47:05 -0000	1.1.4.4
@@ -89,8 +89,12 @@
 STRLCAT_OBJS = strlcat.o strlcpy.o
 #endif
 
-#if HasGetpeereid
-GETPEEREID_DEFINES = -DHAS_GETPEEREID
+#if HasGetpeerucred
+GETPEER_DEFINES = -DHAS_GETPEERUCRED
+#else
+# if HasGetpeereid
+GETPEER_DEFINES = -DHAS_GETPEEREID
+# endif
 #endif
 
 BOOTSTRAPCFLAGS = 
@@ -128,7 +132,7 @@
 #endif
         DEFINES = -DXSERV_t -DTRANS_SERVER $(CONNECTION_FLAGS) $(MEM_DEFINES) \
 		  $(XDMAUTHDEFS) $(RPCDEFS) $(SIGNAL_DEFINES) $(OS_DEFINES) \
-		  $(KRB5_DEFINES) $(RGB_DEFINES) $(GETPEEREID_DEFINES) \
+		  $(KRB5_DEFINES) $(RGB_DEFINES) $(GETPEER_DEFINES) \
 		  $(RANDOM_DEFINES)
        INCLUDES = -I. -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) \
 		  -I$(SERVERSRC)/Xext -I$(FONTINCSRC) -I$(SERVERSRC)/render \

Index: access.c
===================================================================
RCS file: /cvs/xorg/xc/programs/Xserver/os/access.c,v
retrieving revision 1.1.4.5
retrieving revision 1.1.4.6
diff -u -d -r1.1.4.5 -r1.1.4.6
--- a/access.c	15 Apr 2004 10:17:33 -0000	1.1.4.5
+++ b/access.c	17 Apr 2004 18:47:05 -0000	1.1.4.6
@@ -88,6 +88,9 @@
 #include <netdnet/dnetdb.h>
 #endif
 
+#ifdef HAS_GETPEERUCRED
+# include <ucred.h>
+#endif
 
 #if defined(DGUX)
 #include <sys/ioctl.h>
@@ -1365,12 +1368,14 @@
 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 @@
     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 @@
     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;




More information about the xorg-commit-diffs mailing list