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

« back to all changes in this revision

Viewing changes to ivle/makeuser.py

  • Committer: William Grant
  • Date: 2009-04-23 03:36:48 UTC
  • Revision ID: grantw@unimelb.edu.au-20090423033648-da4wxhvvtd50qzkq
Remove ivle.conf.python_site_packages_override.

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
    """
80
80
    users = store.find(ivle.database.User)
81
81
    groups = {}
82
 
    for u in users:
83
 
        role = str(u.role)
84
 
        if role not in groups:
85
 
            groups[role] = []
86
 
        groups[role].append(u.login)
 
82
    # TODO: Populate groups with per-offering tutors/lecturers/etc.
87
83
    f = open(ivle.conf.svn_conf + ".new", "w")
88
84
    f.write("# IVLE SVN Repositories Configuration\n")
89
85
    f.write("# Auto-generated on %s\n" % time.asctime())
197
193
        raise Exception("Must run make_jail as root")
198
194
    
199
195
    # tempdir is for putting backup homes in
200
 
    tempdir = os.path.join(ivle.conf.jail_base, '__temp__')
 
196
    tempdir = os.path.join(ivle.conf.jail_src_base, '__temp__')
201
197
    if not os.path.exists(tempdir):
202
198
        os.makedirs(tempdir)
203
199
    elif not os.path.isdir(tempdir):
217
213
        warnings.simplefilter('ignore')
218
214
        homebackup = os.tempnam(tempdir)
219
215
        warnings.resetwarnings()
220
 
        # Note: shutil.move does not behave like "mv" - it does not put a file
221
 
        # into a directory if it already exists, just fails. Therefore it is
222
 
        # not susceptible to tmpnam symlink attack.
 
216
        # Back up the /home directory, delete the entire jail, recreate the
 
217
        # jail directory tree, then copy the /home back
 
218
        # NOTE that shutil.move changed in Python 2.6, it now moves a
 
219
        # directory INTO the target (like `mv`), which it didn't use to do.
 
220
        # This code works regardless.
223
221
        shutil.move(homedir, homebackup)
224
222
        shutil.rmtree(userdir)
225
 
        os.makedirs(homedir)
 
223
        os.makedirs(userdir)
226
224
        shutil.move(homebackup, homedir)
227
225
        # Change the ownership of all the files to the right unixid
228
226
        logging.debug("chown %s's home directory files to uid %d"
229
227
            %(user.login, user.unixid))
230
 
        os.chown(userhomedir, user.unixid, user.unixid)
231
 
        for root, dirs, files in os.walk(userhomedir):
232
 
            for fsobj in dirs + files:
233
 
                os.chown(os.path.join(root, fsobj), user.unixid, user.unixid)
 
228
        os.spawnvp(os.P_WAIT, 'chown', ['chown', '-R', '%d:%d' % (user.unixid,
 
229
                                        user.unixid), userhomedir])
234
230
    else:
235
231
        # No user jail exists
236
232
        # Set up the user's home directory
240
236
        # Chmod to rwxr-xr-x (755)
241
237
        os.chmod(userhomedir, 0755)
242
238
 
243
 
    make_conf_py(user.login, userdir, ivle.conf.jail_system, user.svn_pass)
 
239
    make_ivle_conf(user.login, userdir, user.svn_pass)
244
240
    make_etc_passwd(user.login, userdir, ivle.conf.jail_system, user.unixid)
245
241
 
246
242
    return userhomedir
247
243
 
248
 
def make_conf_py(username, user_jail_dir, staging_dir, svn_pass):
 
244
def make_ivle_conf(username, user_jail_dir, svn_pass):
249
245
    """
250
246
    Creates (overwriting any existing file, and creating directories) a
251
 
    file ${python_site_packages}/ivle/conf/conf.py in a given user's jail.
 
247
    file /etc/ivle/ivle.conf in a given user's jail.
252
248
    username: Username.
253
249
    user_jail_dir: User's jail dir, ie. ivle.conf.jail_base + username
254
 
    staging_dir: The dir with the staging copy of the jail. (With the
255
 
        template conf.py file).
256
 
    svn_pass: As with make_jail. User's SVN password, but if not supplied,
257
 
        will look up in the DB.
 
250
    svn_pass: User's SVN password.
258
251
    """
259
 
    template_conf_path = os.path.join(staging_dir,
260
 
            ivle.conf.python_site_packages[1:], "ivle/conf/conf.py")
261
 
    conf_path = os.path.join(user_jail_dir,
262
 
            ivle.conf.python_site_packages[1:], "ivle/conf/conf.py")
 
252
    conf_path = os.path.join(user_jail_dir, "etc/ivle/ivle.conf")
263
253
    os.makedirs(os.path.dirname(conf_path))
264
254
 
265
 
    # Read the contents of the template conf file
266
 
    try:
267
 
        template_conf_file = open(template_conf_path, "r")
268
 
        template_conf_data = template_conf_file.read()
269
 
        template_conf_file.close()
270
 
    except:
271
 
        # Couldn't open template conf.py for some reason
272
 
        # Just treat it as empty file
273
 
        template_conf_data = ("# Warning: Problem building config script.\n"
274
 
                              "# Could not find template conf.py file.\n")
275
 
 
276
 
    conf_file = open(conf_path, "w")
277
 
    conf_file.write(template_conf_data)
278
 
    conf_file.write("\n# The login name for the owner of the jail\n")
279
 
    conf_file.write("login = %s\n" % repr(username))
280
 
    conf_file.write("\n")
281
 
    conf_file.write("# The subversion-only password for the owner of "
282
 
        "the jail\n")
283
 
    conf_file.write("svn_pass = %s\n" % repr(svn_pass))
284
 
    conf_file.close()
 
255
    # In the "in-jail" version of conf, we don't need MOST of the details
 
256
    # (it would be a security risk to have them here).
 
257
    # So we just write root_dir.
 
258
    conf_obj = ivle.config.Config(blank=True)
 
259
    conf_obj.filename = conf_path
 
260
    conf_obj['urls']['root'] = ivle.conf.root_dir
 
261
    conf_obj['urls']['public_host'] = ivle.conf.public_host
 
262
    conf_obj['urls']['svn_addr'] = ivle.conf.svn_addr
 
263
    conf_obj['user_info']['login'] = username
 
264
    conf_obj['user_info']['svn_pass'] = svn_pass
 
265
    conf_obj.write()
285
266
 
286
267
    # Make this file world-readable
287
268
    # (chmod 644 conf_path)