~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-28 08:35:40 UTC
  • Revision ID: grantw@unimelb.edu.au-20090428083540-0mjpvly46rbt8o8l
Drop another unneeded ivle.conf import, from ivle.webapp.help.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
# Do not call os.system("chown www-data") - use Python lib
36
36
# and use the web server uid given in conf. (Several places).
37
37
 
38
 
import md5
 
38
import hashlib
39
39
import os
40
40
import stat
41
41
import shutil
124
124
    """Setup svn authentication for the given user.
125
125
       Uses the given DB store object. Does not commit to the db.
126
126
    """
127
 
    passwd = md5.new(uuid.uuid4().bytes).digest().encode('hex')
 
127
    passwd = hashlib.md5(uuid.uuid4().bytes).hexdigest()
128
128
    if os.path.exists(ivle.conf.svn_auth_ivle):
129
129
        create = ""
130
130
    else:
213
213
        warnings.simplefilter('ignore')
214
214
        homebackup = os.tempnam(tempdir)
215
215
        warnings.resetwarnings()
216
 
        # Note: shutil.move does not behave like "mv" - it does not put a file
217
 
        # into a directory if it already exists, just fails. Therefore it is
218
 
        # 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.
219
221
        shutil.move(homedir, homebackup)
220
222
        shutil.rmtree(userdir)
221
 
        os.makedirs(homedir)
 
223
        os.makedirs(userdir)
222
224
        shutil.move(homebackup, homedir)
223
225
        # Change the ownership of all the files to the right unixid
224
226
        logging.debug("chown %s's home directory files to uid %d"
234
236
        # Chmod to rwxr-xr-x (755)
235
237
        os.chmod(userhomedir, 0755)
236
238
 
237
 
    make_conf_py(user.login, userdir, user.svn_pass)
 
239
    make_ivle_conf(user.login, userdir, user.svn_pass)
238
240
    make_etc_passwd(user.login, userdir, ivle.conf.jail_system, user.unixid)
239
241
 
240
242
    return userhomedir
241
243
 
242
 
def make_conf_py(username, user_jail_dir, svn_pass):
 
244
def make_ivle_conf(username, user_jail_dir, svn_pass):
243
245
    """
244
246
    Creates (overwriting any existing file, and creating directories) a
245
 
    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.
246
248
    username: Username.
247
249
    user_jail_dir: User's jail dir, ie. ivle.conf.jail_base + username
248
250
    svn_pass: User's SVN password.
249
251
    """
250
 
    conf_path = os.path.join(user_jail_dir,
251
 
            ivle.conf.python_site_packages[1:], "ivle/conf/conf.py")
 
252
    conf_path = os.path.join(user_jail_dir, "etc/ivle/ivle.conf")
252
253
    os.makedirs(os.path.dirname(conf_path))
253
254
 
254
255
    # In the "in-jail" version of conf, we don't need MOST of the details
255
256
    # (it would be a security risk to have them here).
256
 
    # So we just write root_dir, and jail_base is "/".
257
 
    # (jail_base being "/" means "jail-relative" paths are relative to "/"
258
 
    # when inside the jail.)
259
 
 
260
 
    # XXX: jail_base is wrong and shouldn't be here. Unfortunately, jail code
261
 
    #      uses ivle.studpath.url_to_{local,jailpaths}, both of which use
262
 
    #      jail_base. Note that they don't use the bits of the return value
263
 
    #      that depend on jail_base, so it can be any string.
264
 
    conf_file = open(conf_path, "w")
265
 
    conf_file.write("""# IVLE jail configuration
266
 
 
267
 
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
268
 
# with this).
269
 
# eg. "/" or "/ivle".
270
 
root_dir = %(root_dir)r
271
 
 
272
 
# This value is not relevant inside the jail, but must remain for now. See
273
 
# the XXX in ivle.makeuser.make_conf_py.
274
 
jail_base = '/'
275
 
 
276
 
# The hostname for serving publicly accessible pages
277
 
public_host = %(public_host)r
278
 
 
279
 
# The URL under which the Subversion repositories are located.
280
 
svn_addr = %(svn_addr)r
281
 
 
282
 
# The login name for the owner of the jail
283
 
login = %(username)r
284
 
 
285
 
# The subversion-only password for the owner of the jail
286
 
svn_pass = %(svn_pass)r
287
 
""" % {'root_dir': ivle.conf.root_dir,
288
 
       'public_host': ivle.conf.public_host,
289
 
       'svn_addr': ivle.conf.svn_addr,
290
 
       'username': username,
291
 
       'svn_pass': svn_pass,
292
 
      })
293
 
    conf_file.close()
 
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()
294
266
 
295
267
    # Make this file world-readable
296
268
    # (chmod 644 conf_path)