r25218: After discussion with Simo, remove the subclass support from LDB.
authorAndrew Bartlett <abartlet@samba.org>
Tue, 18 Sep 2007 22:43:06 +0000 (22:43 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 20:06:56 +0000 (15:06 -0500)
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

source/lib/ldb/common/attrib_handlers.c
source/lib/ldb/common/ldb_attributes.c
source/lib/ldb/ldb_tdb/ldb_cache.c
source/lib/ldb/ldb_tdb/ldb_index.c
source/lib/ldb/ldb_tdb/ldb_tdb.h
source/lib/ldb/tests/schema-tests/schema.ldif
source/lib/ldb/tests/test-tdb-features.sh
testprogs/ejs/ldb.js

index b8747c3b955e113d1964cd1e55720384dbfc0118..8ed2763d4df5112af67f89b43b109f0e3c359cbc 100644 (file)
@@ -277,33 +277,6 @@ int ldb_comparison_dn(struct ldb_context *ldb, void *mem_ctx,
        return ret;
 }
 
-/*
-  compare two objectclasses, looking at subclasses
-*/
-int ldb_comparison_objectclass(struct ldb_context *ldb, void *mem_ctx,
-                                     const struct ldb_val *v1, const struct ldb_val *v2)
-{
-       int ret, i;
-       const char **subclasses;
-       ret = ldb_comparison_fold(ldb, mem_ctx, v1, v2);
-       if (ret == 0) {
-               return 0;
-       }
-       subclasses = ldb_subclass_list(ldb, (char *)v1->data);
-       if (subclasses == NULL) {
-               return ret;
-       }
-       for (i=0;subclasses[i];i++) {
-               struct ldb_val vs;
-               vs.data = discard_const(subclasses[i]);
-               vs.length = strlen(subclasses[i]);
-               if (ldb_comparison_objectclass(ldb, mem_ctx, &vs, v2) == 0) {
-                       return 0;
-               }
-       }
-       return ret;
-}
-
 /*
   compare two utc time values. 1 second resolution
 */
@@ -368,7 +341,7 @@ static const struct ldb_schema_syntax ldb_standard_syntaxes[] = {
                .ldif_read_fn    = ldb_handler_copy,
                .ldif_write_fn   = ldb_handler_copy,
                .canonicalise_fn = ldb_handler_fold,
-               .comparison_fn   = ldb_comparison_objectclass
+               .comparison_fn   = ldb_comparison_fold
        },
        { 
                .name            = LDB_SYNTAX_UTC_TIME,
index 358d2f18bd599ec2f53766ae6ac27a7451062323..effd93ae2674e9e8ec620d53033b3bf4e2732886 100644 (file)
@@ -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;
-       }
-}
index a7f72dd6d08d1d61151e1edb335dd5c2fb6867f8..de489e3d8b3325eb51fd669ba4a37892f7ae41ca 100644 (file)
@@ -38,7 +38,6 @@
 #define LTDB_FLAG_CASE_INSENSITIVE (1<<0)
 #define LTDB_FLAG_INTEGER          (1<<1)
 #define LTDB_FLAG_HIDDEN           (1<<2)
-#define LTDB_FLAG_OBJECTCLASS      (1<<3)
 
 /* valid attribute flags */
 static const struct {
@@ -167,66 +166,6 @@ failed:
 }
 
 
-/*
-  register any subclasses from @SUBCLASSES
-*/
-static int ltdb_subclasses_load(struct ldb_module *module)
-{
-       struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data;
-       struct ldb_message *msg = ltdb->cache->subclasses;
-       struct ldb_dn *dn;
-       int i, j, r;
-
-       dn = ldb_dn_new(module, module->ldb, LTDB_SUBCLASSES);
-       if (dn == NULL) goto failed;
-
-       r = ltdb_search_dn1(module, dn, msg);
-       if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) {
-               talloc_free(dn);
-               goto failed;
-       }
-       talloc_free(dn);
-
-       for (i=0;i<msg->num_elements;i++) {
-               struct ldb_message_element *el = &msg->elements[i];
-               for (j=0;j<el->num_values;j++) {
-                       if (ldb_subclass_add(module->ldb, el->name, 
-                                            (char *)el->values[j].data) != 0) {
-                               goto failed;
-                       }
-               }
-       }
-
-       return 0;
-failed:
-       return -1;
-}
-
-
-/*
-  de-register any @SUBCLASSES
-*/
-static void ltdb_subclasses_unload(struct ldb_module *module)
-{
-       struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data;
-       struct ldb_message *msg;
-       int i;
-
-       if (ltdb->cache->subclasses == NULL) {
-               /* no previously loaded subclasses */
-               return;
-       }
-
-       msg = ltdb->cache->subclasses;
-       for (i=0;i<msg->num_elements;i++) {
-               ldb_subclass_remove(module->ldb, msg->elements[i].name);
-       }
-
-       talloc_free(ltdb->cache->subclasses);
-       ltdb->cache->subclasses = NULL;
-}
-
-
 /*
   initialise the baseinfo record
 */
