static int dn2domain( LDAPDN *dn, char *str, int *iRDN );
/* AVA helpers */
-LDAPAVA * ldapava_new( const char *attr, const struct berval *val,
+LDAPAVA * ldapava_new( const struct berval *attr, const struct berval *val,
unsigned flags );
void ldapava_free( LDAPAVA *ava );
LDAPRDN * ldapava_append_to_rdn( LDAPRDN *rdn, LDAPAVA *ava );
}
if ( !notypes ) {
- al = strlen( ava->la_attr );
-
- l = vl + al + 1;
+ l = vl + ava->la_attr->bv_len + 1;
str = LDAP_MALLOC( l + 1 );
- AC_MEMCPY( str, ava->la_attr, al );
- str[ al++ ] = '=';
+ AC_MEMCPY( str, ava->la_attr->bv_val,
+ ava->la_attr->bv_len );
+ str[ ava->la_attr->bv_len + 1 ] = '=';
} else {
l = vl;
#define LDAP_DC_ATTR "dc"
/* better look at the AttributeDescription? */
-/* FIXME: no composite rdn or non-"dc" types, right? */
+/* FIXME: no composite rdn or non-"dc" types, right?
+ * (what about "dc" in OID form?) */
/* FIXME: we do not allow binary values in domain, right? */
#define LDAP_DN_IS_RDN_DC( rdn ) \
( ( rdn ) && ( rdn )[ 0 ][ 0 ] && !( rdn )[ 1 ] \
&& ( ( rdn )[ 0 ][ 0 ]->la_flags == LDAP_AVA_STRING ) \
- && ! strcasecmp( ( rdn )[ 0 ][ 0 ]->la_attr, LDAP_DC_ATTR ) )
+ && ! strcasecmp( ( rdn )[ 0 ][ 0 ]->la_attr->bv_val, LDAP_DC_ATTR ) )
/* Composite rules */
#define LDAP_DN_ALLOW_ONE_SPACE(f) \
* on structural representations of DNs).
*/
LDAPAVA *
-ldapava_new( const char *attr, const struct berval *val, unsigned flags )
+ldapava_new( const struct berval *attr, const struct berval *val,
+ unsigned flags )
{
LDAPAVA *ava;
return( NULL );
}
- ava->la_attr = ( char * )attr;
+ ava->la_attr = ( struct berval * )attr;
ava->la_value = ( struct berval * )val;
ava->la_flags = flags;
{
assert( ava );
- LDAP_FREE( ava->la_attr );
+ ber_bvfree( ava->la_attr );
ber_bvfree( ava->la_value );
LDAP_FREE( ava );
ldap_str2dn( const char *str, LDAPDN **dn, unsigned flags )
{
const char *p;
- int state = B4AVA;
int rc = LDAP_INVALID_DN_SYNTAX;
- int attrTypeEncoding, attrValueEncoding;
-
- char *attrType = NULL;
- struct berval *attrValue = NULL;
LDAPDN *newDN = NULL;
LDAPRDN *newRDN = NULL;
}
for ( ; p[ 0 ]; p++ ) {
- int rdnsep = 0;
LDAPDN *dn;
rc = ldap_str2rdn( p, &newRDN, &p, flags );
const char *p;
int state = B4AVA;
int rc = LDAP_INVALID_DN_SYNTAX;
- int attrTypeEncoding, attrValueEncoding;
+ int attrTypeEncoding = LDAP_AVA_STRING,
+ attrValueEncoding = LDAP_AVA_STRING;
- char *attrType = NULL;
+ struct berval *attrType = NULL;
struct berval *attrValue = NULL;
LDAPRDN *newRDN = NULL;
case B4OIDATTRTYPE: {
int err = LDAP_SUCCESS;
+ char *type;
- attrType = parse_numericoid( &p, &err, 0 );
- if ( attrType == NULL ) {
+ 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;
+ goto parsing_error;
+ }
+ attrType->bv_val = type;
+ attrType->bv_len = strlen( type );
attrTypeEncoding = LDAP_AVA_BINARY;
state = B4AVAEQUALS;
}
assert( attrType == NULL );
- attrType = LDAP_STRNDUP( startPos, len );
+ 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;
/*
parsing_error:;
/* They are set to NULL after they're used in an AVA */
if ( attrType ) {
- LDAP_FREE( attrType );
+ ber_bvfree( attrType );
}
if ( attrValue ) {
static int
strval2ADstr( struct berval *val, char *str, unsigned flags, ber_len_t *len )
{
- ber_len_t s, d, cl;
+ ber_len_t s, d;
assert( val );
assert( str );
LDAPAVA *ava = rdn[ iAVA ][ 0 ];
/* len(type) + '=' + '+' | ',' */
- l += strlen( ava->la_attr ) + 2;
+ l += ava->la_attr->bv_len + 2;
if ( ava->la_flags & LDAP_AVA_BINARY ) {
/* octothorpe + twice the length */
for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
LDAPAVA *ava = rdn[ iAVA ][ 0 ];
- ber_len_t al = strlen( ava->la_attr );
- AC_MEMCPY( &str[ l ], ava->la_attr, al );
- l += al;
+ AC_MEMCPY( &str[ l ], ava->la_attr->bv_val,
+ ava->la_attr->bv_len );
+ l += ava->la_attr->bv_len;
str[ l++ ] = '=';
LDAPAVA *ava = rdn[ iAVA ][ 0 ];
/* len(type) + '=' + ',' | '/' */
- l += strlen( ava->la_attr ) + 2;
+ l += ava->la_attr->bv_len + 2;
switch ( ava->la_flags ) {
case LDAP_AVA_BINARY:
for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
LDAPAVA *ava = rdn[ iAVA ][ 0 ];
- ber_len_t al = strlen( ava->la_attr );
if ( first ) {
first = 0;
str[ l++ ] = ( iAVA ? ',' : '/' );
}
- AC_MEMCPY( &str[ l ], ava->la_attr, al );
- l += al;
+ AC_MEMCPY( &str[ l ], ava->la_attr->bv_val,
+ ava->la_attr->bv_len );
+ l += ava->la_attr->bv_len;
str[ l++ ] = '=';
case LDAP_AVA_STRING: {
ber_len_t vl;
- if ( strval2str( ava->la_value, &str[ l ],
+ if ( strval2ADstr( ava->la_value, &str[ l ],
ava->la_flags, &vl ) ) {
return( -1 );
}
rc = rdn2ADstr( rdn, *str, &l, 1 );
back = 0;
break;
+
+ default:
+ /* need at least one of the previous */
+ return( LDAP_OTHER );
}
if ( rc ) {
*/
int ldap_dn2str( LDAPDN *dn, char **str, unsigned flags )
{
- int iRDN, iAVA;
+ int iRDN;
int rc = LDAP_OTHER;
ber_len_t len, l;