/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 at recompile
  • Date: 2020-02-07 20:53:34 UTC
  • Revision ID: teddy@recompile.se-20200207205334-dp41p8c8vw0ytik5
Allow users to more easily alter mandos.service

The sysvinit script uses /etc/default/mandos as an environment file,
and supports adding additional server options to a DAEMON_ARGS
environment variable.  This should be supported by the systemd
service, too.

* mandos.service ([Service]/EnvironmentFile): New; set to
  "/etc/default/mandos ".
  ([Service]/ExecStart): Append "$DAEMON_ARGS".

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
# "AvahiService" class, and some lines in "main".
12
12
#
13
13
# Everything else is
14
 
# Copyright © 2008-2020 Teddy Hogeborn
15
 
# Copyright © 2008-2020 Björn Påhlsson
 
14
# Copyright © 2008-2019 Teddy Hogeborn
 
15
# Copyright © 2008-2019 Björn Påhlsson
16
16
#
17
17
# This file is part of Mandos.
18
18
#
79
79
import codecs
80
80
import unittest
81
81
import random
82
 
import shlex
83
82
 
84
83
import dbus
85
84
import dbus.service
104
103
    collections.abc = abc
105
104
    del abc
106
105
 
107
 
# Add shlex.quote if it does not exist
108
 
try:
109
 
    shlex.quote
110
 
except AttributeError:
111
 
    shlex.quote = re.escape
112
 
 
113
106
# Show warnings by default
114
107
if not sys.warnoptions:
115
108
    import warnings
143
136
if sys.version_info < (3, 2):
144
137
    configparser.Configparser = configparser.SafeConfigParser
145
138
 
146
 
version = "1.8.14"
 
139
version = "1.8.9"
147
140
stored_state_file = "clients.pickle"
148
141
 
149
142
logger = logging.getLogger()
524
517
class AvahiServiceToSyslog(AvahiService):
525
518
    def rename(self, *args, **kwargs):
526
519
        """Add the new name to the syslog messages"""
527
 
        ret = super(AvahiServiceToSyslog, self).rename(*args,
528
 
                                                       **kwargs)
 
520
        ret = super(AvahiServiceToSyslog, self).rename(*args, **kwargs)
529
521
        syslogger.setFormatter(logging.Formatter(
530
522
            'Mandos ({}) [%(process)d]: %(levelname)s: %(message)s'
531
523
            .format(self.name)))
775
767
 
776
768
        x509_crt_fmt_t = ctypes.c_int
777
769
 
778
 
        # All the function declarations below are from
779
 
        # gnutls/abstract.h
 
770
        # All the function declarations below are from gnutls/abstract.h
780
771
        pubkey_init = _library.gnutls_pubkey_init
781
772
        pubkey_init.argtypes = [ctypes.POINTER(pubkey_t)]
782
773
        pubkey_init.restype = _error_code
796
787
        pubkey_deinit.argtypes = [pubkey_t]
797
788
        pubkey_deinit.restype = None
798
789
    else:
799
 
        # All the function declarations below are from
800
 
        # gnutls/openpgp.h
 
790
        # All the function declarations below are from gnutls/openpgp.h
801
791
 
802
792
        openpgp_crt_init = _library.gnutls_openpgp_crt_init
803
793
        openpgp_crt_init.argtypes = [ctypes.POINTER(openpgp_crt_t)]
809
799
                                       openpgp_crt_fmt_t]
810
800
        openpgp_crt_import.restype = _error_code
811
801
 
812
 
        openpgp_crt_verify_self = \
813
 
            _library.gnutls_openpgp_crt_verify_self
814
 
        openpgp_crt_verify_self.argtypes = [
815
 
            openpgp_crt_t,
816
 
            ctypes.c_uint,
817
 
            ctypes.POINTER(ctypes.c_uint),
818
 
        ]
 
802
        openpgp_crt_verify_self = _library.gnutls_openpgp_crt_verify_self
 
803
        openpgp_crt_verify_self.argtypes = [openpgp_crt_t, ctypes.c_uint,
 
804
                                            ctypes.POINTER(ctypes.c_uint)]
