178
178
class Client(dbus.service.Object):
179
179
"""A representation of a client host served by this server.
181
name: string; from the config file, used in log messages and
181
name: string; from the config file, used in log messages
183
182
fingerprint: string (40 or 32 hexadecimal digits); used to
184
183
uniquely identify the client
185
184
secret: bytestring; sent verbatim (over TLS) to client
226
225
if config is None:
228
227
logger.debug(u"Creating client %r", self.name)
229
self.use_dbus = False # During __init__
228
self.use_dbus = use_dbus
230
self.dbus_object_path = (dbus.ObjectPath
232
+ self.name.replace(".", "_")))
233
dbus.service.Object.__init__(self, bus,
234
self.dbus_object_path)
230
235
# Uppercase and remove spaces from fingerprint for later
231
236
# comparison purposes with return value from the fingerprint()
256
261
self.disable_initiator_tag = None
257
262
self.checker_callback_tag = None
258
263
self.checker_command = config["checker"]
259
self.last_connect = None
260
# Only now, when this client is initialized, can it show up on
262
self.use_dbus = use_dbus
264
self.dbus_object_path = (dbus.ObjectPath
266
+ self.name.replace(".", "_")))
267
dbus.service.Object.__init__(self, bus,
268
self.dbus_object_path)
270
265
def enable(self):
271
266
"""Start this client's checker and timeout hooks"""
324
319
# Emit D-Bus signal
325
320
self.PropertyChanged(dbus.String(u"checker_running"),
326
321
dbus.Boolean(False, variant_level=1))
327
if os.WIFEXITED(condition):
328
exitstatus = os.WEXITSTATUS(condition)
330
logger.info(u"Checker for %(name)s succeeded",
334
logger.info(u"Checker for %(name)s failed",
322
if (os.WIFEXITED(condition)
323
and (os.WEXITSTATUS(condition) == 0)):
324
logger.info(u"Checker for %(name)s succeeded",
336
326
if self.use_dbus:
337
327
# Emit D-Bus signal
338
self.CheckerCompleted(dbus.Int16(exitstatus),
339
dbus.Int64(condition),
328
self.CheckerCompleted(dbus.Boolean(True),
329
dbus.UInt16(condition),
340
330
dbus.String(command))
332
elif not os.WIFEXITED(condition):
342
333
logger.warning(u"Checker for %(name)s crashed?",
344
335
if self.use_dbus:
345
336
# Emit D-Bus signal
346
self.CheckerCompleted(dbus.Int16(-1),
347
dbus.Int64(condition),
337
self.CheckerCompleted(dbus.Boolean(False),
338
dbus.UInt16(condition),
339
dbus.String(command))
341
logger.info(u"Checker for %(name)s failed",
345
self.CheckerCompleted(dbus.Boolean(False),
346
dbus.UInt16(condition),
348
347
dbus.String(command))
350
def checked_ok(self):
349
def bump_timeout(self):
351
350
"""Bump up the timeout for this client.
352
351
This should only be called when the client has been seen,
449
448
return now < (self.last_checked_ok + self.timeout)
451
450
## D-Bus methods & signals
452
_interface = u"se.bsnet.fukt.Mandos.Client"
451
_interface = u"org.mandos_system.Mandos.Client"
455
CheckedOK = dbus.service.method(_interface)(checked_ok)
456
CheckedOK.__name__ = "CheckedOK"
453
# BumpTimeout - method
454
BumpTimeout = dbus.service.method(_interface)(bump_timeout)
455
BumpTimeout.__name__ = "BumpTimeout"
458
457
# CheckerCompleted - signal
459
@dbus.service.signal(_interface, signature="nxs")
460
def CheckerCompleted(self, exitcode, waitstatus, command):
458
@dbus.service.signal(_interface, signature="bqs")
459
def CheckerCompleted(self, success, condition, command):
504
503
dbus.String("checker_running"):
505
504
dbus.Boolean(self.checker is not None,
506
505
variant_level=1),
507
dbus.String("object_path"):
508
dbus.ObjectPath(self.dbus_object_path,
510
506
}, signature="sv")
512
508
# IsStillValid - method
941
937
server_config.read(os.path.join(options.configdir, "mandos.conf"))
942
938
# Convert the SafeConfigParser object to a dict
943
939
server_settings = server_config.defaults()
944
# Use the appropriate methods on the non-string config options
945
server_settings["debug"] = server_config.getboolean("DEFAULT",
947
server_settings["use_dbus"] = server_config.getboolean("DEFAULT",
949
if server_settings["port"]:
950
server_settings["port"] = server_config.getint("DEFAULT",
940
# Use getboolean on the boolean config options
941
server_settings["debug"] = (server_config.getboolean
942
("DEFAULT", "debug"))
943
server_settings["use_dbus"] = (server_config.getboolean
944
("DEFAULT", "use_dbus"))
952
945
del server_config
954
947
# Override the settings from the config file with command line
1038
1031
avahi.DBUS_INTERFACE_SERVER)
1039
1032
# End of Avahi example code
1041
bus_name = dbus.service.BusName(u"se.bsnet.fukt.Mandos", bus)
1034
bus_name = dbus.service.BusName(u"org.mandos-system.Mandos",
1043
1037
clients.update(Set(Client(name = section,
1098
1092
class MandosServer(dbus.service.Object):
1099
1093
"""A D-Bus proxy object"""
1100
1094
def __init__(self):
1101
dbus.service.Object.__init__(self, bus, "/")
1102
_interface = u"se.bsnet.fukt.Mandos"
1095
dbus.service.Object.__init__(self, bus,
1097
_interface = u"org.mandos_system.Mandos"
1104
1099
@dbus.service.signal(_interface, signature="oa{sv}")
1105
1100
def ClientAdded(self, objpath, properties):
1109
@dbus.service.signal(_interface, signature="os")
1110
def ClientRemoved(self, objpath, name):
1104
@dbus.service.signal(_interface, signature="o")
1105
def ClientRemoved(self, objpath):
1114
1109
@dbus.service.method(_interface, out_signature="ao")
1115
1110
def GetAllClients(self):
1116
1111
return dbus.Array(c.dbus_object_path for c in clients)
1118
1113
@dbus.service.method(_interface, out_signature="a{oa{sv}}")
1119
1114
def GetAllClientsWithProperties(self):
1120
1115
return dbus.Dictionary(
1121
1116
((c.dbus_object_path, c.GetAllProperties())
1122
1117
for c in clients),
1123
1118
signature="oa{sv}")
1125
1120
@dbus.service.method(_interface, in_signature="o")
1126
1121
def RemoveClient(self, object_path):
1127
1122
for c in clients:
1131
1126
c.use_dbus = False
1133
1128
# Emit D-Bus signal
1134
self.ClientRemoved(object_path, c.name)
1129
self.ClientRemoved(object_path)
1132
@dbus.service.method(_interface)
1140
1138
mandos_server = MandosServer()
1142
1140
for client in clients: