Commit 1874658a authored by Howard Chu's avatar Howard Chu
Browse files

More memory context tweaks

parent 374d919f
......@@ -1229,15 +1229,18 @@ typedef struct ldap_ava {
struct berval la_attr;
struct berval la_value;
unsigned la_flags;
#define LDAP_AVA_STRING 0x0000U
#define LDAP_AVA_BINARY 0x0001U
#define LDAP_AVA_NONPRINTABLE 0x0002U
#define LDAP_AVA_NULL 0x0000U
#define LDAP_AVA_STRING 0x0001U
#define LDAP_AVA_BINARY 0x0002U
#define LDAP_AVA_NONPRINTABLE 0x0004U
#define LDAP_AVA_FREE_ATTR 0x0010U
#define LDAP_AVA_FREE_VALUE 0x0020U
void *la_private;
} LDAPAVA;
typedef LDAPAVA** LDAPRDN;
typedef LDAPRDN** LDAPDN;
typedef LDAPRDN* LDAPDN;
/* DN formats */
#define LDAP_DN_FORMAT_LDAP 0x0000U
......@@ -1256,57 +1259,75 @@ typedef LDAPRDN** LDAPDN;
#define LDAP_DN_P_NOSPACEAFTERRDN 0x2000U
#define LDAP_DN_PEDANTIC 0xF000U
LDAP_F( void ) ldap_avafree LDAP_P(( LDAPAVA *ava ));
LDAP_F( void ) ldap_rdnfree LDAP_P(( LDAPRDN *rdn ));
LDAP_F( void ) ldap_dnfree LDAP_P(( LDAPDN *dn ));
LDAP_F( void ) ldap_rdnfree LDAP_P(( LDAPRDN rdn ));
LDAP_F( void ) ldap_rdnfree_x LDAP_P(( LDAPRDN rdn, void *ctx ));
LDAP_F( void ) ldap_dnfree LDAP_P(( LDAPDN dn ));
LDAP_F( void ) ldap_dnfree_x LDAP_P(( LDAPDN dn, void *ctx ));
LDAP_F( int )
ldap_bv2dn LDAP_P((
struct berval *bv,
LDAPDN **dn,
LDAPDN *dn,
unsigned flags ));
LDAP_F( int )
ldap_bv2dn_x LDAP_P((
struct berval *bv, LDAPDN *dn, unsigned flags, void *ctx ));
LDAP_F( int )
ldap_str2dn LDAP_P((
LDAP_CONST char *str,
LDAPDN **dn,
LDAPDN *dn,
unsigned flags ));
LDAP_F( int )
ldap_dn2bv LDAP_P((
LDAPDN *dn,
LDAPDN dn,
struct berval *bv,
unsigned flags ));
LDAP_F( int )
ldap_dn2bv_x LDAP_P((
LDAPDN dn, struct berval *bv, unsigned flags, void *ctx ));
LDAP_F( int )
ldap_dn2str LDAP_P((
LDAPDN *dn,
LDAPDN dn,
char **str,
unsigned flags ));
LDAP_F( int )
ldap_bv2rdn LDAP_P((
struct berval *bv,
LDAPRDN **rdn,
LDAPRDN *rdn,
char **next,
unsigned flags ));
LDAP_F( int )
ldap_bv2rdn_x LDAP_P((
struct berval *bv, LDAPRDN *rdn, char **next,
unsigned flags, void *ctx ));
LDAP_F( int )
ldap_str2rdn LDAP_P((
LDAP_CONST char *str,
LDAPRDN **rdn,
LDAPRDN *rdn,
char **next,
unsigned flags ));
LDAP_F( int )
ldap_rdn2bv LDAP_P((
LDAPRDN *rdn,
LDAPRDN rdn,
struct berval *bv,
unsigned flags ));
LDAP_F( int )
ldap_rdn2bv_x LDAP_P((
LDAPRDN rdn, struct berval *bv, unsigned flags, void *ctx ));
LDAP_F( int )
ldap_rdn2str LDAP_P((
LDAPRDN *rdn,
LDAPRDN rdn,
char **str,
unsigned flags ));
......@@ -1329,7 +1350,7 @@ ldap_explode_rdn LDAP_P(( /* deprecated */
LDAP_CONST char *rdn,
int notypes ));
typedef int LDAPDN_rewrite_func LDAP_P(( LDAPDN *dn, unsigned flags ));
typedef int LDAPDN_rewrite_func LDAP_P(( LDAPDN dn, unsigned flags, void *ctx ));
LDAP_F( int )
ldap_X509dn2bv LDAP_P(( void *x509_name, struct berval *dn,
......
......@@ -39,8 +39,8 @@ int ldap_dn2domain(
{
int i, j;
char *ndomain;
LDAPDN *dn = NULL;
LDAPRDN *rdn = NULL;
LDAPDN dn = NULL;
LDAPRDN rdn = NULL;
LDAPAVA *ava = NULL;
struct berval domain = { 0, NULL };
static const struct berval DC = BER_BVC("DC");
......@@ -49,18 +49,21 @@ int ldap_dn2domain(
assert( dn_in != NULL );
assert( domainp != NULL );
*domainp = NULL;
if ( ldap_str2dn( dn_in, &dn, LDAP_DN_FORMAT_LDAP ) != LDAP_SUCCESS ) {
return -2;
}
if( dn ) for( i=0; (*dn)[i] != NULL; i++ ) {
rdn = (*dn)[i];
if( dn ) for( i=0; dn[i] != NULL; i++ ) {
rdn = dn[i];
for( j=0; (*rdn)[j] != NULL; j++ ) {
ava = (*rdn)[j];
for( j=0; rdn[j] != NULL; j++ ) {
ava = rdn[j];
if( (*dn)[i][j][1] == NULL &&
!ava->la_flags && ava->la_value.bv_len &&
if( rdn[j+1] == NULL &&
(ava->la_flags & LDAP_AVA_STRING) &&
ava->la_value.bv_len &&
( ber_bvstrcasecmp( &ava->la_attr, &DC ) == 0
|| ber_bvstrcasecmp( &ava->la_attr, &DCOID ) == 0 ) )
{
......
......@@ -33,7 +33,7 @@ main( int argc, char *argv[] )
int rc, i, debug = 0, f2 = 0;
unsigned flags[ 2 ] = { 0U, 0 };
char *strin, *str = NULL, buf[ 1024 ];
LDAPDN *dn, *dn2 = NULL;
LDAPDN dn, dn2 = NULL;
while ( 1 ) {
int opt = getopt( argc, argv, "d:" );
......@@ -124,8 +124,8 @@ main( int argc, char *argv[] )
if ( rc == LDAP_SUCCESS ) {
int i;
if ( dn ) {
for ( i = 0; dn[ 0 ][ i ]; i++ ) {
LDAPRDN *rdn = dn[ 0 ][ i ];
for ( i = 0; dn[ i ]; i++ ) {
LDAPRDN rdn = dn[ i ];
char *rstr = NULL;
if ( ldap_rdn2str( rdn, &rstr, flags[ f2 ] ) ) {
......@@ -241,15 +241,15 @@ main( int argc, char *argv[] )
if( dn != NULL && dn2 == NULL ) {
fprintf( stdout, "dn mismatch\n" );
} else if (( dn != NULL ) && (dn2 != NULL))
for ( iRDN = 0; dn[ 0 ][ iRDN ] && dn2[ 0 ][ iRDN ]; iRDN++ )
for ( iRDN = 0; dn[ iRDN ] && dn2[ iRDN ]; iRDN++ )
{
LDAPRDN *r = dn[ 0 ][ iRDN ];
LDAPRDN *r2 = dn2[ 0 ][ iRDN ];
LDAPRDN r = dn[ iRDN ];
LDAPRDN r2 = dn2[ iRDN ];
int iAVA;
for ( iAVA = 0; r[ 0 ][ iAVA ] && r2[ 0 ][ iAVA ]; iAVA++ ) {
LDAPAVA *a = r[ 0 ][ iAVA ];
LDAPAVA *a2 = r2[ 0 ][ iAVA ];
for ( iAVA = 0; r[ iAVA ] && r2[ iAVA ]; iAVA++ ) {
LDAPAVA *a = r[ iAVA ];
LDAPAVA *a2 = r2[ iAVA ];
if ( a->la_attr.bv_len != a2->la_attr.bv_len ) {
fprintf( stdout, "ava(%d), rdn(%d) attr len mismatch (%ld->%ld)\n",
......
This diff is collapsed.
......@@ -348,13 +348,21 @@ LDAP_F ( void ) ldap_int_initialize_global_options LDAP_P((
/* memory.c */
/* simple macros to realloc for now */
#define LDAP_MALLOC(s) (LBER_MALLOC((s)))
#define LDAP_CALLOC(n,s) (LBER_CALLOC((n),(s)))
#define LDAP_REALLOC(p,s) (LBER_REALLOC((p),(s)))
#define LDAP_FREE(p) (LBER_FREE((p)))
#define LDAP_VFREE(v) (LBER_VFREE((void **)(v)))
#define LDAP_STRDUP(s) (LBER_STRDUP((s)))
#define LDAP_STRNDUP(s,l) (LBER_STRNDUP((s),(l)))
#define LDAP_MALLOC(s) (ber_memalloc_x((s),NULL))
#define LDAP_CALLOC(n,s) (ber_memcalloc_x((n),(s),NULL))
#define LDAP_REALLOC(p,s) (ber_memrealloc_x((p),(s),NULL))
#define LDAP_FREE(p) (ber_memfree_x((p),NULL))
#define LDAP_VFREE(v) (ber_memvfree_x((void **)(v),NULL))
#define LDAP_STRDUP(s) (ber_strdup_x((s),NULL))
#define LDAP_STRNDUP(s,l) (ber_strndup_x((s),(l),NULL))
#define LDAP_MALLOCX(s,x) (ber_memalloc_x((s),(x)))
#define LDAP_CALLOCX(n,s,x) (ber_memcalloc_x((n),(s),(x)))
#define LDAP_REALLOCX(p,s,x) (ber_memrealloc_x((p),(s),(x)))
#define LDAP_FREEX(p,x) (ber_memfree_x((p),(x)))
#define LDAP_VFREEX(v,x) (ber_memvfree_x((void **)(v),(x)))
#define LDAP_STRDUPX(s,x) (ber_strdup_x((s),(x)))
#define LDAP_STRNDUPX(s,l,x) (ber_strndup_x((s),(l),(x)))
/*
* in error.c
......
......@@ -112,6 +112,7 @@ ldap_pvt_tls_destroy( void )
tls_def_ctx = NULL;
EVP_cleanup();
ERR_remove_state(0);
ERR_free_strings();
if ( tls_opt_certfile ) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment