]> git.sur5r.net Git - openldap/commitdiff
fix several schema checking issues; add rename specific statement for entry renaming...
authorPierangelo Masarati <ando@openldap.org>
Mon, 17 Jan 2005 19:32:28 +0000 (19:32 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 17 Jan 2005 19:32:28 +0000 (19:32 +0000)
12 files changed:
servers/slapd/back-sql/add.c
servers/slapd/back-sql/back-sql.h
servers/slapd/back-sql/bind.c
servers/slapd/back-sql/compare.c
servers/slapd/back-sql/config.c
servers/slapd/back-sql/init.c
servers/slapd/back-sql/modify.c
servers/slapd/back-sql/modrdn.c
servers/slapd/back-sql/operational.c
servers/slapd/back-sql/proto-sql.h
servers/slapd/back-sql/search.c
servers/slapd/back-sql/util.c

index 96a9ef10df6ed6e72c510d474b9e8ad64aa53388..2453443d87b43215528bca67830cc661a24f3e63 100644 (file)
  * - operational attributes
  * - empty attributes
  */
+#define backsql_opattr_skip(ad) \
+       (is_at_operational( (ad)->ad_type ) && (ad) != slap_schema.si_ad_ref )
 #define        backsql_attr_skip(ad, vals) \
        ( \
                ( (ad) == slap_schema.si_ad_objectClass \
                                && (vals) && BER_BVISNULL( &((vals)[ 1 ]) ) ) \
-               || is_at_operational( (ad)->ad_type ) \
+               || backsql_opattr_skip( (ad) ) \
                || ( (vals) && BER_BVISNULL( &((vals)[ 0 ]) ) ) \
        )
 
@@ -316,7 +318,7 @@ backsql_modify_internal(
 #if 0
                /* NOTE: some day we'll have to pass 
                 * the normalized values as well */
-               BerVarray               nvalues;
+               BerVarray               sm_nvalues;
 #endif
                backsql_at_map_rec      *at = NULL;
                struct berval           *at_val;
@@ -951,7 +953,7 @@ backsql_add( Operation *op, SlapReply *rs )
        unsigned long           new_keyval = 0;
        RETCODE                 rc;
        backsql_oc_map_rec      *oc = NULL;
-       backsql_srch_info       bsi;
+       backsql_srch_info       bsi = { 0 };
        Entry                   p = { 0 }, *e = NULL;
        Attribute               *at,
                                *at_objectClass = NULL;
index e91736288b87df440a54f999be9b5687bb417f27..6c79a7b0c4d2406bf38ff9163fe31641dee55794 100644 (file)
@@ -474,6 +474,7 @@ typedef struct backsql_info {
                        *sql_at_query;
        char            *sql_insentry_stmt,
                        *sql_delentry_stmt,
+                       *sql_renentry_stmt,
                        *sql_delobjclasses_stmt,
                        *sql_delreferrals_stmt;
        char            *sql_id_query;
index 3ce75c1f08add6db532491bae69e0fb4cc1961e4..5817d06af60eaaa9b1fc0dea4fd214ef3385a267 100644 (file)
@@ -34,7 +34,7 @@ backsql_bind( Operation *op, SlapReply *rs )
        SQLHDBC                 dbh = SQL_NULL_HDBC;
        Entry                   e = { 0 };
        Attribute               *a;
-       backsql_srch_info       bsi;
+       backsql_srch_info       bsi = { 0 };
        AttributeName           anlist[2];
        int                     rc;
  
@@ -101,10 +101,12 @@ backsql_bind( Operation *op, SlapReply *rs )
        }
 
 error_return:;
-       (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
+       if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
+               (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
+       }
 
-       if ( bsi.bsi_e ) {
-               entry_clean( bsi.bsi_e );
+       if ( !BER_BVISNULL( &e.e_nname ) ) {
+               entry_clean( &e );
        }
 
        if ( bsi.bsi_attrs != NULL ) {
index 4dfb365a0bbca0f49b7171d709ce3dc7af065550..3a87819622cc2122ac8c2773799a50495227cb02 100644 (file)
@@ -34,7 +34,7 @@ backsql_compare( Operation *op, SlapReply *rs )
        SQLHDBC                 dbh = SQL_NULL_HDBC;
        Entry                   e = { 0 };
        Attribute               *a = NULL;
-       backsql_srch_info       bsi;
+       backsql_srch_info       bsi = { 0 };
        int                     rc;
        AttributeName           anlist[2],
                                *anlistp = NULL;
@@ -174,10 +174,12 @@ return_results:;
                rs->sr_ref = NULL;
        }
 
-       (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
+       if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
+               (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
+       }
 
-       if ( bsi.bsi_e ) {
-               entry_clean( bsi.bsi_e );
+       if ( !BER_BVISNULL( &e.e_nname ) ) {
+               entry_clean( &e );
        }
 
        if ( bsi.bsi_attrs != NULL ) {
index c45c70716eb84d2bbf2f6707d935a09371cd959c..51d50e6a6a5bf201979ad8ef0f8a949c2ff6303b 100644 (file)
@@ -291,6 +291,21 @@ backsql_db_config(
                Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
                        "delentry_stmt=%s\n", bi->sql_delentry_stmt, 0, 0 );
 
+       } else if ( !strcasecmp( argv[ 0 ], "renentry_stmt" ) ||
+                       !strcasecmp( argv[ 0 ], "renentry_query" ) )
+       {
+               if ( argc < 2 ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "<==backsql_db_config (%s line %d): "
+                               "missing SQL statement "
+                               "in \"renentry_stmt\" directive\n",
+                               fname, lineno, 0 );
+                       return 1;
+               }
+               bi->sql_renentry_stmt = ch_strdup( argv[ 1 ] );
+               Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
+                       "renentry_stmt=%s\n", bi->sql_renentry_stmt, 0, 0 );
+
        } else if ( !strcasecmp( argv[ 0 ], "delobjclasses_stmt" ) ||
                        !strcasecmp( argv[ 0 ], "delobjclasses_query" ) )
        {
index 3ebdfea0a93e67154ca3e73eed0d8e828253482b..11aa1ffd38327e72a76cb7dbfde25923f59fa17e 100644 (file)
@@ -47,6 +47,12 @@ sql_back_initialize(
 
        bi->bi_controls = controls;
 
+       bi->bi_flags |=
+#if 0
+               SLAP_BFLAG_INCREMENT |
+#endif
+               SLAP_BFLAG_REFERRALS;
+
        Debug( LDAP_DEBUG_TRACE,"==>sql_back_initialize()\n", 0, 0, 0 );
        
        bi->bi_db_init = backsql_db_init;
@@ -137,6 +143,7 @@ backsql_db_destroy(
        free( bi->sql_at_query );
        free( bi->sql_insentry_stmt );
        free( bi->sql_delentry_stmt );
+       free( bi->sql_renentry_stmt );
        free( bi->sql_delobjclasses_stmt );
        free( bi->sql_delreferrals_stmt );
 
@@ -375,6 +382,17 @@ backsql_db_open(
                bi->sql_delentry_stmt = ch_strdup( backsql_def_delentry_stmt );
        }
 
+       if ( bi->sql_renentry_stmt == NULL ) {
+               Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
+                       "entry deletion SQL statement not specified "
+                       "(use \"renentry_stmt\" directive in slapd.conf)\n",
+                       0, 0, 0 );
+               Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
+                       "setting \"%s\" by default\n",
+                       backsql_def_renentry_stmt, 0, 0 );
+               bi->sql_renentry_stmt = ch_strdup( backsql_def_renentry_stmt );
+       }
+
        if ( bi->sql_delobjclasses_stmt == NULL ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
                        "objclasses deletion SQL statement not specified "
index ac9a197155cc3f25fbcbcd373244654c509b6ce9..b4de8641990fdde3e3eaf4d1e460e7b2cc959c54 100644 (file)
@@ -143,7 +143,6 @@ backsql_modify( Operation *op, SlapReply *rs )
                goto done;
        }
 
-       /* FIXME: need the whole entry (ITS#3480) */
        if ( !acl_check_modlist( op, &m, op->oq_modify.rs_modlist ) ) {
                rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
                e = &m;
@@ -153,7 +152,36 @@ backsql_modify( Operation *op, SlapReply *rs )
        rs->sr_err = backsql_modify_internal( op, rs, dbh, oc,
                        &bsi.bsi_base_id,
                        op->oq_modify.rs_modlist );
+       if ( rs->sr_err != LDAP_SUCCESS ) {
+               e = &m;
+               goto do_transact;
+       }
+
+       if ( global_schemacheck ) {
+               char            textbuf[ SLAP_TEXT_BUFLEN ] = { '\0' };
 
+               entry_clean( &m );
+
+               bsi.bsi_e = &m;
+               rs->sr_err = backsql_id2entry( &bsi, &bsi.bsi_base_id );
+               if ( rs->sr_err != LDAP_SUCCESS ) {
+                       e = &m;
+                       goto do_transact;
+               }
+
+               rs->sr_err = entry_schema_check( op->o_bd, &m,
+                               NULL,
+                               &rs->sr_text, textbuf, sizeof( textbuf ) );
+               if ( rs->sr_err != LDAP_SUCCESS ) {
+                       Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
+                               "entry failed schema check -- aborting\n",
+                               m.e_name.bv_val, 0, 0 );
+                       e = NULL;
+                       goto do_transact;
+               }
+       }
+
+do_transact:;
        /*
         * Commit only if all operations succeed
         */
@@ -182,10 +210,12 @@ done:;
 
        send_ldap_result( op, rs );
 
-       (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
+       if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
+               (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
+       }
 
-       if ( bsi.bsi_e != NULL ) {
-               entry_clean( bsi.bsi_e );
+       if ( !BER_BVISNULL( &m.e_nname ) ) {
+               entry_clean( &m );
        }
 
        if ( bsi.bsi_attrs != NULL ) {
index a722e9f39882326423bc703617c188de3c1cadc5..d5aa697f8ce4ebef38d806b4132f9b052cebde57 100644 (file)
@@ -291,32 +291,11 @@ backsql_modrdn( Operation *op, SlapReply *rs )
        Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): new entry dn is \"%s\"\n",
                        new_dn.bv_val, 0, 0 );
 
-       Debug(  LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
-               "executing delentry_stmt\n", 0, 0, 0 );
-
-       rc = backsql_Prepare( dbh, &sth, bi->sql_delentry_stmt, 0 );
-       if ( rc != SQL_SUCCESS ) {
-               Debug( LDAP_DEBUG_TRACE,
-                       "   backsql_modrdn(): "
-                       "error preparing delentry_stmt\n", 0, 0, 0 );
-               backsql_PrintErrors( bi->sql_db_env, dbh, 
-                               sth, rc );
-
-               rs->sr_text = "SQL-backend error";
-               rs->sr_err = LDAP_OTHER;
-               e = NULL;
-               goto done;
-       }
-
-       rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT, &e_id.eid_id );
-       if ( rc != SQL_SUCCESS ) {
-               Debug( LDAP_DEBUG_TRACE,
-                       "   backsql_delete(): "
-                       "error binding entry ID parameter "
-                       "for objectClass %s\n",
-                       oc->bom_oc->soc_cname.bv_val, 0, 0 );
-               backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
+       realnew_dn = new_dn;
+       if ( backsql_api_dn2odbc( op, rs, &realnew_dn ) ) {
+               Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(\"%s\"): "
+                       "backsql_api_dn2odbc(\"%s\") failed\n", 
+                       op->o_req_dn.bv_val, realnew_dn.bv_val, 0 );
                SQLFreeStmt( sth, SQL_DROP );
 
                rs->sr_text = "SQL-backend error";
@@ -325,29 +304,14 @@ backsql_modrdn( Operation *op, SlapReply *rs )
                goto done;
        }
 
-       rc = SQLExecute( sth );
-       if ( rc != SQL_SUCCESS ) {
-               Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
-                       "failed to delete record from ldap_entries\n",
-                       0, 0, 0 );
-               backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
-               SQLFreeStmt( sth, SQL_DROP );
-               rs->sr_err = LDAP_OTHER;
-               rs->sr_text = "SQL-backend error";
-               e = NULL;
-               goto done;
-       }
-
-       SQLFreeStmt( sth, SQL_DROP );
-
        Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
-               "executing insentry_stmt\n", 0, 0, 0 );
+               "executing renentry_stmt\n", 0, 0, 0 );
 
-       rc = backsql_Prepare( dbh, &sth, bi->sql_insentry_stmt, 0 );
+       rc = backsql_Prepare( dbh, &sth, bi->sql_renentry_stmt, 0 );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
                        "   backsql_modrdn(): "
-                       "error preparing insentry_stmt\n", 0, 0, 0 );
+                       "error preparing renentry_stmt\n", 0, 0, 0 );
                backsql_PrintErrors( bi->sql_db_env, dbh, 
                                sth, rc );
 
@@ -357,19 +321,6 @@ backsql_modrdn( Operation *op, SlapReply *rs )
                goto done;
        }
 
