diff -r 74acdbfca2ee Doc/lib/libsocket.tex --- a/Doc/lib/libsocket.tex Sat May 20 21:30:13 2006 +0200 +++ b/Doc/lib/libsocket.tex Sat May 20 23:32:06 2006 +0200 @@ -307,6 +307,14 @@ success, a new \class{SSLObject} is retu \warning{This does not do any certificate verification!} \end{funcdesc} +\begin{funcdesc}{ucred}{pid, uid, gid} +Construct a new ucred object which is associated with the corresponding +process ID, user ID and group ID. + +Availability: \UNIX{} (maybe not all platforms). +\versionadded{2.5} +\end{funcdesc} + \begin{funcdesc}{socketpair}{\optional{family\optional{, type\optional{, proto}}}} Build a pair of connected socket objects using the given address family, socket type, and protocol number. Address family, socket type, @@ -517,6 +525,18 @@ see above.) On some systems this functi see above.) On some systems this function is not supported. \end{methoddesc} +\begin{methoddesc}[socket]{getpeercred}{} +Return a \code{ucred} structure containing the process id, user id and +group id of the process the socket is connected to, if it is a local +connection. In case the connection isn't local or the method is not supported +on the current socket type, the return value is a structure with +\code{pid=0} and \code{uid=gid=-1}. On some systems this method is not +supported at all. + +Availability: \UNIX{} (maybe not all platforms). +\versionadded{2.5} +\end{methoddesc} + \begin{methoddesc}[socket]{getsockname}{} Return the socket's own address. This is useful to find out the port number of an IPv4/v6 socket, for instance. @@ -710,6 +730,45 @@ If \var{n} is provided, read \var{n} byt If \var{n} is provided, read \var{n} bytes from the SSL connection, otherwise read until EOF. The return value is a string of the bytes read. \end{methoddesc} + +\subsection{ucred Objects \label{ucred-objects}} + +ucred objects (if defined for the current platform) have the following methods +and members. + +\begin{methoddesc}[ucred]{getpwuid}{} +Returns the \code{struct_passwd} associated with the uid of this ucred +object. This might raise a \code{NotImplementedError}, in case +\code{getpwuid} is not available on your system, or a \code{KeyError} +in case \code{getpwuid} is unable to find the user information associated +with the uid. + +Availability: \UNIX. +\end{methoddesc} + +\begin{methoddesc}[ucred]{getgrgid}{} +Returns the \code{struct_group} associated with the gid of this ucred +object. This might raise a \code{NotImplementedError}, in case +\code{getgrgid} is not available on your system, or a \code{KeyError} +in case \code{getgrgid} is unable to find the user information associated +with the gid. + +Availability: \UNIX. +\end{methoddesc} + +\begin{memberdesc}[ucred]{pid} +Process ID of the connected process. +\end{memberdesc} + +\begin{memberdesc}[ucred]{uid} +User ID of the connected process. +\end{memberdesc} + +\begin{memberdesc}[ucred]{gid} +Group ID of the connected process. +\end{memberdesc} + +\versionadded{2.5} \subsection{Example \label{socket-example}} diff -r 74acdbfca2ee Doc/whatsnew/whatsnew25.tex --- a/Doc/whatsnew/whatsnew25.tex Sat May 20 21:30:13 2006 +0200 +++ b/Doc/whatsnew/whatsnew25.tex Sat May 20 23:32:06 2006 +0200 @@ -1444,6 +1455,14 @@ Socket objects also gained accessor meth Socket objects also gained accessor methods \method{getfamily()}, \method{gettype()}, and \method{getproto()} methods to retrieve the family, type, and protocol values for the socket. + +\item The \module{socket} module now supports the +\code{getsockopt(SO_PEERCRED)} call that is available on Linux to retrieve +the uid, gid and pid of a connected process as a convenience function on +\code{socket} objects, called \code{getpeercred}. The result is wrapped in a +new \code{ucred} type, which is also implemented in the \module{socket} +module and wraps \code{struct ucred} that is available on BSD-derived +systems. (Implemented by Heiko Wundram.) \item New module: the \module{spwd} module provides functions for accessing the shadow password database on systems that support diff -r 74acdbfca2ee Lib/socket.py --- a/Lib/socket.py Sat May 20 21:30:13 2006 +0200 +++ b/Lib/socket.py Sat May 20 23:32:06 2006 +0200 @@ -53,6 +53,13 @@ except ImportError: except ImportError: pass +_have_ucred = False +try: + from _socket import ucred + _have_ucred = True +except ImportError: + pass + import os, sys try: @@ -72,6 +79,8 @@ if _have_ssl: if hasattr(sock, "_sock"): sock = sock._sock return _realssl(sock, keyfile, certfile) +if _have_ucred: + _realucred = ucred # WSA error codes if sys.platform.lower().startswith("win"): @@ -123,8 +132,8 @@ def getfqdn(name=''): _socketmethods = ( 'bind', 'connect', 'connect_ex', 'fileno', 'listen', - 'getpeername', 'getsockname', 'getsockopt', 'setsockopt', - 'sendall', 'setblocking', + 'getpeername', 'getsockname', 'getsockopt', + 'setsockopt', 'sendall', 'setblocking', 'settimeout', 'gettimeout', 'shutdown') if sys.platform == "riscos": @@ -167,6 +176,20 @@ class _socketobject(object): Return a new socket object connected to the same system resource.""" return _socketobject(_sock=self._sock) + + if hasattr(_realsocket,"getpeercred"): + def getpeercred(self): + return self._sock.getpeercred(_ucredobject) + getpeercred.__doc__ = _realsocket.getpeercred.__doc__ + else: + def getpeercred(self): + """getpeercred() -> credentials info + + Return a ucred structure with the credentials of the connected + process. + + This is a dummy method.""" + return ucred(0,-1,-1) def makefile(self, mode='r', bufsize=-1): """makefile([mode[, bufsize]]) -> file object @@ -402,3 +425,105 @@ class _fileobject(object): if not line: raise StopIteration return line + +if _have_ucred: + # If we have a ucred type, define an extended ucred type. + + _have_getpwuid = False + try: + from pwd import getpwuid as _getpwuid + _have_getpwuid = True + except ImportError: + pass + + _have_getgrgid = False + try: + from grp import getgrgid as _getgrgid + _have_getgrgid = True + except ImportError: + pass + + class _ucredobject(_realucred): + __doc__ = _realucred.__doc__ + + def __new__(cls, pid, uid, gid): + return super(_ucredobject,cls).__new__(cls, pid, uid, gid) + + if _have_getpwuid: + def getpwuid(self): + """Return the passwd struct for the uid associated with this + ucred object.""" + return _getpwuid(self.uid) + else: + def getpwuid(self): + """Return the passwd struct for the uid associated with this + ucred object.""" + raise NotImplementedError("getpwuid isn't implemented") + + if _have_getgrgid: + def getgrgid(self): + """Return the group struct for the gid associated with this + ucred object.""" + return _getgrgid(self.gid) + else: + def getgrgid(self): + """Return the group struct for the gid associated with this + ucred object.""" + raise NotImplementedError("getgrgid isn't implemented") +else: + # There is no ucred type support in the _socket module, define dummy. + class _ucredobject(object): + """ucred(pid, uid, gid) -> ucred object + + Create a new ucred object which is used to store process information + when communicating with a remote process on the local machine. + + This is a dummy object.""" + + def __new__(cls, pid, uid, gid): + assert ( isinstance(pid, int) and + isinstance(uid, int) and + isinstance(gid, int) ) + + self = object.__new__(cls) + self.__pid = pid + self.__uid = uid + self.__gid = gid + return self + + pid = property(lambda self: self.__pid, "Process ID of remote process") + uid = property(lambda self: self.__uid, "User ID of remote process") + gid = property(lambda self: self.__gid, "Group ID of remote process") + + def getpwuid(self): + """Return the passwd struct for the uid associated with this + ucred object.""" + raise NotImplementedError("getpwuid isn't implemented") + + def getgrgid(self): + """Return the group struct for the gid associated with this + ucred object.""" + raise NotImplementedError("getgrgid isn't implemented") + + def __hash__(self): + return self.__pid + self.__uid * (1<<10) + self.__gid * (1<<20) + + def __eq__(self,other): + if not isinstance(other,_ucredobject): + return NotImplemented + return ( self.__pid == other.__pid and + self.__uid == other.__uid and + self.__gid == other.__gid ) + + def __ne__(self,other): + if not isinstance(other,_ucredobject): + return NotImplemented + return ( self.__pid <> other.__pid or + self.__uid <> other.__uid or + self.__gid <> other.__gid ) + + def __repr__(self): + return ("" % + (self.__pid, self.__uid, self.__gid)) + +ucred = UcredType = _ucredobject diff -r 74acdbfca2ee Lib/test/test_socket.py --- a/Lib/test/test_socket.py Sat May 20 21:30:13 2006 +0200 +++ b/Lib/test/test_socket.py Sat May 20 23:32:06 2006 +0200 @@ -825,6 +825,53 @@ class TestExceptions(unittest.TestCase): self.assert_(issubclass(socket.gaierror, socket.error)) self.assert_(issubclass(socket.timeout, socket.error)) +class TestGetPeerCred(unittest.TestCase): + + def testGetPeerCredSocketPair(self): + if not hasattr(socket,"socketpair"): + return + x, y = [socket.socket(_sock=x) for x in socket.socketpair()] + pc = x.getpeercred() + self.assert_(isinstance(pc, socket.ucred)) + if not pc.pid: + self.assert_(pc.uid == -1 and pc.gid == -1) + else: + import os + self.assert_(pc.pid == os.getpid()) + self.assert_(pc.uid == os.getuid()) + self.assert_(pc.gid == os.getgid()) + + def testGetPeerCredEmpty(self): + x = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + pc = x.getpeercred() + self.assert_(pc.pid == 0 and pc.uid == -1 and pc.gid == -1) + + def testCreate(self): + self.assert_(isinstance(socket.ucred(1, 2, 3), socket.ucred)) + + def testCompare(self): + x, y = socket.ucred(1, 2, 3), socket.ucred(4, 5, 6) + self.assert_(x <> y) + z = socket.ucred(1, 2, 3) + self.assert_(x == z) + + def testHash(self): + x = socket.ucred(1, 2, 3) + self.assert_(hash(x) == 1 + 2*(1<<10) + 3*(1<<20)) + + def testPwdGrp(self): + x = socket.ucred(1, 0, 0) + try: + from pwd import getpwuid + self.assert_(getpwuid(0) == x.getpwuid()) + except ImportError: + self.assertRaises(NotImplementedError, x.getpwuid) + try: + from grp import getgrgid + self.assert_(getgrgid(0) == x.getgrgid()) + except ImportError: + self.assertRaises(NotImplementedError, x.getgrgid) + class TestLinuxAbstractNamespace(unittest.TestCase): UNIX_PATH_MAX = 108 @@ -862,7 +909,8 @@ def test_main(): FileObjectClassTestCase, UnbufferedFileObjectClassTestCase, LineBufferedFileObjectClassTestCase, - SmallBufferedFileObjectClassTestCase + SmallBufferedFileObjectClassTestCase, + TestGetPeerCred ]) if hasattr(socket, "socketpair"): tests.append(BasicSocketPairTest) diff -r 74acdbfca2ee Modules/socketmodule.c --- a/Modules/socketmodule.c Sat May 20 21:30:13 2006 +0200 +++ b/Modules/socketmodule.c Sat May 20 23:32:06 2006 +0200 @@ -98,6 +98,7 @@ dup() -- return a new socket object iden dup() -- return a new socket object identical to the current one [*]\n\ fileno() -- return underlying file descriptor\n\ getpeername() -- return remote address [*]\n\ +getpeercred() -- return the peer credentials as ucred [*]\n\ getsockname() -- return local address\n\ getsockopt(level, optname[, buflen]) -- get socket options\n\ gettimeout() -- return timeout or None\n\ @@ -404,11 +405,16 @@ static int taskwindow; static int taskwindow; #endif -/* A forward reference to the socket type object. +/* A forward reference to the socket and ucred type objects. The sock_type variable contains pointers to various functions, some of which call new_sockobject(), which uses sock_type, so - there has to be a circular reference. */ + there has to be a circular reference. + The ucred_type variable contains the machinery used to + construct ucred objects, which is needed by getpeercred(). */ static PyTypeObject sock_type; +#ifdef HAVE_STRUCT_UCRED +static PyTypeObject ucred_type; +#endif /* HAVE_STRUCT_UCRED */ /* Can we call select() with this socket without a buffer overrun? */ #ifdef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE @@ -2042,6 +2048,49 @@ info is a pair (hostaddr, port)."); #endif /* HAVE_GETPEERNAME */ +#if defined(HAVE_STRUCT_UCRED) && defined(SO_PEERCRED) +/* s.getpeercred() method */ + +static PyObject * +sock_getpeercred(PySocketSockObject *s, PyObject *args) +{ + PyTypeObject *cur_ucred_type = &ucred_type; + PySocketUcredObject *peercred = NULL; + int buflen = sizeof(struct ucred); + + if (!PyArg_ParseTuple(args, "|O:getpeercred", &cur_ucred_type)) + return NULL; + +#ifdef __BEOS__ + /* We have incomplete socket option support. */ + PyErr_SetString(socket_error, "getpeercred not supported"); + return NULL; +#else + if (!PyType_IsSubtype(cur_ucred_type, &ucred_type)) { + PyErr_SetString(PyExc_TypeError, + "need a _socket.ucred derived class as argument"); + return NULL; + } + + if (!(peercred = (PySocketUcredObject*)PyType_GenericAlloc( + cur_ucred_type, 1))) + return NULL; + if (getsockopt(s->sock_fd, SOL_SOCKET, SO_PEERCRED, &peercred->ucred, + &buflen)) + return s->errorhandler(); + + return (PyObject*)peercred; +#endif /* __BEOS__ */ +} + +PyDoc_STRVAR(getpeercred_doc, +"getpeercred() -> credentials info\n\ +\n\ +Return a ucred structure with the credentials of the connected process."); + +#endif /* defined(HAVE_STRUCT_UCRED) && defined(SO_PEERCRED) */ + + /* s.listen(n) method */ static PyObject * @@ -2522,6 +2571,10 @@ static PyMethodDef sock_methods[] = { #ifdef HAVE_GETPEERNAME {"getpeername", (PyCFunction)sock_getpeername, METH_NOARGS, getpeername_doc}, +#endif +#if defined(HAVE_STRUCT_UCRED) && defined(SO_PEERCRED) + {"getpeercred", (PyCFunction)sock_getpeercred, + METH_VARARGS, getpeercred_doc}, #endif {"getsockname", (PyCFunction)sock_getsockname, METH_NOARGS, getsockname_doc}, @@ -2705,6 +2758,140 @@ static PyTypeObject sock_type = { }; +/* Only define ucred if it's defined in sys/socket.h... */ +#ifdef HAVE_STRUCT_UCRED + +static PyObject * +ucred_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + static char *kwlist[] = {"pid", "uid", "gid", NULL}; + PySocketUcredObject *self = NULL; + + if (!(self = (PySocketUcredObject *)type->tp_alloc(type, 0))) + return NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "iii", kwlist, + &self->ucred.pid, + &self->ucred.uid, + &self->ucred.gid)) { + Py_DECREF(self); + return NULL; + } + + return (PyObject *)self; +} + +static PyObject * +ucred_repr(PySocketUcredObject *self) +{ + char buf[512]; + + PyOS_snprintf(buf,sizeof(buf), + "", + self->ucred.pid, + self->ucred.uid, + self->ucred.gid); + return PyString_FromString(buf); +} + +static long +ucred_hash(PySocketUcredObject *self) +{ + return self->ucred.pid + self->ucred.uid*(1<<10) + + self->ucred.gid*(1<<20); +} + +static PyObject * +ucred_richcompare(PyObject *v, PyObject *w, int op) +{ + PyObject *rv; + int cmp; + + if (!PyObject_IsInstance(v, (PyObject *)&ucred_type) || + !PyObject_IsInstance(w, (PyObject *)&ucred_type)) { + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } + + if (op != Py_EQ && op != Py_NE) { + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } + + cmp = memcmp(&((PySocketUcredObject *)v)->ucred, + &((PySocketUcredObject *)w)->ucred, + sizeof(struct ucred)); + + rv = (op == Py_EQ ? !cmp : cmp) ? Py_True : Py_False; + Py_INCREF(rv); + return rv; +} + +static PyMethodDef ucred_methods[] = { + {NULL} +}; + +static PyMemberDef ucred_memberlist[] = { + {"pid", T_INT, offsetof(PySocketUcredObject, ucred.pid), + READONLY, "Process ID of remote process."}, + {"uid", T_INT, offsetof(PySocketUcredObject, ucred.uid), + READONLY, "User ID of remote process."}, + {"gid", T_INT, offsetof(PySocketUcredObject, ucred.gid), + READONLY, "Group ID of remote process."}, + {NULL} +}; + +PyDoc_STRVAR(ucred_doc, +"ucred(pid, uid, gid) -> ucred object\n\ +\n\ +Create a new ucred object which is used to store process\n\ +information when communicating with a remote process on the\n\ +local machine."); + +static PyTypeObject ucred_type = { + PyObject_HEAD_INIT(0) /* Must fill in type value later */ + 0, /* ob_size */ + "_socket.ucred", /* tp_name */ + sizeof(PySocketUcredObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)ucred_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)ucred_hash, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ucred_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + ucred_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + ucred_methods, /* tp_methods */ + ucred_memberlist, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + ucred_new, /* tp_new */ +}; + +#endif /* HAVE_STRUCT_UCRED */ + + /* Python interface to gethostname(). */ /*ARGSUSED*/ @@ -4028,6 +4215,15 @@ init_socket(void) (PyObject *)&sock_type) != 0) return; +#ifdef HAVE_STRUCT_UCRED + if (PyType_Ready((PyTypeObject *)&ucred_type) < 0) + return; + Py_INCREF((PyObject *)&ucred_type); + if (PyModule_AddObject(m, "ucred", + (PyObject *)&ucred_type) != 0) + return; +#endif + #ifdef ENABLE_IPV6 has_ipv6 = Py_True; #else @@ -4212,6 +4408,7 @@ init_socket(void) #endif #endif + /* Socket options. */ #ifdef SO_DEBUG PyModule_AddIntConstant(m, "SO_DEBUG", SO_DEBUG); #endif @@ -4269,6 +4466,20 @@ init_socket(void) #endif #ifdef SO_TYPE PyModule_AddIntConstant(m, "SO_TYPE", SO_TYPE); +#endif +#ifdef SO_PASSCRED + PyModule_AddIntConstant(m, "SO_PASSCRED", SO_PASSCRED); +#endif +#ifdef SO_PEERCRED + PyModule_AddIntConstant(m, "SO_PEERCRED", SO_PEERCRED); +#endif + + /* Socket ancillary message types. */ +#ifdef SCM_RIGHTS + PyModule_AddIntConstant(m, "SCM_RIGHTS", SCM_RIGHTS); +#endif +#ifdef SCM_CREDENTIALS + PyModule_AddIntConstant(m, "SCM_CREDENTIALS", SCM_CREDENTIALS); #endif /* Maximum number of connections for "listen" */ diff -r 74acdbfca2ee Modules/socketmodule.h --- a/Modules/socketmodule.h Sat May 20 21:30:13 2006 +0200 +++ b/Modules/socketmodule.h Sat May 20 23:32:06 2006 +0200 @@ -122,6 +122,18 @@ typedef struct { 0.0 means non-blocking */ } PySocketSockObject; +#ifdef HAVE_STRUCT_UCRED +#include + +/* The object holding a ucred struct. */ + +typedef struct { + PyObject_HEAD + struct ucred ucred; +} PySocketUcredObject; + +#endif /* HAVE_STRUCT_UCRED */ + /* --- C API ----------------------------------------------------*/ /* Short explanation of what this C API export mechanism does diff -r 74acdbfca2ee configure --- a/configure Sat May 20 21:30:13 2006 +0200 +++ b/configure Sat May 20 23:32:06 2006 +0200 @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 46010 . +# From configure.in Revision: 46046 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59 for python 2.5. # @@ -722,13 +722,13 @@ echo X"$0" | /^X\(\/\).*/{ s//\1/; q; } s/.*/./; q'` srcdir=$ac_confdir - if test ! -r $srcdir/$ac_unique_file; then + if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi -if test ! -r $srcdir/$ac_unique_file; then +if test ! -r "$srcdir/$ac_unique_file"; then if test "$ac_srcdir_defaulted" = yes; then { echo "$as_me: error: cannot find sources ($ac_unique_file) in $ac_confdir or .." >&2 { (exit 1); exit 1; }; } @@ -737,7 +737,7 @@ if test ! -r $srcdir/$ac_unique_file; th { (exit 1); exit 1; }; } fi fi -(cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null || +(cd $srcdir && test -r "./$ac_unique_file") 2>/dev/null || { echo "$as_me: error: sources are in $srcdir, but \`cd $srcdir' does not work" >&2 { (exit 1); exit 1; }; } srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'` @@ -21585,6 +21585,76 @@ then cat >>confdefs.h <<\_ACEOF #define HAVE_STAT_TV_NSEC2 1 +_ACEOF + +fi + +# Check for struct ucred definition +echo "$as_me:$LINENO: checking for struct ucred in sys/socket.h" >&5 +echo $ECHO_N "checking for struct ucred in sys/socket.h... $ECHO_C" >&6 +if test "${ac_cv_struct_ucred_defined+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#ifdef HAVE_SYS_SOCKET_H +#include +#endif + +int +main () +{ + +struct ucred ucred; + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_struct_ucred_defined=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_struct_ucred_defined=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +echo "$as_me:$LINENO: result: $ac_cv_struct_ucred_defined" >&5 +echo "${ECHO_T}$ac_cv_struct_ucred_defined" >&6 +if test "$ac_cv_struct_ucred_defined" = yes +then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_STRUCT_UCRED 1 _ACEOF fi diff -r 74acdbfca2ee configure.in --- a/configure.in Sat May 20 21:30:13 2006 +0200 +++ b/configure.in Sat May 20 23:32:06 2006 +0200 @@ -3210,6 +3210,26 @@ then [Define if you have struct stat.st_mtimensec]) fi +# Check for struct ucred definition +AC_MSG_CHECKING(for struct ucred in sys/socket.h) +AC_CACHE_VAL(ac_cv_struct_ucred_defined, +AC_TRY_COMPILE([ +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +], [ +struct ucred ucred; +], +ac_cv_struct_ucred_defined=yes, +ac_cv_struct_ucred_defined=no, +ac_cv_struct_ucred_defined=no)) +AC_MSG_RESULT($ac_cv_struct_ucred_defined) +if test "$ac_cv_struct_ucred_defined" = yes +then + AC_DEFINE(HAVE_STRUCT_UCRED, 1, + [Define if struct ucred is available in bits/socket.h]) +fi + # On HP/UX 11.0, mvwdelch is a block with a return statement AC_MSG_CHECKING(whether mvwdelch is an expression) AC_CACHE_VAL(ac_cv_mvwdelch_is_expression, diff -r 74acdbfca2ee pyconfig.h.in --- a/pyconfig.h.in Sat May 20 21:30:13 2006 +0200 +++ b/pyconfig.h.in Sat May 20 23:32:06 2006 +0200 @@ -521,6 +521,9 @@ /* Define to 1 if `tm_zone' is member of `struct tm'. */ #undef HAVE_STRUCT_TM_TM_ZONE + +/* Define if struct ucred is available in bits/socket.h */ +#undef HAVE_STRUCT_UCRED /* Define to 1 if your `struct stat' has `st_blocks'. Deprecated, use `HAVE_STRUCT_STAT_ST_BLOCKS' instead. */