1 /*
2 * Copyright (c) 2000, 2013, 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
25
26 /*
27 * ===========================================================================
28 * (C) Copyright IBM Corp. 2000 All Rights Reserved.
29 * ===========================================================================
30 */
31
32 #define UNICODE
33 #define _UNICODE
34
35 #include <windows.h>
36 #include <stdio.h>
37 #include <string.h>
38 #define SECURITY_WIN32
39 #include <security.h>
40 #include <ntsecapi.h>
41 #include <dsgetdc.h>
42 #include <lmcons.h>
43 #include <lmapibuf.h>
44 #include <jni.h>
45 #include <winsock.h>
46
47 #undef LSA_SUCCESS
48 #define LSA_SUCCESS(Status) ((Status) >= 0)
49 #define EXIT_FAILURE -1 // mdu
50
51 /*
52 * Library-wide static references
53 */
54
55 jclass derValueClass = NULL;
56 jclass ticketClass = NULL;
57 jclass principalNameClass = NULL;
58 jclass encryptionKeyClass = NULL;
59 jclass ticketFlagsClass = NULL;
60 jclass kerberosTimeClass = NULL;
61 jclass javaLangStringClass = NULL;
62
63 jmethodID derValueConstructor = 0;
64 jmethodID ticketConstructor = 0;
90 InitUnicodeString(
91 PUNICODE_STRING DestinationString,
92 PCWSTR SourceString OPTIONAL
93 );
94
95 jobject BuildTicket(JNIEnv *env, PUCHAR encodedTicket, ULONG encodedTicketSize);
96
97 //mdu
98 jobject BuildPrincipal(JNIEnv *env, PKERB_EXTERNAL_NAME principalName,
99 UNICODE_STRING domainName);
100
101 jobject BuildEncryptionKey(JNIEnv *env, PKERB_CRYPTO_KEY cryptoKey);
102 jobject BuildTicketFlags(JNIEnv *env, PULONG flags);
103 jobject BuildKerberosTime(JNIEnv *env, PLARGE_INTEGER kerbtime);
104
105 /*
106 * Class: sun_security_krb5_KrbCreds
107 * Method: JNI_OnLoad
108 */
109
110 JNIEXPORT jint JNICALL JNI_OnLoad(
111 JavaVM *jvm,
112 void *reserved) {
113
114 jclass cls;
115 JNIEnv *env;
116 jfieldID fldDEBUG;
117
118 if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
119 return JNI_EVERSION; /* JNI version not supported */
120 }
121
122 cls = (*env)->FindClass(env,"sun/security/krb5/internal/Krb5");
123 if (cls == NULL) {
124 printf("LSA: Couldn't find Krb5\n");
125 return JNI_ERR;
126 }
127 fldDEBUG = (*env)->GetStaticFieldID(env, cls, "DEBUG", "Z");
128 if (fldDEBUG == NULL) {
129 printf("LSA: Krb5 has no DEBUG field\n");
130 return JNI_ERR;
312 if (kerberosTimeConstructor == 0) {
313 printf("LSA: Couldn't find KerberosTime constructor\n");
314 return JNI_ERR;
315 }
316 if (native_debug) {
317 printf("LSA: Found KerberosTime constructor\n");
318 }
319
320 if (native_debug) {
321 printf("LSA: Finished OnLoad processing\n");
322 }
323
324 return JNI_VERSION_1_2;
325 }
326
327 /*
328 * Class: sun_security_jgss_KrbCreds
329 * Method: JNI_OnUnload
330 */
331
332 JNIEXPORT void JNICALL JNI_OnUnload(
333 JavaVM *jvm,
334 void *reserved) {
335
336 JNIEnv *env;
337
338 if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
339 return; /* Nothing else we can do */
340 }
341
342 if (ticketClass != NULL) {
343 (*env)->DeleteWeakGlobalRef(env,ticketClass);
344 }
345 if (derValueClass != NULL) {
346 (*env)->DeleteWeakGlobalRef(env,derValueClass);
347 }
348 if (principalNameClass != NULL) {
349 (*env)->DeleteWeakGlobalRef(env,principalNameClass);
350 }
351 if (encryptionKeyClass != NULL) {
352 (*env)->DeleteWeakGlobalRef(env,encryptionKeyClass);
|
1 /*
2 * Copyright (c) 2000, 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
25
26 /*
27 * ===========================================================================
28 * (C) Copyright IBM Corp. 2000 All Rights Reserved.
29 * ===========================================================================
30 */
31
32 #define UNICODE
33 #define _UNICODE
34
35 #include <windows.h>
36 #include <stdio.h>
37 #include <string.h>
38 #define SECURITY_WIN32
39 #include <security.h>
40 #include <ntsecapi.h>
41 #include <dsgetdc.h>
42 #include <lmcons.h>
43 #include <lmapibuf.h>
44 #include <jni.h>
45 #include "jni_util.h"
46 #include <winsock.h>
47
48 #undef LSA_SUCCESS
49 #define LSA_SUCCESS(Status) ((Status) >= 0)
50 #define EXIT_FAILURE -1 // mdu
51
52 /*
53 * Library-wide static references
54 */
55
56 jclass derValueClass = NULL;
57 jclass ticketClass = NULL;
58 jclass principalNameClass = NULL;
59 jclass encryptionKeyClass = NULL;
60 jclass ticketFlagsClass = NULL;
61 jclass kerberosTimeClass = NULL;
62 jclass javaLangStringClass = NULL;
63
64 jmethodID derValueConstructor = 0;
65 jmethodID ticketConstructor = 0;
91 InitUnicodeString(
92 PUNICODE_STRING DestinationString,
93 PCWSTR SourceString OPTIONAL
94 );
95
96 jobject BuildTicket(JNIEnv *env, PUCHAR encodedTicket, ULONG encodedTicketSize);
97
98 //mdu
99 jobject BuildPrincipal(JNIEnv *env, PKERB_EXTERNAL_NAME principalName,
100 UNICODE_STRING domainName);
101
102 jobject BuildEncryptionKey(JNIEnv *env, PKERB_CRYPTO_KEY cryptoKey);
103 jobject BuildTicketFlags(JNIEnv *env, PULONG flags);
104 jobject BuildKerberosTime(JNIEnv *env, PLARGE_INTEGER kerbtime);
105
106 /*
107 * Class: sun_security_krb5_KrbCreds
108 * Method: JNI_OnLoad
109 */
110
111 JNIEXPORT jint JNICALL DEF_JNI_OnLoad(
112 JavaVM *jvm,
113 void *reserved) {
114
115 jclass cls;
116 JNIEnv *env;
117 jfieldID fldDEBUG;
118
119 if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
120 return JNI_EVERSION; /* JNI version not supported */
121 }
122
123 cls = (*env)->FindClass(env,"sun/security/krb5/internal/Krb5");
124 if (cls == NULL) {
125 printf("LSA: Couldn't find Krb5\n");
126 return JNI_ERR;
127 }
128 fldDEBUG = (*env)->GetStaticFieldID(env, cls, "DEBUG", "Z");
129 if (fldDEBUG == NULL) {
130 printf("LSA: Krb5 has no DEBUG field\n");
131 return JNI_ERR;
313 if (kerberosTimeConstructor == 0) {
314 printf("LSA: Couldn't find KerberosTime constructor\n");
315 return JNI_ERR;
316 }
317 if (native_debug) {
318 printf("LSA: Found KerberosTime constructor\n");
319 }
320
321 if (native_debug) {
322 printf("LSA: Finished OnLoad processing\n");
323 }
324
325 return JNI_VERSION_1_2;
326 }
327
328 /*
329 * Class: sun_security_jgss_KrbCreds
330 * Method: JNI_OnUnload
331 */
332
333 JNIEXPORT void JNICALL DEF_JNI_OnUnload(
334 JavaVM *jvm,
335 void *reserved) {
336
337 JNIEnv *env;
338
339 if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
340 return; /* Nothing else we can do */
341 }
342
343 if (ticketClass != NULL) {
344 (*env)->DeleteWeakGlobalRef(env,ticketClass);
345 }
346 if (derValueClass != NULL) {
347 (*env)->DeleteWeakGlobalRef(env,derValueClass);
348 }
349 if (principalNameClass != NULL) {
350 (*env)->DeleteWeakGlobalRef(env,principalNameClass);
351 }
352 if (encryptionKeyClass != NULL) {
353 (*env)->DeleteWeakGlobalRef(env,encryptionKeyClass);
|