/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

merge +
mandosclient
        Added a adjustbuffer function.

Show diffs side-by-side

added added

removed removed

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