11
11
# "AvahiService" class, and some lines in "main".
13
13
# Everything else is
14
# Copyright © 2008-2013 Teddy Hogeborn
15
# Copyright © 2008-2013 Björn Påhlsson
14
# Copyright © 2008-2014 Teddy Hogeborn
15
# Copyright © 2008-2014 Björn Påhlsson
17
17
# This program is free software: you can redistribute it and/or modify
18
18
# it under the terms of the GNU General Public License as published by
88
88
except ImportError:
89
89
SO_BINDTODEVICE = None
92
92
stored_state_file = "clients.pickle"
94
94
logger = logging.getLogger()
95
syslogger = (logging.handlers.SysLogHandler
96
(facility = logging.handlers.SysLogHandler.LOG_DAEMON,
97
address = str("/dev/log")))
100
98
if_nametoindex = (ctypes.cdll.LoadLibrary
106
104
SIOCGIFINDEX = 0x8933 # From /usr/include/linux/sockios.h
107
105
with contextlib.closing(socket.socket()) as s:
108
106
ifreq = fcntl.ioctl(s, SIOCGIFINDEX,
109
struct.pack(str("16s16x"),
111
interface_index = struct.unpack(str("I"),
107
struct.pack(b"16s16x", interface))
108
interface_index = struct.unpack("I", ifreq[16:20])[0]
113
109
return interface_index
116
112
def initlogger(debug, level=logging.WARNING):
117
113
"""init logger and add loglevel"""
116
syslogger = (logging.handlers.SysLogHandler
118
logging.handlers.SysLogHandler.LOG_DAEMON,
119
address = "/dev/log"))
119
120
syslogger.setFormatter(logging.Formatter
120
121
('Mandos [%(process)d]: %(levelname)s:'
221
222
class AvahiError(Exception):
222
223
def __init__(self, value, *args, **kwargs):
223
224
self.value = value
224
super(AvahiError, self).__init__(value, *args, **kwargs)
225
def __unicode__(self):
226
return unicode(repr(self.value))
225
return super(AvahiError, self).__init__(value, *args,
228
228
class AvahiServiceError(AvahiError):
335
335
elif state == avahi.ENTRY_GROUP_FAILURE:
336
336
logger.critical("Avahi: Error in group state changed %s",
338
raise AvahiGroupError("State changed: {0!s}"
338
raise AvahiGroupError("State changed: {!s}"
341
341
def cleanup(self):
392
392
"""Add the new name to the syslog messages"""
393
393
ret = AvahiService.rename(self)
394
394
syslogger.setFormatter(logging.Formatter
395
('Mandos ({0}) [%(process)d]:'
395
('Mandos ({}) [%(process)d]:'
396
396
' %(levelname)s: %(message)s'
397
397
.format(self.name)))
401
def timedelta_to_milliseconds(td):
402
"Convert a datetime.timedelta() to milliseconds"
403
return ((td.days * 24 * 60 * 60 * 1000)
404
+ (td.seconds * 1000)
405
+ (td.microseconds // 1000))
408
401
class Client(object):
409
402
"""A representation of a client host served by this server.
465
458
"enabled": "True",
468
def timeout_milliseconds(self):
469
"Return the 'timeout' attribute in milliseconds"
470
return timedelta_to_milliseconds(self.timeout)
472
def extended_timeout_milliseconds(self):
473
"Return the 'extended_timeout' attribute in milliseconds"
474
return timedelta_to_milliseconds(self.extended_timeout)
476
def interval_milliseconds(self):
477
"Return the 'interval' attribute in milliseconds"
478
return timedelta_to_milliseconds(self.interval)
480
def approval_delay_milliseconds(self):
481
return timedelta_to_milliseconds(self.approval_delay)
484
462
def config_parser(config):
485
463
"""Construct a new dict of client settings of this form:
510
488
"rb") as secfile:
511
489
client["secret"] = secfile.read()
513
raise TypeError("No secret or secfile for section {0}"
491
raise TypeError("No secret or secfile for section {}"
514
492
.format(section))
515
493
client["timeout"] = string_to_delta(section["timeout"])
516
494
client["extended_timeout"] = string_to_delta(
533
511
server_settings = {}
534
512
self.server_settings = server_settings
535
513
# adding all client settings
536
for setting, value in settings.iteritems():
514
for setting, value in settings.items():
537
515
setattr(self, setting, value)
622
600
if self.checker_initiator_tag is not None:
623
601
gobject.source_remove(self.checker_initiator_tag)
624
602
self.checker_initiator_tag = (gobject.timeout_add
625
(self.interval_milliseconds(),
604
.total_seconds() * 1000),
626
605
self.start_checker))
627
606
# Schedule a disable() when 'timeout' has passed
628
607
if self.disable_initiator_tag is not None:
629
608
gobject.source_remove(self.disable_initiator_tag)
630
609
self.disable_initiator_tag = (gobject.timeout_add
631
(self.timeout_milliseconds(),
611
.total_seconds() * 1000),
633
613
# Also start a new checker *right now*.
634
614
self.start_checker()
666
646
self.disable_initiator_tag = None
667
647
if getattr(self, "enabled", False):
668
648
self.disable_initiator_tag = (gobject.timeout_add
669
(timedelta_to_milliseconds
670
(timeout), self.disable))
649
(int(timeout.total_seconds()
650
* 1000), self.disable))
671
651
self.expires = datetime.datetime.utcnow() + timeout
673
653
def need_approval(self):
690
670
# If a checker exists, make sure it is not a zombie
692
672
pid, status = os.waitpid(self.checker.pid, os.WNOHANG)
693
except (AttributeError, OSError) as error:
694
if (isinstance(error, OSError)
695
and error.errno != errno.ECHILD):
673
except AttributeError:
675
except OSError as error:
676
if error.errno != errno.ECHILD:
699
680
logger.warning("Checker was a zombie")
703
684
# Start a new checker if needed
704
685
if self.checker is None:
705
686
# Escape attributes for the shell
706
escaped_attrs = dict(
707
(attr, re.escape(unicode(getattr(self, attr))))
709
self.runtime_expansions)
687
escaped_attrs = { attr:
688
re.escape(unicode(getattr(self,
690
for attr in self.runtime_expansions }
711
692
command = self.checker_command % escaped_attrs
712
693
except TypeError as error:
793
774
# "Set" method, so we fail early here:
794
775
if byte_arrays and signature != "ay":
795
776
raise ValueError("Byte arrays not supported for non-'ay'"
796
" signature {0!r}".format(signature))
777
" signature {!r}".format(signature))
797
778
def decorator(func):
798
779
func._dbus_is_property = True
799
780
func._dbus_interface = dbus_interface
847
828
class DBusPropertyException(dbus.exceptions.DBusException):
848
829
"""A base class for D-Bus property-related exceptions
850
def __unicode__(self):
851
return unicode(str(self))
854
833
class DBusPropertyAccessException(DBusPropertyException):
855
834
"""A property's access permissions disallows an operation.
878
857
If called like _is_dbus_thing("method") it returns a function
879
858
suitable for use as predicate to inspect.getmembers().
881
return lambda obj: getattr(obj, "_dbus_is_{0}".format(thing),
860
return lambda obj: getattr(obj, "_dbus_is_{}".format(thing),
884
863
def _get_all_dbus_things(self, thing):
933
912
# The byte_arrays option is not supported yet on
934
913
# signatures other than "ay".
935
914
if prop._dbus_signature != "ay":
915
raise ValueError("Byte arrays not supported for non-"
916
"'ay' signature {!r}"
917
.format(prop._dbus_signature))
937
918
value = dbus.ByteArray(b''.join(chr(byte)
938
919
for byte in value))
1004
985
"_dbus_annotations",
1006
for name, value in annots.iteritems():
987
for name, value in annots.items():
1007
988
ann_tag = document.createElement(
1009
990
ann_tag.setAttribute("name", name)
1012
993
# Add interface annotation tags
1013
994
for annotation, value in dict(
1014
995
itertools.chain.from_iterable(
1015
annotations().iteritems()
996
annotations().items()
1016
997
for name, annotations in
1017
998
self._get_all_dbus_things("interface")
1018
999
if name == if_tag.getAttribute("name")
1020
1001
ann_tag = document.createElement("annotation")
1021
1002
ann_tag.setAttribute("name", annotation)
1022
1003
ann_tag.setAttribute("value", value)
1079
1060
def wrapper(cls):
1080
1061
for orig_interface_name, alt_interface_name in (
1081
alt_interface_names.iteritems()):
1062
alt_interface_names.items()):
1083
1064
interface_names = set()
1084
1065
# Go though all attributes of the class
1201
1182
attribute.func_closure)))
1203
1184
# Deprecate all alternate interfaces
1204
iname="_AlternateDBusNames_interface_annotation{0}"
1185
iname="_AlternateDBusNames_interface_annotation{}"
1205
1186
for interface_name in interface_names:
1206
1187
@dbus_interface_annotations(interface_name)
1207
1188
def func(self):
1216
1197
if interface_names:
1217
1198
# Replace the class with a new subclass of it with
1218
1199
# methods, signals, etc. as created above.
1219
cls = type(b"{0}Alternate".format(cls.__name__),
1200
cls = type(b"{}Alternate".format(cls.__name__),
1263
1244
to the D-Bus. Default: no transform
1264
1245
variant_level: D-Bus variant level. Default: 1
1266
attrname = "_{0}".format(dbus_name)
1247
attrname = "_{}".format(dbus_name)
1267
1248
def setter(self, value):
1268
1249
if hasattr(self, "dbus_object_path"):
1269
1250
if (not hasattr(self, attrname) or
1299
1280
approval_delay = notifychangeproperty(dbus.UInt64,
1300
1281
"ApprovalDelay",
1302
timedelta_to_milliseconds)
1283
lambda td: td.total_seconds()
1303
1285
approval_duration = notifychangeproperty(
1304
1286
dbus.UInt64, "ApprovalDuration",
1305
type_func = timedelta_to_milliseconds)
1287
type_func = lambda td: td.total_seconds() * 1000)
1306
1288
host = notifychangeproperty(dbus.String, "Host")
1307
1289
timeout = notifychangeproperty(dbus.UInt64, "Timeout",
1309
timedelta_to_milliseconds)
1290
type_func = lambda td:
1291
td.total_seconds() * 1000)
1310
1292
extended_timeout = notifychangeproperty(
1311
1293
dbus.UInt64, "ExtendedTimeout",
1312
type_func = timedelta_to_milliseconds)
1294
type_func = lambda td: td.total_seconds() * 1000)
1313
1295
interval = notifychangeproperty(dbus.UInt64,
1316
timedelta_to_milliseconds)
1298
lambda td: td.total_seconds()
1317
1300
checker_command = notifychangeproperty(dbus.String, "Checker")
1319
1302
del notifychangeproperty
1347
1330
*args, **kwargs)
1349
1332
def start_checker(self, *args, **kwargs):
1350
old_checker = self.checker
1351
if self.checker is not None:
1352
old_checker_pid = self.checker.pid
1354
old_checker_pid = None
1333
old_checker_pid = getattr(self.checker, "pid", None)
1355
1334
r = Client.start_checker(self, *args, **kwargs)
1356
1335
# Only if new checker process was started
1357
1336
if (self.checker is not None
1367
1346
def approve(self, value=True):
1368
1347
self.approved = value
1369
gobject.timeout_add(timedelta_to_milliseconds
1370
(self.approval_duration),
1371
self._reset_approved)
1348
gobject.timeout_add(int(self.approval_duration.total_seconds()
1349
* 1000), self._reset_approved)
1372
1350
self.send_changedstate()
1374
1352
## D-Bus methods, signals & properties
1477
1455
access="readwrite")
1478
1456
def ApprovalDelay_dbus_property(self, value=None):
1479
1457
if value is None: # get
1480
return dbus.UInt64(self.approval_delay_milliseconds())
1458
return dbus.UInt64(self.approval_delay.total_seconds()
1481
1460
self.approval_delay = datetime.timedelta(0, 0, 0, value)
1483
1462
# ApprovalDuration - property
1485
1464
access="readwrite")
1486
1465
def ApprovalDuration_dbus_property(self, value=None):
1487
1466
if value is None: # get
1488
return dbus.UInt64(timedelta_to_milliseconds(
1489
self.approval_duration))
1467
return dbus.UInt64(self.approval_duration.total_seconds()
1490
1469
self.approval_duration = datetime.timedelta(0, 0, 0, value)
1492
1471
# Name - property
1558
1537
access="readwrite")
1559
1538
def Timeout_dbus_property(self, value=None):
1560
1539
if value is None: # get
1561
return dbus.UInt64(self.timeout_milliseconds())
1540
return dbus.UInt64(self.timeout.total_seconds() * 1000)
1562
1541
old_timeout = self.timeout
1563
1542
self.timeout = datetime.timedelta(0, 0, 0, value)
1564
1543
# Reschedule disabling
1575
1554
gobject.source_remove(self.disable_initiator_tag)
1576
1555
self.disable_initiator_tag = (
1577
1556
gobject.timeout_add(
1578
timedelta_to_milliseconds(self.expires - now),
1557
int((self.expires - now).total_seconds()
1558
* 1000), self.disable))
1581
1560
# ExtendedTimeout - property
1582
1561
@dbus_service_property(_interface, signature="t",
1583
1562
access="readwrite")
1584
1563
def ExtendedTimeout_dbus_property(self, value=None):
1585
1564
if value is None: # get
1586
return dbus.UInt64(self.extended_timeout_milliseconds())
1565
return dbus.UInt64(self.extended_timeout.total_seconds()
1587
1567
self.extended_timeout = datetime.timedelta(0, 0, 0, value)
1589
1569
# Interval - property
1591
1571
access="readwrite")
1592
1572
def Interval_dbus_property(self, value=None):
1593
1573
if value is None: # get
1594
return dbus.UInt64(self.interval_milliseconds())
1574
return dbus.UInt64(self.interval.total_seconds() * 1000)
1595
1575
self.interval = datetime.timedelta(0, 0, 0, value)
1596
1576
if getattr(self, "checker_initiator_tag", None) is None:
1630
1610
@dbus_service_property(_interface, signature="ay",
1631
1611
access="write", byte_arrays=True)
1632
1612
def Secret_dbus_property(self, value):
1633
self.secret = str(value)
1613
self.secret = bytes(value)
1702
1682
logger.debug("Protocol version: %r", line)
1704
1684
if int(line.strip().split()[0]) > 1:
1685
raise RuntimeError(line)
1706
1686
except (ValueError, IndexError, RuntimeError) as error:
1707
1687
logger.error("Unknown protocol version: %s", error)
1757
1737
if self.server.use_dbus:
1758
1738
# Emit D-Bus signal
1759
1739
client.NeedApproval(
1760
client.approval_delay_milliseconds(),
1761
client.approved_by_default)
1740
client.approval_delay.total_seconds()
1741
* 1000, client.approved_by_default)
1763
1743
logger.warning("Client %s was not approved",
1770
1750
#wait until timeout or approved
1771
1751
time = datetime.datetime.now()
1772
1752
client.changedstate.acquire()
1773
client.changedstate.wait(
1774
float(timedelta_to_milliseconds(delay)
1753
client.changedstate.wait(delay.total_seconds())
1776
1754
client.changedstate.release()
1777
1755
time2 = datetime.datetime.now()
1778
1756
if (time2 - time) >= delay:
1916
1894
def add_pipe(self, parent_pipe, proc):
1917
1895
"""Dummy function; override as necessary"""
1918
raise NotImplementedError
1896
raise NotImplementedError()
1921
1899
class IPv6_TCPServer(MultiprocessingMixInWithPipe,
1978
1956
self.socket.setsockopt(socket.SOL_SOCKET,
1979
1957
SO_BINDTODEVICE,
1980
str(self.interface + '\0'))
1958
(self.interface + "\0")
1981
1960
except socket.error as error:
1982
1961
if error.errno == errno.EPERM:
1983
1962
logger.error("No permission to bind to"
2186
2165
token_duration = Token(re.compile(r"P"), None,
2187
2166
frozenset((token_year, token_month,
2188
2167
token_day, token_time,
2190
2169
# Define starting values
2191
2170
value = datetime.timedelta() # Value so far
2192
2171
found_token = None
2193
followers = frozenset(token_duration,) # Following valid tokens
2172
followers = frozenset((token_duration,)) # Following valid tokens
2194
2173
s = duration # String left to parse
2195
2174
# Loop until end token is found
2196
2175
while found_token is not token_end:
2256
2235
elif suffix == "w":
2257
2236
delta = datetime.timedelta(0, 0, 0, 0, 0, 0, value)
2259
raise ValueError("Unknown suffix {0!r}"
2238
raise ValueError("Unknown suffix {!r}"
2260
2239
.format(suffix))
2261
except (ValueError, IndexError) as e:
2240
except IndexError as e:
2262
2241
raise ValueError(*(e.args))
2263
2242
timevalue += delta
2264
2243
return timevalue
2279
2258
# Close all standard open file descriptors
2280
2259
null = os.open(os.devnull, os.O_NOCTTY | os.O_RDWR)
2281
2260
if not stat.S_ISCHR(os.fstat(null).st_mode):
2282
raise OSError(errno.ENODEV,
2283
"{0} not a character device"
2261
raise OSError(errno.ENODEV, "{} not a character device"
2284
2262
.format(os.devnull))
2285
2263
os.dup2(null, sys.stdin.fileno())
2286
2264
os.dup2(null, sys.stdout.fileno())
2297
2275
parser = argparse.ArgumentParser()
2298
2276
parser.add_argument("-v", "--version", action="version",
2299
version = "%(prog)s {0}".format(version),
2277
version = "%(prog)s {}".format(version),
2300
2278
help="show version number and exit")
2301
2279
parser.add_argument("-i", "--interface", metavar="IF",
2302
2280
help="Bind to interface IF")
2335
2313
help="Directory to save/restore state in")
2336
2314
parser.add_argument("--foreground", action="store_true",
2337
2315
help="Run in foreground", default=None)
2316
parser.add_argument("--no-zeroconf", action="store_false",
2317
dest="zeroconf", help="Do not use Zeroconf",
2339
2320
options = parser.parse_args()
2341
2322
if options.check:
2324
fail_count, test_count = doctest.testmod()
2325
sys.exit(os.EX_OK if fail_count == 0 else 1)
2346
2327
# Default values for config file for server-global settings
2347
2328
server_defaults = { "interface": "",
2390
2372
for option in ("interface", "address", "port", "debug",
2391
2373
"priority", "servicename", "configdir",
2392
2374
"use_dbus", "use_ipv6", "debuglevel", "restore",
2393
"statedir", "socket", "foreground"):
2375
"statedir", "socket", "foreground", "zeroconf"):
2394
2376
value = getattr(options, option)
2395
2377
if value is not None:
2396
2378
server_settings[option] = value
2398
2380
# Force all strings to be unicode
2399
2381
for option in server_settings.keys():
2400
if type(server_settings[option]) is str:
2401
server_settings[option] = unicode(server_settings[option])
2382
if isinstance(server_settings[option], bytes):
2383
server_settings[option] = (server_settings[option]
2402
2385
# Force all boolean options to be boolean
2403
2386
for option in ("debug", "use_dbus", "use_ipv6", "restore",
2387
"foreground", "zeroconf"):
2405
2388
server_settings[option] = bool(server_settings[option])
2406
2389
# Debug implies foreground
2407
2390
if server_settings["debug"]:
2411
2394
##################################################################
2396
if (not server_settings["zeroconf"] and
2397
not (server_settings["port"]
2398
or server_settings["socket"] != "")):
2399
parser.error("Needs port or socket to work without"
2413
2402
# For convenience
2414
2403
debug = server_settings["debug"]
2415
2404
debuglevel = server_settings["debuglevel"]
2418
2407
stored_state_path = os.path.join(server_settings["statedir"],
2419
2408
stored_state_file)
2420
2409
foreground = server_settings["foreground"]
2410
zeroconf = server_settings["zeroconf"]
2423
2413
initlogger(debug, logging.DEBUG)
2431
2421
if server_settings["servicename"] != "Mandos":
2432
2422
syslogger.setFormatter(logging.Formatter
2433
('Mandos ({0}) [%(process)d]:'
2423
('Mandos ({}) [%(process)d]:'
2434
2424
' %(levelname)s: %(message)s'
2435
2425
.format(server_settings
2436
2426
["servicename"])))
2444
2434
global mandos_dbus_service
2445
2435
mandos_dbus_service = None
2438
if server_settings["socket"] != "":
2439
socketfd = server_settings["socket"]
2447
2440
tcp_server = MandosServer((server_settings["address"],
2448
2441
server_settings["port"]),
2453
2446
gnutls_priority=
2454
2447
server_settings["priority"],
2455
2448
use_dbus=use_dbus,
2456
socketfd=(server_settings["socket"]
2458
2450
if not foreground:
2459
2451
pidfilename = "/run/mandos.pid"
2452
if not os.path.isdir("/run/."):
2453
pidfilename = "/var/run/mandos.pid"
2462
2456
pidfile = open(pidfilename, "w")
2528
2522
use_dbus = False
2529
2523
server_settings["use_dbus"] = False
2530
2524
tcp_server.use_dbus = False
2531
protocol = avahi.PROTO_INET6 if use_ipv6 else avahi.PROTO_INET
2532
service = AvahiServiceToSyslog(name =
2533
server_settings["servicename"],
2534
servicetype = "_mandos._tcp",
2535
protocol = protocol, bus = bus)
2536
if server_settings["interface"]:
2537
service.interface = (if_nametoindex
2538
(str(server_settings["interface"])))
2526
protocol = avahi.PROTO_INET6 if use_ipv6 else avahi.PROTO_INET
2527
service = AvahiServiceToSyslog(name =
2528
server_settings["servicename"],
2529
servicetype = "_mandos._tcp",
2530
protocol = protocol, bus = bus)
2531
if server_settings["interface"]:
2532
service.interface = (if_nametoindex
2533
(server_settings["interface"]
2540
2536
global multiprocessing_manager
2541
2537
multiprocessing_manager = multiprocessing.Manager()
2565
2561
os.remove(stored_state_path)
2566
2562
except IOError as e:
2567
2563
if e.errno == errno.ENOENT:
2568
logger.warning("Could not load persistent state: {0}"
2564
logger.warning("Could not load persistent state: {}"
2569
2565
.format(os.strerror(e.errno)))
2571
2567
logger.critical("Could not load persistent state:",
2607
2603
if datetime.datetime.utcnow() >= client["expires"]:
2608
2604
if not client["last_checked_ok"]:
2609
2605
logger.warning(
2610
"disabling client {0} - Client never "
2606
"disabling client {} - Client never "
2611
2607
"performed a successful checker"
2612
2608
.format(client_name))
2613
2609
client["enabled"] = False
2614
2610
elif client["last_checker_status"] != 0:
2615
2611
logger.warning(
2616
"disabling client {0} - Client "
2617
"last checker failed with error code {1}"
2612
"disabling client {} - Client last"
2613
" checker failed with error code {}"
2618
2614
.format(client_name,
2619
2615
client["last_checker_status"]))
2620
2616
client["enabled"] = False
2633
2629
except PGPError:
2634
2630
# If decryption fails, we use secret from new settings
2635
logger.debug("Failed to decrypt {0} old secret"
2631
logger.debug("Failed to decrypt {} old secret"
2636
2632
.format(client_name))
2637
2633
client["secret"] = (
2638
2634
client_settings[client_name]["secret"])
2646
2642
clients_data[client_name] = client_settings[client_name]
2648
2644
# Create all client objects
2649
for client_name, client in clients_data.iteritems():
2645
for client_name, client in clients_data.items():
2650
2646
tcp_server.clients[client_name] = client_class(
2651
2647
name = client_name, settings = client,
2652
2648
server_settings = server_settings)
2756
2753
# A list of attributes that can not be pickled
2758
exclude = set(("bus", "changedstate", "secret",
2759
"checker", "server_settings"))
2755
exclude = { "bus", "changedstate", "secret",
2756
"checker", "server_settings" }
2760
2757
for name, typ in (inspect.getmembers
2761
2758
(dbus.service.Object)):
2762
2759
exclude.add(name)
2785
2782
except NameError:
2787
2784
if e.errno in (errno.ENOENT, errno.EACCES, errno.EEXIST):
2788
logger.warning("Could not save persistent state: {0}"
2785
logger.warning("Could not save persistent state: {}"
2789
2786
.format(os.strerror(e.errno)))
2791
2788
logger.warning("Could not save persistent state:",
2795
2792
# Delete all clients, and settings from config
2796
2793
while tcp_server.clients:
2820
2817
tcp_server.server_activate()
2822
2819
# Find out what port we got
2823
service.port = tcp_server.socket.getsockname()[1]
2821
service.port = tcp_server.socket.getsockname()[1]
2825
2823
logger.info("Now listening on address %r, port %d,"
2826
2824
" flowinfo %d, scope_id %d",
2832
2830
#service.interface = tcp_server.socket.getsockname()[3]
2835
# From the Avahi example code
2838
except dbus.exceptions.DBusException as error:
2839
logger.critical("D-Bus Exception", exc_info=error)
2842
# End of Avahi example code
2834
# From the Avahi example code
2837
except dbus.exceptions.DBusException as error:
2838
logger.critical("D-Bus Exception", exc_info=error)
2841
# End of Avahi example code
2844
2843
gobject.io_add_watch(tcp_server.fileno(), gobject.IO_IN,
2845
2844
lambda *args, **kwargs: