440
by drtomc
usrmgt: move the usrmgt sever to a better place. |
1 |
#!/usr/bin/python
|
2 |
||
3 |
import sys |
|
4 |
||
5 |
import common.chat |
|
6 |
import common.makeuser |
|
7 |
||
8 |
# usage:
|
|
9 |
# usrmgt-server <port> <magic>
|
|
10 |
||
452
by drtomc
usrmgt: checkpoint work on the usrmgt server. |
11 |
# User management operations:
|
12 |
# - Create local user
|
|
13 |
# - [Re]Create jail for a user
|
|
14 |
# - Create a svn repository for a user
|
|
15 |
# - create repository
|
|
16 |
# - svn config
|
|
17 |
# - svn auth
|
|
18 |
# - Checkout repository as home directory
|
|
19 |
# - /etc/passwd entry
|
|
20 |
# - Disable a user's account
|
|
21 |
# - Enable a user's account
|
|
22 |
# - Remove a user
|
|
23 |
# - Rebuild svn config
|
|
24 |
# - Rebuild svn auth file
|
|
25 |
# - Rebuild passwd + push to nodes.
|
|
26 |
||
27 |
||
440
by drtomc
usrmgt: move the usrmgt sever to a better place. |
28 |
def create_user(props): |
452
by drtomc
usrmgt: checkpoint work on the usrmgt server. |
29 |
"""Create the database record for the given user.
|
30 |
Expected properties:
|
|
31 |
username - used as a unix login name and svn repository name.
|
|
32 |
STRING REQUIRED
|
|
33 |
uid - the unix uid under which execution will take place
|
|
454
by drtomc
usrmgt-server: more work. |
34 |
on the behalf of the user. Don't use 0! If not specified
|
35 |
or None, one will be allocated from the configured
|
|
36 |
numeric range.
|
|
37 |
INT OPTIONAL
|
|
38 |
password - the clear-text password for the user. If this property is
|
|
39 |
absent or None, this is an indication that external
|
|
40 |
authentication should be used (i.e. LDAP).
|
|
452
by drtomc
usrmgt: checkpoint work on the usrmgt server. |
41 |
STRING OPTIONAL
|
42 |
nick - the display name to use.
|
|
43 |
STRING REQUIRED
|
|
44 |
fullname - The name of the user for results and/or other official
|
|
45 |
purposes.
|
|
46 |
STRING REQUIRED
|
|
47 |
rolenm - The user's role. Must be one of "anyone", "student",
|
|
48 |
"tutor", "lecturer", "admin".
|
|
49 |
STRING/ENUM REQUIRED
|
|
454
by drtomc
usrmgt-server: more work. |
50 |
studentid - If supplied and not None, the student id of the user for
|
452
by drtomc
usrmgt: checkpoint work on the usrmgt server. |
51 |
results and/or other official purposes.
|
52 |
STRING OPTIONAL
|
|
454
by drtomc
usrmgt-server: more work. |
53 |
Return Value: the uid associated with the user. INT
|
452
by drtomc
usrmgt: checkpoint work on the usrmgt server. |
54 |
"""
|
440
by drtomc
usrmgt: move the usrmgt sever to a better place. |
55 |
|
456
by drtomc
usrmgt-server: a bit more work. |
56 |
if 'uid' not in props or props['uid'] is None: |
454
by drtomc
usrmgt-server: more work. |
57 |
raise Exception, "No algorithm for creating uids yet!" |
58 |
# uid = invent-uid
|
|
59 |
# props['uid'] = uid
|
|
440
by drtomc
usrmgt: move the usrmgt sever to a better place. |
60 |
|
61 |
common.makeuser.make_user_db(props['username'], props['uid'], |
|
62 |
props['password'], props['nick'], |
|
63 |
props['fullname'], props['rolenm'], |
|
64 |
props['studentid']) |
|
65 |
||
454
by drtomc
usrmgt-server: more work. |
66 |
return props['uid'] |
67 |
||
68 |
def create_jail(props): |
|
69 |
"""Create the jail for a user.
|
|
70 |
Expected properties:
|
|
71 |
username - the username for the jail
|
|
72 |
STRING REQUIRED
|
|
73 |
uid - the unix uid to make the owner of the home directory
|
|
74 |
in the jail.
|
|
75 |
INT REQUIRED
|
|
76 |
gid - the unix group id to make the group of the home directory
|
|
77 |
in the jail. If not supplied (or None), then the uid is
|
|
78 |
also used.
|
|
79 |
INT OPTIONAL
|
|
456
by drtomc
usrmgt-server: a bit more work. |
80 |
Return Value: None
|
454
by drtomc
usrmgt-server: more work. |
81 |
"""
|
456
by drtomc
usrmgt-server: a bit more work. |
82 |
|
83 |
if 'gid' not in props or props['gid'] is None: |
|
84 |
gid = props['uid'] |
|
85 |
||
86 |
common.makeuser.make_jail(props['username'], props['uid'], gid) |
|
87 |
||
454
by drtomc
usrmgt-server: more work. |
88 |
return None |
440
by drtomc
usrmgt: move the usrmgt sever to a better place. |
89 |
|
452
by drtomc
usrmgt: checkpoint work on the usrmgt server. |
90 |
actions = { |
454
by drtomc
usrmgt-server: more work. |
91 |
'create-user':create_user, |
92 |
'create-jail':create_jail |
|
452
by drtomc
usrmgt: checkpoint work on the usrmgt server. |
93 |
}
|
94 |
||
95 |
def dispatch(props): |
|
96 |
action = props.keys()[0] |
|
97 |
return actions[action](props[action]) |
|
98 |
||
440
by drtomc
usrmgt: move the usrmgt sever to a better place. |
99 |
if __name__ == "__main__": |
100 |
port = int(sys.argv[1]) |
|
101 |
magic = sys.argv[2] |
|
102 |
||
452
by drtomc
usrmgt: checkpoint work on the usrmgt server. |
103 |
common.chat.start_server(port, magic, False, dispatch) |