mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-20 22:59:34 -05:00
use ldap_bv2[r]dn and turn ldap_str2[r]dn into wrappers
This commit is contained in:
parent
b1c39eff65
commit
a117c5eee7
7 changed files with 70 additions and 40 deletions
|
|
@ -1227,6 +1227,13 @@ ldap_dn2str LDAP_P((
|
||||||
char **str,
|
char **str,
|
||||||
unsigned flags ));
|
unsigned flags ));
|
||||||
|
|
||||||
|
LDAP_F( int )
|
||||||
|
ldap_bv2rdn LDAP_P((
|
||||||
|
struct berval *bv,
|
||||||
|
LDAPRDN **rdn,
|
||||||
|
char **next,
|
||||||
|
unsigned flags ));
|
||||||
|
|
||||||
LDAP_F( int )
|
LDAP_F( int )
|
||||||
ldap_str2rdn LDAP_P((
|
ldap_str2rdn LDAP_P((
|
||||||
LDAP_CONST char *str,
|
LDAP_CONST char *str,
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
#define PRETTY_ESCAPE
|
#define PRETTY_ESCAPE
|
||||||
|
|
||||||
/* parsing/printing routines */
|
/* parsing/printing routines */
|
||||||
static int str2strval( const char *str, struct berval *val,
|
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 );
|
||||||
static int DCE2strval( const char *str, struct berval *val,
|
static int DCE2strval( const char *str, struct berval *val,
|
||||||
const char **next, unsigned flags );
|
const char **next, unsigned flags );
|
||||||
|
|
@ -599,24 +599,19 @@ ldap_dnfree( LDAPDN *dn )
|
||||||
#define TMP_RDN_SLOTS 32
|
#define TMP_RDN_SLOTS 32
|
||||||
|
|
||||||
int
|
int
|
||||||
ldap_bv2dn( struct berval *bv, LDAPDN **dn, unsigned flags )
|
ldap_str2dn( LDAP_CONST char *str, LDAPDN **dn, unsigned flags )
|
||||||
{
|
{
|
||||||
assert( bv );
|
struct berval bv = { 0, (char *)str };
|
||||||
assert( dn );
|
|
||||||
|
|
||||||
/*
|
assert( str );
|
||||||
* FIXME: ldap_bv2dn() and ldap_str2dn() will be swapped,
|
|
||||||
* i.e. ldap_str2dn() will become a wrapper for ldap_bv2dn()
|
|
||||||
*/
|
|
||||||
if ( bv->bv_len != strlen( bv->bv_val ) ) {
|
|
||||||
return LDAP_INVALID_DN_SYNTAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ldap_str2dn( bv->bv_val, dn, flags );
|
bv.bv_len = strlen( str );
|
||||||
|
|
||||||
|
return ldap_bv2dn( &bv, dn, flags );
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ldap_str2dn( LDAP_CONST char *str, LDAPDN **dn, unsigned flags )
|
ldap_bv2dn( struct berval *bv, LDAPDN **dn, unsigned flags )
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
int rc = LDAP_DECODING_ERROR;
|
int rc = LDAP_DECODING_ERROR;
|
||||||
|
|
@ -625,8 +620,10 @@ ldap_str2dn( LDAP_CONST char *str, LDAPDN **dn, unsigned flags )
|
||||||
LDAPDN *newDN = NULL;
|
LDAPDN *newDN = NULL;
|
||||||
LDAPRDN *newRDN = NULL, *tmpDN_[TMP_RDN_SLOTS], **tmpDN = tmpDN_;
|
LDAPRDN *newRDN = NULL, *tmpDN_[TMP_RDN_SLOTS], **tmpDN = tmpDN_;
|
||||||
int num_slots = TMP_RDN_SLOTS;
|
int num_slots = TMP_RDN_SLOTS;
|
||||||
|
char *str = bv->bv_val;
|
||||||
|
|
||||||
assert( str );
|
assert( bv );
|
||||||
|
assert( bv->bv_val );
|
||||||
assert( dn );
|
assert( dn );
|
||||||
|
|
||||||
Debug( LDAP_DEBUG_TRACE, "=> ldap_str2dn(%s,%u)\n%s", str, flags, "" );
|
Debug( LDAP_DEBUG_TRACE, "=> ldap_str2dn(%s,%u)\n%s", str, flags, "" );
|
||||||
|
|
@ -684,8 +681,9 @@ ldap_str2dn( LDAP_CONST char *str, LDAPDN **dn, unsigned flags )
|
||||||
|
|
||||||
for ( ; p[ 0 ]; p++ ) {
|
for ( ; p[ 0 ]; p++ ) {
|
||||||
int err;
|
int err;
|
||||||
|
struct berval tmpbv = { bv->bv_len - ( p - str ), (char *)p };
|
||||||
|
|
||||||
err = ldap_str2rdn( p, &newRDN, (char **) &p, flags );
|
err = ldap_bv2rdn( &tmpbv, &newRDN, (char **) &p, flags );
|
||||||
if ( err != LDAP_SUCCESS ) {
|
if ( err != LDAP_SUCCESS ) {
|
||||||
goto parsing_error;
|
goto parsing_error;
|
||||||
}
|
}
|
||||||
|
|
@ -793,7 +791,7 @@ return_result:;
|
||||||
LDAP_FREE( tmpDN );
|
LDAP_FREE( tmpDN );
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug( LDAP_DEBUG_TRACE, "<= ldap_str2dn(%s,%u)=%d\n", str, flags, rc );
|
Debug( LDAP_DEBUG_TRACE, "<= ldap_bv2dn(%s,%u)=%d\n", str, flags, rc );
|
||||||
*dn = newDN;
|
*dn = newDN;
|
||||||
|
|
||||||
return( rc );
|
return( rc );
|
||||||
|
|
@ -810,6 +808,20 @@ return_result:;
|
||||||
int
|
int
|
||||||
ldap_str2rdn( LDAP_CONST char *str, LDAPRDN **rdn,
|
ldap_str2rdn( LDAP_CONST char *str, LDAPRDN **rdn,
|
||||||
char **n_in, unsigned flags )
|
char **n_in, unsigned flags )
|
||||||
|
{
|
||||||
|
struct berval bv = { 0, (char *)str };
|
||||||
|
|
||||||
|
assert( str );
|
||||||
|
assert( str[ 0 ] != '\0' ); /* FIXME: is this required? */
|
||||||
|
|
||||||
|
bv.bv_len = strlen( str );
|
||||||
|
|
||||||
|
return ldap_bv2rdn( &bv, rdn, n_in, flags );
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ldap_bv2rdn( struct berval *bv, LDAPRDN **rdn,
|
||||||
|
char **n_in, unsigned flags )
|
||||||
{
|
{
|
||||||
const char **n = (const char **) n_in;
|
const char **n = (const char **) n_in;
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
@ -826,14 +838,23 @@ ldap_str2rdn( LDAP_CONST char *str, LDAPRDN **rdn,
|
||||||
LDAPAVA *tmpRDN_[TMP_AVA_SLOTS], **tmpRDN = tmpRDN_;
|
LDAPAVA *tmpRDN_[TMP_AVA_SLOTS], **tmpRDN = tmpRDN_;
|
||||||
int num_slots = TMP_AVA_SLOTS;
|
int num_slots = TMP_AVA_SLOTS;
|
||||||
|
|
||||||
assert( str );
|
char *str;
|
||||||
|
ber_len_t stoplen;
|
||||||
|
|
||||||
|
assert( bv );
|
||||||
|
assert( bv->bv_len );
|
||||||
|
assert( bv->bv_val );
|
||||||
assert( rdn || flags & LDAP_DN_SKIP );
|
assert( rdn || flags & LDAP_DN_SKIP );
|
||||||
assert( n );
|
assert( n );
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
Debug( LDAP_DEBUG_TRACE, "=> ldap_str2rdn(%s,%u)\n%s", str, flags, "" );
|
Debug( LDAP_DEBUG_TRACE, "=> ldap_bv2rdn(%s,%u)\n%s",
|
||||||
|
bv->bv_val, flags, "" );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
str = bv->bv_val;
|
||||||
|
stoplen = bv->bv_len;
|
||||||
|
|
||||||
if ( rdn ) {
|
if ( rdn ) {
|
||||||
*rdn = NULL;
|
*rdn = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -1126,7 +1147,8 @@ ldap_str2rdn( LDAP_CONST char *str, LDAPRDN **rdn,
|
||||||
switch ( LDAP_DN_FORMAT( flags ) ) {
|
switch ( LDAP_DN_FORMAT( flags ) ) {
|
||||||
case LDAP_DN_FORMAT_LDAP:
|
case LDAP_DN_FORMAT_LDAP:
|
||||||
case LDAP_DN_FORMAT_LDAPV3:
|
case LDAP_DN_FORMAT_LDAPV3:
|
||||||
if ( str2strval( p, &attrValue, &p, flags,
|
if ( str2strval( p, stoplen - ( p - str ),
|
||||||
|
&attrValue, &p, flags,
|
||||||
&attrValueEncoding ) ) {
|
&attrValueEncoding ) ) {
|
||||||
goto parsing_error;
|
goto parsing_error;
|
||||||
}
|
}
|
||||||
|
|
@ -1310,9 +1332,9 @@ return_result:;
|
||||||
* '\' + HEXPAIR(p) -> unhex(p)
|
* '\' + HEXPAIR(p) -> unhex(p)
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
str2strval( const char *str, 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 )
|
||||||
{
|
{
|
||||||
const char *p, *startPos, *endPos = NULL;
|
const char *p, *end, *startPos, *endPos = NULL;
|
||||||
ber_len_t len, escapes;
|
ber_len_t len, escapes;
|
||||||
|
|
||||||
assert( str );
|
assert( str );
|
||||||
|
|
@ -1320,8 +1342,8 @@ str2strval( const char *str, struct berval *val, const char **next, unsigned fla
|
||||||
assert( next );
|
assert( next );
|
||||||
|
|
||||||
*next = NULL;
|
*next = NULL;
|
||||||
|
end = str + stoplen;
|
||||||
for ( startPos = p = str, escapes = 0; p[ 0 ]; p++ ) {
|
for ( startPos = p = str, escapes = 0; p < end; p++ ) {
|
||||||
if ( LDAP_DN_ESCAPE( p[ 0 ] ) ) {
|
if ( LDAP_DN_ESCAPE( p[ 0 ] ) ) {
|
||||||
p++;
|
p++;
|
||||||
if ( p[ 0 ] == '\0' ) {
|
if ( p[ 0 ] == '\0' ) {
|
||||||
|
|
@ -1409,7 +1431,13 @@ str2strval( const char *str, struct berval *val, const char **next, unsigned fla
|
||||||
val->bv_len = len;
|
val->bv_len = len;
|
||||||
|
|
||||||
if ( escapes == 0 ) {
|
if ( escapes == 0 ) {
|
||||||
|
if ( *retFlags == LDAP_AVA_NONPRINTABLE ) {
|
||||||
|
val->bv_val = LDAP_MALLOC( len + 1 );
|
||||||
|
AC_MEMCPY( val->bv_val, startPos, len );
|
||||||
|
val->bv_val[ len ] = '\0';
|
||||||
|
} else {
|
||||||
val->bv_val = LDAP_STRNDUP( startPos, len );
|
val->bv_val = LDAP_STRNDUP( startPos, len );
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ber_len_t s, d;
|
ber_len_t s, d;
|
||||||
|
|
|
||||||
|
|
@ -430,7 +430,7 @@ retry: /* transaction retry */
|
||||||
/* Get attribute type and attribute value of our new rdn, we will
|
/* Get attribute type and attribute value of our new rdn, we will
|
||||||
* need to add that to our new entry
|
* need to add that to our new entry
|
||||||
*/
|
*/
|
||||||
if ( ldap_str2rdn( newrdn->bv_val, &new_rdn, (char **)&text,
|
if ( ldap_bv2rdn( newrdn, &new_rdn, (char **)&text,
|
||||||
LDAP_DN_FORMAT_LDAP ) )
|
LDAP_DN_FORMAT_LDAP ) )
|
||||||
{
|
{
|
||||||
Debug( LDAP_DEBUG_TRACE,
|
Debug( LDAP_DEBUG_TRACE,
|
||||||
|
|
@ -445,7 +445,7 @@ retry: /* transaction retry */
|
||||||
"bdb_modrdn: new_rdn_type=\"%s\", new_rdn_val=\"%s\"\n",
|
"bdb_modrdn: new_rdn_type=\"%s\", new_rdn_val=\"%s\"\n",
|
||||||
new_rdn[0][0]->la_attr.bv_val, new_rdn[0][0]->la_value.bv_val, 0 );
|
new_rdn[0][0]->la_attr.bv_val, new_rdn[0][0]->la_value.bv_val, 0 );
|
||||||
|
|
||||||
if ( ldap_str2rdn( dn->bv_val, &old_rdn, (char **)&text,
|
if ( ldap_bv2rdn( dn, &old_rdn, (char **)&text,
|
||||||
LDAP_DN_FORMAT_LDAP ) )
|
LDAP_DN_FORMAT_LDAP ) )
|
||||||
{
|
{
|
||||||
Debug( LDAP_DEBUG_TRACE,
|
Debug( LDAP_DEBUG_TRACE,
|
||||||
|
|
|
||||||
|
|
@ -497,7 +497,7 @@ ldbm_back_modrdn(
|
||||||
/* Get attribute types and values of our new rdn, we will
|
/* Get attribute types and values of our new rdn, we will
|
||||||
* need to add that to our new entry
|
* need to add that to our new entry
|
||||||
*/
|
*/
|
||||||
if ( ldap_str2rdn( newrdn->bv_val, &new_rdn, (char **)&text,
|
if ( ldap_bv2rdn( newrdn, &new_rdn, (char **)&text,
|
||||||
LDAP_DN_FORMAT_LDAP ) )
|
LDAP_DN_FORMAT_LDAP ) )
|
||||||
{
|
{
|
||||||
#ifdef NEW_LOGGING
|
#ifdef NEW_LOGGING
|
||||||
|
|
@ -525,7 +525,7 @@ ldbm_back_modrdn(
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Retrieve the old rdn from the entry's dn */
|
/* Retrieve the old rdn from the entry's dn */
|
||||||
if ( ldap_str2rdn( dn->bv_val, &old_rdn, (char **)&text,
|
if ( ldap_bv2rdn( dn, &old_rdn, (char **)&text,
|
||||||
LDAP_DN_FORMAT_LDAP ) )
|
LDAP_DN_FORMAT_LDAP ) )
|
||||||
{
|
{
|
||||||
#ifdef NEW_LOGGING
|
#ifdef NEW_LOGGING
|
||||||
|
|
|
||||||
|
|
@ -386,7 +386,7 @@ monitor_subsys_conn_create(
|
||||||
|
|
||||||
/* create exactly the required entry */
|
/* create exactly the required entry */
|
||||||
|
|
||||||
if ( ldap_str2rdn( ndn->bv_val, &values, (char **)&text,
|
if ( ldap_bv2rdn( ndn, &values, (char **)&text,
|
||||||
LDAP_DN_FORMAT_LDAP ) )
|
LDAP_DN_FORMAT_LDAP ) )
|
||||||
{
|
{
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ passwd_back_search(
|
||||||
/* Use the first attribute of the DN
|
/* Use the first attribute of the DN
|
||||||
* as an attribute within the entry itself.
|
* as an attribute within the entry itself.
|
||||||
*/
|
*/
|
||||||
if( ldap_str2rdn( base->bv_val, &rdn, (char **)&text,
|
if( ldap_bv2rdn( base, &rdn, (char **)&text,
|
||||||
LDAP_DN_FORMAT_LDAP ) )
|
LDAP_DN_FORMAT_LDAP ) )
|
||||||
{
|
{
|
||||||
err = LDAP_INVALID_DN_SYNTAX;
|
err = LDAP_INVALID_DN_SYNTAX;
|
||||||
|
|
@ -197,7 +197,7 @@ passwd_back_search(
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ldap_str2rdn( base->bv_val, &rdn, (char **)&text,
|
if ( ldap_bv2rdn( base, &rdn, (char **)&text,
|
||||||
LDAP_DN_FORMAT_LDAP ))
|
LDAP_DN_FORMAT_LDAP ))
|
||||||
{
|
{
|
||||||
err = LDAP_OPERATIONS_ERROR;
|
err = LDAP_OPERATIONS_ERROR;
|
||||||
|
|
|
||||||
|
|
@ -479,11 +479,6 @@ dnPrettyNormal(
|
||||||
pretty->bv_len = 0;
|
pretty->bv_len = 0;
|
||||||
normal->bv_len = 0;
|
normal->bv_len = 0;
|
||||||
|
|
||||||
/* FIXME: str2dn should take a bv and handle this */
|
|
||||||
if( strlen( val->bv_val ) != val->bv_len ) {
|
|
||||||
return LDAP_INVALID_SYNTAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME: should be liberal in what we accept */
|
/* FIXME: should be liberal in what we accept */
|
||||||
rc = ldap_bv2dn( val, &dn, LDAP_DN_FORMAT_LDAP );
|
rc = ldap_bv2dn( val, &dn, LDAP_DN_FORMAT_LDAP );
|
||||||
if ( rc != LDAP_SUCCESS ) {
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
|
|
@ -619,7 +614,7 @@ dnExtractRdn(
|
||||||
return LDAP_OTHER;
|
return LDAP_OTHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = ldap_str2rdn( dn->bv_val, &tmpRDN, (char **)&p, LDAP_DN_FORMAT_LDAP );
|
rc = ldap_bv2rdn( dn, &tmpRDN, (char **)&p, LDAP_DN_FORMAT_LDAP );
|
||||||
if ( rc != LDAP_SUCCESS ) {
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
@ -698,7 +693,7 @@ rdnValidate( struct berval *rdn )
|
||||||
/*
|
/*
|
||||||
* must be parsable
|
* must be parsable
|
||||||
*/
|
*/
|
||||||
rc = ldap_str2rdn( rdn, &RDN, (char **)&p, LDAP_DN_FORMAT_LDAP );
|
rc = ldap_bv2rdn( rdn, &RDN, (char **)&p, LDAP_DN_FORMAT_LDAP );
|
||||||
if ( rc != LDAP_SUCCESS ) {
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue