From 11ca3f9e5491c12d3dae441685392091d5601b3e Mon Sep 17 00:00:00 2001 From: Hyung-Gyu Ryoo Date: Thu, 11 Apr 2024 21:00:38 +0900 Subject: [PATCH] [CBRD-25290] _db_auth's rows are not deleted when dropping an user (#5079) (#5116) http://jira.cubrid.org/browse/CBRD-25290 11.3 backport of #5079 --- src/object/authenticate.c | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/src/object/authenticate.c b/src/object/authenticate.c index c2f104ba2c8..35e7237d3da 100644 --- a/src/object/authenticate.c +++ b/src/object/authenticate.c @@ -562,6 +562,8 @@ static void au_print_grant_entry (DB_SET * grants, int grant_index, FILE * fp); static void au_print_auth (MOP auth, FILE * fp); static int au_change_serial_owner (MOP serial_mop, MOP owner_mop, bool by_class_owner_change); +static int au_delete_auth_of_dropping_user (MOP user); + /* * DB_ EXTENSION FUNCTIONS */ @@ -2098,6 +2100,77 @@ au_delete_auth_of_dropping_table (const char *class_name) return error; } +/* + * au_delete_auth_of_dropping_user - delete _db_auth records refers to the given grantee user. + * return: error code + * user(in): the grantee user name to be dropped + */ +static int +au_delete_auth_of_dropping_user (MOP user) +{ + int error = NO_ERROR, save; + const char *sql_query = "DELETE FROM [" CT_CLASSAUTH_NAME "] [au] WHERE [au].[grantee] = ?;"; + DB_VALUE val; + DB_QUERY_RESULT *result = NULL; + DB_SESSION *session = NULL; + int stmt_id; + + db_make_null (&val); + + /* Disable the checking for internal authorization object access */ + AU_DISABLE (save); + + assert (user != NULL); + + session = db_open_buffer_local (sql_query); + if (session == NULL) + { + ASSERT_ERROR_AND_SET (error); + goto exit; + } + + error = db_set_system_generated_statement (session); + if (error != NO_ERROR) + { + goto release; + } + + stmt_id = db_compile_statement_local (session); + if (stmt_id < 0) + { + ASSERT_ERROR_AND_SET (error); + goto release; + } + + db_make_object (&val, user); + error = db_push_values (session, 1, &val); + if (error != NO_ERROR) + { + goto release; + } + + error = db_execute_statement_local (session, stmt_id, &result); + if (error < 0) + { + goto release; + } + + error = db_query_end (result); + +release: + if (session != NULL) + { + db_close_session (session); + } + +exit: + pr_clear_value (&val); + + AU_ENABLE (save); + + return error; +} + /* * check_user_name * return: error code @@ -3692,6 +3765,12 @@ au_drop_user (MOP user) } } + error = au_delete_auth_of_dropping_user (user); + if (error != NO_ERROR) + { + goto error; + } + /* * could go through classes created by this user and change ownership * to the DBA ? - do this as the classes are referenced instead