Added dn_rdnlen. Fixed rdn leak in limits.c.

This commit is contained in:
Howard Chu 2001-12-08 11:08:26 +00:00
parent e2c2de11c3
commit ad9d17d537
5 changed files with 31 additions and 38 deletions

View File

@ -355,11 +355,7 @@ acl_get(
if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) || DN_ESCAPE( e->e_ndn[dnlen - patlen - 2] ) )
continue;
rdn = dn_rdn( NULL, e->e_ndn );
if ( rdn != NULL ) {
rdnlen = strlen( rdn );
ch_free( rdn );
}
rdnlen = dn_rdnlen( NULL, e->e_ndn );
if ( rdnlen != dnlen - patlen - 1 )
continue;
@ -562,11 +558,7 @@ acl_mask(
if ( !DN_SEPARATOR( op->o_ndn[odnlen - patlen - 1] ) || DN_ESCAPE( op->o_ndn[odnlen - patlen - 2] ) )
continue;
rdn = dn_rdn( NULL, op->o_ndn );
if ( rdn != NULL ) {
rdnlen = strlen( rdn );
ch_free( rdn );
}
rdnlen = dn_rdnlen( NULL, op->o_ndn );
if ( rdnlen != odnlen - patlen - 1 )
continue;

View File

@ -678,32 +678,24 @@ bdb_dn2id_add(
int rc, rlen, nrlen;
DBT key, data;
DB *db = bdb->bi_id2parent->bdi_db;
char *nrdn = dn_rdn( be, e->e_ndn );
char *rdn;
diskNode *d;
idNode *n;
if (nrdn == NULL) {
nrdn = "";
rdn = "";
} else {
rdn = dn_rdn( be, e->e_dn );
}
nrlen = dn_rdnlen( be, e->e_ndn );
rlen = dn_rdnlen( be, e->e_dn );
nrlen = strlen(nrdn);
rlen = strlen(rdn);
d = ch_malloc(sizeof(diskNode) + rlen + nrlen + 2);
d->rdn.bv_len = rlen;
d->nrdn.bv_len = nrlen;
d->rdn.bv_val = (char *)(d+1);
d->nrdn.bv_val = bdb_strcopy(d->rdn.bv_val, rdn) + 1;
strcpy(d->nrdn.bv_val, nrdn);
d->nrdn.bv_val = d->rdn.bv_val + rlen + 1;
strncpy(d->rdn.bv_val, e->e_dn, rlen);
d->rdn.bv_val[rlen] = '\0';
strncpy(d->nrdn.bv_val, e->e_ndn, nrlen);
d->nrdn.bv_val[nrlen] = '\0';
d->rdn.bv_val -= (long)d;
d->nrdn.bv_val -= (long)d;
if (nrdn[0]) free(nrdn);
if (rdn[0]) free(rdn);
if (pdn) {
bdb_dn2id(be, txn, pdn, &d->parent);
} else {

View File

@ -369,7 +369,7 @@ dn_parent(
return "";
}
char * dn_rdn(
int dn_rdnlen(
Backend *be,
const char *dn_in )
{
@ -377,7 +377,7 @@ char * dn_rdn(
int inquote;
if( dn_in == NULL ) {
return NULL;
return 0;
}
while(*dn_in && ASCII_SPACE(*dn_in)) {
@ -385,14 +385,14 @@ char * dn_rdn(
}
if( *dn_in == '\0' ) {
return( NULL );
return( 0 );
}
if ( be != NULL && be_issuffix( be, dn_in ) ) {
return( NULL );
return( 0 );
}
dn = ch_strdup( dn_in );
dn = dn_in;
inquote = 0;
@ -411,15 +411,26 @@ char * dn_rdn(
if ( *s == '"' ) {
inquote = 1;
} else if ( DN_SEPARATOR( *s ) ) {
*s = '\0';
return( dn );
break;
}
}
}
return( dn );
return( s - dn );
}
char * dn_rdn(
Backend *be,
const char *dn_in )
{
char *rdn;
int i = dn_rdnlen( be, dn_in );
rdn = ch_malloc( i + 1 );
strncpy(rdn, dn_in, i);
rdn[i] = '\0';
return rdn;
}
/*
* return a charray of all subtrees to which the DN resides in

View File

@ -75,16 +75,13 @@ get_limits(
/* in case of (sub)match ... */
if ( strcmp( lm[0]->lm_dn_pat->bv_val, &ndn[d] ) == 0 ) {
/* check for exacctly one rdn in case of ONE */
/* check for exactly one rdn in case of ONE */
if ( lm[0]->lm_type == SLAP_LIMITS_ONE ) {
char *rdn;
/*
* if ndn is more that one rdn
* below dn_pat, continue
*/
rdn = dn_rdn( NULL, ndn );
if ( strlen( rdn ) != d - 1 ) {
if ( dn_rdnlen( NULL, ndn ) != d - 1 ) {
break;
}
}

View File

@ -321,6 +321,7 @@ LDAP_SLAPD_F (int) dn_match LDAP_P(( const char *val, const char *asserted ));
LDAP_SLAPD_F (char *) dn_parent LDAP_P(( Backend *be, const char *dn ));
LDAP_SLAPD_F (char **) dn_subtree LDAP_P(( Backend *be, const char *dn ));
LDAP_SLAPD_F (char *) dn_rdn LDAP_P(( Backend *be, const char *dn ));
LDAP_SLAPD_F (int) dn_rdnlen LDAP_P(( Backend *be, const char *dn ));
LDAP_SLAPD_F (int) dn_issuffix LDAP_P(( const char *dn, const char *suffix ));
LDAP_SLAPD_F (int) rdn_validate LDAP_P(( const char* str ));
LDAP_SLAPD_F (char *) rdn_attr_value LDAP_P(( const char * rdn ));