2 exec smbscript "$0" ${1+"$@"}
4 provision a Samba4 server
5 Copyright Andrew Tridgell 2005
6 Released under the GNU GPL v2 or later
9 options = GetOptions(ARGV,
12 "POPT_COMMON_VERSION",
13 "POPT_COMMON_CREDENTIALS",
41 if (options == undefined) {
42 println("Failed to parse options");
46 libinclude("base.js");
47 libinclude("provision.js");
50 print a message if quiet is not set
54 if (options["quiet"] == undefined) {
55 print(vsprintf(arguments));
68 --realm REALM set realm
69 --domain DOMAIN set domain
70 --domain-guid GUID set domainguid (otherwise random)
71 --domain-sid SID set domainsid (otherwise random)
72 --host-name HOSTNAME set hostname
73 --host-ip IPADDRESS set ipaddress
74 --host-guid GUID set hostguid (otherwise random)
75 --policy-guid GUID set group policy guid (otherwise random)
76 --invocationid GUID set invocationid (otherwise random)
77 --adminpass PASSWORD choose admin password (otherwise random)
78 --krbtgtpass PASSWORD choose krbtgt password (otherwise random)
79 --machinepass PASSWORD choose machine password (otherwise random)
80 --root USERNAME choose 'root' unix username
81 --nobody USERNAME choose 'nobody' user
82 --nogroup GROUPNAME choose 'nogroup' group
83 --wheel GROUPNAME choose 'wheel' privileged group
84 --users GROUPNAME choose 'users' group
86 --blank do not add users or groups, just the structure
87 --partitions-only Configure Samba's partitions, but do not modify them (ie, join a BDC)
88 --ldap-base output only an LDIF file, suitable for creating an LDAP baseDN
89 --ldap-backend LDAPSERVER LDAP server to use for this provision
90 --ldap-module= MODULE LDB mapping module to use for the LDAP backend
91 --aci= ACI An arbitary LDIF fragment, particularly useful to loading a backend ACI value into a target LDAP server
92 You must provide at least a realm and domain
98 if (options['host-name'] == undefined) {
99 options['host-name'] = hostname();
105 if (options["realm"] == undefined ||
106 options["domain"] == undefined ||
107 options["host-name"] == undefined) {
111 /* cope with an initially blank smb.conf */
112 var lp = loadparm_init();
113 lp.set("realm", options.realm);
114 lp.set("workgroup", options.domain);
117 var subobj = provision_guess();
119 var key = strupper(join("", split("-", r)));
120 subobj[key] = options[r];
123 var blank = (options["blank"] != undefined);
124 var ldapbase = (options["ldap-base"] != undefined);
125 var ldapbackend = (options["ldap-backend"] != undefined);
126 var ldapmodule = (options["ldap-module"] != undefined);
127 var partitions_only = (options["partitions-only"] != undefined);
128 var paths = provision_default_paths(subobj);
129 if (options["aci"] != undefined) {
130 message("set ACI: %s\n", subobj["ACI"]);
133 message("set DOMAIN SID: %s\n", subobj["DOMAINSID"]);
135 provision_fix_subobj(subobj, paths);
138 if (options["ldap-backend"] == "ldapi") {
139 subobj.LDAPBACKEND = subobj.LDAPI_URI;
142 subobj.LDAPMODULE = "entryUUID";
144 subobj.DOMAINDN_LDB = subobj.LDAPBACKEND;
145 subobj.DOMAINDN_MOD2 = "," + subobj.LDAPMODULE + ",paged_searches";
146 subobj.CONFIGDN_LDB = subobj.LDAPBACKEND;
147 subobj.CONFIGDN_MOD2 = "," + subobj.LDAPMODULE + ",paged_searches";
148 subobj.SCHEMADN_LDB = subobj.LDAPBACKEND;
149 subobj.SCHEMADN_MOD2 = "," + subobj.LDAPMODULE + ",paged_searches";
150 message("LDAP module: %s on backend: %s\n", subobj.LDAPMODULE, subobj.LDAPBACKEND);
153 if (!provision_validate(subobj, message)) {
157 var system_session = system_session();
158 var creds = options.get_credentials();
159 message("Provisioning for %s in realm %s\n", subobj.DOMAIN, subobj.REALM);
160 message("Using administrator password: %s\n", subobj.ADMINPASS);
162 provision_ldapbase(subobj, message, paths);
163 message("Please install the LDIF located in " + paths.ldap_basedn_ldif + ", " + paths.ldap_config_basedn_ldif + " and " + paths.ldap_schema_basedn_ldif + " into your LDAP server, and re-run with --ldap-backend=ldap://my.ldap.server\n");
164 } else if (partitions_only) {
165 provision_become_dc(subobj, message, false, paths, system_session);
167 provision(subobj, message, blank, paths, system_session, creds, ldapbackend);
168 provision_dns(subobj, message, paths, system_session, creds);