/mandos/trunk

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

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2016-03-05 21:05:11 UTC
  • Revision ID: teddy@recompile.se-20160305210511-pbehwc5ap85cfhdm
Rename "gobject" to "GObject"; prefer the new python-gi

* debian/control (Source: mandos/Build-Depends-Indep): Change
  "python-gobject | python-gi" to "python-gi | python-gobject"
  (Package: mandos/Depends): - '' -
* mandos: Prefer "gi" module over "gobject" module.  Import "gobject"
  as "GObject"; change spelling throughout.
* mandos-monitor: - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
import dbus
78
78
import dbus.service
79
79
try:
80
 
    import gobject
 
80
    from gi.repository import GObject
81
81
except ImportError:
82
 
    from gi.repository import GObject as gobject
 
82
    import gobject as GObject
83
83
import avahi
84
84
from dbus.mainloop.glib import DBusGMainLoop
85
85
import ctypes
715
715
    checker:    subprocess.Popen(); a running checker process used
716
716
                                    to see if the client lives.
717
717
                                    'None' if no process is running.
718
 
    checker_callback_tag: a gobject event source tag, or None
 
718
    checker_callback_tag: a GObject event source tag, or None
719
719
    checker_command: string; External command which is run to check
720
720
                     if client lives.  %() expansions are done at
721
721
                     runtime with vars(self) as dict, so that for
722
722
                     instance %(name)s can be used in the command.
723
 
    checker_initiator_tag: a gobject event source tag, or None
 
723
    checker_initiator_tag: a GObject event source tag, or None
724
724
    created:    datetime.datetime(); (UTC) object creation
725
725
    client_structure: Object describing what attributes a client has
726
726
                      and is used for storing the client at exit
727
727
    current_checker_command: string; current running checker_command
728
 
    disable_initiator_tag: a gobject event source tag, or None
 
728
    disable_initiator_tag: a GObject event source tag, or None
729
729
    enabled:    bool()
730
730
    fingerprint: string (40 or 32 hexadecimal digits); used to
731
731
                 uniquely identify the client
885
885
        if not quiet:
886
886
            logger.info("Disabling client %s", self.name)
887
887
        if getattr(self, "disable_initiator_tag", None) is not None:
888
 
            gobject.source_remove(self.disable_initiator_tag)
 
888
            GObject.source_remove(self.disable_initiator_tag)
889
889
            self.disable_initiator_tag = None
890
890
        self.expires = None
891
891
        if getattr(self, "checker_initiator_tag", None) is not None:
892
 
            gobject.source_remove(self.checker_initiator_tag)
 
892
            GObject.source_remove(self.checker_initiator_tag)
893
893
            self.checker_initiator_tag = None
894
894
        self.stop_checker()
895
895
        self.enabled = False
896
896
        if not quiet:
897
897
            self.send_changedstate()
898
 
        # Do not run this again if called by a gobject.timeout_add
 
898
        # Do not run this again if called by a GObject.timeout_add
899
899
        return False
900
900
    
901
901
    def __del__(self):
905
905
        # Schedule a new checker to be started an 'interval' from now,
906
906
        # and every interval from then on.
907
907
        if self.checker_initiator_tag is not None:
908
 
            gobject.source_remove(self.checker_initiator_tag)
