Bugzilla #495: LocalClientCred should use getpeerucred on Solaris 10
This commit is contained in:
parent
7215fb186f
commit
425251a752
25
os/access.c
25
os/access.c
|
@ -1,5 +1,5 @@
|
||||||
/* $Xorg: access.c,v 1.5 2001/02/09 02:05:23 xorgcvs Exp $ */
|
/* $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
|
Copyright 1987, 1998 The Open Group
|
||||||
|
@ -88,6 +88,9 @@ SOFTWARE.
|
||||||
#include <netdnet/dnetdb.h>
|
#include <netdnet/dnetdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_GETPEERUCRED
|
||||||
|
# include <ucred.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(DGUX)
|
#if defined(DGUX)
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
@ -1365,12 +1368,14 @@ Bool LocalClient(ClientPtr client)
|
||||||
int
|
int
|
||||||
LocalClientCred(ClientPtr client, int *pUid, int *pGid)
|
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;
|
int fd;
|
||||||
XtransConnInfo ci;
|
XtransConnInfo ci;
|
||||||
#ifdef HAS_GETPEEREID
|
#ifdef HAS_GETPEEREID
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
|
#elif defined(HAS_GETPEERUCRED)
|
||||||
|
ucred_t *peercred = NULL;
|
||||||
#elif defined(SO_PEERCRED)
|
#elif defined(SO_PEERCRED)
|
||||||
struct ucred peercred;
|
struct ucred peercred;
|
||||||
socklen_t so_len = sizeof(peercred);
|
socklen_t so_len = sizeof(peercred);
|
||||||
|
@ -1379,10 +1384,15 @@ LocalClientCred(ClientPtr client, int *pUid, int *pGid)
|
||||||
if (client == NULL)
|
if (client == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
ci = ((OsCommPtr)client->osPrivate)->trans_conn;
|
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)) {
|
if (!_XSERVTransIsLocal(ci)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
fd = _XSERVTransGetConnectionNumber(ci);
|
fd = _XSERVTransGetConnectionNumber(ci);
|
||||||
#ifdef HAS_GETPEEREID
|
#ifdef HAS_GETPEEREID
|
||||||
if (getpeereid(fd, &uid, &gid) == -1)
|
if (getpeereid(fd, &uid, &gid) == -1)
|
||||||
|
@ -1392,6 +1402,15 @@ LocalClientCred(ClientPtr client, int *pUid, int *pGid)
|
||||||
if (pGid != NULL)
|
if (pGid != NULL)
|
||||||
*pGid = gid;
|
*pGid = gid;
|
||||||
return 0;
|
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)
|
#elif defined(SO_PEERCRED)
|
||||||
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &peercred, &so_len) == -1)
|
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &peercred, &so_len) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue