src/java.security.jgss/share/native/libj2gss/NativeUtil.c
changeset 49682 2918e1146106
parent 47216 71c04702a3d5
child 52134 a35cc060f251
equal deleted inserted replaced
49681:4beba2c2a329 49682:2918e1146106
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   467   jbyteArray jbytes;
   467   jbyteArray jbytes;
   468 
   468 
   469   if (bytes != NULL) {
   469   if (bytes != NULL) {
   470     /* constructs the String object with new String(byte[])
   470     /* constructs the String object with new String(byte[])
   471        NOTE: do NOT include the trailing NULL */
   471        NOTE: do NOT include the trailing NULL */
   472     len = bytes->length;
   472     len = (int) bytes->length;
   473     jbytes = (*env)->NewByteArray(env, len);
   473     jbytes = (*env)->NewByteArray(env, len);
   474     if (jbytes == NULL) {
   474     if (jbytes == NULL) {
   475       goto finish;
   475       goto finish;
   476     }
   476     }
   477 
   477 
   495  */
   495  */
   496 jstring getMinorMessage(JNIEnv *env, jobject jstub, OM_uint32 statusValue) {
   496 jstring getMinorMessage(JNIEnv *env, jobject jstub, OM_uint32 statusValue) {
   497   OM_uint32 messageContext, minor, major;
   497   OM_uint32 messageContext, minor, major;
   498   gss_buffer_desc statusString;
   498   gss_buffer_desc statusString;
   499   gss_OID mech;
   499   gss_OID mech;
   500   jstring msg;
       
   501 
   500 
   502   messageContext = 0;
   501   messageContext = 0;
   503   if (jstub != NULL) {
   502   if (jstub != NULL) {
   504     mech = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jstub, FID_GSSLibStub_pMech));
   503     mech = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jstub, FID_GSSLibStub_pMech));
   505   } else {
   504   } else {
   634   jbyteArray result = NULL;
   633   jbyteArray result = NULL;
   635   OM_uint32 minor; // don't care, just so it compiles
   634   OM_uint32 minor; // don't care, just so it compiles
   636 
   635 
   637   if (cbytes != NULL) {
   636   if (cbytes != NULL) {
   638     if ((cbytes != GSS_C_NO_BUFFER) && (cbytes->length != 0)) {
   637     if ((cbytes != GSS_C_NO_BUFFER) && (cbytes->length != 0)) {
   639       result = (*env)->NewByteArray(env, cbytes->length);
   638       result = (*env)->NewByteArray(env, (int) cbytes->length);
   640       if (result == NULL) {
   639       if (result == NULL) {
   641         goto finish;
   640         goto finish;
   642       }
   641       }
   643       (*env)->SetByteArrayRegion(env, result, 0, cbytes->length,
   642       (*env)->SetByteArrayRegion(env, result, 0, (int) cbytes->length,
   644                                  cbytes->value);
   643                                  cbytes->value);
   645       if ((*env)->ExceptionCheck(env)) {
   644       if ((*env)->ExceptionCheck(env)) {
   646         result = NULL;
   645         result = NULL;
   647       }
   646       }
   648     }
   647     }
   659  * NOTE: must call deleteGSSOID(...) to free up the gss_OID.
   658  * NOTE: must call deleteGSSOID(...) to free up the gss_OID.
   660  */
   659  */
   661 gss_OID newGSSOID(JNIEnv *env, jobject jOid) {
   660 gss_OID newGSSOID(JNIEnv *env, jobject jOid) {
   662   jbyteArray jbytes;
   661   jbyteArray jbytes;
   663   gss_OID cOid;
   662   gss_OID cOid;
   664   jthrowable gssEx;
       
   665   if (jOid != NULL) {
   663   if (jOid != NULL) {
   666     jbytes = (*env)->CallObjectMethod(env, jOid, MID_Oid_getDER);
   664     jbytes = (*env)->CallObjectMethod(env, jOid, MID_Oid_getDER);
   667     if ((*env)->ExceptionCheck(env)) {
   665     if ((*env)->ExceptionCheck(env)) {
   668       return GSS_C_NO_OID;
   666       return GSS_C_NO_OID;
   669     }
   667     }
   781 jobjectArray getJavaOIDArray(JNIEnv *env, gss_OID_set cOidSet) {
   779 jobjectArray getJavaOIDArray(JNIEnv *env, gss_OID_set cOidSet) {
   782   int numOfOids = 0;
   780   int numOfOids = 0;
   783   jobjectArray jOidSet;
   781   jobjectArray jOidSet;
   784   jobject jOid;
   782   jobject jOid;
   785   int i;
   783   int i;
   786   jthrowable gssEx;
       
   787 
   784 
   788   if (cOidSet != NULL && cOidSet != GSS_C_NO_OID_SET) {
   785   if (cOidSet != NULL && cOidSet != GSS_C_NO_OID_SET) {
   789     numOfOids = cOidSet->count;
   786     numOfOids = (int) cOidSet->count;
   790     jOidSet = (*env)->NewObjectArray(env, numOfOids, CLS_Oid, NULL);
   787     jOidSet = (*env)->NewObjectArray(env, numOfOids, CLS_Oid, NULL);
   791     if ((*env)->ExceptionCheck(env)) {
   788     if ((*env)->ExceptionCheck(env)) {
   792       return NULL;
   789       return NULL;
   793     }
   790     }
   794     for (i = 0; i < numOfOids; i++) {
   791     for (i = 0; i < numOfOids; i++) {