api: improve handling of removed VMs just before the call (try 2)

If the destination domain doesn't exist anymore when the call gets
to qubesd, inform the client accordingly rather than giving it
a generic PermissionDenied error.
This enables client applications to handle such edge cases. Some
may want to inform the user about an incorrect request, others
(e.g. qvm-ls) may want to remove the specific domain from their
result list or try again later.

Fixes QubesOS/qubes-issues#5105
这个提交包含在:
3hhh 2021-04-09 16:46:07 +02:00
父节点 df6407f508
当前提交 d2ab40de54
找不到此签名对应的密钥
GPG 密钥 ID: EB03A691DB2F0833

查看文件

@ -118,20 +118,21 @@ class AbstractQubesAPI:
#: :py:class:`qubes.Qubes` object #: :py:class:`qubes.Qubes` object
self.app = app self.app = app
#: source qube
self.src = self.app.domains[src.decode('ascii')]
try: try:
vm = src.decode('ascii')
#: source qube
self.src = self.app.domains[vm]
vm = dest.decode('ascii')
#: destination qube #: destination qube
self.dest = self.app.domains[dest.decode('ascii')] self.dest = self.app.domains[vm]
except KeyError: except KeyError:
# normally this should filtered out by qrexec policy, but there are # normally this should filtered out by qrexec policy, but there are
# two cases it might not be: # two cases it might not be:
# 1. The call comes from dom0, which bypasses qrexec policy # 1. The call comes from dom0, which bypasses qrexec policy
# 2. Domain was removed between checking the policy and here # 2. Domain was removed between checking the policy and here
# For uniform handling on the client side, treat this as permission # we inform the client accordingly
# denied error too raise qubes.exc.QubesVMNotFoundError(vm)
raise PermissionDenied
#: argument #: argument
self.arg = arg.decode('ascii') self.arg = arg.decode('ascii')