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/>.
27 sys
.path
.insert(0, "bin/python")
33 from samba
import param
35 from samba
.auth
import system_session
36 import samba
.getopt
as options
37 from samba
.provision
import provision_backend
, find_setup_dir
39 parser
= optparse
.OptionParser("provision [options]")
40 sambaopts
= options
.SambaOptions(parser
)
41 parser
.add_option_group(sambaopts
)
42 parser
.add_option_group(options
.VersionOptions(parser
))
43 credopts
= options
.CredentialsOptions(parser
)
44 parser
.add_option_group(credopts
)
45 parser
.add_option("--setupdir", type="string", metavar
="DIR",
46 help="directory with setup files")
47 parser
.add_option("--realm", type="string", metavar
="REALM", help="set realm")
48 parser
.add_option("--domain", type="string", metavar
="DOMAIN",
50 parser
.add_option("--host-name", type="string", metavar
="HOSTNAME",
52 parser
.add_option("--ldap-admin-pass", type="string", metavar
="PASSWORD",
53 help="choose LDAP admin password (otherwise random)")
54 parser
.add_option("--root", type="string", metavar
="USERNAME",
55 help="choose 'root' unix username")
56 parser
.add_option("--quiet", help="Be quiet", action
="store_true")
57 parser
.add_option("--ldap-backend-type", type="choice", metavar
="LDAP-BACKEND-TYPE",
58 help="LDB mapping module to use for the LDAP backend",
59 choices
=["fedora-ds", "openldap"])
60 parser
.add_option("--ldap-backend-port", type="int", metavar
="PORT",
61 help="TCP Port LDAP server should listen to (default ldapi only)")
62 parser
.add_option("--server-role", type="choice", metavar
="ROLE",
63 choices
=["domain controller", "dc", "member server", "member", "standalone"],
64 help="Set server role to provision for (default standalone)")
65 parser
.add_option("--targetdir", type="string", metavar
="DIR",
66 help="Set target directory")
67 parser
.add_option("--ol-mmr-urls", type="string", metavar
="LDAPSERVER",
68 help="List of LDAP-URLS [ ldap://<FQDN>:port/ (where port != 389) ] separated with whitespaces for use with OpenLDAP-MMR (Multi-Master-Replication)")
69 parser
.add_option("--ol-olc", type="choice", metavar
="OPENLDAP-OLC",
70 help="To setup OpenLDAP-Backend with Online-Configuration [slapd.d] choose 'yes'",
71 choices
=["yes", "no"])
72 parser
.add_option("--ol-slaptest", type="string", metavar
="SLAPTEST-PATH",
73 help="Path to slaptest-binary [e.g.:'/usr/local/sbin']. Only for use with --ol-olc='yes'")
75 opts
= parser
.parse_args()[0]
78 """print a message if quiet is not set."""
82 if opts
.realm
is None or opts
.domain
is None:
83 if opts
.realm
is None:
84 print >>sys
.stderr
, "No realm set"
85 if opts
.domain
is None:
86 print >>sys
.stderr
, "No domain set"
90 smbconf
= sambaopts
.get_loadparm().configfile
92 if opts
.server_role
== "dc":
93 server_role
= "domain controller"
94 elif opts
.server_role
== "member":
95 server_role
= "member server"
97 server_role
= opts
.server_role
99 setup_dir
= opts
.setupdir
100 if setup_dir
is None:
101 setup_dir
= find_setup_dir()
103 provision_backend(setup_dir
=setup_dir
, message
=message
, smbconf
=smbconf
, targetdir
=opts
.targetdir
,
104 realm
=opts
.realm
, domain
=opts
.domain
,
105 hostname
=opts
.host_name
,
106 adminpass
=opts
.ldap_admin_pass
,
107 root
=opts
.root
, serverrole
=server_role
,
108 ldap_backend_type
=opts
.ldap_backend_type
,
109 ldap_backend_port
=opts
.ldap_backend_port
,
110 ol_mmr_urls
=opts
.ol_mmr_urls
,
112 ol_slaptest
=opts
.ol_slaptest
)