diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2018-10-08 11:04:48 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2018-10-25 14:52:44 +0200 |
commit | 36defede63afe94e9bc6872eac955757c49452c1 (patch) | |
tree | 22808dc57e280b96da66d96190e50dea826236c9 /connectivity | |
parent | e840ab22b71898c07a4d44dbeae250f93b7b5983 (diff) |
Revert removal of mysql jdbc connector
And also make some minor fixes so it cooperates with the new mysqlc
library.
Change-Id: I866add99a699150c6550ee7f7ff2ee947e07117c
Reviewed-on: https://gerrit.libreoffice.org/61648
Tested-by: Jenkins
Reviewed-by: Tamás Bunth <btomi96@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/62318
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/Configuration_mysql.mk | 8 | ||||
-rw-r--r-- | connectivity/Configuration_mysqlc.mk | 20 | ||||
-rw-r--r-- | connectivity/Library_mysql.mk | 32 | ||||
-rw-r--r-- | connectivity/Module_connectivity.mk | 5 | ||||
-rw-r--r-- | connectivity/registry/mysql/org/openoffice/Office/DataAccess/Drivers.xcu | 249 | ||||
-rw-r--r-- | connectivity/source/drivers/mysql/YUser.cxx | 320 | ||||
-rw-r--r-- | connectivity/source/drivers/mysql/mysql.component | 26 |
7 files changed, 652 insertions, 8 deletions
diff --git a/connectivity/Configuration_mysql.mk b/connectivity/Configuration_mysql.mk index 5ef54c70a80c..1cb07ca71441 100644 --- a/connectivity/Configuration_mysql.mk +++ b/connectivity/Configuration_mysql.mk @@ -7,13 +7,13 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. # -$(eval $(call gb_Configuration_Configuration,driver_mysqlc)) +$(eval $(call gb_Configuration_Configuration,driver_mysql)) -$(eval $(call gb_Configuration_add_spool_modules,driver_mysqlc,connectivity/registry/mysqlc,\ - org/openoffice/Office/DataAccess/Drivers-mysqlc.xcu \ +$(eval $(call gb_Configuration_add_spool_modules,driver_mysql,connectivity/registry/mysql,\ + org/openoffice/Office/DataAccess/Drivers-mysql.xcu \ )) -$(eval $(call gb_Configuration_add_localized_datas,driver_mysqlc,connectivity/registry/mysqlc,\ +$(eval $(call gb_Configuration_add_localized_datas,driver_mysql,connectivity/registry/mysql,\ org/openoffice/Office/DataAccess/Drivers.xcu \ )) diff --git a/connectivity/Configuration_mysqlc.mk b/connectivity/Configuration_mysqlc.mk new file mode 100644 index 000000000000..5ef54c70a80c --- /dev/null +++ b/connectivity/Configuration_mysqlc.mk @@ -0,0 +1,20 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Configuration_Configuration,driver_mysqlc)) + +$(eval $(call gb_Configuration_add_spool_modules,driver_mysqlc,connectivity/registry/mysqlc,\ + org/openoffice/Office/DataAccess/Drivers-mysqlc.xcu \ +)) + +$(eval $(call gb_Configuration_add_localized_datas,driver_mysqlc,connectivity/registry/mysqlc,\ + org/openoffice/Office/DataAccess/Drivers.xcu \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/connectivity/Library_mysql.mk b/connectivity/Library_mysql.mk index f82593c23d2e..ac3c0c2619e8 100644 --- a/connectivity/Library_mysql.mk +++ b/connectivity/Library_mysql.mk @@ -1,20 +1,48 @@ # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- # +# # This file is part of the LibreOffice project. # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this -# file, you can obtain one at http://mozilla.org/MPL/2.0/. +# file, You can obtain one at http://mozilla.org/MPL/2.0/. # $(eval $(call gb_Library_Library,mysql)) +$(eval $(call gb_Library_set_componentfile,mysql,connectivity/source/drivers/mysql/mysql)) + +$(eval $(call gb_Library_use_external,mysql,boost_headers)) + +$(eval $(call gb_Library_use_sdk_api,mysql)) + +$(eval $(call gb_Library_set_include,mysql,\ + $$(INCLUDE) \ + -I$(SRCDIR)/connectivity/inc \ + -I$(SRCDIR)/connectivity/source/inc \ +)) + +$(eval $(call gb_Library_set_precompiled_header,mysql,$(SRCDIR)/connectivity/inc/pch/precompiled_mysql)) + $(eval $(call gb_Library_use_libraries,mysql,\ + cppu \ + cppuhelper \ sal \ + salhelper \ + dbtools \ + comphelper \ )) $(eval $(call gb_Library_add_exception_objects,mysql,\ - connectivity/source/drivers/mysqlc/mysql_dummy \ + connectivity/source/drivers/mysql/YDriver \ + connectivity/source/drivers/mysql/YTables \ + connectivity/source/drivers/mysql/YTable \ + connectivity/source/drivers/mysql/YViews \ + connectivity/source/drivers/mysql/YCatalog \ + connectivity/source/drivers/mysql/YColumns \ + connectivity/source/drivers/mysql/YUser \ + connectivity/source/drivers/mysql/YUsers \ + connectivity/source/drivers/mysql/Yservices \ )) # vim: set noet sw=4 ts=4: diff --git a/connectivity/Module_connectivity.mk b/connectivity/Module_connectivity.mk index 250172e936a1..4a579ddcb43b 100644 --- a/connectivity/Module_connectivity.mk +++ b/connectivity/Module_connectivity.mk @@ -40,6 +40,8 @@ ifneq ($(ENABLE_JAVA),) $(eval $(call gb_Module_add_targets,connectivity,\ Configuration_hsqldb \ Configuration_jdbc \ + Configuration_mysql \ + Library_mysql \ Jar_sdbc_hsqldb \ Library_hsqldb \ Library_jdbc \ @@ -81,9 +83,8 @@ endif ifeq ($(ENABLE_MARIADBC),TRUE) $(eval $(call gb_Module_add_targets,connectivity,\ - Configuration_mysql \ + Configuration_mysqlc \ Library_mysqlc \ - Library_mysql \ )) endif diff --git a/connectivity/registry/mysql/org/openoffice/Office/DataAccess/Drivers.xcu b/connectivity/registry/mysql/org/openoffice/Office/DataAccess/Drivers.xcu new file mode 100644 index 000000000000..faf9ddb9fa55 --- /dev/null +++ b/connectivity/registry/mysql/org/openoffice/Office/DataAccess/Drivers.xcu @@ -0,0 +1,249 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> +<oor:component-data oor:name="Drivers" oor:package="org.openoffice.Office.DataAccess" xmlns:install="http://openoffice.org/2004/installation" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema"> + <node oor:name="Installed" install:module="mysql"> + <node oor:name="sdbc:mysql:jdbc:*" oor:op="replace"> + <prop oor:name="Driver"> + <value>org.openoffice.comp.drivers.MySQL.Driver</value> + </prop> + <prop oor:name="DriverTypeDisplayName" oor:type="xs:string"> + <value xml:lang="en-US">MySQL (JDBC)</value> + </prop> + <node oor:name="Properties"> + <node oor:name="CharSet" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:string"> + <value></value> + </prop> + </node> + <node oor:name="JavaDriverClass" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:string"> + <value>com.mysql.jdbc.Driver</value> + </prop> + </node> + <node oor:name="AddIndexAppendix" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + </node> + <node oor:name="Features"> + <node oor:name="UseKeywordAsBeforeAlias" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="IgnoreDriverPrivileges" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="DisplayVersionColumns" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="UseDOSLineEnds" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="BooleanComparisonMode" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="FormsCheckRequiredFields" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + </node> + <node oor:name="MetaData"> + <node oor:name="SupportsTableCreation" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="UseJava" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="Authentication" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:string"> + <value>UserPassword</value> + </prop> + </node> + <node oor:name="SupportsColumnDescription" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + </node> + </node> + <node oor:name="sdbc:mysql:odbc:*" oor:op="replace"> + <prop oor:name="Driver"> + <value>org.openoffice.comp.drivers.MySQL.Driver</value> + </prop> + <prop oor:name="DriverTypeDisplayName" oor:type="xs:string"> + <value xml:lang="en-US">MySQL (ODBC)</value> + </prop> + <node oor:name="Properties"> + <node oor:name="CharSet" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:string"> + <value></value> + </prop> + </node> + <node oor:name="AddIndexAppendix" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + </node> + <node oor:name="Features"> + <node oor:name="UseKeywordAsBeforeAlias" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="IgnoreDriverPrivileges" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="DisplayVersionColumns" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="UseDOSLineEnds" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="BooleanComparisonMode" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="FormsCheckRequiredFields" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + </node> + <node oor:name="MetaData"> + <node oor:name="SupportsTableCreation" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="SupportsBrowsing" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="Authentication" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:string"> + <value>UserPassword</value> + </prop> + </node> + </node> + </node> + <node oor:name="sdbc:mysql:mysqlc:*" oor:op="replace"> + <prop oor:name="Driver"> + <value>org.openoffice.comp.drivers.MySQL.Driver</value> + </prop> + <prop oor:name="DriverTypeDisplayName" oor:type="xs:string"> + <value xml:lang="en-US">MySQL (Native)</value> + </prop> + <node oor:name="Properties"> + <node oor:name="CharSet" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:string"> + <value></value> + </prop> + </node> + <node oor:name="LocalSocket" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:string"> + <value></value> + </prop> + </node> + <node oor:name="NamedPipe" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:string"> + <value></value> + </prop> + </node> + <node oor:name="AddIndexAppendix" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + </node> + <node oor:name="Features"> + <node oor:name="UseKeywordAsBeforeAlias" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="IgnoreDriverPrivileges" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="DisplayVersionColumns" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="UseDOSLineEnds" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="BooleanComparisonMode" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="FormsCheckRequiredFields" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + </node> + <node oor:name="MetaData"> + <node oor:name="SupportsTableCreation" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="Authentication" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:string"> + <value>UserPassword</value> + </prop> + </node> + <node oor:name="SupportsColumnDescription" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + </node> + </node> + </node> +</oor:component-data> diff --git a/connectivity/source/drivers/mysql/YUser.cxx b/connectivity/source/drivers/mysql/YUser.cxx new file mode 100644 index 000000000000..bc9c8c55b22e --- /dev/null +++ b/connectivity/source/drivers/mysql/YUser.cxx @@ -0,0 +1,320 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <mysql/YUser.hxx> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <connectivity/dbtools.hxx> +#include <connectivity/dbexception.hxx> +#include <com/sun/star/sdbcx/Privilege.hpp> +#include <com/sun/star/sdbcx/PrivilegeObject.hpp> +#include <TConnection.hxx> +#include <strings.hrc> + +using namespace connectivity; +using namespace connectivity::mysql; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + +OMySQLUser::OMySQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection) : connectivity::sdbcx::OUser(true) + ,m_xConnection(_xConnection) +{ + construct(); +} + +OMySQLUser::OMySQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection, + const OUString& Name + ) : connectivity::sdbcx::OUser(Name,true) + ,m_xConnection(_xConnection) +{ + construct(); +} + +void OMySQLUser::refreshGroups() +{ +} + +OUserExtend::OUserExtend( const css::uno::Reference< css::sdbc::XConnection >& _xConnection) : OMySQLUser(_xConnection) +{ + construct(); +} + +void OUserExtend::construct() +{ + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD), PROPERTY_ID_PASSWORD,0,&m_Password,::cppu::UnoType<OUString>::get()); +} + +cppu::IPropertyArrayHelper* OUserExtend::createArrayHelper() const +{ + Sequence< Property > aProps; + describeProperties(aProps); + return new cppu::OPropertyArrayHelper(aProps); +} + +cppu::IPropertyArrayHelper & OUserExtend::getInfoHelper() +{ + return *OUserExtend_PROP::getArrayHelper(); +} +typedef connectivity::sdbcx::OUser_BASE OUser_BASE_RBHELPER; + +sal_Int32 SAL_CALL OMySQLUser::getPrivileges( const OUString& objName, sal_Int32 objType ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); + + sal_Int32 nRights,nRightsWithGrant; + findPrivilegesAndGrantPrivileges(objName,objType,nRights,nRightsWithGrant); + return nRights; +} + +void OMySQLUser::findPrivilegesAndGrantPrivileges(const OUString& objName, sal_Int32 objType,sal_Int32& nRights,sal_Int32& nRightsWithGrant) +{ + nRightsWithGrant = nRights = 0; + // first we need to create the sql stmt to select the privs + Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); + OUString sCatalog,sSchema,sTable; + ::dbtools::qualifiedNameComponents(xMeta,objName,sCatalog,sSchema,sTable,::dbtools::EComposeRule::InDataManipulation); + Reference<XResultSet> xRes; + switch(objType) + { + case PrivilegeObject::TABLE: + case PrivilegeObject::VIEW: + { + Any aCatalog; + if ( !sCatalog.isEmpty() ) + aCatalog <<= sCatalog; + xRes = xMeta->getTablePrivileges(aCatalog,sSchema,sTable); + } + break; + + case PrivilegeObject::COLUMN: + { + Any aCatalog; + if ( !sCatalog.isEmpty() ) + aCatalog <<= sCatalog; + xRes = xMeta->getColumnPrivileges(aCatalog,sSchema,sTable, "%"); + } + break; + } + + if ( xRes.is() ) + { + static const char sYes [] = "YES"; + + nRightsWithGrant = nRights = 0; + + Reference<XRow> xCurrentRow(xRes,UNO_QUERY); + while( xCurrentRow.is() && xRes->next() ) + { + OUString sGrantee = xCurrentRow->getString(5); + OUString sPrivilege = xCurrentRow->getString(6); + OUString sGrantable = xCurrentRow->getString(7); + + if (!m_Name.equalsIgnoreAsciiCase(sGrantee)) + continue; + + if (sPrivilege.equalsIgnoreAsciiCase("SELECT")) + { + nRights |= Privilege::SELECT; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::SELECT; + } + else if (sPrivilege.equalsIgnoreAsciiCase("INSERT")) + { + nRights |= Privilege::INSERT; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::INSERT; + } + else if (sPrivilege.equalsIgnoreAsciiCase("UPDATE")) + { + nRights |= Privilege::UPDATE; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::UPDATE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("DELETE")) + { + nRights |= Privilege::DELETE; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::DELETE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("READ")) + { + nRights |= Privilege::READ; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::READ; + } + else if (sPrivilege.equalsIgnoreAsciiCase("CREATE")) + { + nRights |= Privilege::CREATE; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::CREATE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("ALTER")) + { + nRights |= Privilege::ALTER; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::ALTER; + } + else if (sPrivilege.equalsIgnoreAsciiCase("REFERENCES")) + { + nRights |= Privilege::REFERENCE; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::REFERENCE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("DROP")) + { + nRights |= Privilege::DROP; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::DROP; + } + } + ::comphelper::disposeComponent(xRes); + } +} + +sal_Int32 SAL_CALL OMySQLUser::getGrantablePrivileges( const OUString& objName, sal_Int32 objType ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); + + sal_Int32 nRights,nRightsWithGrant; + findPrivilegesAndGrantPrivileges(objName,objType,nRights,nRightsWithGrant); + return nRightsWithGrant; +} + +void SAL_CALL OMySQLUser::grantPrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) +{ + if ( objType != PrivilegeObject::TABLE ) + { + ::connectivity::SharedResources aResources; + const OUString sError( aResources.getResourceString(STR_PRIVILEGE_NOT_GRANTED)); + ::dbtools::throwGenericSQLException(sError,*this); + } // if ( objType != PrivilegeObject::TABLE ) + + ::osl::MutexGuard aGuard(m_aMutex); + + OUString sPrivs = getPrivilegeString(objPrivileges); + if(!sPrivs.isEmpty()) + { + Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); + OUString sGrant = "GRANT " + sPrivs + + " ON " + ::dbtools::quoteTableName(xMeta,objName,::dbtools::EComposeRule::InDataManipulation) + + " TO " + m_Name; + + Reference<XStatement> xStmt = m_xConnection->createStatement(); + if(xStmt.is()) + xStmt->execute(sGrant); + ::comphelper::disposeComponent(xStmt); + } +} + +void SAL_CALL OMySQLUser::revokePrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) +{ + if ( objType != PrivilegeObject::TABLE ) + { + ::connectivity::SharedResources aResources; + const OUString sError( aResources.getResourceString(STR_PRIVILEGE_NOT_REVOKED)); + ::dbtools::throwGenericSQLException(sError,*this); + } + + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); + OUString sPrivs = getPrivilegeString(objPrivileges); + if(!sPrivs.isEmpty()) + { + Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); + OUString sGrant = "REVOKE " + sPrivs + + " ON " + ::dbtools::quoteTableName(xMeta,objName,::dbtools::EComposeRule::InDataManipulation) + + " FROM " + m_Name; + + Reference<XStatement> xStmt = m_xConnection->createStatement(); + if(xStmt.is()) + xStmt->execute(sGrant); + ::comphelper::disposeComponent(xStmt); + } +} + +// XUser +void SAL_CALL OMySQLUser::changePassword( const OUString& /*oldPassword*/, const OUString& newPassword ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); + OUString sAlterPwd = "SET PASSWORD FOR " + + m_Name + "@\"%\" = PASSWORD('" + + newPassword + "')"; + + + Reference<XStatement> xStmt = m_xConnection->createStatement(); + if ( xStmt.is() ) + { + xStmt->execute(sAlterPwd); + ::comphelper::disposeComponent(xStmt); + } +} + +OUString OMySQLUser::getPrivilegeString(sal_Int32 nRights) +{ + OUString sPrivs; + if((nRights & Privilege::INSERT) == Privilege::INSERT) + sPrivs += "INSERT"; + + if((nRights & Privilege::DELETE) == Privilege::DELETE) + { + if(!sPrivs.isEmpty()) + sPrivs += ","; + sPrivs += "DELETE"; + } + + if((nRights & Privilege::UPDATE) == Privilege::UPDATE) + { + if(!sPrivs.isEmpty()) + sPrivs += ","; + sPrivs += "UPDATE"; + } + + if((nRights & Privilege::ALTER) == Privilege::ALTER) + { + if(!sPrivs.isEmpty()) + sPrivs += ","; + sPrivs += "ALTER"; + } + + if((nRights & Privilege::SELECT) == Privilege::SELECT) + { + if(!sPrivs.isEmpty()) + sPrivs += ","; + sPrivs += "SELECT"; + } + + if((nRights & Privilege::REFERENCE) == Privilege::REFERENCE) + { + if(!sPrivs.isEmpty()) + sPrivs += ","; + sPrivs += "REFERENCES"; + } + + return sPrivs; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysql/mysql.component b/connectivity/source/drivers/mysql/mysql.component new file mode 100644 index 000000000000..9c3e7ad7c6cd --- /dev/null +++ b/connectivity/source/drivers/mysql/mysql.component @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" + prefix="mysql" xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="org.openoffice.comp.drivers.MySQL.Driver"> + <service name="com.sun.star.sdbc.Driver"/> + <service name="com.sun.star.sdbcx.Driver"/> + </implementation> +</component> |