s4:dsdb Fix up after the MAP_ constants became LDB_MAP_
[ira/wip.git] / source4 / dsdb / samdb / ldb_modules / simple_ldap_map.c
index d923e55484a11ca0080e0b317f812b4c81505ab1..2ab448662aa4d0a61ff3ef5a1ccf669833f54fa5 100644 (file)
@@ -33,6 +33,7 @@
 #include "librpc/gen_ndr/ndr_misc.h"
 #include "librpc/ndr/libndr.h"
 #include "dsdb/samdb/samdb.h"
+#include "../../../lib/ldb/include/ldb_handlers.h"
 
 struct entryuuid_private {
        struct ldb_context *ldb;
@@ -122,6 +123,25 @@ static struct ldb_val sid_always_binary(struct ldb_module *module, TALLOC_CTX *c
        return out;
 }
 
+/* Ensure we always convert sids into string, so the backend doesn't have to know about both forms */
+static struct ldb_val sid_always_string(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
+{
+       struct ldb_context *ldb = ldb_module_get_ctx(module);
+       struct ldb_val out = data_blob(NULL, 0);
+
+       if (ldif_comparision_objectSid_isString(val)) {
+               if (ldb_handler_copy(ldb, ctx, val, &out) != LDB_SUCCESS) {
+                       return data_blob(NULL, 0);
+               }
+
+       } else {
+               if (ldif_write_objectSid(ldb, ctx, val, &out) != LDB_SUCCESS) {
+                       return data_blob(NULL, 0);
+               }
+       }
+       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)
 {
@@ -470,9 +490,9 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
                .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
-                               .remote_name = "objectSid", 
-                               .convert_local = sid_always_binary,
-                               .convert_remote = val_copy,
+                               .remote_name = "sambaSID", 
+                               .convert_local = sid_always_string,
+                               .convert_remote = sid_always_binary,
                        }
                }
        },
@@ -593,7 +613,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "unixHomeDirectory",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "homeDirectory"
@@ -602,7 +622,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "pwdLastSet",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "sambaPwdLastSet"
@@ -611,7 +631,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "lastLogon",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "sambaLogonTime"
@@ -620,7 +640,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "lastLogoff",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "sambaLogoffTime"
@@ -629,7 +649,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "badPwdCount",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "sambaBadPasswordCount"
@@ -638,7 +658,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "logonHours",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "sambaLogonHours"
@@ -647,7 +667,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "homeDrive",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "sambaHomeDrive"
@@ -656,7 +676,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "scriptPath",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "sambaLogonScript"
@@ -665,7 +685,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "profilePath",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "sambaProfilePath"
@@ -674,7 +694,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "userWorkstations",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "sambaUserWorkstations"
@@ -683,7 +703,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "homeDirectory",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "sambaHomePath"
@@ -692,7 +712,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "nextRid",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "sambaNextRid"
@@ -701,7 +721,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "privilegeDisplayName",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "sambaPrivName"