909
 
        self.checker_initiator_tag = gobject.timeout_add(
 
908
            GObject.source_remove(self.checker_initiator_tag)
 
909
        self.checker_initiator_tag = GObject.timeout_add(
910
910
            int(self.interval.total_seconds() * 1000),
911
911
            self.start_checker)
912
912
        # Schedule a disable() when 'timeout' has passed
913
913
        if self.disable_initiator_tag is not None:
914
 
            gobject.source_remove(self.disable_initiator_tag)
915
 
        self.disable_initiator_tag = gobject.timeout_add(
 
914
            GObject.source_remove(self.disable_initiator_tag)
 
915
        self.disable_initiator_tag = GObject.timeout_add(
916
916
            int(self.timeout.total_seconds() * 1000), self.disable)
917
917
        # Also start a new checker *right now*.
918
918
        self.start_checker()
954
954
        if timeout is None:
955
955
            timeout = self.timeout
956
956
        if self.disable_initiator_tag is not None:
957
 
            gobject.source_remove(self.disable_initiator_tag)
 
957
            GObject.source_remove(self.disable_initiator_tag)
958
958
            self.disable_initiator_tag = None
959
959
        if getattr(self, "enabled", False):
960
 
            self.disable_initiator_tag = gobject.timeout_add(
 
960
            self.disable_initiator_tag = GObject.timeout_add(
961
961
                int(timeout.total_seconds() * 1000), self.disable)
962
962
            self.expires = datetime.datetime.utcnow() + timeout
963
963
    
1018
1018
                args = (pipe[1], subprocess.call, command),
1019
1019
                kwargs = popen_args)
1020
1020
            self.checker.start()
1021
 
            self.checker_callback_tag = gobject.io_add_watch(
1022
 
                pipe[0].fileno(), gobject.IO_IN,
 
1021
            self.checker_callback_tag = GObject.io_add_watch(
 
1022
                pipe[0].fileno(), GObject.IO_IN,
1023
1023
                self.checker_callback, pipe[0], command)
1024
 
        # Re-run this periodically if run by gobject.timeout_add
 
1024
        # Re-run this periodically if run by GObject.timeout_add
1025
1025
        return True
1026
1026
    
1027
1027
    def stop_checker(self):
1028
1028
        """Force the checker process, if any, to stop."""
1029
1029
        if self.checker_callback_tag:
1030
 
            gobject.source_remove(self.checker_callback_tag)
 
1030
            GObject.source_remove(self.checker_callback_tag)
1031
1031
            self.checker_callback_tag = None
1032
1032
        if getattr(self, "checker", None) is None:
1033
1033
            return
1807
1807
    
1808
1808
    def approve(self, value=True):
1809
1809
        self.approved = value
1810
 
        gobject.timeout_add(int(self.approval_duration.total_seconds()
 
1810
        GObject.timeout_add(int(self.approval_duration.total_seconds()
1811
1811
                                * 1000), self._reset_approved)
1812
1812
        self.send_changedstate()
1813
1813
    
2024
2024
                if (getattr(self, "disable_initiator_tag", None)
2025
2025
                    is None):
2026
2026
                    return
2027
 
                gobject.source_remove(self.disable_initiator_tag)
2028
 
                self.disable_initiator_tag = gobject.timeout_add(
 
2027
                GObject.source_remove(self.disable_initiator_tag)
 
2028
                self.disable_initiator_tag = GObject.timeout_add(
2029
2029
                    int((self.expires - now).total_seconds() * 1000),
2030
2030
                    self.disable)
2031
2031
    
2051
2051
            return
2052
2052
        if self.enabled:
2053
2053
            # Reschedule checker run
2054
 
            gobject.source_remove(self.checker_initiator_tag)
2055
 
            self.checker_initiator_tag = gobject.timeout_add(
 
2054
            GObject.source_remove(self.checker_initiator_tag)
 
2055
            self.checker_initiator_tag = GObject.timeout_add(
2056
2056
                value, self.start_checker)
2057
2057
            self.start_checker() # Start one now, too
2058
2058
    
2462
2462
        gnutls_priority GnuTLS priority string
2463
2463
        use_dbus:       Boolean; to emit D-Bus signals or not
2464
2464
    
2465
 
    Assumes a gobject.MainLoop event loop.
 
2465
    Assumes a GObject.MainLoop event loop.
2466
2466
    """
2467
2467
    
2468
2468
    def __init__(self, server_address, RequestHandlerClass,
2493
2493
    
2494
2494
    def add_pipe(self, parent_pipe, proc):
2495
2495
        # Call "handle_ipc" for both data and EOF events
2496
 
        gobject.io_add_watch(
 
2496
        GObject.io_add_watch(
2497
2497
            parent_pipe.fileno(),
2498
 
            gobject.IO_IN | gobject.IO_HUP,
 
2498
            GObject.IO_IN | GObject.IO_HUP,
2499
2499
            functools.partial(self.handle_ipc,
2500
2500
                              parent_pipe = parent_pipe,
2501
2501
                              proc = proc))
2505
2505
                   proc = None,
2506
2506
                   client_object=None):
2507
2507
        # error, or the other end of multiprocessing.Pipe has closed
2508
 
        if condition & (gobject.IO_ERR | gobject.IO_HUP):
 
2508
        if condition & (GObject.IO_ERR | GObject.IO_HUP):
2509
2509
            # Wait for other process to exit
2510
2510
            proc.join()
2511
2511
            return False
2532
2532
                parent_pipe.send(False)
2533
2533
                return False
2534
2534
            
2535
 
            gobject.io_add_watch(
 
2535
            GObject.io_add_watch(
2536
2536
                parent_pipe.fileno(),
2537
 
                gobject.IO_IN | gobject.IO_HUP,
 
2537
                GObject.IO_IN | GObject.IO_HUP,
2538
2538
                functools.partial(self.handle_ipc,
2539
2539
                                  parent_pipe = parent_pipe,
2540
2540
                                  proc = proc,
2965
2965
        # Close all input and output, do double fork, etc.
2966
2966
        daemon()
2967
2967
    
2968
 
    # multiprocessing will use threads, so before we use gobject we
2969
 
    # need to inform gobject that threads will be used.
2970
 
    gobject.threads_init()
 
2968
    # multiprocessing will use threads, so before we use GObject we
 
2969
    # need to inform GObject that threads will be used.
 
2970
    GObject.threads_init()
2971
2971
    
2972
2972
    global main_loop
2973
2973
    # From the Avahi example code
2974
2974
    DBusGMainLoop(set_as_default=True)
2975
 
    main_loop = gobject.MainLoop()
 
2975
    main_loop = GObject.MainLoop()
2976
2976
    bus = dbus.SystemBus()
2977
2977
    # End of Avahi example code
2978
2978
    if use_dbus:
3347
3347
                sys.exit(1)
3348
3348
            # End of Avahi example code
3349
3349
        
3350
 
        gobject.io_add_watch(tcp_server.fileno(), gobject.IO_IN,
 
3350
        GObject.io_add_watch(tcp_server.fileno(), GObject.IO_IN,
3351
3351
                             lambda *args, **kwargs:
3352
3352
                             (tcp_server.handle_request
3353
3353
                              (*args[2:], **kwargs) or True))