From 26c5ac04b09139d062499564ea599e93bd53a1fb Mon Sep 17 00:00:00 2001 From: robocop Date: Mon, 4 Apr 2005 08:33:43 +0000 Subject: [PATCH] This is my first attempt in four years to fix the nonsense code I wrote for grants extraction in FB1. --- src/isql/extract.epp | 77 ++++++++++++++------------------------------ src/isql/show.epp | 15 ++++----- 2 files changed, 31 insertions(+), 61 deletions(-) diff --git a/src/isql/extract.epp b/src/isql/extract.epp index 872b64417c..1809caf3bd 100644 --- a/src/isql/extract.epp +++ b/src/isql/extract.epp @@ -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,17 +904,16 @@ 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 + // 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 + + char banner[100]; + sprintf(banner, "%s/* Grant permissions for this database */%s", + NEWLINE, + NEWLINE); - first = true; + 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 + // 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 + // 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; } diff --git a/src/isql/show.epp b/src/isql/show.epp index 22515cb4e9..de3620d583 100644 --- a/src/isql/show.epp +++ b/src/isql/show.epp @@ -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);