Don't load ldap library dynamically, link it!
Change-Id: I5e9aeb3ebda0c30da364df0d7a1c0f245a33431c
This commit is contained in:
@@ -68,6 +68,24 @@ $(eval $(call gb_Library_use_libraries,ldapbe2,\
|
|||||||
sal \
|
sal \
|
||||||
))
|
))
|
||||||
|
|
||||||
|
ifeq ($(OS),WNT)
|
||||||
|
$(eval $(call gb_Library_use_libraries,ldapbe2,\
|
||||||
|
wldap32 \
|
||||||
|
))
|
||||||
|
else # 0S!=WNT
|
||||||
|
ifneq ($(WITH_OPENLDAP),YES)
|
||||||
|
$(eval $(call gb_Library_add_libs,ldapbe2,\
|
||||||
|
-lldap50 \
|
||||||
|
))
|
||||||
|
else # WITH_OPENLDAP=YES
|
||||||
|
$(eval $(call gb_Library_add_libs,ldapbe2,\
|
||||||
|
-lldap \
|
||||||
|
))
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ifeq ($(OS),FREEBSD)
|
ifeq ($(OS),FREEBSD)
|
||||||
$(eval $(call gb_Library_add_libs,ldapbe2,\
|
$(eval $(call gb_Library_add_libs,ldapbe2,\
|
||||||
-lcompat \
|
-lcompat \
|
||||||
|
@@ -35,21 +35,6 @@
|
|||||||
|
|
||||||
namespace extensions { namespace config { namespace ldap {
|
namespace extensions { namespace config { namespace ldap {
|
||||||
|
|
||||||
oslModule LdapConnection::s_Ldap_Module = NULL;
|
|
||||||
t_ldap_unbind_s LdapConnection::s_p_unbind_s = NULL;
|
|
||||||
t_ldap_simple_bind_s LdapConnection::s_p_simple_bind_s = NULL;
|
|
||||||
t_ldap_set_option LdapConnection::s_p_set_option = NULL;
|
|
||||||
t_ldap_err2string LdapConnection::s_p_err2string = NULL;
|
|
||||||
t_ldap_init LdapConnection::s_p_init = NULL;
|
|
||||||
t_ldap_msgfree LdapConnection::s_p_msgfree = NULL;
|
|
||||||
t_ldap_get_dn LdapConnection::s_p_get_dn = NULL;
|
|
||||||
t_ldap_first_entry LdapConnection::s_p_first_entry = NULL;
|
|
||||||
t_ldap_first_attribute LdapConnection::s_p_first_attribute = NULL;
|
|
||||||
t_ldap_next_attribute LdapConnection::s_p_next_attribute = NULL;
|
|
||||||
t_ldap_search_s LdapConnection::s_p_search_s = NULL;
|
|
||||||
t_ldap_value_free LdapConnection::s_p_value_free = NULL;
|
|
||||||
t_ldap_get_values LdapConnection::s_p_get_values = NULL;
|
|
||||||
t_ldap_memfree LdapConnection::s_p_memfree = NULL;
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
typedef int LdapErrCode;
|
typedef int LdapErrCode;
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -59,7 +44,7 @@ struct LdapMessageHolder
|
|||||||
~LdapMessageHolder()
|
~LdapMessageHolder()
|
||||||
{
|
{
|
||||||
if (msg)
|
if (msg)
|
||||||
(*LdapConnection::s_p_msgfree)(msg);
|
ldap_msgfree(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
LDAPMessage * msg;
|
LDAPMessage * msg;
|
||||||
@@ -79,7 +64,7 @@ void LdapConnection::disconnect()
|
|||||||
{
|
{
|
||||||
if (mConnection != NULL)
|
if (mConnection != NULL)
|
||||||
{
|
{
|
||||||
(*s_p_unbind_s)(mConnection) ;
|
ldap_unbind_s(mConnection) ;
|
||||||
mConnection = NULL;
|
mConnection = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,11 +83,11 @@ static void checkLdapReturnCode(const sal_Char *aOperation,
|
|||||||
{
|
{
|
||||||
message.appendAscii(aOperation).appendAscii(": ") ;
|
message.appendAscii(aOperation).appendAscii(": ") ;
|
||||||
}
|
}
|
||||||
message.appendAscii((*LdapConnection::s_p_err2string)(aRetCode)).appendAscii(" (") ;
|
message.appendAscii(ldap_err2string(aRetCode)).appendAscii(" (") ;
|
||||||
sal_Char *stub = NULL ;
|
sal_Char *stub = NULL ;
|
||||||
|
|
||||||
#ifndef LDAP_OPT_SIZELIMIT // for use with OpenLDAP
|
#ifndef LDAP_OPT_SIZELIMIT // for use with OpenLDAP
|
||||||
(*s_p_get_lderrno)(aConnection, NULL, &stub) ;
|
ldap_get_lderrno(aConnection, NULL, &stub) ;
|
||||||
#endif
|
#endif
|
||||||
if (stub != NULL)
|
if (stub != NULL)
|
||||||
{
|
{
|
||||||
@@ -112,7 +97,7 @@ static void checkLdapReturnCode(const sal_Char *aOperation,
|
|||||||
// string itself. At any rate freeing it seems to
|
// string itself. At any rate freeing it seems to
|
||||||
// cause some undue problems at least on Windows.
|
// cause some undue problems at least on Windows.
|
||||||
// This call is thus disabled for the moment.
|
// This call is thus disabled for the moment.
|
||||||
//(*s_p_memfree)(stub) ;
|
//ldap_memfree(stub) ;
|
||||||
}
|
}
|
||||||
else { message.appendAscii(kNoSpecificMessage) ; }
|
else { message.appendAscii(kNoSpecificMessage) ; }
|
||||||
message.appendAscii(")") ;
|
message.appendAscii(")") ;
|
||||||
@@ -139,20 +124,20 @@ void LdapConnection::connectSimple()
|
|||||||
initConnection() ;
|
initConnection() ;
|
||||||
// Set Protocol V3
|
// Set Protocol V3
|
||||||
int version = LDAP_VERSION3;
|
int version = LDAP_VERSION3;
|
||||||
(*s_p_set_option)(mConnection,
|
ldap_set_option(mConnection,
|
||||||
LDAP_OPT_PROTOCOL_VERSION,
|
LDAP_OPT_PROTOCOL_VERSION,
|
||||||
&version);
|
&version);
|
||||||
|
|
||||||
#ifdef LDAP_X_OPT_CONNECT_TIMEOUT // OpenLDAP doesn't support this and the func
|
#ifdef LDAP_X_OPT_CONNECT_TIMEOUT // OpenLDAP doesn't support this and the func
|
||||||
/* timeout is specified in milliseconds -> 4 seconds*/
|
/* timeout is specified in milliseconds -> 4 seconds*/
|
||||||
int timeout = 4000;
|
int timeout = 4000;
|
||||||
(*s_p_set_option)( mConnection,
|
ldap_set_option( mConnection,
|
||||||
LDAP_X_OPT_CONNECT_TIMEOUT,
|
LDAP_X_OPT_CONNECT_TIMEOUT,
|
||||||
&timeout );
|
&timeout );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Do the bind
|
// Do the bind
|
||||||
LdapErrCode retCode = (*s_p_simple_bind_s)(mConnection,
|
LdapErrCode retCode = ldap_simple_bind_s(mConnection,
|
||||||
mLdapDefinition.mAnonUser.getStr(),
|
mLdapDefinition.mAnonUser.getStr(),
|
||||||
mLdapDefinition.mAnonCredentials.getStr()) ;
|
mLdapDefinition.mAnonCredentials.getStr()) ;
|
||||||
|
|
||||||
@@ -173,7 +158,7 @@ void LdapConnection::initConnection()
|
|||||||
|
|
||||||
if (mLdapDefinition.mPort == 0) mLdapDefinition.mPort = LDAP_PORT;
|
if (mLdapDefinition.mPort == 0) mLdapDefinition.mPort = LDAP_PORT;
|
||||||
|
|
||||||
mConnection = (*s_p_init)(mLdapDefinition.mServer.getStr(),
|
mConnection = ldap_init(mLdapDefinition.mServer.getStr(),
|
||||||
mLdapDefinition.mPort) ;
|
mLdapDefinition.mPort) ;
|
||||||
if (mConnection == NULL)
|
if (mConnection == NULL)
|
||||||
{
|
{
|
||||||
@@ -199,7 +184,7 @@ void LdapConnection::initConnection()
|
|||||||
rtl::OString aUserDn =findUserDn( rtl::OUStringToOString(aUser, RTL_TEXTENCODING_ASCII_US));
|
rtl::OString aUserDn =findUserDn( rtl::OUStringToOString(aUser, RTL_TEXTENCODING_ASCII_US));
|
||||||
|
|
||||||
LdapMessageHolder result;
|
LdapMessageHolder result;
|
||||||
LdapErrCode retCode = (*s_p_search_s)(mConnection,
|
LdapErrCode retCode = ldap_search_s(mConnection,
|
||||||
aUserDn.getStr(),
|
aUserDn.getStr(),
|
||||||
LDAP_SCOPE_BASE,
|
LDAP_SCOPE_BASE,
|
||||||
"(objectclass=*)",
|
"(objectclass=*)",
|
||||||
@@ -209,18 +194,18 @@ void LdapConnection::initConnection()
|
|||||||
|
|
||||||
checkLdapReturnCode("getUserProfile", retCode,mConnection) ;
|
checkLdapReturnCode("getUserProfile", retCode,mConnection) ;
|
||||||
|
|
||||||
void * ptr;
|
BerElement * ptr;
|
||||||
char * attr = (*s_p_first_attribute)(mConnection, result.msg, &ptr);
|
char * attr = ldap_first_attribute(mConnection, result.msg, &ptr);
|
||||||
while (attr != 0) {
|
while (attr != 0) {
|
||||||
char ** values = (*s_p_get_values)(mConnection, result.msg, attr);
|
char ** values = ldap_get_values(mConnection, result.msg, attr);
|
||||||
if (values != 0) {
|
if (values != 0) {
|
||||||
data->insert(
|
data->insert(
|
||||||
LdapData::value_type(
|
LdapData::value_type(
|
||||||
rtl::OStringToOUString(attr, RTL_TEXTENCODING_ASCII_US),
|
rtl::OStringToOUString(attr, RTL_TEXTENCODING_ASCII_US),
|
||||||
rtl::OStringToOUString(*values, RTL_TEXTENCODING_UTF8)));
|
rtl::OStringToOUString(*values, RTL_TEXTENCODING_UTF8)));
|
||||||
(*s_p_value_free)(values);
|
ldap_value_free(values);
|
||||||
}
|
}
|
||||||
attr = (*s_p_next_attribute)(mConnection, result.msg, ptr);
|
attr = ldap_next_attribute(mConnection, result.msg, ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -249,21 +234,21 @@ void LdapConnection::initConnection()
|
|||||||
sal_Char * attributes [2];
|
sal_Char * attributes [2];
|
||||||
attributes[0]= const_cast<sal_Char *>(LDAP_NO_ATTRS);
|
attributes[0]= const_cast<sal_Char *>(LDAP_NO_ATTRS);
|
||||||
attributes[1]= NULL;
|
attributes[1]= NULL;
|
||||||
LdapErrCode retCode = (*s_p_search_s)(mConnection,
|
LdapErrCode retCode = ldap_search_s(mConnection,
|
||||||
mLdapDefinition.mBaseDN.getStr(),
|
mLdapDefinition.mBaseDN.getStr(),
|
||||||
LDAP_SCOPE_SUBTREE,
|
LDAP_SCOPE_SUBTREE,
|
||||||
filter.makeStringAndClear().getStr(), attributes, 0, &result.msg) ;
|
filter.makeStringAndClear().getStr(), attributes, 0, &result.msg) ;
|
||||||
|
|
||||||
checkLdapReturnCode("FindUserDn", retCode,mConnection) ;
|
checkLdapReturnCode("FindUserDn", retCode,mConnection) ;
|
||||||
rtl::OString userDn ;
|
rtl::OString userDn ;
|
||||||
LDAPMessage *entry = (*s_p_first_entry)(mConnection, result.msg) ;
|
LDAPMessage *entry = ldap_first_entry(mConnection, result.msg) ;
|
||||||
|
|
||||||
if (entry != NULL)
|
if (entry != NULL)
|
||||||
{
|
{
|
||||||
sal_Char *charsDn = (*s_p_get_dn)(mConnection, entry) ;
|
sal_Char *charsDn = ldap_get_dn(mConnection, entry) ;
|
||||||
|
|
||||||
userDn = charsDn ;
|
userDn = charsDn ;
|
||||||
(*s_p_memfree)(charsDn) ;
|
ldap_memfree(charsDn) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -273,48 +258,8 @@ void LdapConnection::initConnection()
|
|||||||
return userDn ;
|
return userDn ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined WNT || !defined WITH_OPENLDAP
|
|
||||||
extern "C" { static void SAL_CALL thisModule() {} }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void LdapConnection::loadModule()
|
|
||||||
{
|
|
||||||
if ( !s_Ldap_Module )
|
|
||||||
{
|
|
||||||
#if defined WNT
|
|
||||||
s_Ldap_Module = osl_loadModuleAscii("wldap32.dll", 0);
|
|
||||||
#elif defined WITH_OPENLDAP
|
|
||||||
s_Ldap_Module = osl_loadModuleAscii(
|
|
||||||
("libldap-" SAL_STRINGIFY(LDAP_VENDOR_VERSION_MAJOR) "."
|
|
||||||
SAL_STRINGIFY(LDAP_VENDOR_VERSION_MINOR) ".so."
|
|
||||||
SAL_STRINGIFY(LDAP_VENDOR_VERSION_MAJOR)),
|
|
||||||
0);
|
|
||||||
#else
|
|
||||||
s_Ldap_Module = osl_loadModuleRelativeAscii(
|
|
||||||
&thisModule, "libldap50.so", 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ( s_Ldap_Module )
|
|
||||||
{
|
|
||||||
s_p_unbind_s = (t_ldap_unbind_s)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_unbind_s")).pData));
|
|
||||||
s_p_simple_bind_s = (t_ldap_simple_bind_s)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_simple_bind_s")).pData));
|
|
||||||
s_p_set_option = (t_ldap_set_option)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_set_option")).pData));
|
|
||||||
s_p_err2string = (t_ldap_err2string)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_err2string")).pData));
|
|
||||||
s_p_init = (t_ldap_init)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_init")).pData));
|
|
||||||
s_p_msgfree = (t_ldap_msgfree)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_msgfree")).pData));
|
|
||||||
s_p_get_dn = (t_ldap_get_dn)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_get_dn")).pData));
|
|
||||||
s_p_first_entry = (t_ldap_first_entry)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_first_entry")).pData));
|
|
||||||
s_p_first_attribute = (t_ldap_first_attribute)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_first_attribute")).pData));
|
|
||||||
s_p_next_attribute = (t_ldap_next_attribute)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_next_attribute")).pData));
|
|
||||||
s_p_search_s = (t_ldap_search_s)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_search_s")).pData));
|
|
||||||
s_p_value_free = (t_ldap_value_free)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_value_free")).pData));
|
|
||||||
s_p_get_values = (t_ldap_get_values)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_get_values")).pData));
|
|
||||||
s_p_memfree = (t_ldap_memfree)(osl_getFunctionSymbol(s_Ldap_Module, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ldap_memfree")).pData));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
} } } // extensions.config.ldap
|
} } } // extensions.config.ldap
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -40,20 +40,6 @@ namespace ldap = css::ldap ;
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
struct LdapUserProfile;
|
struct LdapUserProfile;
|
||||||
|
|
||||||
typedef LDAP_API(int) (LDAP_CALL *t_ldap_unbind_s)( LDAP *ld );
|
|
||||||
typedef LDAP_API(int) (LDAP_CALL *t_ldap_simple_bind_s)( LDAP *ld, const char *who, const char *passwd );
|
|
||||||
typedef LDAP_API(int) (LDAP_CALL *t_ldap_set_option)( LDAP *ld, int option, const void *optdata );
|
|
||||||
typedef LDAP_API(char *) (LDAP_CALL *t_ldap_err2string)( int err );
|
|
||||||
typedef LDAP_API(LDAP *) (LDAP_CALL *t_ldap_init)( const char *defhost, int defport );
|
|
||||||
typedef LDAP_API(int) (LDAP_CALL *t_ldap_msgfree)( LDAPMessage *lm );
|
|
||||||
typedef LDAP_API(char *) (LDAP_CALL *t_ldap_get_dn)( LDAP *ld, LDAPMessage *entry );
|
|
||||||
typedef LDAP_API(LDAPMessage *) (LDAP_CALL *t_ldap_first_entry)( LDAP *ld, LDAPMessage *chain );
|
|
||||||
typedef LDAP_API(char *) (LDAP_CALL *t_ldap_first_attribute)( LDAP *ld, LDAPMessage *entry, void **ptr );
|
|
||||||
typedef LDAP_API(char *) (LDAP_CALL *t_ldap_next_attribute)( LDAP *ld, LDAPMessage *entry, void *ptr );
|
|
||||||
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 );
|
|
||||||
typedef LDAP_API(void) (LDAP_CALL *t_ldap_value_free)( char **vals );
|
|
||||||
typedef LDAP_API(char **) (LDAP_CALL *t_ldap_get_values)( LDAP *ld, LDAPMessage *entry, const char *target );
|
|
||||||
typedef LDAP_API(void) (LDAP_CALL *t_ldap_memfree)( void *p );
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/** Struct containing the information on LDAP connection */
|
/** Struct containing the information on LDAP connection */
|
||||||
struct LdapDefinition
|
struct LdapDefinition
|
||||||
@@ -113,9 +99,6 @@ public:
|
|||||||
ldap::LdapConnectionException,
|
ldap::LdapConnectionException,
|
||||||
ldap::LdapGenericException);
|
ldap::LdapGenericException);
|
||||||
|
|
||||||
void loadModule();
|
|
||||||
|
|
||||||
static t_ldap_err2string s_p_err2string;
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void initConnection()
|
void initConnection()
|
||||||
@@ -134,24 +117,8 @@ private:
|
|||||||
/** LDAP connection object */
|
/** LDAP connection object */
|
||||||
LDAP* mConnection ;
|
LDAP* mConnection ;
|
||||||
LdapDefinition mLdapDefinition;
|
LdapDefinition mLdapDefinition;
|
||||||
|
|
||||||
static oslModule s_Ldap_Module;
|
|
||||||
static t_ldap_value_free s_p_value_free;
|
|
||||||
static t_ldap_get_values s_p_get_values;
|
|
||||||
static t_ldap_unbind_s s_p_unbind_s;
|
|
||||||
static t_ldap_simple_bind_s s_p_simple_bind_s;
|
|
||||||
static t_ldap_set_option s_p_set_option;
|
|
||||||
static t_ldap_init s_p_init;
|
|
||||||
static t_ldap_msgfree s_p_msgfree;
|
|
||||||
static t_ldap_get_dn s_p_get_dn;
|
|
||||||
static t_ldap_first_entry s_p_first_entry;
|
|
||||||
static t_ldap_first_attribute s_p_first_attribute;
|
|
||||||
static t_ldap_next_attribute s_p_next_attribute;
|
|
||||||
static t_ldap_search_s s_p_search_s;
|
|
||||||
|
|
||||||
static t_ldap_memfree s_p_memfree;
|
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
}} }
|
}} }
|
||||||
|
|
||||||
|
@@ -85,7 +85,6 @@ LdapUserProfileBe::LdapUserProfileBe( const uno::Reference<uno::XComponentContex
|
|||||||
}
|
}
|
||||||
|
|
||||||
LdapConnection connection;
|
LdapConnection connection;
|
||||||
connection.loadModule();
|
|
||||||
connection.connectSimple(aDefinition);
|
connection.connectSimple(aDefinition);
|
||||||
connection.getUserProfile(loggedOnUser, &data_);
|
connection.getUserProfile(loggedOnUser, &data_);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user