]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldap/config.c
fix rewrite iteration
[openldap] / servers / slapd / back-ldap / config.c
index 54b49155b611b19f400ff26ac2b7cd2a24deb4d2..8f041a117e327b2db716d12c01a5315877f2898b 100644 (file)
@@ -220,8 +220,9 @@ ldap_back_db_config(
                } else if ( strcasecmp( argv[1], "attribute" ) == 0 ) {
                        map = &li->at_map;
                } else {
-                       fprintf( stderr,
-       "%s: line %d: syntax is \"map {objectclass | attribute} {<source> | *} [<dest> | *]\"\n",
+                       fprintf( stderr, "%s: line %d: syntax is "
+                               "\"map {objectclass | attribute} {<source> | *} "
+                                       "[<dest> | *]\"\n",
                                fname, lineno );
                        return( 1 );
                }
@@ -257,7 +258,8 @@ ldap_back_db_config(
                                fname, lineno );
                }
 
-               mapping = (struct ldapmapping *)ch_calloc( 2, sizeof(struct ldapmapping) );
+               mapping = (struct ldapmapping *)ch_calloc( 2,
+                       sizeof(struct ldapmapping) );
                if ( mapping == NULL ) {
                        fprintf( stderr,
                                "%s: line %d: out of memory\n",
@@ -274,8 +276,8 @@ ldap_back_db_config(
                        mapping[1].dst = mapping->dst;
                }
 
-               if ( avl_find( map->map, (caddr_t)mapping, mapping_cmp ) != NULL
-                       || avl_find( map->remap, (caddr_t)&mapping[1], mapping_cmp ) != NULL)
+               if ( avl_find( map->map, (caddr_t)mapping, mapping_cmp ) != NULL ||
+                       avl_find( map->remap, (caddr_t)&mapping[1], mapping_cmp ) != NULL)
                {
                        fprintf( stderr,
                                "%s: line %d: duplicate mapping found (ignored)\n",
@@ -290,8 +292,8 @@ ldap_back_db_config(
 
        /* anything else */
        } else {
-               fprintf( stderr,
-"%s: line %d: unknown directive \"%s\" in ldap database definition (ignored)\n",
+               fprintf( stderr, "%s: line %d: unknown directive \"%s\" "
+                       "in ldap database definition (ignored)\n",
                    fname, lineno, argv[0] );
        }
        return 0;
@@ -316,6 +318,33 @@ mapping_dup ( void *c1, void *c2 )
        return( ( strcasecmp(map1->src.bv_val, map2->src.bv_val) == 0 ) ? -1 : 0 );
 }
 
+void
+ldap_back_map_init ( struct ldapmap *lm, struct ldapmapping **m )
+{
+       struct ldapmapping *mapping;
+
+       assert( m );
+
+       *m = NULL;
+       
+       mapping = (struct ldapmapping *)ch_calloc( 2, 
+                       sizeof( struct ldapmapping ) );
+       if ( mapping == NULL ) {
+               return;
+       }
+
+       ber_str2bv( "objectclass", sizeof("objectclass")-1, 1, &mapping->src);
+       ber_dupbv( &mapping->dst, &mapping->src );
+       mapping[1].src = mapping->src;
+       mapping[1].dst = mapping->dst;
+
+       avl_insert( &lm->map, (caddr_t)mapping, 
+                       mapping_cmp, mapping_dup );
+       avl_insert( &lm->remap, (caddr_t)&mapping[1], 
+                       mapping_cmp, mapping_dup );
+       *m = mapping;
+}
+
 void
 ldap_back_map ( struct ldapmap *map, struct berval *s, struct berval *bv,
        int remap )
@@ -378,7 +407,7 @@ ldap_back_map_filter(
                        in_quote = !in_quote;
                        if (q != NULL) {
                                plen = p - q;
-                               memcpy(s, q, plen);
+                               AC_MEMCPY(s, q, plen);
                                s += plen;
                                q = NULL;
                        }
@@ -421,7 +450,7 @@ ldap_back_map_filter(
                                        }
                                        s += (long)nf;
                                }
-                               memcpy(s, m.bv_val, plen);
+                               AC_MEMCPY(s, m.bv_val, plen);
                                s += plen;
                                *p = c;
                                q = NULL;
@@ -436,19 +465,18 @@ ldap_back_map_filter(
 char **
 ldap_back_map_attrs(
                struct ldapmap *at_map,
-               AttributeName *a,
+               AttributeName *an,
                int remap
 )
 {
        int i;
        char **na;
-       AttributeName *an;
        struct berval mapped;
 
-       if (a == NULL)
+       if (an == NULL)
                return(NULL);
 
-       for (i = 0, an=a; an; an=an->an_next, i++) {
+       for (i = 0; an[i].an_name.bv_val; i++) {
                /*  */
        }
 
@@ -456,8 +484,8 @@ ldap_back_map_attrs(
        if (na == NULL)
                return(NULL);
 
-       for (i = 0, an=a; an; an=an->an_next) {
-               ldap_back_map(at_map, &an->an_name, &mapped, remap);
+       for (i = 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++;
@@ -501,12 +529,12 @@ suffix_massage_patternize( const char *s, int normalize )
 {
        char *res;
 
-       res = ch_calloc( sizeof( char ), strlen( s ) + 3 );
+       res = ch_calloc( sizeof( char ), strlen( s ) + sizeof("%1") );
 
        sprintf( res, "%%1%s", s );
 
        if ( normalize ) {
-               char *out = dn_normalize( res + 2 );
+               char *out = dn_normalize( res + (sizeof("%1")-1) );
                if ( out != res + 2 ) {
                        strcpy( res + 2, out );
                        free( out );
@@ -599,4 +627,3 @@ suffix_massage_config(
        return 0;
 }
 #endif /* ENABLE_REWRITE */
-