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