s4:provision Make setting the domain SID in the self join optional
[abartlet/samba.git/.git] / source4 / scripting / python / samba / provision.py
index b5e8867e16c2d32d0da5303d32af2561cecfdb22..2e7843ac03a3716e1104330548443ce433224c88 100644 (file)
@@ -53,6 +53,7 @@ from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError
 from ms_display_specifiers import read_ms_ldif
 from schema import Schema
 from provisionbackend import LDBBackend, ExistingBackend, FDSBackend, OpenLDAPBackend
+from provisionexceptions import ProvisioningError, InvalidNetbiosName
 from signal import SIGTERM
 from dcerpc.misc import SEC_CHAN_BDC, SEC_CHAN_WKSTA
 
@@ -153,15 +154,6 @@ DEFAULTSITE = "Default-First-Site-Name"
 
 # Exception classes
 
-class ProvisioningError(Exception):
-    """A generic provision error."""
-
-class InvalidNetbiosName(Exception):
-    """A specified name was not a valid NetBIOS name."""
-    def __init__(self, name):
-        super(InvalidNetbiosName, self).__init__("The name '%r' is not a valid NetBIOS name" % name)
-
-
 class ProvisionPaths(object):
     def __init__(self):
         self.shareconf = None
@@ -580,7 +572,7 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info,
 
         
 def secretsdb_self_join(secretsdb, domain, 
-                        netbiosname, domainsid, machinepass, 
+                        netbiosname, machinepass, domainsid=None,
                         realm=None, dnsdomain=None,
                         keytab_path=None, 
                         key_version_number=1,
@@ -615,7 +607,8 @@ def secretsdb_self_join(secretsdb, domain,
     msg["secret"] = [machinepass]
     msg["samAccountName"] = ["%s$" % netbiosname]
     msg["secureChannelType"] = [str(secure_channel_type)]
-    msg["objectSid"] = [ndr_pack(domainsid)]
+    if domainsid is not None:
+        msg["objectSid"] = [ndr_pack(domainsid)]
     
     res = secretsdb.search(base="cn=Primary Domains", 
                            attrs=attrs, 
@@ -1138,6 +1131,8 @@ def provision(setup_dir, message, session_info,
 
     if not os.path.exists(paths.private_dir):
         os.mkdir(paths.private_dir)
+    if not os.path.exists(os.path.join(paths.private_dir,"tls")):
+        os.mkdir(os.path.join(paths.private_dir,"tls"))
 
     ldapi_url = "ldapi://%s" % urllib.quote(paths.s4_ldapi_path, safe="")
     
@@ -1273,7 +1268,7 @@ def provision(setup_dir, message, session_info,
 
         # Only make a zone file on the first DC, it should be replicated with DNS replication
         if serverrole == "domain controller":
-            secretsdb_self_join(secrets_ldb, domain=domain,
+            secretsdb_self_join(secrets_ldb, domain=names.domain,
                                 realm=names.realm,
                                 dnsdomain=names.dnsdomain,
                                 netbiosname=names.netbiosname,