119
119
self.domain = domain
121
121
self.rename_count = 0
122
self.max_renames = max_renames
122
123
def rename(self):
123
124
"""Derived from the Avahi example code"""
124
125
if self.rename_count >= self.max_renames:
125
126
logger.critical(u"No suitable service name found after %i"
126
127
u" retries, exiting.", rename_count)
127
128
raise AvahiServiceError("Too many renames")
128
name = server.GetAlternativeServiceName(name)
129
logger.error(u"Changing name to %r ...", name)
129
self.name = server.GetAlternativeServiceName(self.name)
130
logger.info(u"Changing name to %r ...", str(self.name))
130
131
syslogger.setFormatter(logging.Formatter\
131
132
('Mandos (%s): %%(levelname)s:'
132
' %%(message)s' % name))
133
' %%(message)s' % self.name))
135
136
self.rename_count += 1
337
338
logger.info(u"Starting checker %r for %s",
338
339
command, self.name)
340
# We don't need to redirect stdout and stderr, since
341
# in normal mode, that is already done by daemon(),
342
# and in debug mode we don't want to. (Stdin is
343
# always replaced by /dev/null.)
339
344
self.checker = subprocess.Popen(command,
341
346
shell=True, cwd="/")
342
347
self.checker_callback_tag = gobject.child_watch_add\
343
348
(self.checker.pid,
344
349
self.checker_callback)
345
except subprocess.OSError, error:
350
except OSError, error:
346
351
logger.error(u"Failed to start subprocess: %s",
348
353
# Re-run this periodically if run by gobject.timeout_add
405
410
gnutls.library.functions.gnutls_openpgp_crt_import\
406
411
(crt, ctypes.byref(datum),
407
412
gnutls.library.constants.GNUTLS_OPENPGP_FMT_RAW)
413
# Verify the self signature in the key
414
crtverify = ctypes.c_uint();
415
gnutls.library.functions.gnutls_openpgp_crt_verify_self\
416
(crt, ctypes.c_uint(0), ctypes.byref(crtverify))
418
gnutls.library.functions.gnutls_openpgp_crt_deinit(crt)
419
raise gnutls.errors.CertificateSecurityError("Verify failed")
408
420
# New buffer for the fingerprint
409
421
buffer = ctypes.create_string_buffer(20)
410
422
buffer_length = ctypes.c_size_t()
562
574
datetime.timedelta(1)
563
575
>>> string_to_delta(u'1w')
564
576
datetime.timedelta(7)
577
>>> string_to_delta('5m 30s')
578
datetime.timedelta(0, 330)
567
suffix=unicode(interval[-1])
568
value=int(interval[:-1])
570
delta = datetime.timedelta(value)
572
delta = datetime.timedelta(0, value)
574
delta = datetime.timedelta(0, 0, 0, 0, value)
576
delta = datetime.timedelta(0, 0, 0, 0, 0, value)
578
delta = datetime.timedelta(0, 0, 0, 0, 0, 0, value)
580
timevalue = datetime.timedelta(0)
581
for s in interval.split():
583
suffix=unicode(s[-1])
586
delta = datetime.timedelta(value)
588
delta = datetime.timedelta(0, value)
590
delta = datetime.timedelta(0, 0, 0, 0, value)
592
delta = datetime.timedelta(0, 0, 0, 0, 0, value)
594
delta = datetime.timedelta(0, 0, 0, 0, 0, 0, value)
597
except (ValueError, IndexError):
581
except (ValueError, IndexError):
586
603
def server_state_changed(state):
699
716
server_config = ConfigParser.SafeConfigParser(server_defaults)
700
717
del server_defaults
701
718
server_config.read(os.path.join(options.configdir, "mandos.conf"))
702
server_section = "server"
703
719
# Convert the SafeConfigParser object to a dict
704
server_settings = dict(server_config.items(server_section))
720
server_settings = server_config.defaults()
705
721
# Use getboolean on the boolean config option
706
722
server_settings["debug"] = server_config.getboolean\
707
(server_section, "debug")
708
724
del server_config
710
726
# Override the settings from the config file with command line
732
748
# Parse config file with clients
733
749
client_defaults = { "timeout": "1h",
734
750
"interval": "5m",
735
"checker": "fping -q -- %%(host)s",
751
"checker": "fping -q -- %(host)s",
737
754
client_config = ConfigParser.SafeConfigParser(client_defaults)
738
755
client_config.read(os.path.join(server_settings["configdir"],
772
789
logger.critical(u"No clients defined")
793
# Redirect stdin so all checkers get /dev/null
794
null = os.open(os.path.devnull, os.O_NOCTTY | os.O_RDWR)
795
os.dup2(null, sys.stdin.fileno())
776
800
logger.removeHandler(console)
801
# Close all input and output, do double fork, etc.
779
804
pidfilename = "/var/run/mandos/mandos.pid"