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

Change struct berval ** to BVarray

parent 81e9e868
...@@ -58,7 +58,7 @@ typedef struct AciSetCookie { ...@@ -58,7 +58,7 @@ typedef struct AciSetCookie {
Operation *op; Operation *op;
} AciSetCookie; } AciSetCookie;
char **aci_set_gather (void *cookie, char *name, struct berval *attr); BVarray aci_set_gather (void *cookie, char *name, struct berval *attr);
static int aci_match_set ( struct berval *subj, Backend *be, static int aci_match_set ( struct berval *subj, Backend *be,
Entry *e, Connection *conn, Operation *op, int setref ); Entry *e, Connection *conn, Operation *op, int setref );
...@@ -1021,7 +1021,7 @@ acl_check_modlist( ...@@ -1021,7 +1021,7 @@ acl_check_modlist(
Modifications *mlist Modifications *mlist
) )
{ {
int i; struct berval *bv;
assert( be != NULL ); assert( be != NULL );
...@@ -1098,9 +1098,9 @@ acl_check_modlist( ...@@ -1098,9 +1098,9 @@ acl_check_modlist(
if ( mlist->sml_bvalues == NULL ) { if ( mlist->sml_bvalues == NULL ) {
break; break;
} }
for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) { for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ ) {
if ( ! access_allowed( be, conn, op, e, if ( ! access_allowed( be, conn, op, e,
mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) ) mlist->sml_desc, bv, ACL_WRITE ) )
{ {
return( 0 ); return( 0 );
} }
...@@ -1116,9 +1116,9 @@ acl_check_modlist( ...@@ -1116,9 +1116,9 @@ acl_check_modlist(
} }
break; break;
} }
for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) { for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ ) {
if ( ! access_allowed( be, conn, op, e, if ( ! access_allowed( be, conn, op, e,
mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) ) mlist->sml_desc, bv, ACL_WRITE ) )
{ {
return( 0 ); return( 0 );
} }
...@@ -1202,12 +1202,11 @@ aci_get_part( ...@@ -1202,12 +1202,11 @@ aci_get_part(
return(bv->bv_len); return(bv->bv_len);
} }
char ** BVarray
aci_set_gather (void *cookie, char *name, struct berval *attr) aci_set_gather (void *cookie, char *name, struct berval *attr)
{ {
AciSetCookie *cp = cookie; AciSetCookie *cp = cookie;
struct berval **bvals = NULL; BVarray bvals = NULL;
char **vals = NULL;
struct berval bv, ndn; struct berval bv, ndn;
int i; int i;
...@@ -1224,21 +1223,10 @@ aci_set_gather (void *cookie, char *name, struct berval *attr) ...@@ -1224,21 +1223,10 @@ aci_set_gather (void *cookie, char *name, struct berval *attr)
if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) { if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) {
backend_attribute(cp->be, NULL, NULL, backend_attribute(cp->be, NULL, NULL,
cp->e, &ndn, desc, &bvals); cp->e, &ndn, desc, &bvals);
if (bvals != NULL) {
for (i = 0; bvals[i] != NULL; i++) { }
vals = ch_calloc(i + 1, sizeof(char *));
if (vals != NULL) {
while (--i >= 0) {
vals[i] = bvals[i]->bv_val;
bvals[i]->bv_val = NULL;
}
}
ber_bvecfree(bvals);
}
} }
free(ndn.bv_val); free(ndn.bv_val);
} }
return(vals); return(bvals);
} }
static int static int
...@@ -1251,16 +1239,16 @@ aci_match_set ( ...@@ -1251,16 +1239,16 @@ aci_match_set (
int setref int setref
) )
{ {
char *set = NULL; struct berval set = { 0, NULL };
int rc = 0; int rc = 0;
AciSetCookie cookie; AciSetCookie cookie;
if (setref == 0) { if (setref == 0) {
set = aci_bvstrdup(subj); ber_dupbv( &set, subj );
} else { } else {
struct berval subjdn, ndn = { 0, NULL }; struct berval subjdn, ndn = { 0, NULL };
struct berval setat; struct berval setat;
struct berval **bvals; BVarray bvals;
const char *text; const char *text;
AttributeDescription *desc = NULL; AttributeDescription *desc = NULL;
...@@ -1289,9 +1277,15 @@ aci_match_set ( ...@@ -1289,9 +1277,15 @@ aci_match_set (
backend_attribute(be, NULL, NULL, e, backend_attribute(be, NULL, NULL, e,
&ndn, desc, &bvals); &ndn, desc, &bvals);
if ( bvals != NULL ) { if ( bvals != NULL ) {
if ( bvals[0] != NULL ) if ( bvals[0].bv_val != NULL ) {
set = ch_strdup(bvals[0]->bv_val); int i;
ber_bvecfree(bvals); set = bvals[0];
bvals[0].bv_val = NULL;
for (i=1;bvals[i].bv_val;i++);
bvals[0].bv_val = bvals[i-1].bv_val;
bvals[i-1].bv_val = NULL;
}
bvarray_free(bvals);
} }
} }
if (ndn.bv_val) if (ndn.bv_val)
...@@ -1300,13 +1294,13 @@ aci_match_set ( ...@@ -1300,13 +1294,13 @@ aci_match_set (
ch_free(subjdn.bv_val); ch_free(subjdn.bv_val);
} }
if (set != NULL) { if (set.bv_val != NULL) {
cookie.be = be; cookie.be = be;
cookie.e = e; cookie.e = e;
cookie.conn = conn; cookie.conn = conn;
cookie.op = op; cookie.op = op;
rc = (set_filter(aci_set_gather, &cookie, set, op->o_ndn.bv_val, e->e_ndn, NULL) > 0); rc = (set_filter(aci_set_gather, &cookie, &set, op->o_ndn.bv_val, e->e_ndn, NULL) > 0);
ch_free(set); ch_free(set.bv_val);
} }
return(rc); return(rc);
} }
......
...@@ -552,13 +552,11 @@ parse_acl( ...@@ -552,13 +552,11 @@ parse_acl(
{ {
int rc; int rc;
struct berval val; struct berval vals[2];
struct berval *vals[2];
val.bv_val = b->a_group_oc->soc_oid; vals[0].bv_val = b->a_group_oc->soc_oid;
val.bv_len = strlen(val.bv_val); vals[0].bv_len = strlen(vals[0].bv_val);
vals[0] = &val; vals[1].bv_val = NULL;
vals[1] = NULL;
rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL ); rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
......
...@@ -40,9 +40,9 @@ do_add( Connection *conn, Operation *op ) ...@@ -40,9 +40,9 @@ do_add( Connection *conn, Operation *op )
ber_tag_t tag; ber_tag_t tag;
Entry *e; Entry *e;
Backend *be; Backend *be;
LDAPModList *modlist = NULL; Modifications *modlist = NULL;
LDAPModList **modtail = &modlist; Modifications **modtail = &modlist;
Modifications *mods = NULL; Modifications tmp;
const char *text; const char *text;
int rc = LDAP_SUCCESS; int rc = LDAP_SUCCESS;
int manageDSAit; int manageDSAit;
...@@ -112,11 +112,9 @@ do_add( Connection *conn, Operation *op ) ...@@ -112,11 +112,9 @@ do_add( Connection *conn, Operation *op )
for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT; for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
tag = ber_next_element( ber, &len, last ) ) tag = ber_next_element( ber, &len, last ) )
{ {
LDAPModList *mod = (LDAPModList *) ch_malloc( sizeof(LDAPModList) ); Modifications *mod;
mod->ml_op = LDAP_MOD_ADD;
mod->ml_next = NULL;
rc = ber_scanf( ber, "{a{V}}", &mod->ml_type, &mod->ml_bvalues ); rc = ber_scanf( ber, "{o{W}}", &tmp.sml_type, &tmp.sml_bvalues );
if ( rc == LBER_ERROR ) { if ( rc == LBER_ERROR ) {
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
...@@ -128,28 +126,36 @@ do_add( Connection *conn, Operation *op ) ...@@ -128,28 +126,36 @@ do_add( Connection *conn, Operation *op )
send_ldap_disconnect( conn, op, send_ldap_disconnect( conn, op,
LDAP_PROTOCOL_ERROR, "decoding error" ); LDAP_PROTOCOL_ERROR, "decoding error" );
rc = -1; rc = -1;
free( mod );
goto done; goto done;
} }
if ( mod->ml_bvalues == NULL ) { if ( tmp.sml_bvalues == NULL ) {
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_INFO, LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
"do_add: conn %d no values for type %s\n", "do_add: conn %d no values for type %s\n",
conn->c_connid, mod->ml_type )); conn->c_connid, tmp.sml_type.bv_val ));
#else #else
Debug( LDAP_DEBUG_ANY, "no values for type %s\n", Debug( LDAP_DEBUG_ANY, "no values for type %s\n",
mod->ml_type, 0, 0 ); tmp.sml_type.bv_val, 0, 0 );
#endif #endif
send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR, send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR,
NULL, "no values for attribute type", NULL, NULL ); NULL, "no values for attribute type", NULL, NULL );
free( mod->ml_type ); free( tmp.sml_type.bv_val );
free( mod );
goto done; goto done;
} }
mod = (Modifications *) ch_malloc( sizeof(Modifications)
+ tmp.sml_type.bv_len + 1);
mod->sml_op = LDAP_MOD_ADD;
mod->sml_next = NULL;
mod->sml_desc = NULL;
mod->sml_type.bv_val = (char *)(mod+1);
strcpy(mod->sml_type.bv_val, tmp.sml_type.bv_val);
mod->sml_type.bv_len = tmp.sml_type.bv_len;
mod->sml_bvalues = tmp.sml_bvalues;
*modtail = mod; *modtail = mod;
modtail = &mod->ml_next; modtail = &mod->sml_next;
} }
if ( ber_scanf( ber, /*{*/ "}") == LBER_ERROR ) { if ( ber_scanf( ber, /*{*/ "}") == LBER_ERROR ) {
...@@ -184,7 +190,7 @@ do_add( Connection *conn, Operation *op ) ...@@ -184,7 +190,7 @@ do_add( Connection *conn, Operation *op )
Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d ADD dn=\"%s\"\n", Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d ADD dn=\"%s\"\n",
op->o_connid, op->o_opid, e->e_dn, 0, 0 ); op->o_connid, op->o_opid, e->e_dn, 0, 0 );
if( e->e_ndn == NULL || *e->e_ndn == '\0' ) { if( e->e_nname.bv_len == 0 ) {
/* protocolError may be a more appropriate error */ /* protocolError may be a more appropriate error */
send_ldap_result( conn, op, rc = LDAP_ALREADY_EXISTS, send_ldap_result( conn, op, rc = LDAP_ALREADY_EXISTS,
NULL, "root DSE already exists", NULL, "root DSE already exists",
...@@ -209,13 +215,13 @@ do_add( Connection *conn, Operation *op ) ...@@ -209,13 +215,13 @@ do_add( Connection *conn, Operation *op )
*/ */
be = select_backend( &e->e_nname, manageDSAit, 0 ); be = select_backend( &e->e_nname, manageDSAit, 0 );
if ( be == NULL ) { if ( be == NULL ) {
struct berval **ref = referral_rewrite( default_referral, BVarray ref = referral_rewrite( default_referral,
NULL, &e->e_name, LDAP_SCOPE_DEFAULT ); NULL, &e->e_name, LDAP_SCOPE_DEFAULT );
send_ldap_result( conn, op, rc = LDAP_REFERRAL, send_ldap_result( conn, op, rc = LDAP_REFERRAL,
NULL, NULL, ref ? ref : default_referral, NULL ); NULL, NULL, ref ? ref : default_referral, NULL );
ber_bvecfree( ref ); bvarray_free( ref );
goto done; goto done;
} }
...@@ -250,7 +256,7 @@ do_add( Connection *conn, Operation *op ) ...@@ -250,7 +256,7 @@ do_add( Connection *conn, Operation *op )
char textbuf[SLAP_TEXT_BUFLEN]; char textbuf[SLAP_TEXT_BUFLEN];
size_t textlen = sizeof textbuf; size_t textlen = sizeof textbuf;
rc = slap_modlist2mods( modlist, update, &mods, &text, rc = slap_mods_check( modlist, update, &text,
textbuf, textlen ); textbuf, textlen );
if( rc != LDAP_SUCCESS ) { if( rc != LDAP_SUCCESS ) {
...@@ -262,15 +268,14 @@ do_add( Connection *conn, Operation *op ) ...@@ -262,15 +268,14 @@ do_add( Connection *conn, Operation *op )
if ( (be->be_lastmod == ON || (be->be_lastmod == UNDEFINED && if ( (be->be_lastmod == ON || (be->be_lastmod == UNDEFINED &&
global_lastmod == ON)) && !repl_user ) global_lastmod == ON)) && !repl_user )
{ {
Modifications **modstail; for( modtail = &modlist;
for( modstail = &mods; *modtail != NULL;
*modstail != NULL; modtail = &(*modtail)->sml_next )
modstail = &(*modstail)->sml_next )
{ {
assert( (*modstail)->sml_op == LDAP_MOD_ADD ); assert( (*modtail)->sml_op == LDAP_MOD_ADD );
assert( (*modstail)->sml_desc != NULL ); assert( (*modtail)->sml_desc != NULL );
} }
rc = slap_mods_opattrs( op, mods, modstail, &text, rc = slap_mods_opattrs( op, modlist, modtail, &text,
textbuf, textlen ); textbuf, textlen );
if( rc != LDAP_SUCCESS ) { if( rc != LDAP_SUCCESS ) {
send_ldap_result( conn, op, rc, send_ldap_result( conn, op, rc,
...@@ -279,7 +284,7 @@ do_add( Connection *conn, Operation *op ) ...@@ -279,7 +284,7 @@ do_add( Connection *conn, Operation *op )
} }
} }
rc = slap_mods2entry( mods, &e, &text ); rc = slap_mods2entry( modlist, &e, &text );
if( rc != LDAP_SUCCESS ) { if( rc != LDAP_SUCCESS ) {
send_ldap_result( conn, op, rc, send_ldap_result( conn, op, rc,
NULL, text, NULL, NULL ); NULL, text, NULL, NULL );
...@@ -299,15 +304,15 @@ do_add( Connection *conn, Operation *op ) ...@@ -299,15 +304,15 @@ do_add( Connection *conn, Operation *op )
#ifndef SLAPD_MULTIMASTER #ifndef SLAPD_MULTIMASTER
} else { } else {
struct berval **defref = be->be_update_refs BVarray defref = be->be_update_refs
? be->be_update_refs : default_referral; ? be->be_update_refs : default_referral;
struct berval **ref = referral_rewrite( defref, BVarray ref = referral_rewrite( defref,
NULL, &e->e_name, LDAP_SCOPE_DEFAULT ); NULL, &e->e_name, LDAP_SCOPE_DEFAULT );
send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL, send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
ref ? ref : defref, NULL ); ref ? ref : defref, NULL );
ber_bvecfree( ref ); bvarray_free( ref );
#endif #endif
} }
} else { } else {
...@@ -325,10 +330,7 @@ done: ...@@ -325,10 +330,7 @@ done:
free( dn.bv_val ); free( dn.bv_val );
if( modlist != NULL ) { if( modlist != NULL ) {
slap_modlist_free( modlist ); slap_mods_free( modlist );
}
if( mods != NULL ) {
slap_mods_free( mods );
} }
if( e != NULL ) { if( e != NULL ) {
entry_free( e ); entry_free( e );
...@@ -358,20 +360,20 @@ static int slap_mods2entry( ...@@ -358,20 +360,20 @@ static int slap_mods2entry(
#ifdef SLURPD_FRIENDLY #ifdef SLURPD_FRIENDLY
ber_len_t i,j; ber_len_t i,j;
for( i=0; attr->a_vals[i]; i++ ) { for( i=0; attr->a_vals[i].bv_val; i++ ) {
/* count them */ /* count them */
} }
for( j=0; mods->sml_bvalues[j]; j++ ) { for( j=0; mods->sml_bvalues[j].bv_val; j++ ) {
/* count them */ /* count them */
} }
j++; /* NULL */ j++; /* NULL */
attr->a_vals = ch_realloc( attr->a_vals, attr->a_vals = ch_realloc( attr->a_vals,
sizeof( struct berval * ) * (i+j) ); sizeof( struct berval ) * (i+j) );
/* should check for duplicates */ /* should check for duplicates */
AC_MEMCPY( &attr->a_vals[i], mods->sml_bvalues, AC_MEMCPY( &attr->a_vals[i], mods->sml_bvalues,
sizeof( struct berval * ) * j ); sizeof( struct berval ) * j );
/* trim the mods array */ /* trim the mods array */
ch_free( mods->sml_bvalues ); ch_free( mods->sml_bvalues );
......
...@@ -402,25 +402,23 @@ at_index_print( void ) ...@@ -402,25 +402,23 @@ at_index_print( void )
int int
at_schema_info( Entry *e ) at_schema_info( Entry *e )
{ {
struct berval val; struct berval vals[2];
struct berval *vals[2];
AttributeType *at; AttributeType *at;
AttributeDescription *ad_attributeTypes = slap_schema.si_ad_attributeTypes; AttributeDescription *ad_attributeTypes = slap_schema.si_ad_attributeTypes;
vals[0] = &val; vals[1].bv_val = NULL;
vals[1] = NULL;
for ( at = attr_list; at; at = at->sat_next ) { for ( at = attr_list; at; at = at->sat_next ) {
if ( ldap_attributetype2bv( &at->sat_atype, &val ) == NULL ) { if ( ldap_attributetype2bv( &at->sat_atype, vals ) == NULL ) {
return -1; return -1;
} }
#if 0 #if 0
Debug( LDAP_DEBUG_TRACE, "Merging at [%ld] %s\n", Debug( LDAP_DEBUG_TRACE, "Merging at [%ld] %s\n",
(long) val.bv_len, val.bv_val, 0 ); (long) vals[0].bv_len, vals[0].bv_val, 0 );
#endif #endif
attr_merge( e, ad_attributeTypes, vals ); attr_merge( e, ad_attributeTypes, vals );
ldap_memfree( val.bv_val ); ldap_memfree( vals[0].bv_val );
} }
return 0; return 0;
} }
......
...@@ -29,7 +29,7 @@ static void at_index_print( void ) {}; ...@@ -29,7 +29,7 @@ static void at_index_print( void ) {};
void void
attr_free( Attribute *a ) attr_free( Attribute *a )
{ {
ber_bvecfree( a->a_vals ); bvarray_free( a->a_vals );
free( a ); free( a );
} }
...@@ -55,19 +55,18 @@ Attribute *attr_dup( Attribute *a ) ...@@ -55,19 +55,18 @@ Attribute *attr_dup( Attribute *a )
if( a->a_vals != NULL ) { if( a->a_vals != NULL ) {
int i; int i;
for( i=0; a->a_vals[i] != NULL; i++ ) { for( i=0; a->a_vals[i].bv_val != NULL; i++ ) {
/* EMPTY */ ; /* EMPTY */ ;
} }
tmp->a_vals = ch_malloc((i+1) * sizeof(struct berval*)); tmp->a_vals = ch_malloc((i+1) * sizeof(struct berval));
for( i=0; a->a_vals[i] != NULL; i++ ) { for( i=0; a->a_vals[i].bv_val != NULL; i++ ) {
tmp->a_vals[i] = ber_bvdup( a->a_vals[i] ); ber_dupbv( &tmp->a_vals[i], &a->a_vals[i] );
if( tmp->a_vals[i].bv_val == NULL ) break;
if( tmp->a_vals[i] == NULL ) break;
} }
tmp->a_vals[i] = NULL; tmp->a_vals[i].bv_val = NULL;
} else { } else {
tmp->a_vals = NULL; tmp->a_vals = NULL;
...@@ -110,7 +109,7 @@ int ...@@ -110,7 +109,7 @@ int
attr_merge( attr_merge(
Entry *e, Entry *e,
AttributeDescription *desc, AttributeDescription *desc,
struct berval **vals ) BVarray vals )
{ {
Attribute **a; Attribute **a;
......
...@@ -120,7 +120,7 @@ retry: rc = txn_abort( ltid ); ...@@ -120,7 +120,7 @@ retry: rc = txn_abort( ltid );
if ( p == NULL ) { if ( p == NULL ) {
char *matched_dn = NULL; char *matched_dn = NULL;
struct berval **refs; BVarray refs;
if ( matched != NULL ) { if ( matched != NULL ) {
matched_dn = ch_strdup( matched->e_dn ); matched_dn = ch_strdup( matched->e_dn );
...@@ -141,7 +141,7 @@ retry: rc = txn_abort( ltid ); ...@@ -141,7 +141,7 @@ retry: rc = txn_abort( ltid );
send_ldap_result( conn, op, rc = LDAP_REFERRAL, send_ldap_result( conn, op, rc = LDAP_REFERRAL,
matched_dn, NULL, refs, NULL ); matched_dn, NULL, refs, NULL );