The branch, master has been updated via 687e065 provision: Write configuration without help of templates. via bb4de6d pyparam: fix formatting. via 8524181 provision: Simplify make_smbconf a bit. via 3bfccdf provision: Fix order for error formatting. via e27e519 provision: Raise proper error when shares are missing rather than AssertionError. from 411119d provision: Share more code for determine_netbios_name() with samba.valid_netbios_name().
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 687e065036d0d39099a6ec909860c07144b8aa51 Author: Jelmer Vernooij <jel...@samba.org> Date: Sun Feb 26 23:15:48 2012 +0100 provision: Write configuration without help of templates. Autobuild-User: Jelmer Vernooij <jel...@samba.org> Autobuild-Date: Mon Feb 27 00:52:46 CET 2012 on sn-devel-104 commit bb4de6df6ef2ff155e2bdc10794c232a288b0a9b Author: Jelmer Vernooij <jel...@samba.org> Date: Sun Feb 26 22:43:15 2012 +0100 pyparam: fix formatting. commit 852418133ee5a8fc629bf8d3e01458eac6a0342d Author: Jelmer Vernooij <jel...@samba.org> Date: Sun Feb 26 22:23:27 2012 +0100 provision: Simplify make_smbconf a bit. commit 3bfccdfbc89acf9a88043698ded045042bf4c577 Author: Jelmer Vernooij <jel...@samba.org> Date: Sun Feb 26 22:09:44 2012 +0100 provision: Fix order for error formatting. commit e27e519bb8cc844da8b4114f5b6c0ea417e43578 Author: Jelmer Vernooij <jel...@samba.org> Date: Sun Feb 26 21:47:50 2012 +0100 provision: Raise proper error when shares are missing rather than AssertionError. ----------------------------------------------------------------------- Summary of changes: source4/param/pyparam.c | 22 ++-- .../scripting/python/samba/provision/__init__.py | 120 ++++++++++---------- source4/scripting/python/samba/tests/samdb.py | 4 +- source4/setup/provision.smb.conf.dc | 21 ---- source4/setup/provision.smb.conf.member | 12 -- source4/setup/provision.smb.conf.standalone | 12 -- 6 files changed, 73 insertions(+), 118 deletions(-) delete mode 100644 source4/setup/provision.smb.conf.dc delete mode 100644 source4/setup/provision.smb.conf.member delete mode 100644 source4/setup/provision.smb.conf.standalone Changeset truncated at 500 lines: diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c index 4d246a7..9874006 100644 --- a/source4/param/pyparam.c +++ b/source4/param/pyparam.c @@ -475,17 +475,17 @@ static PyObject *py_sbin_dir(PyObject *self) } static PyMethodDef pyparam_methods[] = { - { "default_path", (PyCFunction)py_default_path, METH_NOARGS, - "Returns the default smb.conf path." }, - { "setup_dir", (PyCFunction)py_setup_dir, METH_NOARGS, - "Returns the compiled in location of provision tempates." }, - { "modules_dir", (PyCFunction)py_modules_dir, METH_NOARGS, - "Returns the compiled in location of modules." }, - { "bin_dir", (PyCFunction)py_bin_dir, METH_NOARGS, - "Returns the compiled in BINDIR." }, - { "sbin_dir", (PyCFunction)py_sbin_dir, METH_NOARGS, - "Returns the compiled in SBINDIR." }, - { NULL } + { "default_path", (PyCFunction)py_default_path, METH_NOARGS, + "Returns the default smb.conf path." }, + { "setup_dir", (PyCFunction)py_setup_dir, METH_NOARGS, + "Returns the compiled in location of provision tempates." }, + { "modules_dir", (PyCFunction)py_modules_dir, METH_NOARGS, + "Returns the compiled in location of modules." }, + { "bin_dir", (PyCFunction)py_bin_dir, METH_NOARGS, + "Returns the compiled in BINDIR." }, + { "sbin_dir", (PyCFunction)py_sbin_dir, METH_NOARGS, + "Returns the compiled in SBINDIR." }, + { NULL } }; void initparam(void) diff --git a/source4/scripting/python/samba/provision/__init__.py b/source4/scripting/python/samba/provision/__init__.py index 3a69a07..48dd867 100644 --- a/source4/scripting/python/samba/provision/__init__.py +++ b/source4/scripting/python/samba/provision/__init__.py @@ -499,7 +499,6 @@ def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, netbiosname = lp.get("netbios name") if netbiosname is None: netbiosname = determine_netbios_name(hostname) - assert netbiosname is not None netbiosname = netbiosname.upper() if not valid_netbios_name(netbiosname): raise InvalidNetbiosName(netbiosname) @@ -527,7 +526,7 @@ def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, raise ProvisioningError("guess_names: 'realm=%s' in %s must match chosen realm '%s'! Please remove the smb.conf file and let provision generate it" % (lp.get("realm").upper(), realm, lp.configfile)) if lp.get("server role").lower() != serverrole: - raise ProvisioningError("guess_names: 'server role=%s' in %s must match chosen server role '%s'! Please remove the smb.conf file and let provision generate it" % (lp.get("server role"), serverrole, lp.configfile)) + raise ProvisioningError("guess_names: 'server role=%s' in %s must match chosen server role '%s'! Please remove the smb.conf file and let provision generate it" % (lp.get("server role"), lp.configfile, serverrole)) if serverrole == "domain controller": if domain is None: @@ -567,7 +566,7 @@ def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, schemadn = "CN=Schema," + configdn if sitename is None: - sitename=DEFAULTSITE + sitename = DEFAULTSITE names = ProvisionNames() names.rootdn = rootdn @@ -587,29 +586,21 @@ def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, return names -def make_smbconf(smbconf, hostname, domain, realm, serverrole, - targetdir, sid_generator="internal", eadb=False, lp=None, +def make_smbconf(smbconf, hostname, domain, realm, targetdir, + serverrole=None, sid_generator=None, eadb=False, lp=None, server_services=None): """Create a new smb.conf file based on a couple of basic settings. """ assert smbconf is not None + if hostname is None: hostname = socket.gethostname().split(".")[0] - netbiosname = determine_netbios_name(hostname) - else: - netbiosname = hostname.upper() + + netbiosname = determine_netbios_name(hostname) if serverrole is None: serverrole = "standalone" - assert serverrole in ("domain controller", "member server", "standalone") - if serverrole == "domain controller": - smbconfsuffix = "dc" - elif serverrole == "member server": - smbconfsuffix = "member" - elif serverrole == "standalone": - smbconfsuffix = "standalone" - if sid_generator is None: sid_generator = "internal" @@ -619,6 +610,14 @@ def make_smbconf(smbconf, hostname, domain, realm, serverrole, assert realm is not None realm = realm.upper() + global_settings = { + "passdb backend": "samba4", + "netbios name": netbiosname, + "workgroup": domain, + "realm": realm, + "server role": serverrole, + } + if lp is None: lp = samba.param.LoadParm() #Load non-existant file @@ -632,43 +631,39 @@ def make_smbconf(smbconf, hostname, domain, realm, serverrole, lp.set("posix:eadb", os.path.abspath(os.path.join(privdir, "eadb.tdb"))) if server_services is not None: - server_services_line = "server services = " + " ".join(server_services) - else: - server_services_line = "" + global_settings["server services"] = " ".join(server_services) if targetdir is not None: - privatedir_line = "private dir = " + os.path.abspath(os.path.join(targetdir, "private")) - lockdir_line = "lock dir = " + os.path.abspath(targetdir) - statedir_line = "state directory = " + os.path.abspath(targetdir) - cachedir_line = "cache directory = " + os.path.abspath(targetdir) + global_settings["private dir"] = os.path.abspath(os.path.join(targetdir, "private")) + global_settings["lock dir"] = os.path.abspath(targetdir) + global_settings["state directory"] = os.path.abspath(targetdir) + global_settings["cache directory"] = os.path.abspath(targetdir) lp.set("lock dir", os.path.abspath(targetdir)) lp.set("state directory", os.path.abspath(targetdir)) lp.set("cache directory", os.path.abspath(targetdir)) - else: - privatedir_line = "" - lockdir_line = "" - statedir_line = "" - cachedir_line = "" - - sysvol = os.path.join(lp.get("state directory"), "sysvol") - netlogon = os.path.join(sysvol, realm.lower(), "scripts") - - setup_file(setup_path("provision.smb.conf.%s" % smbconfsuffix), - smbconf, { - "NETBIOS_NAME": netbiosname, - "DOMAIN": domain, - "REALM": realm, - "SERVERROLE": serverrole, - "NETLOGONPATH": netlogon, - "SYSVOLPATH": sysvol, - "PRIVATEDIR_LINE": privatedir_line, - "LOCKDIR_LINE": lockdir_line, - "STATEDIR_LINE": statedir_line, - "CACHEDIR_LINE": cachedir_line, - "SERVER_SERVICES_LINE": server_services_line - }) + shares = {} + if serverrole == "domain controller": + shares["sysvol"] = os.path.join(global_settings["state directory"], + "sysvol") + shares["netlogon"] = os.path.join(shares["sysvol"], realm.lower(), + "scripts") + + f = open(smbconf, 'w') + try: + f.write("[globals]\n") + for key, val in global_settings.iteritems(): + f.write("\t%s = %s\n" % (key, val)) + f.write("\n") + + for name, path in shares.iteritems(): + f.write("[%s]\n" % name) + f.write("\tpath = %s\n" % path) + f.write("\tread only = no\n") + f.write("\n") + finally: + f.close() # reload the smb.conf lp.load(smbconf) @@ -1645,7 +1640,7 @@ def provision(logger, session_info, credentials, smbconf=None, server_services = None if dns_backend == "SAMBA_INTERNAL": - server_services = [ "+dns" ] + server_services = ["+dns"] # only install a new smb.conf if there isn't one there already if os.path.exists(smbconf): @@ -1659,12 +1654,13 @@ def provision(logger, session_info, credentials, smbconf=None, f.close() if data is None or data == "": make_smbconf(smbconf, hostname, domain, realm, - serverrole, targetdir, sid_generator, useeadb, + targetdir, serverrole=serverrole, + sid_generator=sid_generator, eadb=useeadb, lp=lp, server_services=server_services) else: - make_smbconf(smbconf, hostname, domain, realm, serverrole, - targetdir, sid_generator, useeadb, lp=lp, - server_services=server_services) + make_smbconf(smbconf, hostname, domain, realm, targetdir, + serverrole=serverrole, sid_generator=sid_generator, + eadb=useeadb, lp=lp, server_services=server_services) if lp is None: lp = samba.param.LoadParm() @@ -1779,17 +1775,12 @@ def provision(logger, session_info, credentials, smbconf=None, if serverrole == "domain controller": if paths.netlogon is None: - logger.info("Existing smb.conf does not have a [netlogon] share, but you are configuring a DC.") - logger.info("Please either remove %s or see the template at %s" % - (paths.smbconf, setup_path("provision.smb.conf.dc"))) - assert paths.netlogon is not None + raise MissingShareError("netlogon", paths.smbconf, + setup_path("provision.smb.conf.dc")) if paths.sysvol is None: - logger.info("Existing smb.conf does not have a [sysvol] share, but you" - " are configuring a DC.") - logger.info("Please either remove %s or see the template at %s" % - (paths.smbconf, setup_path("provision.smb.conf.dc"))) - assert paths.sysvol is not None + raise MissingShareError("sysvol", paths.smbconf, + setup_path("provision.smb.conf.dc")) if not os.path.isdir(paths.netlogon): os.makedirs(paths.netlogon, 0755) @@ -1931,3 +1922,12 @@ class InvalidNetbiosName(Exception): def __init__(self, name): super(InvalidNetbiosName, self).__init__( "The name '%r' is not a valid NetBIOS name" % name) + + +class MissingShareError(ProvisioningError): + + def __init__(self, name, smbconf, smbconf_template): + super(MissingShareError, self).__init__( + "Existing smb.conf does not have a [%s] share, but you are " + "configuring a DC. Please either remove %s or see the template " + "at %s" % (name, smbconf, smbconf_template)) diff --git a/source4/scripting/python/samba/tests/samdb.py b/source4/scripting/python/samba/tests/samdb.py index 3df72b0..a60062d 100644 --- a/source4/scripting/python/samba/tests/samdb.py +++ b/source4/scripting/python/samba/tests/samdb.py @@ -53,7 +53,7 @@ class SamDBTestCase(TestCaseInTempDir): domainsid = security.random_sid() path = os.path.join(self.tempdir, "samdb.ldb") session_info = system_session() - + hostname="foo" domain="EXAMPLE" dnsdomain="example.com" @@ -62,7 +62,7 @@ class SamDBTestCase(TestCaseInTempDir): smbconf = os.path.join(self.tempdir, "smb.conf") make_smbconf(smbconf, hostname, domain, dnsdomain, - serverrole, self.tempdir) + self.tempdir, serverrole=serverrole) self.lp = param.LoadParm() self.lp.load(smbconf) diff --git a/source4/setup/provision.smb.conf.dc b/source4/setup/provision.smb.conf.dc deleted file mode 100644 index ba8555f..0000000 --- a/source4/setup/provision.smb.conf.dc +++ /dev/null @@ -1,21 +0,0 @@ -[globals] - netbios name = ${NETBIOS_NAME} - workgroup = ${DOMAIN} - realm = ${REALM} - server role = ${SERVERROLE} - ${SERVER_SERVICES_LINE} - - ${PRIVATEDIR_LINE} - ${LOCKDIR_LINE} - ${STATEDIR_LINE} - ${CACHEDIR_LINE} - - passdb backend = samba4 - -[netlogon] - path = ${NETLOGONPATH} - read only = no - -[sysvol] - path = ${SYSVOLPATH} - read only = no diff --git a/source4/setup/provision.smb.conf.member b/source4/setup/provision.smb.conf.member deleted file mode 100644 index 0fc4de5..0000000 --- a/source4/setup/provision.smb.conf.member +++ /dev/null @@ -1,12 +0,0 @@ -[globals] - netbios name = ${NETBIOS_NAME} - workgroup = ${DOMAIN} - realm = ${REALM} - server role = ${SERVERROLE} - ${PRIVATEDIR_LINE} - ${LOCKDIR_LINE} - ${STATEDIR_LINE} - ${CACHEDIR_LINE} - - passdb backend = samba4 - diff --git a/source4/setup/provision.smb.conf.standalone b/source4/setup/provision.smb.conf.standalone deleted file mode 100644 index 0fc4de5..0000000 --- a/source4/setup/provision.smb.conf.standalone +++ /dev/null @@ -1,12 +0,0 @@ -[globals] - netbios name = ${NETBIOS_NAME} - workgroup = ${DOMAIN} - realm = ${REALM} - server role = ${SERVERROLE} - ${PRIVATEDIR_LINE} - ${LOCKDIR_LINE} - ${STATEDIR_LINE} - ${CACHEDIR_LINE} - - passdb backend = samba4 - -- Samba Shared Repository