1
0
mirror of https://github.com/samba-team/samba.git synced 2025-11-05 04:23:51 +03:00

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 commit is contained in:
Stefan Metzmacher
2006-12-15 13:08:57 +00:00
committed by Gerald (Jerry) Carter
parent 1f67433914
commit b97b8f5dcb
16 changed files with 254 additions and 391 deletions

View File

@@ -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");
const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(module->ldb, "objectSid");
if (handler->canonicalise_fn(module->ldb, ctx, val, &out) != LDB_SUCCESS) {
if (a->syntax->canonicalise_fn(module->ldb, ctx, val, &out) != LDB_SUCCESS) {
return data_blob(NULL, 0);
}

View File

@@ -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;
ldb->schema.attributes = a;
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));
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) {
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

View File

@@ -618,15 +618,15 @@ 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,
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) {

View File

@@ -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;
}

View File

@@ -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,10 +169,10 @@ 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,
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);

View File

@@ -329,17 +329,6 @@ 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;
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 {
const char *name;
ldb_attr_handler_t ldif_read_fn;
@@ -348,6 +337,15 @@ struct ldb_schema_syntax {
ldb_attr_comparison_t comparison_fn;
};
struct ldb_schema_attribute {
const char *name;
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);

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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,

View File

@@ -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],

View File

@@ -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)));

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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,

View File

@@ -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[] = {
#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 = "objectSid",
.flags = 0,
.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
},
{
.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,
},{
.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
},
{
.attr = "objectGUID",
.flags = 0,
},{
.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
},
{
.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,
},{
.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,
},
{
.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,
},
{
.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,
.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;
}

View File

@@ -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,7 +195,7 @@ 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,
if (a->syntax->ldif_write_fn(ldb, msg,
&el->values[j], &v) != 0) {
goto failed;
}