]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldap/config.c
error message from be_entry_put tool backend function
[openldap] / servers / slapd / back-ldap / config.c
index 8b7c9bd5cd25382a346611f9ff0b76f9cd977715..7c3dc0bfd7d04e2fbddcdfb1c8aef4bac0a42ac9 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 */
@@ -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,15 +258,16 @@ 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",
                                fname, lineno );
                        return( 1 );
                }
-               mapping->src = ch_strdup(src);
-               mapping->dst = ch_strdup(dst);
+               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;
@@ -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,174 +292,13 @@ 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;
 }
 
-int
-mapping_cmp ( const void *c1, const void *c2 )
-{
-       struct ldapmapping *map1 = (struct ldapmapping *)c1;
-       struct ldapmapping *map2 = (struct ldapmapping *)c2;
-
-       return ( strcasecmp(map1->src, map2->src) );
-}
-
-int
-mapping_dup ( void *c1, void *c2 )
-{
-       struct ldapmapping *map1 = (struct ldapmapping *)c1;
-       struct ldapmapping *map2 = (struct ldapmapping *)c2;
-
-       return( ( strcasecmp(map1->src, map2->src) == 0 ) ? -1 : 0 );
-}
-
-char *
-ldap_back_map ( struct ldapmap *map, char *s, int remap )
-{
-       Avlnode *tree;
-       struct ldapmapping *mapping, fmapping;
-
-       if (remap)
-               tree = map->remap;
-       else
-               tree = map->map;
-
-       fmapping.src = s;
-       mapping = (struct ldapmapping *)avl_find( tree, (caddr_t)&fmapping, mapping_cmp );
-       if (mapping != NULL) {
-               if ( *mapping->dst == 0 )
-                       return(NULL);
-               return(mapping->dst);
-       }
-
-       if (map->drop_missing)
-               return(NULL);
-
-       return(s);
-}
-
-char *
-ldap_back_map_filter(
-               struct ldapmap *at_map,
-               struct ldapmap *oc_map,
-               char *f,
-               int remap
-)
-{
-       char *nf, *m, *p, *q, *s, c;
-       int len, extra, plen, in_quote;
-
-       if (f == NULL)
-               return(NULL);
-
-       len = strlen(f);
-       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; (c = *p); p++) {
-               if (c == '"') {
-                       in_quote = !in_quote;
-                       if (q != NULL) {
-                               plen = p - q;
-                               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;
-                               m = ldap_back_map(at_map, q, remap);
-                               if (m == NULL)
-                                       m = ldap_back_map(oc_map, q, remap);
-                               if (m == NULL) {
-                                       m = q;
-                               }
-                               extra += p - q;
-                               plen = strlen(m);
-                               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;
-                               }
-                               memcpy(s, m, plen);
-                               s += plen;
-                               *p = c;
-                               q = NULL;
-                       }
-                       *s++ = c;
-               }
-       }
-       *s = 0;
-       return(nf);
-}
-
-char **
-ldap_back_map_attrs(
-               struct ldapmap *at_map,
-               AttributeName *a,
-               int remap
-)
-{
-       int i;
-       char *mapped, **na;
-       AttributeName *an;
-
-       if (a == NULL)
-               return(NULL);
-
-       for (i = 0, an=a; an; an=an->an_next, i++) {
-               /*  */
-       }
-
-       na = (char **)ch_calloc( i + 1, sizeof(char *) );
-       if (na == NULL)
-               return(NULL);
-
-       for (i = 0, an=a; an; an=an->an_next) {
-               mapped = ldap_back_map(at_map, an->an_name.bv_val, remap);
-               if (mapped != NULL) {
-                       na[i] = mapped;
-                       i++;
-               }
-       }
-       return(na);
-}
-
 #ifdef ENABLE_REWRITE
 static char *
 suffix_massage_regexize( const char *s )
@@ -493,12 +334,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 );
@@ -591,4 +432,3 @@ suffix_massage_config(
        return 0;
 }
 #endif /* ENABLE_REWRITE */
-