mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-05-28 04:35:57 -04:00
For ITS#1601, add ber_init2() using given buffer in-place instead of
allocating a copy.
This commit is contained in:
parent
32e48d9e4d
commit
933f6a5fdd
3 changed files with 25 additions and 36 deletions
|
|
@ -443,6 +443,12 @@ ber_get_next LDAP_P((
|
|||
ber_len_t *len,
|
||||
BerElement *ber ));
|
||||
|
||||
LBER_F( void )
|
||||
ber_init2 LDAP_P((
|
||||
BerElement *ber,
|
||||
struct berval *bv,
|
||||
int options ));
|
||||
|
||||
LBER_F( void )
|
||||
ber_init_w_nullc LDAP_P(( /* DEPRECATED */
|
||||
BerElement *ber,
|
||||
|
|
|
|||
|
|
@ -292,13 +292,12 @@ ber_dup( BerElement *ber )
|
|||
}
|
||||
|
||||
|
||||
/* OLD U-Mich ber_init() */
|
||||
void
|
||||
ber_init_w_nullc( BerElement *ber, int options )
|
||||
ber_init2( BerElement *ber, struct berval *bv, int options )
|
||||
{
|
||||
assert( ber != NULL );
|
||||
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
(void) memset( (char *)ber, '\0', sizeof( BerElement ));
|
||||
ber->ber_valid = LBER_VALID_BERELEMENT;
|
||||
|
|
@ -306,9 +305,22 @@ ber_init_w_nullc( BerElement *ber, int options )
|
|||
ber->ber_options = (char) options;
|
||||
ber->ber_debug = ber_int_debug;
|
||||
|
||||
if ( bv != NULL ) {
|
||||
ber->ber_buf = bv->bv_val;
|
||||
ber->ber_ptr = ber->ber_buf;
|
||||
ber->ber_end = ber->ber_buf + bv->bv_len;
|
||||
}
|
||||
|
||||
assert( LBER_VALID( ber ) );
|
||||
}
|
||||
|
||||
/* OLD U-Mich ber_init() */
|
||||
void
|
||||
ber_init_w_nullc( BerElement *ber, int options )
|
||||
{
|
||||
ber_init2( ber, NULL, options );
|
||||
}
|
||||
|
||||
/* New C-API ber_init() */
|
||||
/* This function constructs a BerElement containing a copy
|
||||
** of the data in the bv argument.
|
||||
|
|
|
|||
|
|
@ -74,26 +74,15 @@ int slap_passwd_parse( struct berval *reqdata,
|
|||
int rc = LDAP_SUCCESS;
|
||||
ber_tag_t tag;
|
||||
ber_len_t len;
|
||||
BerElement *ber;
|
||||
char berbuf[256];
|
||||
BerElement *ber = (BerElement *)berbuf;
|
||||
|
||||
if( reqdata == NULL ) {
|
||||
return LDAP_SUCCESS;
|
||||
}
|
||||
|
||||
ber = ber_init( reqdata );
|
||||
|
||||
if( ber == NULL ) {
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
|
||||
"slap_passwd_parse: ber_init failed\n" ));
|
||||
#else
|
||||
Debug( LDAP_DEBUG_TRACE, "slap_passwd_parse: ber_init failed\n",
|
||||
0, 0, 0 );
|
||||
#endif
|
||||
|
||||
*text = "password decoding error";
|
||||
return LDAP_PROTOCOL_ERROR;
|
||||
}
|
||||
/* ber_init2 uses reqdata directly, doesn't allocate new buffers */
|
||||
ber_init2( ber, reqdata, 0 );
|
||||
|
||||
tag = ber_scanf( ber, "{" /*}*/ );
|
||||
|
||||
|
|
@ -214,24 +203,6 @@ decoding_error:
|
|||
}
|
||||
|
||||
done:
|
||||
if( rc != LDAP_SUCCESS ) {
|
||||
if( id && id->bv_val != NULL ) {
|
||||
free( id->bv_val );
|
||||
id->bv_val = NULL;
|
||||
}
|
||||
|
||||
if( oldpass && oldpass->bv_val != NULL ) {
|
||||
free( oldpass->bv_val );
|
||||
oldpass->bv_val = NULL;
|
||||
}
|
||||
|
||||
if( newpass && newpass->bv_val != NULL ) {
|
||||
free( newpass->bv_val );
|
||||
newpass->bv_val = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ber_free( ber, 1 );
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue