/* add.c - ldap backend add function */
/* $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 */
{
struct ldapinfo *li = (struct ldapinfo *) be->be_private;
struct ldapconn *lc;
- int i;
+ int i, j;
Attribute *a;
LDAPMod **attrs;
- char *mdn = NULL, *mapped;
+ struct berval mapped;
+ struct berval mdn = { 0, NULL };
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY, "ldap_back_add: %s\n",
* Rewrite the add dn, if needed
*/
#ifdef ENABLE_REWRITE
- switch (rewrite_session( li->rwinfo, "addDn", e->e_dn, conn, &mdn )) {
+ switch (rewrite_session( li->rwinfo, "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 ));
+ e->e_dn, mdn.bv_val ));
#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;
return( -1 );
}
#else /* !ENABLE_REWRITE */
- mdn = ldap_back_dn_massage( li, ch_strdup( e->e_dn ), 0 );
+ ldap_back_dn_massage( li, &e->e_name, &mdn, 0, 1 );
#endif /* !ENABLE_REWRITE */
/* Count number of attributes in entry */
}
#endif
- mapped = ldap_back_map(&li->at_map, a->a_desc->ad_cname.bv_val, 0);
- if (mapped == NULL) {
+ ldap_back_map(&li->at_map, &a->a_desc->ad_cname, &mapped, 0);
+ if (mapped.bv_val == NULL) {
continue;
}
}
attrs[i]->mod_op = LDAP_MOD_BVALUES;
- attrs[i]->mod_type = mapped;
+ attrs[i]->mod_type = mapped.bv_val;
#ifdef ENABLE_REWRITE
/*
}
#endif /* ENABLE_REWRITE */
- 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->ld, mdn, attrs);
- for (--i; i>= 0; --i)
- free(attrs[i]);
- free(attrs);
-#ifdef ENABLE_REWRITE
- if ( mdn != e->e_dn ) {
-#endif /* ENABLE_REWRITE */
- free( mdn );
-#ifdef ENABLE_REWRITE
+ ldap_add_s(lc->ld, mdn.bv_val, attrs);
+ for (--i; i>= 0; --i) {
+ ch_free(attrs[i]->mod_vals.modv_bvals);
+ ch_free(attrs[i]);
+ }
+ ch_free(attrs);
+ if ( mdn.bv_val != e->e_dn ) {
+ free( mdn.bv_val );
}
-#endif /* ENABLE_REWRITE */
return( ldap_back_op_result( lc, op ) );
}
int
ldap_dnattr_rewrite(
struct rewrite_info *rwinfo,
- struct berval **a_vals,
+ BerVarray a_vals,
void *cookie
)
{
- int j;
char *mattr;
- for ( j = 0; a_vals[ j ] != NULL; j++ ) {
- switch ( rewrite_session( rwinfo, "bindDn", a_vals[ j ]->bv_val,
+ for ( ; a_vals->bv_val != NULL; a_vals++ ) {
+ switch ( rewrite_session( rwinfo, "bindDn", a_vals->bv_val,
cookie, &mattr )) {
case REWRITE_REGEXEC_OK:
if ( mattr == NULL ) {
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] bindDn (in add of dn-valued"
" attr): \"%s\" -> \"%s\"\n",
- a_vals[ j ]->bv_val, mattr ));
+ a_vals->bv_val, mattr ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS,
"rw> bindDn (in add of dn-valued attr):"
" \"%s\" -> \"%s\"\n%s",
- a_vals[ j ]->bv_val, mattr, "" );
+ a_vals->bv_val, mattr, "" );
#endif /* !NEW_LOGGING */
- free( a_vals[ j ]->bv_val );
- a_vals[ j ]->bv_val = mattr;
- a_vals[ j ]->bv_len = strlen( mattr );
+ /*
+ * FIXME: replacing server-allocated memory
+ * (ch_malloc) with librewrite allocated memory
+ * (malloc)
+ */
+ ch_free( a_vals->bv_val );
+ a_vals->bv_val = mattr;
+ a_vals->bv_len = strlen( mattr );
break;