src/java.security.jgss/windows/native/libsspi_bridge/sspi.cpp
author stuefe
Sun, 15 Sep 2019 08:41:48 +0200
changeset 58140 a6f653312b19
parent 55638 430a51e86f28
child 58679 9c3209ff7550
permissions -rw-r--r--
8230910: libsspi_bridge does not build on Windows 32bit Reviewed-by: alanb, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
     1
/*
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
     4
 *
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    10
 *
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    15
 * accompanied this code).
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    16
 *
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    20
 *
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    23
 * questions.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    24
 */
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    25
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    26
// This library is client-side only, and only supports the default credentials.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    27
// It speaks krb5 and SPNEGO. NTLM is excluded from SPNEGO negotiation.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    28
//
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    29
// This library can be built directly with the following command:
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    30
//   cl -I %OPENJDK%\src\java.security.jgss\share\native\libj2gss\ sspi.cpp \
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    31
//      -link -dll -out:sspi_bridge.dll
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    33
#define UNICODE
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    34
#define _UNICODE
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    35
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    36
#include <windows.h>
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    37
#include <stdlib.h>
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    38
#include <stdio.h>
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    39
#include <string.h>
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    40
#include <Strsafe.h>
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    41
#include <ntsecapi.h>
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    42
#include <new>
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    43
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    44
#define GSS_DLL_FILE
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    45
#include <gssapi.h>
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    46
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    47
#define SECURITY_WIN32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    48
#include <sspi.h>
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    49
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    50
#pragma comment(lib, "secur32.lib")
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    51
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    52
// Otherwise an exception will be thrown
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    53
#define new new (std::nothrow)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    54
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    55
// A debugging macro
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    56
#define PP(fmt, ...) \
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    57
        if (trace) { \
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    58
            fprintf(stderr, "[SSPI:%ld] "fmt"\n", __LINE__, ##__VA_ARGS__); \
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    59
            fflush(stderr); \
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    60
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    61
#define SEC_SUCCESS(status) ((*minor_status = (status)), (status) >= SEC_E_OK)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    62
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    63
#ifdef __cplusplus
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    64
extern "C" {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    65
#endif /* __cplusplus */
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    66
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    67
// When SSPI_BRIDGE_TRACE is set, debug info goes to stderr. The value is ignored.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    68
char* trace = getenv("SSPI_BRIDGE_TRACE");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    69
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    70
void
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    71
dump(const char* title, PBYTE data, size_t len)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    72
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    73
    if (trace) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    74
        fprintf(stderr, "==== %s ====\n", title);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    75
        for (size_t i = 0; i < len; i++) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    76
            if (i != 0 && i % 16 == 0) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    77
                fprintf(stderr, "\n");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    78
            }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    79
            fprintf(stderr, "%02X ", *(data + i) & 0xff);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    80
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    81
        fprintf(stderr, "\n");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    82
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    83
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    84
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    85
gss_OID_desc KRB5_OID = {9, (void*)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x02"};
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    86
gss_OID_desc SPNEGO_OID = {6, (void*)"\x2b\x06\x01\x05\x05\x02"};
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    87
gss_OID_desc USER_NAME_OID = {10, (void*)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01"};
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    88
gss_OID_desc KRB5_NAME_OID = {10, (void*)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x01"};
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    89
gss_OID_desc HOST_SERVICE_NAME_OID = {10, (void*)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04"};
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    90
gss_OID_desc EXPORT_NAME_OID = {6, (void*)"\x2b\x06\x01\x05\x06\x04"};
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    91
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    92
struct gss_name_struct {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    93
    SEC_WCHAR* name;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    94
};
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    95
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    96
struct gss_ctx_id_struct {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    97
    CredHandle* phCred;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    98
    CtxtHandle hCtxt;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
    99
    SecPkgContext_Sizes SecPkgContextSizes;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   100
    SecPkgContext_NativeNames nnames;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   101
    BOOLEAN established;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   102
    BOOLEAN isSPNEGO;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   103
    BOOLEAN isLocalCred;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   104
    OM_uint32 flags;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   105
};
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   106
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   107
struct gss_cred_id_struct {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   108
    CredHandle* phCredK;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   109
    CredHandle* phCredS;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   110
    long time;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   111
};
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   112
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   113
/* This section holds supporting functions that are not exported */
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   114
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   115
static OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   116
seconds_until(int inputIsUTC, TimeStamp *time)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   117
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   118
    // time is local time
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   119
    LARGE_INTEGER uiLocal;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   120
    FILETIME now;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   121
    GetSystemTimeAsFileTime(&now);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   122
    if (!inputIsUTC) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   123
        FILETIME nowLocal;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   124
        if (FileTimeToLocalFileTime(&now, &nowLocal) == 0) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   125
            return -1;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   126
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   127
        now = nowLocal;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   128
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   129
    uiLocal.HighPart = now.dwHighDateTime;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   130
    uiLocal.LowPart = now.dwLowDateTime;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   131
    if (time->QuadPart < uiLocal.QuadPart) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   132
        return 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   133
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   134
    ULONGLONG diff = (time->QuadPart - uiLocal.QuadPart) / 10000000;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   135
    if (diff > (ULONGLONG)~(OM_uint32)0)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   136
        return GSS_C_INDEFINITE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   137
    return (OM_uint32)diff;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   138
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   139
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   140
static void
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   141
show_time(char* label, TimeStamp* ts)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   142
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   143
    if (trace) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   144
        SYSTEMTIME stLocal;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   145
        FileTimeToSystemTime((FILETIME*)ts, &stLocal);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   146
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   147
        // Build a string showing the date and time.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   148
        PP("%s: %02d/%02d/%d  %02d:%02d %uld", label,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   149
            stLocal.wMonth, stLocal.wDay, stLocal.wYear,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   150
            stLocal.wHour, stLocal.wMinute,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   151
            seconds_until(1, ts));
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   152
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   153
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   154
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   155
// isSPNEGO: true, SPNEGO. false, Kerberos.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   156
static gss_ctx_id_t
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   157
new_context(BOOLEAN isSPNEGO)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   158
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   159
    gss_ctx_id_t out = new gss_ctx_id_struct;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   160
    if (out == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   161
        return NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   162
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   163
    out->phCred = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   164
    out->hCtxt.dwLower = out->hCtxt.dwUpper = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   165
    out->established = FALSE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   166
    out->SecPkgContextSizes.cbMaxSignature
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   167
            = out->SecPkgContextSizes.cbBlockSize
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   168
            = out->SecPkgContextSizes.cbSecurityTrailer
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   169
            = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   170
    out->nnames.sClientName = out->nnames.sServerName = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   171
    out->isSPNEGO = isSPNEGO;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   172
    out->isLocalCred = FALSE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   173
    return out;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   174
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   175
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   176
static gss_cred_id_t
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   177
new_cred()
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   178
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   179
    gss_cred_id_t out = new gss_cred_id_struct;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   180
    out->phCredK = out->phCredS = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   181
    out->time = 0L;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   182
    return out;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   183
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   184
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   185
static int
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   186
flag_sspi_to_gss(int fin)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   187
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   188
    int fout = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   189
    if (fin & ISC_REQ_MUTUAL_AUTH) fout |= GSS_C_MUTUAL_FLAG;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   190
    if (fin & ISC_REQ_CONFIDENTIALITY) fout |= GSS_C_CONF_FLAG;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   191
    if (fin & ISC_REQ_DELEGATE) fout |= GSS_C_DELEG_FLAG;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   192
    if (fin & ISC_REQ_INTEGRITY) fout |= GSS_C_INTEG_FLAG;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   193
    if (fin & ISC_REQ_REPLAY_DETECT) fout |= GSS_C_REPLAY_FLAG;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   194
    if (fin & ISC_REQ_SEQUENCE_DETECT) fout |= GSS_C_SEQUENCE_FLAG;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   195
    return fout;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   196
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   197
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   198
static int
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   199
flag_gss_to_sspi(int fin)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   200
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   201
    int fout = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   202
    if (fin & GSS_C_MUTUAL_FLAG) fout |= ISC_RET_MUTUAL_AUTH;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   203
    if (fin & GSS_C_CONF_FLAG) fout |= ISC_RET_CONFIDENTIALITY;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   204
    if (fin & GSS_C_DELEG_FLAG) fout |= ISC_RET_DELEGATE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   205
    if (fin & GSS_C_INTEG_FLAG) fout |= ISC_RET_INTEGRITY;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   206
    if (fin & GSS_C_REPLAY_FLAG) fout |= ISC_RET_REPLAY_DETECT;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   207
    if (fin & GSS_C_SEQUENCE_FLAG) fout |= ISC_RET_SEQUENCE_DETECT;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   208
    return fout;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   209
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   210
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   211
static BOOLEAN
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   212
is_same_oid(gss_const_OID o2, gss_const_OID o1)
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   213
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   214
    return o1 && o2 && o1->length == o2->length
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   215
            && !memcmp(o1->elements, o2->elements, o2->length);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   216
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   217
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   218
static BOOLEAN
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   219
has_oid(gss_const_OID_set set, gss_const_OID oid)
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   220
{
58140
a6f653312b19 8230910: libsspi_bridge does not build on Windows 32bit
stuefe
parents: 55638
diff changeset
   221
    for (size_t i = 0; i < set->count; i++) {
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   222
        if (is_same_oid(&set->elements[i], oid)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   223
            return TRUE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   224
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   225
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   226
    return FALSE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   227
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   228
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   229
static void
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   230
show_oid(gss_const_OID mech)
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   231
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   232
    if (trace) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   233
        if (is_same_oid(mech, &KRB5_OID)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   234
            PP("Kerberos mech");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   235
        } else if (is_same_oid(mech, &SPNEGO_OID)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   236
            PP("SPNEGO mech");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   237
        } else if (is_same_oid(mech, &USER_NAME_OID)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   238
            PP("NT_USER_NAME name-type");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   239
        } else if (is_same_oid(mech, &KRB5_NAME_OID)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   240
            PP("KRB5_NAME name-type");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   241
        } else if (is_same_oid(mech, &HOST_SERVICE_NAME_OID)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   242
            PP("NT_HOSTBASED_SERVICE name-type");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   243
        } else if (is_same_oid(mech, &EXPORT_NAME_OID)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   244
            PP("NT_EXPORT_NAME name-type");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   245
        } else {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   246
            dump("UNKNOWN OID", (PBYTE)mech->elements, mech->length);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   247
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   248
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   249
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   250
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   251
static void
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   252
show_oid_set(gss_const_OID_set mechs)
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   253
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   254
    if (trace) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   255
        if (mechs == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   256
            PP("OID set is NULL");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   257
            return;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   258
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   259
        PP("gss_OID_set.count is %d", (int)mechs->count);
58140
a6f653312b19 8230910: libsspi_bridge does not build on Windows 32bit
stuefe
parents: 55638
diff changeset
   260
        for (size_t i = 0; i < mechs->count; i++) {
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   261
            show_oid(&mechs->elements[i]);
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   262
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   263
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   264
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   265
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   266
// Add realm to a name if there was none.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   267
// Returns a newly allocated name.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   268
static WCHAR*
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   269
get_full_name(WCHAR* input)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   270
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   271
    // input has realm, no need to add one
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   272
    for (int i = 0;; i++) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   273
        if (!input[i]) { // the end
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   274
            break;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   275
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   276
        if (input[i] == L'\\') { // escaped
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   277
            i++;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   278
            continue;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   279
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   280
        if (input[i] == L'@') {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   281
            return _wcsdup(input);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   282
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   283
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   284
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   285
    // Always use the default domain
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   286
    WCHAR* realm = _wgetenv(L"USERDNSDOMAIN");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   287
    if (realm == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   288
        realm = L"";
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   289
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   290
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   291
    size_t oldlen = wcslen(input);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   292
    size_t newlen = oldlen + 1 + wcslen(realm) + 1;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   293
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   294
    WCHAR* fullname = new WCHAR[newlen];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   295
    if (!fullname) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   296
        return NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   297
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   298
    wcscpy_s(fullname, newlen, input);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   299
    wcscat_s(fullname, newlen, L"@");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   300
    wcscat_s(fullname, newlen, realm);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   301
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   302
    PP("get_full_name returns %ls", fullname);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   303
    return fullname;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   304
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   305
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   306
/* End support section */
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   307
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   308
/* This section holds GSS-API exported functions */
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   309
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   310
#define CHECK_OUTPUT(x)  if (!x) return GSS_S_CALL_INACCESSIBLE_WRITE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   311
#define CHECK_BUFFER(b)  if (!b || !b->value) return GSS_S_CALL_INACCESSIBLE_READ;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   312
#define CHECK_OID(o)     if (!o || !o->elements) return GSS_S_CALL_INACCESSIBLE_READ;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   313
#define CHECK_NAME(n)    if (!n || !(n->name)) return GSS_S_BAD_NAME;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   314
#define CHECK_CONTEXT(c) if (!c) return GSS_S_NO_CONTEXT;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   315
#define CHECK_CRED(c)    if (!c || (!(cred_handle->phCredK) && !(cred_handle->phCredS))) \
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   316
                                return GSS_S_NO_CRED;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   317
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   318
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   319
gss_release_name(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   320
                 gss_name_t *name)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   321
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   322
    PP(">>>> Calling gss_release_name %p...", *name);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   323
    if (name != NULL && *name != GSS_C_NO_NAME) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   324
        if ((*name)->name != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   325
            delete[] (*name)->name;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   326
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   327
        delete *name;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   328
        *name = GSS_C_NO_NAME;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   329
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   330
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   331
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   332
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   333
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   334
gss_import_name(OM_uint32 *minor_status,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   335
                gss_const_buffer_t input_name_buffer,
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   336
                gss_const_OID input_name_type,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   337
                gss_name_t *output_name)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   338
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   339
    PP(">>>> Calling gss_import_name...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   340
    CHECK_BUFFER(input_name_buffer)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   341
    CHECK_OUTPUT(output_name)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   342
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   343
    int len = (int)input_name_buffer->length;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   344
    LPSTR input = (LPSTR)input_name_buffer->value;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   345
    if (input_name_type != NULL
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   346
            && is_same_oid(input_name_type, &EXPORT_NAME_OID)) {
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   347
        if (len < 4 || input[0] != 4 || input[1] != 1 || input[2] != 0) {
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   348
            return GSS_S_FAILURE;
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   349
        }
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   350
        int mechLen = (int)input[3]; /* including 06 len */
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   351
        len -= mechLen + 8; /* 4 header bytes, and an int32 length after OID */
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   352
        if (len <= 0) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   353
            return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   354
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   355
        // Reject if mech is not krb5
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   356
        if (mechLen - 2!= KRB5_OID.length ||
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   357
                memcmp(input + 6, KRB5_OID.elements, mechLen - 2)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   358
            return GSS_S_FAILURE;;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   359
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   360
        input = input + mechLen + 8;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   361
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   362
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   363
    SEC_WCHAR* value = new SEC_WCHAR[len + 1];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   364
    if (value == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   365
        goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   366
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   367
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   368
    len = MultiByteToWideChar(CP_UTF8, 0, input, len, value, len+1);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   369
    if (len == 0) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   370
        goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   371
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   372
    value[len] = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   373
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   374
    PP("import_name from %ls", value);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   375
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   376
    if (len > 33 && !wcscmp(value+len-33, L"@WELLKNOWN:ORG.H5L.REFERALS-REALM")) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   377
        // Remove the wellknown referrals realms
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   378
        value[len-33] = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   379
        len -= 33;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   380
    } else if (value[len-1] == L'@') {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   381
        // Remove the empty realm. It might come from an NT_EXPORT_NAME.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   382
        value[len-1] = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   383
        len--;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   384
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   385
    if (len == 0) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   386
        goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   387
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   388
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   389
    if (input_name_type != NULL
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   390
            && is_same_oid(input_name_type, &HOST_SERVICE_NAME_OID)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   391
        // HOST_SERVICE_NAME_OID takes the form of service@host.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   392
        for (int i = 0; i < len; i++) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   393
            if (value[i] == L'\\') {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   394
                i++;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   395
                continue;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   396
            }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   397
            if (value[i] == L'@') {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   398
                value[i] = L'/';
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   399
                break;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   400
            }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   401
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   402
        PP("Host-based service now %ls", value);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   403
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   404
    PP("import_name to %ls", value);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   405
    gss_name_struct* name = new gss_name_struct;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   406
    if (name == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   407
        goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   408
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   409
    name->name = value;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   410
    *output_name = (gss_name_t) name;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   411
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   412
err:
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   413
    if (value != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   414
        delete[] value;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   415
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   416
    return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   417
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   418
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   419
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   420
gss_compare_name(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   421
                 gss_const_name_t name1,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   422
                 gss_const_name_t name2,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   423
                 int *name_equal)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   424
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   425
    PP(">>>> Calling gss_compare_name...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   426
    CHECK_NAME(name1)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   427
    CHECK_NAME(name2)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   428
    CHECK_OUTPUT(name_equal)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   429
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   430
    *name_equal = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   431
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   432
    SEC_WCHAR* n1 = name1->name;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   433
    SEC_WCHAR* n2 = name2->name;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   434
    PP("Comparing %ls and %ls", n1, n2);
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   435
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   436
    int l1 = lstrlen(n1);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   437
    int l2 = lstrlen(n2);
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   438
    int r1 = l1; // position of @ or the end if none
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   439
    int r2 = l2;
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   440
    int i;
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   441
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   442
    for (i = 0; i < l1; i++) {
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   443
        if (n1[i] == L'\\') {
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   444
            i++;
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   445
            continue;
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   446
        }
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   447
        if (n1[i] == L'@') {
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   448
            r1 = i;
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   449
            break;
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   450
        }
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   451
    }
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   452
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   453
    for (i = 0; i < l2; i++) {
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   454
        if (n2[i] == L'\\') {
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   455
            i++;
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   456
            continue;
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   457
        }
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   458
        if (n2[i] == L'@') {
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   459
            r2 = i;
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   460
            break;
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   461
        }
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   462
    }
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   463
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   464
    if (l1 < l2 && l1 != r2
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   465
            || l2 < l1 && l2 != l1) {
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   466
        return GSS_S_COMPLETE; // different
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   467
    }
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   468
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   469
    if (l1 > l2) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   470
        l1 = l2; // choose the smaller one. longer=smaller @ ...
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   471
    }
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   472
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   473
    // Two names are equal if they are the same or one has no realm and
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   474
    // one has realm but they have the same name. If both have realm but
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   475
    // different, they are treated different even if the names are the same.
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   476
    // Note: the default name concept is not used here.
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   477
    // Principal names on Windows are case-insensitive, both user name
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   478
    // and service principal name.
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   479
    if (CompareStringEx(LOCALE_NAME_SYSTEM_DEFAULT, NORM_IGNORECASE,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   480
            n1, l1, n2, l1, NULL, NULL, 0) == CSTR_EQUAL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   481
        *name_equal = 1;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   482
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   483
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   484
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   485
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   486
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   487
gss_canonicalize_name(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   488
                      gss_const_name_t input_name,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   489
                      gss_const_OID mech_type,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   490
                      gss_name_t *output_name)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   491
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   492
    PP(">>>> Calling gss_canonicalize_name...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   493
    CHECK_NAME(input_name)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   494
    CHECK_OID(mech_type)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   495
    CHECK_OUTPUT(output_name)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   496
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   497
    if (!is_same_oid(mech_type, &KRB5_OID)) {
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   498
        PP("Cannot canonicalize to non-krb5 OID");
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   499
        return GSS_S_BAD_MECH;
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   500
    }
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   501
    gss_name_t names2 = new gss_name_struct;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   502
    if (names2 == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   503
        return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   504
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   505
    names2->name = get_full_name(input_name->name);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   506
    if (names2->name == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   507
        delete names2;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   508
        return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   509
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   510
    *output_name = names2;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   511
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   512
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   513
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   514
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   515
gss_export_name(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   516
                gss_const_name_t input_name,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   517
                gss_buffer_t exported_name)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   518
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   519
    PP(">>>> Calling gss_export_name...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   520
    CHECK_NAME(input_name)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   521
    CHECK_OUTPUT(exported_name)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   522
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   523
    OM_uint32 result = GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   524
    SEC_WCHAR* name = input_name->name;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   525
    SEC_WCHAR* fullname = get_full_name(name);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   526
    if (!fullname) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   527
        goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   528
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   529
    PP("Make fullname: %ls -> %ls", name, fullname);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   530
    int len;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   531
    size_t namelen = wcslen(fullname);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   532
    if (namelen > 255) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   533
        goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   534
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   535
    len = (int)namelen;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   536
    // We only deal with not-so-long names.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   537
    // 04 01 00 ** 06 ** OID len:int32 name
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   538
    int mechLen = KRB5_OID.length;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   539
    char* buffer = new char[10 + mechLen + len];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   540
    if (buffer == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   541
        goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   542
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   543
    buffer[0] = 4;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   544
    buffer[1] = 1;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   545
    buffer[2] = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   546
    buffer[3] = 2 + mechLen;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   547
    buffer[4] = 6;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   548
    buffer[5] = mechLen;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   549
    memcpy_s(buffer + 6, mechLen, KRB5_OID.elements, mechLen);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   550
    buffer[6 + mechLen] = buffer[7 + mechLen] = buffer[8 + mechLen] = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   551
    buffer[9 + mechLen] = (char)len;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   552
    len = WideCharToMultiByte(CP_UTF8, 0, fullname, len,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   553
                buffer+10+mechLen, len, NULL, NULL);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   554
    if (len == 0) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   555
        delete[] buffer;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   556
        goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   557
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   558
    exported_name->length = 10 + mechLen + len;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   559
    exported_name->value = buffer;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   560
    result = GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   561
err:
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   562
    if (fullname != name) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   563
        delete[] fullname;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   564
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   565
    return result;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   566
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   567
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   568
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   569
gss_display_name(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   570
                 gss_const_name_t input_name,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   571
                 gss_buffer_t output_name_buffer,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   572
                 gss_OID *output_name_type)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   573
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   574
    PP(">>>> Calling gss_display_name...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   575
    CHECK_NAME(input_name)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   576
    CHECK_OUTPUT(output_name_buffer)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   577
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   578
    SEC_WCHAR* names = input_name->name;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   579
    int len = (int)wcslen(names);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   580
    char* buffer = new char[4*len+1];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   581
    if (buffer == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   582
        return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   583
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   584
    len = WideCharToMultiByte(CP_UTF8, 0, names, len, buffer, 4*len, NULL, NULL);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   585
    if (len == 0) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   586
        delete[] buffer;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   587
        return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   588
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   589
    buffer[len] = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   590
    output_name_buffer->length = len;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   591
    output_name_buffer->value = buffer;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   592
    PP("Name found: %ls -> %d [%s]", names, len, buffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   593
    if (output_name_type != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   594
        *output_name_type = &KRB5_NAME_OID;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   595
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   596
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   597
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   598
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   599
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   600
gss_acquire_cred(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   601
                 gss_const_name_t desired_name,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   602
                 OM_uint32 time_req,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   603
                 gss_const_OID_set desired_mechs,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   604
                 gss_cred_usage_t cred_usage,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   605
                 gss_cred_id_t *output_cred_handle,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   606
                 gss_OID_set *actual_mechs,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   607
                 OM_uint32 *time_rec)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   608
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   609
    PP(">>>> Calling gss_acquire_cred...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   610
    CHECK_OUTPUT(output_cred_handle)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   611
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   612
    SECURITY_STATUS ss;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   613
    TimeStamp ts;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   614
    ts.QuadPart = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   615
    cred_usage = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   616
    PP("AcquireCredentialsHandle with %d %p", cred_usage, desired_mechs);
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   617
    show_oid_set(desired_mechs);
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   618
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   619
    BOOLEAN reqKerberos, reqSPNEGO;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   620
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   621
    if (!desired_mechs) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   622
        reqKerberos = reqSPNEGO = TRUE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   623
    } else {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   624
        if (has_oid(desired_mechs, &KRB5_OID)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   625
            PP("reqKerberos");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   626
            reqKerberos = TRUE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   627
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   628
        if (has_oid(desired_mechs, &SPNEGO_OID)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   629
            PP("reqSPNEGO");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   630
            reqSPNEGO = TRUE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   631
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   632
        if (!reqSPNEGO && !reqKerberos) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   633
            return GSS_S_BAD_MECH;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   634
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   635
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   636
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   637
    if (actual_mechs) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   638
        *actual_mechs = GSS_C_NO_OID_SET;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   639
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   640
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   641
    gss_cred_id_t cred = new_cred();
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   642
    if (cred == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   643
        goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   644
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   645
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   646
    if (reqKerberos) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   647
        cred->phCredK = new CredHandle;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   648
        if (cred->phCredK == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   649
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   650
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   651
        ss = AcquireCredentialsHandle(
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   652
                NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   653
                L"Kerberos",
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   654
                cred_usage == 0 ? SECPKG_CRED_BOTH :
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   655
                    (cred_usage == 1 ? SECPKG_CRED_OUTBOUND : SECPKG_CRED_INBOUND),
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   656
                NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   657
                NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   658
                NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   659
                NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   660
                cred->phCredK,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   661
                &ts);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   662
        if (!(SEC_SUCCESS(ss))) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   663
            delete cred->phCredK;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   664
            cred->phCredK = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   665
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   666
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   667
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   668
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   669
    if (reqSPNEGO) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   670
        cred->phCredS = new CredHandle;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   671
        if (cred->phCredS == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   672
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   673
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   674
        SEC_WINNT_AUTH_IDENTITY_EX auth;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   675
        ZeroMemory(&auth, sizeof(auth));
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   676
        auth.Version = SEC_WINNT_AUTH_IDENTITY_VERSION;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   677
        auth.Length = sizeof(auth);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   678
        auth.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   679
        auth.PackageList = (unsigned short*)L"Kerberos";
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   680
        auth.PackageListLength = 8;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   681
        ss = AcquireCredentialsHandle(
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   682
                NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   683
                L"Negotiate",
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   684
                cred_usage == 0 ? SECPKG_CRED_BOTH :
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   685
                    (cred_usage == 1 ? SECPKG_CRED_OUTBOUND : SECPKG_CRED_INBOUND),
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   686
                NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   687
                &auth,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   688
                NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   689
                NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   690
                cred->phCredS,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   691
                &ts);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   692
        if (!(SEC_SUCCESS(ss))) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   693
            delete cred->phCredS;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   694
            cred->phCredS = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   695
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   696
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   697
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   698
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   699
    if (actual_mechs) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   700
        if (gss_create_empty_oid_set(minor_status, actual_mechs)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   701
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   702
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   703
        if (reqKerberos) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   704
            if (gss_add_oid_set_member(minor_status, &KRB5_OID, actual_mechs)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   705
                goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   706
            }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   707
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   708
        if (reqSPNEGO) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   709
            if (gss_add_oid_set_member(minor_status, &SPNEGO_OID, actual_mechs)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   710
                goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   711
            }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   712
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   713
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   714
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   715
    *output_cred_handle = (gss_cred_id_t)cred;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   716
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   717
    // Note: ts here is weirdly huge, maybe because LSA retains the
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   718
    // password and can re-acquire a TGT at anytime. It will be
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   719
    // GSSCredential.INDEFINITE_LIFETIME.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   720
    show_time("cred expiration", &ts);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   721
    cred->time = seconds_until(1, &ts);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   722
    if (time_rec != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   723
        *time_rec = cred->time;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   724
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   725
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   726
    // Since only default cred is supported, if there is a desired_name,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   727
    // we must make sure it is the same as the realname of the default cred.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   728
    if (desired_name != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   729
        PP("Acquiring cred with a name. Check if it's me.");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   730
        gss_name_t realname;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   731
        if (gss_inquire_cred(minor_status, *output_cred_handle, &realname,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   732
                NULL, NULL, NULL) != GSS_S_COMPLETE) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   733
            PP("Cannot get owner name of default creds");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   734
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   735
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   736
        SEC_WCHAR* rnames = realname->name;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   737
        SEC_WCHAR* dnames = desired_name->name;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   738
        int equals = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   739
        gss_compare_name(minor_status, realname, desired_name, &equals);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   740
        gss_release_name(minor_status, &realname);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   741
        PP("Comparing result: %d", equals);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   742
        if (!equals) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   743
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   744
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   745
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   746
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   747
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   748
err:
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   749
    if (cred) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   750
        OM_uint32 dummy;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   751
        gss_release_cred(&dummy, &cred);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   752
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   753
    if (actual_mechs) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   754
        OM_uint32 dummy;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   755
        gss_release_oid_set(&dummy, actual_mechs);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   756
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   757
    return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   758
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   759
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   760
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   761
gss_release_cred(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   762
                 gss_cred_id_t *cred_handle)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   763
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   764
    PP(">>>> Calling gss_release_cred...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   765
    if (cred_handle && *cred_handle) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   766
        if ((*cred_handle)->phCredK) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   767
            FreeCredentialsHandle((*cred_handle)->phCredK);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   768
            delete (*cred_handle)->phCredK;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   769
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   770
        if ((*cred_handle)->phCredS) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   771
            FreeCredentialsHandle((*cred_handle)->phCredS);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   772
            delete (*cred_handle)->phCredS;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   773
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   774
        delete *cred_handle;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   775
        *cred_handle = GSS_C_NO_CREDENTIAL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   776
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   777
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   778
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   779
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   780
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   781
gss_inquire_cred(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   782
                 gss_const_cred_id_t cred_handle,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   783
                 gss_name_t *name,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   784
                 OM_uint32 *lifetime,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   785
                 gss_cred_usage_t *cred_usage,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   786
                 gss_OID_set *mechanisms)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   787
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   788
    PP(">>>> Calling gss_inquire_cred...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   789
    CHECK_CRED(cred_handle)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   790
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   791
    CredHandle* cred = cred_handle->phCredK
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   792
            ? cred_handle->phCredK
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   793
            : cred_handle->phCredS;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   794
    SECURITY_STATUS ss;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   795
    if (name) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   796
        *name = GSS_C_NO_NAME;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   797
        SecPkgCredentials_Names snames;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   798
        ss = QueryCredentialsAttributes(cred, SECPKG_CRED_ATTR_NAMES, &snames);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   799
        if (!SEC_SUCCESS(ss)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   800
            return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   801
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   802
        SEC_WCHAR* names = new SEC_WCHAR[lstrlen(snames.sUserName) + 1];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   803
        if (names == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   804
            return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   805
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   806
        StringCchCopy(names, lstrlen(snames.sUserName) + 1, snames.sUserName);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   807
        FreeContextBuffer(snames.sUserName);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   808
        PP("Allocate new name at %p", names);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   809
        gss_name_t name1 = new gss_name_struct;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   810
        if (name1 == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   811
            delete[] names;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   812
            return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   813
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   814
        name1->name = names;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   815
        *name = (gss_name_t) name1;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   816
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   817
    if (lifetime) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   818
        *lifetime = cred_handle->time;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   819
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   820
    if (cred_usage) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   821
        *cred_usage = 1; // We only support INITIATE_ONLY now
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   822
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   823
    if (mechanisms) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   824
        // Useless for Java
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   825
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   826
    // Others inquiries not supported yet
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   827
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   828
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   829
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   830
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   831
gss_import_sec_context(OM_uint32 *minor_status,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   832
                       gss_const_buffer_t interprocess_token,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   833
                       gss_ctx_id_t *context_handle)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   834
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   835
    // Not transferable, return FAILURE
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   836
    PP(">>>> Calling UNIMPLEMENTED gss_import_sec_context...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   837
    *minor_status = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   838
    return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   839
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   840
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   841
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   842
gss_init_sec_context(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   843
                     gss_const_cred_id_t initiator_cred_handle,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   844
                     gss_ctx_id_t *context_handle,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   845
                     gss_const_name_t target_name,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   846
                     gss_const_OID mech_type,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   847
                     OM_uint32 req_flags,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   848
                     OM_uint32 time_req,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   849
                     gss_const_channel_bindings_t input_chan_bindings,
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
   850
                     gss_const_buffer_t input_token,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   851
                     gss_OID *actual_mech_type,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   852
                     gss_buffer_t output_token,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   853
                     OM_uint32 *ret_flags,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   854
                     OM_uint32 *time_rec)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   855
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   856
    PP(">>>> Calling gss_init_sec_context...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   857
    CHECK_NAME(target_name)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   858
    CHECK_OUTPUT(output_token)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   859
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   860
    SECURITY_STATUS ss;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   861
    TimeStamp lifeTime;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   862
    SecBufferDesc inBuffDesc;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   863
    SecBuffer inSecBuff;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   864
    SecBufferDesc outBuffDesc;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   865
    SecBuffer outSecBuff;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   866
    BOOLEAN isSPNEGO = is_same_oid(mech_type, &SPNEGO_OID);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   867
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   868
    gss_ctx_id_t pc;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   869
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   870
    output_token->length = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   871
    output_token->value = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   872
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   873
    BOOLEAN firstTime = (*context_handle == GSS_C_NO_CONTEXT);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   874
    PP("First time? %d", firstTime);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   875
    if (firstTime) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   876
        pc = new_context(isSPNEGO);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   877
        if (pc == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   878
            return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   879
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   880
        *context_handle = (gss_ctx_id_t) pc;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   881
    } else {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   882
        pc = *context_handle;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   883
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   884
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   885
    if (pc == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   886
        return GSS_S_NO_CONTEXT;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   887
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   888
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   889
    DWORD outFlag;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   890
    TCHAR outName[100];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   891
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   892
    OM_uint32 minor;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   893
    gss_buffer_desc tn;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   894
    gss_display_name(&minor, target_name, &tn, NULL);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   895
    int len = MultiByteToWideChar(CP_UTF8, 0, (LPCCH)tn.value, (int)tn.length,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   896
            outName, sizeof(outName) - 1);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   897
    if (len == 0) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   898
        goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   899
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   900
    outName[len] = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   901
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   902
    int flag = flag_gss_to_sspi(req_flags) | ISC_REQ_ALLOCATE_MEMORY;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   903
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   904
    outBuffDesc.ulVersion = SECBUFFER_VERSION;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   905
    outBuffDesc.cBuffers = 1;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   906
    outBuffDesc.pBuffers = &outSecBuff;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   907
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   908
    outSecBuff.BufferType = SECBUFFER_TOKEN;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   909
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   910
    if (!firstTime) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   911
        inBuffDesc.ulVersion = SECBUFFER_VERSION;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   912
        inBuffDesc.cBuffers = 1;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   913
        inBuffDesc.pBuffers = &inSecBuff;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   914
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   915
        inSecBuff.BufferType = SECBUFFER_TOKEN;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   916
        inSecBuff.cbBuffer = (ULONG)input_token->length;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   917
        inSecBuff.pvBuffer = input_token->value;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   918
    } else if (!pc->phCred) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   919
        if (isSPNEGO && initiator_cred_handle
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   920
                && initiator_cred_handle->phCredS) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   921
            PP("Find SPNEGO credentials");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   922
            pc->phCred = initiator_cred_handle->phCredS;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   923
            pc->isLocalCred = FALSE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   924
        } else if (!isSPNEGO && initiator_cred_handle
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   925
                && initiator_cred_handle->phCredK) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   926
            PP("Find Kerberos credentials");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   927
            pc->phCred = initiator_cred_handle->phCredK;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   928
            pc->isLocalCred = FALSE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   929
        } else {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   930
            PP("No credentials provided, acquire myself");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   931
            CredHandle* newCred = new CredHandle;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   932
            SEC_WINNT_AUTH_IDENTITY_EX auth;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   933
            ZeroMemory(&auth, sizeof(auth));
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   934
            auth.Version = SEC_WINNT_AUTH_IDENTITY_VERSION;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   935
            auth.Length = sizeof(auth);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   936
            auth.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   937
            auth.PackageList = (unsigned short*)L"Kerberos";
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   938
            auth.PackageListLength = 8;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   939
            ss = AcquireCredentialsHandle(
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   940
                    NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   941
                    isSPNEGO ? L"Negotiate" : L"Kerberos",
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   942
                    SECPKG_CRED_OUTBOUND,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   943
                    NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   944
                    isSPNEGO ? &auth : NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   945
                    NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   946
                    NULL,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   947
                    newCred,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   948
                    &lifeTime);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   949
            if (!(SEC_SUCCESS(ss))) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   950
                delete newCred;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   951
                goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   952
            }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   953
            pc->phCred = newCred;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   954
            pc->isLocalCred = TRUE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   955
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   956
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   957
    ss = InitializeSecurityContext(
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   958
            pc->phCred,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   959
            firstTime ? NULL : &pc->hCtxt,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   960
            outName,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   961
            flag,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   962
            0,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   963
            SECURITY_NATIVE_DREP,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   964
            firstTime ? NULL : &inBuffDesc,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   965
            0,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   966
            &pc->hCtxt,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   967
            &outBuffDesc,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   968
            &outFlag,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   969
            &lifeTime);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   970
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   971
    if (!SEC_SUCCESS(ss)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   972
        PP("InitializeSecurityContext failed");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   973
        goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   974
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   975
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   976
    pc->flags = *ret_flags = flag_sspi_to_gss(outFlag);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   977
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   978
    // Ignore the result of the next call. Might fail before context established.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   979
    QueryContextAttributes(
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   980
            &pc->hCtxt, SECPKG_ATTR_SIZES, &pc->SecPkgContextSizes);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   981
    PP("cbMaxSignature: %ld. cbBlockSize: %ld. cbSecurityTrailer: %ld",
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   982
            pc->SecPkgContextSizes.cbMaxSignature,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   983
            pc->SecPkgContextSizes.cbBlockSize,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   984
            pc->SecPkgContextSizes.cbSecurityTrailer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   985
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   986
    output_token->length = outSecBuff.cbBuffer;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   987
    if (outSecBuff.cbBuffer) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   988
        // No idea how user would free the data. Let's duplicate one.
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   989
        output_token->value = new char[outSecBuff.cbBuffer];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   990
        if (!output_token->value) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   991
            FreeContextBuffer(outSecBuff.pvBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   992
            output_token->length = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   993
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   994
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   995
        memcpy(output_token->value, outSecBuff.pvBuffer, outSecBuff.cbBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   996
        FreeContextBuffer(outSecBuff.pvBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   997
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   998
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
   999
    if (ss == SEC_I_CONTINUE_NEEDED) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1000
        return GSS_S_CONTINUE_NEEDED;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1001
    } else {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1002
        pc->established = true;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1003
        ss = QueryContextAttributes(&pc->hCtxt, SECPKG_ATTR_NATIVE_NAMES, &pc->nnames);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1004
        if (!SEC_SUCCESS(ss)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1005
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1006
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1007
        PP("Names. %ls %ls", pc->nnames.sClientName, pc->nnames.sServerName);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1008
        *ret_flags |= GSS_C_PROT_READY_FLAG;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1009
        return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1010
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1011
err:
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1012
    if (firstTime) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1013
        OM_uint32 dummy;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1014
        gss_delete_sec_context(&dummy, context_handle, GSS_C_NO_BUFFER);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1015
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1016
    if (output_token->value) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1017
        gss_release_buffer(NULL, output_token);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1018
        output_token = GSS_C_NO_BUFFER;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1019
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1020
    return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1021
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1022
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1023
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1024
gss_accept_sec_context(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1025
                       gss_ctx_id_t *context_handle,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1026
                       gss_const_cred_id_t acceptor_cred_handle,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1027
                       gss_const_buffer_t input_token,
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1028
                       gss_const_channel_bindings_t input_chan_bindings,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1029
                       gss_name_t *src_name,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1030
                       gss_OID *mech_type,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1031
                       gss_buffer_t output_token,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1032
                       OM_uint32 *ret_flags,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1033
                       OM_uint32 *time_rec,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1034
                       gss_cred_id_t *delegated_cred_handle)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1035
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1036
    PP(">>>> Calling UNIMPLEMENTED gss_accept_sec_context...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1037
    PP("gss_accept_sec_context is not supported in this initiator-only library");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1038
    return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1039
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1040
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1041
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1042
gss_inquire_context(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1043
                    gss_const_ctx_id_t context_handle,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1044
                    gss_name_t *src_name,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1045
                    gss_name_t *targ_name,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1046
                    OM_uint32 *lifetime_rec,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1047
                    gss_OID *mech_type,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1048
                    OM_uint32 *ctx_flags,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1049
                    int *locally_initiated,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1050
                    int *open)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1051
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1052
    PP(">>>> Calling gss_inquire_context...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1053
    CHECK_CONTEXT(context_handle)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1054
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1055
    gss_name_t n1 = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1056
    gss_name_t n2 = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1057
    if (!context_handle->established) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1058
        return GSS_S_NO_CONTEXT;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1059
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1060
    if (src_name != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1061
        n1 = new gss_name_struct;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1062
        if (n1 == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1063
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1064
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1065
        n1->name = new SEC_WCHAR[lstrlen(context_handle->nnames.sClientName) + 1];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1066
        if (n1->name == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1067
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1068
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1069
        PP("Allocate new name at %p", n1->name);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1070
        StringCchCopy(n1->name, lstrlen(context_handle->nnames.sClientName) + 1,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1071
                context_handle->nnames.sClientName);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1072
        *src_name = (gss_name_t) n1;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1073
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1074
    if (targ_name != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1075
        n2 = new gss_name_struct;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1076
        if (n2 == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1077
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1078
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1079
        n2->name = new SEC_WCHAR[lstrlen(context_handle->nnames.sServerName) + 1];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1080
        if (n2->name == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1081
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1082
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1083
        PP("Allocate new name at %p", n2->name);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1084
        StringCchCopy(n2->name, lstrlen(context_handle->nnames.sServerName) + 1,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1085
                context_handle->nnames.sServerName);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1086
        *targ_name = (gss_name_t) n2;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1087
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1088
    if (lifetime_rec != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1089
        SecPkgContext_Lifespan ls;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1090
        SECURITY_STATUS ss;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1091
        ss = QueryContextAttributes(
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1092
                (PCtxtHandle)&context_handle->hCtxt,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1093
                SECPKG_ATTR_LIFESPAN,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1094
                &ls);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1095
        if (!SEC_SUCCESS(ss)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1096
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1097
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1098
        *lifetime_rec = seconds_until(0, &ls.tsExpiry);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1099
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1100
    if (mech_type != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1101
        *mech_type = context_handle->isSPNEGO
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1102
                ? &SPNEGO_OID : &KRB5_OID;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1103
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1104
    if (ctx_flags != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1105
        *ctx_flags = context_handle->flags;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1106
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1107
    if (locally_initiated != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1108
        // We are always initiator
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1109
        *locally_initiated = 1;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1110
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1111
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1112
err:
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1113
    if (n1 != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1114
        if (n1->name != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1115
            delete[] n1->name;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1116
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1117
        delete n1;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1118
        n1 = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1119
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1120
    if (n2 != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1121
        if (n2->name != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1122
            delete[] n2->name;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1123
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1124
        delete n2;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1125
        n2 = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1126
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1127
    return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1128
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1129
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1130
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1131
gss_delete_sec_context(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1132
                       gss_ctx_id_t *context_handle,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1133
                       gss_buffer_t output_token)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1134
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1135
    PP(">>>> Calling gss_delete_sec_context...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1136
    CHECK_CONTEXT(context_handle)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1137
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1138
    DeleteSecurityContext(&(*context_handle)->hCtxt);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1139
    if ((*context_handle)->isLocalCred && (*context_handle)->phCred != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1140
        FreeCredentialsHandle((*context_handle)->phCred);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1141
        (*context_handle)->phCred = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1142
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1143
    if ((*context_handle)->nnames.sClientName != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1144
        FreeContextBuffer((*context_handle)->nnames.sClientName);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1145
        (*context_handle)->nnames.sClientName = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1146
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1147
    if ((*context_handle)->nnames.sServerName != NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1148
        FreeContextBuffer((*context_handle)->nnames.sServerName);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1149
        (*context_handle)->nnames.sServerName = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1150
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1151
    delete (*context_handle);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1152
    *context_handle = GSS_C_NO_CONTEXT;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1153
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1154
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1155
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1156
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1157
gss_context_time(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1158
                 gss_const_ctx_id_t context_handle,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1159
                 OM_uint32 *time_rec)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1160
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1161
    PP(">>>> Calling IMPLEMENTED gss_context_time...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1162
    CHECK_CONTEXT(context_handle)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1163
    CHECK_OUTPUT(time_rec)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1164
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1165
    SECURITY_STATUS ss;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1166
    SecPkgContext_Lifespan ls;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1167
    ss = QueryContextAttributes(
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1168
            (PCtxtHandle)&context_handle->hCtxt,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1169
            SECPKG_ATTR_LIFESPAN,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1170
            &ls);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1171
    if (ss == SEC_E_OK) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1172
        *time_rec = seconds_until(0, &ls.tsExpiry);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1173
        show_time("context start", &ls.tsStart);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1174
        show_time("context expiry", &ls.tsExpiry);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1175
        return *time_rec == 0 ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1176
    } else {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1177
        return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1178
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1179
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1180
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1181
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1182
gss_wrap_size_limit(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1183
                    gss_const_ctx_id_t context_handle,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1184
                    int conf_req_flag,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1185
                    gss_qop_t qop_req,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1186
                    OM_uint32 req_output_size,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1187
                    OM_uint32 *max_input_size)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1188
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1189
    PP(">>>> Calling gss_wrap_size_limit...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1190
    CHECK_CONTEXT(context_handle)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1191
    CHECK_OUTPUT(max_input_size)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1192
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1193
    *max_input_size = req_output_size
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1194
            - context_handle->SecPkgContextSizes.cbSecurityTrailer
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1195
            - context_handle->SecPkgContextSizes.cbBlockSize;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1196
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1197
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1198
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1199
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1200
gss_export_sec_context(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1201
                       gss_ctx_id_t *context_handle,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1202
                       gss_buffer_t interprocess_token)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1203
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1204
    PP(">>>> Calling UNIMPLEMENTED gss_export_sec_context...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1205
    return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1206
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1207
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1208
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1209
gss_get_mic(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1210
            gss_const_ctx_id_t context_handle,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1211
            gss_qop_t qop_req,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1212
            gss_const_buffer_t message_buffer,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1213
            gss_buffer_t msg_token)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1214
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1215
    PP(">>>> Calling gss_get_mic...");
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1216
    CHECK_CONTEXT(context_handle)
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1217
    CHECK_BUFFER(message_buffer)
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1218
    CHECK_OUTPUT(msg_token)
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1219
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1220
    SECURITY_STATUS ss;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1221
    SecBufferDesc buffDesc;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1222
    SecBuffer secBuff[2];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1223
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1224
    buffDesc.cBuffers = 2;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1225
    buffDesc.pBuffers = secBuff;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1226
    buffDesc.ulVersion = SECBUFFER_VERSION;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1227
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1228
    secBuff[0].BufferType = SECBUFFER_DATA;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1229
    secBuff[0].cbBuffer = (ULONG)message_buffer->length;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1230
    secBuff[0].pvBuffer = message_buffer->value;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1231
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1232
    secBuff[1].BufferType = SECBUFFER_TOKEN;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1233
    secBuff[1].cbBuffer = context_handle->SecPkgContextSizes.cbMaxSignature;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1234
    secBuff[1].pvBuffer = msg_token->value = new char[secBuff[1].cbBuffer];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1235
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1236
    ss = MakeSignature((PCtxtHandle)&context_handle->hCtxt, 0, &buffDesc, 0);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1237
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1238
    if (!SEC_SUCCESS(ss)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1239
        msg_token->length = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1240
        msg_token->value = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1241
        delete[] secBuff[1].pvBuffer;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1242
        return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1243
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1244
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1245
    msg_token->length = secBuff[1].cbBuffer;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1246
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1247
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1248
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1249
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1250
gss_verify_mic(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1251
               gss_const_ctx_id_t context_handle,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1252
               gss_const_buffer_t message_buffer,
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1253
               gss_const_buffer_t token_buffer,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1254
               gss_qop_t *qop_state)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1255
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1256
    PP(">>>> Calling gss_verify_mic...");
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1257
    CHECK_CONTEXT(context_handle)
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1258
    CHECK_BUFFER(message_buffer)
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1259
    CHECK_BUFFER(token_buffer)
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1260
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1261
    SECURITY_STATUS ss;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1262
    SecBufferDesc buffDesc;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1263
    SecBuffer secBuff[2];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1264
    ULONG qop;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1265
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1266
    buffDesc.ulVersion = SECBUFFER_VERSION;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1267
    buffDesc.cBuffers = 2;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1268
    buffDesc.pBuffers = secBuff;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1269
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1270
    secBuff[0].BufferType = SECBUFFER_TOKEN;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1271
    secBuff[0].cbBuffer = (ULONG)token_buffer->length;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1272
    secBuff[0].pvBuffer = token_buffer->value;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1273
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1274
    secBuff[1].BufferType = SECBUFFER_DATA;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1275
    secBuff[1].cbBuffer = (ULONG)message_buffer->length;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1276
    secBuff[1].pvBuffer = message_buffer->value;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1277
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1278
    ss = VerifySignature((PCtxtHandle)&context_handle->hCtxt, &buffDesc, 0, &qop);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1279
    if (qop_state) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1280
        *qop_state = qop;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1281
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1282
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1283
    if (ss == SEC_E_OK) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1284
        return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1285
    } else if (ss == SEC_E_OUT_OF_SEQUENCE) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1286
        return GSS_S_UNSEQ_TOKEN;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1287
    } else {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1288
        return GSS_S_BAD_SIG;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1289
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1290
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1291
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1292
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1293
gss_wrap(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1294
         gss_const_ctx_id_t context_handle,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1295
         int conf_req_flag,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1296
         gss_qop_t qop_req,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1297
         gss_const_buffer_t input_message_buffer,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1298
         int *conf_state,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1299
         gss_buffer_t output_message_buffer)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1300
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1301
    PP(">>>> Calling gss_wrap...");
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1302
    CHECK_CONTEXT(context_handle)
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1303
    CHECK_BUFFER(input_message_buffer)
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1304
    CHECK_OUTPUT(output_message_buffer)
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1305
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1306
    SECURITY_STATUS ss;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1307
    SecBufferDesc buffDesc;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1308
    SecBuffer secBuff[3];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1309
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1310
    buffDesc.ulVersion = SECBUFFER_VERSION;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1311
    buffDesc.cBuffers = 3;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1312
    buffDesc.pBuffers = secBuff;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1313
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1314
    secBuff[0].BufferType = SECBUFFER_TOKEN;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1315
    secBuff[0].cbBuffer = context_handle->SecPkgContextSizes.cbSecurityTrailer;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1316
    output_message_buffer->value = secBuff[0].pvBuffer = malloc(
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1317
            context_handle->SecPkgContextSizes.cbSecurityTrailer
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1318
                    + input_message_buffer->length
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1319
                    + context_handle->SecPkgContextSizes.cbBlockSize);;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1320
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1321
    secBuff[1].BufferType = SECBUFFER_DATA;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1322
    secBuff[1].cbBuffer = (ULONG)input_message_buffer->length;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1323
    secBuff[1].pvBuffer = malloc(secBuff[1].cbBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1324
    memcpy_s(secBuff[1].pvBuffer, secBuff[1].cbBuffer,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1325
            input_message_buffer->value, input_message_buffer->length);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1326
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1327
    secBuff[2].BufferType = SECBUFFER_PADDING;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1328
    secBuff[2].cbBuffer = context_handle->SecPkgContextSizes.cbBlockSize;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1329
    secBuff[2].pvBuffer = malloc(secBuff[2].cbBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1330
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1331
    ss = EncryptMessage((PCtxtHandle)&context_handle->hCtxt,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1332
            conf_req_flag ? 0 : SECQOP_WRAP_NO_ENCRYPT,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1333
            &buffDesc, 0);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1334
    if (conf_state) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1335
        *conf_state = conf_req_flag;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1336
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1337
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1338
    if (!SEC_SUCCESS(ss)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1339
        free(secBuff[0].pvBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1340
        free(secBuff[1].pvBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1341
        free(secBuff[2].pvBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1342
        output_message_buffer->length = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1343
        output_message_buffer->value = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1344
        return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1345
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1346
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1347
    memcpy_s((PBYTE)secBuff[0].pvBuffer + secBuff[0].cbBuffer,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1348
            input_message_buffer->length + context_handle->SecPkgContextSizes.cbBlockSize,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1349
            secBuff[1].pvBuffer,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1350
            secBuff[1].cbBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1351
    memcpy_s((PBYTE)secBuff[0].pvBuffer + secBuff[0].cbBuffer + secBuff[1].cbBuffer,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1352
            context_handle->SecPkgContextSizes.cbBlockSize,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1353
            secBuff[2].pvBuffer,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1354
            secBuff[2].cbBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1355
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1356
    output_message_buffer->length = secBuff[0].cbBuffer + secBuff[1].cbBuffer
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1357
            + secBuff[2].cbBuffer;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1358
    free(secBuff[1].pvBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1359
    free(secBuff[2].pvBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1360
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1361
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1362
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1363
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1364
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1365
gss_unwrap(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1366
           gss_const_ctx_id_t context_handle,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1367
           gss_const_buffer_t input_message_buffer,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1368
           gss_buffer_t output_message_buffer,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1369
           int *conf_state,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1370
           gss_qop_t *qop_state)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1371
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1372
    PP(">>>> Calling gss_unwrap...");
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1373
    CHECK_CONTEXT(context_handle)
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1374
    CHECK_BUFFER(input_message_buffer)
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1375
    CHECK_OUTPUT(output_message_buffer)
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1376
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1377
    SECURITY_STATUS ss;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1378
    SecBufferDesc buffDesc;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1379
    SecBuffer secBuff[2];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1380
    ULONG ulQop = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1381
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1382
    buffDesc.cBuffers = 2;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1383
    buffDesc.pBuffers = secBuff;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1384
    buffDesc.ulVersion = SECBUFFER_VERSION;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1385
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1386
    secBuff[0].BufferType = SECBUFFER_STREAM;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1387
    secBuff[0].cbBuffer = (ULONG)input_message_buffer->length;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1388
    secBuff[0].pvBuffer = malloc(input_message_buffer->length);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1389
    memcpy_s(secBuff[0].pvBuffer, input_message_buffer->length,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1390
            input_message_buffer->value, input_message_buffer->length);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1391
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1392
    secBuff[1].BufferType = SECBUFFER_DATA;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1393
    secBuff[1].cbBuffer = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1394
    secBuff[1].pvBuffer = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1395
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1396
    ss = DecryptMessage((PCtxtHandle)&context_handle->hCtxt, &buffDesc, 0, &ulQop);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1397
    if (qop_state) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1398
        *qop_state = ulQop;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1399
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1400
    if (!SEC_SUCCESS(ss)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1401
        free(secBuff[0].pvBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1402
        output_message_buffer->length = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1403
        output_message_buffer->value = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1404
        return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1405
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1406
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1407
    // Must allocate a new memory block so client can release it correctly
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1408
    output_message_buffer->length = secBuff[1].cbBuffer;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1409
    output_message_buffer->value = new char[secBuff[1].cbBuffer];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1410
    memcpy_s(output_message_buffer->value, secBuff[1].cbBuffer,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1411
            secBuff[1].pvBuffer, secBuff[1].cbBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1412
    *conf_state = ulQop == SECQOP_WRAP_NO_ENCRYPT ? 0 : 1;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1413
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1414
    free(secBuff[0].pvBuffer);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1415
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1416
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1417
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1418
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1419
gss_indicate_mechs(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1420
                   gss_OID_set *mech_set)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1421
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1422
    PP(">>>> Calling gss_indicate_mechs...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1423
    OM_uint32 major = GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1424
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1425
    ULONG ccPackages;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1426
    PSecPkgInfo packages;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1427
    EnumerateSecurityPackages(&ccPackages, &packages);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1428
    PP("EnumerateSecurityPackages returns %ld", ccPackages);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1429
    for (unsigned int i = 0; i < ccPackages; i++) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1430
        PP("#%d: %ls, %ls\n", i, packages[i].Name, packages[i].Comment);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1431
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1432
    FreeContextBuffer(packages);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1433
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1434
    // Hardcode kerberos and SPNEGO support
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1435
    major = gss_create_empty_oid_set(minor_status, mech_set);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1436
    if (major != GSS_S_COMPLETE) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1437
        goto done;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1438
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1439
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1440
    major = gss_add_oid_set_member(minor_status, &KRB5_OID, mech_set);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1441
    if (major != GSS_S_COMPLETE) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1442
        goto done;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1443
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1444
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1445
    major = gss_add_oid_set_member(minor_status, &SPNEGO_OID, mech_set);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1446
    if (major != GSS_S_COMPLETE) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1447
        goto done;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1448
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1449
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1450
done:
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1451
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1452
    if (major != GSS_S_COMPLETE) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1453
        gss_release_oid_set(minor_status, mech_set);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1454
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1455
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1456
    return major;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1457
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1458
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1459
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1460
gss_inquire_names_for_mech(OM_uint32 *minor_status,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1461
                           gss_const_OID mechanism,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1462
                           gss_OID_set *name_types)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1463
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1464
    PP(">>>> Calling gss_inquire_names_for_mech...");
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1465
    CHECK_OID(mechanism)
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1466
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1467
    if (gss_create_empty_oid_set(minor_status, name_types)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1468
        return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1469
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1470
    if (gss_add_oid_set_member(minor_status, &USER_NAME_OID, name_types)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1471
        goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1472
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1473
    if (gss_add_oid_set_member(minor_status, &HOST_SERVICE_NAME_OID, name_types)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1474
        goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1475
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1476
    if (!is_same_oid(mechanism, &SPNEGO_OID)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1477
        if (gss_add_oid_set_member(minor_status, &EXPORT_NAME_OID, name_types)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1478
            goto err;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1479
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1480
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1481
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1482
err:
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1483
    gss_release_oid_set(minor_status, name_types);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1484
    return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1485
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1486
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1487
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1488
gss_add_oid_set_member(OM_uint32 *minor_status,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1489
                       gss_const_OID member_oid,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1490
                       gss_OID_set *oid_set)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1491
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1492
    PP(">>>> Calling gss_add_oid_set_member...");
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1493
    CHECK_OID(member_oid)
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1494
    CHECK_OUTPUT(oid_set)
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1495
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1496
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1497
    int count = (int)(*oid_set)->count;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1498
    for (int i = 0; i < count; i++) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1499
        if (is_same_oid(&(*oid_set)->elements[i], member_oid)) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1500
            // already there
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1501
            return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1502
        }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1503
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1504
    gss_OID existing = (*oid_set)->elements;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1505
    gss_OID newcopy = new gss_OID_desc[count + 1];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1506
    if (newcopy == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1507
        return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1508
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1509
    if (existing) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1510
        memcpy_s(newcopy, (count + 1) * sizeof(gss_OID_desc),
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1511
                existing, count * sizeof(gss_OID_desc));
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1512
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1513
    newcopy[count].length = member_oid->length;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1514
    newcopy[count].elements = new char[member_oid->length];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1515
    if (newcopy[count].elements == NULL) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1516
        delete[] newcopy;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1517
        return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1518
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1519
    memcpy_s(newcopy[count].elements, member_oid->length,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1520
            member_oid->elements, member_oid->length);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1521
    (*oid_set)->elements = newcopy;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1522
    (*oid_set)->count++;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1523
    if (existing) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1524
        delete[] existing;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1525
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1526
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1527
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1528
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1529
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1530
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1531
gss_display_status(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1532
                   OM_uint32 status_value,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1533
                   int status_type,
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1534
                   gss_const_OID mech_type,
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1535
                   OM_uint32 *message_context,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1536
                   gss_buffer_t status_string)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1537
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1538
    PP(">>>> Calling gss_display_status...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1539
    TCHAR msg[256];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1540
    int len = FormatMessage(
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1541
            FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1542
            0, status_value,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1543
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1544
            msg, 256, 0);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1545
    if (len > 0) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1546
        status_string->value = new char[len + 20];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1547
        status_string->length = sprintf_s(
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1548
                (LPSTR)status_string->value, len + 19,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1549
                "(%lx) %ls", status_value, msg);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1550
    } else {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1551
        status_string->value = new char[33];
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1552
        status_string->length = sprintf_s(
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1553
                (LPSTR)status_string->value, 32,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1554
                "status is %lx", status_value);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1555
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1556
    if (status_string->length <= 0) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1557
        gss_release_buffer(NULL, status_string);
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1558
        status_string = GSS_C_NO_BUFFER;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1559
        return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1560
    } else {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1561
        return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1562
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1563
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1564
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1565
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1566
gss_create_empty_oid_set(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1567
                         gss_OID_set *oid_set)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1568
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1569
    PP(">>>> Calling gss_create_empty_oid_set...");
55638
430a51e86f28 8225687: Newly added sspi.cpp in JDK-6722928 still contains some small errors
weijun
parents: 55354
diff changeset
  1570
    CHECK_OUTPUT(oid_set)
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1571
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1572
    if (*oid_set = new gss_OID_set_desc) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1573
        memset(*oid_set, 0, sizeof(gss_OID_set_desc));
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1574
        return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1575
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1576
    return GSS_S_FAILURE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1577
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1578
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1579
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1580
gss_release_oid_set(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1581
                    gss_OID_set *set)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1582
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1583
    PP(">>>> Calling gss_release_oid_set...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1584
    if (set == NULL || *set == GSS_C_NO_OID_SET) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1585
        return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1586
    }
58140
a6f653312b19 8230910: libsspi_bridge does not build on Windows 32bit
stuefe
parents: 55638
diff changeset
  1587
    for (size_t i = 0; i < (*set)->count; i++) {
55354
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1588
        delete[] (*set)->elements[i].elements;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1589
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1590
    delete[] (*set)->elements;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1591
    delete *set;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1592
    *set = GSS_C_NO_OID_SET;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1593
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1594
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1595
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1596
__declspec(dllexport) OM_uint32
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1597
gss_release_buffer(OM_uint32 *minor_status,
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1598
                   gss_buffer_t buffer)
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1599
{
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1600
    PP(">>>> Calling gss_release_buffer...");
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1601
    if (buffer == NULL || buffer == GSS_C_NO_BUFFER) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1602
        return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1603
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1604
    if (buffer->value) {
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1605
        delete[] buffer->value;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1606
        buffer->value = NULL;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1607
    }
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1608
    buffer->length = 0;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1609
    return GSS_S_COMPLETE;
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1610
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1611
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1612
/* End implemented section */
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1613
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1614
#ifdef __cplusplus
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1615
}
74f0622db875 6722928: Support SSPI as a native GSS-API provider
weijun
parents:
diff changeset
  1616
#endif