diff options
Diffstat (limited to 'source4')
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/entryUUID.c | 6 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_attributes.c | 157 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_dn.c | 10 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_ldif.c | 14 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_match.c | 24 | ||||
-rw-r--r-- | source4/lib/ldb/include/ldb.h | 26 | ||||
-rw-r--r-- | source4/lib/ldb/include/ldb_private.h | 23 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_cache.c | 14 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_index.c | 6 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_search.c | 6 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.c | 6 | ||||
-rw-r--r-- | source4/lib/ldb/modules/operational.c | 14 | ||||
-rw-r--r-- | source4/lib/ldb/modules/rdn_name.c | 4 | ||||
-rw-r--r-- | source4/lib/ldb/modules/sort.c | 8 | ||||
-rw-r--r-- | source4/lib/ldb/samba/ldif_handlers.c | 315 | ||||
-rw-r--r-- | source4/scripting/ejs/mprutil.c | 12 |
16 files changed, 254 insertions, 391 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/entryUUID.c b/source4/dsdb/samdb/ldb_modules/entryUUID.c index 42aa53ca64..9bd4c499fe 100644 --- a/source4/dsdb/samdb/ldb_modules/entryUUID.c +++ b/source4/dsdb/samdb/ldb_modules/entryUUID.c @@ -96,9 +96,9 @@ static struct ldb_val val_copy(struct ldb_module *module, TALLOC_CTX *ctx, const static struct ldb_val sid_always_binary(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val) { struct ldb_val out = data_blob(NULL, 0); - const struct ldb_attrib_handler *handler = ldb_attrib_handler(module->ldb, "objectSid"); - - if (handler->canonicalise_fn(module->ldb, ctx, val, &out) != LDB_SUCCESS) { + const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(module->ldb, "objectSid"); + + if (a->syntax->canonicalise_fn(module->ldb, ctx, val, &out) != LDB_SUCCESS) { return data_blob(NULL, 0); } diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index a0118d2452..f884c1d5c6 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -33,81 +33,84 @@ #include "ldb/include/includes.h" /* - add to the list of ldif handlers for this ldb context + add a attribute to the ldb_schema + + if flags contains LDB_ATTR_FLAG_ALLOCATED + the attribute name string will be copied using + talloc_strdup(), otherwise it needs to be a static const + string at least with a lifetime longer than the ldb struct! + + the ldb_schema_syntax structure should be a pointer + to a static const struct or at least it needs to be + a struct with a longer lifetime than the ldb context! + */ -int ldb_set_attrib_handlers(struct ldb_context *ldb, - const struct ldb_attrib_handler *handlers, - unsigned num_handlers) +int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, + const char *attribute, + unsigned flags, + const struct ldb_schema_syntax *syntax) { - int i, j, n; - struct ldb_attrib_handler *h; - n = ldb->schema.num_attrib_handlers + num_handlers; - h = talloc_realloc(ldb, ldb->schema.attrib_handlers, - struct ldb_attrib_handler, n); - if (h == NULL) { + int i, n; + struct ldb_schema_attribute *a; + + n = ldb->schema.num_attributes + 1; + + a = talloc_realloc(ldb, ldb->schema.attributes, + struct ldb_schema_attribute, n); + if (a == NULL) { ldb_oom(ldb); return -1; } - ldb->schema.attrib_handlers = h; - - for (i = 0; i < num_handlers; i++) { - for (j = 0; j < ldb->schema.num_attrib_handlers; j++) { - if (ldb_attr_cmp(handlers[i].attr, h[j].attr) < 0) { - memmove(h+j+1, h+j, sizeof(*h) * (ldb->schema.num_attrib_handlers-j)); - break; - } + ldb->schema.attributes = a; + + for (i = 0; i < ldb->schema.num_attributes; i++) { + if (ldb_attr_cmp(attribute, a[i].name) < 0) { + memmove(a+i+1, a+i, sizeof(*a) * (ldb->schema.num_attributes-i)); + break; } - h[j] = handlers[i]; - if (h[j].flags & LDB_ATTR_FLAG_ALLOCATED) { - h[j].attr = talloc_strdup(h, h[j].attr); - if (h[j].attr == NULL) { - ldb_oom(ldb); - return -1; - } + } + + a[i].name = attribute; + a[i].flags = flags; + a[i].syntax = syntax; + + if (a[i].flags & LDB_ATTR_FLAG_ALLOCATED) { + a[i].name = talloc_strdup(a, a[i].name); + if (a[i].name == NULL) { + ldb_oom(ldb); + return -1; } - ldb->schema.num_attrib_handlers++; } + + ldb->schema.num_attributes++; return 0; } - - - -/* - default handler function pointers -*/ -static const struct ldb_attrib_handler ldb_default_attrib_handler = { - .attr = NULL, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_handler_copy, - .comparison_fn = ldb_comparison_binary, -}; /* return the attribute handlers for a given attribute */ -const struct ldb_attrib_handler *ldb_attrib_handler(struct ldb_context *ldb, - const char *attrib) +const struct ldb_schema_attribute *ldb_schema_attribute_by_name(struct ldb_context *ldb, + const char *name) { int i, e, b = 0, r; - const struct ldb_attrib_handler *def = &ldb_default_attrib_handler; + const struct ldb_schema_attribute *def = NULL; /* as handlers are sorted, '*' must be the first if present */ - if (strcmp(ldb->schema.attrib_handlers[0].attr, "*") == 0) { - def = &ldb->schema.attrib_handlers[0]; + if (strcmp(ldb->schema.attributes[0].name, "*") == 0) { + def = &ldb->schema.attributes[0]; b = 1; } /* do a binary search on the array */ - e = ldb->schema.num_attrib_handlers - 1; + e = ldb->schema.num_attributes - 1; while (b <= e) { i = (b + e) / 2; - r = ldb_attr_cmp(attrib, ldb->schema.attrib_handlers[i].attr); + r = ldb_attr_cmp(name, ldb->schema.attributes[i].name); if (r == 0) { - return &ldb->schema.attrib_handlers[i]; + return &ldb->schema.attributes[i]; } if (r < 0) { e = i - 1; @@ -124,45 +127,39 @@ const struct ldb_attrib_handler *ldb_attrib_handler(struct ldb_context *ldb, /* add to the list of ldif handlers for this ldb context */ -void ldb_remove_attrib_handler(struct ldb_context *ldb, const char *attrib) +void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name) { - const struct ldb_attrib_handler *h; + const struct ldb_schema_attribute *a; int i; - h = ldb_attrib_handler(ldb, attrib); - if (h == &ldb_default_attrib_handler) { + + a = ldb_schema_attribute_by_name(ldb, name); + if (a == NULL) { return; } - if (h->flags & LDB_ATTR_FLAG_ALLOCATED) { - talloc_free(discard_const_p(char, h->attr)); + + if (a->flags & LDB_ATTR_FLAG_ALLOCATED) { + talloc_free(discard_const_p(char, a->name)); } - i = h - ldb->schema.attrib_handlers; - if (i < ldb->schema.num_attrib_handlers - 1) { - memmove(&ldb->schema.attrib_handlers[i], - h+1, sizeof(*h) * (ldb->schema.num_attrib_handlers-(i+1))); + + i = a - ldb->schema.attributes; + if (i < ldb->schema.num_attributes - 1) { + memmove(&ldb->schema.attributes[i], + a+1, sizeof(*a) * (ldb->schema.num_attributes-(i+1))); } - ldb->schema.num_attrib_handlers--; + + ldb->schema.num_attributes--; } /* setup a attribute handler using a standard syntax */ -int ldb_set_attrib_handler_syntax(struct ldb_context *ldb, - const char *attr, const char *syntax) +int ldb_schema_attribute_add(struct ldb_context *ldb, + const char *attribute, + unsigned flags, + const char *syntax) { const struct ldb_schema_syntax *s = ldb_standard_syntax_by_name(ldb, syntax); - struct ldb_attrib_handler h; - if (s == NULL) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Unknown syntax '%s'\n", syntax); - return -1; - } - h.attr = attr; - h.flags = 0; - h.ldif_read_fn = s->ldif_read_fn; - h.ldif_write_fn = s->ldif_write_fn; - h.canonicalise_fn = s->canonicalise_fn; - h.comparison_fn = s->comparison_fn; - - return ldb_set_attrib_handlers(ldb, &h, 1); + return ldb_schema_attribute_add_with_syntax(ldb, attribute, flags, s); } /* @@ -174,6 +171,7 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb) const char *attr; const char *syntax; } wellknown[] = { + { "*", LDB_SYNTAX_OCTET_STRING }, { "dn", LDB_SYNTAX_DN }, { "distinguishedName", LDB_SYNTAX_DN }, { "cn", LDB_SYNTAX_DIRECTORY_STRING }, @@ -182,15 +180,18 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb) { "objectClass", LDB_SYNTAX_OBJECTCLASS } }; int i; + int ret; + for (i=0;i<ARRAY_SIZE(wellknown);i++) { - if (ldb_set_attrib_handler_syntax(ldb, wellknown[i].attr, - wellknown[i].syntax) != 0) { - return -1; + ret = ldb_schema_attribute_add(ldb, wellknown[i].attr, 0, + wellknown[i].syntax); + if (ret != LDB_SUCCESS) { + return ret; } } - return 0; -} + return LDB_SUCCESS; +} /* return the list of subclasses for a class diff --git a/source4/lib/ldb/common/ldb_dn.c b/source4/lib/ldb/common/ldb_dn.c index 7a17d2cb71..dc440ef3de 100644 --- a/source4/lib/ldb/common/ldb_dn.c +++ b/source4/lib/ldb/common/ldb_dn.c @@ -618,17 +618,17 @@ static bool ldb_dn_casefold_internal(struct ldb_dn *dn) } for (i = 0; i < dn->comp_num; i++) { - const struct ldb_attrib_handler *h; + const struct ldb_schema_attribute *a; dn->components[i].cf_name = ldb_attr_casefold(dn->components, dn->components[i].name); if (!dn->components[i].cf_name) { goto failed; } - h = ldb_attrib_handler(dn->ldb, dn->components[i].cf_name); - ret = h->canonicalise_fn(dn->ldb, dn->components, - &(dn->components[i].value), - &(dn->components[i].cf_value)); + a = ldb_schema_attribute_by_name(dn->ldb, dn->components[i].cf_name); + ret = a->syntax->canonicalise_fn(dn->ldb, dn->components, + &(dn->components[i].value), + &(dn->components[i].cf_value)); if (ret != 0) { goto failed; } diff --git a/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c index 86041a8b78..3b6783f803 100644 --- a/source4/lib/ldb/common/ldb_ldif.c +++ b/source4/lib/ldb/common/ldb_ldif.c @@ -306,9 +306,9 @@ int ldb_ldif_write(struct ldb_context *ldb, } for (i=0;i<msg->num_elements;i++) { - const struct ldb_attrib_handler *h; + const struct ldb_schema_attribute *a; - h = ldb_attrib_handler(ldb, msg->elements[i].name); + a = ldb_schema_attribute_by_name(ldb, msg->elements[i].name); if (ldif->changetype == LDB_CHANGETYPE_MODIFY) { switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { @@ -329,7 +329,7 @@ int ldb_ldif_write(struct ldb_context *ldb, for (j=0;j<msg->elements[i].num_values;j++) { struct ldb_val v; - ret = h->ldif_write_fn(ldb, mem_ctx, &msg->elements[i].values[j], &v); + ret = a->syntax->ldif_write_fn(ldb, mem_ctx, &msg->elements[i].values[j], &v); CHECK_RET; if (ldb_should_b64_encode(&v)) { ret = fprintf_fn(private_data, "%s:: ", @@ -575,7 +575,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb, } while (next_attr(ldif, &s, &attr, &value) == 0) { - const struct ldb_attrib_handler *h; + const struct ldb_schema_attribute *a; struct ldb_message_element *el; int ret, empty = 0; @@ -621,7 +621,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb, el = &msg->elements[msg->num_elements-1]; - h = ldb_attrib_handler(ldb, attr); + a = ldb_schema_attribute_by_name(ldb, attr); if (msg->num_elements > 0 && ldb_attr_cmp(attr, el->name) == 0 && flags == el->flags) { @@ -632,7 +632,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb, if (!el->values) { goto failed; } - ret = h->ldif_read_fn(ldb, ldif, &value, &el->values[el->num_values]); + ret = a->syntax->ldif_read_fn(ldb, ldif, &value, &el->values[el->num_values]); if (ret != 0) { goto failed; } @@ -661,7 +661,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb, goto failed; } el->num_values = 1; - ret = h->ldif_read_fn(ldb, ldif, &value, &el->values[0]); + ret = a->syntax->ldif_read_fn(ldb, ldif, &value, &el->values[0]); if (ret != 0) { goto failed; } diff --git a/source4/lib/ldb/common/ldb_match.c b/source4/lib/ldb/common/ldb_match.c index 524214992b..df11107402 100644 --- a/source4/lib/ldb/common/ldb_match.c +++ b/source4/lib/ldb/common/ldb_match.c @@ -104,7 +104,7 @@ static int ldb_match_comparison(struct ldb_context *ldb, { unsigned int i; struct ldb_message_element *el; - const struct ldb_attrib_handler *h; + const struct ldb_schema_attribute *a; int ret; /* FIXME: APPROX comparison not handled yet */ @@ -115,10 +115,10 @@ static int ldb_match_comparison(struct ldb_context *ldb, return 0; } - h = ldb_attrib_handler(ldb, el->name); + a = ldb_schema_attribute_by_name(ldb, el->name); for (i = 0; i < el->num_values; i++) { - ret = h->comparison_fn(ldb, ldb, &el->values[i], &tree->u.comparison.value); + ret = a->syntax->comparison_fn(ldb, ldb, &el->values[i], &tree->u.comparison.value); if (ret == 0) { return 1; @@ -144,7 +144,7 @@ static int ldb_match_equality(struct ldb_context *ldb, { unsigned int i; struct ldb_message_element *el; - const struct ldb_attrib_handler *h; + const struct ldb_schema_attribute *a; struct ldb_dn *valuedn; int ret; @@ -169,11 +169,11 @@ static int ldb_match_equality(struct ldb_context *ldb, return 0; } - h = ldb_attrib_handler(ldb, el->name); + a = ldb_schema_attribute_by_name(ldb, el->name); for (i=0;i<el->num_values;i++) { - if (h->comparison_fn(ldb, ldb, &tree->u.equality.value, - &el->values[i]) == 0) { + if (a->syntax->comparison_fn(ldb, ldb, &tree->u.equality.value, + &el->values[i]) == 0) { return 1; } } @@ -185,7 +185,7 @@ static int ldb_wildcard_compare(struct ldb_context *ldb, const struct ldb_parse_tree *tree, const struct ldb_val value) { - const struct ldb_attrib_handler *h; + const struct ldb_schema_attribute *a; struct ldb_val val; struct ldb_val cnk; struct ldb_val *chunk; @@ -193,9 +193,9 @@ static int ldb_wildcard_compare(struct ldb_context *ldb, uint8_t *save_p = NULL; int c = 0; - h = ldb_attrib_handler(ldb, tree->u.substring.attr); + a = ldb_schema_attribute_by_name(ldb, tree->u.substring.attr); - if(h->canonicalise_fn(ldb, ldb, &value, &val) != 0) + if(a->syntax->canonicalise_fn(ldb, ldb, &value, &val) != 0) return -1; save_p = val.data; @@ -204,7 +204,7 @@ static int ldb_wildcard_compare(struct ldb_context *ldb, if ( ! tree->u.substring.start_with_wildcard ) { chunk = tree->u.substring.chunks[c]; - if(h->canonicalise_fn(ldb, ldb, chunk, &cnk) != 0) goto failed; + if(a->syntax->canonicalise_fn(ldb, ldb, chunk, &cnk) != 0) goto failed; /* This deals with wildcard prefix searches on binary attributes (eg objectGUID) */ if (cnk.length > val.length) { @@ -221,7 +221,7 @@ static int ldb_wildcard_compare(struct ldb_context *ldb, while (tree->u.substring.chunks[c]) { chunk = tree->u.substring.chunks[c]; - if(h->canonicalise_fn(ldb, ldb, chunk, &cnk) != 0) goto failed; + if(a->syntax->canonicalise_fn(ldb, ldb, chunk, &cnk) != 0) goto failed; /* FIXME: case of embedded nulls */ p = strstr((char *)val.data, (char *)cnk.data); diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index 3db334d341..853adb82c6 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -329,25 +329,23 @@ typedef int (*ldb_attr_comparison_t)(struct ldb_context *, void *mem_ctx, const comparison_fn -> compare two values */ -struct ldb_attrib_handler { - - const char *attr; - unsigned flags; - +struct ldb_schema_syntax { + const char *name; ldb_attr_handler_t ldif_read_fn; ldb_attr_handler_t ldif_write_fn; ldb_attr_handler_t canonicalise_fn; ldb_attr_comparison_t comparison_fn; }; -struct ldb_schema_syntax { +struct ldb_schema_attribute { const char *name; - ldb_attr_handler_t ldif_read_fn; - ldb_attr_handler_t ldif_write_fn; - ldb_attr_handler_t canonicalise_fn; - ldb_attr_comparison_t comparison_fn; + unsigned flags; + const struct ldb_schema_syntax *syntax; }; +const struct ldb_schema_attribute *ldb_schema_attribute_by_name(struct ldb_context *ldb, + const char *name); + /** The attribute is not returned by default */ @@ -1281,10 +1279,6 @@ char *ldb_base64_encode(void *mem_ctx, const char *buf, int len); */ int ldb_base64_decode(char *s); -int ldb_attrib_add_handlers(struct ldb_context *ldb, - const struct ldb_attrib_handler *handlers, - unsigned num_handlers); - /* The following definitions come from lib/ldb/common/ldb_dn.c */ struct ldb_dn *ldb_dn_new(void *mem_ctx, struct ldb_context *ldb, const char *dn); @@ -1524,10 +1518,6 @@ int ldb_set_debug_stderr(struct ldb_context *ldb); int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value); void *ldb_get_opaque(struct ldb_context *ldb, const char *name); -const struct ldb_attrib_handler *ldb_attrib_handler(struct ldb_context *ldb, - const char *attrib); - - const char **ldb_attr_list_copy(void *mem_ctx, const char * const *attrs); const char **ldb_attr_list_copy_add(void *mem_ctx, const char * const *attrs, const char *new_attr); int ldb_attr_in_list(const char * const *attrs, const char *attr); diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h index 02fb370e16..81993efaef 100644 --- a/source4/lib/ldb/include/ldb_private.h +++ b/source4/lib/ldb/include/ldb_private.h @@ -79,8 +79,8 @@ typedef int (*ldb_connect_fn) (struct ldb_context *ldb, const char *url, unsigne */ struct ldb_schema { /* attribute handling table */ - unsigned num_attrib_handlers; - struct ldb_attrib_handler *attrib_handlers; + unsigned num_attributes; + struct ldb_schema_attribute *attributes; /* objectclass information */ unsigned num_classes; @@ -183,17 +183,22 @@ int ldb_match_msg(struct ldb_context *ldb, struct ldb_dn *base, enum ldb_scope scope); -void ldb_remove_attrib_handler(struct ldb_context *ldb, const char *attrib); const struct ldb_schema_syntax *ldb_standard_syntax_by_name(struct ldb_context *ldb, const char *syntax); -int ldb_set_attrib_handlers(struct ldb_context *ldb, - const struct ldb_attrib_handler *handlers, - unsigned num_handlers); -int ldb_setup_wellknown_attributes(struct ldb_context *ldb); -int ldb_set_attrib_handler_syntax(struct ldb_context *ldb, - const char *attr, const char *syntax); /* The following definitions come from lib/ldb/common/ldb_attributes.c */ + +int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, + const char *name, + unsigned flags, + const struct ldb_schema_syntax *syntax); +int ldb_schema_attribute_add(struct ldb_context *ldb, + const char *name, + unsigned flags, + const char *syntax); +void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name); +int ldb_setup_wellknown_attributes(struct ldb_context *ldb); + const char **ldb_subclass_list(struct ldb_context *ldb, const char *classname); void ldb_subclass_remove(struct ldb_context *ldb, const char *classname); int ldb_subclass_add(struct ldb_context *ldb, const char *classname, const char *subclass); diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index d64340b5d0..dbd5222ce5 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -71,7 +71,7 @@ static void ltdb_attributes_unload(struct ldb_module *module) msg = ltdb->cache->attributes; for (i=0;i<msg->num_elements;i++) { - ldb_remove_attrib_handler(module->ldb, msg->elements[i].name); + ldb_schema_attribute_remove(module->ldb, msg->elements[i].name); } talloc_free(ltdb->cache->attributes); @@ -126,7 +126,6 @@ static int ltdb_attributes_load(struct ldb_module *module) unsigned flags; const char *syntax; const struct ldb_schema_syntax *s; - struct ldb_attrib_handler h; if (ltdb_attributes_flags(&msg->elements[i], &flags) != 0) { ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Invalid @ATTRIBUTES element for '%s'\n", msg->elements[i].name); @@ -156,14 +155,9 @@ static int ltdb_attributes_load(struct ldb_module *module) syntax, msg->elements[i].name); goto failed; } - h.attr = msg->elements[i].name; - h.flags |= LDB_ATTR_FLAG_ALLOCATED; - h.ldif_read_fn = s->ldif_read_fn; - h.ldif_write_fn = s->ldif_write_fn; - h.canonicalise_fn = s->canonicalise_fn; - h.comparison_fn = s->comparison_fn; - - if (ldb_set_attrib_handlers(module->ldb, &h, 1) != 0) { + + flags |= LDB_ATTR_FLAG_ALLOCATED; + if (ldb_schema_attribute_add_with_syntax(module->ldb, msg->elements[i].name, flags, s) != 0) { goto failed; } } diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index 19385f5504..fd61d41037 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_index.c +++ b/source4/lib/ldb/ldb_tdb/ldb_index.c @@ -108,7 +108,7 @@ static struct ldb_dn *ltdb_index_key(struct ldb_context *ldb, { struct ldb_dn *ret; struct ldb_val v; - const struct ldb_attrib_handler *h; + const struct ldb_schema_attribute *a; char *attr_folded; int r; @@ -117,8 +117,8 @@ static struct ldb_dn *ltdb_index_key(struct ldb_context *ldb, return NULL; } - h = ldb_attrib_handler(ldb, attr); - r = h->canonicalise_fn(ldb, ldb, value, &v); + a = ldb_schema_attribute_by_name(ldb, attr); + r = a->syntax->canonicalise_fn(ldb, ldb, value, &v); if (r != LDB_SUCCESS) { const char *errstr = ldb_errstring(ldb); /* canonicalisation can be refused. For example, diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 5736b7684b..6890378185 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -123,9 +123,9 @@ static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *r } for (i=0;i<msg->num_elements;i++) { - const struct ldb_attrib_handler *h; - h = ldb_attrib_handler(ldb, msg->elements[i].name); - if (h->flags & LDB_ATTR_FLAG_HIDDEN) { + const struct ldb_schema_attribute *a; + a = ldb_schema_attribute_by_name(ldb, msg->elements[i].name); + if (a->flags & LDB_ATTR_FLAG_HIDDEN) { continue; } if (msg_add_element(ret, &msg->elements[i], diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 09ddca5034..6adf6f48ca 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -558,7 +558,7 @@ static int msg_delete_element(struct ldb_module *module, unsigned int i; int found; struct ldb_message_element *el; - const struct ldb_attrib_handler *h; + const struct ldb_schema_attribute *a; found = find_element(msg, name); if (found == -1) { @@ -567,10 +567,10 @@ static int msg_delete_element(struct ldb_module *module, el = &msg->elements[found]; - h = ldb_attrib_handler(ldb, el->name); + a = ldb_schema_attribute_by_name(ldb, el->name); for (i=0;i<el->num_values;i++) { - if (h->comparison_fn(ldb, ldb, &el->values[i], val) == 0) { + if (a->syntax->comparison_fn(ldb, ldb, &el->values[i], val) == 0) { if (i<el->num_values-1) { memmove(&el->values[i], &el->values[i+1], sizeof(el->values[i])*(el->num_values-(i+1))); diff --git a/source4/lib/ldb/modules/operational.c b/source4/lib/ldb/modules/operational.c index c327a96f90..764ce76294 100644 --- a/source4/lib/ldb/modules/operational.c +++ b/source4/lib/ldb/modules/operational.c @@ -291,11 +291,17 @@ static int operational_search(struct ldb_module *module, struct ldb_request *req static int operational_init(struct ldb_module *ctx) { + int ret = 0; + /* setup some standard attribute handlers */ - ldb_set_attrib_handler_syntax(ctx->ldb, "whenCreated", LDB_SYNTAX_UTC_TIME); - ldb_set_attrib_handler_syntax(ctx->ldb, "whenChanged", LDB_SYNTAX_UTC_TIME); - ldb_set_attrib_handler_syntax(ctx->ldb, "subschemaSubentry", LDB_SYNTAX_DN); - ldb_set_attrib_handler_syntax(ctx->ldb, "structuralObjectClass", LDB_SYNTAX_OBJECTCLASS); + ret |= ldb_schema_attribute_add(ctx->ldb, "whenCreated", 0, LDB_SYNTAX_UTC_TIME); + ret |= ldb_schema_attribute_add(ctx->ldb, "whenChanged", 0, LDB_SYNTAX_UTC_TIME); + ret |= ldb_schema_attribute_add(ctx->ldb, "subschemaSubentry", 0, LDB_SYNTAX_DN); + ret |= ldb_schema_attribute_add(ctx->ldb, "structuralObjectClass", 0, LDB_SYNTAX_OBJECTCLASS); + + if (ret != 0) { + return ret; + } return ldb_next_init(ctx); } diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 0da8b8f573..cb5add2875 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -107,10 +107,10 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } } else { - const struct ldb_attrib_handler *handler = ldb_attrib_handler(module->ldb, rdn_name); + const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(module->ldb, rdn_name); for (i = 0; i < attribute->num_values; i++) { - if (handler->comparison_fn(module->ldb, msg, &rdn_val, &attribute->values[i]) == 0) { + if (a->syntax->comparison_fn(module->ldb, msg, &rdn_val, &attribute->values[i]) == 0) { /* overwrite so it matches in case */ attribute->values[i] = rdn_val; break; diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 4fa03f8bfa..6f34cebdb7 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -59,7 +59,7 @@ struct sort_context { int num_msgs; int num_refs; - const struct ldb_attrib_handler *h; + const struct ldb_schema_attribute *a; int sort_result; }; @@ -161,9 +161,9 @@ static int sort_compare(struct ldb_message **msg1, struct ldb_message **msg2, vo } if (ac->reverse) - return ac->h->comparison_fn(ac->module->ldb, ac, &el2->values[0], &el1->values[0]); + return ac->a->syntax->comparison_fn(ac->module->ldb, ac, &el2->values[0], &el1->values[0]); - return ac->h->comparison_fn(ac->module->ldb, ac, &el1->values[0], &el2->values[0]); + return ac->a->syntax->comparison_fn(ac->module->ldb, ac, &el1->values[0], &el2->values[0]); } static int server_sort_search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares) @@ -315,7 +315,7 @@ static int server_sort_results(struct ldb_handle *handle) ac = talloc_get_type(handle->private_data, struct sort_context); - ac->h = ldb_attrib_handler(ac->module->ldb, ac->attributeName); + ac->a = ldb_schema_attribute_by_name(ac->module->ldb, ac->attributeName); ac->sort_result = 0; ldb_qsort(ac->msgs, ac->num_msgs, diff --git a/source4/lib/ldb/samba/ldif_handlers.c b/source4/lib/ldb/samba/ldif_handlers.c index 573107f40d..961312afb6 100644 --- a/source4/lib/ldb/samba/ldif_handlers.c +++ b/source4/lib/ldb/samba/ldif_handlers.c @@ -361,237 +361,104 @@ static int ldif_comparison_objectCategory(struct ldb_context *ldb, void *mem_ctx return strcmp(oc1, oc2); } -static const struct ldb_attrib_handler samba_handlers[] = { - { - .attr = "objectSid", - .flags = 0, - .ldif_read_fn = ldif_read_objectSid, - .ldif_write_fn = ldif_write_objectSid, - .canonicalise_fn = ldb_canonicalise_objectSid, - .comparison_fn = ldb_comparison_objectSid - }, - { - .attr = "securityIdentifier", - .flags = 0, - .ldif_read_fn = ldif_read_objectSid, - .ldif_write_fn = ldif_write_objectSid, - .canonicalise_fn = ldb_canonicalise_objectSid, - .comparison_fn = ldb_comparison_objectSid - }, - { - .attr = "ntSecurityDescriptor", - .flags = 0, - .ldif_read_fn = ldif_read_ntSecurityDescriptor, - .ldif_write_fn = ldif_write_ntSecurityDescriptor, - .canonicalise_fn = ldb_handler_copy, - .comparison_fn = ldb_comparison_binary - }, - { - .attr = "objectGUID", - .flags = 0, - .ldif_read_fn = ldif_read_objectGUID, - .ldif_write_fn = ldif_write_objectGUID, - .canonicalise_fn = ldb_canonicalise_objectGUID, - .comparison_fn = ldb_comparison_objectGUID - }, - { - .attr = "invocationId", - .flags = 0, - .ldif_read_fn = ldif_read_objectGUID, - .ldif_write_fn = ldif_write_objectGUID, - .canonicalise_fn = ldb_canonicalise_objectGUID, - .comparison_fn = ldb_comparison_objectGUID - }, - { - .attr = "schemaIDGUID", - .flags = 0, - .ldif_read_fn = ldif_read_objectGUID, - .ldif_write_fn = ldif_write_objectGUID, - .canonicalise_fn = ldb_canonicalise_objectGUID, - .comparison_fn = ldb_comparison_objectGUID - }, - { - .attr = "attributeSecurityGUID", - .flags = 0, - .ldif_read_fn = ldif_read_objectGUID, - .ldif_write_fn = ldif_write_objectGUID, - .canonicalise_fn = ldb_canonicalise_objectGUID, - .comparison_fn = ldb_comparison_objectGUID - }, - { - .attr = "parentGUID", - .flags = 0, - .ldif_read_fn = ldif_read_objectGUID, - .ldif_write_fn = ldif_write_objectGUID, - .canonicalise_fn = ldb_canonicalise_objectGUID, - .comparison_fn = ldb_comparison_objectGUID - }, - { - .attr = "siteGUID", - .flags = 0, - .ldif_read_fn = ldif_read_objectGUID, - .ldif_write_fn = ldif_write_objectGUID, - .canonicalise_fn = ldb_canonicalise_objectGUID, - .comparison_fn = ldb_comparison_objectGUID - }, - { - .attr = "pKTGUID", - .flags = 0, - .ldif_read_fn = ldif_read_objectGUID, - .ldif_write_fn = ldif_write_objectGUID, - .canonicalise_fn = ldb_canonicalise_objectGUID, - .comparison_fn = ldb_comparison_objectGUID - }, - { - .attr = "fRSVersionGUID", - .flags = 0, - .ldif_read_fn = ldif_read_objectGUID, - .ldif_write_fn = ldif_write_objectGUID, - .canonicalise_fn = ldb_canonicalise_objectGUID, - .comparison_fn = ldb_comparison_objectGUID - }, - { - .attr = "fRSReplicaSetGUID", - .flags = 0, - .ldif_read_fn = ldif_read_objectGUID, - .ldif_write_fn = ldif_write_objectGUID, - .canonicalise_fn = ldb_canonicalise_objectGUID, - .comparison_fn = ldb_comparison_objectGUID - }, - { - .attr = "netbootGUID", - .flags = 0, - .ldif_read_fn = ldif_read_objectGUID, - .ldif_write_fn = ldif_write_objectGUID, - .canonicalise_fn = ldb_canonicalise_objectGUID, - .comparison_fn = ldb_comparison_objectGUID - }, - { - .attr = "objectCategory", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldif_canonicalise_objectCategory, - .comparison_fn = ldif_comparison_objectCategory, - }, - { - .attr = "member", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, - }, - { - .attr = "memberOf", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, - }, - { - .attr = "nCName", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, - }, - { - .attr = "schemaNamingContext", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, - }, - { - .attr = "configurationNamingContext", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, - }, - { - .attr = "rootDomainNamingContext", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, - }, - { - .attr = "defaultNamingContext", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, - }, - { - .attr = "subRefs", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, - }, - { - .attr = "dMDLocation", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, - }, - { - .attr = "serverReference", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, - }, - { - .attr = "masteredBy", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, - }, - { - .attr = "msDs-masteredBy", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, - }, - { - .attr = "subRefs", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, - }, +#define LDB_SYNTAX_SAMBA_SID "LDB_SYNTAX_SAMBA_SID" +#define LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR "LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR" +#define LDB_SYNTAX_SAMBA_GUID "LDB_SYNTAX_SAMBA_GUID" +#define LDB_SYNTAX_SAMBA_OBJECT_CATEGORY "LDB_SYNTAX_SAMBA_OBJECT_CATEGORY" + +static const struct ldb_schema_syntax samba_syntaxes[] = { { - .attr = "fSMORoleOwner", - .flags = 0, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn, + .name = LDB_SYNTAX_SAMBA_SID, + .ldif_read_fn = ldif_read_objectSid, + .ldif_write_fn = ldif_write_objectSid, + .canonicalise_fn= ldb_canonicalise_objectSid, + .comparison_fn = ldb_comparison_objectSid + },{ + .name = LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR, + .ldif_read_fn = ldif_read_ntSecurityDescriptor, + .ldif_write_fn = ldif_write_ntSecurityDescriptor, + .canonicalise_fn= ldb_handler_copy, + .comparison_fn = ldb_comparison_binary + },{ + .name = LDB_SYNTAX_SAMBA_GUID, + .ldif_read_fn = ldif_read_objectGUID, + .ldif_write_fn = ldif_write_objectGUID, + .canonicalise_fn= ldb_canonicalise_objectGUID, + .comparison_fn = ldb_comparison_objectGUID + },{ + .name = LDB_SYNTAX_SAMBA_OBJECT_CATEGORY, + .ldif_read_fn = ldb_handler_copy, + .ldif_write_fn = ldb_handler_copy, + .canonicalise_fn= ldif_canonicalise_objectCategory, + .comparison_fn = ldif_comparison_objectCategory } }; +static const struct { + const char *name; + const char *syntax; +} samba_attributes[] = { + { "objectSid", LDB_SYNTAX_SAMBA_SID }, + { "securityIdentifier", LDB_SYNTAX_SAMBA_SID }, + { "ntSecurityDescriptor", LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR }, + { "objectGUID", LDB_SYNTAX_SAMBA_GUID }, + { "invocationId", LDB_SYNTAX_SAMBA_GUID }, + { "schemaIDGUID", LDB_SYNTAX_SAMBA_GUID }, + { "attributeSecurityGUID", LDB_SYNTAX_SAMBA_GUID }, + { "parentGUID", LDB_SYNTAX_SAMBA_GUID }, + { "siteGUID", LDB_SYNTAX_SAMBA_GUID }, + { "pKTGUID", LDB_SYNTAX_SAMBA_GUID }, + { "fRSVersionGUID", LDB_SYNTAX_SAMBA_GUID }, + { "fRSReplicaSetGUID", LDB_SYNTAX_SAMBA_GUID }, + { "netbootGUID", LDB_SYNTAX_SAMBA_GUID }, + { "objectCategory", LDB_SYNTAX_SAMBA_OBJECT_CATEGORY }, + { "member", LDB_SYNTAX_DN }, + { "memberOf", LDB_SYNTAX_DN }, + { "nCName", LDB_SYNTAX_DN }, + { "schemaNamingContext", LDB_SYNTAX_DN }, + { "configurationNamingContext", LDB_SYNTAX_DN }, + { "rootDomainNamingContext", LDB_SYNTAX_DN }, + { "defaultNamingContext", LDB_SYNTAX_DN }, + { "subRefs", LDB_SYNTAX_DN }, + { "dMDLocation", LDB_SYNTAX_DN }, + { "serverReference", LDB_SYNTAX_DN }, + { "masteredBy", LDB_SYNTAX_DN }, + { "msDs-masteredBy", LDB_SYNTAX_DN }, + { "fSMORoleOwner", LDB_SYNTAX_DN }, +}; + /* register the samba ldif handlers */ int ldb_register_samba_handlers(struct ldb_context *ldb) { - return ldb_set_attrib_handlers(ldb, samba_handlers, ARRAY_SIZE(samba_handlers)); + uint32_t i; + + for (i=0; i < ARRAY_SIZE(samba_attributes); i++) { + int ret; + uint32_t j; + struct ldb_schema_syntax *s = NULL; + + for (j=0; j < ARRAY_SIZE(samba_syntaxes); j++) { + if (strcmp(samba_attributes[i].syntax, samba_syntaxes[j].name) == 0) { + s = &samba_syntaxes[j]; + break; + } + } + + if (!s) { + s = ldb_standard_syntax_by_name(ldb, samba_attributes[i].syntax); + } + + if (!s) { + return -1; + } + + ret = ldb_schema_attribute_add_with_syntax(ldb, samba_attributes[i].name, 0, s); + if (ret != LDB_SUCCESS) { + return ret; + } + } + + return LDB_SUCCESS; } diff --git a/source4/scripting/ejs/mprutil.c b/source4/scripting/ejs/mprutil.c index 6c989807a6..cfed69dbe0 100644 --- a/source4/scripting/ejs/mprutil.c +++ b/source4/scripting/ejs/mprutil.c @@ -171,17 +171,17 @@ static struct MprVar mprLdbMessage(struct ldb_context *ldb, struct ldb_message * for (i=0;i<msg->num_elements;i++) { struct ldb_message_element *el = &msg->elements[i]; struct MprVar val; - const struct ldb_attrib_handler *attr; + const struct ldb_schema_attribute *a; struct ldb_val v; - attr = ldb_attrib_handler(ldb, el->name); - if (attr == NULL) { + a = ldb_schema_attribute_by_name(ldb, el->name); + if (a == NULL) { goto failed; } if (el->num_values == 1 && !str_list_check_ci(multivalued, el->name)) { - if (attr->ldif_write_fn(ldb, msg, &el->values[0], &v) != 0) { + if (a->syntax->ldif_write_fn(ldb, msg, &el->values[0], &v) != 0) { goto failed; } /* FIXME: nasty hack, remove me when ejs will support @@ -195,8 +195,8 @@ static struct MprVar mprLdbMessage(struct ldb_context *ldb, struct ldb_message * int j; val = mprArray(el->name); for (j=0;j<el->num_values;j++) { - if (attr->ldif_write_fn(ldb, msg, - &el->values[j], &v) != 0) { + if (a->syntax->ldif_write_fn(ldb, msg, + &el->values[j], &v) != 0) { goto failed; } /* FIXME: nasty hack, remove me when ejs will support |