Ethereal-dev: Re: [Ethereal-dev] Re: Preliminary heimdal autoconf support

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Joerg Mayer <jmayer@xxxxxxxxx>
Date: Mon, 15 Mar 2004 12:57:48 +0100
Ronnie,

I hope this patch addresses the problems you mentioned and does not
create too many new ones :-)
Still todo: Proper MIT Kerberos detection - but it seems that this
isn't too iomportant due to lack of MIT kerberos code.

  Ciao
     Jörg
-- 
Joerg Mayer                                           <jmayer@xxxxxxxxx>
We are stuck with technology when what we really want is just stuff that
works. Some say that should read Microsoft instead of technology.
Index: acinclude.m4
===================================================================
RCS file: /usr/local/cvsroot/ethereal/acinclude.m4,v
retrieving revision 1.68
diff -p -u -r1.68 acinclude.m4
--- acinclude.m4	26 Feb 2004 09:39:43 -0000	1.68
+++ acinclude.m4	15 Mar 2004 11:52:15 -0000
@@ -849,3 +849,120 @@ changequote([, ])dnl
 		AC_MSG_RESULT(not required)
 	fi
 ])
+
+
+#
+# AC_ETHEREAL_KRB5_CHECK
+#
+AC_DEFUN(AC_ETHEREAL_KRB5_CHECK,
+[
+	if test "x$krb5_dir" != "x"
+	then
+	  #
+	  # The user specified a directory in which kerberos resides,
+	  # so add the "include" subdirectory of that directory to
+	  # the include file search path and the "lib" subdirectory
+	  # of that directory to the library search path.
+	  #
+	  # XXX - if there's also a kerberos in a directory that's
+	  # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
+	  # make us find the version in the specified directory,
+	  # as the compiler and/or linker will search that other
+	  # directory before it searches the specified directory.
+	  #
+	  ethereal_save_CFLAGS="$CFLAGS"
+	  CFLAGS="$CFLAGS -I$krb5_dir/include"
+	  ethereal_save_CPPFLAGS="$CPPFLAGS"
+	  CPPFLAGS="$CPPFLAGS -I$krb5_dir/include"
+	  ethereal_save_LIBS="$LIBS"
+	  LIBS="$LIBS -lkrb5 -lasn1 -lcrypto -lroken -lcrypt -lresolv"
+	  ethereal_save_LDFLAGS="$LDFLAGS"
+	  LDFLAGS="$LDFLAGS -L$krb5_dir/lib"
+	else
+	  AC_PATH_PROG(KRB5_CONFIG, krb5-config) 
+	  if test -x $KRB5_CONFIG
+	  then
+	    KRB5_FLAGS=`$KRB5_CONFIG --cflags`
+	    CFLAGS="$CFLAGS $KRB5_FLAGS"
+            CPPFLAGS="$CPPFLAGS $KRB5_FLAGS"
+	    KRB5_LIBS=`$KRB5_CONFIG --libs`
+	    LIBS="$LIBS $KRB5_LIBS"
+	    ac_krb5_version=`$KRB5_CONFIG --version | head -n 1 | sed 's/^.*heimdal.*$/HEIMDAL/i'`
+ 	  fi
+	fi
+
+	#
+	# Make sure we have "krb5.h".  If we don't, it means we probably
+	# don't have kerberos, so don't use it.
+	#
+	AC_CHECK_HEADER(krb5.h,,
+	  [
+	    if test "x$krb5_dir" != "x"
+	    then
+	      #
+	      # The user used "--with-krb5=" to specify a directory
+	      # containing kerberos, but we didn't find the header file
+	      # there; that either means they didn't specify the
+	      # right directory or are confused about whether kerberos
+	      # is, in fact, installed.  Report the error and give up.
+	      #
+	      AC_MSG_ERROR([kerberos header not found in directory specified in --with-krb5])
+	    else
+	      if test "x$want_krb5" = "xyes"
+	      then
+		#
+		# The user tried to force us to use the library, but we
+		# couldn't find the header file; report an error.
+		#
+		AC_MSG_ERROR(Header file krb5.h not found.)
+	      else
+		#
+		# We couldn't find the header file; don't use the
+		# library, as it's probably not present.
+		#
+		want_krb5=no
+	      fi
+	    fi
+	  ])
+
+	if test "x$want_krb5" != "xno" -a "x$ac_krb5_version" = "xHEIMDAL"
+	then
+		#
+		# Well, we at least have the krb5 header file.
+		#
+		AC_CHECK_LIB(krb5, krb5_kt_resolve,
+		[
+			if test "x$krb5_dir" != "x"
+			then
+				#
+				# Put the "-I" and "-L" flags for pcre at
+				# the beginning of CFLAGS, CPPFLAGS,
+				# LDFLAGS, and LIBS.
+				#
+				KRB5_LIBS="-L$krb5_dir/lib $KRB5_LIBS"
+			fi
+			AC_DEFINE(HAVE_KERBEROS, 1, [Define to use kerberos])
+			AC_DEFINE(HAVE_HEIMDAL_KERBEROS, 1, [Define to use heimdal kerberos])
+		],[
+			if test "x$krb5_dir" != "x"
+			then
+				#
+				# Restore the versions of CFLAGS, CPPFLAGS,
+				# LDFLAGS, and LIBS before we added the
+				# "--with-krb5=" directory, as we didn't
+				# actually find kerberos there.
+				#
+				CFLAGS="$ethereal_save_CFLAGS"
+				CPPFLAGS="$ethereal_save_CPPFLAGS"
+				LDFLAGS="$ethereal_save_LDFLAGS"
+				LIBS="$ethereal_save_LIBS"
+				KRB5_LIBS=""
+			fi
+			want_krb5=no
+		])
+		AC_SUBST(KRB5_LIBS)
+	else
+		want_krb5=no
+	fi
+])
+
Index: configure.in
===================================================================
RCS file: /usr/local/cvsroot/ethereal/configure.in,v
retrieving revision 1.250
diff -p -u -r1.250 configure.in
--- configure.in	4 Mar 2004 06:28:42 -0000	1.250
+++ configure.in	15 Mar 2004 11:52:18 -0000
@@ -701,6 +701,43 @@ fi
 
 AC_SUBST(SNMP_LIBS)
 
