2005-07-14 13:51:49 +04:00
#!/bin/sh
2005-08-02 02:10:24 +04:00
exec smbscript "$0" ${1+"$@"}
2005-07-11 13:20:47 +04:00
/*
provision a Samba4 server
Copyright Andrew Tridgell 2005
Released under the GNU GPL v2 or later
*/
2005-08-22 18:32:58 +04:00
options = GetOptions(ARGV,
2005-07-11 13:20:47 +04:00
"POPT_AUTOHELP",
"POPT_COMMON_SAMBA",
"POPT_COMMON_VERSION",
2006-01-06 15:29:06 +03:00
"POPT_COMMON_CREDENTIALS",
2005-07-11 13:20:47 +04:00
'realm=s',
'domain=s',
'domain-guid=s',
2007-07-13 12:01:36 +04:00
'domain-guid=s',
2005-07-11 13:20:47 +04:00
'domain-sid=s',
2007-07-13 12:01:36 +04:00
'policy-guid=s',
2005-07-11 13:20:47 +04:00
'host-name=s',
'host-ip=s',
'host-guid=s',
'invocationid=s',
'adminpass=s',
'krbtgtpass=s',
'machinepass=s',
2007-08-28 08:28:02 +04:00
'dnspass=s',
2005-07-11 13:20:47 +04:00
'root=s',
'nobody=s',
'nogroup=s',
'wheel=s',
'users=s',
2005-07-27 04:23:09 +04:00
'quiet',
2007-01-02 14:50:04 +03:00
'blank',
2007-05-08 08:38:16 +04:00
'partitions-only',
r16264: Add, but do not yet enable, the partitions module.
This required changes to the rootDSE module, to allow registration of
partitions. In doing so I renamed the 'register' operation to
'register_control' and 'register_partition', which changed a few more
modules.
Due to the behaviour of certain LDAP servers, we create the baseDN
entry in two parts: Firstly, we allow the admin to export a simple
LDIF file to add to their server. Then we perform a modify to add the
remaining attributes.
To delete all users in partitions, we must now search and delete all
objects in the partition, rather than a simple search from the root.
Against LDAP, this might not delete all objects, so we allow this to
fail.
In testing, we found that the 'Domain Controllers' container was
misnamed, and should be 'CN=', rather than 'OU='.
To avoid the Templates being found in default searches, they have been
moved to CN=Templates from CN=Templates,${BASEDN}.
Andrew Bartlett
(This used to be commit b49a4fbb57f10726bd288fdc9fc95c0cbbe9094a)
2006-06-15 22:04:24 +04:00
'ldap-base',
2007-01-03 06:19:02 +03:00
'ldap-backend=s',
2007-01-03 08:31:50 +03:00
'ldap-module=s',
'aci=s');
2005-08-22 18:32:58 +04:00
if (options == undefined) {
2005-08-26 15:38:07 +04:00
println("Failed to parse options");
2005-07-11 13:20:47 +04:00
return -1;
}
libinclude("base.js");
2005-07-12 15:46:34 +04:00
libinclude("provision.js");
2005-07-12 06:36:07 +04:00
2005-07-11 13:20:47 +04:00
/*
print a message if quiet is not set
*/
2007-01-02 14:50:04 +03:00
function message()
2005-07-11 13:20:47 +04:00
{
if (options["quiet"] == undefined) {
2005-07-12 15:46:34 +04:00
print(vsprintf(arguments));
2005-07-12 10:02:20 +04:00
}
}
2005-07-11 13:20:47 +04:00
/*
show some help
*/
function ShowHelp()
{
print("
Samba4 provisioning
2005-07-13 09:29:05 +04:00
provision [options]
2005-07-11 13:20:47 +04:00
--realm REALM set realm
--domain DOMAIN set domain
--domain-guid GUID set domainguid (otherwise random)
--domain-sid SID set domainsid (otherwise random)
--host-name HOSTNAME set hostname
--host-ip IPADDRESS set ipaddress
--host-guid GUID set hostguid (otherwise random)
2007-07-13 12:01:36 +04:00
--policy-guid GUID set group policy guid (otherwise random)
2005-07-11 13:20:47 +04:00
--invocationid GUID set invocationid (otherwise random)
--adminpass PASSWORD choose admin password (otherwise random)
--krbtgtpass PASSWORD choose krbtgt password (otherwise random)
--machinepass PASSWORD choose machine password (otherwise random)
--root USERNAME choose 'root' unix username
--nobody USERNAME choose 'nobody' user
--nogroup GROUPNAME choose 'nogroup' group
--wheel GROUPNAME choose 'wheel' privileged group
--users GROUPNAME choose 'users' group
--quiet Be quiet
2005-07-27 04:23:09 +04:00
--blank do not add users or groups, just the structure
2007-05-08 08:38:16 +04:00
--partitions-only Configure Samba's partitions, but do not modify them (ie, join a BDC)
r16264: Add, but do not yet enable, the partitions module.
This required changes to the rootDSE module, to allow registration of
partitions. In doing so I renamed the 'register' operation to
'register_control' and 'register_partition', which changed a few more
modules.
Due to the behaviour of certain LDAP servers, we create the baseDN
entry in two parts: Firstly, we allow the admin to export a simple
LDIF file to add to their server. Then we perform a modify to add the
remaining attributes.
To delete all users in partitions, we must now search and delete all
objects in the partition, rather than a simple search from the root.
Against LDAP, this might not delete all objects, so we allow this to
fail.
In testing, we found that the 'Domain Controllers' container was
misnamed, and should be 'CN=', rather than 'OU='.
To avoid the Templates being found in default searches, they have been
moved to CN=Templates from CN=Templates,${BASEDN}.
Andrew Bartlett
(This used to be commit b49a4fbb57f10726bd288fdc9fc95c0cbbe9094a)
2006-06-15 22:04:24 +04:00
--ldap-base output only an LDIF file, suitable for creating an LDAP baseDN
--ldap-backend LDAPSERVER LDAP server to use for this provision
2007-01-03 06:19:02 +03:00
--ldap-module= MODULE LDB mapping module to use for the LDAP backend
2007-01-03 08:31:50 +03:00
--aci= ACI An arbitary LDIF fragment, particularly useful to loading a backend ACI value into a target LDAP server
2005-07-11 13:20:47 +04:00
You must provide at least a realm and domain
");
exit(1);
}
2005-07-12 06:36:07 +04:00
if (options['host-name'] == undefined) {
options['host-name'] = hostname();
}
2005-07-11 13:20:47 +04:00
/*
main program
*/
if (options["realm"] == undefined ||
options["domain"] == undefined ||
options["host-name"] == undefined) {
ShowHelp();
}
2005-07-20 14:07:48 +04:00
/* cope with an initially blank smb.conf */
var lp = loadparm_init();
lp.set("realm", options.realm);
lp.set("workgroup", options.domain);
lp.reload();
2005-07-12 15:46:34 +04:00
var subobj = provision_guess();
2005-07-12 01:53:10 +04:00
for (r in options) {
2005-07-12 06:36:07 +04:00
var key = strupper(join("", split("-", r)));
subobj[key] = options[r];
2005-07-11 13:20:47 +04:00
}
2007-01-05 23:10:38 +03:00
var blank = (options["blank"] != undefined);
var ldapbase = (options["ldap-base"] != undefined);
var ldapbackend = (options["ldap-backend"] != undefined);
var ldapmodule = (options["ldap-module"] != undefined);
2007-05-08 08:38:16 +04:00
var partitions_only = (options["partitions-only"] != undefined);
2007-07-05 04:34:11 +04:00
var paths = provision_default_paths(subobj);
2007-01-03 08:31:50 +03:00
if (options["aci"] != undefined) {
2007-04-27 14:06:34 +04:00
message("set ACI: %s\n", subobj["ACI"]);
2007-01-03 08:31:50 +03:00
}
2005-07-12 06:36:07 +04:00
2007-04-27 14:06:34 +04:00
message("set DOMAIN SID: %s\n", subobj["DOMAINSID"]);
2007-04-23 11:33:15 +04:00
2007-07-05 04:34:11 +04:00
provision_fix_subobj(subobj, paths);
2007-01-05 23:10:38 +03:00
if (ldapbackend) {
2007-07-05 04:34:11 +04:00
if (options["ldap-backend"] == "ldapi") {
subobj.LDAPBACKEND = subobj.LDAPI_URI;
}
2007-01-05 23:10:38 +03:00
if (!ldapmodule) {
2007-07-04 15:06:32 +04:00
subobj.LDAPMODULE = "entryUUID";
2007-01-05 23:10:38 +03:00
}
2007-07-04 15:06:32 +04:00
subobj.DOMAINDN_LDB = subobj.LDAPBACKEND;
subobj.DOMAINDN_MOD2 = "," + subobj.LDAPMODULE + ",paged_searches";
subobj.CONFIGDN_LDB = subobj.LDAPBACKEND;
subobj.CONFIGDN_MOD2 = "," + subobj.LDAPMODULE + ",paged_searches";
subobj.SCHEMADN_LDB = subobj.LDAPBACKEND;
subobj.SCHEMADN_MOD2 = "," + subobj.LDAPMODULE + ",paged_searches";
2007-07-05 04:34:11 +04:00
message("LDAP module: %s on backend: %s\n", subobj.LDAPMODULE, subobj.LDAPBACKEND);
2006-08-14 04:59:57 +04:00
}
2005-09-13 03:52:25 +04:00
if (!provision_validate(subobj, message)) {
return -1;
}
2006-01-07 00:04:32 +03:00
var system_session = system_session();
2006-01-31 01:22:37 +03:00
var creds = options.get_credentials();
2005-07-12 15:46:34 +04:00
message("Provisioning for %s in realm %s\n", subobj.DOMAIN, subobj.REALM);
message("Using administrator password: %s\n", subobj.ADMINPASS);
r16264: Add, but do not yet enable, the partitions module.
This required changes to the rootDSE module, to allow registration of
partitions. In doing so I renamed the 'register' operation to
'register_control' and 'register_partition', which changed a few more
modules.
Due to the behaviour of certain LDAP servers, we create the baseDN
entry in two parts: Firstly, we allow the admin to export a simple
LDIF file to add to their server. Then we perform a modify to add the
remaining attributes.
To delete all users in partitions, we must now search and delete all
objects in the partition, rather than a simple search from the root.
Against LDAP, this might not delete all objects, so we allow this to
fail.
In testing, we found that the 'Domain Controllers' container was
misnamed, and should be 'CN=', rather than 'OU='.
To avoid the Templates being found in default searches, they have been
moved to CN=Templates from CN=Templates,${BASEDN}.
Andrew Bartlett
(This used to be commit b49a4fbb57f10726bd288fdc9fc95c0cbbe9094a)
2006-06-15 22:04:24 +04:00
if (ldapbase) {
provision_ldapbase(subobj, message, paths);
2007-05-29 16:18:41 +04:00
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");
2007-05-08 08:38:16 +04:00
} else if (partitions_only) {
provision_become_dc(subobj, message, false, paths, system_session);
r16264: Add, but do not yet enable, the partitions module.
This required changes to the rootDSE module, to allow registration of
partitions. In doing so I renamed the 'register' operation to
'register_control' and 'register_partition', which changed a few more
modules.
Due to the behaviour of certain LDAP servers, we create the baseDN
entry in two parts: Firstly, we allow the admin to export a simple
LDIF file to add to their server. Then we perform a modify to add the
remaining attributes.
To delete all users in partitions, we must now search and delete all
objects in the partition, rather than a simple search from the root.
Against LDAP, this might not delete all objects, so we allow this to
fail.
In testing, we found that the 'Domain Controllers' container was
misnamed, and should be 'CN=', rather than 'OU='.
To avoid the Templates being found in default searches, they have been
moved to CN=Templates from CN=Templates,${BASEDN}.
Andrew Bartlett
(This used to be commit b49a4fbb57f10726bd288fdc9fc95c0cbbe9094a)
2006-06-15 22:04:24 +04:00
} else {
2007-01-02 14:50:04 +03:00
provision(subobj, message, blank, paths, system_session, creds, ldapbackend);
r16264: Add, but do not yet enable, the partitions module.
This required changes to the rootDSE module, to allow registration of
partitions. In doing so I renamed the 'register' operation to
'register_control' and 'register_partition', which changed a few more
modules.
Due to the behaviour of certain LDAP servers, we create the baseDN
entry in two parts: Firstly, we allow the admin to export a simple
LDIF file to add to their server. Then we perform a modify to add the
remaining attributes.
To delete all users in partitions, we must now search and delete all
objects in the partition, rather than a simple search from the root.
Against LDAP, this might not delete all objects, so we allow this to
fail.
In testing, we found that the 'Domain Controllers' container was
misnamed, and should be 'CN=', rather than 'OU='.
To avoid the Templates being found in default searches, they have been
moved to CN=Templates from CN=Templates,${BASEDN}.
Andrew Bartlett
(This used to be commit b49a4fbb57f10726bd288fdc9fc95c0cbbe9094a)
2006-06-15 22:04:24 +04:00
provision_dns(subobj, message, paths, system_session, creds);
}
2005-07-12 15:46:34 +04:00
message("All OK\n");
2005-07-12 01:53:10 +04:00
return 0;