From b5e7208cb8006bcccb3785a7d722e79cf2fe8c83 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 12 Jun 2002 16:39:05 +0000 Subject: [PATCH] Date: Thu, 2 May 2002 08:54:59 GMT 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} { | *} [ | *] 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). --- servers/slapd/back-ldap/config.c | 51 ++++++++++++------------------- servers/slapd/back-ldap/map.c | 14 ++++----- servers/slapd/back-meta/config.c | 52 ++++++++++++-------------------- 3 files changed, 47 insertions(+), 70 deletions(-) diff --git a/servers/slapd/back-ldap/config.c b/servers/slapd/back-ldap/config.c index f40fd8273f..a8e82ad0ea 100644 --- a/servers/slapd/back-ldap/config.c +++ b/servers/slapd/back-ldap/config.c @@ -232,7 +232,7 @@ ldap_back_db_config( 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 ); } @@ -243,32 +243,24 @@ ldap_back_db_config( map = &li->at_map; } 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] ); } 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 ); diff --git a/servers/slapd/back-ldap/map.c b/servers/slapd/back-ldap/map.c index a21cf53865..7bf1e470a1 100644 --- a/servers/slapd/back-ldap/map.c +++ b/servers/slapd/back-ldap/map.c @@ -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); } diff --git a/servers/slapd/back-meta/config.c b/servers/slapd/back-meta/config.c index 7b8f7cf6e5..107ac5cadb 100644 --- a/servers/slapd/back-meta/config.c +++ b/servers/slapd/back-meta/config.c @@ -503,7 +503,7 @@ meta_back_db_config( 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,32 +514,23 @@ meta_back_db_config( map = &li->targets[ i ]->at_map; } 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 ] ); } 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 ); -- 2.39.5