-       realnew_dn = new_dn;
-       if ( backsql_api_dn2odbc( op, rs, &realnew_dn ) ) {
-               Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(\"%s\"): "
-                       "backsql_api_dn2odbc(\"%s\") failed\n", 
-                       op->o_req_dn.bv_val, realnew_dn.bv_val, 0 );
-               SQLFreeStmt( sth, SQL_DROP );
-
-               rs->sr_text = "SQL-backend error";
-               rs->sr_err = LDAP_OTHER;
-               e = NULL;
-               goto done;
-       }
-
        rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &realnew_dn );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
@@ -386,11 +337,11 @@ backsql_modrdn( Operation *op, SlapReply *rs )
                goto done;
        }
 
-       rc = backsql_BindParamInt( sth, 2, SQL_PARAM_INPUT, &e_id.eid_oc_id );
+       rc = backsql_BindParamID( sth, 2, SQL_PARAM_INPUT, &n_id.eid_id );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
                        "   backsql_add_attr(): "
-                       "error binding objectClass ID parameter for objectClass %s\n",
+                       "error binding parent ID parameter for objectClass %s\n",
                        oc->bom_oc->soc_cname.bv_val, 0, 0 );
                backsql_PrintErrors( bi->sql_db_env, dbh, 
                        sth, rc );
