From 933f6a5fdd70033bb65aeee1c35cc777dc612798 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 14 Feb 2002 13:32:40 +0000 Subject: [PATCH] For ITS#1601, add ber_init2() using given buffer in-place instead of allocating a copy. --- include/lber.h | 6 ++++++ libraries/liblber/io.c | 18 +++++++++++++++--- servers/slapd/passwd.c | 37 ++++--------------------------------- 3 files changed, 25 insertions(+), 36 deletions(-) diff --git a/include/lber.h b/include/lber.h index 1a0316b218..ffa52b2bf8 100644 --- a/include/lber.h +++ b/include/lber.h @@ -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, diff --git a/libraries/liblber/io.c b/libraries/liblber/io.c index 3f2b30ce03..e9c1bac4f4 100644 --- a/libraries/liblber/io.c +++ b/libraries/liblber/io.c @@ -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. diff --git a/servers/slapd/passwd.c b/servers/slapd/passwd.c index ab04da8d2a..90ac1d3bbf 100644 --- a/servers/slapd/passwd.c +++ b/servers/slapd/passwd.c @@ -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; } -- 2.39.5