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

added the ability to change sql security option in alter package

This commit is contained in:
Alexander Zhdanov 2023-10-26 00:37:13 +03:00
parent 5b620936e2
commit 695082ece7
5 changed files with 80 additions and 7 deletions

View File

@ -613,3 +613,8 @@ ALTER FUNCTION <name> [ {DETERMINISTIC | NOT DETERMINISTIC} ] [ SQL SECURITY {DE
(Alexander Zhdanov) (Alexander Zhdanov)
ALTER PROCEDURE <name> SQL SECURITY {DEFINER | INVOKER} | DROP SQL SECURITY ALTER PROCEDURE <name> SQL SECURITY {DEFINER | INVOKER} | DROP SQL SECURITY
26) Added the ability to change sql security option without specifying the entire body of the package
(Alexander Zhdanov)
ALTER PACKAGE <name> SQL SECURITY {DEFINER | INVOKER} | DROP SQL SECURITY

View File

@ -215,6 +215,9 @@ string CreateAlterPackageNode::internalPrint(NodePrinter& printer) const
DdlNode* CreateAlterPackageNode::dsqlPass(DsqlCompilerScratch* dsqlScratch) DdlNode* CreateAlterPackageNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
{ {
if(alter && !items)
return DdlNode::dsqlPass(dsqlScratch);
MemoryPool& pool = dsqlScratch->getPool(); MemoryPool& pool = dsqlScratch->getPool();
source.ltrim("\n\r\t "); source.ltrim("\n\r\t ");
@ -319,9 +322,18 @@ void CreateAlterPackageNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlS
// run all statements under savepoint control // run all statements under savepoint control
AutoSavePoint savePoint(tdbb, transaction); AutoSavePoint savePoint(tdbb, transaction);
const bool alterIndividualParameters = (alter && !items);
if (alter) if (alter)
{ {
if (!executeAlter(tdbb, dsqlScratch, transaction)) if(alterIndividualParameters)
{
if(!executeAlterIndividualParameters(tdbb, dsqlScratch, transaction))
status_exception::raise(
Arg::Gds(isc_no_meta_update) <<
Arg::Gds(isc_dyn_package_not_found) << Arg::Str(name));
}
else if (!executeAlter(tdbb, dsqlScratch, transaction))
{ {
if (create) // create or alter if (create) // create or alter
executeCreate(tdbb, dsqlScratch, transaction); executeCreate(tdbb, dsqlScratch, transaction);
@ -371,10 +383,10 @@ void CreateAlterPackageNode::executeCreate(thread_db* tdbb, DsqlCompilerScratch*
PKG.RDB$PACKAGE_HEADER_SOURCE.NULL = FALSE; PKG.RDB$PACKAGE_HEADER_SOURCE.NULL = FALSE;
attachment->storeMetaDataBlob(tdbb, transaction, &PKG.RDB$PACKAGE_HEADER_SOURCE, source); attachment->storeMetaDataBlob(tdbb, transaction, &PKG.RDB$PACKAGE_HEADER_SOURCE, source);
if (ssDefiner.isAssigned()) if (ssDefiner.has_value())
{ {
PKG.RDB$SQL_SECURITY.NULL = FALSE; PKG.RDB$SQL_SECURITY.NULL = FALSE;
PKG.RDB$SQL_SECURITY = ssDefiner.asBool() ? FB_TRUE : FB_FALSE; PKG.RDB$SQL_SECURITY = ssDefiner.value() == SqlSecurity::SS_DEFINER ? FB_TRUE : FB_FALSE;
} }
else else
PKG.RDB$SQL_SECURITY.NULL = TRUE; PKG.RDB$SQL_SECURITY.NULL = TRUE;
@ -445,10 +457,10 @@ bool CreateAlterPackageNode::executeAlter(thread_db* tdbb, DsqlCompilerScratch*
if (!PKG.RDB$VALID_BODY_FLAG.NULL) if (!PKG.RDB$VALID_BODY_FLAG.NULL)
PKG.RDB$VALID_BODY_FLAG = FALSE; PKG.RDB$VALID_BODY_FLAG = FALSE;
if (ssDefiner.isAssigned()) if (ssDefiner.has_value())
{ {
PKG.RDB$SQL_SECURITY.NULL = FALSE; PKG.RDB$SQL_SECURITY.NULL = FALSE;
PKG.RDB$SQL_SECURITY = ssDefiner.asBool() ? FB_TRUE : FB_FALSE; PKG.RDB$SQL_SECURITY = ssDefiner.value() == SqlSecurity::SS_DEFINER ? FB_TRUE : FB_FALSE;
} }
else else
PKG.RDB$SQL_SECURITY.NULL = TRUE; PKG.RDB$SQL_SECURITY.NULL = TRUE;
@ -475,6 +487,44 @@ bool CreateAlterPackageNode::executeAlter(thread_db* tdbb, DsqlCompilerScratch*
} }
bool CreateAlterPackageNode::executeAlterIndividualParameters(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction)
{
AutoCacheRequest requestHandle(tdbb, drq_m_prm_pkg, DYN_REQUESTS);
bool modified = false;
FOR (REQUEST_HANDLE requestHandle TRANSACTION_HANDLE transaction)
PKG IN RDB$PACKAGES
WITH PKG.RDB$PACKAGE_NAME EQ name.c_str()
{
modified = true;
executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_BEFORE,
DDL_TRIGGER_ALTER_PACKAGE, name, NULL);
MODIFY PKG
if (ssDefiner.has_value())
{
if(ssDefiner.value() != SqlSecurity::SS_DROP)
{
PKG.RDB$SQL_SECURITY.NULL = FALSE;
PKG.RDB$SQL_SECURITY = ssDefiner.value() == SqlSecurity::SS_DEFINER ? FB_TRUE : FB_FALSE;
}
else
PKG.RDB$SQL_SECURITY.NULL = TRUE;
}
END_MODIFY
}
END_FOR
if (modified)
{
executeDdlTrigger(tdbb, dsqlScratch, transaction,
DTW_AFTER, DDL_TRIGGER_ALTER_PACKAGE, name, NULL);
}
return modified;
}
void CreateAlterPackageNode::executeItems(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, void CreateAlterPackageNode::executeItems(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch,
jrd_tra* transaction) jrd_tra* transaction)
{ {

View File

@ -100,6 +100,7 @@ protected:
private: private:
void executeCreate(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction); void executeCreate(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction);
bool executeAlter(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction); bool executeAlter(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction);
bool executeAlterIndividualParameters(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction);
void executeItems(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction); void executeItems(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction);
public: public:
@ -110,7 +111,7 @@ public:
Firebird::Array<Item>* items; Firebird::Array<Item>* items;
Firebird::SortedArray<MetaName> functionNames; Firebird::SortedArray<MetaName> functionNames;
Firebird::SortedArray<MetaName> procedureNames; Firebird::SortedArray<MetaName> procedureNames;
TriState ssDefiner; std::optional<SqlSecurity> ssDefiner;
private: private:
MetaName owner; MetaName owner;

View File

@ -2977,7 +2977,7 @@ replace_function_clause
%type <createAlterPackageNode> package_clause %type <createAlterPackageNode> package_clause
package_clause package_clause
: symbol_package_name sql_security_clause_opt AS BEGIN package_items_opt END : symbol_package_name optional_sql_security_full_alter_clause AS BEGIN package_items_opt END
{ {
CreateAlterPackageNode* node = newNode<CreateAlterPackageNode>(*$1); CreateAlterPackageNode* node = newNode<CreateAlterPackageNode>(*$1);
node->ssDefiner = $2; node->ssDefiner = $2;
@ -2987,6 +2987,16 @@ package_clause
} }
; ;
%type <createAlterPackageNode> change_opt_package_clause
change_opt_package_clause
: symbol_package_name optional_sql_security_partial_alter_clause
{
CreateAlterPackageNode* node = newNode<CreateAlterPackageNode>(*$1);
node->ssDefiner = $2;
$$ = node;
}
;
%type <packageItems> package_items_opt %type <packageItems> package_items_opt
package_items_opt package_items_opt
: package_items : package_items
@ -3024,6 +3034,12 @@ alter_package_clause
$$->alter = true; $$->alter = true;
$$->create = false; $$->create = false;
} }
| change_opt_package_clause
{
$$ = $1;
$$->alter = true;
$$->create = false;
}
; ;
%type <createAlterPackageNode> replace_package_clause %type <createAlterPackageNode> replace_package_clause

View File

@ -200,6 +200,7 @@ enum drq_type_t
drq_m_pkg_prc, // drop package body drq_m_pkg_prc, // drop package body
drq_m_pkg_fun, // drop package body drq_m_pkg_fun, // drop package body
drq_m_pkg, // alter package drq_m_pkg, // alter package
drq_m_prm_pkg, // modify individual package parameters
drq_l_pkg_funcs, // lookup packaged functions drq_l_pkg_funcs, // lookup packaged functions
drq_l_pkg_func_args, // lookup packaged function arguments drq_l_pkg_func_args, // lookup packaged function arguments
drq_l_pkg_procs, // lookup packaged procedures drq_l_pkg_procs, // lookup packaged procedures