s4:"rdn_name" LDB module - fix the creation of the RDN attribute (try to normalise it)
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Mon, 24 May 2010 09:06:29 +0000 (11:06 +0200)
committerMatthias Dieter Wallnöfer <mdw@samba.org>
Mon, 24 May 2010 12:01:06 +0000 (14:01 +0200)
And return always the correct error codes on the failed add operations (should
anyway be ERR_OPERATIONS_ERROR - therefore no behaviour change).

source4/lib/ldb/modules/rdn_name.c

index f1c167cc3943430f88ceb52128d94b85f9c1bfb9..3a4068daf2aac7bdd851680df5658f008579dc7d 100644 (file)
@@ -134,19 +134,33 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req)
                attribute->num_values = 0;
        }
 
-       if (ldb_msg_add_value(msg, "name", &rdn_val, NULL) != 0) {
+       ret = ldb_msg_add_value(msg, "name", &rdn_val, NULL);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
+       a = ldb_schema_attribute_by_name(ldb, rdn_name);
+       if (a == NULL) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
        attribute = rdn_name_find_attribute(msg, rdn_name);
-
        if (!attribute) {
-               if (ldb_msg_add_value(msg, rdn_name, &rdn_val, NULL) != 0) {
-                       return LDB_ERR_OPERATIONS_ERROR;
+               /* add entry with normalised RDN information if possible */
+               if (a->name != NULL) {
+                       ret = ldb_msg_add_value(msg, a->name, &rdn_val, NULL);
+               } else {
+                       ret = ldb_msg_add_value(msg, rdn_name, &rdn_val, NULL);
+               }
+               if (ret != LDB_SUCCESS) {
+                       return ret;
                }
        } else {
-               a = ldb_schema_attribute_by_name(ldb, rdn_name);
-
+               /* normalise attribute name if possible */
+               if (a->name != NULL) {
+                       attribute->name = a->name;
+               }
+               /* normalise attribute value */
                for (i = 0; i < attribute->num_values; i++) {
                        ret = a->syntax->comparison_fn(ldb, msg,
                                        &rdn_val, &attribute->values[i]);