Hi,

Kerberos 1.11 introduced a new configuration variable to override the default location of the credential cache at build time. Fedora 18 and up have used this new configuration variable to define an alternate default cache location (/run/user/$UID/krb5cc/tkt). This bug was initially reported against Fedora [1].

On Linux and Solaris systems, FileCredentialsCache.getDefaultCacheName() defaults to the previously hard-coded location (/tmp/krb5cc_$UID). This location will be incorrect if Kerberos was built with an alternative credential cache location set. Since this credential cache location can be arbitrary, we need to query the Kerberos API for the correct location. This patch implements this query using a new JNI call, which adds a dependency on libkrb5 for Linux and Solaris systems. I have also included a test case which uses a stub library in place of the real JNI libkrb5 wrapper.

The patch krb5-default-ccache should be applied to jdk8. This includes modifications to the build system in order to handle the dependency on libkrb5. These changes include querying pkg-config for the location of Kerberos includes and libraries, although there does not appear to be support for a libkrb5 pkg-config file just yet. An alternative program, krb5-config, operates similarly to pkg-config and prints the locations of the required libraries and includes. This program is included as part of Kerberos. This patch adds M4 macros to query krb5-config, and integrates these macros into libraries.m4. I have omitted generated-configure.sh for brevity.

The second patch jdk-krb5-default-ccache-fix should be applied to jdk8/jdk. This includes the changes to FileCredentialsCache and the new native component, krb5ccache.c. The library generated from it is named libj2krb5. This patch includes krb5-config support in jdk_generic_profile.sh. This will allow users of the old build system (and JDK7) to automatically find the necessary includes and libraries for Kerberos. For the test component, the patch includes a Makefile to build the stub library. The test should be run using the provided run_tests.sh shell script.

Thanks,
Elliott

