mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-21 03:10:25 +08:00
ldap_str2rdn() can parse without allocating a LDAPRDN* (not very clean, though); used by dn_rdnlen
This commit is contained in:
parent
92c6c9c25d
commit
2f3f7c6765
@ -1188,6 +1188,7 @@ typedef LDAPRDN** LDAPDN;
|
|||||||
|
|
||||||
/* DN flags */
|
/* DN flags */
|
||||||
#define LDAP_DN_PRETTY 0x0100U
|
#define LDAP_DN_PRETTY 0x0100U
|
||||||
|
#define LDAP_DN_SKIP 0x0200U
|
||||||
#define LDAP_DN_P_NOLEADTRAILSPACES 0x1000U
|
#define LDAP_DN_P_NOLEADTRAILSPACES 0x1000U
|
||||||
#define LDAP_DN_P_NOSPACEAFTERRDN 0x2000U
|
#define LDAP_DN_P_NOSPACEAFTERRDN 0x2000U
|
||||||
#define LDAP_DN_PEDANTIC 0xF000U
|
#define LDAP_DN_PEDANTIC 0xF000U
|
||||||
|
@ -873,12 +873,14 @@ ldap_str2rdn( const char *str, LDAPRDN **rdn, const char **n, unsigned flags )
|
|||||||
LDAPRDN *newRDN = NULL;
|
LDAPRDN *newRDN = NULL;
|
||||||
|
|
||||||
assert( str );
|
assert( str );
|
||||||
assert( rdn );
|
assert( rdn || flags & LDAP_DN_SKIP );
|
||||||
assert( n );
|
assert( n );
|
||||||
|
|
||||||
Debug( LDAP_DEBUG_TRACE, "=> ldap_str2rdn(%s,%u)\n%s", str, flags, "" );
|
Debug( LDAP_DEBUG_TRACE, "=> ldap_str2rdn(%s,%u)\n%s", str, flags, "" );
|
||||||
|
|
||||||
|
if ( rdn ) {
|
||||||
*rdn = NULL;
|
*rdn = NULL;
|
||||||
|
}
|
||||||
*n = NULL;
|
*n = NULL;
|
||||||
|
|
||||||
switch ( LDAP_DN_FORMAT( flags ) ) {
|
switch ( LDAP_DN_FORMAT( flags ) ) {
|
||||||
@ -995,13 +997,22 @@ ldap_str2rdn( const char *str, LDAPRDN **rdn, const char **n, unsigned flags )
|
|||||||
if ( type == NULL ) {
|
if ( type == NULL ) {
|
||||||
goto parsing_error;
|
goto parsing_error;
|
||||||
}
|
}
|
||||||
attrType = LDAP_MALLOC( sizeof( struct berval ) );
|
|
||||||
if ( attrType== NULL ) {
|
if ( flags & LDAP_DN_SKIP ) {
|
||||||
|
/*
|
||||||
|
* FIXME: hack for skipping a rdn;
|
||||||
|
* need a cleaner solution
|
||||||
|
*/
|
||||||
|
LDAP_FREE( type );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
attrType = ber_bvstr( type );
|
||||||
|
if ( attrType == NULL ) {
|
||||||
rc = LDAP_NO_MEMORY;
|
rc = LDAP_NO_MEMORY;
|
||||||
goto parsing_error;
|
goto parsing_error;
|
||||||
}
|
}
|
||||||
attrType->bv_val = type;
|
}
|
||||||
attrType->bv_len = strlen( type );
|
|
||||||
attrTypeEncoding = LDAP_AVA_BINARY;
|
attrTypeEncoding = LDAP_AVA_BINARY;
|
||||||
|
|
||||||
state = B4AVAEQUALS;
|
state = B4AVAEQUALS;
|
||||||
@ -1053,6 +1064,20 @@ ldap_str2rdn( const char *str, LDAPRDN **rdn, const char **n, unsigned flags )
|
|||||||
goto parsing_error;
|
goto parsing_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
attrTypeEncoding = LDAP_AVA_STRING;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* here we need to decide whether to use it as is
|
||||||
|
* or turn it in OID form; as a consequence, we
|
||||||
|
* need to decide whether to binary encode the value
|
||||||
|
*/
|
||||||
|
|
||||||
|
state = B4AVAEQUALS;
|
||||||
|
|
||||||
|
if ( flags & LDAP_DN_SKIP ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
assert( attrType == NULL );
|
assert( attrType == NULL );
|
||||||
attrType = LDAP_MALLOC( sizeof( struct berval ) );
|
attrType = LDAP_MALLOC( sizeof( struct berval ) );
|
||||||
if ( attrType == NULL ) {
|
if ( attrType == NULL ) {
|
||||||
@ -1065,15 +1090,7 @@ ldap_str2rdn( const char *str, LDAPRDN **rdn, const char **n, unsigned flags )
|
|||||||
goto parsing_error;
|
goto parsing_error;
|
||||||
}
|
}
|
||||||
attrType->bv_len = len;
|
attrType->bv_len = len;
|
||||||
attrTypeEncoding = LDAP_AVA_STRING;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* here we need to decide whether to use it as is
|
|
||||||
* or turn it in OID form; as a consequence, we
|
|
||||||
* need to decide whether to binary encode the value
|
|
||||||
*/
|
|
||||||
|
|
||||||
state = B4AVAEQUALS;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1209,9 +1226,11 @@ ldap_str2rdn( const char *str, LDAPRDN **rdn, const char **n, unsigned flags )
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case GOTAVA: {
|
case GOTAVA: {
|
||||||
|
int rdnsep = 0;
|
||||||
|
|
||||||
|
if ( !( flags & LDAP_DN_SKIP ) ) {
|
||||||
LDAPAVA *ava;
|
LDAPAVA *ava;
|
||||||
LDAPRDN *rdn;
|
LDAPRDN *rdn;
|
||||||
int rdnsep = 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* we accept empty values
|
* we accept empty values
|
||||||
@ -1229,6 +1248,7 @@ ldap_str2rdn( const char *str, LDAPRDN **rdn, const char **n, unsigned flags )
|
|||||||
goto parsing_error;
|
goto parsing_error;
|
||||||
}
|
}
|
||||||
newRDN = rdn;
|
newRDN = rdn;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if we got an AVA separator ('+', or ',' for DCE )
|
* if we got an AVA separator ('+', or ',' for DCE )
|
||||||
@ -1294,7 +1314,9 @@ return_result:;
|
|||||||
|
|
||||||
Debug( LDAP_DEBUG_TRACE, "<= ldap_str2rdn(%*s)=%d\n",
|
Debug( LDAP_DEBUG_TRACE, "<= ldap_str2rdn(%*s)=%d\n",
|
||||||
*n - p, str, rc );
|
*n - p, str, rc );
|
||||||
|
if ( rdn ) {
|
||||||
*rdn = newRDN;
|
*rdn = newRDN;
|
||||||
|
}
|
||||||
|
|
||||||
return( rc );
|
return( rc );
|
||||||
}
|
}
|
||||||
@ -1394,6 +1416,11 @@ str2strval( const char *str, struct berval **val, const char **next, unsigned fl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*next = p;
|
||||||
|
if ( flags & LDAP_DN_SKIP ) {
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FIXME: test memory?
|
* FIXME: test memory?
|
||||||
*/
|
*/
|
||||||
@ -1442,9 +1469,6 @@ str2strval( const char *str, struct berval **val, const char **next, unsigned fl
|
|||||||
assert( strlen( ( *val )->bv_val ) == len );
|
assert( strlen( ( *val )->bv_val ) == len );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
*next = p;
|
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1501,6 +1525,10 @@ DCE2strval( const char *str, struct berval **val, const char **next, unsigned fl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*next = p;
|
||||||
|
if ( flags & LDAP_DN_SKIP ) {
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
len = ( endPos ? endPos : p ) - startPos - escapes;
|
len = ( endPos ? endPos : p ) - startPos - escapes;
|
||||||
*val = LDAP_MALLOC( sizeof( struct berval ) );
|
*val = LDAP_MALLOC( sizeof( struct berval ) );
|
||||||
@ -1528,8 +1556,6 @@ DCE2strval( const char *str, struct berval **val, const char **next, unsigned fl
|
|||||||
assert( strlen( ( *val )->bv_val ) == len );
|
assert( strlen( ( *val )->bv_val ) == len );
|
||||||
}
|
}
|
||||||
|
|
||||||
*next = p;
|
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1582,6 +1608,11 @@ IA52strval( const char *str, struct berval **val, const char **next, unsigned fl
|
|||||||
/* no op */
|
/* no op */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*next = p;
|
||||||
|
if ( flags & LDAP_DN_SKIP ) {
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
*val = LDAP_MALLOC( sizeof( struct berval ) );
|
*val = LDAP_MALLOC( sizeof( struct berval ) );
|
||||||
len = ( endPos ? endPos : p ) - startPos - escapes;
|
len = ( endPos ? endPos : p ) - startPos - escapes;
|
||||||
( *val )->bv_len = len;
|
( *val )->bv_len = len;
|
||||||
@ -1601,7 +1632,6 @@ IA52strval( const char *str, struct berval **val, const char **next, unsigned fl
|
|||||||
( *val )->bv_val[ d ] = '\0';
|
( *val )->bv_val[ d ] = '\0';
|
||||||
assert( strlen( ( *val )->bv_val ) == len );
|
assert( strlen( ( *val )->bv_val ) == len );
|
||||||
}
|
}
|
||||||
*next = p;
|
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
@ -1669,6 +1699,11 @@ quotedIA52strval( const char *str, struct berval **val, const char **next, unsig
|
|||||||
/* no op */
|
/* no op */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*next = p;
|
||||||
|
if ( flags & LDAP_DN_SKIP ) {
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
len = endPos - startPos - escapes;
|
len = endPos - startPos - escapes;
|
||||||
assert( len >= 0 );
|
assert( len >= 0 );
|
||||||
*val = LDAP_MALLOC( sizeof( struct berval ) );
|
*val = LDAP_MALLOC( sizeof( struct berval ) );
|
||||||
@ -1692,8 +1727,6 @@ quotedIA52strval( const char *str, struct berval **val, const char **next, unsig
|
|||||||
assert( strlen( ( *val )->bv_val ) == len );
|
assert( strlen( ( *val )->bv_val ) == len );
|
||||||
}
|
}
|
||||||
|
|
||||||
*next = p;
|
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1811,6 +1844,11 @@ hexstr2binval( const char *str, struct berval **val, const char **next, unsigned
|
|||||||
|
|
||||||
end_of_value:;
|
end_of_value:;
|
||||||
|
|
||||||
|
*next = p;
|
||||||
|
if ( flags & LDAP_DN_SKIP ) {
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
len = ( ( endPos ? endPos : p ) - startPos ) / 2;
|
len = ( ( endPos ? endPos : p ) - startPos ) / 2;
|
||||||
/* must be even! */
|
/* must be even! */
|
||||||
assert( 2 * len == (ber_len_t) (( endPos ? endPos : p ) - startPos ));
|
assert( 2 * len == (ber_len_t) (( endPos ? endPos : p ) - startPos ));
|
||||||
@ -1836,7 +1874,6 @@ end_of_value:;
|
|||||||
}
|
}
|
||||||
|
|
||||||
( *val )->bv_val[ d ] = '\0';
|
( *val )->bv_val[ d ] = '\0';
|
||||||
*next = p;
|
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
@ -714,7 +714,8 @@ dn_rdnlen(
|
|||||||
Backend *be,
|
Backend *be,
|
||||||
struct berval *dn_in )
|
struct berval *dn_in )
|
||||||
{
|
{
|
||||||
struct berval rdn;
|
int rc;
|
||||||
|
char *p;
|
||||||
|
|
||||||
assert( dn_in );
|
assert( dn_in );
|
||||||
|
|
||||||
@ -730,13 +731,13 @@ dn_rdnlen(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( dnExtractRdn( dn_in, &rdn ) != LDAP_SUCCESS ) {
|
rc = ldap_str2rdn( dn_in->bv_val, NULL, &p,
|
||||||
|
LDAP_DN_FORMAT_LDAP | LDAP_DN_SKIP );
|
||||||
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
free( rdn.bv_val );
|
return p - dn_in->bv_val;
|
||||||
|
|
||||||
return rdn.bv_len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user