]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldap/config.c
Silence a warning about ldap_debug
[openldap] / servers / slapd / back-ldap / config.c
index 8f041a117e327b2db716d12c01a5315877f2898b..30d00755c6edb2c0babd4d1d109c79911e473baf 100644 (file)
@@ -1,7 +1,7 @@
 /* config.c - ldap backend configuration file routine */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 /* This is an altered version */
@@ -146,7 +146,7 @@ ldap_back_db_config(
                        return( 1 );
                }
                tmp_be = select_backend( &ndn, 0, 0 );
-               free( ndn.bv_val );
+               ch_free( ndn.bv_val );
                if ( tmp_be != NULL && tmp_be != be ) {
                        fprintf( stderr, "%s: line %d: suffix already in use"
                                       " by another backend in"
@@ -164,7 +164,7 @@ ldap_back_db_config(
                        return( 1 );
                }
                tmp_be = select_backend( &ndn, 0, 0 );
-               free( ndn.bv_val );
+               ch_free( ndn.bv_val );
                if ( tmp_be != NULL ) {
                        fprintf( stderr, "%s: line %d: massaged suffix"
                                       " already in use by another backend in" 
@@ -299,206 +299,11 @@ ldap_back_db_config(
        return 0;
 }
 
-int
-mapping_cmp ( const void *c1, const void *c2 )
-{
-       struct ldapmapping *map1 = (struct ldapmapping *)c1;
-       struct ldapmapping *map2 = (struct ldapmapping *)c2;
-       int rc = map1->src.bv_len - map2->src.bv_len;
-       if (rc) return rc;
-       return ( strcasecmp(map1->src.bv_val, map2->src.bv_val) );
-}
-
-int
-mapping_dup ( void *c1, void *c2 )
-{
-       struct ldapmapping *map1 = (struct ldapmapping *)c1;
-       struct ldapmapping *map2 = (struct ldapmapping *)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 )
-{
-       Avlnode *tree;
-       struct ldapmapping *mapping, fmapping;
-
-       if (remap)
-               tree = map->remap;
-       else
-               tree = map->map;
-
-       bv->bv_len = 0;
-       bv->bv_val = NULL;
-       fmapping.src = *s;
-       mapping = (struct ldapmapping *)avl_find( tree, (caddr_t)&fmapping, mapping_cmp );
-       if (mapping != NULL) {
-               if ( mapping->dst.bv_val )
-                       *bv = mapping->dst;
-               return;
-       }
-
-       if (!map->drop_missing)
-               *bv = *s;
-
-       return;
-}
-
-char *
-ldap_back_map_filter(
-               struct ldapmap *at_map,
-               struct ldapmap *oc_map,
-               struct berval *f,
-               int remap
-)
-{
-       char *nf, *p, *q, *s, c;
-       int len, extra, plen, in_quote;
-       struct berval m, tmp;
-
-       if (f == NULL)
-               return(NULL);
-
-       len = f->bv_len;
-       extra = len;
-       len *= 2;
-       nf = ch_malloc( len + 1 );
-       if (nf == NULL)
-               return(NULL);
-
-       /* this loop assumes the filter ends with one
-        * of the delimiter chars -- probably ')'.
-        */
-
-       s = nf;
-       q = NULL;
-       in_quote = 0;
-       for (p = f->bv_val; (c = *p); p++) {
-               if (c == '"') {
-                       in_quote = !in_quote;
-                       if (q != NULL) {
-                               plen = p - q;
-                               AC_MEMCPY(s, q, plen);
-                               s += plen;
-                               q = NULL;
-                       }
-                       *s++ = c;
-               } else if (in_quote) {
-                       /* ignore everything in quotes --
-                        * what about attrs in DNs?
-                        */
-                       *s++ = c;
-               } else if (c != '(' && c != ')'
-                       && c != '=' && c != '>' && c != '<'
-                       && c != '|' && c != '&')
-               {
-                       if (q == NULL)
-                               q = p;
-               } else {
-                       if (q != NULL) {
-                               *p = 0;
-                               tmp.bv_len = p - q;
-                               tmp.bv_val = q;
-                               ldap_back_map(at_map, &tmp, &m, remap);
-                               if (m.bv_val == NULL)
-                                       ldap_back_map(oc_map, &tmp, &m, remap);
-                               if (m.bv_val == NULL) {
-                                       m = tmp;
-                               }
-                               extra += p - q;
-                               plen = m.bv_len;
-                               extra -= plen;
-                               if (extra < 0) {
-                                       while (extra < 0) {
-                                               extra += len;
-                                               len *= 2;
-                                       }
-                                       s -= (long)nf;
-                                       nf = ch_realloc(nf, len + 1);
-                                       if (nf == NULL) {
-                                               free(nf);
-                                               return(NULL);
-                                       }
-                                       s += (long)nf;
-                               }
-                               AC_MEMCPY(s, m.bv_val, plen);
-                               s += plen;
-                               *p = c;
-                               q = NULL;
-                       }
-                       *s++ = c;
-               }
-       }
-       *s = 0;
-       return(nf);
-}
-
-char **
-ldap_back_map_attrs(
-               struct ldapmap *at_map,
-               AttributeName *an,
-               int remap
-)
-{
-       int i;
-       char **na;
-       struct berval mapped;
-
-       if (an == NULL)
-               return(NULL);
-
-       for (i = 0; an[i].an_name.bv_val; i++) {
-               /*  */
-       }
-
-       na = (char **)ch_calloc( i + 1, sizeof(char *) );
-       if (na == NULL)
-               return(NULL);
-
-       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++;
-               }
-       }
-       return(na);
-}
-
 #ifdef ENABLE_REWRITE
 static char *
 suffix_massage_regexize( const char *s )
 {
-       char *res, *p, *r;
+       char *res, *p, *r, *ptr;
        int i;
 
        for ( i = 0, p = ( char * )s; 
@@ -508,18 +313,18 @@ suffix_massage_regexize( const char *s )
 
        res = ch_calloc( sizeof( char ), strlen( s ) + 4 + 4*i + 1 );
 
-       strcpy( res, "(.*)" );
+       ptr = slap_strcopy( res, "(.*)" );
        for ( i = 0, p = ( char * )s;
                        ( r = strchr( p, ',' ) ) != NULL;
                        p = r + 1 , i++ ) {
-               strncat( res, p, r - p + 1 );
-               strcat( res, "[ ]?" );
+               ptr = slap_strncopy( ptr, p, r - p + 1 );
+               ptr = slap_strcopy( ptr, "[ ]?" );
 
                if ( r[ 1 ] == ' ' ) {
                        r++;
                }
        }
-       strcat( res, p );
+       slap_strcopy( ptr, p );
 
        return res;
 }
@@ -527,19 +332,33 @@ suffix_massage_regexize( const char *s )
 static char *
 suffix_massage_patternize( const char *s, int normalize )
 {
-       char *res;
-
-       res = ch_calloc( sizeof( char ), strlen( s ) + sizeof("%1") );
+       struct berval   dn = { 0, NULL }, odn = { 0, NULL };
+       int             rc;
+       char            *res;
 
-       sprintf( res, "%%1%s", s );
+       dn.bv_val = ( char * )s;
+       dn.bv_len = strlen( s );
 
        if ( normalize ) {
-               char *out = dn_normalize( res + (sizeof("%1")-1) );
-               if ( out != res + 2 ) {
-                       strcpy( res + 2, out );
-                       free( out );
-               }
+               rc = dnNormalize2( NULL, &dn, &odn );
+       } else {
+               rc = dnPretty2( NULL, &dn, &odn );
+       }
+
+       if ( rc != LDAP_SUCCESS ) {
+               return NULL;
        }
+       
+       res = ch_calloc( sizeof( char ), odn.bv_len + sizeof( "%1" ) );
+       if ( res == NULL ) {
+               return NULL;
+       }
+
+       strcpy( res, "%1" );
+       strcpy( res + sizeof( "%1" ) - 1, odn.bv_val );
+
+       /* FIXME: what FREE should I use? */
+       free( odn.bv_val );
 
        return res;
 }