domain.py: Make schemaupgrade option work regardless of config
authorTim Beale <timbeale@catalyst.net.nz>
Thu, 5 Oct 2017 02:43:53 +0000 (15:43 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 14 Dec 2017 07:20:15 +0000 (08:20 +0100)
Currently the 'samba-tool domain schemaupgrade' command will only work
if the Samba config has the non-default option 'dsdb:schema update
allowed = yes'. The whole point of running this samba-tool option is to
upgrade the schema, so it would seem to make sense to bypass the setting
temporarily, in order to apply the schema updates successfully.

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/domain.py

index f6e315ac37d8de5123f47deff4da622d67e4a772..c34a438b7b4a0cc202205a894ed07d03fb0f0aec 100644 (file)
@@ -4037,6 +4037,7 @@ class cmd_domain_schema_upgrade(Command):
     def run(self, **kwargs):
         from samba.schema import Schema
 
+        updates_allowed_overriden = False
         sambaopts = kwargs.get("sambaopts")
         credopts = kwargs.get("credopts")
         versionpts = kwargs.get("versionopts")
@@ -4047,6 +4048,12 @@ class cmd_domain_schema_upgrade(Command):
 
         samdb = SamDB(url=H, session_info=system_session(), credentials=creds, lp=lp)
 
+        # we're not going to get far if the config doesn't allow schema updates
+        if lp.get("dsdb:schema update allowed") is None:
+            lp.set("dsdb:schema update allowed", "yes")
+            print("Temporarily overriding 'dsdb:schema update allowed' setting")
+            updates_allowed_overriden = True
+
         # work out the version of the target schema we're upgrading to
         end = Schema.get_version(target_schema)
 
@@ -4060,6 +4067,7 @@ class cmd_domain_schema_upgrade(Command):
 
         samdb.transaction_start()
         count = 0
+        error_encountered = False
 
         try:
             # Apply the schema updates needed to move to the new schema version
@@ -4076,6 +4084,12 @@ class cmd_domain_schema_upgrade(Command):
             print("Exception: %s" % e)
             print("Error encountered, aborting schema upgrade")
             samdb.transaction_cancel()
+            error_encountered = True
+
+        if updates_allowed_overriden:
+            lp.set("dsdb:schema update allowed", "no")
+
+        if error_encountered:
             raise CommandError('Failed to upgrade schema')
 
 class cmd_domain(SuperCommand):