[1] https://bugzilla.redhat.com/show_bug.cgi?id=991170
diff --git a/common/autoconf/build-aux/krb5.m4 b/common/autoconf/build-aux/krb5.m4
new file mode 100644
--- /dev/null
+++ b/common/autoconf/build-aux/krb5.m4
@@ -0,0 +1,154 @@
+# krb5.m4 - Macros to locate and utilise krb5-config.            -*- Autoconf -*-
+
+#
+# Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# 
+# Copyright © 2004 Scott James Remnant <[email protected]>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+#
+# This file was derived from pkg.m4.
+#
+
+# KRB5_PROG_KRB5_CONFIG()
+# ----------------------------------
+AC_DEFUN([KRB5_PROG_KRB5_CONFIG],
+[m4_pattern_forbid([^_KRB5_[A-Z_]+$])
+m4_pattern_allow([^KRB5_$])
+AC_ARG_VAR([KRB5_CONFIG], [path to krb5-config utility])dnl
+if test "x$ac_cv_env_KRB5_CONFIG_set" != "xset"; then
+	AC_PATH_TOOL([KRB5_CONFIG], [krb5-config])
+fi[]dnl
+])# KRB5_PROG_KRB5_CONFIG
+
+# KRB5_CHECK_EXISTS(LIBRARY, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+#
+# Check to see whether a particular library exists.  Similar
+# to KRB5_CHECK_LIBRARY(), but does not set variables or print errors.
+#
+#
+# Similar to KRB5_CHECK_LIBRARY, make sure that the first instance of
+# this or KRB5_CHECK_LIBRARY is called, or make sure to call
+# KRB5_CHECK_EXISTS manually
+# --------------------------------------------------------------
+AC_DEFUN([KRB5_CHECK_EXISTS],
+[AC_REQUIRE([KRB5_PROG_KRB5_CONFIG])dnl
+if test -n "$KRB5_CONFIG" && \
+    AC_RUN_LOG([$KRB5_CONFIG --version "$1" >/dev/null 2>&1]); then
+  m4_ifval([$2], [$2], [:])
+m4_ifvaln([$3], [else
+  $3])dnl
+fi])
+
+
+# _KRB5_CONFIG([VARIABLE], [COMMAND], [LIBRARY])
+# ---------------------------------------------
+m4_define([_KRB5_CONFIG],
+[if test -n "$$1"; then
+    lib_cv_[]$1="$$1"
+ elif test -n "$KRB5_CONFIG"; then
+    KRB5_CHECK_EXISTS([$3],
+                     [lib_cv_[]$1=`$KRB5_CONFIG --[]$2 "$3" 2>/dev/null`],
+		     [lib_failed=yes])
+ else
+    lib_failed=untried
+fi[]dnl
+])# _KRB5_CONFIG
+
+# KRB5_CHECK_LIBRARY(VARIABLE-PREFIX, LIBRARY, [ACTION-IF-FOUND],
+# [ACTION-IF-NOT-FOUND])
+#
+#
+# Note that if there is a possibility the first call to
+# KRB5_CHECK_LIBRARY might not happen, you should be sure to include an
+# explicit call to KRB5_PROG_KRB5_CONFIG in your configure.ac
+#
+#
+# --------------------------------------------------------------
+AC_DEFUN([KRB5_CHECK_LIBRARY],
+[AC_REQUIRE([KRB5_PROG_KRB5_CONFIG])dnl
+AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding krb5-config])dnl
+AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding krb5-config])dnl
+
+lib_failed=no
+AC_MSG_CHECKING([for $1 using krb5-config])
+
+_KRB5_CONFIG([$1][_CFLAGS], [cflags], [$2])
+_KRB5_CONFIG([$1][_LIBS], [libs], [$2])
+
+m4_define([_KRB5_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
+and $1[]_LIBS to avoid the need to call krb5-config.
+See the krb5-config man page for more details.])
+
+if test $lib_failed = yes; then
+	$1[]_KRB5_ERRORS=`$KRB5_CONFIG --version "$2" 2>&1`
+	# Put the nasty error message in config.log where it belongs
+	echo "$$1[]_KRB5_ERRORS" >&AS_MESSAGE_LOG_FD
+
+	ifelse([$4], , [AC_MSG_ERROR(dnl
+[Library requirements ($2) were not met:
+
+$$1_KRB5_ERRORS
+
+_KRB5_TEXT
+])],
+		[AC_MSG_RESULT([no])
+                $4])
+elif test $lib_failed = untried; then
+	ifelse([$4], , [AC_MSG_FAILURE(dnl
+[The krb5-config script could not be found.  Make sure it is in your PATH or
+set the KRB5_CONFIG environment variable to the full path to krb5-config.
+
+_KRB5_TEXT
+
+To get Kerberos, see <http://web.mit.edu/kerberos/>.])],
+		[$4])
+else
+	$1[]_CFLAGS=$lib_cv_[]$1[]_CFLAGS
+	$1[]_LIBS=$lib_cv_[]$1[]_LIBS
+        AC_MSG_RESULT([yes])
+	ifelse([$3], , :, [$3])
+fi[]dnl
+])# KRB5_CHECK_LIBRARY
diff --git a/common/autoconf/configure.ac b/common/autoconf/configure.ac
--- a/common/autoconf/configure.ac
+++ b/common/autoconf/configure.ac
@@ -35,6 +35,7 @@
 
 AC_CONFIG_AUX_DIR([build-aux])
 m4_include([build-aux/pkg.m4])
+m4_include([build-aux/krb5.m4])
 
 # Include these first...
 m4_include([basics.m4])
@@ -107,6 +108,9 @@
 # Check if pkg-config is available.
 PKG_PROG_PKG_CONFIG
 
+# Check if krb5-config is available.
+KRB5_PROG_KRB5_CONFIG
+
 # After basic tools have been setup, we can check build os specific details.
 PLATFORM_SETUP_OPENJDK_BUILD_OS_VERSION
 
@@ -182,6 +186,7 @@
 LIB_SETUP_CUPS
 LIB_SETUP_FREETYPE
 LIB_SETUP_ALSA
+LIB_SETUP_KRB5
 LIB_SETUP_MISC_LIBS
 LIB_SETUP_STATIC_LINK_LIBSTDCPP
 
diff --git a/common/autoconf/help.m4 b/common/autoconf/help.m4
--- a/common/autoconf/help.m4
+++ b/common/autoconf/help.m4
@@ -31,7 +31,7 @@
 AC_DEFUN([HELP_MSG_MISSING_DEPENDENCY],
 [
     # Print a helpful message on how to acquire the necessary build dependency.
-    # $1 is the help tag: freetyp2, cups, pulse, alsa etc
+    # $1 is the help tag: freetype2, cups, pulse, alsa, krb5 etc
     MISSING_DEPENDENCY=$1
     PKGHANDLER_COMMAND=
 
@@ -86,6 +86,8 @@
         PKGHANDLER_COMMAND="sudo apt-get install libX11-dev libxext-dev libxrender-dev libxtst-dev" ;;
     ccache)
         PKGHANDLER_COMMAND="sudo apt-get install ccache" ;;
+    krb5)
+        PKGHANDLER_COMMAND="sudo apt-get install libkrb5-dev" ;;
     * )
        break ;;
     esac
@@ -109,6 +111,8 @@
         PKGHANDLER_COMMAND="sudo yum install libXtst-devel" ;;
     ccache)
         PKGHANDLER_COMMAND="sudo yum install ccache" ;;
+    krb5)
+        PKGHANDLER_COMMAND="sudo yum install krb5-devel" ;;
     * )
        break ;;
     esac
diff --git a/common/autoconf/libraries.m4 b/common/autoconf/libraries.m4
--- a/common/autoconf/libraries.m4
+++ b/common/autoconf/libraries.m4
@@ -1,5 +1,6 @@
 #
 # Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -49,7 +50,8 @@
     ALSA_NOT_NEEDED=yes
     PULSE_NOT_NEEDED=yes
     X11_NOT_NEEDED=yes
