+dnl Check if we can directly use Kerberos 5 API, used for reading keytabs
+dnl and automatically construction DirectoryService names from that, instead
+dnl of requiring special configuration in afp.conf
+AC_DEFUN([AC_NETATALK_KERBEROS], [
+AC_MSG_CHECKING([for Kerberos 5 (necessary for GetSrvrInfo:DirectoryNames support)])
+AC_ARG_WITH([kerberos],
+ [AS_HELP_STRING([--with-kerberos], [Kerberos 5 support (default=auto)])],
+ [],
+ [with_kerberos=auto])
+AC_MSG_RESULT($with_kerberos)
+
+if test x"$with_kerberos" != x"no"; then
+ have_krb5_header="no"
+ AC_CHECK_HEADERS([krb5/krb5.h krb5.h], [have_krb5_header="yes"; break])
+ if test x"$have_krb5_header" = x"no" && test x"$with_kerberos" != x"auto"; then
+ AC_MSG_FAILURE([--with-kerberos was given, but no headers found])
+ fi
+
+ AC_PATH_PROG([KRB5_CONFIG], [krb5-config])
+ AC_MSG_CHECKING([for krb5-config])
+ if test -x "$KRB5_CONFIG"; then
+ AC_MSG_RESULT([$KRB5_CONFIG])
+ KRB5_CFLAGS="`$KRB5_CONFIG --cflags krb5`"
+ KRB5_LIBS="`$KRB5_CONFIG --libs krb5`"
+ AC_SUBST(KRB5_CFLAGS)
+ AC_SUBST(KRB5_LIBS)
+ with_kerberos="yes"
+ else
+ AC_MSG_RESULT([not found])
+ if test x"$with_kerberos" != x"auto"; then
+ AC_MSG_FAILURE([--with-kerberos was given, but krb5-config could not be found])
+ fi
+ fi
+fi
+
+if test x"$with_kerberos" = x"yes"; then
+ AC_DEFINE([HAVE_KERBEROS], [1], [Define if Kerberos 5 is available])
+fi
+
+dnl Check for krb5_free_unparsed_name and krb5_free_error_message
+save_CFLAGS="$CFLAGS"
+save_LIBS="$LIBS"
+CFLAGS="$KRB5_CFLAGS"
+LIBS="$KRB5_LIBS"
+AC_CHECK_FUNCS([krb5_free_unparsed_name krb5_free_error_message])
+CFLAGS="$save_CFLAGS"
+LIBS="$save_LIBS"
+])
+