User: hr Date: 06/06/19 18:11:18 Modified: /dba/connectivity/source/drivers/adabas/ BUser.cxx
Log: INTEGRATION: CWS warnings01 (1.14.30); FILE MERGED 2005/12/22 11:44:30 fs 1.14.30.2: #i57457# warning-free code 2005/11/16 12:58:50 fs 1.14.30.1: #i57457# warning free code File Changes: Directory: /dba/connectivity/source/drivers/adabas/ =================================================== File [changed]: BUser.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/adabas/BUser.cxx?r1=1.14&r2=1.15 Delta lines: +49 -59 --------------------- --- BUser.cxx 8 Sep 2005 05:24:40 -0000 1.14 +++ BUser.cxx 20 Jun 2006 01:11:15 -0000 1.15 @@ -143,15 +143,18 @@ // ----------------------------------------------------------------------------- sal_Int32 SAL_CALL OAdabasUser::getPrivileges( const ::rtl::OUString& objName, sal_Int32 objType ) throw(SQLException, RuntimeException) { + if ( objType != PrivilegeObject::TABLE ) + return 0; + ::osl::MutexGuard aGuard(m_aMutex); checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); sal_Int32 nRights,nRightsWithGrant; - findPrivilegesAndGrantPrivileges(objName,objType,nRights,nRightsWithGrant); + getAnyTablePrivileges(objName,nRights,nRightsWithGrant); return nRights; } // ----------------------------------------------------------------------------- -void OAdabasUser::findPrivilegesAndGrantPrivileges(const ::rtl::OUString& objName, sal_Int32 objType,sal_Int32& nRights,sal_Int32& nRightsWithGrant) throw(SQLException, RuntimeException) +void OAdabasUser::getAnyTablePrivileges(const ::rtl::OUString& objName, sal_Int32& nRights,sal_Int32& nRightsWithGrant) throw(SQLException, RuntimeException) { nRightsWithGrant = nRights = 0; // first we need to create the sql stmt to select the privs @@ -173,50 +176,29 @@ if(xRow.is() && xRes->next()) { ::rtl::OUString sPrivs = xRow->getString(2); - static const ::rtl::OUString sInsert = ::rtl::OUString::createFromAscii("INS"); - static const ::rtl::OUString sDelete = ::rtl::OUString::createFromAscii("DEL"); - static const ::rtl::OUString sUpdate = ::rtl::OUString::createFromAscii("UPD"); - static const ::rtl::OUString sAlter = ::rtl::OUString::createFromAscii("ALT"); - static const ::rtl::OUString sSelect = ::rtl::OUString::createFromAscii("SEL"); - static const ::rtl::OUString sReference = ::rtl::OUString::createFromAscii("REF"); - static const ::rtl::OUString sGrant = ::rtl::OUString::createFromAscii("+"); - sal_Int32 nIndex = -1; - if(nIndex = sPrivs.indexOf(sInsert) != -1) - { - nRights |= Privilege::INSERT; - if(sGrant == sPrivs.copy(nIndex+2,1)) - nRightsWithGrant |= Privilege::INSERT; - } - if(nIndex = sPrivs.indexOf(sDelete) != -1) - { - nRights |= Privilege::DELETE; - if(sGrant == sPrivs.copy(nIndex+2,1)) - nRightsWithGrant |= Privilege::DELETE; - } - if(nIndex = sPrivs.indexOf(sUpdate) != -1) - { - nRights |= Privilege::UPDATE; - if(sGrant == sPrivs.copy(nIndex+2,1)) - nRightsWithGrant |= Privilege::UPDATE; - } - if(nIndex = sPrivs.indexOf(sAlter) != -1) + struct _priv_nam { - nRights |= Privilege::ALTER; - if(sGrant == sPrivs.copy(nIndex+2,1)) - nRightsWithGrant |= Privilege::ALTER; - } - if(nIndex = sPrivs.indexOf(sSelect) != -1) - { - nRights |= Privilege::SELECT; - if(sGrant == sPrivs.copy(nIndex+2,1)) - nRightsWithGrant |= Privilege::SELECT; - } - if(nIndex = sPrivs.indexOf(sReference) != -1) - { - nRights |= Privilege::REFERENCE; - if(sGrant == sPrivs.copy(nIndex+2,1)) - nRightsWithGrant |= Privilege::REFERENCE; + const sal_Char* pAsciiName; + sal_Int32 nNumericValue; + } privileges[] = + { + { "INS", Privilege::INSERT }, + { "DEL", Privilege::DELETE }, + { "UPD", Privilege::UPDATE }, + { "ALT", Privilege::ALTER }, + { "SEL", Privilege::SELECT }, + { "REF", Privilege::REFERENCE } + }; + for ( size_t i = 0; i < sizeof( privileges ) / sizeof( privileges[0] ); ++i ) + { + sal_Int32 nIndex = sPrivs.indexOf( ::rtl::OUString::createFromAscii( privileges[i].pAsciiName ) ); + if ( nIndex == -1 ) + continue; + + nRights |= privileges[i].nNumericValue; + if ( sPrivs.copy( nIndex + 2, 1 ).equalsAscii( "+" ) ) + nRightsWithGrant |= privileges[i].nNumericValue; } } ::comphelper::disposeComponent(xRes); @@ -227,18 +209,23 @@ // ------------------------------------------------------------------------- sal_Int32 SAL_CALL OAdabasUser::getGrantablePrivileges( const ::rtl::OUString& objName, sal_Int32 objType ) throw(SQLException, RuntimeException) { + if ( objType != PrivilegeObject::TABLE ) + return 0; + ::osl::MutexGuard aGuard(m_aMutex); checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); sal_Int32 nRights,nRightsWithGrant; - findPrivilegesAndGrantPrivileges(objName,objType,nRights,nRightsWithGrant); + getAnyTablePrivileges(objName,nRights,nRightsWithGrant); return nRightsWithGrant; } // ------------------------------------------------------------------------- void SAL_CALL OAdabasUser::grantPrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) throw(SQLException, RuntimeException) { - ::osl::MutexGuard aGuard(m_aMutex); + if ( objType != PrivilegeObject::TABLE ) + ::dbtools::throwSQLException( "Privilege not granted: Only table privileges can be granted", "01007", *this ); + ::osl::MutexGuard aGuard(m_aMutex); ::rtl::OUString sPrivs = getPrivilegeString(objPrivileges); if(sPrivs.getLength()) { @@ -260,6 +247,9 @@ // ------------------------------------------------------------------------- void SAL_CALL OAdabasUser::revokePrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) throw(SQLException, RuntimeException) { + if ( objType != PrivilegeObject::TABLE ) + ::dbtools::throwSQLException( "Privilege not revoked: Only table privileges can be revoked", "01006", *this ); + ::osl::MutexGuard aGuard(m_aMutex); checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); ::rtl::OUString sPrivs = getPrivilegeString(objPrivileges); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
