8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
authorweijun
Thu, 22 May 2014 07:04:57 +0800
changeset 24506 abb4cc4647ee
parent 24505 d2c5179475ea
child 24507 a1219a8699e5
8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth Reviewed-by: alanb
jdk/make/mapfiles/libjava/mapfile-vers
jdk/src/share/classes/sun/misc/VM.java
jdk/src/share/classes/sun/security/krb5/internal/rcache/DflCache.java
jdk/src/solaris/native/sun/misc/VM_md.c
jdk/src/windows/native/sun/misc/VM_md.c
jdk/test/sun/security/krb5/auto/ReplayCacheTestProc.java
--- a/jdk/make/mapfiles/libjava/mapfile-vers	Wed May 21 10:22:20 2014 +0200
+++ b/jdk/make/mapfiles/libjava/mapfile-vers	Thu May 22 07:04:57 2014 +0800
@@ -270,7 +270,10 @@
                 Java_sun_misc_Version_getJvmVersionInfo;
                 Java_sun_misc_Version_getJvmSpecialVersion;
 		Java_sun_misc_VM_latestUserDefinedLoader;
-                Java_sun_misc_VM_isSetUID;
+                Java_sun_misc_VM_getuid;
+                Java_sun_misc_VM_geteuid;
+                Java_sun_misc_VM_getgid;
+                Java_sun_misc_VM_getegid;
                 Java_sun_misc_VM_initialize;
 		Java_sun_misc_VMSupport_initAgentProperties;
 		Java_sun_misc_VMSupport_getVMTemporaryDirectory;
--- a/jdk/src/share/classes/sun/misc/VM.java	Wed May 21 10:22:20 2014 +0200
+++ b/jdk/src/share/classes/sun/misc/VM.java	Thu May 22 07:04:57 2014 +0800
@@ -370,7 +370,37 @@
     /**
      * Returns {@code true} if we are in a set UID program.
      */