-    AC_MSG_RESULT([alsa cups pulse x11])
+    KRB5_NOT_NEEDED=yes
+    AC_MSG_RESULT([alsa cups pulse x11 krb5])
 fi
 
 if test "x$OPENJDK_TARGET_OS" = xmacosx; then
@@ -58,14 +60,16 @@
     PULSE_NOT_NEEDED=yes
     X11_NOT_NEEDED=yes
     FREETYPE2_NOT_NEEDED=yes    
+    KRB5_NOT_NEEDED=yes
     # If the java runtime framework is disabled, then we need X11.
     # This will be adjusted below.
-    AC_MSG_RESULT([alsa pulse x11])
+    AC_MSG_RESULT([alsa pulse x11 krb5])
 fi
 
 if test "x$OPENJDK_TARGET_OS" = xbsd; then
     AC_MSG_CHECKING([what is not needed on bsd?])
     ALSA_NOT_NEEDED=yes
+    KRB5_NOT_NEEDED=yes
     AC_MSG_RESULT([alsa])    
 fi
 
@@ -484,6 +488,74 @@
 
 ])
 
+AC_DEFUN_ONCE([LIB_SETUP_KRB5],
+[
+
+###############################################################################
+#
+# Check for Kerberos headers and libraries. Used on Linux/GNU and Solaris systems.
+#
+AC_ARG_WITH(krb5, [AS_HELP_STRING([--with-krb5],
+	[specify prefix directory for the krb5 package
+	 (expecting the libraries under PATH/lib and the headers under PATH/include)])])
+AC_ARG_WITH(krb5-include, [AS_HELP_STRING([--with-krb5-include],
+	[specify directory for the krb5 include files])])
+AC_ARG_WITH(krb5-lib, [AS_HELP_STRING([--with-krb5-lib],
+	[specify directory for the krb5 library])])
+
+if test "x$KRB5_NOT_NEEDED" = xyes; then
+	if test "x${with_krb5}" != x || test "x${with_krb5_include}" != x || test "x${with_krb5_lib}" != x; then
+		AC_MSG_WARN([krb5 not used, so --with-krb5 is ignored])
+	fi
+	KRB5_CFLAGS=
+	KRB5_LIBS=
+else
+	KRB5_FOUND=no
+
+	if test "x${with_krb5}" = xno || test "x${with_krb5_include}" = xno || test "x${with_krb5_lib}" = xno; then
+	    AC_MSG_ERROR([It is not possible to disable the use of krb5. Remove the --without-krb5 option.])
+	fi
+
+	if test "x${with_krb5}" != x; then
+	    KRB5_LIBS="-L${with_krb5}/lib -lkrb5"
+	    KRB5_CFLAGS="-I${with_krb5}/include"
+	    KRB5_FOUND=yes
+	fi
+	if test "x${with_krb5_include}" != x; then
+	    KRB5_CFLAGS="-I${with_krb5_include}"
+	    KRB5_FOUND=yes
+	fi
+	if test "x${with_krb5_lib}" != x; then
+	    KRB5_LIBS="-L${with_krb5_lib} -lkrb5"
+	    KRB5_FOUND=yes
+	fi
+	if test "x$KRB5_FOUND" = xno; then
+	    BDEPS_CHECK_MODULE(KRB5, krb5, xxx, [KRB5_FOUND=yes], [KRB5_FOUND=no])
+	fi
+	if test "x$KRB5_FOUND" = xno; then
+	    PKG_CHECK_MODULES(KRB5, krb5, [KRB5_FOUND=yes], [KRB5_FOUND=no])
+	fi
+  if test "x$KRB5_FOUND" = xno; then
+	    KRB5_CHECK_LIBRARY(KRB5, krb5, [KRB5_FOUND=yes], [KRB5_FOUND=no])
+	fi
+	if test "x$KRB5_FOUND" = xno; then
+	    AC_CHECK_HEADERS([krb5.h],
+	                     [KRB5_FOUND=yes
+	                      KRB5_CFLAGS=-Iignoreme
+	                      KRB5_LIBS=-lkrb5
+	                      DEFAULT_KRB5=yes],
+	                     [KRB5_FOUND=no])
+	fi
+	if test "x$KRB5_FOUND" = xno; then 
+	    HELP_MSG_MISSING_DEPENDENCY([krb5])
+	    AC_MSG_ERROR([Could not find krb5! $HELP_MSG ])
+	fi    
+fi
+
+AC_SUBST(KRB5_CFLAGS)
+AC_SUBST(KRB5_LIBS)
+
+])
 AC_DEFUN_ONCE([LIB_SETUP_MISC_LIBS],
 [
 
diff --git a/common/autoconf/spec.gmk.in b/common/autoconf/spec.gmk.in
--- a/common/autoconf/spec.gmk.in
+++ b/common/autoconf/spec.gmk.in
@@ -277,6 +277,8 @@
 CUPS_CFLAGS:=@CUPS_CFLAGS@
 ALSA_LIBS:=@ALSA_LIBS@
 ALSA_CFLAGS:=@ALSA_CFLAGS@
+KRB5_LIBS:=@KRB5_LIBS@
+KRB5_CFLAGS:=@KRB5_CFLAGS@
 
 PACKAGE_PATH=@PACKAGE_PATH@
 
diff --git a/make/common/Defs.gmk b/make/common/Defs.gmk
--- a/make/common/Defs.gmk
+++ b/make/common/Defs.gmk
@@ -252,6 +252,7 @@
 NO_JAVALIB_PKGS = \
 		sun.security.mscapi \
 		sun.security.krb5 \
+		sun.security.krb5.internal.ccache \
 		sun.security.pkcs11 \
 		sun.security.jgss \
 		sun.security.jgss.wrapper \
diff --git a/make/jdk_generic_profile.sh b/make/jdk_generic_profile.sh
--- a/make/jdk_generic_profile.sh
+++ b/make/jdk_generic_profile.sh
@@ -419,3 +419,27 @@
 export ZLIB_CFLAGS
 export ZLIB_LIBS
 
+# KRB5_CFLAGS and KRB5_LIBS tell the compiler how to compile and
+# link against Kerberos
+pkgconfig=$(which pkg-config 2>/dev/null)
+# Similar to pkg-config, but specific to Kerberos
+krb5config=$(which krb5-config 2>/dev/null)
+if [ -x "${pkgconfig}" ] ; then
+  if [ "${KRB5_CFLAGS}" = "" ] ; then
+    KRB5_CFLAGS=$("${pkgconfig}" --cflags krb5)
+    if [ "${KRB5_CFLAGS}" = "" ] ; then
+      KRB5_CFLAGS=$("${krb5config}" --cflags krb5)
+    fi
+  fi
+  if [ "${KRB5_LIBS}" = "" ] ; then
+    KRB5_LIBS=$("${pkgconfig}" --libs krb5)
+    if [ "${KRB5_LIBS}" = "" ] ; then
+      KRB5_LIBS=$("${krb5config}" --libs krb5)
+    fi
+  fi
+fi
+if [ "${KRB5_LIBS}" = "" ] ; then
+    KRB5_LIBS="-lkrb5"
+fi
+export KRB5_CFLAGS
+export KRB5_LIBS
diff --git a/make/sun/security/Makefile b/make/sun/security/Makefile
--- a/make/sun/security/Makefile
+++ b/make/sun/security/Makefile
@@ -1,5 +1,6 @@
 #
 # Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -47,6 +48,12 @@
 # Build PKCS#11 on all platforms
 PKCS11 = pkcs11
 
+# Build krb5/internal/ccache only on Linux and Solaris platforms.
+KRB5_CCACHE =
+ifeq ($(PLATFORM), $(filter $(PLATFORM),linux solaris))
+  KRB5_CCACHE = krb5/internal/ccache
+endif
+
 # Build Microsoft CryptoAPI provider only on Windows platform.
 MSCAPI =
 ifeq ($(PLATFORM), windows)
@@ -60,7 +67,7 @@
   INTREE_EC =
 endif
 
-SUBDIRS       = $(INTREE_EC) other action util krb5
+SUBDIRS       = $(INTREE_EC) other action util krb5 $(KRB5_CCACHE)
 SUBDIRS_misc  = jgss $(PKCS11) $(JGSS_WRAPPER) $(MSCAPI) smartcardio
 SUBDIRS_tools = tools
 include $(BUILDDIR)/common/Subdirs.gmk
diff --git a/make/sun/security/krb5/internal/ccache/Makefile b/make/sun/security/krb5/internal/ccache/Makefile
new file mode 100644
--- /dev/null
+++ b/make/sun/security/krb5/internal/ccache/Makefile
@@ -0,0 +1,49 @@
+#
+# Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+BUILDDIR = ../../../../..
+PACKAGE = sun.security.krb5.internal.ccache
+PRODUCT = sun
+include $(BUILDDIR)/common/Defs.gmk
+
+#
+# Java Files
+#
+AUTO_FILES_JAVA_DIRS = sun/security/krb5/internal/ccache
+
+ifeq ($(PLATFORM), $(filter $(PLATFORM),linux solaris))
+FILES_export = sun/security/krb5/internal/ccache/FileCredentialsCache.java
+FILES_c = krb5ccache.c
+LIBRARY = j2krb5
+
+vpath %.c \
+  $(PLATFORM_SRC)/native/sun/security/krb5/internal/ccache
+
+include $(BUILDDIR)/common/Library.gmk
+
+OTHER_CFLAGS += $(KRB5_CFLAGS)
+OTHER_LDLIBS = $(LIBDL) $(JVMLIB) $(KRB5_LIBS)
+endif # PLATFORM
diff --git a/makefiles/CompileNativeLibraries.gmk b/makefiles/CompileNativeLibraries.gmk
--- a/makefiles/CompileNativeLibraries.gmk
+++ b/makefiles/CompileNativeLibraries.gmk
@@ -2619,6 +2619,28 @@
 
 ##########################################################################################
 
+ifeq ($(OPENJDK_TARGET_OS), $(filter $(OPENJDK_TARGET_OS),linux solaris))
+$(eval $(call SetupNativeCompilation,BUILD_LIBJ2KRB5,\
+		LIBRARY:=j2krb5,\
+                OUTPUT_DIR:=$(INSTALL_LIBRARIES_HERE),\
+		SRC:=$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/krb5/internal/ccache,\
+		LANG:=C,\
+		OPTIMIZATION:=LOW, \
+		CFLAGS:=$(CFLAGS_JDKLIB) $(KRB5_CFLAGS) \
+                     -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/krb5/internal/ccache,\
+		MAPFILE:=$(JDK_TOPDIR)/makefiles/mapfiles/libj2krb5/mapfile-vers, \
+		LDFLAGS:=$(LDFLAGS_JDKLIB) \
+			 $(call SET_SHARED_LIBRARY_ORIGIN),\
+		LDFLAGS_SUFFIX:=$(LIBDL) $(KRB5_LIBS),\
+		LDFLAGS_SUFFIX_solaris:=-lc $(KRB5_LIBS),\
+		OBJECT_DIR:=$(JDK_OUTPUTDIR)/objs/libj2krb5,\
+		DEBUG_SYMBOLS:=$(DEBUG_ALL_BINARIES)))
+
+BUILD_LIBRARIES += $(BUILD_LIBJ2KRB5)
+endif
+
+##########################################################################################
+
 ifneq ($(BUILD_CRYPTO),no)
   BUILD_LIBKRB5_NAME:=
   ifeq ($(OPENJDK_TARGET_OS), windows)
diff --git a/makefiles/mapfiles/libj2krb5/mapfile-vers b/makefiles/mapfiles/libj2krb5/mapfile-vers
new file mode 100644
--- /dev/null
+++ b/makefiles/mapfiles/libj2krb5/mapfile-vers
@@ -0,0 +1,35 @@
+#
+# Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# Define public interface.
+
+SUNWprivate_1.1 {
+	global:
+    Java_sun_security_krb5_internal_ccache_FileCredentialsCache_nativeGetDefaultCacheName;
+		
+	local:
+		*;
+};
diff --git a/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java b/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java
--- a/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java
+++ b/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -43,7 +44,9 @@
 import java.io.FileOutputStream;
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
-import java.lang.reflect.*;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 
 /**
  * CredentialsCache stores credentials(tickets, session keys, etc) in a
@@ -62,6 +65,8 @@
     private Vector<Credentials> credentialsList;
     private static String dir;
     private static boolean DEBUG = Krb5.DEBUG;
+    private static boolean alreadyLoaded = false;
+    private static boolean alreadyTried = false;
 
     public static synchronized FileCredentialsCache acquireInstance(
                 PrincipalName principal, String cache) {
@@ -349,9 +354,10 @@
      * The path name is searched in the following order:
      *
      * 1. KRB5CCNAME (bare file name without FILE:)
-     * 2. /tmp/krb5cc_<uid> on unix systems
-     * 3. <user.home>/krb5cc_<user.name>
-     * 4. <user.home>/krb5cc (if can't get <user.name>)
+     * 2. location specified by Kerberos API on unix systems
+     * 3. /tmp/krb5cc_<uid> on unix systems
+     * 4. <user.home>/krb5cc_<user.name>
+     * 5. <user.home>/krb5cc (if can't get <user.name>)
      */
 
     public static String getDefaultCacheName() {
@@ -398,26 +404,62 @@
          */
 
         if (osname != null) {
-            String cmd = null;
-            String uidStr = null;
-            long uid = 0;
-
             if (osname.startsWith("SunOS") ||
                 (osname.startsWith("Linux"))) {
                 try {
-                    Class<?> c = Class.forName
-                        ("com.sun.security.auth.module.UnixSystem");
-                    Constructor<?> constructor = c.getConstructor();
-                    Object obj = constructor.newInstance();
-                    Method method = c.getMethod("getUid");
-                    uid =  ((Long)method.invoke(obj)).longValue();
-                    name = File.separator + "tmp" +
-                        File.separator + stdCacheNameComponent + "_" + uid;
-                    if (DEBUG) {
-                        System.out.println(">>>KinitOptions cache name is " +
-                                           name);
+                    // Load the native code if necessary
+                    if (!alreadyTried) {
+                        // See if there's any native code to load
+                        try {
+                            ensureLoaded();
+                        } catch (Exception e) {
+                            if (DEBUG) {
+                                System.out.println("Could not load native Kerberos bridge");
+                                e.printStackTrace();
+                            }
+                            alreadyTried = true;
+                        }
                     }
-                    return name;
+                    if (alreadyLoaded) {
+                        // There is some native code
+                        if (DEBUG) {
+                           System.out.println(">> Look up native default credential cache");
+                        }
+                        // Query the native Kerberos API for the cache location
+                        name = nativeGetDefaultCacheName();
+                    }
+
+                    /*
+                     * We require the default cache location to be a file name.
+                     * DIR: can point to a cache collection, while DIR:: points
+                     * to a specific cache file.
+                     *
+                     * http://k5wiki.kerberos.org/wiki?title=Projects/Client_principal_selection&oldid=4118
+                     */
+                    if (name != null && (name.startsWith("FILE:") || name.startsWith("DIR::"))) {
+                        name = name.substring(5);
+                        if (DEBUG) {
+                            System.out.println(">>>KinitOptions cache name is " +
+                                    name);
+                        }
+                        return name;
+                    } else {
+                        long uid = 0;
+
+                        Class<?> c = Class.forName
+                            ("com.sun.security.auth.module.UnixSystem");
+                        Constructor<?> constructor = c.getConstructor();
+                        Object obj = constructor.newInstance();
+                        Method method = c.getMethod("getUid");
+                        uid =  ((Long)method.invoke(obj)).longValue();
+                        name = File.separator + "tmp" +
+                            File.separator + stdCacheNameComponent + "_" + uid;
+                        if (DEBUG) {
+                            System.out.println(">>>KinitOptions cache name is " +
+                                               name);
+                        }
+                        return name;
+                    }
                 } catch (Exception e) {
                     if (DEBUG) {
                         System.out.println("Exception in obtaining uid " +
@@ -462,6 +504,8 @@
         return name;
     }
 
+    private native static String nativeGetDefaultCacheName() throws Exception;
+
     public static String checkValidation(String name) {
         String fullname = null;
         if (name == null) {
@@ -542,4 +586,16 @@
         }
         return null;
     }
+
+    private static void ensureLoaded() {
+        java.security.AccessController.doPrivileged(
+                new java.security.PrivilegedAction<Void> () {
+                    public Void run() {
+                            System.loadLibrary("j2krb5");
+                        return null;
+                    }
+                });
+        alreadyLoaded = true;
+    }
+
 }
diff --git a/src/solaris/native/sun/security/krb5/internal/ccache/krb5ccache.c b/src/solaris/native/sun/security/krb5/internal/ccache/krb5ccache.c
new file mode 100644
--- /dev/null
+++ b/src/solaris/native/sun/security/krb5/internal/ccache/krb5ccache.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include <krb5.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "sun_security_krb5_internal_ccache_FileCredentialsCache.h"
+
+static void handle_error(JNIEnv *env, krb5_context context, krb5_error_code err, const char *func_name);
+static jint throw_Exception(JNIEnv *env, const char *class_name, const char *message);
+
+/*
+ * Class:     sun_security_krb5_internal_ccache_FileCredentialsCache
+ * Method:    nativeGetDefaultCacheName
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_sun_security_krb5_internal_ccache_FileCredentialsCache_nativeGetDefaultCacheName
+(JNIEnv *env, jclass krbcredsClass)
+{
+    krb5_context context;
+    krb5_error_code err;
+    krb5_ccache cache;
+    const char *cc_type, *cc_name;
+    char *cc_full_name;
+    size_t len;
+    jstring result;
+    (void) krbcredsClass; /* silence compiler */
+
+    /* Need a krb5_context to proceed further */
+    err = krb5_init_context(&context);
+    if (err) {
+        handle_error(env, context, err, "krb5_init_context");
+        return NULL;
+    }
+
+    /* Get the default credential cache.
+     * We intentionally do not use krb5_cc_default_name because when the cache
+     * is a collection, krb5_cc_default_name returns the collection directory.
+     * By using krb5_cc_default and then krb5_cc_get_name, we get the primary
+     * cache file within the collection. */
+    err = krb5_cc_default(context, &cache);
+    if (err) {
+        handle_error(env, context, err, "krb5_cc_default");
+        krb5_free_context(context);
+        return NULL;
+    }
+
+    /* Get the type and name of the default cache and construct a string
+     * of the form 'type:name'. */
+    cc_type = krb5_cc_get_type(context, cache);
+    cc_name = krb5_cc_get_name(context, cache);
+    len = strlen(cc_type) + strlen(cc_name) + 2; /* ':', '\0' */
+    cc_full_name = (char *) malloc(len * sizeof(char));
+    if (!cc_full_name) {
+        throw_Exception(env, "java/lang/OutOfMemoryError", "Unable to construct credential cache string");
+        krb5_cc_close(context, cache);
+        krb5_free_context(context);
+        return NULL;
+    }
+    snprintf(cc_full_name, len, "%s:%s", cc_type, cc_name);
+
+    result = (*env)->NewStringUTF(env, cc_full_name);
+
+    free(cc_full_name);
+    krb5_cc_close(context, cache);
+    krb5_free_context(context);
+    return result;
+}
+
+static void handle_error(JNIEnv *env, krb5_context context, krb5_error_code err, const char *func_name) {
+    const char *err_msg;
+    char *result;
+    size_t len;
+
+    err_msg = krb5_get_error_message(context, err);
+    len = strlen(func_name) + strlen(err_msg) + 3; /* ':', ' ', '\0' */
+    result = (char *) malloc(len * sizeof(char));
+    if (!result) {
+        throw_Exception(env, "java/lang/OutOfMemoryError", "Unable to construct error message");
+        return;
+    }
+    snprintf(result, len, "%s: %s", func_name, err_msg);
+    throw_Exception(env, "java/lang/Exception", result);
+
+    free(result);
+    krb5_free_error_message(context, err_msg);
+}
+
+static jint throw_Exception(JNIEnv *env, const char *class_name, const char *message) {
+    jclass class;
+
+    class = (*env)->FindClass(env, class_name);
+    if (class == NULL) {
+        return -1;
+    }
+    return (*env)->ThrowNew(env, class, message);
+}
diff --git a/test/sun/security/krb5/internal/ccache/Krb5Test.c b/test/sun/security/krb5/internal/ccache/Krb5Test.c
new file mode 100644
--- /dev/null
+++ b/test/sun/security/krb5/internal/ccache/Krb5Test.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "sun_security_krb5_internal_ccache_FileCredentialsCache.h"
+
+JNIEXPORT jstring JNICALL Java_sun_security_krb5_internal_ccache_FileCredentialsCache_nativeGetDefaultCacheName
+(JNIEnv *env, jclass krbcredsClass)
+{
+    const char *ccache;
+    (void) krbcredsClass; /* silence compiler */
+
+    ccache = "DIR::/path/to/krb5cc";
+    return (*env)->NewStringUTF(env, ccache);
+}
diff --git a/test/sun/security/krb5/internal/ccache/Krb5Test.java b/test/sun/security/krb5/internal/ccache/Krb5Test.java
new file mode 100644
--- /dev/null
+++ b/test/sun/security/krb5/internal/ccache/Krb5Test.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+import java.lang.reflect.Field;
+
+import sun.security.krb5.internal.ccache.FileCredentialsCache;
+
+/* 
+ * This test should be run with the provided shell script 'run_tests.sh'
+ */
+public class Krb5Test {
+    
+    private static final String CC_NAME = "/path/to/krb5cc";
+    
+    public static void main(String[] args) throws NoSuchFieldException,
+            SecurityException, IllegalArgumentException, IllegalAccessException {
+        // Argument to our stub libj2krb5.so must be passed as the first argument
+        if (args.length < 1) {
+            throw new RuntimeException("Must specify directory of stub libj2krb5.so");
+        }
+        File libDir = new File(args[0]);
+        if (!libDir.exists()) {
+            throw new RuntimeException("Library directory does not exist");
+        }
+        resetLibraryPath(libDir);
+        String ccName = FileCredentialsCache.getDefaultCacheName();
+        if (!CC_NAME.equals(ccName)) {
+            throw new RuntimeException("Expected '" + CC_NAME + "', but got '" + ccName + "'!"); 
+        }
+    }
+
+    private static void resetLibraryPath(File libDir) throws NoSuchFieldException,
+            IllegalAccessException {
+        // Prepend our stub library's path to sun.boot.library.path
+        String bootLibraryPath = System.getProperty("sun.boot.library.path");
+        System.setProperty("sun.boot.library.path", libDir.getAbsolutePath() + ":" + bootLibraryPath);
+
+        // Set ClassLoader.sys_paths to null to force rereading sun.boot.library.path
+        Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
+        sysPathsField.setAccessible(true);
+        sysPathsField.set(null, null);
+    }
+    
+}
diff --git a/test/sun/security/krb5/internal/ccache/Makefile b/test/sun/security/krb5/internal/ccache/Makefile
new file mode 100644
--- /dev/null
+++ b/test/sun/security/krb5/internal/ccache/Makefile
@@ -0,0 +1,90 @@
+#
+# Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+
+#
+# Makefile for building libKrb5Test.so
+#
+# To build libKrb5Test.so requires :-
+#     JAVA_HOME environment variable 
+#     cc (Solaris) or gcc (Linux) on PATH
+#
+# The library is created in a architecture specific directory :-
+#
+#     build/solaris-sparc/lib/sparc/libKrb5Test.so	(Solaris/SPARC)
+#     build/solaris-i586/lib/i386/libKrb5Test.so	(Solaris/x86)
+#     build/linux-i586/lib/i386/libKrb5Test.so	(Linux/x86)
+
+ECHO  = echo
+MKDIR = mkdir
+UNAME = uname
+
+CLASSNAME = sun.security.krb5.internal.ccache.FileCredentialsCache
+HEADERFILE = sun_security_krb5_internal_ccache_FileCredentialsCache.h
+LIBRARY = j2krb5
+
+JDK_TOPDIR=../../../../../..
+
+FILES_c = Krb5Test.c
+FILES_export = sun/security/krb5/internal/ccache/FileCredentialsCache.java
+FILES_java = Krb5Test.java
+TEMPDIR = tmp
+CLASSHDRDIR = include
+JAVA_TOOLS_DIR = $(JAVA_HOME)/bin
+JAVAHFLAGS = -classpath $(JAVA_HOME)/jre/lib/rt.jar
+
+include $(JDK_TOPDIR)/make/common/shared/Platform.gmk
+include $(JDK_TOPDIR)/make/common/Defs.gmk
+
+CWD = $(shell $(PWD))
+OUTPUTDIR = $(CWD)/build/$(PLATFORM)-$(ARCH)
+AUTO_FILES_JAVA_DIRS = $(CWD)
+
+include $(JDK_TOPDIR)/make/common/Library.gmk
+
+JAVAC_CMD += $(JAVAHFLAGS)
+
+$(CLASSDESTDIR)/%.class: %.java
+	@$(add-java-file)
+
+all: platform_check java_home build
+
+clean::
+	$(RM) -r $(OUTPUTDIR)
+
+java_home:
+ifndef JAVA_HOME
+	@$(ECHO) "ERROR: Your JAVA_HOME environment variable is not set."
+	exit 1
+endif
+
+platform_check:
+ifneq ($(PLATFORM), $(filter $(PLATFORM),linux solaris))
+	@$(ECHO) "ERROR: This test is for Linux and Solaris only."
+	exit 1
+endif
+
+libdir:
+	@$(ECHO) $(OUTPUTDIR)/lib/$(LIBARCH)
+
+classdir:
+	@$(ECHO) $(OUTPUTDIR)/classes
diff --git a/test/sun/security/krb5/internal/ccache/run_tests.sh b/test/sun/security/krb5/internal/ccache/run_tests.sh
new file mode 100644
--- /dev/null
+++ b/test/sun/security/krb5/internal/ccache/run_tests.sh
@@ -0,0 +1,110 @@
+#!/bin/sh
+
+#
+# Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# This file was derived from:
+# test/java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh
+
+# @test
+# @summary Unit test for obtaining Kerberos ccache location from native API
+# @build Krb5Test 
+# @run shell run_tests.sh
+
+os=`uname -s`
+
+if [ "$os" == "Linux" ]; then
+    MAKE=make
+elif [ "$os" == "SunOS" ]; then
+    MAKE=gmake
+else
+    echo "Test not designed to run on this operating system, skipping..."
+    exit 0
+fi
+
+
+# if TESTJAVA isn't set then we assume an interactive run. So that it's
+# clear which version of 'java' is running we do a 'which java' and
+# a 'java -version'.
+
+if [ -z "$TESTJAVA" ]; then
+    TESTSRC=`pwd`
+    TESTCLASSES=`pwd`
+    JAVA=java
+    which $JAVA
+    ${JAVA} -d64 -version > /dev/null 2<&1
+    if [ $? = 1 ]; then
+        ${JAVA} -version
+    else
+        ${JAVA} -d64 -version
+    fi
+else
+    JAVA="${TESTJAVA}/bin/java"
+fi
+
+DFLAG=
+BITS=32
+# if 'java -d64' works, then assume 64-bit.
+${JAVA} -d64 -version > /dev/null 2<&1 
+if [ $? = 0 ]; then
+    DFLAG=-d64
+    BITS=64
+fi
+
+SAVE_CWD=`pwd`
+cd ${TESTSRC}
+LIBDIR=`${MAKE} ARCH_DATA_MODEL=${BITS} libdir`
+CLASSDIR=`${MAKE} classdir`
+cd ${SAVE_CWD}
+
+CLASSPATH=${CLASSDIR}:${TESTCLASSES}
+export CLASSPATH
+
+KRB5TESTLIB=${LIBDIR}/libj2krb5.so
+
+if [ ! -f "${KRB5TESTLIB}" ]; then
+    echo "Cannot find ${KRB5TESTLIB} - library not available for this system"
+    exit 1
+fi
+
+failures=0
+
+go() {
+    echo ''
+    sh -xc "$JAVA $DFLAG $1 $2 $3 $4 $5 $6 $7 $8" 2>&1
+    if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
+}
+
+# Run the tests
+
+go Krb5Test ${LIBDIR}
+
+#
+# Results
+#
+echo ''
+if [ $failures -gt 0 ];
+  then echo "$failures test(s) failed";
+  else echo "All test(s) passed"; fi
+exit $failures

Reply via email to