fixed threading issues as described in ticket [ 1971514 ]
[mod_auth_kerb.git] / configure.in
1 # Process this file with autoconf to produce a configure script.
2 AC_REVISION($Revision$)
3 AC_PREREQ(2.57)
4 AC_INIT(mod_auth_kerb, 5.3, modauthkerb-developers@lists.sourceforge.net)
5 AC_CONFIG_SRCDIR([src/mod_auth_kerb.c])
6 AC_CONFIG_HEADER([config.h])
7
8 # Checks for programs.
9 AC_PROG_CC
10 AC_PROG_MAKE_SET
11
12 # Checks for libraries.
13 # FIXME: Replace `main' with a function in `-lresolv':
14 LIB_resolv=""
15 AC_CHECK_LIB([resolv], [main], [LIB_resolv=-lresolv])
16 AC_SUBST(LIB_resolv)
17
18 # Checks for header files.
19 AC_HEADER_STDC
20 AC_CHECK_HEADERS([limits.h netdb.h stddef.h stdlib.h string.h unistd.h])
21
22 # Checks for typedefs, structures, and compiler characteristics.
23 #AC_C_CONST
24 AC_TYPE_SIZE_T
25 AC_STRUCT_TM
26
27 # Checks for library functions.
28 #AC_FUNC_MALLOC
29 #AC_FUNC_MEMCMP
30 #AC_CHECK_FUNCS([gethostbyname memset putenv strcasecmp strchr strdup strerror])
31
32 #
33 # kerberos5 enviroment
34 #
35 krb5_config_command=krb5-config
36 SPNEGO_SRCS=""
37
38 AC_ARG_WITH(krb5,
39   AC_HELP_STRING([--with-krb5=dir],[use krb5 in dir]),
40   [ with_krb5="$withval" ])
41
42 if test "x$with_krb5" != "xno" ; then
43   ac_save_CPPFLAGS="$CPPFLAGS"
44   ac_save_LDFLAGS="$LDFLAGS"
45   ac_save_LIBS="$LIBS"
46    
47   if test -n "$with_krb5"; then
48      if test -x "$with_krb5/bin/krb5-config"; then
49         krb5_config_command="$with_krb5/bin/krb5-config"
50      else
51         krb5_config_command=""
52      fi
53   fi
54
55   dnl
56   dnl find header files
57   dnl
58
59   if test -z "$KRB5_CPPFLAGS"; then
60      TMP_KRB5_CPPFLAGS=""
61      if test -n "$krb5_config_command"; then
62         TMP_KRB5_CPPFLAGS=`$krb5_config_command --cflags gssapi 2>/dev/null`
63      fi
64      if test -z "$TMP_KRB5_CPPFLAGS"; then
65         TMP_KRB5_CPPFLAGS="-I$with_krb5/include"
66      fi
67      CPPFLAGS="$CPPFLAGS $TMP_KRB5_CPPFLAGS"
68      AC_CHECK_HEADERS(gssapi.h, 
69                       [ KRB5_CPPFLAGS="$TMP_KRB5_CPPFLAGS" ])
70      if test -z "$KRB5_CPPFLAGS"; then
71         AC_CHECK_HEADERS(gssapi/gssapi.h, 
72                          [ KRB5_CPPFLAGS="$TMP_KRB5_CPPFLAGS" ])
73      fi
74      CPPFLAGS="$ac_save_CPPFLAGS" 
75   fi
76
77   dnl
78   dnl find libraries
79   dnl
80
81   if test -z "$KRB5_LDFLAGS" -a -n "$krb5_config_command"; then
82      TMP_KRB5_LDFLAGS=`$krb5_config_command --libs gssapi 2>/dev/null`
83      if test -n "$TMP_KRB5_LDFLAGS"; then
84         LIBS="$LIBS $TMP_KRB5_LDFLAGS $LIB_resolv"
85         AC_CHECK_LIB(krb5, krb5_init_context,
86                      [ KRB5_LDFLAGS="$TMP_KRB5_LDFLAGS" ])
87         LIBS="$ac_save_LIBS"
88      fi
89   fi
90
91   if test -z "$KRB5_LDFLAGS"; then
92      #try MIT
93      TMP_KRB5_LDFLAGS="-L$with_krb5/lib -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err"
94      LIBS="$LIBS $TMP_KRB5_LDFLAGS $LIB_resolv"
95      AC_CHECK_LIB(krb5, krb5_init_context, [ KRB5_LDFLAGS="$TMP_KRB5_LDFLAGS" ])
96      LIBS="$ac_save_LIBS"
97   fi
98
99   if test -z "$KRB5_LDFLAGS"; then
100      #Try Heimdal
101      TMP_KRB5_LDFLAGS="-L$with_krb5/lib -lgssapi -lkrb5 -lasn1 -lcrypto -lroken -lcrypt"
102      LIBS="$LIBS $TMP_KRB5_LDFLAGS $LIB_resolv"
103      AC_CHECK_LIB(krb5, krb5_init_context, [ KRB5_LDFLAGS="$TMP_KRB5_LDFLAGS" ])
104      LIBS="$ac_save_LIBS"
105   fi
106
107   if test -z "$KRB5_LDFLAGS"; then
108      #Try Heimdal on OpenBSD
109      TMP_KRB5_LDFLAGS="-L$with_krb5/lib -lgssapi -lkrb5 -lasn1 -ldes -lcrypto"
110      LIBS="$LIBS $TMP_KRB5_LDFLAGS $LIB_resolv"
111      AC_CHECK_LIB(krb5, krb5_init_context, [ KRB5_LDFLAGS="$TMP_KRB5_LDFLAGS" ])
112      LIBS="$ac_save_LIBS"
113   fi
114
115   if test -z "$KRB5_LDFLAGS"; then
116      with_krb5=no
117   else
118      with_krb5=yes
119      AC_DEFINE(KRB5)
120      AC_CHECK_LIB(krb5,
121                   krb5_cc_new_unique,
122                   [ AC_DEFINE(HAVE_KRB5_CC_NEW_UNIQUE) ])
123
124      # check for Heimdal
125      have_heimdal=""
126      AC_MSG_CHECKING(whether we are using Heimdal)
127      ac_save_CFLAGS="$CFLAGS"
128      CFLAGS="$KRB5_CPPFLAGS"
129      AC_TRY_COMPILE([#include <krb5.h>],
130                     [ char *tmp = heimdal_version; ],
131                     [ AC_MSG_RESULT(yes)
132                       AC_DEFINE(HEIMDAL)
133                       have_heimdal=yes ],
134                     [ AC_MSG_RESULT(no) ])
135      CFLAGS="$ac_save_CFLAGS"
136
137 # If SPNEGO is supported by the gssapi libraries, we shouln't build our support.
138 # SPNEGO is supported as of Heimdal 0.7, and MIT 1.5.
139      gssapi_supports_spnego=""
140      AC_MSG_CHECKING(whether the GSSAPI libraries support SPNEGO)
141
142      ac_save_CFLAGS="$CFLAGS"
143      CFLAGS="$KRB5_CPPFLAGS"
144      ac_save_LDFLAGS="$LDFLAGS"
145      LDFLAGS=$KRB5_LDFLAGS
146
147      AC_TRY_RUN([
148 #include <string.h>
149 #include <krb5.h>
150 #ifdef HEIMDAL
151 #include <gssapi.h>
152 #else
153 #include <gssapi/gssapi.h>
154 #endif
155 int main(int argc, char** argv)
156 {
157        OM_uint32 major_status, minor_status;
158        gss_OID_set mech_set;
159        gss_OID_desc spnego_oid_desc = {6, (void *)"\x2b\x06\x01\x05\x05\x02"};
160        int SPNEGO = 0;
161                                                                                
162        major_status = gss_indicate_mechs(&minor_status, &mech_set);
163        if (GSS_ERROR(major_status))
164                return 1;
165        else {
166                unsigned int i;
167                for (i=0; i < mech_set->count && !SPNEGO; i++) {
168                        gss_OID tmp_oid = &mech_set->elements[i];
169                       if (tmp_oid->length == spnego_oid_desc.length &&
170                            !memcmp(tmp_oid->elements, spnego_oid_desc.elements, 
171                                    tmp_oid->length)) {
172                                SPNEGO = 1;
173                                break;
174                        }
175                }
176                gss_release_oid_set(&minor_status, &mech_set);
177                return (!SPNEGO);
178        }
179 }],
180                 [ if test $? -eq 0; then 
181                      AC_MSG_RESULT(yes)
182                      AC_DEFINE(GSSAPI_SUPPORTS_SPNEGO)
183                      gssapi_supports_spnego=yes 
184                   else
185                      AC_MSG_RESULT(no)
186                   fi],
187                 [AC_MSG_RESULT(no)])
188
189      CFLAGS="$ac_save_CFLAGS"
190      LDFLAGS="$ac_save_LDFLAGS"
191
192      if test -z "$gssapi_supports_spnego"; then
193         if test -n "$have_heimdal"; then SPNEGO_SRCS="\
194                 spnegokrb5/asn1_MechType.c         \
195                 spnegokrb5/asn1_MechTypeList.c     \
196                 spnegokrb5/asn1_ContextFlags.c     \
197                 spnegokrb5/asn1_NegTokenInit.c     \
198                 spnegokrb5/asn1_NegTokenTarg.c     \
199                 spnegokrb5/init_sec_context.c      \
200                 spnegokrb5/accept_sec_context.c    \
201                 spnegokrb5/encapsulate.c           \
202                 spnegokrb5/decapsulate.c           \
203                 spnegokrb5/external.c"
204         else SPNEGO_SRCS="\
205                 spnegokrb5/asn1_MechType.c         \
206                 spnegokrb5/asn1_MechTypeList.c     \
207                 spnegokrb5/asn1_ContextFlags.c     \
208                 spnegokrb5/asn1_NegTokenInit.c     \
209                 spnegokrb5/asn1_NegTokenTarg.c     \
210                 spnegokrb5/der_get.c               \
211                 spnegokrb5/der_put.c               \
212                 spnegokrb5/der_free.c              \
213                 spnegokrb5/der_length.c            \
214                 spnegokrb5/der_copy.c              \
215                 spnegokrb5/timegm.c                \
216                 spnegokrb5/init_sec_context.c      \
217                 spnegokrb5/accept_sec_context.c    \
218                 spnegokrb5/encapsulate.c           \
219                 spnegokrb5/decapsulate.c           \
220                 spnegokrb5/external.c"
221         fi
222      fi
223   fi
224 fi
225 AC_SUBST(KRB5_CPPFLAGS)
226 AC_SUBST(KRB5_LDFLAGS)
227 AC_SUBST(SPNEGO_SRCS)
228
229 #
230 # Kerberos4 enviroment
231 #
232
233 AC_ARG_WITH(krb4,
234   AC_HELP_STRING([--with-krb4=dir], [use krb4 in dir]),
235   [ with_krb4="$withval" ])
236
237 if test "x$with_krb4" != "xno"; then
238   AC_MSG_CHECKING([for Kerberos4 installation])
239   if test "x$with_krb4" != "x"; then
240      if test -x "$with_krb4/bin/krb4-config"; then
241         KRB4_CPPFLAGS=`$with_krb4/bin/krb4-config --cflags krb4 2>/dev/null`
242         KRB4_LDFLAGS=`$with_krb4/bin/krb4-config --libs krb4 2>/dev/null`
243      elif test -x "$with_krb4/bin/krb5-config"; then
244         KRB4_CPPFLAGS=`$with_krb4/bin/krb5-config --cflags krb4 2>/dev/null`
245         KRB4_LDFLAGS=`$with_krb4/bin/krb5-config --libs krb4 2>/dev/null`
246      else
247         AC_MSG_ERROR([failed to find krb4-config or krb5-config in $with_krb4/bin])
248      fi
249   else
250      KRB4_CPPFLAGS=`krb4-config --cflags krb4 2>/dev/null`
251      KRB4_LDFLAGS=`krb4-config --libs krb4 2>/dev/null`
252      if test "x$KRB4_LDFLAGS" = "x" -a -n "$krb5_config_command"; then
253         KRB4_CPPFLAGS=`$krb5_config_command --cflags krb4 2>/dev/null`
254         KRB4_LDFLAGS=`$krb5_config_command --libs krb4 2>/dev/null`
255         if test $? -ne 0; then
256            KRB4_CPPFLAGS=""
257            KRB4_LDFLAGS=""
258         fi
259      fi
260   fi
261   if test "x$KRB4_LDFLAGS" = "x"; then
262      with_krb4=no
263      AC_MSG_RESULT(no)
264   else
265      AC_MSG_RESULT(yes)
266
267      ac_save_CFLAGS=$CFLAGS
268      ac_save_CPPFLAGS=$CPPFLAGS
269      ac_save_LDFLAGS=$LDFLAGS
270      ac_save_LIBS=$LIBS
271      CFLAGS="$CFLAGS $KRB4_CPPFLAGS"
272      CPPFLAGS="$CFLAGS $KRB4_CPPFLAGS"
273      LDFLAGS="$LDFLAGS $KRB4_LDFLAGS"
274      LIBS="$LIBS $LDFLAGS $LIB_resolv"
275
276 #    if not found krb.h suppose it's in the kerberosIV subdirectory
277      AC_CHECK_HEADER(krb.h, , with_krb4=no)
278      if test "x$with_krb4" = "xno"; then
279          KRB4_CPPFLAGS="$KRB4_CPPFLAGS ${KRB4_CPPFLAGS}/kerberosIV"
280 #        second run of AC_CHECK_HEADER for the same library returns the cached
281 #        result created by previous run :-(
282          AC_CHECK_HEADER(kerberosIV/krb.h, with_krb4=yes,
283                          [  with_krb4=no
284                             KRB4_CPPFLAGS=""
285                             KRB4_LDFLAGS=""])
286      fi
287
288      if test "x$with_krb4" != "xno"; then
289         AC_CHECK_LIB(krb4, krb_get_pw_in_tkt, [], [with_krb4=no])
290         if test "x$with_krb4" = "xno"; then
291            AC_CHECK_LIB(krb, krb_get_pw_in_tkt, [with_krb4=yes], 
292                         [with_krb4=no
293                          KRB4_CPPFLAGS=""
294                          KRB4_LDFLAGS=""])
295         fi
296      fi
297
298      CFLAGS=$ac_save_CFLAGS
299      CPPFLAGS=$ac_save_CPPFLAGS
300      LDFLAGS=$ac_save_LDFLAGS
301      LIBS=$ac_save_LIBS
302
303      AC_DEFINE(KRB4)
304   fi
305 fi
306 AC_SUBST(KRB4_CPPFLAGS)
307 AC_SUBST(KRB4_LDFLAGS)
308
309
310 if test "x$with_krb5" = "xno" -a "x$with_krb4" = "xno"; then
311   AC_MSG_ERROR([No Kerberos enviroment found])
312 fi
313
314 #
315 # Apache enviroment
316 #
317 AC_ARG_WITH(apache,
318   AC_HELP_STRING([--with-apache=dir],[use apache in dir]),
319   [ with_apache="$withval" ])
320
321 AC_PATH_PROG([APXS], [apxs], [], [$with_apache/bin:$with_apache/sbin:$PATH])
322 if test -z "$APXS"; then
323    AC_PATH_PROG([APXS], [apxs2], [], [$with_apache/bin:$with_apache/sbin:$PATH])
324    if test -z "$APXS"; then
325       AC_MSG_ERROR([failed to find apache apxs executable])
326    fi
327 fi
328 AC_SUBST(APXS)
329
330 AC_CONFIG_FILES([Makefile])
331
332 AC_OUTPUT