~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/makeuser.py

  • Committer: William Grant
  • Date: 2009-12-08 05:26:00 UTC
  • Revision ID: grantw@unimelb.edu.au-20091208052600-j5jpe25vgjtypex9
Fix missing GroupsView when creating a project set.

Show diffs side-by-side

added added

removed removed

Lines of Context:
211
211
    """
212
212
    # filename is, eg, /var/lib/ivle/svn/ivle.auth
213
213
    filename = config['paths']['svn']['auth_ivle']
214
 
    passwd = hashlib.md5(uuid.uuid4().bytes).hexdigest()
215
214
    if os.path.exists(filename):
216
215
        create = ""
217
216
    else:
218
217
        create = "c"
219
218
 
220
219
    user = User.get_by_login(store, login)
221
 
    user.svn_pass = unicode(passwd)
 
220
 
 
221
    if user.svn_pass is None:
 
222
        passwd = hashlib.md5(uuid.uuid4().bytes).hexdigest()
 
223
        user.svn_pass = unicode(passwd)
222
224
 
223
225
    res = subprocess.call(['htpasswd', '-%smb' % create,
224
 
                           filename, login, passwd])
 
226
                           filename, login, user.svn_pass])
225
227
    if res != 0 and throw_on_error:
226
228
        raise Exception("Unable to create ivle-auth for %s" % login)
227
229
 
229
231
    if create == "c":
230
232
        chown_to_webserver(filename)
231
233
 
232
 
    return passwd
 
234
    return user.svn_pass
233
235
 
234
236
def make_jail(user, config, force=True):
235
237
    """Create or update a user's jail.
258
260
        os.mkdir(tempdir)
259
261
    userdir = os.path.join(jail_src_base, user.login)
260
262
    homedir = os.path.join(userdir, 'home')
 
263
    tmpdir = os.path.join(userdir, 'tmp')
261
264
    userhomedir = os.path.join(homedir, user.login)   # Return value
262
265
 
263
266
    if os.path.exists(userdir):
275
278
        # NOTE that shutil.move changed in Python 2.6, it now moves a
276
279
        # directory INTO the target (like `mv`), which it didn't use to do.
277
280
        # This code works regardless.
278
 
        shutil.move(homedir, homebackup)
 
281
        shutil.move(userhomedir, homebackup)
279
282
        shutil.rmtree(userdir)
280
 
        os.makedirs(userdir)
281
 
        shutil.move(homebackup, homedir)
 
283
        os.makedirs(homedir)
 
284
        shutil.move(homebackup, userhomedir)
282
285
        # Change the ownership of all the files to the right unixid
283
286
        logging.debug("chown %s's home directory files to uid %d"
284
287
            %(user.login, user.unixid))
296
299
    make_ivle_conf(user.login, userdir, user.svn_pass, config)
297
300
    make_etc_passwd(user.login, userdir, config['paths']['jails']['template'],
298
301
                    user.unixid)
 
302
    os.makedirs(tmpdir)
 
303
    os.chmod(tmpdir, 01777)
299
304
 
300
305
    return userhomedir
301
306
 
310
315
    @param svn_pass: User's SVN password.
311
316
    @param sys_config: An ivle.config.Config object (the system-wide config).
312
317
    """
313
 
    conf_path = os.path.join(user_jail_dir, "etc/ivle/ivle.conf")
314
 
    os.makedirs(os.path.dirname(conf_path))
 
318
    conf_path = os.path.join(user_jail_dir, "home/.ivle.conf")
 
319
    if not os.path.exists(os.path.dirname(conf_path)):
 
320
        os.makedirs(os.path.dirname(conf_path))
315
321
 
316
322
    # In the "in-jail" version of conf, we don't need MOST of the details
317
323
    # (it would be a security risk to have them here).
336
342
    Creates /etc/passwd in the given user's jail. This will be identical to
337
343
    that in the template jail, except for the added entry for this user.
338
344
    """
339
 
    template_passwd_path = os.path.join(template_dir, "etc/passwd")
340
 
    passwd_path = os.path.join(user_jail_dir, "etc/passwd")
 
345
    template_passwd_path = os.path.join(template_dir, "home/.passwd")
 
346
    passwd_path = os.path.join(user_jail_dir, "home/.passwd")
341
347
    passwd_dir = os.path.dirname(passwd_path)
342
348
    if not os.path.exists(passwd_dir):
343
349
        os.makedirs(passwd_dir)