s4-dsdb: added dsdb_check_single_valued_link()
authorAndrew Tridgell <tridge@samba.org>
Sat, 19 Dec 2009 10:40:55 +0000 (21:40 +1100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 1 Jan 2010 21:16:51 +0000 (08:16 +1100)
This is used in conjunction with the RELAX control, to check for
violations of single value rules for linked attributes

source4/dsdb/samdb/ldb_modules/util.c
source4/dsdb/samdb/ldb_modules/util.h

index b0ccd0341ceae0598db76436f2236cc0ecab99d9..fa451f4bcfdc46cd1e06b8f1935b33cd712d890d 100644 (file)
@@ -371,3 +371,32 @@ const struct dsdb_class * get_last_structural_class(const struct dsdb_schema *sc
 
        return last_class;
 }
+
+/*
+  check if a single valued link has multiple non-deleted values
+
+  This is needed when we will be using the RELAX control to stop
+  ldb_tdb from checking single valued links
+ */
+int dsdb_check_single_valued_link(const struct dsdb_attribute *attr,
+                                 const struct ldb_message_element *el)
+{
+       bool found_active = false;
+       int i;
+
+       if (!(attr->ldb_schema_attribute->flags & LDB_ATTR_FLAG_SINGLE_VALUE) ||
+           el->num_values < 2) {
+               return LDB_SUCCESS;
+       }
+
+       for (i=0; i<el->num_values; i++) {
+               if (!dsdb_dn_is_deleted_val(&el->values[i])) {
+                       if (found_active) {
+                               return LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
+                       }
+                       found_active = true;
+               }
+       }
+
+       return LDB_SUCCESS;
+}
index cc184eee8f26a8b0337b8f4e9781f8c90e011192..66579ab852bb063dde8052c96a8a026bd5982131 100644 (file)
@@ -21,6 +21,8 @@
 
 struct dsdb_schema; /* predeclare schema struct */
 struct GUID;
+struct dsdb_attribute;
+
 #include "dsdb/samdb/ldb_modules/util_proto.h"
 
 #define DSDB_SEARCH_SEARCH_ALL_PARTITIONS     0x0001