X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fentry.c;h=f5829d395af02a3555138d88234b8df301b6e68e;hb=804490a8b12a94a19e7c1a8710a7d8a2fb7d5477;hp=6ae8ba512b075eb7f1f2da3c81e9cb28ab8a6d32;hpb=763c0de59b423f88b8a0f2aa362fe6c37b4007b6;p=openldap diff --git a/servers/slapd/entry.c b/servers/slapd/entry.c index 6ae8ba512b..f5829d395a 100644 --- a/servers/slapd/entry.c +++ b/servers/slapd/entry.c @@ -1,7 +1,7 @@ /* entry.c - routines for dealing with entries */ /* $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 */ @@ -24,7 +24,7 @@ static int emaxsize;/* max size of ebuf */ /* * Empty root entry */ -const Entry slap_entry_root = { NOID, { 0, "" }, { 0, "" }, NULL, NULL }; +const Entry slap_entry_root = { NOID, { 0, "" }, { 0, "" }, NULL, 0, { 0, "" }, NULL }; int entry_destroy(void) { @@ -71,7 +71,7 @@ str2entry( char *s ) #endif /* initialize reader/writer lock */ - e = (Entry *) ch_malloc( sizeof(Entry) ); + e = (Entry *) ch_calloc( 1, sizeof(Entry) ); if( e == NULL ) { #ifdef NEW_LOGGING @@ -87,12 +87,6 @@ str2entry( char *s ) /* initialize entry */ e->e_id = NOID; - e->e_name.bv_val = NULL; - e->e_name.bv_len = 0; - e->e_nname.bv_val = NULL; - e->e_nname.bv_len = 0; - e->e_attrs = NULL; - e->e_private = NULL; /* dn + attributes */ vals[1].bv_val = NULL; @@ -115,8 +109,6 @@ str2entry( char *s ) } if ( strcasecmp( type, "dn" ) == 0 ) { - struct berval *pdn = NULL; - free( type ); if ( e->e_dn != NULL ) { @@ -137,22 +129,21 @@ str2entry( char *s ) } rc = dnPrettyNormal( NULL, &vals[0], &e->e_name, &e->e_nname ); - free( vals[0].bv_val ); if( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG(( "operation", LDAP_LEVEL_DETAIL1, "str2entry: " "entry %ld has invalid DN \"%s\"\n", - (long) e->e_id, - pdn->bv_val ? pdn->bv_val : "" )); + (long) e->e_id, vals[0].bv_val )); #else Debug( LDAP_DEBUG_ANY, "str2entry: " "entry %ld has invalid DN \"%s\"\n", - (long) e->e_id, - pdn->bv_val ? pdn->bv_val : "", 0 ); + (long) e->e_id, vals[0].bv_val, 0 ); #endif entry_free( e ); + free( vals[0].bv_val ); return NULL; } + free( vals[0].bv_val ); continue; } @@ -314,6 +305,8 @@ entry2str( int i; ber_len_t tmplen; + assert( e != NULL ); + /* * In string format, an entry looks like this: * dn: \n @@ -369,6 +362,11 @@ entry_free( Entry *e ) e->e_ndn = NULL; } + if ( e->e_bv.bv_val != NULL ) { + free( e->e_bv.bv_val ); + e->e_bv.bv_val = NULL; + } + /* free attributes */ attrs_free( e->e_attrs ); e->e_attrs = NULL; @@ -561,10 +559,10 @@ int entry_decode(struct berval *bv, Entry **e) const char *text; AttributeDescription *ad; unsigned char *ptr = (unsigned char *)bv->bv_val; - BVarray bptr; + BerVarray bptr; i = entry_getlen(&ptr); - x = ch_malloc(i); + x = ch_calloc(1, i); i = entry_getlen(&ptr); x->e_name.bv_val = ptr; x->e_name.bv_len = i; @@ -581,17 +579,19 @@ int entry_decode(struct berval *bv, Entry **e) "entry_decode: \"%s\"\n", x->e_dn, 0, 0 ); #endif - x->e_private = bv->bv_val; + x->e_bv = *bv; /* A valid entry must have at least one attr, so this * pointer can never be NULL */ x->e_attrs = (Attribute *)(x+1); - bptr = (BVarray)x->e_attrs; + bptr = (BerVarray)x->e_attrs; a = NULL; - while (i = entry_getlen(&ptr)) { - struct berval bv = { i, ptr }; + while ((i = entry_getlen(&ptr))) { + struct berval bv; + bv.bv_len = i; + bv.bv_val = ptr; if (a) { a->a_next = (Attribute *)bptr; } @@ -623,8 +623,9 @@ int entry_decode(struct berval *bv, Entry **e) } ptr += i + 1; a->a_desc = ad; - bptr = (BVarray)(a+1); + bptr = (BerVarray)(a+1); a->a_vals = bptr; + a->a_flags = 0; j = entry_getlen(&ptr); while (j) {