@@ -298,7 +237,6 @@ static void ltdb_cache_free(struct ldb_module *module)
 int ltdb_cache_reload(struct ldb_module *module)
 {
        ltdb_attributes_unload(module);
-       ltdb_subclasses_unload(module);
        ltdb_cache_free(module);
        return ltdb_cache_load(module);
 }
@@ -325,10 +263,8 @@ int ltdb_cache_load(struct ldb_module *module)
                ltdb->cache = talloc_zero(ltdb, struct ltdb_cache);
                if (ltdb->cache == NULL) goto failed;
                ltdb->cache->indexlist = talloc_zero(ltdb->cache, struct ldb_message);
-               ltdb->cache->subclasses = talloc_zero(ltdb->cache, struct ldb_message);
                ltdb->cache->attributes = talloc_zero(ltdb->cache, struct ldb_message);
                if (ltdb->cache->indexlist == NULL ||
-                   ltdb->cache->subclasses == NULL ||
                    ltdb->cache->attributes == NULL) {
                        goto failed;
                }
@@ -369,16 +305,12 @@ int ltdb_cache_load(struct ldb_module *module)
        memset(&ltdb->cache->last_attribute, 0, sizeof(ltdb->cache->last_attribute));
 
        ltdb_attributes_unload(module);
-       ltdb_subclasses_unload(module);
 
        talloc_free(ltdb->cache->indexlist);
-       talloc_free(ltdb->cache->subclasses);
 
        ltdb->cache->indexlist = talloc_zero(ltdb->cache, struct ldb_message);
-       ltdb->cache->subclasses = talloc_zero(ltdb->cache, struct ldb_message);
        ltdb->cache->attributes = talloc_zero(ltdb->cache, struct ldb_message);
        if (ltdb->cache->indexlist == NULL ||
-           ltdb->cache->subclasses == NULL ||
            ltdb->cache->attributes == NULL) {
                goto failed;
        }
@@ -394,9 +326,6 @@ int ltdb_cache_load(struct ldb_module *module)
        if (ltdb_attributes_load(module) == -1) {
                goto failed;
        }
-       if (ltdb_subclasses_load(module) == -1) {
-               goto failed;
-       }
 
 done:
        talloc_free(baseinfo);
