Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25290] _db_auth's rows are not deleted when dropping an user (#5079) #5116

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 79 additions & 0 deletions src/object/authenticate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down