fdo#47937: copy column privileges into table privileges
This commit is contained in:
@@ -674,9 +674,7 @@ sal_Int32 getTablePrivileges(const Reference< XDatabaseMetaData>& _xMetaData,
|
|||||||
Reference< XResultSet > xPrivileges = _xMetaData->getTablePrivileges(aVal, _sSchema, _sTable);
|
Reference< XResultSet > xPrivileges = _xMetaData->getTablePrivileges(aVal, _sSchema, _sTable);
|
||||||
Reference< XRow > xCurrentRow(xPrivileges, UNO_QUERY);
|
Reference< XRow > xCurrentRow(xPrivileges, UNO_QUERY);
|
||||||
|
|
||||||
if ( xCurrentRow.is() )
|
const ::rtl::OUString sUserWorkingFor = _xMetaData->getUserName();
|
||||||
{
|
|
||||||
::rtl::OUString sUserWorkingFor = _xMetaData->getUserName();
|
|
||||||
static const ::rtl::OUString sSELECT( RTL_CONSTASCII_USTRINGPARAM( "SELECT" ));
|
static const ::rtl::OUString sSELECT( RTL_CONSTASCII_USTRINGPARAM( "SELECT" ));
|
||||||
static const ::rtl::OUString sINSERT( RTL_CONSTASCII_USTRINGPARAM( "INSERT" ));
|
static const ::rtl::OUString sINSERT( RTL_CONSTASCII_USTRINGPARAM( "INSERT" ));
|
||||||
static const ::rtl::OUString sUPDATE( RTL_CONSTASCII_USTRINGPARAM( "UPDATE" ));
|
static const ::rtl::OUString sUPDATE( RTL_CONSTASCII_USTRINGPARAM( "UPDATE" ));
|
||||||
@@ -686,7 +684,10 @@ sal_Int32 getTablePrivileges(const Reference< XDatabaseMetaData>& _xMetaData,
|
|||||||
static const ::rtl::OUString sALTER( RTL_CONSTASCII_USTRINGPARAM( "ALTER" ));
|
static const ::rtl::OUString sALTER( RTL_CONSTASCII_USTRINGPARAM( "ALTER" ));
|
||||||
static const ::rtl::OUString sREFERENCE( RTL_CONSTASCII_USTRINGPARAM( "REFERENCE" ));
|
static const ::rtl::OUString sREFERENCE( RTL_CONSTASCII_USTRINGPARAM( "REFERENCE" ));
|
||||||
static const ::rtl::OUString sDROP( RTL_CONSTASCII_USTRINGPARAM( "DROP" ));
|
static const ::rtl::OUString sDROP( RTL_CONSTASCII_USTRINGPARAM( "DROP" ));
|
||||||
// after creation the set is positioned before the first record, per definitionem
|
|
||||||
|
if ( xCurrentRow.is() )
|
||||||
|
{
|
||||||
|
// after creation the set is positioned before the first record, per definition
|
||||||
#ifdef DBG_UTIL
|
#ifdef DBG_UTIL
|
||||||
Reference< XResultSetMetaDataSupplier > xSup(xPrivileges,UNO_QUERY);
|
Reference< XResultSetMetaDataSupplier > xSup(xPrivileges,UNO_QUERY);
|
||||||
if ( xSup.is() )
|
if ( xSup.is() )
|
||||||
@@ -743,6 +744,56 @@ sal_Int32 getTablePrivileges(const Reference< XDatabaseMetaData>& _xMetaData,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
disposeComponent(xPrivileges);
|
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)
|
catch(const SQLException& e)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user