index bcab3acafe05aa6d28c04809df54cf9c8ea5e596..cf9380f8c089bf47e454d8d292acdbcfa6b6cbe0 100644 (file)
@@ -257,67 +257,6 @@ static int ltdb_index_dn_simple(struct ldb_module *module,
 
 static int list_union(struct ldb_context *, struct dn_list *, const struct dn_list *);
 
-/*
-  return a list of dn's that might match a simple indexed search on
-  the special objectclass attribute
- */
-static int ltdb_index_dn_objectclass(struct ldb_module *module, 
-                                    const struct ldb_parse_tree *tree,
-                                    const struct ldb_message *index_list,
-                                    struct dn_list *list)
-{
-       struct ldb_context *ldb = module->ldb;
-       unsigned int i;
-       int ret;
-       const char *target = (const char *)tree->u.equality.value.data;
-       const char **subclasses;
-
-       list->count = 0;
-       list->dn = NULL;
-
-       ret = ltdb_index_dn_simple(module, tree, index_list, list);
-
-       subclasses = ldb_subclass_list(module->ldb, target);
-
-       if (subclasses == NULL) {
-               return ret;
-       }
-
-       for (i=0;subclasses[i];i++) {
-               struct ldb_parse_tree tree2;
-               struct dn_list *list2;
-               tree2.operation = LDB_OP_EQUALITY;
-               tree2.u.equality.attr = LTDB_OBJECTCLASS;
-               if (!tree2.u.equality.attr) {
-                       return LDB_ERR_OPERATIONS_ERROR;
-               }
-               tree2.u.equality.value.data = 
-                       (uint8_t *)talloc_strdup(list, subclasses[i]);
-               if (tree2.u.equality.value.data == NULL) {
-                       return LDB_ERR_OPERATIONS_ERROR;                        
-               }
-               tree2.u.equality.value.length = strlen(subclasses[i]);
-               list2 = talloc(list, struct dn_list);
-               if (list2 == NULL) {
-                       talloc_free(tree2.u.equality.value.data);
-                       return LDB_ERR_OPERATIONS_ERROR;
-               }
-               if (ltdb_index_dn_objectclass(module, &tree2, 
-                                             index_list, list2) == LDB_SUCCESS) {
-                       if (list->count == 0) {
-                               *list = *list2;
-                               ret = LDB_SUCCESS;
-                       } else {
-                               list_union(ldb, list, list2);
-                               talloc_free(list2);
-                       }
-               }
-               talloc_free(tree2.u.equality.value.data);
-       }
-
-       return ret;
-}
-
 /*
   return a list of dn's that might match a leaf indexed search
  */
@@ -326,9 +265,6 @@ static int ltdb_index_dn_leaf(struct ldb_module *module,
                              const struct ldb_message *index_list,
                              struct dn_list *list)
 {
-       if (ldb_attr_cmp(tree->u.equality.attr, LTDB_OBJECTCLASS) == 0) {
-               return ltdb_index_dn_objectclass(module, tree, index_list, list);
-       }
        if (ldb_attr_dn(tree->u.equality.attr) == 0) {
                list->dn = talloc_array(list, char *, 1);
                if (list->dn == NULL) {
index 61b5f789d768f462dd05c7354aade87a34e6fdbf..d4a8ff2fb15ee185cf5f320bd7c3a59953c9f124 100644 (file)
@@ -21,7 +21,6 @@ struct ltdb_private {
        struct ltdb_cache {
                struct ldb_message *indexlist;
                struct ldb_message *attributes;
-               struct ldb_message *subclasses;
 
                struct {
                        char *name;
@@ -56,7 +55,6 @@ struct ltdb_context {
 #define LTDB_IDXONE     "@IDXONE"
 #define LTDB_BASEINFO   "@BASEINFO"
 #define LTDB_ATTRIBUTES "@ATTRIBUTES"
-#define LTDB_SUBCLASSES "@SUBCLASSES"
 
 /* special attribute types */
 #define LTDB_SEQUENCE_NUMBER "sequenceNumber"
index 515408144ab37aef33f1feb0db9cc57d1c3d5b15..4ab1932839b8b8b91bcdea9da886303b81aa4f89 100644 (file)
@@ -26,18 +26,6 @@ lmPwdHistory: HIDDEN
 createTimestamp: HIDDEN
 modifyTimestamp: HIDDEN
 
-dn: @SUBCLASSES
-top: domain
-top: person
-top: group
-domain: domainDNS
-domain: builtinDomain
-person: organizationalPerson
-organizationalPerson: user
-user: computer
-template: userTemplate
-template: groupTemplate
-
 dn: @MODULES
 @LIST: timestamps,schema
 
index 09a46d833e5dd2ee6f4c0db4aac1a26f9d187f09..fc0959c54a16775e3cc45592318ff0db9380ff6a 100644 (file)
@@ -83,16 +83,6 @@ echo "Testing class search"
 checkcount 0 '(objectClass=otherclass)'
 checkcount 1 '(objectClass=testclass)'
 
-echo "Adding subclass"
-cat <<EOF | $VALGRIND bin/ldbmodify || exit 1
-dn: @SUBCLASSES
-changetype: add
-add: otherclass
-otherclass: testclass
-EOF
-checkcount 1 '(objectClass=otherclass)'
-checkcount 1 '(objectClass=testclass)'
-
 echo "Adding index"
 cat <<EOF | $VALGRIND bin/ldbadd || exit 1
 dn: @INDEXLIST
index 75c02d70915b941740a943c8ae8f5714a5b34300..36b175f2c12bb516da0f77106a7adc7b17b1e994 100755 (executable)
@@ -97,7 +97,6 @@ partition: cn=SideTest:" + prefix + "/" + "testside.ldb
 partition: cn=Sub,cn=PartTest:" + prefix + "/" + "testsub.ldb
 partition: cn=PartTest:" + prefix + "/" + "testpartition.ldb
 partition: cn=Sub,cn=Sub,cn=PartTest:" + prefix + "/" + "testsubsub.ldb
-replicateEntries: @SUBCLASSES
 replicateEntries: @ATTRIBUTES
 replicateEntries: @INDEXLIST
 modules: cn=PartTest:objectguid