s4 - Mapped AD schema to existing FDS schema.
[samba.git] / source4 / dsdb / samdb / ldb_modules / simple_ldap_map.c
index 8fb639f53f10996be30407a8d1c7ad99c0cf4183..d923e55484a11ca0080e0b317f812b4c81505ab1 100644 (file)
@@ -147,6 +147,8 @@ static struct ldb_val objectCategory_always_dn(struct ldb_module *module, TALLOC
 static struct ldb_val normalise_to_signed32(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
 {
        struct ldb_val out;
+       /* We've to use "strtoll" here to have the intended overflows.
+        * Otherwise we may get "LONG_MAX" and the conversion is wrong. */
        int32_t i = (int32_t) strtoll((char *)val->data, NULL, 0);
        out = data_blob_string_const(talloc_asprintf(ctx, "%d", i));
        return out;
@@ -231,7 +233,7 @@ static const struct ldb_map_attribute entryuuid_attributes[] =
        /* objectGUID */
        {
                .local_name = "objectGUID",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                .remote_name = "entryUUID", 
@@ -243,7 +245,7 @@ static const struct ldb_map_attribute entryuuid_attributes[] =
        /* invocationId */
        {
                .local_name = "invocationId",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                .remote_name = "invocationId", 
@@ -255,7 +257,7 @@ static const struct ldb_map_attribute entryuuid_attributes[] =
        /* objectSid */
        {
                .local_name = "objectSid",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                .remote_name = "objectSid", 
@@ -266,7 +268,7 @@ static const struct ldb_map_attribute entryuuid_attributes[] =
        },
        {
                .local_name = "name",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "samba4RDN"
@@ -275,7 +277,7 @@ static const struct ldb_map_attribute entryuuid_attributes[] =
        },
        {
                .local_name = "whenCreated",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "createTimestamp"
@@ -284,7 +286,7 @@ static const struct ldb_map_attribute entryuuid_attributes[] =
        },
        {
                .local_name = "whenChanged",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "modifyTimestamp"
@@ -293,7 +295,7 @@ static const struct ldb_map_attribute entryuuid_attributes[] =
        },
        {
                .local_name = "objectClasses",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "samba4ObjectClasses"
@@ -302,7 +304,7 @@ static const struct ldb_map_attribute entryuuid_attributes[] =
        },
        {
                .local_name = "dITContentRules",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "samba4DITContentRules"
@@ -311,7 +313,7 @@ static const struct ldb_map_attribute entryuuid_attributes[] =
        },
        {
                .local_name = "attributeTypes",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "samba4AttributeTypes"
@@ -320,7 +322,7 @@ static const struct ldb_map_attribute entryuuid_attributes[] =
        },
        {
                .local_name = "objectCategory",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                .remote_name = "objectCategory", 
@@ -331,60 +333,71 @@ static const struct ldb_map_attribute entryuuid_attributes[] =
        },
        {
                .local_name = "distinguishedName",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "entryDN"
                         }
                }
        },
+       {
+               .local_name = "primaryGroupID",
+               .type = LDB_MAP_CONVERT,
+               .u = {
+                       .convert = {
+                                .remote_name = "primaryGroupID",
+                                .convert_local = normalise_to_signed32,
+                                .convert_remote = val_copy,
+                       }
+               }
+       },
        {
                .local_name = "groupType",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                 .remote_name = "groupType",
                                 .convert_local = normalise_to_signed32,
                                 .convert_remote = val_copy,
-                        },
+                        }
                }
        },
        {
                .local_name = "userAccountControl",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                 .remote_name = "userAccountControl",
                                 .convert_local = normalise_to_signed32,
                                 .convert_remote = val_copy,
-                        },
+                        }
                }
        },
        {
                .local_name = "sAMAccountType",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                 .remote_name = "sAMAccountType",
                                 .convert_local = normalise_to_signed32,
                                 .convert_remote = val_copy,
-                        },
+                        }
                }
        },
        {
                .local_name = "systemFlags",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                 .remote_name = "systemFlags",
                                 .convert_local = normalise_to_signed32,
                                 .convert_remote = val_copy,
-                        },
+                        }
                }
        },
        {
                .local_name = "usnChanged",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                 .remote_name = "entryCSN",
@@ -395,7 +408,7 @@ static const struct ldb_map_attribute entryuuid_attributes[] =
        },
        {
                .local_name = "usnCreated",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                 .remote_name = "createTimestamp",
@@ -406,7 +419,7 @@ static const struct ldb_map_attribute entryuuid_attributes[] =
        },
        {
                .local_name = "*",
-               .type = MAP_KEEP,
+               .type = LDB_MAP_KEEP,
        },
        {
                .local_name = NULL,
@@ -442,30 +455,30 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        /* objectGUID */
        {
                .local_name = "objectGUID",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                .remote_name = "nsuniqueid", 
                                .convert_local = guid_ns_string,
                                .convert_remote = encode_ns_guid,
-                       },
-               },
+                       }
+               }
        },
        /* objectSid */ 
        {
                .local_name = "objectSid",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                .remote_name = "objectSid", 
                                .convert_local = sid_always_binary,
                                .convert_remote = val_copy,
-                       },
-               },
+                       }
+               }
        },
        {
                .local_name = "whenCreated",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "createTimestamp"
@@ -474,7 +487,7 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "whenChanged",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "modifyTimestamp"
@@ -483,99 +496,267 @@ static const struct ldb_map_attribute nsuniqueid_attributes[] =
        },
        {
                .local_name = "objectCategory",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                .remote_name = "objectCategory", 
                                .convert_local = objectCategory_always_dn,
                                .convert_remote = val_copy,
-                       },
-               },
+                       }
+               }
        },
        {
                .local_name = "distinguishedName",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                 .remote_name = "entryDN"
                         }
                }
        },
