1
0
mirror of https://github.com/samba-team/samba.git synced 2025-11-14 12:23:52 +03:00

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 commit is contained in:
Jelmer Vernooij
2007-12-17 11:12:36 +01:00
committed by Stefan Metzmacher
parent b87e71ed4b
commit 1b89311e5f
13 changed files with 431 additions and 148 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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)