]> git.sur5r.net Git - openldap/commitdiff
Date: Thu, 2 May 2002 08:54:59 GMT
authorKurt Zeilenga <kurt@openldap.org>
Wed, 12 Jun 2002 16:39:05 +0000 (16:39 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Wed, 12 Jun 2002 16:39:05 +0000 (16:39 +0000)
From: h.b.furuseth@usit.uio.no
To: openldap-its@OpenLDAP.org
Subject: Patch: Bugs with back-ldap/meta mappings

Full_Name: Hallvard B. Furuseth
Version: HEAD
OS: Linux
URL: http://folk.uio.no/hbf/OpenLDAP/back-ldap.txt
Submission from: (NULL) (158.36.148.34)

The source claims the 'map' attribute has syntax
map {objectclass | attribute}   {<source> | *}      [<dest> | *]
while it actually has syntax
map {objectclass | attribute} [<local name> | *] {<foreign name> |
*}
except that the code is confused about it.  Removed attributes are
put in both the maps for local and foreign names:
# Remove description and present title as description instead
map attribute description
map attribute description title
-->
slapd.conf: line 10: duplicate mapping found (ignored)

Also, map.c:ldap_back_map_attrs() loops forever on removed attributes
(ie. if one asks ldapsearch for an attribute which has been removed).

servers/slapd/back-ldap/config.c
servers/slapd/back-ldap/map.c
servers/slapd/back-meta/config.c

index f40fd8273f3aefca0f40785b4397ac9d0364218f..a8e82ad0eacd6c612c246ca2760630c0d1bce8c8 100644 (file)
@@ -232,7 +232,7 @@ ldap_back_db_config(
 
                if ( argc < 3 || argc > 4 ) {
                        fprintf( stderr,
-       "%s: line %d: syntax is \"map {objectclass | attribute} {<source> | *} [<dest> | *]\"\n",
+       "%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
                                fname, lineno );
                        return( 1 );
                }
@@ -243,32 +243,24 @@ ldap_back_db_config(
                        map = &li->at_map;
                } else {
                        fprintf( stderr, "%s: line %d: syntax is "
-                               "\"map {objectclass | attribute} {<source> | *} "
-                                       "[<dest> | *]\"\n",
+                               "\"map {objectclass | attribute} [<local> | *] "
+                               "{<foreign> | *}\"\n",
                                fname, lineno );
                        return( 1 );
                }
 
-               if ( strcasecmp( argv[2], "*" ) != 0 ) {
-                       src = argv[2];
-                       if ( argc < 4 )
-                               dst = "";
-                       else if ( strcasecmp( argv[3], "*" ) == 0 )
-                               dst = src;
-                       else
-                               dst = argv[3];
-               } else {
-                       if ( argc < 4 ) {
-                               map->drop_missing = 1;
+               if ( strcmp( argv[2], "*" ) == 0 ) {
+                       if ( argc < 4 || strcmp( argv[3], "*" ) == 0 ) {
+                               map->drop_missing = ( argc < 4 );
                                return 0;
                        }
-                       if ( strcasecmp( argv[3], "*" ) == 0 ) {
-                               map->drop_missing = 0;
-                               return 0;
-                       }
-
-                       src = argv[3];
-                       dst = src;
+                       src = dst = argv[3];
+               } else if ( argc < 4 ) {
+                       src = "";
+                       dst = argv[2];
+               } else {
+                       src = argv[2];
+                       dst = ( strcmp( argv[3], "*" ) == 0 ? src : argv[3] );
                }
 
                if ( ( map == &li->at_map )
@@ -290,15 +282,11 @@ ldap_back_db_config(
                }
                ber_str2bv( src, 0, 1, &mapping->src );
                ber_str2bv( dst, 0, 1, &mapping->dst );
-               if ( *dst != 0 ) {
-                       mapping[1].src = mapping->dst;
-                       mapping[1].dst = mapping->src;
-               } else {
-                       mapping[1].src = mapping->src;
-                       mapping[1].dst = mapping->dst;
-               }
+               mapping[1].src = mapping->dst;
+               mapping[1].dst = mapping->src;
 
-               if ( avl_find( map->map, (caddr_t)mapping, mapping_cmp ) != NULL ||
+               if ( (*src != '\0' &&
+                         avl_find( map->map, (caddr_t)mapping, mapping_cmp ) != NULL) ||
                        avl_find( map->remap, (caddr_t)&mapping[1], mapping_cmp ) != NULL)
                {
                        fprintf( stderr,
@@ -307,8 +295,9 @@ ldap_back_db_config(
                        return 0;
                }
 
-               avl_insert( &map->map, (caddr_t)mapping,
-                                       mapping_cmp, mapping_dup );
+               if ( *src != '\0' )
+                       avl_insert( &map->map, (caddr_t)mapping,
+                                               mapping_cmp, mapping_dup );
                avl_insert( &map->remap, (caddr_t)&mapping[1],
                                        mapping_cmp, mapping_dup );
 
index a21cf538656bcc575ccddfc4503ece0e997cf82d..7bf1e470a1cd057b603e2a0941a489ea759a9ba1 100644 (file)
@@ -216,7 +216,7 @@ ldap_back_map_attrs(
                int remap
 )
 {
-       int i;
+       int i, j;
        char **na;
        struct berval mapped;
 
@@ -231,14 +231,14 @@ ldap_back_map_attrs(
        if (na == NULL)
                return(NULL);
 
-       for (i = 0; an[i].an_name.bv_val; ) {
+       for (i = j = 0; an[i].an_name.bv_val; i++) {
                ldap_back_map(at_map, &an[i].an_name, &mapped, remap);
-               if (mapped.bv_val != NULL) {
-                       na[i] = mapped.bv_val;
-                       i++;
-               }
+               if (mapped.bv_val != NULL)
+                       na[j++] = mapped.bv_val;
        }
-       na[i] = NULL;
+       if (j == 0 && i != 0)
+               na[j++] = LDAP_NO_ATTRS;
+       na[j] = NULL;
 
        return(na);
 }
index 7b8f7cf6e54039ed4e0f3b2326478438a17e18cc..107ac5cadb9cc1c350fd99aa8f8527c8ec90e573 100644 (file)
@@ -503,7 +503,7 @@ meta_back_db_config(
 
                if ( argc < 3 || argc > 4 ) {
                        fprintf( stderr,
-       "%s: line %d: syntax is \"map {objectclass | attribute} {<source> | *} [<dest> | *]\"\n",
+       "%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
                                fname, lineno );
                        return 1;
                }
@@ -514,32 +514,23 @@ meta_back_db_config(
                        map = &li->targets[ i ]->at_map;
                } else {
                        fprintf( stderr,
-       "%s: line %d: syntax is \"map {objectclass | attribute} {<source> | *} [<dest> | *]\"\n",
+       "%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
                                fname, lineno );
                        return 1;
                }
 
-               if ( strcasecmp( argv[ 2 ], "*" ) != 0 ) {
-                       src = argv[ 2 ];
-                       if ( argc < 4 ) {
-                               dst = "";
-                       } else if ( strcasecmp( argv[ 3 ], "*" ) == 0 ) {
-                               dst = src;
-                       } else {
-                               dst = argv[ 3 ];
-                       }
-               } else {
-                       if ( argc < 4 ) {
-                               map->drop_missing = 1;
-                               return 0;
-                       }
-                       if ( strcasecmp( argv[ 3 ], "*" ) == 0 ) {
-                               map->drop_missing = 0;
+               if ( strcmp( argv[ 2 ], "*" ) == 0 ) {
+                       if ( argc < 4 || strcmp( argv[ 3 ], "*" ) == 0 ) {
+                               map->drop_missing = ( argc < 4 );
                                return 0;
                        }
-
-                       src = argv[ 3 ];
-                       dst = src;
+                       src = dst = argv[ 3 ];
+               } else if ( argc < 4 ) {
+                       src = "";
+                       dst = argv[ 2 ];
+               } else {
+                       src = argv[ 2 ];
+                       dst = ( strcmp( argv[ 3 ], "*" ) == 0 ? src : argv[ 3 ] );
                }
 
                if ( ( map == &li->targets[ i ]->at_map )
@@ -559,16 +550,12 @@ meta_back_db_config(
                }
                ber_str2bv( src, 0, 1, &mapping->src );
                ber_str2bv( dst, 0, 1, &mapping->dst );
-               if ( *dst != 0 ) {
-                       mapping[ 1 ].src = mapping->dst;
-                       mapping[ 1 ].dst = mapping->src;
-               } else {
-                       mapping[ 1 ].src = mapping->src;
-                       mapping[ 1 ].dst = mapping->dst;
-               }
+               mapping[ 1 ].src = mapping->dst;
+               mapping[ 1 ].dst = mapping->src;
 
-               if ( avl_find( map->map, ( caddr_t )mapping,
-                               mapping_cmp ) != NULL
+               if ( (*src != '\0' &&
+                         avl_find( map->map, ( caddr_t )mapping,
+                               mapping_cmp ) != NULL)
                        || avl_find( map->remap, ( caddr_t )&mapping[ 1 ],
                                mapping_cmp ) != NULL) {
                        fprintf( stderr,
@@ -577,8 +564,9 @@ meta_back_db_config(
                        return 0;
                }
 
-               avl_insert( &map->map, ( caddr_t )mapping,
-                                       mapping_cmp, mapping_dup );
+               if ( *src != '\0' )
+                       avl_insert( &map->map, ( caddr_t )mapping,
+                                               mapping_cmp, mapping_dup );
                avl_insert( &map->remap, ( caddr_t )&mapping[ 1 ],
                                        mapping_cmp, mapping_dup );