/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-03-15 04:22:14 UTC
  • mfrom: (326 mandos)
  • mto: This revision was merged to the branch mainline in revision 327.
  • Revision ID: teddy@fukt.bsnet.se-20090315042214-gvps0knkvuyewtxl
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
137
137
        logger.info(u"Changing Zeroconf service name to %r ...",
138
138
                    str(self.name))
139
139
        syslogger.setFormatter(logging.Formatter
140
 
                               ('Mandos (%s) [%%(process)d]:'
141
 
                                ' %%(levelname)s: %%(message)s'
142
 
                                % self.name))
 
140
                               ('Mandos (%s): %%(levelname)s:'
 
141
                                ' %%(message)s' % self.name))
143
142
        self.remove()
144
143
        self.add()
145
144
        self.rename_count += 1
543
542
        "D-Bus signal"
544
543
        pass
545
544
    
546
 
    # ReceivedSecret - signal
547
 
    @dbus.service.signal(_interface)
548
 
    def ReceivedSecret(self):
549
 
        "D-Bus signal"
550
 
        pass
551
 
    
552
 
    # Rejected - signal
553
 
    @dbus.service.signal(_interface)
554
 
    def Rejected(self):
555
 
        "D-Bus signal"
556
 
        pass
557
 
    
558
545
    # SetChecker - method
559
546
    @dbus.service.method(_interface, in_signature="s")
560
547
    def SetChecker(self, checker):
691
678
    def handle(self):
692
679
        logger.info(u"TCP connection from: %s",
693
680
                    unicode(self.client_address))
694
 
        logger.debug(u"IPC Pipe FD: %d", self.server.pipe[1])
 
681
        logger.debug(u"Pipe: %d", self.server.pipe[1])
695
682
        # Open IPC pipe to parent process
696
683
        with closing(os.fdopen(self.server.pipe[1], "w", 1)) as ipc:
