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

« back to all changes in this revision

Viewing changes to ivle/makeuser.py

  • Committer: William Grant
  • Date: 2009-06-29 01:55:55 UTC
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: grantw@unimelb.edu.au-20090629015555-49xxv0piiieunx8e
Add docs on configuring Apache.

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