Convert qubesagent module to python3
This and all files using it. QubesOS/qubes-issues#5297
This commit is contained in:
		
							parent
							
								
									73648ca038
								
							
						
					
					
						commit
						a899adb69e
					
				
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							@ -11,7 +11,7 @@ BINDIR ?= /usr/bin
 | 
			
		||||
LIBDIR ?= /usr/lib
 | 
			
		||||
SYSLIBDIR ?= /lib
 | 
			
		||||
 | 
			
		||||
PYTHON ?= /usr/bin/python2
 | 
			
		||||
PYTHON ?= /usr/bin/python3
 | 
			
		||||
PYTHON_SITEARCH = $(shell python2 -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_lib(1)')
 | 
			
		||||
PYTHON2_SITELIB = $(shell python2 -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_lib()')
 | 
			
		||||
PYTHON3_SITELIB = $(shell python3 -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())')
 | 
			
		||||
 | 
			
		||||
@ -61,10 +61,10 @@ build() {
 | 
			
		||||
# * core systemd services and drop-ins
 | 
			
		||||
# * basic network functionality (setting IP address, DNS, default gateway)
 | 
			
		||||
package_qubes-vm-core() {
 | 
			
		||||
    depends=("qubes-vm-utils>=3.1.3" python2 python2-xdg ethtool ntp net-tools
 | 
			
		||||
    depends=("qubes-vm-utils>=3.1.3" python2 python3-xdg ethtool ntp net-tools
 | 
			
		||||
             gnome-packagekit imagemagick fakeroot notification-daemon dconf
 | 
			
		||||
             zenity qubes-libvchan "qubes-db-vm>=3.2.1" haveged python2-gobject
 | 
			
		||||
             python2-dbus xdg-utils notification-daemon gawk sed procps-ng librsvg
 | 
			
		||||
             zenity qubes-libvchan "qubes-db-vm>=3.2.1" haveged python3-gobject
 | 
			
		||||
             python3-dbus xdg-utils notification-daemon gawk sed procps-ng librsvg
 | 
			
		||||
             socat
 | 
			
		||||
             )
 | 
			
		||||
    optdepends=(gnome-keyring gnome-settings-daemon python2-nautilus gpk-update-viewer qubes-vm-networking qubes-vm-keyring)
 | 
			
		||||
@ -74,7 +74,7 @@ package_qubes-vm-core() {
 | 
			
		||||
    # shellcheck disable=SC2154
 | 
			
		||||
    make -C qrexec install DESTDIR="$pkgdir" SBINDIR=/usr/bin LIBDIR=/usr/lib SYSLIBDIR=/usr/lib
 | 
			
		||||
 | 
			
		||||
    PYTHON=python2 make install-corevm DESTDIR="$pkgdir" SBINDIR=/usr/bin LIBDIR=/usr/lib SYSLIBDIR=/usr/lib SYSTEM_DROPIN_DIR=/usr/lib/systemd/system USER_DROPIN_DIR=/usr/lib/systemd/user DIST=archlinux
 | 
			
		||||
    make install-corevm DESTDIR="$pkgdir" SBINDIR=/usr/bin LIBDIR=/usr/lib SYSLIBDIR=/usr/lib SYSTEM_DROPIN_DIR=/usr/lib/systemd/system USER_DROPIN_DIR=/usr/lib/systemd/user DIST=archlinux
 | 
			
		||||
 | 
			
		||||
    # Remove things non wanted in archlinux
 | 
			
		||||
    rm -r "$pkgdir/etc/yum"*
 | 
			
		||||
@ -122,13 +122,13 @@ EOF
 | 
			
		||||
#
 | 
			
		||||
package_qubes-vm-networking() {
 | 
			
		||||
    pkgdesc="Qubes OS tools allowing to use a Qubes VM as a NetVM/ProxyVM"
 | 
			
		||||
    depends=(qubes-vm-core "qubes-vm-utils>=3.1.3" python2 ethtool net-tools
 | 
			
		||||
    depends=(qubes-vm-core "qubes-vm-utils>=3.1.3" python3 ethtool net-tools
 | 
			
		||||
             "qubes-db-vm>=3.2.1" networkmanager iptables tinyproxy nftables
 | 
			
		||||
             )
 | 
			
		||||
    install=PKGBUILD-networking.install
 | 
			
		||||
 | 
			
		||||
    # shellcheck disable=SC2154
 | 
			
		||||
    PYTHON=python2 make install-netvm DESTDIR="$pkgdir" SBINDIR=/usr/bin LIBDIR=/usr/lib SYSLIBDIR=/usr/lib SYSTEM_DROPIN_DIR=/usr/lib/systemd/system USER_DROPIN_DIR=/usr/lib/systemd/user DIST=archlinux
 | 
			
		||||
    make install-netvm DESTDIR="$pkgdir" SBINDIR=/usr/bin LIBDIR=/usr/lib SYSLIBDIR=/usr/lib SYSTEM_DROPIN_DIR=/usr/lib/systemd/system USER_DROPIN_DIR=/usr/lib/systemd/user DIST=archlinux
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										12
									
								
								debian/control
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								debian/control
									
									
									
									
										vendored
									
									
								
							@ -7,7 +7,7 @@ Build-Depends:
 | 
			
		||||
    libqubes-rpc-filecopy-dev (>= 3.1.3),
 | 
			
		||||
    libvchan-xen-dev,
 | 
			
		||||
    python,
 | 
			
		||||
    python-setuptools,
 | 
			
		||||
    python3-setuptools,
 | 
			
		||||
    debhelper,
 | 
			
		||||
    quilt,
 | 
			
		||||
    libxen-dev,
 | 
			
		||||
@ -40,11 +40,11 @@ Depends:
 | 
			
		||||
    util-linux,
 | 
			
		||||
    e2fsprogs,
 | 
			
		||||
    python2.7,
 | 
			
		||||
    python-daemon,
 | 
			
		||||
    python-qubesdb,
 | 
			
		||||
    python-gi,
 | 
			
		||||
    python-xdg,
 | 
			
		||||
    python-dbus,
 | 
			
		||||
    python3-daemon,
 | 
			
		||||
    python3-qubesdb,
 | 
			
		||||
    python3-gi,
 | 
			
		||||
    python3-xdg,
 | 
			
		||||
    python3-dbus,
 | 
			
		||||
    qubes-utils (>= 3.1.3),
 | 
			
		||||
    qubes-core-qrexec,
 | 
			
		||||
    qubesdb-vm,
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								debian/qubes-core-agent.install
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								debian/qubes-core-agent.install
									
									
									
									
										vendored
									
									
								
							@ -107,8 +107,8 @@ usr/bin/qvm-connect-tcp
 | 
			
		||||
usr/bin/qvm-console
 | 
			
		||||
usr/bin/qvm-sync-clock
 | 
			
		||||
usr/bin/xenstore-watch-qubes
 | 
			
		||||
usr/lib/python2.7/dist-packages/qubesagent-*.egg-info/*
 | 
			
		||||
usr/lib/python2.7/dist-packages/qubesagent/*
 | 
			
		||||
usr/lib/python3/dist-packages/qubesagent-*.egg-info/*
 | 
			
		||||
usr/lib/python3/dist-packages/qubesagent/*
 | 
			
		||||
usr/lib/qubes-bind-dirs.d/30_cron.conf
 | 
			
		||||
usr/lib/qubes/close-window
 | 
			
		||||
usr/lib/qubes/init/bind-dirs.sh
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
#!/usr/bin/python2
 | 
			
		||||
#!/usr/bin/python3
 | 
			
		||||
 | 
			
		||||
from qubesagent.xdg import launch
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
@ -1,9 +1,9 @@
 | 
			
		||||
#!/usr/bin/python2
 | 
			
		||||
#!/usr/bin/python3
 | 
			
		||||
# -*- coding: utf-8 -*-
 | 
			
		||||
#
 | 
			
		||||
# The Qubes OS Project, http://www.qubes-os.org
 | 
			
		||||
#
 | 
			
		||||
# Copyright (C) 2015  Marek Marczykowski-Górecki
 | 
			
		||||
# Copyright (C) 2015-2019  Marek Marczykowski-Górecki
 | 
			
		||||
#                                        <marmarek@invisiblethingslab.com>
 | 
			
		||||
#
 | 
			
		||||
# This program is free software; you can redistribute it and/or
 | 
			
		||||
@ -21,7 +21,6 @@
 | 
			
		||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 | 
			
		||||
#
 | 
			
		||||
#
 | 
			
		||||
import subprocess
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
from xdg.DesktopEntry import DesktopEntry
 | 
			
		||||
@ -78,8 +77,9 @@ def process_autostart(environments):
 | 
			
		||||
                if entry_should_be_started(entry, environments):
 | 
			
		||||
                    launch(entry_path, wait=False)
 | 
			
		||||
            except Exception as e:
 | 
			
		||||
                print >>sys.stderr, "Failed to process '{}': {}".format(
 | 
			
		||||
                    entry_name, str(e)
 | 
			
		||||
                print("Failed to process '{}': {}".format(
 | 
			
		||||
                    entry_name, str(e)),
 | 
			
		||||
                    file=sys.stderr
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
def main():
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,3 @@
 | 
			
		||||
#!/usr/bin/python2 -O
 | 
			
		||||
# vim: fileencoding=utf-8
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
@ -103,7 +102,8 @@ class FirewallWorker(object):
 | 
			
		||||
        entries = self.qdb.multiread('/qubes-firewall/{}/'.format(target))
 | 
			
		||||
        assert isinstance(entries, dict)
 | 
			
		||||
        # drop full path
 | 
			
		||||
        entries = dict(((k.split('/')[3], v) for k, v in entries.items()))
 | 
			
		||||
        entries = dict(((k.split('/')[3], v.decode())
 | 
			
		||||
                        for k, v in entries.items()))
 | 
			
		||||
        if 'policy' not in entries:
 | 
			
		||||
            raise RuleParseError('No \'policy\' defined')
 | 
			
		||||
        policy = entries.pop('policy')
 | 
			
		||||
@ -377,7 +377,7 @@ class IptablesWorker(FirewallWorker):
 | 
			
		||||
        try:
 | 
			
		||||
            self.run_ipt(family, ['-F', chain])
 | 
			
		||||
            p = self.run_ipt_restore(family, ['-n'])
 | 
			
		||||
            (output, _) = p.communicate(iptables)
 | 
			
		||||
            (output, _) = p.communicate(iptables.encode())
 | 
			
		||||
            if p.returncode != 0:
 | 
			
		||||
                raise RuleApplyError(
 | 
			
		||||
                    'iptables-restore failed: {}'.format(output))
 | 
			
		||||
@ -437,7 +437,7 @@ class NftablesWorker(FirewallWorker):
 | 
			
		||||
                             stdin=subprocess.PIPE,
 | 
			
		||||
                             stdout=subprocess.PIPE,
 | 
			
		||||
                             stderr=subprocess.STDOUT)
 | 
			
		||||
        stdout, _ = p.communicate(nft_input)
 | 
			
		||||
        stdout, _ = p.communicate(nft_input.encode())
 | 
			
		||||
        if p.returncode != 0:
 | 
			
		||||
            raise RuleApplyError('nft failed: {}'.format(stdout))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -14,7 +14,7 @@ class DummyIptablesRestore(object):
 | 
			
		||||
        self.returncode = 0
 | 
			
		||||
 | 
			
		||||
    def communicate(self, stdin=None):
 | 
			
		||||
        self._worker_mock.loaded_iptables[self._family] = stdin
 | 
			
		||||
        self._worker_mock.loaded_iptables[self._family] = stdin.decode()
 | 
			
		||||
        return ("", None)
 | 
			
		||||
 | 
			
		||||
class DummyQubesDB(object):
 | 
			
		||||
@ -480,18 +480,18 @@ class TestFirewallWorker(TestCase):
 | 
			
		||||
        self.obj = FirewallWorker()
 | 
			
		||||
        rules = {
 | 
			
		||||
            '10.137.0.1': {
 | 
			
		||||
                'policy': 'accept',
 | 
			
		||||
                '0000': 'proto=tcp dstports=80-80 action=drop',
 | 
			
		||||
                '0001': 'proto=udp specialtarget=dns action=accept',
 | 
			
		||||
                '0002': 'proto=udp action=drop',
 | 
			
		||||
                'policy': b'accept',
 | 
			
		||||
                '0000': b'proto=tcp dstports=80-80 action=drop',
 | 
			
		||||
                '0001': b'proto=udp specialtarget=dns action=accept',
 | 
			
		||||
                '0002': b'proto=udp action=drop',
 | 
			
		||||
            },
 | 
			
		||||
            '10.137.0.2': {'policy': 'accept'},
 | 
			
		||||
            '10.137.0.2': {'policy': b'accept'},
 | 
			
		||||
            # no policy
 | 
			
		||||
            '10.137.0.3': {'0000': 'proto=tcp action=accept'},
 | 
			
		||||
            '10.137.0.3': {'0000': b'proto=tcp action=accept'},
 | 
			
		||||
            # no action
 | 
			
		||||
            '10.137.0.4': {
 | 
			
		||||
                'policy': 'drop',
 | 
			
		||||
                '0000': 'proto=tcp'
 | 
			
		||||
                'policy': b'drop',
 | 
			
		||||
                '0000': b'proto=tcp'
 | 
			
		||||
            },
 | 
			
		||||
        }
 | 
			
		||||
        for addr, entries in rules.items():
 | 
			
		||||
 | 
			
		||||
@ -124,9 +124,9 @@ Requires:   hostname
 | 
			
		||||
Requires:   xterm
 | 
			
		||||
# for qubes-desktop-run
 | 
			
		||||
Requires:   pygobject3-base
 | 
			
		||||
Requires:   dbus-python
 | 
			
		||||
Requires:   python3-dbus
 | 
			
		||||
# for qubes-session-autostart, xdg-icon
 | 
			
		||||
Requires:   pyxdg
 | 
			
		||||
Requires:   python3-pyxdg
 | 
			
		||||
Requires:   python3-daemon
 | 
			
		||||
# for qvm-feature-request
 | 
			
		||||
Requires:   python3-qubesdb
 | 
			
		||||
@ -654,7 +654,6 @@ rm -f %{name}-%{version}
 | 
			
		||||
/usr/lib/qubes/init/resize-rootfs-if-needed.sh
 | 
			
		||||
/usr/lib/qubes/init/setup-rw.sh
 | 
			
		||||
/usr/lib/qubes/init/setup-rwdev.sh
 | 
			
		||||
/usr/lib/qubes/init/functions
 | 
			
		||||
%dir /usr/lib/qubes-bind-dirs.d
 | 
			
		||||
/usr/lib/qubes-bind-dirs.d/30_cron.conf
 | 
			
		||||
/usr/share/applications/qubes-run-terminal.desktop
 | 
			
		||||
@ -666,13 +665,14 @@ rm -f %{name}-%{version}
 | 
			
		||||
/usr/share/glib-2.0/schemas/20_org.gnome.desktop.wm.preferences.qubes.gschema.override
 | 
			
		||||
%{_mandir}/man1/qvm-*.1*
 | 
			
		||||
 | 
			
		||||
%dir %{python2_sitelib}/qubesagent-*-py2.7.egg-info
 | 
			
		||||
%{python2_sitelib}/qubesagent-*-py2.7.egg-info/*
 | 
			
		||||
%dir %{python2_sitelib}/qubesagent
 | 
			
		||||
%{python2_sitelib}/qubesagent/__init__.py*
 | 
			
		||||
%{python2_sitelib}/qubesagent/firewall.py*
 | 
			
		||||
%{python2_sitelib}/qubesagent/test_firewall.py*
 | 
			
		||||
%{python2_sitelib}/qubesagent/xdg.py*
 | 
			
		||||
%dir %{python3_sitelib}/qubesagent-*-py*.egg-info
 | 
			
		||||
%{python3_sitelib}/qubesagent-*-py*.egg-info/*
 | 
			
		||||
%{python3_sitelib}/qubesagent/__pycache__
 | 
			
		||||
%dir %{python3_sitelib}/qubesagent
 | 
			
		||||
%{python3_sitelib}/qubesagent/__init__.py*
 | 
			
		||||
%{python3_sitelib}/qubesagent/firewall.py*
 | 
			
		||||
%{python3_sitelib}/qubesagent/test_firewall.py*
 | 
			
		||||
%{python3_sitelib}/qubesagent/xdg.py*
 | 
			
		||||
 | 
			
		||||
/usr/share/qubes/mime-override/globs
 | 
			
		||||
/usr/share/qubes/qubes-master-key.asc
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user