src/java.security.jgss/windows/native/libw2k_lsa_auth/NativeCreds.c
author weijun
Wed, 25 Sep 2019 17:54:21 +0800
changeset 58331 e4ce29f6094e
parent 57487 643978a35f6e
child 58679 9c3209ff7550
permissions -rw-r--r--
8228659: Record which Java methods are called by native codes in JGSS and JAAS Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 53326
diff changeset
     2
 * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2591
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2591
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2591
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2591
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2591
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * ===========================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 2000 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * ===========================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#define UNICODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#define _UNICODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <windows.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#define SECURITY_WIN32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <security.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <ntsecapi.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <dsgetdc.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include <lmcons.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include <lmapibuf.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include <jni.h>
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 30322
diff changeset
    45
#include "jni_util.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include <winsock.h>
50471
f0aeede1b855 8204572: SetupJdkLibrary should setup SRC and -I flags automatically
ihse
parents: 47216
diff changeset
    47
#include "sun_security_krb5_Credentials.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#undef LSA_SUCCESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#define LSA_SUCCESS(Status) ((Status) >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#define EXIT_FAILURE -1 // mdu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * Library-wide static references
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
jclass ticketClass = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
jclass principalNameClass = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
jclass encryptionKeyClass = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
jclass ticketFlagsClass = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
jclass kerberosTimeClass = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
jclass javaLangStringClass = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
jmethodID ticketConstructor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
jmethodID principalNameConstructor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
jmethodID encryptionKeyConstructor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
jmethodID ticketFlagsConstructor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
jmethodID kerberosTimeConstructor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
jmethodID krbcredsConstructor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Function prototypes for internal routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 */
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
    75
