diff --git a/src/metadata/MetadataTemplateCmdHandler.cpp b/src/metadata/MetadataTemplateCmdHandler.cpp index 9676007f..7d469528 100644 --- a/src/metadata/MetadataTemplateCmdHandler.cpp +++ b/src/metadata/MetadataTemplateCmdHandler.cpp @@ -300,21 +300,21 @@ void MetadataTemplateCmdHandler::handleTemplateCmd(TemplateProcessor *tp, Domain* dom = dynamic_cast(object); std::vector* p = 0; if (rel) - p = rel->getPrivileges(); + p = rel->getPrivileges(false); if (proc) - p = proc->getPrivileges(); + p = proc->getPrivileges(false); if (role) - p = role->getPrivileges(); + p = role->getPrivileges(false); if (func) - p = func->getPrivileges(); + p = func->getPrivileges(false); if (pack) - p = pack->getPrivileges(); + p = pack->getPrivileges(false); if (gen) - p = gen->getPrivileges(); + p = gen->getPrivileges(false); if (exc) - p = exc->getPrivileges(); + p = exc->getPrivileges(false); if (dom) - p = dom->getPrivileges(); + p = dom->getPrivileges(false); if (!p) return; bool firstItem = true; diff --git a/src/metadata/domain.cpp b/src/metadata/domain.cpp index a3ef055f..ad99cbd0 100644 --- a/src/metadata/domain.cpp +++ b/src/metadata/domain.cpp @@ -406,7 +406,7 @@ void Domain::acceptVisitor(MetadataItemVisitor* visitor) visitor->visitDomain(*this); } -std::vector* Domain::getPrivileges() +std::vector* Domain::getPrivileges(bool splitPerGrantor) { // load privileges from database and return the pointer to collection DatabasePtr db = getDatabase(); @@ -427,11 +427,12 @@ std::vector* Domain::getPrivileges() "RDB$GRANT_OPTION, RDB$FIELD_NAME " "from RDB$USER_PRIVILEGES " "where RDB$RELATION_NAME = ? and rdb$object_type = 9 " - "order by rdb$user, rdb$user_type, rdb$grant_option, rdb$privilege" + "order by rdb$user, rdb$user_type, rdb$grantor, rdb$grant_option, rdb$privilege" ); st1->Set(1, wx2std(getName_(), converter)); st1->Execute(); std::string lastuser; + std::string lastGrantor; int lasttype = -1; Privilege* pr = 0; while (st1->Fetch()) @@ -445,12 +446,13 @@ std::vector* Domain::getPrivileges() if (!st1->IsNull(5)) st1->Get(5, grantoption); st1->Get(6, field); - if (!pr || user != lastuser || usertype != lasttype) + if (!pr || user != lastuser || usertype != lasttype || (splitPerGrantor && grantor != lastGrantor)) { Privilege p(this, wxString(user.c_str(), *converter).Strip(), usertype); privilegesM.push_back(p); pr = &privilegesM.back(); lastuser = user; + lastGrantor = grantor; lasttype = usertype; } pr->addPrivilege(privilege[0], std2wxIdentifier(grantor, converter), diff --git a/src/metadata/domain.h b/src/metadata/domain.h index 804f427d..adfd5908 100644 --- a/src/metadata/domain.h +++ b/src/metadata/domain.h @@ -66,7 +66,7 @@ class Domain: public MetadataItem wxString getAlterSqlTemplate() const; virtual const wxString getTypeName() const; virtual void acceptVisitor(MetadataItemVisitor* v); - std::vector* getPrivileges(); + std::vector* getPrivileges(bool splitPerGrantor=true); }; class DomainCollectionBase: public MetadataCollection diff --git a/src/metadata/exception.cpp b/src/metadata/exception.cpp index ba75b802..0a0c6e5a 100644 --- a/src/metadata/exception.cpp +++ b/src/metadata/exception.cpp @@ -130,7 +130,7 @@ void Exception::acceptVisitor(MetadataItemVisitor* visitor) visitor->visitException(*this); } -std::vector* Exception::getPrivileges() +std::vector* Exception::getPrivileges(bool splitPerGrantor) { // load privileges from database and return the pointer to collection DatabasePtr db = getDatabase(); @@ -151,11 +151,12 @@ std::vector* Exception::getPrivileges() "RDB$GRANT_OPTION, RDB$FIELD_NAME " "from RDB$USER_PRIVILEGES " "where RDB$RELATION_NAME = ? and rdb$object_type = 7 " - "order by rdb$user, rdb$user_type, rdb$grant_option, rdb$privilege" + "order by rdb$user, rdb$user_type, rdb$grantor, rdb$grant_option, rdb$privilege" ); st1->Set(1, wx2std(getName_(), converter)); st1->Execute(); std::string lastuser; + std::string lastGrantor; int lasttype = -1; Privilege* pr = 0; while (st1->Fetch()) @@ -169,12 +170,13 @@ std::vector* Exception::getPrivileges() if (!st1->IsNull(5)) st1->Get(5, grantoption); st1->Get(6, field); - if (!pr || user != lastuser || usertype != lasttype) + if (!pr || user != lastuser || usertype != lasttype || (splitPerGrantor && grantor != lastGrantor)) { Privilege p(this, wxString(user.c_str(), *converter).Strip(), usertype); privilegesM.push_back(p); pr = &privilegesM.back(); lastuser = user; + lastGrantor = grantor; lasttype = usertype; } pr->addPrivilege(privilege[0], std2wxIdentifier(grantor, converter), diff --git a/src/metadata/exception.h b/src/metadata/exception.h index f20f90a2..e411592e 100644 --- a/src/metadata/exception.h +++ b/src/metadata/exception.h @@ -51,7 +51,7 @@ class Exception: public MetadataItem virtual const wxString getTypeName() const; virtual void acceptVisitor(MetadataItemVisitor* visitor); - std::vector* getPrivileges(); + std::vector* getPrivileges(bool splitPerGrantor=true); }; class Exceptions : public MetadataCollection diff --git a/src/metadata/function.cpp b/src/metadata/function.cpp index 929abe70..1628dc28 100644 --- a/src/metadata/function.cpp +++ b/src/metadata/function.cpp @@ -314,7 +314,7 @@ wxString Function::getSqlSecurity() } } -std::vector* Function::getPrivileges() +std::vector* Function::getPrivileges(bool splitPerGrantor) { // load privileges from database and return the pointer to collection DatabasePtr db = getDatabase(); @@ -334,11 +334,12 @@ std::vector* Function::getPrivileges() "RDB$GRANT_OPTION, RDB$FIELD_NAME " "from RDB$USER_PRIVILEGES " "where RDB$RELATION_NAME = ? and rdb$object_type = 15 " - "order by rdb$user, rdb$user_type, rdb$privilege" + "order by rdb$user, rdb$user_type, rdb$grantor, rdb$privilege" ); st1->Set(1, wx2std(getName_(), converter)); st1->Execute(); std::string lastuser; + std::string lastGrantor; int lasttype = -1; Privilege* pr = 0; while (st1->Fetch()) @@ -352,13 +353,14 @@ std::vector* Function::getPrivileges() if (!st1->IsNull(5)) st1->Get(5, grantoption); st1->Get(6, field); - if (!pr || user != lastuser || usertype != lasttype) + if (!pr || user != lastuser || usertype != lasttype || (splitPerGrantor && grantor != lastGrantor)) { Privilege p(this, std2wxIdentifier(user, converter), usertype); privilegesM.push_back(p); pr = &privilegesM.back(); lastuser = user; + lastGrantor = grantor; lasttype = usertype; } pr->addPrivilege(privilege[0], wxString(grantor.c_str(), *converter), diff --git a/src/metadata/function.h b/src/metadata/function.h index b5d87175..5327f608 100644 --- a/src/metadata/function.h +++ b/src/metadata/function.h @@ -62,7 +62,7 @@ class Function: public MetadataItem virtual wxString getSource() = 0; wxString getSqlSecurity(); virtual const wxString getTypeName() const = 0; - std::vector* getPrivileges(); + std::vector* getPrivileges(bool splitPerGrantor=true); virtual void acceptVisitor(MetadataItemVisitor* visitor); virtual void checkDependentFunction(); diff --git a/src/metadata/generator.cpp b/src/metadata/generator.cpp index 8b96ec41..43f5d620 100644 --- a/src/metadata/generator.cpp +++ b/src/metadata/generator.cpp @@ -116,7 +116,7 @@ wxString Generator::getSource() return sql ; } -std::vector* Generator::getPrivileges() +std::vector* Generator::getPrivileges(bool splitPerGrantor) { // load privileges from database and return the pointer to collection DatabasePtr db = getDatabase(); @@ -137,11 +137,12 @@ std::vector* Generator::getPrivileges() "RDB$GRANT_OPTION, RDB$FIELD_NAME " "from RDB$USER_PRIVILEGES " "where RDB$RELATION_NAME = ? and rdb$object_type = 14 " - "order by rdb$user, rdb$user_type, rdb$grant_option, rdb$privilege" + "order by rdb$user, rdb$user_type, rdb$grantor, rdb$grant_option, rdb$privilege" ); st1->Set(1, wx2std(getName_(), converter)); st1->Execute(); std::string lastuser; + std::string lastGrantor; int lasttype = -1; Privilege* pr = 0; while (st1->Fetch()) @@ -155,12 +156,13 @@ std::vector* Generator::getPrivileges() if (!st1->IsNull(5)) st1->Get(5, grantoption); st1->Get(6, field); - if (!pr || user != lastuser || usertype != lasttype) + if (!pr || user != lastuser || usertype != lasttype || (splitPerGrantor && grantor != lastGrantor)) { Privilege p(this, wxString(user.c_str(), *converter).Strip(), usertype); privilegesM.push_back(p); pr = &privilegesM.back(); lastuser = user; + lastGrantor = grantor; lasttype = usertype; } pr->addPrivilege(privilege[0], std2wxIdentifier(grantor, converter), diff --git a/src/metadata/generator.h b/src/metadata/generator.h index 8a4b8036..5a4c188d 100644 --- a/src/metadata/generator.h +++ b/src/metadata/generator.h @@ -48,7 +48,7 @@ class Generator: public MetadataItem virtual const wxString getTypeName() const; virtual void acceptVisitor(MetadataItemVisitor* visitor); wxString getSource(); - std::vector* getPrivileges(); + std::vector* getPrivileges(bool splitPerGrantor=true); }; class Generators: public MetadataCollection diff --git a/src/metadata/package.cpp b/src/metadata/package.cpp index 50ee9993..399fca92 100644 --- a/src/metadata/package.cpp +++ b/src/metadata/package.cpp @@ -412,7 +412,7 @@ void Package::checkDependentPackage() } } -std::vector* Package::getPrivileges() +std::vector* Package::getPrivileges(bool splitPerGrantor) { // load privileges from database and return the pointer to collection DatabasePtr db = getDatabase(); @@ -432,11 +432,12 @@ std::vector* Package::getPrivileges() "RDB$GRANT_OPTION, RDB$FIELD_NAME " "from RDB$USER_PRIVILEGES " "where RDB$RELATION_NAME = ? and rdb$object_type in( 18, 19 ) " - "order by rdb$user, rdb$user_type, rdb$privilege" + "order by rdb$user, rdb$user_type, rdb$grantor, rdb$privilege" ); st1->Set(1, wx2std(getName_(), converter)); st1->Execute(); std::string lastuser; + std::string lastGrantor; int lasttype = -1; Privilege *pr = 0; while (st1->Fetch()) @@ -450,13 +451,14 @@ std::vector* Package::getPrivileges() if (!st1->IsNull(5)) st1->Get(5, grantoption); st1->Get(6, field); - if (!pr || user != lastuser || usertype != lasttype) + if (!pr || user != lastuser || usertype != lasttype || (splitPerGrantor && grantor != lastGrantor)) { Privilege p(this, std2wxIdentifier(user, converter), usertype); privilegesM.push_back(p); pr = &privilegesM.back(); lastuser = user; + lastGrantor = grantor; lasttype = usertype; } pr->addPrivilege(privilege[0], wxString(grantor.c_str(), *converter), diff --git a/src/metadata/package.h b/src/metadata/package.h index 2f4cd15d..8534e223 100644 --- a/src/metadata/package.h +++ b/src/metadata/package.h @@ -82,7 +82,7 @@ class Package : public MetadataItem wxString getAlterHeader(); wxString getAlterBody(); - std::vector* getPrivileges(); + std::vector* getPrivileges(bool splitPerGrantor=true); void checkDependentPackage(); diff --git a/src/metadata/privilege.cpp b/src/metadata/privilege.cpp index 09f61d14..70ea0ab2 100644 --- a/src/metadata/privilege.cpp +++ b/src/metadata/privilege.cpp @@ -150,9 +150,11 @@ wxString Privilege::getSql(bool withGrantOption) const Identifier id(granteeM); ret += parentObjectM->getQuotedName() + " TO " + granteeTypeToString(granteeTypeM) + " " + id.getQuoted(); - + if (withGrantOption) ret += " WITH GRANT OPTION"; + + ret += " GRANTED BY "+ (privilegeItemsM.begin())->second.grantor; ret += ";\n"; return ret; } @@ -173,6 +175,7 @@ wxString Privilege::getSql() const break; } } + ret += " GRANTED BY " + (privilegeItemsM.begin())->second.grantor; ret += ";\n"; return ret; } diff --git a/src/metadata/procedure.cpp b/src/metadata/procedure.cpp index 3ceee032..731f24b7 100644 --- a/src/metadata/procedure.cpp +++ b/src/metadata/procedure.cpp @@ -497,7 +497,7 @@ void Procedure::checkDependentProcedures() } } -std::vector* Procedure::getPrivileges() +std::vector* Procedure::getPrivileges(bool splitPerGrantor) { // load privileges from database and return the pointer to collection DatabasePtr db = getDatabase(); @@ -517,11 +517,12 @@ std::vector* Procedure::getPrivileges() "RDB$GRANT_OPTION, RDB$FIELD_NAME " "from RDB$USER_PRIVILEGES " "where RDB$RELATION_NAME = ? and rdb$object_type = 5 " - "order by rdb$user, rdb$user_type, rdb$privilege" + "order by rdb$user, rdb$user_type, rdb$grantor, rdb$privilege" ); st1->Set(1, wx2std(getName_(), converter)); st1->Execute(); std::string lastuser; + std::string lastGrantor; int lasttype = -1; Privilege *pr = 0; while (st1->Fetch()) @@ -535,13 +536,14 @@ std::vector* Procedure::getPrivileges() if (!st1->IsNull(5)) st1->Get(5, grantoption); st1->Get(6, field); - if (!pr || user != lastuser || usertype != lasttype) + if (!pr || user != lastuser || usertype != lasttype || (splitPerGrantor && grantor != lastGrantor)) { Privilege p(this, std2wxIdentifier(user, converter), usertype); privilegesM.push_back(p); pr = &privilegesM.back(); lastuser = user; + lastGrantor = grantor; lasttype = usertype; } pr->addPrivilege(privilege[0], wxString(grantor.c_str(), *converter), diff --git a/src/metadata/procedure.h b/src/metadata/procedure.h index e39e751c..863992a8 100644 --- a/src/metadata/procedure.h +++ b/src/metadata/procedure.h @@ -61,7 +61,7 @@ class Procedure : public MetadataItem wxString getDefinition(); // used for calltip in sql editor wxString getSqlSecurity(); - std::vector* getPrivileges(); + std::vector* getPrivileges(bool splitPerGrantor=true); void checkDependentProcedures(); diff --git a/src/metadata/relation.cpp b/src/metadata/relation.cpp index 8f54afe4..b4ce2bb9 100644 --- a/src/metadata/relation.cpp +++ b/src/metadata/relation.cpp @@ -589,7 +589,7 @@ wxString Relation::getRebuildSql(const wxString& forColumn) return sql; } -std::vector* Relation::getPrivileges() +std::vector* Relation::getPrivileges(bool splitPerGrantor) { // load privileges from database and return the pointer to collection DatabasePtr db = getDatabase(); @@ -610,11 +610,12 @@ std::vector* Relation::getPrivileges() "RDB$GRANT_OPTION, RDB$FIELD_NAME " "from RDB$USER_PRIVILEGES " "where RDB$RELATION_NAME = ? and rdb$object_type = 0 " - "order by rdb$user, rdb$user_type, rdb$grant_option, rdb$privilege" + "order by rdb$user, rdb$user_type, rdb$grantor, rdb$grant_option, rdb$privilege" ); st1->Set(1, wx2std(getName_(), converter)); st1->Execute(); std::string lastuser; + std::string lastGrantor; int lasttype = -1; Privilege *pr = 0; while (st1->Fetch()) @@ -628,12 +629,13 @@ std::vector* Relation::getPrivileges() if (!st1->IsNull(5)) st1->Get(5, grantoption); st1->Get(6, field); - if (!pr || user != lastuser || usertype != lasttype) + if (!pr || user != lastuser || usertype != lasttype || (splitPerGrantor && grantor != lastGrantor)) { Privilege p(this, wxString(user.c_str(), *converter).Strip(), usertype); privilegesM.push_back(p); pr = &privilegesM.back(); lastuser = user; + lastGrantor = grantor; lasttype = usertype; } pr->addPrivilege(privilege[0], std2wxIdentifier(grantor, converter), diff --git a/src/metadata/relation.h b/src/metadata/relation.h index 7219b0b5..2f278530 100644 --- a/src/metadata/relation.h +++ b/src/metadata/relation.h @@ -83,7 +83,7 @@ class Relation: public MetadataItem ColumnPtr findColumn(const wxString& name) const; wxString getRebuildSql(const wxString& forColumn = ""); - std::vector* getPrivileges(); + std::vector* getPrivileges(bool splitPerGrantor=true); bool getChildren(std::vector& temp); void getTriggers(std::vector& list, Trigger::FiringTime time); diff --git a/src/metadata/role.cpp b/src/metadata/role.cpp index 7e204898..76984004 100644 --- a/src/metadata/role.cpp +++ b/src/metadata/role.cpp @@ -45,7 +45,7 @@ Role::Role(DatabasePtr database, const wxString& name) { } -std::vector* Role::getPrivileges() +std::vector* Role::getPrivileges(bool splitPerGrantor) { // load privileges from database and return the pointer to collection DatabasePtr db = getDatabase(); @@ -64,11 +64,12 @@ std::vector* Role::getPrivileges() "RDB$GRANT_OPTION " "from RDB$USER_PRIVILEGES " "where RDB$RELATION_NAME = ? and rdb$object_type = 13 " - "order by rdb$user, rdb$user_type, rdb$privilege" + "order by rdb$user, rdb$user_type, rdb$grantor, rdb$grant_option, rdb$privilege" ); st1->Set(1, wx2std(getName_(), db->getCharsetConverter())); st1->Execute(); std::string lastuser; + std::string lastGrantor; int lasttype = -1; Privilege *pr = 0; while (st1->Fetch()) @@ -81,12 +82,13 @@ std::vector* Role::getPrivileges() st1->Get(4, privilege); if (!st1->IsNull(5)) st1->Get(5, grantoption); - if (!pr || user != lastuser || usertype != lasttype) + if (!pr || user != lastuser || usertype != lasttype || (splitPerGrantor && grantor != lastGrantor)) { Privilege p(this, wxString(user).Strip(), usertype); privilegesM.push_back(p); pr = &privilegesM.back(); lastuser = user; + lastGrantor = grantor; lasttype = usertype; } pr->addPrivilege(privilege[0], wxString(grantor).Strip(), diff --git a/src/metadata/role.h b/src/metadata/role.h index 766c1c8e..13db9c2f 100644 --- a/src/metadata/role.h +++ b/src/metadata/role.h @@ -40,7 +40,7 @@ class Role: public MetadataItem public: Role(DatabasePtr database, const wxString& name); wxString getOwner(); - std::vector* getPrivileges(); + std::vector* getPrivileges(bool splitPerGrantor=true); virtual const wxString getTypeName() const; virtual void acceptVisitor(MetadataItemVisitor* visitor); };