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-24633] Delete owner information from schema, index, trigger, and object files of general users. #4136

Merged
merged 10 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion msg/en_US/utils.msg
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ valid options:\n\
-S, --SA-mode stand-alone mode execution\n\
-C, --CS-mode client-server mode execution\n\
--datafile-per-class create a object file for each class; default: disabled\n\
--split-schema-files split schema information by object and generate each file; Default: generate one schema file with all objects\n
--split-schema-files split schema information by object and generate each file; Default: generate one schema file with all objects\n\
--same-as-dba If the login user is a member of the DBA group, extract the same schema file as the DBA.\n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about:
--as-dba



$set 14 MSGCAT_UTIL_SET_COMPACTDB
Expand Down
4 changes: 2 additions & 2 deletions msg/ko_KR.utf8/utils.msg
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ unloaddb: 데이터베이스에서 스키마와 객체를 언로드\n\
-S, --SA-mode 독립 모드 실행\n\
-C, --CS-mode 클라이언트 서버 모드 실행\n\
--datafile-per-class 각 클래스별 오브젝트 파일 생성; 기본값:한 개의 오브젝트 파일생성\n\
--split-schema-files 스키마 정보를 오브젝트별로 분리하여 각각의 파일로 생성; 기본값: 모든 오브젝트가 포함된 한 개의 스키마 파일 생성\n

--split-schema-files 스키마 정보를 오브젝트별로 분리하여 각각의 파일로 생성; 기본값: 모든 오브젝트가 포함된 한 개의 스키마 파일 생성\n\
--same-as-dba 로그인 사용자가 DBA 그룹의 구성원인 경우 DBA와 동일한 스키마 파일을 추출합니다.\n

$set 14 MSGCAT_UTIL_SET_COMPACTDB
11 \n패스 1\n\n
Expand Down
6 changes: 6 additions & 0 deletions src/executables/extract_schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ struct extract_context
int do_auth;
EMIT_STORAGE_ORDER storage_order;
const char *exec_name;
const char *login_user;
const char *output_dirname;
const char *output_prefix;
bool is_dba_user;
bool is_dba_group_member;

