]> git.sur5r.net Git - openldap/commitdiff
Pretty the entry DNs on add but not rename (yet).
authorKurt Zeilenga <kurt@openldap.org>
Sat, 8 Dec 2001 06:57:06 +0000 (06:57 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Sat, 8 Dec 2001 06:57:06 +0000 (06:57 +0000)
servers/slapd/add.c
servers/slapd/dn.c
servers/slapd/entry.c
servers/slapd/proto-slap.h

index 9399d5d4a08964b32928d0ceeb84fb79d5e232ee..f0d75237fff61d5f5a67586fceef22c5e096e22c 100644 (file)
@@ -34,7 +34,7 @@ int
 do_add( Connection *conn, Operation *op )
 {
        BerElement      *ber = op->o_ber;
-       char            *dn, *ndn, *last;
+       char            *dn, *last;
        ber_len_t       len;
        ber_tag_t       tag;
        Entry           *e;
@@ -68,7 +68,7 @@ do_add( Connection *conn, Operation *op )
        if ( ber_scanf( ber, "{a", /*}*/ &dn ) == LBER_ERROR ) {
 #ifdef NEW_LOGGING
                LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                          "do_add: conn %d ber_scanf failed\n", conn->c_connid ));
+                       "do_add: conn %d ber_scanf failed\n", conn->c_connid ));
 #else
                Debug( LDAP_DEBUG_ANY, "do_add: ber_scanf failed\n", 0, 0, 0 );
 #endif
@@ -77,32 +77,28 @@ do_add( Connection *conn, Operation *op )
                return -1;
        }
 
-       ndn = ch_strdup( dn );
+       e = (Entry *) ch_calloc( 1, sizeof(Entry) );
 
-       if ( dn_normalize( ndn ) == NULL ) {
+       e->e_dn = dn_pretty( dn );
+       e->e_ndn = dn_normalize( dn );
+       e->e_attrs = NULL;
+       e->e_private = NULL;
+
+       if ( e->e_ndn == NULL ) {
 #ifdef NEW_LOGGING
                LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                          "do_add: conn %d      invalid dn (%s)\n", conn->c_connid, dn ));
+                       "do_add: conn %d         invalid dn (%s)\n", conn->c_connid, dn ));
 #else
                Debug( LDAP_DEBUG_ANY, "do_add: invalid dn (%s)\n", dn, 0, 0 );
 #endif
-               send_ldap_result( conn, op, LDAP_INVALID_DN_SYNTAX, NULL,
+               send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
                    "invalid DN", NULL, NULL );
-               free( dn );
-               free( ndn );
-               return LDAP_INVALID_DN_SYNTAX;
+               goto done;
        }
 
-       e = (Entry *) ch_calloc( 1, sizeof(Entry) );
-
-       e->e_dn = dn;
-       e->e_ndn = ndn;
-       e->e_attrs = NULL;
-       e->e_private = NULL;
-
 #ifdef NEW_LOGGING
        LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
-                  "do_add: conn %d  ndn (%s)\n", conn->c_connid, e->e_ndn ));
+               "do_add: conn %d  ndn (%s)\n", conn->c_connid, e->e_ndn ));
 #else
        Debug( LDAP_DEBUG_ARGS, "do_add: ndn (%s)\n", e->e_ndn, 0, 0 );
 #endif
@@ -191,7 +187,7 @@ do_add( Connection *conn, Operation *op )
                goto done;
 
 #if defined( SLAPD_SCHEMA_DN )
-       } else if ( strcasecmp( ndn, SLAPD_SCHEMA_DN ) == 0 ) {
+       } else if ( strcasecmp( e->e_ndn, SLAPD_SCHEMA_DN ) == 0 ) {
                /* protocolError may be a more appropriate error */
                send_ldap_result( conn, op, rc = LDAP_ALREADY_EXISTS,
                        NULL, "subschema subentry already exists",
index 9117641293e946890e081df754b21d5862741b11..07f5fbe2007abcb02ce2879bf278f3b6886f977c 100644 (file)
 #define INQUOTEDVALUE  7
 #define B4SEPARATOR            8
 
+/*
+ * dn_pretty - "pretty" the DN
+ */
+char *dn_pretty( const char *dn_in )
+{
+       /*
+        * dn_validate based implementation (for now)
+        *      likely better just to zap this, dn_validate, dn_normalize
+        */
+       char *dn, *dn_out;
+
+       dn = ch_strdup( dn_in );
+       dn_out = dn_validate( dn );
+       if( dn_out == NULL ) free( dn );
+       return dn_out;
+}
+
 /*
  * dn_validate - validate and compress dn.  the dn is
  * compressed in place are returned if valid.
@@ -302,8 +319,7 @@ dn_match( const char *val, const char *asserted )
 char *
 dn_parent(
        Backend *be,
-       const char      *dn
-)
+       const char      *dn )
 {
        const char      *s;
        int     inquote;
index ccb773a5a775e8d5d35ee0f4d0100ab489ab95d0..3608eeaefb46ad43d19b9985d807ee08ce72f5b6 100644 (file)
@@ -266,12 +266,28 @@ str2entry( char *s )
        }
 
        /* generate normalized dn */
-       e->e_ndn = ch_strdup( e->e_dn );
+       e->e_ndn = e->e_dn;
+       e->e_dn = dn_pretty( e->e_dn );
+
+       if( e->e_dn == NULL ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
+                          "str2entry:  entry %ld has invalid dn: %s\n",
+                               (long) e->e_id, e->e_ndn ));
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "str2entry: entry %ld has invalid dn: %s\n",
+                   (long) e->e_id, e->e_ndn, 0 );
+#endif
+               entry_free( e );
+               return( NULL );
+       }
+
        (void) dn_normalize( e->e_ndn );
 
 #ifdef NEW_LOGGING
        LDAP_LOG(( "operation", LDAP_LEVEL_DETAIL2,
-                  "str2entry(%s) -> 0x%lx\n", e->e_dn, (unsigned long)e ));
+               "str2entry(%s) -> 0x%lx\n", e->e_dn, (unsigned long)e ));
 #else
        Debug(LDAP_DEBUG_TRACE, "<= str2entry(%s) -> 0x%lx\n",
                e->e_dn, (unsigned long) e, 0 );
index 282dd08357d5edd7a6bdf536c72b07fd8409e127..8b3539f7454c7175baf84ce8212c69a257311d81 100644 (file)
@@ -314,6 +314,7 @@ LDAP_SLAPD_F (void) connection_internal_close( Connection *conn );
  * dn.c
  */
 
+LDAP_SLAPD_F (char *) dn_pretty LDAP_P(( const char *dn ));
 LDAP_SLAPD_F (char *) dn_validate LDAP_P(( char *dn ));
 LDAP_SLAPD_F (char *) dn_normalize LDAP_P(( char *dn ));
 LDAP_SLAPD_F (int) dn_match LDAP_P(( const char *val, const char *asserted ));