[Patches] [ python-Patches-1492240 ] Socket-object convenience function: getpeercred().

SourceForge.net noreply at sourceforge.net
Sat May 20 23:39:03 CEST 2006


Patches item #1492240, was opened at 2006-05-20 23:39
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1492240&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Heiko Wundram (hwundram)
Assigned to: Nobody/Anonymous (nobody)
Summary: Socket-object convenience function: getpeercred().

Initial Comment:
The attached patch implements a convenience function
called getpeercred() which internally calls
getsockopt(SO_PEERCRED) to retrieve the credentials
(pid, uid and gid) of the remote process a socket is
attached to, in case the remote end is local.

This currently (AFAIK) only works (properly) on Linux
2.4+, but might work on BSD-style systems too.

The returned data is wrapped in a new ucred type, which
is subclassable to implement additional convenience
functions in Lib/socket.py.

The patch updates the socket module, the test suite,
the documentation (including whatsnew), and adds a
configure check for the definition of struct ucred in
sys/socket.h, which is the default place for struct
ucred if it is available.

If struct ucred is not available on the current system,
getpeercred() is made a dummy method, which returns a
python-defined ucred type which contains pid=0,
uid=gid=-1, which are the default values returned under
Linux when the call fails because there is no
credentials data associated with the socket.

The decision to move the data to a separate type was
made with respect to the ability to use struct ucred
under other systems in a SCM_CREDENTIALS sendmsg()
call. I'll post the implementation of sendmsg() and
recvmsg() as a separate tracker item, but the latter
patch will rely on the inclusion of this patch.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1492240&group_id=5470


More information about the Patches mailing list