/* $OpenLDAP$ */
/*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* Portions
#include <ac/time.h>
#include "ldap-int.h"
+#include "ldap_schema.h"
/* extension to UFN that turns trailing "dc=value" rdns in DNS style,
* e.g. "ou=People,dc=openldap,dc=org" => "People, openldap.org" */
#define DC_IN_UFN
/* #define PRETTY_ESCAPE */
-static int dn2dn( const char *dnin, unsigned fin, char **dnout, unsigned fout );
-
-/* from libraries/libldap/schema.c */
-extern char * parse_numericoid(const char **sp, int *code, const int flags);
-
/* parsing/printing routines */
-static int str2strval( const char *str, struct berval **val,
+static int str2strval( const char *str, struct berval *val,
const char **next, unsigned flags, unsigned *retFlags );
-static int DCE2strval( const char *str, struct berval **val,
+static int DCE2strval( const char *str, struct berval *val,
const char **next, unsigned flags );
-static int IA52strval( const char *str, struct berval **val,
+static int IA52strval( const char *str, struct berval *val,
const char **next, unsigned flags );
-static int quotedIA52strval( const char *str, struct berval **val,
+static int quotedIA52strval( const char *str, struct berval *val,
const char **next, unsigned flags );
-static int hexstr2binval( const char *str, struct berval **val,
+static int hexstr2binval( const char *str, struct berval *val,
const char **next, unsigned flags );
static int hexstr2bin( const char *str, char *c );
static int byte2hexpair( const char *val, char *pair );
/* AVA helpers */
static LDAPAVA * ldapava_new(
const struct berval *attr, const struct berval *val, unsigned flags );
-static LDAPRDN * ldapava_append_to_rdn( LDAPRDN *rdn, LDAPAVA *ava );
-static LDAPRDN * ldapava_insert_into_rdn(
- LDAPRDN *rdn, LDAPAVA *ava, unsigned where );
-static LDAPDN * ldapava_append_to_dn( LDAPDN *dn, LDAPRDN *rdn );
-static LDAPDN * ldapava_insert_into_dn(
- LDAPDN *dn, LDAPRDN *rdn, unsigned where );
/* Higher level helpers */
static int rdn2strlen( LDAPRDN *rdn, unsigned flags, ber_len_t *len,
Debug( LDAP_DEBUG_TRACE, "ldap_dn2ufn\n", 0, 0, 0 );
- ( void )dn2dn( dn, LDAP_DN_FORMAT_LDAP, &out, LDAP_DN_FORMAT_UFN );
+ ( void )ldap_dn_normalize( dn, LDAP_DN_FORMAT_LDAP,
+ &out, LDAP_DN_FORMAT_UFN );
return( out );
}
return values;
}
- for ( iRDN = 0; tmpDN[ iRDN ]; iRDN++ ) {
- char *str, **v = NULL;
-
- ldap_rdn2str( tmpDN[ iRDN ][ 0 ], &str, flag );
+ for ( iRDN = 0; tmpDN[ 0 ][ iRDN ]; iRDN++ );
- v = LDAP_REALLOC( values, sizeof( char * ) * ( 2 + iRDN ) );
- if ( v == NULL ) {
- LBER_VFREE( values );
- ldap_dnfree( tmpDN );
- return NULL;
- }
- values = v;
- values[ iRDN ] = str;
+ values = LDAP_MALLOC( sizeof( char * ) * ( 1 + iRDN ) );
+ if ( values == NULL ) {
+ ldap_dnfree( tmpDN );
+ return NULL;
}
+ for ( iRDN = 0; tmpDN[ 0 ][ iRDN ]; iRDN++ ) {
+ ldap_rdn2str( tmpDN[ 0 ][ iRDN ], &values[ iRDN ], flag );
+ }
+ ldap_dnfree( tmpDN );
values[ iRDN ] = NULL;
+
return values;
}
* FIXME: we prefer efficiency over checking if the _ENTIRE_
* dn can be parsed
*/
- if ( ldap_str2rdn( rdn, &tmpRDN, &p, LDAP_DN_FORMAT_LDAP )
+ if ( ldap_str2rdn( rdn, &tmpRDN, (char **) &p, LDAP_DN_FORMAT_LDAP )
!= LDAP_SUCCESS ) {
return( NULL );
}
- for ( iAVA = 0; tmpRDN[ iAVA ]; iAVA++ ) {
+ for ( iAVA = 0; tmpRDN[ 0 ][ iAVA ]; iAVA++ ) ;
+ values = LDAP_MALLOC( sizeof( char * ) * ( 1 + iAVA ) );
+ if ( values == NULL ) {
+ ldap_rdnfree( tmpRDN );
+ return( NULL );
+ }
+
+ for ( iAVA = 0; tmpRDN[ 0 ][ iAVA ]; iAVA++ ) {
ber_len_t l = 0, vl, al = 0;
- char *str, **v = NULL;
- LDAPAVA *ava = tmpRDN[ iAVA ][ 0 ];
-
- v = LDAP_REALLOC( values, sizeof( char * ) * ( 2 + iAVA ) );
- if ( v == NULL ) {
- goto error_return;
- }
- values = v;
+ char *str;
+ LDAPAVA *ava = tmpRDN[ 0 ][ iAVA ];
if ( ava->la_flags == LDAP_AVA_BINARY ) {
- vl = 1 + 2 * ava->la_value->bv_len;
+ vl = 1 + 2 * ava->la_value.bv_len;
} else {
- if ( strval2strlen( ava->la_value,
+ if ( strval2strlen( &ava->la_value,
ava->la_flags, &vl ) ) {
goto error_return;
}
}
if ( !notypes ) {
- al = ava->la_attr->bv_len;
- l = vl + ava->la_attr->bv_len + 1;
+ al = ava->la_attr.bv_len;
+ l = vl + ava->la_attr.bv_len + 1;
str = LDAP_MALLOC( l + 1 );
- AC_MEMCPY( str, ava->la_attr->bv_val,
- ava->la_attr->bv_len );
+ AC_MEMCPY( str, ava->la_attr.bv_val,
+ ava->la_attr.bv_len );
str[ al++ ] = '=';
} else {
if ( ava->la_flags == LDAP_AVA_BINARY ) {
str[ al++ ] = '#';
- if ( binval2hexstr( ava->la_value, &str[ al ] ) ) {
+ if ( binval2hexstr( &ava->la_value, &str[ al ] ) ) {
goto error_return;
}
} else {
- if ( strval2str( ava->la_value, &str[ al ],
+ if ( strval2str( &ava->la_value, &str[ al ],
ava->la_flags, &vl ) ) {
goto error_return;
}
Debug( LDAP_DEBUG_TRACE, "ldap_dn2dcedn\n", 0, 0, 0 );
- ( void )dn2dn( dn, LDAP_DN_FORMAT_LDAP, &out, LDAP_DN_FORMAT_DCE );
+ ( void )ldap_dn_normalize( dn, LDAP_DN_FORMAT_LDAP,
+ &out, LDAP_DN_FORMAT_DCE );
return( out );
}
Debug( LDAP_DEBUG_TRACE, "ldap_dcedn2dn\n", 0, 0, 0 );
- ( void )dn2dn( dce, LDAP_DN_FORMAT_DCE, &out, LDAP_DN_FORMAT_LDAPV3 );
+ ( void )ldap_dn_normalize( dce, LDAP_DN_FORMAT_DCE, &out, LDAP_DN_FORMAT_LDAPV3 );
return( out );
}
Debug( LDAP_DEBUG_TRACE, "ldap_dn2ad_canonical\n", 0, 0, 0 );
- ( void )dn2dn( dn, LDAP_DN_FORMAT_LDAP,
+ ( void )ldap_dn_normalize( dn, LDAP_DN_FORMAT_LDAP,
&out, LDAP_DN_FORMAT_AD_CANONICAL );
return( out );
}
-int
-ldap_dn_normalize( const char *in, unsigned iflags, char **out, unsigned oflags )
-{
- assert( out );
-
- Debug( LDAP_DEBUG_TRACE, "ldap_dn_normalize\n", 0, 0, 0 );
-
- return dn2dn( in, iflags, out, oflags);
-}
-
/*
- * helper that changes the string representation of dnin
+ * function that changes the string representation of dnin
* from ( fin & LDAP_DN_FORMAT_MASK ) to ( fout & LDAP_DN_FORMAT_MASK )
*
* fin can be one of:
* LDAP_DN_FORMAT_UFN (rfc 1781, partial and with extensions)
* LDAP_DN_FORMAT_AD_CANONICAL (?)
*/
-static int
-dn2dn( const char *dnin, unsigned fin, char **dnout, unsigned fout )
+int
+ldap_dn_normalize( LDAP_CONST char *dnin,
+ unsigned fin, char **dnout, unsigned fout )
{
int rc;
LDAPDN *tmpDN = NULL;
+ Debug( LDAP_DEBUG_TRACE, "ldap_dn_normalize\n", 0, 0, 0 );
+
assert( dnout );
*dnout = NULL;
*/
#define LDAP_DN_ASCII_SPACE(c) \
( (c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' )
-#define LDAP_DN_ASCII_LOWER(c) ( (c) >= 'a' && (c) <= 'z' )
-#define LDAP_DN_ASCII_UPPER(c) ( (c) >= 'A' && (c) <= 'Z' )
-#define LDAP_DN_ASCII_ALPHA(c) \
- ( LDAP_DN_ASCII_LOWER(c) || LDAP_DN_ASCII_UPPER(c) )
-#define LDAP_DN_ASCII_DIGIT(c) ( (c) >= '0' && (c) <= '9' )
-#define LDAP_DN_ASCII_LCASE_HEXALPHA(c) ( (c) >= 'a' && (c) <= 'f' )
-#define LDAP_DN_ASCII_UCASE_HEXALPHA(c) ( (c) >= 'A' && (c) <= 'F' )
-#define LDAP_DN_ASCII_HEXDIGIT(c) \
- ( LDAP_DN_ASCII_DIGIT(c) \
- || LDAP_DN_ASCII_LCASE_HEXALPHA(c) \
- || LDAP_DN_ASCII_UCASE_HEXALPHA(c) )
-#define LDAP_DN_ASCII_ALNUM(c) \
- ( LDAP_DN_ASCII_ALPHA(c) || LDAP_DN_ASCII_DIGIT(c) )
+#define LDAP_DN_ASCII_LOWER(c) LDAP_LOWER(c)
+#define LDAP_DN_ASCII_UPPER(c) LDAP_UPPER(c)
+#define LDAP_DN_ASCII_ALPHA(c) LDAP_ALPHA(c)
+
+#define LDAP_DN_ASCII_DIGIT(c) LDAP_DIGIT(c)
+#define LDAP_DN_ASCII_LCASE_HEXALPHA(c) LDAP_HEXLOWER(c)
+#define LDAP_DN_ASCII_UCASE_HEXALPHA(c) LDAP_HEXUPPER(c)
+#define LDAP_DN_ASCII_HEXDIGIT(c) LDAP_HEX(c)
+#define LDAP_DN_ASCII_ALNUM(c) LDAP_ALNUM(c)
#define LDAP_DN_ASCII_PRINTABLE(c) ( (c) >= ' ' && (c) <= '~' )
/* attribute type */
-#define LDAP_DN_OID_LEADCHAR(c) ( LDAP_DN_ASCII_DIGIT(c) )
-#define LDAP_DN_DESC_LEADCHAR(c) ( LDAP_DN_ASCII_ALPHA(c) )
-#define LDAP_DN_DESC_CHAR(c) ( LDAP_DN_ASCII_ALNUM(c) || (c) == '-' )
+#define LDAP_DN_OID_LEADCHAR(c) LDAP_DIGIT(c)
+#define LDAP_DN_DESC_LEADCHAR(c) LDAP_ALPHA(c)
+#define LDAP_DN_DESC_CHAR(c) LDAP_LDH(c)
#define LDAP_DN_LANG_SEP(c) ( (c) == ';' )
#define LDAP_DN_ATTRDESC_CHAR(c) \
( LDAP_DN_DESC_CHAR(c) || LDAP_DN_LANG_SEP(c) )
#define LDAP_DC_ATTR "dc"
#define LDAP_DC_ATTRU "DC"
#define LDAP_DN_IS_RDN_DC( r ) \
- ( (r) && (r)[0][0] && !(r)[1] \
+ ( (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)[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])))
/* Composite rules */
#define LDAP_DN_ALLOW_ONE_SPACE(f) \
assert( attr );
assert( val );
- ava = LDAP_MALLOC( sizeof( LDAPAVA ) );
+ ava = LDAP_MALLOC( sizeof( LDAPAVA ) + attr->bv_len + 1 );
/* should we test it? */
if ( ava == NULL ) {
return( NULL );
}
- ava->la_attr = ( struct berval * )attr;
- ava->la_value = ( struct berval * )val;
+ 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_private = NULL;
assert( ava->la_private == NULL );
#endif
- ber_bvfree( ava->la_attr );
- ber_bvfree( ava->la_value );
+#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 );
LDAP_FREE( ava );
}
-LDAPRDN *
-ldapava_append_to_rdn( LDAPRDN *rdn, LDAPAVA *ava )
-{
- LDAPRDN *newRDN;
- unsigned i = 0U;
-
- assert( ava );
-
- if ( rdn != NULL ) {
- for ( i = 0U; rdn[ i ]; i++ ) {
- /* no op */
- }
- }
- newRDN = LDAP_REALLOC( rdn, ( i + 2 ) * sizeof( LDAPAVA ** ) );
- newRDN[ i ] = LDAP_MALLOC( sizeof( LDAPAVA * ) );
- newRDN[ i ][ 0 ] = ava;
- newRDN[ i + 1 ] = NULL;
-
- return( newRDN );
-}
-
-LDAPRDN *
-ldapava_insert_into_rdn( LDAPRDN *rdn, LDAPAVA *ava, unsigned where )
-{
- LDAPRDN *newRDN;
- unsigned i = 0U;
-
- assert( ava );
-
- if ( rdn != NULL ) {
- for ( i = 0U; rdn[ i ]; i++ ) {
- /* no op */
- }
- }
- if ( where > i ) {
- where = i;
- /* assume "at end", which corresponds to
- * ldapava_append_to_rdn */
- }
-
- newRDN = LDAP_REALLOC( rdn, ( i + 2 ) * sizeof( LDAPAVA ** ) );
-
- /* data after insert point */
- AC_MEMCPY( &newRDN[ where + 1 ], &newRDN[ where ],
- ( i - where ) * sizeof( LDAPRDN * ) );
-
- newRDN[ where ] = LDAP_MALLOC( sizeof( LDAPAVA * ) );
- newRDN[ where ][ 0 ] = ava;
- newRDN[ i + 1 ] = NULL;
-
- return( newRDN );
-}
-
void
ldap_rdnfree( LDAPRDN *rdn )
{
return;
}
- for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
- assert( rdn[ iAVA ][ 0 ] );
-
- ldap_avafree( rdn[ iAVA ][ 0 ] );
- }
-
- LDAP_VFREE( rdn );
-}
-
-LDAPDN *
-ldapava_append_to_dn( LDAPDN *dn, LDAPRDN *rdn )
-{
- LDAPDN *newDN;
- unsigned i = 0U;
-
- assert( rdn );
-
- if ( dn != NULL ) {
- for ( i = 0U; dn[ i ]; i++ ) {
- /* no op */
- }
+ for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
+ ldap_avafree( rdn[ 0 ][ iAVA ] );
}
- newDN = LDAP_REALLOC( dn, ( i + 2 ) * sizeof( LDAPRDN ** ) );
- newDN[ i ] = LDAP_MALLOC( sizeof( LDAPRDN * ) );
- newDN[ i ][ 0 ] = rdn;
- newDN[ i + 1 ] = NULL;
- return( newDN );
-}
-
-LDAPDN *
-ldapava_insert_into_dn( LDAPDN *dn, LDAPRDN *rdn, unsigned where )
-{
- LDAPDN *newDN;
- unsigned i = 0U;
-
- assert( rdn );
-
- if ( dn != NULL ) {
- for ( i = 0U; dn[ i ]; i++ ) {
- /* no op */
- }
- }
- if ( where > i ) {
- where = i;
- /* assume "at end", which corresponds to
- * ldapava_append_to_dn */
- }
-
- newDN = LDAP_REALLOC( dn, ( i + 2 ) * sizeof( LDAPRDN ** ) );
-
- /* data after insert point */
- AC_MEMCPY( &newDN[ where + 1 ], &newDN[ where ],
- ( i - where ) * sizeof( LDAPDN * ) );
-
- newDN[ where ] = LDAP_MALLOC( sizeof( LDAPRDN * ) );
- newDN[ where ][ 0 ] = rdn;
- newDN[ i + 1 ] = NULL;
-
- return( newDN );
+ LDAP_FREE( rdn );
}
void
return;
}
- for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
- assert( dn[ iRDN ][ 0 ] );
-
- ldap_rdnfree( dn[ iRDN ][ 0 ] );
+ for ( iRDN = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
+ ldap_rdnfree( dn[ 0 ][ iRDN ] );
}
- LDAP_VFREE( dn );
+ LDAP_FREE( dn );
}
/*
* and readable as soon as it works as expected.
*/
+#define TMP_SLOTS 1024
+
int
-ldap_str2dn( const char *str, LDAPDN **dn, unsigned flags )
+ldap_str2dn( LDAP_CONST char *str, LDAPDN **dn, unsigned flags )
{
const char *p;
- int rc = LDAP_INVALID_DN_SYNTAX;
+ int rc = LDAP_DECODING_ERROR;
+ int nrdns = 0;
LDAPDN *newDN = NULL;
- LDAPRDN *newRDN = NULL;
+ LDAPRDN *newRDN = NULL, *tmpDN[TMP_SLOTS];
assert( str );
assert( dn );
/* unsupported in str2dn */
case LDAP_DN_FORMAT_UFN:
case LDAP_DN_FORMAT_AD_CANONICAL:
- return( LDAP_INVALID_DN_SYNTAX );
+ return LDAP_PARAM_ERROR;
+ case LDAP_DN_FORMAT_LBER:
default:
- return( LDAP_OTHER );
+ return LDAP_PARAM_ERROR;
}
if ( str[ 0 ] == '\0' ) {
- return( LDAP_SUCCESS );
+ return LDAP_SUCCESS;
}
p = str;
}
for ( ; p[ 0 ]; p++ ) {
- LDAPDN *dn;
int err;
- err = ldap_str2rdn( p, &newRDN, &p, flags );
+ err = ldap_str2rdn( p, &newRDN, (char **) &p, flags );
if ( err != LDAP_SUCCESS ) {
goto parsing_error;
}
switch ( LDAP_DN_FORMAT( flags ) ) {
case LDAP_DN_FORMAT_LDAPV3:
if ( !LDAP_DN_RDN_SEP( p[ 0 ] ) ) {
- rc = LDAP_OTHER;
+ rc = LDAP_DECODING_ERROR;
goto parsing_error;
}
break;
case LDAP_DN_FORMAT_LDAP:
case LDAP_DN_FORMAT_LDAPV2:
if ( !LDAP_DN_RDN_SEP_V2( p[ 0 ] ) ) {
- rc = LDAP_OTHER;
+ rc = LDAP_DECODING_ERROR;
goto parsing_error;
}
break;
case LDAP_DN_FORMAT_DCE:
if ( !LDAP_DN_RDN_SEP_DCE( p[ 0 ] ) ) {
- rc = LDAP_OTHER;
+ rc = LDAP_DECODING_ERROR;
goto parsing_error;
}
break;
}
- if ( LDAP_DN_DCE( flags ) ) {
- /* add in reversed order */
- dn = ldapava_insert_into_dn( newDN, newRDN, 0 );
- } else {
- dn = ldapava_append_to_dn( newDN, newRDN );
- }
+ tmpDN[nrdns++] = newRDN;
+ newRDN = NULL;
- if ( dn == NULL ) {
- rc = LDAP_NO_MEMORY;
+#if 0
+ /*
+ * prone to attacks?
+ */
+ assert (nrdns < TMP_SLOTS);
+#else
+ /*
+ * make the static AVA array dynamically rescalable
+ */
+ if (nrdns >= TMP_SLOTS) {
+ rc = LDAP_DECODING_ERROR;
goto parsing_error;
}
-
- newDN = dn;
- newRDN = NULL;
+#endif
if ( p[ 0 ] == '\0' ) {
-
/*
* the DN is over, phew
*/
- rc = LDAP_SUCCESS;
+ newDN = (LDAPDN *)LDAP_MALLOC( sizeof(LDAPDN) +
+ sizeof(LDAPRDN *) * (nrdns+1));
+ 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];
+ } else {
+ for ( i=0; i<nrdns; i++ )
+ newDN[0][i] = tmpDN[i];
+ }
+ newDN[0][nrdns] = NULL;
+ rc = LDAP_SUCCESS;
+ }
goto return_result;
}
}
ldap_rdnfree( newRDN );
}
- if ( newDN ) {
- ldap_dnfree( newDN );
- newDN = NULL;
- }
+ for (nrdns-- ;nrdns>=0; nrdns-- )
+ ldap_rdnfree( tmpDN[nrdns] );
return_result:;
-
Debug( LDAP_DEBUG_TRACE, "<= ldap_str2dn(%s,%u)=%d\n", str, flags, rc );
*dn = newDN;
* corresponds to the rdn separator or to '\0' in case the string is over.
*/
int
-ldap_str2rdn( const char *str, LDAPRDN **rdn, const char **n, unsigned flags )
+ldap_str2rdn( LDAP_CONST char *str, LDAPRDN **rdn,
+ char **n_in, unsigned flags )
{
+ const char **n = (const char **) n_in;
const char *p;
+ int navas = 0;
int state = B4AVA;
- int rc = LDAP_INVALID_DN_SYNTAX;
+ int rc = LDAP_DECODING_ERROR;
int attrTypeEncoding = LDAP_AVA_STRING,
attrValueEncoding = LDAP_AVA_STRING;
- struct berval *attrType = NULL;
- struct berval *attrValue = NULL;
+ struct berval attrType = { 0, NULL };
+ struct berval attrValue = { 0, NULL };
LDAPRDN *newRDN = NULL;
+ LDAPAVA *tmpRDN[TMP_SLOTS];
assert( str );
- assert( rdn );
+ assert( rdn || flags & LDAP_DN_SKIP );
assert( n );
Debug( LDAP_DEBUG_TRACE, "=> ldap_str2rdn(%s,%u)\n%s", str, flags, "" );
- *rdn = NULL;
+ if ( rdn ) {
+ *rdn = NULL;
+ }
*n = NULL;
switch ( LDAP_DN_FORMAT( flags ) ) {
/* unsupported in str2dn */
case LDAP_DN_FORMAT_UFN:
case LDAP_DN_FORMAT_AD_CANONICAL:
- return( LDAP_INVALID_DN_SYNTAX );
+ return LDAP_PARAM_ERROR;
+ case LDAP_DN_FORMAT_LBER:
default:
- return( LDAP_OTHER );
+ return LDAP_PARAM_ERROR;
}
if ( str[ 0 ] == '\0' ) {
- return( LDAP_SUCCESS );
+ return LDAP_SUCCESS;
}
p = str;
case B4OIDATTRTYPE: {
int err = LDAP_SUCCESS;
- char *type;
- type = parse_numericoid( &p, &err, 0 );
- if ( type == NULL ) {
- goto parsing_error;
- }
- attrType = LDAP_MALLOC( sizeof( struct berval ) );
- if ( attrType== NULL ) {
- rc = LDAP_NO_MEMORY;
+ attrType.bv_val = ldap_int_parse_numericoid( &p, &err,
+ LDAP_SCHEMA_SKIP);
+
+ if ( err != LDAP_SUCCESS ) {
goto parsing_error;
}
- attrType->bv_val = type;
- attrType->bv_len = strlen( type );
+ attrType.bv_len = p - attrType.bv_val;
+
attrTypeEncoding = LDAP_AVA_BINARY;
state = B4AVAEQUALS;
goto parsing_error;
}
- assert( attrType == NULL );
- attrType = LDAP_MALLOC( sizeof( struct berval ) );
- if ( attrType == NULL ) {
- rc = LDAP_NO_MEMORY;
- goto parsing_error;
- }
- attrType->bv_val = LDAP_STRNDUP( startPos, len );
- if ( attrType->bv_val == NULL ) {
- rc = LDAP_NO_MEMORY;
- goto parsing_error;
- }
- attrType->bv_len = len;
attrTypeEncoding = LDAP_AVA_STRING;
/*
*/
state = B4AVAEQUALS;
+
+ if ( flags & LDAP_DN_SKIP ) {
+ break;
+ }
+
+ attrType.bv_val = (char *)startPos;
+ attrType.bv_len = len;
+
break;
}
* here STRING means RFC 2253 string
* FIXME: what about DCE strings?
*/
- state = B4STRINGVALUE;
+ if ( !p[ 0 ] ) {
+ /* empty value */
+ state = GOTAVA;
+ } else {
+ state = B4STRINGVALUE;
+ }
break;
case B4BINARYVALUE:
break;
case GOTAVA: {
- LDAPAVA *ava;
- LDAPRDN *rdn;
int rdnsep = 0;
- /*
- * we accept empty values
- */
- ava = ldapava_new( attrType, attrValue,
- attrValueEncoding );
- if ( ava == NULL ) {
- rc = LDAP_NO_MEMORY;
- goto parsing_error;
- }
+ if ( !( flags & LDAP_DN_SKIP ) ) {
+ LDAPAVA *ava;
- rdn = ldapava_append_to_rdn( newRDN, ava );
- if ( rdn == NULL ) {
- rc = LDAP_NO_MEMORY;
- goto parsing_error;
+ /*
+ * we accept empty values
+ */
+ ava = ldapava_new( &attrType, &attrValue,
+ attrValueEncoding );
+
+ if ( ava == NULL ) {
+ rc = LDAP_NO_MEMORY;
+ goto parsing_error;
+ }
+ tmpRDN[navas++] = ava;
+
+ attrValue.bv_val = NULL;
+ attrValue.bv_len = 0;
+
+ assert(navas < TMP_SLOTS);
}
- newRDN = rdn;
/*
* if we got an AVA separator ('+', or ',' for DCE )
* the RDN is over, phew
*/
*n = p;
+ if ( !( flags & LDAP_DN_SKIP ) ) {
+ newRDN = (LDAPRDN *)LDAP_MALLOC( sizeof(LDAPRDN)
+ + sizeof(LDAPAVA *) * (navas+1) );
+ 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;
+ }
+
+ }
rc = LDAP_SUCCESS;
goto return_result;
}
/* they should have been used in an AVA */
- attrType = NULL;
- attrValue = NULL;
+ attrType.bv_val = NULL;
+ attrValue.bv_val = NULL;
p++;
state = B4AVA;
goto parsing_error;
}
}
+ *n = p;
parsing_error:;
/* They are set to NULL after they're used in an AVA */
- if ( attrType ) {
- ber_bvfree( attrType );
- }
- if ( attrValue ) {
- ber_bvfree( attrValue );
+ if ( attrValue.bv_val ) {
+ free( attrValue.bv_val );
}
- if ( newRDN ) {
- ldap_rdnfree( newRDN );
- newRDN = NULL;
- }
+ for (navas-- ; navas>=0; navas-- )
+ ldap_avafree( tmpRDN[navas] );
return_result:;
Debug( LDAP_DEBUG_TRACE, "<= ldap_str2rdn(%*s)=%d\n",
- *n - p, str, rc );
- *rdn = newRDN;
+ p - str, str, rc );
+ if ( rdn ) {
+ *rdn = newRDN;
+ }
return( rc );
}
* '\' + HEXPAIR(p) -> unhex(p)
*/
static int
-str2strval( const char *str, struct berval **val, const char **next, unsigned flags, unsigned *retFlags )
+str2strval( const char *str, struct berval *val, const char **next, unsigned flags, unsigned *retFlags )
{
const char *p, *startPos, *endPos = NULL;
ber_len_t len, escapes, unescapes;
assert( val );
assert( next );
- *val = NULL;
*next = NULL;
for ( startPos = p = str, escapes = 0, unescapes = 0; p[ 0 ]; p++ ) {
*/
unescapes++;
+ } else if (!LDAP_DN_ASCII_PRINTABLE( p[ 0 ] ) ) {
+ *retFlags = LDAP_AVA_NONPRINTABLE;
+
} else if ( ( LDAP_DN_LDAP( flags ) && LDAP_DN_VALUE_END_V2( p[ 0 ] ) )
|| ( LDAP_DN_LDAPV3( flags ) && LDAP_DN_VALUE_END( p[ 0 ] ) ) ) {
break;
}
}
+ *next = p;
+ if ( flags & LDAP_DN_SKIP ) {
+ return( 0 );
+ }
+
/*
* FIXME: test memory?
*/
len = ( endPos ? endPos : p ) - startPos - escapes - unescapes;
- *val = LDAP_MALLOC( sizeof( struct berval ) );
- ( *val )->bv_len = len;
+ val->bv_len = len;
if ( escapes == 0 && unescapes == 0 ) {
- ( *val )->bv_val = LDAP_STRNDUP( startPos, len );
+ val->bv_val = LDAP_STRNDUP( startPos, len );
} else {
ber_len_t s, d;
- ( *val )->bv_val = LDAP_MALLOC( len + 1 );
+ val->bv_val = LDAP_MALLOC( len + 1 );
for ( s = 0, d = 0; d < len; ) {
if ( LDAP_DN_ESCAPE( startPos[ s ] ) ) {
s++;
if ( ( s == 0 && LDAP_DN_NEEDESCAPE_LEAD( startPos[ s ] ) )
|| ( s == len - 1 && LDAP_DN_NEEDESCAPE_TRAIL( startPos[ s ] ) )
|| LDAP_DN_NEEDESCAPE( startPos[ s ] ) ) {
- ( *val )->bv_val[ d++ ] =
+ val->bv_val[ d++ ] =
startPos[ s++ ];
} else if ( LDAP_DN_HEXPAIR( &startPos[ s ] ) ) {
char c;
hexstr2bin( &startPos[ s ], &c );
- ( *val )->bv_val[ d++ ] = c;
+ val->bv_val[ d++ ] = c;
s += 2;
} else {
* we allow escaping of chars
* that do not need to
*/
- ( *val )->bv_val[ d++ ] =
+ val->bv_val[ d++ ] =
startPos[ s++ ];
}
} else {
- ( *val )->bv_val[ d++ ] = startPos[ s++ ];
+ val->bv_val[ d++ ] = startPos[ s++ ];
}
}
- ( *val )->bv_val[ d ] = '\0';
- assert( strlen( ( *val )->bv_val ) == len );
+ val->bv_val[ d ] = '\0';
+ assert( strlen( val->bv_val ) == len );
}
-
- *next = p;
-
return( 0 );
}
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 )
{
const char *p, *startPos, *endPos = NULL;
ber_len_t len, escapes;
assert( val );
assert( next );
- *val = NULL;
*next = NULL;
for ( startPos = p = str, escapes = 0; p[ 0 ]; p++ ) {
}
}
-
+ *next = p;
+ if ( flags & LDAP_DN_SKIP ) {
+ return( 0 );
+ }
+
len = ( endPos ? endPos : p ) - startPos - escapes;
- *val = LDAP_MALLOC( sizeof( struct berval ) );
- ( *val )->bv_len = len;
+ val->bv_len = len;
if ( escapes == 0 ){
- ( *val )->bv_val = LDAP_STRNDUP( startPos, len );
+ val->bv_val = LDAP_STRNDUP( startPos, len );
} else {
ber_len_t s, d;
- ( *val )->bv_val = LDAP_MALLOC( len + 1 );
+ val->bv_val = LDAP_MALLOC( len + 1 );
for ( s = 0, d = 0; d < len; ) {
/*
* This point is reached only if escapes
s++;
}
- ( *val )->bv_val[ d++ ] = startPos[ s++ ];
+ val->bv_val[ d++ ] = startPos[ s++ ];
}
- ( *val )->bv_val[ d ] = '\0';
- assert( strlen( ( *val )->bv_val ) == len );
+ val->bv_val[ d ] = '\0';
+ assert( strlen( val->bv_val ) == len );
}
- *next = p;
-
return( 0 );
}
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 )
{
const char *p, *startPos, *endPos = NULL;
ber_len_t len, escapes;
assert( val );
assert( next );
- *val = NULL;
*next = NULL;
/*
/* no op */
}
- *val = LDAP_MALLOC( sizeof( struct berval ) );
+ *next = p;
+ if ( flags & LDAP_DN_SKIP ) {
+ return( 0 );
+ }
+
len = ( endPos ? endPos : p ) - startPos - escapes;
- ( *val )->bv_len = len;
+ val->bv_len = len;
if ( escapes == 0 ) {
- ( *val )->bv_val = LDAP_STRNDUP( startPos, len );
+ val->bv_val = LDAP_STRNDUP( startPos, len );
} else {
ber_len_t s, d;
- ( *val )->bv_val = LDAP_MALLOC( len + 1 );
+ val->bv_val = LDAP_MALLOC( len + 1 );
for ( s = 0, d = 0; d < len; ) {
if ( LDAP_DN_ESCAPE( startPos[ s ] ) ) {
s++;
}
- ( *val )->bv_val[ d++ ] = startPos[ s++ ];
+ val->bv_val[ d++ ] = startPos[ s++ ];
}
- ( *val )->bv_val[ d ] = '\0';
- assert( strlen( ( *val )->bv_val ) == len );
+ val->bv_val[ d ] = '\0';
+ assert( strlen( val->bv_val ) == len );
}
- *next = p;
return( 0 );
}
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 )
{
const char *p, *startPos, *endPos = NULL;
ber_len_t len;
assert( val );
assert( next );
- *val = NULL;
*next = NULL;
/* initial quote already eaten */
/* no op */
}
+ *next = p;
+ if ( flags & LDAP_DN_SKIP ) {
+ return( 0 );
+ }
+
len = endPos - startPos - escapes;
assert( len >= 0 );
- *val = LDAP_MALLOC( sizeof( struct berval ) );
- ( *val )->bv_len = len;
+ val->bv_len = len;
if ( escapes == 0 ) {
- ( *val )->bv_val = LDAP_STRNDUP( startPos, len );
+ val->bv_val = LDAP_STRNDUP( startPos, len );
} else {
ber_len_t s, d;
- ( *val )->bv_val = LDAP_MALLOC( len + 1 );
- ( *val )->bv_len = len;
+ val->bv_val = LDAP_MALLOC( len + 1 );
+ val->bv_len = len;
for ( s = d = 0; d < len; ) {
if ( LDAP_DN_ESCAPE( str[ s ] ) ) {
s++;
}
- ( *val )->bv_val[ d++ ] = str[ s++ ];
+ val->bv_val[ d++ ] = str[ s++ ];
}
- ( *val )->bv_val[ d ] = '\0';
- assert( strlen( ( *val )->bv_val ) == len );
+ val->bv_val[ d ] = '\0';
+ assert( strlen( val->bv_val ) == len );
}
- *next = p;
-
return( 0 );
}
}
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 )
{
const char *p, *startPos, *endPos = NULL;
ber_len_t len;
assert( val );
assert( next );
- *val = NULL;
*next = NULL;
for ( startPos = p = str; p[ 0 ]; p += 2 ) {
end_of_value:;
+ *next = p;
+ if ( flags & LDAP_DN_SKIP ) {
+ return( 0 );
+ }
+
len = ( ( endPos ? endPos : p ) - startPos ) / 2;
/* must be even! */
assert( 2 * len == (ber_len_t) (( endPos ? endPos : p ) - startPos ));
- *val = LDAP_MALLOC( sizeof( struct berval ) );
- if ( *val == NULL ) {
- return( LDAP_NO_MEMORY );
- }
-
- ( *val )->bv_len = len;
- ( *val )->bv_val = LDAP_MALLOC( len + 1 );
- if ( ( *val )->bv_val == NULL ) {
- LDAP_FREE( *val );
+ val->bv_len = len;
+ val->bv_val = LDAP_MALLOC( len + 1 );
+ if ( val->bv_val == NULL ) {
return( LDAP_NO_MEMORY );
}
hexstr2bin( &startPos[ s ], &c );
- ( *val )->bv_val[ d ] = c;
+ val->bv_val[ d ] = c;
}
- ( *val )->bv_val[ d ] = '\0';
- *next = p;
+ val->bv_val[ d ] = '\0';
return( 0 );
}
}
for ( l = 0, p = val->bv_val; p[ 0 ]; p += cl ) {
- cl = ldap_utf8_charlen( p );
+ cl = LDAP_UTF8_CHARLEN( p );
if ( cl == 0 ) {
/* illegal utf-8 char! */
return( -1 );
* of the value
*/
for ( s = 0, d = 0, end = val->bv_len - 1; s < val->bv_len; ) {
- ber_len_t cl = ldap_utf8_charlen( &val->bv_val[ s ] );
+ ber_len_t cl = LDAP_UTF8_CHARLEN( &val->bv_val[ s ] );
/*
* there might be some chars we want to escape in form
LDAPRDN *rdn;
LDAPAVA *ava;
- assert( dn[ i ][ 0 ] );
- rdn = dn[ i ][ 0 ];
+ assert( dn[ 0 ][ i ] );
+ rdn = dn[ 0 ][ i ];
assert( rdn[ 0 ][ 0 ] );
ava = rdn[ 0 ][ 0 ];
if ( first ) {
first = 0;
- AC_MEMCPY( str, ava->la_value->bv_val,
- ava->la_value->bv_len + 1);
- l += ava->la_value->bv_len;
+ AC_MEMCPY( str, ava->la_value.bv_val,
+ ava->la_value.bv_len + 1);
+ l += ava->la_value.bv_len;
} else {
- AC_MEMCPY( str + ava->la_value->bv_len + 1, bv->bv_val, l);
- AC_MEMCPY( str, ava->la_value->bv_val,
- ava->la_value->bv_len );
- str[ ava->la_value->bv_len ] = '.';
- l += ava->la_value->bv_len + 1;
+ AC_MEMCPY( str + ava->la_value.bv_len + 1, bv->bv_val + pos, l);
+ AC_MEMCPY( str, ava->la_value.bv_val,
+ ava->la_value.bv_len );
+ str[ ava->la_value.bv_len ] = '.';
+ l += ava->la_value.bv_len + 1;
}
}
*len = 0;
- for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ iAVA ][ 0 ];
+ for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ 0 ][ iAVA ];
/* len(type) + '=' + '+' | ',' */
- l += ava->la_attr->bv_len + 2;
+ l += ava->la_attr.bv_len + 2;
if ( ava->la_flags & LDAP_AVA_BINARY ) {
/* octothorpe + twice the length */
- l += 1 + 2 * ava->la_value->bv_len;
+ l += 1 + 2 * ava->la_value.bv_len;
} else {
ber_len_t vl;
unsigned f = flags | ava->la_flags;
- if ( ( *s2l )( ava->la_value, f, &vl ) ) {
+ if ( ( *s2l )( &ava->la_value, f, &vl ) ) {
return( -1 );
}
l += vl;
int iAVA;
ber_len_t l = 0;
- for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ iAVA ][ 0 ];
+ for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ 0 ][ iAVA ];
- AC_MEMCPY( &str[ l ], ava->la_attr->bv_val,
- ava->la_attr->bv_len );
- l += ava->la_attr->bv_len;
+ AC_MEMCPY( &str[ l ], ava->la_attr.bv_val,
+ ava->la_attr.bv_len );
+ l += ava->la_attr.bv_len;
str[ l++ ] = '=';
if ( ava->la_flags & LDAP_AVA_BINARY ) {
str[ l++ ] = '#';
- if ( binval2hexstr( ava->la_value, &str[ l ] ) ) {
+ if ( binval2hexstr( &ava->la_value, &str[ l ] ) ) {
return( -1 );
}
- l += 2 * ava->la_value->bv_len;
+ l += 2 * ava->la_value.bv_len;
} else {
ber_len_t vl;
unsigned f = flags | ava->la_flags;
- if ( ( *s2s )( ava->la_value, &str[ l ], f, &vl ) ) {
+ if ( ( *s2s )( &ava->la_value, &str[ l ], f, &vl ) ) {
return( -1 );
}
l += vl;
}
- str[ l++ ] = ( rdn[ iAVA + 1 ] ? '+' : ',' );
+ str[ l++ ] = ( rdn[ 0 ][ iAVA + 1 ] ? '+' : ',' );
}
*len = l;
*len = 0;
- for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ iAVA ][ 0 ];
+ for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ 0 ][ iAVA ];
/* len(type) + '=' + ',' | '/' */
- l += ava->la_attr->bv_len + 2;
+ l += ava->la_attr.bv_len + 2;
switch ( ava->la_flags ) {
case LDAP_AVA_BINARY:
/* octothorpe + twice the length */
- l += 1 + 2 * ava->la_value->bv_len;
+ l += 1 + 2 * ava->la_value.bv_len;
break;
case LDAP_AVA_STRING: {
ber_len_t vl;
unsigned f = flags | ava->la_flags;
- if ( strval2DCEstrlen( ava->la_value, f, &vl ) ) {
+ if ( strval2DCEstrlen( &ava->la_value, f, &vl ) ) {
return( -1 );
}
l += vl;
int iAVA;
ber_len_t l = 0;
- for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ iAVA ][ 0 ];
+ for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ 0 ][ iAVA ];
if ( first ) {
first = 0;
str[ l++ ] = ( iAVA ? ',' : '/' );
}
- AC_MEMCPY( &str[ l ], ava->la_attr->bv_val,
- ava->la_attr->bv_len );
- l += ava->la_attr->bv_len;
+ AC_MEMCPY( &str[ l ], ava->la_attr.bv_val,
+ ava->la_attr.bv_len );
+ l += ava->la_attr.bv_len;
str[ l++ ] = '=';
switch ( ava->la_flags ) {
case LDAP_AVA_BINARY:
str[ l++ ] = '#';
- if ( binval2hexstr( ava->la_value, &str[ l ] ) ) {
+ if ( binval2hexstr( &ava->la_value, &str[ l ] ) ) {
return( -1 );
}
- l += 2 * ava->la_value->bv_len;
+ l += 2 * ava->la_value.bv_len;
break;
case LDAP_AVA_STRING: {
ber_len_t vl;
unsigned f = flags | ava->la_flags;
- if ( strval2DCEstr( ava->la_value, &str[ l ], f, &vl ) ) {
+ if ( strval2DCEstr( &ava->la_value, &str[ l ], f, &vl ) ) {
return( -1 );
}
l += vl;
*len = 0;
- for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ iAVA ][ 0 ];
+ for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ 0 ][ iAVA ];
/* ' + ' | ', ' */
- l += ( rdn[ iAVA + 1 ] ? 3 : 2 );
+ l += ( rdn[ 0 ][ iAVA + 1 ] ? 3 : 2 );
/* FIXME: are binary values allowed in UFN? */
if ( ava->la_flags & LDAP_AVA_BINARY ) {
/* octothorpe + twice the value */
- l += 1 + 2 * ava->la_value->bv_len;
+ l += 1 + 2 * ava->la_value.bv_len;
} else {
ber_len_t vl;
unsigned f = flags | ava->la_flags;
- if ( strval2strlen( ava->la_value, f, &vl ) ) {
+ if ( strval2strlen( &ava->la_value, f, &vl ) ) {
return( -1 );
}
l += vl;
int iAVA;
ber_len_t l = 0;
- for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ iAVA ][ 0 ];
+ for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ 0 ][ iAVA ];
if ( ava->la_flags & LDAP_AVA_BINARY ) {
str[ l++ ] = '#';
- if ( binval2hexstr( ava->la_value, &str[ l ] ) ) {
+ if ( binval2hexstr( &ava->la_value, &str[ l ] ) ) {
return( -1 );
}
- l += 2 * ava->la_value->bv_len;
+ l += 2 * ava->la_value.bv_len;
} else {
ber_len_t vl;
unsigned f = flags | ava->la_flags;
- if ( strval2str( ava->la_value, &str[ l ], f, &vl ) ) {
+ if ( strval2str( &ava->la_value, &str[ l ], f, &vl ) ) {
return( -1 );
}
l += vl;
}
- if ( rdn[ iAVA + 1 ]) {
+ if ( rdn[ 0 ][ iAVA + 1 ]) {
AC_MEMCPY( &str[ l ], " + ", 3 );
l += 3;
*len = 0;
- for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ iAVA ][ 0 ];
+ for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ 0 ][ iAVA ];
/* ',' | '/' */
l++;
switch ( ava->la_flags ) {
case LDAP_AVA_BINARY:
/* octothorpe + twice the value */
- l += 1 + 2 * ava->la_value->bv_len;
+ l += 1 + 2 * ava->la_value.bv_len;
break;
case LDAP_AVA_STRING: {
ber_len_t vl;
unsigned f = flags | ava->la_flags;
- if ( strval2ADstrlen( ava->la_value, f, &vl ) ) {
+ if ( strval2ADstrlen( &ava->la_value, f, &vl ) ) {
return( -1 );
}
l += vl;
int iAVA;
ber_len_t l = 0;
- for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
- LDAPAVA *ava = rdn[ iAVA ][ 0 ];
+ for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
+ LDAPAVA *ava = rdn[ 0 ][ iAVA ];
if ( first ) {
first = 0;
switch ( ava->la_flags ) {
case LDAP_AVA_BINARY:
str[ l++ ] = '#';
- if ( binval2hexstr( ava->la_value, &str[ l ] ) ) {
+ if ( binval2hexstr( &ava->la_value, &str[ l ] ) ) {
return( -1 );
}
- l += 2 * ava->la_value->bv_len;
+ l += 2 * ava->la_value.bv_len;
break;
case LDAP_AVA_STRING: {
ber_len_t vl;
unsigned f = flags | ava->la_flags;
- if ( strval2ADstr( ava->la_value, &str[ l ], f, &vl ) ) {
+ if ( strval2ADstr( &ava->la_value, &str[ l ], f, &vl ) ) {
return( -1 );
}
l += vl;
assert( str );
+ if((flags & LDAP_DN_FORMAT_MASK) == LDAP_DN_FORMAT_LBER) {
+ return LDAP_PARAM_ERROR;
+ }
+
rc = ldap_rdn2bv( rdn, &bv, flags );
*str = bv.bv_val;
return rc;
switch ( LDAP_DN_FORMAT( flags ) ) {
case LDAP_DN_FORMAT_LDAPV3:
if ( rdn2strlen( rdn, flags, &l, strval2strlen ) ) {
- return( LDAP_OTHER );
+ return LDAP_DECODING_ERROR;
}
break;
case LDAP_DN_FORMAT_LDAPV2:
if ( rdn2strlen( rdn, flags, &l, strval2IA5strlen ) ) {
- return( LDAP_OTHER );
+ return LDAP_DECODING_ERROR;
}
break;
case LDAP_DN_FORMAT_UFN:
if ( rdn2UFNstrlen( rdn, flags, &l ) ) {
- return( LDAP_OTHER );
+ return LDAP_DECODING_ERROR;
}
break;
case LDAP_DN_FORMAT_DCE:
if ( rdn2DCEstrlen( rdn, flags, &l ) ) {
- return( LDAP_OTHER );
+ return LDAP_DECODING_ERROR;
}
break;
case LDAP_DN_FORMAT_AD_CANONICAL:
if ( rdn2ADstrlen( rdn, flags, &l ) ) {
- return( LDAP_OTHER );
+ return LDAP_DECODING_ERROR;
}
break;
default:
- return( LDAP_INVALID_DN_SYNTAX );
+ return( LDAP_PARAM_ERROR );
}
bv->bv_val = LDAP_MALLOC( l + 1 );
default:
/* need at least one of the previous */
- return( LDAP_OTHER );
+ return LDAP_PARAM_ERROR;
}
if ( rc ) {
ldap_memfree( bv->bv_val );
- return( LDAP_OTHER );
+ return rc;
}
bv->bv_len = l - back;
bv->bv_val[ bv->bv_len ] = '\0';
- return( LDAP_SUCCESS );
+ return LDAP_SUCCESS;
}
/*
assert( str );
+ if((flags & LDAP_DN_FORMAT_MASK) == LDAP_DN_FORMAT_LBER) {
+ return LDAP_PARAM_ERROR;
+ }
+
rc = ldap_dn2bv( dn, &bv, flags );
*str = bv.bv_val;
return rc;
int ldap_dn2bv( LDAPDN *dn, struct berval *bv, unsigned flags )
{
int iRDN;
- int rc = LDAP_OTHER;
+ int rc = LDAP_ENCODING_ERROR;
ber_len_t len, l;
/* stringifying helpers for LDAPv3/LDAPv2 */
sv2s = strval2IA5str;
got_funcs:
- for ( iRDN = 0, len = 0; dn[ iRDN ]; iRDN++ ) {
+ for ( iRDN = 0, len = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ iRDN ][ 0 ];
+ LDAPRDN *rdn = dn[ 0 ][ iRDN ];
if ( rdn2strlen( rdn, flags, &rdnl, sv2l ) ) {
goto return_results;
break;
}
- for ( l = 0, iRDN = 0; dn[ iRDN ]; iRDN++ ) {
+ for ( l = 0, iRDN = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ iRDN ][ 0 ];
+ LDAPRDN *rdn = dn[ 0 ][ iRDN ];
if ( rdn2str( rdn, &bv->bv_val[ l ], flags,
&rdnl, sv2s ) ) {
int last_iRDN = -1;
#endif /* DC_IN_UFN */
- for ( iRDN = 0, len = 0; dn[ iRDN ]; iRDN++ ) {
+ for ( iRDN = 0, len = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ iRDN ][ 0 ];
+ LDAPRDN *rdn = dn[ 0 ][ iRDN ];
if ( rdn2UFNstrlen( rdn, flags, &rdnl ) ) {
goto return_results;
#ifdef DC_IN_UFN
if ( leftmost_dc == -1 ) {
#endif /* DC_IN_UFN */
- for ( l = 0, iRDN = 0; dn[ iRDN ]; iRDN++ ) {
+ for ( l = 0, iRDN = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
ber_len_t vl;
- LDAPRDN *rdn = dn[ iRDN ][ 0 ];
+ LDAPRDN *rdn = dn[ 0 ][ iRDN ];
if ( rdn2UFNstr( rdn, &bv->bv_val[ l ],
flags, &vl ) ) {
for ( l = 0, iRDN = 0; iRDN < leftmost_dc; iRDN++ ) {
ber_len_t vl;
- LDAPRDN *rdn = dn[ iRDN ][ 0 ];
+ LDAPRDN *rdn = dn[ 0 ][ iRDN ];
if ( rdn2UFNstr( rdn, &bv->bv_val[ l ],
flags, &vl ) ) {
case LDAP_DN_FORMAT_DCE:
- for ( iRDN = 0, len = 0; dn[ iRDN ]; iRDN++ ) {
+ for ( iRDN = 0, len = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ iRDN ][ 0 ];
+ LDAPRDN *rdn = dn[ 0 ][ iRDN ];
if ( rdn2DCEstrlen( rdn, flags, &rdnl ) ) {
goto return_results;
for ( l = 0; iRDN--; ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ iRDN ][ 0 ];
+ LDAPRDN *rdn = dn[ 0 ][ iRDN ];
if ( rdn2DCEstr( rdn, &bv->bv_val[ l ], flags,
&rdnl, 0 ) ) {
*
* "microsoft.com/People/Bill,Gates"
*/
- for ( iRDN = 0, len = -1; dn[ iRDN ]; iRDN++ ) {
+ for ( iRDN = 0, len = -1; dn[ 0 ][ iRDN ]; iRDN++ ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ iRDN ][ 0 ];
+ LDAPRDN *rdn = dn[ 0 ][ iRDN ];
if ( rdn2ADstrlen( rdn, flags, &rdnl ) ) {
goto return_results;
if ( iRDN && dn2domain( dn, bv, 0, &iRDN ) ) {
for ( l = bv->bv_len; iRDN >= 0 ; iRDN-- ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ iRDN ][ 0 ];
+ LDAPRDN *rdn = dn[ 0 ][ iRDN ];
if ( rdn2ADstr( rdn, &bv->bv_val[ l ],
flags, &rdnl, 0 ) ) {
if ( flags & LDAP_DN_PEDANTIC ) {
LDAP_FREE( bv->bv_val );
bv->bv_val = NULL;
- rc = LDAP_INVALID_DN_SYNTAX;
+ rc = LDAP_ENCODING_ERROR;
break;
}
for ( l = 0; iRDN >= 0 ; iRDN-- ) {
ber_len_t rdnl;
- LDAPRDN *rdn = dn[ iRDN ][ 0 ];
+ LDAPRDN *rdn = dn[ 0 ][ iRDN ];
if ( rdn2ADstr( rdn, &bv->bv_val[ l ],
flags, &rdnl, first ) ) {
}
default:
- return( LDAP_INVALID_DN_SYNTAX );
-
+ return LDAP_PARAM_ERROR;
}
- Debug( LDAP_DEBUG_TRACE, "<= ldap_dn2bv(%s,%u)=%d\n", bv->bv_val, flags, rc );
+ Debug( LDAP_DEBUG_TRACE, "<= ldap_dn2bv(%s,%u)=%d\n",
+ bv->bv_val, flags, rc );
return_results:;
return( rc );
}