Convert some more files to GPLv3.
[jra/samba/.git] / source4 / scripting / libjs / provision.js
index ca0fedf97b97b64144bd5f705ac6225941f0769c..51e2785762bd79a29c2beba5b478f08066f80a05 100644 (file)
@@ -1,7 +1,7 @@
 /*
        backend code for provisioning a Samba4 server
        Copyright Andrew Tridgell 2005
-       Released under the GNU GPL v2 or later
+       Released under the GNU GPL version 3 or later
 */
 
 sys = sys_init();
@@ -162,7 +162,7 @@ function ldb_erase(info, ldb)
        /* delete the specials */
        ldb.del("@INDEXLIST");
        ldb.del("@ATTRIBUTES");
-       ldb.del("@SUBCLASSES");
+       ldb.del("@OPTIONS");
        ldb.del("@MODULES");
        ldb.del("@PARTITION");
        ldb.del("@KLUDGEACL");
@@ -170,7 +170,7 @@ function ldb_erase(info, ldb)
        /* and the rest */
        attrs = new Array("dn");
        var basedn = "";
-       var res = ldb.search("(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", basedn, ldb.SCOPE_SUBTREE, attrs);
+       var res = ldb.search("(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))", basedn, ldb.SCOPE_SUBTREE, attrs);
        var i;
        if (res.error != 0) {
                ldb_delete(info, ldb);
@@ -180,7 +180,7 @@ function ldb_erase(info, ldb)
                ldb.del(res.msgs[i].dn);
        }
 
