Finish removal of iconv_convenience in public API's.
[bbaumbach/samba-autobuild/.git] / source4 / dsdb / samdb / ldb_modules / samba3sam.c
index 429710c2c54fd721ae859c04eeea2f1562ea27e7..42245ce49112a9139f9d44f9bfbc92856899e1ab 100644 (file)
@@ -1,37 +1,43 @@
-/* 
+/*
    ldb database library - Samba3 SAM compatibility backend
 
    Copyright (C) Jelmer Vernooij 2005
+   Copyright (C) Martin Kuehl <mkhl@samba.org> 2006
 */
 
 #include "includes.h"
-#include "ldb/modules/ldb_map.h"
-#include "ldb/include/ldb.h"
-#include "ldb/include/ldb_private.h"
+#include "ldb_module.h"
+#include "ldb/ldb_map/ldb_map.h"
 #include "system/passwd.h"
 
-/* 
+#include "librpc/gen_ndr/ndr_security.h"
+#include "librpc/gen_ndr/ndr_samr.h"
+#include "librpc/ndr/libndr.h"
+#include "libcli/security/security.h"
+#include "libcli/security/proto.h"
+#include "lib/samba3/samba3.h"
+
+/*
  * sambaSID -> member  (dn!)
- * sambaSIDList -> member (dn!) 
- * sambaDomainName -> name 
- * sambaTrustPassword 
- * sambaUnixIdPool 
- * sambaIdmapEntry 
- * sambaAccountPolicy 
- * sambaSidEntry 
+ * sambaSIDList -> member (dn!)
+ * sambaDomainName -> name
+ * sambaTrustPassword
+ * sambaUnixIdPool
+ * sambaIdmapEntry
+ * sambaSidEntry
  * sambaAcctFlags -> systemFlags ?
  * sambaPasswordHistory  -> ntPwdHistory*/
 
 /* Not necessary:
  * sambaConfig
  * sambaShare
- * sambaConfigOption 
+ * sambaConfigOption
  * sambaNextGroupRid
  * sambaNextUserRid
  * sambaAlgorithmicRidBase
  */
 
-/* Not in Samba4: 
+/* Not in Samba4:
  * sambaKickoffTime
  * sambaPwdCanChange
  * sambaPwdMustChange
 /* In Samba4 but not in Samba3:
 */
 