@@ -402,11 +353,11 @@ backsql_modrdn( Operation *op, SlapReply *rs )
                goto done;
        }
 
-       rc = backsql_BindParamID( sth, 3, SQL_PARAM_INPUT, &n_id.eid_id );
+       rc = backsql_BindParamID( sth, 3, SQL_PARAM_INPUT, &e_id.eid_keyval );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
                        "   backsql_add_attr(): "
-                       "error binding parent ID parameter for objectClass %s\n",
+                       "error binding entry ID parameter for objectClass %s\n",
                        oc->bom_oc->soc_cname.bv_val, 0, 0 );
                backsql_PrintErrors( bi->sql_db_env, dbh, 
                        sth, rc );
@@ -418,11 +369,11 @@ backsql_modrdn( Operation *op, SlapReply *rs )
                goto done;
        }
 
-       rc = backsql_BindParamID( sth, 4, SQL_PARAM_INPUT, &e_id.eid_keyval );
+       rc = backsql_BindParamID( sth, 4, SQL_PARAM_INPUT, &e_id.eid_id );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
                        "   backsql_add_attr(): "
-                       "error binding entry ID parameter for objectClass %s\n",
+                       "error binding ID parameter for objectClass %s\n",
                        oc->bom_oc->soc_cname.bv_val, 0, 0 );
                backsql_PrintErrors( bi->sql_db_env, dbh, 
                        sth, rc );
