/* dn massaging */
} else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
#ifndef ENABLE_REWRITE
- char *dn, *massaged_dn;
+ struct berval *bd2, *nd2;
#endif /* ENABLE_REWRITE */
BackendDB *tmp_be;
- struct berval bdn, *ndn = NULL;
+ struct berval bdn, ndn;
/*
* syntax:
bdn.bv_val = argv[1];
bdn.bv_len = strlen(bdn.bv_val);
- if ( dnNormalize( NULL, &bdn, &ndn ) != LDAP_SUCCESS ) {
+ if ( dnNormalize2( NULL, &bdn, &ndn ) != LDAP_SUCCESS ) {
fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
fname, lineno, bdn.bv_val );
return( 1 );
}
- tmp_be = select_backend( ndn, 0, 0 );
- ber_bvfree( ndn );
- ndn = NULL;
+ tmp_be = select_backend( &ndn, 0, 0 );
+ free( ndn.bv_val );
if ( tmp_be != NULL && tmp_be != be ) {
fprintf( stderr, "%s: line %d: suffix already in use"
" by another backend in"
bdn.bv_val = argv[2];
bdn.bv_len = strlen(bdn.bv_val);
- if ( dnNormalize( NULL, &bdn, &ndn ) != LDAP_SUCCESS ) {
+ if ( dnNormalize2( NULL, &bdn, &ndn ) != LDAP_SUCCESS ) {
fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
fname, lineno, bdn.bv_val );
return( 1 );
}
- tmp_be = select_backend( ndn, 0, 0 );
- ber_bvfree( ndn );
+ tmp_be = select_backend( &ndn, 0, 0 );
+ free( ndn.bv_val );
if ( tmp_be != NULL ) {
fprintf( stderr, "%s: line %d: massaged suffix"
" already in use by another backend in"
*/
return suffix_massage_config( li->rwinfo, argc, argv );
#else /* !ENABLE_REWRITE */
- dn = ch_strdup( argv[1] );
- charray_add( &li->suffix_massage, dn );
- (void) dn_normalize( dn );
- charray_add( &li->suffix_massage, dn );
+ bd2 = ber_bvstrdup( argv[1] );
+ ber_bvecadd( &li->suffix_massage, bd2 );
+ nd2 = NULL;
+ dnNormalize( NULL, bd2, &nd2 );
+ ber_bvecadd( &li->suffix_massage, nd2 );
- massaged_dn = ch_strdup( argv[2] );
- charray_add( &li->suffix_massage, massaged_dn );
- (void) dn_normalize( massaged_dn );
- charray_add( &li->suffix_massage, massaged_dn );
-
- free( dn );
- free( massaged_dn );
+ bd2 = ber_bvstrdup( argv[2] );
+ ber_bvecadd( &li->suffix_massage, bd2 );
+ nd2 = NULL;
+ dnNormalize( NULL, bd2, &nd2 );
+ ber_bvecadd( &li->suffix_massage, nd2 );
#endif /* !ENABLE_REWRITE */
#ifdef ENABLE_REWRITE
} 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 );
}
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;
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",
/* 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;
{
struct ldapmapping *map1 = (struct ldapmapping *)c1;
struct ldapmapping *map2 = (struct ldapmapping *)c2;
-
- return ( strcasecmp(map1->src, map2->src) );
+ 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
struct ldapmapping *map1 = (struct ldapmapping *)c1;
struct ldapmapping *map2 = (struct ldapmapping *)c2;
- return( ( strcasecmp(map1->src, map2->src) == 0 ) ? -1 : 0 );
+ return( ( strcasecmp(map1->src.bv_val, map2->src.bv_val) == 0 ) ? -1 : 0 );
}
-char *
-ldap_back_map ( struct ldapmap *map, char *s, int remap )
+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;
else
tree = map->map;
- fmapping.src = s;
+ 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 == 0 )
- return(NULL);
- return(mapping->dst);
+ if ( mapping->dst.bv_val )
+ *bv = mapping->dst;
+ return;
}
- if (map->drop_missing)
- return(NULL);
+ if (!map->drop_missing)
+ *bv = *s;
- return(s);
+ return;
}
char *
ldap_back_map_filter(
struct ldapmap *at_map,
struct ldapmap *oc_map,
- char *f,
+ struct berval *f,
int remap
)
{
- char *nf, *m, *p, *q, *s, c;
+ char *nf, *p, *q, *s, c;
int len, extra, plen, in_quote;
+ struct berval m, tmp;
if (f == NULL)
return(NULL);
- len = strlen(f);
+ len = f->bv_len;
extra = len;
len *= 2;
nf = ch_malloc( len + 1 );
s = nf;
q = NULL;
in_quote = 0;
- for (p = f; (c = *p); p++) {
+ for (p = f->bv_val; (c = *p); p++) {
if (c == '"') {
in_quote = !in_quote;
if (q != NULL) {
plen = p - q;
- memcpy(s, q, plen);
+ AC_MEMCPY(s, q, plen);
s += plen;
q = NULL;
}
} 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;
+ 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 = strlen(m);
+ plen = m.bv_len;
extra -= plen;
if (extra < 0) {
while (extra < 0) {
}
s += (long)nf;
}
- memcpy(s, m, plen);
+ AC_MEMCPY(s, m.bv_val, plen);
s += plen;
*p = c;
q = NULL;
char **
ldap_back_map_attrs(
struct ldapmap *at_map,
- struct berval **a,
+ AttributeName *an,
int remap
)
{
- int i, j, count;
- char *mapped, **na;
+ int i;
+ char **na;
+ struct berval mapped;
- if (a == NULL)
+ if (an == NULL)
return(NULL);
- for (count = 0; a[count] != NULL; count++) {
+ for (i = 0; an[i].an_name.bv_val; i++) {
/* */
}
- na = (char **)ch_calloc( count + 1, sizeof(char *) );
+ na = (char **)ch_calloc( i + 1, sizeof(char *) );
if (na == NULL)
return(NULL);
- for (i = 0, j = 0; i < count; i++) {
- mapped = ldap_back_map(at_map, a[i]->bv_val, remap);
- if (mapped != NULL) {
- na[j] = mapped;
- j++;
+ 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);
{
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 );
return 0;
}
#endif /* ENABLE_REWRITE */
-