]> git.sur5r.net Git - openldap/commitdiff
Add limited LDAP_INVALID_DN_SYNTAX support. dn_normalize{,_case}() now returns
authorKurt Zeilenga <kurt@openldap.org>
Thu, 22 Jul 1999 17:14:42 +0000 (17:14 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Thu, 22 Jul 1999 17:14:42 +0000 (17:14 +0000)
NULL does not meet basic syntax rules.

28 files changed:
servers/slapd/acl.c
servers/slapd/add.c
servers/slapd/back-bdb2/cache.c
servers/slapd/back-bdb2/dn2id.c
servers/slapd/back-bdb2/modrdn.c
servers/slapd/back-ldap/search.c
servers/slapd/back-ldbm/cache.c
servers/slapd/back-ldbm/dn2id.c
servers/slapd/back-ldbm/modrdn.c
servers/slapd/back-passwd/search.c
servers/slapd/bind.c
servers/slapd/compare.c
servers/slapd/config.c
servers/slapd/configinfo.c
servers/slapd/connection.c
servers/slapd/delete.c
servers/slapd/dn.c
servers/slapd/entry.c
servers/slapd/modify.c
servers/slapd/modrdn.c
servers/slapd/monitor.c
servers/slapd/proto-slap.h
servers/slapd/root_dse.c
servers/slapd/schema.c
servers/slapd/search.c
servers/slapd/slap.h
servers/slapd/tools/ldif2id2children-bdb2.c
servers/slapd/tools/ldif2id2children.c

index e632c1a9f69260e50cf22b01ece5645369850ccc..15bbcd4fba8b16150251b30e1e3a8a0cafad2c65 100644 (file)
@@ -360,7 +360,10 @@ acl_access_allowed(
                         */
                        /* see if asker is listed in dnattr */
                        string_expand(buf, sizeof(buf), b->a_group_pat, edn, matches);
-                       (void) dn_normalize_case(buf);
+                       if ( dn_normalize_case(buf) == NULL ) {
+                               /* did not expand to a valid dn */
+                               continue;
+                       }
 
                        if (backend_group(be, e, buf, op->o_ndn,
                                b->a_group_oc, b->a_group_at) != 0)
index 683a7649c318dae81dcbf66f2831dc36a71bfc0c..efb4e18d6d9b04a676c2534e87735f656d82e86a 100644 (file)
@@ -26,7 +26,7 @@ int
 do_add( Connection *conn, Operation *op )
 {
        BerElement      *ber = op->o_ber;
-       char            *dn, *last;
+       char            *dn, *ndn, *last;
        ber_len_t       len;
        ber_tag_t       tag;
        Entry           *e;
@@ -62,10 +62,21 @@ do_add( Connection *conn, Operation *op )
                return -1;
        }
 
+       ndn = ch_strdup( dn );
+
+       if ( dn_normalize_case( ndn ) == NULL ) {
+               Debug( LDAP_DEBUG_ANY, "do_add: invalid dn (%s)\n", dn, 0, 0 );
+               send_ldap_result( conn, op, LDAP_INVALID_DN_SYNTAX, NULL,
+                   "invalid DN", NULL, NULL );
+               free( dn );
+               free( ndn );
+               return LDAP_INVALID_DN_SYNTAX;
+       }
+
        e = (Entry *) ch_calloc( 1, sizeof(Entry) );
 
        e->e_dn = dn;
-       e->e_ndn = dn_normalize_case( ch_strdup( dn ) );
+       e->e_ndn = ndn;
        e->e_private = NULL;
 
        dn = NULL;
index e13c9185373f25d6d2e5a8b2dac00452cc2b8423..593c304351b92c4032927056e0f8e9d917514303 100644 (file)
@@ -358,7 +358,8 @@ bdb2i_cache_find_entry_dn2id(
        int             count = 0;
 
        e.e_dn = dn;
-       e.e_ndn = dn_normalize_case( ch_strdup( dn ) );
+       e.e_ndn = ch_strdup( dn )
+       (void) dn_normalize_case( e.e_ndn );
 
 try_again:
        /* set cache mutex */
index e77cabfa20f6f8d3200938571e72bcf2c80b094a..35b1081d2bd3862238377c5cca73c56d8f7d4236 100644 (file)
@@ -36,7 +36,7 @@ bdb2i_dn2id_add(
        }
 
        dn = ch_strdup( dn );
-       dn_normalize_case( dn );
+       (void) dn_normalize_case( dn );
 
        key.dptr = dn;
        key.dsize = strlen( dn ) + 1;
@@ -71,7 +71,7 @@ bdb2i_dn2id(
 
        dn = ch_strdup( dn );
        Debug( LDAP_DEBUG_TRACE, "=> bdb2i_dn2id( \"%s\" )\n", dn, 0, 0 );
-       dn_normalize_case( dn );
+       (void) dn_normalize_case( dn );
 
        /* first check the cache */
        if ( (id = bdb2i_cache_find_entry_dn2id( be, &li->li_cache, dn )) != NOID ) {
@@ -133,7 +133,7 @@ bdb2i_dn2id_delete(
        }
 
        dn = ch_strdup( dn );
-       dn_normalize_case( dn );
+       (void) dn_normalize_case( dn );
        key.dptr = dn;
        key.dsize = strlen( dn ) + 1;
 
index 8054eed2c1a0e681142f2b2c73087cf8ffce501d..4460c06cdda30904d1fabd39cbe66bd4c812103c 100644 (file)
@@ -170,7 +170,8 @@ bdb2i_back_modrdn_internal(
                       "ldbm_back_modrdn: new parent requested...\n",
                       0, 0, 0 );
 
-               np_ndn = dn_normalize_case( ch_strdup( np_dn ) );
+               np_ndn = ch_strdup( np_dn );
+               (void) dn_normalize_case( np_ndn );
 
                /* newSuperior == oldParent?, if so ==> ERROR */
 
@@ -218,7 +219,8 @@ bdb2i_back_modrdn_internal(
        build_new_dn( &new_dn, e->e_dn, new_parent_dn, newrdn ); 
 
 
-       new_ndn = dn_normalize_case( ch_strdup( new_dn ) );
+       new_ndn = ch_strdup( new_dn );
+       (void) dn_normalize_case( new_ndn );
 
        Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n",
               new_ndn, 0, 0 );
@@ -321,7 +323,9 @@ bdb2i_back_modrdn_internal(
            
        }               
 
+#ifdef DNS_DN
        if ( dn_type( old_rdn ) == DN_X500 ) {
+#endif
 
                Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
                       0, 0, 0 );
@@ -383,6 +387,7 @@ bdb2i_back_modrdn_internal(
                
                }/* if (deleteoldrdn) */
 
+#ifdef DNS_DN
        } else {
            
 
@@ -394,6 +399,7 @@ bdb2i_back_modrdn_internal(
                       0, 0, 0 );  
 
        }
+#endif
 
        /* modify memory copy of entry */
        if ( bdb2i_back_modify_internal( be, conn, op, dn, &mod[0], e )
index c742248c5ee3cb6ae516418e15f57df221557f40..f6054fa66e983d7687e706c9a3e7f1be662966b1 100644 (file)
@@ -141,7 +141,8 @@ ldap_send_entry(
        struct berval *dummy = NULL;
 
        ent.e_dn = ldap_get_dn(lc->ld, e);
-       ent.e_ndn = dn_normalize_case( ch_strdup( ent.e_dn));
+       ent.e_ndn = ch_strdup( ent.e_dn);
+       (void) dn_normalize_case( ent.e_ndn );
        ent.e_id = 0;
        ent.e_attrs = 0;
        ent.e_private = 0;
index 85d3b07ef6d1c73a7d1a129525b6b6e994501882..a355f7142e407f4342bf51e46498dcb2afc4b9ed 100644 (file)
@@ -439,7 +439,8 @@ cache_find_entry_dn2id(
        int count = 0;
 
        e.e_dn = dn;
-       e.e_ndn = dn_normalize_case( ch_strdup( dn ) );
+       e.e_ndn = ch_strdup( dn );
+       (void) dn_normalize_case( e.e_ndn );
 
 try_again:
        /* set cache mutex */
index 377952acba81923823c803099d138f2b1d2f7cc1..405ca65b692ccdc72967da6b4c6bd03fdd896e90 100644 (file)
@@ -36,7 +36,7 @@ dn2id_add(
        }
 
        dn = ch_strdup( dn );
-       dn_normalize_case( dn );
+       (void) dn_normalize_case( dn );
 
        key.dptr = dn;
        key.dsize = strlen( dn ) + 1;
@@ -71,7 +71,7 @@ dn2id(
 
        dn = ch_strdup( dn );
        Debug( LDAP_DEBUG_TRACE, "=> dn2id( \"%s\" )\n", dn, 0, 0 );
-       dn_normalize_case( dn );
+       (void) dn_normalize_case( dn );
 
        /* first check the cache */
        if ( (id = cache_find_entry_dn2id( be, &li->li_cache, dn )) != NOID ) {
@@ -133,7 +133,7 @@ dn2id_delete(
        }
 
        dn = ch_strdup( dn );
-       dn_normalize_case( dn );
+       (void) dn_normalize_case( dn );
        key.dptr = dn;
        key.dsize = strlen( dn ) + 1;
 
index 1b8d49bbcaa2eeae0c6676f3684d9d8dc5da56d3..e7a7f83d0348719332e3cb8b021cf3e94b9e29b4 100644 (file)
@@ -184,7 +184,8 @@ ldbm_back_modrdn(
                       "ldbm_back_modrdn: new parent requested...\n",
                       0, 0, 0 );
 
-               np_ndn = dn_normalize_case( ch_strdup( np_dn ) );
+               np_ndn = ch_strdup( np_dn );
+               (void) dn_normalize_case( np_ndn );
 
                /* newSuperior == oldParent?, if so ==> ERROR */
                /* newSuperior == entry being moved?, if so ==> ERROR */
@@ -250,7 +251,8 @@ ldbm_back_modrdn(
        build_new_dn( &new_dn, e->e_dn, new_parent_dn, newrdn ); 
 
 
-       new_ndn = dn_normalize_case( ch_strdup(new_dn) );
+       new_ndn = ch_strdup(new_dn);
+       (void) dn_normalize_case( new_ndn );
 
        Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n",
               new_ndn, 0, 0 );
@@ -357,7 +359,9 @@ ldbm_back_modrdn(
            
        }               
 
+#ifdef DNS_DN
        if ( dn_type( old_rdn ) == DN_X500 ) {
+#endif
 
                Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
                       0, 0, 0 );
@@ -414,6 +418,7 @@ ldbm_back_modrdn(
                               old_rdn_val, 0, 0 );
                }
        
+#ifdef DNS_DN
        } else {
                Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DNS DN\n",
                       0, 0, 0 );
@@ -427,6 +432,7 @@ ldbm_back_modrdn(
                goto return_results;
 
        }
+#endif
 
        /* modify memory copy of entry */
        if ( ldbm_modify_internal( be, conn, op, dn, &mod[0], e )
index cb1b9f4b29daaa0f23a935ba38bb81c9e1232fdd..08c20b8900f69865c105baa53946a3bd30153135 100644 (file)
@@ -238,7 +238,8 @@ pw2entry( Backend *be, struct passwd *pw, char *rdn )
        /* rdn attribute type should be a configuratable item */
        sprintf( buf, "uid=%s,%s", pw->pw_name, be->be_suffix[0] );
        e->e_dn = ch_strdup( buf );
-       e->e_ndn = dn_normalize_case( ch_strdup( buf ) );
+       e->e_ndn = ch_strdup( buf );
+       (void) dn_normalize_case( e->e_ndn );
 
        val.bv_val = pw->pw_name;
        val.bv_len = strlen( pw->pw_name );
index c09d4098e7218bfb47bef0561cf9abe38d9a4440..74459983bb888721c0b1d03b482fc1a72778e096 100644 (file)
@@ -36,7 +36,7 @@ do_bind(
        ber_int_t               version;
        ber_tag_t method;
        char            *mech;
-       char            *cdn, *ndn;
+       char            *dn, *ndn;
        ber_tag_t       tag;
        int                     rc = LDAP_SUCCESS;
        struct berval   cred;
@@ -44,7 +44,7 @@ do_bind(
 
        Debug( LDAP_DEBUG_TRACE, "do_bind\n", 0, 0, 0 );
 
-       cdn = NULL;
+       dn = NULL;
        ndn = NULL;
        mech = NULL;
        cred.bv_val = NULL;
@@ -98,7 +98,7 @@ do_bind(
         *      }
         */
 
-       tag = ber_scanf( ber, "{iat" /*}*/, &version, &cdn, &method );
+       tag = ber_scanf( ber, "{iat" /*}*/, &version, &dn, &method );
 
        if ( tag == LBER_ERROR ) {
                Debug( LDAP_DEBUG_ANY, "bind: ber_scanf failed\n", 0, 0, 0 );
@@ -108,6 +108,15 @@ do_bind(
                goto cleanup;
        }
 
+       ndn = ch_strdup( dn );
+
+       if ( dn_normalize_case( ndn ) == NULL ) {
+               Debug( LDAP_DEBUG_ANY, "bind: invalid dn (%s)\n", dn, 0, 0 );
+               send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
+                   "invalid DN", NULL, NULL );
+               goto cleanup;
+       }
+
        op->o_protocol = version;
 
        if( method != LDAP_AUTH_SASL ) {
@@ -145,14 +154,12 @@ do_bind(
 
        if( method == LDAP_AUTH_SASL ) {
                Debug( LDAP_DEBUG_TRACE, "do_sasl_bind: dn (%s) mech %s\n",
-                       cdn, mech, NULL );
+                       dn, mech, NULL );
        } else {
                Debug( LDAP_DEBUG_TRACE, "do_bind: version %d dn (%s) method %d\n",
-                       version, cdn, method );
+                       version, dn, method );
        }
 
-       ndn = dn_normalize_case( ch_strdup( cdn ) );
-
        Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d BIND dn=\"%s\" method=%d\n",
            op->o_connid, op->o_opid, ndn, method, 0 );
 
@@ -277,8 +284,8 @@ do_bind(
                if ( (*be->be_bind)( be, conn, op, ndn, method, mech, &cred, &edn ) == 0 ) {
                        ldap_pvt_thread_mutex_lock( &conn->c_mutex );
 
-                       conn->c_cdn = cdn;
-                       cdn = NULL;
+                       conn->c_cdn = dn;
+                       dn = NULL;
 
                        if(edn != NULL) {
                                conn->c_dn = edn;
@@ -306,8 +313,8 @@ do_bind(
        }
 
 cleanup:
-       if( cdn != NULL ) {
-               free( cdn );
+       if( dn != NULL ) {
+               free( dn );
        }
        if( ndn != NULL ) {
                free( ndn );
index c617be202827752a6b5c38c4275bd4731d2e86e0..f3a8ae9c1358663a0a1033608b94129b3ac7659e 100644 (file)
@@ -59,6 +59,15 @@ do_compare(
                return -1;
        }
 
+       if( dn_normalize_case( ndn ) == NULL ) {
+               Debug( LDAP_DEBUG_ANY, "do_compare: invalid dn (%s)\n", ndn, 0, 0 );
+               send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
+                   "invalid DN", NULL, NULL );
+               free( ndn );
+               ava_free( &ava, 0 );
+               return rc;
+       }
+
        if( ( rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
                free( ndn );
                ava_free( &ava, 0 );
@@ -71,8 +80,6 @@ do_compare(
        Debug( LDAP_DEBUG_ARGS, "do_compare: dn (%s) attr (%s) value (%s)\n",
            ndn, ava.ava_type, ava.ava_value.bv_val );
 
-       ndn = dn_normalize_case( ndn );
-
        Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d CMP dn=\"%s\" attr=\"%s\"\n",
            op->o_connid, op->o_opid, ndn, ava.ava_type, 0 );
 
index 3a9e7b4d61dd193ab94cb6132b3259d83c7f8c4e..e4d67fedde2e219a18faf43cd42232ae397fc327 100644 (file)
@@ -264,7 +264,16 @@ read_config( char *fname )
                                    fname, lineno, 0 );
                        } else {
                                be->be_root_dn = ch_strdup( cargv[1] );
-                               be->be_root_ndn = dn_normalize_case( ch_strdup( cargv[1] ) );
+                               be->be_root_ndn = ch_strdup( cargv[1] );
+
+                               if( dn_normalize_case( be->be_root_ndn ) == NULL ) {
+                                       free( be->be_root_dn );
+                                       free( be->be_root_ndn );
+                                       Debug( LDAP_DEBUG_ANY,
+"%s: line %d: rootdn DN is invalid\n",
+                                          fname, lineno, 0 );
+                                       return( 1 );
+                               }
                        }
 
                /* set super-secret magic database password */
@@ -465,7 +474,12 @@ read_config( char *fname )
                                    fname, lineno, 0 );
                        } else {
                                be->be_update_ndn = ch_strdup( cargv[1] );
-                               (void) dn_normalize_case( be->be_update_ndn );
+                               if( dn_normalize_case( be->be_update_ndn ) == NULL ) {
+                                       Debug( LDAP_DEBUG_ANY,
+"%s: line %d: updatedn DN is invalid\n",
+                                           fname, lineno, 0 );
+                                       return 1;
+                               }
                        }
 
                } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
index 4d85b2b62764c17f89be0c2741433165f2ed821d..5d45069fa91d2cb278f6f4b66ef80a145055da4d 100644 (file)
@@ -42,7 +42,8 @@ config_info( Connection *conn, Operation *op )
 
        e->e_attrs = NULL;
        e->e_dn = ch_strdup( SLAPD_CONFIG_DN );
-       e->e_ndn = dn_normalize_case( ch_strdup( SLAPD_CONFIG_DN ));
+       e->e_ndn = ch_strdup( SLAPD_CONFIG_DN );
+       (void) dn_normalize_case( e->e_ndn );
        e->e_private = NULL;
 
        for ( i = 0; i < nbackends; i++ ) {
index 036dde765f4a998cf8642098941b1f6e1c720f20..504fe2cbfe0c13a82f0ef354426eded7eeaadd23 100644 (file)
@@ -1022,7 +1022,8 @@ static int connection_op_activate( Connection *conn, Operation *op )
        arg->co_op->o_bind_in_progress = conn->c_bind_in_progress;
 
        arg->co_op->o_dn = ch_strdup( tmpdn != NULL ? tmpdn : "" );
-       arg->co_op->o_ndn = dn_normalize_case( ch_strdup( arg->co_op->o_dn ) );
+       arg->co_op->o_ndn = ch_strdup( arg->co_op->o_dn );
+       (void) dn_normalize_case( arg->co_op->o_ndn );
 
        arg->co_op->o_protocol = conn->c_protocol;
        arg->co_op->o_connid = conn->c_connid;
index 2b2d41cfaaad047528eb7a394ff88d42d1b86cf6..aa0bbc4b212d1728e8ab2d07e5eed3aa47a9a874 100644 (file)
@@ -52,6 +52,14 @@ do_delete(
                return -1;
        }
 
+       if(     dn_normalize_case( ndn ) == NULL ) {
+               Debug( LDAP_DEBUG_ANY, "do_delete: invalid dn (%s)\n", ndn, 0, 0 );
+               send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
+                   "invalid DN", NULL, NULL );
+               free( ndn );
+               return rc;
+       }
+
        if( ( rc = get_ctrls( conn, op, 1 ) ) != LDAP_SUCCESS ) {
                free( ndn );
                Debug( LDAP_DEBUG_ANY, "do_add: get_ctrls failed\n", 0, 0, 0 );
@@ -59,9 +67,6 @@ do_delete(
        } 
 
        Debug( LDAP_DEBUG_ARGS, "do_delete: dn (%s)\n", ndn, 0, 0 );
-
-       dn_normalize_case( ndn );
-
        Debug( LDAP_DEBUG_STATS, "DEL dn=\"%s\"\n", ndn, 0, 0 );
 
        /*
@@ -70,9 +75,9 @@ do_delete(
         * if we don't hold it.
         */
        if ( (be = select_backend( ndn )) == NULL ) {
-               free( ndn );
                send_ldap_result( conn, op, rc = LDAP_REFERRAL,
                        NULL, NULL, default_referral, NULL );
+               free( ndn );
                return rc;
        }
 
index b9e249711796b59544046a22c849fa3b35d102a1..a04cacfba999bd3e4085c6da7e21efae3078d610 100644 (file)
 
 #include "slap.h"
 
-#define B4TYPE         0
-#define INTYPE         1
-#define B4EQUAL                2
-#define B4VALUE                3
-#define INVALUE                4
-#define INQUOTEDVALUE  5
-#define B4SEPARATOR    6
+#define B4LEADTYPE             0
+#define B4TYPE                 1
+#define INTYPE                 2
+#define B4EQUAL                        3
+#define B4VALUE                        4
+#define INVALUE                        5
+#define INQUOTEDVALUE  6
+#define B4SEPARATOR            7
 
 /*
  * dn_normalize - put dn into a canonical format.  the dn is
- * normalized in place, as well as returned.
+ * normalized in place, as well as returned if valid.
  */
 
 char *
@@ -30,12 +31,11 @@ dn_normalize( char *dn )
        char    *d, *s;
        int     state, gotesc;
 
-       /* Debug( LDAP_DEBUG_TRACE, "=> dn_normalize \"%s\"\n", dn, 0, 0 ); */
-
        gotesc = 0;
-       state = B4TYPE;
+       state = B4LEADTYPE;
        for ( d = s = dn; *s; s++ ) {
                switch ( state ) {
+               case B4LEADTYPE:
                case B4TYPE:
                        if ( ! SPACE( *s ) ) {
                                state = INTYPE;
@@ -59,6 +59,7 @@ dn_normalize( char *dn )
                        } else if ( ! SPACE( *s ) ) {
                                /* not a valid dn - but what can we do here? */
                                *d++ = *s;
+                               dn = NULL;
                        }
                        break;
                case B4VALUE:
@@ -106,6 +107,7 @@ dn_normalize( char *dn )
                        }
                        break;
                default:
+                       dn = NULL;
                        Debug( LDAP_DEBUG_ANY,
                            "dn_normalize - unknown state %d\n", state, 0, 0 );
                        break;
@@ -118,24 +120,40 @@ dn_normalize( char *dn )
        }
        *d = '\0';
 
-       /* Debug( LDAP_DEBUG_TRACE, "<= dn_normalize \"%s\"\n", dn, 0, 0 ); */
+       if( gotesc ) {
+               /* shouldn't be left in escape */
+               dn = NULL;
+       }
+
+       /* check end state */
+       switch( state ) {
+       case B4LEADTYPE:        /* looking for first type */
+       case B4SEPARATOR:       /* looking for separator */
+       case INVALUE:           /* inside value */
+               break;
+       default:
+               dn = NULL;
+       }
+
        return( dn );
 }
 
 /*
  * dn_normalize_case - put dn into a canonical form suitable for storing
  * in a hash database.  this involves normalizing the case as well as
- * the format.  the dn is normalized in place as well as returned.
+ * the format.  the dn is normalized in place as well as returned if valid.
  */
 
 char *
 dn_normalize_case( char *dn )
 {
+       str2upper( dn );
+
        /* normalize format */
-       dn_normalize( dn );
+       dn = dn_normalize( dn );
 
        /* and upper case it */
-       return( str2upper( dn ) );
+       return( dn );
 }
 
 /*
@@ -239,6 +257,7 @@ char * dn_rdn(
 
        dn = ch_strdup( dn );
 
+#ifdef DNS_DN
        /*
         * no =, assume it is a dns name, like blah@some.domain.name
         * if the blah@ part is there, return some.domain.name.  if
@@ -253,6 +272,7 @@ char * dn_rdn(
                *s = '\0';
                return( dn );
        }
+#endif
 
        /*
         * else assume it is an X.500-style name, which looks like
@@ -312,6 +332,7 @@ dn_issuffix(
        return( strcmp( dn + dnlen - suffixlen, suffix ) == 0 );
 }
 
+#ifdef DNS_DN
 /*
  * dn_type - tells whether the given dn is an X.500 thing or DNS thing
  * returns (defined in slap.h):        DN_DNS          dns-style thing
@@ -323,6 +344,7 @@ dn_type( char *dn )
 {
        return( strchr( dn, '=' ) == NULL ? DN_DNS : DN_X500 );
 }
+#endif
 
 char *
 str2upper( char *str )
@@ -386,7 +408,7 @@ get_next_substring( char * s, char d )
            
                s++;
            
-       }/* while ( *s && SPACE(*s) ) */
+       }
        
        /* Copy word */
 
@@ -398,13 +420,13 @@ get_next_substring( char * s, char d )
 
                *str++ = *s++;
            
-       }/* while ( *s && (*s != d) ) */
+       }
        
        *str = '\0';
        
        return r;
        
-}/* char * get_word() */
+}
 
 
 /* rdn_attr_type:
@@ -421,7 +443,7 @@ char * rdn_attr_type( char * s )
 
        return get_next_substring( s, '=' );
 
-}/* char * rdn_attr_type() */
+}
 
 
 /* rdn_attr_value:
@@ -443,11 +465,18 @@ rdn_attr_value( char * rdn )
 
                return get_next_substring(++str, '\0');
 
-       }/* if ( (str = strpbrk( rdn, "=" )) != NULL ) */
+       }
 
        return NULL;
 
-}/* char * rdn_attr_value() */
+}
+
+
+int rdn_validate( const char * rdn )
+{
+       /* just a simple check for now */
+       return strchr( rdn, '=' ) != NULL;
+}
 
 
 /* build_new_dn:
@@ -471,12 +500,15 @@ build_new_dn( char ** new_dn, char *e_dn, char * p_dn, char * newrdn )
     
     *new_dn = (char *) ch_malloc( strlen( p_dn ) + strlen( newrdn ) + 3 );
 
+#ifdef DNS_DN
     if ( dn_type( e_dn ) == DN_X500 ) {
+#endif
 
        strcpy( *new_dn, newrdn );
        strcat( *new_dn, "," );
        strcat( *new_dn, p_dn );
 
+#ifdef DNS_DN
     } else {
 
        char    *s;
@@ -494,12 +526,13 @@ build_new_dn( char ** new_dn, char *e_dn, char * p_dn, char * newrdn )
                sep[1] = '\0';
                strcat( *new_dn, sep );
 
-           }/* if ( (s = strpbrk( dn, ".@" )) != NULL ) */
+           }
 