819
805
        openpgp_crt_verify_self.restype = _error_code
820
806
 
821
807
        openpgp_crt_deinit = _library.gnutls_openpgp_crt_deinit
1141
1127
        if self.checker is None:
1142
1128
            # Escape attributes for the shell
1143
1129
            escaped_attrs = {
1144
 
                attr: shlex.quote(str(getattr(self, attr)))
 
1130
                attr: re.escape(str(getattr(self, attr)))
1145
1131
                for attr in self.runtime_expansions}
1146
1132
            try:
1147
1133
                command = self.checker_command % escaped_attrs
2475
2461
        buf = ctypes.create_string_buffer(32)
2476
2462
        buf_len = ctypes.c_size_t(len(buf))
2477
2463
        # Get the key ID from the raw public key into the buffer
2478
 
        gnutls.pubkey_get_key_id(
2479
 
            pubkey,
2480
 
            gnutls.KEYID_USE_SHA256,
2481
 
            ctypes.cast(ctypes.byref(buf),
2482
 
                        ctypes.POINTER(ctypes.c_ubyte)),
2483
 
            ctypes.byref(buf_len))
 
2464
        gnutls.pubkey_get_key_id(pubkey,
 
2465
                                 gnutls.KEYID_USE_SHA256,
 
2466
                                 ctypes.cast(ctypes.byref(buf),
 
2467
                                             ctypes.POINTER(ctypes.c_ubyte)),
 
2468
                                 ctypes.byref(buf_len))
2484
2469
        # Deinit the certificate
2485
2470
        gnutls.pubkey_deinit(pubkey)
2486
2471
 
2731
2716
            address = request[3]
2732
2717
 
2733
2718
            for c in self.clients.values():
2734
 
                if key_id == ("E3B0C44298FC1C149AFBF4C8996FB924"
2735
 
                              "27AE41E4649B934CA495991B7852B855"):
 
2719
                if key_id == "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855":
2736
2720
                    continue
2737
2721
                if key_id and c.key_id == key_id:
2738
2722
                    client = c
2790
2774
def rfc3339_duration_to_delta(duration):
2791
2775
    """Parse an RFC 3339 "duration" and return a datetime.timedelta
2792
2776
 
2793
 
    >>> timedelta = datetime.timedelta
2794
 
    >>> rfc3339_duration_to_delta("P7D") == timedelta(7)
2795
 
    True
2796
 
    >>> rfc3339_duration_to_delta("PT60S") == timedelta(0, 60)
2797
 
    True
2798
 
    >>> rfc3339_duration_to_delta("PT60M") == timedelta(0, 3600)
2799
 
    True
2800
 
    >>> rfc3339_duration_to_delta("PT24H") == timedelta(1)
2801
 
    True
2802
 
    >>> rfc3339_duration_to_delta("P1W") == timedelta(7)
2803
 
    True
2804
 
    >>> rfc3339_duration_to_delta("PT5M30S") == timedelta(0, 330)
2805
 
    True
2806
 
    >>> rfc3339_duration_to_delta("P1DT3M20S") == timedelta(1, 200)
2807
 
    True
2808
 
    >>> del timedelta
 
2777
    >>> rfc3339_duration_to_delta("P7D") == datetime.timedelta(7)
 
2778
    True
 
2779
    >>> rfc3339_duration_to_delta("PT60S") == datetime.timedelta(0, 60)
 
2780
    True
 
2781
    >>> rfc3339_duration_to_delta("PT60M") == datetime.timedelta(0, 3600)
 
2782
    True
 
2783
    >>> rfc3339_duration_to_delta("PT24H") == datetime.timedelta(1)
 
2784
    True
 
2785
    >>> rfc3339_duration_to_delta("P1W") == datetime.timedelta(7)
 
2786
    True
 
2787
    >>> rfc3339_duration_to_delta("PT5M30S") == datetime.timedelta(0, 330)
 
2788
    True
 
2789
    >>> rfc3339_duration_to_delta("P1DT3M20S") == datetime.timedelta(1, 200)
 
2790
    True
2809
2791
    """
2810
2792
 
2811
2793
    # Parsing an RFC 3339 duration with regular expressions is not