/* working */
int has_indexes;
Expand All @@ -55,8 +58,11 @@ struct extract_context
do_auth (0),
storage_order (FOLLOW_STORAGE_ORDER),
exec_name (NULL),
login_user(NULL),
output_dirname(NULL),
output_prefix(NULL),
is_dba_user (false),
is_dba_group_member (false),
has_indexes (0),
schema_file_list(NULL),
classes (NULL),
Expand Down
87 changes: 66 additions & 21 deletions src/executables/unload_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static void extractobjects_cleanup (void);
static void extractobjects_term_handler (int sig);
static bool mark_referenced_domain (SM_CLASS * class_ptr, int *num_set);
static void gauge_alarm_handler (int sig);
static int process_class (int cl_no);
static int process_class (extract_context & ctxt, int cl_no);
static int process_object (DESC_OBJ * desc_obj, OID * obj_oid, int referenced_class);
static int process_set (DB_SET * set);
static int process_value (DB_VALUE * value);
Expand Down Expand Up @@ -433,7 +433,7 @@ mark_referenced_domain (SM_CLASS * class_ptr, int *num_set)
* exec_name(in): utility name
*/
int
extract_objects (const char *exec_name, const char *output_dirname, const char *output_prefix)
extract_objects (extract_context & ctxt, const char *exec_name, const char *output_dirname, const char *output_prefix)
{
int i, error;
HFID *hfid;
Expand Down Expand Up @@ -632,6 +632,14 @@ extract_objects (const char *exec_name, const char *output_dirname, const char *
fprintf (stdout, "%s%s%s\n", PRINT_IDENTIFIER (sm_ch_name ((MOBJ) class_ptr)));
#endif /* CUBRID_DEBUG */

SPLIT_USER_SPECIFIED_NAME (sm_ch_name ((MOBJ) class_ptr), owner_name, class_name);

if ((ctxt.is_dba_user == false && ctxt.is_dba_group_member == false)
&& strcasecmp (owner_name, ctxt.login_user) != 0)
{
continue;
}

fh_put (cl_table, ws_oid (class_table->mops[i]), &i);
if (input_filename)
{
Expand Down Expand Up @@ -661,13 +669,24 @@ extract_objects (const char *exec_name, const char *output_dirname, const char *

if (!datafile_per_class && (!required_class_only || IS_CLASS_REQUESTED (i)))
{
SPLIT_USER_SPECIFIED_NAME (sm_ch_name ((MOBJ) class_ptr), owner_name, class_name);
if (text_print
(obj_out, NULL, 0, "%cid %s%s%s.%s%s%s %d\n", '%', PRINT_IDENTIFIER (owner_name),
PRINT_IDENTIFIER (class_name), i) != NO_ERROR)
if (ctxt.is_dba_user || ctxt.is_dba_group_member)
Copy link
Contributor

@kisoo-han kisoo-han Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even I'm not sure it is effieient but I'll propose a solution to simplify, it up to you its just idea:

  1. define a function like:
char *
print_owner_name (char * owner_name, bool print_owner_name)
{
  char buf[DB_MAX_USER_LENGTH+4] = "";

  if (print_owner_name)
    {
      sprintf (buf, "%s%s%s%s", PRINT_IDENTIFIER (owner_name), ".")
    }

  return buf;
}
  1. Next re-write following if-else-block as follow:
if (text_print (obj_out, NULL, 0, "%cid %s%s%s%s %d\n", '%', print_owner_name (owner_name, ctxt.is_dba_user || ctxt.is_dba_group_member), PRINT_IDENTIFIER (class_name), ) != NO_ERROR)
  {
    status = 1;
    goto end;
  }

{
status = 1;
goto end;
if (text_print
(obj_out, NULL, 0, "%cid %s%s%s.%s%s%s %d\n", '%', PRINT_IDENTIFIER (owner_name),
PRINT_IDENTIFIER (class_name), i) != NO_ERROR)
{
status = 1;
goto end;
}
}
else
{
if (text_print (obj_out, NULL, 0, "%cid %s%s%s %d\n", '%', PRINT_IDENTIFIER (class_name), i) !=
NO_ERROR)
{
status = 1;
goto end;
}
}
}

Expand Down Expand Up @@ -921,7 +940,7 @@ extract_objects (const char *exec_name, const char *output_dirname, const char *
}
}

ret_val = process_class (i);
ret_val = process_class (ctxt, i);

if (datafile_per_class && IS_CLASS_REQUESTED (i))
{
Expand Down Expand Up @@ -1040,7 +1059,7 @@ gauge_alarm_handler (int sig)
* cl_no(in): class object index for class_table
*/
static int
process_class (int cl_no)
process_class (extract_context & ctxt, int cl_no)
{
int error = NO_ERROR;
DB_OBJECT *class_ = class_table->mops[cl_no];
Expand Down Expand Up @@ -1113,10 +1132,19 @@ process_class (int cl_no)
if (v == 0)
{
SPLIT_USER_SPECIFIED_NAME (sm_ch_name ((MOBJ) class_ptr), owner_name, class_name);
CHECK_PRINT_ERROR (text_print
(obj_out, NULL, 0, "%cclass %s%s%s.%s%s%s shared (%s%s%s", '%',
PRINT_IDENTIFIER (owner_name),
PRINT_IDENTIFIER (class_name), PRINT_IDENTIFIER (attribute->header.name)));
if (ctxt.is_dba_user || ctxt.is_dba_group_member)
{
CHECK_PRINT_ERROR (text_print
(obj_out, NULL, 0, "%cclass %s%s%s.%s%s%s shared (%s%s%s", '%',
PRINT_IDENTIFIER (owner_name),
PRINT_IDENTIFIER (class_name), PRINT_IDENTIFIER (attribute->header.name)));
}
else
{
CHECK_PRINT_ERROR (text_print
(obj_out, NULL, 0, "%cclass %s%s%s shared (%s%s%s", '%',
PRINT_IDENTIFIER (class_name), PRINT_IDENTIFIER (attribute->header.name)));
}
}
else
{
Expand Down Expand Up @@ -1165,10 +1193,19 @@ process_class (int cl_no)
if (v == 0)
{
SPLIT_USER_SPECIFIED_NAME (sm_ch_name ((MOBJ) class_ptr), owner_name, class_name);
CHECK_PRINT_ERROR (text_print
(obj_out, NULL, 0, "%cclass %s%s%s.%s%s%s class (%s%s%s", '%',
PRINT_IDENTIFIER (owner_name),
PRINT_IDENTIFIER (class_name), PRINT_IDENTIFIER (attribute->header.name)));
if (ctxt.is_dba_user || ctxt.is_dba_group_member)
{
CHECK_PRINT_ERROR (text_print
(obj_out, NULL, 0, "%cclass %s%s%s.%s%s%s class (%s%s%s", '%',
PRINT_IDENTIFIER (owner_name),
PRINT_IDENTIFIER (class_name), PRINT_IDENTIFIER (attribute->header.name)));
}
else
{
CHECK_PRINT_ERROR (text_print
(obj_out, NULL, 0, "%cclass %s%s%s class (%s%s%s", '%',
PRINT_IDENTIFIER (class_name), PRINT_IDENTIFIER (attribute->header.name)));
}
}
else
{
Expand Down Expand Up @@ -1205,9 +1242,17 @@ process_class (int cl_no)
}

SPLIT_USER_SPECIFIED_NAME (sm_ch_name ((MOBJ) class_ptr), owner_name, class_name);
CHECK_PRINT_ERROR (text_print (obj_out, NULL, 0, (v) ? "\n%cclass %s%s%s.%s%s%s (" /* new line */
: "%cclass %s%s%s.%s%s%s (", '%', PRINT_IDENTIFIER (owner_name),
PRINT_IDENTIFIER (class_name)));
if (ctxt.is_dba_user || ctxt.is_dba_group_member)
{
CHECK_PRINT_ERROR (text_print (obj_out, NULL, 0, (v) ? "\n%cclass %s%s%s.%s%s%s (" /* new line */
: "%cclass %s%s%s.%s%s%s (", '%', PRINT_IDENTIFIER (owner_name),
PRINT_IDENTIFIER (class_name)));
}
else
{
CHECK_PRINT_ERROR (text_print (obj_out, NULL, 0, (v) ? "\n%cclass %s%s%s (" /* new line */
: "%cclass %s%s%s (", '%', PRINT_IDENTIFIER (class_name)));
}

v = 0;
attribute = class_ptr->ordered_attributes;
Expand Down
Loading