-static void generate_hashes (struct ldb_module *module, const char *local_attr,        const struct ldb_message *local, struct ldb_message *remote_mp, struct ldb_message *remote_fb)
-{
-       const char *upwd = ldb_msg_find_string(local, local_attr, NULL);
-       struct ldb_val val;
-
-       if (!upwd)
-               return;
-
-       ldb_msg_add_string(remote_fb, local_attr, upwd);
-
-       val.length = 16;
-       val.data = talloc_zero_size(module, val.length);
-
-       E_md4hash(upwd, val.data);
-       ldb_msg_add_value(remote_mp, "sambaNTPassword", &val);
-                       
-       val.data = talloc_zero_size(module, val.length);
-       E_deshash(upwd, val.data);
-       ldb_msg_add_value(remote_mp, "sambaLMPassword", &val);
-}
-
-
-static struct ldb_message_element *generate_primaryGroupID(struct ldb_module *module, TALLOC_CTX *ctx, const char *attr, const struct ldb_message *remote)
+/* From a sambaPrimaryGroupSID, generate a primaryGroupID (integer) attribute */
+static struct ldb_message_element *generate_primaryGroupID(struct ldb_module *module, TALLOC_CTX *ctx, const char *local_attr, const struct ldb_message *remote)
 {
        struct ldb_message_element *el;
-       const char *sid = ldb_msg_find_string(remote, attr, NULL);
-
+       const char *sid = ldb_msg_find_attr_as_string(remote, "sambaPrimaryGroupSID", NULL);
+       const char *p;
+       
        if (!sid)
                return NULL;
 
-       if (strchr(sid, '-') == NULL)
+       p = strrchr(sid, '-');
+       if (!p)
                return NULL;
 
        el = talloc_zero(ctx, struct ldb_message_element);
        el->name = talloc_strdup(ctx, "primaryGroupID");
        el->num_values = 1;
        el->values = talloc_array(ctx, struct ldb_val, 1);
-       el->values[0].data = (uint8_t *)talloc_strdup(ctx, strchr(sid, '-')+1);
+       el->values[0].data = (uint8_t *)talloc_strdup(el->values, p+1);
        el->values[0].length = strlen((char *)el->values[0].data);
 
        return el;
@@ -94,19 +81,21 @@ static void generate_sambaPrimaryGroupSID(struct ldb_module *module, const char
        const struct ldb_val *sidval;
        char *sidstring;
        struct dom_sid *sid;
-       NTSTATUS status;
+       enum ndr_err_code ndr_err;
 
+       /* We need the domain, so we get it from the objectSid that we hope is here... */
        sidval = ldb_msg_find_ldb_val(local, "objectSid");
 
-       if (!sidval) 
+       if (!sidval)
                return; /* Sorry, no SID today.. */
 
        sid = talloc(remote_mp, struct dom_sid);
        if (sid == NULL) {
                return;
        }
-       status = ndr_pull_struct_blob(sidval, sid, sid, (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
-       if (!NT_STATUS_IS_OK(status)) {
+
+       ndr_err = ndr_pull_struct_blob(sidval, sid, sid, (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
                talloc_free(sid);
                return;
        }
@@ -118,24 +107,31 @@ static void generate_sambaPrimaryGroupSID(struct ldb_module *module, const char
 
        sidstring = dom_sid_string(remote_mp, sid);
        talloc_free(sid);
-       ldb_msg_add_fmt(remote_mp, "sambaPrimaryGroupSID", "%s-%d", sidstring, ldb_msg_find_uint(local, "primaryGroupID", 0));
+       ldb_msg_add_fmt(remote_mp, "sambaPrimaryGroupSID", "%s-%d", sidstring, ldb_msg_find_attr_as_uint(local, "primaryGroupID", 0));
        talloc_free(sidstring);
 }
 
+/* Just copy the old value. */
 static struct ldb_val convert_uid_samaccount(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
 {
-       return ldb_val_dup(ctx, val);
+       struct ldb_val out = data_blob(NULL, 0);
+       out = ldb_val_dup(ctx, val);
+
+       return out;
 }
 
 static struct ldb_val lookup_homedir(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
 {
+       struct ldb_context *ldb;
        struct passwd *pwd; 
        struct ldb_val retval;
-       
+
+       ldb = ldb_module_get_ctx(module);
+
        pwd = getpwnam((char *)val->data);
 
        if (!pwd) {
-               ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Unable to lookup '%s' in passwd", (char *)val->data);
+               ldb_debug(ldb, LDB_DEBUG_WARNING, "Unable to lookup '%s' in passwd", (char *)val->data);
                return *talloc_zero(ctx, struct ldb_val);
        }
 
@@ -149,7 +145,7 @@ static struct ldb_val lookup_gid(struct ldb_module *module, TALLOC_CTX *ctx, con
 {
        struct passwd *pwd; 
        struct ldb_val retval;
-       
+
        pwd = getpwnam((char *)val->data);
 
        if (!pwd) {
@@ -179,49 +175,84 @@ static struct ldb_val lookup_uid(struct ldb_module *module, TALLOC_CTX *ctx, con
        return retval;
 }
 
+/* Encode a sambaSID to an objectSid. */
 static struct ldb_val encode_sid(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
 {
-       struct dom_sid *sid = dom_sid_parse_talloc(ctx, (char *)val->data);
-       struct ldb_val *out = talloc_zero(ctx, struct ldb_val);
-       NTSTATUS status;
+       struct ldb_val out = data_blob(NULL, 0);
+       struct dom_sid *sid;
+       enum ndr_err_code ndr_err;
 
+       sid = dom_sid_parse_talloc(ctx, (char *)val->data);
        if (sid == NULL) {
-               return *out;
+               return out;
        }
-       status = ndr_push_struct_blob(out, ctx, sid, 
-                                     (ndr_push_flags_fn_t)ndr_push_dom_sid);
+
+       ndr_err = ndr_push_struct_blob(&out, ctx, 
+                                      sid, (ndr_push_flags_fn_t)ndr_push_dom_sid);
        talloc_free(sid);
-       if (!NT_STATUS_IS_OK(status)) {
-               return *out;
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               return out;
        }
 
-       return *out;
+       return out;
 }
 
+/* Decode an objectSid to a sambaSID. */
 static struct ldb_val decode_sid(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
 {
+       struct ldb_val out = data_blob(NULL, 0);
        struct dom_sid *sid;
-       NTSTATUS status;
-       struct ldb_val *out = talloc_zero(ctx, struct ldb_val);
-       
+       enum ndr_err_code ndr_err;
+
        sid = talloc(ctx, struct dom_sid);
        if (sid == NULL) {
-               return *out;
+               return out;
        }
-       status = ndr_pull_struct_blob(val, sid, sid, 
-                                     (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
-       if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(sid);
-               return *out;
+
+       ndr_err = ndr_pull_struct_blob(val, sid, sid,
+                                      (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               goto done;
+       }
+
+       out.data = (uint8_t *)dom_sid_string(ctx, sid);
+       if (out.data == NULL) {
+               goto done;
        }
-       out->data = (uint8_t *)dom_sid_string(ctx, sid);
+       out.length = strlen((const char *)out.data);
+
+done:
        talloc_free(sid);
-       if (out->data == NULL) {
-               return *out;
+       return out;
+}
+
+/* Convert 16 bytes to 32 hex digits. */
+static struct ldb_val bin2hex(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
+{
+       struct ldb_val out;
+       struct samr_Password pwd;
+       if (val->length != sizeof(pwd.hash)) {
+               return data_blob(NULL, 0);
        }
-       out->length = strlen((const char *)out->data);
+       memcpy(pwd.hash, val->data, sizeof(pwd.hash));
+       out = data_blob_string_const(smbpasswd_sethexpwd(ctx, &pwd, 0));
+       if (!out.data) {
+               return data_blob(NULL, 0);
+       }
+       return out;
+}
 
-       return *out;
+/* Convert 32 hex digits to 16 bytes. */
+static struct ldb_val hex2bin(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val)
+{
+       struct ldb_val out;
+       struct samr_Password *pwd;
+       pwd = smbpasswd_gethexpwd(ctx, (const char *)val->data);
+       if (!pwd) {
+               return data_blob(NULL, 0);
+       }
+       out = data_blob_talloc(ctx, pwd->hash, sizeof(pwd->hash));
+       return out;
 }
 
 const struct ldb_map_objectclass samba3_objectclasses[] = {
@@ -239,15 +270,15 @@ const struct ldb_map_objectclass samba3_objectclasses[] = {
                .musts = { "cn", "gidNumber", NULL },
                .mays = { "userPassword", "memberUid", "description", NULL },
        },
-       { 
-               .local_name = "group", 
+       {
+               .local_name = "group",
                .remote_name = "sambaGroupMapping",
                .base_classes = { "top", "posixGroup", NULL },
                .musts = { "gidNumber", "sambaSID", "sambaGroupType", NULL },
                .mays = { "displayName", "description", "sambaSIDList", NULL },
        },
-       { 
-               .local_name = "user", 
+       {
+               .local_name = "user",
                .remote_name = "sambaSAMAccount",
                .base_classes = { "top", "posixAccount", NULL },
                .musts = { "uid", "sambaSID", NULL },
@@ -258,11 +289,11 @@ const struct ldb_map_objectclass samba3_objectclasses[] = {
                        "sambaLogonScript", "sambaProfilePath", "description", "sambaUserWorkstations",
                        "sambaPrimaryGroupSID", "sambaDomainName", "sambaMungedDial",
                        "sambaBadPasswordCount", "sambaBadPasswordTime",
-               "sambaPasswordHistory", "sambaLogonHours", NULL }
-       
+               "sambaPasswordHistory", "sambaLogonHours", NULL }
+
        },
-       { 
-               .local_name = "domain", 
+       {
+               .local_name = "domain",
                .remote_name = "sambaDomain",
                .base_classes = { "top", NULL },
                .musts = { "sambaDomainName", "sambaSID", NULL },
@@ -271,12 +302,12 @@ const struct ldb_map_objectclass samba3_objectclasses[] = {
                { NULL, NULL }
 };
 
-const struct ldb_map_attribute samba3_attributes[] = 
+const struct ldb_map_attribute samba3_attributes[] =
 {
        /* sambaNextRid -> nextRid */
        {
                .local_name = "nextRid",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                .remote_name = "sambaNextRid",
@@ -287,7 +318,7 @@ const struct ldb_map_attribute samba3_attributes[] =
        /* sambaBadPasswordTime -> badPasswordtime*/
        {
                .local_name = "badPasswordTime",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                .remote_name = "sambaBadPasswordTime",
@@ -297,11 +328,13 @@ const struct ldb_map_attribute samba3_attributes[] =
 
        /* sambaLMPassword -> lmPwdHash*/
        {
-               .local_name = "lmPwdHash",
-               .type = MAP_RENAME,
+               .local_name = "dBCSPwd",
+               .type = LDB_MAP_CONVERT,
                .u = {
-                       .rename = {
+                       .convert = {
                                .remote_name = "sambaLMPassword",
+                               .convert_local = bin2hex,
+                               .convert_remote = hex2bin,
                        },
                },
        },
@@ -309,7 +342,7 @@ const struct ldb_map_attribute samba3_attributes[] =
        /* sambaGroupType -> groupType */
        {
                .local_name = "groupType",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                .remote_name = "sambaGroupType",
@@ -319,11 +352,13 @@ const struct ldb_map_attribute samba3_attributes[] =
 
        /* sambaNTPassword -> ntPwdHash*/
        {
-               .local_name = "ntPwdHash",
-               .type = MAP_RENAME,
+               .local_name = "ntpwdhash",
+               .type = LDB_MAP_CONVERT,
                .u = {
-                       .rename = {
+                       .convert = {
                                .remote_name = "sambaNTPassword",
+                               .convert_local = bin2hex,
+                               .convert_remote = hex2bin,
                        },
                },
        },
@@ -331,12 +366,12 @@ const struct ldb_map_attribute samba3_attributes[] =
        /* sambaPrimaryGroupSID -> primaryGroupID */
        {
                .local_name = "primaryGroupID",
-               .type = MAP_GENERATE,
+               .type = LDB_MAP_GENERATE,
                .u = {
                        .generate = {
                                .remote_names = { "sambaPrimaryGroupSID", NULL },
                                .generate_local = generate_primaryGroupID,
-                               .generate_remote = generate_sambaPrimaryGroupSID, 
+                               .generate_remote = generate_sambaPrimaryGroupSID,
                        },
                },
        },
@@ -344,7 +379,7 @@ const struct ldb_map_attribute samba3_attributes[] =
        /* sambaBadPasswordCount -> badPwdCount */
        {
                .local_name = "badPwdCount",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                .remote_name = "sambaBadPasswordCount",
@@ -355,7 +390,7 @@ const struct ldb_map_attribute samba3_attributes[] =
        /* sambaLogonTime -> lastLogon*/
        {
                .local_name = "lastLogon",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                .remote_name = "sambaLogonTime",
@@ -366,7 +401,7 @@ const struct ldb_map_attribute samba3_attributes[] =
        /* sambaLogoffTime -> lastLogoff*/
        {
                .local_name = "lastLogoff",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                .remote_name = "sambaLogoffTime",
@@ -377,7 +412,7 @@ const struct ldb_map_attribute samba3_attributes[] =
        /* uid -> unixName */
        {
                .local_name = "unixName",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                .remote_name = "uid",
@@ -388,7 +423,7 @@ const struct ldb_map_attribute samba3_attributes[] =
        /* displayName -> name */
        {
                .local_name = "name",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                .remote_name = "displayName",
@@ -399,13 +434,13 @@ const struct ldb_map_attribute samba3_attributes[] =
        /* cn */
        {
                .local_name = "cn",
-               .type = MAP_KEEP,
+               .type = LDB_MAP_KEEP,
        },
 
        /* sAMAccountName -> cn */
        {
                .local_name = "sAMAccountName",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                .remote_name = "uid",
@@ -417,120 +452,120 @@ const struct ldb_map_attribute samba3_attributes[] =
        /* objectCategory */
        {
                .local_name = "objectCategory",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* objectGUID */
        {
                .local_name = "objectGUID",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* objectVersion */
        {
                .local_name = "objectVersion",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* codePage */
-       { 
+       {
                .local_name = "codePage",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* dNSHostName */
        {
                .local_name = "dNSHostName",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
 
        /* dnsDomain */
        {
                .local_name = "dnsDomain",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* dnsRoot */
        {
                .local_name = "dnsRoot",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* countryCode */
        {
                .local_name = "countryCode",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* nTMixedDomain */
-       { 
+       {
                .local_name = "nTMixedDomain",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* operatingSystem */
-       { 
+       {
                .local_name = "operatingSystem",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* operatingSystemVersion */
        {
                .local_name = "operatingSystemVersion",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
 
        /* servicePrincipalName */
        {
                .local_name = "servicePrincipalName",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* msDS-Behavior-Version */
        {
                .local_name = "msDS-Behavior-Version",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* msDS-KeyVersionNumber */
        {
                .local_name = "msDS-KeyVersionNumber",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* msDs-masteredBy */
        {
                .local_name = "msDs-masteredBy",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* ou */
        {
                .local_name = "ou",
-               .type = MAP_KEEP,
+               .type = LDB_MAP_KEEP,
        },
 
        /* dc */
        {
                .local_name = "dc",
-               .type = MAP_KEEP,
+               .type = LDB_MAP_KEEP,
        },
 
        /* description */
        {
                .local_name = "description",
-               .type = MAP_KEEP,
+               .type = LDB_MAP_KEEP,
        },
 
        /* sambaSID -> objectSid*/
        {
                .local_name = "objectSid",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
-                               .remote_name = "sambaSID", 
+                               .remote_name = "sambaSID",
                                .convert_local = decode_sid,
                                .convert_remote = encode_sid,
                        },
@@ -540,306 +575,306 @@ const struct ldb_map_attribute samba3_attributes[] =
        /* sambaPwdLastSet -> pwdLastSet */
        {
                .local_name = "pwdLastSet",
-               .type = MAP_RENAME,
+               .type = LDB_MAP_RENAME,
                .u = {
                        .rename = {
                                .remote_name = "sambaPwdLastSet",
                        },
                },
-       },      
+       },
 
        /* accountExpires */
        {
-               .local_name = "accountExpires", 
-               .type = MAP_IGNORE,
+               .local_name = "accountExpires",
+               .type = LDB_MAP_IGNORE,
        },
 
        /* adminCount */
        {
                .local_name = "adminCount",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* canonicalName */
        {
                .local_name = "canonicalName",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* createTimestamp */
        {
                .local_name = "createTimestamp",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
-       
+
        /* creationTime */
        {
                .local_name = "creationTime",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
-       
+
        /* dMDLocation */
        {
                .local_name = "dMDLocation",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
-       
+
        /* fSMORoleOwner */
        {
                .local_name = "fSMORoleOwner",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
-       
+
        /* forceLogoff */
        {
                .local_name = "forceLogoff",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
-       
+
        /* instanceType */
        {
                .local_name = "instanceType",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
-       
+
        /* invocationId */
        {
                .local_name = "invocationId",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
-       
+
        /* isCriticalSystemObject */
        {
                .local_name = "isCriticalSystemObject",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
-       
+
        /* localPolicyFlags */
        {
                .local_name = "localPolicyFlags",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
-       
+
        /* lockOutObservationWindow */
        {
                .local_name = "lockOutObservationWindow",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* lockoutDuration */
        {
                .local_name = "lockoutDuration",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* lockoutThreshold */
        {
                .local_name = "lockoutThreshold",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* logonCount */
        {
                .local_name = "logonCount",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* masteredBy */
        {
                .local_name = "masteredBy",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* maxPwdAge */
        {
                .local_name = "maxPwdAge",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* member */
        {
                .local_name = "member",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* memberOf */
        {
                .local_name = "memberOf",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* minPwdAge */
        {
                .local_name = "minPwdAge",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* minPwdLength */
        {
                .local_name = "minPwdLength",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* modifiedCount */
        {
                .local_name = "modifiedCount",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* modifiedCountAtLastProm */
        {
                .local_name = "modifiedCountAtLastProm",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* modifyTimestamp */
        {
                .local_name = "modifyTimestamp",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* nCName */
        {
                .local_name = "nCName",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* nETBIOSName */
        {
                .local_name = "nETBIOSName",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* oEMInformation */
        {
                .local_name = "oEMInformation",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* privilege */
        {
                .local_name = "privilege",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* pwdHistoryLength */
        {
                .local_name = "pwdHistoryLength",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* pwdProperties */
        {
                .local_name = "pwdProperties",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* rIDAvailablePool */
        {
                .local_name = "rIDAvailablePool",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* revision */
        {
                .local_name = "revision",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* ridManagerReference */
        {
                .local_name = "ridManagerReference",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* sAMAccountType */
        {
                .local_name = "sAMAccountType",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* sPNMappings */
        {
                .local_name = "sPNMappings",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* serverReference */
        {
                .local_name = "serverReference",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* serverState */
        {
                .local_name = "serverState",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* showInAdvancedViewOnly */
        {
                .local_name = "showInAdvancedViewOnly",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* subRefs */
        {
                .local_name = "subRefs",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* systemFlags */
        {
                .local_name = "systemFlags",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* uASCompat */
        {
                .local_name = "uASCompat",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* uSNChanged */
        {
                .local_name = "uSNChanged",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* uSNCreated */
        {
                .local_name = "uSNCreated",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
-       /* sambaPassword */
+       /* userPassword */
        {
-               .local_name = "sambaPassword",
-               .type = MAP_IGNORE,
+               .local_name = "userPassword",
+               .type = LDB_MAP_IGNORE,
        },
 
        /* userAccountControl */
        {
                .local_name = "userAccountControl",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* whenChanged */
        {
                .local_name = "whenChanged",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* whenCreated */
        {
                .local_name = "whenCreated",
-               .type = MAP_IGNORE,
+               .type = LDB_MAP_IGNORE,
        },
 
        /* uidNumber */
        {
                .local_name = "unixName",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                .remote_name = "uidNumber",
@@ -852,7 +887,7 @@ const struct ldb_map_attribute samba3_attributes[] =
         * groups and accounts? */
        {
                .local_name = "unixName",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                .remote_name = "gidNumber",
@@ -864,7 +899,7 @@ const struct ldb_map_attribute samba3_attributes[] =
        /* homeDirectory */
        {
                .local_name = "unixName",
-               .type = MAP_CONVERT,
+               .type = LDB_MAP_CONVERT,
                .u = {
                        .convert = {
                                .remote_name = "homeDirectory",
@@ -877,8 +912,20 @@ const struct ldb_map_attribute samba3_attributes[] =
        }
 };
 
-       /* the init function */
-struct ldb_module *ldb_samba3sam_module_init(struct ldb_context *ldb, const char *options[])
+/* the context init function */
+static int samba3sam_init(struct ldb_module *module)
 {
-       return ldb_map_init(ldb, samba3_attributes, samba3_objectclasses, "samba3sam");
+       int ret;
+
+       ret = ldb_map_init(module, samba3_attributes, samba3_objectclasses, NULL, NULL, "samba3sam");
+       if (ret != LDB_SUCCESS)
+               return ret;
+
+       return ldb_next_init(module);
 }
+
+_PUBLIC_ const struct ldb_module_ops ldb_samba3sam_module_ops = {
+       LDB_MAP_OPS
+       .name              = "samba3sam",
+       .init_context      = samba3sam_init,
+};