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
|
#!/usr/bin/python
import sys
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
"""
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 create_jail(props):
"""Create the jail for a user.
Expected properties:
username - the username for the jail
STRING REQUIRED
uid - the unix uid to make the owner of the home directory
in the jail.
INT REQUIRED
gid - the unix group id to make the group of the home directory
in the jail. If not supplied (or None), then the uid is
also used.
INT OPTIONAL
Return Value: None
"""
if 'gid' not in props or props['gid'] is None:
gid = props['uid']
common.makeuser.make_jail(props['username'], props['uid'], gid)
return None
actions = {
'create-user':create_user,
'init-jail':create_jail
}
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)
|