4
# usrmgt-server <port> <magic>
16
if os.fork(): # launch child and...
17
os._exit(0) # kill off parent
19
if os.fork(): # launch child and...
20
os._exit(0) # kill off parent again.
23
# The global 'magic' is the secret that the client and server share
24
# which is used to create and md5 digest to authenticate requests.
25
# It is assigned a real value at startup.
28
if __name__ == "__main__":
29
port = int(sys.argv[1])
32
# Attempt to open the socket.
33
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
37
# Excellent! It worked. Let's turn ourself into a daemon,
38
# then get on with the job of being a python interpreter.
42
(conn, addr) = s.accept()
45
buf = cStringIO.StringIO()
50
blk = conn.recv(1024, socket.MSG_DONTWAIT)
52
# Exception thrown if it WOULD block (but we
53
# told it not to wait) - ie. we are done
56
msg = cjson.decode(inp)
58
# Check that the message is
59
digest = md5.new(msg['login'] + magic).digest().encode('hex')
60
if msg['digest'] != digest:
64
os.system("useradd '%s'" % msg['login'])
66
os.system("scp /etc/passwd informatics%s:/etc/passwd" % str(n))
68
conn.sendall(cjson.encode(True))