Convert some more files to GPLv3.
[jra/samba/.git] / source4 / scripting / libjs / provision.js
index f9814884f35edc87a34fedb3af2144ff48145ed4..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();
@@ -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;
@@ -207,8 +207,8 @@ function ldb_erase_partitions(info, ldb, ldapbackend)
                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;
@@ -389,6 +389,7 @@ function provision_default_paths(subobj)
        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";
@@ -398,9 +399,6 @@ function provision_default_paths(subobj)
        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";
@@ -487,9 +485,6 @@ 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;
@@ -530,6 +525,10 @@ 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;
@@ -616,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 {
@@ -670,6 +680,9 @@ function provision(subobj, message, blank, paths, session_info, credentials, lda
        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);
@@ -699,6 +712,20 @@ function provision(subobj, message, blank, paths, session_info, credentials, lda
 
        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);
 
@@ -866,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");
@@ -934,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
@@ -986,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);
@@ -994,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");
@@ -1018,6 +1019,7 @@ function provision_guess()
        var modules_list     = new Array("rootdse",
                                         "paged_results",
                                         "ranged_results",
+                                        "anr",
                                         "server_sort",
                                         "extended_dn",
                                         "asq",
@@ -1037,14 +1039,10 @@ function provision_guess()
        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;
@@ -1130,7 +1128,7 @@ 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
@@ -1140,7 +1138,7 @@ dn: %s
 changetype: modify
 add: member
 member: %s
-", 
+",
                               dom_users, user_dn);
 
 
@@ -1176,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;
 }