s4:provision - Removed dependency on full Samba 3 schema from FDS
[samba.git] / source4 / dsdb / samdb / ldb_modules / simple_ldap_map.c
index de88178e39f22d109f592b6b9fb9a2ebe9895602..8d3c78d37fb8cea09c11f4104158081fc9b4d4f4 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,
                        }
                }
        },
@@ -530,7 +550,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
                .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
-                                .remote_name = "groupType",
+                                .remote_name = "sambaGroupType",
                                 .convert_local = normalise_to_signed32,
                                 .convert_remote = val_copy,
                         }
@@ -591,6 +611,114 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
                         }
                }
        },
+       {
+               .local_name = "pwdLastSet",
+               .type = LDB_MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaPwdLastSet"
+                        }
+               }
+       },
+       {
+               .local_name = "lastLogon",
+               .type = LDB_MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaLogonTime"
+                        }
+               }
+       },
+       {
+               .local_name = "lastLogoff",
+               .type = LDB_MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaLogoffTime"
+                        }
+               }
+       },
+       {
+               .local_name = "badPwdCount",
+               .type = LDB_MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaBadPasswordCount"
+                        }
+               }
+       },
+       {
+               .local_name = "logonHours",
+               .type = LDB_MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaLogonHours"
+                        }
+               }
+       },
+       {
+               .local_name = "homeDrive",
+               .type = LDB_MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaHomeDrive"
+                        }
+               }
+       },
+       {
+               .local_name = "scriptPath",
+               .type = LDB_MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaLogonScript"
+                        }
+               }
+       },
+       {
+               .local_name = "profilePath",
+               .type = LDB_MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaProfilePath"
+                        }
+               }
+       },
+       {
+               .local_name = "userWorkstations",
+               .type = LDB_MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaUserWorkstations"
+                        }
+               }
+       },
+       {
+               .local_name = "homeDirectory",
+               .type = LDB_MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaHomePath"
+                        }
+               }
+       },
+       {
+               .local_name = "nextRid",
+               .type = LDB_MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaNextRid"
+                        }
+               }
+       },
+       {
+               .local_name = "privilegeDisplayName",
+               .type = LDB_MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaPrivName"
+                        }
+               }
+       },
        {
                .local_name = "*",
                .type = LDB_MAP_KEEP,
@@ -600,6 +728,14 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        }
 };
 
+/* This objectClass conflicts with builtin classes on FDS */
+const struct ldb_map_objectclass nsuniqueid_objectclasses[] =
+{
+       {
+               .local_name = NULL
+       }
+};
+
 /* These things do not show up in wildcard searches in OpenLDAP, but
  * we need them to show up in the AD-like view */
 static const char * const nsuniqueid_wildcard_attributes[] = {
@@ -626,7 +762,7 @@ static int entryuuid_init(struct ldb_module *module)
 static int nsuniqueid_init(struct ldb_module *module)
 {
         int ret;
-       ret = ldb_map_init(module, nsuniqueid_attributes, NULL, nsuniqueid_wildcard_attributes, "extensibleObject", NULL);
+       ret = ldb_map_init(module, nsuniqueid_attributes, nsuniqueid_objectclasses, nsuniqueid_wildcard_attributes, "extensibleObject", NULL);
         if (ret != LDB_SUCCESS)
                 return ret;