[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha8-1055-g7a79d16
Matthias Dieter Wallnöfer
mdw at samba.org
Mon Aug 17 04:10:02 MDT 2009
The branch, master has been updated
via 7a79d161838efcec27a159fc40481e7be419b778 (commit)
via 0a5ea25d21a9745508e118a20fca837e74b031df (commit)
via 0a46fd630e38134a080214119e5712673687f7c0 (commit)
via faedda0455da90aa8d5500eb2263b6ade3b72ec1 (commit)
from 36f828bafb973586157e9745593418994a962a34 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 7a79d161838efcec27a159fc40481e7be419b778
Author: Matthias Dieter Wallnöfer <mwallnoefer at yahoo.de>
Date: Sat Aug 15 15:20:09 2009 +0200
s4: Major rework of the LDB/SAMDB/IDMAP python bindings
- Centralise the lookups for the default domain (root) in the call "domain_dn"
- Reduce the LDB connections attempts ("connect" calls) from three to one
- tools should load faster
- Make the LDB connection init more like the "ldb_wrap_connection" call
- Load the right UTF8 casefolder which fixes up problems with special characters
(discovered by me: e.g. small "Umlaute" (ä, ö, ü, ...) in the DN weren't upcased
- so records "seemed" lost in TDB)
commit 0a5ea25d21a9745508e118a20fca837e74b031df
Author: Matthias Dieter Wallnöfer <mwallnoefer at yahoo.de>
Date: Mon Aug 17 11:47:53 2009 +0200
s4:python tools - Centralise the lookups for the default domain (root) in the call "domain_dn" from SamDB
commit 0a46fd630e38134a080214119e5712673687f7c0
Author: Matthias Dieter Wallnöfer <mwallnoefer at yahoo.de>
Date: Mon Aug 17 11:46:23 2009 +0200
s4:pyglue Add a wrapper for loading the correct UTF8 casefolder
Needed for special characters (e.g. in German "Umlaute")
commit faedda0455da90aa8d5500eb2263b6ade3b72ec1
Author: Matthias Dieter Wallnöfer <mwallnoefer at yahoo.de>
Date: Sat Aug 15 15:18:46 2009 +0200
s4:ldb python bindings: Handle the parameters of the connect call in the right way
-----------------------------------------------------------------------
Summary of changes:
source4/lib/ldb/pyldb.c | 10 +++-
source4/scripting/python/pyglue.c | 20 ++++++++
source4/scripting/python/samba/__init__.py | 35 +++++++++-----
source4/scripting/python/samba/idmap.py | 26 +++++-----
source4/scripting/python/samba/samdb.py | 51 ++++++++------------
source4/setup/enableaccount | 11 +---
source4/setup/pwsettings | 12 ++---
7 files changed, 92 insertions(+), 73 deletions(-)
delete mode 100644 source4/scripting/python/samba/tests/dcerpc/__init__.py
Changeset truncated at 500 lines:
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index a9425b5..5825f88 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -6,6 +6,7 @@
Copyright (C) 2005,2006 Tim Potter <tpot at samba.org>
Copyright (C) 2006 Simo Sorce <idra at samba.org>
Copyright (C) 2007-2009 Jelmer Vernooij <jelmer at samba.org>
+ Copyright (C) 2009 Matthias Dieter Wallnöfer
** NOTE! The following LGPL license applies to the ldb
** library. This does NOT imply that all of Samba is released
@@ -612,7 +613,7 @@ static PyObject *py_ldb_connect(PyLdbObject *self, PyObject *args, PyObject *kwa
const char **options;
const char * const kwnames[] = { "url", "flags", "options", NULL };
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iO",
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ziO",
discard_const_p(char *, kwnames),
&url, &flags, &py_options))
return NULL;
@@ -2327,9 +2328,14 @@ void initldb(void)
PyModule_AddObject(m, "ERR_ENTRY_ALREADY_EXISTS", PyInt_FromLong(LDB_ERR_ENTRY_ALREADY_EXISTS));
PyModule_AddObject(m, "ERR_OBJECT_CLASS_MODS_PROHIBITED", PyInt_FromLong(LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED));
PyModule_AddObject(m, "ERR_AFFECTS_MULTIPLE_DSAS", PyInt_FromLong(LDB_ERR_AFFECTS_MULTIPLE_DSAS));
-
PyModule_AddObject(m, "ERR_OTHER", PyInt_FromLong(LDB_ERR_OTHER));
+ PyModule_AddObject(m, "FLG_RDONLY", PyInt_FromLong(LDB_FLG_RDONLY));
+ PyModule_AddObject(m, "FLG_NOSYNC", PyInt_FromLong(LDB_FLG_NOSYNC));
+ PyModule_AddObject(m, "FLG_RECONNECT", PyInt_FromLong(LDB_FLG_RECONNECT));
+ PyModule_AddObject(m, "FLG_NOMMAP", PyInt_FromLong(LDB_FLG_NOMMAP));
+
+
PyModule_AddObject(m, "__docformat__", PyString_FromString("restructuredText"));
PyExc_LdbError = PyErr_NewException(discard_const_p(char, "_ldb.LdbError"), NULL, NULL);
diff --git a/source4/scripting/python/pyglue.c b/source4/scripting/python/pyglue.c
index d4db554..f5694e1 100644
--- a/source4/scripting/python/pyglue.c
+++ b/source4/scripting/python/pyglue.c
@@ -1,6 +1,7 @@
/*
Unix SMB/CIFS implementation.
Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2007
+ Copyright (C) Matthias Dieter Wallnöfer 2009
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,6 +20,7 @@
#include "includes.h"
#include "ldb.h"
#include "ldb_errors.h"
+#include "ldb_wrap.h"
#include "param/param.h"
#include "auth/credentials/credentials.h"
#include "dsdb/samdb/samdb.h"
@@ -155,6 +157,21 @@ static PyObject *py_ldb_set_session_info(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
+static PyObject *py_ldb_set_utf8_casefold(PyObject *self, PyObject *args)
+{
+ PyObject *py_ldb;
+ struct ldb_context *ldb;
+
+ if (!PyArg_ParseTuple(args, "O", &py_ldb))
+ return NULL;
+
+ PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+ ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
+
+ Py_RETURN_NONE;
+}
+
static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
{
PyObject *py_ldb, *py_sid;
@@ -396,6 +413,9 @@ static PyMethodDef py_misc_methods[] = {
{ "ldb_register_samba_handlers", (PyCFunction)py_ldb_register_samba_handlers, METH_VARARGS,
"ldb_register_samba_handlers(ldb)\n"
"Register Samba-specific LDB modules and schemas." },
+ { "ldb_set_utf8_casefold", (PyCFunction)py_ldb_set_utf8_casefold, METH_VARARGS,
+ "ldb_set_utf8_casefold(ldb)\n"
+ "Set the right Samba casefolding function for UTF8 charset." },
{ "dsdb_set_ntds_invocation_id", (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
NULL },
{ "dsdb_set_opaque_integer", (PyCFunction)py_dsdb_set_opaque_integer, METH_VARARGS,
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index ad75f5f..5379530 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -52,21 +52,22 @@ class Ldb(ldb.Ldb):
not necessarily the Sam database. For Sam-specific helper
functions see samdb.py.
"""
- def __init__(self, url=None, session_info=None, credentials=None,
- modules_dir=None, lp=None, options=None):
- """Open a Samba Ldb file.
+ def __init__(self, url=None, lp=None, modules_dir=None, session_info=None,
+ credentials=None, flags=0, options=None):
+ """Opens a Samba Ldb file.
:param url: Optional LDB URL to open
+ :param lp: Optional loadparm object
+ :param modules_dir: Optional modules directory
:param session_info: Optional session information
:param credentials: Optional credentials, defaults to anonymous.
- :param modules_dir: Modules directory, if not the default.
- :param lp: Loadparm object, optional.
+ :param flags: Optional LDB flags
+ :param options: Additional options (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(Ldb, self).__init__(options=options)
if modules_dir is not None:
self.set_modules_dir(modules_dir)
@@ -75,23 +76,33 @@ class Ldb(ldb.Ldb):
elif lp is not None:
self.set_modules_dir(os.path.join(lp.get("modules dir"), "ldb"))
- if credentials is not None:
- self.set_credentials(credentials)
-
if session_info is not None:
self.set_session_info(session_info)
- glue.ldb_register_samba_handlers(self)
+ if credentials is not None:
+ self.set_credentials(credentials)
if lp is not None:
self.set_loadparm(lp)
+ # This must be done before we load the schema, as these handlers for
+ # objectSid and objectGUID etc must take precedence over the 'binary
+ # attribute' declaration in the schema
+ glue.ldb_register_samba_handlers(self)
+
+ # TODO set debug
def msg(l,text):
print text
#self.set_debug(msg)
- if url is not None:
- self.connect(url, options=options)
+ glue.ldb_set_utf8_casefold(self)
+
+ # Allow admins to force non-sync ldb for all databases
+ nosync_p = lp.get("nosync", "ldb")
+ if nosync_p is not None and nosync_p == true:
+ flags |= FLG_NOSYNC
+
+ self.connect(url, flags, options)
def set_credentials(self, credentials):
glue.ldb_set_credentials(self, credentials)
diff --git a/source4/scripting/python/samba/idmap.py b/source4/scripting/python/samba/idmap.py
index ee79be1..acc98a5 100644
--- a/source4/scripting/python/samba/idmap.py
+++ b/source4/scripting/python/samba/idmap.py
@@ -32,23 +32,23 @@ class IDmapDB(samba.Ldb):
TYPE_GID = 2
TYPE_BOTH = 3
- def __init__(self, url=None, session_info=None, credentials=None,
- modules_dir=None, lp=None):
- """Open the IDmap Database.
-
- :param url: URL of the database.
+ def __init__(self, url=None, lp=None, modules_dir=None, session_info=None,
+ credentials=None, flags=0, options=None):
+ """Opens the IDmap Database.
+ For parameter meanings see the super class (samba.Ldb)
"""
+
self.lp = lp
+ if url is None:
+ url = lp.get("idmap database")
- super(IDmapDB, self).__init__(session_info=session_info, credentials=credentials,
- modules_dir=modules_dir, lp=lp)
- if url:
- self.connect(url)
- else:
- self.connect(lp.get("idmap database"))
+ super(IDmapDB, self).__init__(url=url, lp=lp, modules_dir=modules_dir,
+ session_info=session_info, credentials=credentials, flags=flags,
+ options=options)
- def connect(self, url):
- super(IDmapDB, self).connect(self.lp.private_path(url))
+ def connect(self, url=None, flags=0, options=None):
+ super(IDmapDB, self).connect(url=self.lp.private_path(url), flags=flags,
+ options=options)
def setup_name_mapping(self, sid, type, unixid):
"""Setup a mapping between a sam name and a unix name.
diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py
index d9d1212..a58d6c5 100644
--- a/source4/scripting/python/samba/samdb.py
+++ b/source4/scripting/python/samba/samdb.py
@@ -35,23 +35,25 @@ __docformat__ = "restructuredText"
class SamDB(samba.Ldb):
"""The SAM database."""
- def __init__(self, url=None, session_info=None, credentials=None,
- modules_dir=None, lp=None, options=None):
- """Open the Sam Database.
-
- :param url: URL of the database.
+ def __init__(self, url=None, lp=None, modules_dir=None, session_info=None,
+ credentials=None, flags=0, options=None):
+ """Opens the Sam Database.
+ For parameter meanings see the super class (samba.Ldb)
"""
+
self.lp = lp
- super(SamDB, self).__init__(session_info=session_info, credentials=credentials,
- modules_dir=modules_dir, lp=lp, options=options)
+ if url is None:
+ url = lp.get("sam database")
+
+ super(SamDB, self).__init__(url=url, lp=lp, modules_dir=modules_dir,
+ session_info=session_info, credentials=credentials, flags=flags,
+ options=options)
+
glue.dsdb_set_global_schema(self)
- if url:
- self.connect(url)
- else:
- self.connect(lp.get("sam database"))
- def connect(self, url):
- super(SamDB, self).connect(self.lp.private_path(url))
+ def connect(self, url=None, flags=0, options=None):
+ super(SamDB, self).connect(url=self.lp.private_path(url), flags=flags,
+ options=options)
def enable_account(self, user_dn):
"""Enable an account.
@@ -73,7 +75,6 @@ replace: userAccountControl
userAccountControl: %u
""" % (user_dn, userAccountControl)
self.modify_ldif(mod)
-
def force_password_change_at_next_login(self, user_dn):
"""Force a password change at next login
@@ -89,8 +90,9 @@ pwdLastSet: 0
self.modify_ldif(mod)
def domain_dn(self):
- # find the DNs for the domain and the domain users group
- res = self.search("", scope=ldb.SCOPE_BASE,
+ # find the DNs for the domain
+ res = self.search(base="",
+ scope=ldb.SCOPE_BASE,
expression="(defaultNamingContext=*)",
attrs=["defaultNamingContext"])
assert(len(res) == 1 and res[0]["defaultNamingContext"] is not None)
@@ -106,9 +108,7 @@ pwdLastSet: 0
# connect to the sam
self.transaction_start()
try:
- domain_dn = self.domain_dn()
- assert(domain_dn is not None)
- user_dn = "CN=%s,CN=Users,%s" % (username, domain_dn)
+ user_dn = "CN=%s,CN=Users,%s" % (username, self.domain_dn())
#
# the new user record. note the reliance on the samdb module to
@@ -156,17 +156,8 @@ pwdLastSet: 0
# connect to the sam
self.transaction_start()
try:
- # find the DNs for the domain
- res = self.search("", scope=ldb.SCOPE_BASE,
- expression="(defaultNamingContext=*)",
- attrs=["defaultNamingContext"])
- assert(len(res) == 1 and res[0]["defaultNamingContext"] is not None)
- domain_dn = res[0]["defaultNamingContext"][0]
- assert(domain_dn is not None)
-
- res = self.search(domain_dn, scope=ldb.SCOPE_SUBTREE,
- expression=filter,
- attrs=[])
+ res = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
+ expression=filter, attrs=[])
assert(len(res) == 1)
user_dn = res[0].dn
diff --git a/source4/scripting/python/samba/tests/dcerpc/__init__.py b/source4/scripting/python/samba/tests/dcerpc/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/source4/setup/enableaccount b/source4/setup/enableaccount
index 1b73419..d4e9540 100755
--- a/source4/setup/enableaccount
+++ b/source4/setup/enableaccount
@@ -56,14 +56,9 @@ else:
samdb = SamDB(url=url, session_info=system_session(),
credentials=creds, lp=lp)
-if opts.base is None:
- res = samdb.search("", scope=ldb.SCOPE_BASE,
- expression="(defaultNamingContext=*)",
- attrs=["defaultNamingContext"])
- assert(len(res) == 1 and res[0]["defaultNamingContext"] is not None)
- domain_dn = res[0]["defaultNamingContext"][0]
-else:
- domain_dn = opts.base
+domain_dn = opts.base
+if domain_dn is None:
+ domain_dn = SamDB.domain_dn(samdb)
filter = "(&(objectClass=user)(samAccountName=%s))" % username
diff --git a/source4/setup/pwsettings b/source4/setup/pwsettings
index a270853..fc59f8c 100755
--- a/source4/setup/pwsettings
+++ b/source4/setup/pwsettings
@@ -64,14 +64,10 @@ else:
samdb = SamDB(url=url, session_info=system_session(),
credentials=creds, lp=lp)
-res = samdb.search("", scope=ldb.SCOPE_BASE,
- expression="(defaultNamingContext=*)",
- attrs=["defaultNamingContext"])
-assert(len(res) == 1 and res[0]["defaultNamingContext"] is not None)
-domain_dn = res[0]["defaultNamingContext"][0]
-
-res = samdb.search(domain_dn, scope=ldb.SCOPE_BASE, attrs=["pwdProperties",
- "pwdHistoryLength", "minPwdLength", "minPwdAge", "maxPwdAge"])
+domain_dn = SamDB.domain_dn(samdb)
+res = samdb.search(domain_dn, scope=ldb.SCOPE_BASE,
+ attrs=["pwdProperties", "pwdHistoryLength", "minPwdLength", "minPwdAge",
+ "maxPwdAge"])
assert(len(res) == 1)
try:
pwd_props = int(res[0]["pwdProperties"][0])
--
Samba Shared Repository
More information about the samba-cvs
mailing list