Update ldap_first_attribute/ldap_next_attribute to handle

BerElement argument per latest IETF ldapext draft c api spec.
That is, caller is solely responsible for freeing the BerElement
allocated and returned by ldap_first_attribute.
Update man pages accordingly.
Update applications accordingly.
This commit is contained in:
Kurt Zeilenga 1999-01-20 20:21:38 +00:00
parent 19a17982c6
commit eed7408e7e
6 changed files with 36 additions and 21 deletions

View file

@ -428,7 +428,7 @@ void print_entry(
{
char *a, *dn, *ufn, tmpfname[ 64 ];
int i, j, notascii;
BerElement *ber;
BerElement *ber = NULL;
struct berval **bvals;
FILE *tmpfp;
@ -505,6 +505,10 @@ void print_entry(
ber_bvecfree( bvals );
}
}
if( ber != NULL ) {
ber_free( ber, 0 );
}
}

View file

@ -82,7 +82,6 @@ parse_answer( LDAPMessage *s )
{
int idx;
char **rdns;
BerElement *cookie;
register LDAPMessage *ep;
register char *ap;
@ -98,6 +97,7 @@ parse_answer( LDAPMessage *s )
printf(" Done clearing entry\n");
#endif
for (ep = ldap_first_entry(ld, s); ep != NULL; ep = ldap_next_entry(ld, ep)) {
BerElement *cookie = NULL;
#ifdef DEBUG
if (debug & D_PARSE)
printf(" Determining DN and name\n");
@ -126,6 +126,10 @@ parse_answer( LDAPMessage *s )
}
add_value(&(Entry.attrs[idx]), ep, ap);
}
if( cookie != NULL ) {
ber_free( cookie, 0 );
}
}
#ifdef DEBUG
if (debug & D_PARSE)

View file

@ -43,15 +43,9 @@ allocated to keep track of its current position. This pointer should
be passed to subsequent calls to
.B ldap_next_attribute()
and is used used
to effectively step through the entry's attributes. This pointer
is freed by
.B ldap_next_attribute()
when there are no more attributes (that
is, when
.B ldap_next_attribute()
returns NULL). Otherwise, the caller is
responsible for freeing the BerElement pointed to by \fIberptr\fP when
it is no longer needed by calling
to effectively step through the entry's attributes. The caller is
solely responsible for freeing the BerElement pointed to by \fIberptr\fP
when it is no longer needed by calling
.BR ber_free (3).
When calling
.BR ber_free (3)
@ -69,9 +63,8 @@ for a description of possible error codes.
.SH NOTES
The
.B ldap_first_attribute()
routine dyanamically allocated memory that may need to
be freed by the caller via
.BR ber_free (3).
routine dyanamically allocated memory that must be freed by the caller via
.BR ber_free (3).
.SH SEE ALSO
.BR ldap(3),
.BR ldap_first_entry(3),

View file

@ -29,6 +29,7 @@ ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **ber )
Debug( LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0 );
if ( (*ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
*ber = NULL;
return( NULL );
}
@ -45,6 +46,7 @@ ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **ber )
== LBER_ERROR ) {
ld->ld_errno = LDAP_DECODING_ERROR;
ber_free( *ber, 0 );
*ber = NULL;
return( NULL );
}
@ -64,7 +66,7 @@ ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber )
if ( ber_scanf( ber, "{sx}", ld->ld_attrbuffer, &len )
== LBER_ERROR ) {
ld->ld_errno = LDAP_DECODING_ERROR;
ber_free( ber, 0 );
/* ber_free( ber, 0 ); *//* don't free the BerElement */
return( NULL );
}

View file

@ -914,14 +914,14 @@ print_ldap_result( LDAP *ld, LDAPMessage *lm, char *s )
static void
print_search_entry( LDAP *ld, LDAPMessage *res )
{
BerElement *ber;
char *a, *dn, *ufn;
struct berval **vals;
int i;
LDAPMessage *e;
for ( e = ldap_first_entry( ld, res ); e != NULLMSG;
e = ldap_next_entry( ld, e ) ) {
e = ldap_next_entry( ld, e ) )
{
BerElement *ber = NULL;
char *a, *dn, *ufn;
if ( e->lm_msgtype == LDAP_RES_SEARCH_RESULT )
break;
@ -935,12 +935,16 @@ print_search_entry( LDAP *ld, LDAPMessage *res )
free( ufn );
for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL;
a = ldap_next_attribute( ld, e, ber ) ) {
a = ldap_next_attribute( ld, e, ber ) )
{
struct berval **vals;
printf( "\t\tATTR: %s\n", a );
if ( (vals = ldap_get_values_len( ld, e, a ))
== NULL ) {
printf( "\t\t\t(no values)\n" );
} else {
int i;
for ( i = 0; vals[i] != NULL; i++ ) {
int j, nonascii;
@ -965,6 +969,10 @@ print_search_entry( LDAP *ld, LDAPMessage *res )
ber_bvecfree( vals );
}
}
if(ber != NULL) {
ber_free( ber, 0 );
}
}
if ( res->lm_msgtype == LDAP_RES_SEARCH_RESULT

View file

@ -265,6 +265,10 @@ do_entry2text(
ldap_value_free( vals );
}
}
if( ber != NULL) {
ber_free( ber, 0 );
}
} else {
for ( rowp = ldap_first_tmplrow( tmpl );
NONFATAL_LDAP_ERR( err ) && rowp != NULLTMPLITEM;