8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 20:43:02 +01:00

Package support. Work in progress.

This commit is contained in:
robocop 2009-11-12 07:17:01 +00:00
parent fb7dba7325
commit 33ca7e6a77
3 changed files with 369 additions and 139 deletions

View File

@ -1073,6 +1073,10 @@ static processing_state list_all_grants2(bool show_role_list, const SCHAR* termi
system_flag = true;
END_FOR
ON_ERROR
ISQL_errmsg(gds_status);
return OBJECT_NOT_FOUND;
END_ERROR;
}
if (! system_flag)
@ -1149,19 +1153,36 @@ static processing_state list_all_grants2(bool show_role_list, const SCHAR* termi
SHOW_grant_roles2(terminator, 0, 0, mangle);
// Again for stored procedures
// Again for stored procedures, but ignore private procedures inside packages.
FOR PRC IN RDB$PROCEDURES
WITH (PRC.RDB$SYSTEM_FLAG NE 1 OR PRC.RDB$SYSTEM_FLAG MISSING)
SORTED BY PRC.RDB$PROCEDURE_NAME
// Null terminate name string
bool private_flag = false;
if (isqlGlob.major_ods >= ODS_VERSION12)
{
FOR HIDDEN IN RDB$PROCEDURES
WITH HIDDEN.RDB$PROCEDURE_NAME = PRC.RDB$PROCEDURE_NAME
AND HIDDEN.RDB$PRIVATE_FLAG = 1
private_flag = true;
END_FOR
ON_ERROR
ISQL_errmsg(gds_status);
return OBJECT_NOT_FOUND;
END_ERROR;
}
fb_utils::exact_name(PRC.RDB$PROCEDURE_NAME);
if (!private_flag)
{
// Null terminate name string
fb_utils::exact_name(PRC.RDB$PROCEDURE_NAME);
const processing_state rc =
SHOW_grants2(PRC.RDB$PROCEDURE_NAME, terminator, obj_procedure,
first ? banner: 0, mangle);
if (rc == SKIP)
first = false;
const processing_state rc =
SHOW_grants2(PRC.RDB$PROCEDURE_NAME, terminator, obj_procedure,
first ? banner: 0, mangle);
if (rc == SKIP)
first = false;
}
END_FOR
ON_ERROR
@ -1169,6 +1190,26 @@ static processing_state list_all_grants2(bool show_role_list, const SCHAR* termi
return OBJECT_NOT_FOUND;
END_ERROR;
if (isqlGlob.major_ods >= ODS_VERSION12)
{
FOR PACK IN RDB$PACKAGES
WITH (PACK.RDB$SYSTEM_FLAG NE 1 OR PACK.RDB$SYSTEM_FLAG MISSING)
SORTED BY PACK.RDB$PACKAGE_NAME
// Null terminate name string
fb_utils::exact_name(PACK.RDB$PACKAGE_NAME);
const processing_state rc =
SHOW_grants2(PACK.RDB$PACKAGE_NAME, terminator, obj_package_header,
first ? banner: 0, mangle);
if (rc == SKIP)
first = false;
END_FOR
ON_ERROR
ISQL_errmsg(gds_status);
return OBJECT_NOT_FOUND;
END_ERROR
}
return first_role && first ? OBJECT_NOT_FOUND : SKIP;
}

View File

@ -105,25 +105,25 @@ const int NULL_DISP_LEN = 6;
const int MSG_LENGTH = 1024;
const int ISQL_MSG_FAC = 17;
const int GEN_ERR = 0; // General non-zero SQLCODE error
const int SWITCH = 2; // Bad command line arg
const int NO_DB = 3; // No database specified
const int FILE_OPEN_ERR = 4; // Can't open specified file
const int COMMIT_PROMPT = 5; // Commit or rollback question
const int COMMIT_MSG = 6; // Committing ...
const int ROLLBACK_MSG = 7; // Rolling back
const int CMD_ERR = 8; // Unknown frontend command
const int ADD_PROMPT = 9; // Prompt for add function
const int GEN_ERR = 0; // General non-zero SQLCODE error
const int SWITCH = 2; // Bad command line arg
const int NO_DB = 3; // No database specified
const int FILE_OPEN_ERR = 4; // Can't open specified file
const int COMMIT_PROMPT = 5; // Commit or rollback question
const int COMMIT_MSG = 6; // Committing ...
const int ROLLBACK_MSG = 7; // Rolling back
const int CMD_ERR = 8; // Unknown frontend command
const int ADD_PROMPT = 9; // Prompt for add function
const int VERSION = 10; // Version string for -z
const int NUMBER_PAGES = 12; // Number of DB pages allocated = %d \n
const int SWEEP_INTERV = 13; // Sweep interval = %d \n
//const int NUM_WAL_BUFF = 14; // Number of wal buffers = %d \n
//const int WAL_BUFF_SIZE = 15; // Wal buffer size = %d \n
const int CKPT_LENGTH = 16; // Check point length = %d \n
const int CKPT_INTERV = 17; // Check point interval = %d \n
//const int WAL_GRPC_WAIT = 18; // Wal group commit wait = %d \n
const int BASE_LEVEL = 19; // Base level = %d \n
const int LIMBO = 20; // Transaction in limbo = %d \n
const int NUMBER_PAGES = 12; // Number of DB pages allocated = @1 \n
const int SWEEP_INTERV = 13; // Sweep interval = @1 \n
//const int NUM_WAL_BUFF = 14; // Number of wal buffers = @1 \n
//const int WAL_BUFF_SIZE = 15; // Wal buffer size = @1 \n
const int CKPT_LENGTH = 16; // Check point length = @1 \n
const int CKPT_INTERV = 17; // Check point interval = @1 \n
//const int WAL_GRPC_WAIT = 18; // Wal group commit wait = @1 \n
const int BASE_LEVEL = 19; // Base level = @1 \n
const int LIMBO = 20; // Transaction in limbo = @1 \n
// Help list
const int HLP_FRONTEND = 21; // Frontend commands:\n
const int HLP_BLOBVIEW = 22; // BLOBVIEW [<blobid as high:low>] -- edit a blob\n
@ -155,18 +155,18 @@ const int REPORT2 = 93; // Buffers = !b\nReads = !r\nWrites = !w\nFetches =
#else
const int REPORT2 = 45; // Cpu = !u sec\nBuffers = !b\nReads = !r\nWrites = !w\nFetches = !f\n
#endif
const int BLOB_SUBTYPE = 46; // Blob display set to subtype %d. This blob: subtype = %d\n
const int BLOB_PROMPT = 47; // Blob: %s, type 'edit' or filename to load>
const int DATE_PROMPT = 48; // Enter %s as M/D/Y>
const int NAME_PROMPT = 49; // Enter %s>
const int DATE_ERR = 50; // Bad date %s\n
const int BLOB_SUBTYPE = 46; // Blob display set to subtype @1. This blob: subtype = @2\n
const int BLOB_PROMPT = 47; // Blob: @1, type 'edit' or filename to load>
const int DATE_PROMPT = 48; // Enter @1 as M/D/Y>
const int NAME_PROMPT = 49; // Enter @1>
const int DATE_ERR = 50; // Bad date @1\n
const int CON_PROMPT = 51; // "CON> "
const int HLP_SETLIST = 52; // \tSET LIST -- toggles column or table display\n
const int NOT_FOUND_MSG = 53; // %s not found\n
const int COPY_ERR = 54; // Errors occurred (possibly duplicate domains) in creating %s in %s\n"
const int NOT_FOUND_MSG = 53; // @1 not found\n
const int COPY_ERR = 54; // Errors occurred (possibly duplicate domains) in creating @1 in @2\n"
const int SERVER_TOO_OLD = 55; // Server version too old to support the isql command
const int REC_COUNT = 56; // Total returned: %ld
const int UNLICENSED = 57; // Unlicensed for database "%s"
const int REC_COUNT = 56; // Total returned: @1
const int UNLICENSED = 57; // Unlicensed for database "@1"
const int HLP_SETWIDTH = 58; // \tSET WIDTH <column name> [<width>] --sets/unsets print width for column name
const int HLP_SETPLAN = 59; // Toggle display of query access plan
const int HLP_SETTIME = 60; // Toggle display of timestamp with DATE values
@ -177,68 +177,68 @@ const int HLP_OBJTYPE2 = 64; // More objects
const int HLP_SETBLOB2 = 65; // \t SET BLOB turns off blob display\n
const int HLP_SET_ROOT = 66; // (Use HELP SET for set options)
const int NO_TABLES = 67; // There are no tables in this database
const int NO_TABLE = 68; // There is no table %s in this database
const int NO_TABLE = 68; // There is no table @1 in this database
const int NO_VIEWS = 69; // There are no views in this database
const int NO_VIEW = 70; // There is no view %s in this database
const int NO_INDICES_ON_REL = 71; // There are no indices on table %s in this database
const int NO_REL_OR_INDEX = 72; // There is no table or index %s in this database
const int NO_VIEW = 70; // There is no view @1 in this database
const int NO_INDICES_ON_REL = 71; // There are no indices on table @1 in this database
const int NO_REL_OR_INDEX = 72; // There is no table or index @1 in this database
const int NO_INDICES = 73; // There are no indices in this database
const int NO_DOMAIN = 74; // There is no domain %s in this database
const int NO_DOMAIN = 74; // There is no domain @1 in this database
const int NO_DOMAINS = 75; // There are no domains in this database
const int NO_EXCEPTION = 76; // There is no exception %s in this database
const int NO_EXCEPTION = 76; // There is no exception @1 in this database
const int NO_EXCEPTIONS = 77; // There are no exceptions in this database
const int NO_FILTER = 78; // There is no filter %s in this database
const int NO_FILTER = 78; // There is no filter @1 in this database
const int NO_FILTERS = 79; // There are no filters in this database
const int NO_FUNCTION = 80; // There is no user-defined function %s in this database
const int NO_FUNCTION = 80; // There is no user-defined function @1 in this database
const int NO_FUNCTIONS = 81; // There are no user-defined functions in this database
const int NO_GEN = 82; // There is no generator %s in this database
const int NO_GEN = 82; // There is no generator @1 in this database
const int NO_GENS = 83; // There are no generators in this database
const int NO_GRANT_ON_REL = 84; // There is no privilege granted on table %s in this database
const int NO_GRANT_ON_PROC = 85; // There is no privilege granted on stored procedure %s in this database
const int NO_REL_OR_PROC = 86; // There is no table or stored procedure %s in this database
const int NO_PROC = 87; // There is no stored procedure %s in this database
const int NO_GRANT_ON_REL = 84; // There is no privilege granted on table @1 in this database
const int NO_GRANT_ON_PROC = 85; // There is no privilege granted on stored procedure @1 in this database
const int NO_REL_OR_PROC = 86; // There is no table or stored procedure @1 in this database
const int NO_PROC = 87; // There is no stored procedure @1 in this database
const int NO_PROCS = 88; // There are no stored procedures in this database
const int NO_TRIGGERS_ON_REL = 89; // There are no triggers on table %s in this database
const int NO_REL_OR_TRIGGER = 90; // There is no table or trigger %s in this database
const int NO_TRIGGERS_ON_REL = 89; // There are no triggers on table @1 in this database
const int NO_REL_OR_TRIGGER = 90; // There is no table or trigger @1 in this database
const int NO_TRIGGERS = 91; // There are no triggers in this database
const int NO_TRIGGER = 121; // There is no trigger %s in this database
const int NO_CHECKS_ON_REL = 92; // There are no check constraints on table %s in this database
const int NO_TRIGGER = 121; // There is no trigger @1 in this database
const int NO_CHECKS_ON_REL = 92; // There are no check constraints on table @1 in this database
const int NO_COMMENTS = 115; // There are no comments for objects in this database.
const int BUFFER_OVERFLOW = 94; // An isql command exceeded maximum buffer size
const int NO_ROLES = 95; // There are no roles in this database
const int NO_REL_OR_PROC_OR_ROLE = 96; // There is no table, stored procedure, or
// role %s in this database
// role @1 in this database
const int NO_GRANT_ON_ROL = 97; // There is no membership privilege granted
// on %s in this database
// on @1 in this database
const int UNEXPECTED_EOF = 98; // Expected end of statement, encountered EOF
const int TIME_ERR = 101; // Bad TIME: %s\n
const int TIME_ERR = 101; // Bad TIME: @1\n
const int HLP_OBJTYPE3 = 102; // Some more objects
const int NO_ROLE = 103; // There is no role %s in this database
const int INCOMPLETE_STR = 105; // Incomplete string in %s
const int NO_ROLE = 103; // There is no role @1 in this database
const int INCOMPLETE_STR = 105; // Incomplete string in @1
const int HLP_SETSQLDIALECT = 106; // \tSET SQL DIALECT <n> -- set sql dialect to <n>
const int NO_GRANT_ON_ANY = 107; // There is no privilege granted in this database.
const int HLP_SETPLANONLY = 108; // toggle display of query plan without executing
const int HLP_SETHEADING = 109; // toggle display of query column titles
const int HLP_SETBAIL = 110; // toggle bailing out on errors in non-interactive mode
const int TIME_PROMPT = 112; // Enter %s as H:M:S>
const int TIMESTAMP_PROMPT = 113; // Enter %s as Y/MON/D H:MIN:S[.MSEC]>
const int TIMESTAMP_ERR = 114; // Bad TIMESTAMP: %s\n
const int ONLY_FIRST_BLOBS = 116; // Printing only the first %d blobs.
const int TIME_PROMPT = 112; // Enter @1 as H:M:S>
const int TIMESTAMP_PROMPT = 113; // Enter @1 as Y/MON/D H:MIN:S[.MSEC]>
const int TIMESTAMP_ERR = 114; // Bad TIMESTAMP: @1\n
const int ONLY_FIRST_BLOBS = 116; // Printing only the first @1 blobs.
const int MSG_TABLES = 117; // Tables:
const int MSG_FUNCTIONS = 118; // Functions:
const int EXACTLINE = 119; // At line %d in file %s
const int AFTERLINE = 120; // After line %d in file %s
const int EXACTLINE = 119; // At line @1 in file @1
const int AFTERLINE = 120; // After line @1 in file @2
const int USAGE = 1; // usage: syntax
const int USAGE_NOARG = 142; // usage: missing argument for "%s"
const int USAGE_NOTINT = 143; // usage: argument "%s" for switch "%s" is not an integer
const int USAGE_RANGE = 144; // usage: value "%s" for switch "%s" is out of range
const int USAGE_DUPSW = 145; // usage: switch "%s" or its equivalent used more than once
const int USAGE_DUPDB = 146; // usage: more than one database name: "%s", "%s"
const int NO_DEPENDENCIES = 147; // No dependencies for %s were found
const int NO_COLLATION = 148; // There is no collation %s in this database
const int USAGE_NOARG = 142; // usage: missing argument for "@1"
const int USAGE_NOTINT = 143; // usage: argument "@1" for switch "@2" is not an integer
const int USAGE_RANGE = 144; // usage: value "@1" for switch "@2" is out of range
const int USAGE_DUPSW = 145; // usage: switch "@1" or its equivalent used more than once
const int USAGE_DUPDB = 146; // usage: more than one database name: "@1", "@2"
const int NO_DEPENDENCIES = 147; // No dependencies for @1 were found
const int NO_COLLATION = 148; // There is no collation @1 in this database
const int NO_COLLATIONS = 149; // There are no collations in this database
const int MSG_COLLATIONS = 150; // Collations:
const int NO_SECCLASS = 151; // There are no security classes for %s
const int NO_SECCLASS = 151; // There are no security classes for @1
const int NO_DB_WIDE_SECCLASS = 152; // There is no database-wide security class
const int CANNOT_GET_SRV_VER = 153; // Cannot get server version without database connection
const int BULK_PROMPT = 156; // "BULK> "
@ -250,6 +250,10 @@ const int USAGE_FETCH = 161; // -f(etch_password) fetch password from
const int PASS_FILE_OPEN = 162; // could not open password file @1, errno @2
const int PASS_FILE_READ = 163; // could not read password file @1, errno @2
const int EMPTY_PASS = 164; // empty password file @1
const int NO_PACKAGE = 166; // There is no package @1 in this database
const int NO_PACKAGES = 167; // There are no packages in this database
const int NO_SCHEMA = 168; // There is no schema @1 in this database
const int NO_SCHEMAS = 169; // There are no schemas in this database
// Initialize types

View File

@ -97,6 +97,7 @@ static processing_state show_generators(const SCHAR*);
static void show_index(SCHAR*, SCHAR*, const SSHORT, const SSHORT, const SSHORT);
static processing_state show_indices(const SCHAR* const*);
static processing_state show_proc(const SCHAR*);
static processing_state show_packages(const SCHAR* package_name);
static processing_state show_role(const SCHAR*);
static processing_state show_secclass(const char* object, const char* opt);
static processing_state show_table(const SCHAR*, bool);
@ -549,6 +550,41 @@ static const char* granted_by(char* buffer, const char* grantor)
}
static void set_grantee(int user_type, const char* SQL_identifier, char* user_string)
{
switch (user_type)
{
case obj_view:
sprintf (user_string, "VIEW %s", SQL_identifier);
break;
case obj_trigger:
sprintf (user_string, "TRIGGER %s", SQL_identifier);
break;
case obj_procedure:
sprintf (user_string, "PROCEDURE %s", SQL_identifier);
break;
case obj_user:
if (strcmp(SQL_identifier, "PUBLIC"))
sprintf (user_string, "USER %s", SQL_identifier);
else
strcpy (user_string, SQL_identifier);
break;
case obj_user_group:
sprintf (user_string, "GROUP %s", SQL_identifier);
break;
case obj_sql_role:
sprintf (user_string, "ROLE %s", SQL_identifier);
break;
case obj_package_header:
sprintf(user_string, "PACKAGE %s", SQL_identifier);
break;
default:
strcpy (user_string, SQL_identifier);
break;
}
}
processing_state SHOW_grants2 (const SCHAR* object,
const SCHAR* terminator,
USHORT obj_type,
@ -579,6 +615,7 @@ processing_state SHOW_grants2 (const SCHAR* object,
BASED_ON RDB$USER_PRIVILEGES.RDB$FIELD_NAME prev_field;
BASED_ON RDB$USER_PRIVILEGES.RDB$USER_TYPE prev_user_type;
BASED_ON RDB$USER_PRIVILEGES.RDB$GRANTOR prev_grantor;
BASED_ON RDB$USER_PRIVILEGES.RDB$OBJECT_TYPE prev_object_type;
SCHAR buf_grantor[sizeof(prev_grantor) + 20];
SCHAR user_string[QUOTEDLENGTH + 20];
bool first = true;
@ -593,6 +630,7 @@ processing_state SHOW_grants2 (const SCHAR* object,
prev_field[0] = '\0';
prev_grantor[0] = '\0';
prev_user_type = -1;
prev_object_type = -1;
char priv_string[MAX_PRIV_LIST] = "";
char col_string[BUFFER_LENGTH128] = "";
char with_option[19] = "";
@ -604,7 +642,7 @@ processing_state SHOW_grants2 (const SCHAR* object,
// Find the user specified relation and show its privileges
FOR FIRST 1 R IN RDB$RELATIONS WITH R.RDB$RELATION_NAME EQ object;
FOR FIRST 1 R IN RDB$RELATIONS WITH R.RDB$RELATION_NAME EQ object
// This query only finds tables, eliminating owner privileges
@ -614,7 +652,7 @@ processing_state SHOW_grants2 (const SCHAR* object,
REL.RDB$RELATION_NAME EQ object AND
PRV.RDB$PRIVILEGE NE 'M' AND
REL.RDB$OWNER_NAME NE PRV.RDB$USER
SORTED BY PRV.RDB$USER, PRV.RDB$FIELD_NAME, PRV.RDB$GRANT_OPTION;
SORTED BY PRV.RDB$USER, PRV.RDB$FIELD_NAME, PRV.RDB$GRANT_OPTION;
fb_utils::exact_name(PRV.RDB$USER);
@ -634,7 +672,8 @@ processing_state SHOW_grants2 (const SCHAR* object,
(!prev_field_null && strcmp (prev_field, PRV.RDB$FIELD_NAME)) ||
(prev_option != -1 && prev_option != PRV.RDB$GRANT_OPTION) ||
(prev_user_type != -1 && prev_user_type != PRV.RDB$USER_TYPE) ||
(prev_grantor[0] && strcmp (prev_grantor, PRV.RDB$GRANTOR)))
(prev_grantor[0] && strcmp (prev_grantor, PRV.RDB$GRANTOR)) ||
(prev_object_type != -1 && prev_object_type != PRV.RDB$OBJECT_TYPE))
{
make_priv_string (priv_flags, priv_string);
@ -671,6 +710,7 @@ processing_state SHOW_grants2 (const SCHAR* object,
strcpy (prev_field, PRV.RDB$FIELD_NAME);
prev_user_type = PRV.RDB$USER_TYPE;
strcpy (prev_grantor, PRV.RDB$GRANTOR);
prev_object_type = PRV.RDB$OBJECT_TYPE;
switch (PRV.RDB$USER_TYPE)
{
@ -679,6 +719,7 @@ processing_state SHOW_grants2 (const SCHAR* object,
case obj_trigger:
case obj_procedure:
case obj_sql_role:
case obj_package_header:
case obj_user: // Users can be machine\user and need quoting
if (mangle && isqlGlob.db_SQL_dialect > SQL_DIALECT_V6_TRANSITION) {
IUTILS_copy_SQL_id (PRV.RDB$USER, SQL_identifier, DBL_QUOTE);
@ -691,33 +732,7 @@ processing_state SHOW_grants2 (const SCHAR* object,
break;
}
switch (PRV.RDB$USER_TYPE)
{
case obj_view:
sprintf (user_string, "VIEW %s", SQL_identifier);
break;
case obj_trigger:
sprintf (user_string, "TRIGGER %s", SQL_identifier);
break;
case obj_procedure:
sprintf (user_string, "PROCEDURE %s", SQL_identifier);
break;
case obj_user:
if (strcmp(SQL_identifier, "PUBLIC"))
sprintf (user_string, "USER %s", SQL_identifier);
else
strcpy (user_string, SQL_identifier);
break;
case obj_user_group:
sprintf (user_string, "GROUP %s", SQL_identifier);
break;
case obj_sql_role:
sprintf (user_string, "ROLE %s", SQL_identifier);
break;
default:
strcpy (user_string, SQL_identifier);
break;
}
set_grantee(PRV.RDB$USER_TYPE, SQL_identifier, user_string);
// Only the first character is used for permissions
@ -818,7 +833,7 @@ processing_state SHOW_grants2 (const SCHAR* object,
PRC.RDB$PROCEDURE_NAME EQ object AND
PRV.RDB$PRIVILEGE EQ 'X' AND
PRC.RDB$OWNER_NAME NE PRV.RDB$USER
SORTED BY PRV.RDB$USER, PRV.RDB$FIELD_NAME, PRV.RDB$GRANT_OPTION;
SORTED BY PRV.RDB$USER, PRV.RDB$FIELD_NAME, PRV.RDB$GRANT_OPTION
if (first && optional_msg)
isqlGlob.prints(optional_msg);
@ -833,6 +848,8 @@ processing_state SHOW_grants2 (const SCHAR* object,
case obj_trigger:
case obj_procedure:
case obj_sql_role:
case obj_package_header:
case obj_user:
if (mangle && isqlGlob.db_SQL_dialect > SQL_DIALECT_V6_TRANSITION) {
IUTILS_copy_SQL_id (PRV.RDB$USER, SQL_identifier, DBL_QUOTE);
}
@ -844,33 +861,7 @@ processing_state SHOW_grants2 (const SCHAR* object,
break;
}
switch (PRV.RDB$USER_TYPE)
{
case obj_view:
sprintf (user_string, "VIEW %s", SQL_identifier);
break;
case obj_trigger:
sprintf (user_string, "TRIGGER %s", SQL_identifier);
break;
case obj_procedure:
sprintf (user_string, "PROCEDURE %s", SQL_identifier);
break;
case obj_user:
if (strcmp(SQL_identifier, "PUBLIC"))
sprintf (user_string, "USER %s", SQL_identifier);
else
strcpy (user_string, SQL_identifier);
break;
case obj_user_group:
sprintf (user_string, "GROUP %s", SQL_identifier);
break;
case obj_sql_role:
sprintf (user_string, "ROLE %s", SQL_identifier);
break;
default:
strcpy (user_string, SQL_identifier);
break;
}
set_grantee(PRV.RDB$USER_TYPE, SQL_identifier, user_string);
if (PRV.RDB$GRANT_OPTION)
strcpy (with_option, " WITH GRANT OPTION");
@ -886,7 +877,6 @@ processing_state SHOW_grants2 (const SCHAR* object,
isqlGlob.printf("GRANT EXECUTE ON PROCEDURE %s TO %s%s%s%s%s",
SQL_identifier, user_string, with_option,
granted_by(buf_grantor, PRV.RDB$GRANTOR), terminator, NEWLINE);
first = false;
END_FOR
ON_ERROR
@ -921,7 +911,7 @@ processing_state SHOW_grants2 (const SCHAR* object,
PRV.RDB$USER_TYPE EQ obj_user AND
PRV.RDB$RELATION_NAME EQ object AND
PRV.RDB$PRIVILEGE EQ 'M'
SORTED BY PRV.RDB$USER
SORTED BY PRV.RDB$USER
fb_utils::exact_name(PRV.RDB$RELATION_NAME);
strcpy (role_name, PRV.RDB$RELATION_NAME);
@ -964,6 +954,80 @@ processing_state SHOW_grants2 (const SCHAR* object,
return (SKIP);
}
if (obj_type == obj_package_header || obj_type == 255)
{
fb_assert(isqlGlob.major_ods >= ODS_VERSION12);
if (isqlGlob.major_ods < ODS_VERSION12)
return OBJECT_NOT_FOUND;
FOR FIRST 1 P IN RDB$PACKAGES WITH P.RDB$PACKAGE_NAME EQ object
FOR PRV IN RDB$USER_PRIVILEGES CROSS
PACK IN RDB$PACKAGES WITH
PRV.RDB$OBJECT_TYPE = obj_package_header AND
PRV.RDB$RELATION_NAME EQ object AND
PACK.RDB$PACKAGE_NAME EQ object AND
PRV.RDB$PRIVILEGE EQ 'X' AND
PACK.RDB$OWNER_NAME NE PRV.RDB$USER
SORTED BY PRV.RDB$USER, PRV.RDB$FIELD_NAME, PRV.RDB$GRANT_OPTION
if (first && optional_msg)
isqlGlob.prints(optional_msg);
first = false;
fb_utils::exact_name(PRV.RDB$USER);
switch (PRV.RDB$USER_TYPE)
{
case obj_relation:
case obj_view:
case obj_trigger:
case obj_procedure:
case obj_sql_role:
case obj_package_header:
case obj_user:
if (mangle && isqlGlob.db_SQL_dialect > SQL_DIALECT_V6_TRANSITION) {
IUTILS_copy_SQL_id (PRV.RDB$USER, SQL_identifier, DBL_QUOTE);
}
else
strcpy (SQL_identifier, PRV.RDB$USER);
break;
default:
strcpy (SQL_identifier, PRV.RDB$USER);
break;
}
set_grantee(PRV.RDB$USER_TYPE, SQL_identifier, user_string);
if (PRV.RDB$GRANT_OPTION)
strcpy (with_option, " WITH GRANT OPTION");
else
with_option[0] = '\0';
if (mangle && isqlGlob.db_SQL_dialect > SQL_DIALECT_V6_TRANSITION) {
IUTILS_copy_SQL_id (object, SQL_identifier, DBL_QUOTE);
}
else
strcpy (SQL_identifier, object);
isqlGlob.printf("GRANT EXECUTE ON PACKAGE %s TO %s%s%s%s%s",
SQL_identifier, user_string, with_option,
granted_by(buf_grantor, PRV.RDB$GRANTOR), terminator, NEWLINE);
END_FOR
ON_ERROR
ISQL_errmsg (isc_status);
return ps_ERR;
END_ERROR
END_FOR
ON_ERROR
ISQL_errmsg(isc_status);
return ps_ERR;
END_ERROR;
if (!first)
return (SKIP);
}
return OBJECT_NOT_FOUND;
}
@ -1146,7 +1210,7 @@ processing_state SHOW_metadata(const SCHAR* const* cmd, SCHAR** lcmd)
role, table, view, system, index, domain, exception,
filter, function, generator, grant, procedure, trigger,
check, database, comment, dependency, collation, security_class,
users, wrong
users, package, schema, wrong
};
ShowOptions(const optionsMap* inmap, size_t insize, int wrongval)
: OptionsBase(inmap, insize, wrongval)
@ -1200,7 +1264,9 @@ processing_state SHOW_metadata(const SCHAR* const* cmd, SCHAR** lcmd)
{ShowOptions::collation, "COLLATIONS", 9},
{ShowOptions::security_class, "SECURITY CLASSES", 12},
{ShowOptions::security_class, "SECCLASSES", 6},
{ShowOptions::users, "USERS", 0}
{ShowOptions::users, "USERS", 0},
{ShowOptions::package, "PACKAGES", 4},
{ShowOptions::schema, "SCHEMAS", 4}
};
const ShowOptions showoptions(options, FB_NELEM(options), ShowOptions::wrong);
@ -1499,12 +1565,12 @@ processing_state SHOW_metadata(const SCHAR* const* cmd, SCHAR** lcmd)
}
else
strcpy(SQL_id_for_grant, cmd[2]);
ret = SHOW_grants (SQL_id_for_grant, "", 255);
ret = SHOW_grants(SQL_id_for_grant, "", 255);
}
else
{
strcpy(SQL_id_for_grant, cmd[2]);
ret = EXTRACT_list_grants ("");
ret = EXTRACT_list_grants("");
}
if (ret == OBJECT_NOT_FOUND)
@ -1687,6 +1753,28 @@ processing_state SHOW_metadata(const SCHAR* const* cmd, SCHAR** lcmd)
key = NO_CONNECTED_USERS;
break;
case ShowOptions::package:
if (*cmd[2] == '"')
{
remove_delimited_double_quotes(lcmd[2]);
ret = show_packages(lcmd[2]);
}
else
ret = show_packages(cmd[2]);
if (ret == OBJECT_NOT_FOUND)
{
if (*cmd[2])
key = NO_PACKAGE;
else
key = NO_PACKAGES;
}
break;
case ShowOptions::schema:
return ps_ERR;
break;
default:
return ps_ERR;
} // switch
@ -2229,10 +2317,10 @@ static void show_comment(const char* objtype, char* name1, char* name2,
// When extracting comments, we do the usual escaping to make the script valid.
static processing_state show_comments(const commentMode showextract, const char* banner)
{
// From dsql.h:
// ddl_database, ddl_domain, ddl_relation, ddl_view, ddl_procedure, ddl_trigger,
// ddl_udf, ddl_blob_filter, ddl_exception, ddl_generator, ddl_index, ddl_role,
// ddl_charset, ddl_collation//, ddl_sec_class
// From dsql.h:
// ddl_database, ddl_domain, ddl_relation, ddl_view, ddl_procedure, ddl_trigger,
// ddl_udf, ddl_blob_filter, ddl_exception, ddl_generator, ddl_index, ddl_role,
// ddl_charset, ddl_collation//, ddl_sec_class
bool first = true;
@ -2466,6 +2554,23 @@ static processing_state show_comments(const commentMode showextract, const char*
END_ERROR
}
if (isqlGlob.major_ods >= ODS_VERSION12)
{
FOR PACK IN RDB$PACKAGES
WITH PACK.RDB$DESCRIPTION NOT MISSING
AND (PACK.RDB$SYSTEM_FLAG EQ 0 OR PACK.RDB$SYSTEM_FLAG MISSING)
SORTED BY PACK.RDB$PACKAGE_NAME
show_comment("PACKAGE", PACK.RDB$PACKAGE_NAME, 0, &PACK.RDB$DESCRIPTION,
showextract, first ? banner : 0);
first = false;
END_FOR
ON_ERROR
ISQL_errmsg(isc_status);
return ps_ERR;
END_ERROR
}
FOR CH IN RDB$CHARACTER_SETS
WITH CH.RDB$DESCRIPTION NOT MISSING
AND (CH.RDB$SYSTEM_FLAG EQ 0 OR CH.RDB$SYSTEM_FLAG MISSING)
@ -3631,6 +3736,83 @@ static processing_state show_indices(const SCHAR* const* cmd)
}
static processing_state show_packages(const SCHAR* package_name)
{
/*************************************
*
* s h o w _ p a c k a g e s
*
**************************************
*
* Functional description
* Show all packages or the named package
************************************/
if (isqlGlob.major_ods < ODS_VERSION12)
return OBJECT_NOT_FOUND;
bool first = true;
if (!*package_name)
{
bool odd = true;
// List all package names in columns
FOR PACK IN RDB$PACKAGES WITH
PACK.RDB$SYSTEM_FLAG NE 1
SORTED BY PACK.RDB$PACKAGE_NAME
first = false;
isqlGlob.printf("%38s%s", PACK.RDB$PACKAGE_NAME, (odd ? " " : NEWLINE));
odd = !odd;
END_FOR
ON_ERROR
ISQL_errmsg(isc_status);
return ps_ERR;
END_ERROR;
if (!first)
isqlGlob.printf(NEWLINE);
}
else
{
// List named package
FOR PACK IN RDB$PACKAGES WITH
PACK.RDB$PACKAGE_NAME EQ package_name
first = false;
// Print the name of the package
fb_utils::exact_name(PACK.RDB$PACKAGE_NAME);
isqlGlob.printf("%-32s", PACK.RDB$PACKAGE_NAME);
isqlGlob.printf(NEWLINE);
if (!PACK.RDB$PACKAGE_HEADER_SOURCE.NULL)
{
isqlGlob.printf("%s%s", "Header source:", NEWLINE);
SHOW_print_metadata_text_blob (isqlGlob.Out, &PACK.RDB$PACKAGE_HEADER_SOURCE);
isqlGlob.printf(NEWLINE);
}
if (!PACK.RDB$PACKAGE_BODY_SOURCE.NULL)
{
isqlGlob.printf("%s%s", "Body source:", NEWLINE);
SHOW_print_metadata_text_blob (isqlGlob.Out, &PACK.RDB$PACKAGE_BODY_SOURCE);
isqlGlob.printf(NEWLINE);
}
END_FOR
ON_ERROR
ISQL_errmsg(isc_status);
return ps_ERR;
END_ERROR;
}
if (first)
return (OBJECT_NOT_FOUND);
return (SKIP);
}
static processing_state show_proc(const SCHAR* procname)
{
/**************************************
@ -3931,6 +4113,9 @@ static processing_state show_proc(const SCHAR* procname)
static processing_state show_role(const SCHAR* object)
{
if (isqlGlob.major_ods < ODS_VERSION9)
return OBJECT_NOT_FOUND;
if (object == NULL)
{
// show role with no parameters, show all roles