summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_tdb/ldb_cache.c
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-05-17 21:43:47 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:16:52 -0500
commitca4e0c8539e5b0e01ca9d68eba8692c544d7a4d6 (patch)
tree018e9cc324cb33f16408d960368f2e79c08d638e /source4/lib/ldb/ldb_tdb/ldb_cache.c
parentf9ad3029ae97f5d5beed3f85ad912830fa8d7930 (diff)
downloadsamba-ca4e0c8539e5b0e01ca9d68eba8692c544d7a4d6.tar.gz
samba-ca4e0c8539e5b0e01ca9d68eba8692c544d7a4d6.tar.bz2
samba-ca4e0c8539e5b0e01ca9d68eba8692c544d7a4d6.zip
r6867: this code will change the way the @ATTRIBUTES object is handled
this object properties are now used as multivalue attributes now all values inserted are checked against a "valid values table" eg: this form is now accepted: dn: @ATTRIBUTES uid: CASE_INSENSITIVE uid: WILDCARD this form is now rejected: dn: @ATTRIBUTES uid: CASE_INSENSITIVE WILDCARD please update your .ldb files if you make use of @ATTRIBUTES (sam.ldb heavily uses it) the code passes all make test tests for both tdb and ldap, it also passes the new test to check for wrong @ATTRIBUTES attribute values Simo. (This used to be commit 1295b891a26c2cb2c34540f90ded83390cf87da2)
Diffstat (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_cache.c64
1 files changed, 37 insertions, 27 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c
index ec22aca3ec..0fe573a829 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_cache.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c
@@ -37,6 +37,21 @@
#include "ldb/include/ldb_private.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
+
+/* valid attribute flags */
+static const struct {
+ const char *name;
+ int value;
+} ltdb_valid_attr_flags[] = {
+ { "CASE_INSENSITIVE", LTDB_FLAG_CASE_INSENSITIVE },
+ { "INTEGER", LTDB_FLAG_INTEGER },
+ { "WILDCARD", LTDB_FLAG_WILDCARD },
+ { "HIDDEN", LTDB_FLAG_HIDDEN },
+ { "NONE", LTDB_FLAG_NONE },
+ { NULL, 0 }
+};
+
+
/*
initialise the baseinfo record
*/
@@ -245,18 +260,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module)
int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name)
{
struct ltdb_private *ltdb = module->private_data;
- const char *attrs;
- const struct {
- const char *name;
- int value;
- } names[] = {
- { "CASE_INSENSITIVE", LTDB_FLAG_CASE_INSENSITIVE },
- { "INTEGER", LTDB_FLAG_INTEGER },
- { "WILDCARD", LTDB_FLAG_WILDCARD },
- { "HIDDEN", LTDB_FLAG_HIDDEN },
- { NULL, 0}
- };
- size_t len;
+ const struct ldb_message_element *attr_el;
int i, ret=0;
if (ltdb->cache->last_attribute.name &&
@@ -269,30 +273,22 @@ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name)
ret = LTDB_FLAG_OBJECTCLASS | LTDB_FLAG_CASE_INSENSITIVE;
}
- attrs = ldb_msg_find_string(ltdb->cache->attributes, attr_name, NULL);
+ attr_el = ldb_msg_find_element(ltdb->cache->attributes, attr_name);
- if (!attrs) {
+ if (!attr_el) {
/* check if theres a wildcard attribute */
- attrs = ldb_msg_find_string(ltdb->cache->attributes, "*", NULL);
+ attr_el = ldb_msg_find_element(ltdb->cache->attributes, "*");
- if (!attrs) {
+ if (!attr_el) {
return ret;
}
}
- /* we avoid using strtok and friends due to their nasty
- interface. This is a little trickier, but much nicer
- from a C interface point of view */
- while ((len = strcspn(attrs, " ,")) > 0) {
- for (i=0;names[i].name;i++) {
- if (strncmp(names[i].name, attrs, len) == 0 &&
- names[i].name[len] == 0) {
- ret |= names[i].value;
- }
+ for (i = 0; i < attr_el->num_values; i++) {
+ if (strcmp(ltdb_valid_attr_flags[i].name, attr_el->values[i].data) == 0) {
+ ret |= ltdb_valid_attr_flags[i].value;
}
- attrs += len;
- attrs += strspn(attrs, " ,");
}
talloc_free(ltdb->cache->last_attribute.name);
@@ -302,3 +298,17 @@ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name)
return ret;
}
+
+int ltdb_check_at_attributes_values(const struct ldb_val *value)
+{
+ int i;
+
+ for (i = 0; ltdb_valid_attr_flags[i].name != NULL; i++) {
+ if ((strcmp(ltdb_valid_attr_flags[i].name, value->data) == 0)) {
+ return 0;
+ }
+ }
+
+ return -1;
+}
+