-    public static native boolean isSetUID();
+    public static boolean isSetUID() {
+        long uid = getuid();
+        long euid = geteuid();
+        long gid = getgid();
+        long egid = getegid();
+        return uid != euid  || gid != egid;
+    }
+
+    /**
+     * Returns the real user ID of the calling process,
+     * or -1 if the value is not available.
+     */
+    public static native long getuid();
+
+    /**
+     * Returns the effective user ID of the calling process,
+     * or -1 if the value is not available.
+     */
+    public static native long geteuid();
+
+    /**
+     * Returns the real group ID of the calling process,
+     * or -1 if the value is not available.
+     */
+    public static native long getgid();
+
+    /**
+     * Returns the effective group ID of the calling process,
+     * or -1 if the value is not available.
+     */
+    public static native long getegid();
 
     static {
         initialize();
--- a/jdk/src/share/classes/sun/security/krb5/internal/rcache/DflCache.java	Wed May 21 10:22:20 2014 +0200
+++ b/jdk/src/share/classes/sun/security/krb5/internal/rcache/DflCache.java	Thu May 22 07:04:57 2014 +0800
@@ -39,7 +39,6 @@
 import java.security.AccessController;
 import java.util.*;
 
-import com.sun.security.auth.module.UnixSystem;
 import sun.security.action.GetPropertyAction;
 import sun.security.krb5.internal.KerberosTime;
 import sun.security.krb5.internal.Krb5;
@@ -61,8 +60,7 @@
  *
  *    service_euid
  *
- * Java does not have a method to get euid, so uid is used instead. This
- * should normally to be since a Java program is seldom used as a setuid app.
+ * in which euid is available as sun.misc.VM.geteuid().
  *
  * The file has a header:
  *
@@ -108,14 +106,8 @@
 
     private static long uid;
     static {
-        try {
-            // Available on Solaris, Linux and Mac. Otherwise, no _euid suffix
-            UnixSystem us = new com.sun.security.auth.module.UnixSystem();
-            uid = us.getUid();
-        } catch (Throwable e) {
-            // Cannot be only Exception, might be UnsatisfiedLinkError
-            uid = -1;
-        }
+        // Available on Solaris, Linux and Mac. Otherwise, -1 and no _euid suffix
+        uid = sun.misc.VM.geteuid();
     }
 
     public DflCache (String source) {
--- a/jdk/src/solaris/native/sun/misc/VM_md.c	Wed May 21 10:22:20 2014 +0200
+++ b/jdk/src/solaris/native/sun/misc/VM_md.c	Thu May 22 07:04:57 2014 +0800
@@ -27,12 +27,26 @@
 #include "jni_util.h"
 
 
-JNIEXPORT jboolean JNICALL
-Java_sun_misc_VM_isSetUID(JNIEnv *env, jclass thisclass) {
+JNIEXPORT jlong JNICALL
+Java_sun_misc_VM_getuid(JNIEnv *env, jclass thisclass) {
+
+    return getuid();
+}
+
+JNIEXPORT jlong JNICALL
+Java_sun_misc_VM_geteuid(JNIEnv *env, jclass thisclass) {
+
+    return geteuid();
+}
 
-    /* Return true if we are in a set UID or set GID process. */
-    if (getuid() != geteuid() || getgid() != getegid()) {
-        return JNI_TRUE;
-    }
-    return JNI_FALSE;
+JNIEXPORT jlong JNICALL
+Java_sun_misc_VM_getgid(JNIEnv *env, jclass thisclass) {
+
+    return getgid();
 }
+
+JNIEXPORT jlong JNICALL
+Java_sun_misc_VM_getegid(JNIEnv *env, jclass thisclass) {
+
+    return getegid();
+}
--- a/jdk/src/windows/native/sun/misc/VM_md.c	Wed May 21 10:22:20 2014 +0200
+++ b/jdk/src/windows/native/sun/misc/VM_md.c	Thu May 22 07:04:57 2014 +0800
@@ -26,9 +26,30 @@
 #include "jni_util.h"
 
 
-JNIEXPORT jboolean JNICALL
-Java_sun_misc_VM_isSetUID(JNIEnv *env, jclass thisclass) {
+JNIEXPORT jlong JNICALL
+Java_sun_misc_VM_getuid(JNIEnv *env, jclass thisclass) {
+
+    /* -1 means function not available. */
+    return -1;
+}
+
+JNIEXPORT jlong JNICALL
+Java_sun_misc_VM_geteuid(JNIEnv *env, jclass thisclass) {
+
+    /* -1 means function not available. */
+    return -1;
+}
 
-    /* There is no set UID on Windows. */
-    return JNI_FALSE;
+JNIEXPORT jlong JNICALL
+Java_sun_misc_VM_getgid(JNIEnv *env, jclass thisclass) {
+
+    /* -1 means function not available. */
+    return -1;
 }
+
+JNIEXPORT jlong JNICALL
+Java_sun_misc_VM_getegid(JNIEnv *env, jclass thisclass) {
+
+    /* -1 means function not available. */
+    return -1;
+}
--- a/jdk/test/sun/security/krb5/auto/ReplayCacheTestProc.java	Wed May 21 10:22:20 2014 +0200
+++ b/jdk/test/sun/security/krb5/auto/ReplayCacheTestProc.java	Thu May 22 07:04:57 2014 +0800
@@ -40,7 +40,6 @@
 import java.security.MessageDigest;
 import java.util.*;
 
-import com.sun.security.auth.module.UnixSystem;
 import sun.security.jgss.GSSUtil;
 import sun.security.krb5.internal.APReq;
 import sun.security.krb5.internal.rcache.AuthTime;
@@ -79,13 +78,7 @@
                 mode = -1;
             }
 
-            try {
-                UnixSystem us = new com.sun.security.auth.module.UnixSystem();
-                uid = us.getUid();
-            } catch (Throwable e) {
-                // Cannot be only Exception, might be UnsatisfiedLinkError
-                uid = -1;
-            }
+            uid = sun.misc.VM.geteuid();
 
             KDC kdc = KDC.create(OneKDC.REALM, HOST, 0, true);
             for (int i=0; i<nu; i++) {