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) );
+ 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.bv_val, map2->src.bv_val) == 0 ) ? -1 : 0 );
+ return ( ( strcasecmp( map1->src.bv_val, map2->src.bv_val ) == 0 ) ? -1 : 0 );
}
void
Avlnode *tree;
struct ldapmapping *mapping, fmapping;
- if (remap == BACKLDAP_REMAP)
+ if ( remap == BACKLDAP_REMAP ) {
tree = map->remap;
- else
+ } else {
tree = map->map;
+ }
- bv->bv_len = 0;
- bv->bv_val = NULL;
+ BER_BVZERO( bv );
fmapping.src = *s;
mapping = (struct ldapmapping *)avl_find( tree, (caddr_t)&fmapping, mapping_cmp );
- if (mapping != NULL) {
- if ( mapping->dst.bv_val )
+ if ( mapping != NULL ) {
+ if ( !BER_BVISNULL( &mapping->dst ) ) {
*bv = mapping->dst;
+ }
return;
}
- if (!map->drop_missing)
+ if ( !map->drop_missing ) {
*bv = *s;
+ }
return;
}
char **na;
struct berval mapped;
- if (an == NULL) {
+ if ( an == NULL ) {
*mapped_attrs = NULL;
return LDAP_SUCCESS;
}
- for (i = 0; an[i].an_name.bv_val; i++) {
- /* */
- }
+ for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ )
+ /* */ ;
na = (char **)ch_calloc( i + 1, sizeof(char *) );
- if (na == NULL) {
+ if ( na == NULL ) {
*mapped_attrs = NULL;
return LDAP_NO_MEMORY;
}
- 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 && mapped.bv_val != '\0')
+ for ( i = j = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
+ ldap_back_map( at_map, &an[i].an_name, &mapped, remap );
+ if ( !BER_BVISNULL( &mapped ) && !BER_BVISEMPTY( &mapped ) ) {
na[j++] = mapped.bv_val;
+ }
}
- if (j == 0 && i != 0)
+ if ( j == 0 && i != 0 ) {
na[j++] = LDAP_NO_ATTRS;
+ }
na[j] = NULL;
*mapped_attrs = na;
int freeval = 0;
ldap_back_map( &dc->rwmap->rwm_at, &ad->ad_cname, mapped_attr, remap );
- if ( mapped_attr->bv_val == NULL || mapped_attr->bv_val[0] == '\0') {
+ if ( BER_BVISNULL( mapped_attr ) || BER_BVISEMPTY( mapped_attr ) ) {
/*
* FIXME: are we sure we need to search oc_map if at_map fails?
*/
ldap_back_map( &dc->rwmap->rwm_oc, &ad->ad_cname, mapped_attr, remap );
- if ( mapped_attr->bv_val == NULL || mapped_attr->bv_val[0] == '\0' ) {
+ if ( BER_BVISNULL( mapped_attr ) || BER_BVISEMPTY( mapped_attr ) ) {
*mapped_attr = ad->ad_cname;
}
}
} else if ( ad == slap_schema.si_ad_objectClass || ad == slap_schema.si_ad_structuralObjectClass ) {
ldap_back_map( &dc->rwmap->rwm_oc, value, &vtmp, remap );
- if ( vtmp.bv_val == NULL || vtmp.bv_val[0] == '\0' ) {
+ if ( BER_BVISNULL( &vtmp ) || BER_BVISEMPTY( &vtmp ) ) {
vtmp = *value;
}
/* cannot be a DN ... */
- fstr->bv_len = atmp.bv_len + ( sizeof("(=*)") - 1 );
- fstr->bv_val = malloc( fstr->bv_len + 128 );
+ fstr->bv_len = atmp.bv_len + ( STRLENOF( "(=*)" ) );
+ fstr->bv_val = malloc( fstr->bv_len + 128 ); /* FIXME: why 128 ? */
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
atmp.bv_val );
- if ( f->f_sub_initial.bv_val != NULL ) {
+ if ( !BER_BVISNULL( &f->f_sub_initial ) ) {
len = fstr->bv_len;
filter_escape_value( &f->f_sub_initial, &vtmp );
}
if ( f->f_sub_any != NULL ) {
- for ( i = 0; f->f_sub_any[i].bv_val != NULL; i++ ) {
+ for ( i = 0; !BER_BVISNULL( &f->f_sub_any[i] ); i++ ) {
len = fstr->bv_len;
filter_escape_value( &f->f_sub_any[i], &vtmp );
}
}
- if ( f->f_sub_final.bv_val != NULL ) {
+ if ( !BER_BVISNULL( &f->f_sub_final ) ) {
len = fstr->bv_len;
filter_escape_value( &f->f_sub_final, &vtmp );
return -1;
}
- fstr->bv_len = atmp.bv_len + ( sizeof("(=*)") - 1 );
+ fstr->bv_len = atmp.bv_len + ( STRLENOF( "(=*)" ) );
fstr->bv_val = malloc( fstr->bv_len + 1 );
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
case LDAP_FILTER_AND:
case LDAP_FILTER_OR:
case LDAP_FILTER_NOT:
- fstr->bv_len = sizeof("(%)") - 1;
- fstr->bv_val = malloc( fstr->bv_len + 128 );
+ fstr->bv_len = STRLENOF( "(%)" );
+ fstr->bv_val = malloc( fstr->bv_len + 128 ); /* FIXME: why 128? */
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%c)",
f->f_choice == LDAP_FILTER_AND ? '&' :
}
} else {
- atmp.bv_len = 0;
- atmp.bv_val = "";
-
+ BER_BVSTR( &atmp, "" );
filter_escape_value( &f->f_mr_value, &vtmp );
}
-
+ /* FIXME: cleanup (less ?: operators...) */
fstr->bv_len = atmp.bv_len +
- ( f->f_mr_dnattrs ? sizeof(":dn")-1 : 0 ) +
- ( f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_len+1 : 0 ) +
- vtmp.bv_len + ( sizeof("(:=)") - 1 );
+ ( f->f_mr_dnattrs ? STRLENOF( ":dn" ) : 0 ) +
+ ( !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_len + 1 : 0 ) +
+ vtmp.bv_len + ( STRLENOF( "(:=)" ) );
fstr->bv_val = malloc( fstr->bv_len + 1 );
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s:=%s)",
atmp.bv_val,
f->f_mr_dnattrs ? ":dn" : "",
- f->f_mr_rule_text.bv_len ? ":" : "",
- f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_val : "",
+ !BER_BVISEMPTY( &f->f_mr_rule_text ) ? ":" : "",
+ !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_val : "",
vtmp.bv_val );
ber_memfree( vtmp.bv_val );
} break;
struct berval bv;
int i, last;
- for ( last = 0; a_vals[last].bv_val != NULL; last++ );
+ assert( a_vals != NULL );
+
+ for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ )
+ ;
last--;
- for ( i = 0; a_vals[i].bv_val != NULL; i++ ) {
+ for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
switch ( ldap_back_dn_massage( dc, &a_vals[i], &bv ) ) {
case LDAP_UNWILLING_TO_PERFORM:
/*
* it should be when searching (e.g. ACLs).
*/
ch_free( a_vals[i].bv_val );
- if (last > i ) {
+ if ( last > i ) {
a_vals[i] = a_vals[last];
}
- a_vals[last].bv_len = 0;
- a_vals[last].bv_val = NULL;
+ BER_BVZERO( &a_vals[last] );
last--;
break;
default:
/* leave attr untouched if massage failed */
- if ( bv.bv_val && bv.bv_val != a_vals[i].bv_val ) {
+ if ( !BER_BVISNULL( &bv ) && bv.bv_val != a_vals[i].bv_val ) {
ch_free( a_vals[i].bv_val );
a_vals[i] = bv;
}
struct berval bv;
int i, last;
- for ( last = 0; a_vals[last].bv_val; last++ );
+ assert( a_vals != NULL );
+
+ for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ )
+ ;
last--;
- for ( i = 0; a_vals[i].bv_val; i++ ) {
+ for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
switch ( ldap_back_dn_massage( dc, &a_vals[i], &bv ) ) {
case LDAP_UNWILLING_TO_PERFORM:
/*
default:
/* leave attr untouched if massage failed */
- if ( bv.bv_val && a_vals[i].bv_val != bv.bv_val ) {
+ if ( !BER_BVISNULL( &bv ) && a_vals[i].bv_val != bv.bv_val ) {
LBER_FREE( a_vals[i].bv_val );
a_vals[i] = bv;
}
ldap_back_map( &li->targets[ candidate ]->mt_rwmap.rwm_at,
&ml->sml_desc->ad_cname, &mapped,
BACKLDAP_MAP );
- if ( BER_BVISNULL( &mapped ) || mapped.bv_val[0] == '\0' ) {
+ if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
continue;
}
* to allow their use in ACLs at the back-ldap
* level.
*/
- if ( strcmp( ml->sml_desc->ad_type->sat_syntax->ssyn_oid,
- SLAPD_DN_SYNTAX ) == 0 )
- {
- ( void )ldap_dnattr_rewrite( &dc, ml->sml_values );
- }
-
if ( ml->sml_values != NULL ) {
- for ( j = 0; ml->sml_values[ j ].bv_val; j++ )
- ;
- mods[ i ].mod_bvalues =
- (struct berval **)ch_malloc( ( j + 1 ) *
- sizeof(struct berval *) );
- for ( j = 0; ml->sml_values[ j ].bv_val; j++ ) {
- mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
+ /* mod_op must be delete all values */
+ if ( strcmp( ml->sml_desc->ad_type->sat_syntax->ssyn_oid,
+ SLAPD_DN_SYNTAX ) == 0 )
+ {
+ ( void )ldap_dnattr_rewrite( &dc, ml->sml_values );
+ }
+
+ if ( ml->sml_values != NULL ) {
+ for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ )
+ ;
+ mods[ i ].mod_bvalues =
+ (struct berval **)ch_malloc( ( j + 1 ) *
+ sizeof(struct berval *) );
+ for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ ) {
+ mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
+ }
+ mods[ i ].mod_bvalues[ j ] = NULL;
}
- mods[ i ].mod_bvalues[ j ] = NULL;
} else {
mods[ i ].mod_bvalues = NULL;