/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 server.py

  • Committer: Teddy Hogeborn
  • Date: 2008-08-02 10:48:24 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080802104824-fx0miwp9o4g9r31e
* plugbasedclient.c (struct process): New fields "eof", "completed",
                                      and "status".
  (handle_sigchld): New function.
  (main): Initialize "dir" to NULL to only closedir() it if necessary.
          Move "process_list" to be a global variable to be accessible
          by "handle_sigchld".  Make "handle_sigchld" handle SIGCHLD.
          Remove redundant check for NULL "dir".  Free "filename" when
          no longer used.  Block SIGCHLD around fork()/exec().
          Restore normal signals in child.  Only loop while running
          processes exist.  Print process buffer when the process is
          done and it has emitted EOF, not when it only emits EOF.
          Remove processes from list which exit non-cleanly.  In
          cleaning up, closedir() if necessary.  Bug fix: set next
          pointer correctly when freeing process list.

* plugins.d/passprompt.c (main): Do not ignore SIGQUIT.

Show diffs side-by-side

added added

removed removed

Lines of Context:
435
435
                     unicode(self.client_address))
436
436
        session = gnutls.connection.ClientSession\
437
437
                  (self.request, gnutls.connection.X509Credentials())
438
 
        
439
 
        line = self.request.makefile().readline()
440
 
        logger.debug(u"Protocol version: %r", line)
441
 
        try:
442
 
            if int(line.strip().split()[0]) > 1:
443
 
                raise RuntimeError
444
 
        except (ValueError, IndexError, RuntimeError), error:
445
 
            logger.error(u"Unknown protocol version: %s", error)
446
 
            return
447
 
        
448
438
        # Note: gnutls.connection.X509Credentials is really a generic
449
439
        # GnuTLS certificate credentials object so long as no X.509
450
440
        # keys are added to it.  Therefore, we can use it here despite
602
592
                        unicode(error))
603
593
        raise AvahiGroupError("State changed: %s", str(error))
604
594
 
605
 
def if_nametoindex(interface):
 
595
def if_nametoindex(interface, _func=[None]):
606
596
    """Call the C function if_nametoindex(), or equivalent"""
607
 
    global if_nametoindex
 
597
    if _func[0] is not None:
 
598
        return _func[0](interface)
608
599
    try:
609
600
        if "ctypes.util" not in sys.modules:
610
601
            import ctypes.util
611
 
        if_nametoindex = ctypes.cdll.LoadLibrary\
612
 
            (ctypes.util.find_library("c")).if_nametoindex
 
602
        while True:
 
603
            try:
 
604
                libc = ctypes.cdll.LoadLibrary\
 
605
                       (ctypes.util.find_library("c"))
 
606
                _func[0] = libc.if_nametoindex
 
607
                return _func[0](interface)
 
608
            except IOError, e:
 
609
                if e != errno.EINTR:
 
610
                    raise
613
611
    except (OSError, AttributeError):
614
612
        if "struct" not in sys.modules:
615
613
            import struct
616
614
        if "fcntl" not in sys.modules:
617
615
            import fcntl
618
 
        def if_nametoindex(interface):
 
616
        def the_hard_way(interface):
619
617
            "Get an interface index the hard way, i.e. using fcntl()"
620
618
            SIOCGIFINDEX = 0x8933  # From /usr/include/linux/sockios.h
621
619
            s = socket.socket()
624
622
            s.close()
625
623
            interface_index = struct.unpack("I", ifreq[16:20])[0]
626
624
            return interface_index
627
 
    return if_nametoindex(interface)
 
625
        _func[0] = the_hard_way
 
626
        return _func[0](interface)
628
627
 
629
628
 
630
629
def daemon(nochdir, noclose):