/mandos/release

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

« back to all changes in this revision

Viewing changes to mandos-monitor

  • Committer: Teddy Hogeborn
  • Date: 2014-07-15 23:52:00 UTC
  • mto: (237.7.272 trunk)
  • mto: This revision was merged to the branch mainline in revision 319.
  • Revision ID: teddy@recompile.se-20140715235200-4dukd7i2tvbcix61
mandos-client: Bug Fix: Fix some memory leaks.

* plugins.d/mandos-client.c (resolve_callback): Always free resolver.
  (run_network_hooks): Free the individual direntries.
  (main): When listing network interfaces and when removing the GPGME
          temp directory, free the individual direntries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
 
49
49
import locale
50
50
 
51
 
if sys.version_info.major == 2:
 
51
if sys.version_info[0] == 2:
52
52
    str = unicode
53
53
 
54
54
locale.setlocale(locale.LC_ALL, '')
60
60
domain = 'se.recompile'
61
61
server_interface = domain + '.Mandos'
62
62
client_interface = domain + '.Mandos.Client'
63
 
version = "1.6.7"
 
63
version = "1.6.6"
64
64
 
65
65
def isoformat_to_datetime(iso):
66
66
    "Parse an ISO 8601 date string to a datetime.datetime()"
161
161
                                         self.rejected,
162
162
                                         client_interface,
163
163
                                         byte_arrays=True))
