objectclass_attrs: Remove schema copy shallow from attr_handler2
authorGarming Sam <garming@catalyst.net.nz>
Wed, 8 Mar 2017 23:22:13 +0000 (12:22 +1300)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 10 Mar 2017 14:34:38 +0000 (15:34 +0100)
This appears quite expensive (particularly in provision), and also
unnecessary.

Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Fri Mar 10 15:34:39 CET 2017 on sn-devel-144

source4/dsdb/samdb/ldb_modules/objectclass_attrs.c
source4/dsdb/schema/schema_init.c

index e239fb946e7ac004e3bfe3ab380e445cdd7d29f9..c144578f22794d39021a80b06139fb45a73bd4a5 100644 (file)
@@ -456,25 +456,13 @@ static int attr_handler2(struct oc_context *ac)
                struct dsdb_attribute *att = talloc(ac, struct dsdb_attribute);
                const struct dsdb_syntax *attrSyntax;
                WERROR status;
-               struct dsdb_schema *tmp_schema = NULL;
 
-               /*
-                * We temporary remove the prefix map from the schema,
-                * a new prefix map is added by dsdb_create_prefix_mapping()
-                * via the "schema_data" module.
-                */
-               tmp_schema = dsdb_schema_copy_shallow(ac, ldb, ac->schema);
-               if (tmp_schema == NULL) {
-                       return ldb_module_oom(ac->module);
-               }
-               TALLOC_FREE(tmp_schema->prefixmap);
-               status= dsdb_attribute_from_ldb(tmp_schema, msg, att);
+               status = dsdb_attribute_from_ldb(NULL, msg, att);
                if (!W_ERROR_IS_OK(status)) {
                        ldb_set_errstring(ldb,
                                                "objectclass: failed to translate the schemaAttribute to a dsdb_attribute");
                        return LDB_ERR_UNWILLING_TO_PERFORM;
                }
-               TALLOC_FREE(tmp_schema);
 
                attrSyntax = dsdb_syntax_for_attribute(att);
                if (!attrSyntax) {
index 199ee28053c6dc7d03ab021e0592f5050a185d93..256c46774526f8fc939d16bf3dd80590f3bfc711 100644 (file)
@@ -621,9 +621,15 @@ static int dsdb_schema_setup_ldb_schema_attribute(struct ldb_context *ldb,
 } while (0)
 
 /** Create an dsdb_attribute out of ldb message, attr must be already talloced
+ *
+ * If supplied the attribute will be checked against the prefixmap to
+ * ensure it can be mapped.  However we can't have this attribute
+ * const as dsdb_schema_pfm_attid_from_oid calls
+ * dsdb_schema_pfm_make_attid_impl() which may modify prefixmap in
+ * other situations.
  */
 
-WERROR dsdb_attribute_from_ldb(const struct dsdb_schema *schema,
+WERROR dsdb_attribute_from_ldb(struct dsdb_schema_prefixmap *prefixmap,
                               struct ldb_message *msg,
                               struct dsdb_attribute *attr)
 {
@@ -646,13 +652,13 @@ WERROR dsdb_attribute_from_ldb(const struct dsdb_schema *schema,
 
        GET_STRING_LDB(msg, "lDAPDisplayName", attr, attr, lDAPDisplayName, true);
        GET_STRING_LDB(msg, "attributeID", attr, attr, attributeID_oid, true);
-       if (!schema->prefixmap || schema->prefixmap->length == 0) {
+       if (!prefixmap || prefixmap->length == 0) {
                /* set an invalid value */
                attr->attributeID_id = DRSUAPI_ATTID_INVALID;
        } else {
-               status = dsdb_schema_pfm_attid_from_oid(schema->prefixmap,
-                                                   attr->attributeID_oid,
-                                                   &attr->attributeID_id);
+               status = dsdb_schema_pfm_attid_from_oid(prefixmap,
+                                                       attr->attributeID_oid,
+                                                       &attr->attributeID_id);
                if (!W_ERROR_IS_OK(status)) {
                        DEBUG(0,("%s: '%s': unable to map attributeID %s: %s\n",
                                __location__, attr->lDAPDisplayName, attr->attributeID_oid,
@@ -676,11 +682,11 @@ WERROR dsdb_attribute_from_ldb(const struct dsdb_schema *schema,
        GET_UINT32_LDB(msg, "linkID", attr, linkID);
 
        GET_STRING_LDB(msg, "attributeSyntax", attr, attr, attributeSyntax_oid, true);
-       if (!schema->prefixmap || schema->prefixmap->length == 0) {
+       if (!prefixmap || prefixmap->length == 0) {
                /* set an invalid value */
                attr->attributeSyntax_id = DRSUAPI_ATTID_INVALID;
        } else {
-               status = dsdb_schema_pfm_attid_from_oid(schema->prefixmap,
+               status = dsdb_schema_pfm_attid_from_oid(prefixmap,
                                                        attr->attributeSyntax_oid,
                                                        &attr->attributeSyntax_id);
                if (!W_ERROR_IS_OK(status)) {
@@ -723,7 +729,7 @@ WERROR dsdb_set_attribute_from_ldb_dups(struct ldb_context *ldb,
                return WERR_NOT_ENOUGH_MEMORY;
        }
 
-       status = dsdb_attribute_from_ldb(schema, msg, attr);
+       status = dsdb_attribute_from_ldb(schema->prefixmap, msg, attr);
        if (!W_ERROR_IS_OK(status)) {
                return status;
        }