summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common/ldb_ldif.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-07-01 06:21:26 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:19:01 -0500
commita06d66a3a669c3a0a0f816438e2b3e91e208f398 (patch)
tree0a80e63dad3f00cd584263e56df6f751b46de58e /source4/lib/ldb/common/ldb_ldif.c
parent8ab3f59a10d00357cb129a2051fd0f694b5c8081 (diff)
downloadsamba-a06d66a3a669c3a0a0f816438e2b3e91e208f398.tar.gz
samba-a06d66a3a669c3a0a0f816438e2b3e91e208f398.tar.bz2
samba-a06d66a3a669c3a0a0f816438e2b3e91e208f398.zip
r8037: a fairly major update to the internals of ldb. Changes are:
- moved the knowledge of attribute types out of ldb_tdb and into the generic ldb code. This allows the ldb_match() message match logic to be generic, so it can be used by other backend - added the generic ability to load attribute handlers, for canonicalisation, compare, ldif read and ldif write. In the future this will be used by the schema module to allow us to correctly obey the attributetype schema elements - added attribute handlers for some of the core ldap attribute types, Integer, DirectoryString, DN, ObjectClass etc - added automatic registration of attribute handlers for well-known attribute names 'cn', 'dc', 'dn', 'ou' and 'objectClass' - converted the objectSid special handlers for Samba to the new system - added more correct handling of indexing in tdb backend based on the attribute canonicalisation function - added generic support for subclasses, moving it out of the tdb backend. This will be used in future by the schema module - fixed several bugs in the dn_explode code. It still needs more work, but doesn't corrupt ldb dbs any more. (This used to be commit 944c5844ab441b96d8e5d7b2d151982139d1fab9)
Diffstat (limited to 'source4/lib/ldb/common/ldb_ldif.c')
-rw-r--r--source4/lib/ldb/common/ldb_ldif.c78
1 files changed, 9 insertions, 69 deletions
diff --git a/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c
index f3bc5c6207..deeb84b3c0 100644
--- a/source4/lib/ldb/common/ldb_ldif.c
+++ b/source4/lib/ldb/common/ldb_ldif.c
@@ -45,68 +45,6 @@
#endif
/*
- add to the list of ldif handlers for this ldb context
-*/
-int ldb_ldif_add_handlers(struct ldb_context *ldb,
- const struct ldb_ldif_handler *handlers,
- unsigned num_handlers)
-{
- struct ldb_ldif_handler *h;
- h = talloc_realloc(ldb, ldb->ldif_handlers,
- struct ldb_ldif_handler,
- ldb->ldif_num_handlers + num_handlers);
- if (h == NULL) {
- ldb_oom(ldb);
- return -1;
- }
- ldb->ldif_handlers = h;
- memcpy(h + ldb->ldif_num_handlers,
- handlers, sizeof(*h) * num_handlers);
- ldb->ldif_num_handlers += num_handlers;
- return 0;
-}
-
-
-/*
- default function for ldif read/write
-*/
-static int ldb_ldif_default(struct ldb_context *ldb, const struct ldb_val *in,
- struct ldb_val *out)
-{
- *out = *in;
- return 0;
-}
-
-
-/*
- return a function for reading an ldif encoded attributes into a ldb_val
-*/
-static ldb_ldif_handler_t ldb_ldif_read_fn(struct ldb_context *ldb, const char *attr)
-{
- int i;
- for (i=0;i<ldb->ldif_num_handlers;i++) {
- if (ldb_attr_cmp(attr, ldb->ldif_handlers[i].attr) == 0) {
- return ldb->ldif_handlers[i].read_fn;
- }
- }
- return ldb_ldif_default;
-}
-
-/*
- return a function for writing an ldif encoded attribute from a ldb_val
-*/
-static ldb_ldif_handler_t ldb_ldif_write_fn(struct ldb_context *ldb, const char *attr)
-{
- int i;
- for (i=0;i<ldb->ldif_num_handlers;i++) {
- if (ldb_attr_cmp(attr, ldb->ldif_handlers[i].attr) == 0) {
- return ldb->ldif_handlers[i].write_fn;
- }
- }
- return ldb_ldif_default;
-}
-
-/*
*/
static int ldb_read_data_file(void *mem_ctx, struct ldb_val *value)
@@ -356,6 +294,10 @@ int ldb_ldif_write(struct ldb_context *ldb,
}
for (i=0;i<msg->num_elements;i++) {
+ const struct ldb_attrib_handler *h;
+
+ h = ldb_attrib_handler(ldb, msg->elements[i].name);
+
if (ldif->changetype == LDB_CHANGETYPE_MODIFY) {
switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) {
case LDB_FLAG_MOD_ADD:
@@ -374,10 +316,8 @@ int ldb_ldif_write(struct ldb_context *ldb,
}
for (j=0;j<msg->elements[i].num_values;j++) {
- ldb_ldif_handler_t write_fn = ldb_ldif_write_fn(ldb,
- msg->elements[i].name);
struct ldb_val v;
- ret = write_fn(ldb, &msg->elements[i].values[j], &v);
+ ret = h->ldif_write_fn(ldb, &msg->elements[i].values[j], &v);
CHECK_RET;
if (ldb_should_b64_encode(&v)) {
ret = fprintf_fn(private_data, "%s:: ",
@@ -650,7 +590,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
msg->dn = value.data;
while (next_attr(ldif, &s, &attr, &value) == 0) {
- ldb_ldif_handler_t read_fn;
+ const struct ldb_attrib_handler *h;
struct ldb_message_element *el;
int ret, empty = 0;
@@ -696,7 +636,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
el = &msg->elements[msg->num_elements-1];
- read_fn = ldb_ldif_read_fn(ldb, attr);
+ h = ldb_attrib_handler(ldb, attr);
if (msg->num_elements > 0 && ldb_attr_cmp(attr, el->name) == 0 &&
flags == el->flags) {
@@ -707,7 +647,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
if (!el->values) {
goto failed;
}
- ret = read_fn(ldb, &value, &el->values[el->num_values]);
+ ret = h->ldif_read_fn(ldb, &value, &el->values[el->num_values]);
if (ret != 0) {
goto failed;
}
@@ -731,7 +671,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
goto failed;
}
el->num_values = 1;
- ret = read_fn(ldb, &value, &el->values[0]);
+ ret = h->ldif_read_fn(ldb, &value, &el->values[0]);
if (ret != 0) {
goto failed;
}