2
|
1 |
/*
|
|
2 |
* Copyright 1995-2003 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
#include "jni.h"
|
|
27 |
#include "jni_util.h"
|
|
28 |
#include "jvm.h"
|
|
29 |
|
|
30 |
#include "java_lang_SecurityManager.h"
|
|
31 |
#include "java_lang_ClassLoader.h"
|
|
32 |
#include "java_util_ResourceBundle.h"
|
|
33 |
|
|
34 |
/*
|
|
35 |
* Make sure a security manager instance is initialized.
|
|
36 |
* TRUE means OK, FALSE means not.
|
|
37 |
*/
|
|
38 |
static jboolean
|
|
39 |
check(JNIEnv *env, jobject this)
|
|
40 |
{
|
|
41 |
static jfieldID initField = 0;
|
|
42 |
jboolean initialized = JNI_FALSE;
|
|
43 |
|
|
44 |
if (initField == 0) {
|
|
45 |
jclass clazz = (*env)->FindClass(env, "java/lang/SecurityManager");
|
|
46 |
if (clazz == 0) {
|
|
47 |
(*env)->ExceptionClear(env);
|
|
48 |
return JNI_FALSE;
|
|
49 |
}
|
|
50 |
initField = (*env)->GetFieldID(env, clazz, "initialized", "Z");
|
|
51 |
if (initField == 0) {
|
|
52 |
(*env)->ExceptionClear(env);
|
|
53 |
return JNI_FALSE;
|
|
54 |
}
|
|
55 |
}
|
|
56 |
initialized = (*env)->GetBooleanField(env, this, initField);
|
|
57 |
|
|
58 |
if (initialized == JNI_TRUE) {
|
|
59 |
return JNI_TRUE;
|
|
60 |
} else {
|
|
61 |
jclass securityException =
|
|
62 |
(*env)->FindClass(env, "java/lang/SecurityException");
|
|
63 |
if (securityException != 0) {
|
|
64 |
(*env)->ThrowNew(env, securityException,
|
|
65 |
"security manager not initialized.");
|
|
66 |
}
|
|
67 |
return JNI_FALSE;
|
|
68 |
}
|
|
69 |
}
|
|
70 |
|
|
71 |
JNIEXPORT jobjectArray JNICALL
|
|
72 |
Java_java_lang_SecurityManager_getClassContext(JNIEnv *env, jobject this)
|
|
73 |
{
|
|
74 |
if (!check(env, this)) {
|
|
75 |
return NULL; /* exception */
|
|
76 |
}
|
|
77 |
|
|
78 |
return JVM_GetClassContext(env);
|
|
79 |
}
|
|
80 |
|
|
81 |
JNIEXPORT jclass JNICALL
|
|
82 |
Java_java_lang_SecurityManager_currentLoadedClass0(JNIEnv *env, jobject this)
|
|
83 |
{
|
|
84 |
/* Make sure the security manager instance is initialized */
|
|
85 |
if (!check(env, this)) {
|
|
86 |
return NULL; /* exception */
|
|
87 |
}
|
|
88 |
|
|
89 |
return JVM_CurrentLoadedClass(env);
|
|
90 |
}
|
|
91 |
|
|
92 |
JNIEXPORT jobject JNICALL
|
|
93 |
Java_java_lang_SecurityManager_currentClassLoader0(JNIEnv *env, jobject this)
|
|
94 |
{
|
|
95 |
/* Make sure the security manager instance is initialized */
|
|
96 |
if (!check(env, this)) {
|
|
97 |
return NULL; /* exception */
|
|
98 |
}
|
|
99 |
|
|
100 |
return JVM_CurrentClassLoader(env);
|
|
101 |
}
|
|
102 |
|
|
103 |
JNIEXPORT jint JNICALL
|
|
104 |
Java_java_lang_SecurityManager_classDepth(JNIEnv *env, jobject this,
|
|
105 |
jstring name)
|
|
106 |
{
|
|
107 |
/* Make sure the security manager instance is initialized */
|
|
108 |
if (!check(env, this)) {
|
|
109 |
return -1; /* exception */
|
|
110 |
}
|
|
111 |
|
|
112 |
if (name == NULL) {
|
|
113 |
JNU_ThrowNullPointerException(env, 0);
|
|
114 |
return -1;
|
|
115 |
}
|
|
116 |
|
|
117 |
return JVM_ClassDepth(env, name);
|
|
118 |
}
|
|
119 |
|
|
120 |
JNIEXPORT jint JNICALL
|
|
121 |
Java_java_lang_SecurityManager_classLoaderDepth0(JNIEnv *env, jobject this)
|
|
122 |
{
|
|
123 |
/* Make sure the security manager instance is initialized */
|
|
124 |
if (!check(env, this)) {
|
|
125 |
return -1; /* exception */
|
|
126 |
}
|
|
127 |
|
|
128 |
return JVM_ClassLoaderDepth(env);
|
|
129 |
}
|