class LdapSam(object):
"""Samba 3 LDAP passdb backend reader."""
def __init__(self, url):
- self.ldap_url = ldap_url
+ self.ldap_url = url
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)
+ assert self.version in (0, 1, 2, 3)
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))
- (user.bad_password_count, data) = unpack_uint16(data)
- (user.logon_count, data) = unpack_uint16(data)
- (user.unknown_6, data) = unpack_uint32(data)
+ # FIXME (reactivate also the tests in tests/samba3.py after fixing this)
+ #(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
Does not use a parameter table, unlike the "normal".
"""
- def __init__(self):
- self._sections = {}
+ def __init__(self, sections=None):
+ self._sections = sections or {}
def _sanitize_name(self, name):
return name.strip().lower().replace(" ","")
+ def __repr__(self):
+ return "ParamFile(%r)" % self._sections
+
def read(self, filename):
"""Read a file.
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:-2])
+ section = self._sanitize_name(l[1:-1])
self._sections.setdefault(section, {})
elif "=" in l:
(k, v) = l.split("=", 1)
self._sections[section][self._sanitize_name(k)] = v
else:
- raise Error("Unable to parser line %d: %r" % (i+1,l))
+ raise Exception("Unable to parser line %d: %r" % (i+1,l))
def get(self, param, section=None):
"""Return the value of a parameter.
if not section in self._sections:
return None
param = self._sanitize_name(param)
- return self._sections[section].get(param)
+ if not param in self._sections[section]:
+ return None
+ return self._sections[section][param].strip()
def __getitem__(self, section):
return self._sections[section]
def get_sam_db(self):
lp = self.get_conf()
- backends = str(lp.get("passdb backend")).split(" ")
+ backends = (lp.get("passdb backend") or "").split(" ")
if ":" in backends[0]:
(name, location) = backends[0].split(":", 2)
else: