summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2012-11-11 11:35:02 +1100
committerAndrew Bartlett <abartlet@samba.org>2012-11-12 00:05:08 +1100
commitb4d8629f511005540cb1fbbbe9abfb278c064ba2 (patch)
tree447c440aa6ff47636aefcfdab5f8db9558bfb872 /source4/scripting
parentc06d602d7f3b8d3da972071a1b5392c6b145133f (diff)
downloadsamba-b4d8629f511005540cb1fbbbe9abfb278c064ba2.tar.gz
samba-b4d8629f511005540cb1fbbbe9abfb278c064ba2.tar.bz2
samba-b4d8629f511005540cb1fbbbe9abfb278c064ba2.zip
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>
Diffstat (limited to 'source4/scripting')
-rw-r--r--source4/scripting/python/samba/upgrade.py41
1 files changed, 24 insertions, 17 deletions
diff --git a/source4/scripting/python/samba/upgrade.py b/source4/scripting/python/samba/upgrade.py
index 786bb6518e..13d33c1442 100644
--- a/source4/scripting/python/samba/upgrade.py
+++ b/source4/scripting/python/samba/upgrade.py
@@ -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