/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 21:45:14 UTC
  • mfrom: (24.1.13 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20080803214514-plvvkrpoitwsrxeg
Merge.

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
        
438
448
        # Note: gnutls.connection.X509Credentials is really a generic
439
449
        # GnuTLS certificate credentials object so long as no X.509
440
450
        # keys are added to it.  Therefore, we can use it here despite
592
602
                        unicode(error))
593
603
        raise AvahiGroupError("State changed: %s", str(error))
594
604
 
595
 
def if_nametoindex(interface, _func=[None]):
 
605
def if_nametoindex(interface):
596
606
    """Call the C function if_nametoindex(), or equivalent"""
597
 
    if _func[0] is not None:
598
 
        return _func[0](interface)
 
607
    global if_nametoindex
599
608
    try:
600
609
        if "ctypes.util" not in sys.modules:
601
610
            import ctypes.util
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
 
611
        if_nametoindex = ctypes.cdll.LoadLibrary\
 
612
            (ctypes.util.find_library("c")).if_nametoindex
611
613
    except (OSError, AttributeError):
612
614
        if "struct" not in sys.modules:
613
615
            import struct
614
616
        if "fcntl" not in sys.modules:
615
617
            import fcntl
616
 
        def the_hard_way(interface):
 
618
        def if_nametoindex(interface):
617
619
            "Get an interface index the hard way, i.e. using fcntl()"
618
620
            SIOCGIFINDEX = 0x8933  # From /usr/include/linux/sockios.h
619
621
            s = socket.socket()
622
624
            s.close()
623
625
            interface_index = struct.unpack("I", ifreq[16:20])[0]
624
626
            return interface_index
625
 
        _func[0] = the_hard_way
626
 
        return _func[0](interface)
 
627
    return if_nametoindex(interface)
627
628
 
628
629
 
629
630
def daemon(nochdir, noclose):