app.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. # -*- encoding: utf8 -*-
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2017 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation; either version 2.1 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License along
  19. # with this program; if not, see <http://www.gnu.org/licenses/>.
  20. '''
  21. Main Qubes() class and related classes.
  22. '''
  23. import os
  24. import shlex
  25. import socket
  26. import subprocess
  27. import sys
  28. import logging
  29. import qubesadmin.base
  30. import qubesadmin.exc
  31. import qubesadmin.label
  32. import qubesadmin.storage
  33. import qubesadmin.utils
  34. import qubesadmin.vm
  35. import qubesadmin.config
  36. BUF_SIZE = 4096
  37. class VMCollection(object):
  38. '''Collection of VMs objects'''
  39. def __init__(self, app):
  40. self.app = app
  41. self._vm_list = None
  42. self._vm_objects = {}
  43. def clear_cache(self):
  44. '''Clear cached list of VMs'''
  45. self._vm_list = None
  46. def refresh_cache(self, force=False):
  47. '''Refresh cached list of VMs'''
  48. if not force and self._vm_list is not None:
  49. return
  50. vm_list_data = self.app.qubesd_call(
  51. 'dom0',
  52. 'admin.vm.List'
  53. )
  54. new_vm_list = {}
  55. # FIXME: this will probably change
  56. for vm_data in vm_list_data.splitlines():
  57. vm_name, props = vm_data.decode('ascii').split(' ', 1)
  58. vm_name = str(vm_name)
  59. props = props.split(' ')
  60. new_vm_list[vm_name] = dict(
  61. [vm_prop.split('=', 1) for vm_prop in props])
  62. self._vm_list = new_vm_list
  63. for name, vm in list(self._vm_objects.items()):
  64. if vm.name not in self._vm_list:
  65. # VM no longer exists
  66. del self._vm_objects[name]
  67. elif vm.__class__.__name__ != self._vm_list[vm.name]['class']:
  68. # VM class have changed
  69. del self._vm_objects[name]
  70. # TODO: some generation ID, to detect VM re-creation
  71. elif name != vm.name:
  72. # renamed
  73. self._vm_objects[vm.name] = vm
  74. del self._vm_objects[name]
  75. def __getitem__(self, item):
  76. if not self.app.blind_mode and item not in self:
  77. raise KeyError(item)
  78. return self.get_blind(item)
  79. def get_blind(self, item):
  80. '''
  81. Get a vm without downloading the list
  82. and checking if exists
  83. '''
  84. if item not in self._vm_objects:
  85. cls = qubesadmin.vm.QubesVM
  86. # provide class name to constructor, if already cached (which can be
  87. # done by 'item not in self' check above, unless blind_mode is
  88. # enabled
  89. klass = None
  90. if self._vm_list and item in self._vm_list:
  91. klass = self._vm_list[item]['class']
  92. self._vm_objects[item] = cls(self.app, item, klass=klass)
  93. return self._vm_objects[item]
  94. def __contains__(self, item):
  95. self.refresh_cache()
  96. return item in self._vm_list
  97. def __delitem__(self, key):
  98. self.app.qubesd_call(key, 'admin.vm.Remove')
  99. self.clear_cache()
  100. def __iter__(self):
  101. self.refresh_cache()
  102. for vm in sorted(self._vm_list):
  103. yield self[vm]
  104. def keys(self):
  105. '''Get list of VM names.'''
  106. self.refresh_cache()
  107. return self._vm_list.keys()
  108. def values(self):
  109. '''Get list of VM objects.'''
  110. self.refresh_cache()
  111. return [self[name] for name in self._vm_list]
  112. class QubesBase(qubesadmin.base.PropertyHolder):
  113. '''Main Qubes application'''
  114. #: domains (VMs) collection
  115. domains = None
  116. #: labels collection
  117. labels = None
  118. #: storage pools
  119. pools = None
  120. #: type of qubesd connection: either 'socket' or 'qrexec'
  121. qubesd_connection_type = None
  122. #: logger
  123. log = None
  124. #: do not check for object (VM, label etc) existence before really needed
  125. blind_mode = False
  126. def __init__(self):
  127. super(QubesBase, self).__init__(self, 'admin.property.', 'dom0')
  128. self.domains = VMCollection(self)
  129. self.labels = qubesadmin.base.WrapperObjectsCollection(
  130. self, 'admin.label.List', qubesadmin.label.Label)
  131. self.pools = qubesadmin.base.WrapperObjectsCollection(
  132. self, 'admin.pool.List', qubesadmin.storage.Pool)
  133. #: cache for available storage pool drivers and options to create them
  134. self._pool_drivers = None
  135. self.log = logging.getLogger('app')
  136. def _refresh_pool_drivers(self):
  137. '''
  138. Refresh cached storage pool drivers and their parameters.
  139. :return: None
  140. '''
  141. if self._pool_drivers is None:
  142. pool_drivers_data = self.qubesd_call(
  143. 'dom0', 'admin.pool.ListDrivers', None, None)
  144. assert pool_drivers_data.endswith(b'\n')
  145. pool_drivers = {}
  146. for driver_line in pool_drivers_data.decode('ascii').splitlines():
  147. if not driver_line:
  148. continue
  149. driver_name, driver_options = driver_line.split(' ', 1)
  150. pool_drivers[driver_name] = driver_options.split(' ')
  151. self._pool_drivers = pool_drivers
  152. @property
  153. def pool_drivers(self):
  154. ''' Available storage pool drivers '''
  155. self._refresh_pool_drivers()
  156. return self._pool_drivers.keys()
  157. def pool_driver_parameters(self, driver):
  158. ''' Parameters to initialize storage pool using given driver '''
  159. self._refresh_pool_drivers()
  160. return self._pool_drivers[driver]
  161. def add_pool(self, name, driver, **kwargs):
  162. ''' Add a storage pool to config
  163. :param name: name of storage pool to create
  164. :param driver: driver to use, see :py:meth:`pool_drivers` for
  165. available drivers
  166. :param kwargs: configuration parameters for storage pool,
  167. see :py:meth:`pool_driver_parameters` for a list
  168. '''
  169. # sort parameters only to ease testing, not required by API
  170. payload = 'name={}\n'.format(name) + \
  171. ''.join('{}={}\n'.format(key, value)
  172. for key, value in sorted(kwargs.items()))
  173. self.qubesd_call('dom0', 'admin.pool.Add', driver,
  174. payload.encode('utf-8'))
  175. def remove_pool(self, name):
  176. ''' Remove a storage pool '''
  177. self.qubesd_call('dom0', 'admin.pool.Remove', name, None)
  178. def get_label(self, label):
  179. '''Get label as identified by index or name
  180. :throws KeyError: when label is not found
  181. '''
  182. # first search for name, verbatim
  183. try:
  184. return self.labels[label]
  185. except KeyError:
  186. pass
  187. # then search for index
  188. if type(label) == int or label.isdigit():
  189. return self.labels.values()[int(label)]
  190. raise KeyError(label)
  191. @staticmethod
  192. def get_vm_class(clsname):
  193. '''Find the class for a domain.
  194. Compatibility function, client tools use str to identify domain classes.
  195. :param str clsname: name of the class
  196. :return str: class
  197. '''
  198. return clsname
  199. def add_new_vm(self, cls, name, label, template=None, pool=None,
  200. pools=None):
  201. '''Create new Virtual Machine
  202. Example usage with custom storage pools:
  203. >>> app = qubesadmin.Qubes()
  204. >>> pools = {'private': 'external'}
  205. >>> vm = app.add_new_vm('AppVM', 'my-new-vm', 'red',
  206. >>> 'my-template', pools=pools)
  207. >>> vm.netvm = app.domains['sys-whonix']
  208. :param str cls: name of VM class (`AppVM`, `TemplateVM` etc)
  209. :param str name: name of VM
  210. :param str label: label color for new VM
  211. :param str template: template to use (if apply for given VM class),
  212. can be also VM object; use None for default value
  213. :param str pool: storage pool to use instead of default one
  214. :param dict pools: storage pool for specific volumes
  215. :return new VM object
  216. '''
  217. if not isinstance(cls, str):
  218. cls = cls.__name__
  219. if template is qubesadmin.DEFAULT:
  220. template = None
  221. elif template is not None:
  222. template = str(template)
  223. if pool and pools:
  224. raise ValueError('only one of pool= and pools= can be used')
  225. method_prefix = 'admin.vm.Create.'
  226. payload = 'name={} label={}'.format(name, label)
  227. if pool:
  228. payload += ' pool={}'.format(str(pool))
  229. method_prefix = 'admin.vm.CreateInPool.'
  230. if pools:
  231. payload += ''.join(' pool:{}={}'.format(vol, str(pool))
  232. for vol, pool in sorted(pools.items()))
  233. method_prefix = 'admin.vm.CreateInPool.'
  234. self.qubesd_call('dom0', method_prefix + cls, template,
  235. payload.encode('utf-8'))
  236. self.domains.clear_cache()
  237. return self.domains[name]
  238. def clone_vm(self, src_vm, new_name, new_cls=None,
  239. pool=None, pools=None, ignore_errors=False, ignore_volumes=None):
  240. '''Clone Virtual Machine
  241. Example usage with custom storage pools:
  242. >>> app = qubesadmin.Qubes()
  243. >>> pools = {'private': 'external'}
  244. >>> src_vm = app.domains['personal']
  245. >>> vm = app.clone_vm(src_vm, 'my-new-vm', pools=pools)
  246. >>> vm.label = app.labels['green']
  247. :param QubesVM or str src_vm: source VM
  248. :param str new_name: name of new VM
  249. :param str new_cls: name of VM class (`AppVM`, `TemplateVM` etc) - use
  250. None to copy it from *src_vm*
  251. :param str pool: storage pool to use instead of default one
  252. :param dict pools: storage pool for specific volumes
  253. :param bool ignore_errors: should errors on meta-data setting be only
  254. logged, or abort the whole operation?
  255. :param list ignore_volumes: do not clone volumes on this list,
  256. like 'private' or 'root'
  257. :return new VM object
  258. '''
  259. if pool and pools:
  260. raise ValueError('only one of pool= and pools= can be used')
  261. if isinstance(src_vm, str):
  262. src_vm = self.domains[src_vm]
  263. if new_cls is None:
  264. new_cls = src_vm.klass
  265. template = getattr(src_vm, 'template', None)
  266. if template is not None:
  267. template = str(template)
  268. label = src_vm.label
  269. method_prefix = 'admin.vm.Create.'
  270. payload = 'name={} label={}'.format(new_name, label)
  271. if pool:
  272. payload += ' pool={}'.format(str(pool))
  273. method_prefix = 'admin.vm.CreateInPool.'
  274. if pools:
  275. payload += ''.join(' pool:{}={}'.format(vol, str(pool))
  276. for vol, pool in sorted(pools.items()))
  277. method_prefix = 'admin.vm.CreateInPool.'
  278. self.qubesd_call('dom0', method_prefix + new_cls, template,
  279. payload.encode('utf-8'))
  280. self.domains.clear_cache()
  281. dst_vm = self.domains[new_name]
  282. try:
  283. assert isinstance(dst_vm, qubesadmin.vm.QubesVM)
  284. for prop in src_vm.property_list():
  285. # handled by admin.vm.Create call
  286. if prop in ('name', 'qid', 'template', 'label', 'uuid',
  287. 'installed_by_rpm'):
  288. continue
  289. if src_vm.property_is_default(prop):
  290. continue
  291. try:
  292. setattr(dst_vm, prop, getattr(src_vm, prop))
  293. except AttributeError:
  294. pass
  295. except qubesadmin.exc.QubesException as e:
  296. dst_vm.log.error(
  297. 'Failed to set {!s} property: {!s}'.format(prop, e))
  298. if not ignore_errors:
  299. raise
  300. for tag in src_vm.tags:
  301. if tag.startswith('created-by-'):
  302. continue
  303. try:
  304. dst_vm.tags.add(tag)
  305. except qubesadmin.exc.QubesException as e:
  306. dst_vm.log.error(
  307. 'Failed to add {!s} tag: {!s}'.format(tag, e))
  308. if not ignore_errors:
  309. raise
  310. for feature, value in src_vm.features.items():
  311. try:
  312. dst_vm.features[feature] = value
  313. except qubesadmin.exc.QubesException as e:
  314. dst_vm.log.error(
  315. 'Failed to set {!s} feature: {!s}'.format(feature, e))
  316. if not ignore_errors:
  317. raise
  318. try:
  319. dst_vm.firewall.save_rules(src_vm.firewall.rules)
  320. except qubesadmin.exc.QubesException as e:
  321. self.log.error('Failed to set firewall: %s', e)
  322. if not ignore_errors:
  323. raise
  324. try:
  325. # FIXME: convert to qrexec calls to dom0/GUI VM
  326. appmenus_cmd = \
  327. ['qvm-appmenus', '--init', '--update',
  328. '--source', src_vm.name, dst_vm.name]
  329. subprocess.check_output(appmenus_cmd, stderr=subprocess.STDOUT)
  330. except OSError:
  331. # this file needs to be python 2.7 compatible,
  332. # so no FileNotFoundError
  333. self.log.error('Failed to clone appmenus, qvm-appmenus missing')
  334. if not ignore_errors:
  335. raise qubesadmin.exc.QubesException(
  336. 'Failed to clone appmenus')
  337. except subprocess.CalledProcessError as e:
  338. self.log.error('Failed to clone appmenus: %s',
  339. e.output.decode())
  340. if not ignore_errors:
  341. raise qubesadmin.exc.QubesException(
  342. 'Failed to clone appmenus')
  343. except qubesadmin.exc.QubesException:
  344. if not ignore_errors:
  345. del self.domains[dst_vm.name]
  346. raise
  347. try:
  348. for dst_volume in sorted(dst_vm.volumes.values()):
  349. if not dst_volume.save_on_stop:
  350. # clone only persistent volumes
  351. continue
  352. if ignore_volumes and dst_volume.name in ignore_volumes:
  353. continue
  354. src_volume = src_vm.volumes[dst_volume.name]
  355. dst_vm.log.info('Cloning {} volume'.format(dst_volume.name))
  356. dst_volume.clone(src_volume)
  357. except qubesadmin.exc.QubesException:
  358. del self.domains[dst_vm.name]
  359. raise
  360. return dst_vm
  361. def run_service(self, dest, service, filter_esc=False, user=None,
  362. localcmd=None, wait=True, **kwargs):
  363. '''Run qrexec service in a given destination
  364. *kwargs* are passed verbatim to :py:meth:`subprocess.Popen`.
  365. :param str dest: Destination - may be a VM name or empty
  366. string for default (for a given service)
  367. :param str service: service name
  368. :param bool filter_esc: filter escape sequences to protect terminal \
  369. emulator
  370. :param str user: username to run service as
  371. :param str localcmd: Command to connect stdin/stdout to
  372. :rtype: subprocess.Popen
  373. '''
  374. raise NotImplementedError
  375. class QubesLocal(QubesBase):
  376. '''Application object communicating through local socket.
  377. Used when running in dom0.
  378. '''
  379. qubesd_connection_type = 'socket'
  380. def qubesd_call(self, dest, method, arg=None, payload=None,
  381. payload_stream=None):
  382. '''
  383. Execute Admin API method.
  384. Only one of `payload` and `payload_stream` can be specified.
  385. :param dest: Destination VM name
  386. :param method: Full API method name ('admin...')
  387. :param arg: Method argument (if any)
  388. :param payload: Payload send to the method
  389. :param payload_stream: file-like object to read payload from
  390. :return: Data returned by qubesd (string)
  391. .. warning:: *payload_stream* will get closed by this function
  392. '''
  393. if payload and payload_stream:
  394. raise ValueError(
  395. 'Only one of payload and payload_stream can be used')
  396. if payload_stream:
  397. # payload_stream can be used for large amount of data,
  398. # so optimize for throughput, not latency: spawn actual qrexec
  399. # service implementation, which may use some optimization there (
  400. # see admin.vm.volume.Import - actual data handling is done with dd)
  401. method_path = os.path.join(
  402. qubesadmin.config.QREXEC_SERVICES_DIR, method)
  403. if not os.path.exists(method_path):
  404. raise qubesadmin.exc.QubesDaemonCommunicationError(
  405. '{} not found'.format(method_path))
  406. command = ['env', 'QREXEC_REMOTE_DOMAIN=dom0',
  407. 'QREXEC_REQUESTED_TARGET=' + dest, method_path, arg]
  408. if os.getuid() != 0:
  409. command.insert(0, 'sudo')
  410. proc = subprocess.Popen(command, stdin=payload_stream,
  411. stdout=subprocess.PIPE)
  412. payload_stream.close()
  413. (return_data, _) = proc.communicate()
  414. return self._parse_qubesd_response(return_data)
  415. try:
  416. client_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  417. client_socket.connect(qubesadmin.config.QUBESD_SOCKET)
  418. except (IOError, OSError) as e:
  419. raise qubesadmin.exc.QubesDaemonCommunicationError(
  420. 'Failed to connect to qubesd service: %s', str(e))
  421. # src, method, dest, arg
  422. for call_arg in ('dom0', method, dest, arg):
  423. if call_arg is not None:
  424. client_socket.sendall(call_arg.encode('ascii'))
  425. client_socket.sendall(b'\0')
  426. if payload is not None:
  427. client_socket.sendall(payload)
  428. client_socket.shutdown(socket.SHUT_WR)
  429. return_data = client_socket.makefile('rb').read()
  430. client_socket.close()
  431. return self._parse_qubesd_response(return_data)
  432. def run_service(self, dest, service, filter_esc=False, user=None,
  433. localcmd=None, wait=True, **kwargs):
  434. '''Run qrexec service in a given destination
  435. :param str dest: Destination - may be a VM name or empty
  436. string for default (for a given service)
  437. :param str service: service name
  438. :param bool filter_esc: filter escape sequences to protect terminal \
  439. emulator
  440. :param str user: username to run service as
  441. :param str localcmd: Command to connect stdin/stdout to
  442. :param bool wait: wait for remote process to finish
  443. :param int connect_timeout: qrexec client connection timeout
  444. :rtype: subprocess.Popen
  445. '''
  446. if not dest:
  447. raise ValueError('Empty destination name allowed only from a VM')
  448. if not wait and localcmd:
  449. raise ValueError('wait=False incompatible with localcmd')
  450. try:
  451. self.qubesd_call(dest, 'admin.vm.Start')
  452. except qubesadmin.exc.QubesVMNotHaltedError:
  453. pass
  454. qrexec_opts = ['-d', dest]
  455. if filter_esc:
  456. qrexec_opts.extend(['-t'])
  457. if filter_esc or os.isatty(sys.stderr.fileno()):
  458. qrexec_opts.extend(['-T'])
  459. if localcmd:
  460. qrexec_opts.extend(['-l', localcmd])
  461. if user is None:
  462. user = 'DEFAULT'
  463. if not wait:
  464. qrexec_opts.extend(['-e'])
  465. if 'connect_timeout' in kwargs:
  466. qrexec_opts.extend(['-w', str(kwargs.pop('connect_timeout'))])
  467. kwargs.setdefault('stdin', subprocess.PIPE)
  468. kwargs.setdefault('stdout', subprocess.PIPE)
  469. kwargs.setdefault('stderr', subprocess.PIPE)
  470. proc = subprocess.Popen([qubesadmin.config.QREXEC_CLIENT] +
  471. qrexec_opts + ['{}:QUBESRPC {} dom0'.format(user, service)],
  472. **kwargs)
  473. return proc
  474. class QubesRemote(QubesBase):
  475. '''Application object communicating through qrexec services.
  476. Used when running in VM.
  477. '''
  478. qubesd_connection_type = 'qrexec'
  479. def qubesd_call(self, dest, method, arg=None, payload=None,
  480. payload_stream=None):
  481. '''
  482. Execute Admin API method.
  483. Only one of `payload` and `payload_stream` can be specified.
  484. :param dest: Destination VM name
  485. :param method: Full API method name ('admin...')
  486. :param arg: Method argument (if any)
  487. :param payload: Payload send to the method
  488. :param payload_stream: file-like object to read payload from
  489. :return: Data returned by qubesd (string)
  490. .. warning:: *payload_stream* will get closed by this function
  491. '''
  492. if payload and payload_stream:
  493. raise ValueError(
  494. 'Only one of payload and payload_stream can be used')
  495. service_name = method
  496. if arg is not None:
  497. service_name += '+' + arg
  498. p = subprocess.Popen([qubesadmin.config.QREXEC_CLIENT_VM,
  499. dest, service_name],
  500. stdin=(payload_stream or subprocess.PIPE),
  501. stdout=subprocess.PIPE,
  502. stderr=subprocess.PIPE)
  503. if payload_stream is not None:
  504. payload_stream.close()
  505. (stdout, stderr) = p.communicate(payload)
  506. if p.returncode != 0:
  507. raise qubesadmin.exc.QubesDaemonNoResponseError(
  508. 'Service call error: %s', stderr.decode())
  509. return self._parse_qubesd_response(stdout)
  510. def run_service(self, dest, service, filter_esc=False, user=None,
  511. localcmd=None, wait=True, **kwargs):
  512. '''Run qrexec service in a given destination
  513. :param str dest: Destination - may be a VM name or empty
  514. string for default (for a given service)
  515. :param str service: service name
  516. :param bool filter_esc: filter escape sequences to protect terminal \
  517. emulator
  518. :param str user: username to run service as
  519. :param str localcmd: Command to connect stdin/stdout to
  520. :param bool wait: wait for process to finish
  521. :rtype: subprocess.Popen
  522. '''
  523. if filter_esc:
  524. raise NotImplementedError(
  525. 'filter_esc not implemented for calls from VM')
  526. if user:
  527. raise ValueError(
  528. 'non-default user not possible for calls from VM')
  529. if not wait and localcmd:
  530. raise ValueError('wait=False incompatible with localcmd')
  531. if not wait:
  532. # qrexec-client-vm can only request service calls, which are
  533. # started using MSG_EXEC_CMDLINE qrexec protocol message; this
  534. # message means "start the process, pipe its stdin/out/err,
  535. # and when it terminates, send exit code back".
  536. # According to the protocol qrexec-client-vm needs to wait for
  537. # MSG_DATA_EXIT_CODE, so implementing wait=False would require
  538. # some protocol change (or protocol violation).
  539. raise NotImplementedError(
  540. 'wait=False not implemented for calls from VM')
  541. kwargs.setdefault('stdin', subprocess.PIPE)
  542. kwargs.setdefault('stdout', subprocess.PIPE)
  543. kwargs.setdefault('stderr', subprocess.PIPE)
  544. proc = subprocess.Popen([qubesadmin.config.QREXEC_CLIENT_VM,
  545. dest or '', service] + (shlex.split(localcmd) if localcmd else []),
  546. **kwargs)
  547. return proc