/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-ctl

  • Committer: Teddy Hogeborn
  • Date: 2019-02-10 03:50:20 UTC
  • mto: (237.7.594 trunk)
  • mto: This revision was merged to the branch mainline in revision 370.
  • Revision ID: teddy@recompile.se-20190210035020-nttr1tybgwwixueu
Show debconf note about new TLS key IDs

If mandos-client did not see TLS keys and had to create them, or if
mandos sees GnuTLS version 3.6.6 or later, show an important notice on
package installation about the importance of adding the new key_id
options to clients.conf on the Mandos server.

* debian/control (Package: mandos, Package: mandos-client): Depend on
                                                            debconf.
* debian/mandos-client.lintian-overrides: Override warnings.
* debian/mandos-client.postinst (create_keys): Show notice if new TLS
                                               key files were created.
* debian/mandos-client.templates: New.
* debian/mandos.lintian-overrides: Override warnings.
* debian/mandos.postinst (configure): If GnuTLS 3.6.6 or later is
                                      detected, show an important
                                      notice (once) about the new
                                      key_id option required in
                                      clients.conf.
* debian/mandos.templates: New.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
 
# -*- mode: python; coding: utf-8; after-save-hook: (lambda () (let ((command (if (and (boundp 'tramp-file-name-structure) (string-match (car tramp-file-name-structure) (buffer-file-name))) (tramp-file-name-localname (tramp-dissect-file-name (buffer-file-name))) (buffer-file-name)))) (if (= (shell-command (format "%s --check" (shell-quote-argument command)) "*Test*") 0) (let ((w (get-buffer-window "*Test*"))) (if w (delete-window w)) (kill-buffer "*Test*")) (display-buffer "*Test*")))); -*-
 
2
# -*- mode: python; coding: utf-8 -*-
3
3
#
4
4
# Mandos Monitor - Control and monitor the Mandos server
5
5
#
6
 
# Copyright © 2008-2019 Teddy Hogeborn
7
 
# Copyright © 2008-2019 Björn Påhlsson
 
6
# Copyright © 2008-2018 Teddy Hogeborn
 
7
# Copyright © 2008-2018 Björn Påhlsson
8
8
#
9
9
# This file is part of Mandos.
10
10
#
40
40
import os
41
41
import collections
42
42
import json
43
 
import unittest
44
 
import logging
45
43
 
46
44
import dbus
47
45
 
48
 
# Show warnings by default
49
 
if not sys.warnoptions:
50
 
    import warnings
51
 
    warnings.simplefilter("default")
52
 
 
53
 
log = logging.getLogger(sys.argv[0])
54
 
logging.basicConfig(level="INFO", # Show info level messages
55
 
                    format="%(message)s") # Show basic log messages
56
 
 
57
 
logging.captureWarnings(True)   # Show warnings via the logging system
58
 
 
59
46
if sys.version_info.major == 2:
60
47
    str = unicode
61
48
 
89
76
server_path = "/"
90
77
server_interface = domain + ".Mandos"
91
78
client_interface = domain + ".Mandos.Client"
92
 
version = "1.8.3"
 
79
version = "1.7.20"
93
80
 
94
81
 
95
82
try:
358
345
    if options.all and not has_actions(options):
359
346
        parser.error("--all requires an action.")
360
347
 
 
348
    if options.check:
 
349
        import doctest
 
350
        fail_count, test_count = doctest.testmod()
 
351
        sys.exit(os.EX_OK if fail_count == 0 else 1)
 
352
 
361
353
    try:
362
354
        bus = dbus.SystemBus()
363
355
        mandos_dbus_objc = bus.get_object(busname, server_path)
364
356
    except dbus.exceptions.DBusException:
365
 
        log.critical("Could not connect to Mandos server")
 
357
        print("Could not connect to Mandos server", file=sys.stderr)
366
358
        sys.exit(1)
367
359
 
368
360
    mandos_serv = dbus.Interface(mandos_dbus_objc,
387
379
            os.dup2(stderrcopy, sys.stderr.fileno())
388
380
            os.close(stderrcopy)
389
381
    except dbus.exceptions.DBusException as e:
390
 
        log.critical("Failed to access Mandos server through D-Bus:"
391
 
                     "\n%s", e)
 
382
        print("Access denied: "
 
383
              "Accessing mandos server through D-Bus: {}".format(e),
 
384
              file=sys.stderr)
392
385
        sys.exit(1)
393
386
 
394
387
    # Compile dict of (clients: properties) to process
405
398
                    clients[client_objc] = client
406
399
                    break
407
400
            else:
408
 
                log.critical("Client not found on server: %r", name)
 
401
                print("Client not found on server: {!r}"
 
402
                      .format(name), file=sys.stderr)
409
403
                sys.exit(1)
410
404
 
411
405
    if not has_actions(options) and clients:
499
493
                client.Approve(dbus.Boolean(False),
500
494
                               dbus_interface=client_interface)
501
495
 
502
 
 
503
 
class Test_milliseconds_to_string(unittest.TestCase):
504
 
    def test_all(self):
505
 
        self.assertEqual(milliseconds_to_string(93785000),
506
 
                         "1T02:03:05")
507
 
    def test_no_days(self):
508
 
        self.assertEqual(milliseconds_to_string(7385000), "02:03:05")
509
 
    def test_all_zero(self):
510
 
        self.assertEqual(milliseconds_to_string(0), "00:00:00")
511
 
    def test_no_fractional_seconds(self):
512
 
        self.assertEqual(milliseconds_to_string(400), "00:00:00")
513
 
        self.assertEqual(milliseconds_to_string(900), "00:00:00")
514
 
        self.assertEqual(milliseconds_to_string(1900), "00:00:01")
515
 
 
516
 
 
517
 
def should_only_run_tests():
518
 
    parser = argparse.ArgumentParser(add_help=False)
519
 
    parser.add_argument("--check", action='store_true')
520
 
    args, unknown_args = parser.parse_known_args()
521
 
    run_tests = args.check
522
 
    if run_tests:
523
 
        # Remove --check argument from sys.argv
524
 
        sys.argv[1:] = unknown_args
525
 
    return run_tests
526
 
 
527
 
# Add all tests from doctest strings
528
 
def load_tests(loader, tests, none):
529
 
    import doctest
530
 
    tests.addTests(doctest.DocTestSuite())
531
 
    return tests
532
496
 
533
497
if __name__ == "__main__":
534
 
    if should_only_run_tests():
535
 
        # Call using ./tdd-python-script --check [--verbose]
536
 
        unittest.main()
537
 
    else:
538
 
        main()
 
498
    main()