diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2007-12-17 11:12:36 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2007-12-21 05:51:06 +0100 |
commit | 32f439bfa458f7936b507cb5a1e3c74bcb8c68bf (patch) | |
tree | 417c255fcd68bfc164e0916772060000fa19309a /source4/scripting/python/samba | |
parent | e956111917a432d5ea1a7c5cc2fef6c0c3dcbcc1 (diff) | |
download | samba-32f439bfa458f7936b507cb5a1e3c74bcb8c68bf.tar.gz samba-32f439bfa458f7936b507cb5a1e3c74bcb8c68bf.tar.xz samba-32f439bfa458f7936b507cb5a1e3c74bcb8c68bf.zip |
r26503: Change order of arguments in param interface so it's easier to make the
section name optional. Fix several smaller bits and pieces in the Python code.
(This used to be commit 1b89311e5fa4fcde060df50e580dc221205cc8ca)
Diffstat (limited to 'source4/scripting/python/samba')
-rw-r--r-- | source4/scripting/python/samba/__init__.py | 56 | ||||
-rw-r--r-- | source4/scripting/python/samba/provision.py | 30 | ||||
-rw-r--r-- | source4/scripting/python/samba/tests/__init__.py | 2 |
3 files changed, 45 insertions, 43 deletions
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py index 56adce44735..511dcd905a0 100644 --- a/source4/scripting/python/samba/__init__.py +++ b/source4/scripting/python/samba/__init__.py @@ -33,11 +33,9 @@ if _in_source_tree(): default_ldb_modules_dir = "%s/bin/modules/ldb" % srcdir -import misc import ldb -ldb.Ldb.set_credentials = misc.ldb_set_credentials -ldb.Ldb.set_session_info = misc.ldb_set_session_info -ldb.Ldb.set_loadparm = misc.ldb_set_loadparm +import credentials +import misc class Ldb(ldb.Ldb): """Simple Samba-specific LDB subclass that takes care @@ -47,38 +45,42 @@ class Ldb(ldb.Ldb): not necessarily the Sam database. For Sam-specific helper functions see samdb.py. """ - def __init__(url, session_info=None, credentials=None, modules_dir=None, - lp=None): + def __init__(self, url=None, session_info=None, credentials=None, + modules_dir=None, lp=None): """Open a Samba Ldb file. - :param url: LDB Url to open + :param url: Optional LDB URL to open :param session_info: Optional session information :param credentials: Optional credentials, defaults to anonymous. - :param modules_dir: Modules directory, automatically set if not specified. + :param modules_dir: Modules directory, if not the default. :param lp: Loadparm object, optional. This is different from a regular Ldb file in that the Samba-specific modules-dir is used by default and that credentials and session_info can be passed through (required by some modules). """ - super(self, Ldb).__init__() - import ldb - ret = ldb.Ldb() - if modules_dir is None: - modules_dir = default_ldb_modules_dir + super(Ldb, self).__init__() + if modules_dir is not None: - ret.set_modules_dir(modules_dir) - def samba_debug(level,text): - print "%d %s" % (level, text) + self.set_modules_dir(modules_dir) + elif default_ldb_modules_dir is not None: + self.set_modules_dir(default_ldb_modules_dir) + if credentials is not None: - ldb.set_credentials(credentials) + self.set_credentials(self, credentials) + if session_info is not None: - ldb.set_session_info(session_info) + self.set_session_info(self, session_info) + if lp is not None: - ldb.set_loadparm(lp) - #ret.set_debug(samba_debug) - ret.connect(url) - return ret + self.set_loadparm(self, lp) + + if url: + self.connect(url) + + set_credentials = misc.ldb_set_credentials + set_session_info = misc.ldb_set_session_info + set_loadparm = misc.ldb_set_loadparm def searchone(self, basedn, expression, attribute): """Search for one attribute as a string.""" @@ -93,19 +95,19 @@ class Ldb(ldb.Ldb): for attr in ["@INDEXLIST", "@ATTRIBUTES", "@SUBCLASSES", "@MODULES", "@OPTIONS", "@PARTITION", "@KLUDGEACL"]: try: - self.delete(Dn(self, attr)) - except LdbError, (LDB_ERR_NO_SUCH_OBJECT, _): + self.delete(ldb.Dn(self, attr)) + except ldb.LdbError, (LDB_ERR_NO_SUCH_OBJECT, _): # Ignore missing dn errors pass - basedn = Dn(self, "") + basedn = ldb.Dn(self, "") # and the rest - for msg in self.search(basedn, SCOPE_SUBTREE, + for msg in self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"]): self.delete(msg.dn) - res = self.search(basedn, SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"]) + res = self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"]) assert len(res) == 0 diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 60dcf06c832..5332a9f9ff4 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -16,6 +16,7 @@ import param import registry from samba import Ldb, substitute_var, valid_netbios_name from samba.samdb import SamDB +import security from ldb import Dn, SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \ LDB_ERR_NO_SUCH_OBJECT, timestring @@ -69,7 +70,7 @@ class ProvisionSettings(object): "DOMAINDN_LDB": self.domaindn_ldb, "DOMAINDN_MOD": "pdc_fsmo,password_hash", "DOMAINDN_MOD2": ",objectguid", - "DOMAINSID": self.domainsid, + "DOMAINSID": str(self.domainsid), "MODULES_LIST": ",".join(self.modules_list), "CONFIGDN_MOD": "naming_fsmo", "CONFIGDN_MOD2": ",objectguid", @@ -115,13 +116,13 @@ class ProvisionSettings(object): if not valid_netbios_name(self.netbiosname): raise InvalidNetbiosName(self.netbiosname) - if lp.get("workgroup").upper() != self.domain.upper(): + if lp.get_string("workgroup").upper() != self.domain.upper(): raise Error("workgroup '%s' in smb.conf must match chosen domain '%s'\n", - lp.get("workgroup"), self.domain) + lp.get_string("workgroup"), self.domain) - if lp.get("realm").upper() != self.realm.upper(): + if lp.get_string("realm").upper() != self.realm.upper(): raise Error("realm '%s' in smb.conf must match chosen realm '%s'\n" % - (lp.get("realm"), self.realm)) + (lp.get_string("realm"), self.realm)) class ProvisionPaths: @@ -147,9 +148,9 @@ class ProvisionPaths: def install_ok(lp, session_info, credentials): """Check whether the current install seems ok.""" - if lp.get("realm") == "": + if lp.get_string("realm") == "": return False - ldb = Ldb(lp.get("sam database"), session_info=session_info, + ldb = Ldb(lp.get_string("sam database"), session_info=session_info, credentials=credentials) if len(ldb.search("(cn=Administrator)")) != 1: return False @@ -166,7 +167,6 @@ def findnss(nssfn, *names): raise Exception("Unable to find user/group for %s" % arguments[1]) - def hostip(): """return first host IP.""" return gethostbyname(hostname()) @@ -230,7 +230,7 @@ def setup_ldb(setup_dir, ldif, session_info, credentials, subobj, dbname, ldb.transaction_start() try: if erase: - ldb_erase(ldb); + ldb.erase(); setup_add_ldif(setup_dir, ldif, subobj, ldb) except: ldb.transaction_cancel() @@ -271,10 +271,10 @@ def provision_default_paths(lp, subobj): :param subobj: Object """ paths = ProvisionPaths() - private_dir = lp.get("private dir") + private_dir = lp.get_string("private dir") paths.shareconf = os.path.join(private_dir, "share.ldb") - paths.samdb = lp.get("sam database") or os.path.join(private_dir, "samdb.ldb") - paths.secrets = lp.get("secrets database") or os.path.join(private_dir, "secrets.ldb") + paths.samdb = lp.get_string("sam database") or os.path.join(private_dir, "samdb.ldb") + paths.secrets = lp.get_string("secrets database") or os.path.join(private_dir, "secrets.ldb") paths.templates = os.path.join(private_dir, "templates.ldb") paths.keytab = os.path.join(private_dir, "secrets.keytab") paths.dns = os.path.join(private_dir, subobj.dnsdomain + ".zone") @@ -572,8 +572,8 @@ def provision_ldapbase(setup_dir, subobj, message, paths): def provision_guess(lp): """guess reasonably default options for provisioning.""" - subobj = ProvisionSettings(realm=lp.get("realm").upper(), - domain=lp.get("workgroup"), + subobj = ProvisionSettings(realm=lp.get_string("realm").upper(), + domain=lp.get_string("workgroup"), hostname=hostname(), hostip=hostip()) @@ -581,7 +581,7 @@ def provision_guess(lp): assert subobj.domain is not None assert subobj.hostname is not None - subobj.domainsid = sid.random() + subobj.domainsid = security.random_sid() subobj.invocationid = uuid.random() subobj.policyguid = uuid.random() subobj.krbtgtpass = misc.random_password(12) diff --git a/source4/scripting/python/samba/tests/__init__.py b/source4/scripting/python/samba/tests/__init__.py index d374f8bafab..d3930e217aa 100644 --- a/source4/scripting/python/samba/tests/__init__.py +++ b/source4/scripting/python/samba/tests/__init__.py @@ -27,7 +27,7 @@ class LdbTestCase(unittest.TestCase): self.filename = os.tempnam() self.ldb = samba.Ldb(self.filename) - def load_modules(self, modules=[]): + def set_modules(self, modules=[]): m = ldb.Message() m.dn = ldb.Dn(self.ldb, "@MODULES") m["@LIST"] = ",".join(modules) |