/* match a simple leaf node */ static int ldb_match_equality(struct ldb_context *ldb, const struct ldb_message *msg, const struct ldb_parse_tree *tree, enum ldb_scope scope, bool *matched) { unsigned int i; struct ldb_message_element *el; const struct ldb_schema_attribute *a; struct ldb_dn *valuedn; int ret; if (ldb_attr_dn(tree->u.equality.attr) == 0) { valuedn = ldb_dn_from_ldb_val(ldb, ldb, &tree->u.equality.value); if (valuedn == NULL) { return LDB_ERR_INVALID_DN_SYNTAX; } ret = ldb_dn_compare(msg->dn, valuedn); talloc_free(valuedn); *matched = (ret == 0); return LDB_SUCCESS; } /* TODO: handle the "*" case derived from an extended search operation without the attibute type defined */ el = ldb_msg_find_element(msg, tree->u.equality.attr); if (el == NULL) { *matched = false; return LDB_SUCCESS; } a = ldb_schema_attribute_by_name(ldb, el->name); if (a == NULL) { return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; } for (i=0;i<el->num_values;i++) { if (a->syntax->operator_fn) { ret = a->syntax->operator_fn(ldb, LDB_OP_EQUALITY, a, &tree->u.equality.value, &el->values[i], matched); if (ret != LDB_SUCCESS) return ret; if (*matched) return LDB_SUCCESS; } else { if (a->syntax->comparison_fn(ldb, ldb, &tree->u.equality.value, &el->values[i]) == 0) { *matched = true; return LDB_SUCCESS; } } } *matched = false; return LDB_SUCCESS; }
/* return a list of dn's that might match a leaf indexed search */ static int ltdb_index_dn_leaf(struct ldb_module *module, const struct ldb_parse_tree *tree, 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) { ldb_oom(module->ldb); return LDB_ERR_OPERATIONS_ERROR; } list->dn[0] = talloc_strdup(list->dn, (char *)tree->u.equality.value.data); if (list->dn[0] == NULL) { ldb_oom(module->ldb); return LDB_ERR_OPERATIONS_ERROR; } list->count = 1; return LDB_SUCCESS; }
/* match if node is present */ static int ldb_match_present(struct ldb_context *ldb, const struct ldb_message *msg, const struct ldb_parse_tree *tree, enum ldb_scope scope, bool *matched) { const struct ldb_schema_attribute *a; struct ldb_message_element *el; if (ldb_attr_dn(tree->u.present.attr) == 0) { *matched = true; return LDB_SUCCESS; } el = ldb_msg_find_element(msg, tree->u.present.attr); if (el == NULL) { *matched = false; return LDB_SUCCESS; } a = ldb_schema_attribute_by_name(ldb, el->name); if (!a) { return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; } if (a->syntax->operator_fn) { unsigned int i; for (i = 0; i < el->num_values; i++) { int ret = a->syntax->operator_fn(ldb, LDB_OP_PRESENT, a, &el->values[i], NULL, matched); if (ret != LDB_SUCCESS) return ret; if (*matched) return LDB_SUCCESS; } *matched = false; return LDB_SUCCESS; } *matched = true; return LDB_SUCCESS; }