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

  • Committer: Teddy Hogeborn
  • Date: 2016-03-19 03:48:56 UTC
  • mto: (237.7.594 trunk)
  • mto: This revision was merged to the branch mainline in revision 341.
  • Revision ID: teddy@recompile.se-20160319034856-d8rox0kdxekgr03g
Server: Make persistent state directory mode u=rwx,go=

The Makefile target "install-server" creates the server persistent
state directory /var/lib/mandos as mode u=rwx,go= (0700).  Make this
also the case for the Debian package (unless overridden by
dpkg-statoverride).

* debian/mandos.postinst (configure): Fix state directory permissions,
  but only if not listed by "dpkg-statoverride".

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
4
4
# Mandos Monitor - Control and monitor the Mandos server
5
5
6
 
# Copyright © 2009-2014 Teddy Hogeborn
7
 
# Copyright © 2009-2014 Björn Påhlsson
 
6
# Copyright © 2009-2016 Teddy Hogeborn
 
7
# Copyright © 2009-2016 Björn Påhlsson
8
8
9
9
# This program is free software: you can redistribute it and/or modify
10
10
# it under the terms of the GNU General Public License as published by
39
39
import urwid
40
40
 
41
41
from dbus.mainloop.glib import DBusGMainLoop
42
 
try:
43
 
    import gobject
44
 
except ImportError:
45
 
    from gi.repository import GObject as gobject
 
42
from gi.repository import GLib
46
43
 
47
44
import dbus
48
45
 
60
57
domain = 'se.recompile'
61
58
server_interface = domain + '.Mandos'
62
59
client_interface = domain + '.Mandos.Client'
63
 
version = "1.6.9"
 
60
version = "1.7.6"
 
61
 
 
62
try:
 
63
    dbus.OBJECT_MANAGER_IFACE
 
64
except AttributeError:
 
65
    dbus.OBJECT_MANAGER_IFACE = "org.freedesktop.DBus.ObjectManager"
64
66
 
65
67
def isoformat_to_datetime(iso):
66
68
    "Parse an ISO 8601 date string to a datetime.datetime()"
105
107
        It updates the changed properties in the "properties" dict.
106
108
        """
107
109
        # Update properties dict with new value
108
 
        self.properties.update(properties)
 
110
        if interface == client_interface:
 
111
            self.properties.update(properties)
109
112
    
110
113
    def delete(self):
111
114
        self.property_changed_match.remove()
166
169
        """
167
170
        if flag and self._update_timer_callback_tag is None:
168
171
            # Will update the shown timer value every second
169
 
            self._update_timer_callback_tag = (gobject.timeout_add
 
172
            self._update_timer_callback_tag = (GLib.timeout_add
170
173
                                               (1000,
171
174
                                                self.update_timer))
172
175
        elif not (flag or self._update_timer_callback_tag is None):
173
 
            gobject.source_remove(self._update_timer_callback_tag)
 
176
            GLib.source_remove(self._update_timer_callback_tag)
174
177
            self._update_timer_callback_tag = None
175
178
    
176
179
    def checker_completed(self, exitstatus, condition, command):
191
194
                        ' killed by signal {}'
192
195
                        .format(self.properties["Name"], command,
193
196
                                os.WTERMSIG(condition)))
194
 
        elif os.WCOREDUMP(condition):
195
 
            self.logger('Checker for client {} (command "{}") dumped'
196
 
                        ' core'.format(self.properties["Name"],
197
 
                                       command))
198
 
        else:
199
 
            self.logger('Checker for client {} completed'
200
 
                        ' mysteriously'
201
 
                        .format(self.properties["Name"]))
202
197
        self.update()
203
198
    
204
199
    def checker_started(self, command):
311
306
            self.update_hook()
312
307
    
313
308
    def update_timer(self):
314
 
        """called by gobject. Will indefinitely loop until
315
 
        gobject.source_remove() on tag is called"""
 
309
        """called by GLib. Will indefinitely loop until
 
310
        GLib.source_remove() on tag is called
 
311
        """
316
312
        self.update()
317
313
        return True             # Keep calling this
318
314
    
319
315
    def delete(self, **kwargs):
320
316
        if self._update_timer_callback_tag is not None:
321
 
            gobject.source_remove(self._update_timer_callback_tag)
 
317
            GLib.source_remove(self._update_timer_callback_tag)
322
318
            self._update_timer_callback_tag = None
323
319
        for match in self.match_objects:
324
320
            match.remove()
337
333
        """Handle keys.
338
334
        This overrides the method from urwid.FlowWidget"""
339
335
        if key == "+":
340
 
            self.proxy.Enable(dbus_interface = client_interface,
341
 
                              ignore_reply=True)
 
336
            self.proxy.Set(client_interface, "Enabled",
 
337
                           dbus.Boolean(True), ignore_reply = True,
 
338
                           dbus_interface = dbus.PROPERTIES_IFACE)
342
339
        elif key == "-":
343
 
            self.proxy.Disable(dbus_interface = client_interface,
344
 
                               ignore_reply=True)
 
340
            self.proxy.Set(client_interface, "Enabled", False,
 
341
                           ignore_reply = True,
 
342
                           dbus_interface = dbus.PROPERTIES_IFACE)
