/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

merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
226
226
        if config is None:
227
227
            config = {}
228
228
        logger.debug(u"Creating client %r", self.name)
229
 
        self.use_dbus = use_dbus
230
 
        if self.use_dbus:
231
 
            self.dbus_object_path = (dbus.ObjectPath
232
 
                                     ("/Mandos/clients/"
233
 
                                      + self.name.replace(".", "_")))
234
 
            dbus.service.Object.__init__(self, bus,
235
 
                                         self.dbus_object_path)
 
229
        self.use_dbus = False   # During __init__
236
230
        # Uppercase and remove spaces from fingerprint for later
237
231
        # comparison purposes with return value from the fingerprint()
238
232
        # function
262
256
        self.disable_initiator_tag = None
263
257
        self.checker_callback_tag = None
264
258
        self.checker_command = config["checker"]
 
259
        self.last_connect = None
 
260
        # Only now, when this client is initialized, can it show up on
 
261
        # the D-Bus
 
262
        self.use_dbus = use_dbus
 
263
        if self.use_dbus:
 
264
            self.dbus_object_path = (dbus.ObjectPath
 
265
                                     ("/clients/"
 
266
                                      + self.name.replace(".", "_")))
 
267
            dbus.service.Object.__init__(self, bus,
 
268
                                         self.dbus_object_path)
265
269
    
266
270
    def enable(self):
267
271
        """Start this client's checker and timeout hooks"""
320
324
            # Emit D-Bus signal
321
325
            self.PropertyChanged(dbus.String(u"checker_running"),
322
326
                                 dbus.Boolean(False, variant_level=1))
323
 
        if (os.WIFEXITED(condition)
324
 
            and (os.WEXITSTATUS(condition) == 0)):
325
 
            logger.info(u"Checker for %(name)s succeeded",
326
 
                        vars(self))
 
327
        if os.WIFEXITED(condition):
 
328
            exitstatus = os.WEXITSTATUS(condition)
 
329
            if exitstatus == 0:
 
330
                logger.info(u"Checker for %(name)s succeeded",
 
331
                            vars(self))
 
332
                self.bump_timeout()
 
333
            else:
 
334
                logger.info(u"Checker for %(name)s failed",
 
335
                            vars(self))
327
336
            if self.use_dbus:
328
337
                # Emit D-Bus signal
329
 
                self.CheckerCompleted(dbus.Boolean(True),
330
 
                                      dbus.UInt16(condition),
 
338
                self.CheckerCompleted(dbus.Int16(exitstatus),
 
339
                                      dbus.Int64(condition),
331
340
                                      dbus.String(command))
332
 
            self.bump_timeout()
333
 
        elif not os.WIFEXITED(condition):
 
341
        else:
334
342
            logger.warning(u"Checker for %(name)s crashed?",
335
343
                           vars(self))
336
344
            if self.use_dbus:
337
345
                # Emit D-Bus signal
338
 
                self.CheckerCompleted(dbus.Boolean(False),
339
 
                                      dbus.UInt16(condition),
340
 
                                      dbus.String(command))
341
 
        else:
342
 
            logger.info(u"Checker for %(name)s failed",
343
 
                        vars(self))
344
 
            if self.use_dbus:
345
 
                # Emit D-Bus signal
346
 
                self.CheckerCompleted(dbus.Boolean(False),
347
 
                                      dbus.UInt16(condition),
 
346
                self.CheckerCompleted(dbus.Int16(-1),
 
347
                                      dbus.Int64(condition),
348
348
                                      dbus.String(command))
349
349
    
350
350
    def bump_timeout(self):
449
449
            return now < (self.last_checked_ok + self.timeout)
450
450
    
451
451
    ## D-Bus methods & signals
452
 
    _interface = u"org.mandos_system.Mandos.Client"
 
452
    _interface = u"se.bsnet.fukt.Mandos.Client"
453
453
    
454
454
    # BumpTimeout - method
455
455
    BumpTimeout = dbus.service.method(_interface)(bump_timeout)
456
456
    BumpTimeout.__name__ = "BumpTimeout"
457
457
    
458
458
    # CheckerCompleted - signal
459
 
    @dbus.service.signal(_interface, signature="bqs")
460
 
    def CheckerCompleted(self, success, condition, command):
 
459
    @dbus.service.signal(_interface, signature="nxs")
 
460
    def CheckerCompleted(self, exitcode, waitstatus, command):
461
461
        "D-Bus signal"
462
462
        pass
463
463
    
1035
1035
                            avahi.DBUS_INTERFACE_SERVER)
1036
1036
    # End of Avahi example code
1037
1037
    if use_dbus:
1038
 
        bus_name = dbus.service.BusName(u"org.mandos-system.Mandos",
1039
 
                                        bus)
 
1038
        bus_name = dbus.service.BusName(u"se.bsnet.fukt.Mandos", bus)
1040
1039
    
1041
1040
    clients.update(Set(Client(name = section,
1042
1041
                              config
1096
1095
        class MandosServer(dbus.service.Object):
1097
1096
            """A D-Bus proxy object"""
1098
1097
            def __init__(self):
1099
 
                dbus.service.Object.__init__(self, bus,
1100
 
                                             "/Mandos")
1101
 
            _interface = u"org.mandos_system.Mandos"
 
1098
                dbus.service.Object.__init__(self, bus, "/")
 
1099
            _interface = u"se.bsnet.fukt.Mandos"
1102
1100
            
1103
1101
            @dbus.service.signal(_interface, signature="oa{sv}")
1104
1102
            def ClientAdded(self, objpath, properties):
1134
1132
                        return
1135
1133
                raise KeyError
1136
1134
            
1137
 
            @dbus.service.method(_interface, in_signature="s")
1138
 
            def RemoveClientByName(self, name):
1139
 
                for c in clients:
1140
 
                    if c.name == name:
1141
 
                        clients.remove(c)
1142
 
                        # Don't signal anything except ClientRemoved
1143
 
                        c.use_dbus = False
1144
 
                        c.disable()
1145
 
                        # Emit D-Bus signal
1146
 
                        self.ClientRemoved(c.dbus_object_path, name)
1147
 
                        return
1148
 
                raise KeyError
1149
 
            
1150
 
            @dbus.service.method(_interface)
1151
 
            def Quit(self):
1152
 
                main_loop.quit()
1153
 
            
1154
1135
            del _interface
1155
1136
        
1156
1137
        mandos_server = MandosServer()