43
44
45 /*
46 * OS calls loaded from DLL on intialization
47 */
48
49 static FREE_CREDENTIALS_HANDLE_FN pFreeCredentialsHandle;
50 static ACQUIRE_CREDENTIALS_HANDLE_FN pAcquireCredentialsHandle;
51 static FREE_CONTEXT_BUFFER_FN pFreeContextBuffer;
52 static INITIALIZE_SECURITY_CONTEXT_FN pInitializeSecurityContext;
53 static COMPLETE_AUTH_TOKEN_FN pCompleteAuthToken;
54 static DELETE_SECURITY_CONTEXT_FN pDeleteSecurityContext;
55
56 static void endSequence (PCredHandle credHand, PCtxtHandle ctxHandle);
57
58 static jfieldID ntlm_ctxHandleID;
59 static jfieldID ntlm_crdHandleID;
60
61 static HINSTANCE lib = NULL;
62
63 JNIEXPORT void JNICALL Java_sun_net_www_protocol_http_NTLMAuthSequence_initFirst
64 (JNIEnv *env, jclass clazz)
65 {
66 OSVERSIONINFO version;
67 UCHAR libName[MAX_PATH];
68
69 ntlm_ctxHandleID = (*env)->GetFieldID(env, clazz, "ctxHandle", "J");
70 ntlm_crdHandleID = (*env)->GetFieldID(env, clazz, "crdHandle", "J");
71
72 version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
73 GetVersionEx (&version);
74
75 if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) {
76 strcpy (libName, "security.dll" );
77 }
78 else if (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
79 strcpy (libName, "secur32.dll" );
80 }
81
82 lib = LoadLibrary (libName);
83
96 pInitializeSecurityContext
97 = (INITIALIZE_SECURITY_CONTEXT_FN) GetProcAddress(
98 lib, "InitializeSecurityContextA" );
99
100 pCompleteAuthToken
101 = (COMPLETE_AUTH_TOKEN_FN) GetProcAddress(
102 lib, "CompleteAuthToken" );
103
104 pDeleteSecurityContext
105 = (DELETE_SECURITY_CONTEXT_FN) GetProcAddress(
106 lib, "DeleteSecurityContext" );
107
108 }
109
110 /*
111 * Class: sun_net_www_protocol_http_NTLMAuthSequence
112 * Method: getCredentialsHandle
113 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J
114 */
115
116 JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_NTLMAuthSequence_getCredentialsHandle
117 (JNIEnv *env, jobject this, jstring user, jstring domain, jstring password)
118 {
119 SEC_WINNT_AUTH_IDENTITY AuthId;
120 SEC_WINNT_AUTH_IDENTITY * pAuthId;
121 const CHAR *pUser = 0;
122 const CHAR *pDomain = 0;
123 const CHAR *pPassword = 0;
124 CredHandle *pCred;
125 TimeStamp ltime;
126 jboolean isCopy;
127 SECURITY_STATUS ss;
128
129 if (user != 0) {
130 pUser = JNU_GetStringPlatformChars(env, user, &isCopy);
131 if (pUser == NULL)
132 return 0; // pending Exception
133 }
134 if (domain != 0) {
135 pDomain = JNU_GetStringPlatformChars(env, domain, &isCopy);
136 if (pDomain == NULL) {
180 NULL, "NTLM", SECPKG_CRED_OUTBOUND,
181 NULL, pAuthId, NULL, NULL,
182 pCred, <ime
183 );
184
185 /* Release resources held by JNU_GetStringPlatformChars */
186 if (pUser != NULL)
187 JNU_ReleaseStringPlatformChars(env, user, pUser);
188 if (pPassword != NULL)
189 JNU_ReleaseStringPlatformChars(env, password, pPassword);
190 if (pDomain != NULL)
191 JNU_ReleaseStringPlatformChars(env, domain, pDomain);
192
193 if (ss == 0) {
194 return (jlong) pCred;
195 } else {
196 return 0;
197 }
198 }
199
200 JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_NTLMAuthSequence_getNextToken
201 (JNIEnv *env, jobject this, jlong crdHandle, jbyteArray lastToken)
202 {
203
204 VOID *pInput = 0;
205 DWORD inputLen;
206 CHAR buffOut[512];
207 jboolean isCopy;
208 SECURITY_STATUS ss;
209 SecBufferDesc OutBuffDesc;
210 SecBuffer OutSecBuff;
211 SecBufferDesc InBuffDesc;
212 SecBuffer InSecBuff;
213 ULONG ContextAttributes;
214 CredHandle *pCred = (CredHandle *)crdHandle;
215 CtxtHandle *pCtx;
216 CtxtHandle *newContext;
217 TimeStamp ltime;
218 jbyteArray result;
219
220
|
43
44
45 /*
46 * OS calls loaded from DLL on intialization
47 */
48
49 static FREE_CREDENTIALS_HANDLE_FN pFreeCredentialsHandle;
50 static ACQUIRE_CREDENTIALS_HANDLE_FN pAcquireCredentialsHandle;
51 static FREE_CONTEXT_BUFFER_FN pFreeContextBuffer;
52 static INITIALIZE_SECURITY_CONTEXT_FN pInitializeSecurityContext;
53 static COMPLETE_AUTH_TOKEN_FN pCompleteAuthToken;
54 static DELETE_SECURITY_CONTEXT_FN pDeleteSecurityContext;
55
56 static void endSequence (PCredHandle credHand, PCtxtHandle ctxHandle);
57
58 static jfieldID ntlm_ctxHandleID;
59 static jfieldID ntlm_crdHandleID;
60
61 static HINSTANCE lib = NULL;
62
63 JNIEXPORT void JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_initFirst
64 (JNIEnv *env, jclass clazz)
65 {
66 OSVERSIONINFO version;
67 UCHAR libName[MAX_PATH];
68
69 ntlm_ctxHandleID = (*env)->GetFieldID(env, clazz, "ctxHandle", "J");
70 ntlm_crdHandleID = (*env)->GetFieldID(env, clazz, "crdHandle", "J");
71
72 version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
73 GetVersionEx (&version);
74
75 if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) {
76 strcpy (libName, "security.dll" );
77 }
78 else if (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
79 strcpy (libName, "secur32.dll" );
80 }
81
82 lib = LoadLibrary (libName);
83
96 pInitializeSecurityContext
97 = (INITIALIZE_SECURITY_CONTEXT_FN) GetProcAddress(
98 lib, "InitializeSecurityContextA" );
99
100 pCompleteAuthToken
101 = (COMPLETE_AUTH_TOKEN_FN) GetProcAddress(
102 lib, "CompleteAuthToken" );
103
104 pDeleteSecurityContext
105 = (DELETE_SECURITY_CONTEXT_FN) GetProcAddress(
106 lib, "DeleteSecurityContext" );
107
108 }
109
110 /*
111 * Class: sun_net_www_protocol_http_NTLMAuthSequence
112 * Method: getCredentialsHandle
113 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J
114 */
115
116 JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_getCredentialsHandle
117 (JNIEnv *env, jobject this, jstring user, jstring domain, jstring password)
118 {
119 SEC_WINNT_AUTH_IDENTITY AuthId;
120 SEC_WINNT_AUTH_IDENTITY * pAuthId;
121 const CHAR *pUser = 0;
122 const CHAR *pDomain = 0;
123 const CHAR *pPassword = 0;
124 CredHandle *pCred;
125 TimeStamp ltime;
126 jboolean isCopy;
127 SECURITY_STATUS ss;
128
129 if (user != 0) {
130 pUser = JNU_GetStringPlatformChars(env, user, &isCopy);
131 if (pUser == NULL)
132 return 0; // pending Exception
133 }
134 if (domain != 0) {
135 pDomain = JNU_GetStringPlatformChars(env, domain, &isCopy);
136 if (pDomain == NULL) {
180 NULL, "NTLM", SECPKG_CRED_OUTBOUND,
181 NULL, pAuthId, NULL, NULL,
182 pCred, <ime
183 );
184
185 /* Release resources held by JNU_GetStringPlatformChars */
186 if (pUser != NULL)
187 JNU_ReleaseStringPlatformChars(env, user, pUser);
188 if (pPassword != NULL)
189 JNU_ReleaseStringPlatformChars(env, password, pPassword);
190 if (pDomain != NULL)
191 JNU_ReleaseStringPlatformChars(env, domain, pDomain);
192
193 if (ss == 0) {
194 return (jlong) pCred;
195 } else {
196 return 0;
197 }
198 }
199
200 JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_getNextToken
201 (JNIEnv *env, jobject this, jlong crdHandle, jbyteArray lastToken)
202 {
203
204 VOID *pInput = 0;
205 DWORD inputLen;
206 CHAR buffOut[512];
207 jboolean isCopy;
208 SECURITY_STATUS ss;
209 SecBufferDesc OutBuffDesc;
210 SecBuffer OutSecBuff;
211 SecBufferDesc InBuffDesc;
212 SecBuffer InSecBuff;
213 ULONG ContextAttributes;
214 CredHandle *pCred = (CredHandle *)crdHandle;
215 CtxtHandle *pCtx;
216 CtxtHandle *newContext;
217 TimeStamp ltime;
218 jbyteArray result;
219
220
|