BOOL native_debug = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
BOOL PackageConnectLookup(PHANDLE,PULONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
53326
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
    79
NTSTATUS ConstructTicketRequest(JNIEnv *env,
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
    80
                                UNICODE_STRING DomainName,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                PKERB_RETRIEVE_TKT_REQUEST *outRequest,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                ULONG *outSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
DWORD ConcatenateUnicodeStrings(UNICODE_STRING *pTarget,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                                UNICODE_STRING Source1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                UNICODE_STRING Source2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
VOID ShowNTError(LPSTR,NTSTATUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
VOID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
InitUnicodeString(
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    92
    PUNICODE_STRING DestinationString,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    PCWSTR SourceString OPTIONAL
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    94
);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
jobject BuildTicket(JNIEnv *env, PUCHAR encodedTicket, ULONG encodedTicketSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
//mdu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
jobject BuildPrincipal(JNIEnv *env, PKERB_EXTERNAL_NAME principalName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                UNICODE_STRING domainName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
jobject BuildEncryptionKey(JNIEnv *env, PKERB_CRYPTO_KEY cryptoKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
jobject BuildTicketFlags(JNIEnv *env, PULONG flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
jobject BuildKerberosTime(JNIEnv *env, PLARGE_INTEGER kerbtime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
53326
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   106
void ThrowOOME(JNIEnv *env, const char *szMessage);
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   107
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * Class:     sun_security_krb5_KrbCreds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * Method:    JNI_OnLoad
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 30322
diff changeset
   113
JNIEXPORT jint JNICALL DEF_JNI_OnLoad(
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   114
        JavaVM  *jvm,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   115
        void    *reserved) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   117
    jclass cls;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   118
    JNIEnv *env;
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   119
    jfieldID fldDEBUG;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   121
    if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   122
        return JNI_EVERSION; /* JNI version not supported */
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   123
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   125
    cls = (*env)->FindClass(env,"sun/security/krb5/internal/Krb5");
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   126
    if (cls == NULL) {
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   127
        printf("LSA: Couldn't find Krb5\n");
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   128
        return JNI_ERR;
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   129
    }
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   130
    fldDEBUG = (*env)->GetStaticFieldID(env, cls, "DEBUG", "Z");
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   131
    if (fldDEBUG == NULL) {
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   132
        printf("LSA: Krb5 has no DEBUG field\n");
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   133
        return JNI_ERR;
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   134
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   135
    native_debug = (*env)->GetStaticBooleanField(env, cls, fldDEBUG);
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   136
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   137
    cls = (*env)->FindClass(env,"sun/security/krb5/internal/Ticket");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   139
    if (cls == NULL) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   140
        printf("LSA: Couldn't find Ticket\n");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   141
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   142
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   143
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   144
        printf("LSA: Found Ticket\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   145
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   147
    ticketClass = (*env)->NewWeakGlobalRef(env,cls);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   148
    if (ticketClass == NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   149
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   150
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   151
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   152
        printf("LSA: Made NewWeakGlobalRef\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   153
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   155
    cls = (*env)->FindClass(env, "sun/security/krb5/PrincipalName");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   157
    if (cls == NULL) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   158
        printf("LSA: Couldn't find PrincipalName\n");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   159
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   160
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   161
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   162
        printf("LSA: Found PrincipalName\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   163
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   165
    principalNameClass = (*env)->NewWeakGlobalRef(env,cls);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   166
    if (principalNameClass == NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   167
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   168
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   169
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   170
        printf("LSA: Made NewWeakGlobalRef\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   171
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   173
    cls = (*env)->FindClass(env,"sun/security/krb5/EncryptionKey");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   175
    if (cls == NULL) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   176
        printf("LSA: Couldn't find EncryptionKey\n");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   177
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   178
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   179
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   180
        printf("LSA: Found EncryptionKey\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   181
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   183
    encryptionKeyClass = (*env)->NewWeakGlobalRef(env,cls);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   184
    if (encryptionKeyClass == NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   185
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   186
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   187
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   188
        printf("LSA: Made NewWeakGlobalRef\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   189
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   191
    cls = (*env)->FindClass(env,"sun/security/krb5/internal/TicketFlags");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   193
    if (cls == NULL) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   194
        printf("LSA: Couldn't find TicketFlags\n");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   195
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   196
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   197
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   198
        printf("LSA: Found TicketFlags\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   199
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   201
    ticketFlagsClass = (*env)->NewWeakGlobalRef(env,cls);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   202
    if (ticketFlagsClass == NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   203
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   204
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   205
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   206
        printf("LSA: Made NewWeakGlobalRef\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   207
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   209
    cls = (*env)->FindClass(env,"sun/security/krb5/internal/KerberosTime");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   211
    if (cls == NULL) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   212
        printf("LSA: Couldn't find KerberosTime\n");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   213
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   214
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   215
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   216
        printf("LSA: Found KerberosTime\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   217
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   219
    kerberosTimeClass = (*env)->NewWeakGlobalRef(env,cls);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   220
    if (kerberosTimeClass == NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   221
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   222
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   223
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   224
        printf("LSA: Made NewWeakGlobalRef\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   225
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   227
    cls = (*env)->FindClass(env,"java/lang/String");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   229
    if (cls == NULL) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   230
        printf("LSA: Couldn't find String\n");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   231
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   232
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   233
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   234
        printf("LSA: Found String\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   235
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   237
    javaLangStringClass = (*env)->NewWeakGlobalRef(env,cls);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   238
    if (javaLangStringClass == NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   239
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   240
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   241
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   242
        printf("LSA: Made NewWeakGlobalRef\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   243
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   245
    ticketConstructor = (*env)->GetMethodID(env, ticketClass,
58331
e4ce29f6094e 8228659: Record which Java methods are called by native codes in JGSS and JAAS
weijun
parents: 57487
diff changeset
   246
                            "<init>", "([B)V");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   247
    if (ticketConstructor == 0) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   248
        printf("LSA: Couldn't find Ticket constructor\n");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   249
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   250
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   251
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   252
        printf("LSA: Found Ticket constructor\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   253
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   255
    principalNameConstructor = (*env)->GetMethodID(env, principalNameClass,
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 8781
diff changeset
   256
                        "<init>", "([Ljava/lang/String;Ljava/lang/String;)V");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   257
    if (principalNameConstructor == 0) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   258
        printf("LSA: Couldn't find PrincipalName constructor\n");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   259
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   260
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   261
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   262
        printf("LSA: Found PrincipalName constructor\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   263
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   265
    encryptionKeyConstructor = (*env)->GetMethodID(env, encryptionKeyClass,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   266
                                            "<init>", "(I[B)V");
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   267
    if (encryptionKeyConstructor == 0) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   268
        printf("LSA: Couldn't find EncryptionKey constructor\n");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   269
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   270
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   271
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   272
        printf("LSA: Found EncryptionKey constructor\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   273
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   275
    ticketFlagsConstructor = (*env)->GetMethodID(env, ticketFlagsClass,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   276
                                            "<init>", "(I[B)V");
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   277
    if (ticketFlagsConstructor == 0) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   278
        printf("LSA: Couldn't find TicketFlags constructor\n");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   279
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   280
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   281
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   282
        printf("LSA: Found TicketFlags constructor\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   283
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   285
    kerberosTimeConstructor = (*env)->GetMethodID(env, kerberosTimeClass,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   286
                                    "<init>", "(Ljava/lang/String;)V");
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   287
    if (kerberosTimeConstructor == 0) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   288
        printf("LSA: Couldn't find KerberosTime constructor\n");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   289
        return JNI_ERR;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   290
    }
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   291
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   292
        printf("LSA: Found KerberosTime constructor\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   293
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   295
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   296
        printf("LSA: Finished OnLoad processing\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   297
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   299
    return JNI_VERSION_1_2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 * Class:     sun_security_jgss_KrbCreds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 * Method:    JNI_OnUnload
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 30322
diff changeset
   307
JNIEXPORT void JNICALL DEF_JNI_OnUnload(
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   308
        JavaVM  *jvm,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   309
        void    *reserved) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   311
    JNIEnv *env;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   313
    if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   314
        return; /* Nothing else we can do */
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   315
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   317
    if (ticketClass != NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   318
        (*env)->DeleteWeakGlobalRef(env,ticketClass);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   319
    }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   320
    if (principalNameClass != NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   321
        (*env)->DeleteWeakGlobalRef(env,principalNameClass);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   322
    }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   323
    if (encryptionKeyClass != NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   324
        (*env)->DeleteWeakGlobalRef(env,encryptionKeyClass);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   325
    }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   326
    if (ticketFlagsClass != NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   327
        (*env)->DeleteWeakGlobalRef(env,ticketFlagsClass);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   328
    }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   329
    if (kerberosTimeClass != NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   330
        (*env)->DeleteWeakGlobalRef(env,kerberosTimeClass);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   331
    }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   332
    if (javaLangStringClass != NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   333
        (*env)->DeleteWeakGlobalRef(env,javaLangStringClass);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   334
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   336
    return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
 * Class:     sun_security_krb5_Credentials
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
 * Method:    acquireDefaultNativeCreds
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   342
 * Signature: ([I])Lsun/security/krb5/Credentials;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
JNIEXPORT jobject JNICALL Java_sun_security_krb5_Credentials_acquireDefaultNativeCreds(
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   345
        JNIEnv *env,
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   346
        jclass krbcredsClass,
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   347
        jintArray jetypes) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   349
    KERB_QUERY_TKT_CACHE_REQUEST CacheRequest;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   350
    PKERB_RETRIEVE_TKT_RESPONSE TktCacheResponse = NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   351
    PKERB_RETRIEVE_TKT_REQUEST pTicketRequest = NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   352
    PKERB_RETRIEVE_TKT_RESPONSE pTicketResponse = NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   353
    NTSTATUS Status, SubStatus;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   354
    ULONG requestSize = 0;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   355
    ULONG responseSize = 0;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   356
    ULONG rspSize = 0;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   357
    HANDLE LogonHandle = NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   358
    ULONG PackageId;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   359
    jobject ticket, clientPrincipal, targetPrincipal, encryptionKey;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   360
    jobject ticketFlags, startTime, endTime, krbCreds = NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   361
    jobject authTime, renewTillTime, hostAddresses = NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   362
    KERB_EXTERNAL_TICKET *msticket;
22269
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   363
    int found = 0;
30322
c08d5c975168 8078495: End time checking for native TGT is wrong
weijun
parents: 25859
diff changeset
   364
    FILETIME Now, EndTime;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   366
    int i, netypes;
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   367
    jint *etypes = NULL;
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   368
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   369
    while (TRUE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if (krbcredsConstructor == 0) {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   372
            krbcredsConstructor = (*env)->GetMethodID(env, krbcredsClass, "<init>",
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   373
                    "(Lsun/security/krb5/internal/Ticket;"
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   374
                    "Lsun/security/krb5/PrincipalName;"
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   375
                    "Lsun/security/krb5/PrincipalName;"
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 53326
diff changeset
   376
                    "Lsun/security/krb5/PrincipalName;"
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 53326
diff changeset
   377
                    "Lsun/security/krb5/PrincipalName;"
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   378
                    "Lsun/security/krb5/EncryptionKey;"
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   379
                    "Lsun/security/krb5/internal/TicketFlags;"
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   380
                    "Lsun/security/krb5/internal/KerberosTime;"
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   381
                    "Lsun/security/krb5/internal/KerberosTime;"
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   382
                    "Lsun/security/krb5/internal/KerberosTime;"
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   383
                    "Lsun/security/krb5/internal/KerberosTime;"
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   384
                    "Lsun/security/krb5/internal/HostAddresses;)V");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            if (krbcredsConstructor == 0) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   386
                printf("LSA: Couldn't find sun.security.krb5.Credentials constructor\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   391
        if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   392
            printf("LSA: Found KrbCreds constructor\n");
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   393
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        // Get the logon handle and package ID from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        // Kerberos package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if (!PackageConnectLookup(&LogonHandle, &PackageId))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   402
        if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   403
            printf("LSA: Got handle to Kerberos package\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   404
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        // Get the MS TGT from cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        CacheRequest.MessageType = KerbRetrieveTicketMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        CacheRequest.LogonId.LowPart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        CacheRequest.LogonId.HighPart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        Status = LsaCallAuthenticationPackage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                        LogonHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                        PackageId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                        &CacheRequest,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                        sizeof(CacheRequest),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                        &TktCacheResponse,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                        &rspSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                        &SubStatus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   421
        if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   422
            printf("LSA: Response size is %d\n", rspSize);
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   423
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        if (!LSA_SUCCESS(Status) || !LSA_SUCCESS(SubStatus)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            if (!LSA_SUCCESS(Status)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                ShowNTError("LsaCallAuthenticationPackage", Status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                ShowNTError("Protocol status", SubStatus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        // got the native MS TGT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        msticket = &(TktCacheResponse->Ticket);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   437
        netypes = (*env)->GetArrayLength(env, jetypes);
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   438
        etypes = (jint *) (*env)->GetIntArrayElements(env, jetypes, NULL);
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   439
23030
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   440
        if (etypes == NULL) {
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   441
            break;
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   442
        }
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   443
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        // check TGT validity
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   445
        if (native_debug) {
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   446
            printf("LSA: TICKET SessionKey KeyType is %d\n", msticket->SessionKey.KeyType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   449
        if ((msticket->TicketFlags & KERB_TICKET_FLAGS_invalid) == 0) {
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   450
            GetSystemTimeAsFileTime(&Now);
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   451
            EndTime.dwLowDateTime = msticket->EndTime.LowPart;
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   452
            EndTime.dwHighDateTime = msticket->EndTime.HighPart;
30322
c08d5c975168 8078495: End time checking for native TGT is wrong
weijun
parents: 25859
diff changeset
   453
            if (CompareFileTime(&Now, &EndTime) < 0) {
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   454
                for (i=0; i<netypes; i++) {
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   455
                    if (etypes[i] == msticket->SessionKey.KeyType) {
22269
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   456
                        found = 1;
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   457
                        if (native_debug) {
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   458
                            printf("LSA: Valid etype found: %d\n", etypes[i]);
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   459
                        }
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   460
                        break;
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   461
                    }
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   462
                }
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   463
            }
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   464
        }
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   465
22269
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   466
        if (!found) {
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   467
            if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   468
                printf("LSA: MS TGT in cache is invalid/not supported; request new ticket\n");
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   469
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            // use domain to request Ticket
53326
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   472
            Status = ConstructTicketRequest(env, msticket->TargetDomainName,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                                &pTicketRequest, &requestSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            if (!LSA_SUCCESS(Status)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                ShowNTError("ConstructTicketRequest status", Status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            pTicketRequest->MessageType = KerbRetrieveEncodedTicketMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            pTicketRequest->CacheOptions = KERB_RETRIEVE_TICKET_DONT_USE_CACHE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   482
            for (i=0; i<netypes; i++) {
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   483
                pTicketRequest->EncryptionType = etypes[i];
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   484
                Status = LsaCallAuthenticationPackage(
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   485
                            LogonHandle,
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   486
                            PackageId,
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   487
                            pTicketRequest,
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   488
                            requestSize,
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   489
                            &pTicketResponse,
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   490
                            &responseSize,
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   491
                            &SubStatus
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   492
                            );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   494
                if (native_debug) {
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   495
                    printf("LSA: Response size is %d for %d\n", responseSize, etypes[i]);
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   496
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   498
                if (!LSA_SUCCESS(Status) || !LSA_SUCCESS(SubStatus)) {
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   499
                    if (!LSA_SUCCESS(Status)) {
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   500
                        ShowNTError("LsaCallAuthenticationPackage", Status);
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   501
                    } else {
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   502
                        ShowNTError("Protocol status", SubStatus);
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   503
                    }
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   504
                    continue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                }
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   506
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   507
                // got the native MS Kerberos TGT
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   508
                msticket = &(pTicketResponse->Ticket);
22269
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   509
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   510
                if (msticket->SessionKey.KeyType != etypes[i]) {
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   511
                    if (native_debug) {
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   512
                        printf("LSA: Response etype is %d for %d. Retry.\n", msticket->SessionKey.KeyType, etypes[i]);
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   513
                    }
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   514
                    continue;
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   515
                }
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   516
                found = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   519
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   521
        if (etypes != NULL) {
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   522
            (*env)->ReleaseIntArrayElements(env, jetypes, etypes, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   525
        /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   527
        typedef struct _KERB_RETRIEVE_TKT_RESPONSE {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   528
            KERB_EXTERNAL_TICKET Ticket;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   529
        } KERB_RETRIEVE_TKT_RESPONSE, *PKERB_RETRIEVE_TKT_RESPONSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   531
        typedef struct _KERB_EXTERNAL_TICKET {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   532
            PKERB_EXTERNAL_NAME ServiceName;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   533
            PKERB_EXTERNAL_NAME TargetName;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   534
            PKERB_EXTERNAL_NAME ClientName;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   535
            UNICODE_STRING DomainName;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   536
            UNICODE_STRING TargetDomainName;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   537
            UNICODE_STRING AltTargetDomainName;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   538
            KERB_CRYPTO_KEY SessionKey;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   539
            ULONG TicketFlags;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   540
            ULONG Flags;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   541
            LARGE_INTEGER KeyExpirationTime;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   542
            LARGE_INTEGER StartTime;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   543
            LARGE_INTEGER EndTime;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   544
            LARGE_INTEGER RenewUntil;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   545
            LARGE_INTEGER TimeSkew;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   546
            ULONG EncodedTicketSize;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   547
            PUCHAR EncodedTicket; <========== Here's the good stuff
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   548
        } KERB_EXTERNAL_TICKET, *PKERB_EXTERNAL_TICKET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   550
        typedef struct _KERB_EXTERNAL_NAME {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   551
            SHORT NameType;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   552
            USHORT NameCount;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   553
            UNICODE_STRING Names[ANYSIZE_ARRAY];
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   554
        } KERB_EXTERNAL_NAME, *PKERB_EXTERNAL_NAME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   556
        typedef struct _LSA_UNICODE_STRING {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   557
            USHORT Length;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   558
            USHORT MaximumLength;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   559
            PWSTR  Buffer;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   560
        } LSA_UNICODE_STRING, *PLSA_UNICODE_STRING;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   562
        typedef LSA_UNICODE_STRING UNICODE_STRING, *PUNICODE_STRING;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   564
        typedef struct KERB_CRYPTO_KEY {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   565
            LONG KeyType;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   566
            ULONG Length;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   567
            PUCHAR Value;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   568
        } KERB_CRYPTO_KEY, *PKERB_CRYPTO_KEY;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   570
        */
22269
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   571
        if (!found) {
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   572
            break;
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   573
        }
852e4737460a 8031046: Native Windows ccache might still get unsupported ticket
weijun
parents: 21278
diff changeset
   574
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        // Build a com.sun.security.krb5.Ticket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        ticket = BuildTicket(env, msticket->EncodedTicket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                msticket->EncodedTicketSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        if (ticket == NULL) {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   579
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        // OK, have a Ticket, now need to get the client name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        clientPrincipal = BuildPrincipal(env, msticket->ClientName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                msticket->TargetDomainName); // mdu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        if (clientPrincipal == NULL) {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   585
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        // and the "name" of tgt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        targetPrincipal = BuildPrincipal(env, msticket->ServiceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                        msticket->DomainName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        if (targetPrincipal == NULL) {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   592
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        // Get the encryption key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        encryptionKey = BuildEncryptionKey(env, &(msticket->SessionKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        if (encryptionKey == NULL) {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   598
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        // and the ticket flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        ticketFlags = BuildTicketFlags(env, &(msticket->TicketFlags));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        if (ticketFlags == NULL) {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   604
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        // Get the start time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        startTime = BuildKerberosTime(env, &(msticket->StartTime));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (startTime == NULL) {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   610
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
         * mdu: No point storing the eky expiration time in the auth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
         * time field. Set it to be same as startTime. Looks like
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
         * windows does not have post-dated tickets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        authTime = startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        // and the end time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        endTime = BuildKerberosTime(env, &(msticket->EndTime));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        if (endTime == NULL) {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   623
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        // Get the renew till time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        renewTillTime = BuildKerberosTime(env, &(msticket->RenewUntil));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        if (renewTillTime == NULL) {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   629
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        // and now go build a KrbCreds object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        krbCreds = (*env)->NewObject(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                krbcredsClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                krbcredsConstructor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                clientPrincipal,
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 53326
diff changeset
   639
                NULL,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                targetPrincipal,
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 53326
diff changeset
   641
                NULL,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                encryptionKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                ticketFlags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                authTime, // mdu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                startTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                endTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                renewTillTime, //mdu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                hostAddresses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        break;
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14342
diff changeset
   651
    } // end of WHILE. This WHILE will never loop.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   653
    // clean up resources
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   654
    if (TktCacheResponse != NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   655
        LsaFreeReturnBuffer(TktCacheResponse);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   656
    }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   657
    if (pTicketRequest) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   658
        LocalFree(pTicketRequest);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   659
    }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   660
    if (pTicketResponse != NULL) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   661
        LsaFreeReturnBuffer(pTicketResponse);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   662
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   664
    return krbCreds;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
static NTSTATUS
53326
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   668
ConstructTicketRequest(JNIEnv *env, UNICODE_STRING DomainName,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                PKERB_RETRIEVE_TKT_REQUEST *outRequest, ULONG *outSize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
{
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   671
    NTSTATUS Status;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   672
    UNICODE_STRING TargetPrefix;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   673
    USHORT TargetSize;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   674
    ULONG RequestSize;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   675
    ULONG Length;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   676
    PKERB_RETRIEVE_TKT_REQUEST pTicketRequest = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   678
    *outRequest = NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   679
    *outSize = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   681
    //
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   682
    // Set up the "krbtgt/" target prefix into a UNICODE_STRING so we
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   683
    // can easily concatenate it later.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   684
    //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   686
    TargetPrefix.Buffer = L"krbtgt/";
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   687
    Length = (ULONG)wcslen(TargetPrefix.Buffer) * sizeof(WCHAR);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   688
    TargetPrefix.Length = (USHORT)Length;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   689
    TargetPrefix.MaximumLength = TargetPrefix.Length;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   691
    //
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   692
    // We will need to concatenate the "krbtgt/" prefix and the
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   693
    // Logon Session's DnsDomainName into our request's target name.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   694
    //
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   695
    // Therefore, first compute the necessary buffer size for that.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   696
    //
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   697
    // Note that we might theoretically have integer overflow.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   698
    //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   700
    TargetSize = TargetPrefix.Length + DomainName.Length;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   702
    //
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   703
    // The ticket request buffer needs to be a single buffer.  That buffer
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   704
    // needs to include the buffer for the target name.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   705
    //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   707
    RequestSize = sizeof (*pTicketRequest) + TargetSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   709
    //
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   710
    // Allocate the request buffer and make sure it's zero-filled.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   711
    //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   713
    pTicketRequest = (PKERB_RETRIEVE_TKT_REQUEST)
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   714
                    LocalAlloc(LMEM_ZEROINIT, RequestSize);
53326
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   715
    if (!pTicketRequest) {
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   716
        ThrowOOME(env, "Can't allocate memory for ticket");
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   717
        return GetLastError();
53326
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   718
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   720
    //
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19373
diff changeset
   721
    // Concatenate the target prefix with the previous response's
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   722
    // target domain.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   723
    //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   725
    pTicketRequest->TargetName.Length = 0;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   726
    pTicketRequest->TargetName.MaximumLength = TargetSize;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   727
    pTicketRequest->TargetName.Buffer = (PWSTR) (pTicketRequest + 1);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   728
    Status = ConcatenateUnicodeStrings(&(pTicketRequest->TargetName),
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   729
                                    TargetPrefix,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   730
                                    DomainName);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   731
    *outRequest = pTicketRequest;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   732
    *outSize    = RequestSize;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   733
    return Status;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
DWORD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
ConcatenateUnicodeStrings(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    UNICODE_STRING *pTarget,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    UNICODE_STRING Source1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    UNICODE_STRING Source2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
{
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   743
    //
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   744
    // The buffers for Source1 and Source2 cannot overlap pTarget's
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   745
    // buffer.  Source1.Length + Source2.Length must be <= 0xFFFF,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   746
    // otherwise we overflow...
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   747
    //
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   749
    USHORT TotalSize = Source1.Length + Source2.Length;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   750
    PBYTE buffer = (PBYTE) pTarget->Buffer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   752
    if (TotalSize > pTarget->MaximumLength)
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   753
        return ERROR_INSUFFICIENT_BUFFER;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   755
    pTarget->Length = TotalSize;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   756
    memcpy(buffer, Source1.Buffer, Source1.Length);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   757
    memcpy(buffer + Source1.Length, Source2.Buffer, Source2.Length);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   758
    return ERROR_SUCCESS;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
BOOL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
PackageConnectLookup(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    HANDLE *pLogonHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    ULONG *pPackageId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    LSA_STRING Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    NTSTATUS Status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    Status = LsaConnectUntrusted(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                pLogonHandle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    if (!LSA_SUCCESS(Status))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        ShowNTError("LsaConnectUntrusted", Status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    Name.Buffer = MICROSOFT_KERBEROS_NAME_A;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    Name.Length = (USHORT)strlen(Name.Buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    Name.MaximumLength = Name.Length + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    Status = LsaLookupAuthenticationPackage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                *pLogonHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                &Name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                pPackageId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    if (!LSA_SUCCESS(Status))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        ShowNTError("LsaLookupAuthenticationPackage", Status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
VOID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
ShowLastError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        LPSTR szAPI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        DWORD dwError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
{
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   806
    #define MAX_MSG_SIZE 256
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   808
    static WCHAR szMsgBuf[MAX_MSG_SIZE];
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   809
    DWORD dwRes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   811
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   812
        printf("LSA: Error calling function %s: %lu\n", szAPI, dwError);
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   813
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   815
    dwRes = FormatMessage (
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   816
            FORMAT_MESSAGE_FROM_SYSTEM,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   817
            NULL,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   818
            dwError,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   819
            0,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   820
            szMsgBuf,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   821
            MAX_MSG_SIZE,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   822
            NULL);
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   823
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   824
        if (0 == dwRes) {
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   825
            printf("LSA: FormatMessage failed with %d\n", GetLastError());
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   826
            // ExitProcess(EXIT_FAILURE);
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   827
        } else {
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   828
            printf("LSA: %S",szMsgBuf);
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   829
        }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   830
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
VOID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
ShowNTError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        LPSTR szAPI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        NTSTATUS Status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    // Convert the NTSTATUS to Winerror. Then call ShowLastError().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    ShowLastError(szAPI, LsaNtStatusToWinError(Status));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
VOID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
InitUnicodeString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        PUNICODE_STRING DestinationString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    PCWSTR SourceString OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    ULONG Length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    DestinationString->Buffer = (PWSTR)SourceString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    if (SourceString != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        Length = (ULONG)wcslen( SourceString ) * sizeof( WCHAR );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        DestinationString->Length = (USHORT)Length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        DestinationString->MaximumLength = (USHORT)(Length + sizeof(UNICODE_NULL));
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   858
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        DestinationString->MaximumLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        DestinationString->Length = 0;
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   862
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
jobject BuildTicket(JNIEnv *env, PUCHAR encodedTicket, ULONG encodedTicketSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
58331
e4ce29f6094e 8228659: Record which Java methods are called by native codes in JGSS and JAAS
weijun
parents: 57487
diff changeset
   867
    // To build a Ticket, we need to make a byte array out of the EncodedTicket.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
58331
e4ce29f6094e 8228659: Record which Java methods are called by native codes in JGSS and JAAS
weijun
parents: 57487
diff changeset
   869
    jobject ticket;
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   870
    jbyteArray ary;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   872
    ary = (*env)->NewByteArray(env,encodedTicketSize);
53326
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   873
    if (ary == NULL) {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   874
        return (jobject) NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   875
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   877
    (*env)->SetByteArrayRegion(env, ary, (jsize) 0, encodedTicketSize,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   878
                                    (jbyte *)encodedTicket);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   879
    if ((*env)->ExceptionOccurred(env)) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   880
        (*env)->DeleteLocalRef(env, ary);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   881
        return (jobject) NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   882
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
58331
e4ce29f6094e 8228659: Record which Java methods are called by native codes in JGSS and JAAS
weijun
parents: 57487
diff changeset
   884
    ticket = (*env)->NewObject(env, ticketClass, ticketConstructor, ary);
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   885
    if ((*env)->ExceptionOccurred(env)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        (*env)->DeleteLocalRef(env, ary);
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   887
        return (jobject) NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   888
    }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   889
    (*env)->DeleteLocalRef(env, ary);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   890
    return ticket;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
// mdu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
jobject BuildPrincipal(JNIEnv *env, PKERB_EXTERNAL_NAME principalName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                                UNICODE_STRING domainName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   897
    /*
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   898
     * To build the Principal, we need to get the names out of
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   899
     * this goofy MS structure
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   900
     */
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   901
    jobject principal = NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   902
    jobject realmStr = NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   903
    jobjectArray stringArray;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   904
    jstring tempString;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   905
    int nameCount,i;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   906
    PUNICODE_STRING scanner;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   907
    WCHAR *realm;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   908
    ULONG realmLen;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   910
    realm = (WCHAR *) LocalAlloc(LMEM_ZEROINIT,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   911
            ((domainName.Length)*sizeof(WCHAR) + sizeof(UNICODE_NULL)));
53326
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   912
    if (realm == NULL) {
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   913
        ThrowOOME(env, "Can't allocate memory for realm");
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   914
        return NULL;
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   915
    }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   916
    wcsncpy(realm, domainName.Buffer, domainName.Length/sizeof(WCHAR));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   918
    if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   919
        printf("LSA: Principal domain is %S\n", realm);
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   920
        printf("LSA: Name type is %x\n", principalName->NameType);
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   921
        printf("LSA: Name count is %x\n", principalName->NameCount);
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   922
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   924
    nameCount = principalName->NameCount;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   925
    stringArray = (*env)->NewObjectArray(env, nameCount,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   926
                            javaLangStringClass, NULL);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   927
    if (stringArray == NULL) {
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   928
        if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   929
            printf("LSA: Can't allocate String array for Principal\n");
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   930
        }
23030
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   931
        goto cleanup;
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   932
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   934
    for (i=0; i<nameCount; i++) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   935
        // get the principal name
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   936
        scanner = &(principalName->Names[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   938
        // OK, got a Char array, so construct a String
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   939
        tempString = (*env)->NewString(env, (const jchar*)scanner->Buffer,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   940
                            scanner->Length/sizeof(WCHAR));
23030
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   941
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   942
        if (tempString == NULL) {
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   943
            goto cleanup;
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   944
        }
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   945
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   946
        // Set the String into the StringArray
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   947
        (*env)->SetObjectArrayElement(env, stringArray, i, tempString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
23030
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   949
        if ((*env)->ExceptionCheck(env)) {
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   950
            goto cleanup;
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   951
        }
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   952
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   953
        // Do I have to worry about storage reclamation here?
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   954
    }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   955
    // now set the realm in the principal
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   956
    realmLen = (ULONG)wcslen((PWCHAR)realm);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   957
    realmStr = (*env)->NewString(env, (PWCHAR)realm, (USHORT)realmLen);
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 8781
diff changeset
   958
23030
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   959
    if (realmStr == NULL) {
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   960
        goto cleanup;
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   961
    }
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   962
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 8781
diff changeset
   963
    principal = (*env)->NewObject(env, principalNameClass,
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 8781
diff changeset
   964
                    principalNameConstructor, stringArray, realmStr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
23030
51178fbafe9c 8035759: [parfait] JNI exception pending in jdk/src/windows/native/sun/security/krb5/NativeCreds.c
weijun
parents: 23010
diff changeset
   966
cleanup:
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   967
    // free local resources
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   968
    LocalFree(realm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   970
    return principal;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
jobject BuildEncryptionKey(JNIEnv *env, PKERB_CRYPTO_KEY cryptoKey) {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   974
    // First, need to build a byte array
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   975
    jbyteArray ary;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   976
    jobject encryptionKey = NULL;
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   977
    unsigned int i;
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   978
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   979
    for (i=0; i<cryptoKey->Length; i++) {
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   980
        if (cryptoKey->Value[i]) break;
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   981
    }
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   982
    if (i == cryptoKey->Length) {
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
   983
        if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   984
            printf("LSA: Session key all zero. Stop.\n");
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   985
        }
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   986
        return NULL;
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
   987
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   989
    ary = (*env)->NewByteArray(env,cryptoKey->Length);
53326
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   990
    if (ary == NULL) {
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   991
        return (jobject) NULL;
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
   992
    }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   993
    (*env)->SetByteArrayRegion(env, ary, (jsize) 0, cryptoKey->Length,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   994
                                    (jbyte *)cryptoKey->Value);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   995
    if ((*env)->ExceptionOccurred(env)) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   996
        (*env)->DeleteLocalRef(env, ary);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   997
    } else {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   998
        encryptionKey = (*env)->NewObject(env, encryptionKeyClass,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   999
                encryptionKeyConstructor, cryptoKey->KeyType, ary);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1000
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1002
    return encryptionKey;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
jobject BuildTicketFlags(JNIEnv *env, PULONG flags) {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1006
    jobject ticketFlags = NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1007
    jbyteArray ary;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1008
    /*
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1009
     * mdu: Convert the bytes to nework byte order before copying
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1010
     * them to a Java byte array.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1011
     */
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1012
    ULONG nlflags = htonl(*flags);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1014
    ary = (*env)->NewByteArray(env, sizeof(*flags));
53326
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
  1015
    if (ary == NULL) {
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
  1016
        return (jobject) NULL;
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
  1017
    }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1018
    (*env)->SetByteArrayRegion(env, ary, (jsize) 0, sizeof(*flags),
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1019
                                    (jbyte *)&nlflags);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1020
    if ((*env)->ExceptionOccurred(env)) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1021
        (*env)->DeleteLocalRef(env, ary);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1022
    } else {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1023
        ticketFlags = (*env)->NewObject(env, ticketFlagsClass,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1024
                ticketFlagsConstructor, sizeof(*flags)*8, ary);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1025
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1027
    return ticketFlags;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
jobject BuildKerberosTime(JNIEnv *env, PLARGE_INTEGER kerbtime) {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1031
    jobject kerberosTime = NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1032
    jstring stringTime = NULL;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1033
    SYSTEMTIME systemTime;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1034
    WCHAR timeString[16];
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1035
    WCHAR month[3];
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1036
    WCHAR day[3];
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1037
    WCHAR hour[3];
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1038
    WCHAR minute[3];
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1039
    WCHAR second[3];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1041
    if (FileTimeToSystemTime((FILETIME *)kerbtime, &systemTime)) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1042
        // XXX Cannot use %02.2ld, because the leading 0 is ignored for integers.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1043
        // So, print them to strings, and then print them to the master string with a
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1044
        // format pattern that makes it two digits and prefix with a 0 if necessary.
8781
1ecbd60a9024 6990848: JGSS/windows security code native code compiler warnings
weijun
parents: 5506
diff changeset
  1045
        swprintf( (wchar_t *)month, 3, L"%2.2d", systemTime.wMonth);
1ecbd60a9024 6990848: JGSS/windows security code native code compiler warnings
weijun
parents: 5506
diff changeset
  1046
        swprintf( (wchar_t *)day, 3, L"%2.2d", systemTime.wDay);
1ecbd60a9024 6990848: JGSS/windows security code native code compiler warnings
weijun
parents: 5506
diff changeset
  1047
        swprintf( (wchar_t *)hour, 3, L"%2.2d", systemTime.wHour);
1ecbd60a9024 6990848: JGSS/windows security code native code compiler warnings
weijun
parents: 5506
diff changeset
  1048
        swprintf( (wchar_t *)minute, 3, L"%2.2d", systemTime.wMinute);
1ecbd60a9024 6990848: JGSS/windows security code native code compiler warnings
weijun
parents: 5506
diff changeset
  1049
        swprintf( (wchar_t *)second, 3, L"%2.2d", systemTime.wSecond);
1ecbd60a9024 6990848: JGSS/windows security code native code compiler warnings
weijun
parents: 5506
diff changeset
  1050
        swprintf( (wchar_t *)timeString, 16,
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1051
                L"%ld%02.2s%02.2s%02.2s%02.2s%02.2sZ",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                systemTime.wYear,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                month,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                day,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                hour,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                minute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                second );
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
  1058
        if (native_debug) {
2588
ec64fd74aa69 6587676: Krb5LoginModule failure if useTicketCache=true on Vista
weijun
parents: 715
diff changeset
  1059
            printf("LSA: %S\n", (wchar_t *)timeString);
2591
6ef824d6d5c2 6830658: Changeset ec64fd74aa69 breaks the fastdebug build in NativeCreds.c
weijun
parents: 2588
diff changeset
  1060
        }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1061
        stringTime = (*env)->NewString(env, timeString,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1062
                (sizeof(timeString)/sizeof(WCHAR))-1);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1063
        if (stringTime != NULL) { // everything's OK so far
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1064
            kerberosTime = (*env)->NewObject(env, kerberosTimeClass,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1065
                    kerberosTimeConstructor, stringTime);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1067
    }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
  1068
    return kerberosTime;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
}
53326
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
  1070
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
  1071
void ThrowOOME(JNIEnv *env, const char *szMessage) {
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
  1072
    jclass exceptionClazz = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
  1073
    if (exceptionClazz != NULL) {
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
  1074
        (*env)->ThrowNew(env, exceptionClazz, szMessage);
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
  1075
    }
0060e9d7c450 8210610: Improved LSA authentication
weijun
parents: 50471
diff changeset
  1076
}