75
75
chown_to_webserver(path)
77
def rebuild_svn_config(store, config):
77
def rebuild_svn_config(store):
78
78
"""Build the complete SVN configuration file.
79
@param config: An ivle.config.Config object.
81
80
users = store.find(ivle.database.User)
83
82
# TODO: Populate groups with per-offering tutors/lecturers/etc.
84
conf_name = config['paths']['svn']['conf']
85
temp_name = conf_name + ".new"
86
f = open(temp_name, "w")
83
f = open(ivle.conf.svn_conf + ".new", "w")
87
84
f.write("# IVLE SVN Repositories Configuration\n")
88
85
f.write("# Auto-generated on %s\n" % time.asctime())
99
96
#f.write("@admin = rw\n")
102
os.rename(temp_name, conf_name)
103
chown_to_webserver(conf_name)
99
os.rename(ivle.conf.svn_conf + ".new", ivle.conf.svn_conf)
100
chown_to_webserver(ivle.conf.svn_conf)
105
def rebuild_svn_group_config(store, config):
102
def rebuild_svn_group_config(store):
106
103
"""Build the complete SVN configuration file for groups
107
@param config: An ivle.config.Config object.
109
conf_name = config['paths']['svn']['group_conf']
110
temp_name = conf_name + ".new"
111
f = open(temp_name, "w")
105
f = open(ivle.conf.svn_group_conf + ".new", "w")
112
106
f.write("# IVLE SVN Group Repositories Configuration\n")
113
107
f.write("# Auto-generated on %s\n" % time.asctime())
123
117
f.write("%s = rw\n" % user.login)
126
os.rename(temp_name, conf_name)
127
chown_to_webserver(conf_name)
120
os.rename(ivle.conf.svn_group_conf + ".new", ivle.conf.svn_group_conf)
121
chown_to_webserver(ivle.conf.svn_group_conf)
129
def make_svn_auth(store, login, config, throw_on_error=True):
123
def make_svn_auth(store, login, throw_on_error=True):
130
124
"""Setup svn authentication for the given user.
131
125
Uses the given DB store object. Does not commit to the db.
133
# filename is, eg, /var/lib/ivle/svn/ivle.auth
134
filename = config['paths']['svn']['auth_ivle']
135
passwd = hashlib.md5(uuid.uuid4().bytes).hexdigest()
136
if os.path.exists(filename):
127
passwd = md5.new(uuid.uuid4().bytes).digest().encode('hex')
128
if os.path.exists(ivle.conf.svn_auth_ivle):
141
133
user = ivle.database.User.get_by_login(store, login)
142
134
user.svn_pass = unicode(passwd)
144
res = os.system("htpasswd -%smb %s %s %s" % (create, filename,
136
res = os.system("htpasswd -%smb %s %s %s" % (create,
137
ivle.conf.svn_auth_ivle,
146
139
if res != 0 and throw_on_error:
147
140
raise Exception("Unable to create ivle-auth for %s" % login)
149
142
# Make sure the file is owned by the web server
150
143
if create == "c":
151
chown_to_webserver(filename)
144
chown_to_webserver(ivle.conf.svn_auth_ivle)
220
213
warnings.simplefilter('ignore')
221
214
homebackup = os.tempnam(tempdir)
222
215
warnings.resetwarnings()
223
# Back up the /home directory, delete the entire jail, recreate the
224
# jail directory tree, then copy the /home back
225
# NOTE that shutil.move changed in Python 2.6, it now moves a
226
# directory INTO the target (like `mv`), which it didn't use to do.
227
# This code works regardless.
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.
228
219
shutil.move(homedir, homebackup)
229
220
shutil.rmtree(userdir)
231
222
shutil.move(homebackup, homedir)
232
223
# Change the ownership of all the files to the right unixid
233
224
logging.debug("chown %s's home directory files to uid %d"
243
234
# Chmod to rwxr-xr-x (755)
244
235
os.chmod(userhomedir, 0755)
246
make_ivle_conf(user.login, userdir, user.svn_pass)
237
make_conf_py(user.login, userdir, user.svn_pass)
247
238
make_etc_passwd(user.login, userdir, ivle.conf.jail_system, user.unixid)
249
240
return userhomedir
251
def make_ivle_conf(username, user_jail_dir, svn_pass):
242
def make_conf_py(username, user_jail_dir, svn_pass):
253
244
Creates (overwriting any existing file, and creating directories) a
254
file /etc/ivle/ivle.conf in a given user's jail.
245
file ${python_site_packages}/ivle/conf/conf.py in a given user's jail.
255
246
username: Username.
256
247
user_jail_dir: User's jail dir, ie. ivle.conf.jail_base + username
257
248
svn_pass: User's SVN password.
259
conf_path = os.path.join(user_jail_dir, "etc/ivle/ivle.conf")
250
conf_path = os.path.join(user_jail_dir,
251
ivle.conf.python_site_packages[1:], "ivle/conf/conf.py")
260
252
os.makedirs(os.path.dirname(conf_path))
262
254
# In the "in-jail" version of conf, we don't need MOST of the details
263
255
# (it would be a security risk to have them here).
264
# So we just write root_dir.
265
conf_obj = ivle.config.Config(blank=True)
266
conf_obj.filename = conf_path
267
conf_obj['urls']['root'] = ivle.conf.root_dir
268
conf_obj['urls']['public_host'] = ivle.conf.public_host
269
conf_obj['urls']['svn_addr'] = ivle.conf.svn_addr
270
conf_obj['user_info']['login'] = username
271
conf_obj['user_info']['svn_pass'] = svn_pass
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.)
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
267
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
269
# eg. "/" or "/ivle".
270
root_dir = %(root_dir)r
272
# This value is not relevant inside the jail, but must remain for now. See
273
# the XXX in ivle.makeuser.make_conf_py.
276
# The hostname for serving publicly accessible pages
277
public_host = %(public_host)r
279
# The URL under which the Subversion repositories are located.
280
svn_addr = %(svn_addr)r
282
# The login name for the owner of the jail
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,
274
295
# Make this file world-readable
275
296
# (chmod 644 conf_path)