-       }/* if ( *s != '.' && *s != '@' ) */
+       }
 
        strcat( *new_dn, p_dn );
 
-    }/* if ( dn_type( e_dn ) == DN_X500 ) {}else */
+    }
+#endif
     
-}/* void build_new_dn() */
+}
index 563e01cec113c893c12e15919146340f9606fa57..e0465230e95cb4f072292a9d574c1b7737801ad9 100644 (file)
@@ -110,7 +110,8 @@ str2entry( char     *s )
                                    e->e_id, e->e_ndn, value );
                                free( e->e_ndn );
                        }
-                       e->e_ndn = dn_normalize_case( ch_strdup( value ) );
+                       e->e_ndn = ch_strdup( value );
+                       (void) dn_normalize_case( e->e_ndn );
                        continue;
                }
 
index 016033742c4f869b2816773a770176d9460da009..2bf8ce5a5c21012a62299c0db94a60e6dc19b185 100644 (file)
@@ -70,7 +70,7 @@ do_modify(
         */
 
        if ( ber_scanf( op->o_ber, "{a" /*}*/, &ndn ) == LBER_ERROR ) {
-               Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
+               Debug( LDAP_DEBUG_ANY, "do_modify: ber_scanf failed\n", 0, 0, 0 );
                send_ldap_disconnect( conn, op,
                        LDAP_PROTOCOL_ERROR, "decoding error" );
                return -1;
@@ -78,7 +78,13 @@ do_modify(
 
        Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", ndn, 0, 0 );
 
-       (void) dn_normalize_case( ndn );
+       if(     dn_normalize_case( ndn ) == NULL ) {
+               Debug( LDAP_DEBUG_ANY, "do_modify: invalid dn (%s)\n", ndn, 0, 0 );
+               send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
+                   "invalid DN", NULL, NULL );
+               free( ndn );
+               return rc;
+       }
 
        /* collect modifications & save for later */
        modlist = NULL;
index 59ce22cdeabddeb812a12eae7602bdea3264a63c..2f559de27d539ba262941f49c4aa5be676c92a8d 100644 (file)
@@ -77,6 +77,24 @@ do_modrdn(
                return -1;
        }
 
+       if( dn_normalize_case( ndn ) == NULL ) {
+               Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid dn (%s)\n", ndn, 0, 0 );
+               send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
+                   "invalid DN", NULL, NULL );
+               free( ndn );
+               free( newrdn );
+               return rc;
+       }
+
+       if( !rdn_validate( newrdn ) ) {
+               Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid rdn (%s)\n", newrdn, 0, 0 );
+               send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
+                   "invalid RDN", NULL, NULL );
+               free( ndn );
+               free( newrdn );
+               return rc;
+       }
+
        /* Check for newSuperior parameter, if present scan it */
 
        if ( ber_peek_tag( op->o_ber, &length ) == LDAP_TAG_NEWSUPERIOR ) {
@@ -110,7 +128,18 @@ do_modrdn(
                        send_ldap_disconnect( conn, op,
                                LDAP_PROTOCOL_ERROR, "decoding error" );
                    return -1;
+               }
+
+               nnewSuperior = ch_strdup( newSuperior );
 
+               if( dn_normalize_case( nnewSuperior ) == NULL ) {
+                       Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid new superior (%s)\n",
+                               newSuperior, 0, 0 );
+                       send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
+                               "invalid (new superior) DN", NULL, NULL );
+                       free( ndn );
+                       free( newrdn );
+                       return rc;
                }
 
        }
