Commit affa8f5a authored by Howard Chu's avatar Howard Chu
Browse files

More struct berval conversions

parent dc4fe017
......@@ -25,7 +25,7 @@ ldbm_back_add(
)
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
char *pdn;
struct berval pdn;
Entry *p = NULL;
int rootlock = 0;
int rc;
......@@ -45,7 +45,7 @@ ldbm_back_add(
/* nobody else can add until we lock our parent */
ldap_pvt_thread_mutex_lock(&li->li_add_mutex);
if ( ( rc = dn2id( be, e->e_ndn, &id ) ) || id != NOID ) {
if ( ( rc = dn2id( be, &e->e_nname, &id ) ) || id != NOID ) {
/* if (rc) something bad happened to ldbm cache */
ldap_pvt_thread_mutex_unlock(&li->li_add_mutex);
send_ldap_result( conn, op,
......@@ -80,15 +80,17 @@ ldbm_back_add(
* add the entry.
*/
pdn = dn_parent( be, e->e_ndn );
pdn.bv_val = dn_parent( be, e->e_ndn );
if (pdn.bv_val && pdn.bv_val[0])
pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn);
else
pdn.bv_len = 0;
if( pdn != NULL && *pdn != '\0' ) {
if( pdn.bv_len ) {
Entry *matched = NULL;
assert( *pdn != '\0' );
/* get parent with writer lock */
if ( (p = dn2entry_w( be, pdn, &matched )) == NULL ) {
if ( (p = dn2entry_w( be, &pdn, &matched )) == NULL ) {
char *matched_dn = NULL;
struct berval **refs;
......@@ -198,8 +200,8 @@ ldbm_back_add(
}
} else {
if(pdn != NULL) {
assert( *pdn == '\0' );
if(pdn.bv_val != NULL) {
assert( *pdn.bv_val == '\0' );
}
/* no parent, must be adding entry to root */
......@@ -239,11 +241,11 @@ ldbm_back_add(
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
"ldbm_back_add: %s add denied.\n",
pdn == NULL ? "suffix"
pdn.bv_val == NULL ? "suffix"
: "entry at root" ));
#else
Debug( LDAP_DEBUG_TRACE, "%s add denied\n",
pdn == NULL ? "suffix"
pdn.bv_val == NULL ? "suffix"
: "entry at root", 0, 0 );
#endif
......@@ -340,7 +342,7 @@ ldbm_back_add(
}
/* dn2id index */
if ( dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) {
if ( dn2id_add( be, &e->e_nname, e->e_id ) != 0 ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
"ldbm_back_add: dn2id_add failed.\n" ));
......@@ -367,7 +369,7 @@ ldbm_back_add(
#endif
/* FIXME: delete attr indices? */
(void) dn2id_delete( be, e->e_ndn, e->e_id );
(void) dn2id_delete( be, &e->e_nname, e->e_id );
send_ldap_result( conn, op, LDAP_OTHER,
NULL, "entry store failed", NULL, NULL );
......
......@@ -14,19 +14,21 @@
#include "proto-back-ldbm.h"
static char* get_alias_dn(
static int get_alias_dn(
Entry *e,
struct berval *al,
int *err,
const char **errmsg );
static char* new_superior(
const char *dn,
const char *oldSup,
const char *newSup );
static void new_superior(
struct berval *dn,
struct berval *oldSup,
struct berval *newSup,
struct berval *res );
static int dnlist_subordinate(
char** dnlist,
const char *dn );
BVarray dnlist,
struct berval *dn );
Entry *deref_internal_r(
Backend* be,
......@@ -36,12 +38,12 @@ Entry *deref_internal_r(
Entry** matched,
const char** text )
{
char *dn;
struct berval dn;
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
Entry *entry;
Entry *sup;
unsigned depth;
char **dnlist;
BVarray dnlist;
assert( ( alias != NULL && dn_in == NULL )
|| ( alias == NULL && dn_in != NULL ) );
......@@ -51,22 +53,22 @@ Entry *deref_internal_r(
*text = NULL;
if( alias == NULL ) {
dn = ch_strdup( dn_in->bv_val );
entry = dn2entry_r( be, dn, &sup );
ber_dupbv( &dn, dn_in );
entry = dn2entry_r( be, &dn, &sup );
} else {
dn = ch_strdup( alias->e_ndn );
ber_dupbv( &dn, &alias->e_nname );
entry = alias;
sup = NULL;
}
dnlist = NULL;
charray_add( &dnlist, dn );
bvarray_add( &dnlist, &dn );
for( depth=0 ; ; depth++ ) {
if( entry != NULL ) {
Entry *newe;
char *aliasDN;
struct berval aliasDN;
/* have entry, may be an alias */
......@@ -85,17 +87,15 @@ Entry *deref_internal_r(
}
/* deref entry */
aliasDN = get_alias_dn( entry, err, text );
if( aliasDN == NULL ) {
if( get_alias_dn( entry, &aliasDN, err, text )) {
*matched = entry;
entry = NULL;
break;
}
/* check if aliasDN is a subordinate of any DN in our list */
if( dnlist_subordinate( dnlist, aliasDN ) ) {
ch_free( aliasDN );
if( dnlist_subordinate( dnlist, &aliasDN ) ) {
ch_free( aliasDN.bv_val );
*matched = entry;
entry = NULL;
*err = LDAP_ALIAS_PROBLEM;
......@@ -105,15 +105,15 @@ Entry *deref_internal_r(
/* attempt to dereference alias */
newe = dn2entry_r( be, aliasDN, &sup );
ch_free( aliasDN );
newe = dn2entry_r( be, &aliasDN, &sup );
ch_free( aliasDN.bv_val );
if( newe != NULL ) {
free( dn );
free( dn.bv_val );
cache_return_entry_r(&li->li_cache, entry );
entry = newe;
dn = ch_strdup( entry->e_ndn );
charray_add( &dnlist, dn );
ber_dupbv( &dn, &entry->e_nname );
bvarray_add( &dnlist, &dn );
continue;
}
......@@ -130,8 +130,8 @@ Entry *deref_internal_r(
/* have superior, may be an alias */
Entry *newe;
Entry *newSup;
char *supDN;
char *aliasDN;
struct berval supDN;
struct berval aliasDN;
if( !is_entry_alias( sup ) ) {
/* entry is not an alias */
......@@ -150,27 +150,17 @@ Entry *deref_internal_r(
}
/* deref entry */
supDN = get_alias_dn( sup, err, text );
if( supDN == NULL ) {
if( get_alias_dn( sup, &supDN, err, text )) {
*matched = sup;
break;
}
aliasDN = new_superior( dn, sup->e_ndn, supDN );
free(supDN);
if( aliasDN == NULL ) {
free(aliasDN);
*matched = sup;
*err = LDAP_ALIAS_PROBLEM;
*text = "superior alias problem";
break;
}
new_superior( &dn, &sup->e_nname, &supDN, &aliasDN );
free(supDN.bv_val);
/* check if aliasDN is a subordinate of any DN in our list */
if( dnlist_subordinate( dnlist, aliasDN ) ) {
free(aliasDN);
if( dnlist_subordinate( dnlist, &aliasDN ) ) {
free(aliasDN.bv_val);
*matched = entry;
entry = NULL;
*err = LDAP_ALIAS_PROBLEM;
......@@ -179,24 +169,23 @@ Entry *deref_internal_r(
}
/* attempt to dereference alias */
newe = dn2entry_r( be, aliasDN, &newSup );
newe = dn2entry_r( be, &aliasDN, &newSup );
if( newe != NULL ) {
free(aliasDN);
free( dn );
free(aliasDN.bv_val);
free( dn.bv_val );
cache_return_entry_r(&li->li_cache, sup );
entry = newe;
dn = ch_strdup( entry->e_ndn );
charray_add( &dnlist, dn );
ber_dupbv( &dn, &entry->e_nname );
bvarray_add( &dnlist, &dn );
continue;
}
if ( newSup != NULL ) {
free( dn );
free( dn.bv_val );
cache_return_entry_r(&li->li_cache, sup );
sup = newSup;
dn = aliasDN;
ber_dupbv( &dn, &aliasDN );
continue;
}
......@@ -208,19 +197,19 @@ Entry *deref_internal_r(
}
}
free( dn );
charray_free( dnlist );
free( dn.bv_val );
bvarray_free( dnlist );
return entry;
}
static char* get_alias_dn(
static int get_alias_dn(
Entry *e,
struct berval *ndn,
int *err,
const char **errmsg )
{
int rc;
struct berval ndn;
Attribute *a;
AttributeDescription *aliasedObjectName
= slap_schema.si_ad_aliasedObjectName;
......@@ -233,7 +222,7 @@ static char* get_alias_dn(
*/
*err = LDAP_ALIAS_PROBLEM;
*errmsg = "alias missing aliasedObjectName attribute";
return NULL;
return -1;
}
/*
......@@ -245,60 +234,58 @@ static char* get_alias_dn(
*/
*err = LDAP_ALIAS_PROBLEM;
*errmsg = "alias missing aliasedObjectName value";
return NULL;
return -1;
}
if( a->a_vals[1] != NULL ) {
*err = LDAP_ALIAS_PROBLEM;
*errmsg = "alias has multivalued aliasedObjectName";
return NULL;
return -1;
}
rc = dnNormalize2( NULL, a->a_vals[0], &ndn );
rc = dnNormalize2( NULL, a->a_vals[0], ndn );
if( rc != LDAP_SUCCESS ) {
*err = LDAP_ALIAS_PROBLEM;
*errmsg = "alias aliasedObjectName value is invalid";
return NULL;
return -1;
}
return ndn.bv_val;
return 0;
}
static char* new_superior(
const char *dn,
const char *oldSup,
const char *newSup )
static void new_superior(
struct berval *dn,
struct berval *oldSup,
struct berval *newSup,
struct berval *newDN )
{
char *newDN;
size_t dnlen, olen, nlen;
assert( dn && oldSup && newSup );
assert( dn && oldSup && newSup && newDN );
dnlen = strlen( dn );
olen = strlen( oldSup );
nlen = strlen( newSup );
dnlen = dn->bv_len;
olen = oldSup->bv_len;
nlen = newSup->bv_len;
newDN = ch_malloc( dnlen - olen + nlen + 1 );
newDN->bv_val = ch_malloc( dnlen - olen + nlen + 1 );
AC_MEMCPY( newDN, dn, dnlen - olen );
AC_MEMCPY( &newDN[dnlen - olen], newSup, nlen );
newDN[dnlen - olen + nlen] = '\0';
AC_MEMCPY( newDN->bv_val, dn->bv_val, dnlen - olen );
AC_MEMCPY( &newDN->bv_val[dnlen - olen], newSup->bv_val, nlen );
newDN->bv_val[dnlen - olen + nlen] = '\0';
return newDN;
return;
}
static int dnlist_subordinate(
char** dnlist,
const char *dn )
BVarray dnlist,
struct berval *dn )
{
int i;
assert( dnlist );
for( i = 0; dnlist[i] != NULL; i++ ) {
if( dn_issuffix( dnlist[i], dn ) ) {
for( ; dnlist->bv_val != NULL; dnlist++ ) {
if( dnIsSuffix( dnlist, dn ) ) {
return 1;
}
}
return 0;
}
......@@ -74,7 +74,7 @@ ldbm_back_attribute(
} else {
/* can we find entry with reader lock */
if ((e = dn2entry_r(be, entry_ndn->bv_val, NULL )) == NULL) {
if ((e = dn2entry_r(be, entry_ndn, NULL )) == NULL) {
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
"ldbm_back_attribute: cannot find entry (%s)\n",
......
......@@ -54,7 +54,7 @@ ldbm_back_bind(
dn = ndn;
/* get entry with reader lock */
if ( (e = dn2entry_r( be, dn->bv_val, &matched )) == NULL ) {
if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
char *matched_dn = NULL;
struct berval **refs = NULL;
......
......@@ -563,41 +563,11 @@ cache_update_entry(
return( 0 );
}
/*
* cache_find_entry_dn2id - find an entry in the cache, given dn
*/
ID
cache_find_entry_dn2id(
Backend *be,
Cache *cache,
const char *dn
)
{
int rc;
struct berval bv;
struct berval ndn;
ID id;
bv.bv_val = (char *)dn;
bv.bv_len = strlen( dn );
rc = dnNormalize2( NULL, &bv, &ndn );
if( rc != LDAP_SUCCESS ) {
return NOID;
}
id = cache_find_entry_ndn2id( be, cache, ndn.bv_val );
free( ndn.bv_val );
return ( id );
}
ID
cache_find_entry_ndn2id(
Backend *be,
Cache *cache,
const char *ndn
struct berval *ndn
)
{
Entry e, *ep;
......@@ -605,7 +575,7 @@ cache_find_entry_ndn2id(
int count = 0;
/* this function is always called with normalized DN */
e.e_ndn = (char *)ndn;
e.e_nname = *ndn;
try_again:
/* set cache mutex */
......
......@@ -34,7 +34,7 @@ ldbm_back_compare(
int manageDSAit = get_manageDSAit( op );
/* get entry with reader lock */
if ( (e = dn2entry_r( be, ndn->bv_val, &matched )) == NULL ) {
if ( (e = dn2entry_r( be, ndn, &matched )) == NULL ) {
char *matched_dn = NULL;
struct berval **refs = NULL;
......
......@@ -27,7 +27,7 @@ ldbm_back_delete(
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
Entry *matched;
char *pdn = NULL;
struct berval pdn;
Entry *e, *p = NULL;
int rootlock = 0;
int rc = -1;
......@@ -42,7 +42,7 @@ ldbm_back_delete(
#endif
/* get entry with writer lock */
if ( (e = dn2entry_w( be, ndn->bv_val, &matched )) == NULL ) {
if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
char *matched_dn = NULL;
struct berval **refs;
......@@ -115,8 +115,9 @@ ldbm_back_delete(
}
/* delete from parent's id2children entry */
if( (pdn = dn_parent( be, e->e_ndn )) != NULL && pdn[ 0 ] != '\0' ) {
if( (p = dn2entry_w( be, pdn, NULL )) == NULL) {
if( (pdn.bv_val = dn_parent( be, e->e_ndn )) != NULL && pdn.bv_val[ 0 ] != '\0' ) {
pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn);
if( (p = dn2entry_w( be, &pdn, NULL )) == NULL) {
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
"ldbm_back_delete: parent of (%s) does not exist\n", dn ));
......@@ -201,7 +202,7 @@ ldbm_back_delete(
}
/* delete from dn2id mapping */
if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
if ( dn2id_delete( be, &e->e_nname, e->e_id ) != 0 ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
"ldbm_back_delete: (%s) operations error\n",
......
......@@ -19,7 +19,7 @@
int
dn2id_add(
Backend *be,
const char *dn,
struct berval *dn,
ID id
)
{
......@@ -30,9 +30,9 @@ dn2id_add(
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
"dn2id_add: (%s):%ld\n", dn, id ));
"dn2id_add: (%s):%ld\n", dn->bv_val, id ));
#else
Debug( LDAP_DEBUG_TRACE, "=> dn2id_add( \"%s\", %ld )\n", dn, id, 0 );
Debug( LDAP_DEBUG_TRACE, "=> dn2id_add( \"%s\", %ld )\n", dn->bv_val, id, 0 );
#endif
assert( id != NOID );
......@@ -51,12 +51,12 @@ dn2id_add(
}
ldbm_datum_init( key );
key.dsize = strlen( dn ) + 2;
key.dsize = dn->bv_len + 2;
buf = ch_malloc( key.dsize );
key.dptr = buf;
buf[0] = DN_BASE_PREFIX;
ptr = buf + 1;
strcpy( ptr, dn );
strcpy( ptr, dn->bv_val );
ldbm_datum_init( data );
data.dptr = (char *) &id;
......@@ -118,7 +118,7 @@ dn2id_add(
int
dn2id(
Backend *be,
const char *dn,
struct berval *dn,
ID *idp
)
{
......@@ -128,9 +128,9 @@ dn2id(
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
"dn2id: (%s)\n", dn ));
"dn2id: (%s)\n", dn->bv_val ));
#else
Debug( LDAP_DEBUG_TRACE, "=> dn2id( \"%s\" )\n", dn, 0, 0 );
Debug( LDAP_DEBUG_TRACE, "=> dn2id( \"%s\" )\n", dn->bv_val, 0, 0 );
#endif
assert( idp );
......@@ -167,9 +167,9 @@ dn2id(
ldbm_datum_init( key );
key.dsize = strlen( dn ) + 2;
key.dsize = dn->bv_len + 2;
key.dptr = ch_malloc( key.dsize );
sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn );
sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn->bv_val );
data = ldbm_cache_fetch( db, key );
......@@ -264,7 +264,7 @@ dn2idl(
int
dn2id_delete(
Backend *be,
const char *dn,
struct berval *dn,
ID id
)
{
......@@ -275,9 +275,9 @@ dn2id_delete(
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
"dn2id_delete: (%s)%ld\n", dn, id ));
"dn2id_delete: (%s)%ld\n", dn->bv_val, id ));
#else
Debug( LDAP_DEBUG_TRACE, "=> dn2id_delete( \"%s\", %ld )\n", dn, id, 0 );
Debug( LDAP_DEBUG_TRACE, "=> dn2id_delete( \"%s\", %ld )\n", dn->bv_val, id, 0 );
#endif
......@@ -298,12 +298,12 @@ dn2id_delete(
}
ldbm_datum_init( key );
key.dsize = strlen( dn ) + 2;
key.dsize = dn->bv_len + 2;
buf = ch_malloc( key.dsize );
key.dptr = buf;
buf[0] = DN_BASE_PREFIX;
ptr = buf + 1;
strcpy( ptr, dn );
strcpy( ptr, dn->bv_val );
rc = ldbm_cache_delete( db, key );
......@@ -364,22 +364,22 @@ dn2id_delete(
Entry *
dn2entry_rw(
Backend *be,
const char *dn,