diff options
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/ldb/ldb_map/ldb_map.c | 18 | ||||
-rw-r--r-- | source4/lib/ldb/samba/samba3sam.c | 8 | ||||
-rwxr-xr-x | source4/lib/ldb/tests/test-samba3sam.sh | 32 |
3 files changed, 47 insertions, 11 deletions
diff --git a/source4/lib/ldb/ldb_map/ldb_map.c b/source4/lib/ldb/ldb_map/ldb_map.c index d2eea49877..d2bbea7c7a 100644 --- a/source4/lib/ldb/ldb_map/ldb_map.c +++ b/source4/lib/ldb/ldb_map/ldb_map.c @@ -120,8 +120,9 @@ static struct ldb_parse_tree *ldb_map_parse_tree(struct ldb_module *module, TALL attr = map_find_attr_local(module, tree->u.equality.attr); - if (!attr) { + if (!attr || attr->type == MAP_KEEP) { DEBUG(0, ("Unable to find local attribute '%s', leaving as is\n", tree->u.equality.attr)); + new_tree->u.equality.attr = talloc_strdup(new_tree, tree->u.equality.attr); return new_tree; } @@ -387,6 +388,7 @@ static const char **available_local_attributes(struct ldb_module *module, const return ret; } +/* Used for search */ static struct ldb_message *ldb_map_message_incoming(struct ldb_module *module, const char * const*attrs, const struct ldb_message *mi) { int i; @@ -418,6 +420,7 @@ static struct ldb_message *ldb_map_message_incoming(struct ldb_module *module, c case MAP_IGNORE:break; case MAP_RENAME: oldelm = ldb_msg_find_element(mi, attr->u.rename.remote_name); + if (!oldelm) continue; elm = talloc(msg, struct ldb_message_element); elm->name = talloc_strdup(elm, attr->local_name); @@ -429,14 +432,18 @@ static struct ldb_message *ldb_map_message_incoming(struct ldb_module *module, c case MAP_CONVERT: oldelm = ldb_msg_find_element(mi, attr->u.rename.remote_name); - elm = attr->u.convert.convert_local(msg, attr->local_name, oldelm); + if (!oldelm) continue; + + elm = attr->u.convert.convert_remote(msg, attr->local_name, oldelm); + if (!elm) continue; ldb_msg_add(module->ldb, msg, elm, elm->flags); break; case MAP_KEEP: oldelm = ldb_msg_find_element(mi, attr->local_name); - + if (!oldelm) continue; + elm = talloc(msg, struct ldb_message_element); elm->num_values = oldelm->num_values; @@ -448,6 +455,8 @@ static struct ldb_message *ldb_map_message_incoming(struct ldb_module *module, c case MAP_GENERATE: elm = attr->u.generate.generate_local(msg, attr->local_name, mi); + if (!elm) continue; + ldb_msg_add(module->ldb, msg, elm, elm->flags); break; default: @@ -461,6 +470,7 @@ static struct ldb_message *ldb_map_message_incoming(struct ldb_module *module, c return msg; } +/* Used for add, modify */ static struct ldb_message *ldb_map_message_outgoing(struct ldb_module *module, const struct ldb_message *mo) { struct ldb_message *msg = talloc_zero(module, struct ldb_message); @@ -493,7 +503,7 @@ static struct ldb_message *ldb_map_message_outgoing(struct ldb_module *module, c break; case MAP_CONVERT: - elm = attr->u.convert.convert_remote(msg, attr->local_name, &mo->elements[i]); + elm = attr->u.convert.convert_local(msg, attr->u.convert.remote_name, &mo->elements[i]); ldb_msg_add(module->ldb, msg, elm, elm->flags); break; diff --git a/source4/lib/ldb/samba/samba3sam.c b/source4/lib/ldb/samba/samba3sam.c index 23f794d90b..c1ac691e92 100644 --- a/source4/lib/ldb/samba/samba3sam.c +++ b/source4/lib/ldb/samba/samba3sam.c @@ -214,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 = convert_unix_id2name, - .u.convert.convert_remote = convert_unix_name2id, + .u.convert.convert_local = convert_unix_name2id, + .u.convert.convert_remote = convert_unix_id2name, }, /* uid -> unixName */ @@ -223,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 = convert_unix_id2name, - .u.convert.convert_remote = convert_unix_name2id, + .u.convert.convert_local = convert_unix_name2id, + .u.convert.convert_remote = convert_unix_id2name, }, /* displayName -> name */ diff --git a/source4/lib/ldb/tests/test-samba3sam.sh b/source4/lib/ldb/tests/test-samba3sam.sh index 60d429e3b1..73610a2be2 100755 --- a/source4/lib/ldb/tests/test-samba3sam.sh +++ b/source4/lib/ldb/tests/test-samba3sam.sh @@ -2,7 +2,33 @@ rm -f samba3.ldb -$VALGRIND ldbadd -H tdb://samba3.ldb < samba3.ldif +echo "Adding samba3 LDIF..." +$VALGRIND ldbadd -H tdb://samba3.ldb < samba3.ldif || exit 1 + +LOC="-H tdb://samba3.ldb" +OPT="-o modules:samba3sam $LOC" + +echo "Looking up by non-mapped attribute" +$VALGRIND ldbsearch $OPT "(cn=Administrator)" || exit 1 + +echo "Looking up by mapped attribute" +$VALGRIND ldbsearch $OPT "(name=Backup Operators)" || exit 1 + +echo "Looking up by old name of renamed attribute" +$VALGRIND ldbsearch $OPT "(displayName=Backup Operators)" || exit 1 + +echo "Adding a record" +$VALGRIND ldbadd $OPT <<EOF +dn: cn=Foo,dc=idealx,dc=org +unixName: root +lastLogon: 20000 +cn: Foo + +EOF + +echo "Checking for existance of record (mapped)" +$VALGRIND ldbsearch $OPT "(cn=Foo)" unixName lastLogon cn || exit 1 + +echo "Checking for existance of record (non-mapped)" +$VALGRIND ldbsearch $LOC "(cn=Foo)" uid sambaLogonTime cn || exit 1 -OPT="-o modules:samba3sam -H tdb://samba3.ldb " -$VALGRIND ldbsearch $OPT "(cn=Administrator)" |