From: Kurt Zeilenga Date: Wed, 28 Sep 2005 02:30:11 +0000 (+0000) Subject: Sync with HEAD X-Git-Tag: OPENLDAP_REL_ENG_2_3_8~18 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d71500e67b51a6ad2341074782ba34a6cae1e03f;p=openldap Sync with HEAD Changes needs updating for release... --- diff --git a/CHANGES b/CHANGES index cbe7e0648f..fd3ef961c9 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,8 @@ OpenLDAP 2.3 Change Log OpenLDAP 2.3.8 Engineering Fixed slapd undef HAVE_EPOLL issue + Documentation + Add slapo-valsort(5) man page OpenLDAP 2.3.7 Release Updated slapd ManageDIT support diff --git a/build/mkdep b/build/mkdep index 0e8ce3d857..eec2d20de3 100755 --- a/build/mkdep +++ b/build/mkdep @@ -161,7 +161,7 @@ for i in $files; do esac done for i in $FILES; do - $MKDEP_CC $MKDEP_CFLAGS $FLAGS $i | egrep '^#.*"' > $TMP.sed + $MKDEP_CC $MKDEP_CFLAGS $FLAGS $i | grep '^#.*"' > $TMP.sed awk ' BEGIN { file = "'$i'" diff --git a/build/openldap.m4 b/build/openldap.m4 index ab2371b3d5..05170db5a9 100644 --- a/build/openldap.m4 +++ b/build/openldap.m4 @@ -80,7 +80,7 @@ if test -z "${MKDEP}"; then noCode; EOF if AC_TRY_COMMAND($OL_MKDEP $flag conftest.c) \ - | egrep '^conftest\.'"${ac_objext}" >/dev/null 2>&1 + | grep '^conftest\.'"${ac_objext}" >/dev/null 2>&1 then if test ! -f conftest."${ac_object}" ; then ol_cv_mkdep=$flag @@ -500,7 +500,7 @@ dnl -------------------------------------------------------------------- dnl Find old Berkeley DB 1.85/1.86 AC_DEFUN([OL_BERKELEY_COMPAT_DB], [AC_CHECK_HEADERS(db_185.h db.h) -if test $ac_cv_header_db_185_h = yes -o $ac_cv_header_db_h = yes; then +if test $ac_cv_header_db_185_h = yes || test $ac_cv_header_db_h = yes; then AC_CACHE_CHECK([if Berkeley DB header compatibility], [ol_cv_header_db1],[ AC_EGREP_CPP(__db_version_1,[ #if HAVE_DB_185_H @@ -562,7 +562,7 @@ AC_DEFUN([OL_GDBM], [AC_REQUIRE([OL_LIB_GDBM]) AC_CHECK_HEADERS(gdbm.h) AC_CACHE_CHECK(for db, [ol_cv_gdbm], [ - if test $ol_cv_lib_gdbm = no -o $ac_cv_header_gdbm_h = no ; then + if test $ol_cv_lib_gdbm = no || test $ac_cv_header_gdbm_h = no ; then ol_cv_gdbm=no else ol_cv_gdbm=yes @@ -607,7 +607,7 @@ AC_DEFUN([OL_MDBM], [AC_REQUIRE([OL_LIB_MDBM]) AC_CHECK_HEADERS(mdbm.h) AC_CACHE_CHECK(for db, [ol_cv_mdbm], [ - if test $ol_cv_lib_mdbm = no -o $ac_cv_header_mdbm_h = no ; then + if test $ol_cv_lib_mdbm = no || test $ac_cv_header_mdbm_h = no ; then ol_cv_mdbm=no else ol_cv_mdbm=yes @@ -663,7 +663,7 @@ AC_DEFUN([OL_NDBM], [AC_REQUIRE([OL_LIB_NDBM]) AC_CHECK_HEADERS(ndbm.h) AC_CACHE_CHECK(for db, [ol_cv_ndbm], [ - if test $ol_cv_lib_ndbm = no -o $ac_cv_header_ndbm_h = no ; then + if test $ol_cv_lib_ndbm = no || test $ac_cv_header_ndbm_h = no ; then ol_cv_ndbm=no else ol_cv_ndbm=yes @@ -894,11 +894,11 @@ AC_DEFUN([OL_LINUX_THREADS], [ AC_REQUIRE([OL_HEADER_LINUX_THREADS]) AC_REQUIRE([OL_SYS_LINUX_THREADS]) AC_CACHE_CHECK([for LinuxThreads consistency], [ol_cv_linux_threads], [ - if test $ol_cv_header_linux_threads = yes -a \ - $ol_cv_sys_linux_threads = yes; then + if test $ol_cv_header_linux_threads = yes && + test $ol_cv_sys_linux_threads = yes; then ol_cv_linux_threads=yes - elif test $ol_cv_header_linux_threads = no -a \ - $ol_cv_sys_linux_threads = no; then + elif test $ol_cv_header_linux_threads = no && + test $ol_cv_sys_linux_threads = no; then ol_cv_linux_threads=no else ol_cv_linux_threads=error @@ -1089,13 +1089,13 @@ AC_DEFUN([OL_FUNC_CTIME_R_NARGS], AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[time_t ti; char *buffer; ctime_r(&ti,buffer);]])],[ol_cv_func_ctime_r_nargs2=yes],[ol_cv_func_ctime_r_nargs2=no]) - if test $ol_cv_func_ctime_r_nargs3 = yes -a \ - $ol_cv_func_ctime_r_nargs2 = no ; then + if test $ol_cv_func_ctime_r_nargs3 = yes && + test $ol_cv_func_ctime_r_nargs2 = no ; then ol_cv_func_ctime_r_nargs=3 - elif test $ol_cv_func_ctime_r_nargs3 = no -a \ - $ol_cv_func_ctime_r_nargs2 = yes ; then + elif test $ol_cv_func_ctime_r_nargs3 = no && + test $ol_cv_func_ctime_r_nargs2 = yes ; then ol_cv_func_ctime_r_nargs=2 @@ -1144,13 +1144,13 @@ AC_DEFUN([OL_FUNC_GETHOSTBYNAME_R_NARGS], (void)gethostbyname_r("localhost", &hent, buffer, bufsize, &rhent, &h_errno);]])],[ol_cv_func_gethostbyname_r_nargs6=yes],[ol_cv_func_gethostbyname_r_nargs6=no]) - if test $ol_cv_func_gethostbyname_r_nargs5 = yes -a \ - $ol_cv_func_gethostbyname_r_nargs6 = no ; then + if test $ol_cv_func_gethostbyname_r_nargs5 = yes && + test $ol_cv_func_gethostbyname_r_nargs6 = no ; then ol_cv_func_gethostbyname_r_nargs=5 - elif test $ol_cv_func_gethostbyname_r_nargs5 = no -a \ - $ol_cv_func_gethostbyname_r_nargs6 = yes ; then + elif test $ol_cv_func_gethostbyname_r_nargs5 = no && + test $ol_cv_func_gethostbyname_r_nargs6 = yes ; then ol_cv_func_gethostbyname_r_nargs=6 @@ -1193,13 +1193,13 @@ AC_DEFUN([OL_FUNC_GETHOSTBYADDR_R_NARGS], alen, AF_INET, &hent, buffer, bufsize, &rhent, &h_errno);]])],[ol_cv_func_gethostbyaddr_r_nargs8=yes],[ol_cv_func_gethostbyaddr_r_nargs8=no]) - if test $ol_cv_func_gethostbyaddr_r_nargs7 = yes -a \ - $ol_cv_func_gethostbyaddr_r_nargs8 = no ; then + if test $ol_cv_func_gethostbyaddr_r_nargs7 = yes && + test $ol_cv_func_gethostbyaddr_r_nargs8 = no ; then ol_cv_func_gethostbyaddr_r_nargs=7 - elif test $ol_cv_func_gethostbyaddr_r_nargs7 = no -a \ - $ol_cv_func_gethostbyaddr_r_nargs8 = yes ; then + elif test $ol_cv_func_gethostbyaddr_r_nargs7 = no && + test $ol_cv_func_gethostbyaddr_r_nargs8 = yes ; then ol_cv_func_gethostbyaddr_r_nargs=8 diff --git a/configure b/configure index 7044222340..37b98acae3 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in OpenLDAP: pkg/ldap/configure.in,v 1.560.2.13 2005/08/29 18:46:16 kurt Exp . +# From configure.in OpenLDAP: pkg/ldap/configure.in,v 1.560.2.14 2005/09/01 20:28:09 kurt Exp . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59. # @@ -1585,7 +1585,7 @@ echo "$as_me: error: could not determine version" >&2;} { (exit 1); exit 1; }; } fi -if test -f "$ac_aux_dir/shtool" -a ! -d $ac_aux_dir/shtool; then +if test -f "$ac_aux_dir/shtool" && test ! -d $ac_aux_dir/shtool; then ac_cv_shtool="$ac_aux_dir/shtool" else { { echo "$as_me:$LINENO: error: no shtool found in $ac_aux_dir" >&5 @@ -3701,19 +3701,19 @@ echo "$as_me: WARNING: LDBM disabled, ignoring --enable-ldbm-api argument" >&2;} echo "$as_me: WARNING: LDBM disabled, ignoring --enable-ldbm-type argument" >&2;} fi - if test $ol_enable_modules != yes -a \ - $ol_enable_bdb = no -a \ - $ol_enable_dnssrv = no -a \ - $ol_enable_hdb = no -a \ - $ol_enable_ldap = no -a \ - $ol_enable_meta = no -a \ - $ol_enable_monitor = no -a \ - $ol_enable_null = no -a \ - $ol_enable_passwd = no -a \ - $ol_enable_perl = no -a \ - $ol_enable_relay = no -a \ - $ol_enable_shell = no -a \ - $ol_enable_sql = no ; then + if test $ol_enable_modules != yes && + test $ol_enable_bdb = no && + test $ol_enable_dnssrv = no && + test $ol_enable_hdb = no && + test $ol_enable_ldap = no && + test $ol_enable_meta = no && + test $ol_enable_monitor = no && + test $ol_enable_null = no && + test $ol_enable_passwd = no && + test $ol_enable_perl = no && + test $ol_enable_relay = no && + test $ol_enable_shell = no && + test $ol_enable_sql = no ; then if test $ol_enable_slapd = yes ; then { { echo "$as_me:$LINENO: error: slapd requires a backend" >&5 @@ -3729,31 +3729,31 @@ echo "$as_me: WARNING: skipping slapd, no backend specified" >&2;} ol_enable_ldbm_api=no ol_enable_ldbm_type=no - if test $ol_enable_bdb != no -o $ol_enable_hdb != no; then + if test $ol_enable_bdb/$ol_enable_hdb != no/no; then ol_enable_ldbm_api=berkeley fi else - if test $ol_enable_ldbm_api = gdbm -a \ - $ol_enable_ldbm_type = btree ; then + if test $ol_enable_ldbm_api = gdbm && + test $ol_enable_ldbm_type = btree ; then { { echo "$as_me:$LINENO: error: GDBM only supports LDBM type hash" >&5 echo "$as_me: error: GDBM only supports LDBM type hash" >&2;} { (exit 1); exit 1; }; } fi - if test $ol_enable_ldbm_api = mdbm -a \ - $ol_enable_ldbm_type = btree ; then + if test $ol_enable_ldbm_api = mdbm && + test $ol_enable_ldbm_type = btree ; then { { echo "$as_me:$LINENO: error: MDBM only supports LDBM type hash" >&5 echo "$as_me: error: MDBM only supports LDBM type hash" >&2;} { (exit 1); exit 1; }; } fi - if test $ol_enable_ldbm_api = ndbm -a \ - $ol_enable_ldbm_type = btree ; then + if test $ol_enable_ldbm_api = ndbm && + test $ol_enable_ldbm_type = btree ; then { { echo "$as_me:$LINENO: error: NDBM only supports LDBM type hash" >&5 echo "$as_me: error: NDBM only supports LDBM type hash" >&2;} { (exit 1); exit 1; }; } fi - if test $ol_enable_bdb != no -o $ol_enable_hdb != no ; then + if test $ol_enable_bdb/$ol_enable_hdb != no/no ; then if test $ol_enable_ldbm_api = auto ; then ol_enable_ldbm_api=berkeley elif test $ol_enable_ldbm_api != berkeley ; then @@ -3764,7 +3764,7 @@ echo "$as_me: error: LDBM API not compatible with BDB/HDB" >&2;} fi fi -if test $ol_enable_meta = yes -a $ol_enable_ldap = no ; then +if test $ol_enable_meta/$ol_enable_ldap = yes/no ; then { { echo "$as_me:$LINENO: error: --enable-meta requires --enable-ldap" >&5 echo "$as_me: error: --enable-meta requires --enable-ldap" >&2;} { (exit 1); exit 1; }; } @@ -3967,10 +3967,11 @@ echo "$as_me: WARNING: disabling threads, no cc_r on AIX" >&2;} fi fi - if test "${CC}" = "cc_r" -o "${CC}" = "xlc_r" ; then + case ${CC} in cc_r | xlc_r) ol_with_threads=posix ol_cv_pthread_create=yes - fi + ;; + esac fi if test -z "${CC}"; then @@ -5685,7 +5686,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 5688 "configure"' > conftest.$ac_ext + echo '#line 5689 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -7665,11 +7666,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7668: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7669: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7672: \$? = $ac_status" >&5 + echo "$as_me:7673: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7927,11 +7928,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7930: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7931: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7934: \$? = $ac_status" >&5 + echo "$as_me:7935: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7989,11 +7990,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7992: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7993: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7996: \$? = $ac_status" >&5 + echo "$as_me:7997: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -10229,7 +10230,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5 (exit $ac_status); }; } \ - | egrep '^conftest\.'"${ac_objext}" >/dev/null 2>&1 + | grep '^conftest\.'"${ac_objext}" >/dev/null 2>&1 then if test ! -f conftest."${ac_object}" ; then ol_cv_mkdep=$flag @@ -17387,7 +17388,7 @@ _ACEOF fi fi -if test "$ol_enable_dnssrv" = yes -o "$ol_enable_dnssrv" = mod ; then +if test "$ol_enable_dnssrv" = yes || test "$ol_enable_dnssrv" = mod ; then if test "$ol_link_dnssrv" = no ; then { { echo "$as_me:$LINENO: error: DNSSRV requires res_query()" >&5 echo "$as_me: error: DNSSRV requires res_query()" >&2;} @@ -17607,7 +17608,7 @@ done ol_link_ipv6=no -if test $ac_cv_func_getaddrinfo = no -o $ac_cv_func_inet_ntop = no ; then +if test $ac_cv_func_getaddrinfo = no || test $ac_cv_func_inet_ntop = no ; then if test $ol_enable_ipv6 = yes ; then { { echo "$as_me:$LINENO: error: IPv6 support requires getaddrinfo() and inet_ntop()" >&5 echo "$as_me: error: IPv6 support requires getaddrinfo() and inet_ntop()" >&2;} @@ -17706,16 +17707,16 @@ fi echo "$as_me:$LINENO: result: $ol_cv_struct_sockaddr_storage" >&5 echo "${ECHO_T}$ol_cv_struct_sockaddr_storage" >&6 - if test $ol_cv_inet6_addrstrlen = yes \ - -a $ol_cv_struct_sockaddr_storage = yes ; then + if test $ol_cv_inet6_addrstrlen = yes && + test $ol_cv_struct_sockaddr_storage = yes ; then ol_link_ipv6=yes - elif test $ol_enable_ipv6 = yes \ - -a $ol_cv_inet6_addrstrlen = no ; then + elif test $ol_enable_ipv6 = yes && + test $ol_cv_inet6_addrstrlen = no ; then { { echo "$as_me:$LINENO: error: IPv6 support requires INET6_ADDRSTRLEN" >&5 echo "$as_me: error: IPv6 support requires INET6_ADDRSTRLEN" >&2;} { (exit 1); exit 1; }; } - elif test $ol_enable_ipv6 = yes \ - -a $ol_cv_struct_sockaddr_storage = no ; then + elif test $ol_enable_ipv6 = yes && + test $ol_cv_struct_sockaddr_storage = no ; then { { echo "$as_me:$LINENO: error: IPv6 support requires struct sockaddr_storage" >&5 echo "$as_me: error: IPv6 support requires struct sockaddr_storage" >&2;} { (exit 1); exit 1; }; } @@ -17887,9 +17888,7 @@ ol_link_kbind=no ol_link_krb5=no ol_link_krb4=no -if test $ol_with_kerberos = yes -o $ol_with_kerberos = auto \ - -o $ol_with_kerberos = k5 -o $ol_with_kerberos = k5only \ - -o $ol_with_kerberos = k425 ; then +case $ol_with_kerberos in yes | auto | k5 | k5only | k425) for ac_header in krb5.h @@ -18495,10 +18494,13 @@ echo "$as_me: error: Required Kerberos 5 support not available" >&2;} fi fi -fi + ;; +esac -if test $ol_link_krb5 = yes -a \( $ol_with_kerberos = yes -o \ - $ol_with_kerberos = auto -o $ol_with_kerberos = k425 \) ; then +if test $ol_link_krb5 = yes && + { test $ol_with_kerberos = yes || + test $ol_with_kerberos = auto || + test $ol_with_kerberos = k425; }; then @@ -18891,8 +18893,7 @@ if test $ol_link_krb5 = yes ; then ol_with_kerberos=found fi -if test $ol_with_kerberos = yes -o $ol_with_kerberos = auto \ - -o $ol_with_kerberos = k4 -o $ol_with_kerberos = kth ; then +case $ol_with_kerberos in yes | auto | k4 | kth) @@ -19134,9 +19135,10 @@ _ACEOF fi fi fi -fi + ;; +esac -if test $ol_link_krb4 = yes -a $ol_enable_kbind != no ; then +if test $ol_link_krb4 = yes && test $ol_enable_kbind != no ; then ol_link_kbind=yes elif test $ol_enable_kbind = yes ; then @@ -19145,14 +19147,14 @@ echo "$as_me: error: Kerberos IV detection failed" >&2;} { (exit 1); exit 1; }; } fi -if test $ol_link_krb4 = yes -o $ol_link_krb5 = yes ; then +if test $ol_link_krb4 = yes || test $ol_link_krb5 = yes ; then cat >>confdefs.h <<\_ACEOF #define HAVE_KERBEROS 1 _ACEOF -elif test $ol_with_kerberos != auto -a $ol_with_kerberos != no ; then +elif test $ol_with_kerberos != auto && test $ol_with_kerberos != no ; then { { echo "$as_me:$LINENO: error: Kerberos detection failed" >&5 echo "$as_me: error: Kerberos detection failed" >&2;} { (exit 1); exit 1; }; } @@ -19313,8 +19315,8 @@ fi done - if test $ac_cv_header_openssl_ssl_h = yes \ - -o $ac_cv_header_ssl_h = yes ; then + if test $ac_cv_header_openssl_ssl_h = yes || + test $ac_cv_header_ssl_h = yes ; then echo "$as_me:$LINENO: checking for SSLeay_add_ssl_algorithms in -lssl" >&5 echo $ECHO_N "checking for SSLeay_add_ssl_algorithms in -lssl... $ECHO_C" >&6 if test "${ac_cv_lib_ssl_SSLeay_add_ssl_algorithms+set}" = set; then @@ -19647,8 +19649,7 @@ fi ol_link_threads=no -if test $ol_with_threads = auto -o $ol_with_threads = yes \ - -o $ol_with_threads = nt ; then +case $ol_with_threads in auto | yes | nt) echo "$as_me:$LINENO: checking for _beginthread" >&5 @@ -19775,10 +19776,10 @@ _ACEOF echo "$as_me: error: could not locate NT Threads" >&2;} { (exit 1); exit 1; }; } fi -fi + ;; +esac -if test $ol_with_threads = auto -o $ol_with_threads = yes \ - -o $ol_with_threads = posix ; then +case $ol_with_threads in auto | yes | posix) for ac_header in pthread.h @@ -24171,9 +24172,9 @@ fi done - if test $ac_cv_func_sched_yield = no -a \ - $ac_cv_func_pthread_yield = no -a \ - $ac_cv_func_thr_yield = no ; then + if test $ac_cv_func_sched_yield = no && + test $ac_cv_func_pthread_yield = no && + test $ac_cv_func_thr_yield = no ; then echo "$as_me:$LINENO: checking for sched_yield in -lrt" >&5 echo $ECHO_N "checking for sched_yield in -lrt... $ECHO_C" >&6 if test "${ac_cv_lib_rt_sched_yield+set}" = set; then @@ -24251,9 +24252,9 @@ else fi fi - if test $ac_cv_func_sched_yield = no -a \ - $ac_cv_func_pthread_yield = no -a \ - "$ac_cv_func_thr_yield" = no ; then + if test $ac_cv_func_sched_yield = no && + test $ac_cv_func_pthread_yield = no && + test "$ac_cv_func_thr_yield" = no ; then { echo "$as_me:$LINENO: WARNING: could not locate sched_yield() or pthread_yield()" >&5 echo "$as_me: WARNING: could not locate sched_yield() or pthread_yield()" >&2;} fi @@ -24669,11 +24670,11 @@ if test "${ol_cv_linux_threads+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else - if test $ol_cv_header_linux_threads = yes -a \ - $ol_cv_sys_linux_threads = yes; then + if test $ol_cv_header_linux_threads = yes && + test $ol_cv_sys_linux_threads = yes; then ol_cv_linux_threads=yes - elif test $ol_cv_header_linux_threads = no -a \ - $ol_cv_sys_linux_threads = no; then + elif test $ol_cv_header_linux_threads = no && + test $ol_cv_sys_linux_threads = no; then ol_cv_linux_threads=no else ol_cv_linux_threads=error @@ -24950,10 +24951,10 @@ echo "$as_me: error: could not locate usable POSIX Threads" >&2;} echo "$as_me: error: could not locate POSIX Threads" >&2;} { (exit 1); exit 1; }; } fi -fi + ;; +esac -if test $ol_with_threads = auto -o $ol_with_threads = yes \ - -o $ol_with_threads = mach ; then +case $ol_with_threads in auto | yes | mach) @@ -25403,10 +25404,10 @@ _ACEOF echo "$as_me: error: could not link with Mach CThreads" >&2;} { (exit 1); exit 1; }; } fi -fi + ;; +esac -if test $ol_with_threads = auto -o $ol_with_threads = yes \ - -o $ol_with_threads = pth ; then +case $ol_with_threads in auto | yes | pth) for ac_header in pth.h @@ -25646,10 +25647,10 @@ _ACEOF fi fi fi -fi + ;; +esac -if test $ol_with_threads = auto -o $ol_with_threads = yes \ - -o $ol_with_threads = lwp ; then +case $ol_with_threads in auto | yes | lwp) @@ -25802,7 +25803,8 @@ fi done - if test $ac_cv_header_thread_h = yes -a $ac_cv_header_synch_h = yes ; then + if test $ac_cv_header_thread_h = yes && + test $ac_cv_header_synch_h = yes ; then echo "$as_me:$LINENO: checking for thr_create in -lthread" >&5 echo $ECHO_N "checking for thr_create in -lthread... $ECHO_C" >&6 if test "${ac_cv_lib_thread_thr_create+set}" = set; then @@ -26232,7 +26234,8 @@ _ACEOF fi fi fi -fi + ;; +esac if test $ol_with_yielding_select = yes ; then @@ -26990,7 +26993,7 @@ done fi -if test $ol_link_threads != no -a $ol_link_threads != nt ; then +if test $ol_link_threads != no && test $ol_link_threads != nt ; then cat >>confdefs.h <<\_ACEOF #define REENTRANT 1 _ACEOF @@ -27134,8 +27137,8 @@ fi echo "$as_me:$LINENO: result: $ol_cv_h_errno_thread_specific" >&5 echo "${ECHO_T}$ol_cv_h_errno_thread_specific" >&6 - if test $ol_cv_errno_thread_specific != yes \ - -o $ol_cv_h_errno_thread_specific != yes ; then + if test $ol_cv_errno_thread_specific != yes || + test $ol_cv_h_errno_thread_specific != yes ; then LIBS="$LTHREAD_LIBS $LIBS" LTHREAD_LIBS="" fi @@ -27379,13 +27382,13 @@ ol_cv_func_ctime_r_nargs2=no fi rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - if test $ol_cv_func_ctime_r_nargs3 = yes -a \ - $ol_cv_func_ctime_r_nargs2 = no ; then + if test $ol_cv_func_ctime_r_nargs3 = yes && + test $ol_cv_func_ctime_r_nargs2 = no ; then ol_cv_func_ctime_r_nargs=3 - elif test $ol_cv_func_ctime_r_nargs3 = no -a \ - $ol_cv_func_ctime_r_nargs2 = yes ; then + elif test $ol_cv_func_ctime_r_nargs3 = no && + test $ol_cv_func_ctime_r_nargs2 = yes ; then ol_cv_func_ctime_r_nargs=2 @@ -27520,13 +27523,13 @@ ol_cv_func_gethostbyname_r_nargs6=no fi rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - if test $ol_cv_func_gethostbyname_r_nargs5 = yes -a \ - $ol_cv_func_gethostbyname_r_nargs6 = no ; then + if test $ol_cv_func_gethostbyname_r_nargs5 = yes && + test $ol_cv_func_gethostbyname_r_nargs6 = no ; then ol_cv_func_gethostbyname_r_nargs=5 - elif test $ol_cv_func_gethostbyname_r_nargs5 = no -a \ - $ol_cv_func_gethostbyname_r_nargs6 = yes ; then + elif test $ol_cv_func_gethostbyname_r_nargs5 = no && + test $ol_cv_func_gethostbyname_r_nargs6 = yes ; then ol_cv_func_gethostbyname_r_nargs=6 @@ -27667,13 +27670,13 @@ ol_cv_func_gethostbyaddr_r_nargs8=no fi rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - if test $ol_cv_func_gethostbyaddr_r_nargs7 = yes -a \ - $ol_cv_func_gethostbyaddr_r_nargs8 = no ; then + if test $ol_cv_func_gethostbyaddr_r_nargs7 = yes && + test $ol_cv_func_gethostbyaddr_r_nargs8 = no ; then ol_cv_func_gethostbyaddr_r_nargs=7 - elif test $ol_cv_func_gethostbyaddr_r_nargs7 = no -a \ - $ol_cv_func_gethostbyaddr_r_nargs8 = yes ; then + elif test $ol_cv_func_gethostbyaddr_r_nargs7 = no && + test $ol_cv_func_gethostbyaddr_r_nargs8 = yes ; then ol_cv_func_gethostbyaddr_r_nargs=8 @@ -27698,9 +27701,7 @@ fi ol_link_ldbm=no -if test $ol_enable_ldbm_api = auto \ - -o $ol_enable_ldbm_api = berkeley \ - -o $ol_enable_ldbm_api = bcompat ; then +case $ol_enable_ldbm_api in auto | berkeley | bcompat) if test $ol_enable_ldbm_api = bcompat; then \ @@ -27854,7 +27855,7 @@ fi done -if test $ac_cv_header_db_185_h = yes -o $ac_cv_header_db_h = yes; then +if test $ac_cv_header_db_185_h = yes || test $ac_cv_header_db_h = yes; then echo "$as_me:$LINENO: checking if Berkeley DB header compatibility" >&5 echo $ECHO_N "checking if Berkeley DB header compatibility... $ECHO_C" >&6 if test "${ol_cv_header_db1+set}" = set; then @@ -33104,9 +33105,10 @@ _ACEOF LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_db" fi fi -fi + ;; +esac -if test $ol_enable_bdb != no -o $ol_enable_hdb != no; then +if test $ol_enable_bdb/$ol_enable_hdb != no/no; then if test $ol_link_ldbm != berkeley ; then { { echo "$as_me:$LINENO: error: BDB/HDB: BerkeleyDB not available" >&5 echo "$as_me: error: BDB/HDB: BerkeleyDB not available" >&2;} @@ -33162,13 +33164,13 @@ echo "$as_me: error: BDB/HDB: BerkeleyDB version incompatible" >&2;} fi fi -if test $ol_link_ldbm = no -a $ol_enable_ldbm_type = btree ; then +if test $ol_link_ldbm = no && test $ol_enable_ldbm_type = btree ; then { echo "$as_me:$LINENO: WARNING: Could not find LDBM with BTREE support" >&5 echo "$as_me: WARNING: Could not find LDBM with BTREE support" >&2;} ol_enable_ldbm_api=none fi -if test $ol_enable_ldbm_api = auto -o $ol_enable_ldbm_api = mdbm ; then +if test $ol_enable_ldbm_api = auto || test $ol_enable_ldbm_api = mdbm ; then echo "$as_me:$LINENO: checking for MDBM library" >&5 echo $ECHO_N "checking for MDBM library... $ECHO_C" >&6 if test "${ol_cv_lib_mdbm+set}" = set; then @@ -33505,7 +33507,7 @@ if test "${ol_cv_mdbm+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else - if test $ol_cv_lib_mdbm = no -o $ac_cv_header_mdbm_h = no ; then + if test $ol_cv_lib_mdbm = no || test $ac_cv_header_mdbm_h = no ; then ol_cv_mdbm=no else ol_cv_mdbm=yes @@ -33532,7 +33534,7 @@ _ACEOF fi fi -if test $ol_enable_ldbm_api = auto -o $ol_enable_ldbm_api = gdbm ; then +if test $ol_enable_ldbm_api = auto || test $ol_enable_ldbm_api = gdbm ; then echo "$as_me:$LINENO: checking for GDBM library" >&5 echo $ECHO_N "checking for GDBM library... $ECHO_C" >&6 if test "${ol_cv_lib_gdbm+set}" = set; then @@ -33869,7 +33871,7 @@ if test "${ol_cv_gdbm+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else - if test $ol_cv_lib_gdbm = no -o $ac_cv_header_gdbm_h = no ; then + if test $ol_cv_lib_gdbm = no || test $ac_cv_header_gdbm_h = no ; then ol_cv_gdbm=no else ol_cv_gdbm=yes @@ -34304,7 +34306,7 @@ if test "${ol_cv_ndbm+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else - if test $ol_cv_lib_ndbm = no -o $ac_cv_header_ndbm_h = no ; then + if test $ol_cv_lib_ndbm = no || test $ac_cv_header_ndbm_h = no ; then ol_cv_ndbm=no else ol_cv_ndbm=yes @@ -34332,20 +34334,20 @@ _ACEOF fi fi -if test $ol_link_ldbm = no -a $ol_enable_ldbm != no ; then +if test $ol_link_ldbm = no && test $ol_enable_ldbm != no ; then { { echo "$as_me:$LINENO: error: could not find suitable LDBM backend" >&5 echo "$as_me: error: could not find suitable LDBM backend" >&2;} { (exit 1); exit 1; }; } fi -if test $ol_enable_bdb = yes -o \ - $ol_enable_hdb = yes -o \ - $ol_enable_ldbm = yes ; then +if test $ol_enable_bdb = yes || + test $ol_enable_hdb = yes || + test $ol_enable_ldbm = yes ; then SLAPD_LIBS="$SLAPD_LIBS \$(LDBM_LIBS)" fi -if test $ol_enable_dynamic = yes -a $enable_shared = yes ; then +if test $ol_enable_dynamic = yes && test $enable_shared = yes ; then BUILD_LIBS_DYNAMIC=shared cat >>confdefs.h <<\_ACEOF @@ -34745,7 +34747,7 @@ fi echo "$as_me:$LINENO: result: $ac_cv_func_openlog" >&5 echo "${ECHO_T}$ac_cv_func_openlog" >&6 - if test $ac_cv_func_openlog = no -a $ol_enable_syslog = yes; then + if test $ac_cv_func_openlog = no && test $ol_enable_syslog = yes; then { { echo "$as_me:$LINENO: error: could not find syslog" >&5 echo "$as_me: error: could not find syslog" >&2;} { (exit select appropriate options or disable); exit select appropriate options or disable; }; } @@ -35232,7 +35234,8 @@ fi done - if test $ac_cv_header_sasl_sasl_h = yes -o $ac_cv_header_sasl_h = yes; then + if test $ac_cv_header_sasl_sasl_h = yes || + test $ac_cv_header_sasl_h = yes; then echo "$as_me:$LINENO: checking for sasl_client_init in -lsasl2" >&5 echo $ECHO_N "checking for sasl_client_init in -lsasl2... $ECHO_C" >&6 if test "${ac_cv_lib_sasl2_sasl_client_init+set}" = set; then @@ -35559,7 +35562,7 @@ echo "$as_me: WARNING: Strong authentication not supported!" >&2;} fi fi -if test $cross_compiling != yes -a "$ac_cv_mingw32" != yes ; then +if test $cross_compiling != yes && test "$ac_cv_mingw32" != yes ; then dev=no if test -r /dev/urandom ; then dev="/dev/urandom"; @@ -36749,18 +36752,18 @@ done ol_have_bn_h=no ol_have_crypto_h=no - if test "$ac_cv_header_openssl_bn_h" = "yes" \ - -o "$ac_cv_header_bn_h" = "yes" ; then + if test "$ac_cv_header_openssl_bn_h" = "yes" || + test "$ac_cv_header_bn_h" = "yes" ; then ol_have_bn_h=yes fi - if test "$ac_cv_header_openssl_crypto_h" = "yes" \ - -o "$ac_cv_header_crypto_h" = "yes" ; then + if test "$ac_cv_header_openssl_crypto_h" = "yes" || + test "$ac_cv_header_crypto_h" = "yes" ; then ol_have_crypto_h=yes fi - if test "$ol_have_bn_h" = "yes" \ - -a "$ol_have_crypto_h" = "yes" ; then + if test "$ol_have_bn_h" = "yes" && + test "$ol_have_crypto_h" = "yes" ; then ol_have_bignum=yes fi fi @@ -41838,7 +41841,8 @@ fi fi LIBSRCS="$LIBSRCS getpeereid.c" fi -if test "$ac_cv_func_snprintf" != yes -o "$ac_cv_func_vsnprintf" != yes; then +if test "$ac_cv_func_snprintf" != yes || + test "$ac_cv_func_vsnprintf" != yes; then if test "$ac_cv_func_snprintf" != yes; then cat >>confdefs.h <<\_ACEOF @@ -42286,7 +42290,7 @@ _ACEOF fi -if test "$ol_link_ldbm" != no -a $ol_enable_ldbm != no; then +if test "$ol_link_ldbm" != no && test $ol_enable_ldbm != no; then BUILD_SLAPD=yes BUILD_LDBM=$ol_enable_ldbm if test "$ol_enable_ldbm" = mod ; then @@ -42669,8 +42673,9 @@ _ACEOF fi -if test "$ol_enable_slurpd" != no -a "$ol_link_threads" != no -a \ - $BUILD_SLAPD = yes ; then +if test "$ol_enable_slurpd" != no && + test "$ol_link_threads" != no && + test $BUILD_SLAPD = yes ; then BUILD_SLURPD=yes fi diff --git a/configure.in b/configure.in index d1ef9c248c..44b15b56d7 100644 --- a/configure.in +++ b/configure.in @@ -40,7 +40,7 @@ if test -z "$OL_STRING"; then AC_MSG_ERROR([could not determine version]) fi -if test -f "$ac_aux_dir/shtool" -a ! -d $ac_aux_dir/shtool; then +if test -f "$ac_aux_dir/shtool" && test ! -d $ac_aux_dir/shtool; then ac_cv_shtool="$ac_aux_dir/shtool" else AC_MSG_ERROR([no shtool found in $ac_aux_dir]) @@ -483,19 +483,19 @@ elif test $ol_enable_ldbm = no ; then AC_MSG_WARN([LDBM disabled, ignoring --enable-ldbm-type argument]) fi - if test $ol_enable_modules != yes -a \ - $ol_enable_bdb = no -a \ - $ol_enable_dnssrv = no -a \ - $ol_enable_hdb = no -a \ - $ol_enable_ldap = no -a \ - $ol_enable_meta = no -a \ - $ol_enable_monitor = no -a \ - $ol_enable_null = no -a \ - $ol_enable_passwd = no -a \ - $ol_enable_perl = no -a \ - $ol_enable_relay = no -a \ - $ol_enable_shell = no -a \ - $ol_enable_sql = no ; then + if test $ol_enable_modules != yes && + test $ol_enable_bdb = no && + test $ol_enable_dnssrv = no && + test $ol_enable_hdb = no && + test $ol_enable_ldap = no && + test $ol_enable_meta = no && + test $ol_enable_monitor = no && + test $ol_enable_null = no && + test $ol_enable_passwd = no && + test $ol_enable_perl = no && + test $ol_enable_relay = no && + test $ol_enable_shell = no && + test $ol_enable_sql = no ; then if test $ol_enable_slapd = yes ; then AC_MSG_ERROR([slapd requires a backend]) @@ -508,26 +508,26 @@ elif test $ol_enable_ldbm = no ; then ol_enable_ldbm_api=no ol_enable_ldbm_type=no - if test $ol_enable_bdb != no -o $ol_enable_hdb != no; then + if test $ol_enable_bdb/$ol_enable_hdb != no/no; then ol_enable_ldbm_api=berkeley fi else dnl SLAPD with LDBM - if test $ol_enable_ldbm_api = gdbm -a \ - $ol_enable_ldbm_type = btree ; then + if test $ol_enable_ldbm_api = gdbm && + test $ol_enable_ldbm_type = btree ; then AC_MSG_ERROR([GDBM only supports LDBM type hash]) fi - if test $ol_enable_ldbm_api = mdbm -a \ - $ol_enable_ldbm_type = btree ; then + if test $ol_enable_ldbm_api = mdbm && + test $ol_enable_ldbm_type = btree ; then AC_MSG_ERROR([MDBM only supports LDBM type hash]) fi - if test $ol_enable_ldbm_api = ndbm -a \ - $ol_enable_ldbm_type = btree ; then + if test $ol_enable_ldbm_api = ndbm && + test $ol_enable_ldbm_type = btree ; then AC_MSG_ERROR([NDBM only supports LDBM type hash]) fi - if test $ol_enable_bdb != no -o $ol_enable_hdb != no ; then + if test $ol_enable_bdb/$ol_enable_hdb != no/no ; then if test $ol_enable_ldbm_api = auto ; then ol_enable_ldbm_api=berkeley elif test $ol_enable_ldbm_api != berkeley ; then @@ -536,7 +536,7 @@ else fi fi -if test $ol_enable_meta = yes -a $ol_enable_ldap = no ; then +if test $ol_enable_meta/$ol_enable_ldap = yes/no ; then AC_MSG_ERROR([--enable-meta requires --enable-ldap]) fi @@ -700,10 +700,11 @@ if test $ol_aix_threads = yes ; then fi fi - if test "${CC}" = "cc_r" -o "${CC}" = "xlc_r" ; then + case ${CC} in cc_r | xlc_r) ol_with_threads=posix ol_cv_pthread_create=yes - fi + ;; + esac fi if test -z "${CC}"; then @@ -1078,7 +1079,7 @@ if test "$ol_cv_lib_resolver" != no ; then fi fi -if test "$ol_enable_dnssrv" = yes -o "$ol_enable_dnssrv" = mod ; then +if test "$ol_enable_dnssrv" = yes || test "$ol_enable_dnssrv" = mod ; then if test "$ol_link_dnssrv" = no ; then AC_MSG_ERROR([DNSSRV requires res_query()]) fi @@ -1094,7 +1095,7 @@ dnl PF_LOCAL may use getaddrinfo in available AC_CHECK_FUNCS( getaddrinfo getnameinfo gai_strerror inet_ntop ) ol_link_ipv6=no -if test $ac_cv_func_getaddrinfo = no -o $ac_cv_func_inet_ntop = no ; then +if test $ac_cv_func_getaddrinfo = no || test $ac_cv_func_inet_ntop = no ; then if test $ol_enable_ipv6 = yes ; then AC_MSG_ERROR([IPv6 support requires getaddrinfo() and inet_ntop()]) fi @@ -1116,14 +1117,14 @@ elif test $ol_enable_ipv6 != no ; then struct sockaddr_storage ss; ]])],[ol_cv_struct_sockaddr_storage=yes],[ol_cv_struct_sockaddr_storage=no])]) - if test $ol_cv_inet6_addrstrlen = yes \ - -a $ol_cv_struct_sockaddr_storage = yes ; then + if test $ol_cv_inet6_addrstrlen = yes && + test $ol_cv_struct_sockaddr_storage = yes ; then ol_link_ipv6=yes - elif test $ol_enable_ipv6 = yes \ - -a $ol_cv_inet6_addrstrlen = no ; then + elif test $ol_enable_ipv6 = yes && + test $ol_cv_inet6_addrstrlen = no ; then AC_MSG_ERROR([IPv6 support requires INET6_ADDRSTRLEN]) - elif test $ol_enable_ipv6 = yes \ - -a $ol_cv_struct_sockaddr_storage = no ; then + elif test $ol_enable_ipv6 = yes && + test $ol_cv_struct_sockaddr_storage = no ; then AC_MSG_ERROR([IPv6 support requires struct sockaddr_storage]) fi fi @@ -1144,9 +1145,7 @@ ol_link_kbind=no ol_link_krb5=no ol_link_krb4=no -if test $ol_with_kerberos = yes -o $ol_with_kerberos = auto \ - -o $ol_with_kerberos = k5 -o $ol_with_kerberos = k5only \ - -o $ol_with_kerberos = k425 ; then +case $ol_with_kerberos in yes | auto | k5 | k5only | k425) AC_CHECK_HEADERS(krb5.h) @@ -1204,10 +1203,13 @@ if test $ol_with_kerberos = yes -o $ol_with_kerberos = auto \ fi fi -fi + ;; +esac -if test $ol_link_krb5 = yes -a \( $ol_with_kerberos = yes -o \ - $ol_with_kerberos = auto -o $ol_with_kerberos = k425 \) ; then +if test $ol_link_krb5 = yes && + { test $ol_with_kerberos = yes || + test $ol_with_kerberos = auto || + test $ol_with_kerberos = k425; }; then AC_CHECK_HEADERS(kerberosIV/krb.h kerberosIV/des.h) @@ -1266,8 +1268,7 @@ if test $ol_link_krb5 = yes ; then ol_with_kerberos=found fi -if test $ol_with_kerberos = yes -o $ol_with_kerberos = auto \ - -o $ol_with_kerberos = k4 -o $ol_with_kerberos = kth ; then +case $ol_with_kerberos in yes | auto | k4 | kth) AC_CHECK_HEADERS(krb.h des.h krb-archaeology.h ) @@ -1289,19 +1290,20 @@ if test $ol_with_kerberos = yes -o $ol_with_kerberos = auto \ fi fi fi -fi + ;; +esac -if test $ol_link_krb4 = yes -a $ol_enable_kbind != no ; then +if test $ol_link_krb4 = yes && test $ol_enable_kbind != no ; then ol_link_kbind=yes elif test $ol_enable_kbind = yes ; then AC_MSG_ERROR([Kerberos IV detection failed]) fi -if test $ol_link_krb4 = yes -o $ol_link_krb5 = yes ; then +if test $ol_link_krb4 = yes || test $ol_link_krb5 = yes ; then AC_DEFINE(HAVE_KERBEROS, 1, [define if you have Kerberos]) -elif test $ol_with_kerberos != auto -a $ol_with_kerberos != no ; then +elif test $ol_with_kerberos != auto && test $ol_with_kerberos != no ; then AC_MSG_ERROR([Kerberos detection failed]) fi @@ -1312,8 +1314,8 @@ ol_link_tls=no if test $ol_with_tls != no ; then AC_CHECK_HEADERS(openssl/ssl.h ssl.h) - if test $ac_cv_header_openssl_ssl_h = yes \ - -o $ac_cv_header_ssl_h = yes ; then + if test $ac_cv_header_openssl_ssl_h = yes || + test $ac_cv_header_ssl_h = yes ; then AC_CHECK_LIB(ssl, SSLeay_add_ssl_algorithms, [have_ssleay=yes need_rsaref=no], @@ -1390,8 +1392,7 @@ dnl ---------------------------------------------------------------- dnl Threads? ol_link_threads=no -if test $ol_with_threads = auto -o $ol_with_threads = yes \ - -o $ol_with_threads = nt ; then +case $ol_with_threads in auto | yes | nt) OL_NT_THREADS @@ -1407,10 +1408,10 @@ if test $ol_with_threads = auto -o $ol_with_threads = yes \ if test $ol_with_threads = nt ; then AC_MSG_ERROR([could not locate NT Threads]) fi -fi + ;; +esac -if test $ol_with_threads = auto -o $ol_with_threads = yes \ - -o $ol_with_threads = posix ; then +case $ol_with_threads in auto | yes | posix) AC_CHECK_HEADERS(pthread.h) @@ -1526,9 +1527,9 @@ dnl [ol_cv_pthread_lpthread_lexc]) dnl check for both, and thr_yield for Solaris AC_CHECK_FUNCS(sched_yield pthread_yield thr_yield) - if test $ac_cv_func_sched_yield = no -a \ - $ac_cv_func_pthread_yield = no -a \ - $ac_cv_func_thr_yield = no ; then + if test $ac_cv_func_sched_yield = no && + test $ac_cv_func_pthread_yield = no && + test $ac_cv_func_thr_yield = no ; then dnl Digital UNIX has sched_yield() in -lrt AC_CHECK_LIB(rt, sched_yield, [LTHREAD_LIBS="$LTHREAD_LIBS -lrt" @@ -1537,9 +1538,9 @@ dnl [ol_cv_pthread_lpthread_lexc]) ac_cv_func_sched_yield=yes], [ac_cv_func_sched_yield=no]) fi - if test $ac_cv_func_sched_yield = no -a \ - $ac_cv_func_pthread_yield = no -a \ - "$ac_cv_func_thr_yield" = no ; then + if test $ac_cv_func_sched_yield = no && + test $ac_cv_func_pthread_yield = no && + test "$ac_cv_func_thr_yield" = no ; then AC_MSG_WARN([could not locate sched_yield() or pthread_yield()]) fi @@ -1692,10 +1693,10 @@ int main(argc, argv) if test $ol_with_threads = posix ; then AC_MSG_ERROR([could not locate POSIX Threads]) fi -fi + ;; +esac -if test $ol_with_threads = auto -o $ol_with_threads = yes \ - -o $ol_with_threads = mach ; then +case $ol_with_threads in auto | yes | mach) dnl check for Mach CThreads AC_CHECK_HEADERS(mach/cthreads.h cthreads.h) @@ -1757,10 +1758,10 @@ if test $ol_with_threads = auto -o $ol_with_threads = yes \ elif test $ol_with_threads = found ; then AC_MSG_ERROR([could not link with Mach CThreads]) fi -fi + ;; +esac -if test $ol_with_threads = auto -o $ol_with_threads = yes \ - -o $ol_with_threads = pth ; then +case $ol_with_threads in auto | yes | pth) AC_CHECK_HEADERS(pth.h) @@ -1778,14 +1779,15 @@ if test $ol_with_threads = auto -o $ol_with_threads = yes \ fi fi fi -fi + ;; +esac -if test $ol_with_threads = auto -o $ol_with_threads = yes \ - -o $ol_with_threads = lwp ; then +case $ol_with_threads in auto | yes | lwp) dnl check for SunOS5 LWP AC_CHECK_HEADERS(thread.h synch.h) - if test $ac_cv_header_thread_h = yes -a $ac_cv_header_synch_h = yes ; then + if test $ac_cv_header_thread_h = yes && + test $ac_cv_header_synch_h = yes ; then AC_CHECK_LIB(thread, thr_create, [have_thr=yes], [have_thr=no]) if test $have_thr = yes ; then @@ -1822,7 +1824,8 @@ if test $ol_with_threads = auto -o $ol_with_threads = yes \ fi fi fi -fi + ;; +esac if test $ol_with_yielding_select = yes ; then AC_DEFINE(HAVE_YIELDING_SELECT,1, @@ -1844,7 +1847,7 @@ if test $ol_with_threads = manual ; then AC_CHECK_HEADERS(thread.h synch.h) fi -if test $ol_link_threads != no -a $ol_link_threads != nt ; then +if test $ol_link_threads != no && test $ol_link_threads != nt ; then dnl needed to get reentrant/threadsafe versions dnl AC_DEFINE(REENTRANT,1) @@ -1869,8 +1872,8 @@ if test $ol_link_threads != no -a $ol_link_threads != nt ; then AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [[h_errno = 0;]])],[ol_cv_h_errno_thread_specific=yes],[ol_cv_h_errno_thread_specific=no]) ]) - if test $ol_cv_errno_thread_specific != yes \ - -o $ol_cv_h_errno_thread_specific != yes ; then + if test $ol_cv_errno_thread_specific != yes || + test $ol_cv_h_errno_thread_specific != yes ; then LIBS="$LTHREAD_LIBS $LIBS" LTHREAD_LIBS="" fi @@ -1975,9 +1978,7 @@ fi dnl ---------------------------------------------------------------- ol_link_ldbm=no -if test $ol_enable_ldbm_api = auto \ - -o $ol_enable_ldbm_api = berkeley \ - -o $ol_enable_ldbm_api = bcompat ; then +case $ol_enable_ldbm_api in auto | berkeley | bcompat) if test $ol_enable_ldbm_api = bcompat; then \ OL_BERKELEY_COMPAT_DB @@ -2006,9 +2007,10 @@ if test $ol_enable_ldbm_api = auto \ LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_db" fi fi -fi + ;; +esac -if test $ol_enable_bdb != no -o $ol_enable_hdb != no; then +if test $ol_enable_bdb/$ol_enable_hdb != no/no; then if test $ol_link_ldbm != berkeley ; then AC_MSG_ERROR(BDB/HDB: BerkeleyDB not available) else @@ -2020,12 +2022,12 @@ if test $ol_enable_bdb != no -o $ol_enable_hdb != no; then fi fi -if test $ol_link_ldbm = no -a $ol_enable_ldbm_type = btree ; then +if test $ol_link_ldbm = no && test $ol_enable_ldbm_type = btree ; then AC_MSG_WARN([Could not find LDBM with BTREE support]) ol_enable_ldbm_api=none fi -if test $ol_enable_ldbm_api = auto -o $ol_enable_ldbm_api = mdbm ; then +if test $ol_enable_ldbm_api = auto || test $ol_enable_ldbm_api = mdbm ; then OL_MDBM if test $ol_cv_mdbm = yes ; then @@ -2037,7 +2039,7 @@ if test $ol_enable_ldbm_api = auto -o $ol_enable_ldbm_api = mdbm ; then fi fi -if test $ol_enable_ldbm_api = auto -o $ol_enable_ldbm_api = gdbm ; then +if test $ol_enable_ldbm_api = auto || test $ol_enable_ldbm_api = gdbm ; then OL_GDBM if test $ol_cv_gdbm = yes ; then @@ -2063,19 +2065,19 @@ if test $ol_enable_ldbm_api = ndbm ; then fi fi -if test $ol_link_ldbm = no -a $ol_enable_ldbm != no ; then +if test $ol_link_ldbm = no && test $ol_enable_ldbm != no ; then AC_MSG_ERROR([could not find suitable LDBM backend]) fi -if test $ol_enable_bdb = yes -o \ - $ol_enable_hdb = yes -o \ - $ol_enable_ldbm = yes ; then +if test $ol_enable_bdb = yes || + test $ol_enable_hdb = yes || + test $ol_enable_ldbm = yes ; then SLAPD_LIBS="$SLAPD_LIBS \$(LDBM_LIBS)" fi dnl ---------------------------------------------------------------- -if test $ol_enable_dynamic = yes -a $enable_shared = yes ; then +if test $ol_enable_dynamic = yes && test $enable_shared = yes ; then BUILD_LIBS_DYNAMIC=shared AC_DEFINE(LDAP_LIBS_DYNAMIC, 1, [define if LDAP libs are dynamic]) LTSTATIC="" @@ -2133,7 +2135,7 @@ fi dnl ---------------------------------------------------------------- if test $ol_enable_syslog != no ; then AC_CHECK_FUNC(openlog) - if test $ac_cv_func_openlog = no -a $ol_enable_syslog = yes; then + if test $ac_cv_func_openlog = no && test $ol_enable_syslog = yes; then AC_MSG_ERROR(could not find syslog, select appropriate options or disable) fi ol_enable_syslog=$ac_cv_func_openlog @@ -2180,7 +2182,8 @@ ol_link_spasswd=no if test $ol_with_cyrus_sasl != no ; then AC_CHECK_HEADERS(sasl/sasl.h sasl.h) - if test $ac_cv_header_sasl_sasl_h = yes -o $ac_cv_header_sasl_h = yes; then + if test $ac_cv_header_sasl_sasl_h = yes || + test $ac_cv_header_sasl_h = yes; then AC_CHECK_LIB(sasl2, sasl_client_init, [ol_link_sasl="-lsasl2"], [AC_CHECK_LIB(sasl, sasl_client_init, @@ -2228,7 +2231,7 @@ fi dnl ---------------------------------------------------------------- dnl Check for entropy sources -if test $cross_compiling != yes -a "$ac_cv_mingw32" != yes ; then +if test $cross_compiling != yes && test "$ac_cv_mingw32" != yes ; then dev=no if test -r /dev/urandom ; then dev="/dev/urandom"; @@ -2339,18 +2342,18 @@ if test "$ol_with_multiple_precision" != "no" ; then ol_have_bn_h=no ol_have_crypto_h=no - if test "$ac_cv_header_openssl_bn_h" = "yes" \ - -o "$ac_cv_header_bn_h" = "yes" ; then + if test "$ac_cv_header_openssl_bn_h" = "yes" || + test "$ac_cv_header_bn_h" = "yes" ; then ol_have_bn_h=yes fi - if test "$ac_cv_header_openssl_crypto_h" = "yes" \ - -o "$ac_cv_header_crypto_h" = "yes" ; then + if test "$ac_cv_header_openssl_crypto_h" = "yes" || + test "$ac_cv_header_crypto_h" = "yes" ; then ol_have_crypto_h=yes fi - if test "$ol_have_bn_h" = "yes" \ - -a "$ol_have_crypto_h" = "yes" ; then + if test "$ol_have_bn_h" = "yes" && + test "$ol_have_crypto_h" = "yes" ; then ol_have_bignum=yes fi fi @@ -2595,7 +2598,8 @@ if test "$ac_cv_func_getpeereid" != yes; then fi LIBSRCS="$LIBSRCS getpeereid.c" fi -if test "$ac_cv_func_snprintf" != yes -o "$ac_cv_func_vsnprintf" != yes; then +if test "$ac_cv_func_snprintf" != yes || + test "$ac_cv_func_vsnprintf" != yes; then if test "$ac_cv_func_snprintf" != yes; then AC_DEFINE(snprintf, ber_pvt_snprintf, [define to snprintf routine]) fi @@ -2734,7 +2738,7 @@ if test "$ol_enable_ldap" != no ; then AC_DEFINE_UNQUOTED(SLAPD_LDAP,$MFLAG,[define to support LDAP backend]) fi -if test "$ol_link_ldbm" != no -a $ol_enable_ldbm != no; then +if test "$ol_link_ldbm" != no && test $ol_enable_ldbm != no; then BUILD_SLAPD=yes BUILD_LDBM=$ol_enable_ldbm if test "$ol_enable_ldbm" = mod ; then @@ -3024,8 +3028,9 @@ if test "$ol_enable_valsort" != no ; then AC_DEFINE_UNQUOTED(SLAPD_OVER_VALSORT,$MFLAG,[define for Value Sorting overlay]) fi -if test "$ol_enable_slurpd" != no -a "$ol_link_threads" != no -a \ - $BUILD_SLAPD = yes ; then +if test "$ol_enable_slurpd" != no && + test "$ol_link_threads" != no && + test $BUILD_SLAPD = yes ; then BUILD_SLURPD=yes fi diff --git a/doc/guide/admin/slapdconf2.sdf b/doc/guide/admin/slapdconf2.sdf index 8f9d607fa2..4db17e6d77 100644 --- a/doc/guide/admin/slapdconf2.sdf +++ b/doc/guide/admin/slapdconf2.sdf @@ -71,9 +71,9 @@ loaded from config files or added at runtime. The usual rules for LDIF files apply to the configuration information: Comment lines beginning with a '{{EX:#}}' character -are ignored. If a line begins with white space, it is considered a +are ignored. If a line begins with a single space, it is considered a continuation of the previous line (even if the previous line is a -comment). Entries are separated by blank lines. +comment) and the single leading space is removed. Entries are separated by blank lines. The general layout of the config LDIF is as follows: @@ -132,9 +132,7 @@ prefix attached. A configuration directive may take arguments. If so, the arguments are separated by white space. If an argument contains white space, -the argument should be enclosed in double quotes {{EX:"like this"}}. If -an argument contains a double quote or a backslash character `{{EX:\}}', -the character should be preceded by a backslash character `{{EX:\}}'. +the argument should be enclosed in double quotes {{EX:"like this"}}. In the descriptions that follow, arguments that should be replaced by actual text are shown in brackets {{EX:<>}}. @@ -349,13 +347,13 @@ H4: Sample Entries >objectClass: olcSchemaConfig >cn: test >olcAttributeTypes: ( 1.1.1 -> NAME 'testAttr' -> EQUALITY integerMatch -> SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 ) +> NAME 'testAttr' +> EQUALITY integerMatch +> SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 ) >olcAttributeTypes: ( 1.1.2 NAME 'testTwo' EQUALITY caseIgnoreMatch -> SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.44 ) +> SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.44 ) >olcObjectClasses: ( 1.1.3 NAME 'testObject' -> MAY ( testAttr $ testTwo ) AUXILIARY ) +> MAY ( testAttr $ testTwo ) AUXILIARY ) H3: Backend-specific Directives diff --git a/include/avl.h b/include/avl.h index 458f99fd48..70bdbcd6cb 100644 --- a/include/avl.h +++ b/include/avl.h @@ -40,11 +40,16 @@ typedef struct avlnode Avlnode; struct avlnode { void* avl_data; - signed int avl_bf; - struct avlnode *avl_left; - struct avlnode *avl_right; + struct avlnode *avl_link[2]; + char avl_bits[2]; + signed char avl_bf; }; +#define avl_left avl_link[0] +#define avl_right avl_link[1] +#define avl_lbit avl_bits[0] +#define avl_rbit avl_bits[1] + #ifdef AVL_INTERNAL #define NULLAVL ((Avlnode *) NULL) @@ -54,12 +59,21 @@ struct avlnode { #define EH 0 #define RH 1 +/* thread bits */ +#define AVL_THREAD 0 +#define AVL_CHILD 1 + /* avl routines */ #define avl_getone(x) ((x) == 0 ? 0 : (x)->avl_data) #define avl_onenode(x) ((x) == 0 || ((x)->avl_left == 0 && (x)->avl_right == 0)) #endif /* AVL_INTERNALS */ +#define avl_child(x,dir) ((x)->avl_bits[dir]) == AVL_CHILD ? \ + (x)->avl_link[dir] : NULL +#define avl_lchild(x) avl_child(x,0) +#define avl_rchild(x) avl_child(x,1) + typedef int (*AVL_APPLY) LDAP_P((void *, void*)); typedef int (*AVL_CMP) LDAP_P((const void*, const void*)); typedef int (*AVL_DUP) LDAP_P((void*, void*)); @@ -103,6 +117,30 @@ avl_apply LDAP_P((Avlnode *, AVL_APPLY, void*, int, int)); LDAP_AVL_F( int ) avl_prefixapply LDAP_P((Avlnode *, void*, AVL_CMP, void*, AVL_CMP, void*, int)); +LDAP_AVL_F( int ) +tavl_free LDAP_P(( Avlnode *root, AVL_FREE dfree )); + +LDAP_AVL_F( int ) +tavl_insert LDAP_P((Avlnode **, void*, AVL_CMP, AVL_DUP)); + +LDAP_AVL_F( void* ) +tavl_delete LDAP_P((Avlnode **, void*, AVL_CMP)); + +LDAP_AVL_F( void* ) +tavl_find LDAP_P((Avlnode *, const void*, AVL_CMP)); + +LDAP_AVL_F( Avlnode* ) +tavl_find2 LDAP_P((Avlnode *, const void*, AVL_CMP)); + +#define TAVL_DIR_LEFT 0 +#define TAVL_DIR_RIGHT 1 + +LDAP_AVL_F( Avlnode* ) +tavl_end LDAP_P((Avlnode *, int direction )); + +LDAP_AVL_F( Avlnode* ) +tavl_next LDAP_P((Avlnode *, int direction )); + /* apply traversal types */ #define AVL_PREORDER 1 #define AVL_INORDER 2 diff --git a/include/ldap_int_thread.h b/include/ldap_int_thread.h index 385fef52f6..307d85c86e 100644 --- a/include/ldap_int_thread.h +++ b/include/ldap_int_thread.h @@ -14,6 +14,16 @@ * . */ + +LDAP_BEGIN_DECL + +/* Can be done twice in libldap_r. See libldap_r/ldap_thr_debug.h. */ +LDAP_F(int) ldap_int_thread_initialize LDAP_P(( void )); +LDAP_F(int) ldap_int_thread_destroy LDAP_P(( void )); + +LDAP_END_DECL + + #ifndef _LDAP_INT_THREAD_H #define _LDAP_INT_THREAD_H @@ -35,6 +45,8 @@ typedef pthread_t ldap_int_thread_t; typedef pthread_mutex_t ldap_int_thread_mutex_t; typedef pthread_cond_t ldap_int_thread_cond_t; +#define ldap_int_thread_equal(a, b) pthread_equal((a), (b)) + #if defined( _POSIX_REENTRANT_FUNCTIONS ) || \ defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \ defined( _POSIX_THREADSAFE_FUNCTIONS ) @@ -53,7 +65,7 @@ typedef pthread_cond_t ldap_int_thread_cond_t; #if 0 && defined( HAVE_PTHREAD_RWLOCK_DESTROY ) #define LDAP_THREAD_HAVE_RDWR 1 -typedef pthread_rwlock_t ldap_pvt_thread_rdwr_t; +typedef pthread_rwlock_t ldap_int_thread_rdwr_t; #endif LDAP_END_DECL @@ -97,7 +109,7 @@ typedef pth_cond_t ldap_int_thread_cond_t; #if 0 #define LDAP_THREAD_HAVE_RDWR 1 -typedef pth_rwlock_t ldap_pvt_thread_rdwr_t; +typedef pth_rwlock_t ldap_int_thread_rdwr_t; #endif LDAP_END_DECL @@ -155,6 +167,11 @@ typedef struct ldap_int_thread_lwp_cv ldap_int_thread_cond_t; LDAP_END_DECL #elif defined(HAVE_NT_THREADS) +/************************************* + * * + * thread definitions for NT threads * + * * + *************************************/ #include #include @@ -168,7 +185,6 @@ typedef HANDLE ldap_int_thread_cond_t; LDAP_END_DECL #else - /*********************************** * * * thread definitions for no * @@ -193,10 +209,17 @@ LDAP_END_DECL #endif /* no threads support */ + LDAP_BEGIN_DECL -LDAP_F(int) ldap_int_thread_initialize LDAP_P(( void )); -LDAP_F(int) ldap_int_thread_destroy LDAP_P(( void )); +#ifndef ldap_int_thread_equal +#define ldap_int_thread_equal(a, b) ((a) == (b)) +#endif + +#ifndef LDAP_THREAD_HAVE_RDWR +typedef struct ldap_int_thread_rdwr_s * ldap_int_thread_rdwr_t; +#endif + LDAP_F(int) ldap_int_thread_pool_startup ( void ); LDAP_F(int) ldap_int_thread_pool_shutdown ( void ); @@ -206,4 +229,46 @@ typedef struct ldap_int_thread_pool_s * ldap_int_thread_pool_t; LDAP_END_DECL + +#if defined(LDAP_THREAD_DEBUG) && !((LDAP_THREAD_DEBUG +0) & 2U) +#define LDAP_THREAD_DEBUG_WRAP 1 +#endif + +#ifdef LDAP_THREAD_DEBUG_WRAP +/************************************** + * * + * definitions for type-wrapped debug * + * * + **************************************/ + +LDAP_BEGIN_DECL + +#ifndef LDAP_UINTPTR_T /* May be configured in CPPFLAGS */ +#define LDAP_UINTPTR_T unsigned long +#endif + +typedef union { + unsigned char *ptr; + LDAP_UINTPTR_T num; +} ldap_debug_usage_info_t; + +typedef struct { + ldap_int_thread_mutex_t wrapped; + ldap_debug_usage_info_t usage; +} ldap_debug_thread_mutex_t; + +typedef struct { + ldap_int_thread_cond_t wrapped; + ldap_debug_usage_info_t usage; +} ldap_debug_thread_cond_t; + +typedef struct { + ldap_int_thread_rdwr_t wrapped; + ldap_debug_usage_info_t usage; +} ldap_debug_thread_rdwr_t; + +LDAP_END_DECL + +#endif /* LDAP_THREAD_DEBUG_WRAP */ + #endif /* _LDAP_INT_THREAD_H */ diff --git a/include/ldap_pvt_thread.h b/include/ldap_pvt_thread.h index 79c821dd65..47bcf129bb 100644 --- a/include/ldap_pvt_thread.h +++ b/include/ldap_pvt_thread.h @@ -15,16 +15,27 @@ */ #ifndef _LDAP_PVT_THREAD_H -#define _LDAP_PVT_THREAD_H +#define _LDAP_PVT_THREAD_H /* libldap_r/ldap_thr_debug.h #undefines this */ #include "ldap_cdefs.h" #include "ldap_int_thread.h" LDAP_BEGIN_DECL -typedef ldap_int_thread_t ldap_pvt_thread_t; -typedef ldap_int_thread_mutex_t ldap_pvt_thread_mutex_t; -typedef ldap_int_thread_cond_t ldap_pvt_thread_cond_t; +#ifndef LDAP_PVT_THREAD_H_DONE +typedef ldap_int_thread_t ldap_pvt_thread_t; +#ifdef LDAP_THREAD_DEBUG_WRAP +typedef ldap_debug_thread_mutex_t ldap_pvt_thread_mutex_t; +typedef ldap_debug_thread_cond_t ldap_pvt_thread_cond_t; +typedef ldap_debug_thread_rdwr_t ldap_pvt_thread_rdwr_t; +#else +typedef ldap_int_thread_mutex_t ldap_pvt_thread_mutex_t; +typedef ldap_int_thread_cond_t ldap_pvt_thread_cond_t; +typedef ldap_int_thread_rdwr_t ldap_pvt_thread_rdwr_t; +#endif +#endif /* !LDAP_PVT_THREAD_H_DONE */ + +#define ldap_pvt_thread_equal ldap_int_thread_equal LDAP_F( int ) ldap_pvt_thread_initialize LDAP_P(( void )); @@ -44,6 +55,7 @@ ldap_pvt_thread_set_concurrency LDAP_P(( int )); #define LDAP_PVT_THREAD_CREATE_JOINABLE 0 #define LDAP_PVT_THREAD_CREATE_DETACHED 1 +#ifndef LDAP_PVT_THREAD_H_DONE #define LDAP_PVT_THREAD_SET_STACK_SIZE #ifndef LDAP_PVT_THREAD_STACK_SIZE /* LARGE stack. Will be twice as large on 64 bit machine. */ @@ -52,6 +64,7 @@ ldap_pvt_thread_set_concurrency LDAP_P(( int )); #elif LDAP_PVT_THREAD_STACK_SIZE == 0 #undef LDAP_PVT_THREAD_SET_STACK_SIZE #endif +#endif /* !LDAP_PVT_THREAD_H_DONE */ LDAP_F( int ) ldap_pvt_thread_create LDAP_P(( @@ -107,10 +120,6 @@ ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex )); LDAP_F( ldap_pvt_thread_t ) ldap_pvt_thread_self LDAP_P(( void )); -#ifndef LDAP_THREAD_HAVE_RDWR -typedef struct ldap_int_thread_rdwr_s * ldap_pvt_thread_rdwr_t; -#endif - LDAP_F( int ) ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp)); @@ -149,10 +158,12 @@ ldap_pvt_thread_rdwr_active LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp)); #define LDAP_PVT_THREAD_EINVAL EINVAL #define LDAP_PVT_THREAD_EBUSY EINVAL +#ifndef LDAP_PVT_THREAD_H_DONE typedef ldap_int_thread_pool_t ldap_pvt_thread_pool_t; typedef void * (ldap_pvt_thread_start_t) LDAP_P((void *ctx, void *arg)); typedef void (ldap_pvt_thread_pool_keyfree_t) LDAP_P((void *key, void *data)); +#endif /* !LDAP_PVT_THREAD_H_DONE */ LDAP_F( int ) ldap_pvt_thread_pool_init LDAP_P(( @@ -213,4 +224,5 @@ ldap_pvt_thread_pool_context_reset LDAP_P(( void *key )); LDAP_END_DECL +#define LDAP_PVT_THREAD_H_DONE #endif /* _LDAP_THREAD_H */ diff --git a/libraries/liblber/encode.c b/libraries/liblber/encode.c index 30ffac3a1e..f0ea2c8698 100644 --- a/libraries/liblber/encode.c +++ b/libraries/liblber/encode.c @@ -56,18 +56,20 @@ static int ber_put_int_or_enum LDAP_P(( ber_int_t num, ber_tag_t tag )); +#define BER_TOP_BYTE(type) (sizeof(type)-1) +#define BER_TOP_MASK(type) ((type)0xffU << (BER_TOP_BYTE(type)*8)) static int ber_calc_taglen( ber_tag_t tag ) { - int i; - ber_tag_t mask; + int i = BER_TOP_BYTE(ber_tag_t); + ber_tag_t mask = BER_TOP_MASK(ber_tag_t); /* find the first non-all-zero byte in the tag */ - for ( i = sizeof(ber_tag_t) - 1; i > 0; i-- ) { - mask = ((ber_tag_t)0xffU << (i * 8)); + for ( ; i > 0; i-- ) { /* not all zero */ if ( tag & mask ) break; + mask >>= 8; } return i + 1; @@ -80,7 +82,7 @@ ber_put_tag( int nosos ) { int rc; - int taglen; + int taglen; int i; unsigned char nettag[sizeof(ber_tag_t)]; @@ -89,14 +91,12 @@ ber_put_tag( taglen = ber_calc_taglen( tag ); - for( i=0; i=0; i-- ) { + nettag[i] = (unsigned char)(tag & 0xffU); tag >>= 8; } - rc = ber_write( ber, - (char *) &nettag[sizeof(ber_tag_t) - taglen], - taglen, nosos ); + rc = ber_write( ber, (char *) nettag, taglen, nosos ); return rc; } @@ -151,10 +151,12 @@ ber_put_len( BerElement *ber, ber_len_t len, int nosos ) */ /* find the first non-all-zero byte */ - for ( i = sizeof(ber_len_t) - 1; i > 0; i-- ) { - mask = ((ber_len_t)0xffU << (i * 8)); + i = BER_TOP_BYTE(ber_len_t); + mask = BER_TOP_MASK(ber_len_t); + for ( ; i > 0; i-- ) { /* not all zero */ if ( len & mask ) break; + mask >>= 8; } lenlen = (unsigned char) ++i; if ( lenlen > 4 ) return -1; @@ -164,15 +166,13 @@ ber_put_len( BerElement *ber, ber_len_t len, int nosos ) /* write the length of the length */ if ( ber_write( ber, &lenlen, 1, nosos ) != 1 ) return -1; - for( j=0; j=0; j-- ) { + netlen[j] = (unsigned char)(len & 0xffU); len >>= 8; } /* write the length itself */ - rc = ber_write( ber, - (char *) &netlen[sizeof(ber_len_t)-i], - i, nosos ); + rc = ber_write( ber, (char *) netlen, i, nosos ); return rc == i ? i+1 : -1; } @@ -199,9 +199,9 @@ ber_put_int_or_enum( * high bit is set - look for first non-all-one byte * high bit is clear - look for first non-all-zero byte */ - for ( i = sizeof(ber_int_t) - 1; i > 0; i-- ) { - mask = ((ber_uint_t)0xffU << (i * 8)); - + i = BER_TOP_BYTE(ber_int_t); + mask = BER_TOP_MASK(ber_uint_t); + for ( ; i > 0; i-- ) { if ( sign ) { /* not all ones */ if ( (unum & mask) != mask ) break; @@ -209,6 +209,7 @@ ber_put_int_or_enum( /* not all zero */ if ( unum & mask ) break; } + mask >>= 8; } /* @@ -231,14 +232,12 @@ ber_put_int_or_enum( } i++; - for( j=0; j=0; j-- ) { + netnum[j] = (unsigned char)(unum & 0xffU); unum >>= 8; } - rc = ber_write( ber, - (char *) &netnum[sizeof(ber_int_t) - i], - i, 0 ); + rc = ber_write( ber, (char *) netnum, i, 0 ); /* length of tag + length + contents */ return rc == i ? taglen + lenlen + i : -1; @@ -536,13 +535,14 @@ ber_put_seqorset( BerElement *ber ) } if( lenlen > 1 ) { - ber_len_t i; - for( i=0; i < lenlen-1; i++ ) { - netlen[(sizeof(ber_len_t)-1) - i] = - (unsigned char)((len >> i*8) & 0xffU); + int i; + ber_len_t j = len; + for( i=lenlen-2; i >= 0; i-- ) { + netlen[i] = j & 0xffU; + j >>= 8; } } else { - netlen[sizeof(ber_len_t)-1] = (unsigned char)(len & 0x7fU); + netlen[0] = (unsigned char)(len & 0x7fU); } if ( (next = (*sos)->sos_next) == NULL ) { @@ -575,9 +575,7 @@ ber_put_seqorset( BerElement *ber ) } /* the length itself */ - rc = ber_write( ber, - (char *) &netlen[sizeof(ber_len_t) - (FOUR_BYTE_LEN-1)], - FOUR_BYTE_LEN-1, 1 ); + rc = ber_write( ber, (char *) netlen, FOUR_BYTE_LEN-1, 1 ); if( rc != FOUR_BYTE_LEN - 1 ) { return -1; @@ -609,14 +607,12 @@ ber_put_seqorset( BerElement *ber ) /* the tag */ taglen = ber_calc_taglen( tmptag ); - for( i = 0; i < taglen; i++ ) { - nettag[(sizeof(ber_tag_t)-1) - i] = (unsigned char)(tmptag & 0xffU); + for( i = taglen-1; i >= 0; i-- ) { + nettag[i] = (unsigned char)(tmptag & 0xffU); tmptag >>= 8; } - AC_FMEMCPY( (*sos)->sos_first, - &nettag[sizeof(ber_tag_t) - taglen], - taglen ); + AC_FMEMCPY( (*sos)->sos_first, nettag, taglen ); if ( ber->ber_options & LBER_USE_DER ) { ltag = (lenlen == 1) @@ -630,9 +626,7 @@ ber_put_seqorset( BerElement *ber ) if ( ber->ber_options & LBER_USE_DER ) { if (lenlen > 1) { /* Write the length itself */ - AC_FMEMCPY( (*sos)->sos_first + 2, - &netlen[sizeof(ber_len_t) - (lenlen - 1)], - lenlen - 1 ); + AC_FMEMCPY( (*sos)->sos_first + 2, netlen, lenlen - 1 ); } if (lenlen != FOUR_BYTE_LEN) { /* @@ -647,8 +641,7 @@ ber_put_seqorset( BerElement *ber ) } else { /* the length itself */ AC_FMEMCPY( (*sos)->sos_first + taglen + 1, - &netlen[sizeof(ber_len_t) - (FOUR_BYTE_LEN - 1)], - FOUR_BYTE_LEN - 1 ); + netlen, FOUR_BYTE_LEN - 1 ); } next->sos_clen += (taglen + lenlen + len); diff --git a/libraries/liblber/io.c b/libraries/liblber/io.c index f5f7ce9b16..fc37f8dfb2 100644 --- a/libraries/liblber/io.c +++ b/libraries/liblber/io.c @@ -559,7 +559,7 @@ ber_get_next( /* Now look for the length */ if (*ber->ber_ptr & 0x80) { /* multi-byte */ - ber_len_t i; + int i; unsigned char *p = (unsigned char *)ber->ber_ptr; int llen = *p++ & 0x7f; if (llen > (int)sizeof(ber_len_t)) { diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index 7715044f14..02eb7828aa 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -209,7 +209,8 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s, int async) { int rc; - struct timeval tv, *opt_tv=NULL; + struct timeval tv = { 0 }, + *opt_tv = NULL; #ifdef LDAP_CONNECTIONLESS /* We could do a connect() but that would interfere with @@ -223,9 +224,9 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s, return ( 0 ); } #endif - if ( (opt_tv = ld->ld_options.ldo_tm_net) != NULL ) { - tv.tv_usec = opt_tv->tv_usec; - tv.tv_sec = opt_tv->tv_sec; + opt_tv = ld->ld_options.ldo_tm_net; + if ( opt_tv != NULL ) { + tv = *opt_tv; } osip_debug(ld, "ldap_connect_timeout: fd: %d tm: %ld async: %d\n", diff --git a/libraries/libldap/os-local.c b/libraries/libldap/os-local.c index 5c46e5c612..1079c50713 100644 --- a/libraries/libldap/os-local.c +++ b/libraries/libldap/os-local.c @@ -167,11 +167,12 @@ static int ldap_pvt_connect(LDAP *ld, ber_socket_t s, struct sockaddr_un *sa, int async) { int rc; - struct timeval tv, *opt_tv=NULL; + struct timeval tv = { 0 }, + *opt_tv = NULL; - if ( (opt_tv = ld->ld_options.ldo_tm_net) != NULL ) { - tv.tv_usec = opt_tv->tv_usec; - tv.tv_sec = opt_tv->tv_sec; + opt_tv = ld->ld_options.ldo_tm_net; + if ( opt_tv != NULL ) { + tv = *opt_tv; } oslocal_debug(ld, "ldap_connect_timeout: fd: %d tm: %ld async: %d\n", diff --git a/libraries/libldap/result.c b/libraries/libldap/result.c index a4f1093bbe..6891e6f915 100644 --- a/libraries/libldap/result.c +++ b/libraries/libldap/result.c @@ -251,7 +251,9 @@ wait4msg( LDAPMessage **result ) { int rc; - struct timeval tv, tv0, *tvp; + struct timeval tv = { 0 }, + tv0 = { 0 }, + *tvp; time_t start_time = 0; time_t tmp_time; LDAPConn *lc, *nextlc; @@ -281,9 +283,9 @@ wait4msg( rc = -2; while ( rc == -2 ) { #ifdef LDAP_DEBUG - Debug( LDAP_DEBUG_TRACE, "wait4msg continue, msgid %d, all %d\n", - msgid, all, 0 ); if ( ldap_debug & LDAP_DEBUG_TRACE ) { + Debug( LDAP_DEBUG_TRACE, "wait4msg continue, msgid %d, all %d\n", + msgid, all, 0 ); ldap_dump_connection( ld, ld->ld_conns, 1 ); ldap_dump_requests_and_responses( ld ); } @@ -360,7 +362,8 @@ wait4msg( if ( rc == -2 && tvp != NULL ) { tmp_time = time( NULL ); - if (( tv0.tv_sec -= ( tmp_time - start_time )) <= 0 ) { + tv0.tv_sec -= ( tmp_time - start_time ); + if ( tv0.tv_sec <= 0 ) { rc = 0; /* timed out */ ld->ld_errno = LDAP_TIMEOUT; break; @@ -1070,7 +1073,7 @@ int ldap_msgtype( LDAPMessage *lm ) { assert( lm != NULL ); - return ( lm != NULL ) ? lm->lm_msgtype : -1; + return ( lm != NULL ) ? (int)lm->lm_msgtype : -1; } diff --git a/libraries/libldap_r/Makefile.in b/libraries/libldap_r/Makefile.in index 09554ea9ad..bc658b84f3 100644 --- a/libraries/libldap_r/Makefile.in +++ b/libraries/libldap_r/Makefile.in @@ -31,10 +31,10 @@ XXSRCS = apitest.c test.c \ turn.c groupings.c txn.c ppolicy.c SRCS = threads.c rdwr.c tpool.c rq.c \ thr_posix.c thr_cthreads.c thr_thr.c thr_lwp.c thr_nt.c \ - thr_pth.c thr_stub.c + thr_pth.c thr_stub.c thr_debug.c OBJS = threads.lo rdwr.lo tpool.lo rq.lo \ thr_posix.lo thr_cthreads.lo thr_thr.lo thr_lwp.lo thr_nt.lo \ - thr_pth.lo thr_stub.lo \ + thr_pth.lo thr_stub.lo thr_debug.lo \ bind.lo open.lo result.lo error.lo compare.lo search.lo \ controls.lo messages.lo references.lo extended.lo cyrus.lo \ modify.lo add.lo modrdn.lo delete.lo abandon.lo \ diff --git a/libraries/libldap_r/ldap_thr_debug.h b/libraries/libldap_r/ldap_thr_debug.h new file mode 100644 index 0000000000..9c15bb1c79 --- /dev/null +++ b/libraries/libldap_r/ldap_thr_debug.h @@ -0,0 +1,175 @@ +/* ldap_thr_debug.h - preprocessor magic for LDAP_THREAD_DEBUG */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 2005 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ + +#ifdef LDAP_THREAD_DEBUG + +/* + * libldap_r .c files should include this file after ldap_pvt_thread.h, + * with the appropriate LDAP_THREAD*_IMPLEMENTATION macro defined. + */ + +#ifndef _LDAP_PVT_THREAD_H +#error "ldap_pvt_thread.h" must be included before "ldap_thr_debug.h" +#endif + +/* + * Support for thr_debug.c: + * + * thr_debug.c defines the ldap_pvt_*() as wrappers around + * ldap_int_*(), and ldap_debug_*() around ldap_int_*(). + * + * Renames ldap_pvt_thread_* names to ldap_int_thread_*, and a few + * ldap_int_*() names to ldap_debug_*(). Includes "ldap_pvt_thread.h" + * to declare these renamed functions, and undefines the macros + * afterwards when included from thr_debug.c. So, + * + * libldap_r/ define ldap_int_* instead of ldap_pvt_*. + * In thread.c, ldap_pvt_thread_() will call + * ldap_debug_*() instead of ldap_int_*(). + * In tpool.c, ldap_int_thread_pool_shutdown() has thr_debug support + * which treats ldap_pvt_thread_pool_destroy() the same way. + */ + +#ifndef LDAP_THREAD_IMPLEMENTATION /* for first part of threads.c */ +#define ldap_int_thread_initialize ldap_debug_thread_initialize +#define ldap_int_thread_destroy ldap_debug_thread_destroy +#else /* LDAP_THREAD_IMPLEMENTATION -- for thr_*.c and end of threads.c */ +#undef ldap_int_thread_initialize +#undef ldap_int_thread_destroy +#ifdef LDAP_THREAD_DEBUG_WRAP /* see ldap_pvt_thread.h */ +#define ldap_pvt_thread_mutex_t ldap_int_thread_mutex_t +#define ldap_pvt_thread_cond_t ldap_int_thread_cond_t +#endif +#define ldap_pvt_thread_sleep ldap_int_thread_sleep +#define ldap_pvt_thread_get_concurrency ldap_int_thread_get_concurrency +#define ldap_pvt_thread_set_concurrency ldap_int_thread_set_concurrency +#define ldap_pvt_thread_create ldap_int_thread_create +#define ldap_pvt_thread_exit ldap_int_thread_exit +#define ldap_pvt_thread_join ldap_int_thread_join +#define ldap_pvt_thread_kill ldap_int_thread_kill +#define ldap_pvt_thread_yield ldap_int_thread_yield +#define ldap_pvt_thread_cond_init ldap_int_thread_cond_init +#define ldap_pvt_thread_cond_destroy ldap_int_thread_cond_destroy +#define ldap_pvt_thread_cond_signal ldap_int_thread_cond_signal +#define ldap_pvt_thread_cond_broadcast ldap_int_thread_cond_broadcast +#define ldap_pvt_thread_cond_wait ldap_int_thread_cond_wait +#define ldap_pvt_thread_mutex_init ldap_int_thread_mutex_init +#define ldap_pvt_thread_mutex_destroy ldap_int_thread_mutex_destroy +#define ldap_pvt_thread_mutex_lock ldap_int_thread_mutex_lock +#define ldap_pvt_thread_mutex_trylock ldap_int_thread_mutex_trylock +#define ldap_pvt_thread_mutex_unlock ldap_int_thread_mutex_unlock +#define ldap_pvt_thread_self ldap_int_thread_self +#endif /* LDAP_THREAD_IMPLEMENTATION */ + +#ifdef LDAP_THREAD_RDWR_IMPLEMENTATION /* rdwr.c, thr_debug.c */ +#ifdef LDAP_THREAD_DEBUG_WRAP /* see ldap_pvt_thread.h */ +#define ldap_pvt_thread_rdwr_t ldap_int_thread_rdwr_t +#endif +#define ldap_pvt_thread_rdwr_init ldap_int_thread_rdwr_init +#define ldap_pvt_thread_rdwr_destroy ldap_int_thread_rdwr_destroy +#define ldap_pvt_thread_rdwr_rlock ldap_int_thread_rdwr_rlock +#define ldap_pvt_thread_rdwr_rtrylock ldap_int_thread_rdwr_rtrylock +#define ldap_pvt_thread_rdwr_runlock ldap_int_thread_rdwr_runlock +#define ldap_pvt_thread_rdwr_wlock ldap_int_thread_rdwr_wlock +#define ldap_pvt_thread_rdwr_wtrylock ldap_int_thread_rdwr_wtrylock +#define ldap_pvt_thread_rdwr_wunlock ldap_int_thread_rdwr_wunlock +#define ldap_pvt_thread_rdwr_readers ldap_int_thread_rdwr_readers +#define ldap_pvt_thread_rdwr_writers ldap_int_thread_rdwr_writers +#define ldap_pvt_thread_rdwr_active ldap_int_thread_rdwr_active +#endif /* LDAP_THREAD_RDWR_IMPLEMENTATION */ + +#ifdef LDAP_THREAD_POOL_IMPLEMENTATION /* tpool.c, thr_stub.c, thr_debug.c */ +#ifdef LDAP_THREAD_DEBUG_WRAP /* see ldap_pvt_thread.h */ +#define ldap_pvt_thread_pool_t ldap_int_thread_pool_t +#endif +#define ldap_pvt_thread_pool_init ldap_int_thread_pool_init +#define ldap_pvt_thread_pool_submit ldap_int_thread_pool_submit +#define ldap_pvt_thread_pool_maxthreads ldap_int_thread_pool_maxthreads +#define ldap_pvt_thread_pool_backload ldap_int_thread_pool_backload +#define ldap_pvt_thread_pool_pause ldap_int_thread_pool_pause +#define ldap_pvt_thread_pool_resume ldap_int_thread_pool_resume +#define ldap_pvt_thread_pool_destroy ldap_int_thread_pool_destroy +#define ldap_pvt_thread_pool_getkey ldap_int_thread_pool_getkey +#define ldap_pvt_thread_pool_setkey ldap_int_thread_pool_setkey +#define ldap_pvt_thread_pool_purgekey ldap_int_thread_pool_purgekey +#define ldap_pvt_thread_pool_context ldap_int_thread_pool_context +#define ldap_pvt_thread_pool_context_reset ldap_int_thread_pool_context_reset +#endif /* LDAP_THREAD_POOL_IMPLEMENTATION */ + +#undef _LDAP_PVT_THREAD_H +#include "ldap_pvt_thread.h" + +#ifdef LDAP_THREAD_POOL_IMPLEMENTATION /* tpool.c */ +/* + * tpool.c:ldap_int_thread_pool_shutdown() needs this. Could not + * use it for ldap_pvt_thread.h above because of its use of LDAP_P(). + */ +#undef ldap_pvt_thread_pool_destroy +#define ldap_pvt_thread_pool_destroy(p,r) ldap_int_thread_pool_destroy(p,r) +#endif + +#ifdef LDAP_THREAD_DEBUG_IMPLEMENTATION /* thr_debug.c */ +#undef ldap_pvt_thread_mutex_t +#undef ldap_pvt_thread_cond_t +#undef ldap_pvt_thread_sleep +#undef ldap_pvt_thread_get_concurrency +#undef ldap_pvt_thread_set_concurrency +#undef ldap_pvt_thread_create +#undef ldap_pvt_thread_exit +#undef ldap_pvt_thread_join +#undef ldap_pvt_thread_kill +#undef ldap_pvt_thread_yield +#undef ldap_pvt_thread_cond_init +#undef ldap_pvt_thread_cond_destroy +#undef ldap_pvt_thread_cond_signal +#undef ldap_pvt_thread_cond_broadcast +#undef ldap_pvt_thread_cond_wait +#undef ldap_pvt_thread_mutex_init +#undef ldap_pvt_thread_mutex_destroy +#undef ldap_pvt_thread_mutex_lock +#undef ldap_pvt_thread_mutex_trylock +#undef ldap_pvt_thread_mutex_unlock +#undef ldap_pvt_thread_self +/* LDAP_THREAD_RDWR_IMPLEMENTATION: */ +#undef ldap_pvt_thread_rdwr_t +#undef ldap_pvt_thread_rdwr_init +#undef ldap_pvt_thread_rdwr_destroy +#undef ldap_pvt_thread_rdwr_rlock +#undef ldap_pvt_thread_rdwr_rtrylock +#undef ldap_pvt_thread_rdwr_runlock +#undef ldap_pvt_thread_rdwr_wlock +#undef ldap_pvt_thread_rdwr_wtrylock +#undef ldap_pvt_thread_rdwr_wunlock +#undef ldap_pvt_thread_rdwr_readers +#undef ldap_pvt_thread_rdwr_writers +#undef ldap_pvt_thread_rdwr_active +/* LDAP_THREAD_POOL_IMPLEMENTATION: */ +#undef ldap_pvt_thread_pool_t +#undef ldap_pvt_thread_pool_init +#undef ldap_pvt_thread_pool_submit +#undef ldap_pvt_thread_pool_maxthreads +#undef ldap_pvt_thread_pool_backload +#undef ldap_pvt_thread_pool_pause +#undef ldap_pvt_thread_pool_resume +#undef ldap_pvt_thread_pool_destroy +#undef ldap_pvt_thread_pool_getkey +#undef ldap_pvt_thread_pool_setkey +#undef ldap_pvt_thread_pool_purgekey +#undef ldap_pvt_thread_pool_context +#undef ldap_pvt_thread_pool_context_reset +#endif /* LDAP_THREAD_DEBUG_IMPLEMENTATION */ + +#endif /* LDAP_THREAD_DEBUG */ diff --git a/libraries/libldap_r/rdwr.c b/libraries/libldap_r/rdwr.c index 5acf713e11..bbae423bc6 100644 --- a/libraries/libldap_r/rdwr.c +++ b/libraries/libldap_r/rdwr.c @@ -40,7 +40,9 @@ #include #include "ldap-int.h" -#include "ldap_pvt_thread.h" +#include "ldap_pvt_thread.h" /* Get the thread interface */ +#define LDAP_THREAD_RDWR_IMPLEMENTATION +#include "ldap_thr_debug.h" /* May rename the symbols defined below */ /* * implementations that provide their own compatible @@ -439,6 +441,6 @@ int ldap_pvt_thread_rdwr_active(ldap_pvt_thread_rdwr_t *rwlock) ldap_pvt_thread_rdwr_writers(rwlock)); } -#endif /* LDAP_DEBUG */ +#endif /* LDAP_RDWR_DEBUG */ #endif /* LDAP_THREAD_HAVE_RDWR */ diff --git a/libraries/libldap_r/thr_cthreads.c b/libraries/libldap_r/thr_cthreads.c index d81e0101b5..83ba5aeb50 100644 --- a/libraries/libldap_r/thr_cthreads.c +++ b/libraries/libldap_r/thr_cthreads.c @@ -20,7 +20,9 @@ #include "portable.h" #if defined( HAVE_MACH_CTHREADS ) -#include "ldap_pvt_thread.h" +#include "ldap_pvt_thread.h" /* Get the thread interface */ +#define LDAP_THREAD_IMPLEMENTATION +#include "ldap_thr_debug.h" /* May rename the symbols defined below */ int ldap_int_thread_initialize( void ) diff --git a/libraries/libldap_r/thr_debug.c b/libraries/libldap_r/thr_debug.c new file mode 100644 index 0000000000..cc69b067d9 --- /dev/null +++ b/libraries/libldap_r/thr_debug.c @@ -0,0 +1,1029 @@ +/* thr_debug.c - wrapper around the chosen thread wrapper, for debugging. */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 2005 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ + +/* + * This package provides three types of thread operation debugging: + * + * - Print error messages and abort() when thread operations fail: + * Operations on threads, mutexes, condition variables, rdwr locks. + * Some thread pool operations are also checked, but not those for + * which failure can happen in normal slapd operation. + * + * - Wrap those types except threads and pools in structs that + * contain a state variable or a pointer to dummy allocated memory, + * and check that on all operations. The dummy memory variant lets + * malloc debuggers see some incorrect use as memory leaks, access + * to freed memory, etc. + * + * - Print a count of leaked thread resources after cleanup. + * + * Compile-time (./configure) setup: Macros defined in CPPFLAGS. + * + * LDAP_THREAD_DEBUG or LDAP_THREAD_DEBUG=2 + * Enables debugging, but value & 2 turns off type wrapping. + * + * LDAP_UINTPTR_T=integer type to hold pointers, preferably unsigned. + * Used by dummy memory option "scramble". Default = unsigned long. + * + * In addition, you may need to set up an implementation-specific way + * to enable whatever error checking your thread library provides. + * Currently only implemented for Posix threads (pthreads), where + * you may need to define LDAP_INT_THREAD_MUTEXATTR. The default + * is PTHREAD_MUTEX_ERRORCHECK, or PTHREAD_MUTEX_ERRORCHECK_NP for + * Linux threads. See pthread_mutexattr_settype(3). + * + * Run-time configuration: Environment variable LDAP_THREAD_DEBUG. + * + * The variable may contain a comma- or space-separated option list. + * Options: + * off - Disable this package. + * Error checking: + * noabort - Do not abort() on errors. + * noerror - Do not report errors. Implies noabort. + * nocount - Do not report counts of unreleased resources. + * State variable/dummy memory, unless type wrapping is disabled: + * noalloc - Default. Use a state variable, not dummy memory. + * dupinit - Implies noalloc. Check if resources that have + * not been destroyed are reinitialized. Tools that + * report uninitialized memory access should disable + * such warnings about debug_already_initialized(). + * alloc - Allocate dummy memory and store pointers as-is. + * Malloc debuggers might not notice unreleased + * resources in global variables as memory leaks. + * scramble - Store bitwise complement of dummy memory pointer. + * That never escapes memory leak detectors - + * but detection while the program is running will + * report active resources as leaks. Do not + * use this if a garbage collector is in use:-) + * adjptr - Point to end of dummy memory. + * Purify reports these as "potential leaks" (PLK). + * I have not checked other malloc debuggers. + * Tracing: + * tracethreads - Report create/join/exit/kill of threads. + */ + +#include "portable.h" + +#if defined( LDAP_THREAD_DEBUG ) + +#include +#include +#include +#include + +#include "ldap_pvt_thread.h" /* Get the thread interface */ +#define LDAP_THREAD_IMPLEMENTATION +#define LDAP_THREAD_DEBUG_IMPLEMENTATION +#define LDAP_THREAD_RDWR_IMPLEMENTATION +#define LDAP_THREAD_POOL_IMPLEMENTATION +#include "ldap_thr_debug.h" /* Get the underlying implementation */ + + +/* Options from environment variable $LDAP_THREAD_DEBUG */ +enum { Count_no = 0, Count_yes, Count_reported, Count_reported_more }; +static int nodebug, noabort, noerror, count = Count_yes, options_done; +#ifdef LDAP_THREAD_DEBUG_WRAP +enum { Wrap_noalloc, Wrap_alloc, Wrap_scramble, Wrap_adjptr }; +static int dupinit, wraptype = Wrap_noalloc, wrap_offset, unwrap_offset; +#endif +static int tracethreads; + +static int threading_enabled; + +enum { + Idx_unexited_thread, Idx_unjoined_thread, Idx_locked_mutex, + Idx_mutex, Idx_cond, Idx_rdwr, Idx_tpool, Idx_max +}; +static int resource_counts[Idx_max]; +static const char *const resource_names[] = { + "unexited threads", "unjoined threads", "locked mutexes", + "mutexes", "conds", "rdwrs", "thread pools" +}; +static ldap_int_thread_mutex_t resource_mutexes[Idx_max]; + + +/* + * Making ldap_pvt_thread_t a wrapper around ldap_int_thread_t would + * slow down ldap_pvt_thread_self(), so keep a list of threads instead. + */ +typedef struct ldap_debug_thread_s { + ldap_pvt_thread_t wrapped; + ldap_debug_usage_info_t usage; + int detached; + int freeme, idx; +} ldap_debug_thread_t; + +static ldap_debug_thread_t **thread_info; +static unsigned int thread_info_size, thread_info_used; +static ldap_int_thread_mutex_t thread_info_mutex; + + +#define WARN(var, msg) (warn (__FILE__, __LINE__, (msg), #var, (var))) +#define ERROR(var,msg) (error(__FILE__, __LINE__, (msg), #var, (var))) +#define WARN_IF(rc, msg) {if (rc) warn (__FILE__, __LINE__, (msg), #rc, (rc));} +#define ERROR_IF(rc,msg) {if (rc) error(__FILE__, __LINE__, (msg), #rc, (rc));} + +#if 0 +static void +warn( const char *file, int line, const char *msg, const char *var, int val ) +{ + fprintf( stderr, "%s:%d: %s warning: %s is %d\n", + file, line, msg, var, val ); +} +#endif + +static void +error( const char *file, int line, const char *msg, const char *var, int val ) +{ + if( !noerror ) { + fprintf( stderr, "%s:%d: %s error: %s is %d\n", + file, line, msg, var, val ); + if( !noabort ) + abort(); + } +} + +static void +count_resource_leaks( void ) +{ + int i, j; + char errbuf[200], *delim = "Leaked"; + if( count == Count_yes ) { + count = Count_reported; +#if 0 /* Could break if there are still threads after atexit */ + for( i = j = 0; i < Idx_max; i++ ) + j |= ldap_int_thread_mutex_destroy( &resource_mutexes[i] ); + WARN_IF( j, "ldap_debug_thread_destroy:mutexes" ); +#endif + for( i = j = 0; i < Idx_max; i++ ) { + if( resource_counts[i] ) { + j += sprintf( errbuf + j, "%s %d %s", + delim, resource_counts[i], resource_names[i] ); + delim = ","; + } + } + if( j ) + fprintf( stderr, "%s:%d: %s.\n", __FILE__, __LINE__, errbuf ); + } +} + +static void +get_options( void ) +{ + static const struct option_info_s { + const char *name; + int *var, val; + } option_info[] = { + { "off", &nodebug, 1 }, + { "noabort", &noabort, 1 }, + { "noerror", &noerror, 1 }, + { "nocount", &count, Count_no }, +#ifdef LDAP_THREAD_DEBUG_WRAP + { "noalloc", &wraptype, Wrap_noalloc }, + { "dupinit", &dupinit, 1 }, + { "alloc", &wraptype, Wrap_alloc }, + { "adjptr", &wraptype, Wrap_adjptr }, + { "scramble", &wraptype, Wrap_scramble }, +#endif + { "tracethreads", &tracethreads, 1 }, + { NULL, NULL, 0 } + }; + const char *s = getenv( "LDAP_THREAD_DEBUG" ); + if( s != NULL ) { + while( *(s += strspn( s, ", \t\r\n" )) != '\0' ) { + size_t optlen = strcspn( s, ", \t\r\n" ); + const struct option_info_s *oi; + for( oi = option_info; oi->name; oi++ ) { + if( strncasecmp( oi->name, s, optlen ) == 0 ) { + if( oi->name && oi->name[optlen] == '\0' ) { + *oi->var = oi->val; + } else { + fprintf( stderr, "Unknown $%s option '%.*s'\n", + "LDAP_THREAD_DEBUG", (int) optlen, s ); + } + break; + } + } + s += optlen; + } + } + if( nodebug ) { + noabort = noerror = 1; + tracethreads = dupinit = 0; + count = Count_no; + } +#ifdef LDAP_THREAD_DEBUG_WRAP + if( nodebug || dupinit ) { + wraptype = Wrap_noalloc; + } else if( wraptype == Wrap_scramble ) { + const unsigned char *dummy = (const unsigned char *)&option_info; + if( sizeof(LDAP_UINTPTR_T) < sizeof(void *) + || (unsigned char *)~~(LDAP_UINTPTR_T) dummy != dummy + || (unsigned char *)~~(LDAP_UINTPTR_T) (unsigned char *)0 ) + { + fprintf( stderr, "Misconfigured for $%s %s. Using %s.\n", + "LDAP_THREAD_DEBUG", "scramble", "adjptr" ); + wraptype = Wrap_adjptr; + } + } + unwrap_offset = -(wrap_offset = (wraptype == Wrap_adjptr)); +#endif + options_done = 1; +} + + +static char * +thread_name( char *buf, int bufsize, ldap_pvt_thread_t thread ) +{ + int i; + --bufsize; + if( bufsize > 2*sizeof(thread) ) + bufsize = 2*sizeof(thread); + for( i = 0; i < bufsize; i += 2 ) + snprintf( buf+i, 3, "%02x", ((unsigned char *)&thread)[i/2] ); + return buf; +} + +static void +exit_thread_message( const ldap_pvt_thread_t thread ) +{ + if( tracethreads ) { + char buf[40]; + fprintf( stderr, "== Exiting thread %s ==\n", + thread_name( buf, sizeof(buf), thread ) ); + } +} + + +#ifndef LDAP_THREAD_DEBUG_WRAP + +#define WRAPPED(ptr) (ptr) +#define alloc_usage(ptr, msg) ((void) 0) +#define check_usage(ptr, msg) ((void) 0) +#define free_usage(ptr, msg) ((void) 0) + +#define with_threads_lock(statement) { statement; } +#define get_new_thread_info(msg) NULL +#define update_thread_info(ti, th, det) {} +#define remove_thread_info(ti, msg) ((void)0) +#define get_thread_info(thread, msg) NULL +#define exiting_thread(msg) exit_thread_message(ldap_pvt_thread_self()) + +#else /* LDAP_THREAD_DEBUG_WRAP */ + +#define WRAPPED(ptr) (&(ptr)->wrapped) + +#define INITED_VALUE 0x12345678UL +#define INITED_BYTE_VALUE 0xd5 + +static int +debug_already_initialized( const LDAP_UINTPTR_T *num ) +{ + /* Valid programs will access uninitialized memory if dupinit */ + return dupinit && *num == INITED_VALUE; +} + +static void +alloc_usage( ldap_debug_usage_info_t *usage, const char *msg ) +{ + if( !options_done ) + get_options(); + if( wraptype == Wrap_noalloc ) { + ERROR_IF( debug_already_initialized( &usage->num ), msg ); + usage->num = INITED_VALUE; + } else { + unsigned char *dummy = malloc( 1 ); + assert( dummy != NULL ); + *dummy = INITED_BYTE_VALUE; + if( wraptype == Wrap_scramble ) { + usage->num = ~(LDAP_UINTPTR_T) dummy; + assert( (unsigned char *)~usage->num == dummy ); + } else { + usage->ptr = dummy + wrap_offset; + } + } +} + +static void +check_usage( ldap_debug_usage_info_t *usage, const char *msg ) +{ + if( wraptype == Wrap_noalloc ) { + ERROR_IF( usage->num != INITED_VALUE, msg ); + } else if( wraptype == Wrap_scramble ) { + ERROR_IF( !usage->num, msg ); + ERROR_IF( *(unsigned char *)~usage->num != INITED_BYTE_VALUE, msg ); + } else { + ERROR_IF( !usage->ptr, msg ); + ERROR_IF( usage->ptr[unwrap_offset] != INITED_BYTE_VALUE, msg ); + } +} + +static void +free_usage( ldap_debug_usage_info_t *usage, const char *msg ) +{ + if( wraptype == Wrap_noalloc ) { + usage->num = ~(LDAP_UINTPTR_T)INITED_VALUE; + } else { + unsigned char *dummy = (wraptype == Wrap_scramble + ? (unsigned char *)~usage->num + : usage->ptr + unwrap_offset); + *(volatile unsigned char *)dummy = (unsigned char)-1; + free( dummy ); + } +} + +#define with_threads_lock(statement) { \ + if( !nodebug ) { \ + int rc_wtl_ = ldap_int_thread_mutex_lock( &thread_info_mutex ); \ + assert( rc_wtl_ == 0 ); \ + } \ + statement; \ + if( !nodebug ) { \ + int rc_wtl_ = ldap_int_thread_mutex_unlock( &thread_info_mutex ); \ + assert( rc_wtl_ == 0 ); \ + } \ +} + +static ldap_debug_thread_t * +get_new_thread_info( const char *msg ) +{ + if( nodebug ) + return NULL; + if( thread_info_used >= thread_info_size ) { + unsigned int more = thread_info_size + 1; /* debug value. increase. */ + unsigned int new_size = thread_info_size + more; + ldap_debug_thread_t *t = calloc( more, sizeof(ldap_debug_thread_t) ); + assert( t != NULL ); + t->freeme = 1; + thread_info = realloc( thread_info, new_size * sizeof(*thread_info) ); + assert( thread_info != NULL ); + while( thread_info_size < new_size ) { + t->idx = thread_info_size; + thread_info[thread_info_size++] = t++; + } + } + alloc_usage( &thread_info[thread_info_used]->usage, msg ); + return thread_info[thread_info_used++]; +} + +static void +update_thread_info( + ldap_debug_thread_t *t, + const ldap_pvt_thread_t *thread, + int detached ) +{ + if( !nodebug ) { + t->wrapped = *thread; + t->detached = detached; + } +} + +static void +remove_thread_info( ldap_debug_thread_t *t, const char *msg ) +{ + if( !nodebug ) { + ldap_debug_thread_t *last; + int idx; + free_usage( &t->usage, msg ); + idx = t->idx; + assert( thread_info[idx] == t ); + last = thread_info[--thread_info_used]; + assert( last->idx == thread_info_used ); + (thread_info[idx] = last)->idx = idx; + (thread_info[thread_info_used] = t )->idx = thread_info_used; + } +} + +ldap_debug_thread_t * +get_thread_info( ldap_pvt_thread_t *thread, const char *msg ) +{ + unsigned int i; + ldap_debug_thread_t *t; + if( nodebug ) + return NULL; + for( i = 0; i < thread_info_used; i++ ) { + if( ldap_pvt_thread_equal( *thread, thread_info[i]->wrapped ) ) + break; + } + ERROR_IF( i == thread_info_used, msg ); + t = thread_info[i]; + check_usage( &t->usage, msg ); + return t; +} + +static void +exiting_thread( const char *msg ) +{ + if( !nodebug ) { + ldap_pvt_thread_t thread; + thread = ldap_pvt_thread_self(); + exit_thread_message( thread ); + with_threads_lock({ + ldap_debug_thread_t *t = get_thread_info( &thread, msg ); + if( t->detached ) + remove_thread_info( t, msg ); + }); + } +} + +#endif /* LDAP_THREAD_DEBUG_WRAP */ + + +static void +adjust_count( int which, int adjust ) +{ + int rc; + switch( count ) { + case Count_no: + break; + case Count_yes: + rc = ldap_int_thread_mutex_lock( &resource_mutexes[which] ); + assert( rc == 0 ); + resource_counts[which] += adjust; + rc = ldap_int_thread_mutex_unlock( &resource_mutexes[which] ); + assert( rc == 0 ); + case Count_reported: + fputs( "...more ldap_debug_thread activity after exit...\n", stderr ); + count = Count_reported_more; + /* FALL THROUGH */ + case Count_reported_more: + /* Not used, but result might be inspected with debugger */ + /* (Hopefully threading is disabled by now...) */ + resource_counts[which] += adjust; + break; + } +} + + +/* Wrappers for LDAP_THREAD_IMPLEMENTATION: */ + +/* Used instead of ldap_int_thread_initialize by ldap_pvt_thread_initialize */ +int +ldap_debug_thread_initialize( void ) +{ + int i, rc, rc2; + if( !options_done ) + get_options(); + ERROR_IF( threading_enabled, "ldap_debug_thread_initialize" ); + threading_enabled = 1; + rc = ldap_int_thread_initialize(); + if( rc ) { + ERROR( rc, "ldap_debug_thread_initialize:threads" ); + threading_enabled = 0; + } else { + rc2 = ldap_int_thread_mutex_init( &thread_info_mutex ); + assert( rc2 == 0 ); + if( count != Count_no ) { + for( i = rc2 = 0; i < Idx_max; i++ ) + rc2 |= ldap_int_thread_mutex_init( &resource_mutexes[i] ); + assert( rc2 == 0 ); + /* FIXME: Only for static libldap_r as in init.c? If so, why? */ + atexit( count_resource_leaks ); + } + } + return rc; +} + +/* Used instead of ldap_int_thread_destroy by ldap_pvt_thread_destroy */ +int +ldap_debug_thread_destroy( void ) +{ + int rc; + ERROR_IF( !threading_enabled, "ldap_debug_thread_destroy" ); + /* sleep(1) -- need to wait for thread pool to finish? */ + rc = ldap_int_thread_destroy(); + if( rc ) { + ERROR( rc, "ldap_debug_thread_destroy:threads" ); + } else { + threading_enabled = 0; + } + return rc; +} + +int +ldap_pvt_thread_set_concurrency( int n ) +{ + int rc; + ERROR_IF( !threading_enabled, "ldap_pvt_thread_set_concurrency" ); + rc = ldap_int_thread_set_concurrency( n ); + ERROR_IF( rc, "ldap_pvt_thread_set_concurrency" ); + return rc; +} + +int +ldap_pvt_thread_get_concurrency( void ) +{ + int rc; + ERROR_IF( !threading_enabled, "ldap_pvt_thread_get_concurrency" ); + rc = ldap_int_thread_get_concurrency(); + ERROR_IF( rc, "ldap_pvt_thread_get_concurrency" ); + return rc; +} + +unsigned int +ldap_pvt_thread_sleep( unsigned int interval ) +{ + int rc; + ERROR_IF( !threading_enabled, "ldap_pvt_thread_sleep" ); + rc = ldap_int_thread_sleep( interval ); + ERROR_IF( rc, "ldap_pvt_thread_sleep" ); + return 0; +} + +int +ldap_pvt_thread_create( + ldap_pvt_thread_t *thread, + int detach, + void *(*start_routine)( void * ), + void *arg ) +{ + int rc; + ERROR_IF( !threading_enabled, "ldap_pvt_thread_create" ); + if( !options_done ) + get_options(); + with_threads_lock({ + ldap_debug_thread_t *t; + t = get_new_thread_info( "ldap_pvt_thread_create" ); + rc = ldap_int_thread_create( thread, detach, start_routine, arg ); + if( rc ) { + ERROR( rc, "ldap_pvt_thread_create" ); + remove_thread_info( t, "ldap_pvt_thread_init" ); + } else { + update_thread_info( t, thread, detach ); + } + }); + if( rc == 0 ) { + if( tracethreads ) { + char buf[40]; + fprintf( stderr, "== Created thread %s%s ==\n", + thread_name( buf, sizeof(buf), *thread ), + detach ? " (detached)" : "" ); + } + adjust_count( Idx_unexited_thread, +1 ); + if( !detach ) + adjust_count( Idx_unjoined_thread, +1 ); + } + return rc; +} + +void +ldap_pvt_thread_exit( void *retval ) +{ + ERROR_IF( !threading_enabled, "ldap_pvt_thread_exit" ); + adjust_count( Idx_unexited_thread, -1 ); + exiting_thread( "ldap_pvt_thread_exit" ); + ldap_int_thread_exit( retval ); +} + +int +ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return ) +{ + int rc; + ldap_debug_thread_t *t; + ERROR_IF( !threading_enabled, "ldap_pvt_thread_join" ); + if( tracethreads ) { + char buf[40]; + fprintf( stderr, "== Joining thread %s ==\n", + thread_name( buf, sizeof(buf), thread ) ); + } + with_threads_lock( + t = get_thread_info( &thread, "ldap_pvt_thread_join" ) ); + rc = ldap_int_thread_join( thread, thread_return ); + if( rc ) { + ERROR( rc, "ldap_pvt_thread_join" ); + } else { + with_threads_lock( + remove_thread_info( t, "ldap_pvt_thread_join" ) ); + adjust_count( Idx_unjoined_thread, -1 ); + } + return rc; +} + +int +ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo ) +{ + int rc; + ERROR_IF( !threading_enabled, "ldap_pvt_thread_kill" ); + if( tracethreads ) { + char buf[40]; + fprintf( stderr, "== Killing thread %s (sig %i) ==\n", + thread_name( buf, sizeof(buf), thread ), signo ); + } + rc = ldap_int_thread_kill( thread, signo ); + ERROR_IF( rc, "ldap_pvt_thread_kill" ); + return rc; +} + +int +ldap_pvt_thread_yield( void ) +{ + int rc; + ERROR_IF( !threading_enabled, "ldap_pvt_thread_yield" ); + rc = ldap_int_thread_yield(); + ERROR_IF( rc, "ldap_pvt_thread_yield" ); + return rc; +} + +ldap_pvt_thread_t +ldap_pvt_thread_self( void ) +{ +#if 0 /* Function is used by ch_free() via slap_sl_contxt() in slapd */ + ERROR_IF( !threading_enabled, "ldap_pvt_thread_self" ); +#endif + return ldap_int_thread_self(); +} + +int +ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond ) +{ + int rc; + alloc_usage( &cond->usage, "ldap_pvt_thread_cond_init" ); + rc = ldap_int_thread_cond_init( WRAPPED( cond ) ); + if( rc ) { + ERROR( rc, "ldap_pvt_thread_cond_init" ); + free_usage( &cond->usage, "ldap_pvt_thread_cond_init" ); + } else { + adjust_count( Idx_cond, +1 ); + } + return rc; +} + +int +ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cond ) +{ + int rc; + check_usage( &cond->usage, "ldap_pvt_thread_cond_destroy" ); + rc = ldap_int_thread_cond_destroy( WRAPPED( cond ) ); + if( rc ) { + ERROR( rc, "ldap_pvt_thread_cond_destroy" ); + } else { + free_usage( &cond->usage, "ldap_pvt_thread_cond_destroy" ); + adjust_count( Idx_cond, -1 ); + } + return rc; +} + +int +ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond ) +{ + int rc; + check_usage( &cond->usage, "ldap_pvt_thread_cond_signal" ); + rc = ldap_int_thread_cond_signal( WRAPPED( cond ) ); + ERROR_IF( rc, "ldap_pvt_thread_cond_signal" ); + return rc; +} + +int +ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond ) +{ + int rc; + check_usage( &cond->usage, "ldap_pvt_thread_cond_broadcast" ); + rc = ldap_int_thread_cond_broadcast( WRAPPED( cond ) ); + ERROR_IF( rc, "ldap_pvt_thread_cond_broadcast" ); + return rc; +} + +int +ldap_pvt_thread_cond_wait( + ldap_pvt_thread_cond_t *cond, + ldap_pvt_thread_mutex_t *mutex ) +{ + int rc; + check_usage( &cond->usage, "ldap_pvt_thread_cond_wait:cond" ); + check_usage( &mutex->usage, "ldap_pvt_thread_cond_wait:mutex" ); + adjust_count( Idx_locked_mutex, -1 ); + rc = ldap_int_thread_cond_wait( WRAPPED( cond ), WRAPPED( mutex ) ); + adjust_count( Idx_locked_mutex, +1 ); + ERROR_IF( rc, "ldap_pvt_thread_cond_wait" ); + return rc; +} + +int +ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex ) +{ + int rc; + alloc_usage( &mutex->usage, "ldap_pvt_thread_mutex_init" ); + rc = ldap_int_thread_mutex_init( WRAPPED( mutex ) ); + if( rc ) { + ERROR( rc, "ldap_pvt_thread_mutex_init" ); + free_usage( &mutex->usage, "ldap_pvt_thread_mutex_init" ); + } else { + adjust_count( Idx_mutex, +1 ); + } + return rc; +} + +int +ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex ) +{ + int rc; + check_usage( &mutex->usage, "ldap_pvt_thread_mutex_destroy" ); + rc = ldap_int_thread_mutex_destroy( WRAPPED( mutex ) ); + if( rc ) { + ERROR( rc, "ldap_pvt_thread_mutex_destroy" ); + } else { + free_usage( &mutex->usage, "ldap_pvt_thread_mutex_destroy" ); + adjust_count( Idx_mutex, -1 ); + } + return rc; +} + +int +ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex ) +{ + int rc; + check_usage( &mutex->usage, "ldap_pvt_thread_mutex_lock" ); + rc = ldap_int_thread_mutex_lock( WRAPPED( mutex ) ); + if( rc ) { + ERROR_IF( rc, "ldap_pvt_thread_mutex_lock" ); + } else { + adjust_count( Idx_locked_mutex, +1 ); + } + return rc; +} + +int +ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mutex ) +{ + int rc; + check_usage( &mutex->usage, "ldap_pvt_thread_mutex_trylock" ); + rc = ldap_int_thread_mutex_trylock( WRAPPED( mutex ) ); + if( rc == 0 ) + adjust_count( Idx_locked_mutex, +1 ); + return rc; +} + +int +ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex ) +{ + int rc; + check_usage( &mutex->usage, "ldap_pvt_thread_mutex_unlock" ); + rc = ldap_int_thread_mutex_unlock( WRAPPED( mutex ) ); + if( rc ) { + ERROR_IF( rc, "ldap_pvt_thread_mutex_unlock" ); + } else { + adjust_count( Idx_locked_mutex, -1 ); + } + return rc; +} + + +/* Wrappers for LDAP_THREAD_RDWR_IMPLEMENTATION: */ + +int +ldap_pvt_thread_rdwr_init( ldap_pvt_thread_rdwr_t *rwlock ) +{ + int rc; + alloc_usage( &rwlock->usage, "ldap_pvt_thread_rdwr_init" ); + rc = ldap_int_thread_rdwr_init( WRAPPED( rwlock ) ); + if( rc ) { + ERROR( rc, "ldap_pvt_thread_rdwr_init" ); + free_usage( &rwlock->usage, "ldap_pvt_thread_rdwr_init" ); + } else { + adjust_count( Idx_rdwr, +1 ); + } + return rc; +} + +int +ldap_pvt_thread_rdwr_destroy( ldap_pvt_thread_rdwr_t *rwlock ) +{ + int rc; + check_usage( &rwlock->usage, "ldap_pvt_thread_rdwr_destroy" ); + rc = ldap_int_thread_rdwr_destroy( WRAPPED( rwlock ) ); + if( rc ) { + ERROR( rc, "ldap_pvt_thread_rdwr_destroy" ); + } else { + free_usage( &rwlock->usage, "ldap_pvt_thread_rdwr_destroy" ); + adjust_count( Idx_rdwr, -1 ); + } + return rc; +} + +int +ldap_pvt_thread_rdwr_rlock( ldap_pvt_thread_rdwr_t *rwlock ) +{ + int rc; + check_usage( &rwlock->usage, "ldap_pvt_thread_rdwr_rlock" ); + rc = ldap_int_thread_rdwr_rlock( WRAPPED( rwlock ) ); + ERROR_IF( rc, "ldap_pvt_thread_rdwr_rlock" ); + return rc; +} + +int +ldap_pvt_thread_rdwr_rtrylock( ldap_pvt_thread_rdwr_t *rwlock ) +{ + check_usage( &rwlock->usage, "ldap_pvt_thread_rdwr_rtrylock" ); + return ldap_int_thread_rdwr_rtrylock( WRAPPED( rwlock ) ); +} + +int +ldap_pvt_thread_rdwr_runlock( ldap_pvt_thread_rdwr_t *rwlock ) +{ + int rc; + check_usage( &rwlock->usage, "ldap_pvt_thread_rdwr_runlock" ); + rc = ldap_int_thread_rdwr_runlock( WRAPPED( rwlock ) ); + ERROR_IF( rc, "ldap_pvt_thread_rdwr_runlock" ); + return rc; +} + +int +ldap_pvt_thread_rdwr_wlock( ldap_pvt_thread_rdwr_t *rwlock ) +{ + int rc; + check_usage( &rwlock->usage, "ldap_pvt_thread_rdwr_wlock" ); + rc = ldap_int_thread_rdwr_wlock( WRAPPED( rwlock ) ); + ERROR_IF( rc, "ldap_pvt_thread_rdwr_wlock" ); + return rc; +} + +int +ldap_pvt_thread_rdwr_wtrylock( ldap_pvt_thread_rdwr_t *rwlock ) +{ + check_usage( &rwlock->usage, "ldap_pvt_thread_rdwr_wtrylock" ); + return ldap_int_thread_rdwr_wtrylock( WRAPPED( rwlock ) ); +} + +int +ldap_pvt_thread_rdwr_wunlock( ldap_pvt_thread_rdwr_t *rwlock ) +{ + int rc; + check_usage( &rwlock->usage, "ldap_pvt_thread_rdwr_wunlock" ); + rc = ldap_int_thread_rdwr_wunlock( WRAPPED( rwlock ) ); + ERROR_IF( rc, "ldap_pvt_thread_rdwr_wunlock" ); + return rc; +} + +#ifdef LDAP_RDWR_DEBUG + +int +ldap_pvt_thread_rdwr_readers( ldap_pvt_thread_rdwr_t *rwlock ) +{ + check_usage( &rwlock->usage, "ldap_pvt_thread_rdwr_readers" ); + return ldap_int_thread_rdwr_readers( WRAPPED( rwlock ) ); +} + +int +ldap_pvt_thread_rdwr_writers( ldap_pvt_thread_rdwr_t *rwlock ) +{ + check_usage( &rwlock->usage, "ldap_pvt_thread_rdwr_writers" ); + return ldap_int_thread_rdwr_writers( WRAPPED( rwlock ) ); +} + +int +ldap_pvt_thread_rdwr_active( ldap_pvt_thread_rdwr_t *rwlock ) +{ + check_usage( &rwlock->usage, "ldap_pvt_thread_rdwr_active" ); + return ldap_int_thread_rdwr_active( WRAPPED( rwlock ) ); +} + +#endif /* LDAP_RDWR_DEBUG */ + + +/* Some wrappers for LDAP_THREAD_POOL_IMPLEMENTATION: */ +#ifdef LDAP_THREAD_POOL_IMPLEMENTATION + +int +ldap_pvt_thread_pool_init( + ldap_pvt_thread_pool_t *tpool, + int max_threads, + int max_pending ) +{ + int rc; + ERROR_IF( !threading_enabled, "ldap_pvt_thread_pool_init" ); + rc = ldap_int_thread_pool_init( tpool, max_threads, max_pending ); + if( rc ) { + ERROR( rc, "ldap_pvt_thread_pool_init" ); + } else { + adjust_count( Idx_tpool, +1 ); + } + return rc; +} + +int +ldap_pvt_thread_pool_submit( + ldap_pvt_thread_pool_t *tpool, + ldap_pvt_thread_start_t *start_routine, void *arg ) +{ + int rc, has_pool; + ERROR_IF( !threading_enabled, "ldap_pvt_thread_pool_submit" ); + has_pool = (tpool != NULL && *tpool != NULL); + rc = ldap_int_thread_pool_submit( tpool, start_routine, arg ); + if( has_pool ) + ERROR_IF( rc, "ldap_pvt_thread_pool_submit" ); + return rc; +} + +int +ldap_pvt_thread_pool_maxthreads( + ldap_pvt_thread_pool_t *tpool, + int max_threads ) +{ + ERROR_IF( !threading_enabled, "ldap_pvt_thread_pool_maxthreads" ); + return ldap_int_thread_pool_maxthreads( tpool, max_threads ); +} + +int +ldap_pvt_thread_pool_backload( ldap_pvt_thread_pool_t *tpool ) +{ + ERROR_IF( !threading_enabled, "ldap_pvt_thread_pool_backload" ); + return ldap_int_thread_pool_backload( tpool ); +} + +int +ldap_pvt_thread_pool_destroy( ldap_pvt_thread_pool_t *tpool, int run_pending ) +{ + int rc, has_pool; + ERROR_IF( !threading_enabled, "ldap_pvt_thread_pool_destroy" ); + has_pool = (tpool != NULL && *tpool != NULL); + rc = ldap_int_thread_pool_destroy( tpool, run_pending ); + if( has_pool ) { + if( rc ) { + ERROR( rc, "ldap_pvt_thread_pool_destroy" ); + } else { + adjust_count( Idx_tpool, -1 ); + } + } + return rc; +} + +int +ldap_pvt_thread_pool_pause( ldap_pvt_thread_pool_t *tpool ) +{ + ERROR_IF( !threading_enabled, "ldap_pvt_thread_pool_pause" ); + return ldap_int_thread_pool_pause( tpool ); +} + +int +ldap_pvt_thread_pool_resume( ldap_pvt_thread_pool_t *tpool ) +{ + ERROR_IF( !threading_enabled, "ldap_pvt_thread_pool_resume" ); + return ldap_int_thread_pool_resume( tpool ); +} + +int +ldap_pvt_thread_pool_getkey( + void *xctx, + void *key, + void **data, + ldap_pvt_thread_pool_keyfree_t **kfree ) +{ +#if 0 /* Function is used by ch_free() via slap_sl_contxt() in slapd */ + ERROR_IF( !threading_enabled, "ldap_pvt_thread_pool_getkey" ); +#endif + return ldap_int_thread_pool_getkey( xctx, key, data, kfree ); +} + +int +ldap_pvt_thread_pool_setkey( + void *xctx, + void *key, + void *data, + ldap_pvt_thread_pool_keyfree_t *kfree ) +{ + int rc; + ERROR_IF( !threading_enabled, "ldap_pvt_thread_pool_setkey" ); + rc = ldap_int_thread_pool_setkey( xctx, key, data, kfree ); + ERROR_IF( rc, "ldap_pvt_thread_pool_setkey" ); + return rc; +} + +void +ldap_pvt_thread_pool_purgekey( void *key ) +{ + ERROR_IF( !threading_enabled, "ldap_pvt_thread_pool_purgekey" ); + ldap_int_thread_pool_purgekey( key ); +} + +void * +ldap_pvt_thread_pool_context( void ) +{ +#if 0 /* Function is used by ch_free() via slap_sl_contxt() in slapd */ + ERROR_IF( !threading_enabled, "ldap_pvt_thread_pool_context" ); +#endif + return ldap_int_thread_pool_context(); +} + +void +ldap_pvt_thread_pool_context_reset( void *vctx ) +{ + ERROR_IF( !threading_enabled, "ldap_pvt_thread_pool_context_reset" ); + ldap_int_thread_pool_context_reset( vctx ); +} + +#endif /* LDAP_THREAD_POOL_IMPLEMENTATION */ + +#endif /* LDAP_THREAD_DEBUG */ diff --git a/libraries/libldap_r/thr_lwp.c b/libraries/libldap_r/thr_lwp.c index 6d66e39136..be72e98976 100644 --- a/libraries/libldap_r/thr_lwp.c +++ b/libraries/libldap_r/thr_lwp.c @@ -38,7 +38,9 @@ #include "ldap-int.h" -#include "ldap_pvt_thread.h" +#include "ldap_pvt_thread.h" /* Get the thread interface */ +#define LDAP_THREAD_IMPLEMENTATION +#include "ldap_thr_debug.h" /* May rename the symbols defined below */ #include #include @@ -67,7 +69,7 @@ ldap_int_thread_initialize( void ) int ldap_int_thread_destroy( void ) { - /* need to destory lwp_scheduler thread and clean up private + /* need to destroy lwp_scheduler thread and clean up private variables */ return 0; } @@ -311,7 +313,7 @@ ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond ) int ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond, - ldap_int_thread_mutex_t *mutex ) + ldap_pvt_thread_mutex_t *mutex ) { if ( ! cond->lcv_created ) { cv_create( &cond->lcv_cv, *mutex ); diff --git a/libraries/libldap_r/thr_nt.c b/libraries/libldap_r/thr_nt.c index 24a7a8d4ae..8953f4bdaf 100644 --- a/libraries/libldap_r/thr_nt.c +++ b/libraries/libldap_r/thr_nt.c @@ -18,7 +18,9 @@ #if defined( HAVE_NT_THREADS ) -#include "ldap_pvt_thread.h" +#include "ldap_pvt_thread.h" /* Get the thread interface */ +#define LDAP_THREAD_IMPLEMENTATION +#include "ldap_thr_debug.h" /* May rename the symbols defined below */ typedef struct ldap_int_thread_s { long tid; diff --git a/libraries/libldap_r/thr_posix.c b/libraries/libldap_r/thr_posix.c index 0d353206fa..cb964d982d 100644 --- a/libraries/libldap_r/thr_posix.c +++ b/libraries/libldap_r/thr_posix.c @@ -20,8 +20,10 @@ #include -#include "ldap_pvt_thread.h" - +#include "ldap_pvt_thread.h" /* Get the thread interface */ +#define LDAP_THREAD_IMPLEMENTATION +#define LDAP_THREAD_RDWR_IMPLEMENTATION +#include "ldap_thr_debug.h" /* May rename the symbols defined below */ #if HAVE_PTHREADS < 6 # define LDAP_INT_THREAD_ATTR_DEFAULT pthread_attr_default @@ -30,13 +32,29 @@ #else # define LDAP_INT_THREAD_ATTR_DEFAULT NULL # define LDAP_INT_THREAD_CONDATTR_DEFAULT NULL -# define LDAP_INT_THREAD_MUTEXATTR_DEFAULT NULL +# define LDAP_INT_THREAD_MUTEXATTR_DEFAULT NULL #endif +#ifdef LDAP_THREAD_DEBUG +# if defined LDAP_INT_THREAD_MUTEXATTR /* May be defined in CPPFLAGS */ +# elif defined HAVE_PTHREAD_KILL_OTHER_THREADS_NP + /* LinuxThreads hack */ +# define LDAP_INT_THREAD_MUTEXATTR PTHREAD_MUTEX_ERRORCHECK_NP +# else +# define LDAP_INT_THREAD_MUTEXATTR PTHREAD_MUTEX_ERRORCHECK +# endif +static pthread_mutexattr_t mutex_attr; +# undef LDAP_INT_THREAD_MUTEXATTR_DEFAULT +# define LDAP_INT_THREAD_MUTEXATTR_DEFAULT &mutex_attr +#endif int ldap_int_thread_initialize( void ) { +#ifdef LDAP_INT_THREAD_MUTEXATTR + pthread_mutexattr_init( &mutex_attr ); + pthread_mutexattr_settype( &mutex_attr, LDAP_INT_THREAD_MUTEXATTR ); +#endif return 0; } @@ -46,6 +64,9 @@ ldap_int_thread_destroy( void ) #ifdef HAVE_PTHREAD_KILL_OTHER_THREADS_NP /* LinuxThreads: kill clones */ pthread_kill_other_threads_np(); +#endif +#ifdef LDAP_INT_THREAD_MUTEXATTR + pthread_mutexattr_destroy( &mutex_attr ); #endif return 0; } @@ -407,7 +428,7 @@ int ldap_pvt_thread_rdwr_wunlock( ldap_pvt_thread_rdwr_t *rw ) #endif } -#endif /* HAVE_PTHREAD_RDLOCK_DESTROY */ +#endif /* HAVE_PTHREAD_RWLOCK_DESTROY */ #endif /* LDAP_THREAD_HAVE_RDWR */ #endif /* HAVE_PTHREADS */ diff --git a/libraries/libldap_r/thr_pth.c b/libraries/libldap_r/thr_pth.c index 9b413ebd15..2d6012ba96 100644 --- a/libraries/libldap_r/thr_pth.c +++ b/libraries/libldap_r/thr_pth.c @@ -18,7 +18,11 @@ #if defined( HAVE_GNU_PTH ) -#include "ldap_pvt_thread.h" +#include "ldap_pvt_thread.h" /* Get the thread interface */ +#define LDAP_THREAD_IMPLEMENTATION +#define LDAP_THREAD_RDWR_IMPLEMENTATION +#include "ldap_thr_debug.h" /* May rename the symbols defined below */ + #include /******************* diff --git a/libraries/libldap_r/thr_stub.c b/libraries/libldap_r/thr_stub.c index ee65e67790..c4db69659a 100644 --- a/libraries/libldap_r/thr_stub.c +++ b/libraries/libldap_r/thr_stub.c @@ -18,7 +18,10 @@ #if defined( NO_THREADS ) -#include "ldap_pvt_thread.h" +#include "ldap_pvt_thread.h" /* Get the thread interface */ +#define LDAP_THREAD_IMPLEMENTATION +#define LDAP_THREAD_POOL_IMPLEMENTATION +#include "ldap_thr_debug.h" /* May rename the symbols defined below */ /*********************************************************************** * * @@ -216,6 +219,10 @@ void *ldap_pvt_thread_pool_context( ) return(NULL); } +void ldap_pvt_thread_pool_context_reset( void *vctx ) +{ +} + ldap_pvt_thread_t ldap_pvt_thread_self( void ) { diff --git a/libraries/libldap_r/thr_thr.c b/libraries/libldap_r/thr_thr.c index e609365447..edbd78a349 100644 --- a/libraries/libldap_r/thr_thr.c +++ b/libraries/libldap_r/thr_thr.c @@ -18,7 +18,9 @@ #if defined( HAVE_THR ) -#include "ldap_pvt_thread.h" +#include "ldap_pvt_thread.h" /* Get the thread interface */ +#define LDAP_THREAD_IMPLEMENTATION +#include "ldap_thr_debug.h" /* May rename the symbols defined below */ /******************* * * diff --git a/libraries/libldap_r/threads.c b/libraries/libldap_r/threads.c index d19400b971..e2ae4e5211 100644 --- a/libraries/libldap_r/threads.c +++ b/libraries/libldap_r/threads.c @@ -22,7 +22,8 @@ #include #include -#include "ldap_pvt_thread.h" +#include "ldap_pvt_thread.h" /* Get the thread interface */ +#include "ldap_thr_debug.h" /* May redirect thread initialize/destroy calls */ /* @@ -60,6 +61,15 @@ int ldap_pvt_thread_destroy( void ) return ldap_int_thread_destroy(); } + +/* + * Default implementations of some LDAP thread routines + */ + +#define LDAP_THREAD_IMPLEMENTATION +#include "ldap_thr_debug.h" /* May rename the symbols defined below */ + + #ifndef LDAP_THREAD_HAVE_GETCONCURRENCY int ldap_pvt_thread_get_concurrency ( void ) diff --git a/libraries/libldap_r/tpool.c b/libraries/libldap_r/tpool.c index d65d9c40b6..ba87eaa989 100644 --- a/libraries/libldap_r/tpool.c +++ b/libraries/libldap_r/tpool.c @@ -24,8 +24,10 @@ #include #include "ldap-int.h" -#include "ldap_pvt_thread.h" +#include "ldap_pvt_thread.h" /* Get the thread interface */ #include "ldap_queue.h" +#define LDAP_THREAD_POOL_IMPLEMENTATION +#include "ldap_thr_debug.h" /* May rename symbols defined below */ #ifndef LDAP_THREAD_HAVE_TPOOL @@ -50,11 +52,6 @@ typedef struct ldap_int_thread_key_s { static ldap_pvt_thread_t tid_zero; -#ifdef HAVE_PTHREADS -#define TID_EQ(a,b) pthread_equal((a),(b)) -#else -#define TID_EQ(a,b) ((a) == (b)) -#endif static struct { ldap_pvt_thread_t id; ldap_int_thread_key_t *ctx; @@ -115,7 +112,7 @@ ldap_int_thread_pool_shutdown ( void ) while ((pool = LDAP_STAILQ_FIRST(&ldap_int_thread_pool_list)) != NULL) { LDAP_STAILQ_REMOVE_HEAD(&ldap_int_thread_pool_list, ltp_next); - ldap_pvt_thread_pool_destroy( &pool, 0); + (ldap_pvt_thread_pool_destroy)(&pool, 0); /* ignore thr_debug macro */ } ldap_pvt_thread_mutex_destroy(&ldap_pvt_thread_pool_mutex); return(0); @@ -277,7 +274,7 @@ ldap_pvt_thread_pool_submit ( */ TID_HASH(thr, hash); for (rc = hash & (LDAP_MAXTHR-1); - !TID_EQ(thread_keys[rc].id, tid_zero); + !ldap_pvt_thread_equal(thread_keys[rc].id, tid_zero); rc = (rc+1) & (LDAP_MAXTHR-1)); thread_keys[rc].id = thr; } else { @@ -437,7 +434,8 @@ ldap_int_thread_pool_wrapper ( /* store pointer to our keys */ TID_HASH(tid, hash); - for (i = hash & (LDAP_MAXTHR-1); !TID_EQ(thread_keys[i].id, tid); + for (i = hash & (LDAP_MAXTHR-1); + !ldap_pvt_thread_equal(thread_keys[i].id, tid); i = (i+1) & (LDAP_MAXTHR-1)); thread_keys[i].ctx = ltc_key; keyslot = i; @@ -661,12 +659,14 @@ void *ldap_pvt_thread_pool_context( ) int i, hash; tid = ldap_pvt_thread_self(); - if ( TID_EQ( tid, ldap_int_main_tid )) + if ( ldap_pvt_thread_equal( tid, ldap_int_main_tid )) return ldap_int_main_thrctx; TID_HASH( tid, hash ); - for (i = hash & (LDAP_MAXTHR-1); !TID_EQ(thread_keys[i].id, tid_zero) && - !TID_EQ(thread_keys[i].id, tid); i = (i+1) & (LDAP_MAXTHR-1)); + for (i = hash & (LDAP_MAXTHR-1); + !ldap_pvt_thread_equal(thread_keys[i].id, tid_zero) && + !ldap_pvt_thread_equal(thread_keys[i].id, tid); + i = (i+1) & (LDAP_MAXTHR-1)); return thread_keys[i].ctx; } diff --git a/libraries/liblunicode/Makefile.in b/libraries/liblunicode/Makefile.in index 48c95a54ce..59b5cae7c5 100644 --- a/libraries/liblunicode/Makefile.in +++ b/libraries/liblunicode/Makefile.in @@ -43,7 +43,7 @@ ucgendat: $(XLIBS) ucgendat.o done touch .links -$(XXSRCS) : .links +$(XXSRCS) $(XXHEADERS) : .links clean-local: FORCE @$(RM) *.dat .links $(XXHEADERS) ucgendat diff --git a/libraries/liblunicode/ucdata/ucgendat.c b/libraries/liblunicode/ucdata/ucgendat.c index 91f5bc9186..297d146ad6 100644 --- a/libraries/liblunicode/ucdata/ucgendat.c +++ b/libraries/liblunicode/ucdata/ucgendat.c @@ -38,6 +38,7 @@ #include "ldap_config.h" #include +#include #include #include #include @@ -1223,7 +1224,7 @@ read_compexdata(FILE *in) */ for (s = line, i = code = 0; *s != '#' && i < 6; i++, s++) { - if (isspace(*s)) break; + if (isspace((unsigned char)*s)) break; code <<= 4; if (*s >= '0' && *s <= '9') code += *s - '0'; @@ -1268,8 +1269,9 @@ write_case(FILE *out, _case_t *tab, int num, int first) for (i=0; i 0) @@ -1491,8 +1495,8 @@ write_cdata(char *opath) create_comps(); #if HARDCODE_DATA - fprintf(out, PREF "ac_uint4 _uccomp_size = %d;\n\n", - comps_used * 4); + fprintf(out, PREF "ac_uint4 _uccomp_size = %ld;\n\n", + comps_used * 4L); fprintf(out, PREF "ac_uint4 _uccomp_data[] = {"); @@ -1502,8 +1506,9 @@ write_cdata(char *opath) if (comps_used > 0) { for (i=0; iavl_left == NULL ) {\ - (void) fputs("RR error\n", stderr); exit( EXIT_FAILURE ); \ - }\ - tmp = (*(x))->avl_left;\ - (*(x))->avl_left = tmp->avl_right;\ - tmp->avl_right = *(x);\ - *(x) = tmp;\ -} -#define ROTATELEFT(x) { \ - Avlnode *tmp;\ - if ( *(x) == NULL || (*(x))->avl_right == NULL ) {\ - (void) fputs("RL error\n", stderr); exit( EXIT_FAILURE ); \ - }\ - tmp = (*(x))->avl_right;\ - (*(x))->avl_right = tmp->avl_left;\ - tmp->avl_left = *(x);\ - *(x) = tmp;\ -} - -/* - * ravl_insert - called from avl_insert() to do a recursive insert into - * and balance of an avl tree. - */ - -static int -ravl_insert( - Avlnode **iroot, - void* data, - int *taller, - AVL_CMP fcmp, /* comparison function */ - AVL_DUP fdup, /* function to call for duplicates */ - int depth -) -{ - int rc, cmp, tallersub; - Avlnode *l, *r; - - if ( *iroot == 0 ) { - if ( (*iroot = (Avlnode *) ber_memalloc( sizeof( Avlnode ) )) - == NULL ) { - return( -1 ); - } - (*iroot)->avl_left = 0; - (*iroot)->avl_right = 0; - (*iroot)->avl_bf = 0; - (*iroot)->avl_data = data; - *taller = 1; - return( 0 ); - } - - cmp = (*fcmp)( data, (*iroot)->avl_data ); - - /* equal - duplicate name */ - if ( cmp == 0 ) { - *taller = 0; - return( (*fdup)( (*iroot)->avl_data, data ) ); - } - - /* go right */ - else if ( cmp > 0 ) { - rc = ravl_insert( &((*iroot)->avl_right), data, &tallersub, - fcmp, fdup, depth ); - if ( tallersub ) - switch ( (*iroot)->avl_bf ) { - case LH : /* left high - balance is restored */ - (*iroot)->avl_bf = EH; - *taller = 0; - break; - case EH : /* equal height - now right heavy */ - (*iroot)->avl_bf = RH; - *taller = 1; - break; - case RH : /* right heavy to start - right balance */ - r = (*iroot)->avl_right; - switch ( r->avl_bf ) { - case LH : /* double rotation left */ - l = r->avl_left; - switch ( l->avl_bf ) { - case LH : (*iroot)->avl_bf = EH; - r->avl_bf = RH; - break; - case EH : (*iroot)->avl_bf = EH; - r->avl_bf = EH; - break; - case RH : (*iroot)->avl_bf = LH; - r->avl_bf = EH; - break; - } - l->avl_bf = EH; - ROTATERIGHT( (&r) ) - (*iroot)->avl_right = r; - ROTATELEFT( iroot ) - *taller = 0; - break; - case EH : /* This should never happen */ - break; - case RH : /* single rotation left */ - (*iroot)->avl_bf = EH; - r->avl_bf = EH; - ROTATELEFT( iroot ) - *taller = 0; - break; - } - break; - } - else - *taller = 0; - } - - /* go left */ - else { - rc = ravl_insert( &((*iroot)->avl_left), data, &tallersub, - fcmp, fdup, depth ); - if ( tallersub ) - switch ( (*iroot)->avl_bf ) { - case LH : /* left high to start - left balance */ - l = (*iroot)->avl_left; - switch ( l->avl_bf ) { - case LH : /* single rotation right */ - (*iroot)->avl_bf = EH; - l->avl_bf = EH; - ROTATERIGHT( iroot ) - *taller = 0; - break; - case EH : /* this should never happen */ - break; - case RH : /* double rotation right */ - r = l->avl_right; - switch ( r->avl_bf ) { - case LH : (*iroot)->avl_bf = RH; - l->avl_bf = EH; - break; - case EH : (*iroot)->avl_bf = EH; - l->avl_bf = EH; - break; - case RH : (*iroot)->avl_bf = EH; - l->avl_bf = LH; - break; - } - r->avl_bf = EH; - ROTATELEFT( (&l) ) - (*iroot)->avl_left = l; - ROTATERIGHT( iroot ) - *taller = 0; - break; - } - break; - case EH : /* equal height - now left heavy */ - (*iroot)->avl_bf = LH; - *taller = 1; - break; - case RH : /* right high - balance is restored */ - (*iroot)->avl_bf = EH; - *taller = 0; - break; - } - else - *taller = 0; - } - - return( rc ); -} +static const int avl_bfs[] = {LH, RH}; /* * avl_insert -- insert a node containing data data into the avl tree @@ -227,245 +65,284 @@ ravl_insert( * * NOTE: this routine may malloc memory */ - int -avl_insert( Avlnode **root, void* data, AVL_CMP fcmp, AVL_DUP fdup ) +avl_insert( Avlnode ** root, void *data, AVL_CMP fcmp, AVL_DUP fdup ) { - int taller; + Avlnode *t, *p, *s, *q, *r; + int a, cmp, ncmp; - return( ravl_insert( root, data, &taller, fcmp, fdup, 0 ) ); -} + if ( *root == NULL ) { + if (( r = (Avlnode *) ber_memalloc( sizeof( Avlnode ))) == NULL ) { + return( -1 ); + } + r->avl_link[0] = r->avl_link[1] = NULL; + r->avl_data = data; + r->avl_bf = EH; + *root = r; -/* - * right_balance() - called from delete when root's right subtree has - * been shortened because of a deletion. - */ + return( 0 ); + } -static int -right_balance( Avlnode **root ) -{ - int shorter = -1; - Avlnode *r, *l; - - switch( (*root)->avl_bf ) { - case RH: /* was right high - equal now */ - (*root)->avl_bf = EH; - shorter = 1; - break; - case EH: /* was equal - left high now */ - (*root)->avl_bf = LH; - shorter = 0; - break; - case LH: /* was right high - balance */ - l = (*root)->avl_left; - switch ( l->avl_bf ) { - case RH : /* double rotation left */ - r = l->avl_right; - switch ( r->avl_bf ) { - case RH : - (*root)->avl_bf = EH; - l->avl_bf = LH; - break; - case EH : - (*root)->avl_bf = EH; - l->avl_bf = EH; - break; - case LH : - (*root)->avl_bf = RH; - l->avl_bf = EH; - break; + t = NULL; + s = p = *root; + + /* find insertion point */ + while (1) { + cmp = fcmp( data, p->avl_data ); + if ( cmp == 0 ) + return (*fdup)( p->avl_data, data ); + + cmp = (cmp > 0); + q = p->avl_link[cmp]; + if (q == NULL) { + /* insert */ + if (( q = (Avlnode *) ber_memalloc( sizeof( Avlnode ))) == NULL ) { + return( -1 ); } - r->avl_bf = EH; - ROTATELEFT( (&l) ) - (*root)->avl_left = l; - ROTATERIGHT( root ) - shorter = 1; - break; - case EH : /* right rotation */ - (*root)->avl_bf = LH; - l->avl_bf = RH; - ROTATERIGHT( root ); - shorter = 0; - break; - case LH : /* single rotation right */ - (*root)->avl_bf = EH; - l->avl_bf = EH; - ROTATERIGHT( root ) - shorter = 1; + q->avl_link[0] = q->avl_link[1] = NULL; + q->avl_data = data; + q->avl_bf = EH; + + p->avl_link[cmp] = q; break; + } else if ( q->avl_bf ) { + t = p; + s = q; } - break; + p = q; + } + + /* adjust balance factors */ + cmp = fcmp( data, s->avl_data ) > 0; + r = p = s->avl_link[cmp]; + a = avl_bfs[cmp]; + + while ( p != q ) { + cmp = fcmp( data, p->avl_data ) > 0; + p->avl_bf = avl_bfs[cmp]; + p = p->avl_link[cmp]; } - return( shorter ); -} - -/* - * left_balance() - called from delete when root's left subtree has - * been shortened because of a deletion. - */ - -static int -left_balance( Avlnode **root ) -{ - int shorter = -1; - Avlnode *r, *l; - - switch( (*root)->avl_bf ) { - case LH: /* was left high - equal now */ - (*root)->avl_bf = EH; - shorter = 1; - break; - case EH: /* was equal - right high now */ - (*root)->avl_bf = RH; - shorter = 0; - break; - case RH: /* was right high - balance */ - r = (*root)->avl_right; - switch ( r->avl_bf ) { - case LH : /* double rotation left */ - l = r->avl_left; - switch ( l->avl_bf ) { - case LH : - (*root)->avl_bf = EH; - r->avl_bf = RH; - break; - case EH : - (*root)->avl_bf = EH; - r->avl_bf = EH; - break; - case RH : - (*root)->avl_bf = LH; - r->avl_bf = EH; - break; + /* checks and balances */ + + if ( s->avl_bf == EH ) { + s->avl_bf = a; + return 0; + } else if ( s->avl_bf == -a ) { + s->avl_bf = EH; + return 0; + } else if ( s->avl_bf == a ) { + cmp = (a > 0); + ncmp = !cmp; + if ( r->avl_bf == a ) { + /* single rotation */ + p = r; + s->avl_link[cmp] = r->avl_link[ncmp]; + r->avl_link[ncmp] = s; + s->avl_bf = 0; + r->avl_bf = 0; + } else if ( r->avl_bf == -a ) { + /* double rotation */ + p = r->avl_link[ncmp]; + r->avl_link[ncmp] = p->avl_link[cmp]; + p->avl_link[cmp] = r; + s->avl_link[cmp] = p->avl_link[ncmp]; + p->avl_link[ncmp] = s; + + if ( p->avl_bf == a ) { + s->avl_bf = -a; + r->avl_bf = 0; + } else if ( p->avl_bf == -a ) { + s->avl_bf = 0; + r->avl_bf = a; + } else { + s->avl_bf = 0; + r->avl_bf = 0; } - l->avl_bf = EH; - ROTATERIGHT( (&r) ) - (*root)->avl_right = r; - ROTATELEFT( root ) - shorter = 1; - break; - case EH : /* single rotation left */ - (*root)->avl_bf = RH; - r->avl_bf = LH; - ROTATELEFT( root ); - shorter = 0; - break; - case RH : /* single rotation left */ - (*root)->avl_bf = EH; - r->avl_bf = EH; - ROTATELEFT( root ) - shorter = 1; - break; + p->avl_bf = 0; } - break; - } + /* Update parent */ + if ( t == NULL ) + *root = p; + else if ( s == t->avl_right ) + t->avl_right = p; + else + t->avl_left = p; + } - return( shorter ); + return 0; } -/* - * ravl_delete() - called from avl_delete to do recursive deletion of a - * node from an avl tree. It finds the node recursively, deletes it, - * and returns shorter if the tree is shorter after the deletion and - * rebalancing. - */ - -static void* -ravl_delete( Avlnode **root, void* data, AVL_CMP fcmp, int *shorter ) +void* +avl_delete( Avlnode **root, void* data, AVL_CMP fcmp ) { - int shortersubtree = 0; - int cmp; - void* savedata; - Avlnode *minnode, *savenode; - - if ( *root == NULLAVL ) - return( 0 ); - - cmp = (*fcmp)( data, (*root)->avl_data ); + Avlnode *p, *q, *r, *top; + int side, side_bf, shorter, nside; - /* found it! */ - if ( cmp == 0 ) { - savenode = *root; - savedata = savenode->avl_data; - - /* simple cases: no left child */ - if ( (*root)->avl_left == 0 ) { - *root = (*root)->avl_right; - *shorter = 1; - ber_memfree( (char *) savenode ); - return( savedata ); - /* no right child */ - } else if ( (*root)->avl_right == 0 ) { - *root = (*root)->avl_left; - *shorter = 1; - ber_memfree( (char *) savenode ); - return( savedata ); - } - - /* - * avl_getmin will return to us the smallest node greater - * than the one we are trying to delete. deleting this node - * from the right subtree is guaranteed to end in one of the - * simple cases above. - */ + /* parent stack */ + Avlnode *pptr[sizeof(void *)*8]; + unsigned char pdir[sizeof(void *)*8]; + int depth = 0; - minnode = (*root)->avl_right; - while ( minnode->avl_left != NULLAVL ) - minnode = minnode->avl_left; + if ( *root == NULL ) + return NULL; - /* swap the data */ - (*root)->avl_data = minnode->avl_data; - minnode->avl_data = savedata; + p = *root; - savedata = ravl_delete( &(*root)->avl_right, data, fcmp, - &shortersubtree ); + while (1) { + side = fcmp( data, p->avl_data ); + if ( !side ) + break; + side = ( side > 0 ); + pdir[depth] = side; + pptr[depth++] = p; - if ( shortersubtree ) - *shorter = right_balance( root ); - else - *shorter = 0; - /* go left */ - } else if ( cmp < 0 ) { - if ( (savedata = ravl_delete( &(*root)->avl_left, data, fcmp, - &shortersubtree )) == 0 ) { - *shorter = 0; - return( 0 ); + p = p->avl_link[side]; + if ( p == NULL ) + return p; + } + data = p->avl_data; + + /* If this node has two children, swap so we are deleting a node with + * at most one child. + */ + if ( p->avl_link[0] && p->avl_link[1] ) { + + /* find the immediate predecessor */ + q = p->avl_link[0]; + side = depth; + pdir[depth++] = 0; + while (q->avl_link[1]) { + pdir[depth] = 1; + pptr[depth++] = q; + q = q->avl_link[1]; } - - /* left subtree shorter? */ - if ( shortersubtree ) - *shorter = left_balance( root ); - else - *shorter = 0; - /* go right */ - } else { - if ( (savedata = ravl_delete( &(*root)->avl_right, data, fcmp, - &shortersubtree )) == 0 ) { - *shorter = 0; - return( 0 ); + /* swap links */ + r = p->avl_link[0]; + p->avl_link[0] = q->avl_link[0]; + q->avl_link[0] = r; + + q->avl_link[1] = p->avl_link[1]; + p->avl_link[1] = NULL; + + q->avl_bf = p->avl_bf; + + /* fix stack positions: old parent of p points to q */ + pptr[side] = q; + if ( side ) { + r = pptr[side-1]; + r->avl_link[pdir[side-1]] = q; + } else { + *root = q; + } + /* new parent of p points to p */ + if ( depth-side > 1 ) { + r = pptr[depth-1]; + r->avl_link[1] = p; + } else { + q->avl_link[0] = p; } - - if ( shortersubtree ) - *shorter = right_balance( root ); - else - *shorter = 0; } - return( savedata ); -} + /* now

has at most one child, get it */ + q = p->avl_link[0] ? p->avl_link[0] : p->avl_link[1]; -/* - * avl_delete() - deletes the node containing data (according to fcmp) from - * the avl tree rooted at root. - */ + ber_memfree( p ); -void* -avl_delete( Avlnode **root, void* data, AVL_CMP fcmp ) -{ - int shorter; + if ( !depth ) { + *root = q; + return data; + } + + /* set the child into p's parent */ + depth--; + p = pptr[depth]; + side = pdir[depth]; + p->avl_link[side] = q; + + top = NULL; + shorter = 1; + + while ( shorter ) { + p = pptr[depth]; + side = pdir[depth]; + nside = !side; + side_bf = avl_bfs[side]; + + /* case 1: height unchanged */ + if ( p->avl_bf == EH ) { + /* Tree is now heavier on opposite side */ + p->avl_bf = avl_bfs[nside]; + shorter = 0; + + } else if ( p->avl_bf == side_bf ) { + /* case 2: taller subtree shortened, height reduced */ + p->avl_bf = EH; + } else { + /* case 3: shorter subtree shortened */ + if ( depth ) + top = pptr[depth-1]; /* p->parent; */ + else + top = NULL; + /* set to the taller of the two subtrees of

*/ + q = p->avl_link[nside]; + if ( q->avl_bf == EH ) { + /* case 3a: height unchanged, single rotate */ + p->avl_link[nside] = q->avl_link[side]; + q->avl_link[side] = p; + shorter = 0; + q->avl_bf = side_bf; + p->avl_bf = (- side_bf); + + } else if ( q->avl_bf == p->avl_bf ) { + /* case 3b: height reduced, single rotate */ + p->avl_link[nside] = q->avl_link[side]; + q->avl_link[side] = p; + shorter = 1; + q->avl_bf = EH; + p->avl_bf = EH; + + } else { + /* case 3c: height reduced, balance factors opposite */ + r = q->avl_link[side]; + q->avl_link[side] = r->avl_link[nside]; + r->avl_link[nside] = q; + + p->avl_link[nside] = r->avl_link[side]; + r->avl_link[side] = p; + + if ( r->avl_bf == side_bf ) { + q->avl_bf = (- side_bf); + p->avl_bf = EH; + } else if ( r->avl_bf == (- side_bf)) { + q->avl_bf = EH; + p->avl_bf = side_bf; + } else { + q->avl_bf = EH; + p->avl_bf = EH; + } + r->avl_bf = EH; + q = r; + } + /* a rotation has caused (or in case 3c) to become + * the root. let

's former parent know this. + */ + if ( top == NULL ) { + *root = q; + } else if (top->avl_link[0] == p) { + top->avl_link[0] = q; + } else { + top->avl_link[1] = q; + } + /* end case 3 */ + p = q; + } + if ( !depth ) + break; + depth--; + } /* end while(shorter) */ - return( ravl_delete( root, data, fcmp, &shorter ) ); + return data; } static int @@ -650,10 +527,8 @@ avl_find2( Avlnode *root, const void *data, AVL_CMP fcmp ) int cmp; while ( root != 0 && (cmp = (*fcmp)( data, root->avl_data )) != 0 ) { - if ( cmp < 0 ) - root = root->avl_left; - else - root = root->avl_right; + cmp = cmp > 0; + root = root->avl_link[cmp]; } return root; } @@ -664,10 +539,8 @@ avl_find( Avlnode *root, const void* data, AVL_CMP fcmp ) int cmp; while ( root != 0 && (cmp = (*fcmp)( data, root->avl_data )) != 0 ) { - if ( cmp < 0 ) - root = root->avl_left; - else - root = root->avl_right; + cmp = cmp > 0; + root = root->avl_link[cmp]; } return( root ? root->avl_data : 0 ); diff --git a/libraries/liblutil/passwd.c b/libraries/liblutil/passwd.c index 8f6fda6129..23d001f7d5 100644 --- a/libraries/liblutil/passwd.c +++ b/libraries/liblutil/passwd.c @@ -209,9 +209,7 @@ static const struct pw_scheme *get_scheme( bv.bv_val = (char *) scheme; for( pws=pw_schemes; pws; pws=pws->next ) { - if( bv.bv_len != pws->s.name.bv_len ) - continue; - if( strncasecmp(bv.bv_val, pws->s.name.bv_val, bv.bv_len ) == 0 ) { + if ( ber_bvstrcasecmp(&bv, &pws->s.name ) == 0 ) { return &(pws->s); } } diff --git a/libraries/liblutil/tavl.c b/libraries/liblutil/tavl.c new file mode 100644 index 0000000000..f588c71d88 --- /dev/null +++ b/libraries/liblutil/tavl.c @@ -0,0 +1,497 @@ +/* avl.c - routines to implement an avl tree */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 2005 The OpenLDAP Foundation. + * Portions Copyright (c) 2005 by Howard Chu, Symas Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* ACKNOWLEDGEMENTS: + * This work was initially developed by Howard Chu for inclusion + * in OpenLDAP software. + */ + +#include "portable.h" + +#include +#include + +#ifdef CSRIMALLOC +#define ber_memalloc malloc +#define ber_memrealloc realloc +#define ber_memfree free +#else +#include "lber.h" +#endif + +#define AVL_INTERNAL +#include "avl.h" + +static const int avl_bfs[] = {LH, RH}; + +/* + * Threaded AVL trees - for fast in-order traversal of nodes. + */ +/* + * tavl_insert -- insert a node containing data data into the avl tree + * with root root. fcmp is a function to call to compare the data portion + * of two nodes. it should take two arguments and return <, >, or == 0, + * depending on whether its first argument is <, >, or == its second + * argument (like strcmp, e.g.). fdup is a function to call when a duplicate + * node is inserted. it should return 0, or -1 and its return value + * will be the return value from avl_insert in the case of a duplicate node. + * the function will be called with the original node's data as its first + * argument and with the incoming duplicate node's data as its second + * argument. this could be used, for example, to keep a count with each + * node. + * + * NOTE: this routine may malloc memory + */ +int +tavl_insert( Avlnode ** root, void *data, AVL_CMP fcmp, AVL_DUP fdup ) +{ + Avlnode *t, *p, *s, *q, *r; + int a, cmp, ncmp; + + if ( *root == NULL ) { + if (( r = (Avlnode *) ber_memalloc( sizeof( Avlnode ))) == NULL ) { + return( -1 ); + } + r->avl_link[0] = r->avl_link[1] = NULL; + r->avl_data = data; + r->avl_bf = EH; + r->avl_bits[0] = r->avl_bits[1] = AVL_THREAD; + *root = r; + + return( 0 ); + } + + t = NULL; + s = p = *root; + + /* find insertion point */ + while (1) { + cmp = fcmp( data, p->avl_data ); + if ( cmp == 0 ) + return (*fdup)( p->avl_data, data ); + + cmp = (cmp > 0); + q = avl_child( p, cmp ); + if (q == NULL) { + /* insert */ + if (( q = (Avlnode *) ber_memalloc( sizeof( Avlnode ))) == NULL ) { + return( -1 ); + } + q->avl_link[cmp] = p->avl_link[cmp]; + q->avl_link[!cmp] = p; + q->avl_data = data; + q->avl_bf = EH; + q->avl_bits[0] = q->avl_bits[1] = AVL_THREAD; + + p->avl_link[cmp] = q; + p->avl_bits[cmp] = AVL_CHILD; + break; + } else if ( q->avl_bf ) { + t = p; + s = q; + } + p = q; + } + + /* adjust balance factors */ + cmp = fcmp( data, s->avl_data ) > 0; + r = p = s->avl_link[cmp]; + a = avl_bfs[cmp]; + + while ( p != q ) { + cmp = fcmp( data, p->avl_data ) > 0; + p->avl_bf = avl_bfs[cmp]; + p = p->avl_link[cmp]; + } + + /* checks and balances */ + + if ( s->avl_bf == EH ) { + s->avl_bf = a; + return 0; + } else if ( s->avl_bf == -a ) { + s->avl_bf = EH; + return 0; + } else if ( s->avl_bf == a ) { + cmp = (a > 0); + ncmp = !cmp; + if ( r->avl_bf == a ) { + /* single rotation */ + p = r; + if ( r->avl_bits[ncmp] == AVL_THREAD ) { + r->avl_bits[ncmp] = AVL_CHILD; + s->avl_bits[cmp] = AVL_THREAD; + } else { + s->avl_link[cmp] = r->avl_link[ncmp]; + r->avl_link[ncmp] = s; + } + s->avl_bf = 0; + r->avl_bf = 0; + } else if ( r->avl_bf == -a ) { + /* double rotation */ + p = r->avl_link[ncmp]; + if ( p->avl_bits[cmp] == AVL_THREAD ) { + p->avl_bits[cmp] = AVL_CHILD; + r->avl_bits[ncmp] = AVL_THREAD; + } else { + r->avl_link[ncmp] = p->avl_link[cmp]; + p->avl_link[cmp] = r; + } + if ( p->avl_bits[ncmp] == AVL_THREAD ) { + p->avl_bits[ncmp] = AVL_CHILD; + s->avl_link[cmp] = p; + s->avl_bits[cmp] = AVL_THREAD; + } else { + s->avl_link[cmp] = p->avl_link[ncmp]; + p->avl_link[ncmp] = s; + } + if ( p->avl_bf == a ) { + s->avl_bf = -a; + r->avl_bf = 0; + } else if ( p->avl_bf == -a ) { + s->avl_bf = 0; + r->avl_bf = a; + } else { + s->avl_bf = 0; + r->avl_bf = 0; + } + p->avl_bf = 0; + } + /* Update parent */ + if ( t == NULL ) + *root = p; + else if ( s == t->avl_right ) + t->avl_right = p; + else + t->avl_left = p; + } + + return 0; +} + +void* +tavl_delete( Avlnode **root, void* data, AVL_CMP fcmp ) +{ + Avlnode *p, *q, *r, *top; + int side, side_bf, shorter, nside; + + /* parent stack */ + Avlnode *pptr[sizeof(void *)*8]; + unsigned char pdir[sizeof(void *)*8]; + int depth = 0; + + if ( *root == NULL ) + return NULL; + + p = *root; + + while (1) { + side = fcmp( data, p->avl_data ); + if ( !side ) + break; + side = ( side > 0 ); + pdir[depth] = side; + pptr[depth++] = p; + + if ( p->avl_bits[side] == AVL_THREAD ) + return NULL; + p = p->avl_link[side]; + } + data = p->avl_data; + + /* If this node has two children, swap so we are deleting a node with + * at most one child. + */ + if ( p->avl_bits[0] == AVL_CHILD && p->avl_bits[1] == AVL_CHILD && + p->avl_link[0] && p->avl_link[1] ) { + + /* find the immediate predecessor */ + q = p->avl_link[0]; + side = depth; + pdir[depth++] = 0; + while (q->avl_bits[1] == AVL_CHILD && q->avl_link[1]) { + pdir[depth] = 1; + pptr[depth++] = q; + q = q->avl_link[1]; + } + /* swap links */ + r = p->avl_link[0]; + p->avl_link[0] = q->avl_link[0]; + q->avl_link[0] = r; + + q->avl_link[1] = p->avl_link[1]; + p->avl_link[1] = q; + + p->avl_bits[0] = q->avl_bits[0]; + p->avl_bits[1] = q->avl_bits[1]; + q->avl_bits[0] = q->avl_bits[1] = AVL_CHILD; + + q->avl_bf = p->avl_bf; + + /* fix stack positions: old parent of p points to q */ + pptr[side] = q; + if ( side ) { + r = pptr[side-1]; + r->avl_link[pdir[side-1]] = q; + } else { + *root = q; + } + /* new parent of p points to p */ + if ( depth-side > 1 ) { + r = pptr[depth-1]; + r->avl_link[1] = p; + } else { + q->avl_link[0] = p; + } + + /* fix right subtree: successor of p points to q */ + r = q->avl_link[1]; + while ( r->avl_bits[0] == AVL_CHILD && r->avl_link[0] ) + r = r->avl_link[0]; + r->avl_link[0] = q; + } + + /* now

has at most one child, get it */ + if ( p->avl_link[0] && p->avl_bits[0] == AVL_CHILD ) { + q = p->avl_link[0]; + /* Preserve thread continuity */ + r = p->avl_link[1]; + nside = 1; + } else if ( p->avl_link[1] && p->avl_bits[1] == AVL_CHILD ) { + q = p->avl_link[1]; + r = p->avl_link[0]; + nside = 0; + } else { + q = NULL; + if ( depth > 0 ) + r = p->avl_link[pdir[depth-1]]; + else + r = NULL; + } + + ber_memfree( p ); + + if ( !depth ) { + *root = q; + return data; + } + + /* set the child into p's parent */ + depth--; + p = pptr[depth]; + side = pdir[depth]; + p->avl_link[side] = q; + + /* Update child thread */ + if ( q ) { + for ( ; q->avl_bits[nside] == AVL_CHILD && q->avl_link[nside]; + q = q->avl_link[nside] ) ; + q->avl_link[nside] = r; + } else { + p->avl_bits[side] = AVL_THREAD; + p->avl_link[side] = r; + } + + top = NULL; + shorter = 1; + + while ( shorter ) { + p = pptr[depth]; + side = pdir[depth]; + nside = !side; + side_bf = avl_bfs[side]; + + /* case 1: height unchanged */ + if ( p->avl_bf == EH ) { + /* Tree is now heavier on opposite side */ + p->avl_bf = avl_bfs[nside]; + shorter = 0; + + } else if ( p->avl_bf == side_bf ) { + /* case 2: taller subtree shortened, height reduced */ + p->avl_bf = EH; + } else { + /* case 3: shorter subtree shortened */ + if ( depth ) + top = pptr[depth-1]; /* p->parent; */ + else + top = NULL; + /* set to the taller of the two subtrees of

*/ + q = p->avl_link[nside]; + if ( q->avl_bf == EH ) { + /* case 3a: height unchanged, single rotate */ + if ( q->avl_bits[side] == AVL_THREAD ) { + q->avl_bits[side] = AVL_CHILD; + p->avl_bits[nside] = AVL_THREAD; + } else { + p->avl_link[nside] = q->avl_link[side]; + q->avl_link[side] = p; + } + shorter = 0; + q->avl_bf = side_bf; + p->avl_bf = (- side_bf); + + } else if ( q->avl_bf == p->avl_bf ) { + /* case 3b: height reduced, single rotate */ + if ( q->avl_bits[side] == AVL_THREAD ) { + q->avl_bits[side] = AVL_CHILD; + p->avl_bits[nside] = AVL_THREAD; + } else { + p->avl_link[nside] = q->avl_link[side]; + q->avl_link[side] = p; + } + shorter = 1; + q->avl_bf = EH; + p->avl_bf = EH; + + } else { + /* case 3c: height reduced, balance factors opposite */ + r = q->avl_link[side]; + if ( r->avl_bits[nside] == AVL_THREAD ) { + r->avl_bits[nside] = AVL_CHILD; + q->avl_bits[side] = AVL_THREAD; + } else { + q->avl_link[side] = r->avl_link[nside]; + r->avl_link[nside] = q; + } + + if ( r->avl_bits[side] == AVL_THREAD ) { + r->avl_bits[side] = AVL_CHILD; + p->avl_bits[nside] = AVL_THREAD; + p->avl_link[nside] = r; + } else { + p->avl_link[nside] = r->avl_link[side]; + r->avl_link[side] = p; + } + + if ( r->avl_bf == side_bf ) { + q->avl_bf = (- side_bf); + p->avl_bf = EH; + } else if ( r->avl_bf == (- side_bf)) { + q->avl_bf = EH; + p->avl_bf = side_bf; + } else { + q->avl_bf = EH; + p->avl_bf = EH; + } + r->avl_bf = EH; + q = r; + } + /* a rotation has caused (or in case 3c) to become + * the root. let

's former parent know this. + */ + if ( top == NULL ) { + *root = q; + } else if (top->avl_link[0] == p) { + top->avl_link[0] = q; + } else { + top->avl_link[1] = q; + } + /* end case 3 */ + p = q; + } + if ( !depth ) + break; + depth--; + } /* end while(shorter) */ + + return data; +} + +/* + * tavl_free -- traverse avltree root, freeing the memory it is using. + * the dfree() is called to free the data portion of each node. The + * number of items actually freed is returned. + */ + +int +tavl_free( Avlnode *root, AVL_FREE dfree ) +{ + int nleft, nright; + + if ( root == 0 ) + return( 0 ); + + nleft = tavl_free( avl_lchild( root ), dfree ); + + nright = tavl_free( avl_rchild( root ), dfree ); + + if ( dfree ) + (*dfree)( root->avl_data ); + ber_memfree( root ); + + return( nleft + nright + 1 ); +} + +/* + * tavl_find -- search avltree root for a node with data data. the function + * cmp is used to compare things. it is called with data as its first arg + * and the current node data as its second. it should return 0 if they match, + * < 0 if arg1 is less than arg2 and > 0 if arg1 is greater than arg2. + */ + +Avlnode * +tavl_find2( Avlnode *root, const void *data, AVL_CMP fcmp ) +{ + int cmp; + + while ( root != 0 && (cmp = (*fcmp)( data, root->avl_data )) != 0 ) { + cmp = cmp > 0; + root = avl_child( root, cmp ); + } + return root; +} + +void* +tavl_find( Avlnode *root, const void* data, AVL_CMP fcmp ) +{ + int cmp; + + while ( root != 0 && (cmp = (*fcmp)( data, root->avl_data )) != 0 ) { + cmp = cmp > 0; + root = avl_child( root, cmp ); + } + + return( root ? root->avl_data : 0 ); +} + +/* Return the leftmost or rightmost node in the tree */ +Avlnode * +tavl_end( Avlnode *root, int dir ) +{ + if ( root ) { + while ( root->avl_bits[dir] == AVL_CHILD ) + root = root->avl_link[dir]; + } + return root; +} + +/* Return the next node in the given direction */ +Avlnode * +tavl_next( Avlnode *root, int dir ) +{ + if ( root ) { + int c = root->avl_bits[dir]; + + root = root->avl_link[dir]; + if ( c == AVL_CHILD ) { + dir ^= 1; + while ( root->avl_bits[dir] == AVL_CHILD ) + root = root->avl_link[dir]; + } + } + return root; +} diff --git a/libraries/liblutil/utils.c b/libraries/liblutil/utils.c index 692d2bebe6..4d179f7543 100644 --- a/libraries/liblutil/utils.c +++ b/libraries/liblutil/utils.c @@ -204,7 +204,7 @@ int lutil_parsetime( char *atm, struct lutil_tm *tm ) { while (atm && tm) { char *ptr = atm; - int i, fracs; + unsigned i, fracs; /* Is the stamp reasonably long? */ for (i=0; isdigit(atm[i]); i++); diff --git a/libraries/liblutil/uuid.c b/libraries/liblutil/uuid.c index f300f42574..6857759fcf 100644 --- a/libraries/liblutil/uuid.c +++ b/libraries/liblutil/uuid.c @@ -169,7 +169,7 @@ lutil_eaddr( void ) if (memcmp(eaddr, zero, sizeof(eaddr)) == 0) { /* XXX - who knows? */ lutil_entropy( eaddr, sizeof(eaddr) ); - eaddr[0] |= 0x80; /* turn it into a multicast address */ + eaddr[0] |= 0x01; /* turn it into a multicast address */ } return eaddr; diff --git a/libraries/librewrite/session.c b/libraries/librewrite/session.c index ac9196cec8..bd0685167c 100644 --- a/libraries/librewrite/session.c +++ b/libraries/librewrite/session.c @@ -204,6 +204,13 @@ rewrite_session_var_set_f( session = rewrite_session_find( info, cookie ); if ( session == NULL ) { session = rewrite_session_init( info, cookie ); + if ( session == NULL ) { + return REWRITE_ERR; + } + +#ifdef USE_REWRITE_LDAP_PVT_THREADS + ldap_pvt_thread_mutex_lock( &session->ls_mutex ); +#endif /* USE_REWRITE_LDAP_PVT_THREADS */ } #ifdef USE_REWRITE_LDAP_PVT_THREADS diff --git a/servers/slapd/Makefile.in b/servers/slapd/Makefile.in index 46ee8dac69..408126e010 100644 --- a/servers/slapd/Makefile.in +++ b/servers/slapd/Makefile.in @@ -38,7 +38,7 @@ SRCS = main.c globals.c bconfig.c config.c daemon.c \ backglue.c backover.c ctxcsn.c ldapsync.c frontend.c \ slapadd.c slapcat.c slapcommon.c slapdn.c slapindex.c \ slappasswd.c slaptest.c slapauth.c slapacl.c component.c \ - aci.c \ + aci.c alock.c \ $(@PLAT@_SRCS) OBJS = main.o globals.o bconfig.o config.o daemon.o \ @@ -56,7 +56,7 @@ OBJS = main.o globals.o bconfig.o config.o daemon.o \ backglue.o backover.o ctxcsn.o ldapsync.o frontend.o \ slapadd.o slapcat.o slapcommon.o slapdn.o slapindex.o \ slappasswd.o slaptest.o slapauth.o slapacl.o component.o \ - aci.o \ + aci.o alock.o \ $(@PLAT@_OBJS) LDAP_INCDIR= ../../include -I$(srcdir) -I$(srcdir)/slapi -I. @@ -168,7 +168,7 @@ slapd.def: libbackends.a liboverlays.a version.o done="" ;\ base=`expr "$$i" : "-l\(.*\)"`; \ for p in $$paths ; do \ - for ext in la dll a ; do \ + for ext in la dll dll.a a ; do \ path=$$p/lib$$base.$$ext; \ test ! -f $$path && continue; \ if test $$ext = la ; then \ @@ -192,12 +192,14 @@ slapd.def: libbackends.a liboverlays.a version.o test -z "$$obj" && continue; \ ;; \ *.la) \ - if test -n "$LTSTATIC"; then \ + if test -n "$(LTSTATIC)"; then \ base=`expr "$$i" : ".*/\(.*\).la"`; \ path=`expr "$$i" : "\(.*/\).*"`; \ obj=$$path.libs/$$base.a; \ fi; \ ;; \ + *.dll.a) \ + ;; \ *.o | *.a) \ obj=$$i; \ esac; \ @@ -335,7 +337,7 @@ backends.o: backends.c $(srcdir)/slap.h depend-local-srv: FORCE @for i in $(SUBDIRS); do \ - if test -d $$i -a -f $$i/Makefile ; then \ + if test -d $$i && test -f $$i/Makefile ; then \ echo; echo " cd $$i; $(MAKE) $(MFLAGS) depend"; \ ( cd $$i; $(MAKE) $(MFLAGS) depend ); \ if test $$? != 0 ; then exit 1; fi ; \ @@ -351,7 +353,7 @@ veryclean-local: clean-local-srv: FORCE @for i in $(SUBDIRS); do \ - if test -d $$i -a -f $$i/Makefile ; then \ + if test -d $$i && test -f $$i/Makefile ; then \ echo; echo " cd $$i; $(MAKE) $(MFLAGS) clean"; \ ( cd $$i; $(MAKE) $(MFLAGS) clean ); \ if test $$? != 0 ; then exit 1; fi ; \ @@ -361,7 +363,7 @@ clean-local-srv: FORCE veryclean-local-srv: FORCE @for i in $(SUBDIRS); do \ - if test -d $$i -a -f $$i/Makefile ; then \ + if test -d $$i && test -f $$i/Makefile ; then \ echo; echo " cd $$i; $(MAKE) $(MFLAGS) clean"; \ ( cd $$i; $(MAKE) $(MFLAGS) veryclean ); \ fi; \ @@ -376,7 +378,7 @@ install-slapd: FORCE $(LTINSTALL) $(INSTALLFLAGS) $(STRIP) -m 755 \ slapd$(EXEEXT) $(DESTDIR)$(libexecdir) @for i in $(SUBDIRS); do \ - if test -d $$i -a -f $$i/Makefile ; then \ + if test -d $$i && test -f $$i/Makefile ; then \ echo; echo " cd $$i; $(MAKE) $(MFLAGS) install"; \ ( cd $$i; $(MAKE) $(MFLAGS) install ); \ if test $$? != 0 ; then exit 1; fi ; \ diff --git a/servers/slapd/acl.c b/servers/slapd/acl.c index 91c33e9c23..f224e68e8a 100644 --- a/servers/slapd/acl.c +++ b/servers/slapd/acl.c @@ -851,7 +851,8 @@ slap_acl_get( continue; } else if ( a->acl_dn_style == ACL_STYLE_ONE ) { - int rdnlen = -1, sep = 0; + ber_len_t rdnlen = 0; + int sep = 0; if ( dnlen <= patlen ) continue; @@ -942,7 +943,7 @@ slap_acl_get( continue; } else if ( a->acl_attrval_style == ACL_STYLE_ONE ) { - int rdnlen = -1; + ber_len_t rdnlen = 0; if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) ) continue; @@ -1186,7 +1187,7 @@ acl_mask_dn( } } else if ( b->a_style == ACL_STYLE_ONE ) { - int rdnlen = -1; + ber_len_t rdnlen = 0; if ( odnlen <= patlen ) { goto dn_match_cleanup; diff --git a/servers/slapd/aclparse.c b/servers/slapd/aclparse.c index e307b550c5..9b0e8e7acb 100644 --- a/servers/slapd/aclparse.c +++ b/servers/slapd/aclparse.c @@ -84,7 +84,7 @@ slap_dynacl_config( for ( da = b->a_dynacl; da; da = da->da_next ) { if ( strcasecmp( da->da_name, name ) == 0 ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: dynacl \"%s\" already specified.\n", fname, lineno, name ); acl_usage(); @@ -119,8 +119,8 @@ regtest(const char *fname, int lineno, char *pat) { int e; regex_t re; - char buf[512]; - unsigned size; + char buf[ SLAP_TEXT_BUFLEN ]; + unsigned size; char *sp; char *dp; @@ -151,18 +151,23 @@ regtest(const char *fname, int lineno, char *pat) { *dp = '\0'; if ( size >= (sizeof(buf) - 1) ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: regular expression \"%s\" too large\n", fname, lineno, pat ); acl_usage(); } if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) { - char error[512]; + char error[ SLAP_TEXT_BUFLEN ]; + regerror(e, &re, error, sizeof(error)); - fprintf( stderr, - "%s: line %d: regular expression \"%s\" bad because of %s\n", - fname, lineno, pat, error ); + + snprintf( buf, sizeof( buf ), + "regular expression \"%s\" bad because of %s", + pat, error ); + Debug( LDAP_DEBUG_ANY, + "%s: line %d: %s\n", + fname, lineno, buf ); acl_usage(); } regfree(&re); @@ -183,7 +188,7 @@ regtest(const char *fname, int lineno, char *pat) { static int check_scope( BackendDB *be, AccessControl *a ) { - int patlen; + ber_len_t patlen; struct berval dn; dn = be->be_nsuffix[0]; @@ -252,7 +257,8 @@ regex_done:; * more than one level between the suffix * and the pattern */ if ( style == ACL_STYLE_ONE ) { - int rdnlen = -1, sep = 0; + ber_len_t rdnlen = 0; + int sep = 0; if ( patlen > 0 ) { if ( !DN_SEPARATOR( dn.bv_val[dn.bv_len - patlen - 1] )) { @@ -329,9 +335,9 @@ parse_acl( /* to clause - select which entries are protected */ if ( strcasecmp( argv[i], "to" ) == 0 ) { if ( a != NULL ) { - fprintf( stderr, "%s: line %d: " + Debug( LDAP_DEBUG_ANY, "%s: line %d: " "only one to clause allowed in access line\n", - fname, lineno ); + fname, lineno, 0 ); acl_usage(); } a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) ); @@ -345,10 +351,10 @@ parse_acl( if ( !BER_BVISEMPTY( &a->acl_dn_pat ) || a->acl_dn_style != ACL_STYLE_REGEX ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: dn pattern" " already specified in to clause.\n", - fname, lineno ); + fname, lineno, 0 ); acl_usage(); } @@ -360,7 +366,7 @@ parse_acl( split( left, '.', &left, &style ); if ( right == NULL ) { - fprintf( stderr, "%s: line %d: " + Debug( LDAP_DEBUG_ANY, "%s: line %d: " "missing \"=\" in \"%s\" in to clause\n", fname, lineno, left ); acl_usage(); @@ -370,10 +376,10 @@ parse_acl( if ( !BER_BVISEMPTY( &a->acl_dn_pat ) || a->acl_dn_style != ACL_STYLE_REGEX ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: dn pattern" " already specified in to clause.\n", - fname, lineno ); + fname, lineno, 0 ); acl_usage(); } @@ -429,7 +435,7 @@ parse_acl( } } else { - fprintf( stderr, "%s: line %d: " + Debug( LDAP_DEBUG_ANY, "%s: line %d: " "unknown dn style \"%s\" in to clause\n", fname, lineno, style ); acl_usage(); @@ -440,7 +446,7 @@ parse_acl( if ( strcasecmp( left, "filter" ) == 0 ) { if ( (a->acl_filter = str2filter( right )) == NULL ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: bad filter \"%s\" in to clause\n", fname, lineno, right ); acl_usage(); @@ -449,10 +455,18 @@ parse_acl( } else if ( strcasecmp( left, "attr" ) == 0 /* TOLERATED */ || strcasecmp( left, "attrs" ) == 0 ) /* DOCUMENTED */ { + if ( strcasecmp( left, "attr" ) == 0 ) { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: \"attr\" " + "is deprecated (and undocumented); " + "use \"attrs\" instead.\n", + fname, lineno, 0 ); + } + a->acl_attrs = str2anlist( a->acl_attrs, right, "," ); if ( a->acl_attrs == NULL ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: unknown attr \"%s\" in to clause\n", fname, lineno, right ); acl_usage(); @@ -462,16 +476,16 @@ parse_acl( char *mr; if ( !BER_BVISEMPTY( &a->acl_attrval ) ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: attr val already specified in to clause.\n", - fname, lineno ); + fname, lineno, 0 ); acl_usage(); } if ( a->acl_attrs == NULL || !BER_BVISEMPTY( &a->acl_attrs[1].an_name ) ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: attr val requires a single attribute.\n", - fname, lineno ); + fname, lineno, 0 ); acl_usage(); } @@ -485,7 +499,7 @@ parse_acl( a->acl_attrval_mr = mr_find( mr ); if ( a->acl_attrval_mr == NULL ) { - fprintf( stderr, "%s: line %d: " + Debug( LDAP_DEBUG_ANY, "%s: line %d: " "invalid matching rule \"%s\".\n", fname, lineno, mr ); acl_usage(); @@ -493,11 +507,16 @@ parse_acl( if( !mr_usable_with_at( a->acl_attrval_mr, a->acl_attrs[ 0 ].an_desc->ad_type ) ) { - fprintf( stderr, "%s: line %d: " + char buf[ SLAP_TEXT_BUFLEN ]; + + snprintf( buf, sizeof( buf ), "matching rule \"%s\" use " - "with attr \"%s\" not appropriate.\n", - fname, lineno, mr, - a->acl_attrs[ 0 ].an_name.bv_val ); + "with attr \"%s\" not appropriate.", + mr, a->acl_attrs[ 0 ].an_name.bv_val ); + + + Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n", + fname, lineno, buf ); acl_usage(); } } @@ -507,11 +526,17 @@ parse_acl( int e = regcomp( &a->acl_attrval_re, a->acl_attrval.bv_val, REG_EXTENDED | REG_ICASE | REG_NOSUB ); if ( e ) { - char buf[512]; - regerror( e, &a->acl_attrval_re, buf, sizeof(buf) ); - fprintf( stderr, "%s: line %d: " - "regular expression \"%s\" bad because of %s\n", - fname, lineno, right, buf ); + char err[SLAP_TEXT_BUFLEN], + buf[ SLAP_TEXT_BUFLEN ]; + + regerror( e, &a->acl_attrval_re, err, sizeof( err ) ); + + snprintf( buf, sizeof( buf ), + "regular expression \"%s\" bad because of %s", + right, err ); + + Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n", + fname, lineno, buf ); acl_usage(); } a->acl_attrval_style = ACL_STYLE_REGEX; @@ -543,33 +568,61 @@ parse_acl( } else if ( !strcasecmp( style, "children" ) ) { a->acl_attrval_style = ACL_STYLE_CHILDREN; } else { - fprintf( stderr, - "%s: line %d: unknown val.