98
98
db.update_user(**update)
101
def get_login(login, passwd, realm, existing_login, _may_save):
101
def get_login(login, passwd, _realm, _login, _may_save):
102
102
"""Callback function used by pysvn for authentication.
103
login, passwd: Credentials of the user attempting to log in.
104
passwd in clear (this should be the user's svn_pass, a
105
randomly-generated permanent password for this user, not their main
107
realm, existing_login, _may_save: The 3 arguments passed by pysvn to
109
The following has been determined empirically, not from docs:
110
existing_login will be the name of the user who owns the process on
111
the first attempt, "" on subsequent attempts. We use this fact.
113
logging.debug("Getting password for %s (realm %s)" % (login, realm))
114
# Only provide credentials on the _first_ attempt.
115
# If we're being asked again, then it means the credentials failed for
116
# some reason and we should just fail. (This is not desirable, but it's
117
# better than being asked an infinite number of times).
118
if existing_login == "":
119
logging.warning("Could not authenticate SVN for %s" % login)
120
return (False, login, passwd, False)
122
return (True, login, passwd, False)
104
logging.debug("Getting password for %s (realm %s)" % (login, _realm))
105
return (True, login, passwd, False)
124
107
def activate_user(props):
125
108
"""Create the on-disk stuff for the given user.
182
163
logging.debug("Creating jail")
183
common.makeuser.make_jail(login, details.unixid, svn_pass=passwd)
185
common.makeuser.mount_jail(login)
187
do_checkout(props, svn_pass=passwd)
164
common.makeuser.make_jail(login, details.unixid)
168
tcf_path = os.path.join(conf.jail_base, 'template/opt/ivle/lib/conf/conf.py')
169
cf_path = os.path.join(conf.jail_base, login, 'opt/ivle/lib/conf/conf.py')
172
cf = open(cf_path, "w")
173
cf.write(open(tcf_path, "r").read())
174
cf.write("# The login name for the owner of the jail\n")
175
cf.write("login = %s\n" % repr(login))
177
cf.write("# The subversion-only password for the owner of the jail\n")
178
cf.write("svn_pass = %s\n" % repr(passwd))
181
# Check out the repositories into the student's home dir
182
# FIXME: Call do_checkout instead of replicating this code.
183
# (do_checkout currently doesn't work)
188
logging.debug("Checking out directories in the jail")
190
svn.checkout(conf.svn_addr + login + "/stuff",
191
common.studpath.url_to_local(login + "/stuff")[1])
192
os.system("chown -R %d:%d %s" \
193
% (details.unixid, details.unixid,
194
common.studpath.url_to_local(login + "/stuff")[1]))
195
except Exception, exc:
196
logging.warning("While mkdiring stuff: %s" % str(exc))
199
svn.checkout(conf.svn_addr + login + "/info1",
200
common.studpath.url_to_local(login + "/info1")[1])
201
os.system("chown -R %d:%d %s" \
202
% (details.unixid, details.unixid,
203
common.studpath.url_to_local(login + "/info1")[1]))
204
except Exception, exc:
205
logging.warning("While mkdiring info1: %s" % str(exc))
189
208
# FIXME: should this be nicer?
190
209
os.system("chown -R %d:%d %s" \
191
210
% (details.unixid, details.unixid,
192
211
common.studpath.url_to_local(login)[1]))
194
214
logging.info("Enabling user")
195
215
db.update_user(login, state='enabled')
210
230
Return Value: None
232
# XXX / FIXME: This doesn't work - cannot get passwd
233
# (activate_me creates passwd, other svn stuff gets it from jailconf - we
234
# can't access either at this point).
212
236
login = props['login']
215
user = db.get_user(login)
216
# If svn_pass isn't supplied, grab it from the DB
218
svn_pass = user.svn_pass
221
237
svn = pysvn.Client()
222
svn.callback_get_login = partial(get_login, login, svn_pass)
224
if conf.svn_addr[-1] != os.sep:
225
conf.svn_addr += os.sep
238
svn.callback_get_login = partial(get_login, login, passwd)
240
if conf.svn_addr[-1] != '/':
241
conf.svn_addr = conf.svn_addr + "/"
229
245
logging.debug("Checking out directories in the jail")
231
247
svn.checkout(conf.svn_addr + login + "/stuff",
232
248
common.studpath.url_to_local(login + "/stuff")[1])
233
249
os.system("chown -R %d:%d %s" \
234
% (user.unixid, user.unixid,
250
% (details.unixid, details.unixid,
235
251
common.studpath.url_to_local(login + "/stuff")[1]))
236
252
except Exception, exc:
237
253
logging.warning("While mkdiring stuff: %s" % str(exc))
240
256
svn.checkout(conf.svn_addr + login + "/info1",
241
257
common.studpath.url_to_local(login + "/info1")[1])
242
258
os.system("chown -R %d:%d %s" \
243
% (user.unixid, user.unixid,
259
% (details.unixid, details.unixid,
244
260
common.studpath.url_to_local(login + "/info1")[1]))
245
261
except Exception, exc:
246
262
logging.warning("While mkdiring info1: %s" % str(exc))
251
265
return {"response": "okay"}