1
0
mirror of https://github.com/samba-team/samba.git synced 2025-07-27 07:42:04 +03:00

samba-tool: Rework ldap attribute fetch in classicupgrade for missing attributes

Is is not required that these additional attributes be filled in, so
catch KeyError in both the nsswitch and ldap backend case.

We rework get_posix_attr_from_ldap_backend() so it raises KeyError
rather than trying to return None, and does not ignore other errors.

Andrew Bartlett

Tested-by: Chirana Gheorghita Eugeniu Theodor <office@adaptcom.ro>
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jelmer Vernooij <jelmer@samba.org>
This commit is contained in:
Andrew Bartlett
2012-11-11 11:35:02 +11:00
parent c06d602d7f
commit b4d8629f51

View File

@ -539,13 +539,14 @@ def get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, user, attr):
expression=("(&(objectClass=posixAccount)(uid=%s))"
% (user)), attrs=[attr])
except ldb.LdbError, e:
logger.warning("Failed to retrieve attribute %s for user %s, the error is: %s", attr, user, e)
raise ProvisioningError("Failed to retrieve attribute %s for user %s, the error is: %s", attr, user, e)
else:
if msg.count == 1:
if msg.count <= 1:
# This will raise KeyError (which is what we want) if there isn't a entry for this user
return msg[0][attr][0]
else:
logger.warning("LDAP entry for user %s contains more than one %s", user, attr)
return None
raise KeyError
def upgrade_from_samba3(samba3, logger, targetdir, session_info=None,
@ -794,23 +795,29 @@ Please fix this account before attempting to upgrade again
for entry in userlist:
username = entry['account_name']
if username in uids.keys():
if ldap:
homes[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "homeDirectory")
shells[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "loginShell")
pgids[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "gidNumber")
else:
try:
try:
if ldap:
homes[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "homeDirectory")
else:
homes[username] = pwd.getpwnam(username).pw_dir
except KeyError:
pass
try:
except KeyError:
pass
try:
if ldap:
shells[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "loginShell")
else:
shells[username] = pwd.getpwnam(username).pw_shell
except KeyError:
pass
try:
except KeyError:
pass
try:
if ldap:
pgids[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "gidNumber")
else:
pgids[username] = pwd.getpwnam(username).pw_gid
except KeyError:
pass
except KeyError:
pass
logger.info("Reading WINS database")
samba3_winsdb = None