core-agent-linux/misc/qvm-features-request
Frédéric Pierret (fepitre) 5805941daf
qvm-features-request: ensure qrexec agent is started
Prevents:

Traceback (most recent call last):
  File "/usr/bin/qvm-features-request", line 81, in <module>
    sys.exit(main())
  File "/usr/bin/qvm-features-request", line 78, in main
    stdin=devnull, stdout=devnull)
  File "/usr/lib/python3.7/subprocess.py", line 347, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['qrexec-client-vm', 'dom0', 'qubes.FeaturesRequest']' returned non-zero exit status 127.

and

Traceback (most recent call last):
  File "/usr/bin/qvm-features-request", line 81, in <module>
    sys.exit(main())
  File "/usr/bin/qvm-features-request", line 70, in main
    qdb = qubesdb.QubesDB()
qubesdb.Error: (2, 'No such file or directory')

Fixes QubesOS/qubes-issues#4469
2021-05-07 11:40:45 +02:00

89 lines
2.8 KiB
Python
Executable File

#!/usr/bin/python3
# vim: fileencoding=utf-8
#
# The Qubes OS Project, https://www.qubes-os.org/
#
# Copyright (C) 2010-2016 Joanna Rutkowska <joanna@invisiblethingslab.com>
# Copyright (C) 2016 Wojtek Porczyk <woju@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.
#
import argparse
import os
import subprocess
import sys
import qubesdb
def is_active(service):
status = subprocess.call(["systemctl", "is-active", "--quiet", service])
return status == 0
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)
if not is_active("qubes-qrexec-agent"):
return
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())