int i;
Attribute *a;
LDAPMod **attrs;
- char *mdn = NULL, *mapped;
+ char *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 = e->e_dn;
}
#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 */
}
attrs[i] = NULL;
- ldap_add_s(lc->ld, mdn, attrs);
+ ldap_add_s(lc->ld, mdn.bv_val, 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
+ if ( mdn.bv_val != e->e_dn ) {
+ free( mdn.bv_val );
}
-#endif /* ENABLE_REWRITE */
return( ldap_back_op_result( lc, op ) );
}
LDAP *ld;
*vals = NULL;
- if (target != NULL && strcmp(target->e_ndn, ndn->bv_val) == 0) {
+ if (target != NULL && target->e_nname.bv_len == ndn->bv_len &&
+ strcmp(target->e_nname.bv_val, ndn->bv_val) == 0) {
/* we already have a copy of the entry */
/* attribute and objectclass mapping has already been done */
if ((attr = attr_find(target->e_attrs, entry_at)) == NULL)
struct ldapconn {
struct slap_conn *conn;
LDAP *ld;
- char *bound_dn;
+ struct berval bound_dn;
int bound;
};
#ifdef ENABLE_REWRITE
struct rewrite_info *rwinfo;
#else /* !ENABLE_REWRITE */
- char **suffix_massage;
+ struct berval **suffix_massage;
#endif /* !ENABLE_REWRITE */
struct ldapmap oc_map;
int ldap_back_op_result(struct ldapconn *lc, Operation *op);
int back_ldap_LTX_init_module(int argc, char *argv[]);
-char *ldap_back_dn_massage(struct ldapinfo *li, char *dn, int normalized);
-char *ldap_back_dn_restore(struct ldapinfo *li, char *dn, int normalized);
+void ldap_back_dn_massage(struct ldapinfo *li, struct berval *dn,
+ struct berval *res, int normalized, int tofrom);
extern int ldap_back_conn_cmp( const void *c1, const void *c2);
extern int ldap_back_conn_dup( void *c1, void *c2 );
struct ldapinfo *li = (struct ldapinfo *) be->be_private;
struct ldapconn *lc;
- char *mdn = NULL;
+ struct berval mdn = { 0, NULL };
int rc = 0;
lc = ldap_back_getconn(li, conn, op);
* Rewrite the bind dn if needed
*/
#ifdef ENABLE_REWRITE
- switch ( rewrite_session( li->rwinfo, "bindDn", dn->bv_val, conn, &mdn ) ) {
+ switch ( rewrite_session( li->rwinfo, "bindDn", dn->bv_val, conn, &mdn.bv_val ) ) {
case REWRITE_REGEXEC_OK:
- if ( mdn == NULL ) {
- mdn = ( char * )dn->bv_val;
+ if ( mdn.bv_val == NULL ) {
+ mdn.bv_val = ( char * )dn->bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
- "[rw] bindDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn ));
+ "[rw] bindDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn.bv_val ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> bindDn: \"%s\" -> \"%s\"\n%s",
- dn->bv_val, mdn, "" );
+ dn->bv_val, mdn.bv_val, "" );
#endif /* !NEW_LOGGING */
break;
return( -1 );
}
#else /* !ENABLE_REWRITE */
- mdn = ldap_back_dn_massage( li, ch_strdup( dn->bv_val ), 0 );
+ ldap_back_dn_massage( li, dn, &mdn, 0, 1 );
#endif /* !ENABLE_REWRITE */
- rc = ldap_bind_s(lc->ld, mdn, cred->bv_val, method);
+ rc = ldap_bind_s(lc->ld, mdn.bv_val, cred->bv_val, method);
if (rc != LDAP_SUCCESS) {
rc = ldap_back_op_result( lc, op );
} else {
lc->bound = 1;
}
-#ifdef ENABLE_REWRITE
- if ( mdn != dn->bv_val ) {
-#endif /* ENABLE_REWRITE */
- free( mdn );
-#ifdef ENABLE_REWRITE
+ if ( mdn.bv_val != dn->bv_val ) {
+ free( mdn.bv_val );
}
-#endif /* ENABLE_REWRITE */
return( rc );
}
* Rewrite the bind dn if needed
*/
#ifdef ENABLE_REWRITE
- lc->bound_dn = NULL;
+ lc->bound_dn.bv_val = NULL;
+ lc->bound_dn.bv_len = 0;
switch ( rewrite_session( li->rwinfo, "bindDn",
lc->conn->c_cdn, conn,
- &lc->bound_dn ) ) {
+ &lc->bound_dn.bv_val ) ) {
case REWRITE_REGEXEC_OK:
- if ( lc->bound_dn == NULL ) {
- lc->bound_dn =
+ if ( lc->bound_dn.bv_val == NULL ) {
+ lc->bound_dn.bv_val =
ch_strdup( lc->conn->c_cdn );
}
#ifdef NEW_LOGGING
"[rw] bindDn: \"%s\" ->"
" \"%s\"\n%s",
lc->conn->c_cdn,
- lc->bound_dn ));
+ lc->bound_dn.bv_val ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS,
"rw> bindDn: \"%s\" ->"
" \"%s\"\n%s",
lc->conn->c_cdn,
- lc->bound_dn, "" );
+ lc->bound_dn.bv_val, "" );
#endif /* !NEW_LOGGING */
break;
return( NULL );
}
#else /* !ENABLE_REWRITE */
- lc->bound_dn = ldap_back_dn_massage( li,
- ch_strdup( lc->conn->c_cdn ), 0 );
+ struct berval bv;
+ ber_str2bv( lc->conn->c_cdn, 0, 0, &bv );
+ ldap_back_dn_massage( li, &bv, &lc->bound_dn, 0, 1 );
#endif /* !ENABLE_REWRITE */
} else {
- lc->bound_dn = NULL;
+ lc->bound_dn.bv_val = NULL;
+ lc->bound_dn.bv_len = 0;
}
lc->bound = 0;
return( lc->bound );
}
- if (ldap_bind_s(lc->ld, lc->bound_dn, NULL, LDAP_AUTH_SIMPLE) !=
+ if (ldap_bind_s(lc->ld, lc->bound_dn.bv_val, NULL, LDAP_AUTH_SIMPLE) !=
LDAP_SUCCESS) {
ldap_back_op_result(lc, op);
return( 0 );
{
struct ldapinfo *li = (struct ldapinfo *) be->be_private;
struct ldapconn *lc;
- char *mdn, *mapped_oc, *mapped_at;
+ char *mapped_oc, *mapped_at;
+ struct berval mdn = { 0, NULL };
lc = ldap_back_getconn(li, conn, op);
if (!lc || !ldap_back_dobind( lc, op ) ) {
* Rewrite the compare dn, if needed
*/
#ifdef ENABLE_REWRITE
- switch ( rewrite_session( li->rwinfo, "compareDn", dn->bv_val, conn, &mdn ) ) {
+ switch ( rewrite_session( li->rwinfo, "compareDn", dn->bv_val, conn, &mdn.bv_val ) ) {
case REWRITE_REGEXEC_OK:
- if ( mdn == NULL ) {
- mdn = ( char * )dn->bv_val;
+ if ( mdn.bv_val == NULL ) {
+ mdn.bv_val = ( char * )dn->bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] compareDn: \"%s\" -> \"%s\"\n",
- dn->bv_val, mdn ));
+ dn->bv_val, mdn.bv_val ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> compareDn: \"%s\" -> \"%s\"\n%s",
- dn->bv_val, mdn, "" );
+ dn->bv_val, mdn.bv_val, "" );
#endif /* !NEW_LOGGING */
break;
return( -1 );
}
#else /* !ENABLE_REWRITE */
- mdn = ldap_back_dn_massage( li, ch_strdup( dn->bv_val ), 0 );
- if ( mdn == NULL ) {
+ ldap_back_dn_massage( li, dn, &mdn, 0, 1 );
+ if ( mdn.bv_val == NULL ) {
return -1;
}
#endif /* !ENABLE_REWRITE */
if (mapped_at == NULL)
return( -1 );
- ldap_compare_s( lc->ld, mdn, mapped_oc, mapped_at );
+ ldap_compare_s( lc->ld, mdn.bv_val, mapped_oc, mapped_at );
-#ifdef ENABLE_REWRITE
- if ( mdn != dn->bv_val ) {
-#endif /* ENABLE_REWRITE */
- free( mdn );
-#ifdef ENABLE_REWRITE
+ if ( mdn.bv_val != dn->bv_val ) {
+ free( mdn.bv_val );
}
-#endif /* ENABLE_REWRITE */
return( ldap_back_op_result( lc, op ) );
}
/* dn massaging */
} else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
#ifndef ENABLE_REWRITE
- char *dn, *massaged_dn;
+ struct berval *bd2;
#endif /* ENABLE_REWRITE */
BackendDB *tmp_be;
struct berval bdn, *ndn = NULL;
*/
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 );
-
- 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 );
+ bd2 = ber_bvstrdup( argv[1] );
+ ber_bvecadd( &li->suffix_massage, bd2 );
+ ndn = NULL;
+ dnNormalize( NULL, bd2, &ndn );
+ ber_bvecadd( &li->suffix_massage, ndn );
- free( dn );
- free( massaged_dn );
+ bd2 = ber_bvstrdup( argv[2] );
+ ber_bvecadd( &li->suffix_massage, bd2 );
+ ndn = NULL;
+ dnNormalize( NULL, bd2, &ndn );
+ ber_bvecadd( &li->suffix_massage, ndn );
#endif /* !ENABLE_REWRITE */
#ifdef ENABLE_REWRITE
struct ldapinfo *li = (struct ldapinfo *) be->be_private;
struct ldapconn *lc;
- char *mdn = NULL;
+ struct berval mdn = { 0, NULL };
lc = ldap_back_getconn( li, conn, op );
* Rewrite the compare dn, if needed
*/
#ifdef ENABLE_REWRITE
- switch ( rewrite_session( li->rwinfo, "deleteDn", dn->bv_val, conn, &mdn ) ) {
+ switch ( rewrite_session( li->rwinfo, "deleteDn", dn->bv_val, conn, &mdn.bv_val ) ) {
case REWRITE_REGEXEC_OK:
- if ( mdn == NULL ) {
- mdn = ( char * )dn->bv_val;
+ if ( mdn.bv_val == NULL ) {
+ mdn.bv_val = ( char * )dn->bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
- "[rw] deleteDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn ));
+ "[rw] deleteDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn.bv_val ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> deleteDn: \"%s\" -> \"%s\"\n%s",
- dn->bv_val, mdn, "" );
+ dn->bv_val, mdn.bv_val, "" );
#endif /* !NEW_LOGGING */
break;
return( -1 );
}
#else /* !ENABLE_REWRITE */
- mdn = ldap_back_dn_massage( li, ch_strdup( dn->bv_val ), 0 );
+ ldap_back_dn_massage( li, dn, &mdn, 0, 1 );
#endif /* !ENABLE_REWRITE */
- ldap_delete_s( lc->ld, mdn );
+ ldap_delete_s( lc->ld, mdn.bv_val );
-#ifdef ENABLE_REWRITE
- if ( mdn != dn->bv_val ) {
-#endif /* ENABLE_REWRITE */
- free( mdn );
-#ifdef ENABLE_REWRITE
+ if ( mdn.bv_val != dn->bv_val ) {
+ free( mdn.bv_val );
}
-#endif /* ENABLE_REWRITE */
return( ldap_back_op_result( lc, op ) );
}
LDAPMessage *result;
char *gattr[2];
- char *filter = NULL;
+ char *filter = NULL, *ptr;
LDAP *ld;
- char *mop_ndn, *mgr_ndn;
+ struct berval mop_ndn = { 0, NULL }, mgr_ndn = { 0, NULL };
AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
char *group_oc_name = NULL;
group_oc_name = group_oc->soc_oid;
}
- if (target != NULL && strcmp(target->e_ndn, gr_ndn->bv_val) == 0) {
+ if (target != NULL && target->e_nname.bv_len == gr_ndn->bv_len &&
+ strcmp(target->e_nname.bv_val, gr_ndn->bv_val) == 0) {
/* we already have a copy of the entry */
/* attribute and objectclass mapping has already been done */
*/
#ifdef ENABLE_REWRITE
switch ( rewrite_session( li->rwinfo, "bindDn",
- op_ndn->bv_val, conn, &mop_ndn ) ) {
+ op_ndn->bv_val, conn, &mop_ndn.bv_val ) ) {
case REWRITE_REGEXEC_OK:
- if ( mop_ndn == NULL ) {
- mop_ndn = ( char * )op_ndn->bv_val;
+ if ( mop_ndn.bv_val == NULL ) {
+ mop_ndn = *op_ndn;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] bindDn (op ndn in group):"
- " \"%s\" -> \"%s\"\n", op_ndn->bv_val, mop_ndn ));
+ " \"%s\" -> \"%s\"\n", op_ndn->bv_val, mop_ndn.bv_val ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS,
"rw> bindDn (op ndn in group): \"%s\" -> \"%s\"\n%s",
- op_ndn->bv_val, mop_ndn, "" );
+ op_ndn->bv_val, mop_ndn.bv_val, "" );
#endif /* !NEW_LOGGING */
break;
* Rewrite the gr ndn if needed
*/
switch ( rewrite_session( li->rwinfo, "searchBase",
- gr_ndn->bv_val, conn, &mgr_ndn ) ) {
+ gr_ndn->bv_val, conn, &mgr_ndn.bv_val ) ) {
case REWRITE_REGEXEC_OK:
- if ( mgr_ndn == NULL ) {
- mgr_ndn = ( char * )gr_ndn->bv_val;
+ if ( mgr_ndn.bv_val == NULL ) {
+ mgr_ndn = *gr_ndn;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] searchBase (gr ndn in group):"
- " \"%s\" -> \"%s\"\n%s", gr_ndn->bv_val, mgr_ndn ));
+ " \"%s\" -> \"%s\"\n%s", gr_ndn->bv_val, mgr_ndn.bv_val ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS,
"rw> searchBase (gr ndn in group):"
" \"%s\" -> \"%s\"\n%s",
- gr_ndn->bv_val, mgr_ndn, "" );
+ gr_ndn->bv_val, mgr_ndn.bv_val, "" );
#endif /* !NEW_LOGGING */
break;
goto cleanup;
}
#else /* !ENABLE_REWRITE */
- mop_ndn = ldap_back_dn_massage( li, ch_strdup( op_ndn ), 1 );
- if ( mop_ndn == NULL ) {
+ ldap_back_dn_massage( li, op_ndn, &mop_ndn, 1, 1 );
+ if ( mop_ndn.bv_val == NULL ) {
goto cleanup;
}
- mgr_ndn = ldap_back_dn_massage( li, ch_strdup( gr_ndn ), 1 );
- if ( mgr_ndn == NULL ) {
+ ldap_back_dn_massage( li, gr_ndn, &mgr_ndn, 1, 1 );
+ if ( mgr_ndn.bv_val == NULL ) {
goto cleanup;
}
#endif /* !ENABLE_REWRITE */
filter = ch_malloc(sizeof("(&(objectclass=)(=))")
+ strlen(group_oc_name)
+ strlen(group_at_name)
- + strlen(mop_ndn) + 1);
+ + mop_ndn.bv_len + 1);
if (filter == NULL)
goto cleanup;
goto cleanup;
}
- strcpy(filter, "(&(objectclass=");
- strcat(filter, group_oc_name);
- strcat(filter, ")(");
- strcat(filter, group_at_name);
- strcat(filter, "=");
- strcat(filter, mop_ndn);
- strcat(filter, "))");
+ ptr = slap_strcopy(filter, "(&(objectclass=");
+ ptr = slap_strcopy(ptr, group_oc_name);
+ ptr = slap_strcopy(ptr, ")(");
+ ptr = slap_strcopy(ptr, group_at_name);
+ ptr = slap_strcopy(ptr, "=");
+ ptr = slap_strcopy(ptr, mop_ndn.bv_val);
+ strcpy(ptr, "))");
gattr[0] = "objectclass";
gattr[1] = NULL;
- if (ldap_search_ext_s(ld, mgr_ndn, LDAP_SCOPE_BASE, filter,
+ if (ldap_search_ext_s(ld, mgr_ndn.bv_val, LDAP_SCOPE_BASE, filter,
gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
LDAP_NO_LIMIT, &result) == LDAP_SUCCESS) {
if (ldap_first_entry(ld, result) != NULL)
ldap_unbind(ld);
}
ch_free(filter);
-#ifdef ENABLE_REWRITE
- if ( mop_ndn != op_ndn->bv_val ) {
-#endif /* ENABLE_REWRITE */
- free( mop_ndn );
-#ifdef ENABLE_REWRITE
+ if ( mop_ndn.bv_val != op_ndn->bv_val ) {
+ free( mop_ndn.bv_val );
}
- if ( mgr_ndn != gr_ndn->bv_val ) {
-#endif /* ENABLE_REWRITE */
- free( mgr_ndn );
-#ifdef ENABLE_REWRITE
+ if ( mgr_ndn.bv_val != gr_ndn->bv_val ) {
+ free( mgr_ndn.bv_val );
}
-#endif /* ENABLE_REWRITE */
return(rc);
}
-
)
{
ldap_unbind(lc->ld);
- if ( lc->bound_dn) free( lc->bound_dn );
+ if ( lc->bound_dn.bv_val) free( lc->bound_dn.bv_val );
free( lc );
}
}
#else /* !ENABLE_REWRITE */
if (li->suffix_massage) {
- ldap_value_free( li->suffix_massage );
+ ber_bvecfree( li->suffix_massage );
}
#endif /* !ENABLE_REWRITE */
LDAPMod *mods;
Modifications *ml;
int i;
- char *mdn = NULL, *mapped;
+ char *mapped;
+ struct berval mdn = { 0, NULL };
lc = ldap_back_getconn(li, conn, op);
if ( !lc || !ldap_back_dobind( lc, op ) ) {
* Rewrite the modify dn, if needed
*/
#ifdef ENABLE_REWRITE
- switch ( rewrite_session( li->rwinfo, "modifyDn", dn->bv_val, conn, &mdn ) ) {
+ switch ( rewrite_session( li->rwinfo, "modifyDn", dn->bv_val, conn, &mdn.bv_val ) ) {
case REWRITE_REGEXEC_OK:
- if ( mdn == NULL ) {
- mdn = ( char * )dn->bv_val;
+ if ( mdn.bv_val == NULL ) {
+ mdn.bv_val = ( char * )dn->bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
- "[rw] modifyDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn ));
+ "[rw] modifyDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn.bv_val ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> modifyDn: \"%s\" -> \"%s\"\n%s",
- dn->bv_val, mdn, "" );
+ dn->bv_val, mdn.bv_val, "" );
#endif /* !NEW_LOGGING */
break;
return( -1 );
}
#else /* !ENABLE_REWRITE */
- mdn = ldap_back_dn_massage( li, ch_strdup( dn->bv_val ), 0 );
+ ldap_back_dn_massage( li, dn, &mdn, 0, 1 );
#endif /* !ENABLE_REWRITE */
for (i=0, ml=modlist; ml; i++,ml=ml->sml_next)
}
modv[i] = 0;
- ldap_modify_s( lc->ld, mdn, modv );
+ ldap_modify_s( lc->ld, mdn.bv_val, modv );
cleanup:;
#ifdef ENABLE_REWRITE
- if ( mdn != dn->bv_val ) {
+ if ( mdn.bv_val != dn->bv_val ) {
#endif /* ENABLE_REWRITE */
- free( mdn );
+ free( mdn.bv_val );
#ifdef ENABLE_REWRITE
}
#endif /* ENABLE_REWRITE */
struct ldapinfo *li = (struct ldapinfo *) be->be_private;
struct ldapconn *lc;
- char *mdn = NULL, *mnewSuperior = NULL;
+ struct berval mdn = { 0, NULL }, mnewSuperior = { 0, NULL };
lc = ldap_back_getconn( li, conn, op );
if ( !lc || !ldap_back_dobind(lc, op) ) {
*/
#ifdef ENABLE_REWRITE
switch ( rewrite_session( li->rwinfo, "newSuperiorDn",
- newSuperior->bv_val, conn, &mnewSuperior ) ) {
+ newSuperior->bv_val, conn, &mnewSuperior.bv_val ) ) {
case REWRITE_REGEXEC_OK:
- if ( mnewSuperior == NULL ) {
- mnewSuperior = ( char * )newSuperior;
+ if ( mnewSuperior.bv_val == NULL ) {
+ mnewSuperior.bv_val = ( char * )newSuperior;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] newSuperiorDn:"
" \"%s\" -> \"%s\"\n",
- newSuperior, mnewSuperior ));
+ newSuperior, mnewSuperior.bv_val ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> newSuperiorDn:"
" \"%s\" -> \"%s\"\n%s",
- newSuperior->bv_val, mnewSuperior, "" );
+ newSuperior->bv_val, mnewSuperior.bv_val, "" );
#endif /* !NEW_LOGGING */
break;
return( -1 );
}
#else /* !ENABLE_REWRITE */
- mnewSuperior = ldap_back_dn_massage( li,
- ch_strdup( newSuperior->bv_val ), 0 );
- if ( mnewSuperior == NULL ) {
+ ldap_back_dn_massage( li, newSuperior, &mnewSuperior, 0, 1 );
+ if ( mnewSuperior.bv_val == NULL ) {
return( -1 );
}
#endif /* !ENABLE_REWRITE */
/*
* Rewrite the modrdn dn, if required
*/
- switch ( rewrite_session( li->rwinfo, "modrDn", dn->bv_val, conn, &mdn ) ) {
+ switch ( rewrite_session( li->rwinfo, "modrDn", dn->bv_val, conn, &mdn.bv_val ) ) {
case REWRITE_REGEXEC_OK:
- if ( mdn == NULL ) {
- mdn = ( char * )dn->bv_val;
+ if ( mdn.bv_val == NULL ) {
+ mdn.bv_val = ( char * )dn->bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
- "[rw] modrDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn ));
+ "[rw] modrDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn.bv_val ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> modrDn: \"%s\" -> \"%s\"\n%s",
- dn->bv_val, mdn, "" );
+ dn->bv_val, mdn.bv_val, "" );
#endif /* !NEW_LOGGING */
break;
return( -1 );
}
#else /* !ENABLE_REWRITE */
- mdn = ldap_back_dn_massage( li, ch_strdup( dn->bv_val ), 0 );
+ ldap_back_dn_massage( li, dn, &mdn, 0, 1 );
#endif /* !ENABLE_REWRITE */
- ldap_rename2_s( lc->ld, mdn, newrdn->bv_val, mnewSuperior, deleteoldrdn );
+ ldap_rename2_s( lc->ld, mdn.bv_val, newrdn->bv_val, mnewSuperior.bv_val, deleteoldrdn );
-#ifdef ENABLE_REWRITE
- if ( mdn != dn->bv_val ) {
-#endif /* ENABLE_REWRITE */
- free( mdn );
-#ifdef ENABLE_REWRITE
+ if ( mdn.bv_val != dn->bv_val ) {
+ free( mdn.bv_val );
}
-#endif /* ENABLE_REWRITE */
- if ( mnewSuperior != NULL
-#ifdef ENABLE_REWRITE
- && mnewSuperior != newSuperior->bv_val
-#endif /* ENABLE_REWRITE */
- ) {
- free( mnewSuperior );
+ if ( mnewSuperior.bv_val != NULL
+ && mnewSuperior.bv_val != newSuperior->bv_val ) {
+ free( mnewSuperior.bv_val );
}
return( ldap_back_op_result( lc, op ) );
LDAPMessage *res, *e;
int count, rc = 0, msgid, sres = LDAP_SUCCESS;
char *match = NULL, *err = NULL;
- char *mbase = NULL, *mapped_filter = NULL, **mapped_attrs = NULL;
+ char *mapped_filter = NULL, **mapped_attrs = NULL;
+ struct berval mbase;
#ifdef ENABLE_REWRITE
char *mfilter = NULL, *mmatch = NULL;
#endif /* ENABLE_REWRITE */
*/
#ifdef ENABLE_REWRITE
switch ( rewrite_session( li->rwinfo, "searchBase",
- base->bv_val, conn, &mbase ) ) {
+ base->bv_val, conn, &mbase.bv_val ) ) {
case REWRITE_REGEXEC_OK:
- if ( mbase == NULL ) {
- mbase = ( char * )base->bv_val;
+ if ( mbase.bv_val == NULL ) {
+ mbase.bv_val = ( char * )base->bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] searchBase: \"%s\" -> \"%s\"\n%",
- base->bv_val, mbase ));
+ base->bv_val, mbase.bv_val ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> searchBase: \"%s\" -> \"%s\"\n%s",
- base->bv_val, mbase, "" );
+ base->bv_val, mbase.bv_val, "" );
#endif /* !NEW_LOGGING */
break;
goto finish;
}
#else /* !ENABLE_REWRITE */
- mbase = ldap_back_dn_massage( li, ch_strdup( base->bv_val ), 0 );
+ ldap_back_dn_massage( li, base, &mbase, 0, 1 );
#endif /* !ENABLE_REWRITE */
mapped_filter = ldap_back_map_filter(&li->at_map, &li->oc_map,
mapped_attrs[count] = NULL;
}
- if ((msgid = ldap_search(lc->ld, mbase, scope, mapped_filter, mapped_attrs,
+ if ((msgid = ldap_search(lc->ld, mbase.bv_val, scope, mapped_filter, mapped_attrs,
attrsonly)) == -1)
{
fail:;
}
#endif /* !ENABLE_REWRITE */
-#ifdef ENABLE_REWRITE
- if ( mbase != base->bv_val ) {
-#endif /* ENABLE_REWRITE */
- free( mbase );
-#ifdef ENABLE_REWRITE
+ if ( mbase.bv_val != base->bv_val ) {
+ free( mbase.bv_val );
}
-#endif /* ENABLE_REWRITE */
return rc;
}
BerElement *ber = NULL;
Attribute *attr, **attrp;
struct berval *dummy = NULL;
- struct berval *bv;
+ struct berval *bv, bdn;
const char *text;
#ifdef ENABLE_REWRITE
return;
}
#else /* !ENABLE_REWRITE */
- ent.e_dn = ldap_back_dn_restore( li, ldap_get_dn(lc->ld, e), 0 );
+ ber_str2bv( ldap_get_dn(lc->ld, e), 0, 0, &bdn );
+ ldap_back_dn_massage( li, &bdn, &ent.e_name, 0, 0 );
#endif /* !ENABLE_REWRITE */
- ent.e_ndn = ch_strdup( ent.e_dn );
- (void) dn_normalize( ent.e_ndn );
+ bv = NULL;
+ dnNormalize( NULL, &ent.e_name, &bv );
+ ent.e_nname = *bv;
ent.e_id = 0;
ent.e_attrs = 0;
ent.e_private = 0;
i--;
} else if ( mapped != bv->bv_val ) {
ch_free(bv->bv_val);
- bv->bv_val = ch_strdup( mapped );
- bv->bv_len = strlen( mapped );
+ ber_str2bv( mapped, 0, 1, bv );
}
}
*
* Aliases the suffix; based on suffix_alias (servers/slapd/suffixalias.c).
*/
-char *
+void
ldap_back_dn_massage(
struct ldapinfo *li,
- char *dn,
- int normalized
+ struct berval *dn,
+ struct berval *res,
+ int normalized,
+ int tofrom
)
{
- int i, dnLength;
+ int i, src, dst;
if ( dn == NULL ) {
- return NULL;
+ res->bv_val = NULL;
+ res->bv_len = 0;
+ return;
}
if ( li == NULL ) {
- return dn;
+ *res = *dn;
+ return;
}
- dnLength = strlen ( dn );
+ if ( tofrom ) {
+ src = 0 + normalized;
+ dst = 2 + normalized;
+ } else {
+ src = 2 + normalized;
+ dst = 0 + normalized;
+ }
for ( i = 0;
li->suffix_massage != NULL && li->suffix_massage[i] != NULL;
i += 4 ) {
- int aliasLength = strlen( li->suffix_massage[i+normalized] );
- int diff = dnLength - aliasLength;
+ int aliasLength = li->suffix_massage[i+src]->bv_len;
+ int diff = dn->bv_len - aliasLength;
if ( diff < 0 ) {
/* alias is longer than dn */
continue;
} else if ( diff > 0 ) {
- if ( normalized && ( ! DN_SEPARATOR(dn[diff-1]) ) ) {
+ if ( normalized && ( ! DN_SEPARATOR(dn->bv_val[diff-1]) ) ) {
/* boundary is not at a DN separator */
continue;
}
/* XXX or an escaped separator... oh well */
}
- if ( !strcmp( li->suffix_massage[i+normalized], &dn[diff] ) ) {
- char *oldDN = dn;
- dn = ch_malloc( diff + strlen( li->suffix_massage[i+2+normalized] ) + 1 );
- strncpy( dn, oldDN, diff );
- strcpy( &dn[diff], li->suffix_massage[i+2+normalized] );
+ if ( !strcmp( li->suffix_massage[i+src]->bv_val, &dn->bv_val[diff] ) ) {
+ res->bv_len = diff + li->suffix_massage[i+dst]->bv_len;
+ res->bv_val = ch_malloc( res->bv_len + 1 );
+ strncpy( res->bv_val, dn->bv_val, diff );
+ strcpy( &res->bv_val[diff], li->suffix_massage[i+dst]->bv_val );
Debug( LDAP_DEBUG_ARGS,
"ldap_back_dn_massage:"
" converted \"%s\" to \"%s\"\n",
- oldDN, dn, 0 );
- free( oldDN );
+ dn->bv_val, res->bv_val, 0 );
break;
}
}
- return dn;
-}
-
-/*
- * ldap_back_dn_restore
- *
- * Restores the original suffix;
- * based on suffix_alias (servers/slapd/suffixalias.c).
- */
-char *
-ldap_back_dn_restore(
- struct ldapinfo *li,
- char *dn,
- int normalized
- )
-{
- int i, dnLength;
-
- if ( dn == NULL ) {
- return NULL;
- }
- if ( li == NULL ) {
- return dn;
- }
-
- dnLength = strlen ( dn );
-
- for ( i = 0;
- li->suffix_massage != NULL && li->suffix_massage[i] != NULL;
- i += 4 ) {
- int aliasLength = strlen( li->suffix_massage[i+2+normalized] );
- int diff = dnLength - aliasLength;
-
- if ( diff < 0 ) {
- /* alias is longer than dn */
- continue;
-
- } else if ( diff > 0 ) {
- if ( normalized && ( ! DN_SEPARATOR(dn[diff-1]) ) ) {
- /* boundary is not at a DN separator */
- continue;
- }
- /* At a DN Separator */
- /* XXX or an escaped separator... oh well */
- }
-
- if ( !strcmp( li->suffix_massage[i+2+normalized], &dn[diff] ) ) {
- char *oldDN = dn;
- dn = ch_malloc( diff + strlen( li->suffix_massage[i+normalized] ) + 1 );
- strncpy( dn, oldDN, diff );
- strcpy( &dn[diff], li->suffix_massage[i+normalized] );
- Debug( LDAP_DEBUG_ARGS,
- "ldap_back_dn_restore:"
- " converted \"%s\" to \"%s\"\n",
- oldDN, dn, 0 );
- free( oldDN );
- break;
- }
- }
-
- return dn;
+ return;
}
#endif /* !ENABLE_REWRITE */
-
* in a segmentation fault
*/
ldap_unbind(lc->ld);
- if ( lc->bound_dn ) {
- free( lc->bound_dn );
+ if ( lc->bound_dn.bv_val ) {
+ free( lc->bound_dn.bv_val );
}
free( lc );
}