samba-tool domain classicupgrade: Do not mix python-samdb transactions and passdb...
authorAndrew Bartlett <abartlet@samba.org>
Fri, 23 Mar 2018 00:05:55 +0000 (13:05 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 6 Apr 2018 00:08:44 +0000 (02:08 +0200)
This worked previously because we knew the same tdb was in use under the hood,
but now that nested TDB transactions are banned this breaks, and it breaks for
LMDB.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
python/samba/upgrade.py

index ff470665fe9597904aa6e40df0163560743c641c..e3fa376e05351ea136d705752edb8780b02bd360 100644 (file)
@@ -785,38 +785,28 @@ Please fix this account before attempting to upgrade again
     result.samdb.transaction_commit()
 
     logger.info("Adding users")
-    # Start a new transaction (should speed this up a little, due to index churn)
-    result.samdb.transaction_start()
-
-    try:
-        # Export users to samba4 backend
-        logger.info("Importing users")
-        for username in userdata:
-            if username.lower() == 'administrator':
-                if userdata[username].user_sid != dom_sid(str(domainsid) + "-500"):
-                    logger.error("User 'Administrator' in your existing directory has SID %s, expected it to be %s" % (userdata[username].user_sid, dom_sid(str(domainsid) + "-500")))
-                    raise ProvisioningError("User 'Administrator' in your existing directory does not have SID ending in -500")
-            if username.lower() == 'root':
-                if userdata[username].user_sid == dom_sid(str(domainsid) + "-500"):
-                    logger.warn('User root has been replaced by Administrator')
-                else:
-                    logger.warn('User root has been kept in the directory, it should be removed in favour of the Administrator user')
 
-            s4_passdb.add_sam_account(userdata[username])
-            if username in uids:
-                add_ad_posix_idmap_entry(result.samdb, userdata[username].user_sid, uids[username], "ID_TYPE_UID", logger)
-                if (username in homes) and (homes[username] is not None) and \
-                   (username in shells) and (shells[username] is not None) and \
-                   (username in pgids) and (pgids[username] is not None):
-                    add_posix_attrs(samdb=result.samdb, sid=userdata[username].user_sid, name=username, nisdomain=domainname.lower(), xid_type="ID_TYPE_UID", home=homes[username], shell=shells[username], pgid=pgids[username], logger=logger)
+    # Export users to samba4 backend
+    logger.info("Importing users")
+    for username in userdata:
+        if username.lower() == 'administrator':
+            if userdata[username].user_sid != dom_sid(str(domainsid) + "-500"):
+                logger.error("User 'Administrator' in your existing directory has SID %s, expected it to be %s" % (userdata[username].user_sid, dom_sid(str(domainsid) + "-500")))
+                raise ProvisioningError("User 'Administrator' in your existing directory does not have SID ending in -500")
+        if username.lower() == 'root':
+            if userdata[username].user_sid == dom_sid(str(domainsid) + "-500"):
+                logger.warn('User root has been replaced by Administrator')
+            else:
+                logger.warn('User root has been kept in the directory, it should be removed in favour of the Administrator user')
 
-    except:
-        # We need this, so that we do not give even more errors due to not cancelling the transaction
-        result.samdb.transaction_cancel()
-        raise
+        s4_passdb.add_sam_account(userdata[username])
+        if username in uids:
+            add_ad_posix_idmap_entry(result.samdb, userdata[username].user_sid, uids[username], "ID_TYPE_UID", logger)
+            if (username in homes) and (homes[username] is not None) and \
+               (username in shells) and (shells[username] is not None) and \
+               (username in pgids) and (pgids[username] is not None):
+                add_posix_attrs(samdb=result.samdb, sid=userdata[username].user_sid, name=username, nisdomain=domainname.lower(), xid_type="ID_TYPE_UID", home=homes[username], shell=shells[username], pgid=pgids[username], logger=logger)
 
-    logger.info("Committing 'add users' transaction to disk")
-    result.samdb.transaction_commit()
 
     logger.info("Adding users to groups")
     # Start a new transaction (should speed this up a little, due to index churn)