~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source4/setup/provision

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
 
1
#!/usr/bin/env python
2
2
#
3
3
# Unix SMB/CIFS implementation.
4
4
# provision a Samba4 server
22
22
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
23
#
24
24
 
 
25
import logging
25
26
import optparse
26
27
import sys
 
28
import tempfile
27
29
 
28
30
# Find right directory when running from source tree
29
31
sys.path.insert(0, "bin/python")
30
32
 
31
33
import samba
 
34
import samba.ntacls
32
35
from samba.credentials import DONT_USE_KERBEROS
33
36
from samba.auth import system_session
34
37
import samba.getopt as options
35
 
from samba.provision import provision, FILL_FULL, FILL_NT4SYNC, FILL_DRS, find_setup_dir
 
38
from samba.provision import provision, FILL_FULL, FILL_NT4SYNC, FILL_DRS, ProvisioningError
 
39
from samba.dsdb import (
 
40
        DS_DOMAIN_FUNCTION_2000,
 
41
        DS_DOMAIN_FUNCTION_2003,
 
42
        DS_DOMAIN_FUNCTION_2008,
 
43
        DS_DOMAIN_FUNCTION_2008_R2,
 
44
        )
36
45
 
37
46
# how do we make this case insensitive??
38
47
 
43
52
credopts = options.CredentialsOptions(parser)
44
53
parser.add_option_group(credopts)
45
54
parser.add_option("--interactive", help="Ask for names", action="store_true")
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
55
parser.add_option("--domain", type="string", metavar="DOMAIN",
50
56
                                  help="set domain")
51
57
parser.add_option("--domain-guid", type="string", metavar="GUID", 
52
58
                help="set domainguid (otherwise random)")
53
59
parser.add_option("--domain-sid", type="string", metavar="SID", 
54
60
                help="set domainsid (otherwise random)")
55
 
parser.add_option("--policy-guid", type="string", metavar="GUID",
56
 
                                  help="set guid for domain policy")
57
 
parser.add_option("--policy-guid-dc", type="string", metavar="GUID",
58
 
                                  help="set guid for domain controller policy")
 
61
parser.add_option("--ntds-guid", type="string", metavar="GUID", 
 
62
                  help="set NTDS object GUID (otherwise random)")
59
63
parser.add_option("--invocationid", type="string", metavar="GUID", 
60
64
                  help="set invocationid (otherwise random)")
61
65
parser.add_option("--host-name", type="string", metavar="HOSTNAME", 
87
91
                help="do not add users or groups, just the structure")
88
92
parser.add_option("--ldap-backend-extra-port", type="int", metavar="LDAP-BACKEND-EXTRA-PORT", 
89
93
                help="Additional TCP port for LDAP backend server (to use for replication)")
 
94
parser.add_option("--ldap-backend-forced-uri", type="string", metavar="LDAP-BACKEND-FORCED-URI", 
 
95
                help="Force the LDAP backend connection to be to a particular URI.  Use this ONLY for 'existing' backends, or when debugging the interaction with the LDAP backend and you need to intercept the LDAP traffic")
90
96
parser.add_option("--ldap-backend-type", type="choice", metavar="LDAP-BACKEND-TYPE", 
91
97
                help="LDAP backend type (fedora-ds or openldap)",
92
98
                choices=["fedora-ds", "openldap"])
93
99
parser.add_option("--ldap-backend-nosync", help="Configure LDAP backend not to call fsync() (for performance in test environments)", action="store_true")
94
100
parser.add_option("--server-role", type="choice", metavar="ROLE",
95
101
                  choices=["domain controller", "dc", "member server", "member", "standalone"],
96
 
                help="Set server role to provision for (default standalone)")
 
102
                help="The server role (domain controller | dc | member server | member | standalone). Default is standalone.")
 
103
parser.add_option("--function-level", type="choice", metavar="FOR-FUN-LEVEL",
 
104
                  choices=["2000", "2003", "2008", "2008_R2"],
 
105
                help="The domain and forest function level (2000 | 2003 | 2008 | 2008_R2 - always native). Default is (Windows) 2003 Native.")
 
106
parser.add_option("--next-rid", type="int", metavar="NEXTRID", default=1000,
 
107
                help="The initial nextRid value (only needed for upgrades).  Default is 1000.")
97
108
parser.add_option("--partitions-only", 
98
109
                help="Configure Samba's partitions, but do not modify them (ie, join a BDC)", action="store_true")
99
110
parser.add_option("--targetdir", type="string", metavar="DIR", 
100
111
                          help="Set target directory")
101
112
parser.add_option("--ol-mmr-urls", type="string", metavar="LDAPSERVER",
102
 
                help="List of LDAP-URLS [ ldap://<FQHN>:<PORT>/  (where <PORT> has to be different than 389!) ] separated with whitespaces for use with OpenLDAP-MMR (Multi-Master-Replication)")
 
113
                help="List of LDAP-URLS [ ldap://<FQHN>:<PORT>/  (where <PORT> has to be different than 389!) ] separated with comma (\",\") for use with OpenLDAP-MMR (Multi-Master-Replication), e.g.: \"ldap://s4dc1:9000,ldap://s4dc2:9000\"")
