4
9
# 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.
11
def create_user(props):
13
if 'uid' not in props:
17
common.makeuser.make_user_db(props['username'], props['uid'],
18
props['password'], props['nick'],
19
props['fullname'], props['rolenm'],
22
common.makeuser.make_jail(props['username'], props['uid'])
24
# eventually, we're going to want to grant shell access, in which
25
# case we'll need to add the uid to the password file. Magic to do
26
# that should go here.
28
30
if __name__ == "__main__":
29
31
port = int(sys.argv[1])
30
32
magic = sys.argv[2]
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))
34
common.chat.start_server(port, magic, False, create_user)