@@ -437,7 +388,7 @@ backsql_modrdn( Operation *op, SlapReply *rs )
        rc = SQLExecute( sth );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
-                       "could not insert ldap_entries record\n", 0, 0, 0 );
+                       "could not rename ldap_entries record\n", 0, 0, 0 );
                backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
                SQLFreeStmt( sth, SQL_DROP );
                rs->sr_err = LDAP_OTHER;
@@ -490,7 +441,34 @@ backsql_modrdn( Operation *op, SlapReply *rs )
 
        oc = backsql_id2oc( bi, e_id.eid_oc_id );
        rs->sr_err = backsql_modify_internal( op, rs, dbh, oc, &e_id, mod );
-       e = &r;
+       if ( rs->sr_err != LDAP_SUCCESS ) {
+               e = &r;
+               goto done;
+       }
+
+       if ( global_schemacheck ) {
+               char            textbuf[ SLAP_TEXT_BUFLEN ] = { '\0' };
+
+               entry_clean( &r );
+
+               bsi.bsi_e = &r;
+               rs->sr_err = backsql_id2entry( &bsi, &e_id );
+               if ( rs->sr_err != LDAP_SUCCESS ) {
+                       e = &r;
+                       goto done;
+               }
+
+               rs->sr_err = entry_schema_check( op->o_bd, &r,
+                               NULL,
+                               &rs->sr_text, textbuf, sizeof( textbuf ) );
+               if ( rs->sr_err != LDAP_SUCCESS ) {
+                       Debug( LDAP_DEBUG_TRACE, "   backsql_add(\"%s\"): "
+                               "entry failed schema check -- aborting\n",
+                               r.e_name.bv_val, 0, 0 );
+                       e = NULL;
+                       goto done;
+               }
+       }
 
 done:;
 #ifdef SLAP_ACL_HONOR_DISCLOSE
