r25000: Fix some more C++ compatibility warnings.
[abartlet/samba.git/.git] / source4 / dsdb / samdb / ldb_modules / entryUUID.c
index c445a0f82a052d7f9861e8cef33fb8ce05121239..1a16cb8321e6da6a14702ff056b8f565f86b66cc 100644 (file)
@@ -8,7 +8,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -17,8 +17,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /* 
@@ -37,7 +36,6 @@
 #include "librpc/ndr/libndr.h"
 
 struct entryUUID_private {
-       struct ldb_result *objectclass_res;     
        struct ldb_dn **base_dns;
 };
 
@@ -149,73 +147,19 @@ static struct ldb_val sid_always_binary(struct ldb_module *module, TALLOC_CTX *c
        return out;
 }
 
+/* Ensure we always convert objectCategory into a DN */
 static struct ldb_val objectCategory_always_dn(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
 {
-       int i;
-       struct map_private *map_private;
-       struct entryUUID_private *entryUUID_private;
-       struct ldb_result *list;
-
-       if (ldb_dn_validate(ldb_dn_new(ctx, module->ldb, (const char *)val->data))) {
-               return *val;
-       }
-       map_private = talloc_get_type(module->private_data, struct map_private);
-
-       entryUUID_private = talloc_get_type(map_private->caller_private, struct entryUUID_private);
-       list = entryUUID_private->objectclass_res;
-
-       for (i=0; list && (i < list->count); i++) {
-               if (ldb_attr_cmp((const char *)val->data, ldb_msg_find_attr_as_string(list->msgs[i], "lDAPDisplayName", NULL)) == 0) {
-                       char *dn = ldb_dn_alloc_linearized(ctx, list->msgs[i]->dn);
-                       return data_blob_string_const(dn);
-               }
-       }
-       return *val;
-}
-
-static struct ldb_val class_to_oid(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
-{
-       int i;
-       struct map_private *map_private;
-       struct entryUUID_private *entryUUID_private;
-       struct ldb_result *list;
-
-       map_private = talloc_get_type(module->private_data, struct map_private);
-
-       entryUUID_private = talloc_get_type(map_private->caller_private, struct entryUUID_private);
-       list = entryUUID_private->objectclass_res;
+       struct ldb_val out = data_blob(NULL, 0);
+       const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(module->ldb, "objectCategory");
 
-       for (i=0; list && (i < list->count); i++) {
-               if (ldb_attr_cmp((const char *)val->data, ldb_msg_find_attr_as_string(list->msgs[i], "lDAPDisplayName", NULL)) == 0) {
-                       const char *oid = ldb_msg_find_attr_as_string(list->msgs[i], "governsID", NULL);
-                       return data_blob_string_const(oid);
-               }
+       if (a->syntax->canonicalise_fn(module->ldb, ctx, val, &out) != LDB_SUCCESS) {
+               return data_blob(NULL, 0);
        }
-       return *val;
-}
-
-static struct ldb_val class_from_oid(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
-{
-       int i;
-       struct map_private *map_private;
-       struct entryUUID_private *entryUUID_private;
-       struct ldb_result *list;
 
-       map_private = talloc_get_type(module->private_data, struct map_private);
-
-       entryUUID_private = talloc_get_type(map_private->caller_private, struct entryUUID_private);
-       list = entryUUID_private->objectclass_res;
-
-       for (i=0; list && (i < list->count); i++) {
-               if (ldb_attr_cmp((const char *)val->data, ldb_msg_find_attr_as_string(list->msgs[i], "governsID", NULL)) == 0) {
-                       const char *oc = ldb_msg_find_attr_as_string(list->msgs[i], "lDAPDisplayName", NULL);
-                       return data_blob_string_const(oc);
-               }
-       }
-       return *val;
+       return out;
 }
 
-
 static struct ldb_val normalise_to_signed32(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
 {
        long long int signed_ll = strtoll((const char *)val->data, NULL, 10);
@@ -307,7 +251,7 @@ static struct ldb_val timestamp_to_usn(struct ldb_module *module, TALLOC_CTX *ct
 }
 
 
-const struct ldb_map_attribute entryUUID_attributes[] = 
+static const struct ldb_map_attribute entryUUID_attributes[] = 
 {
        /* objectGUID */
        {
@@ -399,19 +343,6 @@ const struct ldb_map_attribute entryUUID_attributes[] =
                         }
                }
        },
-#if 0
-       {
-               .local_name = "allowedChildClassesEffective",
-               .type = MAP_CONVERT,
-               .u = {
-                       .convert = {
-                               .remote_name = "allowedChildClassesEffective", 
-                               .convert_local = class_to_oid,
-                               .convert_remote = class_from_oid,
-                       },
-               },
-       },
-#endif
        {
                .local_name = "objectCategory",
                .type = MAP_CONVERT,
@@ -499,7 +430,7 @@ const struct ldb_map_objectclass entryUUID_objectclasses[] =
 
 /* These things do not show up in wildcard searches in OpenLDAP, but
  * we need them to show up in the AD-like view */
-const char * const entryUUID_wildcard_attributes[] = {
+static const char * const entryUUID_wildcard_attributes[] = {
        "objectGUID", 
        "whenCreated", 
        "whenChanged",
@@ -508,7 +439,7 @@ const char * const entryUUID_wildcard_attributes[] = {
        NULL
 };
 
-const struct ldb_map_attribute nsuniqueid_attributes[] = 
+static const struct ldb_map_attribute nsuniqueid_attributes[] = 
 {
        /* objectGUID */
        {
@@ -561,19 +492,6 @@ const struct ldb_map_attribute nsuniqueid_attributes[] =
                         }
                }
        },
-#if 0
-       {
-               .local_name = "allowedChildClassesEffective",
-               .type = MAP_CONVERT,
-               .u = {
-                       .convert = {
-                               .remote_name = "allowedChildClassesEffective", 
-                               .convert_local = class_to_oid,
-                               .convert_remote = class_from_oid,
-                       },
-               },
-       },
-#endif
        {
                .local_name = "objectCategory",
                .type = MAP_CONVERT,
@@ -649,7 +567,7 @@ const struct ldb_map_attribute nsuniqueid_attributes[] =
 
 /* These things do not show up in wildcard searches in OpenLDAP, but
  * we need them to show up in the AD-like view */
-const char * const nsuniqueid_wildcard_attributes[] = {
+static const char * const nsuniqueid_wildcard_attributes[] = {
        "objectGUID", 
        "whenCreated", 
        "whenChanged",
@@ -658,70 +576,6 @@ const char * const nsuniqueid_wildcard_attributes[] = {
        NULL
 };
 
-static struct ldb_dn *find_schema_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx) 
-{
-       const char *rootdse_attrs[] = {"schemaNamingContext", NULL};
-       struct ldb_dn *schema_dn;
-       struct ldb_dn *basedn = ldb_dn_new(mem_ctx, ldb, NULL);
-       struct ldb_result *rootdse_res;
-       int ldb_ret;
-       if (!basedn) {
-               return NULL;
-       }
-       
-       /* Search for rootdse */
-       ldb_ret = ldb_search(ldb, basedn, LDB_SCOPE_BASE, NULL, rootdse_attrs, &rootdse_res);
-       if (ldb_ret != LDB_SUCCESS) {
-               return NULL;
-       }
-       
-       talloc_steal(mem_ctx, rootdse_res);
-
-       if (rootdse_res->count != 1) {
-               ldb_asprintf_errstring(ldb, "Failed to find rootDSE: count %d", rootdse_res->count);
-               return NULL;
-       }
-       
-       /* Locate schema */
-       schema_dn = ldb_msg_find_attr_as_dn(ldb, mem_ctx, rootdse_res->msgs[0], "schemaNamingContext");
-       if (!schema_dn) {
-               return NULL;
-       }
-
-       talloc_free(rootdse_res);
-       return schema_dn;
-}
-
-static int fetch_objectclass_schema(struct ldb_context *ldb, struct ldb_dn *schemadn,
-                             TALLOC_CTX *mem_ctx, 
-                             struct ldb_result **objectclass_res)
-{
-       TALLOC_CTX *local_ctx = talloc_new(mem_ctx);
-       int ret;
-       const char *attrs[] = {
-               "lDAPDisplayName",
-               "governsID",
-               NULL
-       };
-
-       if (!local_ctx) {
-               return LDB_ERR_OPERATIONS_ERROR;
-       }
-       
-       /* Downlaod schema */
-       ret = ldb_search(ldb, schemadn, LDB_SCOPE_SUBTREE, 
-                        "objectClass=classSchema", 
-                        attrs, objectclass_res);
-       if (ret != LDB_SUCCESS) {
-               return ret;
-       }
-
-       talloc_steal(mem_ctx, objectclass_res);
-
-       return ret;
-}
-
-
 static int get_remote_rootdse(struct ldb_context *ldb, void *context, 
                       struct ldb_reply *ares) 
 {
@@ -800,7 +654,6 @@ static int entryUUID_init(struct ldb_module *module)
         int ret;
        struct map_private *map_private;
        struct entryUUID_private *entryUUID_private;
-       struct ldb_dn *schema_dn;
 
        ret = ldb_map_init(module, entryUUID_attributes, entryUUID_objectclasses, entryUUID_wildcard_attributes, NULL);
         if (ret != LDB_SUCCESS)
@@ -811,19 +664,6 @@ static int entryUUID_init(struct ldb_module *module)
        entryUUID_private = talloc_zero(map_private, struct entryUUID_private);
        map_private->caller_private = entryUUID_private;
 
-       schema_dn = find_schema_dn(module->ldb, map_private);
-       if (!schema_dn) {
-               /* Perhaps no schema yet */
-               return LDB_SUCCESS;
-       }
-       
-       ret = fetch_objectclass_schema(module->ldb, schema_dn, entryUUID_private, 
-                                      &entryUUID_private->objectclass_res);
-       if (ret != LDB_SUCCESS) {
-               /* Perhaps no schema yet */
-               return LDB_SUCCESS;
-       }       
-
        ret = find_base_dns(module, entryUUID_private);
 
        return ldb_next_init(module);
@@ -835,7 +675,6 @@ static int nsuniqueid_init(struct ldb_module *module)
         int ret;
        struct map_private *map_private;
        struct entryUUID_private *entryUUID_private;
-       struct ldb_dn *schema_dn;
 
        ret = ldb_map_init(module, nsuniqueid_attributes, NULL, nsuniqueid_wildcard_attributes, NULL);
         if (ret != LDB_SUCCESS)
@@ -846,19 +685,6 @@ static int nsuniqueid_init(struct ldb_module *module)
        entryUUID_private = talloc_zero(map_private, struct entryUUID_private);
        map_private->caller_private = entryUUID_private;
 
-       schema_dn = find_schema_dn(module->ldb, map_private);
-       if (!schema_dn) {
-               /* Perhaps no schema yet */
-               return LDB_SUCCESS;
-       }
-       
-       ret = fetch_objectclass_schema(module->ldb, schema_dn, entryUUID_private, 
-                                      &entryUUID_private->objectclass_res);
-       if (ret != LDB_SUCCESS) {
-               /* Perhaps no schema yet */
-               return LDB_SUCCESS;
-       }       
-
        ret = find_base_dns(module, entryUUID_private);
 
        return ldb_next_init(module);
@@ -867,7 +693,7 @@ static int nsuniqueid_init(struct ldb_module *module)
 static int get_seq(struct ldb_context *ldb, void *context, 
                   struct ldb_reply *ares) 
 {
-       unsigned long long *max_seq = context;
+       unsigned long long *max_seq = (unsigned long long *)context;
        unsigned long long seq;
        if (ares->type == LDB_REPLY_ENTRY) {
                struct ldb_message_element *el = ldb_msg_find_element(ares->message, "contextCSN");