diff options
author | Simo Sorce <idra@samba.org> | 2005-01-12 16:00:01 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:08:47 -0500 |
commit | a2f77f979d7271a9708ed06f43b00ffb10ec7f4c (patch) | |
tree | f9de8a02597f95ba9c7af1c2086a69cafacb3a87 /source4/lib | |
parent | 7588b41e153ebd84c974f7289847bcd05f32ba4b (diff) | |
download | samba-a2f77f979d7271a9708ed06f43b00ffb10ec7f4c.tar.gz samba-a2f77f979d7271a9708ed06f43b00ffb10ec7f4c.tar.bz2 samba-a2f77f979d7271a9708ed06f43b00ffb10ec7f4c.zip |
r4714: move the ldb code to the new talloc interface (eg remove _p suffix)
this helps standalone building of ldb
renew the schema module
split code into functions to improve readability and code reuse
add and modify works correctly but we need a proper testsuite
Simo
(This used to be commit a681ae365ff1b5a2771b42ebd90336651ce1e513)
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/ldb/common/ldb_ldif.c | 16 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_modules.c | 4 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_msg.c | 16 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_parse.c | 10 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_ldap/ldb_ldap.c | 24 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_cache.c | 20 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_index.c | 32 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_pack.c | 6 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_search.c | 16 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.c | 20 | ||||
-rw-r--r-- | source4/lib/ldb/modules/schema.c | 799 | ||||
-rw-r--r-- | source4/lib/ldb/modules/timestamps.c | 16 | ||||
-rw-r--r-- | source4/lib/ldb/tools/ldbedit.c | 2 |
13 files changed, 358 insertions, 623 deletions
diff --git a/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c index d20a2a3553..546cf461f8 100644 --- a/source4/lib/ldb/common/ldb_ldif.c +++ b/source4/lib/ldb/common/ldb_ldif.c @@ -97,7 +97,7 @@ char *ldb_base64_encode(struct ldb_context *ldb, const char *buf, int len) int bytes = (len*8 + 5)/6; char *out; - out = talloc_array_p(ldb, char, bytes+2); + out = talloc_array(ldb, char, bytes+2); if (!out) return NULL; for (i=0;i<bytes;i++) { @@ -305,7 +305,7 @@ static char *next_chunk(struct ldb_context *ldb, if (chunk_size+1 >= alloc_size) { char *c2; alloc_size += 1024; - c2 = talloc_realloc_p(ldb, chunk, char, alloc_size); + c2 = talloc_realloc(ldb, chunk, char, alloc_size); if (!c2) { talloc_free(chunk); errno = ENOMEM; @@ -427,7 +427,7 @@ static int msg_add_empty(struct ldb_context *ldb, { struct ldb_message_element *el2, *el; - el2 = talloc_realloc_p(msg, msg->elements, + el2 = talloc_realloc(msg, msg->elements, struct ldb_message_element, msg->num_elements+1); if (!el2) { errno = ENOMEM; @@ -468,10 +468,10 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb, value.data = NULL; - ldif = talloc_p(ldb, struct ldb_ldif); + ldif = talloc(ldb, struct ldb_ldif); if (!ldif) return NULL; - ldif->msg = talloc_p(ldif, struct ldb_message); + ldif->msg = talloc(ldif, struct ldb_message); if (ldif->msg == NULL) { talloc_free(ldif); return NULL; @@ -556,7 +556,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb, flags == el->flags) { /* its a continuation */ el->values = - talloc_realloc_p(msg->elements, el->values, + talloc_realloc(msg->elements, el->values, struct ldb_val, el->num_values+1); if (!el->values) { goto failed; @@ -565,7 +565,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb, el->num_values++; } else { /* its a new attribute */ - msg->elements = talloc_realloc_p(ldif, msg->elements, + msg->elements = talloc_realloc(ldif, msg->elements, struct ldb_message_element, msg->num_elements+1); if (!msg->elements) { @@ -574,7 +574,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb, el = &msg->elements[msg->num_elements]; el->flags = flags; el->name = talloc_strdup(msg->elements, attr); - el->values = talloc_p(msg->elements, struct ldb_val); + el->values = talloc(msg->elements, struct ldb_val); if (!el->values || !el->name) { goto failed; } diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c index 033717a62b..22d1ce112e 100644 --- a/source4/lib/ldb/common/ldb_modules.c +++ b/source4/lib/ldb/common/ldb_modules.c @@ -69,7 +69,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[]) *p = '\0'; q = p + 1; pn++; - modules = talloc_realloc_p(ldb, modules, char *, pn); + modules = talloc_realloc(ldb, modules, char *, pn); if (!modules) { ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in register_modules()\n"); return -1; @@ -103,7 +103,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[]) for (j = 0; j < msg[0]->num_elements; j++) { for (k = 0; k < msg[0]->elements[j].num_values; k++) { pn++; - modules = talloc_realloc_p(ldb, modules, char *, pn); + modules = talloc_realloc(ldb, modules, char *, pn); if (!modules) { ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in register_modules()\n"); return -1; diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index 416590f462..5ab2088744 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -41,7 +41,7 @@ */ struct ldb_message *ldb_msg_new(void *mem_ctx) { - return talloc_zero_p(mem_ctx, struct ldb_message); + return talloc_zero(mem_ctx, struct ldb_message); } /* @@ -107,7 +107,7 @@ struct ldb_val ldb_val_dup(TALLOC_CTX *mem_ctx, /* the +1 is to cope with buggy C library routines like strndup that look one byte beyond */ - v2.data = talloc_array_p(mem_ctx, char, v->length+1); + v2.data = talloc_array(mem_ctx, char, v->length+1); if (!v2.data) { v2.length = 0; return v2; @@ -126,7 +126,7 @@ int ldb_msg_add_empty(struct ldb_context *ldb, { struct ldb_message_element *els; - els = talloc_realloc_p(msg, msg->elements, + els = talloc_realloc(msg, msg->elements, struct ldb_message_element, msg->num_elements+1); if (!els) { errno = ENOMEM; @@ -185,7 +185,7 @@ int ldb_msg_add_value(struct ldb_context *ldb, return -1; } - vals = talloc_realloc_p(msg, el->values, struct ldb_val, el->num_values+1); + vals = talloc_realloc(msg, el->values, struct ldb_val, el->num_values+1); if (!vals) { errno = ENOMEM; return -1; @@ -351,7 +351,7 @@ struct ldb_message *ldb_msg_copy(struct ldb_context *ldb, struct ldb_message *msg2; int i, j; - msg2 = talloc_p(ldb, struct ldb_message); + msg2 = talloc(ldb, struct ldb_message); if (msg2 == NULL) return NULL; msg2->elements = NULL; @@ -361,7 +361,7 @@ struct ldb_message *ldb_msg_copy(struct ldb_context *ldb, msg2->dn = talloc_strdup(msg2, msg->dn); if (msg2->dn == NULL) goto failed; - msg2->elements = talloc_array_p(msg2, struct ldb_message_element, msg->num_elements); + msg2->elements = talloc_array(msg2, struct ldb_message_element, msg->num_elements); if (msg2->elements == NULL) goto failed; for (i=0;i<msg->num_elements;i++) { @@ -373,7 +373,7 @@ struct ldb_message *ldb_msg_copy(struct ldb_context *ldb, el2->values = NULL; el2->name = talloc_strdup(msg2->elements, el1->name); if (el2->name == NULL) goto failed; - el2->values = talloc_array_p(msg2->elements, struct ldb_val, el1->num_values); + el2->values = talloc_array(msg2->elements, struct ldb_val, el1->num_values); for (j=0;j<el1->num_values;j++) { el2->values[j] = ldb_val_dup(ldb, &el1->values[j]); if (el2->values[j].data == NULL && @@ -413,7 +413,7 @@ struct ldb_message *ldb_msg_canonicalize(struct ldb_context *ldb, struct ldb_message_element *el1 = &msg2->elements[i-1]; struct ldb_message_element *el2 = &msg2->elements[i]; if (ldb_msg_element_compare_name(el1, el2) == 0) { - el1->values = talloc_realloc_p(msg2->elements, el1->values, struct ldb_val, + el1->values = talloc_realloc(msg2->elements, el1->values, struct ldb_val, el1->num_values + el2->num_values); if (el1->values == NULL) { return NULL; diff --git a/source4/lib/ldb/common/ldb_parse.c b/source4/lib/ldb/common/ldb_parse.c index 6ee6f99253..d9f7dbe524 100644 --- a/source4/lib/ldb/common/ldb_parse.c +++ b/source4/lib/ldb/common/ldb_parse.c @@ -138,7 +138,7 @@ static struct ldb_parse_tree *ldb_parse_simple(TALLOC_CTX *ctx, const char *s) char *eq, *val, *l; struct ldb_parse_tree *ret; - ret = talloc_p(ctx, struct ldb_parse_tree); + ret = talloc(ctx, struct ldb_parse_tree); if (!ret) { errno = ENOMEM; return NULL; @@ -188,7 +188,7 @@ static struct ldb_parse_tree *ldb_parse_filterlist(TALLOC_CTX *ctx, { struct ldb_parse_tree *ret, *next; - ret = talloc_p(ctx, struct ldb_parse_tree); + ret = talloc(ctx, struct ldb_parse_tree); if (!ret) { errno = ENOMEM; return NULL; @@ -196,7 +196,7 @@ static struct ldb_parse_tree *ldb_parse_filterlist(TALLOC_CTX *ctx, ret->operation = op; ret->u.list.num_elements = 1; - ret->u.list.elements = talloc_p(ret, struct ldb_parse_tree *); + ret->u.list.elements = talloc(ret, struct ldb_parse_tree *); if (!ret->u.list.elements) { errno = ENOMEM; talloc_free(ret); @@ -213,7 +213,7 @@ static struct ldb_parse_tree *ldb_parse_filterlist(TALLOC_CTX *ctx, while (*s && (next = ldb_parse_filter(ret->u.list.elements, &s))) { struct ldb_parse_tree **e; - e = talloc_realloc_p(ret, ret->u.list.elements, + e = talloc_realloc(ret, ret->u.list.elements, struct ldb_parse_tree *, ret->u.list.num_elements+1); if (!e) { @@ -238,7 +238,7 @@ static struct ldb_parse_tree *ldb_parse_not(TALLOC_CTX *ctx, const char *s) { struct ldb_parse_tree *ret; - ret = talloc_p(ctx, struct ldb_parse_tree); + ret = talloc(ctx, struct ldb_parse_tree); if (!ret) { errno = ENOMEM; return NULL; diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c index bab3c86e16..46ea1a9e33 100644 --- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c +++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c @@ -161,7 +161,7 @@ static int lldb_add_msg_attr(struct ldb_context *ldb, return -1; } - el = talloc_realloc_p(msg, msg->elements, struct ldb_message_element, + el = talloc_realloc(msg, msg->elements, struct ldb_message_element, msg->num_elements + 1); if (!el) { errno = ENOMEM; @@ -180,7 +180,7 @@ static int lldb_add_msg_attr(struct ldb_context *ldb, el->flags = 0; el->num_values = 0; - el->values = talloc_array_p(msg->elements, struct ldb_val, count); + el->values = talloc_array(msg->elements, struct ldb_val, count); if (!el->values) { errno = ENOMEM; return -1; @@ -230,7 +230,7 @@ static int lldb_search(struct ldb_module *module, const char *base, return count; } - (*res) = talloc_array_p(lldb, struct ldb_message *, count+1); + (*res) = talloc_array(lldb, struct ldb_message *, count+1); if (! *res) { ldap_msgfree(ldapres); errno = ENOMEM; @@ -254,7 +254,7 @@ static int lldb_search(struct ldb_module *module, const char *base, break; } - (*res)[msg_count] = talloc_p(*res, struct ldb_message); + (*res)[msg_count] = talloc(*res, struct ldb_message); if (!(*res)[msg_count]) { goto failed; } @@ -317,7 +317,7 @@ static LDAPMod **lldb_msg_to_mods(struct ldb_context *ldb, int num_mods = 0; /* allocate maximum number of elements needed */ - mods = talloc_array_p(ldb, LDAPMod *, msg->num_elements+1); + mods = talloc_array(ldb, LDAPMod *, msg->num_elements+1); if (!mods) { errno = ENOMEM; return NULL; @@ -327,7 +327,7 @@ static LDAPMod **lldb_msg_to_mods(struct ldb_context *ldb, for (i=0;i<msg->num_elements;i++) { const struct ldb_message_element *el = &msg->elements[i]; - mods[num_mods] = talloc_p(ldb, LDAPMod); + mods[num_mods] = talloc(ldb, LDAPMod); if (!mods[num_mods]) { goto failed; } @@ -347,7 +347,7 @@ static LDAPMod **lldb_msg_to_mods(struct ldb_context *ldb, } } mods[num_mods]->mod_type = el->name; - mods[num_mods]->mod_vals.modv_bvals = talloc_array_p(mods[num_mods], + mods[num_mods]->mod_vals.modv_bvals = talloc_array(mods[num_mods], struct berval *, 1+el->num_values); if (!mods[num_mods]->mod_vals.modv_bvals) { @@ -355,7 +355,7 @@ static LDAPMod **lldb_msg_to_mods(struct ldb_context *ldb, } for (j=0;j<el->num_values;j++) { - mods[num_mods]->mod_vals.modv_bvals[j] = talloc_p(mods[num_mods]->mod_vals.modv_bvals, + mods[num_mods]->mod_vals.modv_bvals[j] = talloc(mods[num_mods]->mod_vals.modv_bvals, struct berval); if (!mods[num_mods]->mod_vals.modv_bvals[j]) { goto failed; @@ -499,13 +499,13 @@ struct ldb_context *lldb_connect(const char *url, struct lldb_private *lldb = NULL; int i, version = 3; - ldb = talloc_p(NULL, struct ldb_context); + ldb = talloc(NULL, struct ldb_context); if (!ldb) { errno = ENOMEM; goto failed; } - lldb = talloc_p(ldb, struct lldb_private); + lldb = talloc(ldb, struct lldb_private); if (!lldb) { errno = ENOMEM; goto failed; @@ -526,7 +526,7 @@ struct ldb_context *lldb_connect(const char *url, goto failed; } - ldb->modules = talloc_p(ldb, struct ldb_module); + ldb->modules = talloc(ldb, struct ldb_module); if (!ldb->modules) { errno = ENOMEM; goto failed; @@ -541,7 +541,7 @@ struct ldb_context *lldb_connect(const char *url, on the caller keeping it around (it might be dynamic) */ for (i=0;options[i];i++) ; - lldb->options = talloc_array_p(lldb, char *, i+1); + lldb->options = talloc_array(lldb, char *, i+1); if (!lldb->options) { goto failed; } diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index ebdfdb7bed..8cc6616d52 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -54,7 +54,7 @@ static int ltdb_baseinfo_init(struct ldb_module *module) ltdb->sequence_number = atof(initial_sequence_number); - msg = talloc_p(ltdb, struct ldb_message); + msg = talloc(ltdb, struct ldb_message); if (msg == NULL) { goto failed; } @@ -120,11 +120,11 @@ int ltdb_cache_load(struct ldb_module *module) double seq; if (ltdb->cache == NULL) { - ltdb->cache = talloc_zero_p(ltdb, struct ltdb_cache); + ltdb->cache = talloc_zero(ltdb, struct ltdb_cache); if (ltdb->cache == NULL) goto failed; - ltdb->cache->indexlist = talloc_zero_p(ltdb->cache, struct ldb_message); - ltdb->cache->subclasses = talloc_zero_p(ltdb->cache, struct ldb_message); - ltdb->cache->attributes = talloc_zero_p(ltdb->cache, struct ldb_message); + ltdb->cache->indexlist = talloc_zero(ltdb->cache, struct ldb_message); + ltdb->cache->subclasses = talloc_zero(ltdb->cache, struct ldb_message); + ltdb->cache->attributes = talloc_zero(ltdb->cache, struct ldb_message); if (ltdb->cache->indexlist == NULL || ltdb->cache->subclasses == NULL || ltdb->cache->attributes == NULL) { @@ -133,7 +133,7 @@ int ltdb_cache_load(struct ldb_module *module) } talloc_free(ltdb->cache->baseinfo); - ltdb->cache->baseinfo = talloc_p(ltdb->cache, struct ldb_message); + ltdb->cache->baseinfo = talloc(ltdb->cache, struct ldb_message); if (ltdb->cache->baseinfo == NULL) goto failed; if (ltdb_search_dn1(module, LTDB_BASEINFO, ltdb->cache->baseinfo) == -1) { @@ -165,9 +165,9 @@ int ltdb_cache_load(struct ldb_module *module) talloc_free(ltdb->cache->subclasses); talloc_free(ltdb->cache->attributes); - ltdb->cache->indexlist = talloc_zero_p(ltdb->cache, struct ldb_message); - ltdb->cache->subclasses = talloc_zero_p(ltdb->cache, struct ldb_message); - ltdb->cache->attributes = talloc_zero_p(ltdb->cache, struct ldb_message); + ltdb->cache->indexlist = talloc_zero(ltdb->cache, struct ldb_message); + ltdb->cache->subclasses = talloc_zero(ltdb->cache, struct ldb_message); + ltdb->cache->attributes = talloc_zero(ltdb->cache, struct ldb_message); if (ltdb->cache->indexlist == NULL || ltdb->cache->subclasses == NULL || ltdb->cache->attributes == NULL) { @@ -204,7 +204,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module) char *s = NULL; int ret; - msg = talloc_p(ltdb, struct ldb_message); + msg = talloc(ltdb, struct ldb_message); if (msg == NULL) { errno = ENOMEM; return -1; diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index 88ef997a03..af325f9203 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_index.c +++ b/source4/lib/ldb/ldb_tdb/ldb_index.c @@ -180,7 +180,7 @@ static int ltdb_index_dn_simple(struct ldb_module *module, dn = ldb_dn_key(ldb, tree->u.simple.attr, &tree->u.simple.value); if (!dn) return -1; - msg = talloc_p(list, struct ldb_message); + msg = talloc(list, struct ldb_message); if (msg == NULL) { return -1; } @@ -200,7 +200,7 @@ static int ltdb_index_dn_simple(struct ldb_module *module, el = &msg->elements[i]; - list->dn = talloc_array_p(list, char *, el->num_values); + list->dn = talloc_array(list, char *, el->num_values); if (!list->dn) { break; } @@ -259,7 +259,7 @@ static int ltdb_index_dn_objectclass(struct ldb_module *module, return -1; } tree2.u.simple.value = el->values[j]; - list2 = talloc_p(list, struct dn_list); + list2 = talloc(list, struct dn_list); if (list2 == NULL) { return -1; } @@ -313,12 +313,12 @@ static int list_intersect(struct ldb_context *ldb, return 0; } - list3 = talloc_p(ldb, struct dn_list); + list3 = talloc(ldb, struct dn_list); if (list3 == NULL) { return -1; } - list3->dn = talloc_array_p(list3, char *, list->count); + list3->dn = talloc_array(list3, char *, list->count); if (!list3->dn) { talloc_free(list); talloc_free(list3); @@ -363,7 +363,7 @@ static int list_union(struct ldb_context *ldb, return 0; } - d = talloc_realloc_p(list, list->dn, char *, list->count + list2->count); + d = talloc_realloc(list, list->dn, char *, list->count + list2->count); if (!d) { talloc_free(list); return -1; @@ -415,7 +415,7 @@ static int ltdb_index_dn_or(struct ldb_module *module, struct dn_list *list2; int v; - list2 = talloc_p(module, struct dn_list); + list2 = talloc(module, struct dn_list); if (list2 == NULL) { return -1; } @@ -500,7 +500,7 @@ static int ltdb_index_dn_and(struct ldb_module *module, struct dn_list *list2; int v; - list2 = talloc_p(module, struct dn_list); + list2 = talloc(module, struct dn_list); if (list2 == NULL) { return -1; } @@ -591,7 +591,7 @@ static int ldb_index_filter(struct ldb_module *module, struct ldb_parse_tree *tr struct ldb_message *msg; int ret; - msg = talloc_p(module, struct ldb_message); + msg = talloc(module, struct ldb_message); if (msg == NULL) { return -1; } @@ -642,7 +642,7 @@ int ltdb_search_indexed(struct ldb_module *module, return -1; } - dn_list = talloc_p(module, struct dn_list); + dn_list = talloc(module, struct dn_list); if (dn_list == NULL) { return -1; } @@ -672,7 +672,7 @@ static int ltdb_index_add1_new(struct ldb_context *ldb, struct ldb_message_element *el2; /* add another entry */ - el2 = talloc_realloc_p(msg, msg->elements, + el2 = talloc_realloc(msg, msg->elements, struct ldb_message_element, msg->num_elements+1); if (!el2) { return -1; @@ -684,7 +684,7 @@ static int ltdb_index_add1_new(struct ldb_context *ldb, return -1; } msg->elements[msg->num_elements].num_values = 0; - msg->elements[msg->num_elements].values = talloc_p(msg->elements, struct ldb_val); + msg->elements[msg->num_elements].values = talloc(msg->elements, struct ldb_val); if (!msg->elements[msg->num_elements].values) { return -1; } @@ -717,7 +717,7 @@ static int ltdb_index_add1_add(struct ldb_context *ldb, } } - v2 = talloc_realloc_p(msg->elements, msg->elements[idx].values, + v2 = talloc_realloc(msg->elements, msg->elements[idx].values, struct ldb_val, msg->elements[idx].num_values+1); if (!v2) { @@ -749,7 +749,7 @@ static int ltdb_index_add1(struct ldb_module *module, char *dn, return -1; } - msg = talloc_p(dn_key, struct ldb_message); + msg = talloc(dn_key, struct ldb_message); if (msg == NULL) { return -1; } @@ -842,7 +842,7 @@ int ltdb_index_del_value(struct ldb_module *module, const char *dn, return -1; } - msg = talloc_p(dn_key, struct ldb_message); + msg = talloc(dn_key, struct ldb_message); if (msg == NULL) { talloc_free(dn_key); return -1; @@ -948,7 +948,7 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void * return 0; } - msg = talloc_p(module, struct ldb_message); + msg = talloc(module, struct ldb_message); if (msg == NULL) { return -1; } diff --git a/source4/lib/ldb/ldb_tdb/ldb_pack.c b/source4/lib/ldb/ldb_tdb/ldb_pack.c index 501728fac5..4433e16cb2 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_pack.c +++ b/source4/lib/ldb/ldb_tdb/ldb_pack.c @@ -99,7 +99,7 @@ int ltdb_pack_data(struct ldb_module *module, } /* allocate it */ - data->dptr = talloc_array_p(ldb, char, size); + data->dptr = talloc_array(ldb, char, size); if (!data->dptr) { errno = ENOMEM; return -1; @@ -199,7 +199,7 @@ int ltdb_unpack_data(struct ldb_module *module, goto failed; } - message->elements = talloc_array_p(message, struct ldb_message_element, message->num_elements); + message->elements = talloc_array(message, struct ldb_message_element, message->num_elements); if (!message->elements) { errno = ENOMEM; goto failed; @@ -225,7 +225,7 @@ int ltdb_unpack_data(struct ldb_module *module, message->elements[i].num_values = pull_uint32(p, 0); message->elements[i].values = NULL; if (message->elements[i].num_values != 0) { - message->elements[i].values = talloc_array_p(message->elements, + message->elements[i].values = talloc_array(message->elements, struct ldb_val, message->elements[i].num_values); if (!message->elements[i].values) { diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 295c9578cc..536d1ac005 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -47,7 +47,7 @@ static int msg_add_element(struct ldb_context *ldb, unsigned int i; struct ldb_message_element *e2, *elnew; - e2 = talloc_realloc_p(ret, ret->elements, struct ldb_message_element, ret->num_elements+1); + e2 = talloc_realloc(ret, ret->elements, struct ldb_message_element, ret->num_elements+1); if (!e2) { return -1; } @@ -61,7 +61,7 @@ static int msg_add_element(struct ldb_context *ldb, } if (el->num_values) { - elnew->values = talloc_array_p(ret->elements, struct ldb_val, el->num_values); + elnew->values = talloc_array(ret->elements, struct ldb_val, el->num_values); if (!elnew->values) { return -1; } @@ -117,7 +117,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, struct ldb_message *ret; int i; - ret = talloc_p(ldb, struct ldb_message); + ret = talloc(ldb, struct ldb_message); if (!ret) { return NULL; } @@ -279,12 +279,12 @@ int ltdb_search_dn(struct ldb_module *module, char *dn, int ret; struct ldb_message *msg, *msg2; - *res = talloc_array_p(ldb, struct ldb_message *, 2); + *res = talloc_array(ldb, struct ldb_message *, 2); if (! *res) { return -1; } - msg = talloc_p(*res, struct ldb_message); + msg = talloc(*res, struct ldb_message); if (msg == NULL) { talloc_free(*res); *res = NULL; @@ -333,7 +333,7 @@ int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg, } /* add to the results list */ - res2 = talloc_realloc_p(ldb, *res, struct ldb_message *, (*count)+2); + res2 = talloc_realloc(ldb, *res, struct ldb_message *, (*count)+2); if (!res2) { talloc_free(msg2); return -1; @@ -378,7 +378,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi return 0; } - msg = talloc_p(sinfo, struct ldb_message); + msg = talloc(sinfo, struct ldb_message); if (msg == NULL) { return -1; } @@ -442,7 +442,7 @@ static int ltdb_search_full(struct ldb_module *module, int ret, count; struct ltdb_search_info *sinfo; - sinfo = talloc_p(ltdb, struct ltdb_search_info); + sinfo = talloc(ltdb, struct ltdb_search_info); if (sinfo == NULL) { return -1; } diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 288633cb01..b1de96986d 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -300,7 +300,7 @@ static int ltdb_delete(struct ldb_module *module, const char *dn) goto failed; } - msg = talloc_p(module, struct ldb_message); + msg = talloc(module, struct ldb_message); if (msg == NULL) { goto failed; } @@ -368,7 +368,7 @@ static int msg_add_element(struct ldb_context *ldb, struct ldb_message_element *e2; unsigned int i; - e2 = talloc_realloc_p(msg, msg->elements, struct ldb_message_element, + e2 = talloc_realloc(msg, msg->elements, struct ldb_message_element, msg->num_elements+1); if (!e2) { errno = ENOMEM; @@ -383,7 +383,7 @@ static int msg_add_element(struct ldb_context *ldb, e2->flags = el->flags; e2->values = NULL; if (el->num_values != 0) { - e2->values = talloc_array_p(msg->elements, struct ldb_val, el->num_values); + e2->values = talloc_array(msg->elements, struct ldb_val, el->num_values); if (!e2->values) { errno = ENOMEM; return -1; @@ -422,7 +422,7 @@ static int msg_delete_attribute(struct ldb_module *module, } msg->num_elements--; i--; - msg->elements = talloc_realloc_p(msg, msg->elements, + msg->elements = talloc_realloc(msg, msg->elements, struct ldb_message_element, msg->num_elements); } @@ -498,7 +498,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms return -1; } - msg2 = talloc_p(tdb_key.dptr, struct ldb_message); + msg2 = talloc(tdb_key.dptr, struct ldb_message); if (msg2 == NULL) { talloc_free(tdb_key.dptr); return -1; @@ -547,7 +547,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms } } - vals = talloc_realloc_p(msg2->elements, el2->values, struct ldb_val, + vals = talloc_realloc(msg2->elements, el2->values, struct ldb_val, el2->num_values + el->num_values); if (vals == NULL) @@ -661,7 +661,7 @@ static int ltdb_rename(struct ldb_module *module, const char *olddn, const char return -1; } - msg = talloc_p(module, struct ldb_message); + msg = talloc(module, struct ldb_message); if (msg == NULL) { goto failed; } @@ -765,7 +765,7 @@ struct ldb_context *ltdb_connect(const char *url, TDB_CONTEXT *tdb; struct ldb_context *ldb; - ldb = talloc_zero_p(NULL, struct ldb_context); + ldb = talloc_zero(NULL, struct ldb_context); if (!ldb) { errno = ENOMEM; return NULL; @@ -798,7 +798,7 @@ struct ldb_context *ltdb_connect(const char *url, return NULL; } - ltdb = talloc_zero_p(ldb, struct ltdb_private); + ltdb = talloc_zero(ldb, struct ltdb_private); if (!ltdb) { tdb_close(tdb); talloc_free(ldb); @@ -811,7 +811,7 @@ struct ldb_context *ltdb_connect(const char *url, talloc_set_destructor(ltdb, ltdb_destructor); - ldb->modules = talloc_p(ldb, struct ldb_module); + ldb->modules = talloc(ldb, struct ldb_module); if (!ldb->modules) { talloc_free(ldb); errno = ENOMEM; diff --git a/source4/lib/ldb/modules/schema.c b/source4/lib/ldb/modules/schema.c index 1f9017976e..63d94eed81 100644 --- a/source4/lib/ldb/modules/schema.c +++ b/source4/lib/ldb/modules/schema.c @@ -63,6 +63,10 @@ static struct attribute_syntax attrsyn[] = { #define SCHEMA_TALLOC_CHECK(root, mem, ret) do { if (!mem) { talloc_free(root); return ret;} } while(0); +#define SA_FLAG_RESET 0 +#define SA_FLAG_AUXCLASS 1 +#define SA_FLAG_CHECKED 2 + struct private_data { struct ldb_context *schema_db; const char *error_string; @@ -88,105 +92,177 @@ static int schema_search_free(struct ldb_module *module, struct ldb_message **re return ldb_next_search_free(module, res); } -struct check_list { - int check; - char *name; -}; - -struct attr_list { - int syntax; - char *name; -}; - -struct objc_list { - int aux; +struct attribute_list { + int flags; char *name; }; struct schema_structures { - struct check_list *cl; - struct objc_list *ol; - struct attr_list *must; - struct attr_list *may; - int num_cl; - int num_objc; - int num_must; - int num_may; + struct attribute_list *check_list; + struct attribute_list *objectclass_list; + struct attribute_list *must; + struct attribute_list *may; + int check_list_num; + int objectclass_list_num; + int must_num; + int may_num; }; -/* add_record */ -static int schema_add_record(struct ldb_module *module, const struct ldb_message *msg) +static int get_object_objectclasses(struct ldb_context *ldb, const char *dn, struct schema_structures *schema_struct) { - struct private_data *data = (struct private_data *)module->private_data; + char *filter = talloc_asprintf(schema_struct, "dn=%s", dn); + const char *attrs[] = {"objectClass", NULL}; struct ldb_message **srch; - struct schema_structures *ss; - int i, j, k, l; - int ret; + int i, j, ret; + + schema_struct->objectclass_list = NULL; + schema_struct->objectclass_list_num = 0; + ret = ldb_search(ldb, NULL, LDB_SCOPE_SUBTREE, filter, attrs, &srch); + if (ret == 1) { + for (i = 0; i < (*srch)->num_elements; i++) { + schema_struct->objectclass_list_num = (*srch)->elements[i].num_values; + schema_struct->objectclass_list = talloc_array(schema_struct, + struct attribute_list, + schema_struct->objectclass_list_num); + if (schema_struct->objectclass_list == 0) { + ldb_search_free(ldb, srch); + return -1; + } + for (j = 0; j < schema_struct->objectclass_list_num; j++) { + schema_struct->objectclass_list[j].name = talloc_strndup(schema_struct->objectclass_list, + (*srch)->elements[i].values[j].data, + (*srch)->elements[i].values[j].length); + if (schema_struct->objectclass_list[j].name == 0) { + ldb_search_free(ldb, srch); + return -1; + } + schema_struct->objectclass_list[j].flags = SA_FLAG_RESET; + } + } + ldb_search_free(ldb, srch); + } else { + ldb_search_free(ldb, srch); + return -1; + } - /* First implementation: - Build up a list of must and mays from each objectclass - Check all the musts are there and all the other attributes are mays - Throw an error in case a check fail - Free all structures and commit the change - */ + return 0; +} - ss = talloc_p(module, struct schema_structures); - if (!ss) { +static int get_check_list(struct ldb_module *module, struct schema_structures *schema_struct, const struct ldb_message *msg) +{ + int i, j, k; + + schema_struct->objectclass_list = NULL; + schema_struct->objectclass_list_num = 0; + schema_struct->check_list_num = msg->num_elements; + schema_struct->check_list = talloc_array(schema_struct, + struct attribute_list, + schema_struct->check_list_num); + if (schema_struct->check_list == 0) { return -1; } - - ss->ol = NULL; - ss->num_objc = 0; - ss->num_cl = msg->num_elements; - ss->cl = talloc_array_p(ss, struct check_list, ss->num_cl); - SCHEMA_TALLOC_CHECK(ss, ss->cl, -1); for (i = 0, j = 0; i < msg->num_elements; i++) { if (strcasecmp(msg->elements[i].name, "objectclass") == 0) { - ss->num_objc = msg->elements[i].num_values; - ss->ol = talloc_array_p(ss, struct objc_list, ss->num_objc); - SCHEMA_TALLOC_CHECK(ss, ss->ol, -1); - for (k = 0; k < ss->num_objc; k++) { - ss->ol[k].name = talloc_strndup(ss->ol, msg->elements[i].values[k].data, msg->elements[i].values[k].length); - SCHEMA_TALLOC_CHECK(ss, ss->ol[k].name, -1); - ss->ol[k].aux = 0; + schema_struct->objectclass_list_num = msg->elements[i].num_values; + schema_struct->objectclass_list = talloc_array(schema_struct, + struct attribute_list, + schema_struct->objectclass_list_num); + if (schema_struct->objectclass_list == 0) { + return -1; + } + for (k = 0; k < schema_struct->objectclass_list_num; k++) { + schema_struct->objectclass_list[k].name = talloc_strndup(schema_struct->objectclass_list, + msg->elements[i].values[k].data, + msg->elements[i].values[k].length); + if (schema_struct->objectclass_list[k].name == 0) { + return -1; + } + schema_struct->objectclass_list[k].flags = SA_FLAG_RESET; } } - ss->cl[j].check = 0; - ss->cl[j].name = talloc_strdup(ss->cl, msg->elements[i].name); - SCHEMA_TALLOC_CHECK(ss, ss->cl[j].name, -1); + schema_struct->check_list[j].flags = SA_FLAG_RESET; + schema_struct->check_list[j].name = talloc_strdup(schema_struct->check_list, + msg->elements[i].name); + if (schema_struct->check_list[j].name == 0) { + return -1; + } j++; } - /* find all other objectclasses recursively */ - ss->must = NULL; - ss->may = NULL; - ss->num_must = 0; - ss->num_may = 0; - for (i = 0; i < ss->num_objc; i++) { + return 0; +} + +static int add_attribute_uniq(struct attribute_list **list, int *list_num, int flags, struct ldb_message_element *el, void *mem_ctx) +{ + int i, j, vals; + + vals = el->num_values; + *list = talloc_realloc(mem_ctx, *list, struct attribute_list, *list_num + vals); + if (list == 0) { + return -1; + } + for (i = 0, j = 0; i < vals; i++) { + int c, found, len; + + found = 0; + for (c = 0; c < *list_num; c++) { + len = strlen((*list)[c].name); + if (len == el->values[i].length) { + if (strncasecmp((*list)[c].name, el->values[i].data, len) == 0) { + found = 1; + break; + } + } + } + if (!found) { + (*list)[j + *list_num].name = talloc_strndup(*list, el->values[i].data, el->values[i].length); + if ((*list)[j + *list_num].name == 0) { + return -1; + } + (*list)[j + *list_num].flags = flags; + j++; + } + } + *list_num += j; + + return 0; +} + +static int get_attr_list_recursive(struct ldb_module *module, struct ldb_context *ldb, struct schema_structures *schema_struct) +{ + struct private_data *data = (struct private_data *)module->private_data; + struct ldb_message **srch; + int i, j; + int ret; + + schema_struct->must = NULL; + schema_struct->may = NULL; + schema_struct->must_num = 0; + schema_struct->may_num = 0; + for (i = 0; i < schema_struct->objectclass_list_num; i++) { char *filter; - filter = talloc_asprintf(ss, "lDAPDisplayName=%s", ss->ol[i].name); - SCHEMA_TALLOC_CHECK(ss, filter, -1); - ret = ldb_search(data->schema_db, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &srch); + filter = talloc_asprintf(schema_struct, "lDAPDisplayName=%s", schema_struct->objectclass_list[i].name); + SCHEMA_TALLOC_CHECK(schema_struct, filter, -1); + ret = ldb_search(ldb, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &srch); if (ret == 0) { int ok; ok = 0; - /* suppose auxiliary classess are not required */ - if (ss->ol[i].aux) { + /* suppose auxiliary classeschema_struct are not required */ + if (schema_struct->objectclass_list[i].flags & SA_FLAG_AUXCLASS) { int d; ok = 1; - ss->num_objc -= 1; - for (d = i; d < ss->num_objc; d++) { - ss->ol[d] = ss->ol[d + 1]; + schema_struct->objectclass_list_num -= 1; + for (d = i; d < schema_struct->objectclass_list_num; d++) { + schema_struct->objectclass_list[d] = schema_struct->objectclass_list[d + 1]; } i -= 1; } if (!ok) { /* Schema Violation: Object Class Description Not Found */ data->error_string = "ObjectClass not found"; - talloc_free(ss); return -1; } continue; @@ -194,13 +270,11 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message if (ret < 0) { /* Schema DB Error: Error occurred retrieving Object Class Description */ data->error_string = "Internal error. Error retrieving schema objectclass"; - talloc_free(ss); return -1; } if (ret > 1) { /* Schema DB Error: Too Many Records */ data->error_string = "Internal error. Too many records searching for schema objectclass"; - talloc_free(ss); return -1; } } @@ -208,12 +282,12 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message /* Add inherited classes eliminating duplicates */ /* fill in kust and may attribute lists */ for (j = 0; j < (*srch)->num_elements; j++) { - int o, is_aux, is_class; + int is_aux, is_class; is_aux = 0; is_class = 0; if (strcasecmp((*srch)->elements[j].name, "systemAuxiliaryclass") == 0) { - is_aux = 1; + is_aux = SA_FLAG_AUXCLASS; is_class = 1; } if (strcasecmp((*srch)->elements[j].name, "subClassOf") == 0) { @@ -221,103 +295,87 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message } if (is_class) { - o = (*srch)->elements[j].num_values; - ss->ol = talloc_realloc_p(ss, ss->ol, struct objc_list, ss->num_objc + o); - SCHEMA_TALLOC_CHECK(ss, ss->ol, -1); - for (k = 0, l = 0; k < o; k++) { - int c, found, len; - - found = 0; - for (c = 0; c < ss->num_objc; c++) { - len = strlen(ss->ol[c].name); - if (len == (*srch)->elements[j].values[k].length) { - if (strncasecmp(ss->ol[c].name, (*srch)->elements[j].values[k].data, len) == 0) { - found = 1; - break; - } - } - } - if (!found) { - ss->ol[l + ss->num_objc].name = talloc_strndup(ss->ol, (*srch)->elements[j].values[k].data, (*srch)->elements[j].values[k].length); - SCHEMA_TALLOC_CHECK(ss, ss->ol[l + ss->num_objc].name, -1); - ss->ol[l + ss->num_objc].aux = is_aux; - l++; - } + if (add_attribute_uniq(&schema_struct->objectclass_list, + &schema_struct->objectclass_list_num, + is_aux, + &(*srch)->elements[j], + schema_struct) != 0) { + return -1; } - ss->num_objc += l; } else { - if (strcasecmp((*srch)->elements[j].name, "mustContain") == 0 || strcasecmp((*srch)->elements[j].name, "SystemMustContain") == 0) { - int m; - - m = (*srch)->elements[j].num_values; - - ss->must = talloc_realloc_p(ss, ss->must, struct attr_list, ss->num_must + m); - SCHEMA_TALLOC_CHECK(ss, ss->must, -1); - for (k = 0, l = 0; k < m; k++) { - int c, found, len; - - found = 0; - for (c = 0; c < ss->num_must; c++) { - len = strlen(ss->must[c].name); - if (len == (*srch)->elements[j].values[k].length) { - if (strncasecmp(ss->must[c].name, (*srch)->elements[j].values[k].data, len) == 0) { - found = 1; - break; - } - } - } - if (!found) { - ss->must[l + ss->num_must].name = talloc_strndup(ss->must, (*srch)->elements[j].values[k].data, (*srch)->elements[j].values[k].length); - SCHEMA_TALLOC_CHECK(ss, ss->must[l + ss->num_must].name, -1); - l++; - } + if (strcasecmp((*srch)->elements[j].name, "mustContain") == 0 || + strcasecmp((*srch)->elements[j].name, "SystemMustContain") == 0) { + if (add_attribute_uniq(&schema_struct->must, + &schema_struct->must_num, + SA_FLAG_RESET, + &(*srch)->elements[j], + schema_struct) != 0) { + return -1; } - ss->num_must += l; } - if (strcasecmp((*srch)->elements[j].name, "mayContain") == 0 || strcasecmp((*srch)->elements[j].name, "SystemMayContain") == 0) { - int m; - - m = (*srch)->elements[j].num_values; - - ss->may = talloc_realloc_p(ss, ss->may, struct attr_list, ss->num_may + m); - SCHEMA_TALLOC_CHECK(ss, ss->may, -1); - for (k = 0, l = 0; k < m; k++) { - int c, found, len; - - found = 0; - for (c = 0; c < ss->num_may; c++) { - len = strlen(ss->may[c].name); - if (len == (*srch)->elements[j].values[k].length) { - if (strncasecmp(ss->may[c].name, (*srch)->elements[j].values[k].data, (*srch)->elements[j].values[k].length) == 0) { - found = 1; - break; - } - } - } - if (!found) { - ss->may[l + ss->num_may].name = talloc_strndup(ss->may, (*srch)->elements[j].values[k].data, (*srch)->elements[j].values[k].length); - SCHEMA_TALLOC_CHECK(ss, ss->may[l + ss->num_may].name, -1); - l++; - } + if (strcasecmp((*srch)->elements[j].name, "mayContain") == 0 || + strcasecmp((*srch)->elements[j].name, "SystemMayContain") == 0) { + + if (add_attribute_uniq(&schema_struct->may, + &schema_struct->may_num, + SA_FLAG_RESET, + &(*srch)->elements[j], + schema_struct) != 0) { + return -1; } - ss->num_may += l; } } } - ldb_search_free(data->schema_db, srch); + ldb_search_free(ldb, srch); + } + + return 0; +} + +/* add_record */ +static int schema_add_record(struct ldb_module *module, const struct ldb_message *msg) +{ + struct private_data *data = (struct private_data *)module->private_data; + struct schema_structures *entry_structs; + int i, j; + int ret; + + /* First implementation: + Build up a list of must and mays from each objectclass + Check all the musts are there and all the other attributes are mays + Throw an error in case a check fail + Free all structures and commit the change + */ + + entry_structs = talloc(module, struct schema_structures); + if (!entry_structs) { + return -1; + } + + ret = get_check_list(module, entry_structs, msg); + if (ret != 0) { + talloc_free(entry_structs); + return ret; + } + + /* find all other objectclasses recursively */ + ret = get_attr_list_recursive(module, data->schema_db, entry_structs); + if (ret != 0) { + talloc_free(entry_structs); + return ret; } /* now check all musts are present */ - for (i = 0; i < ss->num_must; i++) { + for (i = 0; i < entry_structs->must_num; i++) { int found; found = 0; - for (j = 0; j < ss->num_cl; j++) { - if (strcasecmp(ss->must[i].name, ss->cl[j].name) == 0) { - ss->cl[j].check = 1; + for (j = 0; j < entry_structs->check_list_num; j++) { + if (strcasecmp(entry_structs->must[i].name, entry_structs->check_list[j].name) == 0) { + entry_structs->check_list[j].flags = SA_FLAG_CHECKED; found = 1; break; } @@ -325,22 +383,22 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message if ( ! found ) { /* TODO: set the error string */ - data->error_string = "Objectclass violation, a required attribute is missing"; - talloc_free(ss); + data->error_string = "Objectclass violation, a required attribute is mischema_structing"; + talloc_free(entry_structs); return -1; } } /* now check all others atribs are found in mays */ - for (i = 0; i < ss->num_cl; i++) { + for (i = 0; i < entry_structs->check_list_num; i++) { - if ( ! ss->cl[i].check ) { + if (entry_structs->check_list[i].flags != SA_FLAG_CHECKED) { int found; found = 0; - for (j = 0; j < ss->num_may; j++) { - if (strcasecmp(ss->may[j].name, ss->cl[i].name) == 0) { - ss->cl[i].check = 1; + for (j = 0; j < entry_structs->may_num; j++) { + if (strcasecmp(entry_structs->may[j].name, entry_structs->check_list[i].name) == 0) { + entry_structs->check_list[i].flags = SA_FLAG_CHECKED; found = 1; break; } @@ -348,13 +406,13 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message if ( ! found ) { data->error_string = "Objectclass violation, an invalid attribute name was found"; - talloc_free(ss); + talloc_free(entry_structs); return -1; } } } - talloc_free(ss); + talloc_free(entry_structs); return ldb_next_add_record(module, msg); } @@ -363,9 +421,8 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message static int schema_modify_record(struct ldb_module *module, const struct ldb_message *msg) { struct private_data *data = (struct private_data *)module->private_data; - struct ldb_message **srch; - struct schema_structures *ss, *ms; - int i, j, k, l; + struct schema_structures *entry_structs, *modify_structs; + int i, j; int ret; /* First implementation: @@ -379,387 +436,65 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess Free all structures and commit the change. */ - ss = talloc_p(module, struct schema_structures); - if (!ss) { + /* allocate object structs */ + entry_structs = talloc(module, struct schema_structures); + if (!entry_structs) { return -1; } - ms = talloc_p(module, struct schema_structures); - SCHEMA_TALLOC_CHECK(ss, ms, -1); - - ms->ol = NULL; - ms->num_objc = 0; - ms->num_cl = msg->num_elements; - ms->cl = talloc_array_p(ms, struct check_list, ms->num_cl); - SCHEMA_TALLOC_CHECK(ss, ms->cl, -1); - for (i = 0, j = 0; i < msg->num_elements; i++) { - if (strcasecmp(msg->elements[i].name, "objectclass") == 0) { - ms->num_objc = msg->elements[i].num_values; - ms->ol = talloc_array_p(ms, struct objc_list, ms->num_objc); - SCHEMA_TALLOC_CHECK(ss, ms->ol, -1); - for (k = 0; k < ms->num_objc; k++) { - ms->ol[k].name = talloc_strndup(ms->ol, msg->elements[i].values[k].data, msg->elements[i].values[k].length); - SCHEMA_TALLOC_CHECK(ss, ms->ol[k].name, -1); - ms->ol[k].aux = 0; - } - } + /* allocate modification entry structs */ + modify_structs = talloc(entry_structs, struct schema_structures); + if (!modify_structs) { + talloc_free(entry_structs); + return -1; + } - ms->cl[j].check = 0; - ms->cl[j].name = talloc_strdup(ms->cl, msg->elements[i].name); - SCHEMA_TALLOC_CHECK(ss, ms->cl[j].name, -1); - j++; + /* get list of values to modify */ + ret = get_check_list(module, modify_structs, msg); + if (ret != 0) { + talloc_free(entry_structs); + return ret; } /* find all modify objectclasses recursively if any objectclass is being added */ - ms->must = NULL; - ms->may = NULL; - ms->num_must = 0; - ms->num_may = 0; - for (i = 0; i < ms->num_objc; i++) { - char *filter; - - filter = talloc_asprintf(ss, "lDAPDisplayName=%s", ms->ol[i].name); - SCHEMA_TALLOC_CHECK(ss, filter, -1); - ret = ldb_search(data->schema_db, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &srch); - if (ret == 0) { - int ok; - - ok = 0; - /* suppose auxiliary classess are not required */ - if (ms->ol[i].aux) { - int d; - ok = 1; - ms->num_objc -= 1; - for (d = i; d < ms->num_objc; d++) { - ms->ol[d] = ms->ol[d + 1]; - } - i -= 1; - } - if (!ok) { - /* Schema Violation: Object Class Description Not Found */ - data->error_string = "ObjectClass not found"; - talloc_free(ss); - return -1; - } - continue; - } else { - if (ret < 0) { - /* Schema DB Error: Error occurred retrieving Object Class Description */ - data->error_string = "Internal error. Error retrieving schema objectclass"; - talloc_free(ss); - return -1; - } - if (ret > 1) { - /* Schema DB Error: Too Many Records */ - data->error_string = "Internal error. Too many records searching for schema objectclass"; - talloc_free(ss); - return -1; - } - } - - /* Add inherited classes eliminating duplicates */ - /* fill in kust and may attribute lists */ - for (j = 0; j < (*srch)->num_elements; j++) { - int o, is_aux, is_class; - - is_aux = 0; - is_class = 0; - if (strcasecmp((*srch)->elements[j].name, "systemAuxiliaryclass") == 0) { - is_aux = 1; - is_class = 1; - } - if (strcasecmp((*srch)->elements[j].name, "subClassOf") == 0) { - is_class = 1; - } - - if (is_class) { - o = (*srch)->elements[j].num_values; - ms->ol = talloc_realloc_p(ms, ms->ol, struct objc_list, ms->num_objc + o); - SCHEMA_TALLOC_CHECK(ss, ms->ol, -1); - for (k = 0, l = 0; k < o; k++) { - int c, found, len; - - found = 0; - for (c = 0; c < ms->num_objc; c++) { - len = strlen(ms->ol[c].name); - if (len == (*srch)->elements[j].values[k].length) { - if (strncasecmp(ss->ol[c].name, (*srch)->elements[j].values[k].data, len) == 0) { - found = 1; - break; - } - } - } - if (!found) { - ms->ol[l + ms->num_objc].name = talloc_strndup(ms->ol, (*srch)->elements[j].values[k].data, (*srch)->elements[j].values[k].length); - SCHEMA_TALLOC_CHECK(ss, ms->ol[l + ms->num_objc].name, -1); - ms->ol[l + ms->num_objc].aux = is_aux; - l++; - } - } - ms->num_objc += l; - } else { - - if (strcasecmp((*srch)->elements[j].name, "mustContain") == 0 || strcasecmp((*srch)->elements[j].name, "SystemMustContain") == 0) { - int m; - - m = (*srch)->elements[j].num_values; - - ms->must = talloc_realloc_p(ms, ms->must, struct attr_list, ms->num_must + m); - SCHEMA_TALLOC_CHECK(ss, ms->must, -1); - for (k = 0, l = 0; k < m; k++) { - int c, found, len; - - found = 0; - for (c = 0; c < ms->num_must; c++) { - len = strlen(ms->must[c].name); - if (len == (*srch)->elements[j].values[k].length) { - if (strncasecmp(ms->must[c].name, (*srch)->elements[j].values[k].data, len) == 0) { - found = 1; - break; - } - } - } - if (!found) { - ms->must[l + ms->num_must].name = talloc_strndup(ms->must, (*srch)->elements[j].values[k].data, (*srch)->elements[j].values[k].length); - SCHEMA_TALLOC_CHECK(ss, ms->must[l + ms->num_must].name, -1); - l++; - } - } - ms->num_must += l; - } - - if (strcasecmp((*srch)->elements[j].name, "mayContain") == 0 || strcasecmp((*srch)->elements[j].name, "SystemMayContain") == 0) { - int m; - - m = (*srch)->elements[j].num_values; - - ms->may = talloc_realloc_p(ms, ms->may, struct attr_list, ms->num_may + m); - SCHEMA_TALLOC_CHECK(ss, ms->may, -1); - for (k = 0, l = 0; k < m; k++) { - int c, found, len; - - found = 0; - for (c = 0; c < ms->num_may; c++) { - len = strlen(ms->may[c].name); - if (len == (*srch)->elements[j].values[k].length) { - if (strncasecmp(ms->may[c].name, (*srch)->elements[j].values[k].data, (*srch)->elements[j].values[k].length) == 0) { - found = 1; - break; - } - } - } - if (!found) { - ms->may[l + ms->num_may].name = talloc_strndup(ms->may, (*srch)->elements[j].values[k].data, (*srch)->elements[j].values[k].length); - SCHEMA_TALLOC_CHECK(ss, ms->may[l + ms->num_may].name, -1); - l++; - } - } - ms->num_may += l; - } - } - } - - ldb_search_free(data->schema_db, srch); + ret = get_attr_list_recursive(module, data->schema_db, modify_structs); + if (ret != 0) { + talloc_free(entry_structs); + return ret; } /* now search for the original object objectclasses */ - - ss->ol = NULL; - ss->num_objc = 0; - - /* find all other objectclasses recursively */ - { - char *filter = talloc_asprintf(ss, "dn=%s", msg->dn); - const char *attrs[] = {"objectClass", NULL}; - - ret = ldb_search(module->ldb, NULL, LDB_SCOPE_SUBTREE, filter, attrs, &srch); - if (ret == 1) { - for (i = 0; i < msg->num_elements; i++) { - ss->num_objc = (*srch)->elements[i].num_values; - ss->ol = talloc_array_p(ss, struct objc_list, ss->num_objc); - SCHEMA_TALLOC_CHECK(ss, ss->ol, -1); - for (k = 0; k < ss->num_objc; k++) { - ss->ol[k].name = talloc_strndup(ss->ol, (*srch)->elements[i].values[k].data, (*srch)->elements[i].values[k].length); - SCHEMA_TALLOC_CHECK(ss, ss->ol[k].name, -1); - ss->ol[k].aux = 0; - } - } - ldb_search_free(module->ldb, srch); - } else { - ldb_search_free(module->ldb, srch); - return -1; - } + ret = get_object_objectclasses(module->ldb, msg->dn, entry_structs); + if (ret != 0) { + talloc_free(entry_structs); + return ret; } - ss->must = NULL; - ss->may = NULL; - ss->num_must = 0; - ss->num_may = 0; - for (i = 0; i < ss->num_objc; i++) { - char *filter; - - filter = talloc_asprintf(ss, "lDAPDisplayName=%s", ss->ol[i].name); - SCHEMA_TALLOC_CHECK(ss, filter, -1); - ret = ldb_search(data->schema_db, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &srch); - if (ret == 0) { - int ok; - - ok = 0; - /* suppose auxiliary classess are not required */ - if (ss->ol[i].aux) { - int d; - ok = 1; - ss->num_objc -= 1; - for (d = i; d < ss->num_objc; d++) { - ss->ol[d] = ss->ol[d + 1]; - } - i -= 1; - } - if (!ok) { - /* Schema Violation: Object Class Description Not Found */ - data->error_string = "ObjectClass not found"; - talloc_free(ss); - return -1; - } - continue; - } else { - if (ret < 0) { - /* Schema DB Error: Error occurred retrieving Object Class Description */ - data->error_string = "Internal error. Error retrieving schema objectclass"; - talloc_free(ss); - return -1; - } - if (ret > 1) { - /* Schema DB Error: Too Many Records */ - data->error_string = "Internal error. Too many records searching for schema objectclass"; - talloc_free(ss); - return -1; - } - } - - /* Add inherited classes eliminating duplicates */ - /* fill in kust and may attribute lists */ - for (j = 0; j < (*srch)->num_elements; j++) { - int o, is_aux, is_class; - - is_aux = 0; - is_class = 0; - if (strcasecmp((*srch)->elements[j].name, "systemAuxiliaryclass") == 0) { - is_aux = 1; - is_class = 1; - } - if (strcasecmp((*srch)->elements[j].name, "subClassOf") == 0) { - is_class = 1; - } - - if (is_class) { - o = (*srch)->elements[j].num_values; - ss->ol = talloc_realloc_p(ss, ss->ol, struct objc_list, ss->num_objc + o); - SCHEMA_TALLOC_CHECK(ss, ss->ol, -1); - for (k = 0, l = 0; k < o; k++) { - int c, found, len; - - found = 0; - for (c = 0; c < ss->num_objc; c++) { - len = strlen(ss->ol[c].name); - if (len == (*srch)->elements[j].values[k].length) { - if (strncasecmp(ss->ol[c].name, (*srch)->elements[j].values[k].data, len) == 0) { - found = 1; - break; - } - } - } - if (!found) { - ss->ol[l + ss->num_objc].name = talloc_strndup(ss->ol, (*srch)->elements[j].values[k].data, (*srch)->elements[j].values[k].length); - SCHEMA_TALLOC_CHECK(ss, ss->ol[l + ss->num_objc].name, -1); - ss->ol[l + ss->num_objc].aux = is_aux; - l++; - } - } - ss->num_objc += l; - } else { - - if (strcasecmp((*srch)->elements[j].name, "mustContain") == 0 || strcasecmp((*srch)->elements[j].name, "SystemMustContain") == 0) { - int m; - - m = (*srch)->elements[j].num_values; - - ss->must = talloc_realloc_p(ss, ss->must, struct attr_list, ss->num_must + m); - SCHEMA_TALLOC_CHECK(ss, ss->must, -1); - for (k = 0, l = 0; k < m; k++) { - int c, found, len; - - found = 0; - for (c = 0; c < ss->num_must; c++) { - len = strlen(ss->must[c].name); - if (len == (*srch)->elements[j].values[k].length) { - if (strncasecmp(ss->must[c].name, (*srch)->elements[j].values[k].data, len) == 0) { - found = 1; - break; - } - } - } - if (!found) { - ss->must[l + ss->num_must].name = talloc_strndup(ss->must, (*srch)->elements[j].values[k].data, (*srch)->elements[j].values[k].length); - SCHEMA_TALLOC_CHECK(ss, ss->must[l + ss->num_must].name, -1); - l++; - } - } - ss->num_must += l; - } - - if (strcasecmp((*srch)->elements[j].name, "mayContain") == 0 || strcasecmp((*srch)->elements[j].name, "SystemMayContain") == 0) { - int m; - - m = (*srch)->elements[j].num_values; - - ss->may = talloc_realloc_p(ss, ss->may, struct attr_list, ss->num_may + m); - SCHEMA_TALLOC_CHECK(ss, ss->may, -1); - for (k = 0, l = 0; k < m; k++) { - int c, found, len; - - found = 0; - for (c = 0; c < ss->num_may; c++) { - len = strlen(ss->may[c].name); - if (len == (*srch)->elements[j].values[k].length) { - if (strncasecmp(ss->may[c].name, (*srch)->elements[j].values[k].data, (*srch)->elements[j].values[k].length) == 0) { - found = 1; - break; - } - } - } - if (!found) { - ss->may[l + ss->num_may].name = talloc_strndup(ss->may, (*srch)->elements[j].values[k].data, (*srch)->elements[j].values[k].length); - SCHEMA_TALLOC_CHECK(ss, ss->may[l + ss->num_may].name, -1); - l++; - } - } - ss->num_may += l; - } - } - } - - ldb_search_free(data->schema_db, srch); + /* find all other objectclasses recursively */ + ret = get_attr_list_recursive(module, data->schema_db, entry_structs); + if (ret != 0) { + talloc_free(entry_structs); + return ret; } /* now check all entries are present either as musts or mays of curent objectclasses */ /* do not return errors there may be attirbutes defined in new objectclasses */ /* just mark them as being proved valid attribs */ - for (i = 0; i < ms->num_cl; i++) { + for (i = 0; i < modify_structs->check_list_num; i++) { int found; found = 0; - for (j = 0; j < ss->num_may; j++) { - if (strcasecmp(ss->may[j].name, ms->cl[i].name) == 0) { - ms->cl[i].check = 1; + for (j = 0; j < entry_structs->may_num; j++) { + if (strcasecmp(entry_structs->may[j].name, modify_structs->check_list[i].name) == 0) { + modify_structs->check_list[i].flags = SA_FLAG_CHECKED; found = 1; break; } } if ( ! found) { - for (j = 0; j < ss->num_must; j++) { - if (strcasecmp(ss->must[j].name, ms->cl[i].name) == 0) { - ms->cl[i].check = 1; + for (j = 0; j < entry_structs->must_num; j++) { + if (strcasecmp(entry_structs->must[j].name, modify_structs->check_list[i].name) == 0) { + modify_structs->check_list[i].flags = SA_FLAG_CHECKED; break; } } @@ -767,13 +502,13 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess } /* now check all new objectclasses musts are present */ - for (i = 0; i < ms->num_must; i++) { + for (i = 0; i < modify_structs->must_num; i++) { int found; found = 0; - for (j = 0; j < ms->num_cl; j++) { - if (strcasecmp(ms->must[i].name, ms->cl[j].name) == 0) { - ms->cl[j].check = 1; + for (j = 0; j < modify_structs->check_list_num; j++) { + if (strcasecmp(modify_structs->must[i].name, modify_structs->check_list[j].name) == 0) { + modify_structs->check_list[j].flags = SA_FLAG_CHECKED; found = 1; break; } @@ -782,21 +517,21 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess if ( ! found ) { /* TODO: set the error string */ data->error_string = "Objectclass violation, a required attribute is missing"; - talloc_free(ss); + talloc_free(entry_structs); return -1; } } /* now check all others atribs are found in mays */ - for (i = 0; i < ms->num_cl; i++) { + for (i = 0; i < modify_structs->check_list_num; i++) { - if ( ! ms->cl[i].check ) { + if (modify_structs->check_list[i].flags != SA_FLAG_CHECKED) { int found; found = 0; - for (j = 0; j < ms->num_may; j++) { - if (strcasecmp(ms->may[j].name, ms->cl[i].name) == 0) { - ms->cl[i].check = 1; + for (j = 0; j < modify_structs->may_num; j++) { + if (strcasecmp(modify_structs->may[j].name, modify_structs->check_list[i].name) == 0) { + modify_structs->check_list[i].flags = SA_FLAG_CHECKED; found = 1; break; } @@ -804,13 +539,13 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess if ( ! found ) { data->error_string = "Objectclass violation, an invalid attribute name was found"; - talloc_free(ss); + talloc_free(entry_structs); return -1; } } } - talloc_free(ss); + talloc_free(entry_structs); return ldb_next_modify_record(module, msg); } @@ -818,7 +553,7 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess /* delete_record */ static int schema_delete_record(struct ldb_module *module, const char *dn) { - struct private_data *data = (struct private_data *)module->private_data; +/* struct private_data *data = (struct private_data *)module->private_data; */ return ldb_next_delete_record(module, dn); } @@ -880,7 +615,7 @@ struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *optio char *db_url = NULL; int i; - ctx = talloc_p(ldb, struct ldb_module); + ctx = talloc(ldb, struct ldb_module); if (!ctx) { return NULL; } @@ -923,7 +658,7 @@ struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *optio ldb_search_free(ldb, msgs); } - data = talloc_p(ctx, struct private_data); + data = talloc(ctx, struct private_data); SCHEMA_TALLOC_CHECK(ctx, data, NULL); data->schema_db = ldb_connect(db_url, 0, NULL); diff --git a/source4/lib/ldb/modules/timestamps.c b/source4/lib/ldb/modules/timestamps.c index 09679435f5..4066d231cd 100644 --- a/source4/lib/ldb/modules/timestamps.c +++ b/source4/lib/ldb/modules/timestamps.c @@ -74,11 +74,11 @@ static int add_time_element(struct ldb_module *module, struct ldb_message *msg, } } - msg->elements = talloc_realloc_p(msg, msg->elements, + msg->elements = talloc_realloc(msg, msg->elements, struct ldb_message_element, msg->num_elements + 1); name = talloc_strdup(msg->elements, attr_name); timestr = talloc_strdup(msg->elements, time_string); - values = talloc_p(msg->elements, struct ldb_val); + values = talloc(msg->elements, struct ldb_val); if (!msg->elements || !name || !timestr || !values) { return -1; } @@ -113,7 +113,7 @@ static int timestamps_add_record(struct ldb_module *module, const struct ldb_mes return -1; } - msg2 = talloc_p(module, struct ldb_message); + msg2 = talloc(module, struct ldb_message); if (!msg2) { return -1; } @@ -130,7 +130,7 @@ static int timestamps_add_record(struct ldb_module *module, const struct ldb_mes msg2->dn = msg->dn; msg2->num_elements = msg->num_elements; msg2->private_data = msg->private_data; - msg2->elements = talloc_array_p(msg2, struct ldb_message_element, msg2->num_elements); + msg2->elements = talloc_array(msg2, struct ldb_message_element, msg2->num_elements); for (i = 0; i < msg2->num_elements; i++) { msg2->elements[i] = msg->elements[i]; } @@ -169,7 +169,7 @@ static int timestamps_modify_record(struct ldb_module *module, const struct ldb_ return -1; } - msg2 = talloc_p(module, struct ldb_message); + msg2 = talloc(module, struct ldb_message); if (!msg2) { return -1; } @@ -187,7 +187,7 @@ static int timestamps_modify_record(struct ldb_module *module, const struct ldb_ msg2->dn = msg->dn; msg2->num_elements = msg->num_elements; msg2->private_data = msg->private_data; - msg2->elements = talloc_array_p(msg2, struct ldb_message_element, msg2->num_elements); + msg2->elements = talloc_array(msg2, struct ldb_message_element, msg2->num_elements); for (i = 0; i < msg2->num_elements; i++) { msg2->elements[i] = msg->elements[i]; } @@ -272,11 +272,11 @@ struct ldb_module *timestamps_module_init(struct ldb_context *ldb, const char *o struct ldb_module *ctx; struct private_data *data; - ctx = talloc_p(ldb, struct ldb_module); + ctx = talloc(ldb, struct ldb_module); if (!ctx) return NULL; - data = talloc_p(ctx, struct private_data); + data = talloc(ctx, struct private_data); if (!data) { talloc_free(ctx); return NULL; diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 66b684f4d5..4c38ea6803 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -280,7 +280,7 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun } while ((ldif = ldb_ldif_read_file(ldb, f))) { - msgs2 = talloc_realloc_p(ldb, msgs2, struct ldb_message *, count2+1); + msgs2 = talloc_realloc(ldb, msgs2, struct ldb_message *, count2+1); if (!msgs2) { fprintf(stderr, "out of memory"); return -1; |