summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-06-26 23:59:22 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:18:52 -0500
commit1702f52498168c0437416dec1014cedead634774 (patch)
tree51085d868dd9e562571ccb96dac48a5dd43bd55a /source4
parent14b0722edf38872ba258c27e27094536ecb93d4f (diff)
downloadsamba-1702f52498168c0437416dec1014cedead634774.tar.gz
samba-1702f52498168c0437416dec1014cedead634774.tar.bz2
samba-1702f52498168c0437416dec1014cedead634774.zip
r7936: new ldb_dn_explode and ldb_dn_casefold functions and co
(This used to be commit 7ccf21ab4eeb9821e457308a239f2103a106fb12)
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/ldb/Makefile.in2
-rw-r--r--source4/lib/ldb/common/ldb_utf8.c80
-rw-r--r--source4/lib/ldb/config.mk2
-rw-r--r--source4/lib/ldb/include/ldb.h1
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c48
-rw-r--r--source4/lib/talloc/talloc.c22
-rw-r--r--source4/lib/talloc/talloc.h1
7 files changed, 70 insertions, 86 deletions
diff --git a/source4/lib/ldb/Makefile.in b/source4/lib/ldb/Makefile.in
index a633320d06..ac3155f27e 100644
--- a/source4/lib/ldb/Makefile.in
+++ b/source4/lib/ldb/Makefile.in
@@ -52,7 +52,7 @@ LDB_TDB_OBJ=ldb_tdb/ldb_match.o ldb_tdb/ldb_tdb.o \
COMMON_OBJ=common/ldb.o common/ldb_ldif.o \
common/ldb_parse.o common/ldb_msg.o common/ldb_utf8.o \
common/ldb_debug.o common/ldb_modules.o \
- common/ldb_explode_dn.o
+ common/ldb_dn.o
MODULES_OBJ=modules/timestamps.o modules/schema.o
diff --git a/source4/lib/ldb/common/ldb_utf8.c b/source4/lib/ldb/common/ldb_utf8.c
index ae35ad81b6..0c1ea6ca81 100644
--- a/source4/lib/ldb/common/ldb_utf8.c
+++ b/source4/lib/ldb/common/ldb_utf8.c
@@ -59,7 +59,7 @@ char *ldb_casefold(void *mem_ctx, const char *s)
a caseless compare, optimised for 7 bit
TODO: doesn't yet handle UTF8
*/
-static int ldb_caseless_cmp(const char *s1, const char *s2)
+int ldb_caseless_cmp(const char *s1, const char *s2)
{
int i;
for (i=0;s1[i] != 0;i++) {
@@ -89,81 +89,3 @@ int ldb_attr_cmp(const char *dn1, const char *dn2)
return ldb_caseless_cmp(dn1, dn2);
}
-
-/*
- casefold a dn. We need to uppercase the attribute names, and the
- attribute values of case insensitive attributes. We also need to remove
- extraneous spaces between elements
-*/
-char *ldb_dn_fold(void * mem_ctx,
- const char * dn,
- void * user_data,
- int (* case_fold_attr_fn)(void * user_data, char * attr))
-{
- const char *dn_orig = dn;
- TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
- char *ret;
- size_t len;
-
- ret = talloc_strdup(tmp_ctx, "");
- if (ret == NULL) goto failed;
-
- while ((len = strcspn(dn, ",")) > 0) {
- char *p = strchr(dn, '=');
- char *attr, *value;
- int case_fold_required;
-
- if (p == NULL || (p-dn) > len) goto failed;
-
- attr = talloc_strndup(tmp_ctx, dn, p-dn);
- if (attr == NULL) goto failed;
-
- /* trim spaces from the attribute name */
- while (' ' == *attr) attr++;
- while (' ' == attr[strlen(attr)-1]) {
- attr[strlen(attr)-1] = 0;
- }
- if (*attr == 0) goto failed;
-
- value = talloc_strndup(tmp_ctx, p+1, len-(p+1-dn));
- if (value == NULL) goto failed;
-
- /* trim spaces from the value */
- while (' ' == *value) value++;
- while (' ' == value[strlen(value)-1]) {
- value[strlen(value)-1] = 0;
- }
- if (*value == 0) goto failed;
-
- case_fold_required = case_fold_attr_fn(user_data, attr);
-
- attr = ldb_casefold(tmp_ctx, attr);
- if (attr == NULL) goto failed;
- talloc_steal(tmp_ctx, attr);
-
- if (case_fold_required) {
- value = ldb_casefold(tmp_ctx, value);
- if (value == NULL) goto failed;
- talloc_steal(tmp_ctx, value);
- }
-
- if (dn[len] == ',') {
- ret = talloc_asprintf_append(ret, "%s=%s,", attr, value);
- } else {
- ret = talloc_asprintf_append(ret, "%s=%s", attr, value);
- }
- if (ret == NULL) goto failed;
-
- dn += len;
- if (*dn == ',') dn++;
- }
-
- talloc_steal(mem_ctx, ret);
- talloc_free(tmp_ctx);
- return ret;
-
-failed:
- talloc_free(tmp_ctx);
- return ldb_casefold(mem_ctx, dn_orig);
-}
-
diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk
index cf3a7fa93d..61bd8f0152 100644
--- a/source4/lib/ldb/config.mk
+++ b/source4/lib/ldb/config.mk
@@ -70,7 +70,7 @@ ADD_OBJ_FILES = \
lib/ldb/common/ldb_utf8.o \
lib/ldb/common/ldb_debug.o \
lib/ldb/common/ldb_modules.o \
- lib/ldb/common/ldb_explode_dn.o
+ lib/ldb/common/ldb_dn.o
REQUIRED_SUBSYSTEMS = \
LIBREPLACE LIBTALLOC LDBSAMBA
NOPROTO = YES
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index 1b5c7c4f57..8feec9e002 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -279,6 +279,7 @@ const char *ldb_errstring(struct ldb_context *ldb);
casefold a string (should be UTF8, but at the moment it isn't)
*/
char *ldb_casefold(void *mem_ctx, const char *s);
+int ldb_caseless_cmp(const char *s1, const char *s2);
/*
ldif manipulation functions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index f8c98d6712..bc61378f18 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -38,6 +38,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
#include "ldb/include/ldb_private.h"
+#include "ldb/include/ldb_dn.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
#define LDBLOCK "INT_LDBLOCK"
@@ -107,9 +108,30 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn)
talloc_free(attr_name_folded);
}
talloc_free(attr_name);
- } else {
- dn_folded = ldb_dn_fold(module->ldb, dn,
- module, ltdb_case_fold_attr_required);
+ }
+ /* special cases for tdb */
+ else if (*dn == '@' || strncmp(LDBLOCK, dn, strlen(LDBLOCK)) == 0) {
+
+ dn_folded = talloc_strdup(ldb, dn);
+ }
+ else {
+ struct ldb_dn *edn, *cedn;
+
+ edn = ldb_dn_explode(ldb, dn);
+ if (!edn)
+ goto failed;
+
+ cedn = ldb_dn_casefold(ldb, edn, module,
+ ltdb_case_fold_attr_required);
+ if (!edn)
+ goto failed;
+
+ dn_folded = ldb_dn_linearize(ldb, cedn);
+ if (!dn_folded)
+ goto failed;
+
+ talloc_free(edn);
+ talloc_free(cedn);
}
if (!dn_folded) {
@@ -141,6 +163,7 @@ failed:
static int ltdb_lock(struct ldb_module *module, const char *lockname)
{
struct ltdb_private *ltdb = module->private_data;
+ char *lock_dn;
TDB_DATA key;
int ret;
@@ -148,14 +171,21 @@ static int ltdb_lock(struct ldb_module *module, const char *lockname)
return -1;
}
- key = ltdb_key(module, lockname);
+ lock_dn = talloc_asprintf(module->ldb, "%s_%s", LDBLOCK, lockname);
+ if (lock_dn == NULL) {
+ return -1;
+ }
+
+ key = ltdb_key(module, lock_dn);
if (!key.dptr) {
+ talloc_free(lock_dn);
return -1;
}
ret = tdb_chainlock(ltdb->tdb, key);
talloc_free(key.dptr);
+ talloc_free(lock_dn);
return ret;
}
@@ -166,20 +196,28 @@ static int ltdb_lock(struct ldb_module *module, const char *lockname)
static int ltdb_unlock(struct ldb_module *module, const char *lockname)
{
struct ltdb_private *ltdb = module->private_data;
+ char *lock_dn;
TDB_DATA key;
if (lockname == NULL) {
return -1;
}
- key = ltdb_key(module, lockname);
+ lock_dn = talloc_asprintf(module->ldb, "%s_%s", LDBLOCK, lockname);
+ if (lock_dn == NULL) {
+ return -1;
+ }
+
+ key = ltdb_key(module, lock_dn);
if (!key.dptr) {
+ talloc_free(lock_dn);
return -1;
}
tdb_chainunlock(ltdb->tdb, key);
talloc_free(key.dptr);
+ talloc_free(lock_dn);
return 0;
}
diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c
index 08d4cb93a6..3adf741870 100644
--- a/source4/lib/talloc/talloc.c
+++ b/source4/lib/talloc/talloc.c
@@ -918,6 +918,28 @@ char *talloc_strdup(const void *t, const char *p)
}
/*
+ append to a talloced string
+*/
+char *talloc_append_string(const void *t, char *orig, const char *append)
+{
+ char *ret;
+ size_t olen = strlen(orig);
+ size_t alenz = strlen(append) + 1;
+
+ if (!append)
+ return orig;
+
+ ret = talloc_realloc(t, orig, char, olen + alenz);
+ if (!ret)
+ return NULL;
+
+ /* append the string with the trailing \0 */
+ memcpy(&ret[olen], append, alenz);
+
+ return ret;
+}
+
+/*
strndup with a talloc
*/
char *talloc_strndup(const void *t, const char *p, size_t n)
diff --git a/source4/lib/talloc/talloc.h b/source4/lib/talloc/talloc.h
index 04d5cbb9af..d68510abef 100644
--- a/source4/lib/talloc/talloc.h
+++ b/source4/lib/talloc/talloc.h
@@ -119,6 +119,7 @@ void *_talloc_zero(const void *ctx, size_t size, const char *name);
void *_talloc_memdup(const void *t, const void *p, size_t size, const char *name);
char *talloc_strdup(const void *t, const char *p);
char *talloc_strndup(const void *t, const char *p, size_t n);
+char *talloc_append_string(const void *t, char *orig, const char *append);
char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
char *talloc_asprintf_append(char *s,