@@ -124,6 +153,7 @@ do_modrdn(
                free( ndn );
                free( newrdn ); 
                free( newSuperior );
+               free( nnewSuperior );
                Debug( LDAP_DEBUG_ANY, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
                send_ldap_disconnect( conn, op,
                                LDAP_PROTOCOL_ERROR, "decoding error" );
@@ -138,37 +168,6 @@ do_modrdn(
                return rc;
        } 
 
-       if( newSuperior != NULL ) {
-               /* GET BACKEND FOR NEW SUPERIOR */
-
-               nnewSuperior = strdup( newSuperior );
-               dn_normalize_case( nnewSuperior );
-
-               if ( (newSuperior_be = select_backend( nnewSuperior )) 
-                    == NULL ) {
-                   
-                       /* We do not have a backend for newSuperior so we send
-                        * a referral.
-                        * XXX: We may need to do something else here, not sure
-                        * what though.
-                        */
-
-                       Debug( LDAP_DEBUG_ARGS,
-                              "do_modrdn: cant find backend for=(%s)\n",
-                              newSuperior, 0, 0 );
-                       
-                       free( ndn );
-                       free( newrdn );
-                       free( newSuperior );
-                       free( nnewSuperior );
-                       send_ldap_result( conn, op, LDAP_REFERRAL,
-                               NULL, NULL, default_referral, NULL );
-                       return 0;
-               }
-       }
-
-       dn_normalize_case( ndn );
-
        Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MODRDN dn=\"%s\"\n",
            op->o_connid, op->o_opid, ndn, 0, 0 );
 
@@ -188,25 +187,27 @@ do_modrdn(
                return rc;
        }
 
+
        /* Make sure that the entry being changed and the newSuperior are in 
         * the same backend, otherwise we return an error.
         */
+       if( newSuperior != NULL ) {
+               newSuperior_be = select_backend( nnewSuperior );
 
-       if ( (newSuperior_be != NULL) && ( be != newSuperior_be) ) {
+               if ( newSuperior != be ) {
+                       /* newSuperior is in same backend */
+                       rc = LDAP_AFFECTS_MULTIPLE_DSAS;
 
-               Debug( LDAP_DEBUG_ANY, "dn=(%s), newSuperior=(%s)\n", ndn,
-                      newSuperior, 0 );
-               
-               free( ndn );
-               free( newrdn );
-               free( newSuperior );
-               free( nnewSuperior );
-               
-               send_ldap_result( conn, op, rc = LDAP_AFFECTS_MULTIPLE_DSAS,
-                       NULL, NULL, NULL, NULL );
-           
-               return rc;
+                       send_ldap_result( conn, op, rc,
+                               NULL, NULL, NULL, NULL );
 
+                       free( ndn );
+                       free( newrdn );
+                       free( newSuperior );
+                       free( nnewSuperior );
+
+                       return rc;
+               }
        }
 
        /*
index dff72f9690e8daaceae5d550f4025002310b3f62..891cbab2b10cb1d46c068583326d66a39dc3b1bd 100644 (file)
@@ -46,7 +46,8 @@ monitor_info( Connection *conn, Operation *op )
        /* initialize reader/writer lock */
        e->e_attrs = NULL;
        e->e_dn = ch_strdup( SLAPD_MONITOR_DN );
-       e->e_ndn = dn_normalize_case( ch_strdup(SLAPD_MONITOR_DN) );
+       e->e_ndn = ch_strdup(SLAPD_MONITOR_DN);
+       (void) dn_normalize_case( e->e_ndn );
        e->e_private = NULL;
 
        val.bv_val = (char *) Versionstr;
index 3e90384d7e3cccf50d6d40f32c3ecb0fce305760..1abab8b82a0fd9799fe7271145d5fea757ab7f9f 100644 (file)
@@ -176,9 +176,12 @@ char * dn_normalize_case LDAP_P(( char *dn ));
 char * dn_parent LDAP_P(( Backend *be, char *dn ));
 char * dn_rdn LDAP_P(( Backend *be, char *dn ));
 int dn_issuffix LDAP_P(( char *dn, char *suffix ));
+#ifdef DNS_DN
 int dn_type LDAP_P(( char *dn ));
+#endif
 char * str2upper LDAP_P(( char *str ));
 char * str2lower LDAP_P(( char *str ));
+int rdn_validate LDAP_P(( const char* str ));
 char * rdn_attr_value LDAP_P(( char * rdn ));
 char * rdn_attr_type LDAP_P(( char * rdn ));
 void build_new_dn LDAP_P(( char ** new_dn, char *e_dn, char * p_dn,
index 25d5f7ddbfdd9ba9bf1353bc52d7f2960ddfa29e..700b4bd489a3df7d1e38b708453d5c315988fc12 100644 (file)
@@ -32,7 +32,8 @@ root_dse_info( Connection *conn, Operation *op, char **attrs, int attrsonly )
 
        e->e_attrs = NULL;
        e->e_dn = ch_strdup( LDAP_ROOT_DSE );
-       e->e_ndn = dn_normalize_case( ch_strdup( LDAP_ROOT_DSE ));
+       e->e_ndn = ch_strdup( LDAP_ROOT_DSE );
+       (void) dn_normalize_case( e->e_ndn );
        e->e_private = NULL;
 
        for ( i = 0; i < nbackends; i++ ) {
index e2e2294d56093413c6d85a73b8ca5a6f34f5737d..ec67cc3905811be854637179f45500ce08ffe155 100644 (file)
@@ -1109,7 +1109,8 @@ schema_info( Connection *conn, Operation *op, char **attrs, int attrsonly )
 
        e->e_attrs = NULL;
        e->e_dn = ch_strdup( SLAPD_SCHEMA_DN );
-       e->e_ndn = dn_normalize_case( ch_strdup( SLAPD_SCHEMA_DN ));
+       e->e_ndn = ch_strdup( SLAPD_SCHEMA_DN );
+       (void) dn_normalize_case( e->e_ndn );
        e->e_private = NULL;
 
        val.bv_val = ch_strdup( "top" );
index 92a34841bf0914a9578c09fa80dd097a72a367a6..ef38c6a59184692bdc719a91034ed82d1c89175f 100644 (file)
@@ -105,7 +105,12 @@ do_search(
                goto return_results;
        }
 
-       (void) dn_normalize_case( base );
+       if( dn_normalize_case( base ) == NULL ) {
+               send_ldap_result( conn, op, LDAP_INVALID_DN_SYNTAX,
+                       NULL, "invalid DN", NULL, NULL );
+               rc = -1;
+               goto return_results;
+       }
 
        Debug( LDAP_DEBUG_ARGS, "SRCH \"%s\" %d %d", base, scope, deref );
        Debug( LDAP_DEBUG_ARGS, "    %d %d %d\n", sizelimit, timelimit,
index aa558c63738b313eb4c97dc1799dbcd0367d25b3..625890574f822cbf0d86540998d268ef9427a7c2 100644 (file)
@@ -45,8 +45,10 @@ LDAP_BEGIN_DECL
  */
 #define LDAP_MOD_SOFTADD       0x1000
 
+#ifdef DNS_DN
 #define DN_DNS 0
 #define DN_X500        1
+#endif
 
 #define ON     1
 #define OFF    (-1)
index 1aac3017ea7a219afef80c5995bcda7baaec3bc6..61113a3462db65b0a7f856b9995082301fc2836e 100644 (file)
@@ -177,7 +177,8 @@ main( int argc, char **argv )
                                        fprintf( stderr, "entry %ld has no dn\n",
                                            id );
                                } else {
-                                       key.dptr = dn_normalize_case( val );
+                                       (void) dn_normalize_case( val );
+                                       key.dptr = val;
                                        key.dsize = strlen( val ) + 1;
                                        data.dptr = (char *) &id;
                                        data.dsize = sizeof(ID);
@@ -262,15 +263,15 @@ main( int argc, char **argv )
                                            == NULL ) {
                                                pid = 0;
                                        } else {
-                                               key.dptr =
-                                                   dn_normalize_case( dn );
+                                               (void) dn_normalize_case( dn );
+                                               key.dptr = dn;
                                                key.dsize = strlen( dn ) + 1;
 
                                                data = ldbm_fetch( db->dbc_db,
                                                    key );
                                                free( dn );
                                                if ( data.dptr == NULL ) {
-                                                       dn_normalize_case( val );
+                                                       (void) dn_normalize_case( val );
                                                        if ( ! be_issuffix( be,
                                                            val ) ) {
        Debug( LDAP_DEBUG_PARSE, "no parent \"%s\" of \"%s\"\n", dn, val, 0 );
index 3f43bf66f9a774f2f3e16867e133054c55077b78..6eb25ea47342c20f4e813ade5a906dac90815bf8 100644 (file)
@@ -179,7 +179,8 @@ main( int argc, char **argv )
                                        fprintf( stderr, "entry %ld has no dn\n",
                                            id );
                                } else {
-                                       key.dptr = dn_normalize_case( val );
+                                       (void) dn_normalize_case( val );
+                                       key.dptr = val;
                                        key.dsize = strlen( val ) + 1;
                                        data.dptr = (char *) &id;
                                        data.dsize = sizeof(ID);
@@ -264,15 +265,15 @@ main( int argc, char **argv )
                                            == NULL ) {
                                                pid = 0;
                                        } else {
-                                               key.dptr =
-                                                   dn_normalize_case( dn );
+                                               (void) dn_normalize_case( dn );
+                                               key.dptr = dn;
                                                key.dsize = strlen( dn ) + 1;
 
                                                data = ldbm_fetch( db->dbc_db,
                                                    key );
                                                free( dn );
                                                if ( data.dptr == NULL ) {
-                                                       dn_normalize_case( val );
+                                                       (void) dn_normalize_case( val );
                                                        if ( ! be_issuffix( be,
                                                            val ) ) {
        Debug( LDAP_DEBUG_PARSE, "no parent \"%s\" of \"%s\"\n", dn, val, 0 );