svn commit: samba r9686 - in branches/SAMBA_4_0/source/lib/ldb:
ldb_map samba
jelmer at samba.org
jelmer at samba.org
Sat Aug 27 16:33:43 GMT 2005
Author: jelmer
Date: 2005-08-27 16:33:42 +0000 (Sat, 27 Aug 2005)
New Revision: 9686
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9686
Log:
Another round of bugfixes. Works somewhat now, when running under valgrind ;-)
Modified:
branches/SAMBA_4_0/source/lib/ldb/ldb_map/ldb_map.c
branches/SAMBA_4_0/source/lib/ldb/samba/samba3sam.c
Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_map/ldb_map.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_map/ldb_map.c 2005-08-27 15:13:15 UTC (rev 9685)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_map/ldb_map.c 2005-08-27 16:33:42 UTC (rev 9686)
@@ -73,8 +73,13 @@
{
int i;
const struct ldb_map_attribute *attr;
- struct ldb_parse_tree *new_tree = talloc_memdup(module, tree, sizeof(*tree));
+ struct ldb_parse_tree *new_tree;
+ if (tree == NULL)
+ return NULL;
+
+ new_tree = talloc_memdup(module, tree, sizeof(*tree));
+
/* Find attr in question and:
* - if it has a convert_operator function, run that
* - otherwise, replace attr name with required[0] */
@@ -102,7 +107,7 @@
attr = map_find_attr_local(module, tree->u.equality.attr);
if (!attr) {
- DEBUG(0, ("Unable to find local attribute '%s', leaving as is", tree->u.equality.attr));
+ DEBUG(0, ("Unable to find local attribute '%s', leaving as is\n", tree->u.equality.attr));
return new_tree;
}
@@ -323,22 +328,77 @@
return NULL;
}
+static const char **available_local_attributes(struct ldb_module *module, const struct ldb_message *msg)
+{
+ struct map_private *map = module->private_data;
+ int i, j;
+ int count = 0;
+ const char **ret = talloc_array(module, const char *, 1);
+
+ ret[0] = NULL;
+
+ for (i = 0; map->attribute_maps[i].local_name; i++) {
+ BOOL avail = False;
+ const struct ldb_map_attribute *attr = &map->attribute_maps[i];
+
+ /* If all remote attributes for this attribute are present, add the
+ * local one to the list */
+
+ switch (attr->type) {
+ case MAP_IGNORE: break;
+ case MAP_KEEP:
+ avail = (ldb_msg_find_ldb_val(msg, attr->local_name) != NULL);
+ break;
+
+ case MAP_RENAME:
+ case MAP_CONVERT:
+ avail = (ldb_msg_find_ldb_val(msg, attr->u.rename.remote_name) != NULL);
+ break;
+
+ case MAP_GENERATE:
+ avail = True;
+ for (j = 0; attr->u.generate.remote_names[j]; j++) {
+ avail &= (ldb_msg_find_ldb_val(msg, attr->u.generate.remote_names[j]) != NULL);
+ }
+ break;
+ }
+
+ if (!avail)
+ continue;
+
+ ret = talloc_realloc(module, ret, const char *, count+2);
+ ret[count] = attr->local_name;
+ ret[count+1] = NULL;
+ count++;
+ }
+
+ return ret;
+}
+
static struct ldb_message *ldb_map_message_incoming(struct ldb_module *module, const char * const*attrs, const struct ldb_message *mi)
{
int i;
struct ldb_message *msg = talloc_zero(module, struct ldb_message);
struct ldb_message_element *elm, *oldelm;
+ const char **newattrs = NULL;
msg->dn = map_remote_dn(module, mi->dn);
/* Loop over attrs, find in ldb_map_attribute array and
* run generate() */
+ if (attrs == NULL) {
+ /* Generate list of the local attributes that /can/ be generated
+ * using the specific remote attributes */
+
+ attrs = newattrs = available_local_attributes(module, mi);
+ }
+
for (i = 0; attrs[i]; i++) {
const struct ldb_map_attribute *attr = map_find_attr_local(module, attrs[i]);
if (!attr) {
- DEBUG(0, ("Unable to find local attribute '%s' when generating incoming message", attrs[i]));
+ DEBUG(0, ("Unable to find local attribute '%s' when generating incoming message\n", attrs[i]));
continue;
}
@@ -373,6 +433,8 @@
}
}
+ talloc_free(newattrs);
+
return msg;
}
@@ -482,8 +544,10 @@
talloc_free(new_tree);
talloc_free(newattrs);
+ *res = talloc_array(module, struct ldb_message *, ret);
+
for (i = 0; i < ret; i++) {
- *res[i] = ldb_map_message_incoming(module, attrs, newres[i]);
+ (*res)[i] = ldb_map_message_incoming(module, attrs, newres[i]);
talloc_free(newres[i]);
}
@@ -500,7 +564,7 @@
struct ldb_parse_tree *tree;
int ret;
- tree = ldb_parse_tree(map, expression);
+ tree = ldb_parse_tree(NULL, expression);
if (tree == NULL) {
map->last_err_string = "expression parse failed";
return -1;
Modified: branches/SAMBA_4_0/source/lib/ldb/samba/samba3sam.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/samba/samba3sam.c 2005-08-27 15:13:15 UTC (rev 9685)
+++ branches/SAMBA_4_0/source/lib/ldb/samba/samba3sam.c 2005-08-27 16:33:42 UTC (rev 9686)
@@ -60,8 +60,34 @@
* sambaMungedDial
* sambaLogonHours */
+static struct ldb_message_element *convert_sid_rid(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
+{
+ printf("Converting SID TO RID *\n");
+ return talloc_memdup(ctx, el, sizeof(*el));
+}
+static struct ldb_message_element *convert_rid_sid(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
+{
+ printf("Converting RID TO SID *\n");
+
+ return talloc_memdup(ctx, el, sizeof(*el));
+}
+
+static struct ldb_message_element *convert_unix_id2name(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
+{
+ printf("Converting UNIX ID to name\n");
+
+ return talloc_memdup(ctx, el, sizeof(*el));
+}
+
+static struct ldb_message_element *convert_unix_name2id(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
+{
+ printf("Converting UNIX name to ID\n");
+
+ return talloc_memdup(ctx, el, sizeof(*el));
+}
+
const struct ldb_map_objectclass samba3_objectclasses[] = {
{ "group", "sambaGroupMapping" },
{ "user", "sambaSAMAccount" },
@@ -110,8 +136,8 @@
.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 +166,8 @@
.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 +175,8 @@
.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 +220,5 @@
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);
}
More information about the samba-cvs
mailing list