r24729: First try and publishing a DNS service account, for folks to play with.
[samba.git] / source / setup / provision
1 #!/bin/sh
2 exec smbscript "$0" ${1+"$@"}
3 /*
4         provision a Samba4 server
5         Copyright Andrew Tridgell 2005
6         Released under the GNU GPL v2 or later
7 */
8
9 options = GetOptions(ARGV,
10                 "POPT_AUTOHELP",
11                 "POPT_COMMON_SAMBA",
12                 "POPT_COMMON_VERSION",
13                 "POPT_COMMON_CREDENTIALS",
14                 'realm=s',
15                 'domain=s',
16                 'domain-guid=s',
17                 'domain-guid=s',
18                 'domain-sid=s',
19                 'policy-guid=s',
20                 'host-name=s',
21                 'host-ip=s',
22                 'host-guid=s',
23                 'invocationid=s',
24                 'adminpass=s',
25                 'krbtgtpass=s',
26                 'machinepass=s',
27                 'dnspass=s',
28                 'root=s',
29                 'nobody=s',
30                 'nogroup=s',
31                 'wheel=s',
32                 'users=s',
33                 'quiet',
34                 'blank',
35                 'partitions-only',
36                 'ldap-base',
37                 'ldap-backend=s',
38                 'ldap-module=s',
39                 'aci=s');
40
41 if (options == undefined) {
42    println("Failed to parse options");
43    return -1;
44 }
45
46 libinclude("base.js");
47 libinclude("provision.js");
48
49 /*
50   print a message if quiet is not set
51 */
52 function message()
53 {
54         if (options["quiet"] == undefined) {
55                 print(vsprintf(arguments));
56         }
57 }
58
59 /*
60  show some help
61 */
62 function ShowHelp()
63 {
64         print("
65 Samba4 provisioning
66
67 provision [options]
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
85  --quiet                        Be quiet
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
93
94 ");
95         exit(1);
96 }
97
98 if (options['host-name'] == undefined) {
99         options['host-name'] = hostname();
100 }
101
102 /*
103    main program
104 */
105 if (options["realm"] == undefined ||
106     options["domain"] == undefined ||
107     options["host-name"] == undefined) {
108         ShowHelp();
109 }
110
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);
115 lp.reload();
116
117 var subobj = provision_guess();
118 for (r in options) {
119         var key = strupper(join("", split("-", r)));
120         subobj[key] = options[r];
121 }
122
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"]);
131 }
132
133 message("set DOMAIN SID: %s\n", subobj["DOMAINSID"]);
134
135 provision_fix_subobj(subobj, paths);
136
137 if (ldapbackend) {
138         if (options["ldap-backend"] == "ldapi") {
139                 subobj.LDAPBACKEND = subobj.LDAPI_URI;
140         }
141         if (!ldapmodule) {
142                 subobj.LDAPMODULE = "entryUUID";
143         }
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);
151 }
152
153 if (!provision_validate(subobj, message)) {
154         return -1;
155 }
156
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);
161 if (ldapbase) {
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);
166 } else {
167         provision(subobj, message, blank, paths, system_session, creds, ldapbackend);
168         provision_dns(subobj, message, paths, system_session, creds);
169 }
170 message("All OK\n");
171 return 0;