lib/ldb: switch ldb_tdb to schema-based attribute comparison
[metze/samba/wip.git] / lib / ldb / ldb_tdb / ldb_tdb.c
index 30c58f5ee362b94669a195022f48d7f4993d94b3..753d2b4c1dfd22d89e8d1981bd0bb5dd579bc322 100644 (file)
@@ -345,15 +345,15 @@ static int ltdb_add_internal(struct ldb_module *module,
                        return LDB_ERR_CONSTRAINT_VIOLATION;
                }
 
-               /* Do not check "@ATTRIBUTES" for duplicated values */
-               if (ldb_dn_is_special(msg->dn) &&
-                   ldb_dn_check_special(msg->dn, LTDB_ATTRIBUTES)) {
-                       continue;
-               }
-
                /* TODO: This is O(n^2) - replace with more efficient check */
                for (j=0; j<el->num_values; j++) {
-                       if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) {
+                       struct ldb_val *found_val;
+                       ret = ldb_msg_find_val_schema(ldb, a, el,
+                                                     &el->values[j], &found_val);
+                       if (ret != LDB_SUCCESS) {
+                               return ret;
+                       }
+                       if (found_val != &el->values[j]) {
                                ldb_asprintf_errstring(ldb,
                                                       "attribute '%s': value #%u on '%s' provided more than once",
                                                       el->name, j, ldb_dn_get_linearized(msg->dn));
@@ -620,13 +620,9 @@ static int msg_delete_element(struct ldb_module *module,
 
        for (i=0;i<el->num_values;i++) {
                bool matched;
-               if (a->syntax->operator_fn) {
-                       ret = a->syntax->operator_fn(ldb, LDB_OP_EQUALITY, a,
-                                                    &el->values[i], val, &matched);
-                       if (ret != LDB_SUCCESS) return ret;
-               } else {
-                       matched = (a->syntax->comparison_fn(ldb, ldb,
-                                                           &el->values[i], val) == 0);
+               ret = ldb_val_equal_schema(ldb, a, &el->values[i], val, &matched);
+               if (ret != LDB_SUCCESS) {
+                       return ret;
                }
                if (matched) {
                        if (el->num_values == 1) {
@@ -787,7 +783,13 @@ int ltdb_modify_internal(struct ldb_module *module,
                                   valued attributes or aren't provided twice */
                                /* TODO: This is O(n^2) - replace with more efficient check */
                                for (j = 0; j < el->num_values; j++) {
-                                       if (ldb_msg_find_val(el2, &el->values[j]) != NULL) {
+                                       struct ldb_val *matched_val;
+                                       ret = ldb_msg_find_val_schema(ldb, a, el2,
+                                                                     &el->values[j], &matched_val);
+                                       if (ret != LDB_SUCCESS) {
+                                               return ret;
+                                       }
+                                       if (matched_val != NULL) {
                                                if (control_permissive) {
                                                        /* remove this one as if it was never added */
                                                        el->num_values--;
@@ -805,7 +807,12 @@ int ltdb_modify_internal(struct ldb_module *module,
                                                ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
                                                goto done;
                                        }
-                                       if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) {
+                                       ret = ldb_msg_find_val_schema(ldb, a, el,
+                                                                     &el->values[j], &matched_val);
+                                       if (ret != LDB_SUCCESS) {
+                                               return ret;
+                                       }
+                                       if (matched_val != &el->values[j]) {
                                                ldb_asprintf_errstring(ldb,
                                                                       "attribute '%s': value #%u on '%s' provided more than once",
                                                                       el->name, j, ldb_dn_get_linearized(msg2->dn));
@@ -852,7 +859,13 @@ int ltdb_modify_internal(struct ldb_module *module,
 
                        /* TODO: This is O(n^2) - replace with more efficient check */
                        for (j=0; j<el->num_values; j++) {
-                               if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) {
+                               struct ldb_val *matched_val;
+                               ret = ldb_msg_find_val_schema(ldb, a, el,
+                                                             &el->values[j], &matched_val);
+                               if (ret != LDB_SUCCESS) {
+                                       return ret;
+                               }
+                               if (matched_val != &el->values[j]) {
                                        ldb_asprintf_errstring(ldb,
                                                               "attribute '%s': value #%u on '%s' provided more than once",
                                                               el->name, j, ldb_dn_get_linearized(msg2->dn));