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

« back to all changes in this revision

Viewing changes to ivle/makeuser.py

  • Committer: William Grant
  • Date: 2010-02-15 05:37:50 UTC
  • Revision ID: grantw@unimelb.edu.au-20100215053750-hihmegnp8e7dshc2
Ignore test coverage files.

Show diffs side-by-side

added added

removed removed

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