345
343
        elif key == "a":
346
344
            self.proxy.Approve(dbus.Boolean(True, variant_level=1),
347
345
                               dbus_interface = client_interface,
355
353
                                                  .object_path,
356
354
                                                  ignore_reply=True)
357
355
        elif key == "s":
358
 
            self.proxy.StartChecker(dbus_interface = client_interface,
359
 
                                    ignore_reply=True)
 
356
            self.proxy.Set(client_interface, "CheckerRunning",
 
357
                           dbus.Boolean(True), ignore_reply = True,
 
358
                           dbus_interface = dbus.PROPERTIES_IFACE)
360
359
        elif key == "S":
361
 
            self.proxy.StopChecker(dbus_interface = client_interface,
362
 
                                   ignore_reply=True)
 
360
            self.proxy.Set(client_interface, "CheckerRunning",
 
361
                           dbus.Boolean(False), ignore_reply = True,
 
362
                           dbus_interface = dbus.PROPERTIES_IFACE)
363
363
        elif key == "C":
364
364
            self.proxy.CheckedOK(dbus_interface = client_interface,
365
365
                                 ignore_reply=True)
463
463
                              "q: Quit  ?: Help"))
464
464
        
465
465
        self.busname = domain + '.Mandos'
466
 
        self.main_loop = gobject.MainLoop()
 
466
        self.main_loop = GLib.MainLoop()
467
467
    
468
468
    def client_not_found(self, fingerprint, address):
469
469
        self.log_message("Client with address {} and fingerprint {}"
525
525
        self.log_message("Wrap mode: {}".format(self.log_wrap),
526
526
                         level=0)
527
527
    
528
 
    def find_and_remove_client(self, path, name):
 
528
    def find_and_remove_client(self, path, interfaces):
529
529
        """Find a client by its object path and remove it.
530
530
        
531
 
        This is connected to the ClientRemoved signal from the
 
531
        This is connected to the InterfacesRemoved signal from the
532
532
        Mandos server object."""
 
533
        if client_interface not in interfaces:
 
534
            # Not a Mandos client object; ignore
 
535
            return
533
536
        try:
534
537
            client = self.clients_dict[path]
535
538
        except KeyError:
536
539
            # not found?
537
 
            self.log_message("Unknown client {!r} ({!r}) removed"
538
 
                             .format(name, path))
 
540
            self.log_message("Unknown client {!r} removed"
 
541
                             .format(path))
539
542
            return
540
543
        client.delete()
541
544
    
542
 
    def add_new_client(self, path):
 
545
    def add_new_client(self, path, ifs_and_props):
 
546
        """Find a client by its object path and remove it.
 
547
        
 
548
        This is connected to the InterfacesAdded signal from the
 
549
        Mandos server object.
 
550
        """
 
551
        if client_interface not in ifs_and_props:
 
552
            # Not a Mandos client object; ignore
 
553
            return
543
554
        client_proxy_object = self.bus.get_object(self.busname, path)
544
555
        self.add_client(MandosClientWidget(server_proxy_object
545
556
                                           =self.mandos_serv,
550
561
                                           delete_hook
551
562
                                           =self.remove_client,
552
563
                                           logger
553
 
                                           =self.log_message),
 
564
                                           =self.log_message,
 
565
                                           properties
 
566
                                           = dict(ifs_and_props[
 
567
                                               client_interface])),
554
568
                        path=path)
555
569
    
556
570
    def add_client(self, client, path=None):
591
605
            mandos_clients = dbus.Dictionary()
592
606
        
593
607
        (self.mandos_serv
594
 
         .connect_to_signal("ClientRemoved",
 
608
         .connect_to_signal("InterfacesRemoved",
595
609
                            self.find_and_remove_client,
596
 
                            dbus_interface=server_interface,
 
610
                            dbus_interface
 
611
                            = dbus.OBJECT_MANAGER_IFACE,
597
612
                            byte_arrays=True))
598
613
        (self.mandos_serv
599
 
         .connect_to_signal("ClientAdded",
 
614
         .connect_to_signal("InterfacesAdded",
600
615
                            self.add_new_client,
601
 
                            dbus_interface=server_interface,
 
616
                            dbus_interface
 
617
                            = dbus.OBJECT_MANAGER_IFACE,
602
618
                            byte_arrays=True))
603
619
        (self.mandos_serv
604
620
         .connect_to_signal("ClientNotFound",
622
638
                            path=path)
623
639
        
624
640
        self.refresh()
625
 
        self._input_callback_tag = (gobject.io_add_watch
 
641
        self._input_callback_tag = (GLib.io_add_watch
626
642
                                    (sys.stdin.fileno(),
627
 
                                     gobject.IO_IN,
 
643
                                     GLib.IO_IN,
628
644
                                     self.process_input))
629
645
        self.main_loop.run()
630
646
        # Main loop has finished, we should close everything now
631
 
        gobject.source_remove(self._input_callback_tag)
 
647
        GLib.source_remove(self._input_callback_tag)
632
648
        self.screen.stop()
633
649
    
634
650
    def stop(self):