#include "slap.h"
#include "back-ldap.h"
+#undef ldap_debug /* silence a warning in ldap-int.h */
+#include "../../../libraries/libldap/ldap-int.h"
+
int
mapping_cmp ( const void *c1, const void *c2 )
{
return 0;
}
+/*
+ * I don't like this much, but we need two different
+ * functions because different heap managers may be
+ * in use in back-ldap/meta to reduce the amount of
+ * calls to malloc routines, and some of the free()
+ * routines may be macros with args
+ */
int
ldap_dnattr_rewrite(
dncookie *dc,
for ( i = 0; a_vals[i].bv_val != NULL; i++ ) {
switch ( ldap_back_dn_massage( dc, &a_vals[i], &bv ) ) {
- case LDAP_SUCCESS:
- case LDAP_OTHER: /* ? */
- default: /* ??? */
+ case LDAP_UNWILLING_TO_PERFORM:
+ /*
+ * FIXME: need to check if it may be considered
+ * legal to trim values when adding/modifying;
+ * it should be when searching (e.g. ACLs).
+ */
+ ch_free( a_vals[i].bv_val );
+ if (last > i ) {
+ a_vals[i] = a_vals[last];
+ }
+ a_vals[last].bv_len = 0;
+ a_vals[last].bv_val = NULL;
+ last--;
+ break;
+
+ default:
/* leave attr untouched if massage failed */
if ( bv.bv_val && bv.bv_val != a_vals[i].bv_val ) {
ch_free( a_vals[i].bv_val );
a_vals[i] = bv;
}
break;
+ }
+ }
+
+ return 0;
+}
+int
+ldap_dnattr_result_rewrite(
+ dncookie *dc,
+ BerVarray a_vals
+)
+{
+ struct berval bv;
+ int i, last;
+
+ for ( last = 0; a_vals[last].bv_val; last++ );
+ last--;
+
+ for ( i = 0; a_vals[i].bv_val; i++ ) {
+ switch ( ldap_back_dn_massage( dc, &a_vals[i], &bv ) ) {
case LDAP_UNWILLING_TO_PERFORM:
/*
* FIXME: need to check if it may be considered
* legal to trim values when adding/modifying;
- * it should be when searching (see ACLs).
+ * it should be when searching (e.g. ACLs).
*/
- ch_free( a_vals[i].bv_val );
- if (last > i ) {
+ LBER_FREE( &a_vals[i].bv_val );
+ if ( last > i ) {
a_vals[i] = a_vals[last];
}
- a_vals[last].bv_len = 0;
a_vals[last].bv_val = NULL;
+ a_vals[last].bv_len = 0;
last--;
break;
+
+ default:
+ /* leave attr untouched if massage failed */
+ if ( bv.bv_val && a_vals[i].bv_val != bv.bv_val ) {
+ LBER_FREE( a_vals[i].bv_val );
+ a_vals[i] = bv;
+ }
+ break;
}
}
-
+
return 0;
}
*/
} else if ( attr->a_desc->ad_type->sat_syntax ==
slap_schema.si_syn_distinguishedName ) {
- int last, i;
+ ldap_dnattr_result_rewrite( &dc, attr->a_vals );
- /*
- * FIXME: should use ldap_dnattr_rewrite(),
- * but need a different free() callback ...
- */
-
- for ( last = 0; attr->a_vals[last].bv_val; last++ );
-
- for ( i = 0; attr->a_vals[i].bv_val; i++ ) {
- struct berval newval = { 0, NULL };
-
- bv = &attr->a_vals[i];
- switch ( ldap_back_dn_massage( &dc, bv, &newval ) ) {
- case LDAP_UNWILLING_TO_PERFORM:
- LBER_FREE( bv->bv_val );
- if ( last > i ) {
- *bv = attr->a_vals[last];
- }
- attr->a_vals[last].bv_val = NULL;
- last--;
- break;
-
- default:
- if ( newval.bv_val && bv->bv_val != newval.bv_val ) {
- LBER_FREE( bv->bv_val );
- *bv = newval;
- }
- break;
- }
- }
}
if ( normalize && last && attr->a_desc->ad_type->sat_equality &&