jdk/src/java.security.jgss/share/native/libj2gss/NativeUtil.c
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 23585 jdk/src/share/native/sun/security/jgss/wrapper/NativeUtil.c@e4412d1b53d3
child 33653 c1ee09fe3274
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
     2
 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "NativeUtil.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "NativeFunc.h"
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
    28
#include "jlong.h"
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14414
diff changeset
    29
#include <jni.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
const int JAVA_DUPLICATE_TOKEN_CODE = 19; /* DUPLICATE_TOKEN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
const int JAVA_OLD_TOKEN_CODE = 20; /* OLD_TOKEN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
const int JAVA_UNSEQ_TOKEN_CODE = 21; /* UNSEQ_TOKEN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
const int JAVA_GAP_TOKEN_CODE = 22; /* GAP_TOKEN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
const int JAVA_ERROR_CODE[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  2,  /* BAD_MECH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  3,  /* BAD_NAME */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  4,  /* BAD_NAMETYPE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  1,  /* BAD_BINDINGS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  5,  /* BAD_STATUS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  6,  /* BAD_MIC */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  13, /* NO_CRED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  12, /* NO_CONTEXT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  10, /* DEFECTIVE_TOKEN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  9,  /* DEFECTIVE_CREDENTIAL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  8,  /* CREDENTIAL_EXPIRED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  7,  /* CONTEXT_EXPIRED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  11, /* FAILURE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  14, /* BAD_QOP */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  15, /* UNAUTHORIZED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  16, /* UNAVAILABLE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  17, /* DUPLICATE_ELEMENT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  18, /* NAME_NOT_MN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
const char SPNEGO_BYTES[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
jclass CLS_Object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
jclass CLS_String;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
jclass CLS_Oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
jclass CLS_GSSException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
jclass CLS_GSSNameElement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
jclass CLS_GSSCredElement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
jclass CLS_NativeGSSContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
jclass CLS_SunNativeProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
jmethodID MID_String_ctor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
jmethodID MID_Oid_ctor1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
jmethodID MID_Oid_getDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
jmethodID MID_MessageProp_getPrivacy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
jmethodID MID_MessageProp_getQOP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
jmethodID MID_MessageProp_setPrivacy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
jmethodID MID_MessageProp_setQOP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
jmethodID MID_MessageProp_setSupplementaryStates;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
jmethodID MID_GSSException_ctor3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
jmethodID MID_ChannelBinding_getInitiatorAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
jmethodID MID_ChannelBinding_getAcceptorAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
jmethodID MID_ChannelBinding_getAppData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
jmethodID MID_InetAddress_getAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
jmethodID MID_GSSNameElement_ctor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
jmethodID MID_GSSCredElement_ctor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
jmethodID MID_NativeGSSContext_ctor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
jfieldID FID_GSSLibStub_pMech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
jfieldID FID_NativeGSSContext_pContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
jfieldID FID_NativeGSSContext_srcName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
jfieldID FID_NativeGSSContext_targetName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
jfieldID FID_NativeGSSContext_isInitiator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
jfieldID FID_NativeGSSContext_isEstablished;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
jfieldID FID_NativeGSSContext_delegatedCred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
jfieldID FID_NativeGSSContext_flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
jfieldID FID_NativeGSSContext_lifetime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
jfieldID FID_NativeGSSContext_actualMech;
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
    93
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
    94
int JGSS_DEBUG;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
JNI_OnLoad(JavaVM *jvm, void *reserved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  jclass cls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    return JNI_EVERSION; /* JNI version not supported */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  /* Retrieve and store the classes in global ref */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
  cls = (*env)->FindClass(env, "java/lang/Object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  if (cls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    printf("Couldn't find Object class\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
  CLS_Object = (*env)->NewGlobalRef(env, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
  if (CLS_Object == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
  cls = (*env)->FindClass(env, "java/lang/String");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
  if (cls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    printf("Couldn't find String class\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
  CLS_String = (*env)->NewGlobalRef(env, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
  if (CLS_String == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  cls = (*env)->FindClass(env, "org/ietf/jgss/Oid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  if (cls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    printf("Couldn't find org.ietf.jgss.Oid class\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  CLS_Oid = (*env)->NewGlobalRef(env, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  if (CLS_Oid == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  cls = (*env)->FindClass(env, "org/ietf/jgss/GSSException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  if (cls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    printf("Couldn't find org.ietf.jgss.GSSException class\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
  CLS_GSSException = (*env)->NewGlobalRef(env, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
  if (CLS_GSSException == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
  cls = (*env)->FindClass(env, "sun/security/jgss/wrapper/GSSNameElement");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
  if (cls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    printf("Couldn't find sun.security.jgss.wrapper.GSSNameElement class\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
  CLS_GSSNameElement = (*env)->NewGlobalRef(env, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
  if (CLS_GSSException == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
  cls = (*env)->FindClass(env, "sun/security/jgss/wrapper/GSSCredElement");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
  if (cls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    printf("Couldn't find sun.security.jgss.wrapper.GSSCredElement class\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
  CLS_GSSCredElement = (*env)->NewGlobalRef(env, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  if (CLS_GSSCredElement == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
  cls = (*env)->FindClass(env, "sun/security/jgss/wrapper/NativeGSSContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
  if (cls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    printf("Couldn't find sun.security.jgss.wrapper.NativeGSSContext class\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
  CLS_NativeGSSContext = (*env)->NewGlobalRef(env, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
  if (CLS_NativeGSSContext == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
  cls = (*env)->FindClass(env, "sun/security/jgss/wrapper/SunNativeProvider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
  if (cls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    printf("Couldn't find sun.security.jgss.wrapper.SunNativeProvider class\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
  CLS_SunNativeProvider = (*env)->NewGlobalRef(env, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
  if (CLS_SunNativeProvider == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
  /* Compute and cache the method ID */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
  MID_String_ctor = (*env)->GetMethodID(env, CLS_String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                        "<init>", "([B)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
  if (MID_String_ctor == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    printf("Couldn't find String(byte[]) constructor\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
  MID_Oid_ctor1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    (*env)->GetMethodID(env, CLS_Oid, "<init>", "([B)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
  if (MID_Oid_ctor1 == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    printf("Couldn't find Oid(byte[]) constructor\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
  MID_Oid_getDER = (*env)->GetMethodID(env, CLS_Oid, "getDER", "()[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
  if (MID_Oid_getDER == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    printf("Couldn't find Oid.getDER() method\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
  cls = (*env)->FindClass(env, "org/ietf/jgss/MessageProp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
  if (cls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    printf("Couldn't find org.ietf.jgss.MessageProp class\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
  MID_MessageProp_getPrivacy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    (*env)->GetMethodID(env, cls, "getPrivacy", "()Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
  if (MID_MessageProp_getPrivacy == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    printf("Couldn't find MessageProp.getPrivacy() method\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
  MID_MessageProp_getQOP = (*env)->GetMethodID(env, cls, "getQOP", "()I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
  if (MID_MessageProp_getQOP == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    printf("Couldn't find MessageProp.getQOP() method\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
  MID_MessageProp_setPrivacy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    (*env)->GetMethodID(env, cls, "setPrivacy", "(Z)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
  if (MID_MessageProp_setPrivacy == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    printf("Couldn't find MessageProp.setPrivacy(boolean) method\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
  MID_MessageProp_setQOP = (*env)->GetMethodID(env, cls, "setQOP", "(I)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
  if (MID_MessageProp_setQOP == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    printf("Couldn't find MessageProp.setQOP(int) method\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
  MID_MessageProp_setSupplementaryStates =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    (*env)->GetMethodID(env, cls, "setSupplementaryStates",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                        "(ZZZZILjava/lang/String;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
  if (MID_MessageProp_setSupplementaryStates == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    printf("Couldn't find MessageProp.setSupplementaryStates(...) method\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
  MID_GSSException_ctor3 = (*env)->GetMethodID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    (env, CLS_GSSException, "<init>", "(IILjava/lang/String;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
  if (MID_GSSException_ctor3 == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    printf("Couldn't find GSSException(int, int, String) constructor\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
  cls = (*env)->FindClass(env, "org/ietf/jgss/ChannelBinding");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
  if (cls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    printf("Couldn't find org.ietf.jgss.ChannelBinding class\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
  MID_ChannelBinding_getInitiatorAddr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    (*env)->GetMethodID(env, cls, "getInitiatorAddress",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        "()Ljava/net/InetAddress;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
  if (MID_ChannelBinding_getInitiatorAddr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    printf("Couldn't find ChannelBinding.getInitiatorAddress() method\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
  MID_ChannelBinding_getAcceptorAddr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    (*env)->GetMethodID(env, cls, "getAcceptorAddress",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                        "()Ljava/net/InetAddress;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
  if (MID_ChannelBinding_getAcceptorAddr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    printf("Couldn't find ChannelBinding.getAcceptorAddress() method\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
  MID_ChannelBinding_getAppData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    (*env)->GetMethodID(env, cls, "getApplicationData", "()[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
  if (MID_ChannelBinding_getAppData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    printf("Couldn't find ChannelBinding.getApplicationData() method\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
  cls = (*env)->FindClass(env, "java/net/InetAddress");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
  if (cls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    printf("Couldn't find java.net.InetAddress class\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
  MID_InetAddress_getAddr = (*env)->GetMethodID(env, cls, "getAddress",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                                "()[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
  if (MID_InetAddress_getAddr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    printf("Couldn't find InetAddress.getAddress() method\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
  MID_GSSNameElement_ctor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    (*env)->GetMethodID(env, CLS_GSSNameElement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                        "<init>", "(JLsun/security/jgss/wrapper/GSSLibStub;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
  if (MID_GSSNameElement_ctor == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    printf("Couldn't find GSSNameElement(long, GSSLibStub) constructor\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
  MID_GSSCredElement_ctor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    (*env)->GetMethodID(env, CLS_GSSCredElement, "<init>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        "(JLsun/security/jgss/wrapper/GSSNameElement;Lorg/ietf/jgss/Oid;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
  if (MID_GSSCredElement_ctor == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    printf("Couldn't find GSSCredElement(long, GSSLibStub) constructor\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
  MID_NativeGSSContext_ctor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    (*env)->GetMethodID(env, CLS_NativeGSSContext, "<init>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                        "(JLsun/security/jgss/wrapper/GSSLibStub;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
  if (MID_NativeGSSContext_ctor == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    printf("Couldn't find NativeGSSContext(long, GSSLibStub) constructor\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
  /* Compute and cache the field ID */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
  cls = (*env)->FindClass(env, "sun/security/jgss/wrapper/GSSLibStub");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
  if (cls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    printf("Couldn't find sun.security.jgss.wrapper.GSSLibStub class\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
  FID_GSSLibStub_pMech =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    (*env)->GetFieldID(env, cls, "pMech", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
  if (FID_GSSLibStub_pMech == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    printf("Couldn't find GSSLibStub.pMech field\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
  FID_NativeGSSContext_pContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    (*env)->GetFieldID(env, CLS_NativeGSSContext, "pContext", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
  if (FID_NativeGSSContext_pContext == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    printf("Couldn't find NativeGSSContext.pContext field\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
  FID_NativeGSSContext_srcName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    (*env)->GetFieldID(env, CLS_NativeGSSContext, "srcName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                       "Lsun/security/jgss/wrapper/GSSNameElement;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
  if (FID_NativeGSSContext_srcName == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    printf("Couldn't find NativeGSSContext.srcName field\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
   return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
  FID_NativeGSSContext_targetName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    (*env)->GetFieldID(env, CLS_NativeGSSContext, "targetName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                       "Lsun/security/jgss/wrapper/GSSNameElement;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
  if (FID_NativeGSSContext_targetName == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    printf("Couldn't find NativeGSSContext.targetName field\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
  FID_NativeGSSContext_isInitiator =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    (*env)->GetFieldID(env, CLS_NativeGSSContext, "isInitiator", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
  if (FID_NativeGSSContext_isInitiator == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    printf("Couldn't find NativeGSSContext.isInitiator field\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
  FID_NativeGSSContext_isEstablished =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    (*env)->GetFieldID(env, CLS_NativeGSSContext, "isEstablished", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
  if (FID_NativeGSSContext_isEstablished == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    printf("Couldn't find NativeGSSContext.isEstablished field\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
  FID_NativeGSSContext_delegatedCred =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    (*env)->GetFieldID(env, CLS_NativeGSSContext, "delegatedCred",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                       "Lsun/security/jgss/wrapper/GSSCredElement;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
  if (FID_NativeGSSContext_delegatedCred == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    printf("Couldn't find NativeGSSContext.delegatedCred field\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
  FID_NativeGSSContext_flags =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    (*env)->GetFieldID(env, CLS_NativeGSSContext, "flags", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
  if (FID_NativeGSSContext_flags == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    printf("Couldn't find NativeGSSContext.flags field\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
  FID_NativeGSSContext_lifetime =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    (*env)->GetFieldID(env, CLS_NativeGSSContext, "lifetime", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
  if (FID_NativeGSSContext_lifetime == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    printf("Couldn't find NativeGSSContext.lifetime field\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
  FID_NativeGSSContext_actualMech =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    (*env)->GetFieldID(env, CLS_NativeGSSContext, "actualMech",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                       "Lorg/ietf/jgss/Oid;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
  if (FID_NativeGSSContext_actualMech == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    printf("Couldn't find NativeGSSContext.actualMech field\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
  return JNI_VERSION_1_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
JNI_OnUnload(JavaVM *jvm, void *reserved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
  JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
  if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
  /* Delete the global refs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
  (*env)->DeleteGlobalRef(env, CLS_Object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
  (*env)->DeleteGlobalRef(env, CLS_String);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
  (*env)->DeleteGlobalRef(env, CLS_Oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
  (*env)->DeleteGlobalRef(env, CLS_GSSException);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
  (*env)->DeleteGlobalRef(env, CLS_GSSNameElement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
  (*env)->DeleteGlobalRef(env, CLS_GSSCredElement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
  (*env)->DeleteGlobalRef(env, CLS_SunNativeProvider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
const OM_uint32 JAVA_MAX = GSS_C_INDEFINITE/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
 * Utility routine for converting the C unsigned integer time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
 * to Java signed integer time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
jint getJavaTime(OM_uint32 ctime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
  jint result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
  /* special handle values equals or more than JAVA_MAX */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
  if (ctime == GSS_C_INDEFINITE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    result = JAVA_MAX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
  } else if (ctime >= JAVA_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    result = JAVA_MAX-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    result = ctime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
  return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
 * Utility routine for converting the Java signed integer time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
 * to C unsigned integer time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
OM_uint32 getGSSTime(jint jtime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
  OM_uint32 result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
  /* special handle values equal to JAVA_MAX */
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   410
  if (jtime == (jint)JAVA_MAX) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    result = GSS_C_INDEFINITE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    result = jtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
  return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
 * Utility routine for mapping the C error code to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
 * Java one. The routine errors really should have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
 * shared the same values but unfortunately don't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
jint getJavaErrorCode(int cNonCallingErr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
  int cRoutineErr, cSuppStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
  /* map the routine errors */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
  cRoutineErr = GSS_ROUTINE_ERROR(cNonCallingErr) >> 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
  if (cRoutineErr != GSS_S_COMPLETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    return JAVA_ERROR_CODE[cRoutineErr-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
  /* map the supplementary infos */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
  cSuppStatus = GSS_SUPPLEMENTARY_INFO(cNonCallingErr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
  if (cSuppStatus & GSS_S_DUPLICATE_TOKEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    return JAVA_DUPLICATE_TOKEN_CODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
  } else if (cSuppStatus & GSS_S_OLD_TOKEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    return JAVA_OLD_TOKEN_CODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
  } else if (cSuppStatus & GSS_S_UNSEQ_TOKEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    return JAVA_UNSEQ_TOKEN_CODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
  } else if (cSuppStatus & GSS_S_GAP_TOKEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    return JAVA_GAP_TOKEN_CODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
  return GSS_S_COMPLETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
}
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   442
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   443
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   444
/* Throws a Java Exception by name */
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   445
void throwByName(JNIEnv *env, const char *name, const char *msg) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   446
    jclass cls = (*env)->FindClass(env, name);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   447
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   448
    if (cls != NULL) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   449
        (*env)->ThrowNew(env, cls, msg);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   450
    }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   451
}
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   452
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   453
void throwOutOfMemoryError(JNIEnv *env, const char *message) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   454
    throwByName(env, "java/lang/OutOfMemoryError", message);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   455
}
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   456
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
 * Utility routine for creating a java.lang.String object
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   459
 * using the specified gss_buffer_t structure. The specified
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   460
 * gss_buffer_t structure is always released.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
jstring getJavaString(JNIEnv *env, gss_buffer_t bytes) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   463
  jstring result = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
  OM_uint32 minor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
  int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
  jbyteArray jbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
  if (bytes != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /* constructs the String object with new String(byte[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
       NOTE: do NOT include the trailing NULL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    len = bytes->length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    jbytes = (*env)->NewByteArray(env, len);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   473
    if (jbytes == NULL) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   474
      goto finish;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   475
    }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   476
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    (*env)->SetByteArrayRegion(env, jbytes, 0, len, (jbyte *) bytes->value);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   478
    if ((*env)->ExceptionCheck(env)) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   479
      goto finish;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   480
    }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   481
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    result = (*env)->NewObject(env, CLS_String, MID_String_ctor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                               jbytes);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   484
  finish:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    (*env)->DeleteLocalRef(env, jbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    (*ftab->releaseBuffer)(&minor, bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
  } /* else fall through */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
  return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
 * Utility routine for generate message for the specified minor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
 * status code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
jstring getMinorMessage(JNIEnv *env, jobject jstub, OM_uint32 statusValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
  OM_uint32 messageContext, minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
  gss_buffer_desc statusString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
  gss_OID mech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
  jstring msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
  messageContext = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
  if (jstub != NULL) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   503
    mech = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jstub, FID_GSSLibStub_pMech));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    mech = GSS_C_NO_OID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
  }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   507
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
  /* gss_display_status(...) => GSS_S_BAD_MECH, GSS_S_BAD_STATUS */
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   509
  // TBD: check messageContext value and repeat the call if necessary
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
  major = (*ftab->displayStatus)(&minor, statusValue, GSS_C_MECH_CODE, mech,
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   511
                                 &messageContext, &statusString);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   512
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   513
  return getJavaString(env, &statusString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
}
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   515
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
 * Utility routine checking the specified major and minor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
 * status codes. GSSExceptions will be thrown if they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
 * not GSS_S_COMPLETE (i.e. 0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
void checkStatus(JNIEnv *env, jobject jstub, OM_uint32 major,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                 OM_uint32 minor, char* methodName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
  int callingErr, routineErr, supplementaryInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
  jint jmajor, jminor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
  char* msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
  jstring jmsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
  jthrowable gssEx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
  if (major == GSS_S_COMPLETE) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
  callingErr = GSS_CALLING_ERROR(major);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
  routineErr = GSS_ROUTINE_ERROR(major);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
  supplementaryInfo = GSS_SUPPLEMENTARY_INFO(major);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   535
  TRACE3("%s Status major/minor = %x/%d", methodName, major, minor);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   536
  TRACE3("c/r/s = %d/%d/%d ", callingErr>>24, routineErr>>16,
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   537
          supplementaryInfo);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
  jmajor = getJavaErrorCode(routineErr | supplementaryInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
  jminor = minor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
  if (jmajor != GSS_S_COMPLETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    jmsg = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    if (minor != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
      jmsg = getMinorMessage(env, jstub, minor);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   545
      if ((*env)->ExceptionCheck(env)) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   546
        return;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   547
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   549
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    gssEx = (*env)->NewObject(env, CLS_GSSException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                              MID_GSSException_ctor3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                              jmajor, jminor, jmsg);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   553
    if (gssEx != NULL) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   554
      (*env)->Throw(env, gssEx);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   555
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    /* Error in calling the GSS api */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    if (callingErr == GSS_S_CALL_INACCESSIBLE_READ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
      msg = "A required input parameter cannot be read";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    } else if (callingErr == GSS_S_CALL_INACCESSIBLE_WRITE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
      msg = "A required output parameter cannot be write";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
      msg = "A parameter was malformed";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    jmajor = 13; /* use GSSException.FAILURE for now */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    jmsg = (*env)->NewStringUTF(env, msg);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   567
    if (jmsg == NULL) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   568
      return;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   569
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    gssEx = (*env)->NewObject(env, CLS_GSSException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                              MID_GSSException_ctor3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                              jmajor, jminor, jmsg);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   573
    if (gssEx != NULL) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   574
      (*env)->Throw(env, gssEx);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   575
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
}
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 16488
diff changeset
   578
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
 * Utility routine for initializing gss_buffer_t structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
 * with the byte[] in the specified jbyteArray object.
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   582
 * NOTE: must call resetGSSBuffer() to free up the resources
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   583
 * inside the gss_buffer_t structure.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
 */
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   585
void initGSSBuffer(JNIEnv *env, jbyteArray jbytes,
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   586
                     gss_buffer_t cbytes) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   587
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   588
  int len;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   589
  void* value;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   590
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
  if (jbytes != NULL) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   592
    len = (*env)->GetArrayLength(env, jbytes);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   593
    value = malloc(len);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   594
    if (value == NULL) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   595
      throwOutOfMemoryError(env, NULL);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   596
      return;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   597
    } else {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   598
      (*env)->GetByteArrayRegion(env, jbytes, 0, len, value);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   599
      if ((*env)->ExceptionCheck(env)) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   600
        free(value);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   601
        return;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   602
      } else {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   603
        cbytes->length = len;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   604
        cbytes->value = value;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   605
      }
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 16488
diff changeset
   606
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    cbytes->length = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    cbytes->value = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
  }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   611
}
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   612
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   613
/*
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   614
 * Utility routine for freeing the bytes malloc'ed
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   615
 * in initGSSBuffer() method.
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   616
 * NOTE: used in conjunction with initGSSBuffer(...).
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   617
 */
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   618
void resetGSSBuffer(gss_buffer_t cbytes) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   619
  if ((cbytes != NULL) && (cbytes != GSS_C_NO_BUFFER)) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   620
    free(cbytes->value);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   621
    cbytes->length = 0;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   622
    cbytes->value = NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   623
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
}
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 16488
diff changeset
   625
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
 * Utility routine for creating a jbyteArray object using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
 * the byte[] value in specified gss_buffer_t structure.
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   629
 * NOTE: the specified gss_buffer_t structure is always
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   630
 * released.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
jbyteArray getJavaBuffer(JNIEnv *env, gss_buffer_t cbytes) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   633
  jbyteArray result = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
  OM_uint32 minor; // don't care, just so it compiles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   636
  if (cbytes != NULL) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   637
    if ((cbytes != GSS_C_NO_BUFFER) && (cbytes->length != 0)) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   638
      result = (*env)->NewByteArray(env, cbytes->length);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   639
      if (result == NULL) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   640
        goto finish;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   641
      }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   642
      (*env)->SetByteArrayRegion(env, result, 0, cbytes->length,
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   643
                                 cbytes->value);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   644
      if ((*env)->ExceptionCheck(env)) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   645
        result = NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   646
      }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   647
    }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   648
  finish:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    (*ftab->releaseBuffer)(&minor, cbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
  return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
 * Utility routine for creating a non-mech gss_OID using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
 * the specified org.ietf.jgss.Oid object.
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   658
 * NOTE: must call deleteGSSOID(...) to free up the gss_OID.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
gss_OID newGSSOID(JNIEnv *env, jobject jOid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
  jbyteArray jbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
  gss_OID cOid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
  jthrowable gssEx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
  if (jOid != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    jbytes = (*env)->CallObjectMethod(env, jOid, MID_Oid_getDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    if ((*env)->ExceptionCheck(env)) {
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 16488
diff changeset
   667
      return GSS_C_NO_OID;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    cOid = malloc(sizeof(struct gss_OID_desc_struct));
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14414
diff changeset
   670
    if (cOid == NULL) {
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14414
diff changeset
   671
      throwOutOfMemoryError(env,NULL);
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14414
diff changeset
   672
      return GSS_C_NO_OID;
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14414
diff changeset
   673
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    cOid->length = (*env)->GetArrayLength(env, jbytes) - 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    cOid->elements = malloc(cOid->length);
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14414
diff changeset
   676
    if (cOid->elements == NULL) {
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14414
diff changeset
   677
      throwOutOfMemoryError(env,NULL);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   678
      goto cleanup;
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14414
diff changeset
   679
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    (*env)->GetByteArrayRegion(env, jbytes, 2, cOid->length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                               cOid->elements);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   682
    if ((*env)->ExceptionCheck(env)) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   683
      goto cleanup;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   684
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    return cOid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    return GSS_C_NO_OID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
  }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   689
  cleanup:
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   690
    (*env)->DeleteLocalRef(env, jbytes);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   691
    free(cOid->elements);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   692
    free(cOid);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   693
    return GSS_C_NO_OID;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
}
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   695
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
 * Utility routine for releasing the specified gss_OID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
 * structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
 * NOTE: used in conjunction with newGSSOID(...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
void deleteGSSOID(gss_OID oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
  if (oid != GSS_C_NO_OID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    free(oid->elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    free(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
}
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   707
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
 * Utility routine for creating a org.ietf.jgss.Oid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
 * object using the specified gss_OID structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
jobject getJavaOID(JNIEnv *env, gss_OID cOid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
  int cLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
  char oidHdr[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
  jbyteArray jbytes;
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   716
  jobject result = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
  if ((cOid == NULL) || (cOid == GSS_C_NO_OID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
  cLen = cOid->length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
  oidHdr[0] = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
  oidHdr[1] = cLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
  jbytes = (*env)->NewByteArray(env, cLen+2);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   725
  if (jbytes == NULL) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   726
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   727
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
  (*env)->SetByteArrayRegion(env, jbytes, 0, 2, (jbyte *) oidHdr);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   729
  if ((*env)->ExceptionCheck(env)) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   730
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   731
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
  (*env)->SetByteArrayRegion(env, jbytes, 2, cLen, (jbyte *) cOid->elements);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   733
  if ((*env)->ExceptionCheck(env)) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   734
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   735
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
  result = (*env)->NewObject(env, CLS_Oid, MID_Oid_ctor1, jbytes);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   737
  if ((*env)->ExceptionCheck(env)) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   738
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   739
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
  (*env)->DeleteLocalRef(env, jbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
  return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
 * Utility routine for creating a gss_OID_set structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
 * using the specified gss_OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
 * NOTE: need to call deleteGSSOIDSet(...) afterwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
 * to release the created gss_OID_set structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
 */
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   749
gss_OID_set newGSSOIDSet(gss_OID oid) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
  gss_OID_set oidSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
  OM_uint32 minor; // don't care; just so it compiles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
  if (oid->length != 6 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
      memcmp(oid->elements, SPNEGO_BYTES, 6) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
      (*ftab->createEmptyOidSet)(&minor, &oidSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
      (*ftab->addOidSetMember)(&minor, oid, &oidSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
      return oidSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
      // Use all mechs for SPNEGO in order to work with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
      // various native GSS impls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
      return (ftab->mechs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
 * Utility routine for releasing a gss_OID_set structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
 * NOTE: used in conjunction with newGSSOIDSet(...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
void deleteGSSOIDSet(gss_OID_set oidSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
  OM_uint32 minor; /* don't care; just so it compiles */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
  if ((oidSet != ftab->mechs) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
      (oidSet != NULL) && (oidSet != GSS_C_NO_OID_SET)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    (*ftab->releaseOidSet)(&minor, &oidSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
 * Utility routine for creating a org.ietf.jgss.Oid[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
 * using the specified gss_OID_set structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
jobjectArray getJavaOIDArray(JNIEnv *env, gss_OID_set cOidSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
  int numOfOids = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
  jobjectArray jOidSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
  jobject jOid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
  jthrowable gssEx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
  if (cOidSet != NULL && cOidSet != GSS_C_NO_OID_SET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    numOfOids = cOidSet->count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    jOidSet = (*env)->NewObjectArray(env, numOfOids, CLS_Oid, NULL);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   790
    if ((*env)->ExceptionCheck(env)) {
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 16488
diff changeset
   791
      return NULL;
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 16488
diff changeset
   792
    }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   793
    for (i = 0; i < numOfOids; i++) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   794
      jOid = getJavaOID(env, &(cOidSet->elements[i]));
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   795
      if ((*env)->ExceptionCheck(env)) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   796
        return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
      }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   798
      (*env)->SetObjectArrayElement(env, jOidSet, i, jOid);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   799
      if ((*env)->ExceptionCheck(env)) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   800
        return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   801
      }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   802
      (*env)->DeleteLocalRef(env, jOid);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    return jOidSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
  return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   809
int sameMech(gss_OID mech, gss_OID mech2) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
  int result = JNI_FALSE; // default to not equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
  if (mech->length == mech2->length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    result = (memcmp(mech->elements, mech2->elements, mech->length) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
  return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
}