+
+dnl kerberos/heimdal check
+AC_MSG_CHECKING(whether to use kerberos/heimdal)
+
+AC_ARG_WITH(krb5,
+changequote(<<, >>)dnl
+<<  --with-krb5[=DIR]       use kerberos/heimdal (located in directory DIR, if supplied) to use in kerberos dissection  [default=no]>>,
+changequote([, ])dnl
+[
+	if test $withval = no
+	then
+		want_krb5=no
+	elif test $withval = yes
+	then
+		want_krb5=yes
+	else
+		want_krb5=no
+		krb5_dir=$withval
+	fi
+],[
+	#
+	# Use kerberos/heimdal if it's present, otherwise don't.
+	#
+	want_krb5=no
+	krb5_dir=
+])
+if test "x$want_krb5" = "xno" ; then
+        AC_MSG_RESULT(no)
+else
+        AC_MSG_RESULT(yes)
+        AC_ETHEREAL_KRB5_CHECK
+	if test "x$want_krb5" = "xno" ; then
+		AC_MSG_RESULT(heimdal not found - disabling dissection for some kerberos data in packet decoding)
+	fi
+fi
+
+
 dnl ADNS Check
 ADNS_LIBS=''
 AC_MSG_CHECKING(whether to use the GNU ADNS library if available)
@@ -916,6 +953,12 @@ else
 	pcre_message="yes"
 fi
 
+if test "x$want_krb5" = "xno" ; then
+	krb5_message="no"
+else
+	krb5_message="yes (heimdal)"
+fi
+
 if test "x$have_good_adns" = "xyes" ; then
 	adns_message="yes"
 else
@@ -951,6 +994,7 @@ fi
 echo "                  Use pcap library : $want_pcap"
 echo "                  Use zlib library : $zlib_message"
 echo "                  Use pcre library : $pcre_message"
+echo "              Use kerberos library : $krb5_message"
 echo "              Use GNU ADNS library : $adns_message"
 echo "          Use IPv6 name resolution : $enable_ipv6"
 echo "     Use UCD SNMP/NET-SNMP library : $snmp_libs_message"
