Patch [UPDATED]: Bugs with back-ldap/meta mappings (ITS#1787) ================ Written by Hallvard B. Furuseth and placed into the public domain. This software is not subject to any license of the University of Oslo. ================ The source claims the 'map' attribute has syntax map {objectclass | attribute} { | *} [ | *] while it actually has syntax map {objectclass | attribute} [ | *] { | *} 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). Hallvard B. Furuseth , May 2002. diff -u1 -r doc/man/man5/slapd-ldap.5~ doc/man/man5/slapd-ldap.5 --- doc/man/man5/slapd-ldap.5~ Tue Apr 30 18:23:10 2002 +++ doc/man/man5/slapd-ldap.5 Wed May 1 07:57:37 2002 @@ -53,3 +53,3 @@ .TP -.B map "{attribute | objectclass} { | *} [ | *]" +.B map "{attribute | objectclass} [ | *] { | *}" Map attribute names and object classes from the foreign server to @@ -60,6 +60,5 @@ If local or foreign name is `*', the name is preserved. -If foreign name is missing, the name is dropped. -Local name `*' and no foreign name means unmapped attributes are -removed, while local name = foreign name = `*' means unmapped -attributes are preserved. +If local name is omitted, the foreign name is removed. +Unmapped names are preseved if both local and foreign name are `*', +and removed if local name is omitted and foreign name is `*'. .TP diff -u1 -r doc/man/man5/slapd-meta.5~ doc/man/man5/slapd-meta.5 --- doc/man/man5/slapd-meta.5~ Tue Apr 30 18:30:53 2002 +++ doc/man/man5/slapd-meta.5 Wed May 1 07:05:15 2002 @@ -171,3 +171,3 @@ .TP -.B map {objectClass|attribute} {|*} [|*] +.B map "{attribute|objectclass} [|*] {|*}" This maps object classes and attributes as in the LDAP backend. diff -u2 -r servers/slapd/back-ldap/config.c~ servers/slapd/back-ldap/config.c --- servers/slapd/back-ldap/config.c~ Thu Apr 25 18:59:52 2002 +++ servers/slapd/back-ldap/config.c Wed May 1 07:24:13 2002 @@ -221,5 +221,5 @@ if ( argc < 3 || argc > 4 ) { fprintf( stderr, - "%s: line %d: syntax is \"map {objectclass | attribute} { | *} [ | *]\"\n", + "%s: line %d: syntax is \"map {objectclass | attribute} [ | *] { | *}\"\n", fname, lineno ); return( 1 ); @@ -232,30 +232,22 @@ } else { fprintf( stderr, "%s: line %d: syntax is " - "\"map {objectclass | attribute} { | *} " - "[ | *]\"\n", + "\"map {objectclass | attribute} [ | *] " + "{ | *}\"\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] ); } @@ -279,13 +271,9 @@ 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) { @@ -296,6 +284,7 @@ } - 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 ); diff -u2 -r servers/slapd/back-ldap/map.c~ servers/slapd/back-ldap/map.c --- servers/slapd/back-ldap/map.c~ Sat Jan 12 17:35:01 2002 +++ servers/slapd/back-ldap/map.c Wed May 1 12:32:06 2002 @@ -217,5 +217,5 @@ ) { - int i; + int i, j; char **na; struct berval mapped; @@ -232,12 +232,12 @@ 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); diff -u2 -r servers/slapd/back-meta/config.c~ servers/slapd/back-meta/config.c --- servers/slapd/back-meta/config.c~ Sat Jan 12 18:17:14 2002 +++ servers/slapd/back-meta/config.c Wed May 1 17:31:07 2002 @@ -503,5 +503,5 @@ if ( argc < 3 || argc > 4 ) { fprintf( stderr, - "%s: line %d: syntax is \"map {objectclass | attribute} { | *} [ | *]\"\n", + "%s: line %d: syntax is \"map {objectclass | attribute} [ | *] { | *}\"\n", fname, lineno ); return 1; @@ -514,30 +514,21 @@ } else { fprintf( stderr, - "%s: line %d: syntax is \"map {objectclass | attribute} { | *} [ | *]\"\n", + "%s: line %d: syntax is \"map {objectclass | attribute} [ | *] { | *}\"\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 ] ); } @@ -559,14 +550,10 @@ 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) { @@ -577,6 +564,7 @@ } - 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 );