r9689: valgrind-clean now. Editing works now mostly, you just lose half of your
[sfrench/samba-autobuild/.git] / source4 / lib / ldb / samba / samba3sam.c
index 6c98ffc5c18cf910bb62cdac73d974e32fe77933..23f794d90bab39bfe280bb509ca13964212d5bd3 100644 (file)
  * sambaMungedDial
  * sambaLogonHours */
 
+static struct ldb_message_element *convert_sid_rid(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
+{
+       struct ldb_message_element *ret = talloc(ctx, struct ldb_message_element);
+       int i;
+
+       printf("Converting SID TO RID *\n");
+
+       ret->flags = el->flags;
+       ret->name = talloc_strdup(ret, remote_attr);
+       ret->num_values = el->num_values;
+       ret->values = talloc_array(ret, struct ldb_val, ret->num_values);
+
+       for (i = 0; i < ret->num_values; i++) {
+               ret->values[i] = ldb_val_dup(ret->values, &el->values[i]);
+       }
+
+       return ret;
+}
+
+static struct ldb_message_element *convert_rid_sid(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
+{
+       struct ldb_message_element *ret = talloc(ctx, struct ldb_message_element);
+       int i;
+
+       printf("Converting RID TO SID *\n");
+
+       ret->flags = el->flags;
+       ret->name = talloc_strdup(ret, remote_attr);
+       ret->num_values = el->num_values;
+       ret->values = talloc_array(ret, struct ldb_val, ret->num_values);
+
+       for (i = 0; i < ret->num_values; i++) {
+               ret->values[i] = ldb_val_dup(ret->values, &el->values[i]);
+       }
+
+       return ret;
+}
 
+static struct ldb_message_element *convert_unix_id2name(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
+{
+       int i;
+       struct ldb_message_element *ret = talloc(ctx, struct ldb_message_element);
+
+       printf("Converting UNIX ID to name\n");
+
+       ret->flags = el->flags;
+       ret->name = talloc_strdup(ret, remote_attr);
+       ret->num_values = el->num_values;
+       ret->values = talloc_array(ret, struct ldb_val, ret->num_values);
+
+       for (i = 0; i < ret->num_values; i++) {
+               ret->values[i] = ldb_val_dup(ret->values, &el->values[i]);
+       }
+
+       return ret;
+}
+
+static struct ldb_message_element *convert_unix_name2id(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
+{
+       struct ldb_message_element *ret = talloc(ctx, struct ldb_message_element);
+       int i;
+
+       printf("Converting UNIX name to ID\n");
+
+       ret->flags = el->flags;
+       ret->name = talloc_strdup(ret, remote_attr);
+       ret->num_values = el->num_values;
+       ret->values = talloc_array(ret, struct ldb_val, ret->num_values);
+
+       for (i = 0; i < ret->num_values; i++) {
+               ret->values[i] = ldb_val_dup(ret->values, &el->values[i]);
+       }
+
+       return ret;
+}
 
 const struct ldb_map_objectclass samba3_objectclasses[] = {
        { "group", "sambaGroupMapping" },
@@ -110,8 +184,8 @@ const struct ldb_map_attribute samba3_attributes[] =
                .local_name = "primaryGroupID",
                .type = MAP_CONVERT,
                .u.convert.remote_name = "sambaPrimaryGroupSID",
-               .u.convert.convert_local = NULL, /* FIXME: Add domain SID */
-               .u.convert.convert_remote = NULL, /* FIXME: Extract RID */
+               .u.convert.convert_local = convert_rid_sid,
+               .u.convert.convert_remote = convert_sid_rid, 
        },
 
        /* sambaBadPasswordCount -> badPwdCount */
@@ -140,8 +214,8 @@ const struct ldb_map_attribute samba3_attributes[] =
                .local_name = "unixName",
                .type = MAP_CONVERT,
                .u.convert.remote_name = "gidNumber",
-               .u.convert.convert_local = NULL, /* FIXME: Lookup gid */
-               .u.convert.convert_remote = NULL, /* FIXME: Lookup groupname */
+               .u.convert.convert_local = convert_unix_id2name,
+               .u.convert.convert_remote = convert_unix_name2id, 
        },
 
        /* uid -> unixName */
@@ -149,8 +223,8 @@ const struct ldb_map_attribute samba3_attributes[] =
                .local_name = "unixName",
                .type = MAP_CONVERT,
                .u.convert.remote_name = "uid",
-               .u.convert.convert_local = NULL, /* FIXME: Lookup uid */
-               .u.convert.convert_remote = NULL, /* FIXME: Lookup username */
+               .u.convert.convert_local = convert_unix_id2name,
+               .u.convert.convert_remote = convert_unix_name2id,
        },
 
        /* displayName -> name */
@@ -194,5 +268,5 @@ struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
 struct ldb_module *ldb_samba3sam_module_init(struct ldb_context *ldb, const char *options[])
 #endif
 {
-       return ldb_map_init(ldb, &samba3_attributes, &samba3_objectclasses, options);
+       return ldb_map_init(ldb, samba3_attributes, samba3_objectclasses, options);
 }