< prev index next >

src/java.security.jgss/macosx/native/libosxkrb5/nativeccache.c

Print this page


   1 /*
   2  * Copyright (c) 2011, 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
  23  * questions.
  24  */
  25 
  26 #import "sun_security_krb5_Credentials.h"
  27 #import <Kerberos/Kerberos.h>
  28 #import <string.h>
  29 #import <time.h>
  30 


  31 /*
  32  * Based largely on klist.c,
  33  *
  34  * Created by Scott Kovatch on 8/12/04.
  35  *
  36  * See http://www.opensource.apple.com/darwinsource/10.3.3/Kerberos-47/KerberosClients/klist/Sources/klist.c
  37 
  38  */
  39 
  40 /*
  41  * Statics for this module
  42  */
  43 
  44 static jclass derValueClass = NULL;
  45 static jclass ticketClass = NULL;
  46 static jclass principalNameClass = NULL;
  47 static jclass encryptionKeyClass = NULL;
  48 static jclass ticketFlagsClass = NULL;
  49 static jclass kerberosTimeClass = NULL;
  50 static jclass javaLangStringClass = NULL;


  75 static jobject BuildAddressList(JNIEnv *env, krb5_address **kerbtime);
  76 
  77 static void printiferr (errcode_t err, const char *format, ...);
  78 
  79 static jclass FindClass(JNIEnv *env, char *className)
  80 {
  81     jclass cls = (*env)->FindClass(env, className);
  82 
  83     if (cls == NULL) {
  84         printf("Couldn't find %s\n", className);
  85         return NULL;
  86     }
  87 
  88     jobject returnValue = (*env)->NewWeakGlobalRef(env,cls);
  89     return returnValue;
  90 }
  91 /*
  92  * Class:     sun_security_krb5_KrbCreds
  93  * Method:    JNI_OnLoad
  94  */
  95 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
  96 {
  97     JNIEnv *env;
  98 
  99     if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_4)) {
 100         return JNI_EVERSION; /* JNI version not supported */
 101     }
 102 
 103     ticketClass = FindClass(env, "sun/security/krb5/internal/Ticket");
 104     if (ticketClass == NULL) return JNI_ERR;
 105 
 106     principalNameClass = FindClass(env, "sun/security/krb5/PrincipalName");
 107     if (principalNameClass == NULL) return JNI_ERR;
 108 
 109     derValueClass = FindClass(env, "sun/security/util/DerValue");
 110     if (derValueClass == NULL) return JNI_ERR;
 111 
 112     encryptionKeyClass = FindClass(env, "sun/security/krb5/EncryptionKey");
 113     if (encryptionKeyClass == NULL) return JNI_ERR;
 114 
 115     ticketFlagsClass = FindClass(env,"sun/security/krb5/internal/TicketFlags");


 174 
 175     hostAddressConstructor = (*env)->GetMethodID(env, hostAddressClass, "<init>", "(I[B)V");
 176     if (hostAddressConstructor == 0) {
 177         printf("Couldn't find HostAddress constructor\n");
 178         return JNI_ERR;
 179     }
 180 
 181     hostAddressesConstructor = (*env)->GetMethodID(env, hostAddressesClass, "<init>", "([Lsun/security/krb5/internal/HostAddress;)V");
 182     if (hostAddressesConstructor == 0) {
 183         printf("Couldn't find HostAddresses constructor\n");
 184         return JNI_ERR;
 185     }
 186 
 187     return JNI_VERSION_1_2;
 188 }
 189 
 190 /*
 191  * Class:     sun_security_jgss_KrbCreds
 192  * Method:    JNI_OnUnload
 193  */
 194 JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jvm, void *reserved)
 195 {
 196     JNIEnv *env;
 197 
 198     if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
 199         return; /* Nothing else we can do */
 200     }
 201 
 202     if (ticketClass != NULL) {
 203         (*env)->DeleteWeakGlobalRef(env,ticketClass);
 204     }
 205     if (derValueClass != NULL) {
 206         (*env)->DeleteWeakGlobalRef(env,derValueClass);
 207     }
 208     if (principalNameClass != NULL) {
 209         (*env)->DeleteWeakGlobalRef(env,principalNameClass);
 210     }
 211     if (encryptionKeyClass != NULL) {
 212         (*env)->DeleteWeakGlobalRef(env,encryptionKeyClass);
 213     }
 214     if (ticketFlagsClass != NULL) {


   1 /*
   2  * Copyright (c) 2011, 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 #import "sun_security_krb5_Credentials.h"
  27 #import <Kerberos/Kerberos.h>
  28 #import <string.h>
  29 #import <time.h>
  30 
  31 #include "jni_util.h"
  32 
  33 /*
  34  * Based largely on klist.c,
  35  *
  36  * Created by Scott Kovatch on 8/12/04.
  37  *
  38  * See http://www.opensource.apple.com/darwinsource/10.3.3/Kerberos-47/KerberosClients/klist/Sources/klist.c
  39 
  40  */
  41 
  42 /*
  43  * Statics for this module
  44  */
  45 
  46 static jclass derValueClass = NULL;
  47 static jclass ticketClass = NULL;
  48 static jclass principalNameClass = NULL;
  49 static jclass encryptionKeyClass = NULL;
  50 static jclass ticketFlagsClass = NULL;
  51 static jclass kerberosTimeClass = NULL;
  52 static jclass javaLangStringClass = NULL;


  77 static jobject BuildAddressList(JNIEnv *env, krb5_address **kerbtime);
  78 
  79 static void printiferr (errcode_t err, const char *format, ...);
  80 
  81 static jclass FindClass(JNIEnv *env, char *className)
  82 {
  83     jclass cls = (*env)->FindClass(env, className);
  84 
  85     if (cls == NULL) {
  86         printf("Couldn't find %s\n", className);
  87         return NULL;
  88     }
  89 
  90     jobject returnValue = (*env)->NewWeakGlobalRef(env,cls);
  91     return returnValue;
  92 }
  93 /*
  94  * Class:     sun_security_krb5_KrbCreds
  95  * Method:    JNI_OnLoad
  96  */
  97 JNIEXPORT jint JNICALL DEF_JNI_OnLoad(JavaVM *jvm, void *reserved)
  98 {
  99     JNIEnv *env;
 100 
 101     if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_4)) {
 102         return JNI_EVERSION; /* JNI version not supported */
 103     }
 104 
 105     ticketClass = FindClass(env, "sun/security/krb5/internal/Ticket");
 106     if (ticketClass == NULL) return JNI_ERR;
 107 
 108     principalNameClass = FindClass(env, "sun/security/krb5/PrincipalName");
 109     if (principalNameClass == NULL) return JNI_ERR;
 110 
 111     derValueClass = FindClass(env, "sun/security/util/DerValue");
 112     if (derValueClass == NULL) return JNI_ERR;
 113 
 114     encryptionKeyClass = FindClass(env, "sun/security/krb5/EncryptionKey");
 115     if (encryptionKeyClass == NULL) return JNI_ERR;
 116 
 117     ticketFlagsClass = FindClass(env,"sun/security/krb5/internal/TicketFlags");


 176 
 177     hostAddressConstructor = (*env)->GetMethodID(env, hostAddressClass, "<init>", "(I[B)V");
 178     if (hostAddressConstructor == 0) {
 179         printf("Couldn't find HostAddress constructor\n");
 180         return JNI_ERR;
 181     }
 182 
 183     hostAddressesConstructor = (*env)->GetMethodID(env, hostAddressesClass, "<init>", "([Lsun/security/krb5/internal/HostAddress;)V");
 184     if (hostAddressesConstructor == 0) {
 185         printf("Couldn't find HostAddresses constructor\n");
 186         return JNI_ERR;
 187     }
 188 
 189     return JNI_VERSION_1_2;
 190 }
 191 
 192 /*
 193  * Class:     sun_security_jgss_KrbCreds
 194  * Method:    JNI_OnUnload
 195  */
 196 JNIEXPORT void JNICALL DEF_JNI_OnUnload(JavaVM *jvm, void *reserved)
 197 {
 198     JNIEnv *env;
 199 
 200     if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
 201         return; /* Nothing else we can do */
 202     }
 203 
 204     if (ticketClass != NULL) {
 205         (*env)->DeleteWeakGlobalRef(env,ticketClass);
 206     }
 207     if (derValueClass != NULL) {
 208         (*env)->DeleteWeakGlobalRef(env,derValueClass);
 209     }
 210     if (principalNameClass != NULL) {
 211         (*env)->DeleteWeakGlobalRef(env,principalNameClass);
 212     }
 213     if (encryptionKeyClass != NULL) {
 214         (*env)->DeleteWeakGlobalRef(env,encryptionKeyClass);
 215     }
 216     if (ticketFlagsClass != NULL) {


< prev index next >