diff options
author | Stefan Metzmacher <metze@samba.org> | 2006-12-15 13:08:57 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:29:19 -0500 |
commit | c69717755abeaf8bf93e76255d0912e3a24b7cb0 (patch) | |
tree | 979dfa0ee6680bd67b47661ae78965b52577a698 /source4/lib/ldb/common | |
parent | 1a1027b8244a2f41676b2bd5999015c769fb4fb4 (diff) | |
download | samba-c69717755abeaf8bf93e76255d0912e3a24b7cb0.tar.gz samba-c69717755abeaf8bf93e76255d0912e3a24b7cb0.tar.bz2 samba-c69717755abeaf8bf93e76255d0912e3a24b7cb0.zip |
r20184: change ldb_attrib_handler into ldb_schema_attribute, which has a pointer
to a ldb_schema_syntax struct.
the default attribute handler is now registered dynamicly as "*"
attribute, instead of having its own code path.
ldb_schema_attribute's can be added to the ldb_schema given a
ldb_schema_syntax struct or the syntax name
we may also need to introduce a ldb_schema_matching_rule,
and add a pointer to a default ldb_schema_matching_rule
in the ldb_schema_syntax.
metze
(This used to be commit b97b8f5dcbce006f005e53ca79df3330e62f117b)
Diffstat (limited to 'source4/lib/ldb/common')
-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 |
4 files changed, 103 insertions, 102 deletions
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); |