1*46dbaceeSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*46dbaceeSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*46dbaceeSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*46dbaceeSAndrew Rist * distributed with this work for additional information 6*46dbaceeSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*46dbaceeSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*46dbaceeSAndrew Rist * "License"); you may not use this file except in compliance 9*46dbaceeSAndrew Rist * with the License. You may obtain a copy of the License at 10*46dbaceeSAndrew Rist * 11*46dbaceeSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*46dbaceeSAndrew Rist * 13*46dbaceeSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*46dbaceeSAndrew Rist * software distributed under the License is distributed on an 15*46dbaceeSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*46dbaceeSAndrew Rist * KIND, either express or implied. See the License for the 17*46dbaceeSAndrew Rist * specific language governing permissions and limitations 18*46dbaceeSAndrew Rist * under the License. 19*46dbaceeSAndrew Rist * 20*46dbaceeSAndrew Rist *************************************************************/ 21*46dbaceeSAndrew Rist 22*46dbaceeSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef EXTENSIONS_CONFIG_LDAP_LDAPACCESS_HXX_ 25cdf0e10cSrcweir #define EXTENSIONS_CONFIG_LDAP_LDAPACCESS_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "sal/config.h" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <map> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include "wrapldapinclude.hxx" 32cdf0e10cSrcweir #include <com/sun/star/ldap/LdapGenericException.hpp> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <com/sun/star/ldap/LdapConnectionException.hpp> 35cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp> 36cdf0e10cSrcweir #include <osl/module.h> 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace extensions { namespace config { namespace ldap { 39cdf0e10cSrcweir 40cdf0e10cSrcweir namespace css = com::sun::star ; 41cdf0e10cSrcweir namespace uno = css::uno ; 42cdf0e10cSrcweir namespace lang = css::lang ; 43cdf0e10cSrcweir namespace ldap = css::ldap ; 44cdf0e10cSrcweir //------------------------------------------------------------------------------ 45cdf0e10cSrcweir // LdapUserProfile classes 46cdf0e10cSrcweir struct LdapUserProfile; 47cdf0e10cSrcweir class LdapUserProfileMap; 48cdf0e10cSrcweir 49cdf0e10cSrcweir typedef LDAP_API(int) (LDAP_CALL *t_ldap_unbind_s)( LDAP *ld ); 50cdf0e10cSrcweir typedef LDAP_API(int) (LDAP_CALL *t_ldap_simple_bind_s)( LDAP *ld, const char *who, const char *passwd ); 51cdf0e10cSrcweir typedef LDAP_API(int) (LDAP_CALL *t_ldap_set_option)( LDAP *ld, int option, const void *optdata ); 52cdf0e10cSrcweir typedef LDAP_API(char *) (LDAP_CALL *t_ldap_err2string)( int err ); 53cdf0e10cSrcweir typedef LDAP_API(LDAP *) (LDAP_CALL *t_ldap_init)( const char *defhost, int defport ); 54cdf0e10cSrcweir typedef LDAP_API(int) (LDAP_CALL *t_ldap_msgfree)( LDAPMessage *lm ); 55cdf0e10cSrcweir typedef LDAP_API(char *) (LDAP_CALL *t_ldap_get_dn)( LDAP *ld, LDAPMessage *entry ); 56cdf0e10cSrcweir typedef LDAP_API(LDAPMessage *) (LDAP_CALL *t_ldap_first_entry)( LDAP *ld, LDAPMessage *chain ); 57cdf0e10cSrcweir typedef LDAP_API(char *) (LDAP_CALL *t_ldap_first_attribute)( LDAP *ld, LDAPMessage *entry, void **ptr ); 58cdf0e10cSrcweir typedef LDAP_API(char *) (LDAP_CALL *t_ldap_next_attribute)( LDAP *ld, LDAPMessage *entry, void *ptr ); 59cdf0e10cSrcweir typedef LDAP_API(int) (LDAP_CALL *t_ldap_search_s)( LDAP *ld, const char *base, int scope, const char *filter, char **attrs, int attrsonly, LDAPMessage **res ); 60cdf0e10cSrcweir typedef LDAP_API(void) (LDAP_CALL *t_ldap_value_free)( char **vals ); 61cdf0e10cSrcweir typedef LDAP_API(char **) (LDAP_CALL *t_ldap_get_values)( LDAP *ld, LDAPMessage *entry, const char *target ); 62cdf0e10cSrcweir typedef LDAP_API(void) (LDAP_CALL *t_ldap_memfree)( void *p ); 63cdf0e10cSrcweir //------------------------------------------------------------------------------ 64cdf0e10cSrcweir /** Struct containing the information on LDAP connection */ 65cdf0e10cSrcweir struct LdapDefinition 66cdf0e10cSrcweir { 67cdf0e10cSrcweir /** LDAP server name */ 68cdf0e10cSrcweir rtl::OString mServer ; 69cdf0e10cSrcweir /** LDAP server port number */ 70cdf0e10cSrcweir sal_Int32 mPort ; 71cdf0e10cSrcweir /** Repository base DN */ 72cdf0e10cSrcweir rtl::OString mBaseDN ; 73cdf0e10cSrcweir /** DN to use for "anonymous" connection */ 74cdf0e10cSrcweir rtl::OString mAnonUser ; 75cdf0e10cSrcweir /** Credentials to use for "anonymous" connection */ 76cdf0e10cSrcweir rtl::OString mAnonCredentials ; 77cdf0e10cSrcweir /** User Entity Object Class */ 78cdf0e10cSrcweir rtl::OString mUserObjectClass; 79cdf0e10cSrcweir /** User Entity Unique Attribute */ 80cdf0e10cSrcweir rtl::OString mUserUniqueAttr; 81cdf0e10cSrcweir } ; 82cdf0e10cSrcweir 83cdf0e10cSrcweir typedef std::map< rtl::OUString, rtl::OUString > LdapData; // key/value pairs 84cdf0e10cSrcweir 85cdf0e10cSrcweir /** Class encapulating all LDAP functionality */ 86cdf0e10cSrcweir class LdapConnection 87cdf0e10cSrcweir { 88cdf0e10cSrcweir friend struct LdapMessageHolder; 89cdf0e10cSrcweir public: 90cdf0e10cSrcweir 91cdf0e10cSrcweir /** Default constructor */ 92cdf0e10cSrcweir LdapConnection(void) : mConnection(NULL),mLdapDefinition() {} 93cdf0e10cSrcweir /** Destructor, releases the connection */ 94cdf0e10cSrcweir ~LdapConnection(void) ; 95cdf0e10cSrcweir /** Make connection to LDAP server */ 96cdf0e10cSrcweir void connectSimple(const LdapDefinition& aDefinition) 97cdf0e10cSrcweir throw (ldap::LdapConnectionException, 98cdf0e10cSrcweir ldap::LdapGenericException); 99cdf0e10cSrcweir 100cdf0e10cSrcweir /** 101cdf0e10cSrcweir Gets LdapUserProfile from LDAP repository for specified user 102cdf0e10cSrcweir @param aUser name of logged on user 103cdf0e10cSrcweir @param aUserProfileMap Map containing LDAP->00o mapping 104cdf0e10cSrcweir @param aUserProfile struct for holding OOo values 105cdf0e10cSrcweir 106cdf0e10cSrcweir @throws com::sun::star::ldap::LdapGenericException 107cdf0e10cSrcweir if an LDAP error occurs. 108cdf0e10cSrcweir */ 109cdf0e10cSrcweir void getUserProfile(const rtl::OUString& aUser, LdapData * data) 110cdf0e10cSrcweir throw (lang::IllegalArgumentException, 111cdf0e10cSrcweir ldap::LdapConnectionException, 112cdf0e10cSrcweir ldap::LdapGenericException); 113cdf0e10cSrcweir 114cdf0e10cSrcweir /** finds DN of user 115cdf0e10cSrcweir @return DN of User 116cdf0e10cSrcweir */ 117cdf0e10cSrcweir rtl::OString findUserDn(const rtl::OString& aUser) 118cdf0e10cSrcweir throw (lang::IllegalArgumentException, 119cdf0e10cSrcweir ldap::LdapConnectionException, 120cdf0e10cSrcweir ldap::LdapGenericException); 121cdf0e10cSrcweir 122cdf0e10cSrcweir void loadModule(); 123cdf0e10cSrcweir 124cdf0e10cSrcweir static t_ldap_err2string s_p_err2string; 125cdf0e10cSrcweir private: 126cdf0e10cSrcweir 127cdf0e10cSrcweir void initConnection() 128cdf0e10cSrcweir throw (ldap::LdapConnectionException); 129cdf0e10cSrcweir void disconnect(); 130cdf0e10cSrcweir /** 131cdf0e10cSrcweir Indicates whether the connection is in a valid state. 132cdf0e10cSrcweir @return sal_True if connection is valid, sal_False otherwise 133cdf0e10cSrcweir */ 134cdf0e10cSrcweir bool isValid(void) const { return mConnection != NULL ; } 135cdf0e10cSrcweir 136cdf0e10cSrcweir void connectSimple() 137cdf0e10cSrcweir throw (ldap::LdapConnectionException, 138cdf0e10cSrcweir ldap::LdapGenericException); 139cdf0e10cSrcweir 140cdf0e10cSrcweir /** LDAP connection object */ 141cdf0e10cSrcweir LDAP* mConnection ; 142cdf0e10cSrcweir LdapDefinition mLdapDefinition; 143cdf0e10cSrcweir 144cdf0e10cSrcweir static oslModule s_Ldap_Module; 145cdf0e10cSrcweir static t_ldap_value_free s_p_value_free; 146cdf0e10cSrcweir static t_ldap_get_values s_p_get_values; 147cdf0e10cSrcweir static t_ldap_unbind_s s_p_unbind_s; 148cdf0e10cSrcweir static t_ldap_simple_bind_s s_p_simple_bind_s; 149cdf0e10cSrcweir static t_ldap_set_option s_p_set_option; 150cdf0e10cSrcweir static t_ldap_init s_p_init; 151cdf0e10cSrcweir static t_ldap_msgfree s_p_msgfree; 152cdf0e10cSrcweir static t_ldap_get_dn s_p_get_dn; 153cdf0e10cSrcweir static t_ldap_first_entry s_p_first_entry; 154cdf0e10cSrcweir static t_ldap_first_attribute s_p_first_attribute; 155cdf0e10cSrcweir static t_ldap_next_attribute s_p_next_attribute; 156cdf0e10cSrcweir static t_ldap_search_s s_p_search_s; 157cdf0e10cSrcweir 158cdf0e10cSrcweir static t_ldap_memfree s_p_memfree; 159cdf0e10cSrcweir 160cdf0e10cSrcweir } ; 161cdf0e10cSrcweir //------------------------------------------------------------------------------ 162cdf0e10cSrcweir }} } 163cdf0e10cSrcweir 164cdf0e10cSrcweir #endif // EXTENSIONS_CONFIG_LDAP_LDAPUSERPROFILE_HXX_ 165