Author: jelmer
Date: 2005-08-27 19:46:28 +0000 (Sat, 27 Aug 2005)
New Revision: 9690

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9690

Log:
Extend test + fix several bugs

Modified:
   branches/SAMBA_4_0/source/lib/ldb/ldb_map/ldb_map.c
   branches/SAMBA_4_0/source/lib/ldb/samba/samba3sam.c
   branches/SAMBA_4_0/source/lib/ldb/tests/test-samba3sam.sh


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 18:30:00 UTC 
(rev 9689)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_map/ldb_map.c 2005-08-27 19:46:28 UTC 
(rev 9690)
@@ -120,8 +120,9 @@
 
        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 @@
        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 @@
                        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 @@
                                
                        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 @@
 
                        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 @@
        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 @@
                        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;
 

Modified: branches/SAMBA_4_0/source/lib/ldb/samba/samba3sam.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/samba/samba3sam.c 2005-08-27 18:30:00 UTC 
(rev 9689)
+++ branches/SAMBA_4_0/source/lib/ldb/samba/samba3sam.c 2005-08-27 19:46:28 UTC 
(rev 9690)
@@ -214,8 +214,8 @@
                .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 @@
                .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 */

Modified: branches/SAMBA_4_0/source/lib/ldb/tests/test-samba3sam.sh
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/tests/test-samba3sam.sh   2005-08-27 
18:30:00 UTC (rev 9689)
+++ branches/SAMBA_4_0/source/lib/ldb/tests/test-samba3sam.sh   2005-08-27 
19:46:28 UTC (rev 9690)
@@ -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
 
-OPT="-o modules:samba3sam -H tdb://samba3.ldb "
-$VALGRIND ldbsearch $OPT "(cn=Administrator)"
+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
+

Reply via email to