1 """This is the child program run by the su module. Do not import this module."""
3 import cPickle
as pickle
13 """Contains a file descriptor and a function to call when it's ready"""
14 def __init__(self
, fd
, fn
):
21 class SuSlave(proxy
.SlaveProxy
):
22 """A simple implementation of SlaveProxy that doesn't use gtk"""
23 def __init__(self
, to_parent
, from_parent
, slave
):
24 self
.read_watch
= Watch(from_parent
, self
.read_ready
)
25 self
.write_watch
= Watch(to_parent
, self
.write_ready
)
26 proxy
.SlaveProxy
.__init
__(self
, to_parent
, from_parent
, slave
)
28 def enable_read_watch(self
):
29 assert self
.read_watch
not in read_watches
30 read_watches
.append(self
.read_watch
)
32 def enable_write_watch(self
):
33 assert self
.write_watch
not in write_watches
34 write_watches
.append(self
.write_watch
)
37 """This object runs as another user. Most methods behave in a similar
38 way to the standard python methods of the same name."""
40 def spawnvpe(self
, request
, mode
, file, args
, env
= None):
42 request
.send(os
.spawnvp(mode
, file, args
))
44 request
.send(os
.spawnvpe(mode
, file, args
, env
))
46 def waitpid(self
, request
, pid
, flags
):
47 request
.send(os
.waitpid(pid
, flags
))
49 def getuid(self
, request
):
50 request
.send(os
.getuid())
52 def setuid(self
, request
, uid
):
53 request
.send(os
.setuid(uid
))
55 def rmtree(self
, request
, path
):
59 if __name__
== '__main__':
60 from select
import select
62 to_parent
, from_parent
= map(int, sys
.argv
[1:])
64 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(sys
.argv
[0]))))
66 slave_proxy
= SuSlave(to_parent
, from_parent
, Slave())
68 while read_watches
or write_watches
:
69 readable
, writable
= select(read_watches
, write_watches
, [])[:2]
72 read_watches
.remove(w
)
75 write_watches
.remove(w
)