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