697
684
            session = (gnutls.connection
857
844
    def enable(self):
858
845
        self.enabled = True
859
846
    def handle_ipc(self, source, condition, file_objects={}):
860
 
        condition_names = {
861
 
            gobject.IO_IN: "IN", # There is data to read.
862
 
            gobject.IO_OUT: "OUT", # Data can be written (without
863
 
                                   # blocking).
864
 
            gobject.IO_PRI: "PRI", # There is urgent data to read.
865
 
            gobject.IO_ERR: "ERR", # Error condition.
866
 
            gobject.IO_HUP: "HUP"  # Hung up (the connection has been
867
 
                                   # broken, usually for pipes and
868
 
                                   # sockets).
869
 
            }
870
 
        conditions_string = ' | '.join(name
871
 
                                       for cond, name in
872
 
                                       condition_names.iteritems()
873
 
                                       if cond & condition)
874
 
        logger.debug("Handling IPC: FD = %d, condition = %s", source,
875
 
                     conditions_string)
 
847
        logger.debug("Handling IPC: %r : %r", source, condition)
876
848
        
877
 
        # Turn the pipe file descriptor into a Python file object
 
849
        # Turn a file descriptor into a Python file object
878
850
        if source not in file_objects:
879
851
            file_objects[source] = os.fdopen(source, "r", 1)
880
852
        
882
854
        cmdline = file_objects[source].readline()
883
855
        if not cmdline:             # Empty line means end of file
884
856
            # close the IPC pipe
 
857
            logger.debug("Closing: %r", source)
885
858
            file_objects[source].close()
886
859
            del file_objects[source]
887
 
            
 
860
 
888
861
            # Stop calling this function
889
862
            return False
890
863
        
893
866
        # Parse and act on command
894
867
        cmd, args = cmdline.split(None, 1)
895
868
        if cmd == "NOTFOUND":
896
 
            if self.settings["use_dbus"]:
897
 
                # Emit D-Bus signal
898
 
                mandos_dbus_service.ClientNotFound(args)
 
869
            pass                # xxx
899
870
        elif cmd == "INVALID":
900
 
            if self.settings["use_dbus"]:
901
 
                for client in self.clients:
902
 
                    if client.name == args:
903
 
                        # Emit D-Bus signal
904
 
                        client.Rejected()
905
 
                        break
 
871
            pass                # xxx
906
872
        elif cmd == "SENDING":
907
 
            for client in self.clients:
908
 
                if client.name == args:
909
 
                    client.checked_ok()
910
 
                    if self.settings["use_dbus"]:
911
 
                        # Emit D-Bus signal
912
 
                        client.ReceivedSecret()
913
 
                    break
 
873
            pass                # xxx
 
874
            # client.checked_ok()
914
875
        else:
915
876
            logger.error("Unknown IPC command: %r", cmdline)
916
877
        
1027
988
 
1028
989
 
1029
990
def main():
1030
 
    
1031
 
    ######################################################################
1032
 
    # Parsing of options, both command line and config file
1033
 
    
1034
991
    parser = optparse.OptionParser(version = "%%prog %s" % version)
1035
992
    parser.add_option("-i", "--interface", type="string",
1036
993
                      metavar="IF", help="Bind to interface IF")
1105
1062
    del options
1106
1063
    # Now we have our good server settings in "server_settings"
1107
1064
    
1108
 
    ##################################################################
1109
 
    
1110
1065
    # For convenience
1111
1066
    debug = server_settings["debug"]
1112
1067
    use_dbus = server_settings["use_dbus"]
1118
1073
    
1119
1074
    if server_settings["servicename"] != "Mandos":
1120
1075
        syslogger.setFormatter(logging.Formatter
1121
 
                               ('Mandos (%s) [%%(process)d]:'
1122
 
                                ' %%(levelname)s: %%(message)s'
 
1076
                               ('Mandos (%s): %%(levelname)s:'
 
1077
                                ' %%(message)s'
1123
1078
                                % server_settings["servicename"]))
1124
1079
    
1125
1080
    # Parse config file with clients
1131
1086
    client_config = ConfigParser.SafeConfigParser(client_defaults)
1132
1087
    client_config.read(os.path.join(server_settings["configdir"],
1133
1088
                                    "clients.conf"))
1134
 
 
1135
 
    global mandos_dbus_service
1136
 
    mandos_dbus_service = None
1137
1089
    
1138
1090
    clients = Set()
1139
1091
    tcp_server = IPv6_TCPServer((server_settings["address"],
1225
1177
        daemon()
1226
1178
    
1227
1179
    try:
1228
 
        with closing(pidfile):
1229
 
            pid = os.getpid()
1230
 
            pidfile.write(str(pid) + "\n")
 
1180
        pid = os.getpid()
 
1181
        pidfile.write(str(pid) + "\n")
 
1182
        pidfile.close()
1231
1183
        del pidfile
1232
1184
    except IOError:
1233
1185
        logger.error(u"Could not write to file %r with PID %d",
1259
1211
    signal.signal(signal.SIGTERM, lambda signum, frame: sys.exit())
1260
1212
    
1261
1213
    if use_dbus:
1262
 
        class MandosDBusService(dbus.service.Object):
 
1214
        class MandosServer(dbus.service.Object):
1263
1215
            """A D-Bus proxy object"""
1264
1216
            def __init__(self):
1265
1217
                dbus.service.Object.__init__(self, bus, "/")
1270
1222
                "D-Bus signal"
1271
1223
                pass
1272
1224
            
1273
 
            @dbus.service.signal(_interface, signature="s")
1274
 
            def ClientNotFound(self, fingerprint):
1275
 
                "D-Bus signal"
1276
 
                pass
1277
 
            
1278
1225
            @dbus.service.signal(_interface, signature="os")
1279
1226
            def ClientRemoved(self, objpath, name):
1280
1227
                "D-Bus signal"
1309
1256
            
1310
1257
            del _interface
1311
1258
        
1312
 
        mandos_dbus_service = MandosDBusService()
 
1259
        mandos_server = MandosServer()
1313
1260
    
1314
1261
    for client in clients:
1315
1262
        if use_dbus:
1316
1263
            # Emit D-Bus signal
1317
 
            mandos_dbus_service.ClientAdded(client.dbus_object_path,
1318
 
                                            client.GetAllProperties())
 
1264
            mandos_server.ClientAdded(client.dbus_object_path,
 
1265
                                      client.GetAllProperties())
1319
1266
        client.enable()
1320
1267
    
1321
1268
    tcp_server.enable()