1 /*
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #include "NativeUtil.h"
27 #include "NativeFunc.h"
28 #include "jlong.h"
29 #include <jni.h>
30
31 const int JAVA_DUPLICATE_TOKEN_CODE = 19; /* DUPLICATE_TOKEN */
32 const int JAVA_OLD_TOKEN_CODE = 20; /* OLD_TOKEN */
33 const int JAVA_UNSEQ_TOKEN_CODE = 21; /* UNSEQ_TOKEN */
34 const int JAVA_GAP_TOKEN_CODE = 22; /* GAP_TOKEN */
35 const int JAVA_ERROR_CODE[] = {
36 2, /* BAD_MECH */
37 3, /* BAD_NAME */
38 4, /* BAD_NAMETYPE */
39 1, /* BAD_BINDINGS */
40 5, /* BAD_STATUS */
41 6, /* BAD_MIC */
42 13, /* NO_CRED */
43 12, /* NO_CONTEXT */
44 10, /* DEFECTIVE_TOKEN */
45 9, /* DEFECTIVE_CREDENTIAL */
46 8, /* CREDENTIAL_EXPIRED */
47 7, /* CONTEXT_EXPIRED */
48 11, /* FAILURE */
49 14, /* BAD_QOP */
77 jmethodID MID_ChannelBinding_getAcceptorAddr;
78 jmethodID MID_ChannelBinding_getAppData;
79 jmethodID MID_InetAddress_getAddr;
80 jmethodID MID_GSSNameElement_ctor;
81 jmethodID MID_GSSCredElement_ctor;
82 jmethodID MID_NativeGSSContext_ctor;
83 jfieldID FID_GSSLibStub_pMech;
84 jfieldID FID_NativeGSSContext_pContext;
85 jfieldID FID_NativeGSSContext_srcName;
86 jfieldID FID_NativeGSSContext_targetName;
87 jfieldID FID_NativeGSSContext_isInitiator;
88 jfieldID FID_NativeGSSContext_isEstablished;
89 jfieldID FID_NativeGSSContext_delegatedCred;
90 jfieldID FID_NativeGSSContext_flags;
91 jfieldID FID_NativeGSSContext_lifetime;
92 jfieldID FID_NativeGSSContext_actualMech;
93
94 int JGSS_DEBUG;
95
96 JNIEXPORT jint JNICALL
97 JNI_OnLoad(JavaVM *jvm, void *reserved) {
98 JNIEnv *env;
99 jclass cls;
100
101 if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
102 return JNI_EVERSION; /* JNI version not supported */
103 }
104 /* Retrieve and store the classes in global ref */
105 cls = (*env)->FindClass(env, "java/lang/Object");
106 if (cls == NULL) {
107 printf("Couldn't find Object class\n");
108 return JNI_ERR;
109 }
110 CLS_Object = (*env)->NewGlobalRef(env, cls);
111 if (CLS_Object == NULL) {
112 return JNI_ERR;
113 }
114 cls = (*env)->FindClass(env, "java/lang/String");
115 if (cls == NULL) {
116 printf("Couldn't find String class\n");
117 return JNI_ERR;
346 printf("Couldn't find NativeGSSContext.flags field\n");
347 return JNI_ERR;
348 }
349 FID_NativeGSSContext_lifetime =
350 (*env)->GetFieldID(env, CLS_NativeGSSContext, "lifetime", "I");
351 if (FID_NativeGSSContext_lifetime == NULL) {
352 printf("Couldn't find NativeGSSContext.lifetime field\n");
353 return JNI_ERR;
354 }
355 FID_NativeGSSContext_actualMech =
356 (*env)->GetFieldID(env, CLS_NativeGSSContext, "actualMech",
357 "Lorg/ietf/jgss/Oid;");
358 if (FID_NativeGSSContext_actualMech == NULL) {
359 printf("Couldn't find NativeGSSContext.actualMech field\n");
360 return JNI_ERR;
361 }
362 return JNI_VERSION_1_2;
363 }
364
365 JNIEXPORT void JNICALL
366 JNI_OnUnload(JavaVM *jvm, void *reserved) {
367 JNIEnv *env;
368
369 if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
370 return;
371 }
372 /* Delete the global refs */
373 (*env)->DeleteGlobalRef(env, CLS_Object);
374 (*env)->DeleteGlobalRef(env, CLS_String);
375 (*env)->DeleteGlobalRef(env, CLS_Oid);
376 (*env)->DeleteGlobalRef(env, CLS_GSSException);
377 (*env)->DeleteGlobalRef(env, CLS_GSSNameElement);
378 (*env)->DeleteGlobalRef(env, CLS_GSSCredElement);
379 (*env)->DeleteGlobalRef(env, CLS_SunNativeProvider);
380 return;
381 }
382
383 const OM_uint32 JAVA_MAX = GSS_C_INDEFINITE/2;
384
385 /*
386 * Utility routine for converting the C unsigned integer time
|
1 /*
2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #include "NativeUtil.h"
27 #include "NativeFunc.h"
28 #include "jlong.h"
29 #include <jni.h>
30 #include "jni_util.h"
31
32 const int JAVA_DUPLICATE_TOKEN_CODE = 19; /* DUPLICATE_TOKEN */
33 const int JAVA_OLD_TOKEN_CODE = 20; /* OLD_TOKEN */
34 const int JAVA_UNSEQ_TOKEN_CODE = 21; /* UNSEQ_TOKEN */
35 const int JAVA_GAP_TOKEN_CODE = 22; /* GAP_TOKEN */
36 const int JAVA_ERROR_CODE[] = {
37 2, /* BAD_MECH */
38 3, /* BAD_NAME */
39 4, /* BAD_NAMETYPE */
40 1, /* BAD_BINDINGS */
41 5, /* BAD_STATUS */
42 6, /* BAD_MIC */
43 13, /* NO_CRED */
44 12, /* NO_CONTEXT */
45 10, /* DEFECTIVE_TOKEN */
46 9, /* DEFECTIVE_CREDENTIAL */
47 8, /* CREDENTIAL_EXPIRED */
48 7, /* CONTEXT_EXPIRED */
49 11, /* FAILURE */
50 14, /* BAD_QOP */
78 jmethodID MID_ChannelBinding_getAcceptorAddr;
79 jmethodID MID_ChannelBinding_getAppData;
80 jmethodID MID_InetAddress_getAddr;
81 jmethodID MID_GSSNameElement_ctor;
82 jmethodID MID_GSSCredElement_ctor;
83 jmethodID MID_NativeGSSContext_ctor;
84 jfieldID FID_GSSLibStub_pMech;
85 jfieldID FID_NativeGSSContext_pContext;
86 jfieldID FID_NativeGSSContext_srcName;
87 jfieldID FID_NativeGSSContext_targetName;
88 jfieldID FID_NativeGSSContext_isInitiator;
89 jfieldID FID_NativeGSSContext_isEstablished;
90 jfieldID FID_NativeGSSContext_delegatedCred;
91 jfieldID FID_NativeGSSContext_flags;
92 jfieldID FID_NativeGSSContext_lifetime;
93 jfieldID FID_NativeGSSContext_actualMech;
94
95 int JGSS_DEBUG;
96
97 JNIEXPORT jint JNICALL
98 DEF_JNI_OnLoad(JavaVM *jvm, void *reserved) {
99 JNIEnv *env;
100 jclass cls;
101
102 if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
103 return JNI_EVERSION; /* JNI version not supported */
104 }
105 /* Retrieve and store the classes in global ref */
106 cls = (*env)->FindClass(env, "java/lang/Object");
107 if (cls == NULL) {
108 printf("Couldn't find Object class\n");
109 return JNI_ERR;
110 }
111 CLS_Object = (*env)->NewGlobalRef(env, cls);
112 if (CLS_Object == NULL) {
113 return JNI_ERR;
114 }
115 cls = (*env)->FindClass(env, "java/lang/String");
116 if (cls == NULL) {
117 printf("Couldn't find String class\n");
118 return JNI_ERR;
347 printf("Couldn't find NativeGSSContext.flags field\n");
348 return JNI_ERR;
349 }
350 FID_NativeGSSContext_lifetime =
351 (*env)->GetFieldID(env, CLS_NativeGSSContext, "lifetime", "I");
352 if (FID_NativeGSSContext_lifetime == NULL) {
353 printf("Couldn't find NativeGSSContext.lifetime field\n");
354 return JNI_ERR;
355 }
356 FID_NativeGSSContext_actualMech =
357 (*env)->GetFieldID(env, CLS_NativeGSSContext, "actualMech",
358 "Lorg/ietf/jgss/Oid;");
359 if (FID_NativeGSSContext_actualMech == NULL) {
360 printf("Couldn't find NativeGSSContext.actualMech field\n");
361 return JNI_ERR;
362 }
363 return JNI_VERSION_1_2;
364 }
365
366 JNIEXPORT void JNICALL
367 DEF_JNI_OnUnload(JavaVM *jvm, void *reserved) {
368 JNIEnv *env;
369
370 if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
371 return;
372 }
373 /* Delete the global refs */
374 (*env)->DeleteGlobalRef(env, CLS_Object);
375 (*env)->DeleteGlobalRef(env, CLS_String);
376 (*env)->DeleteGlobalRef(env, CLS_Oid);
377 (*env)->DeleteGlobalRef(env, CLS_GSSException);
378 (*env)->DeleteGlobalRef(env, CLS_GSSNameElement);
379 (*env)->DeleteGlobalRef(env, CLS_GSSCredElement);
380 (*env)->DeleteGlobalRef(env, CLS_SunNativeProvider);
381 return;
382 }
383
384 const OM_uint32 JAVA_MAX = GSS_C_INDEFINITE/2;
385
386 /*
387 * Utility routine for converting the C unsigned integer time
|