r9690: Extend test + fix several bugs
authorJelmer Vernooij <jelmer@samba.org>
Sat, 27 Aug 2005 19:46:28 +0000 (19:46 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:34:41 +0000 (13:34 -0500)
source/lib/ldb/ldb_map/ldb_map.c
source/lib/ldb/samba/samba3sam.c
source/lib/ldb/tests/test-samba3sam.sh

index d2eea498775226f5a3e6cfa6825da6172994bb38..d2bbea7c7ade5c68d655b93ddbc391b214615763 100644 (file)
@@ -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;
 
index 23f794d90bab39bfe280bb509ca13964212d5bd3..c1ac691e92c9174cd0ce1149e66f688d6c49e041 100644 (file)
@@ -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 */
index 60d429e3b12987d2a45453305466a7c021ecaf5b..73610a2be2261639854e456324213544349f9e61 100755 (executable)
@@ -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)"