merge the formfield patch from ooo-build
[ooovba.git] / extensions / source / config / ldap / ldapaccess.hxx
blob9a662f8c7ca5de60e7113cd380d8dfc1b22928f1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ldapaccess.hxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef EXTENSIONS_CONFIG_LDAP_LDAPACCESS_HXX_
32 #define EXTENSIONS_CONFIG_LDAP_LDAPACCESS_HXX_
34 #include "wrapldapinclude.hxx"
35 #include <com/sun/star/ldap/LdapGenericException.hpp>
37 #include <com/sun/star/ldap/LdapConnectionException.hpp>
38 #include <com/sun/star/lang/IllegalArgumentException.hpp>
39 #include <osl/module.h>
41 namespace extensions { namespace config { namespace ldap {
43 namespace css = com::sun::star ;
44 namespace uno = css::uno ;
45 namespace lang = css::lang ;
46 namespace ldap = css::ldap ;
47 //------------------------------------------------------------------------------
48 // LdapUserProfile classes
49 struct LdapUserProfile;
50 class LdapUserProfileMap;
52 typedef LDAP_API(int) (LDAP_CALL *t_ldap_unbind_s)( LDAP *ld );
53 typedef LDAP_API(int) (LDAP_CALL *t_ldap_simple_bind_s)( LDAP *ld, const char *who, const char *passwd );
54 typedef LDAP_API(int) (LDAP_CALL *t_ldap_set_option)( LDAP *ld, int option, const void *optdata );
55 typedef LDAP_API(char *) (LDAP_CALL *t_ldap_err2string)( int err );
56 typedef LDAP_API(LDAP *) (LDAP_CALL *t_ldap_init)( const char *defhost, int defport );
57 typedef LDAP_API(int) (LDAP_CALL *t_ldap_msgfree)( LDAPMessage *lm );
58 typedef LDAP_API(char *) (LDAP_CALL *t_ldap_get_dn)( LDAP *ld, LDAPMessage *entry );
59 typedef LDAP_API(LDAPMessage *) (LDAP_CALL *t_ldap_first_entry)( LDAP *ld, LDAPMessage *chain );
60 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 );
61 typedef LDAP_API(void) (LDAP_CALL *t_ldap_value_free)( char **vals );
62 typedef LDAP_API(char **) (LDAP_CALL *t_ldap_get_values)( LDAP *ld, LDAPMessage *entry, const char *target );
63 typedef LDAP_API(void) (LDAP_CALL *t_ldap_memfree)( void *p );
64 //------------------------------------------------------------------------------
65 /** Struct containing the information on LDAP connection */
66 struct LdapDefinition
68 /** LDAP server name */
69 rtl::OString mServer ;
70 /** LDAP server port number */
71 sal_Int32 mPort ;
72 /** Repository base DN */
73 rtl::OString mBaseDN ;
74 /** DN to use for "anonymous" connection */
75 rtl::OString mAnonUser ;
76 /** Credentials to use for "anonymous" connection */
77 rtl::OString mAnonCredentials ;
78 /** User Entity Object Class */
79 rtl::OString mUserObjectClass;
80 /** User Entity Unique Attribute */
81 rtl::OString mUserUniqueAttr;
82 /** Mapping File */
83 rtl::OString mMapping;
84 } ;
86 /** Class encapulating all LDAP functionality */
87 class LdapConnection
89 friend struct LdapMessageHolder;
90 public:
92 /** Default constructor */
93 LdapConnection(void) : mConnection(NULL),mLdapDefinition() {}
94 /** Destructor, releases the connection */
95 ~LdapConnection(void) ;
96 /** Make connection to LDAP server */
97 void connectSimple(const LdapDefinition& aDefinition)
98 throw (ldap::LdapConnectionException,
99 ldap::LdapGenericException);
101 /** query connection status */
102 bool isConnected() const { return isValid(); }
104 /**
105 Gets LdapUserProfile from LDAP repository for specified user
106 @param aUser name of logged on user
107 @param aUserProfileMap Map containing LDAP->00o mapping
108 @param aUserProfile struct for holding OOo values
110 @throws com::sun::star::ldap::LdapGenericException
111 if an LDAP error occurs.
113 void getUserProfile(const rtl::OUString& aUser,
114 const LdapUserProfileMap& aUserProfileMap,
115 LdapUserProfile& aUserProfile)
116 throw (lang::IllegalArgumentException,
117 ldap::LdapConnectionException,
118 ldap::LdapGenericException);
119 /**
120 Retrieves a single attribute from a single entry.
121 @param aDn entry DN
122 @param aAttribute attribute name
124 @throws com::sun::star::ldap::LdapGenericException
125 if an LDAP error occurs.
127 rtl::OString getSingleAttribute(const rtl::OString& aDn,
128 const rtl::OString& aAttribute)
129 throw (ldap::LdapConnectionException,
130 ldap::LdapGenericException);
132 /** finds DN of user
133 @return DN of User
135 rtl::OString findUserDn(const rtl::OString& aUser)
136 throw (lang::IllegalArgumentException,
137 ldap::LdapConnectionException,
138 ldap::LdapGenericException);
140 void loadModule();
142 static t_ldap_err2string s_p_err2string;
143 static t_ldap_value_free s_p_value_free;
144 static t_ldap_get_values s_p_get_values;
145 private:
147 void initConnection()
148 throw (ldap::LdapConnectionException);
149 void disconnect();
151 Indicates whether the connection is in a valid state.
152 @return sal_True if connection is valid, sal_False otherwise
154 bool isValid(void) const { return mConnection != NULL ; }
156 void connectSimple()
157 throw (ldap::LdapConnectionException,
158 ldap::LdapGenericException);
160 /** LDAP connection object */
161 LDAP* mConnection ;
162 LdapDefinition mLdapDefinition;
164 static oslModule s_Ldap_Module;
165 static t_ldap_unbind_s s_p_unbind_s;
166 static t_ldap_simple_bind_s s_p_simple_bind_s;
167 static t_ldap_set_option s_p_set_option;
168 static t_ldap_init s_p_init;
169 static t_ldap_msgfree s_p_msgfree;
170 static t_ldap_get_dn s_p_get_dn;
171 static t_ldap_first_entry s_p_first_entry;
172 static t_ldap_search_s s_p_search_s;
174 static t_ldap_memfree s_p_memfree;
177 //------------------------------------------------------------------------------
178 }} }
180 #endif // EXTENSIONS_CONFIG_LDAP_LDAPUSERPROFILE_HXX_