/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: 2009-02-07 04:50:39 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090207045039-xkr6b80vtqwqrq8l
* Makefile (install-client-nokey): Move "initramfs-tools-script" from
                                   "/scripts/local-top/mandos" to
                                   "/scripts/init-premount/mandos".
  (uninstall-client): - '' -
* debian/mandos-client.dirs: - '' -
* initramfs-tools-script (PREREQ): Added "udev".

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
import ctypes
67
67
import ctypes.util
68
68
 
69
 
version = "1.0.7"
 
69
version = "1.0.5"
70
70
 
71
71
logger = logging.Logger('mandos')
72
72
syslogger = (logging.handlers.SysLogHandler
114
114
    """
115
115
    def __init__(self, interface = avahi.IF_UNSPEC, name = None,
116
116
                 servicetype = None, port = None, TXT = None,
117
 
                 domain = "", host = "", max_renames = 32768,
118
 
                 protocol = avahi.PROTO_UNSPEC):
 
117
                 domain = "", host = "", max_renames = 32768):
119
118
        self.interface = interface
120
119
        self.name = name
121
120
        self.type = servicetype
125
124
        self.host = host
126
125
        self.rename_count = 0
127
126
        self.max_renames = max_renames
128
 
        self.protocol = protocol
129
127
    def rename(self):
130
128
        """Derived from the Avahi example code"""
131
129
        if self.rename_count >= self.max_renames:
160
158
                     service.name, service.type)
161
159
        group.AddService(
162
160
                self.interface,         # interface
163
 
                self.protocol,          # protocol
 
161
                avahi.PROTO_INET6,      # protocol
164
162
                dbus.UInt32(0),         # flags
165
163
                self.name, self.type,
166
164
                self.domain, self.host,
205
203
                     client lives.  %() expansions are done at
206
204
                     runtime with vars(self) as dict, so that for
207
205
                     instance %(name)s can be used in the command.
208
 
    current_checker_command: string; current running checker_command
209
206
    use_dbus: bool(); Whether to provide D-Bus interface and signals
210
207
    dbus_object_path: dbus.ObjectPath ; only set if self.use_dbus
211
208
    """
260
257
        self.disable_initiator_tag = None
261
258
        self.checker_callback_tag = None
262
259
        self.checker_command = config["checker"]
263
 
        self.current_checker_command = None
264
260
        self.last_connect = None
265
261
        # Only now, when this client is initialized, can it show up on
266
262
        # the D-Bus
381
377
        # checkers alone, the checker would have to take more time
382
378
        # than 'timeout' for the client to be declared invalid, which
383
379
        # is as it should be.
384
 
        
385
 
        # If a checker exists, make sure it is not a zombie
386
 
        if self.checker is not None:
387
 
            pid, status = os.waitpid(self.checker.pid, os.WNOHANG)
388
 
            if pid:
389
 
                logger.warning("Checker was a zombie")
390
 
                gobject.source_remove(self.checker_callback_tag)
391
 
                self.checker_callback(pid, status,
392
 
                                      self.current_checker_command)
393
 
        # Start a new checker if needed
394
380
        if self.checker is None:
395
381
            try:
396
382
                # In case checker_command has exactly one % operator
406
392
                    logger.error(u'Could not format string "%s":'
407
393
                                 u' %s', self.checker_command, error)
408
394
                    return True # Try again later
409
 
                self.current_checker_command = command
410
395
            try:
411
396
                logger.info(u"Starting checker %r for %s",
412
397
                            command, self.name)
427
412
                                             (self.checker.pid,
428
413
                                              self.checker_callback,
429
414
                                              data=command))
430
 
                # The checker may have completed before the gobject
431
 
                # watch was added.  Check for this.
432
 
                pid, status = os.waitpid(self.checker.pid, os.WNOHANG)
433
 
                if pid:
434
 
                    gobject.source_remove(self.checker_callback_tag)
435
 
                    self.checker_callback(pid, status, command)
436
415
            except OSError, error:
437
416
                logger.error(u"Failed to start subprocess: %s",
438
417
                             error)
753
732
 
754
733
class IPv6_TCPServer(SocketServer.ForkingMixIn,
755
734
                     SocketServer.TCPServer, object):
756
 
    """IPv6-capable TCP server.  Accepts 'None' as address and/or port
 
735
    """IPv6 TCP server.  Accepts 'None' as address and/or port.
757
736
    Attributes:
758
737
        settings:       Server settings
759
738
        clients:        Set() of Client objects
767
746
        if "clients" in kwargs:
768
747
            self.clients = kwargs["clients"]
