From: Kurt Zeilenga Date: Wed, 13 Jan 1999 01:17:22 +0000 (+0000) Subject: Add normalized dn to Entry structure as field e_ndn. Entry X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~791 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b39fdc0bcd939980759745108e3776a18833ca74;p=openldap Add normalized dn to Entry structure as field e_ndn. Entry creation codes to provide this field. Update cache_entrydn_cmp to strcasecmp() the e_ndn instead of e_dn. Note: strcasecmp() is still used as e_ndn isn't in uppercase. Maybe it should be. Did not update other codes to use e_ndn. Hence, there are lots of dn_normalize() calls that could be eliminated. (The case determination of e_ndn should be made first). --- diff --git a/servers/slapd/add.c b/servers/slapd/add.c index 6e9541b4ee..823389b76b 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -58,8 +58,10 @@ do_add( Connection *conn, Operation *op ) entry_rdwr_init(e); e->e_dn = dn; - dn = dn_normalize( ch_strdup( dn ) ); - Debug( LDAP_DEBUG_ARGS, " do_add: dn (%s)\n", dn, 0, 0 ); + e->e_ndn = dn_normalize( ch_strdup( dn ) ); + dn = NULL; + + Debug( LDAP_DEBUG_ARGS, " do_add: ndn (%s)\n", e->e_ndn, 0, 0 ); /* get the attrs */ e->e_attrs = NULL; @@ -71,7 +73,6 @@ do_add( Connection *conn, Operation *op ) if ( ber_scanf( ber, "{a{V}}", &type, &vals ) == LBER_ERROR ) { send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "decoding error" ); - free( dn ); entry_free( e ); return; } @@ -82,7 +83,6 @@ do_add( Connection *conn, Operation *op ) send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, NULL ); free( type ); - free( dn ); entry_free( e ); return; } @@ -94,15 +94,14 @@ do_add( Connection *conn, Operation *op ) } Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d ADD dn=\"%s\"\n", - conn->c_connid, op->o_opid, dn, 0, 0 ); + conn->c_connid, op->o_opid, e->e_ndn, 0, 0 ); /* * We could be serving multiple database backends. Select the * appropriate one, or send a referral to our "referral server" * if we don't hold it. */ - be = select_backend( dn ); - free( dn ); + be = select_backend( e->e_ndn ); if ( be == NULL ) { entry_free( e ); send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL, diff --git a/servers/slapd/back-ldbm/cache.c b/servers/slapd/back-ldbm/cache.c index 01a92295df..f8664f5ebe 100644 --- a/servers/slapd/back-ldbm/cache.c +++ b/servers/slapd/back-ldbm/cache.c @@ -35,7 +35,8 @@ cache_entry_cmp( Entry *e1, Entry *e2 ) static int cache_entrydn_cmp( Entry *e1, Entry *e2 ) { - return( strcasecmp( e1->e_dn, e2->e_dn ) ); + /* compare their normalized dn's */ + return( strcasecmp( e1->e_ndn, e2->e_ndn ) ); } static int @@ -234,10 +235,13 @@ cache_find_entry_dn2id( pthread_mutex_lock( &cache->c_mutex ); e.e_dn = dn; + e.e_ndn = dn_normalize( ch_strdup( dn ) ); if ( (ep = (Entry *) avl_find( cache->c_dntree, (caddr_t) &e, cache_entrydn_cmp )) != NULL ) { + free(e.e_ndn); + Debug(LDAP_DEBUG_TRACE, "====> cache_find_entry_dn2id: found dn: %s\n", dn, 0, 0); @@ -291,6 +295,8 @@ cache_find_entry_dn2id( return( id ); } + free(e.e_ndn); + /* free cache mutex */ pthread_mutex_unlock( &cache->c_mutex ); diff --git a/servers/slapd/back-passwd/search.c b/servers/slapd/back-passwd/search.c index 93b69fb1c2..a97206fe31 100644 --- a/servers/slapd/back-passwd/search.c +++ b/servers/slapd/back-passwd/search.c @@ -136,6 +136,7 @@ pw2entry( Backend *be, struct passwd *pw ) sprintf( buf, "%s@%s", pw->pw_name, be->be_suffix[0] ); e->e_dn = ch_strdup( buf ); + e->e_ndn = ch_strdup( buf ); val.bv_val = pw->pw_name; val.bv_len = strlen( pw->pw_name ); diff --git a/servers/slapd/entry.c b/servers/slapd/entry.c index 67cc85833e..440411e481 100644 --- a/servers/slapd/entry.c +++ b/servers/slapd/entry.c @@ -17,7 +17,7 @@ static int emaxsize;/* max size of ebuf */ Entry * str2entry( char *s ) { - int i; + int id = 0; Entry *e; Attribute **a; char *type; @@ -46,22 +46,29 @@ str2entry( char *s ) Debug( LDAP_DEBUG_TRACE, "=> str2entry\n", s ? s : "NULL", 0, 0 ); - e = (Entry *) ch_calloc( 1, sizeof(Entry) ); - /* check to see if there's an id included */ next = s; if ( isdigit( *s ) ) { - e->e_id = atoi( s ); + id = atoi( s ); if ( (s = ldif_getline( &next )) == NULL ) { Debug( LDAP_DEBUG_TRACE, "<= str2entry NULL (missing newline after id)\n", 0, 0, 0 ); - free( e ); return( NULL ); } } /* initialize reader/writer lock */ + e = (Entry *) ch_calloc( 1, sizeof(Entry) ); + + if( e == NULL ) { + Debug( LDAP_DEBUG_TRACE, + "<= str2entry NULL (entry allocation failed)\n", + 0, 0, 0 ); + return( NULL ); + } + e->e_id = id; + entry_rdwr_init(e); /* dn + attributes */ @@ -86,6 +93,7 @@ str2entry( char *s ) maxvals = 0; a = NULL; } + if ( strcasecmp( type, "dn" ) == 0 ) { if ( e->e_dn != NULL ) { Debug( LDAP_DEBUG_ANY, @@ -94,6 +102,14 @@ str2entry( char *s ) continue; } e->e_dn = ch_strdup( value ); + + if ( e->e_ndn != NULL ) { + Debug( LDAP_DEBUG_ANY, + "str2entry: entry %lu already has a normalized dn \"%s\" for \"%s\" (first ignored)\n", + e->e_id, e->e_ndn, value ); + free( e->e_ndn ); + } + e->e_ndn = dn_normalize( ch_strdup( value ) ); continue; } @@ -117,6 +133,14 @@ str2entry( char *s ) return( NULL ); } + if ( e->e_ndn == NULL ) { + Debug( LDAP_DEBUG_ANY, + "str2entry: entry %lu (\"%s\") has no normalized dn\n", + e->e_id, e->e_dn, 0 ); + entry_free( e ); + return( NULL ); + } + Debug(LDAP_DEBUG_TRACE, "<= str2entry 0x%lx\n", (unsigned long)e, 0,0); return( e ); @@ -203,6 +227,9 @@ entry_free( Entry *e ) if ( e->e_dn != NULL ) { free( e->e_dn ); } + if ( e->e_ndn != NULL ) { + free( e->e_ndn ); + } for ( a = e->e_attrs; a != NULL; a = next ) { next = a->a_next; attr_free( a ); diff --git a/servers/slapd/monitor.c b/servers/slapd/monitor.c index 698ac953a4..9efffc788e 100644 --- a/servers/slapd/monitor.c +++ b/servers/slapd/monitor.c @@ -49,6 +49,7 @@ monitor_info( Connection *conn, Operation *op ) entry_rdwr_init(e); e->e_attrs = NULL; e->e_dn = ch_strdup( SLAPD_MONITOR_DN ); + e->e_ndn = NULL; val.bv_val = Versionstr; if (( p = strchr( Versionstr, '\n' )) == NULL ) { diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index a8f1a1fbc9..bf30582fc0 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -130,6 +130,7 @@ typedef unsigned long ID; */ typedef struct entry { char *e_dn; /* DN of this entry */ + char *e_ndn; /* normalized DN of this entry */ Attribute *e_attrs; /* list of attributes + values */ ID e_id; /* id of this entry - this should */