3 # Unix SMB/CIFS implementation.
4 # provision a Samba4 server
5 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
6 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2008
8 # Based on the original in EJS:
9 # Copyright (C) Andrew Tridgell 2005
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
32 from auth import system_session
33 import samba.getopt as options
34 from samba.provision import (provision,
35 FILL_FULL, FILL_NT4SYNC,
38 parser = optparse.OptionParser("provision [options]")
39 sambaopts = options.SambaOptions(parser)
40 parser.add_option_group(sambaopts)
41 parser.add_option_group(options.VersionOptions(parser))
42 credopts = options.CredentialsOptions(parser)
43 parser.add_option_group(credopts)
44 parser.add_option("--setupdir", type="string", metavar="DIR",
45 help="directory with setup files")
46 parser.add_option("--realm", type="string", metavar="REALM", help="set realm")
47 parser.add_option("--domain", type="string", metavar="DOMAIN",
49 parser.add_option("--domain-guid", type="string", metavar="GUID",
50 help="set domainguid (otherwise random)")
51 parser.add_option("--domain-sid", type="string", metavar="SID",
52 help="set domainsid (otherwise random)")
53 parser.add_option("--policy-guid", type="string", metavar="GUID",
54 help="set policy guid")
55 parser.add_option("--invocationid", type="string", metavar="GUID",
56 help="set invocationid (otherwise random)")
57 parser.add_option("--host-name", type="string", metavar="HOSTNAME",
59 parser.add_option("--host-ip", type="string", metavar="IPADDRESS",
61 parser.add_option("--adminpass", type="string", metavar="PASSWORD",
62 help="choose admin password (otherwise random)")
63 parser.add_option("--krbtgtpass", type="string", metavar="PASSWORD",
64 help="choose krbtgt password (otherwise random)")
65 parser.add_option("--machinepass", type="string", metavar="PASSWORD",
66 help="choose machine password (otherwise random)")
67 parser.add_option("--dnspass", type="string", metavar="PASSWORD",
68 help="choose dns password (otherwise random)")
69 parser.add_option("--root", type="string", metavar="USERNAME",
70 help="choose 'root' unix username")
71 parser.add_option("--nobody", type="string", metavar="USERNAME",
72 help="choose 'nobody' user")
73 parser.add_option("--nogroup", type="string", metavar="GROUPNAME",
74 help="choose 'nogroup' group")
75 parser.add_option("--wheel", type="string", metavar="GROUPNAME",
76 help="choose 'wheel' privileged group")
77 parser.add_option("--users", type="string", metavar="GROUPNAME",
78 help="choose 'users' group")
79 parser.add_option("--quiet", help="Be quiet", action="store_true")
80 parser.add_option("--blank", action="store_true",
81 help="do not add users or groups, just the structure")
82 parser.add_option("--ldap-backend", type="string", metavar="LDAPSERVER",
83 help="LDAP server to use for this provision")
84 parser.add_option("--ldap-backend-type", type="choice", metavar="LDAP-BACKEND-TYPE",
85 help="LDB mapping module to use for the LDAP backend",
86 choices=["fedora-ds", "openldap"])
87 parser.add_option("--aci", type="string", metavar="ACI",
88 help="An arbitary LDIF fragment, particularly useful to loading a backend ACI value into a target LDAP server. You must provide at least a realm and domain")
89 parser.add_option("--server-role", type="choice", metavar="ROLE",
90 choices=["domain controller", "dc", "member server", "member", "standalone"],
91 help="Set server role to provision for (default standalone)")
92 parser.add_option("--partitions-only",
93 help="Configure Samba's partitions, but do not modify them (ie, join a BDC)", action="store_true")
94 parser.add_option("--targetdir", type="string", metavar="DIR",
95 help="Set target directory")
97 opts = parser.parse_args()[0]
100 """print a message if quiet is not set."""
104 if opts.realm is None or opts.domain is None:
105 if opts.realm is None:
106 print >>sys.stderr, "No realm set"
107 if opts.domain is None:
108 print >>sys.stderr, "No domain set"
112 lp = sambaopts.get_loadparm()
113 smbconf = lp.configfile()
115 if opts.aci is not None:
116 print "set ACI: %s" % opts.aci
118 if opts.server_role == "dc":
119 server_role = "domain controller"
120 elif opts.server_role == "member":
121 server_role = "member server"
123 server_role = opts.server_role
125 creds = credopts.get_credentials(lp)
127 setup_dir = opts.setupdir
128 if setup_dir is None:
131 samdb_fill = FILL_FULL
133 samdb_fill = FILL_NT4SYNC
134 elif opts.partitions_only:
135 samdb_fill = FILL_DRS
137 provision(setup_dir, message,
138 system_session(), creds, smbconf=smbconf, targetdir=opts.targetdir,
139 samdb_fill=samdb_fill, realm=opts.realm, domain=opts.domain,
140 domainguid=opts.domain_guid, domainsid=opts.domain_sid,
141 policyguid=opts.policy_guid, hostname=opts.host_name,
143 invocationid=opts.invocationid, adminpass=opts.adminpass,
144 krbtgtpass=opts.krbtgtpass, machinepass=opts.machinepass,
145 dnspass=opts.dnspass, root=opts.root, nobody=opts.nobody,
146 nogroup=opts.nogroup, wheel=opts.wheel, users=opts.users,
147 aci=opts.aci, serverrole=server_role,
148 ldap_backend=opts.ldap_backend,
149 ldap_backend_type=opts.ldap_backend_type)