]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/entry.c
Don't allow suffixAliases were alias and aliased dn our the same.
[openldap] / servers / slapd / entry.c
index 80617959e04fa3a386b29982ecb5bb5aa0b0880e..fedab892fa46c4d6617630fb85745de2bb5717ac 100644 (file)
@@ -10,9 +10,6 @@
 
 #include "slap.h"
 
-void   entry_free();
-char   *entry2str();
-
 static unsigned char   *ebuf;  /* buf returned by entry2str             */
 static unsigned char   *ecur;  /* pointer to end of currently used ebuf */
 static int             emaxsize;/* max size of ebuf                     */
@@ -20,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;
@@ -49,15 +46,11 @@ str2entry( char     *s )
        Debug( LDAP_DEBUG_TRACE, "=> str2entry\n",
                s ? s : "NULL", 0, 0 );
 
-       e = (Entry *) ch_calloc( 1, sizeof(Entry) );
-       /* initialize reader/writer lock */
-       entry_rdwr_init(e);
-
        /* check to see if there's an id included */
        next = s;
        if ( isdigit( *s ) ) {
-               e->e_id = atoi( s );
-               if ( (s = str_getline( &next )) == NULL ) {
+               id = atoi( s );
+               if ( (s = ldif_getline( &next )) == NULL ) {
                        Debug( LDAP_DEBUG_TRACE,
                            "<= str2entry NULL (missing newline after id)\n",
                            0, 0, 0 );
@@ -65,17 +58,30 @@ str2entry( char     *s )
                }
        }
 
+       /* 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 */
        e->e_attrs = NULL;
        vals[0] = &bval;
        vals[1] = NULL;
        ptype[0] = '\0';
-       while ( (s = str_getline( &next )) != NULL ) {
+       while ( (s = ldif_getline( &next )) != NULL ) {
                if ( *s == '\n' || *s == '\0' ) {
                        break;
                }
 
-               if ( str_parse_line( s, &type, &value, &vlen ) != 0 ) {
+               if ( ldif_parse_line( s, &type, &value, &vlen ) != 0 ) {
                        Debug( LDAP_DEBUG_TRACE,
                            "<= str2entry NULL (parse_line)\n", 0, 0, 0 );
                        continue;
@@ -87,14 +93,23 @@ str2entry( char     *s )
                        maxvals = 0;
                        a = NULL;
                }
+
                if ( strcasecmp( type, "dn" ) == 0 ) {
                        if ( e->e_dn != NULL ) {
                                Debug( LDAP_DEBUG_ANY,
   "str2entry: entry %d has multiple dns \"%s\" and \"%s\" (second ignored)\n",
"str2entry: entry %lu has multiple dns \"%s\" and \"%s\" (second ignored)\n",
                                    e->e_id, e->e_dn, value );
                                continue;
                        }
-                       e->e_dn = strdup( value );
+                       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_case( ch_strdup( value ) );
                        continue;
                }
 
@@ -104,6 +119,7 @@ str2entry( char     *s )
                    != 0 ) {
                        Debug( LDAP_DEBUG_TRACE,
                            "<= str2entry NULL (attr_merge)\n", 0, 0, 0 );
+                       entry_free( e );
                        return( NULL );
                }
                nvals++;
@@ -111,13 +127,21 @@ str2entry( char   *s )
 
        /* check to make sure there was a dn: line */
        if ( e->e_dn == NULL ) {
-               Debug( LDAP_DEBUG_ANY, "str2entry: entry %d has no dn\n",
+               Debug( LDAP_DEBUG_ANY, "str2entry: entry %lu has no dn\n",
                    e->e_id, 0, 0 );
                entry_free( e );
                return( NULL );
        }
 
-       Debug( LDAP_DEBUG_TRACE, "<= str2entry 0x%x\n", e, 0, 0 );
+       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 );
 }
@@ -167,7 +191,7 @@ entry2str(
                /* put "dn: <dn>" */
                tmplen = strlen( e->e_dn );
                MAKE_SPACE( LDIF_SIZE_NEEDED( 2, tmplen ));
-               put_type_and_value( (char **) &ecur, "dn", e->e_dn, tmplen );
+               ldif_put_type_and_value( (char **) &ecur, "dn", e->e_dn, tmplen );
        }
 
        /* put the attributes */
@@ -177,7 +201,7 @@ entry2str(
                        bv = a->a_vals[i];
                        tmplen = strlen( a->a_type );
                        MAKE_SPACE( LDIF_SIZE_NEEDED( tmplen, bv->bv_len ));
-                       put_type_and_value( (char **) &ecur, a->a_type,
+                       ldif_put_type_and_value( (char **) &ecur, a->a_type,
                            bv->bv_val, bv->bv_len );
                }
        }
@@ -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 );
@@ -261,4 +288,3 @@ entry_rdwr_init(Entry *e)
 {
        return pthread_rdwr_init_np(&e->e_rdwr, NULL);
 }
-