+       {
+               .local_name = "primaryGroupID",
+               .type = LDB_MAP_CONVERT,
+               .u = {
+                       .convert = {
+                                .remote_name = "primaryGroupID",
+                                .convert_local = normalise_to_signed32,
+                                .convert_remote = val_copy,
+                       }
+               }
+       },
        {
                .local_name = "groupType",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
-                                .remote_name = "groupType",
+                                .remote_name = "sambaGroupType",
                                 .convert_local = normalise_to_signed32,
                                 .convert_remote = val_copy,
-                        },
+                        }
                }
        },
        {
                .local_name = "userAccountControl",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                 .remote_name = "userAccountControl",
                                 .convert_local = normalise_to_signed32,
                                 .convert_remote = val_copy,
-                        },
+                        }
                }
        },
        {
                .local_name = "sAMAccountType",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                 .remote_name = "sAMAccountType",
                                 .convert_local = normalise_to_signed32,
                                 .convert_remote = val_copy,
-                        },
+                        }
                }
        },
        {
                .local_name = "systemFlags",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                 .remote_name = "systemFlags",
                                 .convert_local = normalise_to_signed32,
                                 .convert_remote = val_copy,
-                        },
+                        }
                }
        },
        {
                .local_name = "usnChanged",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                 .remote_name = "modifyTimestamp",
                                 .convert_local = usn_to_timestamp,
                                 .convert_remote = timestamp_to_usn,
-                        },
-               },
+                        }
+               }
        },
        {
                .local_name = "usnCreated",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                 .remote_name = "createTimestamp",
                                 .convert_local = usn_to_timestamp,
                                 .convert_remote = timestamp_to_usn,
-                        },
-               },
+                        }
+               }
+       },
+       {
+               .local_name = "unixHomeDirectory",
+               .type = MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "homeDirectory"
+                        }
+               }
+       },
+       {
+               .local_name = "pwdLastSet",
+               .type = MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaPwdLastSet"
+                        }
+               }
+       },
+       {
+               .local_name = "lastLogon",
+               .type = MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaLogonTime"
+                        }
+               }
+       },
+       {
+               .local_name = "lastLogoff",
+               .type = MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaLogoffTime"
+                        }
+               }
+       },
+       {
+               .local_name = "badPwdCount",
+               .type = MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaBadPasswordCount"
+                        }
+               }
+       },
+       {
+               .local_name = "logonHours",
+               .type = MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaLogonHours"
+                        }
+               }
+       },
+       {
+               .local_name = "homeDrive",
+               .type = MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaHomeDrive"
+                        }
+               }
+       },
+       {
+               .local_name = "scriptPath",
+               .type = MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaLogonScript"
+                        }
+               }
+       },
+       {
+               .local_name = "profilePath",
+               .type = MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaProfilePath"
+                        }
+               }
+       },
+       {
+               .local_name = "userWorkstations",
+               .type = MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaUserWorkstations"
+                        }
+               }
+       },
+       {
+               .local_name = "homeDirectory",
+               .type = MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaHomePath"
+                        }
+               }
+       },
+       {
+               .local_name = "nextRid",
+               .type = MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaNextRid"
+                        }
+               }
+       },
+       {
+               .local_name = "privilegeDisplayName",
+               .type = MAP_RENAME,
+               .u = {
+                       .rename = {
+                                .remote_name = "sambaPrivName"
+                        }
+               }
        },
        {
                .local_name = "*",
-               .type = MAP_KEEP,
+               .type = LDB_MAP_KEEP,
        },
        {
                .local_name = NULL,
        }
 };
 
+/* This objectClass conflicts with builtin classes on FDS */
+const struct ldb_map_objectclass nsuniqueid_objectclasses[] =
+{
+       {
+               .local_name = "domain",
+               .remote_name = "samba4Domain"
+       },
+       {
+               .local_name = "rFC822LocalPart",
+               .remote_name = "samba4RFC822LocalPart"
+       },
+       {
+               .local_name = "mailRecipient",
+               .remote_name = "samba4MailRecipient"
+       },
+       {
+               .local_name = "nisMap",
+               .remote_name = "samba4NisMap"
+       },
+       {
+               .local_name = "person",
+               .remote_name = "samba4Person"
+       },
+       {
+               .local_name = "organizationalPerson",
+               .remote_name = "samba4OrganizationalPerson"
+       },
+       {
+               .local_name = "residentialPerson",
+               .remote_name = "samba4ResidentialPerson"
+       },
+       {
+               .local_name = "inetOrgPerson",
+               .remote_name = "samba4InetOrgPerson"
+       },
+       {
+               .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[] = {
@@ -602,7 +783,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;