23#include <osl/diagnose.h>
26#include <com/sun/star/ldap/LdapConnectionException.hpp>
67 if (aRetCode == LDAP_SUCCESS) { return ; }
71 if (aOperation !=
nullptr)
73 message += OUString::createFromAscii(aOperation) +
": ";
75 message += OUString::createFromAscii(ldap_err2string(aRetCode)) +
" (" ;
77#ifndef LDAP_OPT_SIZELIMIT
79 ldap_get_lderrno(aConnection,
NULL, &stub) ;
82 message += OUString::createFromAscii(stub) ;
92 { message +=
"No additional information"; }
95 throw ldap::LdapGenericException(message,
nullptr, aRetCode) ;
100 OSL_ENSURE(!
isValid(),
"Re-connecting to an LDAP connection that is already established");
115 int version = LDAP_VERSION3;
117 LDAP_OPT_PROTOCOL_VERSION,
120#ifdef LDAP_X_OPT_CONNECT_TIMEOUT
125 LDAP_X_OPT_CONNECT_TIMEOUT,
129 LDAP_X_OPT_CONNECT_TIMEOUT,
152 throw ldap::LdapConnectionException(
"Cannot initialise connection to LDAP: No server specified.");
166 throw ldap::LdapConnectionException(
167 "Cannot initialise connection to LDAP server "
173 const OUString& aUser,
LdapData * data)
175 OSL_ASSERT(data !=
nullptr);
183 const_cast<PWSTR
>(o3tl::toW(aUserDn.getStr())),
185 const_cast<PWSTR
>( L
"(objectclass=*)" ),
206 const OUString aAttr( o3tl::toU( attr ) );
207 const OUString aValues( o3tl::toU( *
values ) );
208 data->emplace( aAttr, aValues );
218 OStringToOUString(attr, RTL_TEXTENCODING_ASCII_US),
219 OStringToOUString(*
values, RTL_TEXTENCODING_UTF8));
233 throw lang::IllegalArgumentException(
234 "LdapConnection::findUserDn -User id is empty",
238 OUString
filter =
"(&(objectclass="
248 PWCHAR attributes [2] = {
const_cast<PWCHAR
>( L
"1.1" ),
nullptr };
252 const_cast<PWSTR
>(o3tl::toW(
filter.getStr())), attributes, 0, &
result.msg) ;
254 char * attributes [2] = {
const_cast<char *
>(LDAP_NO_ATTRS),
nullptr };
264 if (entry !=
nullptr)
267 PWCHAR charsDn = ldap_get_dnW(
mConnection, entry) ;
269 userDn = OUString( o3tl::toU( charsDn ) );
270 ldap_memfreeW(charsDn) ;
274 userDn = OStringToOUString( charsDn, RTL_TEXTENCODING_UTF8 );
275 ldap_memfree(charsDn) ;
280 OSL_FAIL(
"LdapConnection::findUserDn-could not get DN for User ");
LdapDefinition mLdapDefinition
LDAP * mConnection
LDAP connection object.
void getUserProfile(const OUString &aUser, LdapData *data)
Gets LdapUserProfile from LDAP repository for specified user.
bool isValid() const
Indicates whether the connection is in a valid state.
OUString findUserDn(const OUString &aUser)
finds DN of user
~LdapConnection()
Destructor, releases the connection.
MetadataImporterPluginType * result
std::map< OUString, OUString > LdapData
static void checkLdapReturnCode(const char *aOperation, LdapErrCode aRetCode)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
std::vector< char * > values
Struct containing the information on LDAP connection.
OUString mAnonUser
DN to use for "anonymous" connection.
OUString mServer
LDAP server name.
OUString mUserObjectClass
User Entity Object Class.
OUString mUserUniqueAttr
User Entity Unique Attribute.
OUString mAnonCredentials
Credentials to use for "anonymous" connection.
OUString mBaseDN
Repository base DN.
sal_Int32 mPort
LDAP server port number.
LdapMessageHolder & operator=(const LdapMessageHolder &)=delete
LdapMessageHolder(const LdapMessageHolder &)=delete