/* parsing/printing routines */
static int str2strval( const char *str, ber_len_t stoplen, struct berval *val,
- const char **next, unsigned flags, unsigned *retFlags );
+ const char **next, unsigned flags, unsigned *retFlags, void *ctx );
static int DCE2strval( const char *str, struct berval *val,
- const char **next, unsigned flags );
+ const char **next, unsigned flags, void *ctx );
static int IA52strval( const char *str, struct berval *val,
- const char **next, unsigned flags );
+ const char **next, unsigned flags, void *ctx );
static int quotedIA52strval( const char *str, struct berval *val,
- const char **next, unsigned flags );
+ const char **next, unsigned flags, void *ctx );
static int hexstr2binval( const char *str, struct berval *val,
- const char **next, unsigned flags );
+ const char **next, unsigned flags, void *ctx );
static int hexstr2bin( const char *str, char *c );
static int byte2hexpair( const char *val, char *pair );
static int binval2hexstr( struct berval *val, char *str );
ber_len_t *len );
static int strval2ADstr( struct berval *val, char *str, unsigned flags,
ber_len_t *len );
-static int dn2domain( LDAPDN *dn, struct berval *bv, int pos, int *iRDN );
+static int dn2domain( LDAPDN dn, struct berval *bv, int pos, int *iRDN );
/* AVA helpers */
static LDAPAVA * ldapava_new(
- const struct berval *attr, const struct berval *val, unsigned flags );
+ const struct berval *attr, const struct berval *val, unsigned flags, void *ctx );
/* Higher level helpers */
-static int rdn2strlen( LDAPRDN *rdn, unsigned flags, ber_len_t *len,
+static int rdn2strlen( LDAPRDN rdn, unsigned flags, ber_len_t *len,
int ( *s2l )( struct berval *, unsigned, ber_len_t * ) );
-static int rdn2str( LDAPRDN *rdn, char *str, unsigned flags, ber_len_t *len,
+static int rdn2str( LDAPRDN rdn, char *str, unsigned flags, ber_len_t *len,
int ( *s2s )( struct berval *, char *, unsigned, ber_len_t * ));
-static int rdn2UFNstrlen( LDAPRDN *rdn, unsigned flags, ber_len_t *len );
-static int rdn2UFNstr( LDAPRDN *rdn, char *str, unsigned flags, ber_len_t *len );
-static int rdn2DCEstrlen( LDAPRDN *rdn, unsigned flags, ber_len_t *len );
-static int rdn2DCEstr( LDAPRDN *rdn, char *str, unsigned flag, ber_len_t *len, int first );
-static int rdn2ADstrlen( LDAPRDN *rdn, unsigned flags, ber_len_t *len );
-static int rdn2ADstr( LDAPRDN *rdn, char *str, unsigned flags, ber_len_t *len, int first );
+static int rdn2UFNstrlen( LDAPRDN rdn, unsigned flags, ber_len_t *len );
+static int rdn2UFNstr( LDAPRDN rdn, char *str, unsigned flags, ber_len_t *len );
+static int rdn2DCEstrlen( LDAPRDN rdn, unsigned flags, ber_len_t *len );
+static int rdn2DCEstr( LDAPRDN rdn, char *str, unsigned flag, ber_len_t *len, int first );
+static int rdn2ADstrlen( LDAPRDN rdn, unsigned flags, ber_len_t *len );
+static int rdn2ADstr( LDAPRDN rdn, char *str, unsigned flags, ber_len_t *len, int first );
/*
* RFC 1823 ldap_get_dn
char **
ldap_explode_dn( LDAP_CONST char *dn, int notypes )
{
- LDAPDN *tmpDN;
+ LDAPDN tmpDN;
char **values = NULL;
int iRDN;
unsigned flag = notypes ? LDAP_DN_FORMAT_UFN : LDAP_DN_FORMAT_LDAPV3;
return values;
}
- for ( iRDN = 0; tmpDN[ 0 ][ iRDN ]; iRDN++ );
+ for ( iRDN = 0; tmpDN[ iRDN ]; iRDN++ );
values = LDAP_MALLOC( sizeof( char * ) * ( 1 + iRDN ) );
if ( values == NULL ) {
return NULL;
}
- for ( iRDN = 0; tmpDN[ 0 ][ iRDN ]; iRDN++ ) {
- ldap_rdn2str( tmpDN[ 0 ][ iRDN ], &values[ iRDN ], flag );
+ for ( iRDN = 0; tmpDN[ iRDN ]; iRDN++ ) {
+ ldap_rdn2str( tmpDN[ iRDN ], &values[ iRDN ], flag );
}
ldap_dnfree( tmpDN );
values[ iRDN ] = NULL;
char **
ldap_explode_rdn( LDAP_CONST char *rdn, int notypes )
{
- LDAPRDN *tmpRDN;
+ LDAPRDN tmpRDN;
char **values = NULL;
const char *p;
int iAVA;
return( NULL );
}
- for ( iAVA = 0; tmpRDN[ 0 ][ iAVA ]; iAVA++ ) ;
+ for ( iAVA = 0; tmpRDN[ iAVA ]; iAVA++ ) ;
values = LDAP_MALLOC( sizeof( char * ) * ( 1 + iAVA ) );
if ( values == NULL ) {
ldap_rdnfree( tmpRDN );
return( NULL );
}
- for ( iAVA = 0; tmpRDN[ 0 ][ iAVA ]; iAVA++ ) {
+ for ( iAVA = 0; tmpRDN[ iAVA ]; iAVA++ ) {
ber_len_t l = 0, vl, al = 0;
char *str;
- LDAPAVA *ava = tmpRDN[ 0 ][ iAVA ];
+ LDAPAVA *ava = tmpRDN[ iAVA ];
if ( ava->la_flags == LDAP_AVA_BINARY ) {
vl = 1 + 2 * ava->la_value.bv_len;
unsigned fin, char **dnout, unsigned fout )
{
int rc;
- LDAPDN *tmpDN = NULL;
+ LDAPDN tmpDN = NULL;
#ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, ENTRY, "ldap_dn_normalize\n", 0, 0, 0 );
#define LDAP_DC_ATTR "dc"
#define LDAP_DC_ATTRU "DC"
#define LDAP_DN_IS_RDN_DC( r ) \
- ( (r) && (r)[0][0] && !(r)[0][1] \
- && ((r)[0][0]->la_flags == LDAP_AVA_STRING) \
- && ((r)[0][0]->la_attr.bv_len == 2) \
- && (((r)[0][0]->la_attr.bv_val[0] == LDAP_DC_ATTR[0]) \
- || ((r)[0][0]->la_attr.bv_val[0] == LDAP_DC_ATTRU[0])) \
- && (((r)[0][0]->la_attr.bv_val[1] == LDAP_DC_ATTR[1]) \
- || ((r)[0][0]->la_attr.bv_val[1] == LDAP_DC_ATTRU[1])))
+ ( (r) && (r)[0] && !(r)[1] \
+ && ((r)[0]->la_flags == LDAP_AVA_STRING) \
+ && ((r)[0]->la_attr.bv_len == 2) \
+ && (((r)[0]->la_attr.bv_val[0] == LDAP_DC_ATTR[0]) \
+ || ((r)[0]->la_attr.bv_val[0] == LDAP_DC_ATTRU[0])) \
+ && (((r)[0]->la_attr.bv_val[1] == LDAP_DC_ATTR[1]) \
+ || ((r)[0]->la_attr.bv_val[1] == LDAP_DC_ATTRU[1])))
/* Composite rules */
#define LDAP_DN_ALLOW_ONE_SPACE(f) \
*/
LDAPAVA *
ldapava_new( const struct berval *attr, const struct berval *val,
- unsigned flags )
+ unsigned flags, void *ctx )
{
- LDAPAVA *ava;
+ LDAPAVA *ava;
assert( attr );
assert( val );
- ava = LDAP_MALLOC( sizeof( LDAPAVA ) + attr->bv_len + 1 );
-
- /* should we test it? */
- if ( ava == NULL ) {
- return( NULL );
- }
+ ava = LDAP_MALLOCX( sizeof( LDAPAVA ) + attr->bv_len + 1, ctx );
- ava->la_attr.bv_len = attr->bv_len;
- ava->la_attr.bv_val = (char *)(ava+1);
- AC_MEMCPY( ava->la_attr.bv_val, attr->bv_val, attr->bv_len );
- ava->la_attr.bv_val[attr->bv_len] = '\0';
+ if ( ava ) {
+ ava->la_attr.bv_len = attr->bv_len;
+ ava->la_attr.bv_val = (char *)(ava+1);
+ AC_MEMCPY( ava->la_attr.bv_val, attr->bv_val, attr->bv_len );
+ ava->la_attr.bv_val[attr->bv_len] = '\0';
- ava->la_value = *val;
- ava->la_flags = flags;
+ ava->la_value = *val;
+ ava->la_flags = flags | LDAP_AVA_FREE_VALUE;
- ava->la_private = NULL;
+ ava->la_private = NULL;
+ }
return( ava );
}
void
-ldap_avafree( LDAPAVA *ava )
+ldapava_free( LDAPAVA *ava, void *ctx )
{
assert( ava );
assert( ava->la_private == NULL );
#endif
-#if 0
- /* la_attr is now contiguous with ava, not freed separately */
- LDAP_FREE( ava->la_attr.bv_val );
-#endif
- LDAP_FREE( ava->la_value.bv_val );
+ if (ava->la_flags & LDAP_AVA_FREE_VALUE)
+ LDAP_FREEX( ava->la_value.bv_val, ctx );
+
+ LDAP_FREEX( ava, ctx );
+}
- LDAP_FREE( ava );
+void
+ldap_rdnfree( LDAPRDN rdn )
+{
+ ldap_rdnfree_x( rdn, NULL );
}
void
-ldap_rdnfree( LDAPRDN *rdn )
+ldap_rdnfree_x( LDAPRDN rdn, void *ctx )
{
int iAVA;
return;
}
- for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
- ldap_avafree( rdn[ 0 ][ iAVA ] );
+ for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
+ ldapava_free( rdn[ iAVA ], ctx );
}
- LDAP_FREE( rdn );
+ LDAP_FREEX( rdn, ctx );
}
void
-ldap_dnfree( LDAPDN *dn )
+ldap_dnfree( LDAPDN dn )
+{
+ ldap_dnfree_x( dn, NULL );
+}
+
+void
+ldap_dnfree_x( LDAPDN dn, void *ctx )
{
int iRDN;
return;
}
- for ( iRDN = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
- ldap_rdnfree( dn[ 0 ][ iRDN ] );
+ for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
+ ldap_rdnfree_x( dn[ iRDN ], ctx );
}
- LDAP_FREE( dn );
+ LDAP_FREEX( dn, ctx );
}
/*
#define TMP_RDN_SLOTS 32
int
-ldap_str2dn( LDAP_CONST char *str, LDAPDN **dn, unsigned flags )
+ldap_str2dn( LDAP_CONST char *str, LDAPDN *dn, unsigned flags )
{
struct berval bv;
bv.bv_len = strlen( str );
bv.bv_val = (char *) str;
- return ldap_bv2dn( &bv, dn, flags );
+ return ldap_bv2dn_x( &bv, dn, flags, NULL );
}
int
-ldap_bv2dn( struct berval *bv, LDAPDN **dn, unsigned flags )
+ldap_bv2dn( struct berval *bv, LDAPDN *dn, unsigned flags )
+{
+ return ldap_bv2dn_x( bv, dn, flags, NULL );
+}
+
+int
+ldap_bv2dn_x( struct berval *bv, LDAPDN *dn, unsigned flags, void *ctx )
{
const char *p;
int rc = LDAP_DECODING_ERROR;
int nrdns = 0;
- LDAPDN *newDN = NULL;
- LDAPRDN *newRDN = NULL, *tmpDN_[TMP_RDN_SLOTS], **tmpDN = tmpDN_;
+ LDAPDN newDN = NULL;
+ LDAPRDN newRDN = NULL, tmpDN_[TMP_RDN_SLOTS], *tmpDN = tmpDN_;
int num_slots = TMP_RDN_SLOTS;
char *str = bv->bv_val;
char *end = str + bv->bv_len;
tmpbv.bv_len = bv->bv_len - ( p - str );
tmpbv.bv_val = (char *)p;
- err = ldap_bv2rdn( &tmpbv, &newRDN, (char **) &p, flags );
+ err = ldap_bv2rdn_x( &tmpbv, &newRDN, (char **) &p, flags,ctx);
if ( err != LDAP_SUCCESS ) {
goto parsing_error;
}
* make the static RDN array dynamically rescalable
*/
if ( nrdns == num_slots ) {
- LDAPRDN **tmp;
+ LDAPRDN *tmp;
if ( tmpDN == tmpDN_ ) {
- tmp = LDAP_MALLOC( num_slots * 2 * sizeof( LDAPRDN * ) );
+ tmp = LDAP_MALLOCX( num_slots * 2 * sizeof( LDAPRDN * ), ctx );
if ( tmp == NULL ) {
rc = LDAP_NO_MEMORY;
goto parsing_error;
AC_MEMCPY( tmp, tmpDN, num_slots * sizeof( LDAPRDN * ) );
} else {
- tmp = LDAP_REALLOC( tmpDN, num_slots * 2 * sizeof( LDAPRDN * ) );
+ tmp = LDAP_REALLOCX( tmpDN, num_slots * 2 * sizeof( LDAPRDN * ), ctx );
if ( tmp == NULL ) {
rc = LDAP_NO_MEMORY;
goto parsing_error;
/*
* the DN is over, phew
*/
- newDN = (LDAPDN *)LDAP_MALLOC( sizeof(LDAPDN) +
- sizeof(LDAPRDN *) * (nrdns+1));
+ newDN = (LDAPDN)LDAP_MALLOCX( sizeof(LDAPRDN *) * (nrdns+1), ctx );
if ( newDN == NULL ) {
rc = LDAP_NO_MEMORY;
goto parsing_error;
} else {
int i;
- newDN[0] = (LDAPRDN **)(newDN+1);
-
if ( LDAP_DN_DCE( flags ) ) {
/* add in reversed order */
for ( i=0; i<nrdns; i++ )
- newDN[0][i] = tmpDN[nrdns-1-i];
+ newDN[i] = tmpDN[nrdns-1-i];
} else {
for ( i=0; i<nrdns; i++ )
- newDN[0][i] = tmpDN[i];
+ newDN[i] = tmpDN[i];
}
- newDN[0][nrdns] = NULL;
+ newDN[nrdns] = NULL;
rc = LDAP_SUCCESS;
}
goto return_result;
parsing_error:;
if ( newRDN ) {
- ldap_rdnfree( newRDN );
+ ldap_rdnfree_x( newRDN, ctx );
}
for ( nrdns-- ;nrdns >= 0; nrdns-- ) {
- ldap_rdnfree( tmpDN[nrdns] );
+ ldap_rdnfree_x( tmpDN[nrdns], ctx );
}
return_result:;
if ( tmpDN != tmpDN_ ) {
- LDAP_FREE( tmpDN );
+ LDAP_FREEX( tmpDN, ctx );
}
#ifdef NEW_LOGGING
* corresponds to the rdn separator or to '\0' in case the string is over.
*/
int
-ldap_str2rdn( LDAP_CONST char *str, LDAPRDN **rdn,
+ldap_str2rdn( LDAP_CONST char *str, LDAPRDN *rdn,
char **n_in, unsigned flags )
{
struct berval bv;
bv.bv_len = strlen( str );
bv.bv_val = (char *) str;
- return ldap_bv2rdn( &bv, rdn, n_in, flags );
+ return ldap_bv2rdn_x( &bv, rdn, n_in, flags, NULL );
}
int
-ldap_bv2rdn( struct berval *bv, LDAPRDN **rdn,
+ldap_bv2rdn( struct berval *bv, LDAPRDN *rdn,
char **n_in, unsigned flags )
+{
+ return ldap_bv2rdn_x( bv, rdn, n_in, flags, NULL );
+}
+
+int
+ldap_bv2rdn_x( struct berval *bv, LDAPRDN *rdn,
+ char **n_in, unsigned flags, void *ctx )
{
const char **n = (const char **) n_in;
const char *p;
struct berval attrType = { 0, NULL };
struct berval attrValue = { 0, NULL };
- LDAPRDN *newRDN = NULL;
+ LDAPRDN newRDN = NULL;
LDAPAVA *tmpRDN_[TMP_AVA_SLOTS], **tmpRDN = tmpRDN_;
int num_slots = TMP_AVA_SLOTS;
break;
case B4BINARYVALUE:
- if ( hexstr2binval( p, &attrValue, &p, flags ) ) {
+ if ( hexstr2binval( p, &attrValue, &p, flags, ctx ) ) {
goto parsing_error;
}
case LDAP_DN_FORMAT_LDAPV3:
if ( str2strval( p, stoplen - ( p - str ),
&attrValue, &p, flags,
- &attrValueEncoding ) ) {
+ &attrValueEncoding, ctx ) ) {
goto parsing_error;
}
break;
case LDAP_DN_FORMAT_DCE:
- if ( DCE2strval( p, &attrValue, &p, flags ) ) {
+ if ( DCE2strval( p, &attrValue, &p, flags, ctx ) ) {
goto parsing_error;
}
break;
break;
case B4IA5VALUE:
- if ( IA52strval( p, &attrValue, &p, flags ) ) {
+ if ( IA52strval( p, &attrValue, &p, flags, ctx ) ) {
goto parsing_error;
}
/* lead quote already stripped */
if ( quotedIA52strval( p, &attrValue,
- &p, flags ) ) {
+ &p, flags, ctx ) ) {
goto parsing_error;
}
* we accept empty values
*/
ava = ldapava_new( &attrType, &attrValue,
- attrValueEncoding );
-
+ attrValueEncoding, ctx );
if ( ava == NULL ) {
rc = LDAP_NO_MEMORY;
goto parsing_error;
LDAPAVA **tmp;
if ( tmpRDN == tmpRDN_ ) {
- tmp = LDAP_MALLOC( num_slots * 2 * sizeof( LDAPAVA * ) );
+ tmp = LDAP_MALLOCX( num_slots * 2 * sizeof( LDAPAVA * ), ctx );
if ( tmp == NULL ) {
rc = LDAP_NO_MEMORY;
goto parsing_error;
AC_MEMCPY( tmp, tmpRDN, num_slots * sizeof( LDAPAVA * ) );
} else {
- tmp = LDAP_REALLOC( tmpRDN, num_slots * 2 * sizeof( LDAPAVA * ) );
+ tmp = LDAP_REALLOCX( tmpRDN, num_slots * 2 * sizeof( LDAPAVA * ), ctx );
if ( tmp == NULL ) {
rc = LDAP_NO_MEMORY;
goto parsing_error;
*/
*n = p;
if ( !( flags & LDAP_DN_SKIP ) ) {
- newRDN = (LDAPRDN *)LDAP_MALLOC( sizeof(LDAPRDN)
- + sizeof(LDAPAVA *) * (navas+1) );
+ newRDN = (LDAPRDN)LDAP_MALLOCX(
+ sizeof(LDAPAVA) * (navas+1), ctx );
if ( newRDN == NULL ) {
rc = LDAP_NO_MEMORY;
goto parsing_error;
} else {
- int i;
-
- newRDN[0] = (LDAPAVA**)(newRDN+1);
-
- for (i=0; i<navas; i++)
- newRDN[0][i] = tmpRDN[i];
- newRDN[0][i] = NULL;
+ AC_MEMCPY( newRDN, tmpRDN, sizeof(LDAPAVA *) * navas);
+ newRDN[navas] = NULL;
}
}
/* They are set to NULL after they're used in an AVA */
if ( attrValue.bv_val ) {
- free( attrValue.bv_val );
+ LDAP_FREEX( attrValue.bv_val, ctx );
}
for ( navas-- ; navas >= 0; navas-- ) {
- ldap_avafree( tmpRDN[navas] );
+ ldapava_free( tmpRDN[navas], ctx );
}
return_result:;
if ( tmpRDN != tmpRDN_ ) {
- LDAP_FREE( tmpRDN );
+ LDAP_FREEX( tmpRDN, ctx );
}
if ( rdn ) {
* '\' + HEXPAIR(p) -> unhex(p)
*/
static int
-str2strval( const char *str, ber_len_t stoplen, struct berval *val, const char **next, unsigned flags, unsigned *retFlags )
+str2strval( const char *str, ber_len_t stoplen, struct berval *val, const char **next, unsigned flags, unsigned *retFlags, void *ctx )
{
const char *p, *end, *startPos, *endPos = NULL;
ber_len_t len, escapes;
if ( escapes == 0 ) {
if ( *retFlags == LDAP_AVA_NONPRINTABLE ) {
- val->bv_val = LDAP_MALLOC( len + 1 );
+ val->bv_val = LDAP_MALLOCX( len + 1, ctx );
AC_MEMCPY( val->bv_val, startPos, len );
val->bv_val[ len ] = '\0';
} else {
- val->bv_val = LDAP_STRNDUP( startPos, len );
+ val->bv_val = LDAP_STRNDUPX( startPos, len, ctx );
}
} else {
ber_len_t s, d;
- val->bv_val = LDAP_MALLOC( len + 1 );
+ val->bv_val = LDAP_MALLOCX( len + 1, ctx );
for ( s = 0, d = 0; d < len; ) {
if ( LDAP_DN_ESCAPE( startPos[ s ] ) ) {
s++;
}
static int
-DCE2strval( const char *str, struct berval *val, const char **next, unsigned flags )
+DCE2strval( const char *str, struct berval *val, const char **next, unsigned flags, void *ctx )
{
const char *p, *startPos, *endPos = NULL;
ber_len_t len, escapes;
len = ( endPos ? endPos : p ) - startPos - escapes;
val->bv_len = len;
if ( escapes == 0 ){
- val->bv_val = LDAP_STRNDUP( startPos, len );
+ val->bv_val = LDAP_STRNDUPX( startPos, len, ctx );
} else {
ber_len_t s, d;
- val->bv_val = LDAP_MALLOC( len + 1 );
+ val->bv_val = LDAP_MALLOCX( len + 1, ctx );
for ( s = 0, d = 0; d < len; ) {
/*
* This point is reached only if escapes
}
static int
-IA52strval( const char *str, struct berval *val, const char **next, unsigned flags )
+IA52strval( const char *str, struct berval *val, const char **next, unsigned flags, void *ctx )
{
const char *p, *startPos, *endPos = NULL;
ber_len_t len, escapes;
len = ( endPos ? endPos : p ) - startPos - escapes;
val->bv_len = len;
if ( escapes == 0 ) {
- val->bv_val = LDAP_STRNDUP( startPos, len );
+ val->bv_val = LDAP_STRNDUPX( startPos, len, ctx );
} else {
ber_len_t s, d;
- val->bv_val = LDAP_MALLOC( len + 1 );
+ val->bv_val = LDAP_MALLOCX( len + 1, ctx );
for ( s = 0, d = 0; d < len; ) {
if ( LDAP_DN_ESCAPE( startPos[ s ] ) ) {
s++;
}
static int
-quotedIA52strval( const char *str, struct berval *val, const char **next, unsigned flags )
+quotedIA52strval( const char *str, struct berval *val, const char **next, unsigned flags, void *ctx )
{
const char *p, *startPos, *endPos = NULL;
ber_len_t len;
assert( endPos >= startPos + escapes );
val->bv_len = len;
if ( escapes == 0 ) {
- val->bv_val = LDAP_STRNDUP( startPos, len );
+ val->bv_val = LDAP_STRNDUPX( startPos, len, ctx );
} else {
ber_len_t s, d;
- val->bv_val = LDAP_MALLOC( len + 1 );
+ val->bv_val = LDAP_MALLOCX( len + 1, ctx );
val->bv_len = len;
for ( s = d = 0; d < len; ) {
}
static int
-hexstr2binval( const char *str, struct berval *val, const char **next, unsigned flags )
+hexstr2binval( const char *str, struct berval *val, const char **next, unsigned flags, void *ctx )
{
const char *p, *startPos, *endPos = NULL;
ber_len_t len;
assert( 2 * len == (ber_len_t) (( endPos ? endPos : p ) - startPos ));
val->bv_len = len;
- val->bv_val = LDAP_MALLOC( len + 1 );
+ val->bv_val = LDAP_MALLOCX( len + 1, ctx );
if ( val->bv_val == NULL ) {
return( LDAP_NO_MEMORY );
}
* by Luke Howard, http://www.padl.com/~lukeh)
*/
static int
-dn2domain( LDAPDN *dn, struct berval *bv, int pos, int *iRDN )
+dn2domain( LDAPDN dn, struct berval *bv, int pos, int *iRDN )
{
int i;
int domain = 0, first = 1;
str = bv->bv_val + pos;
for ( i = *iRDN; i >= 0; i-- ) {
- LDAPRDN *rdn;
+ LDAPRDN rdn;
LDAPAVA *ava;
- assert( dn[ 0 ][ i ] );
- rdn = dn[ 0 ][ i ];
+ assert( dn[ i ] );
+ rdn = dn[ i ];
- assert( rdn[ 0 ][ 0 ] );
- ava = rdn[ 0 ][ 0 ];
+ assert( rdn[ 0 ] );
+ ava = rdn[ 0 ];
if ( !LDAP_DN_IS_RDN_DC( rdn ) ) {
break;
}
static int
-rdn2strlen( LDAPRDN *rdn, unsigned flags, ber_len_t *len,
+rdn2strlen( LDAPRDN rdn, unsigned flags, ber_len_t *len,
int ( *s2l )( struct berval *v, unsigned f, ber_len_t *l ) )
{
int iAVA;
*len = 0;
- for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ 0 ][ iAVA ];
+ for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ iAVA ];
/* len(type) + '=' + '+' | ',' */
l += ava->la_attr.bv_len + 2;
}
static int
-rdn2str( LDAPRDN *rdn, char *str, unsigned flags, ber_len_t *len,
+rdn2str( LDAPRDN rdn, char *str, unsigned flags, ber_len_t *len,
int ( *s2s ) ( struct berval *v, char * s, unsigned f, ber_len_t *l ) )
{
int iAVA;
ber_len_t l = 0;
- for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ 0 ][ iAVA ];
+ for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ iAVA ];
AC_MEMCPY( &str[ l ], ava->la_attr.bv_val,
ava->la_attr.bv_len );
}
l += vl;
}
- str[ l++ ] = ( rdn[ 0 ][ iAVA + 1 ] ? '+' : ',' );
+ str[ l++ ] = ( rdn[ iAVA + 1] ? '+' : ',' );
}
*len = l;
}
static int
-rdn2DCEstrlen( LDAPRDN *rdn, unsigned flags, ber_len_t *len )
+rdn2DCEstrlen( LDAPRDN rdn, unsigned flags, ber_len_t *len )
{
int iAVA;
ber_len_t l = 0;
*len = 0;
- for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ 0 ][ iAVA ];
+ for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ iAVA ];
/* len(type) + '=' + ',' | '/' */
l += ava->la_attr.bv_len + 2;
}
static int
-rdn2DCEstr( LDAPRDN *rdn, char *str, unsigned flags, ber_len_t *len, int first )
+rdn2DCEstr( LDAPRDN rdn, char *str, unsigned flags, ber_len_t *len, int first )
{
int iAVA;
ber_len_t l = 0;
- for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ 0 ][ iAVA ];
+ for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ iAVA ];
if ( first ) {
first = 0;
}
static int
-rdn2UFNstrlen( LDAPRDN *rdn, unsigned flags, ber_len_t *len )
+rdn2UFNstrlen( LDAPRDN rdn, unsigned flags, ber_len_t *len )
{
int iAVA;
ber_len_t l = 0;
*len = 0;
- for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ 0 ][ iAVA ];
+ for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ iAVA ];
/* ' + ' | ', ' */
- l += ( rdn[ 0 ][ iAVA + 1 ] ? 3 : 2 );
+ l += ( rdn[ iAVA + 1 ] ? 3 : 2 );
/* FIXME: are binary values allowed in UFN? */
if ( ava->la_flags & LDAP_AVA_BINARY ) {
}
static int
-rdn2UFNstr( LDAPRDN *rdn, char *str, unsigned flags, ber_len_t *len )
+rdn2UFNstr( LDAPRDN rdn, char *str, unsigned flags, ber_len_t *len )
{
int iAVA;
ber_len_t l = 0;
- for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ 0 ][ iAVA ];
+ for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ iAVA ];
if ( ava->la_flags & LDAP_AVA_BINARY ) {
str[ l++ ] = '#';
l += vl;
}
- if ( rdn[ 0 ][ iAVA + 1 ]) {
+ if ( rdn[ iAVA + 1 ] ) {
AC_MEMCPY( &str[ l ], " + ", 3 );
l += 3;
}
static int
-rdn2ADstrlen( LDAPRDN *rdn, unsigned flags, ber_len_t *len )
+rdn2ADstrlen( LDAPRDN rdn, unsigned flags, ber_len_t *len )
{
int iAVA;
ber_len_t l = 0;
*len = 0;
- for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ 0 ][ iAVA ];
+ for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ iAVA ];
/* ',' | '/' */
l++;
}
static int
-rdn2ADstr( LDAPRDN *rdn, char *str, unsigned flags, ber_len_t *len, int first )
+rdn2ADstr( LDAPRDN rdn, char *str, unsigned flags, ber_len_t *len, int first )
{
int iAVA;
ber_len_t l = 0;
- for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ 0 ][ iAVA ];
+ for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ iAVA ];
if ( first ) {
first = 0;
* this is wanted to reduce the allocation of temporary buffers.
*/
int
-ldap_rdn2str( LDAPRDN *rdn, char **str, unsigned flags )
+ldap_rdn2str( LDAPRDN rdn, char **str, unsigned flags )
{
struct berval bv;
int rc;
return LDAP_PARAM_ERROR;
}
- rc = ldap_rdn2bv( rdn, &bv, flags );
+ rc = ldap_rdn2bv_x( rdn, &bv, flags, NULL );
*str = bv.bv_val;
return rc;
}
int
-ldap_rdn2bv( LDAPRDN *rdn, struct berval *bv, unsigned flags )
+ldap_rdn2bv( LDAPRDN rdn, struct berval *bv, unsigned flags )
+{
+ return ldap_rdn2bv_x( rdn, bv, flags, NULL );
+}
+
+int
+ldap_rdn2bv_x( LDAPRDN rdn, struct berval *bv, unsigned flags, void *ctx )
{
int rc, back;
ber_len_t l;
bv->bv_val = NULL;
if ( rdn == NULL ) {
- bv->bv_val = LDAP_STRDUP( "" );
+ bv->bv_val = LDAP_STRDUPX( "", ctx );
return( LDAP_SUCCESS );
}
return LDAP_PARAM_ERROR;
}
- bv->bv_val = LDAP_MALLOC( l + 1 );
+ bv->bv_val = LDAP_MALLOCX( l + 1, ctx );
switch ( LDAP_DN_FORMAT( flags ) ) {
case LDAP_DN_FORMAT_LDAPV3:
}
if ( rc ) {
- ldap_memfree( bv->bv_val );
+ LDAP_FREEX( bv->bv_val, ctx );
return rc;
}
* c) what do we do when binary values must be converted in UTF/DCE/AD?
* use binary encoded BER
*/
-int ldap_dn2str( LDAPDN *dn, char **str, unsigned flags )
+int ldap_dn2str( LDAPDN dn, char **str, unsigned flags )
{
struct berval bv;
int rc;
return LDAP_PARAM_ERROR;
}
- rc = ldap_dn2bv( dn, &bv, flags );
+ rc = ldap_dn2bv_x( dn, &bv, flags, NULL );
*str = bv.bv_val;
return rc;
}
-int ldap_dn2bv( LDAPDN *dn, struct berval *bv, unsigned flags )
+int ldap_dn2bv( LDAPDN dn, struct berval *bv, unsigned flags )
+{
+ return ldap_dn2bv_x( dn, bv, flags, NULL );
+}
+
+int ldap_dn2bv_x( LDAPDN dn, struct berval *bv, unsigned flags, void *ctx )
{
int iRDN;
int rc = LDAP_ENCODING_ERROR;
* FIXME: better raise an error?
*/
if ( dn == NULL ) {
- bv->bv_val = LDAP_STRDUP( "" );
+ bv->bv_val = LDAP_STRDUPX( "", ctx );
return( LDAP_SUCCESS );
}
sv2s = strval2IA5str;
}
- for ( iRDN = 0, len = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
+ for ( iRDN = 0, len = 0; dn[ iRDN ]; iRDN++ ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ 0 ][ iRDN ];
-
- if ( rdn2strlen( rdn, flags, &rdnl, sv2l ) ) {
+ if ( rdn2strlen( dn[ iRDN ], flags, &rdnl, sv2l ) ) {
goto return_results;
}
len += rdnl;
}
- if ( ( bv->bv_val = LDAP_MALLOC( len + 1 ) ) == NULL ) {
+ if ( ( bv->bv_val = LDAP_MALLOCX( len + 1, ctx ) ) == NULL ) {
rc = LDAP_NO_MEMORY;
break;
}
- for ( l = 0, iRDN = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
+ for ( l = 0, iRDN = 0; dn[ iRDN ]; iRDN++ ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ 0 ][ iRDN ];
- if ( rdn2str( rdn, &bv->bv_val[ l ], flags,
+ if ( rdn2str( dn[ iRDN ], &bv->bv_val[ l ], flags,
&rdnl, sv2s ) ) {
- LDAP_FREE( bv->bv_val );
+ LDAP_FREEX( bv->bv_val, ctx );
bv->bv_val = NULL;
goto return_results;
}
int last_iRDN = -1;
#endif /* DC_IN_UFN */
- for ( iRDN = 0, len = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
+ for ( iRDN = 0, len = 0; dn[ iRDN ]; iRDN++ ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ 0 ][ iRDN ];
- if ( rdn2UFNstrlen( rdn, flags, &rdnl ) ) {
+ if ( rdn2UFNstrlen( dn[ iRDN ], flags, &rdnl ) ) {
goto return_results;
}
len += rdnl;
#ifdef DC_IN_UFN
- if ( LDAP_DN_IS_RDN_DC( rdn ) ) {
+ if ( LDAP_DN_IS_RDN_DC( dn[ iRDN ] ) ) {
if ( leftmost_dc == -1 ) {
leftmost_dc = iRDN;
}
#endif /* DC_IN_UFN */
}
- if ( ( bv->bv_val = LDAP_MALLOC( len + 1 ) ) == NULL ) {
+ if ( ( bv->bv_val = LDAP_MALLOCX( len + 1, ctx ) ) == NULL ) {
rc = LDAP_NO_MEMORY;
break;
}
#ifdef DC_IN_UFN
if ( leftmost_dc == -1 ) {
#endif /* DC_IN_UFN */
- for ( l = 0, iRDN = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
+ for ( l = 0, iRDN = 0; dn[ iRDN ]; iRDN++ ) {
ber_len_t vl;
- LDAPRDN *rdn = dn[ 0 ][ iRDN ];
- if ( rdn2UFNstr( rdn, &bv->bv_val[ l ],
+ if ( rdn2UFNstr( dn[ iRDN ], &bv->bv_val[ l ],
flags, &vl ) ) {
- LDAP_FREE( bv->bv_val );
+ LDAP_FREEX( bv->bv_val, ctx );
bv->bv_val = NULL;
goto return_results;
}
for ( l = 0, iRDN = 0; iRDN < leftmost_dc; iRDN++ ) {
ber_len_t vl;
- LDAPRDN *rdn = dn[ 0 ][ iRDN ];
- if ( rdn2UFNstr( rdn, &bv->bv_val[ l ],
+ if ( rdn2UFNstr( dn[ iRDN ], &bv->bv_val[ l ],
flags, &vl ) ) {
- LDAP_FREE( bv->bv_val );
+ LDAP_FREEX( bv->bv_val, ctx );
bv->bv_val = NULL;
goto return_results;
}
}
if ( !dn2domain( dn, bv, l, &last_iRDN ) ) {
- LDAP_FREE( bv->bv_val );
+ LDAP_FREEX( bv->bv_val, ctx );
bv->bv_val = NULL;
goto return_results;
}
} break;
case LDAP_DN_FORMAT_DCE:
- for ( iRDN = 0, len = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
+ for ( iRDN = 0, len = 0; dn[ iRDN ]; iRDN++ ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ 0 ][ iRDN ];
-
- if ( rdn2DCEstrlen( rdn, flags, &rdnl ) ) {
+ if ( rdn2DCEstrlen( dn[ iRDN ], flags, &rdnl ) ) {
goto return_results;
}
len += rdnl;
}
- if ( ( bv->bv_val = LDAP_MALLOC( len + 1 ) ) == NULL ) {
+ if ( ( bv->bv_val = LDAP_MALLOCX( len + 1, ctx ) ) == NULL ) {
rc = LDAP_NO_MEMORY;
break;
}
for ( l = 0; iRDN--; ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ 0 ][ iRDN ];
- if ( rdn2DCEstr( rdn, &bv->bv_val[ l ], flags,
+ if ( rdn2DCEstr( dn[ iRDN ], &bv->bv_val[ l ], flags,
&rdnl, 0 ) ) {
- LDAP_FREE( bv->bv_val );
+ LDAP_FREEX( bv->bv_val, ctx );
bv->bv_val = NULL;
goto return_results;
}
*
* "microsoft.com/People/Bill,Gates"
*/
- for ( iRDN = 0, len = -1; dn[ 0 ][ iRDN ]; iRDN++ ) {
+ for ( iRDN = 0, len = -1; dn[ iRDN ]; iRDN++ ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ 0 ][ iRDN ];
- if ( rdn2ADstrlen( rdn, flags, &rdnl ) ) {
+ if ( rdn2ADstrlen( dn[ iRDN ], flags, &rdnl ) ) {
goto return_results;
}
len += rdnl;
}
- if ( ( bv->bv_val = LDAP_MALLOC( len + 1 ) ) == NULL ) {
+ if ( ( bv->bv_val = LDAP_MALLOCX( len + 1, ctx ) ) == NULL ) {
rc = LDAP_NO_MEMORY;
break;
}
if ( iRDN && dn2domain( dn, bv, 0, &iRDN ) ) {
for ( l = bv->bv_len; iRDN >= 0 ; iRDN-- ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ 0 ][ iRDN ];
- if ( rdn2ADstr( rdn, &bv->bv_val[ l ],
+ if ( rdn2ADstr( dn[ iRDN ], &bv->bv_val[ l ],
flags, &rdnl, 0 ) ) {
- LDAP_FREE( bv->bv_val );
+ LDAP_FREEX( bv->bv_val, ctx );
bv->bv_val = NULL;
goto return_results;
}
* i.e. terminated by a domain component
*/
if ( flags & LDAP_DN_PEDANTIC ) {
- LDAP_FREE( bv->bv_val );
+ LDAP_FREEX( bv->bv_val, ctx );
bv->bv_val = NULL;
rc = LDAP_ENCODING_ERROR;
break;
for ( l = 0; iRDN >= 0 ; iRDN-- ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ 0 ][ iRDN ];
- if ( rdn2ADstr( rdn, &bv->bv_val[ l ],
+ if ( rdn2ADstr( dn[ iRDN ], &bv->bv_val[ l ],
flags, &rdnl, first ) ) {
- LDAP_FREE( bv->bv_val );
+ LDAP_FREEX( bv->bv_val, ctx );
bv->bv_val = NULL;
goto return_results;
}
ldap_X509dn2bv( void *x509_name, struct berval *bv, LDAPDN_rewrite_func *func,
unsigned flags )
{
- LDAPDN *newDN;
- LDAPRDN *newRDN;
+ LDAPDN newDN;
+ LDAPRDN newRDN;
LDAPAVA *newAVA, *baseAVA;
X509_NAME_ENTRY *ne;
ASN1_OBJECT *obj;
nrdns = ne->set + 1;
/* Allocate the DN/RDN/AVA stuff as a single block */
- dnsize = sizeof(LDAPDN) + sizeof(LDAPRDN *) * (nrdns+1);
- dnsize += sizeof(LDAPRDN) * nrdns + sizeof(LDAPAVA *) * (navas+nrdns);
+ dnsize = sizeof(LDAPRDN) * (nrdns+1);
+ dnsize += sizeof(LDAPAVA *) * (navas+nrdns);
dnsize += sizeof(LDAPAVA) * navas;
if (dnsize > sizeof(ptrs)) {
- newDN = (LDAPDN *)LDAP_MALLOC( dnsize );
+ newDN = (LDAPDN)LDAP_MALLOC( dnsize );
if ( newDN == NULL )
return LDAP_NO_MEMORY;
} else {
- newDN = (LDAPDN *)ptrs;
+ newDN = (LDAPDN)ptrs;
}
- newDN[0] = (LDAPRDN**)(newDN+1);
- newDN[0][nrdns] = NULL;
- newRDN = (LDAPRDN*)(newDN[0] + nrdns+1);
- newAVA = (LDAPAVA*)(newRDN + navas + nrdns*2);
+ newDN[nrdns] = NULL;
+ newRDN = (LDAPRDN)(newDN + nrdns+1);
+ newAVA = (LDAPAVA *)(newRDN + navas + nrdns);
baseAVA = newAVA;
/* Retrieve RDNs in reverse order; LDAP is backwards from X.500. */
* previous RDN and advance.
*/
if ( j > 0 ) {
- newRDN[0][k] = NULL;
- newRDN = (LDAPRDN*)(newRDN[0]+k+1);
+ newRDN[k] = NULL;
+ newRDN += k+1;
}
- newDN[0][j++] = newRDN;
+ newDN[j++] = newRDN;
- newRDN[0] = (LDAPAVA**)(newRDN+1);
k = 0;
set = ne->set;
}
#ifdef HAVE_EBCDIC
newAVA->la_attr.bv_val = LDAP_STRDUP( newAVA->la_attr.bv_val );
__etoa( newAVA->la_attr.bv_val );
+ newAVA->la_flags |= LDAP_AVA_FREE_ATTR;
#endif
} else {
get_oid: newAVA->la_attr.bv_val = oidptr;
/* This uses 8-bit, assume ISO 8859-1 */
csize = 1;
to_utf8: rc = ldap_ucs_to_utf8s( &Val, csize, &newAVA->la_value );
+ newAVA->la_flags |= LDAP_AVA_FREE_VALUE;
if (rc != LDAP_SUCCESS) goto nomem;
newAVA->la_flags = LDAP_AVA_NONPRINTABLE;
break;
case V_ASN1_IA5STRING:
case V_ASN1_PRINTABLESTRING:
/* These are always 7-bit strings */
- ber_dupbv( &newAVA->la_value, &Val );
+ newAVA->la_value = Val;
default:
;
}
- newRDN[0][k] = newAVA;
+ newRDN[k] = newAVA;
newAVA++;
k++;
}
- newRDN[0][k] = NULL;
+ newRDN[k] = NULL;
if ( func ) {
- rc = func( newDN, flags );
+ rc = func( newDN, flags, NULL );
if ( rc != LDAP_SUCCESS )
goto nomem;
}
- rc = ldap_dn2bv( newDN, bv, LDAP_DN_FORMAT_LDAPV3 );
+ rc = ldap_dn2bv_x( newDN, bv, LDAP_DN_FORMAT_LDAPV3, NULL );
nomem:
for (;baseAVA < newAVA; baseAVA++) {
- LDAP_FREE( baseAVA->la_value.bv_val );
-#ifdef HAVE_EBCDIC
- if ( !func ) LDAP_FREE( baseAVA->la_attr.bv_val );
-#endif
+ if (baseAVA->la_flags & LDAP_AVA_FREE_ATTR)
+ LDAP_FREE( baseAVA->la_attr.bv_val );
+ if (baseAVA->la_flags & LDAP_AVA_FREE_VALUE)
+ LDAP_FREE( baseAVA->la_value.bv_val );
}
if ( oidsize != 0 )
LDAP_FREE( oidbuf );
- if ( newDN != (LDAPDN*) ptrs )
+ if ( newDN != (LDAPDN) ptrs )
LDAP_FREE( newDN );
return rc;
}