103
114
parser.add_option("--slapd-path", type="string", metavar="SLAPD-PATH", 
104
115
                help="Path to slapd for LDAP backend [e.g.:'/usr/local/libexec/slapd']. Required for Setup with LDAP-Backend. OpenLDAP Version >= 2.4.17 should be used.") 
105
116
parser.add_option("--setup-ds-path", type="string", metavar="SETUP_DS-PATH", 
106
117
                help="Path to setup-ds.pl script for Fedora DS LDAP backend [e.g.:'/usr/sbin/setup-ds.pl']. Required for Setup with Fedora DS backend.") 
107
 
parser.add_option("--nosync", help="Configure LDAP backend not to call fsync() (for performance in test environments)", action="store_true")
 
118
parser.add_option("--use-xattrs", type="choice", choices=["yes","no","auto"], help="Define if we should use the native fs capabilities or a tdb file for storing attributes likes ntacl, auto tries to make an inteligent guess based on the user rights and system capabilities", default="auto")
108
119
parser.add_option("--ldap-dryrun-mode", help="Configure LDAP backend, but do not run any binaries and exit early.  Used only for the test environment.  DO NOT USE", action="store_true")
109
120
 
110
121
opts = parser.parse_args()[0]
111
122
 
112
 
def message(text):
113
 
        """print a message if quiet is not set."""
114
 
        if not opts.quiet:
115
 
                print text
 
123
logger = logging.getLogger("provision")
 
124
logger.addHandler(logging.StreamHandler(sys.stdout))
 
125
if opts.quiet:
 
126
        logger.setLevel(logging.WARNING)
 
127
else:
 
128
        logger.setLevel(logging.INFO)
116
129
 
117
130
if len(sys.argv) == 1:
118
131
        opts.interactive = True
119
132
 
120
 
if not opts.interactive and (opts.realm is None or opts.domain is None):
121
 
        if opts.realm is None:
122
 
                print >>sys.stderr, "No realm set"
123
 
        if opts.domain is None:
124
 
                print >>sys.stderr, "No domain set"
125
 
        parser.print_usage()
126
 
        sys.exit(1)
127
 
 
128
133
if opts.interactive:
129
134
        from getpass import getpass
130
135
        import socket
135
140
                        print "%s: " % (prompt,),
136
141
                return sys.stdin.readline().rstrip("\n") or default
137
142
        try:
138
 
                opts.realm = ask("Realm", socket.getfqdn().split(".", 1)[1].upper())
 
143
                default = socket.getfqdn().split(".", 1)[1].upper()
139
144
        except IndexError:
140
 
                print >>sys.stderr, "Cannot guess realm from %s" % ( socket.getfqdn())
 
145
                default = None
 
146
        opts.realm = ask("Realm", default)
 
147
        if opts.realm in (None, ""):
 
148
                print >>sys.stderr, "No realm set!"
141
149
                sys.exit(1)
142
150
 
143
151
        try:
144
 
                opts.domain = ask("Domain", opts.realm.split(".")[0])
 
152
                default = opts.realm.split(".")[0]
145
153
        except IndexError:
146
 
                print >>sys.stderr, "Cannot guess domain from %s" % ( opts.realm())
 
154
                default = None
 
155
        opts.domain = ask("Domain", default)
 
156
        if opts.domain is None:
 
157
                print >> sys.stderr, "No domain set!"
147
158
                sys.exit(1)
148
159
 
149
160
        opts.server_role = ask("Server Role (dc, member, standalone)", "dc")
153
164
                        print >>sys.stderr, "Invalid administrator password."
154
165
                else:
155
166
                        break
 
167
else:
 
168
        if opts.realm in (None, ""):
 
169
                opts.realm = sambaopts._lp.get('realm')
 
170
        if opts.realm is None or opts.domain is None:
 
171
                if opts.realm is None:
 
172
                        print >>sys.stderr, "No realm set!"
 
173
                if opts.domain is None:
 
174
                        print >> sys.stderr, "No domain set!"
 
175
                parser.print_usage()
 
176
                sys.exit(1)
 
177
 
 
178
if not opts.adminpass:
 
179
        logger.info("Administrator password will be set randomly!")
156
180
 
157
181
lp = sambaopts.get_loadparm()
158
182
smbconf = lp.configfile
164
188
else:
165
189
        server_role = opts.server_role
166
190
 
 
191
if opts.function_level is None:
 
192
        dom_for_fun_level = None
 
193
elif opts.function_level == "2000":
 
194
        dom_for_fun_level = DS_DOMAIN_FUNCTION_2000
 
195
elif opts.function_level == "2003":
 
196
        dom_for_fun_level = DS_DOMAIN_FUNCTION_2003
 
197
elif opts.function_level == "2008":
 
198
        dom_for_fun_level = DS_DOMAIN_FUNCTION_2008
 
199
elif opts.function_level == "2008_R2":
 
200
        dom_for_fun_level = DS_DOMAIN_FUNCTION_2008_R2
 
201
 
167
202
creds = credopts.get_credentials(lp)
168
203
 
