tdb2: create tdb2 versions of various testing TDBs.
[amitay/samba.git] / source4 / scripting / python / samba / samba3.py
index dff3671dbbba5483a5b7ddcd4514c3d0eb5bbfd3..ae5b20edd27cfab0b05ff9acc99d992eee8b50df 100644 (file)
@@ -1,18 +1,16 @@
-#!/usr/bin/python
-
 # Unix SMB/CIFS implementation.
 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
-#   
+#
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
-#   
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-#   
+#
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
@@ -52,9 +50,12 @@ class TdbDatabase(object):
     def __init__(self, file):
         """Open a file.
 
-        :param file: Path of the file to open.
+        :param file: Path of the file to open (appending "2" if TDB2 enabled).
         """
-        self.tdb = tdb.Tdb(file, flags=os.O_RDONLY)
+        if tdb.__version__.startswith("2"):
+            self.tdb = tdb.Tdb(file + "2", flags=os.O_RDONLY)
+        else:
+            self.tdb = tdb.Tdb(file, flags=os.O_RDONLY)
         self._check_version()
 
     def _check_version(self):
@@ -67,7 +68,7 @@ class TdbDatabase(object):
 
 class Registry(TdbDatabase):
     """Simple read-only support for reading the Samba3 registry.
-    
+
     :note: This object uses the same syntax for registry key paths as 
         Samba 3. This particular format uses forward slashes for key path 
         separators and abbreviations for the predefined key names. 
@@ -509,7 +510,7 @@ class TdbSam(TdbDatabase):
     """Samba 3 TDB passdb backend reader."""
     def _check_version(self):
         self.version = fetch_uint32(self.tdb, "INFO/version\0") or 0
-        assert self.version in (0, 1, 2, 3)
+        assert self.version in (0, 1, 2)
 
     def usernames(self):
         """Iterate over the usernames in this Tdb database."""
@@ -592,10 +593,9 @@ class TdbSam(TdbDatabase):
         for entry in hours:
             for i in range(8):
                 user.hours.append(ord(entry) & (2 ** i) == (2 ** i))
-        # FIXME
-        #(user.bad_password_count, data) = unpack_uint16(data)
-        #(user.logon_count, data) = unpack_uint16(data)
-        #(user.unknown_6, data) = unpack_uint32(data)
+        (user.bad_password_count, data) = unpack_uint16(data)
+        (user.logon_count, data) = unpack_uint16(data)
+        (user.unknown_6, data) = unpack_uint32(data)
         assert len(data) == 0
         return user
 
@@ -684,7 +684,7 @@ class ParamFile(object):
         section = None
         for i, l in enumerate(open(filename, 'r').xreadlines()):
             l = l.strip()
-            if not l:
+            if not l or l[0] == '#' or l[0] == ';':
                 continue
             if l[0] == "[" and l[-1] == "]":
                 section = self._sanitize_name(l[1:-1])
@@ -770,7 +770,7 @@ class Samba3(object):
 
     def get_policy_db(self):
         return PolicyDatabase(self.libdir_path("account_policy.tdb"))
-    
+
     def get_registry(self):
         return Registry(self.libdir_path("registry.tdb"))