index d997703d98bc33461a8e6f5b96cd982f486ebf2b..e0f4af3b1ada65e903f2832bc064bf70d82b0cb6 100644 (file)
@@ -180,7 +180,7 @@ backsql_operational(
                        && !got[ BACKSQL_OP_ENTRYUUID ]
                        && attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID ) == NULL )
        {
-               backsql_srch_info       bsi;
+               backsql_srch_info       bsi = { 0 };
 
                rc = backsql_init_search( &bsi, &rs->sr_entry->e_nname,
                                LDAP_SCOPE_BASE,
@@ -197,6 +197,7 @@ backsql_operational(
                *ap = backsql_operational_entryUUID( bi, &bsi.bsi_base_id );
 
                (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
+
                if ( bsi.bsi_attrs != NULL ) {
                        op->o_tmpfree( bsi.bsi_attrs, op->o_tmpmemctx );
                }
index e3cd9b82ffced972dd2d6e1431ba99c60a556e22..f0a8237f9f2983678e2705be3cbb56080660a94e 100644 (file)
@@ -224,6 +224,7 @@ extern char
        backsql_def_needs_select_oc_query[],
        backsql_def_at_query[],
        backsql_def_delentry_stmt[],
+       backsql_def_renentry_stmt[],
        backsql_def_insentry_stmt[],
        backsql_def_delobjclasses_stmt[],
        backsql_def_delreferrals_stmt[],
index d6524d160900041fe70cfebffcf9ae5f67b20588..9440a920c45c307c826e65961a57effaa10ee107 100644 (file)
@@ -1789,7 +1789,7 @@ backsql_search( Operation *op, SlapReply *rs )
                                base_entry = { 0 };
        int                     manageDSAit;
        time_t                  stoptime = 0;
-       backsql_srch_info       bsi;
+       backsql_srch_info       bsi = { 0 };
        backsql_entryID         *eid = NULL;
        struct berval           nbase = BER_BVNULL,
                                realndn = BER_BVNULL;
@@ -2303,7 +2303,7 @@ backsql_entry_get(
                int                     rw,
                Entry                   **ent )
 {
-       backsql_srch_info       bsi;
+       backsql_srch_info       bsi = { 0 };
        SQLHDBC                 dbh = SQL_NULL_HDBC;
        int                     rc;
        SlapReply               rs = { 0 };
@@ -2331,7 +2331,9 @@ backsql_entry_get(
                        dbh, op, &rs, at ? anlist : NULL,
                        BACKSQL_ISF_GET_ENTRY );
 
-       (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
+       if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
+               (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
+       }
 
        if ( rc == LDAP_SUCCESS ) {
 
index 337b6bf975d8a85771b84bc1a6c7bb9a2ef6a409..0b971b024176ddd102e59e4e5fa91247b639a724 100644 (file)
@@ -48,6 +48,8 @@ char backsql_def_at_query[] =
        "param_order,expect_return,sel_expr_u FROM ldap_attr_mappings "
        "WHERE oc_map_id=?";
 char backsql_def_delentry_stmt[] = "DELETE FROM ldap_entries WHERE id=?";
+char backsql_def_renentry_stmt[] =
+       "UPDATE ldap_entries SET dn=?,parent=?,keyval=? WHERE id=?";
 char backsql_def_insentry_stmt[] = 
        "INSERT INTO ldap_entries (dn,oc_map_id,parent,keyval) "
        "VALUES (?,?,?,?)";