/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: 2019-08-05 14:31:51 UTC
  • Revision ID: teddy@recompile.se-20190805143151-lt5d97wqif3t8250
Client: Debian package fix: Make uninstall when using dracut(8) work

Use the same logic to rebuild the initramfs image when uninstalling as
when installing the package.

* debian/mandos-client.postrm (update_initramfs): Use the same logic
  as the update_initramfs function in debian/mandos-client.postinst.

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
 
81
81
import dbus
82
82
import dbus.service
 
83
import gi
83
84
from gi.repository import GLib
84
85
from dbus.mainloop.glib import DBusGMainLoop
85
86
import ctypes
115
116
if sys.version_info.major == 2:
116
117
    str = unicode
117
118
 
118
 
version = "1.8.4"
 
119
if sys.version_info < (3, 2):
 
120
    configparser.Configparser = configparser.SafeConfigParser
 
121
 
 
122
version = "1.8.6"
119
123
stored_state_file = "clients.pickle"
120
124
 
121
125
logger = logging.getLogger()
586
590
        def __init__(self, socket, credentials=None):
587
591
            self._c_object = gnutls.session_t()
588
592
            gnutls_flags = gnutls.CLIENT
589
 
            if gnutls.check_version("3.5.6"):
 
593
            if gnutls.check_version(b"3.5.6"):
590
594
                gnutls_flags |= gnutls.NO_TICKETS
591
595
            if gnutls.has_rawpk:
592
596
                gnutls_flags |= gnutls.ENABLE_RAWPK
794
798
                                                    ctypes.c_size_t)]
795
799
        openpgp_crt_get_fingerprint.restype = _error_code
796
800
 
797
 
    if check_version("3.6.4"):
 
801
    if check_version(b"3.6.4"):
798
802
        certificate_type_get2 = _library.gnutls_certificate_type_get2
799
803
        certificate_type_get2.argtypes = [session_t, ctypes.c_int]
800
804
        certificate_type_get2.restype = _error_code
821
825
    approved:   bool(); 'None' if not yet approved/disapproved
822
826
    approval_delay: datetime.timedelta(); Time to wait for approval
823
827
    approval_duration: datetime.timedelta(); Duration of one approval
824
 
    checker:    subprocess.Popen(); a running checker process used
825
 
                                    to see if the client lives.
826
 
                                    'None' if no process is running.
 
828
    checker: multiprocessing.Process(); a running checker process used
 
829
             to see if the client lives. 'None' if no process is
 
830
             running.
827
831
    checker_callback_tag: a GLib event source tag, or None
828
832
    checker_command: string; External command which is run to check
829
833
                     if client lives.  %() expansions are done at
1036
1040
    def checker_callback(self, source, condition, connection,
1037
1041
                         command):
1038
1042
        """The checker has completed, so take appropriate actions."""
1039
 
        self.checker_callback_tag = None
1040
 
        self.checker = None
1041
1043
        # Read return code from connection (see call_pipe)
1042
1044
        returncode = connection.recv()
1043
1045
        connection.close()
 
1046
        self.checker.join()
 
1047
        self.checker_callback_tag = None
 
1048
        self.checker = None
1044
1049
 
1045
1050
        if returncode >= 0:
1046
1051
            self.last_checker_status = returncode
2287
2292
            approval_required = False
2288
2293
            try:
2289
2294
                if gnutls.has_rawpk:
2290
 
                    fpr = ""
 
2295
                    fpr = b""
2291
2296
                    try:
2292
2297
                        key_id = self.key_id(
2293
2298
                            self.peer_certificate(session))
2297
2302
                    logger.debug("Key ID: %s", key_id)
2298
2303
 
2299
2304
                else:
2300
 
                    key_id = ""
 
2305
                    key_id = b""
2301
2306
                    try:
2302
2307
                        fpr = self.fingerprint(
2303
2308
                            self.peer_certificate(session))
2605
2610
                    raise
2606
2611
        # Only bind(2) the socket if we really need to.
2607
2612
        if self.server_address[0] or self.server_address[1]:
 
2613
            if self.server_address[1]:
 
2614
                self.allow_reuse_address = True
2608
2615
            if not self.server_address[0]:
2609
2616
                if self.address_family == socket.AF_INET6:
2610
2617
                    any_address = "::"  # in6addr_any
2995
3002
    del priority
2996
3003
 
2997
3004
    # Parse config file for server-global settings
2998
 
    server_config = configparser.SafeConfigParser(server_defaults)
 
3005
    server_config = configparser.ConfigParser(server_defaults)
2999
3006
    del server_defaults
3000
3007
    server_config.read(os.path.join(options.configdir, "mandos.conf"))
3001
 
    # Convert the SafeConfigParser object to a dict
 
3008
    # Convert the ConfigParser object to a dict
3002
3009
    server_settings = server_config.defaults()
3003
3010
    # Use the appropriate methods on the non-string config options
3004
3011
    for option in ("debug", "use_dbus", "use_ipv6", "restore",
3076
3083
                                  server_settings["servicename"])))
3077
3084
 
3078
3085
    # Parse config file with clients
3079
 
    client_config = configparser.SafeConfigParser(Client
3080
 
                                                  .client_defaults)
 
3086
    client_config = configparser.ConfigParser(Client.client_defaults)
3081
3087
    client_config.read(os.path.join(server_settings["configdir"],
3082
3088
                                    "clients.conf"))
3083
3089
 
3154
3160
        # Close all input and output, do double fork, etc.
3155
3161
        daemon()
3156
3162
 
3157
 
    # multiprocessing will use threads, so before we use GLib we need
3158
 
    # to inform GLib that threads will be used.
3159
 
    GLib.threads_init()
 
3163
    if gi.version_info < (3, 10, 2):
 
3164
        # multiprocessing will use threads, so before we use GLib we
 
3165
        # need to inform GLib that threads will be used.
 
3166
        GLib.threads_init()
3160
3167
 
3161
3168
    global main_loop
3162
3169
    # From the Avahi example code
3242
3249
                        for k in ("name", "host"):
3243
3250
                            if isinstance(value[k], bytes):
3244
3251
                                value[k] = value[k].decode("utf-8")
3245
 
                        if not value.has_key("key_id"):
 
3252
                        if "key_id" not in value:
3246
3253
                            value["key_id"] = ""
3247
 
                        elif not value.has_key("fingerprint"):
 
3254
                        elif "fingerprint" not in value:
3248
3255
                            value["fingerprint"] = ""
3249
3256
                    #  old_client_settings
3250
3257
                    # .keys()