/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: 2019-08-18 00:42:22 UTC
  • Revision ID: teddy@recompile.se-20190818004222-lfrgtnmqz766a08e
Client: Use the systemd sysusers.d mechanism, if present

* Makefile (install-client-nokey): Also install sysusers.d file, if
                                   $(SYSUSERS) exists.
* sysusers.d-mandos.conf: Adjust comment to match reality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
 
# -*- mode: python; after-save-hook: (lambda () (let ((command (if (fboundp 'file-local-name) (file-local-name (buffer-file-name)) (or (file-remote-p (buffer-file-name) 'localname) (buffer-file-name))))) (if (= (progn (if (get-buffer "*Test*") (kill-buffer "*Test*")) (process-file-shell-command (format "%s --check" (shell-quote-argument command)) nil "*Test*")) 0) (let ((w (get-buffer-window "*Test*"))) (if w (delete-window w))) (progn (with-current-buffer "*Test*" (compilation-mode)) (display-buffer "*Test*" '(display-buffer-in-side-window)))))); coding: utf-8 -*-
 
2
# -*- mode: python; coding: utf-8 -*-
3
3
#
4
4
# Mandos server - give out binary blobs to connecting clients.
5
5
#
77
77
import itertools
78
78
import collections
79
79
import codecs
80
 
import unittest
81
80
 
82
81
import dbus
83
82
import dbus.service
92
91
if sys.version_info.major == 2:
93
92
    __metaclass__ = type
94
93
 
95
 
# Show warnings by default
96
 
if not sys.warnoptions:
97
 
    import warnings
98
 
    warnings.simplefilter("default")
99
 
 
100
94
# Try to find the value of SO_BINDTODEVICE:
101
95
try:
102
96
    # This is where SO_BINDTODEVICE is in Python 3.3 (or 3.4?) and
128
122
if sys.version_info < (3, 2):
129
123
    configparser.Configparser = configparser.SafeConfigParser
130
124
 
131
 
version = "1.8.8"
 
125
version = "1.8.7"
132
126
stored_state_file = "clients.pickle"
133
127
 
134
128
logger = logging.getLogger()
135
 
logging.captureWarnings(True)   # Show warnings via the logging system
136
129
syslogger = None
137
130
 
138
131
try:
1150
1143
                kwargs=popen_args)
1151
1144
            self.checker.start()
1152
1145
            self.checker_callback_tag = GLib.io_add_watch(
1153
 
                GLib.IOChannel.unix_new(pipe[0].fileno()),
1154
 
                GLib.PRIORITY_DEFAULT, GLib.IO_IN,
 
1146
                pipe[0].fileno(), GLib.IO_IN,
1155
1147
                self.checker_callback, pipe[0], command)
1156
1148
        # Re-run this periodically if run by GLib.timeout_add
1157
1149
        return True
2681
2673
    def add_pipe(self, parent_pipe, proc):
2682
2674
        # Call "handle_ipc" for both data and EOF events
2683
2675
        GLib.io_add_watch(
2684
 
            GLib.IOChannel.unix_new(parent_pipe.fileno()),
2685
 
            GLib.PRIORITY_DEFAULT, GLib.IO_IN | GLib.IO_HUP,
 
2676
            parent_pipe.fileno(),
 
2677
            GLib.IO_IN | GLib.IO_HUP,
2686
2678
            functools.partial(self.handle_ipc,
2687
2679
                              parent_pipe=parent_pipe,
2688
2680
                              proc=proc))
2726
2718
                return False
2727
2719
 
2728
2720
            GLib.io_add_watch(
2729
 
                GLib.IOChannel.unix_new(parent_pipe.fileno()),
2730
 
                GLib.PRIORITY_DEFAULT, GLib.IO_IN | GLib.IO_HUP,
 
2721
                parent_pipe.fileno(),
 
2722
                GLib.IO_IN | GLib.IO_HUP,
2731
2723
                functools.partial(self.handle_ipc,
2732
2724
                                  parent_pipe=parent_pipe,
2733
2725
                                  proc=proc,
2983
2975
 
2984
2976
    options = parser.parse_args()
2985
2977
 
 
2978
    if options.check:
 
2979
        import doctest
 
2980
        fail_count, test_count = doctest.testmod()
 
2981
        sys.exit(os.EX_OK if fail_count == 0 else 1)
 
2982
 
2986
2983
    # Default values for config file for server-global settings
2987
2984
    if gnutls.has_rawpk:
2988
2985
        priority = ("SECURE128:!CTYPE-X.509:+CTYPE-RAWPK:!RSA"
3603
3600
                sys.exit(1)
3604
3601
            # End of Avahi example code
3605
3602
 
3606
 
        GLib.io_add_watch(
3607
 
            GLib.IOChannel.unix_new(tcp_server.fileno()),
3608
 
            GLib.PRIORITY_DEFAULT, GLib.IO_IN,
3609
 
            lambda *args, **kwargs: (tcp_server.handle_request
3610
 
                                     (*args[2:], **kwargs) or True))
 
3603
        GLib.io_add_watch(tcp_server.fileno(), GLib.IO_IN,
 
3604
                          lambda *args, **kwargs:
 
3605
                          (tcp_server.handle_request
 
3606
                           (*args[2:], **kwargs) or True))
3611
3607
 
3612
3608
        logger.debug("Starting main loop")
3613
3609
        main_loop.run()
3623
3619
    # Must run before the D-Bus bus name gets deregistered
3624
3620
    cleanup()
3625
3621
 
3626
 
 
3627
 
def should_only_run_tests():
3628
 
    parser = argparse.ArgumentParser(add_help=False)
3629
 
    parser.add_argument("--check", action='store_true')
3630
 
    args, unknown_args = parser.parse_known_args()
3631
 
    run_tests = args.check
3632
 
    if run_tests:
3633
 
        # Remove --check argument from sys.argv
3634
 
        sys.argv[1:] = unknown_args
3635
 
    return run_tests
3636
 
 
3637
 
# Add all tests from doctest strings
3638
 
def load_tests(loader, tests, none):
3639
 
    import doctest
3640
 
    tests.addTests(doctest.DocTestSuite())
3641
 
    return tests
3642
3622
 
3643
3623
if __name__ == '__main__':
3644
 
    try:
3645
 
        if should_only_run_tests():
3646
 
            # Call using ./mandos --check [--verbose]
3647
 
            unittest.main()
3648
 
        else:
3649
 
            main()
3650
 
    finally:
3651
 
        logging.shutdown()
 
3624
    main()