/mandos/trunk

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

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2012-05-12 18:33:24 UTC
  • Revision ID: teddy@recompile.se-20120512183324-5kbaq316kyj329jk
* mandos (Client.start_checker): Remove undocumented support for "%%s"
                                 in the clients.conf "checker" option.
  (main): Use new .errno attribute of OSError.

Show diffs side-by-side

added added

removed removed

Lines of Context:
690
690
                                      self.current_checker_command)
691
691
        # Start a new checker if needed
692
692
        if self.checker is None:
 
693
            # Escape attributes for the shell
 
694
            escaped_attrs = dict(
 
695
                (attr, re.escape(unicode(getattr(self, attr))))
 
696
                for attr in
 
697
                self.runtime_expansions)
693
698
            try:
694
 
                # In case checker_command has exactly one % operator
695
 
                command = self.checker_command % self.host
696
 
            except TypeError:
697
 
                # Escape attributes for the shell
698
 
                escaped_attrs = dict(
699
 
                    (attr,
700
 
                     re.escape(unicode(str(getattr(self, attr, "")),
701
 
                                       errors=
702
 
                                       'replace')))
703
 
                    for attr in
704
 
                    self.runtime_expansions)
705
 
                
706
 
                try:
707
 
                    command = self.checker_command % escaped_attrs
708
 
                except TypeError as error:
709
 
                    logger.error('Could not format string "%s"',
710
 
                                 self.checker_command, exc_info=error)
711
 
                    return True # Try again later
 
699
                command = self.checker_command % escaped_attrs
 
700
            except TypeError as error:
 
701
                logger.error('Could not format string "%s"',
 
702
                             self.checker_command, exc_info=error)
 
703
                return True # Try again later
712
704
            self.current_checker_command = command
713
705
            try:
714
706
                logger.info("Starting checker %r for %s",
720
712
                self.checker = subprocess.Popen(command,
721
713
                                                close_fds=True,
722
714
                                                shell=True, cwd="/")
723
 
                self.checker_callback_tag = (gobject.child_watch_add
724
 
                                             (self.checker.pid,
725
 
                                              self.checker_callback,
726
 
                                              data=command))
727
 
                # The checker may have completed before the gobject
728
 
                # watch was added.  Check for this.
729
 
                pid, status = os.waitpid(self.checker.pid, os.WNOHANG)
730
 
                if pid:
731
 
                    gobject.source_remove(self.checker_callback_tag)
732
 
                    self.checker_callback(pid, status, command)
733
715
            except OSError as error:
734
716
                logger.error("Failed to start subprocess",
735
717
                             exc_info=error)
 
718
            self.checker_callback_tag = (gobject.child_watch_add
 
719
                                         (self.checker.pid,
 
720
                                          self.checker_callback,
 
721
                                          data=command))
 
722
            # The checker may have completed before the gobject
 
723
            # watch was added.  Check for this.
 
724
            pid, status = os.waitpid(self.checker.pid, os.WNOHANG)
 
725
            if pid:
 
726
                gobject.source_remove(self.checker_callback_tag)
 
727
                self.checker_callback(pid, status, command)
736
728
        # Re-run this periodically if run by gobject.timeout_add
737
729
        return True
738
730
    
2295
2287
        os.setgid(gid)
2296
2288
        os.setuid(uid)
2297
2289
    except OSError as error:
2298
 
        if error[0] != errno.EPERM:
 
2290
        if error.errno != errno.EPERM:
2299
2291
            raise error
2300
2292
    
2301
2293
    if debug: