mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 23:23:04 +01:00
This is my first attempt in four years to fix the nonsense code I wrote for grants extraction in FB1.
This commit is contained in:
parent
ac0606ee65
commit
26c5ac04b0
@ -893,15 +893,10 @@ static processing_state list_all_grants2(bool show_role_list,
|
||||
* Get separate permissions on table/views and then procedures.
|
||||
*
|
||||
**************************************/
|
||||
bool first = true;
|
||||
bool first_role = true;
|
||||
TEXT prev_owner[44];
|
||||
|
||||
/******************************************************************
|
||||
**
|
||||
** process GRANT roles
|
||||
**
|
||||
*******************************************************************/
|
||||
|
||||
// Process GRANT roles
|
||||
if (isqlGlob.major_ods >= ODS_VERSION9 && show_role_list)
|
||||
{
|
||||
prev_owner[0] = '\0';
|
||||
@ -909,16 +904,15 @@ static processing_state list_all_grants2(bool show_role_list,
|
||||
FOR XX IN RDB$ROLES
|
||||
SORTED BY XX.RDB$ROLE_NAME
|
||||
|
||||
if (first)
|
||||
if (first_role)
|
||||
{
|
||||
sprintf (Print_buffer, "%s/* Grant role for this database */%s",
|
||||
sprintf (Print_buffer, "%s/* Grant roles for this database */%s",
|
||||
NEWLINE,
|
||||
NEWLINE);
|
||||
ISQL_printf (isqlGlob.Out, Print_buffer);
|
||||
first_role = false;
|
||||
}
|
||||
|
||||
first = false;
|
||||
|
||||
// Null terminate name string
|
||||
fb_utils::exact_name(XX.RDB$ROLE_NAME);
|
||||
fb_utils::exact_name(XX.RDB$OWNER_NAME);
|
||||
@ -953,33 +947,28 @@ static processing_state list_all_grants2(bool show_role_list,
|
||||
END_ERROR;
|
||||
}
|
||||
|
||||
/* This version of cursor gets only sql tables identified by security class
|
||||
and misses views, getting only null view_source */
|
||||
// This version of cursor gets only sql tables identified by security class
|
||||
// and misses views, getting only null view_source
|
||||
|
||||
first = true;
|
||||
char banner[100];
|
||||
sprintf(banner, "%s/* Grant permissions for this database */%s",
|
||||
NEWLINE,
|
||||
NEWLINE);
|
||||
|
||||
bool first = true;
|
||||
|
||||
FOR REL IN RDB$RELATIONS WITH
|
||||
(REL.RDB$SYSTEM_FLAG NE 1 OR REL.RDB$SYSTEM_FLAG MISSING) AND
|
||||
REL.RDB$SECURITY_CLASS STARTING "SQL$"
|
||||
SORTED BY REL.RDB$RELATION_NAME
|
||||
|
||||
if (first) {
|
||||
sprintf (Print_buffer, "%s/* Grant permissions for this database */%s",
|
||||
NEWLINE,
|
||||
NEWLINE);
|
||||
if (show_role_list) {
|
||||
ISQL_printf (isqlGlob.Out, Print_buffer);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Null terminate name string
|
||||
|
||||
fb_utils::exact_name(REL.RDB$RELATION_NAME);
|
||||
|
||||
const processing_state rc =
|
||||
SHOW_grants2 (REL.RDB$RELATION_NAME, terminator, obj_relation,
|
||||
first ? Print_buffer : 0);
|
||||
SHOW_grants2(REL.RDB$RELATION_NAME, terminator, obj_relation,
|
||||
first ? banner : 0);
|
||||
if (rc == SKIP) {
|
||||
first = false;
|
||||
}
|
||||
@ -990,41 +979,23 @@ static processing_state list_all_grants2(bool show_role_list,
|
||||
return OBJECT_NOT_FOUND;
|
||||
END_ERROR;
|
||||
|
||||
if (first) {
|
||||
sprintf(Print_buffer, "%s/* Grant permissions for this database */%s",
|
||||
NEWLINE, NEWLINE);
|
||||
if (show_role_list) {
|
||||
ISQL_printf (isqlGlob.Out, Print_buffer);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (first)
|
||||
SHOW_grant_roles2 (terminator, &first, Print_buffer);
|
||||
SHOW_grant_roles2(terminator, &first, banner);
|
||||
else
|
||||
SHOW_grant_roles (terminator, 0);
|
||||
SHOW_grant_roles(terminator, 0);
|
||||
|
||||
|
||||
// Again for stored procedures
|
||||
// Again for stored procedures
|
||||
FOR PRC IN RDB$PROCEDURES
|
||||
SORTED BY PRC.RDB$PROCEDURE_NAME
|
||||
|
||||
if (first) {
|
||||
sprintf (Print_buffer, "%s/* Grant permissions for this database */%s",
|
||||
NEWLINE, NEWLINE);
|
||||
if (show_role_list) {
|
||||
ISQL_printf (isqlGlob.Out, Print_buffer);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 ? Print_buffer: 0);
|
||||
SHOW_grants2(PRC.RDB$PROCEDURE_NAME, terminator, obj_procedure,
|
||||
first ? banner: 0);
|
||||
if (rc == SKIP)
|
||||
first = false;
|
||||
|
||||
@ -1034,7 +1005,7 @@ static processing_state list_all_grants2(bool show_role_list,
|
||||
return OBJECT_NOT_FOUND;
|
||||
END_ERROR;
|
||||
|
||||
return first ? OBJECT_NOT_FOUND : SKIP;
|
||||
return first_role && first ? OBJECT_NOT_FOUND : SKIP;
|
||||
}
|
||||
|
||||
|
||||
|
@ -791,7 +791,7 @@ void SHOW_grant_roles2 (const SCHAR* terminator,
|
||||
**************************************
|
||||
*
|
||||
* Functional description
|
||||
* Show grants for given role name
|
||||
* Show grants for each role name
|
||||
* This function is also called by extract for privileges.
|
||||
* All membership privilege may have the with_admin option set.
|
||||
*
|
||||
@ -805,7 +805,7 @@ void SHOW_grant_roles2 (const SCHAR* terminator,
|
||||
PRV.RDB$OBJECT_TYPE EQ obj_sql_role AND
|
||||
PRV.RDB$USER_TYPE EQ obj_user AND
|
||||
PRV.RDB$PRIVILEGE EQ 'M'
|
||||
SORTED BY PRV.RDB$RELATION_NAME, PRV.RDB$USER
|
||||
SORTED BY PRV.RDB$RELATION_NAME, PRV.RDB$USER
|
||||
|
||||
if (first) {
|
||||
if (*first && optional_msg) {
|
||||
@ -822,14 +822,13 @@ void SHOW_grant_roles2 (const SCHAR* terminator,
|
||||
else
|
||||
with_option[0] = '\0';
|
||||
|
||||
fb_utils::exact_name(PRV.RDB$RELATION_NAME);
|
||||
if (isqlGlob.db_SQL_dialect > SQL_DIALECT_V6_TRANSITION) {
|
||||
const char* role = fb_utils::exact_name(PRV.RDB$RELATION_NAME);
|
||||
if (isqlGlob.db_SQL_dialect > SQL_DIALECT_V6_TRANSITION)
|
||||
{
|
||||
ISQL_copy_SQL_id (PRV.RDB$RELATION_NAME, SQL_identifier, DBL_QUOTE);
|
||||
sprintf (Print_buffer, "GRANT %s TO %s%s%s%s", SQL_identifier,
|
||||
user_string, with_option, terminator, NEWLINE);
|
||||
role = SQL_identifier;
|
||||
}
|
||||
else
|
||||
sprintf (Print_buffer, "GRANT %s TO %s%s%s%s", PRV.RDB$RELATION_NAME,
|
||||
sprintf (Print_buffer, "GRANT %s TO %s%s%s%s", role,
|
||||
user_string, with_option, terminator, NEWLINE);
|
||||
|
||||
ISQL_printf (isqlGlob.Out, Print_buffer);
|
||||
|
Loading…
Reference in New Issue
Block a user