[Twisted-Python] Re: Switch to a different uid/gid after binding reserved ports (G lyph Lefkowitz)

Richard.Townsend at edl.uk.eds.com Richard.Townsend at edl.uk.eds.com
Mon Jun 9 05:34:16 EDT 2003

> You can specify keyword arguments to Application's constructor.
> 	a = Application(uid=1001, gid=1001)
> Then, call either the setUID or setEUID method of your Application 
> instance.  You will need to call bindPorts before calling these 
> methods, however.

Hi Glyph,

I have now had a chance to test this on HP-UX11i and have discovered a

The code for Application.setUID() calls os.getgid() expecting it to return 0
for root. However, on HP-UX it returns 3.

# id
uid=0(root) gid=3(sys)

# /opt/python/bin/python          
Python 2.2.1 (#5, Jan 23 2003, 13:18:26) [C] on hp-ux11
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.getgid()


>>> os.getgroups()
[3, 0, 1, 2, 4, 5, 6, 7, 20]

A possible solution would be:

    def setUID(self):
        """Retrieve persistent uid/gid pair (if possible) and set the
current process's uid/gid
        if hasattr(os, 'getgroups'):
            if 0 in os.getgroups():
                log.msg('set uid/gid %s/%s' % (self.uid, self.gid))

Alternatively, you might use try/except & ignore OSError exceptions?

Richard Townsend
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20030609/c7eedc81/attachment.htm 

More information about the Twisted-Python mailing list