summaryrefslogtreecommitdiff
path: root/source4/lib/gendb.c
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-06-14 19:15:17 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:18:11 -0500
commit9189833a8753a723a8b8d0af9c8b096571b06a84 (patch)
treed20481827bb51e1d2a6cddb2a7bcb64ff653b7a7 /source4/lib/gendb.c
parent056d63c62f3793fda0d3049a2f98cef435c9003e (diff)
downloadsamba-9189833a8753a723a8b8d0af9c8b096571b06a84.tar.gz
samba-9189833a8753a723a8b8d0af9c8b096571b06a84.tar.bz2
samba-9189833a8753a723a8b8d0af9c8b096571b06a84.zip
r7582: Better way to have a fast path searching for a specific DN.
Old way was ugly and had a bug, you couldn't add an attribute named dn or distinguishedName and search for it, tdb would change that search in a dn search. This makes it also possible to search by dn against an ldap server as the old method was not supported by ldap syntaxes. sss (This used to be commit a614466dec2484a0d39bdfae53da822cfcf80926)
Diffstat (limited to 'source4/lib/gendb.c')
-rw-r--r--source4/lib/gendb.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/source4/lib/gendb.c b/source4/lib/gendb.c
index 5b4f7b251e..dc5b7f39aa 100644
--- a/source4/lib/gendb.c
+++ b/source4/lib/gendb.c
@@ -61,7 +61,7 @@ int gendb_search_v(struct ldb_context *ldb,
/*
search the LDB for the specified attributes - varargs variant
*/
-int gendb_search(struct ldb_context *sam_ldb,
+int gendb_search(struct ldb_context *ldb,
TALLOC_CTX *mem_ctx,
const char *basedn,
struct ldb_message ***res,
@@ -72,12 +72,39 @@ int gendb_search(struct ldb_context *sam_ldb,
int count;
va_start(ap, format);
- count = gendb_search_v(sam_ldb, mem_ctx, basedn, res, attrs, format, ap);
+ count = gendb_search_v(ldb, mem_ctx, basedn, res, attrs, format, ap);
va_end(ap);
return count;
}
+int gendb_search_dn(struct ldb_context *ldb,
+ TALLOC_CTX *mem_ctx,
+ const char *dn,
+ struct ldb_message ***res,
+ const char * const *attrs)
+{
+ va_list ap;
+ int count;
+
+ *res = NULL;
+
+ count = ldb_search(ldb, dn, LDB_SCOPE_BASE, "", attrs, res);
+
+ if (count > 1) {
+ DEBUG(1, ("DB Corruption ? - Found more then one entry for dn: %s", dn));
+ return -1;
+ }
+
+ if (*res) talloc_steal(mem_ctx, *res);
+
+ DEBUG(4,("gendb_search_dn: %s -> %d (%s)\n",
+ dn, count, count==-1?ldb_errstring(ldb):"OK"));
+
+ return count;
+}
+
+
/*
setup some initial ldif in a ldb
*/