Skip to content

Commit

Permalink
1) Modified the logic to allow for separate execution of SP and Metho…
Browse files Browse the repository at this point in the history
…d within an if-else-statement when the CALL statement is executed. 2) Added a part to remove the owner and user_schema when the unloaddb utility is executed as a general user, provided that the owner and user_schema are the same.
  • Loading branch information
jongmin-won committed Jul 3, 2024
1 parent f90eab9 commit 4fabc96
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 21 deletions.
8 changes: 6 additions & 2 deletions src/executables/unload_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -4331,6 +4331,7 @@ emit_stored_procedure (extract_context & ctxt, print_output & output_ctx)
int err;
int err_count = 0;
char owner_name[DB_MAX_USER_LENGTH] = { '\0' };
char output_owner[DB_MAX_USER_LENGTH + 4] = { '\0' };

AU_DISABLE (save);

Expand Down Expand Up @@ -4371,6 +4372,9 @@ emit_stored_procedure (extract_context & ctxt, print_output & output_ctx)
const char *sp_name = db_get_string (&sp_name_val);
sm_qualifier_name (unique_name, owner_name, DB_MAX_USER_LENGTH);

PRINT_OWNER_NAME (owner_name, (ctxt.is_dba_user || ctxt.is_dba_group_member), output_owner,
sizeof (output_owner));

if (ctxt.is_dba_user == false && ctxt.is_dba_group_member == false)
{
owner = db_get_object (&owner_val);
Expand All @@ -4397,7 +4401,7 @@ emit_stored_procedure (extract_context & ctxt, print_output & output_ctx)
}
else
{
output_ctx (" %s%s%s.%s%s%s (", PRINT_IDENTIFIER (owner_name), PRINT_IDENTIFIER (sp_name));
output_ctx (" %s%s%s%s (", output_owner, PRINT_IDENTIFIER (sp_name));
}

arg_cnt = db_get_int (&arg_cnt_val);
Expand Down Expand Up @@ -4444,7 +4448,7 @@ emit_stored_procedure (extract_context & ctxt, print_output & output_ctx)

if (ctxt.is_dba_user || ctxt.is_dba_group_member)
{
output_ctx ("call [change_sp_owner]('%s', '%s') on class [db_root];\n", db_get_string (&unique_name_val),
output_ctx ("call [change_sp_owner]('%s', '%s') on class [db_root];\n", unique_name,
db_get_string (&owner_name_val));
}

Expand Down
38 changes: 37 additions & 1 deletion src/object/authenticate.c
Original file line number Diff line number Diff line change
Expand Up @@ -5118,7 +5118,14 @@ au_change_sp_owner (MOP sp, MOP owner)
{
int error = NO_ERROR;
int save;
DB_VALUE value;
const char *name_str = NULL, *owner_str = NULL;
char new_name_str[DB_MAX_IDENTIFIER_LENGTH] = { '\0' };
char downcase_owner_name[DB_MAX_USER_LENGTH] = { '\0' };
DB_VALUE value, name_value, owner_value;

db_make_null (&value);
db_make_null (&name_value);
db_make_null (&owner_value);

AU_DISABLE (save);
if (!au_is_dba_group_member (Au_user))
Expand All @@ -5128,6 +5135,35 @@ au_change_sp_owner (MOP sp, MOP owner)
}
else
{
error = obj_get (sp, "sp_name", &name_value);
if (error != NO_ERROR)
{
goto end;
}
error = obj_get (owner, "name", &owner_value);
if (error != NO_ERROR)
{
goto end;
}

name_str = db_get_string (&name_value);
owner_str = db_get_string (&owner_value);

sm_downcase_name (owner_str, downcase_owner_name, DB_MAX_USER_LENGTH);
sprintf (new_name_str, "%s.%s", downcase_owner_name, name_str);

/* change the unique_name */
if (new_name_str != NULL)
{
db_make_string (&value, new_name_str);
error = obj_set (sp, SP_ATTR_UNIQUE_NAME, &value);
if (error < 0)
{
goto end;
}
pr_clear_value (&value);
}

db_make_object (&value, owner);
error = obj_set (sp, SP_ATTR_OWNER, &value);
if (error < 0)
Expand Down
37 changes: 19 additions & 18 deletions src/parser/name_resolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,6 @@ pt_bind_names (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue
short i, k, lhs_location, rhs_location, level;
PT_JOIN_TYPE join_type;
void *save_etc = NULL;
DB_VALUE value;

*continue_walk = PT_CONTINUE_WALK;

Expand Down Expand Up @@ -3228,15 +3227,8 @@ pt_bind_names (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue
* first parameter to the on_call_target. If there is no parameter,
* it will be caught in pt_semantic_check_local()
*/
if (!node->info.method_call.on_call_target && node->info.method_call.arg_list
&& !jsp_is_exist_stored_procedure (node->info.method_call.method_name->info.name.original))
{
node->info.method_call.on_call_target = node->info.method_call.arg_list;
node->info.method_call.arg_list = node->info.method_call.arg_list->next;
node->info.method_call.on_call_target->next = NULL;
}

if (!node->info.method_call.on_call_target)
if (!node->info.method_call.on_call_target
&& jsp_is_exist_stored_procedure (node->info.method_call.method_name->info.name.original))
{
PT_NODE *method_name = node->info.method_call.method_name;
node->info.method_call.method_name->info.name.spec_id = (UINTPTR) method_name;
Expand All @@ -3248,13 +3240,23 @@ pt_bind_names (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue
}
else
{
/*
* Class methods are system tables and do not require user_schema.
* Therefore, remove [schema_name.] from schema_name.method_name.
* ex) CALL 'add_user()', 'drop_user()', 'find_user()'
*/
node->info.method_call.method_name->info.name.original =
sm_remove_qualifier_name (node->info.method_call.method_name->info.name.original);
if (!node->info.method_call.on_call_target && node->info.method_call.arg_list)
{
node->info.method_call.on_call_target = node->info.method_call.arg_list;
node->info.method_call.arg_list = node->info.method_call.arg_list->next;
node->info.method_call.on_call_target->next = NULL;
}

if (node->info.method_call.on_call_target)
{
/*
* Class methods are system tables and do not require user_schema.
* Therefore, remove [schema_name.] from schema_name.method_name.
* ex) CALL 'add_user()', 'drop_user()', 'find_user()'
*/
node->info.method_call.method_name->info.name.original =
sm_remove_qualifier_name (node->info.method_call.method_name->info.name.original);
}

/* make method name look resolved */
node->info.method_call.method_name->info.name.spec_id = (UINTPTR) node->info.method_call.method_name;
Expand Down Expand Up @@ -3296,7 +3298,6 @@ pt_bind_names (PARSER_CONTEXT * parser, PT_NODE * node, void *arg, int *continue
}
}
}

break;

case PT_DATA_TYPE:
Expand Down

0 comments on commit 4fabc96

Please sign in to comment.