/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

mandosclient
        Droping privileges
        split gnutls function into global and session

* server.py (if_nametoindex): Redefine itself instead of using a
                              default keyword argument.

Show diffs side-by-side

added added

removed removed

Lines of Context:
602
602
                        unicode(error))
603
603
        raise AvahiGroupError("State changed: %s", str(error))
604
604
 
605
 
def if_nametoindex(interface, _func=[None]):
 
605
def if_nametoindex(interface):
606
606
    """Call the C function if_nametoindex(), or equivalent"""
607
 
    if _func[0] is not None:
608
 
        return _func[0](interface)
 
607
    global if_nametoindex
609
608
    try:
610
609
        if "ctypes.util" not in sys.modules:
611
610
            import ctypes.util
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
 
611
        if_nametoindex = ctypes.cdll.LoadLibrary\
 
612
            (ctypes.util.find_library("c")).if_nametoindex
621
613
    except (OSError, AttributeError):
622
614
        if "struct" not in sys.modules:
623
615
            import struct
624
616
        if "fcntl" not in sys.modules:
625
617
            import fcntl
626
 
        def the_hard_way(interface):
 
618
        def if_nametoindex(interface):
627
619
            "Get an interface index the hard way, i.e. using fcntl()"
628
620
            SIOCGIFINDEX = 0x8933  # From /usr/include/linux/sockios.h
629
621
            s = socket.socket()
632
624
            s.close()
633
625
            interface_index = struct.unpack("I", ifreq[16:20])[0]
634
626
            return interface_index
635
 
        _func[0] = the_hard_way
636
 
        return _func[0](interface)
 
627
    return if_nametoindex(interface)
637
628
 
638
629
 
639
630
def daemon(nochdir, noclose):