Fix an uninitialized variable
[Samba.git] / source4 / setup / provision-backend
blob28e73ae3022f4bb975b56ff14e7c989e2e52e3d9
1 #!/usr/bin/python
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
7 # Copyright (C) Oliver Liebel <oliver@itc.li> 2008-2009
9 # Based on the original in EJS:
10 # Copyright (C) Andrew Tridgell 2005
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 import os, sys
28 sys.path.insert(0, "bin/python")
30 import getopt
31 import optparse
33 import samba
34 from samba import param
36 from samba.auth import system_session
37 import samba.getopt as options
38 from samba.provision import provision_backend, find_setup_dir
40 parser = optparse.OptionParser("provision [options]")
41 sambaopts = options.SambaOptions(parser)
42 parser.add_option_group(sambaopts)
43 parser.add_option_group(options.VersionOptions(parser))
44 credopts = options.CredentialsOptions(parser)
45 parser.add_option_group(credopts)
46 parser.add_option("--setupdir", type="string", metavar="DIR",
47 help="directory with setup files")
48 parser.add_option("--realm", type="string", metavar="REALM", help="set realm")
49 parser.add_option("--domain", type="string", metavar="DOMAIN",
50 help="set domain")
51 parser.add_option("--host-name", type="string", metavar="HOSTNAME",
52 help="set hostname")
53 parser.add_option("--ldap-admin-pass", type="string", metavar="PASSWORD",
54 help="choose LDAP admin password (otherwise random)")
55 parser.add_option("--root", type="string", metavar="USERNAME",
56 help="choose 'root' unix username")
57 parser.add_option("--quiet", help="Be quiet", action="store_true")
58 parser.add_option("--ldap-backend-type", type="choice", metavar="LDAP-BACKEND-TYPE",
59 help="LDB mapping module to use for the LDAP backend",
60 choices=["fedora-ds", "openldap"])
61 parser.add_option("--ldap-backend-port", type="int", metavar="PORT",
62 help="TCP Port LDAP server should listen to (default ldapi only)")
63 parser.add_option("--server-role", type="choice", metavar="ROLE",
64 choices=["domain controller", "dc", "member server", "member", "standalone"],
65 help="Set server role to provision for (default standalone)")
66 parser.add_option("--targetdir", type="string", metavar="DIR",
67 help="Set target directory")
68 parser.add_option("--ol-mmr-urls", type="string", metavar="LDAPSERVER",
69 help="List of LDAP-URLS [ ldap://<FQHN>:<PORT>/ (where <PORT> has to be different from 389!) ] separated with whitespaces for use with OpenLDAP-MMR (Multi-Master-Replication)")
70 parser.add_option("--ol-olc", type="choice", metavar="OPENLDAP-OLC",
71 help="To setup OpenLDAP-Backend with Online-Configuration [slapd.d] choose 'yes'. Note: Only OpenLDAP-Versions greater or equal 2.4.15 should be used!",
72 choices=["yes", "no"])
73 parser.add_option("--ol-slaptest", type="string", metavar="SLAPTEST-PATH",
74 help="Path to slaptest-binary [e.g.:'/usr/local/sbin']. Only for use with --ol-olc='yes'")
76 opts = parser.parse_args()[0]
78 def message(text):
79 """print a message if quiet is not set."""
80 if not opts.quiet:
81 print text
83 if opts.realm is None or opts.domain is None:
84 if opts.realm is None:
85 print >>sys.stderr, "No realm set"
86 if opts.domain is None:
87 print >>sys.stderr, "No domain set"
88 parser.print_usage()
89 sys.exit(1)
91 smbconf = sambaopts.get_loadparm().configfile
93 if opts.server_role == "dc":
94 server_role = "domain controller"
95 elif opts.server_role == "member":
96 server_role = "member server"
97 else:
98 server_role = opts.server_role
100 setup_dir = opts.setupdir
101 if setup_dir is None:
102 setup_dir = find_setup_dir()
104 provision_backend(setup_dir=setup_dir, message=message, smbconf=smbconf, targetdir=opts.targetdir,
105 realm=opts.realm, domain=opts.domain,
106 hostname=opts.host_name,
107 adminpass=opts.ldap_admin_pass,
108 root=opts.root, serverrole=server_role,
109 ldap_backend_type=opts.ldap_backend_type,
110 ldap_backend_port=opts.ldap_backend_port,
111 ol_mmr_urls=opts.ol_mmr_urls,
112 ol_olc=opts.ol_olc,
113 ol_slaptest=opts.ol_slaptest)