From a06d66a3a669c3a0a0f816438e2b3e91e208f398 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Fri, 1 Jul 2005 06:21:26 +0000 Subject: r8037: a fairly major update to the internals of ldb. Changes are: - moved the knowledge of attribute types out of ldb_tdb and into the generic ldb code. This allows the ldb_match() message match logic to be generic, so it can be used by other backend - added the generic ability to load attribute handlers, for canonicalisation, compare, ldif read and ldif write. In the future this will be used by the schema module to allow us to correctly obey the attributetype schema elements - added attribute handlers for some of the core ldap attribute types, Integer, DirectoryString, DN, ObjectClass etc - added automatic registration of attribute handlers for well-known attribute names 'cn', 'dc', 'dn', 'ou' and 'objectClass' - converted the objectSid special handlers for Samba to the new system - added more correct handling of indexing in tdb backend based on the attribute canonicalisation function - added generic support for subclasses, moving it out of the tdb backend. This will be used in future by the schema module - fixed several bugs in the dn_explode code. It still needs more work, but doesn't corrupt ldb dbs any more. (This used to be commit 944c5844ab441b96d8e5d7b2d151982139d1fab9) --- source4/lib/ldb/common/ldb_attributes.c | 281 ++++++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) create mode 100644 source4/lib/ldb/common/ldb_attributes.c (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c new file mode 100644 index 0000000000..e053ccbbf2 --- /dev/null +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -0,0 +1,281 @@ +/* + ldb database library + + Copyright (C) Andrew Tridgell 2005 + + ** NOTE! The following LGPL license applies to the ldb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + register handlers for specific attributes and objectclass relationships + + this allows a backend to store its schema information in any format + it likes (or to not have any schema information at all) while keeping the + message matching logic generic +*/ + +#include "includes.h" +#include "ldb/include/ldb.h" +#include "ldb/include/ldb_private.h" + +/* + add to the list of ldif handlers for this ldb context +*/ +int ldb_set_attrib_handlers(struct ldb_context *ldb, + const struct ldb_attrib_handler *handlers, + unsigned num_handlers) +{ + struct ldb_attrib_handler *h; + h = talloc_realloc(ldb, ldb->schema.attrib_handlers, + struct ldb_attrib_handler, + ldb->schema.num_attrib_handlers + num_handlers); + if (h == NULL) { + ldb_oom(ldb); + return -1; + } + ldb->schema.attrib_handlers = h; + memcpy(h + ldb->schema.num_attrib_handlers, + handlers, sizeof(*h) * num_handlers); + ldb->schema.num_attrib_handlers += num_handlers; + return 0; +} + + +/* + default function for read/write/canonicalise +*/ +static int ldb_default_copy(struct ldb_context *ldb, + const struct ldb_val *in, + struct ldb_val *out) +{ + *out = *in; + return 0; +} + +/* + default function for comparison +*/ +static int ldb_default_cmp(struct ldb_context *ldb, + const struct ldb_val *v1, + const struct ldb_val *v2) +{ + if (v1->length != v2->length) { + return v1->length - v2->length; + } + return memcmp(v1->data, v2->data, v1->length); +} + +/* + default handler function pointers +*/ +static const struct ldb_attrib_handler ldb_default_attrib_handler = { + .attr = NULL, + .ldif_read_fn = ldb_default_copy, + .ldif_write_fn = ldb_default_copy, + .canonicalise_fn = ldb_default_copy, + .comparison_fn = ldb_default_cmp, +}; + +/* + return the attribute handlers for a given attribute +*/ +const struct ldb_attrib_handler *ldb_attrib_handler(struct ldb_context *ldb, + const char *attrib) +{ + int i; + const struct ldb_attrib_handler *def = &ldb_default_attrib_handler; + /* TODO: should be replaced with a binary search, with a sort on add */ + for (i=0;i<ldb->schema.num_attrib_handlers;i++) { + if (strcmp(ldb->schema.attrib_handlers[i].attr, "*") == 0) { + def = &ldb->schema.attrib_handlers[i]; + } + if (ldb_attr_cmp(attrib, ldb->schema.attrib_handlers[i].attr) == 0) { + return &ldb->schema.attrib_handlers[i]; + } + } + return def; +} + + +/* + add to the list of ldif handlers for this ldb context +*/ +void ldb_remove_attrib_handler(struct ldb_context *ldb, const char *attrib) +{ + const struct ldb_attrib_handler *h; + int i; + h = ldb_attrib_handler(ldb, attrib); + if (h == &ldb_default_attrib_handler) { + return; + } + 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))); + } + ldb->schema.num_attrib_handlers--; +} + + +/* + setup the attribute handles for well known attributes +*/ +int ldb_setup_wellknown_attributes(struct ldb_context *ldb) +{ + const struct { + const char *attr; + const char *syntax; + } wellknown[] = { + { "dn", LDB_SYNTAX_DN }, + { "distinguishedName", LDB_SYNTAX_DN }, + { "cn", LDB_SYNTAX_DIRECTORY_STRING }, + { "dc", LDB_SYNTAX_DIRECTORY_STRING }, + { "ou", LDB_SYNTAX_DIRECTORY_STRING }, + { "objectClass", LDB_SYNTAX_OBJECTCLASS } + }; + int i; + for (i=0;i<ARRAY_SIZE(wellknown);i++) { + const struct ldb_attrib_handler *h = + ldb_attrib_handler_syntax(ldb, wellknown[i].syntax); + struct ldb_attrib_handler h2; + if (h == NULL) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "Unknown syntax '%s'\n", + wellknown[i].syntax); + return -1; + } + h2 = *h; + h2.attr = wellknown[i].attr; + if (ldb_set_attrib_handlers(ldb, &h2, 1) != 0) { + return -1; + } + } + return 0; +} + + +/* + return the list of subclasses for a class +*/ +const char **ldb_subclass_list(struct ldb_context *ldb, const char *class) +{ + int i; + for (i=0;i<ldb->schema.num_classes;i++) { + if (ldb_attr_cmp(class, ldb->schema.classes[i].name) == 0) { + return (const char **)ldb->schema.classes[i].subclasses; + } + } + return NULL; +} + + +/* + add a new subclass +*/ +static int ldb_subclass_new(struct ldb_context *ldb, const char *class, const char *subclass) +{ + struct ldb_subclass *s, *c; + s = talloc_realloc(ldb, ldb->schema.classes, struct ldb_subclass, ldb->schema.num_classes+1); + if (s == NULL) goto failed; + + ldb->schema.classes = s; + c = &s[ldb->schema.num_classes]; + c->name = talloc_strdup(s, class); + if (c->name == NULL) goto failed; + + c->subclasses = talloc_array(s, char *, 2); + if (c->subclasses == NULL) goto failed; + + c->subclasses[0] = talloc_strdup(c->subclasses, subclass); + if (c->subclasses[0] == NULL) goto failed; + c->subclasses[1] = NULL; + + ldb->schema.num_classes++; + + return 0; +failed: + ldb_oom(ldb); + return -1; +} + +/* + add a subclass +*/ +int ldb_subclass_add(struct ldb_context *ldb, const char *class, const char *subclass) +{ + int i, n; + struct ldb_subclass *c; + char **s; + + for (i=0;i<ldb->schema.num_classes;i++) { + if (ldb_attr_cmp(class, ldb->schema.classes[i].name) == 0) { + break; + } + } + if (i == ldb->schema.num_classes) { + return ldb_subclass_new(ldb, class, subclass); + } + c = &ldb->schema.classes[i]; + + for (n=0;c->subclasses[n];n++) /* noop */; + + s = talloc_realloc(ldb->schema.classes, c->subclasses, char *, n+2); + if (s == NULL) { + ldb_oom(ldb); + return -1; + } + + c->subclasses = s; + s[n] = talloc_strdup(s, subclass); + if (s[n] == NULL) { + ldb_oom(ldb); + return -1; + } + s[n+1] = NULL; + + return 0; +} + +/* + remove a set of subclasses for a class +*/ +void ldb_subclass_remove(struct ldb_context *ldb, const char *class) +{ + int i; + struct ldb_subclass *c; + + for (i=0;i<ldb->schema.num_classes;i++) { + if (ldb_attr_cmp(class, ldb->schema.classes[i].name) == 0) { + break; + } + } + if (i == ldb->schema.num_classes) { + return; + } + + c = &ldb->schema.classes[i]; + talloc_free(c->name); + talloc_free(c->subclasses); + if (ldb->schema.num_classes-(i+1) > 0) { + memmove(c, c+1, sizeof(*c) * ldb->schema.num_classes-(i+1)); + } + ldb->schema.num_classes--; + if (ldb->schema.num_classes == 0) { + talloc_free(ldb->schema.classes); + ldb->schema.classes = NULL; + } +} -- cgit From 1c5105065a44173667de2a022dd2417e56b527d6 Mon Sep 17 00:00:00 2001 From: Simo Sorce <idra@samba.org> Date: Sat, 2 Jul 2005 17:30:03 +0000 Subject: r8082: large rewite of ldb_dn.c - we do not support multpiple attribute components anymore, makes code a lot easier they will be readded later if we found out they are really used, so far my tests show w2k3 do not handle them as well - fix escaping issues, move component value to be in an ldb_val structure still need to handle binary values case - make cononicalize functions leak less memory by giving a specific memory context - fix tests scripts so that test-ldap can start - make test not delete databases on completion so that I can inspect them (This used to be commit 624a73148d125690ce18515f19231d26df207738) --- source4/lib/ldb/common/ldb_attributes.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index e053ccbbf2..3d4f24771f 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -60,10 +60,16 @@ int ldb_set_attrib_handlers(struct ldb_context *ldb, default function for read/write/canonicalise */ static int ldb_default_copy(struct ldb_context *ldb, + void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { - *out = *in; + *out = ldb_val_dup(mem_ctx, in); + + if (out->length == 0) { + return -1; + } + return 0; } @@ -71,6 +77,7 @@ static int ldb_default_copy(struct ldb_context *ldb, default function for comparison */ static int ldb_default_cmp(struct ldb_context *ldb, + void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { -- cgit From a7c7a9c64c01287efa100ac26863b8b8ab3f3b65 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Tue, 12 Jul 2005 09:02:58 +0000 Subject: r8364: fixed a valgrind bug spotted by simo (This used to be commit ef804e8f36f1835d5d61f69565f1195a70f37e74) --- source4/lib/ldb/common/ldb_attributes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 3d4f24771f..a915666d78 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -278,7 +278,7 @@ void ldb_subclass_remove(struct ldb_context *ldb, const char *class) talloc_free(c->name); talloc_free(c->subclasses); if (ldb->schema.num_classes-(i+1) > 0) { - memmove(c, c+1, sizeof(*c) * ldb->schema.num_classes-(i+1)); + memmove(c, c+1, sizeof(*c) * (ldb->schema.num_classes-(i+1))); } ldb->schema.num_classes--; if (ldb->schema.num_classes == 0) { -- cgit From c0293aa7159c8b5c9f1a1b13f64af08e5a55ad6a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij <jelmer@samba.org> Date: Tue, 30 Aug 2005 00:43:26 +0000 Subject: r9771: - Prevent ldb crash when a invalid DN is added - Don't silently drop records with empty attributes tridge/simo: Could you please verify this patch is correct? (This used to be commit 505c9b1d3d39475da141d3b3c156a7e5ba06790c) --- source4/lib/ldb/common/ldb_attributes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index a915666d78..3973fc515c 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -66,7 +66,7 @@ static int ldb_default_copy(struct ldb_context *ldb, { *out = ldb_val_dup(mem_ctx, in); - if (out->length == 0) { + if (out->data == NULL && in->data != NULL) { return -1; } -- cgit From ca875491688f755637aece917147f149906f9a8f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett <abartlet@samba.org> Date: Thu, 1 Sep 2005 23:24:16 +0000 Subject: r9928: ncName is a DN, and needs to use DN matching rules. Andrew Bartlett (This used to be commit b89e7a7fcdf80f2cab581f138358b4324d15d6bc) --- source4/lib/ldb/common/ldb_attributes.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 3973fc515c..47b4b1788b 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -149,6 +149,7 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb) const char *syntax; } wellknown[] = { { "dn", LDB_SYNTAX_DN }, + { "ncName", LDB_SYNTAX_DN }, { "distinguishedName", LDB_SYNTAX_DN }, { "cn", LDB_SYNTAX_DIRECTORY_STRING }, { "dc", LDB_SYNTAX_DIRECTORY_STRING }, -- cgit From 49cc13a8f0fbc4f68e14720b733329ce45135cec Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Wed, 12 Oct 2005 07:54:15 +0000 Subject: r10915: added a standard attribute handler for a ldap UTC time string (This used to be commit efd7dd1a775c06f21924f35760f7768b4e8db449) --- source4/lib/ldb/common/ldb_attributes.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 47b4b1788b..bf955ece3d 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -138,6 +138,22 @@ void ldb_remove_attrib_handler(struct ldb_context *ldb, const char *attrib) ldb->schema.num_attrib_handlers--; } +/* + setup a attribute handler using a standard syntax +*/ +int ldb_set_attrib_handler_syntax(struct ldb_context *ldb, + const char *attr, const char *syntax) +{ + const struct ldb_attrib_handler *h = ldb_attrib_handler_syntax(ldb, syntax); + struct ldb_attrib_handler h2; + if (h == NULL) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "Unknown syntax '%s'\n", syntax); + return -1; + } + h2 = *h; + h2.attr = attr; + return ldb_set_attrib_handlers(ldb, &h2, 1); +} /* setup the attribute handles for well known attributes @@ -158,17 +174,8 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb) }; int i; for (i=0;i<ARRAY_SIZE(wellknown);i++) { - const struct ldb_attrib_handler *h = - ldb_attrib_handler_syntax(ldb, wellknown[i].syntax); - struct ldb_attrib_handler h2; - if (h == NULL) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Unknown syntax '%s'\n", - wellknown[i].syntax); - return -1; - } - h2 = *h; - h2.attr = wellknown[i].attr; - if (ldb_set_attrib_handlers(ldb, &h2, 1) != 0) { + if (ldb_set_attrib_handler_syntax(ldb, wellknown[i].attr, + wellknown[i].syntax) != 0) { return -1; } } -- cgit From 4d1c5a023cf6680474bd8d8be73f576d155cfe81 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher <metze@samba.org> Date: Tue, 10 Jan 2006 16:48:32 +0000 Subject: r12829: fix ldb headers, to not include '<...>' files in .c files this helps in getting symbol -fvisibility=hidden (GCC 4 feature) working later. metze (This used to be commit 380938e97f31c7860aed1e73cc0110c6e17b472e) --- source4/lib/ldb/common/ldb_attributes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index bf955ece3d..13e721a266 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -30,8 +30,7 @@ */ #include "includes.h" -#include "ldb/include/ldb.h" -#include "ldb/include/ldb_private.h" +#include "ldb/include/includes.h" /* add to the list of ldif handlers for this ldb context -- cgit From 5c3cbdbb138d44dbadced38794d41e5b659f6b55 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett <abartlet@samba.org> Date: Tue, 6 Jun 2006 17:54:10 +0000 Subject: r16062: objectCategory is a DN, and needs to be matched as such. Andrew Bartlett (This used to be commit 1a868b451a47798dc539e0754ab2b075813ed368) --- source4/lib/ldb/common/ldb_attributes.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 13e721a266..679a05f244 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -166,6 +166,7 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb) { "dn", LDB_SYNTAX_DN }, { "ncName", LDB_SYNTAX_DN }, { "distinguishedName", LDB_SYNTAX_DN }, + { "objectCategory", LDB_SYNTAX_DN }, { "cn", LDB_SYNTAX_DIRECTORY_STRING }, { "dc", LDB_SYNTAX_DIRECTORY_STRING }, { "ou", LDB_SYNTAX_DIRECTORY_STRING }, -- cgit From efddd37af84b9db429237a491cb74a2c12c505cb Mon Sep 17 00:00:00 2001 From: Andrew Bartlett <abartlet@samba.org> Date: Tue, 6 Jun 2006 22:04:55 +0000 Subject: r16066: The OSX AD plugin uses objectCategory searches a lot, and uses them both fully qualified and in the 'short' form. Now we test and support this query format. Andrew Bartlett (This used to be commit 9ddcfacbcedc5eea2730d4bf902c0fcd02bcfa11) --- source4/lib/ldb/common/ldb_attributes.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 679a05f244..13e721a266 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -166,7 +166,6 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb) { "dn", LDB_SYNTAX_DN }, { "ncName", LDB_SYNTAX_DN }, { "distinguishedName", LDB_SYNTAX_DN }, - { "objectCategory", LDB_SYNTAX_DN }, { "cn", LDB_SYNTAX_DIRECTORY_STRING }, { "dc", LDB_SYNTAX_DIRECTORY_STRING }, { "ou", LDB_SYNTAX_DIRECTORY_STRING }, -- cgit From 9f7da6fea0bc9a330f8620d100e27d4eabbae253 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Thu, 17 Aug 2006 01:52:24 +0000 Subject: r17579: make ldb build g++ friendly (This used to be commit 403cbd335594112e0c58fd68d20f0e3faad7d186) --- source4/lib/ldb/common/ldb_attributes.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 13e721a266..c8a7909b4c 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -185,11 +185,11 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb) /* return the list of subclasses for a class */ -const char **ldb_subclass_list(struct ldb_context *ldb, const char *class) +const char **ldb_subclass_list(struct ldb_context *ldb, const char *classname) { int i; for (i=0;i<ldb->schema.num_classes;i++) { - if (ldb_attr_cmp(class, ldb->schema.classes[i].name) == 0) { + if (ldb_attr_cmp(classname, ldb->schema.classes[i].name) == 0) { return (const char **)ldb->schema.classes[i].subclasses; } } @@ -200,7 +200,7 @@ const char **ldb_subclass_list(struct ldb_context *ldb, const char *class) /* add a new subclass */ -static int ldb_subclass_new(struct ldb_context *ldb, const char *class, const char *subclass) +static int ldb_subclass_new(struct ldb_context *ldb, const char *classname, const char *subclass) { struct ldb_subclass *s, *c; s = talloc_realloc(ldb, ldb->schema.classes, struct ldb_subclass, ldb->schema.num_classes+1); @@ -208,7 +208,7 @@ static int ldb_subclass_new(struct ldb_context *ldb, const char *class, const ch ldb->schema.classes = s; c = &s[ldb->schema.num_classes]; - c->name = talloc_strdup(s, class); + c->name = talloc_strdup(s, classname); if (c->name == NULL) goto failed; c->subclasses = talloc_array(s, char *, 2); @@ -229,19 +229,19 @@ failed: /* add a subclass */ -int ldb_subclass_add(struct ldb_context *ldb, const char *class, const char *subclass) +int ldb_subclass_add(struct ldb_context *ldb, const char *classname, const char *subclass) { int i, n; struct ldb_subclass *c; char **s; for (i=0;i<ldb->schema.num_classes;i++) { - if (ldb_attr_cmp(class, ldb->schema.classes[i].name) == 0) { + if (ldb_attr_cmp(classname, ldb->schema.classes[i].name) == 0) { break; } } if (i == ldb->schema.num_classes) { - return ldb_subclass_new(ldb, class, subclass); + return ldb_subclass_new(ldb, classname, subclass); } c = &ldb->schema.classes[i]; @@ -267,13 +267,13 @@ int ldb_subclass_add(struct ldb_context *ldb, const char *class, const char *sub /* remove a set of subclasses for a class */ -void ldb_subclass_remove(struct ldb_context *ldb, const char *class) +void ldb_subclass_remove(struct ldb_context *ldb, const char *classname) { int i; struct ldb_subclass *c; for (i=0;i<ldb->schema.num_classes;i++) { - if (ldb_attr_cmp(class, ldb->schema.classes[i].name) == 0) { + if (ldb_attr_cmp(classname, ldb->schema.classes[i].name) == 0) { break; } } -- cgit From 0cf42c464ea240c4e57cc5b0c31227a0c5f684d4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Tue, 17 Oct 2006 05:50:01 +0000 Subject: r19365: fixed a memory leak in the ldb attribute handling (This used to be commit d7e07685164141f8fb2c2a6258e1fcb46ff9d06c) --- source4/lib/ldb/common/ldb_attributes.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index c8a7909b4c..2d9f0e6cf8 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -39,6 +39,7 @@ int ldb_set_attrib_handlers(struct ldb_context *ldb, const struct ldb_attrib_handler *handlers, unsigned num_handlers) { + int i; struct ldb_attrib_handler *h; h = talloc_realloc(ldb, ldb->schema.attrib_handlers, struct ldb_attrib_handler, @@ -50,6 +51,16 @@ int ldb_set_attrib_handlers(struct ldb_context *ldb, ldb->schema.attrib_handlers = h; memcpy(h + ldb->schema.num_attrib_handlers, handlers, sizeof(*h) * num_handlers); + for (i=0;i<num_handlers;i++) { + if (h[ldb->schema.num_attrib_handlers+i].flags & LDB_ATTR_FLAG_ALLOCATED) { + h[ldb->schema.num_attrib_handlers+i].attr = talloc_strdup(ldb->schema.attrib_handlers, + h[ldb->schema.num_attrib_handlers+i].attr); + if (h[ldb->schema.num_attrib_handlers+i].attr == NULL) { + ldb_oom(ldb); + return -1; + } + } + } ldb->schema.num_attrib_handlers += num_handlers; return 0; } @@ -129,6 +140,9 @@ void ldb_remove_attrib_handler(struct ldb_context *ldb, const char *attrib) if (h == &ldb_default_attrib_handler) { return; } + if (h->flags & LDB_ATTR_FLAG_ALLOCATED) { + talloc_free(h->attr); + } i = h - ldb->schema.attrib_handlers; if (i < ldb->schema.num_attrib_handlers - 1) { memmove(&ldb->schema.attrib_handlers[i], -- cgit From ab7411714b7cceba3c551dccfd0d775b8332f1b4 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher <metze@samba.org> Date: Thu, 16 Nov 2006 11:05:37 +0000 Subject: r19740: fix compiler warning metze (This used to be commit 666e674504c514033390bf69746fb3c35baf4b2a) --- source4/lib/ldb/common/ldb_attributes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 2d9f0e6cf8..26c1aac5a5 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -141,7 +141,7 @@ void ldb_remove_attrib_handler(struct ldb_context *ldb, const char *attrib) return; } if (h->flags & LDB_ATTR_FLAG_ALLOCATED) { - talloc_free(h->attr); + talloc_free(discard_const_p(char, h->attr)); } i = h - ldb->schema.attrib_handlers; if (i < ldb->schema.num_attrib_handlers - 1) { -- cgit From ac6fec2f866c9ec1ce4585d1216bef47db560aa4 Mon Sep 17 00:00:00 2001 From: Simo Sorce <idra@samba.org> Date: Sat, 25 Nov 2006 15:41:12 +0000 Subject: r19886: ncName is specific to samba, not the generic ldb engine (This used to be commit 505afb18fb8ba427bc3d03f41eb309b27bad68f7) --- source4/lib/ldb/common/ldb_attributes.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 26c1aac5a5..61dd624c25 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -178,7 +178,6 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb) const char *syntax; } wellknown[] = { { "dn", LDB_SYNTAX_DN }, - { "ncName", LDB_SYNTAX_DN }, { "distinguishedName", LDB_SYNTAX_DN }, { "cn", LDB_SYNTAX_DIRECTORY_STRING }, { "dc", LDB_SYNTAX_DIRECTORY_STRING }, -- cgit From 096aa31e945c9e856ea58a52888a3d51d725105d Mon Sep 17 00:00:00 2001 From: Simo Sorce <idra@samba.org> Date: Sun, 26 Nov 2006 06:04:35 +0000 Subject: r19907: this function is used a lot use a binary search to get the right handler (This used to be commit 789e1088c9ce923ca5a6d703b69810eba3bcd4d0) --- source4/lib/ldb/common/ldb_attributes.c | 58 +++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 18 deletions(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 61dd624c25..75a4b60759 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -39,29 +39,34 @@ int ldb_set_attrib_handlers(struct ldb_context *ldb, const struct ldb_attrib_handler *handlers, unsigned num_handlers) { - int i; + 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, - ldb->schema.num_attrib_handlers + num_handlers); + struct ldb_attrib_handler, n); if (h == NULL) { ldb_oom(ldb); return -1; } ldb->schema.attrib_handlers = h; - memcpy(h + ldb->schema.num_attrib_handlers, - handlers, sizeof(*h) * num_handlers); - for (i=0;i<num_handlers;i++) { - if (h[ldb->schema.num_attrib_handlers+i].flags & LDB_ATTR_FLAG_ALLOCATED) { - h[ldb->schema.num_attrib_handlers+i].attr = talloc_strdup(ldb->schema.attrib_handlers, - h[ldb->schema.num_attrib_handlers+i].attr); - if (h[ldb->schema.num_attrib_handlers+i].attr == NULL) { + + 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; + } + } + 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; } } + ldb->schema.num_attrib_handlers++; } - ldb->schema.num_attrib_handlers += num_handlers; return 0; } @@ -114,17 +119,34 @@ static const struct ldb_attrib_handler ldb_default_attrib_handler = { const struct ldb_attrib_handler *ldb_attrib_handler(struct ldb_context *ldb, const char *attrib) { - int i; + int i, e, b = 0, r; const struct ldb_attrib_handler *def = &ldb_default_attrib_handler; - /* TODO: should be replaced with a binary search, with a sort on add */ - for (i=0;i<ldb->schema.num_attrib_handlers;i++) { - if (strcmp(ldb->schema.attrib_handlers[i].attr, "*") == 0) { - def = &ldb->schema.attrib_handlers[i]; - } - if (ldb_attr_cmp(attrib, ldb->schema.attrib_handlers[i].attr) == 0) { + + /* 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]; + b = 1; + } + + /* do a binary search on the array */ + e = ldb->schema.num_attrib_handlers - 1; + + while (b <= e) { + + i = (b + e) / 2; + + r = ldb_attr_cmp(attrib, ldb->schema.attrib_handlers[i].attr); + if (r == 0) { return &ldb->schema.attrib_handlers[i]; } + if (r < 0) { + e = i - 1; + } else { + b = i + 1; + } + } + return def; } -- cgit From 875a920ac2d67c9e98100ff2df20b1e7d3951d14 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher <metze@samba.org> Date: Thu, 30 Nov 2006 10:44:49 +0000 Subject: r19966: we don't need 2 versions of this functions metze (This used to be commit 98ab0af4ae0d716f27bc48b699f52d34dc2f8507) --- source4/lib/ldb/common/ldb_attributes.c | 38 ++++----------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 75a4b60759..d52264b90f 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -71,46 +71,16 @@ int ldb_set_attrib_handlers(struct ldb_context *ldb, } -/* - default function for read/write/canonicalise -*/ -static int ldb_default_copy(struct ldb_context *ldb, - void *mem_ctx, - const struct ldb_val *in, - struct ldb_val *out) -{ - *out = ldb_val_dup(mem_ctx, in); - - if (out->data == NULL && in->data != NULL) { - return -1; - } - - return 0; -} - -/* - default function for comparison -*/ -static int ldb_default_cmp(struct ldb_context *ldb, - void *mem_ctx, - const struct ldb_val *v1, - const struct ldb_val *v2) -{ - if (v1->length != v2->length) { - return v1->length - v2->length; - } - return memcmp(v1->data, v2->data, v1->length); -} /* default handler function pointers */ static const struct ldb_attrib_handler ldb_default_attrib_handler = { .attr = NULL, - .ldif_read_fn = ldb_default_copy, - .ldif_write_fn = ldb_default_copy, - .canonicalise_fn = ldb_default_copy, - .comparison_fn = ldb_default_cmp, + .ldif_read_fn = ldb_handler_copy, + .ldif_write_fn = ldb_handler_copy, + .canonicalise_fn = ldb_handler_copy, + .comparison_fn = ldb_comparison_binary, }; /* -- cgit From e55ff42229d67c1447f2c811191b79137b1ce8cc Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher <metze@samba.org> Date: Thu, 14 Dec 2006 10:03:21 +0000 Subject: r20168: start separating attributes and syntaxes metze (This used to be commit 8dda4342f648aa71878ac9eeb7941710e2813aee) --- source4/lib/ldb/common/ldb_attributes.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index d52264b90f..a0118d2452 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -149,15 +149,20 @@ void ldb_remove_attrib_handler(struct ldb_context *ldb, const char *attrib) int ldb_set_attrib_handler_syntax(struct ldb_context *ldb, const char *attr, const char *syntax) { - const struct ldb_attrib_handler *h = ldb_attrib_handler_syntax(ldb, syntax); - struct ldb_attrib_handler h2; - if (h == NULL) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Unknown syntax '%s'\n", 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; } - h2 = *h; - h2.attr = attr; - return ldb_set_attrib_handlers(ldb, &h2, 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); } /* -- cgit From c69717755abeaf8bf93e76255d0912e3a24b7cb0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher <metze@samba.org> Date: Fri, 15 Dec 2006 13:08:57 +0000 Subject: 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) --- source4/lib/ldb/common/ldb_attributes.c | 157 ++++++++++++++++---------------- 1 file changed, 79 insertions(+), 78 deletions(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') 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 -- cgit From 8e7d87babc40688023085668ad88e219870c1280 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher <metze@samba.org> Date: Fri, 15 Dec 2006 18:56:56 +0000 Subject: r20188: move back to an default attribute handler and not use the '*' attribute to not conflict with the one that maybe added via the @ATTRIBUTES object this is just to make the test-tdb-feature.sh torture test happy There's still a bug when a attribute is registered multiple time without removing old ldb_schema_attribute instances. But this bug was there before my changes too and was just triggered by my changes metze (This used to be commit 70c4a367433f8c54bdd940eb0a6a24ab976a4063) --- source4/lib/ldb/common/ldb_attributes.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index f884c1d5c6..0cd92576dc 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -86,6 +86,20 @@ int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, return 0; } +static const struct ldb_schema_syntax ldb_syntax_default = { + .name = LDB_SYNTAX_OCTET_STRING, + .ldif_read_fn = ldb_handler_copy, + .ldif_write_fn = ldb_handler_copy, + .canonicalise_fn = ldb_handler_copy, + .comparison_fn = ldb_comparison_binary +}; + +static const struct ldb_schema_attribute ldb_attribute_default = { + .name = NULL, + .flags = 0, + .syntax = &ldb_syntax_default +}; + /* return the attribute handlers for a given attribute */ @@ -93,7 +107,7 @@ const struct ldb_schema_attribute *ldb_schema_attribute_by_name(struct ldb_conte const char *name) { int i, e, b = 0, r; - const struct ldb_schema_attribute *def = NULL; + const struct ldb_schema_attribute *def = &ldb_attribute_default; /* as handlers are sorted, '*' must be the first if present */ if (strcmp(ldb->schema.attributes[0].name, "*") == 0) { @@ -171,7 +185,6 @@ 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 }, -- cgit From 52fb06edc25e8538c413df1aaabba18c859a00cf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij <jelmer@samba.org> Date: Sat, 5 May 2007 18:50:56 +0000 Subject: r22681: Fix standalone ldb build when parent directory name != ldb. (This used to be commit 1093875d59f1ea9b8bd82277d4f9d8366e584952) --- source4/lib/ldb/common/ldb_attributes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 0cd92576dc..b8ae2f6131 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -29,8 +29,7 @@ message matching logic generic */ -#include "includes.h" -#include "ldb/include/includes.h" +#include "ldb_includes.h" /* add a attribute to the ldb_schema -- cgit From b8d69a7ea2505b706ff7c74d7c97bc89d82dfa07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Tue, 10 Jul 2007 02:46:15 +0000 Subject: r23795: more v2->v3 conversion (This used to be commit 84b468b2f8f2dffda89593f816e8bc6a8b6d42ac) --- source4/lib/ldb/common/ldb_attributes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index b8ae2f6131..dc6e04b833 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -10,7 +10,7 @@ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- cgit From 6c973f4e8ccbcb6c9275f8a54e26abb19df7e15a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Tue, 10 Jul 2007 03:42:26 +0000 Subject: r23798: updated old Temple Place FSF addresses to new URL (This used to be commit 40c0919aaa9c1b14bbaebb95ecce53eb0380fdbb) --- source4/lib/ldb/common/ldb_attributes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index dc6e04b833..358d2f18bd 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -18,8 +18,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + License along with this library; if not, see <http://www.gnu.org/licenses/>. */ /* register handlers for specific attributes and objectclass relationships -- cgit From c64116e158080c7cd7304cdd3b80c8666f78c7c6 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett <abartlet@samba.org> Date: Tue, 18 Sep 2007 22:43:06 +0000 Subject: r25218: After discussion with Simo, remove the subclass support from LDB. Subclass support was designed to avoid needing to spell out the full list of objectClasses that an entry was in. However, Samba4 now enforces this restriction in the objectClass module, and the way subclass matching was handled was complex and counter-intuitive in my opinion (and did not match LDAP). Andrew Bartlett (This used to be commit f5ce04b904e14445a2a7e7f92e7e1f64b645c6f2) --- source4/lib/ldb/common/ldb_attributes.c | 111 -------------------------------- 1 file changed, 111 deletions(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 358d2f18bd..effd93ae26 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -204,114 +204,3 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb) return LDB_SUCCESS; } -/* - return the list of subclasses for a class -*/ -const char **ldb_subclass_list(struct ldb_context *ldb, const char *classname) -{ - int i; - for (i=0;i<ldb->schema.num_classes;i++) { - if (ldb_attr_cmp(classname, ldb->schema.classes[i].name) == 0) { - return (const char **)ldb->schema.classes[i].subclasses; - } - } - return NULL; -} - - -/* - add a new subclass -*/ -static int ldb_subclass_new(struct ldb_context *ldb, const char *classname, const char *subclass) -{ - struct ldb_subclass *s, *c; - s = talloc_realloc(ldb, ldb->schema.classes, struct ldb_subclass, ldb->schema.num_classes+1); - if (s == NULL) goto failed; - - ldb->schema.classes = s; - c = &s[ldb->schema.num_classes]; - c->name = talloc_strdup(s, classname); - if (c->name == NULL) goto failed; - - c->subclasses = talloc_array(s, char *, 2); - if (c->subclasses == NULL) goto failed; - - c->subclasses[0] = talloc_strdup(c->subclasses, subclass); - if (c->subclasses[0] == NULL) goto failed; - c->subclasses[1] = NULL; - - ldb->schema.num_classes++; - - return 0; -failed: - ldb_oom(ldb); - return -1; -} - -/* - add a subclass -*/ -int ldb_subclass_add(struct ldb_context *ldb, const char *classname, const char *subclass) -{ - int i, n; - struct ldb_subclass *c; - char **s; - - for (i=0;i<ldb->schema.num_classes;i++) { - if (ldb_attr_cmp(classname, ldb->schema.classes[i].name) == 0) { - break; - } - } - if (i == ldb->schema.num_classes) { - return ldb_subclass_new(ldb, classname, subclass); - } - c = &ldb->schema.classes[i]; - - for (n=0;c->subclasses[n];n++) /* noop */; - - s = talloc_realloc(ldb->schema.classes, c->subclasses, char *, n+2); - if (s == NULL) { - ldb_oom(ldb); - return -1; - } - - c->subclasses = s; - s[n] = talloc_strdup(s, subclass); - if (s[n] == NULL) { - ldb_oom(ldb); - return -1; - } - s[n+1] = NULL; - - return 0; -} - -/* - remove a set of subclasses for a class -*/ -void ldb_subclass_remove(struct ldb_context *ldb, const char *classname) -{ - int i; - struct ldb_subclass *c; - - for (i=0;i<ldb->schema.num_classes;i++) { - if (ldb_attr_cmp(classname, ldb->schema.classes[i].name) == 0) { - break; - } - } - if (i == ldb->schema.num_classes) { - return; - } - - c = &ldb->schema.classes[i]; - talloc_free(c->name); - talloc_free(c->subclasses); - if (ldb->schema.num_classes-(i+1) > 0) { - memmove(c, c+1, sizeof(*c) * (ldb->schema.num_classes-(i+1))); - } - ldb->schema.num_classes--; - if (ldb->schema.num_classes == 0) { - talloc_free(ldb->schema.classes); - ldb->schema.classes = NULL; - } -} -- cgit From 1dc5e75218e57fc410773161ab6431db33cd4b27 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett <abartlet@samba.org> Date: Mon, 18 Aug 2008 20:21:31 +1000 Subject: Allow attributes to be overwritten, not just added to (This used to be commit 0aebae91be0fba7ffa94d73946a94aea930a252a) --- source4/lib/ldb/common/ldb_attributes.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index effd93ae26..ab6aa0b734 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -62,11 +62,20 @@ int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, ldb->schema.attributes = a; for (i = 0; i < ldb->schema.num_attributes; i++) { - if (ldb_attr_cmp(attribute, a[i].name) < 0) { + int cmp = ldb_attr_cmp(attribute, a[i].name); + if (cmp == 0) { + if (a[i].flags & LDB_ATTR_FLAG_ALLOCATED) { + talloc_free(discard_const_p(char, a[i].name)); + } + /* To cancel out increment below */ + ldb->schema.num_attributes--; + break; + } else if (cmp < 0) { memmove(a+i+1, a+i, sizeof(*a) * (ldb->schema.num_attributes-i)); break; } } + ldb->schema.num_attributes++; a[i].name = attribute; a[i].flags = flags; @@ -80,7 +89,6 @@ int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, } } - ldb->schema.num_attributes++; return 0; } @@ -145,7 +153,7 @@ void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name) int i; a = ldb_schema_attribute_by_name(ldb, name); - if (a == NULL) { + if (a == NULL || a->name == NULL) { return; } -- cgit From 7e1c62f8b64c9e42018bea33557af31fb7fa7414 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Wed, 20 Aug 2008 15:46:58 +1000 Subject: added a LDB_ATTR_FLAG_FIXED so the schema module can mark attributes as never to be removed. (This used to be commit 9dce558206a2ce70c69b9b6c5c3c9c58ee165b1d) --- source4/lib/ldb/common/ldb_attributes.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index effd93ae26..81aab52a08 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -149,6 +149,11 @@ void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name) return; } + /* FIXED attributes are never removed */ + if (a->flags & LDB_ATTR_FLAG_FIXED) { + return; + } + if (a->flags & LDB_ATTR_FLAG_ALLOCATED) { talloc_free(discard_const_p(char, a->name)); } -- cgit From 9dffeab5a8770de7c97e1b4e88fda372e5760147 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Wed, 20 Aug 2008 16:00:54 +1000 Subject: don't overwrite fixed attributes with @ATTRIBUTES (This used to be commit e860fc171fd127d73df23336089c1479911953da) --- source4/lib/ldb/common/ldb_attributes.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 1e69f412df..3b9d01682c 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -64,6 +64,10 @@ int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, for (i = 0; i < ldb->schema.num_attributes; i++) { int cmp = ldb_attr_cmp(attribute, a[i].name); if (cmp == 0) { + /* silently ignore attempts to overwrite fixed attributes */ + if (a[i].flags & LDB_ATTR_FLAG_FIXED) { + return 0; + } if (a[i].flags & LDB_ATTR_FLAG_ALLOCATED) { talloc_free(discard_const_p(char, a[i].name)); } -- cgit From 4016cfcab7bfb3ffd48a7592fa16952688525493 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett <abartlet@samba.org> Date: Thu, 21 Aug 2008 12:51:06 +1000 Subject: Don't allow a NULL syntax (This used to be commit 505a0c2b702b696b91dab683626bb25b14a49c38) --- source4/lib/ldb/common/ldb_attributes.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/common/ldb_attributes.c') diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 3b9d01682c..747f241781 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -51,6 +51,10 @@ int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, int i, n; struct ldb_schema_attribute *a; + if (!syntax) { + return LDB_ERR_OPERATIONS_ERROR; + } + n = ldb->schema.num_attributes + 1; a = talloc_realloc(ldb, ldb->schema.attributes, -- cgit