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/>.
30 # Find right directory when running from source tree
31 sys
.path
.insert(0, "bin/python")
34 from samba
.credentials
import DONT_USE_KERBEROS
35 from samba
.auth
import system_session
36 import samba
.getopt
as options
37 from samba
import param
38 from samba
.provision
import provision
, FILL_FULL
, FILL_NT4SYNC
, FILL_DRS
, find_setup_dir
40 # how do we make this case insensitive??
42 parser
= optparse
.OptionParser("provision [options]")
43 sambaopts
= options
.SambaOptions(parser
)
44 parser
.add_option_group(sambaopts
)
45 parser
.add_option_group(options
.VersionOptions(parser
))
46 credopts
= options
.CredentialsOptions(parser
)
47 parser
.add_option_group(credopts
)
48 parser
.add_option("--interactive", help="Ask for names", action
="store_true")
49 parser
.add_option("--setupdir", type="string", metavar
="DIR",
50 help="directory with setup files")
51 parser
.add_option("--realm", type="string", metavar
="REALM", help="set realm")
52 parser
.add_option("--domain", type="string", metavar
="DOMAIN",
54 parser
.add_option("--domain-guid", type="string", metavar
="GUID",
55 help="set domainguid (otherwise random)")
56 parser
.add_option("--domain-sid", type="string", metavar
="SID",
57 help="set domainsid (otherwise random)")
58 parser
.add_option("--policy-guid", type="string", metavar
="GUID",
59 help="set policy guid")
60 parser
.add_option("--invocationid", type="string", metavar
="GUID",
61 help="set invocationid (otherwise random)")
62 parser
.add_option("--host-name", type="string", metavar
="HOSTNAME",
64 parser
.add_option("--host-ip", type="string", metavar
="IPADDRESS",
65 help="set IPv4 ipaddress")
66 parser
.add_option("--host-ip6", type="string", metavar
="IP6ADDRESS",
67 help="set IPv6 ipaddress")
68 parser
.add_option("--adminpass", type="string", metavar
="PASSWORD",
69 help="choose admin password (otherwise random)")
70 parser
.add_option("--krbtgtpass", type="string", metavar
="PASSWORD",
71 help="choose krbtgt password (otherwise random)")
72 parser
.add_option("--machinepass", type="string", metavar
="PASSWORD",
73 help="choose machine password (otherwise random)")
74 parser
.add_option("--dnspass", type="string", metavar
="PASSWORD",
75 help="choose dns password (otherwise random)")
76 parser
.add_option("--root", type="string", metavar
="USERNAME",
77 help="choose 'root' unix username")
78 parser
.add_option("--nobody", type="string", metavar
="USERNAME",
79 help="choose 'nobody' user")
80 parser
.add_option("--nogroup", type="string", metavar
="GROUPNAME",
81 help="choose 'nogroup' group")
82 parser
.add_option("--wheel", type="string", metavar
="GROUPNAME",
83 help="choose 'wheel' privileged group")
84 parser
.add_option("--users", type="string", metavar
="GROUPNAME",
85 help="choose 'users' group")
86 parser
.add_option("--quiet", help="Be quiet", action
="store_true")
87 parser
.add_option("--blank", action
="store_true",
88 help="do not add users or groups, just the structure")
89 parser
.add_option("--ldap-backend", type="string", metavar
="LDAPSERVER",
90 help="LDAP server to use for this provision")
91 parser
.add_option("--ldap-backend-type", type="choice", metavar
="LDAP-BACKEND-TYPE",
92 help="LDB mapping module to use for the LDAP backend",
93 choices
=["fedora-ds", "openldap"])
94 parser
.add_option("--aci", type="string", metavar
="ACI",
95 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")
96 parser
.add_option("--server-role", type="choice", metavar
="ROLE",
97 choices
=["domain controller", "dc", "member server", "member", "standalone"],
98 help="Set server role to provision for (default standalone)")
99 parser
.add_option("--partitions-only",
100 help="Configure Samba's partitions, but do not modify them (ie, join a BDC)", action
="store_true")
101 parser
.add_option("--targetdir", type="string", metavar
="DIR",
102 help="Set target directory")
104 opts
= parser
.parse_args()[0]
107 """print a message if quiet is not set."""
111 if len(sys
.argv
) == 1:
112 opts
.interactive
= True
114 if not opts
.interactive
and (opts
.realm
is None or opts
.domain
is None):
115 if opts
.realm
is None:
116 print >>sys
.stderr
, "No realm set"
117 if opts
.domain
is None:
118 print >>sys
.stderr
, "No domain set"
123 from getpass
import getpass
126 def ask(prompt
, default
=None):
127 if default
is not None:
128 print "%s [%s]: " % (prompt
,default
),
130 print "%s: " % (prompt
,),
131 return sys
.stdin
.readline().rstrip("\n") or default
133 opts
.realm
= ask("Realm", socket
.getfqdn().split(".", 1)[1].upper())
135 print >>sys
.stderr
, "Cannot guess realm from %s" % ( socket
.getfqdn())
139 opts
.domain
= ask("Domain", opts
.realm
.split(".")[0])
141 print >>sys
.stderr
, "Cannot guess domain from %s" % ( opts
.realm())
144 opts
.server_role
= ask("Server Role (dc, member, standalone)", "dc")
146 opts
.adminpass
= getpass("Administrator password: ")
147 if not opts
.adminpass
:
148 print >>sys
.stderr
, "Invalid administrator password."
152 lp
= sambaopts
.get_loadparm()
153 smbconf
= lp
.configfile
155 if opts
.aci
is not None:
156 print "set ACI: %s" % opts
.aci
158 if opts
.server_role
== "dc":
159 server_role
= "domain controller"
160 elif opts
.server_role
== "member":
161 server_role
= "member server"
163 server_role
= opts
.server_role
165 creds
= credopts
.get_credentials(lp
)
167 creds
.set_kerberos_state(DONT_USE_KERBEROS
)
169 setup_dir
= opts
.setupdir
170 if setup_dir
is None:
171 setup_dir
= find_setup_dir()
173 samdb_fill
= FILL_FULL
175 samdb_fill
= FILL_NT4SYNC
176 elif opts
.partitions_only
:
177 samdb_fill
= FILL_DRS
179 session
= system_session()
180 provision(setup_dir
, message
,
181 session
, creds
, smbconf
=smbconf
, targetdir
=opts
.targetdir
,
182 samdb_fill
=samdb_fill
, realm
=opts
.realm
, domain
=opts
.domain
,
183 domainguid
=opts
.domain_guid
, domainsid
=opts
.domain_sid
,
184 policyguid
=opts
.policy_guid
, hostname
=opts
.host_name
,
185 hostip
=opts
.host_ip
, hostip6
=opts
.host_ip6
,
186 invocationid
=opts
.invocationid
, adminpass
=opts
.adminpass
,
187 krbtgtpass
=opts
.krbtgtpass
, machinepass
=opts
.machinepass
,
188 dnspass
=opts
.dnspass
, root
=opts
.root
, nobody
=opts
.nobody
,
189 nogroup
=opts
.nogroup
, wheel
=opts
.wheel
, users
=opts
.users
,
190 aci
=opts
.aci
, serverrole
=server_role
,
191 ldap_backend
=opts
.ldap_backend
,
192 ldap_backend_type
=opts
.ldap_backend_type
)