From bfe1a3d541c415d25fefc1af4bc173f25e5f6ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 20 Apr 2020 00:45:50 +0200 Subject: [PATCH] Adjust for changed qubesd socket protocol The socket protocol is adjusted to match qrexec socket service protocol. QubesOS/qubes-issues#3293 --- qubesadmin/app.py | 7 ++----- qubesadmin/events/__init__.py | 7 +++---- qubesadmin/tests/app.py | 12 ++++++------ qubesadmin/tests/events.py | 4 ++-- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/qubesadmin/app.py b/qubesadmin/app.py index 72dc0cb..de83840 100644 --- a/qubesadmin/app.py +++ b/qubesadmin/app.py @@ -659,11 +659,8 @@ class QubesLocal(QubesBase): raise qubesadmin.exc.QubesDaemonCommunicationError( 'Failed to connect to qubesd service: %s', str(e)) - # src, method, dest, arg - for call_arg in ('dom0', method, dest, arg): - if call_arg is not None: - client_socket.sendall(call_arg.encode('ascii')) - client_socket.sendall(b'\0') + call_header = '{}+{} dom0 name {}\0'.format(method, arg or '', dest) + client_socket.sendall(call_header.encode('ascii')) if payload is not None: client_socket.sendall(payload) diff --git a/qubesadmin/events/__init__.py b/qubesadmin/events/__init__.py index 634c5db..17eb9f3 100644 --- a/qubesadmin/events/__init__.py +++ b/qubesadmin/events/__init__.py @@ -79,10 +79,9 @@ class EventsDispatcher(object): if self.app.qubesd_connection_type == 'socket': reader, writer = yield from asyncio.open_unix_connection( qubesadmin.config.QUBESD_SOCKET) - writer.write(b'dom0\0') # source - writer.write(self._api_method.encode() + b'\0') # method - writer.write(dest.encode('ascii') + b'\0') # dest - writer.write(b'\0') # arg + writer.write(self._api_method.encode() + b'+ ') # method+arg + writer.write(b'dom0 ') # source + writer.write(b'name ' + dest.encode('ascii') + b'\0') # dest writer.write_eof() def cleanup_func(): diff --git a/qubesadmin/tests/app.py b/qubesadmin/tests/app.py index c141dce..743819f 100644 --- a/qubesadmin/tests/app.py +++ b/qubesadmin/tests/app.py @@ -771,19 +771,19 @@ class TC_20_QubesLocal(unittest.TestCase): self.listen_and_send(b'0\0') self.app.qubesd_call('test-vm', 'some.method', 'arg1', b'payload') self.assertEqual(self.get_request(), - b'dom0\0some.method\0test-vm\0arg1\0payload') + b'some.method+arg1 dom0 name test-vm\0payload') def test_001_qubesd_call_none_arg(self): self.listen_and_send(b'0\0') self.app.qubesd_call('test-vm', 'some.method', None, b'payload') self.assertEqual(self.get_request(), - b'dom0\0some.method\0test-vm\0\0payload') + b'some.method+ dom0 name test-vm\0payload') def test_002_qubesd_call_none_payload(self): self.listen_and_send(b'0\0') self.app.qubesd_call('test-vm', 'some.method', None, None) self.assertEqual(self.get_request(), - b'dom0\0some.method\0test-vm\0\0') + b'some.method+ dom0 name test-vm\0') def test_003_qubesd_call_payload_stream(self): payload_input = os.path.join(self.tmpdir, 'payload-input') @@ -851,7 +851,7 @@ class TC_20_QubesLocal(unittest.TestCase): stderr=subprocess.PIPE) self.assertEqual(self.get_request(), - b'dom0\0admin.vm.Start\0some-vm\0\0') + b'admin.vm.Start+ dom0 name some-vm\0') def test_011_run_service_filter_esc(self): self.listen_and_send(b'0\0') @@ -865,7 +865,7 @@ class TC_20_QubesLocal(unittest.TestCase): stderr=subprocess.PIPE) self.assertEqual(self.get_request(), - b'dom0\0admin.vm.Start\0some-vm\0\0') + b'admin.vm.Start+ dom0 name some-vm\0') @mock.patch('os.isatty', lambda fd: fd == 2) def test_012_run_service_user(self): @@ -880,7 +880,7 @@ class TC_20_QubesLocal(unittest.TestCase): stderr=subprocess.PIPE) self.assertEqual(self.get_request(), - b'dom0\0admin.vm.Start\0some-vm\0\0') + b'admin.vm.Start+ dom0 name some-vm\0') def test_013_run_service_default_target(self): with self.assertRaises(ValueError): diff --git a/qubesadmin/tests/events.py b/qubesadmin/tests/events.py index fca6648..0dfd455 100644 --- a/qubesadmin/tests/events.py +++ b/qubesadmin/tests/events.py @@ -166,7 +166,7 @@ class TC_00_Events(qubesadmin.tests.QubesTestCase): self.read_all, sock2)) loop.run_until_complete(asyncio.wait([task, reader])) self.assertEqual(reader.result(), - b'dom0\0admin.Events\0dom0\0\0') + b'admin.Events+ dom0 name dom0\0') self.assertIsInstance(task.result()[0], asyncio.StreamReader) cleanup_func = task.result()[1] cleanup_func() @@ -192,7 +192,7 @@ class TC_00_Events(qubesadmin.tests.QubesTestCase): self.read_all, sock2)) loop.run_until_complete(asyncio.wait([task, reader])) self.assertEqual(reader.result(), - b'dom0\0admin.Events\0test-vm\0\0') + b'admin.Events+ dom0 name test-vm\0') self.assertIsInstance(task.result()[0], asyncio.StreamReader) cleanup_func = task.result()[1] cleanup_func()