-#!/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/>.
#
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):
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.
"""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."""
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
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])
def get_policy_db(self):
return PolicyDatabase(self.libdir_path("account_policy.tdb"))
-
+
def get_registry(self):
return Registry(self.libdir_path("registry.tdb"))