/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-ctl

Merge new wireless network hook.  Fix bridge network hook to use
hardware addresses instead of interface names.  Implement and document
new "CONNECT" environment variable for network hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
server_path = "/"
61
61
server_interface = domain + ".Mandos"
62
62
client_interface = domain + ".Mandos.Client"
63
 
version = "1.3.1"
 
63
version = "1.4.1"
64
64
 
65
65
def timedelta_to_milliseconds(td):
66
66
    """Convert a datetime.timedelta object to milliseconds"""
93
93
    >>> string_to_delta("5m 30s")
94
94
    datetime.timedelta(0, 330)
95
95
    """
96
 
    timevalue = datetime.timedelta(0)
97
 
    regexp = re.compile("\d+[dsmhw]")
 
96
    value = datetime.timedelta(0)
 
97
    regexp = re.compile("(\d+)([dsmhw]?)")
98
98
    
99
 
    for s in regexp.findall(interval):
100
 
        try:
101
 
            suffix = unicode(s[-1])
102
 
            value = int(s[:-1])
103
 
            if suffix == "d":
104
 
                delta = datetime.timedelta(value)
105
 
            elif suffix == "s":
106
 
                delta = datetime.timedelta(0, value)
107
 
            elif suffix == "m":
108
 
                delta = datetime.timedelta(0, 0, 0, 0, value)
109
 
            elif suffix == "h":
110
 
                delta = datetime.timedelta(0, 0, 0, 0, 0, value)
111
 
            elif suffix == "w":
112
 
                delta = datetime.timedelta(0, 0, 0, 0, 0, 0, value)
113
 
            else:
114
 
                raise ValueError
115
 
        except (ValueError, IndexError):
116
 
            raise ValueError
117
 
        timevalue += delta
118
 
    return timevalue
 
99
    for num, suffix in regexp.findall(interval):
 
100
        if suffix == "d":
 
101
            value += datetime.timedelta(int(num))
 
102
        elif suffix == "s":
 
103
            value += datetime.timedelta(0, int(num))
 
104
        elif suffix == "m":
 
105
            value += datetime.timedelta(0, 0, 0, 0, int(num))
 
106
        elif suffix == "h":
 
107
            value += datetime.timedelta(0, 0, 0, 0, 0, int(num))
 
108
        elif suffix == "w":
 
109
            value += datetime.timedelta(0, 0, 0, 0, 0, 0, int(num))
 
110
        elif suffix == "":
 
111
            value += datetime.timedelta(0, 0, 0, int(num))
 
112
    return value
119
113
 
120
114
def print_clients(clients, keywords):
121
115
    def valuetostring(value, keyword):
242
236
            #restore stderr
243
237
            os.dup2(stderrcopy, sys.stderr.fileno())
244
238
            os.close(stderrcopy)
245
 
    except dbus.exceptions.DBusException, e:
 
239
    except dbus.exceptions.DBusException:
246
240
        print("Access denied: Accessing mandos server through dbus.",
247
241
              file=sys.stderr)
248
242
        sys.exit(1)
301
295
                                         dbus_interface=
302
296
                                         dbus.PROPERTIES_IFACE)
303
297
                         else 1)
304
 
            if options.checker:
 
298
            if options.checker is not None:
305
299
                client.Set(client_interface, "Checker",
306
300
                           options.checker,
307
301
                           dbus_interface=dbus.PROPERTIES_IFACE)
308
 
            if options.host:
 
302
            if options.host is not None:
309
303
                client.Set(client_interface, "Host", options.host,
310
304
                           dbus_interface=dbus.PROPERTIES_IFACE)
311
 
            if options.interval:
 
305
            if options.interval is not None:
312
306
                client.Set(client_interface, "Interval",
313
307
                           timedelta_to_milliseconds
314
308
                           (string_to_delta(options.interval)),
315
309
                           dbus_interface=dbus.PROPERTIES_IFACE)
316
 
            if options.approval_delay:
 
310
            if options.approval_delay is not None:
317
311
                client.Set(client_interface, "ApprovalDelay",
318
312
                           timedelta_to_milliseconds
319
313
                           (string_to_delta(options.
320
314
                                            approval_delay)),
321
315
                           dbus_interface=dbus.PROPERTIES_IFACE)
322
 
            if options.approval_duration:
 
316
            if options.approval_duration is not None:
323
317
                client.Set(client_interface, "ApprovalDuration",
324
318
                           timedelta_to_milliseconds
325
319
                           (string_to_delta(options.
326
320
                                            approval_duration)),
327
321
                           dbus_interface=dbus.PROPERTIES_IFACE)
328
 
            if options.timeout:
 
322
            if options.timeout is not None:
329
323
                client.Set(client_interface, "Timeout",
330
324
                           timedelta_to_milliseconds
331
325
                           (string_to_delta(options.timeout)),
332
326
                           dbus_interface=dbus.PROPERTIES_IFACE)
333
 
            if options.extended_timeout:
 
327
            if options.extended_timeout is not None:
334
328
                client.Set(client_interface, "ExtendedTimeout",
335
329
                           timedelta_to_milliseconds
336
330
                           (string_to_delta(options.extended_timeout)),
337
331
                           dbus_interface=dbus.PROPERTIES_IFACE)
338
 
            if options.secret:
 
332
            if options.secret is not None:
339
333
                client.Set(client_interface, "Secret",
340
334
                           dbus.ByteArray(open(options.secret,
341
335
                                               "rb").read()),