Provide framework for ldap_r and reentrant/thread safety levels.

-lldap_r can now be implemented...
This commit is contained in:
Kurt Zeilenga 1998-12-20 00:58:55 +00:00
parent 4123a08af5
commit 8aba5c5059
11 changed files with 235 additions and 33 deletions

View file

@ -174,6 +174,8 @@
/* These are defined in ldap_features.h */ /* These are defined in ldap_features.h */
/* /*
LDAP_API_FEATURE_X_OPENLDAP_REENTRANT
LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE
LDAP_API_FEATURE_X_OPENLDAP_V2_DNS LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
*/ */

View file

@ -23,11 +23,11 @@ lint5: lint5-local FORCE
clean-common: FORCE clean-common: FORCE
$(RM) $(LIBRARY) ../$(LIBRARY) $(XLIBRARY) \ $(RM) $(LIBRARY) ../$(LIBRARY) $(XLIBRARY) \
$(PROGRAMS) $(XPROGRAMS) $(XSRCS) \ $(PROGRAMS) $(XPROGRAMS) $(XSRCS) $(XXSRCS) \
*.o *.lo a.out core version.c .libs/* *.o *.lo a.out core version.c .libs/*
depend-common: FORCE depend-common: FORCE
$(MKDEP) $(DEFS) $(DEFINES) $(SRCS) $(MKDEP) $(DEFS) $(DEFINES) $(SRCS) $(XXSRCS)
lint-local: FORCE lint-local: FORCE
lint5-local: FORCE lint5-local: FORCE

110
configure vendored
View file

@ -7779,11 +7779,9 @@ fi
for ac_func in \ for ac_func in \
bcopy \ bcopy \
ctime_r \
flock \ flock \
getdtablesize \ getdtablesize \
gethostname \ gethostname \
gethostbyaddr_r gethostbyname_r \
getpwuid \ getpwuid \
gettimeofday \ gettimeofday \
lockf \ lockf \
@ -7804,7 +7802,6 @@ for ac_func in \
strsep \ strsep \
strstr \ strstr \
strtok \ strtok \
strtok_r \
strtol \ strtol \
strtoul \ strtoul \
sysconf \ sysconf \
@ -7812,12 +7809,12 @@ for ac_func in \
do do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:7816: checking for $ac_func" >&5 echo "configure:7813: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 7821 "configure" #line 7818 "configure"
#include "confdefs.h" #include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes, /* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */ which can conflict with char $ac_func(); below. */
@ -7840,7 +7837,7 @@ $ac_func();
; return 0; } ; return 0; }
EOF EOF
if { (eval echo configure:7844: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then if { (eval echo configure:7841: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest* rm -rf conftest*
eval "ac_cv_func_$ac_func=yes" eval "ac_cv_func_$ac_func=yes"
else else
@ -7865,15 +7862,21 @@ fi
done done
for ac_func in getopt strdup tempnam # these functions are required to build a thread_safe -lldap
for ac_func in \
strtok_r \
ctime_r \
gethostbyaddr_r \
gethostbyname_r \
do do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:7872: checking for $ac_func" >&5 echo "configure:7875: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 7877 "configure" #line 7880 "configure"
#include "confdefs.h" #include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes, /* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */ which can conflict with char $ac_func(); below. */
@ -7896,7 +7899,82 @@ $ac_func();
; return 0; } ; return 0; }
EOF EOF
if { (eval echo configure:7900: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then if { (eval echo configure:7903: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
echo "configure: failed program was:" >&5
cat conftest.$ac_ext >&5
rm -rf conftest*
eval "ac_cv_func_$ac_func=no"
fi
rm -f conftest*
fi
if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
echo "$ac_t""yes" 1>&6
ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
cat >> confdefs.h <<EOF
#define $ac_tr_func 1
EOF
else
echo "$ac_t""no" 1>&6
fi
done
if test $ac_cv_func_strtok_r = yes \
-a $ac_cv_func_ctime_r = yes \
-a $ac_cv_func_gethostbyaddr_r = yes \
-a $ac_cv_func_gethostbyname_r = yes \
; then
cat >> confdefs.h <<\EOF
#define LDAP_API_FEATURE_X_OPENLDAP_REENTRANT 1
EOF
fi
if test $ol_link_threads != no ; then
cat >> confdefs.h <<\EOF
#define LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE 1
EOF
fi
for ac_func in getopt strdup tempnam
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:7950: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 7955 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
#include <assert.h>
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char $ac_func();
int main() {
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
choke me
#else
$ac_func();
#endif
; return 0; }
EOF
if { (eval echo configure:7978: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest* rm -rf conftest*
eval "ac_cv_func_$ac_func=yes" eval "ac_cv_func_$ac_func=yes"
else else
@ -7926,13 +8004,13 @@ done
# Check Configuration # Check Configuration
echo $ac_n "checking declaration of sys_errlist""... $ac_c" 1>&6 echo $ac_n "checking declaration of sys_errlist""... $ac_c" 1>&6
echo "configure:7930: checking declaration of sys_errlist" >&5 echo "configure:8008: checking declaration of sys_errlist" >&5
if eval "test \"`echo '$''{'ol_cv_dcl_sys_errlist'+set}'`\" = set"; then if eval "test \"`echo '$''{'ol_cv_dcl_sys_errlist'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 7936 "configure" #line 8014 "configure"
#include "confdefs.h" #include "confdefs.h"
#include <stdio.h> #include <stdio.h>
@ -7942,7 +8020,7 @@ int main() {
char *c = (char *) *sys_errlist char *c = (char *) *sys_errlist
; return 0; } ; return 0; }
EOF EOF
if { (eval echo configure:7946: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then if { (eval echo configure:8024: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest* rm -rf conftest*
ol_cv_dcl_sys_errlist=yes ol_cv_dcl_sys_errlist=yes
else else
@ -7963,20 +8041,20 @@ if test $ol_cv_dcl_sys_errlist = no ; then
EOF EOF
echo $ac_n "checking existence of sys_errlist""... $ac_c" 1>&6 echo $ac_n "checking existence of sys_errlist""... $ac_c" 1>&6
echo "configure:7967: checking existence of sys_errlist" >&5 echo "configure:8045: checking existence of sys_errlist" >&5
if eval "test \"`echo '$''{'ol_cv_have_sys_errlist'+set}'`\" = set"; then if eval "test \"`echo '$''{'ol_cv_have_sys_errlist'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 7973 "configure" #line 8051 "configure"
#include "confdefs.h" #include "confdefs.h"
#include <errno.h> #include <errno.h>
int main() { int main() {
char *c = (char *) *sys_errlist char *c = (char *) *sys_errlist
; return 0; } ; return 0; }
EOF EOF
if { (eval echo configure:7980: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then if { (eval echo configure:8058: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest* rm -rf conftest*
ol_cv_have_sys_errlist=yes ol_cv_have_sys_errlist=yes
else else

View file

@ -808,7 +808,13 @@ dnl #if defined( HAVE_REENTRANT_FUNCTIONS ) \
dnl || defined( HAVE_FUNC_R ) dnl || defined( HAVE_FUNC_R )
dnl func_r(...); dnl func_r(...);
dnl #else dnl #else
dnl # if defined( HAVE_THREADS )
dnl /* lock */
dnl # endif
dnl func(...); dnl func(...);
dnl # if defined( HAVE_THREADS )
dnl /* unlock */
dnl # endif
dnl #endif dnl #endif
dnl dnl
dnl HAVE_REENTRANT_FUNCTIONS is derived from: dnl HAVE_REENTRANT_FUNCTIONS is derived from:
@ -816,6 +822,20 @@ dnl _POSIX_REENTRANT_FUNCTIONS
dnl _POSIX_THREAD_SAFE_FUNCTIONS dnl _POSIX_THREAD_SAFE_FUNCTIONS
dnl _POSIX_THREADSAFE_FUNCTIONS dnl _POSIX_THREADSAFE_FUNCTIONS
dnl dnl
dnl and is currently defined in lthread.h
dnl
dnl HAVE_THREADS is defined by lthread.h iff -UNO_THREADS
dnl
dnl libldap/*.c should only include <lthread.h> iff
dnl LDAP_R_COMPILE is defined. ie:
dnl #ifdef LDAP_R_COMPILE
dnl # include LDAP_R_COMPILE
dnl #endif
dnl
dnl LDAP_R_COMIPLE is defined by libldap_r/Makefile.in
dnl specifically for compiling the threadsafe version of
dnl the ldap library (-lldap_r).
dnl
dnl dnl check for reentrant/threadsafe functions dnl dnl check for reentrant/threadsafe functions
dnl dnl dnl dnl
dnl dnl note: these should only be used when linking dnl dnl note: these should only be used when linking
@ -1116,11 +1136,9 @@ AC_FUNC_WAIT3
AC_CHECK_FUNCS( \ AC_CHECK_FUNCS( \
bcopy \ bcopy \
ctime_r \
flock \ flock \
getdtablesize \ getdtablesize \
gethostname \ gethostname \
gethostbyaddr_r gethostbyname_r \
getpwuid \ getpwuid \
gettimeofday \ gettimeofday \
lockf \ lockf \
@ -1141,13 +1159,33 @@ AC_CHECK_FUNCS( \
strsep \ strsep \
strstr \ strstr \
strtok \ strtok \
strtok_r \
strtol \ strtol \
strtoul \ strtoul \
sysconf \ sysconf \
waitpid \ waitpid \
) )
# these functions are required to build a thread_safe -lldap
AC_CHECK_FUNCS( \
strtok_r \
ctime_r \
gethostbyaddr_r \
gethostbyname_r \
)
if test $ac_cv_func_strtok_r = yes \
-a $ac_cv_func_ctime_r = yes \
-a $ac_cv_func_gethostbyaddr_r = yes \
-a $ac_cv_func_gethostbyname_r = yes \
; then
AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_REENTRANT, 1)
fi
if test $ol_link_threads != no ; then
AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE, 1)
fi
dnl We actually may need to replace more than this. dnl We actually may need to replace more than this.
AC_REPLACE_FUNCS(getopt strdup tempnam) AC_REPLACE_FUNCS(getopt strdup tempnam)

View file

@ -40,6 +40,19 @@ LDAP_BEGIN_DECL
/* include LDAP_API_FEATURE defines */ /* include LDAP_API_FEATURE defines */
#include <ldap_features.h> #include <ldap_features.h>
#if defined( LDAP_API_FEATURE_X_OPENLDAP_REENTRANT ) || \
( defined( LDAP_THREAD_SAFE ) && \
defined( LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE ) )
/* -lldap may or may not be thread safe */
/* -lldap_r, if available, is always thread safe */
# define LDAP_API_FEATURE_THREAD_SAFE 1
#endif
#if defined( LDAP_THREAD_SAFE ) && \
defined( LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE )
/* #define LDAP_API_FEATURE_SESSION_SAFE 1 */
/* #define LDAP_API_OPERATION_SESSION_SAFE 1 */
#endif
#define LDAP_COMPAT20 #define LDAP_COMPAT20
#define LDAP_COMPAT30 #define LDAP_COMPAT30
#if defined(LDAP_COMPAT20) || defined(LDAP_COMPAT30) #if defined(LDAP_COMPAT20) || defined(LDAP_COMPAT30)

View file

@ -4,6 +4,39 @@
#ifndef _LDAP_FEATURES_H #ifndef _LDAP_FEATURES_H
#define _LDAP_FEATURES_H 1 #define _LDAP_FEATURES_H 1
/*
** OpenLDAP reentrancy/thread-safeness should be dynamically
** checked using ldap_get_option().
**
** The -lldap implementation may or may not be:
** LDAP_API_FEATURE_THREAD_SAFE
**
** The preprocessor flag LDAP_API_FEATURE_X_OPENLDAP_REENTRANT can
** be used to determine if -lldap is LDAP_API_FEATURE_THREAD_SAFE at
** compile time.
**
** The -lldap_r implementation is always THREAD_SAFE but
** may also be:
** LDAP_API_FEATURE_SESSION_THREAD_SAFE
** LDAP_API_FEATURE_OPERATION_THREAD_SAFE
**
** The preprocessor flag LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE
** can be used to determine if -lldap_r is availalbe at compile
** time. You must define LDAP_THREAD_SAFE if and only if you
** link with -lldap_r.
**
** If you fail to define LDAP_THREAD_SAFE when linking with
** -lldap_r or define LDAP_THREAD_SAFE when linking with -lldap,
** provided header definations and declarations may be incorrect.
**
*/
/* is -lldap reentrant or not */
#undef LDAP_API_FEATURE_X_OPENLDAP_REENTRANT
/* is threadsafe version of -lldap (ie: -lldap_r) *available* or not */
#undef LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE
/* LDAP v2 DNS */ /* LDAP v2 DNS */
#undef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS #undef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS

View file

@ -19,6 +19,12 @@
LDAP_BEGIN_DECL LDAP_BEGIN_DECL
#if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
defined( _POSIX_THREAD_SAFE_FUNCTIONS )
#define HAVE_REENTRANT_FUNCTIONS 1
#endif
#if !defined( HAVE_PTHREAD_ATTR_INIT ) && \ #if !defined( HAVE_PTHREAD_ATTR_INIT ) && \
defined( HAVE_PTHREAD_ATTR_CREATE ) defined( HAVE_PTHREAD_ATTR_CREATE )
#define pthread_attr_init( a ) pthread_attr_create( a ) #define pthread_attr_init( a ) pthread_attr_create( a )
@ -103,6 +109,8 @@ LDAP_END_DECL
LDAP_BEGIN_DECL LDAP_BEGIN_DECL
#define HAVE_REENTRANT_FUNCTIONS 1
typedef void *(*VFP)(); typedef void *(*VFP)();
/* default attr states */ /* default attr states */
@ -145,6 +153,8 @@ LDAP_END_DECL
LDAP_BEGIN_DECL LDAP_BEGIN_DECL
#define HAVE_REENTRANT_FUNCTIONS 1
stkalign_t *get_stack( int *stacknop ); stkalign_t *get_stack( int *stacknop );
void free_stack( int *stackno ); void free_stack( int *stackno );
@ -265,4 +275,9 @@ typedef int pthread_cond_t;
LDAP_END_DECL LDAP_END_DECL
#endif /* no threads support */ #endif /* no threads support */
#ifndef NO_THREADS
# define HAVE_THREADS 1
#endif
#endif /* _LTHREAD_H */ #endif /* _LTHREAD_H */

View file

@ -263,6 +263,8 @@ is provided ``as is'' without express or implied warranty.
/* These are defined in ldap_features.h */ /* These are defined in ldap_features.h */
/* /*
LDAP_API_FEATURE_X_OPENLDAP_REENTRANT
LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE
LDAP_API_FEATURE_X_OPENLDAP_V2_DNS LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
*/ */

View file

@ -8,11 +8,13 @@
#ifndef _LDAP_INT_H #ifndef _LDAP_INT_H
#define _LDAP_INT_H 1 #define _LDAP_INT_H 1
#ifdef LDAP_COMPILING_R
#define LDAP_THREAD_SAFE 1
#endif
#include "../liblber/lber-int.h" #include "../liblber/lber-int.h"
#include "ldap_log.h" #include "ldap_log.h"
#include "ldap.h" #include "ldap.h"
#include <time.h>
#include <netdb.h>
LDAP_BEGIN_DECL LDAP_BEGIN_DECL
@ -280,6 +282,8 @@ int ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input );
* *
*/ */
struct hostent; /* avoid pulling in <netdb.h> */
extern char *ldap_int_strtok( char *str, const char *delim, char **pos ); extern char *ldap_int_strtok( char *str, const char *delim, char **pos );
extern char *ldap_int_ctime( const time_t *tp, char *buf ); extern char *ldap_int_ctime( const time_t *tp, char *buf );
extern int ldap_int_gethostbyname_a( extern int ldap_int_gethostbyname_a(

View file

@ -9,6 +9,22 @@
#include "ldap-int.h" #include "ldap-int.h"
static const char* features[] = { static const char* features[] = {
#ifdef LDAP_API_FEATURE_THREAD_SAFE
"THREAD_SAFE",
#endif
#ifdef LDAP_API_FEATURE_SESSION_THREAD_SAFE
"SESSION_THREAD_SAFE",
#endif
#ifdef LDAP_API_FEATURE_OPERATION_THREAD_SAFE
"OPERATION_THREAD_SAFE",
#endif
#ifdef LDAP_API_FEATURE_X_OPENLDAP_REEENTRANT
"X_OPENLDAP_REENTRANT",
#endif
#if defined( LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE ) && \
defined( LDAP_THREAD_SAFE )
"X_OPENLDAP_THREAD_SAFE",
#endif
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
"X_OPENLDAP_V2_DNS", "X_OPENLDAP_V2_DNS",
#endif #endif

View file

@ -4,12 +4,10 @@
LIBRARY = libldap_r.la LIBRARY = libldap_r.la
XLIBRARY = ../libldap_r.a XLIBRARY = ../libldap_r.a
XDIR = ../libldap
XDEFS = -DLDAP_THREAD_SAFE -I$(XDIR)
PROGRAMS = apitest ltest ttest PROGRAMS = apitest ltest ttest
XSRCS = apitest.c test.c tmpltest.c \ XXDIR = ../libldap
XXSRCS = apitest.c test.c tmpltest.c \
bind.c open.c result.c error.c compare.c search.c \ bind.c open.c result.c error.c compare.c search.c \
modify.c add.c modrdn.c delete.c abandon.c ufn.c cache.c \ modify.c add.c modrdn.c delete.c abandon.c ufn.c cache.c \
getfilter.c sbind.c kbind.c unbind.c friendly.c cldap.c \ getfilter.c sbind.c kbind.c unbind.c friendly.c cldap.c \
@ -28,19 +26,22 @@ OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \
LDAP_INCDIR= ../../include LDAP_INCDIR= ../../include
LDAP_LIBDIR= ../../libraries LDAP_LIBDIR= ../../libraries
XDEFS = -DLDAP_R_COMPILE -I$(XXDIR)
LIBS = $(LDAP_LIBPATH) $(LDAP_LIBLDAP) $(LDAP_LIBLBER) $(AC_LIBS) LIBS = $(LDAP_LIBPATH) $(LDAP_LIBLDAP) $(LDAP_LIBLBER) $(AC_LIBS)
.links : .links : FORCE
@for i in $(XSRCS); do \ @for i in $(XXSRCS); do \
$(RM) $$i ; \ $(RM) $$i ; \
$(LN_S) $(XDIR)/$$i . ; \ $(LN_S) $(XXDIR)/$$i . ; \
done done
touch .links touch .links
$(XSRCS) : .links $(XXSRCS) : .links
clean-local: FORCE clean-local: FORCE
$(RM) .links @$(RM) .links
depend-common: .links
apitest: $(LIBRARY) apitest.o $(LDAP_LIBLBER_DEPEND) apitest: $(LIBRARY) apitest.o $(LDAP_LIBLBER_DEPEND)
$(LTLINK) $(LDFLAGS) -o $@ apitest.o $(LIBS) $(LTLINK) $(LDFLAGS) -o $@ apitest.o $(LIBS)