/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 mandos

  • Committer: Björn Påhlsson
  • Date: 2011-11-24 19:27:53 UTC
  • mto: (518.2.5 persistent-state-gpgme)
  • mto: This revision was merged to the branch mainline in revision 524.
  • Revision ID: belorn@fukt.bsnet.se-20111124192753-y5jxlc1h3tcxpubc
First run of python-lint. Fixed some *obviously* bad code and turned
them into good code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
             (facility = logging.handlers.SysLogHandler.LOG_DAEMON,
94
94
              address = str("/dev/log")))
95
95
 
 
96
try:
 
97
    if_nametoindex = (ctypes.cdll.LoadLibrary
 
98
                      (ctypes.util.find_library("c"))
 
99
                      .if_nametoindex)
 
100
except (OSError, AttributeError):
 
101
    def if_nametoindex(interface):
 
102
        "Get an interface index the hard way, i.e. using fcntl()"
 
103
        SIOCGIFINDEX = 0x8933  # From /usr/include/linux/sockios.h
 
104
        with contextlib.closing(socket.socket()) as s:
 
105
            ifreq = fcntl.ioctl(s, SIOCGIFINDEX,
 
106
                                struct.pack(str("16s16x"),
 
107
                                            interface))
 
108
        interface_index = struct.unpack(str("I"),
 
109
                                        ifreq[16:20])[0]
 
110
        return interface_index
 
111
 
 
112
 
96
113
def initlogger(level=logging.WARNING):
97
114
    """init logger and add loglevel"""
98
115
    
230
247
            try:
231
248
                self.group.Free()
232
249
            except (dbus.exceptions.UnknownMethodException,
233
 
                    dbus.exceptions.DBusException) as e:
 
250
                    dbus.exceptions.DBusException):
234
251
                pass
235
252
            self.group = None
236
253
        self.remove()
764
781
        
765
782
        Note: Will not include properties with access="write".
766
783
        """
767
 
        all = {}
 
784
        properties = {}
768
785
        for name, prop in self._get_all_dbus_properties():
769
786
            if (interface_name
770
787
                and interface_name != prop._dbus_interface):
775
792
                continue
776
793
            value = prop()
777
794
            if not hasattr(value, "variant_level"):
778
 
                all[name] = value
 
795
                properties[name] = value
779
796
                continue
780
 
            all[name] = type(value)(value, variant_level=
781
 
                                    value.variant_level+1)
782
 
        return dbus.Dictionary(all, signature="sv")
 
797
            properties[name] = type(value)(value, variant_level=
 
798
                                           value.variant_level+1)
 
799
        return dbus.Dictionary(properties, signature="sv")
783
800
    
784
801
    @dbus.service.method(dbus.INTROSPECTABLE_IFACE,
785
802
                         out_signature="s",
1852
1869
    return timevalue
1853
1870
 
1854
1871
 
1855
 
def if_nametoindex(interface):
1856
 
    """Call the C function if_nametoindex(), or equivalent
1857
 
    
1858
 
    Note: This function cannot accept a unicode string."""
1859
 
    global if_nametoindex
1860
 
    try:
1861
 
        if_nametoindex = (ctypes.cdll.LoadLibrary
1862
 
                          (ctypes.util.find_library("c"))
1863
 
                          .if_nametoindex)
1864
 
    except (OSError, AttributeError):
1865
 
        logger.warning("Doing if_nametoindex the hard way")
1866
 
        def if_nametoindex(interface):
1867
 
            "Get an interface index the hard way, i.e. using fcntl()"
1868
 
            SIOCGIFINDEX = 0x8933  # From /usr/include/linux/sockios.h
1869
 
            with contextlib.closing(socket.socket()) as s:
1870
 
                ifreq = fcntl.ioctl(s, SIOCGIFINDEX,
1871
 
                                    struct.pack(str("16s16x"),
1872
 
                                                interface))
1873
 
            interface_index = struct.unpack(str("I"),
1874
 
                                            ifreq[16:20])[0]
1875
 
            return interface_index
1876
 
    return if_nametoindex(interface)
1877
 
 
1878
 
 
1879
1872
def daemon(nochdir = False, noclose = False):
1880
1873
    """See daemon(3).  Standard BSD Unix function.
1881
1874