Index: epan/Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/ethereal/epan/Makefile.am,v
retrieving revision 1.40
diff -p -u -r1.40 Makefile.am
--- epan/Makefile.am	13 Mar 2004 10:15:35 -0000	1.40
+++ epan/Makefile.am	15 Mar 2004 11:52:50 -0000
@@ -119,7 +119,7 @@ MAINTAINERCLEANFILES =	\
 #
 # Add the object files for missing routines, if any.
 #
-libethereal_la_LIBADD = @INET_ATON_O@ @INET_PTON_O@ @INET_NTOP_O@ dfilter/libdfilter.la ftypes/libftypes.la
+libethereal_la_LIBADD = @INET_ATON_O@ @INET_PTON_O@ @INET_NTOP_O@ dfilter/libdfilter.la ftypes/libftypes.la @KRB5_LIBS@
 libethereal_la_DEPENDENCIES = @INET_ATON_O@ @INET_PTON_O@ @INET_NTOP_O@ dfilter/libdfilter.la ftypes/libftypes.la
 
 ../packet-ncp2222.c : $(srcdir)/../ncp2222.py
Index: epan/acinclude.m4
===================================================================
RCS file: /usr/local/cvsroot/ethereal/epan/acinclude.m4,v
retrieving revision 1.6
diff -p -u -r1.6 acinclude.m4
--- epan/acinclude.m4	17 Dec 2003 02:41:04 -0000	1.6
+++ epan/acinclude.m4	15 Mar 2004 11:52:50 -0000
@@ -288,3 +288,120 @@ AC_DEFUN(AC_ETHEREAL_LIBPCRE_CHECK,
 		AC_SUBST(PCRE_LIBS)
 	fi
 ])
