samba3-python: Add methods to get any entry (user/group) and its sid from idmap
authorAmitay Isaacs <amitay@gmail.com>
Thu, 18 Aug 2011 05:15:20 +0000 (15:15 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 19 Aug 2011 06:35:04 +0000 (16:35 +1000)
This is required in upgrade_s3 script to migrate idmap database from s3 to s4

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
source4/scripting/python/samba/samba3/__init__.py

index 55e9b18f246c7b5cc4c5f08adc2e367418a9fd9d..f5dde44aa0bc0fca95e533c4446882377cdae887 100644 (file)
@@ -208,6 +208,14 @@ class IdmapDatabase(TdbDatabase):
     def _check_version(self):
         assert fetch_int32(self.tdb, "IDMAP_VERSION\0") == IDMAP_VERSION_V2
 
+    def ids(self):
+        """Retrieve a list of all ids in this database."""
+        for k in self.tdb.iterkeys():
+            if k.startswith(IDMAP_USER_PREFIX):
+                yield k.rstrip("\0").split(" ")
+            if k.startswith(IDMAP_GROUP_PREFIX):
+                yield k.rstrip("\0").split(" ")
+
     def uids(self):
         """Retrieve a list of all uids in this database."""
         for k in self.tdb.iterkeys():
@@ -220,6 +228,12 @@ class IdmapDatabase(TdbDatabase):
             if k.startswith(IDMAP_GROUP_PREFIX):
                 yield int(k[len(IDMAP_GROUP_PREFIX):].rstrip("\0"))
 
+    def get_sid(self, xid, id_type):
+        data = self.tdb.get("%s %s\0" % (id_type, str(xid)))
+        if data is None:
+            return data
+        return data.rstrip("\0")
+
     def get_user_sid(self, uid):
         """Retrieve the SID associated with a particular uid.