Changed be_issuffix and dnParent to take struct bervals.

Changed dn_rdnlen, assumes an already pretty/normalized DN.
Added slap_empty_bv, a zero-length non-NULL berval.
This commit is contained in:
Howard Chu 2002-01-26 05:27:28 +00:00
parent a1987ae99b
commit 07d0f4e411
3 changed files with 23 additions and 19 deletions

View File

@ -579,14 +579,13 @@ select_backend(
int
be_issuffix(
Backend *be,
const char *suffix
struct berval *bvsuffix
)
{
int i;
struct berval bvsuffix = { strlen( suffix ), (char *)suffix };
for ( i = 0; be->be_nsuffix != NULL && be->be_nsuffix[i] != NULL; i++ ) {
if ( ber_bvcmp( be->be_nsuffix[i], &bvsuffix ) == 0 ) {
if ( ber_bvcmp( be->be_nsuffix[i], bvsuffix ) == 0 ) {
return( 1 );
}
}

View File

@ -18,6 +18,8 @@
#include "slap.h"
const struct berval slap_empty_bv = { 0, "" };
#define SLAP_LDAPDN_PRETTY 0x1
/*
@ -564,16 +566,17 @@ dnMatch(
*/
int
dnParent(
const char *dn,
const char **pdn )
struct berval *dn,
struct berval *pdn )
{
const char *p;
p = strchr( dn, ',' );
p = strchr( dn->bv_val, ',' );
/* one-level dn */
if ( p == NULL ) {
*pdn = "";
pdn->bv_val = "";
pdn->bv_len = 0;
return LDAP_SUCCESS;
}
@ -581,7 +584,8 @@ dnParent(
p++;
assert( ATTR_LEADCHAR( p[ 0 ] ) );
*pdn = p;
pdn->bv_val = p;
pdn->bv_len = dn->bv_len - (p - dn->bv_val);
return LDAP_SUCCESS;
}
@ -642,6 +646,7 @@ dn_parent(
const char *dn )
{
const char *pdn;
struct berval bv;
if ( dn == NULL ) {
return NULL;
@ -655,7 +660,9 @@ dn_parent(
return NULL;
}
if ( be != NULL && be_issuffix( be, dn ) ) {
bv.bv_val = dn;
bv.bv_len = strlen(bv.bv_val);
if ( be != NULL && be_issuffix( be, &bv ) ) {
return NULL;
}
@ -699,7 +706,7 @@ dnExtractRdn(
}
/*
* FIXME: should be replaced by dnExtractRdn()
* We can assume the input is a prettied or normalized DN
*/
int
dn_rdnlen(
@ -719,17 +726,13 @@ dn_rdnlen(
return 0;
}
if ( be != NULL && be_issuffix( be, dn_in->bv_val ) ) {
if ( be != NULL && be_issuffix( be, dn_in ) ) {
return 0;
}
rc = ldap_str2rdn( dn_in->bv_val, NULL, (char **)&p,
LDAP_DN_FORMAT_LDAP | LDAP_DN_SKIP );
if ( rc != LDAP_SUCCESS ) {
return 0;
}
p = strchr( dn_in->bv_val, ',' );
return p - dn_in->bv_val;
return p ? p - dn_in->bv_val : dn_in->bv_len;
}

View File

@ -168,7 +168,7 @@ LDAP_SLAPD_F (BackendDB *) select_backend LDAP_P((
int noSubordinates ));
LDAP_SLAPD_F (int) be_issuffix LDAP_P(( Backend *be,
const char *suffix ));
struct berval *suffix ));
LDAP_SLAPD_F (int) be_isroot LDAP_P(( Backend *be,
struct berval *ndn ));
LDAP_SLAPD_F (int) be_isroot_pw LDAP_P(( Backend *be,
@ -349,6 +349,8 @@ LDAP_SLAPD_F (void) slapd_clr_read LDAP_P((ber_socket_t s, int wake));
#define dn_match(dn1, dn2) ( ber_bvcmp((dn1), (dn2)) == 0 )
LDAP_SLAPD_V( const struct berval ) slap_empty_bv;
LDAP_SLAPD_F (int) dnValidate LDAP_P((
Syntax *syntax,
struct berval *val ));
@ -402,7 +404,7 @@ LDAP_SLAPD_F (void) build_new_dn LDAP_P((
struct berval * parent_dn,
struct berval * newrdn ));
LDAP_SLAPD_F (int) dnParent LDAP_P(( const char *dn, const char **pdn ));
LDAP_SLAPD_F (int) dnParent LDAP_P(( struct berval *dn, struct berval *pdn ));
#define SLAP_DN_MIGRATION
#ifdef SLAP_DN_MIGRATION