769
748
            del kwargs["clients"]
770
 
        if "use_ipv6" in kwargs:
771
 
            if not kwargs["use_ipv6"]:
772
 
                self.address_family = socket.AF_INET
773
 
            del kwargs["use_ipv6"]
774
749
        self.enabled = False
775
750
        super(IPv6_TCPServer, self).__init__(*args, **kwargs)
776
751
    def server_bind(self):
794
769
        # Only bind(2) the socket if we really need to.
795
770
        if self.server_address[0] or self.server_address[1]:
796
771
            if not self.server_address[0]:
797
 
                if self.address_family == socket.AF_INET6:
798
 
                    any_address = "::" # in6addr_any
799
 
                else:
800
 
                    any_address = socket.INADDR_ANY
801
 
                self.server_address = (any_address,
 
772
                in6addr_any = "::"
 
773
                self.server_address = (in6addr_any,
802
774
                                       self.server_address[1])
803
775
            elif not self.server_address[1]:
804
776
                self.server_address = (self.server_address[0],
951
923
                      dest="use_dbus",
952
924
                      help="Do not provide D-Bus system bus"
953
925
                      " interface")
954
 
    parser.add_option("--no-ipv6", action="store_false",
955
 
                      dest="use_ipv6", help="Do not use IPv6")
956
926
    options = parser.parse_args()[0]
957
927
    
958
928
    if options.check:
969
939
                        "SECURE256:!CTYPE-X.509:+CTYPE-OPENPGP",
970
940
                        "servicename": "Mandos",
971
941
                        "use_dbus": "True",
972
 
                        "use_ipv6": "True",
973
942
                        }
974
943
    
975
944
    # Parse config file for server-global settings
983
952
                                                        "debug")
984
953
    server_settings["use_dbus"] = server_config.getboolean("DEFAULT",
985
954
                                                           "use_dbus")
986
 
    server_settings["use_ipv6"] = server_config.getboolean("DEFAULT",
987
 
                                                           "use_ipv6")
988
955
    if server_settings["port"]:
989
956
        server_settings["port"] = server_config.getint("DEFAULT",
990
957
                                                       "port")
994
961
    # options, if set.
995
962
    for option in ("interface", "address", "port", "debug",
996
963
                   "priority", "servicename", "configdir",
997
 
                   "use_dbus", "use_ipv6"):
 
964
                   "use_dbus"):
998
965
        value = getattr(options, option)
999
966
        if value is not None:
1000
967
            server_settings[option] = value
1004
971
    # For convenience
1005
972
    debug = server_settings["debug"]
1006
973
    use_dbus = server_settings["use_dbus"]
1007
 
    use_ipv6 = server_settings["use_ipv6"]
1008
974
    
1009
975
    if not debug:
1010
976
        syslogger.setLevel(logging.WARNING)
1031
997
                                 server_settings["port"]),
1032
998
                                TCP_handler,
1033
999
                                settings=server_settings,
1034
 
                                clients=clients, use_ipv6=use_ipv6)
 
1000
                                clients=clients)
1035
1001
    pidfilename = "/var/run/mandos.pid"
1036
1002
    try:
1037
1003
        pidfile = open(pidfilename, "w")
1073
1039
         .gnutls_global_set_log_function(debug_gnutls))
1074
1040
    
1075
1041
    global service
1076
 
    protocol = avahi.PROTO_INET6 if use_ipv6 else avahi.PROTO_INET
1077
1042
    service = AvahiService(name = server_settings["servicename"],
1078
 
                           servicetype = "_mandos._tcp",
1079
 
                           protocol = protocol)
 
1043
                           servicetype = "_mandos._tcp", )
1080
1044
    if server_settings["interface"]:
1081
1045
        service.interface = (if_nametoindex
1082
1046
                             (server_settings["interface"]))
1209
1173
    
1210
1174
    # Find out what port we got
1211
1175
    service.port = tcp_server.socket.getsockname()[1]
1212
 
    if use_ipv6:
1213
 
        logger.info(u"Now listening on address %r, port %d,"
1214
 
                    " flowinfo %d, scope_id %d"
1215
 
                    % tcp_server.socket.getsockname())
1216
 
    else:                       # IPv4
1217
 
        logger.info(u"Now listening on address %r, port %d"
1218
 
                    % tcp_server.socket.getsockname())
 
1176
    logger.info(u"Now listening on address %r, port %d, flowinfo %d,"
 
1177
                u" scope_id %d" % tcp_server.socket.getsockname())
1219
1178
    
1220
1179
    #service.interface = tcp_server.socket.getsockname()[3]
1221
1180