src/java.security.jgss/share/native/libj2gss/GSSLibStub.c
author weijun
Fri, 13 Apr 2018 15:29:33 +0800
changeset 49682 2918e1146106
parent 48571 cd23d1f99660
child 50244 317a8688db78
permissions -rw-r--r--
8200468: Port the native GSS-API bridge to Windows Reviewed-by: ihse, valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
     2
 * Copyright (c) 2005, 2018, 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 "sun_security_jgss_wrapper_GSSLibStub.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "NativeUtil.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "NativeFunc.h"
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
    29
#include "jlong.h"
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
    30
#include <jni.h>
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
    31
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
    32
/* Constants for indicating what type of info is needed for inquiries */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
const int TYPE_CRED_NAME = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
const int TYPE_CRED_TIME = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
const int TYPE_CRED_USAGE = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Method:    init
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
    40
 * Signature: (Ljava/lang/String;Z)Z
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
Java_sun_security_jgss_wrapper_GSSLibStub_init(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
                                               jclass jcls,
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
    45
                                               jstring jlibName,
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
    46
                                               jboolean jDebug) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    const char *libName;
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    48
    int failed;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    char *error = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
    51
    if (!jDebug) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
    52
      JGSS_DEBUG = 0;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
    53
    } else {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
    54
      JGSS_DEBUG = 1;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
    55
    }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
    56
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    if (jlibName == NULL) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
    58
        TRACE0("[GSSLibStub_init] GSS lib name is NULL");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    libName = (*env)->GetStringUTFChars(env, jlibName, NULL);
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
    63
    if (libName == NULL) {
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
    64
        return JNI_FALSE;
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
    65
    }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
    66
    TRACE1("[GSSLibStub_init] libName=%s", libName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /* initialize global function table */
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    69
    failed = loadNative(libName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    (*env)->ReleaseStringUTFChars(env, jlibName, libName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    72
    if (!failed) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    } else {
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    75
        if (JGSS_DEBUG) {
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    76
#ifdef WIN32
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    77
            #define MAX_MSG_SIZE 256
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    78
            static CHAR szMsgBuf[MAX_MSG_SIZE];
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    79
            DWORD dwRes;
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    80
            DWORD dwError = GetLastError();
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    81
            dwRes = FormatMessage (
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    82
                    FORMAT_MESSAGE_FROM_SYSTEM,
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    83
                    NULL,
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    84
                    dwError,
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    85
                    0,
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    86
                    szMsgBuf,
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    87
                    MAX_MSG_SIZE,
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    88
                    NULL);
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    89
            if (0 == dwRes) {
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    90
                printf("GSS-API: Unknown failure %d\n", dwError);
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    91
            } else {
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    92
                printf("GSS-API: %s\n",szMsgBuf);
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    93
            }
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    94
#else
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    95
            char* error = dlerror();
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    96
            if (error) {
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    97
                TRACE0(error);
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    98
            }
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
    99
#endif
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
   100
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * Method:    getMechPtr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * Signature: ([B)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
Java_sun_security_jgss_wrapper_GSSLibStub_getMechPtr(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                                     jclass jcls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                                     jbyteArray jbytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
  gss_OID cOid;
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   115
  unsigned int i, len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
  jbyte* bytes;
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   117
  int found;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
  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
   120
    found = 0;
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   121
    len = (unsigned int)((*env)->GetArrayLength(env, jbytes) - 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    bytes = (*env)->GetByteArrayElements(env, jbytes, NULL);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   123
    if (bytes == NULL) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   124
      return ptr_to_jlong(NULL);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   125
    }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   126
    for (i = 0; i < ftab->mechs->count; i++) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   127
      cOid = &(ftab->mechs->elements[i]);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   128
      if (len == cOid->length &&
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   129
          (memcmp(cOid->elements, (bytes + 2), len) == 0)) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   130
        // Found a match
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   131
        found = 1;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   132
        break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   135
    (*env)->ReleaseByteArrayElements(env, jbytes, bytes, 0);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   136
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   137
    if (found != 1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
      checkStatus(env, NULL, GSS_S_BAD_MECH, 0, "[GSSLibStub_getMechPtr]");
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   139
      return ptr_to_jlong(NULL);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   140
    } else {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   141
      return ptr_to_jlong(cOid);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   142
    }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   143
  } else {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   144
    return ptr_to_jlong(GSS_C_NO_OID);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   145
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   148
/*
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   149
 * Utility routine which releases the specified gss_channel_bindings_t
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   150
 * structure.
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   151
 */
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   152
void deleteGSSCB(gss_channel_bindings_t cb) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   153
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   154
  if (cb == GSS_C_NO_CHANNEL_BINDINGS) return;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   155
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   156
  /* release initiator address */
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   157
  if (cb->initiator_addrtype != GSS_C_AF_NULLADDR) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   158
    resetGSSBuffer(&(cb->initiator_address));
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   159
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   160
  /* release acceptor address */
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   161
  if (cb->acceptor_addrtype != GSS_C_AF_NULLADDR) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   162
    resetGSSBuffer(&(cb->acceptor_address));
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   163
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   164
  /* release application data */
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   165
  if (cb->application_data.length != 0) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   166
    resetGSSBuffer(&(cb->application_data));
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   167
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   168
  free(cb);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   169
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * Utility routine which creates a gss_channel_bindings_t structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * using the specified org.ietf.jgss.ChannelBinding object.
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   174
 * NOTE: must call deleteGSSCB() to free up the resources.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 */
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   176
gss_channel_bindings_t newGSSCB(JNIEnv *env, jobject jcb) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
  gss_channel_bindings_t cb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
  jobject jinetAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
  jbyteArray value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
  if (jcb == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    return GSS_C_NO_CHANNEL_BINDINGS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
  }
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   184
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
  cb = malloc(sizeof(struct gss_channel_bindings_struct));
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   186
  if (cb == NULL) {
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   187
    throwOutOfMemoryError(env,NULL);
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   188
    return NULL;
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   189
  }
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   190
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   191
  // initialize addrtype in CB first
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   192
  cb->initiator_addrtype = GSS_C_AF_NULLADDR;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   193
  cb->acceptor_addrtype = GSS_C_AF_NULLADDR;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   194
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
  /* set up initiator address */
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   196
  jinetAddr = (*env)->CallObjectMethod(env, jcb,
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   197
      MID_ChannelBinding_getInitiatorAddr);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   198
  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
   199
    goto cleanup;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   200
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
  if (jinetAddr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    value = (*env)->CallObjectMethod(env, jinetAddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                     MID_InetAddress_getAddr);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   204
    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
   205
      goto cleanup;
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
   206
    }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   207
    cb->initiator_addrtype = GSS_C_AF_INET;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   208
    initGSSBuffer(env, value, &(cb->initiator_address));
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   209
    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
   210
      goto cleanup;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   211
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
  /* set up acceptor address */
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   214
  jinetAddr = (*env)->CallObjectMethod(env, jcb,
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   215
      MID_ChannelBinding_getAcceptorAddr);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   216
  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
   217
    goto cleanup;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   218
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
  if (jinetAddr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    value = (*env)->CallObjectMethod(env, jinetAddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                                     MID_InetAddress_getAddr);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   222
    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
   223
      goto cleanup;
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
   224
    }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   225
    cb->acceptor_addrtype = GSS_C_AF_INET;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   226
    initGSSBuffer(env, value, &(cb->acceptor_address));
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   227
    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
   228
      goto cleanup;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   229
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
  /* set up application data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
  value = (*env)->CallObjectMethod(env, jcb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                   MID_ChannelBinding_getAppData);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   234
  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
   235
    goto cleanup;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   236
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   237
  initGSSBuffer(env, value, &(cb->application_data));
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   238
  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
   239
    goto cleanup;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
  return cb;
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   242
cleanup:
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   243
  deleteGSSCB(cb);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   244
  return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 * Utility routine for storing the supplementary information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * into the specified org.ietf.jgss.MessageProp object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
void setSupplementaryInfo(JNIEnv *env, jobject jstub, jobject jprop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                          int suppInfo, int minor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  jboolean isDuplicate, isOld, isUnseq, hasGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
  jstring minorMsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
  if (suppInfo != GSS_S_COMPLETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    isDuplicate = ((suppInfo & GSS_S_DUPLICATE_TOKEN) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    isOld = ((suppInfo & GSS_S_OLD_TOKEN) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    isUnseq = ((suppInfo & GSS_S_UNSEQ_TOKEN) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    hasGap = ((suppInfo & GSS_S_GAP_TOKEN) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    minorMsg = 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
   262
    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
   263
      return;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   264
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    (*env)->CallVoidMethod(env, jprop, MID_MessageProp_setSupplementaryStates,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                           isDuplicate, isOld, isUnseq, hasGap, minor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                           minorMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 * Method:    indicateMechs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 * Signature: ()[Lorg/ietf/jgss/Oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
JNIEXPORT jobjectArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
Java_sun_security_jgss_wrapper_GSSLibStub_indicateMechs(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                                        jclass jcls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
  if (ftab->mechs != NULL && ftab->mechs != GSS_C_NO_OID_SET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    return getJavaOIDArray(env, ftab->mechs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
  } else return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 * Method:    inquireNamesForMech
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 * Signature: ()[Lorg/ietf/jgss/Oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
JNIEXPORT jobjectArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
Java_sun_security_jgss_wrapper_GSSLibStub_inquireNamesForMech(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                                                              jobject jobj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
  gss_OID mech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
  gss_OID_set nameTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
  jobjectArray result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
  if (ftab->inquireNamesForMech != NULL) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   300
    mech = (gss_OID)jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech));
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   301
    nameTypes = GSS_C_NO_OID_SET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   303
    /* gss_inquire_names_for_mech(...) => N/A */
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   304
    major = (*ftab->inquireNamesForMech)(&minor, mech, &nameTypes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   306
    /* release intermediate buffers before checking status */
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   307
    result = getJavaOIDArray(env, nameTypes);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   308
    deleteGSSOIDSet(nameTypes);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   309
    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
   310
      return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   311
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   313
    checkStatus(env, jobj, major, minor, "[GSSLibStub_inquireNamesForMech]");
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   314
    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
   315
      return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   316
    }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   317
    return result;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   318
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   319
  return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
 * Method:    releaseName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
 * Signature: (J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
Java_sun_security_jgss_wrapper_GSSLibStub_releaseName(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                                                      jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                                                      jlong pName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
  gss_name_t nameHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   335
  nameHdl = (gss_name_t) jlong_to_ptr(pName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   337
  TRACE1("[GSSLibStub_releaseName] %ld", (long) pName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
  if (nameHdl != GSS_C_NO_NAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /* gss_release_name(...) => GSS_S_BAD_NAME */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    major = (*ftab->releaseName)(&minor, &nameHdl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    checkStatus(env, jobj, major, minor, "[GSSLibStub_releaseName]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
 * Method:    importName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
 * Signature: ([BLorg/ietf/jgss/Oid;)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
Java_sun_security_jgss_wrapper_GSSLibStub_importName(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                                                     jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                                     jbyteArray jnameVal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                                                     jobject jnameType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
  gss_buffer_desc nameVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
  gss_OID nameType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
  gss_name_t nameHdl;
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   361
  nameHdl = GSS_C_NO_NAME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   363
  TRACE0("[GSSLibStub_importName]");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   365
  initGSSBuffer(env, jnameVal, &nameVal);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   366
  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
   367
      return jlong_zero;
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
   368
  }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   369
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
  nameType = newGSSOID(env, jnameType);
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   371
  if ((*env)->ExceptionCheck(env)) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   372
    resetGSSBuffer(&nameVal);
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   373
    return jlong_zero;
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   374
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
  /* gss_import_name(...) => GSS_S_BAD_NAMETYPE, GSS_S_BAD_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     GSS_S_BAD_MECH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
  major = (*ftab->importName)(&minor, &nameVal, nameType, &nameHdl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
   380
  TRACE1("[GSSLibStub_importName] %" PRIuPTR  "", (uintptr_t) nameHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
  /* release intermediate buffers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
  deleteGSSOID(nameType);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   384
  resetGSSBuffer(&nameVal);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
  checkStatus(env, jobj, major, minor, "[GSSLibStub_importName]");
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   387
  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
   388
    return jlong_zero;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   389
  }
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   390
  return ptr_to_jlong(nameHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
 * Method:    compareName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
 * Signature: (JJ)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
Java_sun_security_jgss_wrapper_GSSLibStub_compareName(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                                                      jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                                                      jlong pName1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                                                      jlong pName2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
  gss_name_t nameHdl1, nameHdl2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
  int isEqual;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
  isEqual = 0;
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   410
  nameHdl1 = (gss_name_t) jlong_to_ptr(pName1);
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   411
  nameHdl2 = (gss_name_t) jlong_to_ptr(pName2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   413
  TRACE2("[GSSLibStub_compareName] %ld %ld", (long)pName1, (long)pName2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
  if ((nameHdl1 != GSS_C_NO_NAME) && (nameHdl2 != GSS_C_NO_NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /* gss_compare_name(...) => GSS_S_BAD_NAMETYPE, GSS_S_BAD_NAME(!) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    major = (*ftab->compareName)(&minor, nameHdl1, nameHdl2, &isEqual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    checkStatus(env, jobj, major, minor, "[GSSLibStub_compareName]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
  return (isEqual != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
 * Method:    canonicalizeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
 * Signature: (J)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
Java_sun_security_jgss_wrapper_GSSLibStub_canonicalizeName(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                                           jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                                                           jlong pName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
  gss_name_t nameHdl, mnNameHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
  gss_OID mech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   439
  nameHdl = (gss_name_t) jlong_to_ptr(pName);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   440
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   441
  TRACE1("[GSSLibStub_canonicalizeName] %ld", (long) pName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
  if (nameHdl != GSS_C_NO_NAME) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   444
    mech = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    mnNameHdl = GSS_C_NO_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /* gss_canonicalize_name(...) may return GSS_S_BAD_NAMETYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
       GSS_S_BAD_NAME, GSS_S_BAD_MECH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    major = (*ftab->canonicalizeName)(&minor, nameHdl, mech, &mnNameHdl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
   451
    TRACE1("[GSSLibStub_canonicalizeName] MN=%" PRIuPTR "", (uintptr_t)mnNameHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    checkStatus(env, jobj, major, minor, "[GSSLibStub_canonicalizeName]");
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   454
    if ((*env)->ExceptionCheck(env)) {
29491
821faf99fb06 8074836: Resolve disabled warnings for libosxkrb5
weijun
parents: 25859
diff changeset
   455
      return ptr_to_jlong(GSS_C_NO_NAME);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   456
    }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   457
    return ptr_to_jlong(mnNameHdl);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   458
  }
29491
821faf99fb06 8074836: Resolve disabled warnings for libosxkrb5
weijun
parents: 25859
diff changeset
   459
  return ptr_to_jlong(GSS_C_NO_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
 * Method:    exportName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
 * Signature: (J)[B
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
JNIEXPORT jbyteArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
Java_sun_security_jgss_wrapper_GSSLibStub_exportName(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                                     jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                                                     jlong pName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
  gss_name_t nameHdl, mNameHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
  gss_buffer_desc outBuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
  jbyteArray jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   476
  nameHdl = (gss_name_t) jlong_to_ptr(pName);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   477
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   478
  TRACE1("[GSSLibStub_exportName] %ld", (long) pName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
  /* gss_export_name(...) => GSS_S_NAME_NOT_MN, GSS_S_BAD_NAMETYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     GSS_S_BAD_NAME */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
  major = (*ftab->exportName)(&minor, nameHdl, &outBuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
  /* canonicalize the internal name to MN and retry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
  if (major == GSS_S_NAME_NOT_MN) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   486
    /* release intermediate buffers before retrying */
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   487
    (*ftab->releaseBuffer)(&minor, &outBuf);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   488
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   489
    TRACE0("[GSSLibStub_exportName] canonicalize and re-try");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   491
    mNameHdl = (gss_name_t)jlong_to_ptr(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        Java_sun_security_jgss_wrapper_GSSLibStub_canonicalizeName
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   493
                                        (env, jobj, pName));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    if ((*env)->ExceptionCheck(env)) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   495
        return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   497
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    major = (*ftab->exportName)(&minor, mNameHdl, &outBuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    Java_sun_security_jgss_wrapper_GSSLibStub_releaseName
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   500
                                        (env, jobj, ptr_to_jlong(mNameHdl));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    if ((*env)->ExceptionCheck(env)) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   502
      /* release intermediate buffers */
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   503
      (*ftab->releaseBuffer)(&minor, &outBuf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
      return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   508
  /* release intermediate buffers before checking status */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
  jresult = getJavaBuffer(env, &outBuf);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   510
  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
   511
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   512
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
  checkStatus(env, jobj, major, minor, "[GSSLibStub_exportName]");
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   515
  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
   516
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   517
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
  return jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
 * Method:    displayName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
 * Signature: (J)[Ljava/lang/Object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
JNIEXPORT jobjectArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
Java_sun_security_jgss_wrapper_GSSLibStub_displayName(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                                                      jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                                      jlong pName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
  gss_name_t nameHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
  gss_buffer_desc outNameBuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
  gss_OID outNameType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
  jstring jname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
  jobject jtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
  jobjectArray jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   538
  nameHdl = (gss_name_t) jlong_to_ptr(pName);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   539
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   540
  TRACE1("[GSSLibStub_displayName] %ld", (long) pName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
  if (nameHdl == GSS_C_NO_NAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    checkStatus(env, jobj, GSS_S_BAD_NAME, 0, "[GSSLibStub_displayName]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
  /* gss_display_name(...) => GSS_S_BAD_NAME */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
  major = (*ftab->displayName)(&minor, nameHdl, &outNameBuf, &outNameType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   550
  /* release intermediate buffers before checking status */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
  jname = getJavaString(env, &outNameBuf);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   552
  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
   553
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   554
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   555
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   556
  checkStatus(env, jobj, major, minor, "[GSSLibStub_displayName]");
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   557
  if ((*env)->ExceptionCheck(env)) {
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
   558
    return NULL;
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
   559
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
  jtype = getJavaOID(env, outNameType);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   562
  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
   563
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   564
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   565
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
  jresult = (*env)->NewObjectArray(env, 2, CLS_Object, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
  /* return immediately if an exception has occurred */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
  if ((*env)->ExceptionCheck(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
  (*env)->SetObjectArrayElement(env, jresult, 0, jname);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   573
  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
   574
    return NULL;
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
  (*env)->SetObjectArrayElement(env, jresult, 1, jtype);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   577
  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
   578
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   579
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
  return jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
 * Method:    acquireCred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
 * Signature: (JII)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
Java_sun_security_jgss_wrapper_GSSLibStub_acquireCred(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                                                      jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                                                      jlong pName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                                                      jint reqTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                                      jint usage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
  gss_OID mech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
  gss_OID_set mechs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
  gss_cred_usage_t credUsage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
  gss_name_t nameHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
  gss_cred_id_t credHdl;
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   602
  credHdl = GSS_C_NO_CREDENTIAL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   604
  TRACE0("[GSSLibStub_acquireCred]");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   606
  mech = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech));
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   607
  mechs = newGSSOIDSet(mech);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
  credUsage = (gss_cred_usage_t) usage;
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   609
  nameHdl = (gss_name_t) jlong_to_ptr(pName);
2
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
  TRACE2("[GSSLibStub_acquireCred] pName=%ld, usage=%d", (long)pName, usage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
  /* gss_acquire_cred(...) => GSS_S_BAD_MECH, GSS_S_BAD_NAMETYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     GSS_S_BAD_NAME, GSS_S_CREDENTIALS_EXPIRED, GSS_S_NO_CRED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
  major =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    (*ftab->acquireCred)(&minor, nameHdl, reqTime, mechs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                     credUsage, &credHdl, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
  /* release intermediate buffers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
  deleteGSSOIDSet(mechs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
   621
  TRACE1("[GSSLibStub_acquireCred] pCred=%" PRIuPTR "", (uintptr_t) credHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
  checkStatus(env, jobj, major, minor, "[GSSLibStub_acquireCred]");
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   624
  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
   625
    return jlong_zero;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   626
  }
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   627
  return ptr_to_jlong(credHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
 * Method:    releaseCred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
 * Signature: (J)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
Java_sun_security_jgss_wrapper_GSSLibStub_releaseCred(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                                                      jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                                                      jlong pCred)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
  gss_cred_id_t credHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   643
  credHdl = (gss_cred_id_t) jlong_to_ptr(pCred);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   645
  TRACE1("[GSSLibStub_releaseCred] %ld", (long int)pCred);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
  if (credHdl != GSS_C_NO_CREDENTIAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    /* gss_release_cred(...) => GSS_S_NO_CRED(!) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    major = (*ftab->releaseCred)(&minor, &credHdl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    checkStatus(env, jobj, major, minor, "[GSSLibStub_releaseCred]");
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   652
    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
   653
      return jlong_zero;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   654
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
  }
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   656
  return ptr_to_jlong(credHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
 * Utility routine for obtaining info about a credential.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
void inquireCred(JNIEnv *env, jobject jobj, gss_cred_id_t pCred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                 jint type, void *result) {
25216
291541db1e11 8048511: Uninitialised memory in jdk/src/share/native/sun/security/jgss/wrapper/GSSLibStub.c
weijun
parents: 23585
diff changeset
   664
  OM_uint32 minor=0, major=0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
  OM_uint32 routineErr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
  gss_cred_id_t credHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
  credHdl = pCred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
   670
  TRACE1("[gss_inquire_cred] %" PRIuPTR "", (uintptr_t) pCred);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
  /* gss_inquire_cred(...) => GSS_S_DEFECTIVE_CREDENTIAL(!),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     GSS_S_CREDENTIALS_EXPIRED(!), GSS_S_NO_CRED(!) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
  if (type == TYPE_CRED_NAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    major = (*ftab->inquireCred)(&minor, credHdl, result, NULL, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
  } else if (type == TYPE_CRED_TIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    major = (*ftab->inquireCred)(&minor, credHdl, NULL, result, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
  } else if (type == TYPE_CRED_USAGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    major = (*ftab->inquireCred)(&minor, credHdl, NULL, NULL, result, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
  routineErr = GSS_ROUTINE_ERROR(major);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
  if (routineErr == GSS_S_CREDENTIALS_EXPIRED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    /* ignore GSS_S_CREDENTIALS_EXPIRED for query  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    major = GSS_CALLING_ERROR(major) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
      GSS_SUPPLEMENTARY_INFO(major);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
  } else if (routineErr == GSS_S_NO_CRED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    /* twik since Java API throws BAD_MECH instead of NO_CRED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    major = GSS_CALLING_ERROR(major) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
      GSS_S_BAD_MECH  | GSS_SUPPLEMENTARY_INFO(major);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
  checkStatus(env, jobj, major, minor, "[gss_inquire_cred]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
 * Method:    getCredName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
 * Signature: (J)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
Java_sun_security_jgss_wrapper_GSSLibStub_getCredName(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                                                      jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                                                      jlong pCred)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
  gss_name_t nameHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
  gss_cred_id_t credHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   708
  credHdl = (gss_cred_id_t) jlong_to_ptr(pCred);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   710
  TRACE1("[GSSLibStub_getCredName] %ld", (long int)pCred);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
  nameHdl = GSS_C_NO_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
  inquireCred(env, jobj, credHdl, TYPE_CRED_NAME, &nameHdl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
  /* return immediately if an exception has occurred */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
  if ((*env)->ExceptionCheck(env)) {
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   716
    return jlong_zero;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
   719
  TRACE1("[GSSLibStub_getCredName] pName=%" PRIuPTR "", (uintptr_t) nameHdl);
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   720
  return ptr_to_jlong(nameHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
 * Method:    getCredTime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
 * Signature: (J)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
Java_sun_security_jgss_wrapper_GSSLibStub_getCredTime(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                                                      jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                                                      jlong pCred)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
  gss_cred_id_t credHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
  OM_uint32 lifetime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   736
  credHdl = (gss_cred_id_t) jlong_to_ptr(pCred);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   738
  TRACE1("[GSSLibStub_getCredTime] %ld", (long int)pCred);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
  lifetime = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
  inquireCred(env, jobj, credHdl, TYPE_CRED_TIME, &lifetime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
  /* return immediately if an exception has occurred */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
  if ((*env)->ExceptionCheck(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
  return getJavaTime(lifetime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
 * Method:    getCredUsage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
 * Signature: (J)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
Java_sun_security_jgss_wrapper_GSSLibStub_getCredUsage(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                                                       jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                                                       jlong pCred)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
  gss_cred_usage_t usage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
  gss_cred_id_t credHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   762
  credHdl = (gss_cred_id_t) jlong_to_ptr(pCred);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   764
  TRACE1("[GSSLibStub_getCredUsage] %ld", (long int)pCred);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
  inquireCred(env, jobj, credHdl, TYPE_CRED_USAGE, &usage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
  /* return immediately if an exception has occurred */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
  if ((*env)->ExceptionCheck(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
  return (jint) usage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
 * Method:    importContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
 * Signature: ([B)Lsun/security/jgss/wrapper/NativeGSSContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
Java_sun_security_jgss_wrapper_GSSLibStub_importContext(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                                                        jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                                                        jbyteArray jctxtToken)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
  gss_buffer_desc ctxtToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
  gss_ctx_id_t contextHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
  gss_OID mech, mech2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   788
  TRACE0("[GSSLibStub_importContext]");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
  contextHdl = GSS_C_NO_CONTEXT;
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   791
  initGSSBuffer(env, jctxtToken, &ctxtToken);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   792
  if ((*env)->ExceptionCheck(env)) {
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
   793
    return NULL;
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
   794
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
  /* gss_import_sec_context(...) => GSS_S_NO_CONTEXT, GSS_S_DEFECTIVE_TOKEN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     GSS_S_UNAVAILABLE, GSS_S_UNAUTHORIZED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
  major = (*ftab->importSecContext)(&minor, &ctxtToken, &contextHdl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
   800
  TRACE1("[GSSLibStub_importContext] pContext=%" PRIuPTR "", (uintptr_t) contextHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
  /* release intermediate buffers */
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   803
  resetGSSBuffer(&ctxtToken);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
  checkStatus(env, jobj, major, minor, "[GSSLibStub_importContext]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
  /* return immediately if an exception has occurred */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
  if ((*env)->ExceptionCheck(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
  /* now that the context has been imported, proceed to find out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     its mech */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
  major = (*ftab->inquireContext)(&minor, contextHdl, NULL, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                              NULL, &mech, NULL, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
  checkStatus(env, jobj, major, minor, "[GSSLibStub_importContext] getMech");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
  /* return immediately if an exception has occurred */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
  if ((*env)->ExceptionCheck(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   822
  mech2 = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jobj,
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   823
      FID_GSSLibStub_pMech));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   825
  if (sameMech(mech, mech2) == JNI_TRUE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    /* mech match - return the context object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    return (*env)->NewObject(env, CLS_NativeGSSContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                                 MID_NativeGSSContext_ctor,
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   829
                                 ptr_to_jlong(contextHdl), jobj);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    /* mech mismatch - clean up then return null */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    major = (*ftab->deleteSecContext)(&minor, &contextHdl, GSS_C_NO_BUFFER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    checkStatus(env, jobj, major, minor,
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   834
        "[GSSLibStub_importContext] cleanup");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
}
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   838
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
 * Method:    initContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
 * Signature: (JJLorg/ietf/jgss/ChannelBinding;[BLsun/security/jgss/wrapper/NativeGSSContext;)[B
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
JNIEXPORT jbyteArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
Java_sun_security_jgss_wrapper_GSSLibStub_initContext(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                                                      jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                                                      jlong pCred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                                                      jlong pName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                                                      jobject jcb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                                                      jbyteArray jinToken,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                                                      jobject jcontextSpi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
  gss_cred_id_t credHdl ;
48571
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
   855
  gss_ctx_id_t contextHdl, contextHdlSave;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
  gss_name_t targetName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
  gss_OID mech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
  OM_uint32 flags, aFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
  OM_uint32 time, aTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
  gss_channel_bindings_t cb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
  gss_buffer_desc inToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
  gss_buffer_desc outToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
  jbyteArray jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
/* UNCOMMENT after SEAM bug#6287358 is backported to S10
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
  gss_OID aMech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
  jobject jMech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
*/
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   868
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   869
  TRACE0("[GSSLibStub_initContext]");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   871
  credHdl = (gss_cred_id_t) jlong_to_ptr(pCred);
48571
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
   872
  contextHdl = contextHdlSave = (gss_ctx_id_t) jlong_to_ptr(
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   873
    (*env)->GetLongField(env, jcontextSpi, FID_NativeGSSContext_pContext));
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   874
  targetName = (gss_name_t) jlong_to_ptr(pName);
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   875
  mech = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
  flags = (OM_uint32) (*env)->GetIntField(env, jcontextSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                                          FID_NativeGSSContext_flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
  time = getGSSTime((*env)->GetIntField(env, jcontextSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                                        FID_NativeGSSContext_lifetime));
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   880
  cb = newGSSCB(env, jcb);
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   881
  if ((*env)->ExceptionCheck(env)) {
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   882
    return NULL;
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   883
  }
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   884
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   885
  initGSSBuffer(env, jinToken, &inToken);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   886
  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
   887
    deleteGSSCB(cb);
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
   888
    return NULL;
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
   889
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
   891
  TRACE2( "[GSSLibStub_initContext] before: pCred=%" PRIuPTR ", pContext=%" PRIuPTR "",
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
   892
          (uintptr_t)credHdl, (uintptr_t)contextHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
  /* gss_init_sec_context(...) => GSS_S_CONTINUE_NEEDED(!),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     GSS_S_DEFECTIVE_TOKEN, GSS_S_NO_CRED, GSS_S_DEFECTIVE_CREDENTIAL(!),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     GSS_S_CREDENTIALS_EXPIRED, GSS_S_BAD_BINDINGS, GSS_S_BAD_MIC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     GSS_S_OLD_TOKEN, GSS_S_DUPLICATE_TOKEN, GSS_S_NO_CONTEXT(!),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     GSS_S_BAD_NAMETYPE, GSS_S_BAD_NAME(!), GSS_S_BAD_MECH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
  major = (*ftab->initSecContext)(&minor, credHdl,
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   900
                                 &contextHdl, targetName, mech,
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   901
                                 flags, time, cb, &inToken, NULL /*aMech*/,
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   902
                                 &outToken, &aFlags, &aTime);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
   904
  TRACE2("[GSSLibStub_initContext] after: pContext=%" PRIuPTR ", outToken len=%ld",
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
   905
            (uintptr_t)contextHdl, (long)outToken.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
48571
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
   907
  // update context handle with the latest value if changed
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
   908
  // this is to work with both MIT and Solaris. Former deletes half-built
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
   909
  // context if error occurs
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
   910
  if (contextHdl != contextHdlSave) {
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
   911
    (*env)->SetLongField(env, jcontextSpi, FID_NativeGSSContext_pContext,
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
   912
                         ptr_to_jlong(contextHdl));
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
   913
    TRACE1("[GSSLibStub_initContext] set pContext=%" PRIuPTR "", (uintptr_t)contextHdl);
48571
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
   914
  }
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
   915
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
  if (GSS_ERROR(major) == GSS_S_COMPLETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    /* update member values if needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    (*env)->SetIntField(env, jcontextSpi, FID_NativeGSSContext_flags, aFlags);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   919
    TRACE1("[GSSLibStub_initContext] set flags=0x%x", aFlags);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    if (major == GSS_S_COMPLETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
      (*env)->SetIntField(env, jcontextSpi, FID_NativeGSSContext_lifetime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                          getJavaTime(aTime));
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   924
      TRACE0("[GSSLibStub_initContext] context established");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
      (*env)->SetBooleanField(env, jcontextSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                              FID_NativeGSSContext_isEstablished,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                              JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
/* UNCOMMENT after SEAM bug#6287358 is backported to S10
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
      jMech = getJavaOID(env, aMech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
      (*env)->SetObjectField(env, jcontextSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                             FID_NativeGSSContext_actualMech, jMech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    } else if (major & GSS_S_CONTINUE_NEEDED) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   936
      TRACE0("[GSSLibStub_initContext] context not established");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
      major -= GSS_S_CONTINUE_NEEDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
  }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   940
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   941
  /* release intermediate buffers before checking status */
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   942
  deleteGSSCB(cb);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   943
  resetGSSBuffer(&inToken);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
  jresult = getJavaBuffer(env, &outToken);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   945
  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
   946
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   947
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
  checkStatus(env, jobj, major, minor, "[GSSLibStub_initContext]");
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   950
  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
   951
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   952
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
  return jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
 * Method:    acceptContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
 * Signature: (JLorg/ietf/jgss/ChannelBinding;[BLsun/security/jgss/wrapper/NativeGSSContext;)[B
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
JNIEXPORT jbyteArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
Java_sun_security_jgss_wrapper_GSSLibStub_acceptContext(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                                                        jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                                                        jlong pCred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                                                        jobject jcb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                                                        jbyteArray jinToken,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                                                        jobject jcontextSpi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
  OM_uint32 minor2, major2;
48571
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
   971
  gss_ctx_id_t contextHdl, contextHdlSave;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
  gss_cred_id_t credHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
  gss_buffer_desc inToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
  gss_channel_bindings_t cb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
  gss_name_t srcName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
  gss_buffer_desc outToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
  gss_OID aMech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
  OM_uint32 aFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
  OM_uint32 aTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
  gss_cred_id_t delCred;
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   981
  jobject jsrcName=GSS_C_NO_NAME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
  jobject jdelCred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
  jobject jMech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
  jboolean setTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
  gss_name_t targetName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
  jobject jtargetName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   988
  TRACE0("[GSSLibStub_acceptContext]");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
48571
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
   990
  contextHdl = contextHdlSave = (gss_ctx_id_t)jlong_to_ptr(
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   991
    (*env)->GetLongField(env, jcontextSpi, FID_NativeGSSContext_pContext));
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
   992
  credHdl = (gss_cred_id_t) jlong_to_ptr(pCred);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   993
  initGSSBuffer(env, jinToken, &inToken);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   994
  if ((*env)->ExceptionCheck(env)) {
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
   995
    return NULL;
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
   996
  }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   997
  cb = newGSSCB(env, jcb);
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
   998
  if ((*env)->ExceptionCheck(env)) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
   999
    resetGSSBuffer(&inToken);
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
  1000
    return NULL;
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
  1001
  }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1002
  srcName = targetName = GSS_C_NO_NAME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
  delCred = GSS_C_NO_CREDENTIAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
  setTarget = (credHdl == GSS_C_NO_CREDENTIAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
  aFlags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1007
  TRACE2( "[GSSLibStub_acceptContext] before: pCred=%" PRIuPTR ", pContext=%" PRIuPTR "",
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1008
          (uintptr_t) credHdl, (uintptr_t) contextHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
  /* gss_accept_sec_context(...) => GSS_S_CONTINUE_NEEDED(!),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     GSS_S_DEFECTIVE_TOKEN, GSS_S_DEFECTIVE_CREDENTIAL(!),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     GSS_S_NO_CRED, GSS_S_CREDENTIALS_EXPIRED, GSS_S_BAD_BINDINGS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     GSS_S_NO_CONTEXT(!), GSS_S_BAD_MIC, GSS_S_OLD_TOKEN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     GSS_S_DUPLICATE_TOKEN, GSS_S_BAD_MECH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
  major =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    (*ftab->acceptSecContext)(&minor, &contextHdl, credHdl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                           &inToken, cb, &srcName, &aMech, &outToken,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                           &aFlags, &aTime, &delCred);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1019
  /* release intermediate buffers before checking status */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1021
  deleteGSSCB(cb);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1022
  resetGSSBuffer(&inToken);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1023
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1024
  TRACE3("[GSSLibStub_acceptContext] after: pCred=%" PRIuPTR ", pContext=%" PRIuPTR ", pDelegCred=%" PRIuPTR "",
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1025
        (uintptr_t)credHdl, (uintptr_t)contextHdl, (uintptr_t) delCred);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
48571
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
  1027
  // update context handle with the latest value if changed
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
  1028
  // this is to work with both MIT and Solaris. Former deletes half-built
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
  1029
  // context if error occurs
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
  1030
  if (contextHdl != contextHdlSave) {
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
  1031
    (*env)->SetLongField(env, jcontextSpi, FID_NativeGSSContext_pContext,
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
  1032
                         ptr_to_jlong(contextHdl));
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1033
    TRACE1("[GSSLibStub_acceptContext] set pContext=%" PRIuPTR "", (uintptr_t)contextHdl);
48571
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
  1034
  }
cd23d1f99660 8186212: Improve GSS handling
valeriep
parents: 48049
diff changeset
  1035
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
  if (GSS_ERROR(major) == GSS_S_COMPLETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    /* update member values if needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    // WORKAROUND for a Heimdal bug
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    if (delCred == GSS_C_NO_CREDENTIAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        aFlags &= 0xfffffffe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    (*env)->SetIntField(env, jcontextSpi, FID_NativeGSSContext_flags, aFlags);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1043
    TRACE1("[GSSLibStub_acceptContext] set flags=0x%x", aFlags);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1044
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    if (setTarget) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
      major2 = (*ftab->inquireContext)(&minor2, contextHdl, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                              &targetName, NULL, NULL, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                              NULL, NULL);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1049
      checkStatus(env, jobj, major2, minor2,
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1050
                    "[GSSLibStub_acceptContext] inquire");
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1051
      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
  1052
         goto error;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1053
      }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1054
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
      jtargetName = (*env)->NewObject(env, CLS_GSSNameElement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                                MID_GSSNameElement_ctor,
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1057
                                ptr_to_jlong(targetName), jobj);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1058
      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
  1059
        goto error;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1060
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1062
      TRACE1("[GSSLibStub_acceptContext] set targetName=%" PRIuPTR "",
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1063
              (uintptr_t)targetName);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1064
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
      (*env)->SetObjectField(env, jcontextSpi, FID_NativeGSSContext_targetName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                             jtargetName);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1067
      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
  1068
        goto error;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1069
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    if (srcName != GSS_C_NO_NAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
      jsrcName = (*env)->NewObject(env, CLS_GSSNameElement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                                   MID_GSSNameElement_ctor,
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1074
                                   ptr_to_jlong(srcName), jobj);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
      if ((*env)->ExceptionCheck(env)) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1076
        goto error;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
      }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1078
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1079
      TRACE1("[GSSLibStub_acceptContext] set srcName=%" PRIuPTR "", (uintptr_t)srcName);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1080
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
      (*env)->SetObjectField(env, jcontextSpi, FID_NativeGSSContext_srcName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                             jsrcName);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1083
      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
  1084
        goto error;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1085
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    if (major == GSS_S_COMPLETE) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1088
      TRACE0("[GSSLibStub_acceptContext] context established");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
      (*env)->SetIntField(env, jcontextSpi, FID_NativeGSSContext_lifetime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                          getJavaTime(aTime));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
      (*env)->SetBooleanField(env, jcontextSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                              FID_NativeGSSContext_isEstablished,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                              JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
      jMech = getJavaOID(env, aMech);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1096
      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
  1097
        goto error;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1098
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
      (*env)->SetObjectField(env, jcontextSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                             FID_NativeGSSContext_actualMech, jMech);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1101
      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
  1102
        goto error;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1103
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
      if (delCred != GSS_C_NO_CREDENTIAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        jdelCred = (*env)->NewObject(env, CLS_GSSCredElement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                                     MID_GSSCredElement_ctor,
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1107
                                     ptr_to_jlong(delCred), jsrcName, jMech);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        if ((*env)->ExceptionCheck(env)) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1109
          goto error;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        (*env)->SetObjectField(env, jcontextSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                               FID_NativeGSSContext_delegatedCred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                               jdelCred);
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1114
        TRACE1("[GSSLibStub_acceptContext] set delegatedCred=%" PRIuPTR "",
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1115
                (uintptr_t) delCred);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1116
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1117
        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
  1118
          goto error;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1119
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    } else if (major & GSS_S_CONTINUE_NEEDED) {
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1122
      TRACE0("[GSSLibStub_acceptContext] context not established");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
      if (aFlags & GSS_C_PROT_READY_FLAG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        (*env)->SetIntField(env, jcontextSpi, FID_NativeGSSContext_lifetime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                            getJavaTime(aTime));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
      major -= GSS_S_CONTINUE_NEEDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
  }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1131
  return getJavaBuffer(env, &outToken);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1133
error:
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1134
  (*ftab->releaseBuffer)(&minor, &outToken);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1135
  if (srcName != GSS_C_NO_NAME) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1136
    (*ftab->releaseName)(&minor, &srcName);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1137
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1138
  if (targetName != GSS_C_NO_NAME) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1139
    (*ftab->releaseName)(&minor, &targetName);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1140
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1141
  if (delCred != GSS_C_NO_CREDENTIAL) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1142
    (*ftab->releaseCred) (&minor, &delCred);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1143
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1144
  return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
 * Method:    inquireContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
 * Signature: (J)[J
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
JNIEXPORT jlongArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
Java_sun_security_jgss_wrapper_GSSLibStub_inquireContext(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                                                         jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                                                         jlong pContext)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
  gss_ctx_id_t contextHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
  gss_name_t srcName, targetName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
  OM_uint32 time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
  OM_uint32 flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
  int isInitiator, isEstablished;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
  jlong result[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
  jlongArray jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1166
  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1168
  TRACE1("[GSSLibStub_inquireContext] %" PRIuPTR "", (uintptr_t)contextHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
  srcName = targetName = GSS_C_NO_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
  time = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
  flags = isInitiator = isEstablished = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
  /* gss_inquire_context(...) => GSS_S_NO_CONTEXT(!) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
  major = (*ftab->inquireContext)(&minor, contextHdl, &srcName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                              &targetName, &time, NULL, &flags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                              &isInitiator, &isEstablished);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
  /* update member values if needed */
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1179
  TRACE2("[GSSLibStub_inquireContext] srcName %" PRIuPTR ", targetName %" PRIuPTR "",
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1180
      (uintptr_t)srcName, (uintptr_t)targetName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1182
  checkStatus(env, jobj, major, minor, "[GSSLibStub_inquireContext]");
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1183
  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
  1184
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1185
  }
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1186
  result[0] = ptr_to_jlong(srcName);
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1187
  result[1] = ptr_to_jlong(targetName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
  result[2] = (jlong) isInitiator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
  result[3] = (jlong) isEstablished;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
  result[4] = (jlong) flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
  result[5] = (jlong) getJavaTime(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
  jresult = (*env)->NewLongArray(env, 6);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1194
  if (jresult == NULL) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1195
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1196
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
  (*env)->SetLongArrayRegion(env, jresult, 0, 6, result);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1198
  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
  1199
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1200
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
  return jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
 * Method:    getContextMech
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
 * Signature: (J)Lorg/ietf/jgss/Oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
Java_sun_security_jgss_wrapper_GSSLibStub_getContextMech(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                                                         jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                                                         jlong pContext)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
  gss_OID mech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
  gss_ctx_id_t contextHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1218
  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1220
  TRACE1("[GSSLibStub_getContextMech] %ld", (long int)pContext);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
  major = (*ftab->inquireContext)(&minor, contextHdl, NULL, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                                NULL, &mech, NULL,  NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
  checkStatus(env, jobj, major, minor, "[GSSLibStub_getContextMech]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
  /* return immediately if an exception has occurred */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
  if ((*env)->ExceptionCheck(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
  return getJavaOID(env, mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
 * Method:    getContextName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
 * Signature: (JZ)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
Java_sun_security_jgss_wrapper_GSSLibStub_getContextName(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
  jobject jobj, jlong pContext, jboolean isSrc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
  gss_name_t nameHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
  gss_ctx_id_t contextHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1247
  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1249
  TRACE2("[GSSLibStub_getContextName] %" PRIuPTR ", isSrc=%d",
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1250
          (uintptr_t)contextHdl, isSrc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
  nameHdl = GSS_C_NO_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
  if (isSrc == JNI_TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    major = (*ftab->inquireContext)(&minor, contextHdl, &nameHdl, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                                NULL, NULL, NULL,  NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    major = (*ftab->inquireContext)(&minor, contextHdl, NULL, &nameHdl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                                NULL, NULL, NULL,  NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
  checkStatus(env, jobj, major, minor, "[GSSLibStub_inquireContextAll]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
  /* return immediately if an exception has occurred */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
  if ((*env)->ExceptionCheck(env)) {
16488
816b9df68a9f 8007607: security native code doesn't always use malloc, realloc, and calloc correctly
jzavgren
parents: 14517
diff changeset
  1264
    return jlong_zero;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1267
  TRACE1("[GSSLibStub_getContextName] pName=%" PRIuPTR "", (uintptr_t) nameHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1269
  return ptr_to_jlong(nameHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
 * Method:    getContextTime
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
 * Signature: (J)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
Java_sun_security_jgss_wrapper_GSSLibStub_getContextTime(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                                                         jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                                                         jlong pContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
  gss_ctx_id_t contextHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
  OM_uint32 time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1285
  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1286
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1287
  TRACE1("[GSSLibStub_getContextTime] %" PRIuPTR "", (uintptr_t)contextHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
  if (contextHdl == GSS_C_NO_CONTEXT) return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
  /* gss_context_time(...) => GSS_S_CONTEXT_EXPIRED(!),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     GSS_S_NO_CONTEXT(!) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
  major = (*ftab->contextTime)(&minor, contextHdl, &time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
  if (GSS_ROUTINE_ERROR(major) == GSS_S_CONTEXT_EXPIRED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    major = GSS_CALLING_ERROR(major) | GSS_SUPPLEMENTARY_INFO(major);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
  checkStatus(env, jobj, major, minor, "[GSSLibStub_getContextTime]");
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1298
  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
  1299
    return 0;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1300
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
  return getJavaTime(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
 * Method:    deleteContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
 * Signature: (J)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
Java_sun_security_jgss_wrapper_GSSLibStub_deleteContext(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                                                        jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                                                        jlong pContext)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
  gss_ctx_id_t contextHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1317
  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1318
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1319
  TRACE1("[GSSLibStub_deleteContext] %" PRIuPTR "", (uintptr_t)contextHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1321
  if (contextHdl == GSS_C_NO_CONTEXT) return ptr_to_jlong(GSS_C_NO_CONTEXT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
  /* gss_delete_sec_context(...) => GSS_S_NO_CONTEXT(!) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
  major = (*ftab->deleteSecContext)(&minor, &contextHdl, GSS_C_NO_BUFFER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
  checkStatus(env, jobj, major, minor, "[GSSLibStub_deleteContext]");
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1327
  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
  1328
    return jlong_zero;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1329
  }
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1330
  return (jlong) ptr_to_jlong(contextHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
 * Method:    wrapSizeLimit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
 * Signature: (JIII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
Java_sun_security_jgss_wrapper_GSSLibStub_wrapSizeLimit(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                                                        jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                                                        jlong pContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                                                        jint reqFlag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                                                        jint jqop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                                                        jint joutSize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
  gss_ctx_id_t contextHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
  OM_uint32 outSize, maxInSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
  gss_qop_t qop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1351
  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1352
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1353
  TRACE1("[GSSLibStub_wrapSizeLimit] %" PRIuPTR "", (uintptr_t)contextHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1355
  if (contextHdl == GSS_C_NO_CONTEXT) {
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1356
    // Twik per javadoc
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1357
    checkStatus(env, jobj, GSS_S_NO_CONTEXT, 0,
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1358
        "[GSSLibStub_wrapSizeLimit]");
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1359
    return 0;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1360
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
  qop = (gss_qop_t) jqop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
  outSize = (OM_uint32) joutSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
  /* gss_wrap_size_limit(...) => GSS_S_NO_CONTEXT(!), GSS_S_CONTEXT_EXPIRED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     GSS_S_BAD_QOP */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
  major = (*ftab->wrapSizeLimit)(&minor, contextHdl, reqFlag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                              qop, outSize, &maxInSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
  checkStatus(env, jobj, major, minor, "[GSSLibStub_wrapSizeLimit]");
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1370
  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
  1371
    return 0;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1372
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
  return (jint) maxInSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
 * Method:    exportContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
 * Signature: (J)[B
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
JNIEXPORT jbyteArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
Java_sun_security_jgss_wrapper_GSSLibStub_exportContext(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                                                        jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                                                        jlong pContext)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
  gss_ctx_id_t contextHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
  gss_buffer_desc interProcToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
  jbyteArray jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1391
  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1392
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1393
  TRACE1("[GSSLibStub_exportContext] %" PRIuPTR "", (uintptr_t)contextHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
  if (contextHdl == GSS_C_NO_CONTEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
    // Twik per javadoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
    checkStatus(env, jobj, GSS_S_NO_CONTEXT, 0, "[GSSLibStub_exportContext]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
  /* gss_export_sec_context(...) => GSS_S_CONTEXT_EXPIRED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     GSS_S_NO_CONTEXT, GSS_S_UNAVAILABLE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
  major =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    (*ftab->exportSecContext)(&minor, &contextHdl, &interProcToken);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
  /* release intermediate buffers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
  jresult = getJavaBuffer(env, &interProcToken);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1407
  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
  1408
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1409
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
  checkStatus(env, jobj, major, minor, "[GSSLibStub_exportContext]");
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1411
  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
  1412
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1413
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1414
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
  return jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
 * Method:    getMic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
 * Signature: (JI[B)[B
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
JNIEXPORT jbyteArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
Java_sun_security_jgss_wrapper_GSSLibStub_getMic(JNIEnv *env, jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                                                 jlong pContext, jint jqop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                                                 jbyteArray jmsg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
  gss_ctx_id_t contextHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
  gss_qop_t qop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
  gss_buffer_desc msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
  gss_buffer_desc msgToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
  jbyteArray jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1435
  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1436
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1437
  TRACE1("[GSSLibStub_getMic] %" PRIuPTR "", (uintptr_t)contextHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
  if (contextHdl == GSS_C_NO_CONTEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
    // Twik per javadoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    checkStatus(env, jobj, GSS_S_CONTEXT_EXPIRED, 0, "[GSSLibStub_getMic]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
  qop = (gss_qop_t) jqop;
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1445
  initGSSBuffer(env, jmsg, &msg);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1446
  if ((*env)->ExceptionCheck(env)) {
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
  1447
    return NULL;
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
  1448
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
  /* gss_get_mic(...) => GSS_S_CONTEXT_EXPIRED, GSS_S_NO_CONTEXT(!),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     GSS_S_BAD_QOP */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
  major =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
    (*ftab->getMic)(&minor, contextHdl, qop, &msg, &msgToken);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
  /* release intermediate buffers */
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1456
  resetGSSBuffer(&msg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
  jresult = getJavaBuffer(env, &msgToken);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1458
  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
  1459
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1460
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1461
  checkStatus(env, jobj, major, minor, "[GSSLibStub_getMic]");
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1462
  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
  1463
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1464
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
  return jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
 * Method:    verifyMic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
 * Signature: (J[B[BLorg/ietf/jgss/MessageProp;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
Java_sun_security_jgss_wrapper_GSSLibStub_verifyMic(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                                                    jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                                                    jlong pContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                                                    jbyteArray jmsgToken,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                                                    jbyteArray jmsg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                                                    jobject jprop)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
  gss_ctx_id_t contextHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
  gss_buffer_desc msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
  gss_buffer_desc msgToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
  gss_qop_t qop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1488
  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1489
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1490
  TRACE1("[GSSLibStub_verifyMic] %" PRIuPTR "", (uintptr_t)contextHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
  if (contextHdl == GSS_C_NO_CONTEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
    // Twik per javadoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
    checkStatus(env, jobj, GSS_S_CONTEXT_EXPIRED, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        "[GSSLibStub_verifyMic]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
  }
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
  1498
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1499
  qop = (gss_qop_t) (*env)->CallIntMethod(env, jprop, MID_MessageProp_getQOP);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1500
  if ((*env)->ExceptionCheck(env)) { return; }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1501
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1502
  initGSSBuffer(env, jmsg, &msg);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1503
  if ((*env)->ExceptionCheck(env)) { return; }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1504
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1505
  initGSSBuffer(env, jmsgToken, &msgToken);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1506
  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
  1507
    resetGSSBuffer(&msg);
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
  1508
    return;
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
  1509
  }
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
  1510
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
  /* gss_verify_mic(...) => GSS_S_DEFECTIVE_TOKEN, GSS_S_BAD_MIC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     GSS_S_CONTEXT_EXPIRED, GSS_S_DUPLICATE_TOKEN(!), GSS_S_OLD_TOKEN(!),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     GSS_S_UNSEQ_TOKEN(!), GSS_S_GAP_TOKEN(!), GSS_S_NO_CONTEXT(!) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
  major =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
    (*ftab->verifyMic)(&minor, contextHdl, &msg, &msgToken, &qop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
  /* release intermediate buffers */
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1518
  resetGSSBuffer(&msg);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1519
  resetGSSBuffer(&msgToken);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1520
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1521
  checkStatus(env, jobj, GSS_ERROR(major), minor, "[GSSLibStub_verifyMic]");
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1522
  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
  1523
    return;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1524
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
  (*env)->CallVoidMethod(env, jprop, MID_MessageProp_setQOP, qop);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1527
  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
  1528
    return;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1529
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1530
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
  setSupplementaryInfo(env, jobj, jprop, GSS_SUPPLEMENTARY_INFO(major),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                       minor);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1533
  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
  1534
    return;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1535
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
 * Method:    wrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
 * Signature: (J[BLorg/ietf/jgss/MessageProp;)[B
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
JNIEXPORT jbyteArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
Java_sun_security_jgss_wrapper_GSSLibStub_wrap(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                                               jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                                               jlong pContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                                               jbyteArray jmsg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                                               jobject jprop)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
  jboolean confFlag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
  gss_qop_t qop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
  gss_buffer_desc msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
  gss_buffer_desc msgToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
  int confState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
  gss_ctx_id_t contextHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
  jbyteArray jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1559
  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1560
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1561
  TRACE1("[GSSLibStub_wrap] %" PRIuPTR "", (uintptr_t)contextHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
  if (contextHdl == GSS_C_NO_CONTEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    // Twik per javadoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    checkStatus(env, jobj, GSS_S_CONTEXT_EXPIRED, 0, "[GSSLibStub_wrap]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
  confFlag =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
    (*env)->CallBooleanMethod(env, jprop, MID_MessageProp_getPrivacy);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1571
  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
  1572
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1573
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1574
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
  qop = (gss_qop_t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
    (*env)->CallIntMethod(env, jprop, MID_MessageProp_getQOP);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1577
  if ((*env)->ExceptionCheck(env)) {
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
  1578
    return NULL;
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
  1579
  }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1580
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1581
  initGSSBuffer(env, jmsg, &msg);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1582
  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
  1583
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1584
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1585
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
  /* gss_wrap(...) => GSS_S_CONTEXT_EXPIRED, GSS_S_NO_CONTEXT(!),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     GSS_S_BAD_QOP */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
  major = (*ftab->wrap)(&minor, contextHdl, confFlag, qop, &msg, &confState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                   &msgToken);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1591
  /* release intermediate buffers */
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1592
  resetGSSBuffer(&msg);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1593
  jresult = getJavaBuffer(env, &msgToken);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1594
  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
  1595
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1596
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1597
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1598
  checkStatus(env, jobj, major, minor, "[GSSLibStub_wrap]");
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1599
  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
  1600
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1601
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1602
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
  (*env)->CallVoidMethod(env, jprop, MID_MessageProp_setPrivacy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                         (confState? JNI_TRUE:JNI_FALSE));
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1605
  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
  1606
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1607
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
  return jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
 * Class:     sun_security_jgss_wrapper_GSSLibStub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
 * Method:    unwrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
 * Signature: (J[BLorg/ietf/jgss/MessageProp;)[B
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
JNIEXPORT jbyteArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
Java_sun_security_jgss_wrapper_GSSLibStub_unwrap(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                                                 jobject jobj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                                                 jlong pContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                                                 jbyteArray jmsgToken,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                                                 jobject jprop)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
  OM_uint32 minor, major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
  gss_ctx_id_t contextHdl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
  gss_buffer_desc msgToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
  gss_buffer_desc msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
  int confState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
  gss_qop_t qop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
  jbyteArray jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 5506
diff changeset
  1631
  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1632
49682
2918e1146106 8200468: Port the native GSS-API bridge to Windows
weijun
parents: 48571
diff changeset
  1633
  TRACE1("[GSSLibStub_unwrap] %" PRIuPTR "", (uintptr_t)contextHdl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
  if (contextHdl == GSS_C_NO_CONTEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
    // Twik per javadoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
    checkStatus(env, jobj, GSS_S_CONTEXT_EXPIRED, 0, "[GSSLibStub_unwrap]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
  }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1640
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1641
  initGSSBuffer(env, jmsgToken, &msgToken);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1642
  if ((*env)->ExceptionCheck(env)) {
22940
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
  1643
    return NULL;
56b3ab8ec81c 8031588: warnings from b03 for jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
michaelm
parents: 18175
diff changeset
  1644
  }
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1645
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
  confState = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
  qop = GSS_C_QOP_DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
  /* gss_unwrap(...) => GSS_S_DEFECTIVE_TOKEN, GSS_S_BAD_MIC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
     GSS_S_CONTEXT_EXPIRED, GSS_S_DUPLICATE_TOKEN(!), GSS_S_OLD_TOKEN(!),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
     GSS_S_UNSEQ_TOKEN(!), GSS_S_GAP_TOKEN(!), GSS_S_NO_CONTEXT(!) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
  major =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
    (*ftab->unwrap)(&minor, contextHdl, &msgToken, &msg, &confState, &qop);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1653
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1654
  /* release intermediate buffers */
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1655
  resetGSSBuffer(&msgToken);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1656
  jresult = getJavaBuffer(env, &msg);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1657
  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
  1658
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1659
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1660
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1661
  checkStatus(env, jobj, GSS_ERROR(major), minor, "[GSSLibStub_unwrap]");
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1662
  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
  1663
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1664
  }
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1665
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
  /* update the message prop with relevant info */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
  (*env)->CallVoidMethod(env, jprop, MID_MessageProp_setPrivacy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                         (confState != 0));
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1669
  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
  1670
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1671
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
  (*env)->CallVoidMethod(env, jprop, MID_MessageProp_setQOP, qop);
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1673
  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
  1674
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1675
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
  setSupplementaryInfo(env, jobj, jprop, GSS_SUPPLEMENTARY_INFO(major),
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1677
                         minor);
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1678
  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
  1679
    return NULL;
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 23010
diff changeset
  1680
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
  return jresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
}