/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-09 03:38:33 UTC
  • Revision ID: teddy@recompile.se-20200209033833-2la1pujrnv2m0so4
Use reallocarray() if available, or check for overflow

* dracut-module/password-agent.c (add_to_queue): Check for overflow.
  (test_add_to_queue_overflow): New test.
* plugin-runner.c (add_to_char_array, main): Use reallocarray().
* plugins.d/plymouth.c (exec_and_wait): - '' -

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
#
143
143
if sys.version_info < (3, 2):
144
144
    configparser.Configparser = configparser.SafeConfigParser
145
145
 
146
 
version = "1.8.14"
 
146
version = "1.8.9"
147
147
stored_state_file = "clients.pickle"
148
148
 
149
149
logger = logging.getLogger()
524
524
class AvahiServiceToSyslog(AvahiService):
525
525
    def rename(self, *args, **kwargs):
526
526
        """Add the new name to the syslog messages"""
527
 
        ret = super(AvahiServiceToSyslog, self).rename(*args,
528
 
                                                       **kwargs)
 
527
        ret = super(AvahiServiceToSyslog, self).rename(*args, **kwargs)
529
528
        syslogger.setFormatter(logging.Formatter(
530
529
            'Mandos ({}) [%(process)d]: %(levelname)s: %(message)s'
531
530
            .format(self.name)))
661
660
            raise gnutls.CertificateSecurityError(code=result)
662
661
        raise gnutls.Error(code=result)
663
662
 
664
 
    def _retry_on_error(result, func, arguments,
665
 
                        _error_code=_error_code):
 
663
    def _retry_on_error(result, func, arguments):
666
664
        """A function to retry on some errors, suitable
667
665
        for the 'errcheck' attribute on ctypes functions"""
668
666
        while result < 0:
776
774
 
777
775
        x509_crt_fmt_t = ctypes.c_int
778
776
 
779
 
        # All the function declarations below are from
780
 
        # gnutls/abstract.h
 
777
        # All the function declarations below are from gnutls/abstract.h
781
778
        pubkey_init = _library.gnutls_pubkey_init
782
779
        pubkey_init.argtypes = [ctypes.POINTER(pubkey_t)]
783
780
        pubkey_init.restype = _error_code
797
794
        pubkey_deinit.argtypes = [pubkey_t]
798
795
        pubkey_deinit.restype = None
799
796
    else:
800
 
        # All the function declarations below are from
801
 
        # gnutls/openpgp.h
 
797
        # All the function declarations below are from gnutls/openpgp.h
802
798
 
803
799
        openpgp_crt_init = _library.gnutls_openpgp_crt_init
804
800
        openpgp_crt_init.argtypes = [ctypes.POINTER(openpgp_crt_t)]
810
806
                                       openpgp_crt_fmt_t]
811
807
        openpgp_crt_import.restype = _error_code
812
808
 
813
 
        openpgp_crt_verify_self = \
814
 
            _library.gnutls_openpgp_crt_verify_self
815
 
        openpgp_crt_verify_self.argtypes = [
816
 
            openpgp_crt_t,
817
 
            ctypes.c_uint,
818
 
            ctypes.POINTER(ctypes.c_uint),
819
 
        ]
 
809
        openpgp_crt_verify_self = _library.gnutls_openpgp_crt_verify_self
 
810
        openpgp_crt_verify_self.argtypes = [openpgp_crt_t, ctypes.c_uint,
 
811
                                            ctypes.POINTER(ctypes.c_uint)]
820
812
        openpgp_crt_verify_self.restype = _error_code
821
813
 
822
814
        openpgp_crt_deinit = _library.gnutls_openpgp_crt_deinit
2476
2468
        buf = ctypes.create_string_buffer(32)
2477
2469
        buf_len = ctypes.c_size_t(len(buf))
2478
2470
        # Get the key ID from the raw public key into the buffer
2479
 
        gnutls.pubkey_get_key_id(
2480
 
            pubkey,
2481
 
            gnutls.KEYID_USE_SHA256,
2482
 
            ctypes.cast(ctypes.byref(buf),
2483
 
                        ctypes.POINTER(ctypes.c_ubyte)),
2484
 
            ctypes.byref(buf_len))
 
2471
        gnutls.pubkey_get_key_id(pubkey,
 
2472
                                 gnutls.KEYID_USE_SHA256,
 
2473
                                 ctypes.cast(ctypes.byref(buf),
 
2474
                                             ctypes.POINTER(ctypes.c_ubyte)),
 
2475
                                 ctypes.byref(buf_len))
2485
2476
        # Deinit the certificate
2486
2477
        gnutls.pubkey_deinit(pubkey)
2487
2478
 
2732
2723
            address = request[3]
2733
2724
 
2734
2725
            for c in self.clients.values():
2735
 
                if key_id == ("E3B0C44298FC1C149AFBF4C8996FB924"
2736
 
                              "27AE41E4649B934CA495991B7852B855"):
 
2726
                if key_id == "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855":
2737
2727
                    continue
2738
2728
                if key_id and c.key_id == key_id:
2739
2729
                    client = c
2791
2781
def rfc3339_duration_to_delta(duration):
2792
2782
    """Parse an RFC 3339 "duration" and return a datetime.timedelta
2793
2783
 
2794
 
    >>> timedelta = datetime.timedelta
2795
 
    >>> rfc3339_duration_to_delta("P7D") == timedelta(7)
2796
 
    True
2797
 
    >>> rfc3339_duration_to_delta("PT60S") == timedelta(0, 60)
2798
 
    True
2799
 
    >>> rfc3339_duration_to_delta("PT60M") == timedelta(0, 3600)
2800
 
    True
2801
 
    >>> rfc3339_duration_to_delta("PT24H") == timedelta(1)
2802
 
    True
2803
 
    >>> rfc3339_duration_to_delta("P1W") == timedelta(7)
2804
 
    True
2805
 
    >>> rfc3339_duration_to_delta("PT5M30S") == timedelta(0, 330)
2806
 
    True
2807
 
    >>> rfc3339_duration_to_delta("P1DT3M20S") == timedelta(1, 200)
2808
 
    True
2809
 
    >>> del timedelta
 
2784
    >>> rfc3339_duration_to_delta("P7D") == datetime.timedelta(7)
 
2785
    True
 
2786
    >>> rfc3339_duration_to_delta("PT60S") == datetime.timedelta(0, 60)
 
2787
    True
 
2788
    >>> rfc3339_duration_to_delta("PT60M") == datetime.timedelta(0, 3600)
 
2789
    True
 
2790
    >>> rfc3339_duration_to_delta("PT24H") == datetime.timedelta(1)
 
2791
    True
 
2792
    >>> rfc3339_duration_to_delta("P1W") == datetime.timedelta(7)
 
2793
    True
 
2794
    >>> rfc3339_duration_to_delta("PT5M30S") == datetime.timedelta(0, 330)
 
2795
    True
 
2796
    >>> rfc3339_duration_to_delta("P1DT3M20S") == datetime.timedelta(1, 200)
 
2797
    True
2810
2798
    """
2811
2799
 
2812
2800
    # Parsing an RFC 3339 duration with regular expressions is not