25
28
# - Rebuild svn auth file
26
29
# - Rebuild passwd + push to nodes.
29
def create_user(props):
30
"""Create the database record for the given user.
32
username - used as a unix login name and svn repository name.
34
uid - the unix uid under which execution will take place
35
on the behalf of the user. Don't use 0! If not specified
36
or None, one will be allocated from the configured
39
password - the clear-text password for the user. If this property is
40
absent or None, this is an indication that external
41
authentication should be used (i.e. LDAP).
43
email - the user's email address.
45
nick - the display name to use.
47
fullname - The name of the user for results and/or other official
50
rolenm - The user's role. Must be one of "anyone", "student",
51
"tutor", "lecturer", "admin".
53
studentid - If supplied and not None, the student id of the user for
54
results and/or other official purposes.
56
Return Value: the uid associated with the user. INT
59
# FIXME: the IVLE server must check that an admin is doing this!
61
if 'uid' not in props or props['uid'] is None:
62
raise NotImplementedError, "No algorithm for creating uids yet!"
66
username = props['username']
69
password = props['password']
73
email = props['email']
77
fullname = props['fullname']
78
rolenm = props['rolenm']
80
studentid = props['studentid']
83
common.makeuser.make_user_db(username, uid, password, email, nick,
84
fullname, rolenm, studentid)
88
31
def activate_user(props):
89
32
"""Create the on-disk stuff for the given user.
90
33
Sets the state of the user in the db from pending to enabled.
105
50
details = db.get_user(login)
107
# FIXME: make svn config/auth
111
common.makeuser.make_jail(login, details['unixid'])
52
# make svn config/auth
54
repopath = os.path.join(conf.svn_repo_path, 'users', login)
55
logging.debug("Creating user's Subversion repository")
56
common.makeuser.make_svn_repo(repopath, throw_on_error=False)
58
logging.debug("Rebuilding Subversion authorization config")
60
common.makeuser.rebuild_svn_config()
62
logging.warning('Rebuild of Subversion authorization config failed!')
64
logging.debug("Adding Subversion authentication")
65
passwd = common.makeuser.make_svn_auth(login, throw_on_error=False)
66
logging.debug("passwd: %s" % passwd)
68
logging.debug("Creating jail")
69
common.makeuser.make_jail(login, details.unixid, svn_pass=passwd)
71
logging.info("Enabling user")
113
72
db.update_user(login, state='enabled')
115
74
return {"response": "okay"}
121
'create_user':create_user,
122
'activate_user':activate_user
80
'activate_user':activate_user,
85
pidfile = open('/var/run/usrmgt-server.pid', 'w')
86
pidfile.write('%d\n' % os.getpid())
88
except IOError, (errno, strerror):
89
print "Couldn't write PID file. IO error(%s): %s" % (errno, strerror)
125
92
def dispatch(props):
93
logging.debug(repr(props))
126
94
action = props.keys()[0]
127
95
return actions[action](props[action])
129
97
if __name__ == "__main__":
99
print >>sys.stderr, "Usage: usrmgt-server <port> <magic>"
130
101
port = int(sys.argv[1])
131
102
magic = sys.argv[2]
133
common.chat.start_server(port, magic, False, dispatch)
106
logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
107
logging.info("Starting usrmgt server on port %d (pid = %d)" % (port, pid))
109
common.chat.start_server(port, magic, True, dispatch, initializer)