/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2008-08-12 19:47:50 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080812194750-uebbpk9ynxt3sjnt
* initramfs-tools-hook (gpg): Added "--no-random-seed-file" and
                              "--no-default-keyring".  Bug fix: moved
                              "--import" to end.

* mandos-keygen (gpg): Added "--no-options".

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
        self.domain = domain
120
120
        self.host = host
121
121
        self.rename_count = 0
122
 
        self.max_renames = max_renames
123
122
    def rename(self):
124
123
        """Derived from the Avahi example code"""
125
124
        if self.rename_count >= self.max_renames:
126
125
            logger.critical(u"No suitable service name found after %i"
127
126
                            u" retries, exiting.", rename_count)
128
127
            raise AvahiServiceError("Too many renames")
129
 
        self.name = server.GetAlternativeServiceName(self.name)
130
 
        logger.info(u"Changing name to %r ...", str(self.name))
 
128
        name = server.GetAlternativeServiceName(name)
 
129
        logger.error(u"Changing name to %r ...", name)
131
130
        syslogger.setFormatter(logging.Formatter\
132
131
                               ('Mandos (%s): %%(levelname)s:'
133
 
                               ' %%(message)s' % self.name))
 
132
                               ' %%(message)s' % name))
134
133
        self.remove()
135
134
        self.add()
136
135
        self.rename_count += 1
337
336
            try:
338
337
                logger.info(u"Starting checker %r for %s",
339
338
                            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.)
344
339
                self.checker = subprocess.Popen(command,
345
340
                                                close_fds=True,
346
341
                                                shell=True, cwd="/")
347
342
                self.checker_callback_tag = gobject.child_watch_add\
348
343
                                            (self.checker.pid,
349
344
                                             self.checker_callback)
350
 
            except OSError, error:
 
345
            except subprocess.OSError, error:
351
346
                logger.error(u"Failed to start subprocess: %s",
352
347
                             error)
353
348
        # Re-run this periodically if run by gobject.timeout_add
567
562
    datetime.timedelta(1)
568
563
    >>> string_to_delta(u'1w')
569
564
    datetime.timedelta(7)
570
 
    >>> string_to_delta('5m 30s')
571
 
    datetime.timedelta(0, 330)
572
565
    """
573
 
    timevalue = datetime.timedelta(0)
574
 
    for s in interval.split():
575
 
        try:
576
 
            suffix=unicode(s[-1])
577
 
            value=int(s[:-1])
578
 
            if suffix == u"d":
579
 
                delta = datetime.timedelta(value)
580
 
            elif suffix == u"s":
581
 
                delta = datetime.timedelta(0, value)
582
 
            elif suffix == u"m":
583
 
                delta = datetime.timedelta(0, 0, 0, 0, value)
584
 
            elif suffix == u"h":
585
 
                delta = datetime.timedelta(0, 0, 0, 0, 0, value)
586
 
            elif suffix == u"w":
587
 
                delta = datetime.timedelta(0, 0, 0, 0, 0, 0, value)
588
 
            else:
589
 
                raise ValueError
590
 
        except (ValueError, IndexError):
 
566
    try:
 
567
        suffix=unicode(interval[-1])
 
568
        value=int(interval[:-1])
 
569
        if suffix == u"d":
 
570
            delta = datetime.timedelta(value)
 
571
        elif suffix == u"s":
 
572
            delta = datetime.timedelta(0, value)
 
573
        elif suffix == u"m":
 
574
            delta = datetime.timedelta(0, 0, 0, 0, value)
 
575
        elif suffix == u"h":
 
576
            delta = datetime.timedelta(0, 0, 0, 0, 0, value)
 
577
        elif suffix == u"w":
 
578
            delta = datetime.timedelta(0, 0, 0, 0, 0, 0, value)
 
579
        else:
591
580
            raise ValueError
592
 
        timevalue += delta
593
 
    return timevalue
 
581
    except (ValueError, IndexError):
 
582
        raise ValueError
 
583
    return delta
594
584
 
595
585
 
596
586
def server_state_changed(state):
709
699
    server_config = ConfigParser.SafeConfigParser(server_defaults)
710
700
    del server_defaults
711
701
    server_config.read(os.path.join(options.configdir, "mandos.conf"))
 
702
    server_section = "server"
712
703
    # Convert the SafeConfigParser object to a dict
713
 
    server_settings = server_config.defaults()
 
704
    server_settings = dict(server_config.items(server_section))
714
705
    # Use getboolean on the boolean config option
715
706
    server_settings["debug"] = server_config.getboolean\
716
 
                               ("DEFAULT", "debug")
 
707
                               (server_section, "debug")
717
708
    del server_config
718
709
    
719
710
    # Override the settings from the config file with command line
741
732
    # Parse config file with clients
742
733
    client_defaults = { "timeout": "1h",
743
734
                        "interval": "5m",
744
 
                        "checker": "fping -q -- %(host)s",
745
 
                        "host": "",
 
735
                        "checker": "fping -q -- %%(host)s",
746
736
                        }
747
737
    client_config = ConfigParser.SafeConfigParser(client_defaults)
748
738
    client_config.read(os.path.join(server_settings["configdir"],
782
772
        logger.critical(u"No clients defined")
783
773
        sys.exit(1)
784
774
    
785
 
    if debug:
786
 
        # Redirect stdin so all checkers get /dev/null
787
 
        null = os.open(os.path.devnull, os.O_NOCTTY | os.O_RDWR)
788
 
        os.dup2(null, sys.stdin.fileno())
789
 
        if null > 2:
790
 
            os.close(null)
791
 
    else:
792
 
        # No console logging
 
775
    if not debug:
793
776
        logger.removeHandler(console)
794
 
        # Close all input and output, do double fork, etc.
795
777
        daemon()
796
778
    
797
779
    pidfilename = "/var/run/mandos/mandos.pid"