1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
#!/usr/bin/python
import sys
import common.db
import common.chat
import common.makeuser
# usage:
# usrmgt-server <port> <magic>
# User management operations:
# - Create local user
# - [Re]Create jail for a user
# - Create a svn repository for a user
# - create repository
# - svn config
# - svn auth
# - Checkout repository as home directory
# - /etc/passwd entry
# - Disable a user's account
# - Enable a user's account
# - Remove a user
# - Rebuild svn config
# - Rebuild svn auth file
# - Rebuild passwd + push to nodes.
def create_user(props):
"""Create the database record for the given user.
Expected properties:
username - used as a unix login name and svn repository name.
STRING REQUIRED
uid - the unix uid under which execution will take place
on the behalf of the user. Don't use 0! If not specified
or None, one will be allocated from the configured
numeric range.
INT OPTIONAL
password - the clear-text password for the user. If this property is
absent or None, this is an indication that external
authentication should be used (i.e. LDAP).
STRING OPTIONAL
email - the user's email address.
STRING OPTIONAL
nick - the display name to use.
STRING REQUIRED
fullname - The name of the user for results and/or other official
purposes.
STRING REQUIRED
rolenm - The user's role. Must be one of "anyone", "student",
"tutor", "lecturer", "admin".
STRING/ENUM REQUIRED
studentid - If supplied and not None, the student id of the user for
results and/or other official purposes.
STRING OPTIONAL
Return Value: the uid associated with the user. INT
"""
# FIXME: the IVLE server must check that an admin is doing this!
if 'uid' not in props or props['uid'] is None:
raise NotImplementedError, "No algorithm for creating uids yet!"
# uid = invent-uid
# props['uid'] = uid
username = props['username']
uid = props['uid']
try:
password = props['password']
except KeyError:
password = None
try:
email = props['email']
except KeyError:
email = None
nick = props['nick']
fullname = props['fullname']
rolenm = props['rolenm']
try:
studentid = props['studentid']
except KeyError:
studentid = None
common.makeuser.make_user_db(username, uid, password, email, nick,
fullname, rolenm, studentid)
return uid
def activate_user(props):
"""Create the on-disk stuff for the given user.
Sets the state of the user in the db from pending to enabled.
Expected properties:
login - the user name for the jail
STRING REQUIRED
Return Value: None
"""
login = props['login']
db = common.db.DB()
try:
# FIXME: check we're pending
details = db.get_user(login)
# FIXME: make svn config/auth
# FIXME: etc, etc.
common.makeuser.make_jail(login, details['unixid'])
db.update_user(login, state='enabled')
return {"response": "okay"}
finally:
db.close()
actions = {
'create_user':create_user,
'activate_user':activate_user
}
def dispatch(props):
action = props.keys()[0]
return actions[action](props[action])
if __name__ == "__main__":
port = int(sys.argv[1])
magic = sys.argv[2]
common.chat.start_server(port, magic, False, dispatch)
|