diff --git a/pgadmin/dlg/dlgDatabase.cpp b/pgadmin/dlg/dlgDatabase.cpp index 40014f1..26aaeaf 100644 --- a/pgadmin/dlg/dlgDatabase.cpp +++ b/pgadmin/dlg/dlgDatabase.cpp @@ -89,6 +89,15 @@ dlgDatabase::dlgDatabase(pgaFactory *f, frmMain *frame, pgDatabase *node) dirtyVars = false; seclabelPage = new ctlSeclabelPanel(nbNotebook); + + if (!node) + { + int icon = PGICON_PUBLIC; + wxString name = wxT("public"); + wxString value = wxT("Tc"); + securityPage->lbPrivileges->AppendItem(icon, name, value); + AppendCurrentAcl(name, value); + } } pgObject *dlgDatabase::GetObject() diff --git a/pgadmin/dlg/dlgFunction.cpp b/pgadmin/dlg/dlgFunction.cpp index b716f83..395923b 100644 --- a/pgadmin/dlg/dlgFunction.cpp +++ b/pgadmin/dlg/dlgFunction.cpp @@ -135,6 +135,15 @@ dlgFunction::dlgFunction(pgaFactory *f, frmMain *frame, pgFunction *node, pgSche txtArguments->Disable(); + if (!node) + { + int icon = PGICON_PUBLIC; + wxString name = wxT("public"); + wxString value = wxT("X"); + securityPage->lbPrivileges->AppendItem(icon, name, value); + AppendCurrentAcl(name, value); + } + bool bVal; settings->Read(wxT("frmQuery/ShowLineNumber"), &bVal, false); if (!bVal) diff --git a/pgadmin/dlg/dlgLanguage.cpp b/pgadmin/dlg/dlgLanguage.cpp index 131d700..1b32d96 100644 --- a/pgadmin/dlg/dlgLanguage.cpp +++ b/pgadmin/dlg/dlgLanguage.cpp @@ -45,6 +45,15 @@ dlgLanguage::dlgLanguage(pgaFactory *f, frmMain *frame, pgLanguage *node, pgObje { language = node; seclabelPage = new ctlSeclabelPanel(nbNotebook); + + if (!node) + { + int icon = PGICON_PUBLIC; + wxString name = wxT("public"); + wxString value = wxT("U"); + securityPage->lbPrivileges->AppendItem(icon, name, value); + AppendCurrentAcl(name, value); + } } pgObject *dlgLanguage::GetObject() diff --git a/pgadmin/dlg/dlgProperty.cpp b/pgadmin/dlg/dlgProperty.cpp index 9e04586..15913ad 100644 --- a/pgadmin/dlg/dlgProperty.cpp +++ b/pgadmin/dlg/dlgProperty.cpp @@ -1827,6 +1827,24 @@ dlgSecurityProperty::dlgSecurityProperty(pgaFactory *f, frmMain *frame, pgObject currentAcl.Add(name + wxT("=") + value); } } + else + { + int icon = PGICON_PUBLIC; + wxString name = wxT("public"); + wxString value; + if (obj->GetMetaType() == PGM_DATABASE) + value = wxT("Tc"); + else if (obj->GetMetaType() == PGM_FUNCTION) + value = wxT("X"); + else if (obj->GetMetaType() == PGM_LANGUAGE) + value = wxT("U"); + + if (value != wxEmptyString) + { + securityPage->lbPrivileges->AppendItem(icon, name, value); + currentAcl.Add(name + wxT("=") + value); + } + } } } else @@ -1967,6 +1985,12 @@ bool dlgSecurityProperty::DisablePrivilege(const wxString &priv) return true; } +void dlgSecurityProperty::AppendCurrentAcl(const wxString &name, const wxString &value) +{ + if (!(name.IsEmpty() && value.IsEmpty())) + currentAcl.Add(name + wxT("=") + value); +} + ///////////////////////////////////////////////////////////////////////////// diff --git a/pgadmin/include/dlg/dlgProperty.h b/pgadmin/include/dlg/dlgProperty.h index 485489f..b4b8a3e 100644 --- a/pgadmin/include/dlg/dlgProperty.h +++ b/pgadmin/include/dlg/dlgProperty.h @@ -262,6 +262,7 @@ protected: virtual int Go(bool modal = false); bool DisablePrivilege(const wxString &priv); void SetPrivilegesLayout(); + void AppendCurrentAcl(const wxString &name, const wxString &value); #ifdef __WXMAC__ void OnChangeSize(wxSizeEvent &ev); diff --git a/pgadmin/include/utils/misc.h b/pgadmin/include/utils/misc.h index 711e188..57fbfce 100644 --- a/pgadmin/include/utils/misc.h +++ b/pgadmin/include/utils/misc.h @@ -245,7 +245,9 @@ enum SLM_SEQUENCE, SLM_SET, SLM_SUBSCRIPTION, - SLM_TABLE + SLM_TABLE, + + PGM_LANGUAGE }; diff --git a/pgadmin/schema/pgLanguage.cpp b/pgadmin/schema/pgLanguage.cpp index ad95cc3..934e735 100644 --- a/pgadmin/schema/pgLanguage.cpp +++ b/pgadmin/schema/pgLanguage.cpp @@ -268,6 +268,7 @@ wxString pgLanguageCollection::GetTranslatedMessage(int kindOfMessage) const pgLanguageFactory::pgLanguageFactory() : pgDatabaseObjFactory(__("Language"), __("New Language..."), __("Create a new Language."), language_png_img, language_sm_png_img) { + metaType = PGM_LANGUAGE; } pgCollection *pgLanguageFactory::CreateCollection(pgObject *obj) diff --git a/pgadmin/schema/pgObject.cpp b/pgadmin/schema/pgObject.cpp index 15fafe9..5af08e1 100644 --- a/pgadmin/schema/pgObject.cpp +++ b/pgadmin/schema/pgObject.cpp @@ -1022,7 +1022,8 @@ wxString pgObject::GetPrivileges(const wxString &allPattern, const wxString &str wxString pgObject::GetGrant(const wxString &allPattern, const wxString &_grantFor, const wxString &_column) { - wxString grant, str, user, grantFor; + wxString grant, str, user, grantFor, tmpUser; + if (_grantFor.IsNull()) { grantFor = GetTypeName(); @@ -1041,6 +1042,11 @@ wxString pgObject::GetGrant(const wxString &allPattern, const wxString &_grantFo } else { + // checks if certain privilege is granted to public + bool grantedToPublic = false; + // checks if certain privilege is granted to owner + bool grantedToOwner = false; + queryTokenizer acls(acl.Mid(1, acl.Length() - 2), ','); while (acls.HasMoreTokens()) { @@ -1051,11 +1057,15 @@ wxString pgObject::GetGrant(const wxString &allPattern, const wxString &_grantFo user = str.BeforeFirst('='); str = str.AfterFirst('=').BeforeFirst('/'); if (user == wxT("")) + { user = wxT("public"); + grantedToPublic = true; + } else { if (user.Left(6) == wxT("group ")) { + tmpUser = user.Mid(6); if (user.Mid(6).StartsWith(wxT("\\\"")) && user.Mid(6).EndsWith(wxT("\\\""))) user = wxT("GROUP ") + qtIdent(user.Mid(8, user.Length() - 10)); else @@ -1063,15 +1073,31 @@ wxString pgObject::GetGrant(const wxString &allPattern, const wxString &_grantFo } else { + tmpUser = user; if (user.StartsWith(wxT("\\\"")) && user.EndsWith(wxT("\\\""))) user = qtIdent(user.Mid(2, user.Length() - 4)); else user = qtIdent(user); } + + if (tmpUser.Contains(owner)) + grantedToOwner = true; } grant += GetPrivileges(allPattern, str, grantFor, user, qtIdent(_column)); } + + str = wxEmptyString; + int metaType = GetMetaType(); + + // We check here that whether the user has revoked prvileges granted to databases, functions + // and languages. If so then this must be part of reverse engineered sql statement + if (!grantedToPublic && (metaType == PGM_LANGUAGE || metaType == PGM_FUNCTION || metaType == PGM_DATABASE)) + grant += GetPrivileges(allPattern, str, grantFor, wxT("public"), qtIdent(_column)); + // We check here that whether the owner has revoked prvileges on himself to this postgres + // object. If so then this must be part of reverse engineered sql statement + if (!grantedToOwner) + grant += GetPrivileges(allPattern, str, grantFor, qtIdent(owner), qtIdent(_column)); } } return grant;