2013-01-20 21:44:13 +01:00
|
|
|
#!/usr/bin/python2
|
2014-05-18 21:01:21 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2010-04-05 20:58:57 +02:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2010 Joanna Rutkowska <joanna@invisiblethingslab.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2010-06-26 15:02:58 +02:00
|
|
|
qubes_base_dir = "/var/lib/qubes"
|
2013-03-15 18:43:09 +01:00
|
|
|
system_path = {
|
|
|
|
'qubes_guid_path': '/usr/bin/qubes-guid',
|
|
|
|
'qrexec_daemon_path': '/usr/lib/qubes/qrexec-daemon',
|
|
|
|
'qrexec_client_path': '/usr/lib/qubes/qrexec-client',
|
2013-06-07 05:16:15 +02:00
|
|
|
'qubesdb_daemon_path': '/usr/sbin/qubesdb-daemon',
|
2010-04-05 20:58:57 +02:00
|
|
|
|
2013-03-15 18:43:09 +01:00
|
|
|
'qubes_base_dir': qubes_base_dir,
|
2010-04-05 20:58:57 +02:00
|
|
|
|
2013-07-30 11:37:33 +02:00
|
|
|
# Relative to qubes_base_dir
|
|
|
|
'qubes_appvms_dir': 'appvms',
|
|
|
|
'qubes_templates_dir': 'vm-templates',
|
|
|
|
'qubes_servicevms_dir': 'servicevms',
|
|
|
|
'qubes_store_filename': 'qubes.xml',
|
|
|
|
'qubes_kernels_base_dir': 'vm-kernels',
|
2010-04-05 20:58:57 +02:00
|
|
|
|
2014-07-10 16:17:58 +02:00
|
|
|
# qubes_icon_dir is obsolete
|
|
|
|
# use QIcon.fromTheme() where applicable
|
2014-07-16 02:55:42 +02:00
|
|
|
'qubes_icon_dir': '/usr/share/icons/hicolor/128x128/devices',
|
2010-04-05 20:58:57 +02:00
|
|
|
|
2013-10-17 07:01:43 +02:00
|
|
|
'qrexec_policy_dir': '/etc/qubes-rpc/policy',
|
|
|
|
|
2013-08-02 20:27:33 +02:00
|
|
|
'config_template_pv': '/usr/share/qubes/vm-template.xml',
|
2012-02-24 04:23:27 +01:00
|
|
|
|
2013-03-15 18:43:09 +01:00
|
|
|
'qubes_pciback_cmd': '/usr/lib/qubes/unbind-pci-device.sh',
|
|
|
|
'prepare_volatile_img_cmd': '/usr/lib/qubes/prepare-volatile-img.sh',
|
|
|
|
}
|
2012-03-02 01:46:10 +01:00
|
|
|
|
2013-03-15 18:43:09 +01:00
|
|
|
vm_files = {
|
|
|
|
'root_img': 'root.img',
|
|
|
|
'rootcow_img': 'root-cow.img',
|
|
|
|
'volatile_img': 'volatile.img',
|
|
|
|
'private_img': 'private.img',
|
|
|
|
'kernels_subdir': 'kernels',
|
|
|
|
'firewall_conf': 'firewall.xml',
|
|
|
|
'whitelisted_appmenus': 'whitelisted-appmenus.list',
|
|
|
|
'updates_stat_file': 'updates.stat',
|
|
|
|
}
|
2011-07-05 21:20:43 +02:00
|
|
|
|
2013-03-15 18:43:09 +01:00
|
|
|
defaults = {
|
2013-05-04 04:45:55 +02:00
|
|
|
'libvirt_uri': 'xen:///',
|
2013-03-15 18:43:09 +01:00
|
|
|
'memory': 400,
|
2014-04-16 16:07:59 +02:00
|
|
|
'kernelopts': "nopat",
|
2015-07-01 04:46:46 +02:00
|
|
|
'kernelopts_pcidevs': "nopat iommu=soft swiotlb=8192",
|
2011-06-22 00:44:48 +02:00
|
|
|
|
2013-03-15 18:43:09 +01:00
|
|
|
'dom0_update_check_interval': 6*3600,
|
2010-04-05 20:58:57 +02:00
|
|
|
|
2013-07-29 03:51:39 +02:00
|
|
|
'private_img_size': 2*1024*1024*1024,
|
|
|
|
'root_img_size': 10*1024*1024*1024,
|
|
|
|
|
|
|
|
'storage_class': None,
|
|
|
|
|
2013-03-15 18:43:09 +01:00
|
|
|
# how long (in sec) to wait for VMs to shutdown,
|
|
|
|
# before killing them (when used qvm-run with --wait option),
|
|
|
|
'shutdown_counter_max': 60,
|
2010-04-05 20:58:57 +02:00
|
|
|
|
2013-03-15 18:43:09 +01:00
|
|
|
'vm_default_netmask': "255.255.255.0",
|
|
|
|
|
|
|
|
# Set later
|
|
|
|
'appvm_label': None,
|
|
|
|
'template_label': None,
|
|
|
|
'servicevm_label': None,
|
|
|
|
}
|
|
|
|
|
|
|
|
qubes_max_qid = 254
|
|
|
|
qubes_max_netid = 254
|
2010-04-05 20:58:57 +02:00
|
|
|
|
2013-05-17 04:06:29 +02:00
|
|
|
##########################################
|
2010-09-16 17:52:52 +02:00
|
|
|
|
2011-06-01 23:44:06 +02:00
|
|
|
|
2013-03-16 02:39:30 +01:00
|
|
|
def register_qubes_vm_class(vm_class):
|
|
|
|
QubesVmClasses[vm_class.__name__] = vm_class
|
|
|
|
# register class as local for this module - to make it easy to import from
|
|
|
|
# other modules
|
|
|
|
setattr(sys.modules[__name__], vm_class.__name__, vm_class)
|
2013-01-17 01:18:42 +01:00
|
|
|
|
2011-12-23 17:08:14 +01:00
|
|
|
|
2010-04-05 20:58:57 +02:00
|
|
|
class QubesDaemonPidfile(object):
|
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
self.path = "/var/run/qubes/" + name + ".pid"
|
|
|
|
|
|
|
|
def create_pidfile(self):
|
|
|
|
f = open (self.path, 'w')
|
|
|
|
f.write(str(os.getpid()))
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
def pidfile_exists(self):
|
|
|
|
return os.path.exists(self.path)
|
|
|
|
|
|
|
|
def read_pid(self):
|
|
|
|
f = open (self.path)
|
|
|
|
pid = f.read ().strip()
|
|
|
|
f.close()
|
|
|
|
return int(pid)
|
|
|
|
|
|
|
|
def pidfile_is_stale(self):
|
|
|
|
if not self.pidfile_exists():
|
|
|
|
return False
|
|
|
|
|
|
|
|
# check if the pid file is valid...
|
|
|
|
proc_path = "/proc/" + str(self.read_pid()) + "/cmdline"
|
|
|
|
if not os.path.exists (proc_path):
|
2013-03-16 14:19:03 +01:00
|
|
|
print >> sys.stderr, \
|
|
|
|
"Path {0} doesn't exist, assuming stale pidfile.".\
|
|
|
|
format(proc_path)
|
2010-04-05 20:58:57 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
return False # It's a good pidfile
|
|
|
|
|
|
|
|
def remove_pidfile(self):
|
|
|
|
os.remove (self.path)
|
|
|
|
|
|
|
|
def __enter__ (self):
|
|
|
|
# assumes the pidfile doesn't exist -- you should ensure it before opening the context
|
|
|
|
self.create_pidfile()
|
2013-02-14 19:04:05 +01:00
|
|
|
|
|
|
|
def __exit__ (self, exc_type, exc_val, exc_tb):
|
2010-04-05 20:58:57 +02:00
|
|
|
self.remove_pidfile()
|
2013-02-14 19:04:05 +01:00
|
|
|
return False
|
2010-04-05 20:58:57 +02:00
|
|
|
|
2013-07-22 04:21:11 +02:00
|
|
|
### Initialization code
|
|
|
|
|
|
|
|
defaults["appvm_label"] = QubesVmLabels["red"]
|
|
|
|
defaults["template_label"] = QubesVmLabels["black"]
|
|
|
|
defaults["servicevm_label"] = QubesVmLabels["red"]
|
|
|
|
|
|
|
|
|
|
|
|
QubesVmClasses = {}
|
2013-03-16 02:39:30 +01:00
|
|
|
modules_dir = os.path.join(os.path.dirname(__file__), 'modules')
|
|
|
|
for module_file in sorted(os.listdir(modules_dir)):
|
|
|
|
if not module_file.endswith(".py") or module_file == "__init__.py":
|
|
|
|
continue
|
|
|
|
__import__('qubes.modules.%s' % module_file[:-3])
|
|
|
|
|
2013-07-22 04:23:25 +02:00
|
|
|
try:
|
|
|
|
import qubes.settings
|
|
|
|
qubes.settings.apply(system_path, vm_files, defaults)
|
2013-07-29 03:58:08 +02:00
|
|
|
except ImportError:
|
2013-07-22 04:23:25 +02:00
|
|
|
pass
|
|
|
|
|
2013-07-22 04:22:01 +02:00
|
|
|
for path_key in system_path.keys():
|
2013-07-30 11:37:33 +02:00
|
|
|
if not os.path.isabs(system_path[path_key]):
|
|
|
|
system_path[path_key] = os.path.join(
|
|
|
|
system_path['qubes_base_dir'], system_path[path_key])
|
2013-07-22 04:22:01 +02:00
|
|
|
|
2011-02-27 00:06:46 +01:00
|
|
|
# vim:sw=4:et:
|