/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: 2023-02-11 06:58:15 UTC
  • Revision ID: teddy@recompile.se-20230211065815-jtffi61tbdrgr875
Suppress warnings

Suppress warnings about mlock()ing uninitialized memory and reading an
ievent struct.

* dracut-module/password-agent.c (send_password_to_socket): Suppress
  "-Wmaybe-uninitialized" when mlock()ing password send buffer.
  (test_read_inotify_event_IN_DELETE_badname): When reading from
    a struct ievent, suppress "-Wstringop-overread".

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-2022 Teddy Hogeborn
 
15
# Copyright © 2008-2022 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.16"
147
147
stored_state_file = "clients.pickle"
148
148
 
149
149
log = logging.getLogger(os.path.basename(sys.argv[0]))
1045
1045
        if getattr(self, "enabled", False):
1046
1046
            # Already enabled
1047
1047
            return
1048
 
        self.expires = datetime.datetime.utcnow() + self.timeout
1049
1048
        self.enabled = True
1050
1049
        self.last_enabled = datetime.datetime.utcnow()
1051
1050
        self.init_checker()
1074
1073
    def __del__(self):
1075
1074
        self.disable()
1076
1075
 
1077
 
    def init_checker(self):
1078
 
        # Schedule a new checker to be started an 'interval' from now,
1079
 
        # and every interval from then on.
 
1076
    def init_checker(self, randomize_start=False):
 
1077
        # Schedule a new checker to be started a randomly selected
 
1078
        # time (a fraction of 'interval') from now.  This spreads out
 
1079
        # the startup of checkers over time when the server is
 
1080
        # started.
1080
1081
        if self.checker_initiator_tag is not None:
1081
1082
            GLib.source_remove(self.checker_initiator_tag)
 
1083
        interval_milliseconds = int(self.interval.total_seconds()
 
1084
                                    * 1000)
 
1085
        if randomize_start:
 
1086
            delay_milliseconds = random.randrange(
 
1087
                interval_milliseconds + 1)
 
1088
        else:
 
1089
            delay_milliseconds = interval_milliseconds
1082
1090
        self.checker_initiator_tag = GLib.timeout_add(
1083
 
            random.randrange(int(self.interval.total_seconds() * 1000
1084
 
                                 + 1)),
1085
 
            self.start_checker)
1086
 
        # Schedule a disable() when 'timeout' has passed
 
1091
            delay_milliseconds, self.start_checker, randomize_start)
 
1092
        delay = datetime.timedelta(0, 0, 0, delay_milliseconds)
 
1093
        # A checker might take up to an 'interval' of time, so we can
 
1094
        # expire at the soonest one interval after a checker was
 
1095
        # started.  Since the initial checker is delayed, the expire
 
1096
        # time might have to be extended.
 
1097
        now = datetime.datetime.utcnow()
 
1098
        self.expires = now + delay + self.interval
 
1099
        # Schedule a disable() at expire time
1087
1100
        if self.disable_initiator_tag is not None:
1088
1101
            GLib.source_remove(self.disable_initiator_tag)
1089
1102
        self.disable_initiator_tag = GLib.timeout_add(
1090
 
            int(self.timeout.total_seconds() * 1000), self.disable)
1091
 
        # Also start a new checker *right now*.
1092
 
        self.start_checker()
 
1103
            int((self.expires - now).total_seconds() * 1000),
 
1104
            self.disable)
1093
1105
 
1094
1106
    def checker_callback(self, source, condition, connection,
1095
1107
                         command):
1138
1150
    def need_approval(self):
1139
1151
        self.last_approval_request = datetime.datetime.utcnow()
1140
1152
 
1141
 
    def start_checker(self):
 
1153
    def start_checker(self, start_was_randomized=False):
1142
1154
        """Start a new checker subprocess if one is not running.
1143
1155
 
1144
1156
        If a checker already exists, leave it running and do
1194
1206
                GLib.IOChannel.unix_new(pipe[0].fileno()),
1195
1207
                GLib.PRIORITY_DEFAULT, GLib.IO_IN,
1196
1208
                self.checker_callback, pipe[0], command)
 
1209
        if start_was_randomized:
 
1210
            # We were started after a random delay; Schedule a new
 
1211
            # checker to be started an 'interval' from now, and every
 
1212
            # interval from then on.
 
1213
            now = datetime.datetime.utcnow()
 
1214
            self.checker_initiator_tag = GLib.timeout_add(
 
1215
                int(self.interval.total_seconds() * 1000),
 
1216
                self.start_checker)
 
1217
            self.expires = max(self.expires, now + self.interval)
 
1218
            # Don't start a new checker again after same random delay
 
1219
            return False
1197
1220
        # Re-run this periodically if run by GLib.timeout_add
1198
1221
        return True
1199
1222
 
3609
3632
            mandos_dbus_service.client_added_signal(client)
3610
3633
        # Need to initiate checking of clients
3611
3634
        if client.enabled:
3612
 
            client.init_checker()
 
3635
            client.init_checker(randomize_start=True)
3613
3636
 
3614
3637
    tcp_server.enable()
3615
3638
    tcp_server.server_activate()
3710
3733
#           default-directory dir)
3711
3734
#     (erase-buffer)
3712
3735
#     (compilation-mode))
3713
 
#   (let ((inhibit-read-only t))
3714
 
#     (= (process-file-shell-command
3715
 
#         (funcall get-command-line extra)
3716
 
#         nil "*Test*") 0)))
 
3736
#   (let ((process-result
 
3737
#          (let ((inhibit-read-only t))
 
3738
#            (process-file-shell-command
 
3739
#             (funcall get-command-line extra) nil "*Test*"))))
 
3740
#     (and (numberp process-result)
 
3741
#          (= process-result 0))))
3717
3742
# get-command-line:
3718
3743
# (lambda (&optional extra)
3719
3744
#   (let ((quoted-script