47
43
help='''Apply any package updates in the jail.''')
48
44
parser.add_option("-m", "--mirror",
49
45
action="store", dest="apt_mirror",
50
help="Sets the apt mirror.", default=conf['jail']['mirror'])
51
parser.add_option("--python-site-packages",
52
action="store", dest="python_site_packages",
53
help="Path to Python site packages directory inside the jail.",
46
help="Sets the apt mirror.", default="http://archive.ubuntu.com/ubuntu")
55
47
(options, args) = parser.parse_args(sys.argv)
57
49
if os.geteuid() != 0:
124
111
# Also copy the IVLE lib directory into the jail
125
112
# This is necessary for running certain services
127
# ivle_site_packages is the IVLE install location outside the jail
128
ivle_site_packages = os.path.dirname(ivle.__file__)
130
if options.python_site_packages is None:
131
# Get the site packages from the IVLE install location *OUTSIDE* the
132
# jail. Warning! This only works if you have the same Python site
133
# packages directory inside and out (ie. same Python version).
134
# If not, you should use --python-site-packages.
135
jail_site_packages = os.path.join(build_path, ivle_site_packages[1:])
137
# User-specified site packages
138
jail_site_packages = os.path.join(build_path,
139
options.python_site_packages[1:], "ivle")
113
ivle_site_packages = os.path.join(ivle.conf.python_site_packages, 'ivle')
114
jail_site_packages = os.path.join(build_path, ivle_site_packages[1:])
140
115
if os.path.exists(jail_site_packages):
141
116
shutil.rmtree(jail_site_packages)
142
117
shutil.copytree(ivle_site_packages, jail_site_packages)
144
# Make /tmp and /var/lock un-world-writable. /tmp will be mounted over,
145
# and /var/{lock,tmp} should die.
146
for path in ('tmp', 'var/lock', 'var/tmp'):
147
path = os.path.join(build_path, path)
148
os.chmod(path, os.stat(path).st_mode & ~stat.S_IWOTH)
150
# Verify that nothing in the jail is world-writable.
151
# We don't want students to write into places that others can see.
152
for path, dirs, files in os.walk(build_path):
154
d = os.path.join(path, dname)
155
if os.path.islink(d):
157
if os.stat(d).st_mode & stat.S_IWOTH:
161
f = os.path.join(path, fname)
162
if os.path.islink(f):
164
if os.stat(f).st_mode & stat.S_IWOTH:
165
if (os.path.dirname(f) == os.path.join(build_path, 'dev') and
166
os.path.basename(f) in ('ptmx', 'null', 'tty', 'full', 'zero',
119
# IMPORTANT: ivle/conf/conf.py contains details which could compromise security
120
# if left in the jail (such as the DB password). We delete it now! It would be
121
# shadowed by the per-user conf.py anyway, but it's best to be safe.
122
os.unlink(os.path.join(jail_site_packages, 'conf/conf.py'))
123
# XXX: Shouldn't copy the compiled files at all, but compile them in the jail!
124
os.unlink(os.path.join(jail_site_packages, 'conf/conf.pyc'))
173
126
if os.spawnvp(os.P_WAIT, 'rsync', ['rsync', '-a', '--delete',
174
127
build_path + '/', ivle.conf.jail_system]) != 0:
175
128
print >> sys.stderr, "Jail copying failed."
178
# Now mangle things a bit, so we can bind-mount the user bits in.
179
# /etc/passwd and /etc/ivle/ivle.conf need to be symlinks to somewhere in /home
181
os.rename(os.path.join(ivle.conf.jail_system, 'etc/passwd'),
182
os.path.join(ivle.conf.jail_system, 'home/.passwd')
184
os.symlink('../home/.passwd', os.path.join(ivle.conf.jail_system, 'etc/passwd'))
186
os.makedirs(os.path.join(ivle.conf.jail_system, "etc/ivle"))
187
os.symlink('../../home/.ivle.conf',
188
os.path.join(ivle.conf.jail_system, "etc/ivle/ivle.conf"))