171
except dbus.exceptions.DBusException, error:
172
except dbus.exceptions.DBusException as error:
172
173
logger.critical("DBusException: %s", error)
175
176
self.rename_count += 1
176
177
def remove(self):
177
178
"""Derived from the Avahi example code"""
179
if self.entry_group_state_changed_match is not None:
180
self.entry_group_state_changed_match.remove()
181
self.entry_group_state_changed_match = None
178
182
if self.group is not None:
179
183
self.group.Reset()
181
185
"""Derived from the Avahi example code"""
182
187
if self.group is None:
183
188
self.group = dbus.Interface(
184
189
self.bus.get_object(avahi.DBUS_NAME,
185
190
self.server.EntryGroupNew()),
186
191
avahi.DBUS_INTERFACE_ENTRY_GROUP)
187
self.group.connect_to_signal('StateChanged',
189
.entry_group_state_changed)
192
self.entry_group_state_changed_match = (
193
self.group.connect_to_signal(
194
'StateChanged', self .entry_group_state_changed))
190
195
logger.debug("Adding Zeroconf service '%s' of type '%s' ...",
191
196
self.name, self.type)
192
197
self.group.AddService(
215
220
def cleanup(self):
216
221
"""Derived from the Avahi example code"""
217
222
if self.group is not None:
225
except (dbus.exceptions.UnknownMethodException,
226
dbus.exceptions.DBusException) as e:
219
228
self.group = None
220
def server_state_changed(self, state):
230
def server_state_changed(self, state, error=None):
221
231
"""Derived from the Avahi example code"""
222
232
logger.debug("Avahi server state change: %i", state)
223
if state == avahi.SERVER_COLLISION:
224
logger.error("Zeroconf server name collision")
233
bad_states = { avahi.SERVER_INVALID:
234
"Zeroconf server invalid",
235
avahi.SERVER_REGISTERING: None,
236
avahi.SERVER_COLLISION:
237
"Zeroconf server name collision",
238
avahi.SERVER_FAILURE:
239
"Zeroconf server failure" }
240
if state in bad_states:
241
if bad_states[state] is not None:
243
logger.error(bad_states[state])
245
logger.error(bad_states[state] + ": %r", error)
226
247
elif state == avahi.SERVER_RUNNING:
251
logger.debug("Unknown state: %r", state)
253
logger.debug("Unknown state: %r: %r", state, error)
228
254
def activate(self):
229
255
"""Derived from the Avahi example code"""
230
256
if self.server is None:
231
257
self.server = dbus.Interface(
232
258
self.bus.get_object(avahi.DBUS_NAME,
233
avahi.DBUS_PATH_SERVER),
259
avahi.DBUS_PATH_SERVER,
260
follow_name_owner_changes=True),
234
261
avahi.DBUS_INTERFACE_SERVER)
235
262
self.server.connect_to_signal("StateChanged",
236
263
self.server_state_changed)
445
472
# If a checker exists, make sure it is not a zombie
447
474
pid, status = os.waitpid(self.checker.pid, os.WNOHANG)
448
except (AttributeError, OSError), error:
475
except (AttributeError, OSError) as error:
449
476
if (isinstance(error, OSError)
450
477
and error.errno != errno.ECHILD):
474
501
command = self.checker_command % escaped_attrs
475
except TypeError, error:
502
except TypeError as error:
476
503
logger.error('Could not format string "%s":'
477
504
' %s', self.checker_command, error)
478
505
return True # Try again later
498
525
gobject.source_remove(self.checker_callback_tag)
499
526
self.checker_callback(pid, status, command)
500
except OSError, error:
527
except OSError as error:
501
528
logger.error("Failed to start subprocess: %s",
503
530
# Re-run this periodically if run by gobject.timeout_add
704
731
xmlstring = document.toxml("utf-8")
705
732
document.unlink()
706
733
except (AttributeError, xml.dom.DOMException,
707
xml.parsers.expat.ExpatError), error:
734
xml.parsers.expat.ExpatError) as error:
708
735
logger.error("Failed to override Introspection method",
815
842
def checked_ok(self, *args, **kwargs):
816
r = Client.checked_ok(self, *args, **kwargs)
843
Client.checked_ok(self, *args, **kwargs)
817
844
# Emit D-Bus signal
818
845
self.PropertyChanged(
819
846
dbus.String("LastCheckedOK"),
820
847
(self._datetime_to_dbus(self.last_checked_ok,
821
848
variant_level=1)))
824
850
def need_approval(self, *args, **kwargs):
825
851
r = Client.need_approval(self, *args, **kwargs)
1205
1231
if int(line.strip().split()[0]) > 1:
1206
1232
raise RuntimeError
1207
except (ValueError, IndexError, RuntimeError), error:
1233
except (ValueError, IndexError, RuntimeError) as error:
1208
1234
logger.error("Unknown protocol version: %s", error)
1211
1237
# Start GnuTLS connection
1213
1239
session.handshake()
1214
except gnutls.errors.GNUTLSError, error:
1240
except gnutls.errors.GNUTLSError as error:
1215
1241
logger.warning("Handshake failed: %s", error)
1216
1242
# Do not run session.bye() here: the session is not
1217
1243
# established. Just abandon the request.
1224
1250
fpr = self.fingerprint(self.peer_certificate
1226
except (TypeError, gnutls.errors.GNUTLSError), error:
1253
gnutls.errors.GNUTLSError) as error:
1227
1254
logger.warning("Bad certificate: %s", error)
1229
1256
logger.debug("Fingerprint: %s", fpr)
1292
1319
while sent_size < len(client.secret):
1294
1321
sent = session.send(client.secret[sent_size:])
1295
except (gnutls.errors.GNUTLSError), error:
1322
except gnutls.errors.GNUTLSError as error:
1296
1323
logger.warning("gnutls send failed")
1298
1325
logger.debug("Sent: %d, remaining: %d",
1312
1339
client.approvals_pending -= 1
1315
except (gnutls.errors.GNUTLSError), error:
1342
except gnutls.errors.GNUTLSError as error:
1316
1343
logger.warning("GnuTLS bye failed")
1442
1469
SO_BINDTODEVICE,
1443
1470
str(self.interface
1445
except socket.error, error:
1472
except socket.error as error:
1446
1473
if error[0] == errno.EPERM:
1447
1474
logger.error("No permission to"
1448
1475
" bind to interface %s",
1545
logger.warning("Client not found for fingerprint: %s, ad"
1546
"dress: %s", fpr, address)
1572
logger.info("Client not found for fingerprint: %s, ad"
1573
"dress: %s", fpr, address)
1547
1574
if self.use_dbus:
1548
1575
# Emit D-Bus signal
1549
1576
mandos_dbus_service.ClientNotFound(fpr, address[0])
1613
1640
delta = datetime.timedelta(0, 0, 0, 0, 0, 0, value)
1615
1642
raise ValueError("Unknown suffix %r" % suffix)
1616
except (ValueError, IndexError), e:
1643
except (ValueError, IndexError) as e:
1617
1644
raise ValueError(*(e.args))
1618
1645
timevalue += delta
1619
1646
return timevalue
1867
1894
bus_name = dbus.service.BusName("se.bsnet.fukt.Mandos",
1868
1895
bus, do_not_queue=True)
1869
except dbus.exceptions.NameExistsException, e:
1896
except dbus.exceptions.NameExistsException as e:
1870
1897
logger.error(unicode(e) + ", disabling D-Bus")
1871
1898
use_dbus = False
1872
1899
server_settings["use_dbus"] = False
2022
2049
# From the Avahi example code
2024
2051
service.activate()
2025
except dbus.exceptions.DBusException, error:
2052
except dbus.exceptions.DBusException as error:
2026
2053
logger.critical("DBusException: %s", error)
2036
2063
logger.debug("Starting main loop")
2037
2064
main_loop.run()
2038
except AvahiError, error:
2065
except AvahiError as error:
2039
2066
logger.critical("AvahiError: %s", error)