r26607: Fix reading of values and subkeys in Samba 3 registry files.
[ira/wip.git] / source / scripting / python / samba / samba3.py
index b4261f7c74f5c9bdebbfc39bde7872a0ba598f30..df94f3503c1cdead8ea197a353193350b2225775 100644 (file)
@@ -45,16 +45,36 @@ class Registry:
         data = self.tdb.get("%s\x00" % key)
         if data is None:
             return []
-        # FIXME: Parse data
-        return []
+        import struct
+        (num, ) = struct.unpack("<L", data[0:4])
+        keys = data[4:].split("\0")
+        assert keys[-1] == ""
+        keys.pop()
+        assert len(keys) == num
+        return keys
 
     def values(self, key):
         """Return a dictionary with the values set for a specific key."""
         data = self.tdb.get("%s/%s\x00" % (REGISTRY_VALUE_PREFIX, key))
         if data is None:
             return {}
-        # FIXME: Parse data
-        return {}
+        ret = {}
+        import struct
+        (num, ) = struct.unpack("<L", data[0:4])
+        data = data[4:]
+        for i in range(num):
+            # Value name
+            (name, data) = data.split("\0", 1)
+
+            (type, ) = struct.unpack("<L", data[0:4])
+            data = data[4:]
+            (value_len, ) = struct.unpack("<L", data[0:4])
+            data = data[4:]
+
+            ret[name] = (type, data[:value_len])
+            data = data[value_len:]
+
+        return ret
 
 
 class PolicyDatabase: