177
176
def remove(self):
178
177
"""Derived from the Avahi example code"""
179
178
if self.group is not None:
182
except (dbus.exceptions.UnknownMethodException,
183
dbus.exceptions.DBusException) as e:
186
if self.entry_group_state_changed_match is not None:
187
self.entry_group_state_changed_match.remove()
188
self.entry_group_state_changed_match = None
190
181
"""Derived from the Avahi example code"""
192
self.group = dbus.Interface(
193
self.bus.get_object(avahi.DBUS_NAME,
194
self.server.EntryGroupNew(),
195
follow_name_owner_changes=True),
196
avahi.DBUS_INTERFACE_ENTRY_GROUP)
197
self.entry_group_state_changed_match = (
198
self.group.connect_to_signal(
199
'StateChanged', self .entry_group_state_changed))
182
if self.group is None:
183
self.group = dbus.Interface(
184
self.bus.get_object(avahi.DBUS_NAME,
185
self.server.EntryGroupNew()),
186
avahi.DBUS_INTERFACE_ENTRY_GROUP)
187
self.group.connect_to_signal('StateChanged',
189
.entry_group_state_changed)
200
190
logger.debug("Adding Zeroconf service '%s' of type '%s' ...",
201
191
self.name, self.type)
202
192
self.group.AddService(
224
214
% unicode(error))
225
215
def cleanup(self):
226
216
"""Derived from the Avahi example code"""
228
def server_state_changed(self, state, error=None):
217
if self.group is not None:
220
def server_state_changed(self, state):
229
221
"""Derived from the Avahi example code"""
230
222
logger.debug("Avahi server state change: %i", state)
231
bad_states = { avahi.SERVER_INVALID:
232
"Zeroconf server invalid",
233
avahi.SERVER_REGISTERING: None,
234
avahi.SERVER_COLLISION:
235
"Zeroconf server name collision",
236
avahi.SERVER_FAILURE:
237
"Zeroconf server failure" }
238
if state in bad_states:
239
if bad_states[state]:
240
logger.error(bad_states[state])
223
if state == avahi.SERVER_COLLISION:
224
logger.error("Zeroconf server name collision")
242
226
elif state == avahi.SERVER_RUNNING:
245
logger.debug("Unknown state: %r", state)
246
228
def activate(self):
247
229
"""Derived from the Avahi example code"""
248
230
if self.server is None:
249
231
self.server = dbus.Interface(
250
232
self.bus.get_object(avahi.DBUS_NAME,
251
avahi.DBUS_PATH_SERVER,
252
follow_name_owner_changes=True),
233
avahi.DBUS_PATH_SERVER),
253
234
avahi.DBUS_INTERFACE_SERVER)
254
235
self.server.connect_to_signal("StateChanged",
255
236
self.server_state_changed)
1223
1205
if int(line.strip().split()[0]) > 1:
1224
1206
raise RuntimeError
1225
except (ValueError, IndexError, RuntimeError) as error:
1207
except (ValueError, IndexError, RuntimeError), error:
1226
1208
logger.error("Unknown protocol version: %s", error)
1229
1211
# Start GnuTLS connection
1231
1213
session.handshake()
1232
except gnutls.errors.GNUTLSError as error:
1214
except gnutls.errors.GNUTLSError, error:
1233
1215
logger.warning("Handshake failed: %s", error)
1234
1216
# Do not run session.bye() here: the session is not
1235
1217
# established. Just abandon the request.
1692
1673
##################################################################
1693
1674
# Parsing of options, both command line and config file
1695
parser = argparse.ArgumentParser()
1696
parser.add_argument("-v", "--version", action="version",
1697
version = "%%(prog)s %s" % version,
1698
help="show version number and exit")
1699
parser.add_argument("-i", "--interface", metavar="IF",
1700
help="Bind to interface IF")
1701
parser.add_argument("-a", "--address",
1702
help="Address to listen for requests on")
1703
parser.add_argument("-p", "--port", type=int,
1704
help="Port number to receive requests on")
1705
parser.add_argument("--check", action="store_true",
1706
help="Run self-test")
1707
parser.add_argument("--debug", action="store_true",
1708
help="Debug mode; run in foreground and log"
1710
parser.add_argument("--debuglevel", metavar="LEVEL",
1711
help="Debug level for stdout output")
1712
parser.add_argument("--priority", help="GnuTLS"
1713
" priority string (see GnuTLS documentation)")
1714
parser.add_argument("--servicename",
1715
metavar="NAME", help="Zeroconf service name")
1716
parser.add_argument("--configdir",
1717
default="/etc/mandos", metavar="DIR",
1718
help="Directory to search for configuration"
1720
parser.add_argument("--no-dbus", action="store_false",
1721
dest="use_dbus", help="Do not provide D-Bus"
1722
" system bus interface")
1723
parser.add_argument("--no-ipv6", action="store_false",
1724
dest="use_ipv6", help="Do not use IPv6")
1725
options = parser.parse_args()
1676
parser = optparse.OptionParser(version = "%%prog %s" % version)
1677
parser.add_option("-i", "--interface", type="string",
1678
metavar="IF", help="Bind to interface IF")
1679
parser.add_option("-a", "--address", type="string",
1680
help="Address to listen for requests on")
1681
parser.add_option("-p", "--port", type="int",
1682
help="Port number to receive requests on")
1683
parser.add_option("--check", action="store_true",
1684
help="Run self-test")
1685
parser.add_option("--debug", action="store_true",
1686
help="Debug mode; run in foreground and log to"
1688
parser.add_option("--debuglevel", type="string", metavar="LEVEL",
1689
help="Debug level for stdout output")
1690
parser.add_option("--priority", type="string", help="GnuTLS"
1691
" priority string (see GnuTLS documentation)")
1692
parser.add_option("--servicename", type="string",
1693
metavar="NAME", help="Zeroconf service name")
1694
parser.add_option("--configdir", type="string",
1695
default="/etc/mandos", metavar="DIR",
1696
help="Directory to search for configuration"
1698
parser.add_option("--no-dbus", action="store_false",
1699
dest="use_dbus", help="Do not provide D-Bus"
1700
" system bus interface")
1701
parser.add_option("--no-ipv6", action="store_false",
1702
dest="use_ipv6", help="Do not use IPv6")
1703
options = parser.parse_args()[0]
1727
1705
if options.check: