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