LCOV - code coverage report
Current view: top level - libreoffice/connectivity/source/drivers/postgresql - pq_xuser.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 66 0.0 %
Date: 2012-12-27 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*************************************************************************
       3             :  *
       4             :  *  Effective License of whole file:
       5             :  *
       6             :  *    This library is free software; you can redistribute it and/or
       7             :  *    modify it under the terms of the GNU Lesser General Public
       8             :  *    License version 2.1, as published by the Free Software Foundation.
       9             :  *
      10             :  *    This library is distributed in the hope that it will be useful,
      11             :  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13             :  *    Lesser General Public License for more details.
      14             :  *
      15             :  *    You should have received a copy of the GNU Lesser General Public
      16             :  *    License along with this library; if not, write to the Free Software
      17             :  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      18             :  *    MA  02111-1307  USA
      19             :  *
      20             :  *  Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
      21             :  *
      22             :  *    The Contents of this file are made available subject to the terms of
      23             :  *    the GNU Lesser General Public License Version 2.1
      24             :  *
      25             :  *    Copyright: 2000 by Sun Microsystems, Inc.
      26             :  *
      27             :  *    Contributor(s): Joerg Budischewski
      28             :  *
      29             :  *  All parts contributed on or after August 2011:
      30             :  *
      31             :  *    Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
      32             :  *
      33             :  *    The contents of this file are subject to the Mozilla Public License Version
      34             :  *    1.1 (the "License"); you may not use this file except in compliance with
      35             :  *    the License or as specified alternatively below. You may obtain a copy of
      36             :  *    the License at http://www.mozilla.org/MPL/
      37             :  *
      38             :  *    Software distributed under the License is distributed on an "AS IS" basis,
      39             :  *    WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      40             :  *    for the specific language governing rights and limitations under the
      41             :  *    License.
      42             :  *
      43             :  *    Major Contributor(s):
      44             :  *    [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
      45             :  *
      46             :  *    All Rights Reserved.
      47             :  *
      48             :  *    For minor contributions see the git repository.
      49             :  *
      50             :  *    Alternatively, the contents of this file may be used under the terms of
      51             :  *    either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      52             :  *    the GNU Lesser General Public License Version 2.1 or later (the "LGPLv2.1+"),
      53             :  *    in which case the provisions of the GPLv3+ or the LGPLv2.1+ are applicable
      54             :  *    instead of those above.
      55             :  *
      56             :  ************************************************************************/
      57             : 
      58             : #include <rtl/ustrbuf.hxx>
      59             : 
      60             : #include <cppuhelper/typeprovider.hxx>
      61             : #include <cppuhelper/queryinterface.hxx>
      62             : 
      63             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      64             : 
      65             : #include <com/sun/star/sdbc/XRow.hpp>
      66             : #include <com/sun/star/sdbc/XParameters.hpp>
      67             : 
      68             : #include "pq_xuser.hxx"
      69             : #include "pq_tools.hxx"
      70             : #include "pq_statics.hxx"
      71             : 
      72             : using osl::MutexGuard;
      73             : using osl::Mutex;
      74             : 
      75             : using rtl::OUString;
      76             : using rtl::OUStringBuffer;
      77             : 
      78             : using com::sun::star::container::XNameAccess;
      79             : using com::sun::star::container::XIndexAccess;
      80             : using com::sun::star::container::ElementExistException;
      81             : using com::sun::star::container::NoSuchElementException;
      82             : 
      83             : using com::sun::star::uno::Reference;
      84             : using com::sun::star::uno::Exception;
      85             : using com::sun::star::uno::UNO_QUERY;
      86             : using com::sun::star::uno::XInterface;
      87             : using com::sun::star::uno::Sequence;
      88             : using com::sun::star::uno::Any;
      89             : using com::sun::star::uno::makeAny;
      90             : using com::sun::star::uno::Type;
      91             : using com::sun::star::uno::RuntimeException;
      92             : 
      93             : using com::sun::star::lang::IllegalArgumentException;
      94             : using com::sun::star::lang::IndexOutOfBoundsException;
      95             : 
      96             : using com::sun::star::beans::XPropertySetInfo;
      97             : using com::sun::star::beans::XFastPropertySet;
      98             : using com::sun::star::beans::XMultiPropertySet;
      99             : using com::sun::star::beans::XPropertySet;
     100             : using com::sun::star::beans::Property;
     101             : 
     102             : using com::sun::star::sdbc::XResultSet;
     103             : using com::sun::star::sdbc::XPreparedStatement;
     104             : using com::sun::star::sdbc::XStatement;
     105             : using com::sun::star::sdbc::XParameters;
     106             : using com::sun::star::sdbc::XRow;
     107             : using com::sun::star::sdbc::SQLException;
     108             : 
     109             : namespace pq_sdbc_driver
     110             : {
     111             : 
     112             : #define ASCII_STR(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
     113             : 
     114           0 : User::User( const ::rtl::Reference< RefCountedMutex > & refMutex,
     115             :             const Reference< com::sun::star::sdbc::XConnection > & connection,
     116             :             ConnectionSettings *pSettings )
     117             :     : ReflectionBase(
     118           0 :         getStatics().refl.user.implName,
     119           0 :         getStatics().refl.user.serviceNames,
     120             :         refMutex,
     121             :         connection,
     122             :         pSettings,
     123           0 :         * getStatics().refl.user.pProps )
     124           0 : {}
     125             : 
     126           0 : Reference< XPropertySet > User::createDataDescriptor(  ) throw (RuntimeException)
     127             : {
     128           0 :     UserDescriptor * pUser = new UserDescriptor( m_refMutex, m_conn, m_pSettings );
     129           0 :     pUser->copyValuesFrom( this );
     130             : 
     131           0 :     return Reference< XPropertySet > ( pUser );
     132             : }
     133             : 
     134             : 
     135           0 : Sequence<Type > User::getTypes() throw( RuntimeException )
     136             : {
     137             :     static cppu::OTypeCollection *pCollection;
     138           0 :     if( ! pCollection )
     139             :     {
     140           0 :         MutexGuard guard( osl::Mutex::getGlobalMutex() );
     141           0 :         if( !pCollection )
     142             :         {
     143             :             static cppu::OTypeCollection collection(
     144           0 :                 getCppuType( (Reference< com::sun::star::sdbcx::XUser> *) 0 ),
     145           0 :                 ReflectionBase::getTypes());
     146           0 :             pCollection = &collection;
     147           0 :         }
     148             :     }
     149           0 :     return pCollection->getTypes();
     150             : }
     151             : 
     152           0 : Sequence< sal_Int8> User::getImplementationId() throw( RuntimeException )
     153             : {
     154           0 :     return getStatics().refl.user.implementationId;
     155             : }
     156             : 
     157           0 : Any User::queryInterface( const Type & reqType ) throw (RuntimeException)
     158             : {
     159           0 :     Any ret;
     160             : 
     161           0 :     ret = ReflectionBase::queryInterface( reqType );
     162           0 :     if( ! ret.hasValue() )
     163             :         ret = ::cppu::queryInterface(
     164             :             reqType,
     165           0 :             static_cast< com::sun::star::sdbcx::XUser * > ( this ) );
     166           0 :     return ret;
     167             : }
     168             : 
     169             : 
     170           0 : void User::changePassword(
     171             :     const ::rtl::OUString& oldPassword, const ::rtl::OUString& newPassword )
     172             :     throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
     173             : {
     174             :     (void) oldPassword;
     175           0 :     rtl::OUStringBuffer buf(128);
     176           0 :     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER USER " ) );
     177           0 :     bufferQuoteIdentifier( buf, extractStringProperty( this, getStatics().NAME ), m_pSettings );
     178           0 :     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " PASSWORD " ) );
     179           0 :     bufferQuoteConstant( buf, newPassword, m_pSettings );
     180           0 :     Reference< XStatement > stmt = m_conn->createStatement();
     181           0 :     DisposeGuard guard( stmt );
     182           0 :     stmt->executeUpdate( buf.makeStringAndClear() );
     183           0 : }
     184             : 
     185           0 : sal_Int32 User::getPrivileges( const ::rtl::OUString& objName, sal_Int32 objType )
     186             :     throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
     187             : {
     188           0 :     sal_Int32 ret = 0xffffffff;
     189           0 :     if( isLog( m_pSettings, LogLevel::INFO ) )
     190             :     {
     191           0 :         Statics & st = getStatics();
     192           0 :         rtl::OUString user = extractStringProperty( this, st.NAME );
     193             : 
     194           0 :         rtl::OUStringBuffer buf( 128 );
     195           0 :         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("User::getPrivileges[") );
     196           0 :         buf.append( extractStringProperty( this, st.NAME ) );
     197           0 :         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "] got called for " ) );
     198           0 :         buf.append( objName );
     199           0 :         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "(type=" ) );
     200           0 :         buf.append( objType );
     201           0 :         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ")" ) );
     202           0 :         log( m_pSettings, LogLevel::INFO, buf.makeStringAndClear() );
     203             :     }
     204             :     // all privileges
     205           0 :     return ret;
     206             : }
     207             : 
     208           0 : sal_Int32 User::getGrantablePrivileges( const ::rtl::OUString& objName, sal_Int32 objType )
     209             :     throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
     210             : {
     211             :     (void) objName; (void) objType;
     212             :     // all privileges
     213           0 :     return 0xffffffff;
     214             : }
     215             : 
     216           0 : void User::grantPrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges )
     217             :     throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
     218             : {
     219             :     (void) objName; (void) objType; (void) objPrivileges;
     220             :     throw com::sun::star::sdbc::SQLException(
     221             :         ASCII_STR( "pq_driver: privilege change not implemented yet" ),
     222           0 :         *this, OUString(), 1, Any() );
     223             : }
     224             : 
     225           0 : void User::revokePrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges )
     226             :     throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
     227             : {
     228             :     (void) objName; (void) objType; (void) objPrivileges;
     229             :     throw com::sun::star::sdbc::SQLException(
     230             :         ASCII_STR( "pq_driver: privilege change not implemented yet" ),
     231           0 :         *this, OUString(), 1, Any() );
     232             : }
     233             : 
     234             : //______________________________________________________________________________________
     235           0 : UserDescriptor::UserDescriptor(
     236             :     const ::rtl::Reference< RefCountedMutex > & refMutex,
     237             :     const Reference< com::sun::star::sdbc::XConnection > & connection,
     238             :     ConnectionSettings *pSettings )
     239             :     : ReflectionBase(
     240           0 :         getStatics().refl.userDescriptor.implName,
     241           0 :         getStatics().refl.userDescriptor.serviceNames,
     242             :         refMutex,
     243             :         connection,
     244             :         pSettings,
     245           0 :         * getStatics().refl.userDescriptor.pProps )
     246           0 : {}
     247             : 
     248           0 : Reference< XPropertySet > UserDescriptor::createDataDescriptor(  ) throw (RuntimeException)
     249             : {
     250           0 :     UserDescriptor * pUser = new UserDescriptor( m_refMutex, m_conn, m_pSettings );
     251           0 :     pUser->copyValuesFrom( this );
     252             : 
     253           0 :     return Reference< XPropertySet > ( pUser );
     254             : }
     255             : 
     256             : 
     257             : }

Generated by: LCOV version 1.10