169
204
creds.set_kerberos_state(DONT_USE_KERBEROS)
170
205
 
171
 
setup_dir = opts.setupdir
172
 
if setup_dir is None:
173
 
        setup_dir = find_setup_dir()
174
 
 
175
206
samdb_fill = FILL_FULL
176
207
if opts.blank:
177
208
    samdb_fill = FILL_NT4SYNC
178
209
elif opts.partitions_only:
179
210
    samdb_fill = FILL_DRS
180
211
 
 
212
eadb = True
 
213
if opts.use_xattrs == "yes":
 
214
        eadb = False
 
215
elif opts.use_xattrs == "auto" and not lp.get("posix:eadb"):
 
216
        file = tempfile.NamedTemporaryFile()
 
217
        try:
 
218
                samba.ntacls.setntacl(lp, file.name, 
 
219
                        "O:S-1-5-32G:S-1-5-32", "S-1-5-32", "native")
 
220
                eadb = False
 
221
        except:
 
222
                logger.info("You are not root or your system do not support xattr, using tdb backend for attributes. "
 
223
                            "If you intend to use this provision in production, rerun the script as root on a system supporting xattrs.")
 
224
        file.close()
 
225
 
 
226
 
 
227
if opts.ldap_backend_type == "existing":
 
228
        if opts.ldap_backend_forced_uri is not None:
 
229
                logger.warn("You have specified to use an existing LDAP server as the backend, please make sure an LDAP server is running at %s" % opts.ldap_backend_forced_uri)
 
230
        else:
 
231
                logger.info("You have specified to use an existing LDAP server as the backend, please make sure an LDAP server is running at the default location")
 
232
else:
 
233
        if opts.ldap_backend_forced_uri is not None:
 
234
                logger.warn("You have specified to use an fixed URI %s for connecting to your LDAP server backend.  This is NOT RECOMMENDED, as our default communiation over ldapi:// is more secure and much less prone to unexpected failure or interaction" % opts.ldap_backend_forced_uri)
 
235
        
181
236
session = system_session()
182
 
provision(setup_dir, message, 
183
 
          session, creds, smbconf=smbconf, targetdir=opts.targetdir,
184
 
          samdb_fill=samdb_fill, realm=opts.realm, domain=opts.domain,
185
 
          domainguid=opts.domain_guid, domainsid=opts.domain_sid,
186
 
          policyguid=opts.policy_guid, policyguid_dc=opts.policy_guid_dc,
187
 
          hostname=opts.host_name,
188
 
          hostip=opts.host_ip, hostip6=opts.host_ip6,
189
 
          invocationid=opts.invocationid, adminpass=opts.adminpass,
190
 
          krbtgtpass=opts.krbtgtpass, machinepass=opts.machinepass,
191
 
          dnspass=opts.dnspass, root=opts.root, nobody=opts.nobody,
192
 
          wheel=opts.wheel, users=opts.users,
193
 
          serverrole=server_role, 
194
 
          ldap_backend_extra_port=opts.ldap_backend_extra_port, 
195
 
          ldap_backend_type=opts.ldap_backend_type,
196
 
          ldapadminpass=opts.ldapadminpass,
197
 
          ol_mmr_urls=opts.ol_mmr_urls,
198
 
          slapd_path=opts.slapd_path,
199
 
          setup_ds_path=opts.setup_ds_path,
200
 
          nosync=opts.nosync,
201
 
          ldap_dryrun_mode=opts.ldap_dryrun_mode)
 
237
try:
 
238
        provision(logger,
 
239
                  session, creds, smbconf=smbconf, targetdir=opts.targetdir,
 
240
                  samdb_fill=samdb_fill, realm=opts.realm, domain=opts.domain,
 
241
                  domainguid=opts.domain_guid, domainsid=opts.domain_sid,
 
242
                  hostname=opts.host_name,
 
243
                  hostip=opts.host_ip, hostip6=opts.host_ip6,
 
244
                  ntdsguid=opts.ntds_guid,
 
245
                  invocationid=opts.invocationid, adminpass=opts.adminpass,
 
246
                  krbtgtpass=opts.krbtgtpass, machinepass=opts.machinepass,
 
247
                  dnspass=opts.dnspass, root=opts.root, nobody=opts.nobody,
 
248
                  wheel=opts.wheel, users=opts.users,
 
249
                  serverrole=server_role, dom_for_fun_level=dom_for_fun_level,
 
250
                  ldap_backend_extra_port=opts.ldap_backend_extra_port,
 
251
                  ldap_backend_forced_uri=opts.ldap_backend_forced_uri,
 
252
                  backend_type=opts.ldap_backend_type,
 
253
                  ldapadminpass=opts.ldapadminpass, ol_mmr_urls=opts.ol_mmr_urls,
 
254
                  slapd_path=opts.slapd_path, setup_ds_path=opts.setup_ds_path,
 
255
                  nosync=opts.ldap_backend_nosync, ldap_dryrun_mode=opts.ldap_dryrun_mode, 
 
256
                  useeadb=eadb, next_rid=opts.next_rid, lp=lp)
 
257
except ProvisioningError, e:
 
258
        print str(e)
 
259
        exit(1)