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