char *edn = NULL;
/* deref suffix alias if appropriate */
- ndn->bv_val = suffix_alias( be, ndn->bv_val );
- ndn->bv_len = strlen( ndn->bv_val );
+ suffix_alias( be, ndn );
ret = (*be->be_bind)( be, conn, op,
pdn->bv_val, ndn->bv_val,
/* deref suffix alias if appropriate */
- ndn->bv_val = suffix_alias( be, ndn->bv_val );
- ndn->bv_len = strlen( ndn->bv_val );
+ suffix_alias( be, ndn );
if ( be->be_compare ) {
(*be->be_compare)( be, conn, op, pdn->bv_val, ndn->bv_val, &ava );
}
/* deref suffix alias if appropriate */
- ndn->bv_val = suffix_alias( be, ndn->bv_val );
- ndn->bv_len = strlen( ndn->bv_val );
+ suffix_alias( be, ndn );
/*
* do the delete if 1 && (2 || 3)
}
/* deref suffix alias if appropriate */
- ndn->bv_val = suffix_alias( be, ndn->bv_val );
- ndn->bv_len = strlen( ndn->bv_val );
+ suffix_alias( be, ndn );
/*
* do the modify if 1 && (2 || 3)
struct berval newSuperior = { 0, NULL };
ber_int_t deloldrdn;
- char *ndn = NULL;
+ struct berval *ndn;
char *nnewSuperior = NULL;
Backend *be;
goto cleanup;
}
- ndn = ch_strdup( dn.bv_val );
+ rc = dnNormalize( NULL, &dn, &ndn );
- if( dn_normalize( ndn ) == NULL ) {
+ if( rc != LDAP_SUCCESS ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
"do_modrdn: invalid dn (%s)\n", dn.bv_val ));
goto cleanup;
}
- if( *ndn == '\0' ) {
+ if( ndn->bv_len == 0 ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
"do_modrdn: attempt to modify root DSE.\n" ));
goto cleanup;
#ifdef SLAPD_SCHEMA_DN
- } else if ( strcasecmp( ndn, SLAPD_SCHEMA_DN ) == 0 ) {
+ } else if ( strcasecmp( ndn->bv_val, SLAPD_SCHEMA_DN ) == 0 ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
"do_modrdn: attempt to modify subschema subentry\n" ));
* appropriate one, or send a referral to our "referral server"
* if we don't hold it.
*/
- if ( (be = select_backend( ndn, manageDSAit, 0 )) == NULL ) {
+ if ( (be = select_backend( ndn->bv_val, manageDSAit, 0 )) == NULL ) {
struct berval **ref = referral_rewrite( default_referral,
NULL, dn.bv_val, LDAP_SCOPE_DEFAULT );
}
/* check for referrals */
- rc = backend_check_referrals( be, conn, op, dn.bv_val, ndn );
+ rc = backend_check_referrals( be, conn, op, dn.bv_val, ndn->bv_val );
if ( rc != LDAP_SUCCESS ) {
goto cleanup;
}
goto cleanup;
}
-
- /* deref suffix alias if appropriate */
- nnewSuperior = suffix_alias( be, nnewSuperior );
}
/* deref suffix alias if appropriate */
- ndn = suffix_alias( be, ndn );
+ suffix_alias( be, ndn );
/*
* do the add if 1 && (2 || 3)
if ( be->be_update_ndn == NULL || repl_user )
#endif
{
- if ( (*be->be_modrdn)( be, conn, op, dn.bv_val, ndn,
+ if ( (*be->be_modrdn)( be, conn, op, dn.bv_val, ndn->bv_val,
newrdn.bv_val, deloldrdn, newSuperior.bv_val ) == 0
#ifdef SLAPD_MULTIMASTER
&& ( be->be_update_ndn == NULL || !repl_user )
moddn.deloldrdn = deloldrdn;
moddn.newsup = newSuperior.bv_val;
- replog( be, op, dn.bv_val, ndn, &moddn );
+ replog( be, op, dn.bv_val, ndn->bv_val, &moddn );
}
#ifndef SLAPD_MULTIMASTER
} else {
free( newrdn.bv_val );
free( newSuperior.bv_val );
- if( ndn != NULL ) free( ndn );
+ if( ndn != NULL ) ber_bvfree( ndn );
if ( nnewSuperior != NULL ) free( nnewSuperior );
return rc;
}
/*
* suffixalias.c
*/
-LDAP_SLAPD_F (char *) suffix_alias LDAP_P(( Backend *be, char *ndn ));
+LDAP_SLAPD_F (void) suffix_alias LDAP_P(( Backend *be, struct berval *ndn ));
/*
* value.c
ml->sml_bvalues[i] != NULL; i++ ) {
char *buf, *bufp;
- len = strlen( type );
+ len = ml->sml_desc->ad_cname.bv_len;
len = LDIF_SIZE_NEEDED( len,
ml->sml_bvalues[i]->bv_len ) + 1;
buf = (char *) ch_malloc( len );
char *slap_sasl2dn( char *saslname )
{
- char *uri=NULL, *searchbase=NULL, *DN=NULL;
+ char *uri=NULL, *DN=NULL;
+ struct berval searchbase = {0, NULL};
int rc, scope;
Backend *be;
Filter *filter=NULL;
if( uri == NULL )
goto FINISHED;
- rc = slap_parseURI( uri, &searchbase, &scope, &filter );
+ rc = slap_parseURI( uri, &searchbase.bv_val, &scope, &filter );
if( rc )
goto FINISHED;
+ searchbase.bv_len = strlen( searchbase.bv_val );
/* Massive shortcut: search scope == base */
if( scope == LDAP_SCOPE_BASE ) {
- DN = ch_strdup( searchbase );
+ DN = ch_strdup( searchbase.bv_val );
goto FINISHED;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "sasl", LDAP_LEVEL_DETAIL1,
"slap_sasl2dn: performing internal search (base=%s, scope=%d)\n",
- searchbase, scope ));
+ searchbase.bv_val, scope ));
#else
Debug( LDAP_DEBUG_TRACE,
"slap_sasl2dn: performing internal search (base=%s, scope=%d)\n",
- searchbase, scope, 0 );
+ searchbase.bv_val, scope, 0 );
#endif
- be = select_backend( searchbase, 0, 1 );
+ be = select_backend( searchbase.bv_val, 0, 1 );
if(( be == NULL ) || ( be->be_search == NULL))
goto FINISHED;
- searchbase = suffix_alias( be, searchbase );
+ suffix_alias( be, &searchbase );
rc = connection_internal_open( &conn, &client, saslname );
if( rc != LDAP_SUCCESS )
goto FINISHED;
- (*be->be_search)( be, conn, conn->c_ops, /*base=*/NULL, searchbase,
+ (*be->be_search)( be, conn, conn->c_ops, /*base=*/NULL, searchbase.bv_val,
scope, /*deref=*/1, /*sizelimit=*/1, /*time=*/0, filter, /*fstr=*/NULL,
/*attrs=*/NULL, /*attrsonly=*/0 );
DN = ldap_get_dn( client, msg );
FINISHED:
- if( searchbase ) ch_free( searchbase );
+ if( searchbase.bv_len ) ch_free( searchbase.bv_val );
if( filter ) filter_free( filter );
if( uri ) ch_free( uri );
if( conn ) connection_internal_close( conn );
static
int slap_sasl_match( char *rule, char *assertDN, char *authc )
{
- char *searchbase=NULL, *dn=NULL;
+ char *dn=NULL;
+ struct berval searchbase = {0, NULL};
int rc, scope;
Backend *be;
Filter *filter=NULL;
#endif
- rc = slap_parseURI( rule, &searchbase, &scope, &filter );
+ rc = slap_parseURI( rule, &searchbase.bv_val, &scope, &filter );
if( rc != LDAP_SUCCESS )
goto CONCLUDED;
+ searchbase.bv_len = strlen( searchbase.bv_val );
/* Massive shortcut: search scope == base */
if( scope == LDAP_SCOPE_BASE ) {
- dn_normalize( searchbase );
- rc = regcomp(®, searchbase, REG_EXTENDED|REG_ICASE|REG_NOSUB);
+ dn_normalize( searchbase.bv_val );
+ rc = regcomp(®, searchbase.bv_val, REG_EXTENDED|REG_ICASE|REG_NOSUB);
if ( rc == 0 ) {
rc = regexec(®, assertDN, 0, NULL, 0);
regfree( ® );
#ifdef NEW_LOGGING
LDAP_LOG(( "sasl", LDAP_LEVEL_DETAIL1,
"slap_sasl_match: performing internal search (base=%s, scope=%d)\n",
- searchbase, scope ));
+ searchbase.bv_val, scope ));
#else
Debug( LDAP_DEBUG_TRACE,
"slap_sasl_match: performing internal search (base=%s, scope=%d)\n",
- searchbase, scope, 0 );
+ searchbase.bv_val, scope, 0 );
#endif
- be = select_backend( searchbase, 0, 1 );
+ be = select_backend( searchbase.bv_val, 0, 1 );
if(( be == NULL ) || ( be->be_search == NULL)) {
rc = LDAP_INAPPROPRIATE_AUTH;
goto CONCLUDED;
}
- searchbase = suffix_alias( be, searchbase );
+ suffix_alias( be, &searchbase );
/* Make an internal connection on which to run the search */
rc = connection_internal_open( &conn, &client, authc );
if( rc != LDAP_SUCCESS )
goto CONCLUDED;
- (*be->be_search)( be, conn, conn->c_ops, /*base=*/NULL, searchbase,
+ (*be->be_search)( be, conn, conn->c_ops, /*base=*/NULL, searchbase.bv_val,
scope, /*deref=*/1, /*sizelimit=*/0, /*time=*/0, filter, /*fstr=*/NULL,
/*attrs=*/NULL, /*attrsonly=*/0 );
rc = LDAP_INAPPROPRIATE_AUTH;
CONCLUDED:
- if( searchbase ) ch_free( searchbase );
+ if( searchbase.bv_len ) ch_free( searchbase.bv_val );
if( filter ) filter_free( filter );
if( conn ) connection_internal_close( conn );
if( res ) ldap_msgfree( res );
}
/* deref the base if needed */
- nbase->bv_val = suffix_alias( be, nbase->bv_val );
- nbase->bv_len = strlen( nbase->bv_val );
+ suffix_alias( be, nbase );
/* actually do the search and send the result(s) */
if ( be->be_search ) {
* given a normalized uppercased dn (or root part),
* return an aliased dn if any of the alias suffixes match
*/
-char *suffix_alias(
+void suffix_alias(
Backend *be,
- char *dn )
+ struct berval *dn )
{
int i, dnLength;
- if(dn == NULL) return NULL;
- if(be == NULL) return dn;
+ if(dn == NULL || be == NULL || dn->bv_len == 0)
+ return;
- dnLength = strlen ( dn );
+ dnLength = dn->bv_len;
for ( i = 0;
be->be_suffixAlias != NULL && be->be_suffixAlias[i] != NULL;
/* alias is longer than dn */
continue;
} else if ( diff > 0 ) {
- if ( ! DN_SEPARATOR(dn[diff-1]) ) {
+ if ( ! DN_SEPARATOR(dn->bv_val[diff-1]) ) {
/* boundary is not at a DN separator */
continue;
}
/* XXX or an escaped separator... oh well */
}
- if (!strcmp(be->be_suffixAlias[i]->bv_val, &dn[diff])) {
- char *oldDN = dn;
- dn = ch_malloc( diff + be->be_suffixAlias[i+1]->bv_len + 1 );
- strncpy( dn, oldDN, diff );
- strcpy( &dn[diff], be->be_suffixAlias[i+1]->bv_val );
+ if (!strcmp(be->be_suffixAlias[i]->bv_val, &dn->bv_val[diff])) {
+ char *oldDN = dn->bv_val;
+ dn->bv_len = diff + be->be_suffixAlias[i+1]->bv_len;
+ dn->bv_val = ch_malloc( dn->bv_len + 1 );
+ strncpy( dn->bv_val, oldDN, diff );
+ strcpy( &dn->bv_val[diff], be->be_suffixAlias[i+1]->bv_val );
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
"suffix_alias: converted \"%s\" to \"%s\"\n",
- oldDN, dn ));
+ oldDN, dn->bv_val ));
#else
Debug( LDAP_DEBUG_ARGS,
"suffix_alias: converted \"%s\" to \"%s\"\n",
- oldDN, dn, 0);
+ oldDN, dn->bv_val, 0);
#endif
free (oldDN);
break;
}
}
-
- return dn;
}