[solved] authenticating users for the control socket

martin f krafft madduck at debian.org
Tue Jun 12 10:01:30 UTC 2007


also sprach martin f krafft <madduck at debian.org> [2007.06.12.1004 +0100]:
> >>> SO_PEERCRED = 17
> >>> s.getsockopt(SOL_SOCKET, SO_PEERCRED)
> 17110
> >>> os.getpid()
> 17110

I have to use the socket returned by socket.accept(), of course.
Doh.

>>> s = socket(AF_UNIX)
>>> s.bind('/tmp/s')
>>> s.listen(1)
>>> ps = s.accept()[0]
>>> SO_PEERCRED = 17
>>> ps.getsockopt(SOL_SOCKET, SO_PEERCRED, 1024)
'\xd8B\x00\x00\xe8\x03\x00\x00\xe8\x03\x00\x00'
>>> import struct
>>> fmt = 'III'
>>> struct.unpack(fmt, s.getsockopt(SOL_SOCKET, SO_PEERCRED, 1024))
(17110, 1000, 1000)
>>> struct.unpack(fmt, ps.getsockopt(SOL_SOCKET, SO_PEERCRED, 1024))
(17112, 1000, 1000)

17112 is the client's PID and the user ID is 1000/1000. We should be
able to work with that just fine. Yay.

Thanks to Soren Hansen for his help.

-- 
 .''`.   martin f. krafft <madduck at debian.org>
: :'  :  proud Debian developer, author, administrator, and user
`. `'`   http://people.debian.org/~madduck - http://debiansystem.info
  `-  Debian - when you have better things to do than fixing systems
 
"if you have built castles in the air, your work need not be lost;
 that is where they should be. now put the foundations under them."
                                                -- henry david thoreau
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature (GPG/PGP)
Url : http://lists.alioth.debian.org/pipermail/netconf-devel/attachments/20070612/8c523ecd/attachment.pgp 


More information about the netconf-devel mailing list