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

  • Committer: Teddy Hogeborn
  • Date: 2008-08-03 03:33:56 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080803033356-6aemgj0g0hoz91ow
* plugins.d/mandosclient.c (pgp_packet_decrypt): Renamed variables.
                                                 On debug, show
                                                 decrypted plaintext
                                                 in hexadecimal.  Free
                                                 the GPGME data
                                                 buffers even on
                                                 errors.

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):