s4-schema: rename dsdb_attribute_from_ldb to dsdb_set_attribute_from_ldb and dsdb_cl...
authorMatthieu Patou <mat@matws.net>
Sun, 15 Apr 2012 21:50:20 +0000 (14:50 -0700)
committerMichael Adam <obnox@samba.org>
Tue, 17 Apr 2012 22:06:59 +0000 (00:06 +0200)
source4/dsdb/schema/schema_init.c
source4/dsdb/schema/schema_set.c
source4/dsdb/schema/tests/schema_syntax.c
source4/torture/ldap/schema.c

index 93070503c7b3763ce7a976cef4d2bbac38aca07c..2db708d2df5e74011bc4dece315943fab55c24f4 100644 (file)
@@ -614,14 +614,17 @@ static int dsdb_schema_setup_ldb_schema_attribute(struct ldb_context *ldb,
        }\
 } while (0)
 
-WERROR dsdb_attribute_from_ldb(struct ldb_context *ldb,
-                              struct dsdb_schema *schema,
-                              struct ldb_message *msg)
+/** Create an dsdb_attribute out of ldb message, attr must be already talloced
+ */
+
+WERROR dsdb_attribute_from_ldb(const struct dsdb_schema *schema,
+                              struct ldb_message *msg,
+                              struct dsdb_attribute *attr)
 {
        WERROR status;
-       struct dsdb_attribute *attr = talloc_zero(schema, struct dsdb_attribute);
-       if (!attr) {
-               return WERR_NOMEM;
+       if (attr == NULL) {
+               DEBUG(0, ("%s: attr is null, it's expected not to be so\n", __location__));
+               return WERR_INVALID_PARAM;
        }
 
        GET_STRING_LDB(msg, "cn", attr, attr, cn, false);
@@ -690,6 +693,24 @@ WERROR dsdb_attribute_from_ldb(struct ldb_context *ldb,
        GET_BOOL_LDB(msg, "isDefunct", attr, isDefunct, false);
        GET_BOOL_LDB(msg, "systemOnly", attr, systemOnly, false);
 
+       return WERR_OK;
+}
+
+WERROR dsdb_set_attribute_from_ldb(struct ldb_context *ldb,
+                              struct dsdb_schema *schema,
+                              struct ldb_message *msg)
+{
+       WERROR status;
+       struct dsdb_attribute *attr = talloc_zero(schema, struct dsdb_attribute);
+       if (!attr) {
+               return WERR_NOMEM;
+       }
+
+       status = dsdb_attribute_from_ldb(schema, msg, attr);
+       if (!W_ERROR_IS_OK(status)) {
+               return status;
+       }
+
        attr->syntax = dsdb_syntax_for_attribute(attr);
        if (!attr->syntax) {
                DEBUG(0,(__location__ ": Unknown schema syntax for %s\n",
@@ -709,7 +730,7 @@ WERROR dsdb_attribute_from_ldb(struct ldb_context *ldb,
        return WERR_OK;
 }
 
-WERROR dsdb_class_from_ldb(struct dsdb_schema *schema,
+WERROR dsdb_set_class_from_ldb(struct dsdb_schema *schema,
                           struct ldb_message *msg)
 {
        WERROR status;
index 4142842eee7b2b76274b880deb367855c1770e61..8a4361058b1838a93917985a14083f9afb00a22e 100644 (file)
@@ -667,10 +667,10 @@ WERROR dsdb_schema_set_el_from_ldb_msg(struct ldb_context *ldb, struct dsdb_sche
 {
        if (samdb_find_attribute(ldb, msg,
                                 "objectclass", "attributeSchema") != NULL) {
-               return dsdb_attribute_from_ldb(ldb, schema, msg);
+               return dsdb_set_attribute_from_ldb(ldb, schema, msg);
        } else if (samdb_find_attribute(ldb, msg,
                                 "objectclass", "classSchema") != NULL) {
-               return dsdb_class_from_ldb(schema, msg);
+               return dsdb_set_class_from_ldb(schema, msg);
        }
 
        /* Don't fail on things not classes or attributes */
index 9127d08120a12433c23e213d440acbb7cc48c685..419dc3dc4c27d84e97d735fb5858a2140462b9ce 100644 (file)
@@ -74,9 +74,9 @@ static bool torture_syntax_add_OR_Name(struct torture_context *tctx,
        ldif = ldb_ldif_read_string(ldb, &ldif_str);
        torture_assert(tctx, ldif, "Failed to parse LDIF for authOrig");
 
-       werr = dsdb_attribute_from_ldb(ldb, schema, ldif->msg);
+       werr = dsdb_set_attribute_from_ldb(ldb, schema, ldif->msg);
        ldb_ldif_read_free(ldb, ldif);
-       torture_assert_werr_ok(tctx, werr, "dsdb_attribute_from_ldb() failed!");
+       torture_assert_werr_ok(tctx, werr, "dsdb_set_attribute_from_ldb() failed!");
 
        ldb_res = dsdb_set_schema(ldb, schema);
        torture_assert_int_equal(tctx, ldb_res, LDB_SUCCESS, "dsdb_set_schema() failed");
index af33de9d0a8a80a4de70be61f644d8d0f57a0d7a..66284f1ef0e2ae961ad7beda1749863345a9f988 100644 (file)
@@ -213,7 +213,7 @@ static int test_add_attribute(void *ptr, struct ldb_context *ldb, struct ldb_mes
        struct dsdb_schema *schema = talloc_get_type(ptr, struct dsdb_schema);
        WERROR status;
 
-       status = dsdb_attribute_from_ldb(ldb, schema, msg);
+       status = dsdb_set_attribute_from_ldb(ldb, schema, msg);
        if (!W_ERROR_IS_OK(status)) {
                goto failed;
        }
@@ -228,7 +228,7 @@ static int test_add_class(void *ptr, struct ldb_context *ldb, struct ldb_message
        struct dsdb_schema *schema = talloc_get_type(ptr, struct dsdb_schema);
        WERROR status;
 
-       status = dsdb_class_from_ldb(schema, msg);
+       status = dsdb_set_class_from_ldb(schema, msg);
        if (!W_ERROR_IS_OK(status)) {
                goto failed;
        }