/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to mandos

  • Committer: teddy at recompile
  • Date: 2020-03-21 16:24:12 UTC
  • mfrom: (237.7.759 trunk)
  • Revision ID: teddy@recompile.se-20200321162412-m06i867zmiweuoa3
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python3 -b
 
1
#!/usr/bin/python3 -bI
2
2
# -*- mode: python; after-save-hook: (lambda () (let ((command (if (fboundp 'file-local-name) (file-local-name (buffer-file-name)) (or (file-remote-p (buffer-file-name) 'localname) (buffer-file-name))))) (if (= (progn (if (get-buffer "*Test*") (kill-buffer "*Test*")) (process-file-shell-command (format "%s --check" (shell-quote-argument command)) nil "*Test*")) 0) (let ((w (get-buffer-window "*Test*"))) (if w (delete-window w))) (progn (with-current-buffer "*Test*" (compilation-mode)) (display-buffer "*Test*" '(display-buffer-in-side-window)))))); coding: utf-8 -*-
3
3
#
4
4
# Mandos server - give out binary blobs to connecting clients.
78
78
import collections
79
79
import codecs
80
80
import unittest
 
81
import random
 
82
import shlex
81
83
 
82
84
import dbus
83
85
import dbus.service
91
93
 
92
94
if sys.version_info.major == 2:
93
95
    __metaclass__ = type
 
96
    str = unicode
 
97
 
 
98
# Add collections.abc.Callable if it does not exist
 
99
try:
 
100
    collections.abc.Callable
 
101
except AttributeError:
 
102
    class abc:
 
103
        Callable = collections.Callable
 
104
    collections.abc = abc
 
105
    del abc
 
106
 
 
107
# Add shlex.quote if it does not exist
 
108
try:
 
109
    shlex.quote
 
110
except AttributeError:
 
111
    shlex.quote = re.escape
94
112
 
95
113
# Show warnings by default
96
114
if not sys.warnoptions:
122
140
            # No value found
123
141
            SO_BINDTODEVICE = None
124
142
 
125
 
if sys.version_info.major == 2:
126
 
    str = unicode
127
 
 
128
143
if sys.version_info < (3, 2):
129
144
    configparser.Configparser = configparser.SafeConfigParser
130
145
 
1037
1052
        if self.checker_initiator_tag is not None:
1038
1053
            GLib.source_remove(self.checker_initiator_tag)
1039
1054
        self.checker_initiator_tag = GLib.timeout_add(
1040
 
            int(self.interval.total_seconds() * 1000),
 
1055
            random.randrange(int(self.interval.total_seconds() * 1000
 
1056
                                 + 1)),
1041
1057
            self.start_checker)
1042
1058
        # Schedule a disable() when 'timeout' has passed
1043
1059
        if self.disable_initiator_tag is not None:
1118
1134
        if self.checker is None:
1119
1135
            # Escape attributes for the shell
1120
1136
            escaped_attrs = {
1121
 
                attr: re.escape(str(getattr(self, attr)))
 
1137
                attr: shlex.quote(str(getattr(self, attr)))
1122
1138
                for attr in self.runtime_expansions}
1123
1139
            try:
1124
1140
                command = self.checker_command % escaped_attrs
1413
1429
                raise ValueError("Byte arrays not supported for non-"
1414
1430
                                 "'ay' signature {!r}"
1415
1431
                                 .format(prop._dbus_signature))
1416
 
            value = dbus.ByteArray(b''.join(chr(byte)
1417
 
                                            for byte in value))
 
1432
            value = dbus.ByteArray(bytes(value))
1418
1433
        prop(value)
1419
1434
 
1420
1435
    @dbus.service.method(dbus.PROPERTIES_IFACE,
2749
2764
        if command == 'getattr':
2750
2765
            attrname = request[1]
2751
2766
            if isinstance(client_object.__getattribute__(attrname),
2752
 
                          collections.Callable):
 
2767
                          collections.abc.Callable):
2753
2768
                parent_pipe.send(('function', ))
2754
2769
            else:
2755
2770
                parent_pipe.send((