From: <svn...@op...> - 2009-08-02 18:37:50
|
Author: scriptor Date: Sun Aug 2 20:37:34 2009 New Revision: 5709 URL: http://www.opensync.org/changeset/5709 Log: The LDAP plugin of opensync can now be built against libldap60 from mozldap. Packages used on fedora 11 are: mozldap-6.0.5-5.fc11.x86_64 mozldap-devel-6.0.5-5.fc11.x86_64 mozldap-tools-6.0.5-5.fc11.x86_64 So there are now two possibilities for the linking, and two possibilities of LDAP servers to interact with. This means: If the plugin is built with libldap from openldap, it can talk to: - slapd from openldap - The fedora directory server, which is essentially ns-slapd derived from Mozilla. If the plugin is built with libldap60 from Mozilla (mozldap), it can talk to: - slapd from openldap - The fedora directory server (service dirsrv; ns-slapd) Please note: The build process as well as the synchronization functionality are still in alpha state. Especially the authentication towards the LDAP server has some problems and bugs in the current version. The documentation is NOT up to date, yet. The test suite is NOT up to date, either. Added: branches/3rd-party-cmake-modules/modules/FindLibMozLdap.cmake Modified: plugins/ldap-sync/CMakeLists.txt plugins/ldap-sync/config.h.cmake plugins/ldap-sync/src/CMakeLists.txt plugins/ldap-sync/src/ldap_connect.c plugins/ldap-sync/src/ldap_debug.c plugins/ldap-sync/src/ldap_plugin.c plugins/ldap-sync/src/ldap_plugin.h plugins/ldap-sync/src/ldap_sasl.c Added: branches/3rd-party-cmake-modules/modules/FindLibMozLdap.cmake ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ branches/3rd-party-cmake-modules/modules/FindLibMozLdap.cmake Sun Aug 2 20:37:34 2009 (r5709) @@ -0,0 +1,96 @@ +# Try and find libmozldap. +# As soon as libmozldap has been found, the following variables will be defined: +# +# LIBMOZLDAP_FOUND (this is or is not #defined) +# MOZLDAP_INCLUDE_DIR:DIRPATH +# MOZLDAP_LIBRARY:FILEPATH +# +# +# Copyright (c) 2009 Juergen Leising <jle...@us...> +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + + +MESSAGE(STATUS "checking for libmozldap...") + +# Prepare for using pkg-config +INCLUDE( FindPkgConfig ) + +IF ( LibMozLdap_FIND_REQUIRED ) + SET( _pkgconfig_REQUIRED "REQUIRED" ) +ELSE ( LibMozLdap_FIND_REQUIRED ) + SET( _pkgconfig_REQUIRED "" ) +ENDIF ( LibMozLdap_FIND_REQUIRED ) + +FIND_PROGRAM( PKGCONFIG_EXECUTABLE NAMES pkg-config ) + + + +# Search for the header files and the libraries by means of pkg-config +IF ( PKG_CONFIG_FOUND ) + MESSAGE (STATUS " Trying to invoke pkg-config...") + # PKG_SEARCH_MODULE ( LIBMOZLDAP ${_pkgconfig_REQUIRED} mozldap ) + PKG_CHECK_MODULES ( LIBMOZLDAP ${_pkgconfig_REQUIRED} mozldap ) + IF ( LIBMOZLDAP_FOUND ) + MESSAGE (STATUS " pkg-config found mozldap.") + ELSE ( LIBMOZLDAP_FOUND ) + MESSAGE (STATUS " pkg-config did NOT find mozldap.") + ENDIF ( LIBMOZLDAP_FOUND ) +ENDIF ( PKG_CONFIG_FOUND ) + + + + +# Manually searching for header and library. +# Only, if it has not been found, yet. Which would also be the case, +# if pkg-config could not have been found. +IF ( NOT MOZLDAP_INCLUDE_DIR ) + MESSAGE (STATUS " Falling back to searching for mozldap/ldap.h without pkg-config" ) + FIND_PATH(MOZLDAP_INCLUDE_DIR NAMES mozldap/ldap.h + PATHS /include /usr/include /usr/local/include /usr/share/include /opt/include + DOC "Try and find the header file mozldap/ldap.h.") +ENDIF ( NOT MOZLDAP_INCLUDE_DIR ) + + +IF ( NOT LIBMOZLDAP_LIBRARIES ) + MESSAGE (STATUS " Falling back to searching for libldap60 and libssldap60 without pkg-config" ) + + FIND_LIBRARY(MOZLDAP_LIBRARY NAMES ldap60 + PATHS /usr/lib /lib /usr/local/lib /usr/share/lib /opt/lib /opt/share/lib /var/lib /usr/lib64 /lib64 /usr/local/lib64 /usr/share/lib64 /opt/lib64 /opt/share/lib64 /var/lib64 + DOC "Try and find libldap60 from Mozilla.") + + FIND_LIBRARY(MOZSSLDAP_LIBRARY NAMES ssldap60 + PATHS /usr/lib /lib /usr/local/lib /usr/share/lib /opt/lib /opt/share/lib /var/lib /usr/lib64 /lib64 /usr/local/lib64 /usr/share/lib64 /opt/lib64 /opt/share/lib64 /var/lib64 + DOC "Try and find libssldap60 from Mozilla.") + + SET ( LIBMOZLDAP_LIBRARIES ${MOZLDAP_LIBRARY} ${MOZSSLDAP_LIBRARY} ) + +ENDIF ( NOT LIBMOZLDAP_LIBRARIES ) + + + + + +# Reviewing the results +IF (MOZLDAP_INCLUDE_DIR AND MOZLDAP_LIBRARY) + SET( LIBMOZLDAP_FOUND 1 ) + get_filename_component(MOZLDAP_LIBRARY_DIRS ${MOZLDAP_LIBRARY} PATH) + MESSAGE(STATUS " Found ${MOZLDAP_LIBRARY}") +ELSE (MOZLDAP_INCLUDE_DIR AND MOZLDAP_LIBRARY) + IF ( LibMozLdap_FIND_REQUIRED ) + MESSAGE( FATAL_ERROR " Could NOT find libldap60 from Mozilla. The ldap plugin needs this library.") + ELSE ( LibMozLdap_FIND_REQUIRED ) + MESSAGE( STATUS " Could NOT find libldap60 from Mozilla." ) + MESSAGE( STATUS " LIBMOZLDAP_INCLUDE_DIR = ${LIBMOZLDAP_INCLUDE_DIR}" ) + MESSAGE( STATUS " LIBMOZLDAP_INCLUDE_DIRS = ${LIBMOZLDAP_INCLUDE_DIRS}" ) + MESSAGE( STATUS " LIBMOZLDAP_LIBRARY = ${LIBMOZLDAP_LIBRARY}" ) + MESSAGE( STATUS " LIBMOZLDAP_LIBRARY_DIRS = ${LIBMOZLDAP_LIBRARY_DIRS}" ) + MESSAGE( STATUS " LIBMOZLDAP_LIBDIR = ${LIBMOZLDAP_LIBDIR}" ) + + + ENDIF ( LibMozLdap_FIND_REQUIRED ) +ENDIF (MOZLDAP_INCLUDE_DIR AND MOZLDAP_LIBRARY) + Modified: plugins/ldap-sync/CMakeLists.txt ============================================================================== --- plugins/ldap-sync/CMakeLists.txt Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/CMakeLists.txt Sun Aug 2 20:37:34 2009 (r5709) @@ -40,11 +40,23 @@ FIND_PACKAGE( GLIB2 REQUIRED ) FIND_PACKAGE( LibXml2 REQUIRED ) FIND_PACKAGE( LibXslt REQUIRED ) -FIND_PACKAGE( LibLdap REQUIRED ) +FIND_PACKAGE( LibLdap ) +FIND_PACKAGE( LibMozLdap ) FIND_PACKAGE( LibGCrypt REQUIRED ) +FIND_PACKAGE( LibSASL2 REQUIRED ) FIND_PACKAGE( LibGSSAPIV2 ) +# By default use openldap, if available. +# Fall back to mozldap only, if necessary (and possible, of course). +IF ( LIBLDAP_FOUND ) + SET ( USE_OPENLDAP 1 ) +ELSE ( LIBLDAP_FOUND ) + IF ( LIBMOZLDAP_FOUND ) + SET ( USE_MOZLDAP 1 ) + ENDIF ( LIBMOZLDAP_FOUND ) +ENDIF ( LIBLDAP_FOUND ) + ############### Doxygen ############################ MESSAGE(STATUS "checking for doxygen...") @@ -129,6 +141,13 @@ MESSAGE(STATUS "CWD = $ENV{PWD}" ) MESSAGE(STATUS "LDAP_PLUGIN_OPENSYNC_CONFIGDIR = ${LDAP_PLUGIN_OPENSYNC_CONFIGDIR}") MESSAGE(STATUS "LDAP_PLUGIN_OPENSYNC_SCHEMASDIR = ${LDAP_PLUGIN_OPENSYNC_SCHEMASDIR}") +IF ( USE_OPENLDAP ) + MESSAGE(STATUS "libldap from openldap is to be used.") +ELSE ( USE_OPENLDAP ) + IF ( USE_MOZLDAP ) + MESSAGE(STATUS "libldap60 from Mozilla is to be used.") + ENDIF ( USE_MOZLDAP ) +ENDIF ( USE_OPENLDAP ) ##################### debugging cmake... ################################# Modified: plugins/ldap-sync/config.h.cmake ============================================================================== --- plugins/ldap-sync/config.h.cmake Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/config.h.cmake Sun Aug 2 20:37:34 2009 (r5709) @@ -1,21 +1,107 @@ #ifndef _CONFIG_H_LDAP_PLUGIN #define _CONFIG_H_LDAP_PLUGIN +/* CFLAGS for the build type "Debug" */ +#cmakedefine CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" -#define CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" -#define CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" -#define CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" -#define CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" -#define HAVE_DOT "${HAVE_DOT}" -#define LDAP_INCLUDE_DIR "${LDAP_INCLUDE_DIR}" -#define LDAP_LIBRARY "${LDAP_LIBRARY}" -#define LIBGSSAPIV2_FOUND "${LIBGSSAPIV2_FOUND}" -#define LIBLDAP_FOUND "${LIBLDAP_FOUND}" -#define LIBSASL2_FOUND "${LIBSASL2_FOUND}" -#define LIBXSLT_FOUND "${LIBXSLT_FOUND}" -#define LDAP_PLUGIN_OPENSYNC_CONFIGDIR "${LDAP_PLUGIN_OPENSYNC_CONFIGDIR}" -#define LDAP_PLUGIN_OPENSYNC_SCHEMASDIR "${LDAP_PLUGIN_OPENSYNC_SCHEMASDIR}" -#define VERSION "${VERSION}" +/* LFLAGS for the build type "Debug" */ +#cmakedefine CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" + +/* Where are the cmake modules? */ +#cmakedefine CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" + +/* LFLAGS for the build type "Debug" */ +#cmakedefine CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" + +/* Does the program "dot" exist? Useful for doxygen based documentation + of the source code */ +#cmakedefine HAVE_DOT + + + + +/********************************************************/ +/* There are two alternatives for us which LDAP client library + to use: */ + + + +/****** 1. libldap from openldap: http://www.openldap.org/ ******/ + +/* Whether or not libldap from openldap has been found. */ +#cmakedefine LIBLDAP_FOUND + +/* Whether or not libldap from openldap is to be used. */ +#cmakedefine USE_OPENLDAP + +/* Where is the ldap.h from openldap? */ +#cmakedefine LDAP_INCLUDE_DIR "${LDAP_INCLUDE_DIR}" + +/* Where is libldap.so from openldap? */ +#cmakedefine LDAP_LIBRARY "${LDAP_LIBRARY}" + +/* In which directories can libldap.so be found? */ +#cmakedefine LDAP_LIBRARY_DIRS "${LDAP_LIBRARY_DIRS}" + + + +/****** 2. libldap60 from Mozilla: + http://www.mozilla.org/directory/csdk.html *******/ + +/* Whether or not libldap60 from Mozilla has been found. */ +#cmakedefine LIBMOZLDAP_FOUND + +/* Whether or not libldap60 from Mozilla is to be used. */ +#cmakedefine USE_MOZLDAP + +/* Where is "mozldap/ldap.h" from Mozilla? Please note: + You must write "include <mozldap/ldap.h>" to use this, + not just "include <ldap.h>". (deliberately left out the + hash sign/number sign here to avoid confusing the preprocessor) */ +#cmakedefine MOZLDAP_INCLUDE_DIR "${MOZLDAP_INCLUDE_DIR}" + +/* Where is ldap.h from Mozilla, as pkg-config puts it. + And this means, that one would have to "include <ldap.h>" + WITHOUT prefixing it with "mozldap/". + Be careful with writing the header files on systems + where both of these client libraries are installed. +*/ +#cmakedefine LIBMOZLDAP_INCLUDEDIR "${LIBMOZLDAP_INCLUDEDIR}" + +/* Again, as pkg-config puts it: */ +#cmakedefine LIBMOZLDAP_INCLUDE_DIRS "${LIBMOZLDAP_INCLUDE_DIRS}" + +/* Where is libldap60 from Mozilla? */ +#cmakedefine MOZLDAP_LIBRARY "${MOZLDAP_LIBRARY}" + +/* Which libraries do we need to link against? */ +#cmakedefine LIBMOZLDAP_LIBRARIES "${LIBMOZLDAP_LIBRARIES}" + +/* Where is libldap60 from Mozilla? As pkg-config puts it: */ +#cmakedefine LIBMOZLDAP_LIBDIR "${LIBMOZLDAP_LIBDIR}" + +/***********************************************************/ + + + +/* Whether or not the cyrus-sasl library has been found. */ +#cmakedefine LIBSASL2_FOUND + +/* Is the GSSAPIV2 library available? For kerberos 5. Optional. */ +#cmakedefine LIBGSSAPIV2_FOUND + +/* Whether or not libxslt has been found. */ +#cmakedefine LIBXSLT_FOUND + +/* Where are the libopensync configuration files by default? */ +#cmakedefine LDAP_PLUGIN_OPENSYNC_CONFIGDIR "${LDAP_PLUGIN_OPENSYNC_CONFIGDIR}" + +/* Where are the XML schema files (*.xsd) for XML validation purposes? */ +#cmakedefine LDAP_PLUGIN_OPENSYNC_SCHEMASDIR "${LDAP_PLUGIN_OPENSYNC_SCHEMASDIR}" + +/* The version of the ldap-sync plugin which shares the version number + of the whole opensync package */ +#cmakedefine VERSION "${VERSION}" #endif Modified: plugins/ldap-sync/src/CMakeLists.txt ============================================================================== --- plugins/ldap-sync/src/CMakeLists.txt Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/src/CMakeLists.txt Sun Aug 2 20:37:34 2009 (r5709) @@ -20,10 +20,101 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # - -LINK_DIRECTORIES( ${OPENSYNC_LIBRARY_DIRS} ${GLIB2_LIBRARY_DIRS} ${LIBXML2_LIBRARY_DIRS} ${LIBXSLT_LIBRARY_DIRS} ${LDAP_LIBRARY_DIRS} ${SASL2_LIBRARY_DIRS} ${GSSAPIV2_LIBRARY_DIRS}) -INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} ${OPENSYNC_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIRS} ${LIBXSLT_INCLUDE_DIRS} ${LDAP_INCLUDE_DIRS} ${SASL2_INCLUDE_DIRS} ${GSSAPIV2_INCLUDE_DIRS}) + + +# Determine _LDAP_INCLUDE_DIRS +IF ( LIBLDAP_FOUND ) + # libldap from openldap + SET ( _LDAP_INCLUDE_DIRS ${LDAP_INCLUDE_DIR} ) + +ELSE ( LIBLDAP_FOUND ) + IF ( LIBMOZLDAP_FOUND ) + #libldap60 from Mozilla + IF ( MOZLDAP_INCLUDE_DIR ) + SET ( _LDAP_INCLUDE_DIRS ${MOZLDAP_INCLUDE_DIR} ) + + ELSE ( MOZLDAP_INCLUDE_DIR ) + IF ( LIBMOZLDAP_INCLUDEDIR ) + SET ( _LDAP_INCLUDE_DIRS ${LIBMOZLDAP_INCLUDEDIR}) + ENDIF ( LIBMOZLDAP_INCLUDEDIR ) + ENDIF ( MOZLDAP_INCLUDE_DIR ) + + ELSE ( LIBMOZLDAP_FOUND ) + MESSAGE( FATAL_ERROR " Neither libldap from openldap nor libldap60 from Mozilla could be found. The ldap-sync plugin requires one of these libraries including the header files, as can be found in \"development packages\" or \"SDK's\"." ) + ENDIF ( LIBMOZLDAP_FOUND ) +ENDIF ( LIBLDAP_FOUND ) + + + + +# Determine _LDAP_LIBRARY_DIRS +IF ( LIBLDAP_FOUND ) + SET ( _LDAP_LIBRARY_DIRS ${LDAP_LIBRARY_DIRS} ) +ELSE ( LIBLDAP_FOUND ) + IF ( LIBMOZLDAP_FOUND ) + IF ( LIBMOZLDAP_LIBDIR ) + SET ( _LDAP_LIBRARY_DIRS ${LIBMOZLDAP_LIBDIR} ) + ENDIF ( LIBMOZLDAP_LIBDIR ) + ELSE ( LIBMOZLDAP_FOUND ) + MESSAGE( FATAL_ERROR " Neither libldap from openldap nor libldap60 from Mozilla could be found. The ldap-sync plugin requires one of these." ) + ENDIF ( LIBMOZLDAP_FOUND ) +ENDIF ( LIBLDAP_FOUND ) + + + + +# Determine _LDAP_LIBRARIES +IF ( LIBLDAP_FOUND ) + SET ( _LDAP_LIBRARIES ${LDAP_LIBRARY} ) +ELSE ( LIBLDAP_FOUND ) + IF ( LIBMOZLDAP_FOUND ) + + IF ( LIBMOZLDAP_LIBRARIES ) + SET ( _LDAP_LIBRARIES ${LIBMOZLDAP_LIBRARIES} ) + + ELSE ( LIBMOZLDAP_LIBRARIES ) + IF ( MOZLDAP_LIBRARY ) + SET ( _LDAP_LIBRARIES ${MOZLDAP_LIBRARY} ) + ELSE ( MOZLDAP_LIBRARY ) + MESSAGE( FATAL_ERROR " Neither LIBMOZLDAP_LIBRARIES nor MOZLDAP_LIBRARY has been defined." ) + ENDIF ( MOZLDAP_LIBRARY ) + + ENDIF ( LIBMOZLDAP_LIBRARIES ) + + ELSE ( LIBMOZLDAP_FOUND ) + MESSAGE( FATAL_ERROR " Neither libldap from openldap nor libldap60 from Mozilla could be found. The ldap-sync plugin requires one of these." ) + ENDIF ( LIBMOZLDAP_FOUND ) +ENDIF ( LIBLDAP_FOUND ) + + + + + + + + +# Safety checks +IF ( NOT _LDAP_INCLUDE_DIRS ) + MESSAGE( FATAL_ERROR " _LDAP_INCLUDE_DIRS could not be determined. The ldap-sync plugin requires the header files of an LDAP client library, either from openldap or from Mozilla." ) +ELSE ( NOT _LDAP_INCLUDE_DIRS ) + MESSAGE( STATUS "_LDAP_INCLUDE_DIRS = \"${_LDAP_INCLUDE_DIRS}\"" ) +ENDIF ( NOT _LDAP_INCLUDE_DIRS ) + +IF ( NOT _LDAP_LIBRARY_DIRS ) + MESSAGE( FATAL ERROR " _LDAP_LIBRARY_DIRS could not be determined. The build process of the ldap-sync plugin must know where to find the ldap libraries.") +ELSE ( NOT _LDAP_LIBRARY_DIRS ) + MESSAGE( STATUS "_LDAP_LIBRARY_DIRS = \"${_LDAP_LIBRARY_DIRS}\"" ) +ENDIF ( NOT _LDAP_LIBRARY_DIRS ) + +IF ( NOT _LDAP_LIBRARIES ) + MESSAGE( FATAL ERROR " _LDAP_LIBRARIES could not be determined. The build process of the ldap-sync plugin requires the ldap library.") +ELSE ( NOT _LDAP_LIBRARIES ) + MESSAGE( STATUS "_LDAP_LIBRARIES = \"${_LDAP_LIBRARIES}\"" ) +ENDIF ( NOT _LDAP_LIBRARIES ) + +LINK_DIRECTORIES( ${OPENSYNC_LIBRARY_DIRS} ${GLIB2_LIBRARY_DIRS} ${LIBXML2_LIBRARY_DIRS} ${LIBXSLT_LIBRARY_DIRS} ${_LDAP_LIBRARY_DIRS} ${SASL2_LIBRARY_DIRS} ${GSSAPIV2_LIBRARY_DIRS}) +INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} ${OPENSYNC_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIRS} ${LIBXSLT_INCLUDE_DIRS} ${_LDAP_INCLUDE_DIRS} ${SASL2_INCLUDE_DIRS} ${GSSAPIV2_INCLUDE_DIRS}) INCLUDE( Compiler ) @@ -33,8 +124,8 @@ -TARGET_LINK_LIBRARIES( ldap-sync ${OPENSYNC_LIBRARIES} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARY_DIRS} ${LIBXSLT_LIBRARIES} ${LDAP_LIBRARY} ${GCRYPT_LIBRARY} ${SASL2_LIBRARY}) -TARGET_LINK_LIBRARIES( ldap-format ${OPENSYNC_LIBRARIES} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARY_DIRS} ${LIBXSLT_LIBRARIES} ${LDAP_LIBRARY} ${GCRYPT_LIBRARY}) +TARGET_LINK_LIBRARIES( ldap-sync ${OPENSYNC_LIBRARIES} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARY_DIRS} ${LIBXSLT_LIBRARIES} ${_LDAP_LIBRARIES} ${GCRYPT_LIBRARY} ${SASL2_LIBRARY}) +TARGET_LINK_LIBRARIES( ldap-format ${OPENSYNC_LIBRARIES} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARY_DIRS} ${LIBXSLT_LIBRARIES} ${_LDAP_LIBRARIES} ${GCRYPT_LIBRARY}) Modified: plugins/ldap-sync/src/ldap_connect.c ============================================================================== --- plugins/ldap-sync/src/ldap_connect.c Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/src/ldap_connect.c Sun Aug 2 20:37:34 2009 (r5709) @@ -131,11 +131,27 @@ - +#ifdef USE_OPENLDAP if (ldap_is_ldap_url(sinkenv->servername) || ldap_is_ldaps_url(sinkenv->servername)) { +#else +# ifdef USE_MOZLDAP + if (ldap_is_ldap_url(sinkenv->servername)) { +# else +# error __FILE__ ":" __LINE__ ": ERROR: Neither USE_OPENLDAP nor USE_MOZLDAP has been defined. Compiler cannot proceed." +# endif +#endif + sinkenv->url = g_strdup(sinkenv->servername); +#ifdef USE_OPENLDAP ldap_initialize(&(sinkenv->ld), sinkenv->servername); +#else +# ifdef USE_MOZLDAP + sinkenv->ld = ldap_init(sinkenv->servername, sinkenv->serverport); +# else + sinkenv->ld = NULL; +# endif +#endif if (sinkenv->ld == NULL ) { osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "Could not connect to \"%s\"", sinkenv->servername); @@ -156,10 +172,21 @@ } - osync_trace(TRACE_INTERNAL, "%s:%i: INFO: url = \"%s\"\n", __FILE__, __LINE__, sinkenv->url); + +#ifdef USE_OPENLDAP ldap_initialize(&(sinkenv->ld), sinkenv->url); +#else +# ifdef USE_MOZLDAP + sinkenv->ld = ldap_init(sinkenv->servername, sinkenv->serverport); +# else + sinkenv->ld = NULL; +#endif +#endif + + + if (sinkenv->ld == NULL ) { osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "Could not connect to \"%s\"", sinkenv->url); @@ -680,7 +707,7 @@ */ osync_bool ldap_plugin_set_ldap_protocol (OSyncContext *ctx, OSyncPluginInfo *info, sink_environment *sinkenv, OSyncError **error) { - int *ldap_version = NULL; + int *ldap_protocol_version = NULL; osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, ctx, info, sinkenv, error); @@ -710,9 +737,9 @@ char *ldap_error1 = ldap_plugin_report_ldap_error(sinkenv, __FILE__, __LINE__, ldap_errno); /* Couldn't set version, store connection's version in sinkenv */ - ldap_get_option(sinkenv->ld, LDAP_OPT_PROTOCOL_VERSION, ldap_version); + ldap_get_option(sinkenv->ld, LDAP_OPT_PROTOCOL_VERSION, ldap_protocol_version); - if (ldap_version == NULL) { + if (ldap_protocol_version == NULL) { if (ldap_error1 == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: 1. Could not set LDAP Version to %i. 2. Could not retrieve ldap_version, either. Returning.\n", __FILE__, __LINE__, sinkenv->ldap_version); } else { @@ -723,13 +750,13 @@ } if (ldap_error1 == NULL) { - osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: WARNING: Could not set LDAP Version to %i, using %i\n", __FILE__, __LINE__, sinkenv->ldap_version, *ldap_version); + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: WARNING: Could not set LDAP Version to %i, using %i\n", __FILE__, __LINE__, sinkenv->ldap_version, *ldap_protocol_version); } else { - osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: WARNING: Could not set LDAP Version to %i, because: \"%s\". Using version %i. \n", __FILE__, __LINE__, sinkenv->ldap_version, ldap_error1, *ldap_version); + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: WARNING: Could not set LDAP Version to %i, because: \"%s\". Using version %i. \n", __FILE__, __LINE__, sinkenv->ldap_version, ldap_error1, *ldap_protocol_version); } - sinkenv->ldap_version = *ldap_version; + sinkenv->ldap_version = *ldap_protocol_version; goto error; } @@ -893,7 +920,7 @@ osync_trace(TRACE_INTERNAL, "Simple authentication towards LDAP server selected"); - passwd.bv_val = ber_strdup(bindpwd); + passwd.bv_val = g_strdup(bindpwd); passwd.bv_len = strlen( passwd.bv_val ); @@ -927,10 +954,10 @@ osync_trace(TRACE_INTERNAL, "SASL based authentication towards LDAP server selected"); - passwd.bv_val = ber_strdup(bindpwd); + passwd.bv_val = g_strdup(bindpwd); passwd.bv_len = strlen( passwd.bv_val ); - tmp_authmech = ber_strdup(authmech); - tmp_authcid = ber_strdup(authcid); + tmp_authmech = g_strdup(authmech); + tmp_authcid = g_strdup(authcid); // Load default parameters into a libldap specific struct @@ -951,7 +978,7 @@ char *extra_error = NULL; - ldap_plugin_printf("%s:%i: ldap_errno = %i", __FILE__, __LINE__, ldap_errno); + ldap_plugin_printf("%s:%i: ERROR: ldap_errno = %i", __FILE__, __LINE__, ldap_errno); if ( (ldap_errno == LDAP_AUTH_METHOD_NOT_SUPPORTED) || @@ -1335,7 +1362,15 @@ if (all_entries == NULL) { int result_code = 0; + +#ifdef LDAP_OPT_RESULT_CODE + // openldap version if (ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code) != LDAP_OPT_SUCCESS) { +#else + // mozldap version + if (ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code)) { +#endif + osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_get_option() has failed. result_code could not be filled in.\n", __FILE__, __LINE__); } else { if (result_code != LDAP_SUCCESS) { @@ -1470,11 +1505,23 @@ switch(kind_of_attributes) { case USER_ATTRIBUTES: +#ifdef LDAP_ALL_USER_ATTRIBUTES + // openldap version userattributes[0] = LDAP_ALL_USER_ATTRIBUTES; +#else + // mozldap version + userattributes[0] = NULL; +#endif break; case OPERATIONAL_ATTRIBUTES: +#ifdef LDAP_ALL_OPERATIONAL_ATTRIBUTES + // openldap version userattributes[0] = LDAP_ALL_OPERATIONAL_ATTRIBUTES; +#else + // mozldap version + userattributes[0] = "+"; +#endif break; case OBJECTCLASSES: @@ -1486,7 +1533,14 @@ break; default: +#ifdef LDAP_ALL_USER_ATTRIBUTES + // openldap version userattributes[0] = LDAP_ALL_USER_ATTRIBUTES; +#else + // xxx jl: TODO ??????????????? + // mozldap version + userattributes[0] = NULL; +#endif }; @@ -1523,8 +1577,9 @@ searchbase, scope, filter, - (char **)&userattributes, ///< The attrs parameter is a null-terminated - ///< array of attribute descriptions to return from matching entries. + (char **)&userattributes, ///< Quoting from ldap_search(3) from openldap: + ///< The attrs parameter is a null-terminated array of attribute + ///< descriptions to return from matching entries. ///< If NULL is specified, the return of all user attributes is ///< requested. The description "*" (LDAP_ALL_USER_ATTRIBUTES) may be ///< used to request all user attributes to be returned. @@ -1561,11 +1616,13 @@ case LDAP_SCOPE_SUBTREE: scope_str = "sub"; break; - + +#ifdef LDAP_SCOPE_CHILDREN + // openldap version; mozldap does not support this case LDAP_SCOPE_CHILDREN: scope_str = "children"; break; - +#endif default: scope_str = "default"; break; @@ -1645,8 +1702,14 @@ if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, dn, "(objectClass=*)", LDAP_SCOPE_ONELEVEL, USER_ATTRIBUTES, sinkenv, TRUE, &all_results, error)) { int result_code = 0; - + +#ifdef LDAP_OPT_RESULT_CODE + // openldap version ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); +#else + // mozldap version + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code); +#endif if (result_code == LDAP_NO_SUCH_OBJECT) { #ifdef DEBUG_change_type_deleted @@ -1671,8 +1734,14 @@ if (all_results == NULL) { int result_code = 0; - + +#ifdef LDAP_OPT_RESULT_CODE + // openldap version ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); +#else + // mozldap version + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code); +#endif if (result_code == LDAP_NO_SUCH_OBJECT) { #ifdef DEBUG_change_type_deleted @@ -2038,8 +2107,15 @@ osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } - + +#ifdef LDAP_OPT_RESULT_CODE + // openldap version ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); +#else + // mozldap version + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code); +#endif + if (result_code == LDAP_NO_SUCH_OBJECT) { osync_trace(TRACE_INTERNAL, "%s:%i: Either the searchbase (\"%s\") is really wrong, or the user does not have sufficient access permissions to this particular part of the DIT, or there is indeed not a single entry.", __FILE__, __LINE__, base); @@ -2066,7 +2142,14 @@ int result_code = 0; +#ifdef LDAP_OPT_RESULT_CODE + // openldap version ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); +#else + // mozldap version + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code); +#endif + if (result_code == LDAP_SUCCESS) { goto done; @@ -2495,7 +2578,14 @@ osync_trace(TRACE_INTERNAL, "%s:%i: uid = NULL. Returning NULL. May be, that there is really not a single entry stored on the LDAP server. Authentication mechanism = \"%s\", objtype = \"%s\", scope LDAP_SCOPE_ONELEVEL, searchbase = \"%s\", filter=\"%s\".\n", __FILE__, __LINE__, sinkenv->authmech, osync_objtype_sink_get_name(sinkenv->sink), sinkenv->searchbase, filter); +#ifdef LDAP_OPT_RESULT_CODE + // openldap version if (ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code) != LDAP_OPT_SUCCESS) { +#else + // mozldap version + if (ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code)) { +#endif + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_get_option() has failed. result_code could not be filled in. \n", __FILE__, __LINE__); goto error; @@ -4485,7 +4575,7 @@ filter = g_strdup_printf("(entryCSN=*)"); } - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, filter, LDAP_SCOPE_SUB, OPERATIONAL_ATTRIBUTES, sinkenv, FALSE, &messages, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, filter, LDAP_SCOPE_SUBTREE, OPERATIONAL_ATTRIBUTES, sinkenv, FALSE, &messages, error)) { if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } @@ -4500,7 +4590,7 @@ filter = g_strdup_printf("(modifyTimestamp=*)"); } - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, filter, LDAP_SCOPE_SUB, FEDORADSmodifyTimestamp, sinkenv, FALSE, &messages, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, filter, LDAP_SCOPE_SUBTREE, FEDORADSmodifyTimestamp, sinkenv, FALSE, &messages, error)) { if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } @@ -4522,7 +4612,15 @@ if (messages == NULL) { int result_code = 0; + +#ifdef LDAP_OPT_RESULT_CODE + // openldap version if (ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code) != LDAP_OPT_SUCCESS) { +#else + // mozldap version + if (ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code)) { +#endif + osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_get_option() has failed. result_code could not be filled in.\n", __FILE__, __LINE__); } else { char *error_msg = ldap_plugin_report_ldap_error(sinkenv, __FILE__, __LINE__, result_code); Modified: plugins/ldap-sync/src/ldap_debug.c ============================================================================== --- plugins/ldap-sync/src/ldap_debug.c Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/src/ldap_debug.c Sun Aug 2 20:37:34 2009 (r5709) @@ -124,7 +124,14 @@ if (sinkenv->ld) { +#ifdef LDAP_OPT_RESULT_CODE + // openldap version: if (ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code) != LDAP_OPT_SUCCESS) { +#else + // mozldap version: + if (ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code)) { +#endif + ldap_plugin_printf("%s:%i: ERROR: ldap_get_option() has failed. result_code could not be filled in.", __FILE__, __LINE__); } else { if (result_code != 0) { @@ -478,7 +485,13 @@ strncat(buf, msg2, 4096 - strlen(buf)); if (sinkenv && sinkenv->ld) { +#ifdef LDAP_OPT_DIAGNOSTIC_MESSAGE + // openldap version ldap_get_option(sinkenv->ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, &msg3); +#else + // mozldap version + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_STRING, &msg3); +#endif } if (msg3 && msg3[0]) { Modified: plugins/ldap-sync/src/ldap_plugin.c ============================================================================== --- plugins/ldap-sync/src/ldap_plugin.c Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/src/ldap_plugin.c Sun Aug 2 20:37:34 2009 (r5709) @@ -3310,7 +3310,13 @@ int result_code = 0; +#ifdef LDAP_OPT_RESULT_CODE + // openldap version: ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); +#else + // mozldap version: + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code); +#endif // OK. This error is expected. ldap_add_ext_s() is due. @@ -3557,7 +3563,14 @@ if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, *dn_of_modified_entry, "(objectClass=*)", LDAP_SCOPE_ONELEVEL, USER_ATTRIBUTES, sinkenv, FALSE, &dn_list, error)) { int result_code2 = 0; + +#ifdef LDAP_OPT_RESULT_CODE + // openldap version: ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code2); +#else + // mozldap version: + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code2); +#endif if (result_code2 != LDAP_SUCCESS) { char *msg = ldap_plugin_report_ldap_error(sinkenv, __FILE__, __LINE__, result_code2); @@ -3956,8 +3969,19 @@ int result_code = 0; const char *diagnostic = ""; + +#ifdef LDAP_OPT_RESULT_CODE ldap_set_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); +#else + ldap_set_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code); +#endif + + +#ifdef LDAP_OPT_DIAGNOSTIC_MESSAGE ldap_set_option(sinkenv->ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, diagnostic); +#else + ldap_set_option(sinkenv->ld, LDAP_OPT_ERROR_STRING, diagnostic); +#endif } Modified: plugins/ldap-sync/src/ldap_plugin.h ============================================================================== --- plugins/ldap-sync/src/ldap_plugin.h Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/src/ldap_plugin.h Sun Aug 2 20:37:34 2009 (r5709) @@ -33,13 +33,33 @@ #ifndef _LDAP_PLUGIN_H #define _LDAP_PLUGIN_H +#include "config.h" #include <errno.h> #include <ctype.h> #include <gcrypt.h> #include <glib.h> + +#ifdef LIBLDAP_FOUND #include <lber.h> #include <ldap.h> +#else +# ifdef LIBMOZLDAP_FOUND +# ifdef MOZLDAP_INCLUDE_DIR +# include <mozldap/ldap.h> +# include <mozldap/ldap_ssl.h> +# else +# ifdef LIBMOZLDAP_INCLUDEDIR +// I want to make sure that it is really the "mozldap/ldap.h" that +// is to be included. And NOT some /usr/include/ldap.h. +# include <../mozldap/ldap.h> +# include <../mozldap/ldap_ssl.h> +# endif +# endif +# endif +#endif + + #include <libxml/parser.h> #include <libxml/tree.h> #include <libxml/xmlmemory.h> @@ -68,7 +88,6 @@ #include <sys/stat.h> #include <unistd.h> -#include "config.h" #if 0 @@ -131,7 +150,7 @@ ///< ldap_format_convert_xmlinternal2ldap() -#undef DEBUG_auth +// undef DEBUG_auth #undef DEBUG_configuration #undef DEBUG_detection #undef DEBUG_ldapdata_from_server Modified: plugins/ldap-sync/src/ldap_sasl.c ============================================================================== --- plugins/ldap-sync/src/ldap_sasl.c Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/src/ldap_sasl.c Sun Aug 2 20:37:34 2009 (r5709) @@ -151,23 +151,27 @@ lutilSASLdefaults *ldap_plugin_lutil_sasl_defaults(LDAP *ld, char *mech, char *realm, char *authcid, char *passwd, char *authzid) { - lutilSASLdefaults *defaults; + lutilSASLdefaults *defaults = NULL; if (ld == NULL) { ldap_plugin_printf("%s:%i: ERROR: ld = NULL. Returning.", __FILE__, __LINE__); return NULL; } - - defaults = ber_memalloc( sizeof( lutilSASLdefaults ) ); + +#ifdef USE_OPENLDAP + defaults = ber_memalloc(sizeof( lutilSASLdefaults )); +#else + defaults = malloc(sizeof( lutilSASLdefaults )); +#endif if( defaults == NULL ) return NULL; - defaults->mech = mech ? ber_strdup(mech) : NULL; - defaults->realm = realm ? ber_strdup(realm) : NULL; - defaults->authcid = authcid ? ber_strdup(authcid) : NULL; - defaults->passwd = passwd ? ber_strdup(passwd) : NULL; - defaults->authzid = authzid ? ber_strdup(authzid) : NULL; + defaults->mech = mech ? g_strdup(mech) : NULL; + defaults->realm = realm ? g_strdup(realm) : NULL; + defaults->authcid = authcid ? g_strdup(authcid) : NULL; + defaults->passwd = passwd ? g_strdup(passwd) : NULL; + defaults->authzid = authzid ? g_strdup(authzid) : NULL; if( defaults->mech == NULL ) { |