-       var res = ldb.search("(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", basedn, ldb.SCOPE_SUBTREE, attrs);
+       var res = ldb.search("(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))", basedn, ldb.SCOPE_SUBTREE, attrs);
        if (res.error != 0 || res.msgs.length != 0) {
                ldb_delete(info, ldb);
                return;
@@ -198,14 +198,17 @@ function ldb_erase_partitions(info, ldb, ldapbackend)
        var j;
 
        var res = ldb.search("(objectClass=*)", "", ldb.SCOPE_BASE, rootDSE_attrs);
-       assert(res.error == 0);
+       if (res.error != 0) {
+               info.message("rootdse search failed: " + res.errstr + "\n");
+               assert(res.error == 0);
+       }
        assert(res.msgs.length == 1);
        if (typeof(res.msgs[0].namingContexts) == "undefined") {
                return;
        }       
        for (j=0; j<res.msgs[0].namingContexts.length; j++) {
-               var anything = "(|(objectclass=*)(dn=*))";
-               var attrs = new Array("dn");
+               var anything = "(|(objectclass=*)(distinguishedName=*))";
+               var attrs = new Array("distinguishedName");
                var basedn = res.msgs[0].namingContexts[j];
                var k;
                var previous_remaining = 1;
@@ -221,8 +224,12 @@ function ldb_erase_partitions(info, ldb, ldapbackend)
                        var res2 = ldb.search(anything, basedn, ldb.SCOPE_SUBTREE, attrs);
                        var i;
                        if (res2.error != 0) {
-                               info.message("ldb search failed: " + res.errstr + "\n");
-                               continue;
+                               if (res2.error == 32) {
+                                       break;
+                               } else {
+                                       info.message("ldb search(2) failed: " + res2.errstr + "\n");
+                                       continue;
+                               }
                        }
                        previous_remaining = current_remaining;
                        current_remaining = res2.msgs.length;
@@ -232,7 +239,7 @@ function ldb_erase_partitions(info, ldb, ldapbackend)
                        
                        var res3 = ldb.search(anything, basedn, ldb.SCOPE_SUBTREE, attrs);
                        if (res3.error != 0) {
-                               info.message("ldb search failed: " + res.errstr + "\n");
+                               info.message("ldb search(3) failed: " + res3.errstr + "\n");
                                continue;
                        }
                        if (res3.msgs.length != 0) {
@@ -356,6 +363,11 @@ function setup_file(template, message, fname, subobj)
        var f = fname;
        var src = lp.get("setup directory") + "/" + template;
 
+       if (! sys.stat(src)) {
+               message("Template file not found: %s\n",src);
+               assert(0);
+       }
+
        sys.unlink(f);
 
        var data = sys.file_load(src);
@@ -374,19 +386,22 @@ function provision_default_paths(subobj)
        var dnsdomain = strlower(subobj.REALM);
        var lp = loadparm_init();
        var paths = new Object();
-       paths.smbconf = lp.get("config file");
+       paths.smbconf = lp.filename()
        paths.shareconf = lp.get("private dir") + "/" + "share.ldb";
        paths.samdb = lp.get("sam database");
+       paths.idmapdb = lp.get("idmap database");
        paths.secrets = lp.get("secrets database");
+       paths.templates = lp.get("private dir") + "/" + "templates.ldb";
        paths.keytab = "secrets.keytab";
        paths.dns_keytab = "dns.keytab";
+       paths.dns_keytab_abs = lp.get("private dir") + "/" + paths.dns_keytab;
        paths.dns = lp.get("private dir") + "/" + dnsdomain + ".zone";
        paths.named_conf = lp.get("private dir") + "/named.conf";
        paths.winsdb = "wins.ldb";
        paths.ldapdir = lp.get("private dir") + "/ldap";
-       paths.ldap_basedn_ldif = paths.ldapdir + "/" + dnsdomain + ".ldif";
-       paths.ldap_config_basedn_ldif = paths.ldapdir + "/" + dnsdomain + "-config.ldif";
-       paths.ldap_schema_basedn_ldif = paths.ldapdir + "/" + dnsdomain + "-schema.ldif";
+
+       paths.s4_ldapi_socket = lp.get("private dir") + "/ldapi";
+       paths.phpldapadminconfig = lp.get("private dir") + "/phpldapadmin-config.php";
 
        paths.sysvol = lp.get("sysvol", "path");
 
@@ -454,9 +469,7 @@ function provision_fix_subobj(subobj, paths)
        subobj.REALM       = strupper(subobj.REALM);
        subobj.HOSTNAME    = strlower(subobj.HOSTNAME);
        subobj.DOMAIN      = strupper(subobj.DOMAIN);
-       assert(valid_netbios_name(subobj.DOMAIN));
        subobj.NETBIOSNAME = strupper(subobj.HOSTNAME);
-       assert(valid_netbios_name(subobj.NETBIOSNAME));
        subobj.DNSDOMAIN    = strlower(subobj.REALM);
        subobj.DNSNAME      = sprintf("%s.%s", 
                                      strlower(subobj.HOSTNAME), 
@@ -472,22 +485,34 @@ function provision_fix_subobj(subobj, paths)
        subobj.ADMINPASS_B64   = ldb.encode(subobj.ADMINPASS);
        subobj.DNSPASS_B64     = ldb.encode(subobj.DNSPASS);
 
-       var rdns = split(",", subobj.DOMAINDN);
-       subobj.RDN_DC = substr(rdns[0], strlen("DC="));
-
        subobj.SAM_LDB          = "tdb://" + paths.samdb;
        subobj.SECRETS_KEYTAB   = paths.keytab;
        subobj.DNS_KEYTAB       = paths.dns_keytab;
+       subobj.DNS_KEYTAB_ABS   = paths.dns_keytab_abs;
 
        subobj.LDAPDIR = paths.ldapdir;
        var ldap_path_list = split("/", paths.ldapdir);
        subobj.LDAPI_URI = "ldapi://" + join("%2F", ldap_path_list) + "%2Fldapi";
 
+       var s4ldap_path_list = split("/", paths.s4_ldapi_socket);
+       subobj.S4_LDAPI_URI = "ldapi://" + join("%2F", s4ldap_path_list);
+
        subobj.LDAPMANAGERDN = "cn=Manager," + subobj.DOMAINDN;
 
        subobj.NETLOGONPATH = paths.netlogon;
        subobj.SYSVOLPATH = paths.sysvol;
 
+       if (subobj.DOMAIN_CONF == undefined) {
+               subobj.DOMAIN_CONF = subobj.DOMAIN;
+       }
+       if (subobj.REALM_CONF == undefined) {
+               subobj.REALM_CONF = subobj.REALM;
+       }
+       if (strlower(subobj.SERVERROLE) != strlower("domain controller")) {
+               subobj.REALM = subobj.HOSTNAME;
+               subobj.DOMAIN = subobj.HOSTNAME;
+       }
+
        return true;
 }
 
@@ -500,10 +525,17 @@ function provision_become_dc(subobj, message, erase, paths, session_info)
        var ok = provision_fix_subobj(subobj, paths);
        assert(ok);
 
+       if (subobj.BACKEND_MOD == undefined) {
+               subobj.BACKEND_MOD = "repl_meta_data";
+       }
+
        info.subobj = subobj;
        info.message = message;
        info.session_info = session_info;
 
+       message("Setting up templates into " + paths.templates + "\n");
+       setup_ldb("provision_templates.ldif", info, paths.templates);
+
        /* Also wipes the database */
        message("Setting up " + paths.samdb + " partitions\n");
        setup_ldb("provision_partitions.ldif", info, paths.samdb);
@@ -524,9 +556,6 @@ function provision_become_dc(subobj, message, erase, paths, session_info)
        message("Setting up " + paths.samdb + " indexes\n");
        setup_add_ldif("provision_index.ldif", info, samdb, false);
 
-       message("Setting up " + paths.samdb + " templates\n");
-       setup_add_ldif("provision_templates.ldif", info, samdb, false);
-
        ok = samdb.transaction_commit();
        assert(ok);
 
@@ -535,9 +564,49 @@ function provision_become_dc(subobj, message, erase, paths, session_info)
 
        setup_ldb("secrets.ldif", info, paths.secrets, false);
 
+       setup_ldb("secrets_dc.ldif", info, paths.secrets, false);
+
        return true;
 }
 
+function load_schema(subobj, message, samdb)
+{
+       var lp = loadparm_init();
+       var src = lp.get("setup directory") + "/" + "schema.ldif";
+
+       if (! sys.stat(src)) {
+               message("Template file not found: %s\n",src);
+               assert(0);
+       }
+
+       var schema_data = sys.file_load(src);
+
+       src = lp.get("setup directory") + "/" + "schema_samba4.ldif";
+
+       if (! sys.stat(src)) {
+               message("Template file not found: %s\n",src);
+               assert(0);
+       }
+
+       schema_data = schema_data + sys.file_load(src);
+
+       schema_data = substitute_var(schema_data, subobj);
+
+       src = lp.get("setup directory") + "/" + "provision_schema_basedn_modify.ldif";
+
+       if (! sys.stat(src)) {
+               message("Template file not found: %s\n",src);
+               assert(0);
+       }
+
+       var head_data = sys.file_load(src);
+       head_data = substitute_var(head_data, subobj);
+
+       var ok = samdb.attach_dsdb_schema_from_ldif(head_data, schema_data);
+       return ok;
+}
+
+
 /*
   provision samba4 - caution, this wipes all existing data!
 */
@@ -546,10 +615,21 @@ function provision(subobj, message, blank, paths, session_info, credentials, lda
        var lp = loadparm_init();
        var sys = sys_init();
        var info = new Object();
+       random_init(local);
 
        var ok = provision_fix_subobj(subobj, paths);
        assert(ok);
 
+       if (strlower(subobj.SERVERROLE) == strlower("domain controller")) {
+               if (subobj.BACKEND_MOD == undefined) {
+                       subobj.BACKEND_MOD = "repl_meta_data";
+               }
+       } else {
+               if (subobj.BACKEND_MOD == undefined) {
+                       subobj.BACKEND_MOD = "objectguid";
+               }
+       }
+
        if (subobj.DOMAINGUID != undefined) {
                subobj.DOMAINGUID_MOD = sprintf("replace: objectGUID\nobjectGUID: %s\n-", subobj.DOMAINGUID);
        } else {
@@ -570,8 +650,16 @@ function provision(subobj, message, blank, paths, session_info, credentials, lda
        /* only install a new smb.conf if there isn't one there already */
        var st = sys.stat(paths.smbconf);
        if (st == undefined) {
+               var smbconfsuffix;
+               if (strlower(subobj.SERVERROLE) == strlower("domain controller")) {
+                       smbconfsuffix = "dc";
+               } else if (strlower(subobj.SERVERROLE) == strlower("member server")) {
+                       smbconfsuffix = "member";
+               } else {
+                       smbconfsuffix = subobj.SERVERROLE;
+               }
                message("Setting up " + paths.smbconf +"\n");
-               setup_file("provision.smb.conf", info.message, paths.smbconf, subobj);
+               setup_file("provision.smb.conf." + smbconfsuffix, info.message, paths.smbconf, subobj);
                lp.reload();
        }
        /* only install a new shares config db if there is none */
@@ -589,6 +677,12 @@ function provision(subobj, message, blank, paths, session_info, credentials, lda
        var reg = reg_open();
        reg.apply_patchfile(lp.get("setup directory") + "/provision.reg")
 
+       message("Setting up templates into " + paths.templates + "\n");
+       setup_ldb("provision_templates.ldif", info, paths.templates);
+
+       message("Setting up " + paths.idmapdb +"\n");
+       setup_ldb("idmap_init.ldif", info, paths.idmapdb);
+
        message("Setting up sam.ldb partitions\n");
        /* Also wipes the database */
        setup_ldb("provision_partitions.ldif", info, paths.samdb);
@@ -604,43 +698,72 @@ function provision(subobj, message, blank, paths, session_info, credentials, lda
        message("Erasing data from partitions\n");
        ldb_erase_partitions(info, samdb, ldapbackend);
        
+       // (hack) Reload, now we have the partitions and rootdse loaded.  
+       var commit_ok = samdb.transaction_commit();
+       if (!commit_ok) {
+               info.message("samdb commit failed: " + samdb.errstring() + "\n");
+               assert(commit_ok);
+       }
+       samdb.close();
+
+       message("Pre-loading the Samba4 and AD schema\n");
+       
+       samdb = open_ldb(info, paths.samdb, false);
+
+       samdb.set_domain_sid(subobj.DOMAINSID);
+
+       if (strlower(subobj.SERVERROLE) == strlower("domain controller")) {
+               if (subobj.INVOCATIONID == undefined) {
+                       subobj.INVOCATIONID = randguid();
+               }
+               samdb.set_ntds_invocationId(subobj.INVOCATIONID);
+               if (subobj.BACKEND_MOD == undefined) {
+                       subobj.BACKEND_MOD = "repl_meta_data";
+               }
+       } else {
+               if (subobj.BACKEND_MOD == undefined) {
+                       subobj.BACKEND_MOD = "objectguid";
+               }
+       }
+
+       var load_schema_ok = load_schema(subobj, message, samdb);
+       assert(load_schema_ok.is_ok);
+
        message("Adding DomainDN: " + subobj.DOMAINDN + " (permitted to fail)\n");
        var add_ok = setup_add_ldif("provision_basedn.ldif", info, samdb, true);
        message("Modifying DomainDN: " + subobj.DOMAINDN + "\n");
-       var modify_ok = setup_ldb_modify("provision_basedn_modify.ldif", info, samdb);
-       if (!modify_ok) {
+       var modify_basedn_ok = setup_ldb_modify("provision_basedn_modify.ldif", info, samdb);
+       if (!modify_basedn_ok) {
                if (!add_ok) {
                        message("%s", "Failed to both add and modify " + subobj.DOMAINDN + " in target " + subobj.DOMAINDN_LDB + ": " + samdb.errstring() + "\n");
                        message("Perhaps you need to run the provision script with the --ldap-base-dn option, and add this record to the backend manually\n"); 
                };
-               assert(modify_ok);
+               assert(modify_basedn_ok);
        };
 
        message("Adding configuration container (permitted to fail)\n");
-       var add_ok = setup_add_ldif("provision_configuration_basedn.ldif", info, samdb, true);
+       var add_config_ok = setup_add_ldif("provision_configuration_basedn.ldif", info, samdb, true);
        message("Modifying configuration container\n");
-       var modify_ok = setup_ldb_modify("provision_configuration_basedn_modify.ldif", info, samdb);
-       if (!modify_ok) {
-               if (!add_ok) {
+       var modify_config_ok = setup_ldb_modify("provision_configuration_basedn_modify.ldif", info, samdb);
+       if (!modify_config_ok) {
+               if (!add_config_ok) {
                        message("%s", "Failed to both add and modify " + subobj.CONFIGDN + " in target " + subobj.CONFIGDN_LDB + ": " + samdb.errstring() + "\n");
                        message("Perhaps you need to run the provision script with the --ldap-base-dn option, and add this record to the backend manually\n"); 
-                       assert(modify_ok);
                }
-               assert(modify_ok);
+               assert(modify_config_ok);
        }
 
        message("Adding schema container (permitted to fail)\n");
-       var add_ok = setup_add_ldif("provision_schema_basedn.ldif", info, samdb, true);
+       var add_schema_ok = setup_add_ldif("provision_schema_basedn.ldif", info, samdb, true);
        message("Modifying schema container\n");
-       var modify_ok = setup_ldb_modify("provision_schema_basedn_modify.ldif", info, samdb);
-       if (!modify_ok) {
-               if (!add_ok) {
+       var modify_schema_ok = setup_ldb_modify("provision_schema_basedn_modify.ldif", info, samdb);
+       if (!modify_schema_ok) {
+               if (!add_schema_ok) {
                        message("%s", "Failed to both add and modify " + subobj.SCHEMADN + " in target " + subobj.SCHEMADN_LDB + ": " + samdb.errstring() + "\n");
                        message("Perhaps you need to run the provision script with the --ldap-base-dn option, and add this record to the backend manually\n"); 
-                       assert(modify_ok);
                }
                message("Failed to modify the schema container: " + samdb.errstring() + "\n");
-               assert(modify_ok);
+               assert(modify_schema_ok);
        }
 
        message("Setting up sam.ldb Samba4 schema\n");
@@ -648,45 +771,31 @@ function provision(subobj, message, blank, paths, session_info, credentials, lda
        message("Setting up sam.ldb AD schema\n");
        setup_add_ldif("schema.ldif", info, samdb, false);
 
-       // (hack) Reload, now we have the schema loaded.  
-       var commit_ok = samdb.transaction_commit();
-       if (!commit_ok) {
-               info.message("samdb commit failed: " + samdb.errstring() + "\n");
-               assert(commit_ok);
-       }
-       samdb.close();
-
-       samdb = open_ldb(info, paths.samdb, false);
-
        message("Setting up sam.ldb configuration data\n");
        setup_add_ldif("provision_configuration.ldif", info, samdb, false);
 
        message("Setting up display specifiers\n");
        setup_add_ldif("display_specifiers.ldif", info, samdb, false);
-       message("Setting up sam.ldb templates\n");
-       setup_add_ldif("provision_templates.ldif", info, samdb, false);
 
        message("Adding users container (permitted to fail)\n");
-       var add_ok = setup_add_ldif("provision_users_add.ldif", info, samdb, true);
+       var add_users_ok = setup_add_ldif("provision_users_add.ldif", info, samdb, true);
        message("Modifying users container\n");
-       var modify_ok = setup_ldb_modify("provision_users_modify.ldif", info, samdb);
-       if (!modify_ok) {
-               if (!add_ok) {
+       var modify_users_ok = setup_ldb_modify("provision_users_modify.ldif", info, samdb);
+       if (!modify_users_ok) {
+               if (!add_users_ok) {
                        message("Failed to both add and modify the users container\n");
-                       assert(modify_ok);
                }
-               assert(modify_ok);
+               assert(modify_users_ok);
        }
        message("Adding computers container (permitted to fail)\n");
-       var add_ok = setup_add_ldif("provision_computers_add.ldif", info, samdb, true);
+       var add_computers_ok = setup_add_ldif("provision_computers_add.ldif", info, samdb, true);
        message("Modifying computers container\n");
-       var modify_ok = setup_ldb_modify("provision_computers_modify.ldif", info, samdb);
-       if (!modify_ok) {
-               if (!add_ok) {
+       var modify_computers_ok = setup_ldb_modify("provision_computers_modify.ldif", info, samdb);
+       if (!modify_computers_ok) {
+               if (!add_computers_ok) {
                        message("Failed to both add and modify the computers container\n");
-                       assert(modify_ok);
                }
-               assert(modify_ok);
+               assert(modify_computers_ok);
        }
 
        message("Setting up sam.ldb data\n");
@@ -723,7 +832,7 @@ function provision(subobj, message, blank, paths, session_info, credentials, lda
        message("Setting up sam.ldb users and groups\n");
        setup_add_ldif("provision_users.ldif", info, samdb, false);
 
-       if (lp.get("server role") == "domain controller") {
+       if (strlower(subobj.SERVERROLE) == strlower("domain controller")) {
                message("Setting up self join\n");
                setup_add_ldif("provision_self_join.ldif", info, samdb, false);
                setup_add_ldif("provision_group_policy.ldif", info, samdb, false);
@@ -736,6 +845,9 @@ function provision(subobj, message, blank, paths, session_info, credentials, lda
                sys.mkdir(paths.sysvol + "/"+ subobj.DNSDOMAIN + "/Policies/{" + subobj.POLICYGUID + "}/User", 0755);
 
                sys.mkdir(paths.netlogon, 0755);
+
+               setup_ldb("secrets_dc.ldif", info, paths.secrets, false);
+
        }
 
        if (setup_name_mappings(info, samdb) == false) {
@@ -754,6 +866,10 @@ function provision(subobj, message, blank, paths, session_info, credentials, lda
                assert(commit_ok);
        }
 
+       message("Setting up phpLDAPadmin configuration\n");
+       setup_file("phpldapadmin-config.php", info.message, paths.phpldapadminconfig, subobj);
+       message("Please install the phpLDAPadmin configuration located at " + paths.phpldapadminconfig + " into /etc/phpldapadmin/config.php\n");
+
        return true;
 }
 
@@ -777,6 +893,12 @@ function provision_schema(subobj, message, tmp_schema_path, paths)
        /* This will erase anything in the tmp db */
        var samdb = open_ldb(info, tmp_schema_path, true);
 
+       message("Setting up sam.ldb attributes\n");
+       setup_add_ldif("provision_init.ldif", info, samdb, false);
+
+       message("Setting up sam.ldb rootDSE\n");
+       setup_add_ldif("provision_rootdse_add.ldif", info, samdb, false);
+
        message("Adding schema container (permitted to fail)\n");
        var add_ok = setup_add_ldif("provision_schema_basedn.ldif", info, samdb, true);
        message("Modifying schema container\n");
@@ -808,8 +930,8 @@ function provision_schema(subobj, message, tmp_schema_path, paths)
 function provision_dns(subobj, message, paths, session_info, credentials)
 {
        var lp = loadparm_init();
-       if (lp.get("server role") != "domain controller") {
-               message("No DNS zone required for role %s\n", lp.get("server role"));
+       if (strlower(subobj.SERVERROLE) != strlower("domain controller")) {
+               message("No DNS zone required for role %s\n", subobj.SERVERROLE);
                return;
        }
        message("Setting up DNS zone: " + subobj.DNSDOMAIN + " \n");
@@ -845,34 +967,6 @@ function provision_dns(subobj, message, paths, session_info, credentials)
        message("Please install the zone located in " + paths.dns + " into your DNS server.  A sample BIND configuration snippit is at " + paths.named_conf + "\n");
 }
 
-/* Write out a DNS zone file, from the info in the current database */
-function provision_ldapbase(subobj, message, paths)
-{
-       var ok = provision_fix_subobj(subobj, paths);
-       assert(ok);
-
-       message("Setting up LDAP base entry: " + subobj.DOMAINDN + " \n");
-       var rdns = split(",", subobj.DOMAINDN);
-       subobj.EXTENSIBLEOBJECT = "objectClass: extensibleObject";
-
-       subobj.RDN_DC = substr(rdns[0], strlen("DC="));
-
-       sys.mkdir(paths.ldapdir, 0700);
-
-       setup_file("provision_basedn.ldif", 
-                  message, paths.ldap_basedn_ldif, 
-                  subobj);
-
-       setup_file("provision_configuration_basedn.ldif", 
-                  message, paths.ldap_config_basedn_ldif, 
-                  subobj);
-
-       setup_file("provision_schema_basedn.ldif", 
-                  message, paths.ldap_schema_basedn_ldif, 
-                  subobj);
-
-}
-
 
 /*
   guess reasonably default options for provisioning
@@ -885,6 +979,7 @@ function provision_guess()
        var rdn_list;
        random_init(local);
 
+       subobj.SERVERROLE   = strlower(lp.get("server role"));
        subobj.REALM        = strupper(lp.get("realm"));
        subobj.DOMAIN       = lp.get("workgroup");
        subobj.HOSTNAME     = hostname();
@@ -896,7 +991,6 @@ function provision_guess()
        subobj.VERSION      = version();
        subobj.HOSTIP       = hostip();
        subobj.DOMAINSID    = randsid();
-       subobj.INVOCATIONID = randguid();
        subobj.POLICYGUID   = randguid();
        subobj.KRBTGTPASS   = randpass(12);
        subobj.MACHINEPASS  = randpass(12);
@@ -904,9 +998,6 @@ function provision_guess()
        subobj.ADMINPASS    = randpass(12);
        subobj.LDAPMANAGERPASS     = randpass(12);
        subobj.DEFAULTSITE  = "Default-First-Site-Name";
-       subobj.NEWGUID      = randguid;
-       subobj.NTTIME       = nttime;
-       subobj.LDAPTIME     = ldaptime;
        subobj.DATESTRING   = datestring;
        subobj.ROOT         = findnss(nss.getpwnam, "root");
        subobj.NOBODY       = findnss(nss.getpwnam, "nobody");
@@ -920,34 +1011,38 @@ function provision_guess()
        //
        // Some Known ordering constraints:
        // - rootdse must be first, as it makes redirects from "" -> cn=rootdse
-       // - samldb must be before password_hash, because password_hash checks
-       //   that the objectclass is of type person (filled in by samldb)
+       // - objectclass must be before password_hash, because password_hash checks
+       //   that the objectclass is of type person (filled in by the objectclass 
+       //   module when expanding the objectclass list)
        // - partition must be last
        // - each partition has its own module list then
-       modules_list        = new Array("rootdse",
-                                       "kludge_acl",
-                                       "paged_results",
-                                       "server_sort",
-                                       "extended_dn",
-                                       "asq",
-                                       "samldb",
-                                       "operational",
-                                       "objectclass",
-                                       "rdn_name",
-                                       "show_deleted",
-                                       "partition");
+       var modules_list     = new Array("rootdse",
+                                        "paged_results",
+                                        "ranged_results",
+                                        "anr",
+                                        "server_sort",
+                                        "extended_dn",
+                                        "asq",
+                                        "samldb",
+                                        "rdn_name",
+                                        "objectclass",
+                                        "kludge_acl",
+                                        "operational");
+       var tdb_modules_list = new Array("subtree_rename",
+                                        "subtree_delete",
+                                        "linked_attributes");
+       var modules_list2    = new Array("show_deleted",
+                                        "partition");
        subobj.MODULES_LIST = join(",", modules_list);
+       subobj.TDB_MODULES_LIST = "," + join(",", tdb_modules_list);
+       subobj.MODULES_LIST2 = join(",", modules_list2);
        subobj.DOMAINDN_LDB = "users.ldb";
        subobj.CONFIGDN_LDB = "configuration.ldb";
        subobj.SCHEMADN_LDB = "schema.ldb";
-       subobj.DOMAINDN_MOD = "pdc_fsmo,password_hash";
-       subobj.CONFIGDN_MOD = "naming_fsmo";
-       subobj.SCHEMADN_MOD = "schema_fsmo";
-       subobj.DOMAINDN_MOD2 = ",objectguid";
-       subobj.CONFIGDN_MOD2 = ",objectguid";
-       subobj.SCHEMADN_MOD2 = ",objectguid";
-
-       subobj.EXTENSIBLEOBJECT = "# no objectClass: extensibleObject for local ldb";
+       subobj.DOMAINDN_MOD = "pdc_fsmo,password_hash,instancetype";
+       subobj.CONFIGDN_MOD = "naming_fsmo,instancetype";
+       subobj.SCHEMADN_MOD = "schema_fsmo,instancetype";
+
        subobj.ACI              = "# no aci for local ldb";
 
        return subobj;
@@ -1029,12 +1124,11 @@ function newuser(username, unixname, password, message, session_info, credential
        var ldif = sprintf("
 dn: %s
 sAMAccountName: %s
-memberOf: %s
 unixName: %s
 sambaPassword: %s
 objectClass: user
 ",
-                          user_dn, username, dom_users,
+                          user_dn, username,
                           unixname, password);
        /*
          add the user to the users group as well
@@ -1044,7 +1138,7 @@ dn: %s
 changetype: modify
 add: member
 member: %s
-", 
+",
                               dom_users, user_dn);
 
 
@@ -1080,7 +1174,7 @@ member: %s
 // crh has a paragraph on this in his book (1.4.1.1)
 function valid_netbios_name(name)
 {
-       if (strlen(name) > 13) return false;
+       if (strlen(name) > 15) return false;
        return true;
 }
 
@@ -1099,15 +1193,21 @@ function provision_validate(subobj, message)
        }
 
 
-       if (strupper(lp.get("workgroup")) != strupper(subobj.DOMAIN)) {
+       if (strupper(lp.get("workgroup")) != strupper(subobj.DOMAIN_CONF)) {
                message("workgroup '%s' in smb.conf must match chosen domain '%s'\n",
-                       lp.get("workgroup"), subobj.DOMAIN);
+                       lp.get("workgroup"), subobj.DOMAIN_CONF);
                return false;
        }
 
-       if (strupper(lp.get("realm")) != strupper(subobj.REALM)) {
+       if (strupper(lp.get("realm")) != strupper(subobj.REALM_CONF)) {
                message("realm '%s' in smb.conf must match chosen realm '%s'\n",
-                       lp.get("realm"), subobj.REALM);
+                       lp.get("realm"), subobj.REALM_CONF);
+               return false;
+       }
+
+       if (strlower(lp.get("server role")) != strlower(subobj.SERVERROLE)) {
+               message("server role '%s' in smb.conf must match chosen role '%s'\n",
+                       lp.get("server role"), subobj.SERVERROLE);
                return false;
        }