diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2012-03-27 10:49:49 +0200 |
---|---|---|
committer | Lionel Elie Mamane <lionel@mamane.lu> | 2012-03-27 10:52:47 +0200 |
commit | 077e711b5f5f19fceed44e2d992bf5c027e75ab6 (patch) | |
tree | bca8c8677f57afc96bf24ce4fc5100b693f4c8be /connectivity | |
parent | 31d0dcfa76cc89afb214304dae556226f490421f (diff) |
fdo#47937: copy column privileges into table privileges
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/commontools/dbtools2.cxx | 73 |
1 files changed, 62 insertions, 11 deletions
diff --git a/connectivity/source/commontools/dbtools2.cxx b/connectivity/source/commontools/dbtools2.cxx index e5598472b84e..1ad898560b73 100644 --- a/connectivity/source/commontools/dbtools2.cxx +++ b/connectivity/source/commontools/dbtools2.cxx @@ -674,19 +674,20 @@ sal_Int32 getTablePrivileges(const Reference< XDatabaseMetaData>& _xMetaData, Reference< XResultSet > xPrivileges = _xMetaData->getTablePrivileges(aVal, _sSchema, _sTable); Reference< XRow > xCurrentRow(xPrivileges, UNO_QUERY); + const ::rtl::OUString sUserWorkingFor = _xMetaData->getUserName(); + static const ::rtl::OUString sSELECT( RTL_CONSTASCII_USTRINGPARAM( "SELECT" )); + static const ::rtl::OUString sINSERT( RTL_CONSTASCII_USTRINGPARAM( "INSERT" )); + static const ::rtl::OUString sUPDATE( RTL_CONSTASCII_USTRINGPARAM( "UPDATE" )); + static const ::rtl::OUString sDELETE( RTL_CONSTASCII_USTRINGPARAM( "DELETE" )); + static const ::rtl::OUString sREAD( RTL_CONSTASCII_USTRINGPARAM( "READ" )); + static const ::rtl::OUString sCREATE( RTL_CONSTASCII_USTRINGPARAM( "CREATE" )); + static const ::rtl::OUString sALTER( RTL_CONSTASCII_USTRINGPARAM( "ALTER" )); + static const ::rtl::OUString sREFERENCE( RTL_CONSTASCII_USTRINGPARAM( "REFERENCE" )); + static const ::rtl::OUString sDROP( RTL_CONSTASCII_USTRINGPARAM( "DROP" )); + if ( xCurrentRow.is() ) { - ::rtl::OUString sUserWorkingFor = _xMetaData->getUserName(); - static const ::rtl::OUString sSELECT( RTL_CONSTASCII_USTRINGPARAM( "SELECT" )); - static const ::rtl::OUString sINSERT( RTL_CONSTASCII_USTRINGPARAM( "INSERT" )); - static const ::rtl::OUString sUPDATE( RTL_CONSTASCII_USTRINGPARAM( "UPDATE" )); - static const ::rtl::OUString sDELETE( RTL_CONSTASCII_USTRINGPARAM( "DELETE" )); - static const ::rtl::OUString sREAD( RTL_CONSTASCII_USTRINGPARAM( "READ" )); - static const ::rtl::OUString sCREATE( RTL_CONSTASCII_USTRINGPARAM( "CREATE" )); - static const ::rtl::OUString sALTER( RTL_CONSTASCII_USTRINGPARAM( "ALTER" )); - static const ::rtl::OUString sREFERENCE( RTL_CONSTASCII_USTRINGPARAM( "REFERENCE" )); - static const ::rtl::OUString sDROP( RTL_CONSTASCII_USTRINGPARAM( "DROP" )); - // after creation the set is positioned before the first record, per definitionem + // after creation the set is positioned before the first record, per definition #ifdef DBG_UTIL Reference< XResultSetMetaDataSupplier > xSup(xPrivileges,UNO_QUERY); if ( xSup.is() ) @@ -743,6 +744,56 @@ sal_Int32 getTablePrivileges(const Reference< XDatabaseMetaData>& _xMetaData, } } disposeComponent(xPrivileges); + + // Some drivers put a table privilege as soon as any column has the privilege, + // some drivers only if all columns have the privilege. + // To unifiy the situation, collect column privileges here, too. + Reference< XResultSet > xColumnPrivileges = _xMetaData->getColumnPrivileges(aVal, _sSchema, _sTable, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%"))); + Reference< XRow > xColumnCurrentRow(xColumnPrivileges, UNO_QUERY); + if ( xColumnCurrentRow.is() ) + { + // after creation the set is positioned before the first record, per definition + ::rtl::OUString sPrivilege, sGrantee; + while ( xColumnPrivileges->next() ) + { +#ifdef DBG_UTIL + ::rtl::OUString sCat, sSchema, sTableName, sColumnName, sGrantor, sGrantable; + sCat = xColumnCurrentRow->getString(1); + sSchema = xColumnCurrentRow->getString(2); + sTableName = xColumnCurrentRow->getString(3); + sColumnName = xColumnCurrentRow->getString(4); + sGrantor = xColumnCurrentRow->getString(5); +#endif + sGrantee = xColumnCurrentRow->getString(6); + sPrivilege = xColumnCurrentRow->getString(7); +#ifdef DBG_UTIL + sGrantable = xColumnCurrentRow->getString(8); +#endif + + if (!sUserWorkingFor.equalsIgnoreAsciiCase(sGrantee)) + continue; + + if (sPrivilege.equalsIgnoreAsciiCase(sSELECT)) + nPrivileges |= Privilege::SELECT; + else if (sPrivilege.equalsIgnoreAsciiCase(sINSERT)) + nPrivileges |= Privilege::INSERT; + else if (sPrivilege.equalsIgnoreAsciiCase(sUPDATE)) + nPrivileges |= Privilege::UPDATE; + else if (sPrivilege.equalsIgnoreAsciiCase(sDELETE)) + nPrivileges |= Privilege::DELETE; + else if (sPrivilege.equalsIgnoreAsciiCase(sREAD)) + nPrivileges |= Privilege::READ; + else if (sPrivilege.equalsIgnoreAsciiCase(sCREATE)) + nPrivileges |= Privilege::CREATE; + else if (sPrivilege.equalsIgnoreAsciiCase(sALTER)) + nPrivileges |= Privilege::ALTER; + else if (sPrivilege.equalsIgnoreAsciiCase(sREFERENCE)) + nPrivileges |= Privilege::REFERENCE; + else if (sPrivilege.equalsIgnoreAsciiCase(sDROP)) + nPrivileges |= Privilege::DROP; + } + } + disposeComponent(xColumnPrivileges); } catch(const SQLException& e) { |