From 5261f936b292482449436d59376d65a1832914ee Mon Sep 17 00:00:00 2001 From: Wojtek Porczyk Date: Thu, 19 May 2016 01:36:31 +0200 Subject: [PATCH] misc: add qvm-features-request This tool is used to request features from template. QubesOS/qubes-issues#1637 --- Makefile | 14 ++++--- misc/qvm-features-request | 81 +++++++++++++++++++++++++++++++++++++++ rpm_spec/core-vm.spec | 1 + 3 files changed, 90 insertions(+), 6 deletions(-) create mode 100755 misc/qvm-features-request diff --git a/Makefile b/Makefile index 06fda31..48a9dae 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ VERSION := $(shell cat version) DIST ?= fc18 KDESERVICEDIR ?= /usr/share/kde4/services SBINDIR ?= /usr/sbin +BINDIR ?= /usr/bin LIBDIR ?= /usr/lib SYSLIBDIR ?= /lib @@ -149,7 +150,7 @@ install-common: install -d $(DESTDIR)/var/lib/qubes - install -D misc/xenstore-watch $(DESTDIR)/usr/bin/xenstore-watch-qubes + install -D misc/xenstore-watch $(DESTDIR)$(BINDIR)/xenstore-watch-qubes install -d $(DESTDIR)/etc/udev/rules.d install -m 0644 misc/udev-qubes-misc.rules $(DESTDIR)/etc/udev/rules.d/50-qubes-misc.rules install -d $(DESTDIR)$(LIBDIR)/qubes/ @@ -199,17 +200,18 @@ install-common: install network/qubes-firewall $(DESTDIR)/$(SBINDIR)/ install network/qubes-netwatcher $(DESTDIR)/$(SBINDIR)/ - install -d $(DESTDIR)/usr/bin - install -m 0755 misc/qubes-session-autostart $(DESTDIR)/usr/bin/qubes-session-autostart + install -d $(DESTDIR)$(BINDIR) + install -m 0755 misc/qubes-session-autostart $(DESTDIR)$(BINDIR)/qubes-session-autostart + install -m 0755 misc/qvm-features-request $(DESTDIR)$(BINDIR)/qvm-features-request + install qubes-rpc/{qvm-open-in-dvm,qvm-open-in-vm,qvm-copy-to-vm,qvm-move-to-vm,qvm-run,qvm-mru-entry} $(DESTDIR)$(BINDIR) - install qubes-rpc/{qvm-open-in-dvm,qvm-open-in-vm,qvm-copy-to-vm,qvm-move-to-vm,qvm-run,qvm-mru-entry} $(DESTDIR)/usr/bin install qubes-rpc/qvm-copy-to-vm.kde $(DESTDIR)$(LIBDIR)/qubes install qubes-rpc/qvm-copy-to-vm.gnome $(DESTDIR)$(LIBDIR)/qubes install qubes-rpc/qvm-move-to-vm.kde $(DESTDIR)$(LIBDIR)/qubes install qubes-rpc/qvm-move-to-vm.gnome $(DESTDIR)$(LIBDIR)/qubes install qubes-rpc/xdg-icon $(DESTDIR)$(LIBDIR)/qubes install qubes-rpc/{vm-file-editor,qfile-agent,qopen-in-vm} $(DESTDIR)$(LIBDIR)/qubes - install qubes-rpc/qubes-open $(DESTDIR)/usr/bin + install qubes-rpc/qubes-open $(DESTDIR)$(BINDIR) install qubes-rpc/tar2qfile $(DESTDIR)$(LIBDIR)/qubes # Install qfile-unpacker as SUID - because it will fail to receive files from other vm install -m 4755 qubes-rpc/qfile-unpacker $(DESTDIR)$(LIBDIR)/qubes @@ -241,7 +243,7 @@ install-common: install -d $(DESTDIR)/usr/share/nautilus-python/extensions install -m 0644 qubes-rpc/*_nautilus.py $(DESTDIR)/usr/share/nautilus-python/extensions - install -D -m 0755 misc/qubes-desktop-run $(DESTDIR)/usr/bin/qubes-desktop-run + install -D -m 0755 misc/qubes-desktop-run $(DESTDIR)$(BINDIR)/qubes-desktop-run mkdir -p $(DESTDIR)/$(PYTHON_SITEARCH)/qubes/ diff --git a/misc/qvm-features-request b/misc/qvm-features-request new file mode 100755 index 0000000..9fcc61b --- /dev/null +++ b/misc/qvm-features-request @@ -0,0 +1,81 @@ +#!/usr/bin/env python2 +# vim: fileencoding=utf-8 + +# +# The Qubes OS Project, https://www.qubes-os.org/ +# +# Copyright (C) 2010-2016 Joanna Rutkowska +# Copyright (C) 2016 Wojtek Porczyk +# +# 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. +# + +import argparse +import os +import subprocess +import sys + +import qubesdb + +class FeatureRequestAction(argparse.Action): + '''Action for argument parser that stores a property.''' + # pylint: disable=redefined-builtin,too-few-public-methods + def __init__(self, + option_strings, + dest='features', + metavar='NAME=VALUE', + required=False, + help='request a feature with the value'): + super(FeatureRequestAction, self).__init__(option_strings, dest=dest, + metavar=metavar, nargs='*', required=required, default={}, + help=help) + + def __call__(self, parser, namespace, values, option_string=None): + for request in values: + try: + feature, value = request.split('=', 1) + except ValueError: + parser.error( + 'invalid feature request token: {!r}'.format(request)) + + getattr(namespace, self.dest)[feature] = value + + +parser = argparse.ArgumentParser( + description='submit a feature request to the dom0') + +parser.add_argument('--commit', + action='store_true', default=False, + help='actually send the request (without it, only make entries in qubesdb)') + +parser.add_argument('features', + action=FeatureRequestAction) + + +def main(args=None): + args = parser.parse_args(args) + + qdb = qubesdb.QubesDB() + for feature, value in args.features.items(): + qdb.write('/features-request/' + feature, value) + + if args.commit: + devnull = os.open(os.devnull, os.O_RDWR) + subprocess.check_call( + ['qrexec-client-vm', 'dom0', 'qubes.FeaturesRequest'], + stdin=devnull, stdout=devnull) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/rpm_spec/core-vm.spec b/rpm_spec/core-vm.spec index 3b51da5..11e2fc0 100644 --- a/rpm_spec/core-vm.spec +++ b/rpm_spec/core-vm.spec @@ -384,6 +384,7 @@ rm -f %{name}-%{version} /usr/bin/qvm-open-in-vm /usr/bin/qvm-run /usr/bin/qvm-mru-entry +/usr/bin/qvm-features-request /usr/bin/xenstore-watch-qubes /usr/bin/qubes-desktop-run /usr/bin/qubes-open