/*
- * Copyright 1998-2001 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
int i, candidate = -1;
Attribute *a;
LDAPMod **attrs;
- char *mdn = NULL, *mapped;
+ struct berval mdn = { 0, NULL }, mapped;
#ifdef NEW_LOGGING
- LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY, "meta_back_add: %s\n",
- e->e_dn ));
+ LDAP_LOG( BACK_META, ENTRY, "meta_back_add: %s\n", e->e_dn, 0, 0 );
#else /* !NEW_LOGGING */
Debug(LDAP_DEBUG_ARGS, "==> meta_back_add: %s\n%s%s", e->e_dn, "", "");
#endif /* !NEW_LOGGING */
* get the current connection
*/
lc = meta_back_getconn( li, conn, op, META_OP_REQUIRE_SINGLE,
- e->e_ndn, &candidate );
- if ( !lc || !meta_back_dobind( lc, op ) ) {
+ &e->e_nname, &candidate );
+ if ( !lc || !meta_back_dobind( lc, op ) || !meta_back_is_valid( lc, candidate ) ) {
+ send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
+ NULL, NULL, NULL, NULL );
return -1;
}
* Rewrite the add dn, if needed
*/
switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
- "addDn", e->e_dn, conn, &mdn )) {
+ "addDn", e->e_dn, conn, &mdn.bv_val )) {
case REWRITE_REGEXEC_OK:
- if ( mdn == NULL ) {
- mdn = e->e_dn;
+ if ( mdn.bv_val != NULL && mdn.bv_val[ 0 ] != '\0' ) {
+ mdn.bv_len = strlen( mdn.bv_val );
+ } else {
+ mdn = e->e_name;
}
#ifdef NEW_LOGGING
- LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
- "[rw] addDn: \"%s\" -> \"%s\"\n",
- e->e_dn, mdn ));
+ LDAP_LOG( BACK_META, DETAIL1,
+ "[rw] addDn: \"%s\" -> \"%s\"\n", e->e_dn, mdn.bv_val, 0 );
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> addDn: \"%s\" -> \"%s\"\n%s",
- e->e_dn, mdn, "" );
+ e->e_dn, mdn.bv_val, "" );
#endif /* !NEW_LOGGING */
break;
case REWRITE_REGEXEC_UNWILLING:
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
- NULL, "Unwilling to perform", NULL, NULL );
+ NULL, NULL, NULL, NULL );
return -1;
case REWRITE_REGEXEC_ERR:
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
- NULL, "Operations error", NULL, NULL );
+ NULL, NULL, NULL, NULL );
return -1;
}
attrs = ch_malloc( sizeof( LDAPMod * )*i );
for ( i = 0, a = e->e_attrs; a; a = a->a_next ) {
+ int j;
/*
* lastmod should always be <off>, so that
* creation/modification operational attrs
* of the target directory are used, if available
*/
#if 0
- if ( !strcasecmp( a->a_desc->ad_cname->bv_val,
- slap_schema.si_ad_creatorsName->ad_cname->bv_val )
- || !strcasecmp( a->a_desc->ad_cname->bv_val,
- slap_schema.si_ad_createTimestamp->ad_cname->bv_val )
- || !strcasecmp( a->a_desc->ad_cname->bv_val,
- slap_schema.si_ad_modifiersName->ad_cname->bv_val )
- || !strcasecmp( a->a_desc->ad_cname->bv_val,
- slap_schema.si_ad_modifyTimestamp->ad_cname->bv_val )
+ if ( !strcasecmp( a->a_desc->ad_cname.bv_val,
+ slap_schema.si_ad_creatorsName->ad_cname.bv_val )
+ || !strcasecmp( a->a_desc->ad_cname.bv_val,
+ slap_schema.si_ad_createTimestamp->ad_cname.bv_val )
+ || !strcasecmp( a->a_desc->ad_cname.bv_val,
+ slap_schema.si_ad_modifiersName->ad_cname.bv_val )
+ || !strcasecmp( a->a_desc->ad_cname.bv_val,
+ slap_schema.si_ad_modifyTimestamp->ad_cname.bv_val )
) {
continue;
}
#endif
- mapped = ldap_back_map( &li->targets[ candidate ]->at_map,
- a->a_desc->ad_cname->bv_val, 0);
- if ( mapped == NULL ) {
+ ldap_back_map( &li->targets[ candidate ]->at_map,
+ &a->a_desc->ad_cname, &mapped, 0);
+ if ( mapped.bv_val == NULL ) {
continue;
}
continue;
}
attrs[ i ]->mod_op = LDAP_MOD_BVALUES;
- attrs[ i ]->mod_type = mapped;
+ attrs[ i ]->mod_type = mapped.bv_val;
/*
* FIXME: dn-valued attrs should be rewritten
a->a_vals, conn );
}
- attrs[ i ]->mod_vals.modv_bvals = a->a_vals;
+ for (j=0; a->a_vals[ j ].bv_val; j++);
+ attrs[ i ]->mod_vals.modv_bvals = ch_malloc((j+1)*sizeof(struct berval *));
+ for (j=0; a->a_vals[ j ].bv_val; j++)
+ attrs[ i ]->mod_vals.modv_bvals[ j ] = &a->a_vals[ j ];
+ attrs[ i ]->mod_vals.modv_bvals[ j ] = NULL;
i++;
}
attrs[ i ] = NULL;
- ldap_add_s( lc->conns[ candidate ]->ld, mdn, attrs );
+ ldap_add_s( lc->conns[ candidate ]->ld, mdn.bv_val, attrs );
for ( --i; i >= 0; --i ) {
+ free( attrs[ i ]->mod_vals.modv_bvals );
free( attrs[ i ] );
}
free( attrs );
- if ( mdn != e->e_dn ) {
- free( mdn );
+ if ( mdn.bv_val != e->e_dn ) {
+ free( mdn.bv_val );
}
return meta_back_op_result( lc, op );
}