+
+
+#
+# AC_ETHEREAL_KRB5_CHECK
+#
+AC_DEFUN(AC_ETHEREAL_KRB5_CHECK,
+[
+	if test "x$krb5_dir" != "x"
+	then
+	  #
+	  # The user specified a directory in which kerberos resides,
+	  # so add the "include" subdirectory of that directory to
+	  # the include file search path and the "lib" subdirectory
+	  # of that directory to the library search path.
+	  #
+	  # XXX - if there's also a kerberos in a directory that's
+	  # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
+	  # make us find the version in the specified directory,
+	  # as the compiler and/or linker will search that other
+	  # directory before it searches the specified directory.
+	  #
+	  ethereal_save_CFLAGS="$CFLAGS"
+	  CFLAGS="$CFLAGS -I$krb5_dir/include"
+	  ethereal_save_CPPFLAGS="$CPPFLAGS"
+	  CPPFLAGS="$CPPFLAGS -I$krb5_dir/include"
+	  ethereal_save_LIBS="$LIBS"
+	  LIBS="$LIBS -lkrb5 -lasn1 -lcrypto -lroken -lcrypt -lresolv"
+	  ethereal_save_LDFLAGS="$LDFLAGS"
+	  LDFLAGS="$LDFLAGS -L$krb5_dir/lib"
+	else
+	  AC_PATH_PROG(KRB5_CONFIG, krb5-config) 
+	  if test -x $KRB5_CONFIG
+	  then
+	    KRB5_FLAGS=`$KRB5_CONFIG --cflags`
+	    CFLAGS="$CFLAGS $KRB5_FLAGS"
+            CPPFLAGS="$CPPFLAGS $KRB5_FLAGS"
+	    KRB5_LIBS=`$KRB5_CONFIG --libs`
+	    LIBS="$LIBS $KRB5_LIBS"
+	    ac_krb5_version=`$KRB5_CONFIG --version | head -n 1 | sed 's/^.*heimdal.*$/HEIMDAL/i'`
+ 	  fi
+	fi
+
+	#
+	# Make sure we have "krb5.h".  If we don't, it means we probably
+	# don't have kerberos, so don't use it.
+	#
+	AC_CHECK_HEADER(krb5.h,,
+	  [
+	    if test "x$krb5_dir" != "x"
+	    then
+	      #
+	      # The user used "--with-krb5=" to specify a directory
+	      # containing kerberos, but we didn't find the header file
+	      # there; that either means they didn't specify the
+	      # right directory or are confused about whether kerberos
+	      # is, in fact, installed.  Report the error and give up.
+	      #
+	      AC_MSG_ERROR([kerberos header not found in directory specified in --with-krb5])
+	    else
+	      if test "x$want_krb5" = "xyes"
+	      then
+		#
+		# The user tried to force us to use the library, but we
+		# couldn't find the header file; report an error.
+		#
+		AC_MSG_ERROR(Header file krb5.h not found.)
+	      else
+		#
+		# We couldn't find the header file; don't use the
+		# library, as it's probably not present.
+		#
+		want_krb5=no
+	      fi
+	    fi
+	  ])
+
+	if test "x$want_krb5" != "xno" -a "x$ac_krb5_version" = "xHEIMDAL"
+	then
+		#
+		# Well, we at least have the krb5 header file.
+		#
+		AC_CHECK_LIB(krb5, krb5_kt_resolve,
+		[
+			if test "x$krb5_dir" != "x"
+			then
+				#
+				# Put the "-I" and "-L" flags for pcre at
+				# the beginning of CFLAGS, CPPFLAGS,
+				# LDFLAGS, and LIBS.
+				#
+				KRB5_LIBS="-L$krb5_dir/lib $KRB5_LIBS"
+			fi
+			AC_DEFINE(HAVE_KERBEROS, 1, [Define to use kerberos])
+			AC_DEFINE(HAVE_HEIMDAL_KERBEROS, 1, [Define to use heimdal kerberos])
+		],[
+			if test "x$krb5_dir" != "x"
+			then
+				#
+				# Restore the versions of CFLAGS, CPPFLAGS,
+				# LDFLAGS, and LIBS before we added the
+				# "--with-krb5=" directory, as we didn't
+				# actually find kerberos there.
+				#
+				CFLAGS="$ethereal_save_CFLAGS"
+				CPPFLAGS="$ethereal_save_CPPFLAGS"
+				LDFLAGS="$ethereal_save_LDFLAGS"
+				LIBS="$ethereal_save_LIBS"
+				KRB5_LIBS=""
+			fi
+			want_krb5=no
+		])
+		AC_SUBST(KRB5_LIBS)
+	else
+		want_krb5=no
+	fi
+])
+
Index: epan/configure.in
===================================================================
RCS file: /usr/local/cvsroot/ethereal/epan/configure.in,v
retrieving revision 1.66
diff -p -u -r1.66 configure.in
--- epan/configure.in	13 Mar 2004 10:15:35 -0000	1.66
+++ epan/configure.in	15 Mar 2004 11:52:53 -0000
@@ -178,6 +178,43 @@ else
 	AC_ETHEREAL_IPV6_STACK
 fi
 
+
+dnl kerberos/heimdal check
+AC_MSG_CHECKING(whether to use kerberos/heimdal)
+
+AC_ARG_WITH(krb5,
+changequote(<<, >>)dnl
+<<  --with-krb5[=DIR]       use kerberos/heimdal (located in directory DIR, if supplied) to use in kerberos dissection  [default=no]>>,
+changequote([, ])dnl
+[
+	if test $withval = no
+	then
+		want_krb5=no
+	elif test $withval = yes
+	then
+		want_krb5=yes
+	else
+		want_krb5=no
+		krb5_dir=$withval
+	fi
+],[
+	#
+	# Use kerberos/heimdal if it's present, otherwise don't.
+	#
+	want_krb5=no
+	krb5_dir=
+])
+if test "x$want_krb5" = "xno" ; then
+        AC_MSG_RESULT(no)
+else
+        AC_MSG_RESULT(yes)
+        AC_ETHEREAL_KRB5_CHECK
+	if test "x$want_krb5" = "xno" ; then
+		AC_MSG_RESULT(heimdal not found - disabling dissection for some kerberos data in packet decoding)
+	fi
+fi
+
+
 AC_CHECK_FUNC(inet_aton, INET_ATON_O="",
   INET_ATON_O="inet_aton.lo")
 if test "$ac_cv_func_inet_aton" = no ; then