/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:
73
73
             (facility = logging.handlers.SysLogHandler.LOG_DAEMON,
74
74
              address = "/dev/log"))
75
75
syslogger.setFormatter(logging.Formatter
76
 
                       ('Mandos: %(levelname)s: %(message)s'))
 
76
                       ('Mandos [%(process)d]: %(levelname)s:'
 
77
                        ' %(message)s'))
77
78
logger.addHandler(syslogger)
78
79
 
79
80
console = logging.StreamHandler()
80
 
console.setFormatter(logging.Formatter('%(name)s: %(levelname)s:'
81
 
                                       ' %(message)s'))
 
81
console.setFormatter(logging.Formatter('%(name)s [%(process)d]:'
 
82
                                       ' %(levelname)s: %(message)s'))
82
83
logger.addHandler(console)
83
84
 
84
85
class AvahiError(Exception):
595
596
        != gnutls.library.constants.GNUTLS_CRT_OPENPGP):
596
597
        # ...do the normal thing
597
598
        return session.peer_certificate
598
 
    list_size = ctypes.c_uint()
 
599
    list_size = ctypes.c_uint(1)
599
600
    cert_list = (gnutls.library.functions
600
601
                 .gnutls_certificate_get_peers
601
602
                 (session._c_object, ctypes.byref(list_size)))
 
603
    if not bool(cert_list) and list_size.value != 0:
 
604
        raise gnutls.errors.GNUTLSError("error getting peer"
 
605
                                        " certificate")
602
606
    if list_size.value == 0:
603
607
        return None
604
608
    cert = cert_list[0]
673
677
        # using OpenPGP certificates.
674
678
        
675
679
        #priority = ':'.join(("NONE", "+VERS-TLS1.1", "+AES-256-CBC",
676
 
        #                "+SHA1", "+COMP-NULL", "+CTYPE-OPENPGP",
677
 
        #                "+DHE-DSS"))
 
680
        #                     "+SHA1", "+COMP-NULL", "+CTYPE-OPENPGP",
 
681
        #                     "+DHE-DSS"))
678
682
        # Use a fallback default, since this MUST be set.
679
683
        priority = self.server.settings.get("priority", "NORMAL")
680
684
        (gnutls.library.functions
688
692
            # Do not run session.bye() here: the session is not
689
693
            # established.  Just abandon the request.
690
694
            return
 
695
        logger.debug(u"Handshake succeeded")
691
696
        try:
692
697
            fpr = fingerprint(peer_certificate(session))
693
698
        except (TypeError, gnutls.errors.GNUTLSError), error:
695
700
            session.bye()
696
701
            return
697
702
        logger.debug(u"Fingerprint: %s", fpr)
 
703
        
698
704
        for c in self.server.clients:
699
705
            if c.fingerprint == fpr:
700
706
                client = c
759
765
                                 u" bind to interface %s",
760
766
                                 self.settings["interface"])
761
767
                else:
762
 
                    raise error
 
768
                    raise
763
769
        # Only bind(2) the socket if we really need to.
764
770
        if self.server_address[0] or self.server_address[1]:
765
771
            if not self.server_address[0]:
786
792
 
787
793
def string_to_delta(interval):
788
794
    """Parse a string and return a datetime.timedelta
789
 
 
 
795
    
790
796
    >>> string_to_delta('7d')
791
797
    datetime.timedelta(7)
792
798
    >>> string_to_delta('60s')
995
1001
    pidfilename = "/var/run/mandos.pid"
996
1002
    try:
997
1003
        pidfile = open(pidfilename, "w")
998
 
    except IOError, error:
 
1004
    except IOError:
999
1005
        logger.error("Could not open file %r", pidfilename)
1000
1006
    
1001
1007
    try:
1013
1019
                uid = 65534
1014
1020
                gid = 65534
1015
1021
    try:
 
1022
        os.setgid(gid)
1016
1023
        os.setuid(uid)
1017
 
        os.setgid(gid)
1018
1024
    except OSError, error:
1019
1025
        if error[0] != errno.EPERM:
1020
1026
            raise error
1021
1027
    
 
1028
    # Enable all possible GnuTLS debugging
 
1029
    if debug:
 
1030
        # "Use a log level over 10 to enable all debugging options."
 
1031
        # - GnuTLS manual
 
1032
        gnutls.library.functions.gnutls_global_set_log_level(11)
 
1033
        
 
1034
        @gnutls.library.types.gnutls_log_func
 
1035
        def debug_gnutls(level, string):
 
1036
            logger.debug("GnuTLS: %s", string[:-1])
 
1037
        
 
1038
        (gnutls.library.functions
 
1039
         .gnutls_global_set_log_function(debug_gnutls))
 
1040
    
1022
1041
    global service
1023
1042
    service = AvahiService(name = server_settings["servicename"],
1024
1043
                           servicetype = "_mandos._tcp", )
1113
1132
            
1114
1133
            @dbus.service.method(_interface, out_signature="ao")
1115
1134
            def GetAllClients(self):
 
1135
                "D-Bus method"
1116
1136
                return dbus.Array(c.dbus_object_path for c in clients)
1117
1137
            
1118
1138
            @dbus.service.method(_interface, out_signature="a{oa{sv}}")
1119
1139
            def GetAllClientsWithProperties(self):
 
1140
                "D-Bus method"
1120
1141
                return dbus.Dictionary(
1121
1142
                    ((c.dbus_object_path, c.GetAllProperties())
1122
1143
                     for c in clients),
1124
1145
            
1125
1146
            @dbus.service.method(_interface, in_signature="o")
1126
1147
            def RemoveClient(self, object_path):
 
1148
                "D-Bus method"
1127
1149
                for c in clients:
1128
1150
                    if c.dbus_object_path == object_path:
1129
1151
                        clients.remove(c)
1178
1200
        sys.exit(1)
1179
1201
    except KeyboardInterrupt:
1180
1202
        if debug:
1181
 
            print
 
1203
            print >> sys.stderr
 
1204
        logger.debug("Server received KeyboardInterrupt")
 
1205
    logger.debug("Server exiting")
1182
1206
 
1183
1207
if __name__ == '__main__':
1184
1208
    main()