164
 
        self.logger('Created client {}'
 
164
        self.logger('Created client {0}'
165
165
                    .format(self.properties["Name"]), level=0)
166
166
    
167
167
    def using_timer(self, flag):
179
179
    
180
180
    def checker_completed(self, exitstatus, condition, command):
181
181
        if exitstatus == 0:
182
 
            self.logger('Checker for client {} (command "{}")'
 
182
            self.logger('Checker for client {0} (command "{1}")'
183
183
                        ' succeeded'.format(self.properties["Name"],
184
184
                                            command), level=0)
185
185
            self.update()
186
186
            return
187
187
        # Checker failed
188
188
        if os.WIFEXITED(condition):
189
 
            self.logger('Checker for client {} (command "{}") failed'
190
 
                        ' with exit code {}'
 
189
            self.logger('Checker for client {0} (command "{1}")'
 
190
                        ' failed with exit code {2}'
191
191
                        .format(self.properties["Name"], command,
192
192
                                os.WEXITSTATUS(condition)))
193
193
        elif os.WIFSIGNALED(condition):
194
 
            self.logger('Checker for client {} (command "{}") was'
195
 
                        ' killed by signal {}'
 
194
            self.logger('Checker for client {0} (command "{1}") was'
 
195
                        ' killed by signal {2}'
196
196
                        .format(self.properties["Name"], command,
197
197
                                os.WTERMSIG(condition)))
198
198
        elif os.WCOREDUMP(condition):
199
 
            self.logger('Checker for client {} (command "{}") dumped'
200
 
                        ' core'.format(self.properties["Name"],
201
 
                                       command))
 
199
            self.logger('Checker for client {0} (command "{1}")'
 
200
                        ' dumped core'
 
201
                        .format(self.properties["Name"], command))
202
202
        else:
203
 
            self.logger('Checker for client {} completed'
 
203
            self.logger('Checker for client {0} completed'
204
204
                        ' mysteriously'
205
205
                        .format(self.properties["Name"]))
206
206
        self.update()
207
207
    
208
208
    def checker_started(self, command):
209
209
        """Server signals that a checker started."""
210
 
        self.logger('Client {} started checker "{}"'
 
210
        self.logger('Client {0} started checker "{1}"'
211
211
                    .format(self.properties["Name"],
212
212
                            command), level=0)
213
213
    
214
214
    def got_secret(self):
215
 
        self.logger('Client {} received its secret'
 
215
        self.logger('Client {0} received its secret'
216
216
                    .format(self.properties["Name"]))
217
217
    
218
218
    def need_approval(self, timeout, default):
219
219
        if not default:
220
 
            message = 'Client {} needs approval within {} seconds'
 
220
            message = 'Client {0} needs approval within {1} seconds'
221
221
        else:
222
 
            message = 'Client {} will get its secret in {} seconds'
 
222
            message = 'Client {0} will get its secret in {1} seconds'
223
223
        self.logger(message.format(self.properties["Name"],
224
224
                                   timeout/1000))
225
225
    
226
226
    def rejected(self, reason):
227
 
        self.logger('Client {} was rejected; reason: {}'
 
227
        self.logger('Client {0} was rejected; reason: {1}'
228
228
                    .format(self.properties["Name"], reason))
229
229
    
230
230
    def selectable(self):
274
274
            else:
275
275
                timer = datetime.timedelta()
276
276
            if self.properties["ApprovedByDefault"]:
277
 
                message = "Approval in {}. (d)eny?"
 
277
                message = "Approval in {0}. (d)eny?"
278
278
            else:
279
 
                message = "Denial in {}. (a)pprove?"
 
279
                message = "Denial in {0}. (a)pprove?"
280
280
            message = message.format(str(timer).rsplit(".", 1)[0])
281
281
            self.using_timer(True)
282
282
        elif self.properties["LastCheckerStatus"] != 0:
290
290
                timer = max(expires - datetime.datetime.utcnow(),
291
291
                            datetime.timedelta())
292
292
            message = ('A checker has failed! Time until client'
293
 
                       ' gets disabled: {}'
 
293
                       ' gets disabled: {0}'
294
294
                       .format(str(timer).rsplit(".", 1)[0]))
295
295
            self.using_timer(True)
296
296
        else:
297
297
            message = "enabled"
298
298
            self.using_timer(False)
299
 
        self._text = "{}{}".format(base, message)
 
299
        self._text = "{0}{1}".format(base, message)
300
300
        
301
301
        if not urwid.supports_unicode():
302
302
            self._text = self._text.encode("ascii", "replace")
469
469
        self.main_loop = gobject.MainLoop()
470
470
    
471
471
    def client_not_found(self, fingerprint, address):
472
 
        self.log_message("Client with address {} and fingerprint {}"
473
 
                         " could not be found"
 
472
        self.log_message("Client with address {0} and fingerprint"
 
473
                         " {1} could not be found"
474
474
                         .format(address, fingerprint))
475
475
    
476
476
    def rebuild(self):
494
494
        if level < self.log_level:
495
495
            return
496
496
        timestamp = datetime.datetime.now().isoformat()
497
 
        self.log_message_raw("{}: {}".format(timestamp, message),
 
497
        self.log_message_raw("{0}: {1}".format(timestamp, message),
498
498
                             level=level)
499
499
    
500
500
    def log_message_raw(self, markup, level=1):
513
513
        """Toggle visibility of the log buffer."""
514
514
        self.log_visible = not self.log_visible
515
515
        self.rebuild()
516
 
        self.log_message("Log visibility changed to: {}"
 
516
        self.log_message("Log visibility changed to: {0}"
517
517
                         .format(self.log_visible), level=0)
518
518
    
519
519
    def change_log_display(self):
525
525
            self.log_wrap = "clip"
526
526
        for textwidget in self.log:
527
527
            textwidget.set_wrap_mode(self.log_wrap)
528
 
        self.log_message("Wrap mode: {}".format(self.log_wrap),
 
528
        self.log_message("Wrap mode: {0}".format(self.log_wrap),
529
529
                         level=0)
530
530
    
531
531
    def find_and_remove_client(self, path, name):
537
537
            client = self.clients_dict[path]
538
538
        except KeyError:
539
539
            # not found?
540
 
            self.log_message("Unknown client {!r} ({!r}) removed"
 
540
            self.log_message("Unknown client {0!r} ({1!r}) removed"
541
541
                             .format(name, path))
542
542
            return
543
543
        client.delete()
661
661
            elif key == "window resize":
662
662
                self.size = self.screen.get_cols_rows()
663
663
                self.refresh()
664
 
            elif key == "ctrl l":
665
 
                self.screen.clear()
 
664
            elif key == "\f":  # Ctrl-L
666
665
                self.refresh()
667
666
            elif key == "l" or key == "D":
668
667
                self.toggle_log_display()