mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-24 13:24:56 +08:00
Changed dnExtractRdn to use a provided berval instead of allocating one.
Use ldap_dn2bv and ldap_rdn2bv instead of the *2str versions.
This commit is contained in:
parent
4d7e904404
commit
65636e0855
@ -400,7 +400,7 @@ monitor_subsys_conn_create(
|
||||
|
||||
} else {
|
||||
char **values;
|
||||
struct berval *rdn;
|
||||
struct berval rdn;
|
||||
unsigned long connid;
|
||||
|
||||
/* create exactly the required entry */
|
||||
@ -409,11 +409,11 @@ monitor_subsys_conn_create(
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if ( rdn_attrs( rdn->bv_val, NULL, &values ) != LDAP_SUCCESS ) {
|
||||
ber_bvfree( rdn );
|
||||
if ( rdn_attrs( rdn.bv_val, NULL, &values ) != LDAP_SUCCESS ) {
|
||||
free( rdn.bv_val );
|
||||
return( -1 );
|
||||
}
|
||||
ber_bvfree( rdn );
|
||||
free( rdn.bv_val );
|
||||
|
||||
assert( values );
|
||||
assert( values[ 0 ] );
|
||||
|
@ -122,10 +122,9 @@ dnValidate(
|
||||
*/
|
||||
if ( rc == LDAP_SUCCESS ) {
|
||||
rc = LDAPDN_validate( dn );
|
||||
ldap_dnfree( dn );
|
||||
}
|
||||
|
||||
ldap_dnfree( dn );
|
||||
|
||||
if ( rc != LDAP_SUCCESS ) {
|
||||
return( LDAP_INVALID_SYNTAX );
|
||||
}
|
||||
@ -315,7 +314,6 @@ dnNormalize(
|
||||
|
||||
if ( val->bv_len != 0 ) {
|
||||
LDAPDN *dn = NULL;
|
||||
char *dn_out = NULL;
|
||||
int rc;
|
||||
|
||||
/*
|
||||
@ -337,16 +335,16 @@ dnNormalize(
|
||||
/*
|
||||
* Back to string representation
|
||||
*/
|
||||
rc = ldap_dn2str( dn, &dn_out, LDAP_DN_FORMAT_LDAPV3 );
|
||||
out = ch_malloc( sizeof(struct berval));
|
||||
|
||||
rc = ldap_dn2bv( dn, out, LDAP_DN_FORMAT_LDAPV3 );
|
||||
|
||||
ldap_dnfree( dn );
|
||||
|
||||
if ( rc != LDAP_SUCCESS ) {
|
||||
free( out );
|
||||
return LDAP_INVALID_SYNTAX;
|
||||
}
|
||||
|
||||
out = ber_bvstr( dn_out );
|
||||
|
||||
} else {
|
||||
out = ber_bvdup( val );
|
||||
}
|
||||
@ -376,7 +374,6 @@ dnPretty(
|
||||
|
||||
if ( val->bv_len != 0 ) {
|
||||
LDAPDN *dn = NULL;
|
||||
char *dn_out = NULL;
|
||||
int rc;
|
||||
|
||||
/* FIXME: should be liberal in what we accept */
|
||||
@ -397,17 +394,18 @@ dnPretty(
|
||||
/* RE: the default is the form that is used as
|
||||
* an internal representation; the pretty form
|
||||
* is a variant */
|
||||
rc = ldap_dn2str( dn, &dn_out,
|
||||
|
||||
out = ch_malloc( sizeof(struct berval));
|
||||
|
||||
rc = ldap_dn2bv( dn, out,
|
||||
LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY );
|
||||
|
||||
ldap_dnfree( dn );
|
||||
|
||||
if ( rc != LDAP_SUCCESS ) {
|
||||
free( out );
|
||||
return LDAP_INVALID_SYNTAX;
|
||||
}
|
||||
|
||||
out = ber_bvstr( dn_out );
|
||||
|
||||
} else {
|
||||
out = ber_bvdup( val );
|
||||
}
|
||||
@ -437,7 +435,6 @@ dnPrettyNormal(
|
||||
|
||||
if ( val->bv_len != 0 ) {
|
||||
LDAPDN *dn = NULL;
|
||||
char *dn_out = NULL;
|
||||
int rc;
|
||||
|
||||
pretty->bv_val = NULL;
|
||||
@ -459,7 +456,7 @@ dnPrettyNormal(
|
||||
return LDAP_INVALID_SYNTAX;
|
||||
}
|
||||
|
||||
rc = ldap_dn2str( dn, &dn_out,
|
||||
rc = ldap_dn2bv( dn, pretty,
|
||||
LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY );
|
||||
|
||||
if ( rc != LDAP_SUCCESS ) {
|
||||
@ -467,8 +464,6 @@ dnPrettyNormal(
|
||||
return LDAP_INVALID_SYNTAX;
|
||||
}
|
||||
|
||||
ber_str2bv( dn_out, 0, 0, pretty );
|
||||
|
||||
if ( LDAPDN_rewrite( dn, 0 ) != LDAP_SUCCESS ) {
|
||||
ldap_dnfree( dn );
|
||||
free( pretty->bv_val );
|
||||
@ -477,7 +472,7 @@ dnPrettyNormal(
|
||||
return LDAP_INVALID_SYNTAX;
|
||||
}
|
||||
|
||||
rc = ldap_dn2str( dn, &dn_out, LDAP_DN_FORMAT_LDAPV3 );
|
||||
rc = ldap_dn2bv( dn, normal, LDAP_DN_FORMAT_LDAPV3 );
|
||||
|
||||
ldap_dnfree( dn );
|
||||
if ( rc != LDAP_SUCCESS ) {
|
||||
@ -486,8 +481,6 @@ dnPrettyNormal(
|
||||
pretty->bv_len = 0;
|
||||
return LDAP_INVALID_SYNTAX;
|
||||
}
|
||||
|
||||
ber_str2bv( dn_out, 0, 0, normal );
|
||||
} else {
|
||||
ber_dupbv( pretty, val );
|
||||
ber_dupbv( normal, val );
|
||||
@ -686,11 +679,10 @@ dn_parent(
|
||||
int
|
||||
dnExtractRdn(
|
||||
struct berval *dn,
|
||||
struct berval **rdn )
|
||||
struct berval *rdn )
|
||||
{
|
||||
LDAPRDN *tmpRDN;
|
||||
const char *p;
|
||||
char *rdnout;
|
||||
int rc;
|
||||
|
||||
assert( dn );
|
||||
@ -705,18 +697,12 @@ dnExtractRdn(
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ldap_rdn2str( tmpRDN, &rdnout, LDAP_DN_FORMAT_LDAPV3 );
|
||||
rc = ldap_rdn2bv( tmpRDN, rdn, LDAP_DN_FORMAT_LDAPV3 );
|
||||
ldap_rdnfree( tmpRDN );
|
||||
if ( rc != LDAP_SUCCESS ) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
*rdn = ber_bvstr( rdnout );
|
||||
if ( *rdn == NULL ) {
|
||||
free( rdnout );
|
||||
return LDAP_NO_MEMORY;
|
||||
}
|
||||
|
||||
return LDAP_SUCCESS;
|
||||
}
|
||||
|
||||
@ -728,8 +714,7 @@ dn_rdnlen(
|
||||
Backend *be,
|
||||
struct berval *dn_in )
|
||||
{
|
||||
struct berval *rdn = NULL;
|
||||
int retval = 0;
|
||||
struct berval rdn;
|
||||
|
||||
assert( dn_in );
|
||||
|
||||
@ -749,10 +734,9 @@ dn_rdnlen(
|
||||
return 0;
|
||||
}
|
||||
|
||||
retval = rdn->bv_len;
|
||||
ber_bvfree( rdn );
|
||||
free( rdn.bv_val );
|
||||
|
||||
return retval;
|
||||
return rdn.bv_len;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -762,8 +746,7 @@ char * dn_rdn(
|
||||
Backend *be,
|
||||
struct berval *dn_in )
|
||||
{
|
||||
struct berval *rdn = NULL;
|
||||
char *retval;
|
||||
struct berval rdn;
|
||||
|
||||
assert( dn_in );
|
||||
|
||||
@ -783,10 +766,7 @@ char * dn_rdn(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
retval = rdn->bv_val;
|
||||
free( rdn );
|
||||
|
||||
return retval;
|
||||
return rdn.bv_val;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -380,7 +380,7 @@ LDAP_SLAPD_F (int) dnIsSuffix LDAP_P((
|
||||
const struct berval *dn, const struct berval *suffix ));
|
||||
|
||||
LDAP_SLAPD_F (int) dnExtractRdn LDAP_P((
|
||||
struct berval *dn, struct berval **rdn ));
|
||||
struct berval *dn, struct berval *rdn ));
|
||||
|
||||
LDAP_SLAPD_F (int) rdnValidate LDAP_P(( struct berval * rdn ));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user