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-25762] When a general user performs a trigger unload, remove [user_schema] from condition and action_definition if the owner is the user themselves. #5731

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 84 additions & 2 deletions src/object/trigger_description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ tr_dump_trigger (extract_context &ctxt, print_output &output_ctx, DB_OBJECT *tri
char owner_name[DB_MAX_USER_LENGTH] = { '\0' };
const char *trigger_name = NULL;
const char *class_name = NULL;
PARSER_CONTEXT *parser;
PT_NODE **action_node = nullptr, **condition_node = nullptr;
char *query_action_result, *query_condition_result;

AU_DISABLE (save);

Expand Down Expand Up @@ -314,7 +317,65 @@ tr_dump_trigger (extract_context &ctxt, print_output &output_ctx, DB_OBJECT *tri

if (trigger->condition != NULL)
{
output_ctx ("IF %s\n", trigger->condition->source);
char *text;
int length;
const char *eval_prefix = "EVALUATE ( ";
const char *eval_suffix = " ) ";
char *p = NULL;
const char *remove_eval_prefix = "evaluate (";
size_t remove_eval_suffix_len;

length = strlen (eval_prefix) + strlen (trigger->condition->source) + strlen (eval_suffix) + 1;
text = (char *) malloc (length);
if (text == NULL)
{
output_ctx ("/* ERROR : IF %s */\n", trigger->condition->source);
error = ER_OUT_OF_VIRTUAL_MEMORY;
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, (size_t) length);
free_and_init (text);
return error;
}
strcpy (text, eval_prefix);
strcat (text, trigger->condition->source);
strcat (text, eval_suffix);

parser = parser_create_parser ();
if (parser == NULL)
{
output_ctx ("/* ERROR : IF %s */\n", trigger->condition->source);
}

if (ctxt.is_dba_user == false && ctxt.is_dba_group_member == false)
{
parser->custom_print |= PT_PRINT_NO_CURRENT_USER_NAME;
}

condition_node = parser_parse_string (parser, text);
if (condition_node != NULL)
{
query_condition_result = parser_print_tree_with_quotes (parser, *condition_node);

/* remove appended trigger evaluate info */
p = strstr (query_condition_result, remove_eval_prefix);
if (p != NULL)
{
p = (char *) memmove (p, p + strlen (remove_eval_prefix), strlen (p) - strlen (remove_eval_prefix) + 1);
}

remove_eval_suffix_len = strlen (p);
if (remove_eval_suffix_len > 0 && p[remove_eval_suffix_len - 1] == ')')
{
p[remove_eval_suffix_len - 1] = '\0';
}

output_ctx ("IF %s\n", query_condition_result);
}
else
{
output_ctx ("/* ERROR : IF %s */\n", trigger->condition->source);
}
parser_free_parser (parser);
free_and_init (text);
}

if (trigger->action != NULL)
Expand All @@ -327,7 +388,28 @@ tr_dump_trigger (extract_context &ctxt, print_output &output_ctx, DB_OBJECT *tri
switch (trigger->action->type)
{
case TR_ACT_EXPRESSION:
output_ctx ("%s", trigger->action->source);
parser = parser_create_parser ();
if (parser == NULL)
{
output_ctx ("\n/* ERROR : EXECUTE %s */\n", trigger->action->source);
}

if (ctxt.is_dba_user == false && ctxt.is_dba_group_member == false)
{
parser->custom_print |= PT_PRINT_NO_CURRENT_USER_NAME;
}

action_node = parser_parse_string (parser, trigger->action->source);
if (action_node != NULL)
{
query_action_result = parser_print_tree_with_quotes (parser, *action_node);
output_ctx ("%s", query_action_result);
}
else
{
output_ctx ("\n/* ERROR : EXECUTE %s */\n", trigger->action->source);
}
parser_free_parser (parser);
break;
case TR_ACT_REJECT:
output_ctx ("REJECT");
Expand Down
Loading