From: Howard Chu Date: Sat, 26 Jan 2002 05:27:28 +0000 (+0000) Subject: Changed be_issuffix and dnParent to take struct bervals. X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~26 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=07d0f4e4111906556090818c7917b8188c9b79d1;p=openldap 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. --- diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 64c42e9a44..d2d3f5976c 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -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 ); } } diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index 1c6ad8fc49..5068a04615 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -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; } diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index a9d733a12d..038094c259 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -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