vm: add run_with_args method to call a single command with specific arguments

The method will ensure the parameters are properly handled as actual
separate arguments, regardless of shell special characters in them.
For now implement this with shlex.quote, later dedicated qrexec service
could be used.

QubesOS/qubes-issues#4850
This commit is contained in:
Marek Marczykowski-Górecki 2019-02-28 04:37:59 +01:00
parent 88ab55b940
commit 0092c0ac99
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -21,6 +21,7 @@
'''Qubes VM objects.'''
import logging
import shlex
import subprocess
import warnings
@ -305,6 +306,15 @@ class QubesVM(qubesadmin.base.PropertyHolder):
e.cmd = command
raise e
def run_with_args(self, *args, **kwargs):
'''Run a single command inside the domain using qubes.VMShell qrexec.
This method execute a single command, without interpreting any shell
special characters.
''' # pylint: disable=redefined-builtin
return self.run(' '.join(shlex.quote(arg) for arg in args), **kwargs)
@property
def appvms(self):
''' Returns a generator containing all domains based on the current