/src/FreeRDP/winpr/libwinpr/sspi/sspi.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * FreeRDP: A Remote Desktop Protocol Implementation |
3 | | * Security Support Provider Interface (SSPI) |
4 | | * |
5 | | * Copyright 2012-2014 Marc-Andre Moreau <marcandre.moreau@gmail.com> |
6 | | * |
7 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | | * you may not use this file except in compliance with the License. |
9 | | * You may obtain a copy of the License at |
10 | | * |
11 | | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | * |
13 | | * Unless required by applicable law or agreed to in writing, software |
14 | | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | | * See the License for the specific language governing permissions and |
17 | | * limitations under the License. |
18 | | */ |
19 | | |
20 | | #include <winpr/config.h> |
21 | | |
22 | | #if defined(__clang__) |
23 | | #pragma clang diagnostic push |
24 | | #pragma clang diagnostic ignored "-Wreserved-id-macro" |
25 | | #endif |
26 | | |
27 | | #define _NO_KSECDD_IMPORT_ 1 |
28 | | |
29 | | #if defined(__clang__) |
30 | | #pragma clang diagnostic pop |
31 | | #endif |
32 | | |
33 | | #include <winpr/sspi.h> |
34 | | |
35 | | #include <winpr/crt.h> |
36 | | #include <winpr/synch.h> |
37 | | #include <winpr/wlog.h> |
38 | | #include <winpr/library.h> |
39 | | #include <winpr/environment.h> |
40 | | |
41 | | #include "sspi.h" |
42 | | |
43 | | #if defined(__GNUC__) |
44 | | #pragma GCC diagnostic push |
45 | | #pragma GCC diagnostic ignored "-Wmissing-prototypes" |
46 | | #endif |
47 | | |
48 | | static wLog* g_Log = NULL; |
49 | | |
50 | | static INIT_ONCE g_Initialized = INIT_ONCE_STATIC_INIT; |
51 | | #if defined(WITH_NATIVE_SSPI) |
52 | | static HMODULE g_SspiModule = NULL; |
53 | | static SecurityFunctionTableW windows_SecurityFunctionTableW = { 0 }; |
54 | | static SecurityFunctionTableA windows_SecurityFunctionTableA = { 0 }; |
55 | | #endif |
56 | | |
57 | | static SecurityFunctionTableW* g_SspiW = NULL; |
58 | | static SecurityFunctionTableA* g_SspiA = NULL; |
59 | | |
60 | | #if defined(WITH_NATIVE_SSPI) |
61 | | static BOOL ShouldUseNativeSspi(void); |
62 | | static BOOL InitializeSspiModule_Native(void); |
63 | | #endif |
64 | | |
65 | | #if defined(WITH_NATIVE_SSPI) |
66 | | BOOL ShouldUseNativeSspi(void) |
67 | | { |
68 | | BOOL status = FALSE; |
69 | | #ifdef _WIN32 |
70 | | LPCSTR sspi = "WINPR_NATIVE_SSPI"; |
71 | | DWORD nSize; |
72 | | char* env = NULL; |
73 | | nSize = GetEnvironmentVariableA(sspi, NULL, 0); |
74 | | |
75 | | if (!nSize) |
76 | | return TRUE; |
77 | | |
78 | | env = (LPSTR)malloc(nSize); |
79 | | |
80 | | if (!env) |
81 | | return TRUE; |
82 | | |
83 | | if (GetEnvironmentVariableA(sspi, env, nSize) != nSize - 1) |
84 | | { |
85 | | free(env); |
86 | | return TRUE; |
87 | | } |
88 | | |
89 | | if (strcmp(env, "0") == 0) |
90 | | status = FALSE; |
91 | | else |
92 | | status = TRUE; |
93 | | |
94 | | free(env); |
95 | | #endif |
96 | | return status; |
97 | | } |
98 | | #endif |
99 | | |
100 | | #if defined(WITH_NATIVE_SSPI) |
101 | | BOOL InitializeSspiModule_Native(void) |
102 | | { |
103 | | SecurityFunctionTableW* pSspiW = NULL; |
104 | | SecurityFunctionTableA* pSspiA = NULL; |
105 | | INIT_SECURITY_INTERFACE_W pInitSecurityInterfaceW; |
106 | | INIT_SECURITY_INTERFACE_A pInitSecurityInterfaceA; |
107 | | g_SspiModule = LoadLibraryA("secur32.dll"); |
108 | | |
109 | | if (!g_SspiModule) |
110 | | g_SspiModule = LoadLibraryA("sspicli.dll"); |
111 | | |
112 | | if (!g_SspiModule) |
113 | | return FALSE; |
114 | | |
115 | | pInitSecurityInterfaceW = |
116 | | (INIT_SECURITY_INTERFACE_W)GetProcAddress(g_SspiModule, "InitSecurityInterfaceW"); |
117 | | pInitSecurityInterfaceA = |
118 | | (INIT_SECURITY_INTERFACE_A)GetProcAddress(g_SspiModule, "InitSecurityInterfaceA"); |
119 | | |
120 | | if (pInitSecurityInterfaceW) |
121 | | { |
122 | | pSspiW = pInitSecurityInterfaceW(); |
123 | | |
124 | | if (pSspiW) |
125 | | { |
126 | | g_SspiW = &windows_SecurityFunctionTableW; |
127 | | CopyMemory(g_SspiW, pSspiW, |
128 | | FIELD_OFFSET(SecurityFunctionTableW, SetContextAttributesW)); |
129 | | |
130 | | g_SspiW->dwVersion = SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_3; |
131 | | |
132 | | g_SspiW->SetContextAttributesW = |
133 | | (SET_CONTEXT_ATTRIBUTES_FN_W)GetProcAddress(g_SspiModule, "SetContextAttributesW"); |
134 | | |
135 | | g_SspiW->SetCredentialsAttributesW = (SET_CREDENTIALS_ATTRIBUTES_FN_W)GetProcAddress( |
136 | | g_SspiModule, "SetCredentialsAttributesW"); |
137 | | } |
138 | | } |
139 | | |
140 | | if (pInitSecurityInterfaceA) |
141 | | { |
142 | | pSspiA = pInitSecurityInterfaceA(); |
143 | | |
144 | | if (pSspiA) |
145 | | { |
146 | | g_SspiA = &windows_SecurityFunctionTableA; |
147 | | CopyMemory(g_SspiA, pSspiA, |
148 | | FIELD_OFFSET(SecurityFunctionTableA, SetContextAttributesA)); |
149 | | |
150 | | g_SspiA->dwVersion = SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_3; |
151 | | |
152 | | g_SspiA->SetContextAttributesA = |
153 | | (SET_CONTEXT_ATTRIBUTES_FN_W)GetProcAddress(g_SspiModule, "SetContextAttributesA"); |
154 | | |
155 | | g_SspiA->SetCredentialsAttributesA = (SET_CREDENTIALS_ATTRIBUTES_FN_W)GetProcAddress( |
156 | | g_SspiModule, "SetCredentialsAttributesA"); |
157 | | } |
158 | | } |
159 | | |
160 | | return TRUE; |
161 | | } |
162 | | #endif |
163 | | |
164 | | static BOOL CALLBACK InitializeSspiModuleInt(PINIT_ONCE once, PVOID param, PVOID* context) |
165 | 0 | { |
166 | 0 | BOOL status = FALSE; |
167 | | #if defined(WITH_NATIVE_SSPI) |
168 | | DWORD flags = 0; |
169 | | |
170 | | if (param) |
171 | | flags = *(DWORD*)param; |
172 | | |
173 | | #endif |
174 | 0 | sspi_GlobalInit(); |
175 | 0 | g_Log = WLog_Get("com.winpr.sspi"); |
176 | | #if defined(WITH_NATIVE_SSPI) |
177 | | |
178 | | if (flags && (flags & SSPI_INTERFACE_NATIVE)) |
179 | | { |
180 | | status = InitializeSspiModule_Native(); |
181 | | } |
182 | | else if (flags && (flags & SSPI_INTERFACE_WINPR)) |
183 | | { |
184 | | g_SspiW = winpr_InitSecurityInterfaceW(); |
185 | | g_SspiA = winpr_InitSecurityInterfaceA(); |
186 | | status = TRUE; |
187 | | } |
188 | | |
189 | | if (!status && ShouldUseNativeSspi()) |
190 | | { |
191 | | status = InitializeSspiModule_Native(); |
192 | | } |
193 | | |
194 | | #endif |
195 | |
|
196 | 0 | if (!status) |
197 | 0 | { |
198 | 0 | g_SspiW = winpr_InitSecurityInterfaceW(); |
199 | 0 | g_SspiA = winpr_InitSecurityInterfaceA(); |
200 | 0 | } |
201 | |
|
202 | 0 | return TRUE; |
203 | 0 | } |
204 | | |
205 | | const char* GetSecurityStatusString(SECURITY_STATUS status) |
206 | 0 | { |
207 | 0 | switch (status) |
208 | 0 | { |
209 | 0 | case SEC_E_OK: |
210 | 0 | return "SEC_E_OK"; |
211 | | |
212 | 0 | case SEC_E_INSUFFICIENT_MEMORY: |
213 | 0 | return "SEC_E_INSUFFICIENT_MEMORY"; |
214 | | |
215 | 0 | case SEC_E_INVALID_HANDLE: |
216 | 0 | return "SEC_E_INVALID_HANDLE"; |
217 | | |
218 | 0 | case SEC_E_UNSUPPORTED_FUNCTION: |
219 | 0 | return "SEC_E_UNSUPPORTED_FUNCTION"; |
220 | | |
221 | 0 | case SEC_E_TARGET_UNKNOWN: |
222 | 0 | return "SEC_E_TARGET_UNKNOWN"; |
223 | | |
224 | 0 | case SEC_E_INTERNAL_ERROR: |
225 | 0 | return "SEC_E_INTERNAL_ERROR"; |
226 | | |
227 | 0 | case SEC_E_SECPKG_NOT_FOUND: |
228 | 0 | return "SEC_E_SECPKG_NOT_FOUND"; |
229 | | |
230 | 0 | case SEC_E_NOT_OWNER: |
231 | 0 | return "SEC_E_NOT_OWNER"; |
232 | | |
233 | 0 | case SEC_E_CANNOT_INSTALL: |
234 | 0 | return "SEC_E_CANNOT_INSTALL"; |
235 | | |
236 | 0 | case SEC_E_INVALID_TOKEN: |
237 | 0 | return "SEC_E_INVALID_TOKEN"; |
238 | | |
239 | 0 | case SEC_E_CANNOT_PACK: |
240 | 0 | return "SEC_E_CANNOT_PACK"; |
241 | | |
242 | 0 | case SEC_E_QOP_NOT_SUPPORTED: |
243 | 0 | return "SEC_E_QOP_NOT_SUPPORTED"; |
244 | | |
245 | 0 | case SEC_E_NO_IMPERSONATION: |
246 | 0 | return "SEC_E_NO_IMPERSONATION"; |
247 | | |
248 | 0 | case SEC_E_LOGON_DENIED: |
249 | 0 | return "SEC_E_LOGON_DENIED"; |
250 | | |
251 | 0 | case SEC_E_UNKNOWN_CREDENTIALS: |
252 | 0 | return "SEC_E_UNKNOWN_CREDENTIALS"; |
253 | | |
254 | 0 | case SEC_E_NO_CREDENTIALS: |
255 | 0 | return "SEC_E_NO_CREDENTIALS"; |
256 | | |
257 | 0 | case SEC_E_MESSAGE_ALTERED: |
258 | 0 | return "SEC_E_MESSAGE_ALTERED"; |
259 | | |
260 | 0 | case SEC_E_OUT_OF_SEQUENCE: |
261 | 0 | return "SEC_E_OUT_OF_SEQUENCE"; |
262 | | |
263 | 0 | case SEC_E_NO_AUTHENTICATING_AUTHORITY: |
264 | 0 | return "SEC_E_NO_AUTHENTICATING_AUTHORITY"; |
265 | | |
266 | 0 | case SEC_E_BAD_PKGID: |
267 | 0 | return "SEC_E_BAD_PKGID"; |
268 | | |
269 | 0 | case SEC_E_CONTEXT_EXPIRED: |
270 | 0 | return "SEC_E_CONTEXT_EXPIRED"; |
271 | | |
272 | 0 | case SEC_E_INCOMPLETE_MESSAGE: |
273 | 0 | return "SEC_E_INCOMPLETE_MESSAGE"; |
274 | | |
275 | 0 | case SEC_E_INCOMPLETE_CREDENTIALS: |
276 | 0 | return "SEC_E_INCOMPLETE_CREDENTIALS"; |
277 | | |
278 | 0 | case SEC_E_BUFFER_TOO_SMALL: |
279 | 0 | return "SEC_E_BUFFER_TOO_SMALL"; |
280 | | |
281 | 0 | case SEC_E_WRONG_PRINCIPAL: |
282 | 0 | return "SEC_E_WRONG_PRINCIPAL"; |
283 | | |
284 | 0 | case SEC_E_TIME_SKEW: |
285 | 0 | return "SEC_E_TIME_SKEW"; |
286 | | |
287 | 0 | case SEC_E_UNTRUSTED_ROOT: |
288 | 0 | return "SEC_E_UNTRUSTED_ROOT"; |
289 | | |
290 | 0 | case SEC_E_ILLEGAL_MESSAGE: |
291 | 0 | return "SEC_E_ILLEGAL_MESSAGE"; |
292 | | |
293 | 0 | case SEC_E_CERT_UNKNOWN: |
294 | 0 | return "SEC_E_CERT_UNKNOWN"; |
295 | | |
296 | 0 | case SEC_E_CERT_EXPIRED: |
297 | 0 | return "SEC_E_CERT_EXPIRED"; |
298 | | |
299 | 0 | case SEC_E_ENCRYPT_FAILURE: |
300 | 0 | return "SEC_E_ENCRYPT_FAILURE"; |
301 | | |
302 | 0 | case SEC_E_DECRYPT_FAILURE: |
303 | 0 | return "SEC_E_DECRYPT_FAILURE"; |
304 | | |
305 | 0 | case SEC_E_ALGORITHM_MISMATCH: |
306 | 0 | return "SEC_E_ALGORITHM_MISMATCH"; |
307 | | |
308 | 0 | case SEC_E_SECURITY_QOS_FAILED: |
309 | 0 | return "SEC_E_SECURITY_QOS_FAILED"; |
310 | | |
311 | 0 | case SEC_E_UNFINISHED_CONTEXT_DELETED: |
312 | 0 | return "SEC_E_UNFINISHED_CONTEXT_DELETED"; |
313 | | |
314 | 0 | case SEC_E_NO_TGT_REPLY: |
315 | 0 | return "SEC_E_NO_TGT_REPLY"; |
316 | | |
317 | 0 | case SEC_E_NO_IP_ADDRESSES: |
318 | 0 | return "SEC_E_NO_IP_ADDRESSES"; |
319 | | |
320 | 0 | case SEC_E_WRONG_CREDENTIAL_HANDLE: |
321 | 0 | return "SEC_E_WRONG_CREDENTIAL_HANDLE"; |
322 | | |
323 | 0 | case SEC_E_CRYPTO_SYSTEM_INVALID: |
324 | 0 | return "SEC_E_CRYPTO_SYSTEM_INVALID"; |
325 | | |
326 | 0 | case SEC_E_MAX_REFERRALS_EXCEEDED: |
327 | 0 | return "SEC_E_MAX_REFERRALS_EXCEEDED"; |
328 | | |
329 | 0 | case SEC_E_MUST_BE_KDC: |
330 | 0 | return "SEC_E_MUST_BE_KDC"; |
331 | | |
332 | 0 | case SEC_E_STRONG_CRYPTO_NOT_SUPPORTED: |
333 | 0 | return "SEC_E_STRONG_CRYPTO_NOT_SUPPORTED"; |
334 | | |
335 | 0 | case SEC_E_TOO_MANY_PRINCIPALS: |
336 | 0 | return "SEC_E_TOO_MANY_PRINCIPALS"; |
337 | | |
338 | 0 | case SEC_E_NO_PA_DATA: |
339 | 0 | return "SEC_E_NO_PA_DATA"; |
340 | | |
341 | 0 | case SEC_E_PKINIT_NAME_MISMATCH: |
342 | 0 | return "SEC_E_PKINIT_NAME_MISMATCH"; |
343 | | |
344 | 0 | case SEC_E_SMARTCARD_LOGON_REQUIRED: |
345 | 0 | return "SEC_E_SMARTCARD_LOGON_REQUIRED"; |
346 | | |
347 | 0 | case SEC_E_SHUTDOWN_IN_PROGRESS: |
348 | 0 | return "SEC_E_SHUTDOWN_IN_PROGRESS"; |
349 | | |
350 | 0 | case SEC_E_KDC_INVALID_REQUEST: |
351 | 0 | return "SEC_E_KDC_INVALID_REQUEST"; |
352 | | |
353 | 0 | case SEC_E_KDC_UNABLE_TO_REFER: |
354 | 0 | return "SEC_E_KDC_UNABLE_TO_REFER"; |
355 | | |
356 | 0 | case SEC_E_KDC_UNKNOWN_ETYPE: |
357 | 0 | return "SEC_E_KDC_UNKNOWN_ETYPE"; |
358 | | |
359 | 0 | case SEC_E_UNSUPPORTED_PREAUTH: |
360 | 0 | return "SEC_E_UNSUPPORTED_PREAUTH"; |
361 | | |
362 | 0 | case SEC_E_DELEGATION_REQUIRED: |
363 | 0 | return "SEC_E_DELEGATION_REQUIRED"; |
364 | | |
365 | 0 | case SEC_E_BAD_BINDINGS: |
366 | 0 | return "SEC_E_BAD_BINDINGS"; |
367 | | |
368 | 0 | case SEC_E_MULTIPLE_ACCOUNTS: |
369 | 0 | return "SEC_E_MULTIPLE_ACCOUNTS"; |
370 | | |
371 | 0 | case SEC_E_NO_KERB_KEY: |
372 | 0 | return "SEC_E_NO_KERB_KEY"; |
373 | | |
374 | 0 | case SEC_E_CERT_WRONG_USAGE: |
375 | 0 | return "SEC_E_CERT_WRONG_USAGE"; |
376 | | |
377 | 0 | case SEC_E_DOWNGRADE_DETECTED: |
378 | 0 | return "SEC_E_DOWNGRADE_DETECTED"; |
379 | | |
380 | 0 | case SEC_E_SMARTCARD_CERT_REVOKED: |
381 | 0 | return "SEC_E_SMARTCARD_CERT_REVOKED"; |
382 | | |
383 | 0 | case SEC_E_ISSUING_CA_UNTRUSTED: |
384 | 0 | return "SEC_E_ISSUING_CA_UNTRUSTED"; |
385 | | |
386 | 0 | case SEC_E_REVOCATION_OFFLINE_C: |
387 | 0 | return "SEC_E_REVOCATION_OFFLINE_C"; |
388 | | |
389 | 0 | case SEC_E_PKINIT_CLIENT_FAILURE: |
390 | 0 | return "SEC_E_PKINIT_CLIENT_FAILURE"; |
391 | | |
392 | 0 | case SEC_E_SMARTCARD_CERT_EXPIRED: |
393 | 0 | return "SEC_E_SMARTCARD_CERT_EXPIRED"; |
394 | | |
395 | 0 | case SEC_E_NO_S4U_PROT_SUPPORT: |
396 | 0 | return "SEC_E_NO_S4U_PROT_SUPPORT"; |
397 | | |
398 | 0 | case SEC_E_CROSSREALM_DELEGATION_FAILURE: |
399 | 0 | return "SEC_E_CROSSREALM_DELEGATION_FAILURE"; |
400 | | |
401 | 0 | case SEC_E_REVOCATION_OFFLINE_KDC: |
402 | 0 | return "SEC_E_REVOCATION_OFFLINE_KDC"; |
403 | | |
404 | 0 | case SEC_E_ISSUING_CA_UNTRUSTED_KDC: |
405 | 0 | return "SEC_E_ISSUING_CA_UNTRUSTED_KDC"; |
406 | | |
407 | 0 | case SEC_E_KDC_CERT_EXPIRED: |
408 | 0 | return "SEC_E_KDC_CERT_EXPIRED"; |
409 | | |
410 | 0 | case SEC_E_KDC_CERT_REVOKED: |
411 | 0 | return "SEC_E_KDC_CERT_REVOKED"; |
412 | | |
413 | 0 | case SEC_E_INVALID_PARAMETER: |
414 | 0 | return "SEC_E_INVALID_PARAMETER"; |
415 | | |
416 | 0 | case SEC_E_DELEGATION_POLICY: |
417 | 0 | return "SEC_E_DELEGATION_POLICY"; |
418 | | |
419 | 0 | case SEC_E_POLICY_NLTM_ONLY: |
420 | 0 | return "SEC_E_POLICY_NLTM_ONLY"; |
421 | | |
422 | 0 | case SEC_E_NO_CONTEXT: |
423 | 0 | return "SEC_E_NO_CONTEXT"; |
424 | | |
425 | 0 | case SEC_E_PKU2U_CERT_FAILURE: |
426 | 0 | return "SEC_E_PKU2U_CERT_FAILURE"; |
427 | | |
428 | 0 | case SEC_E_MUTUAL_AUTH_FAILED: |
429 | 0 | return "SEC_E_MUTUAL_AUTH_FAILED"; |
430 | | |
431 | 0 | case SEC_I_CONTINUE_NEEDED: |
432 | 0 | return "SEC_I_CONTINUE_NEEDED"; |
433 | | |
434 | 0 | case SEC_I_COMPLETE_NEEDED: |
435 | 0 | return "SEC_I_COMPLETE_NEEDED"; |
436 | | |
437 | 0 | case SEC_I_COMPLETE_AND_CONTINUE: |
438 | 0 | return "SEC_I_COMPLETE_AND_CONTINUE"; |
439 | | |
440 | 0 | case SEC_I_LOCAL_LOGON: |
441 | 0 | return "SEC_I_LOCAL_LOGON"; |
442 | | |
443 | 0 | case SEC_I_CONTEXT_EXPIRED: |
444 | 0 | return "SEC_I_CONTEXT_EXPIRED"; |
445 | | |
446 | 0 | case SEC_I_INCOMPLETE_CREDENTIALS: |
447 | 0 | return "SEC_I_INCOMPLETE_CREDENTIALS"; |
448 | | |
449 | 0 | case SEC_I_RENEGOTIATE: |
450 | 0 | return "SEC_I_RENEGOTIATE"; |
451 | | |
452 | 0 | case SEC_I_NO_LSA_CONTEXT: |
453 | 0 | return "SEC_I_NO_LSA_CONTEXT"; |
454 | | |
455 | 0 | case SEC_I_SIGNATURE_NEEDED: |
456 | 0 | return "SEC_I_SIGNATURE_NEEDED"; |
457 | | |
458 | 0 | case SEC_I_NO_RENEGOTIATION: |
459 | 0 | return "SEC_I_NO_RENEGOTIATION"; |
460 | 0 | } |
461 | | |
462 | 0 | return NtStatus2Tag((DWORD)status); |
463 | 0 | } |
464 | | |
465 | | BOOL IsSecurityStatusError(SECURITY_STATUS status) |
466 | 0 | { |
467 | 0 | BOOL error = TRUE; |
468 | |
|
469 | 0 | switch (status) |
470 | 0 | { |
471 | 0 | case SEC_E_OK: |
472 | 0 | case SEC_I_CONTINUE_NEEDED: |
473 | 0 | case SEC_I_COMPLETE_NEEDED: |
474 | 0 | case SEC_I_COMPLETE_AND_CONTINUE: |
475 | 0 | case SEC_I_LOCAL_LOGON: |
476 | 0 | case SEC_I_CONTEXT_EXPIRED: |
477 | 0 | case SEC_I_INCOMPLETE_CREDENTIALS: |
478 | 0 | case SEC_I_RENEGOTIATE: |
479 | 0 | case SEC_I_NO_LSA_CONTEXT: |
480 | 0 | case SEC_I_SIGNATURE_NEEDED: |
481 | 0 | case SEC_I_NO_RENEGOTIATION: |
482 | 0 | error = FALSE; |
483 | 0 | break; |
484 | 0 | } |
485 | | |
486 | 0 | return error; |
487 | 0 | } |
488 | | |
489 | | SecurityFunctionTableW* SEC_ENTRY InitSecurityInterfaceExW(DWORD flags) |
490 | 0 | { |
491 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, &flags, NULL); |
492 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "InitSecurityInterfaceExW"); |
493 | 0 | return g_SspiW; |
494 | 0 | } |
495 | | |
496 | | SecurityFunctionTableA* SEC_ENTRY InitSecurityInterfaceExA(DWORD flags) |
497 | 0 | { |
498 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, &flags, NULL); |
499 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "InitSecurityInterfaceExA"); |
500 | 0 | return g_SspiA; |
501 | 0 | } |
502 | | |
503 | | /** |
504 | | * Standard SSPI API |
505 | | */ |
506 | | |
507 | | /* Package Management */ |
508 | | |
509 | | SECURITY_STATUS SEC_ENTRY sspi_EnumerateSecurityPackagesW(ULONG* pcPackages, |
510 | | PSecPkgInfoW* ppPackageInfo) |
511 | 0 | { |
512 | 0 | SECURITY_STATUS status; |
513 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
514 | |
|
515 | 0 | if (!(g_SspiW && g_SspiW->EnumerateSecurityPackagesW)) |
516 | 0 | { |
517 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
518 | |
|
519 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
520 | 0 | } |
521 | | |
522 | 0 | status = g_SspiW->EnumerateSecurityPackagesW(pcPackages, ppPackageInfo); |
523 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "EnumerateSecurityPackagesW: %s (0x%08" PRIX32 ")", |
524 | 0 | GetSecurityStatusString(status), status); |
525 | 0 | return status; |
526 | 0 | } |
527 | | |
528 | | SECURITY_STATUS SEC_ENTRY sspi_EnumerateSecurityPackagesA(ULONG* pcPackages, |
529 | | PSecPkgInfoA* ppPackageInfo) |
530 | 0 | { |
531 | 0 | SECURITY_STATUS status; |
532 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
533 | |
|
534 | 0 | if (!(g_SspiA && g_SspiA->EnumerateSecurityPackagesA)) |
535 | 0 | { |
536 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
537 | |
|
538 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
539 | 0 | } |
540 | | |
541 | 0 | status = g_SspiA->EnumerateSecurityPackagesA(pcPackages, ppPackageInfo); |
542 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "EnumerateSecurityPackagesA: %s (0x%08" PRIX32 ")", |
543 | 0 | GetSecurityStatusString(status), status); |
544 | 0 | return status; |
545 | 0 | } |
546 | | |
547 | | SecurityFunctionTableW* SEC_ENTRY sspi_InitSecurityInterfaceW(void) |
548 | 0 | { |
549 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
550 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "InitSecurityInterfaceW"); |
551 | 0 | return g_SspiW; |
552 | 0 | } |
553 | | |
554 | | SecurityFunctionTableA* SEC_ENTRY sspi_InitSecurityInterfaceA(void) |
555 | 0 | { |
556 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
557 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "InitSecurityInterfaceA"); |
558 | 0 | return g_SspiA; |
559 | 0 | } |
560 | | |
561 | | SECURITY_STATUS SEC_ENTRY sspi_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName, |
562 | | PSecPkgInfoW* ppPackageInfo) |
563 | 0 | { |
564 | 0 | SECURITY_STATUS status; |
565 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
566 | |
|
567 | 0 | if (!(g_SspiW && g_SspiW->QuerySecurityPackageInfoW)) |
568 | 0 | { |
569 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
570 | |
|
571 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
572 | 0 | } |
573 | | |
574 | 0 | status = g_SspiW->QuerySecurityPackageInfoW(pszPackageName, ppPackageInfo); |
575 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "QuerySecurityPackageInfoW: %s (0x%08" PRIX32 ")", |
576 | 0 | GetSecurityStatusString(status), status); |
577 | 0 | return status; |
578 | 0 | } |
579 | | |
580 | | SECURITY_STATUS SEC_ENTRY sspi_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName, |
581 | | PSecPkgInfoA* ppPackageInfo) |
582 | 0 | { |
583 | 0 | SECURITY_STATUS status; |
584 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
585 | |
|
586 | 0 | if (!(g_SspiA && g_SspiA->QuerySecurityPackageInfoA)) |
587 | 0 | { |
588 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
589 | |
|
590 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
591 | 0 | } |
592 | | |
593 | 0 | status = g_SspiA->QuerySecurityPackageInfoA(pszPackageName, ppPackageInfo); |
594 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "QuerySecurityPackageInfoA: %s (0x%08" PRIX32 ")", |
595 | 0 | GetSecurityStatusString(status), status); |
596 | 0 | return status; |
597 | 0 | } |
598 | | |
599 | | /* Credential Management */ |
600 | | |
601 | | SECURITY_STATUS SEC_ENTRY sspi_AcquireCredentialsHandleW( |
602 | | SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, ULONG fCredentialUse, void* pvLogonID, |
603 | | void* pAuthData, SEC_GET_KEY_FN pGetKeyFn, void* pvGetKeyArgument, PCredHandle phCredential, |
604 | | PTimeStamp ptsExpiry) |
605 | 0 | { |
606 | 0 | SECURITY_STATUS status; |
607 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
608 | |
|
609 | 0 | if (!(g_SspiW && g_SspiW->AcquireCredentialsHandleW)) |
610 | 0 | { |
611 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
612 | |
|
613 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
614 | 0 | } |
615 | | |
616 | 0 | status = g_SspiW->AcquireCredentialsHandleW(pszPrincipal, pszPackage, fCredentialUse, pvLogonID, |
617 | 0 | pAuthData, pGetKeyFn, pvGetKeyArgument, |
618 | 0 | phCredential, ptsExpiry); |
619 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "AcquireCredentialsHandleW: %s (0x%08" PRIX32 ")", |
620 | 0 | GetSecurityStatusString(status), status); |
621 | 0 | return status; |
622 | 0 | } |
623 | | |
624 | | SECURITY_STATUS SEC_ENTRY sspi_AcquireCredentialsHandleA( |
625 | | SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, ULONG fCredentialUse, void* pvLogonID, |
626 | | void* pAuthData, SEC_GET_KEY_FN pGetKeyFn, void* pvGetKeyArgument, PCredHandle phCredential, |
627 | | PTimeStamp ptsExpiry) |
628 | 0 | { |
629 | 0 | SECURITY_STATUS status; |
630 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
631 | |
|
632 | 0 | if (!(g_SspiA && g_SspiA->AcquireCredentialsHandleA)) |
633 | 0 | { |
634 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
635 | |
|
636 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
637 | 0 | } |
638 | | |
639 | 0 | status = g_SspiA->AcquireCredentialsHandleA(pszPrincipal, pszPackage, fCredentialUse, pvLogonID, |
640 | 0 | pAuthData, pGetKeyFn, pvGetKeyArgument, |
641 | 0 | phCredential, ptsExpiry); |
642 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "AcquireCredentialsHandleA: %s (0x%08" PRIX32 ")", |
643 | 0 | GetSecurityStatusString(status), status); |
644 | 0 | return status; |
645 | 0 | } |
646 | | |
647 | | SECURITY_STATUS SEC_ENTRY sspi_ExportSecurityContext(PCtxtHandle phContext, ULONG fFlags, |
648 | | PSecBuffer pPackedContext, HANDLE* pToken) |
649 | 0 | { |
650 | 0 | SECURITY_STATUS status; |
651 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
652 | |
|
653 | 0 | if (!(g_SspiW && g_SspiW->ExportSecurityContext)) |
654 | 0 | { |
655 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
656 | |
|
657 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
658 | 0 | } |
659 | | |
660 | 0 | status = g_SspiW->ExportSecurityContext(phContext, fFlags, pPackedContext, pToken); |
661 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "ExportSecurityContext: %s (0x%08" PRIX32 ")", |
662 | 0 | GetSecurityStatusString(status), status); |
663 | 0 | return status; |
664 | 0 | } |
665 | | |
666 | | SECURITY_STATUS SEC_ENTRY sspi_FreeCredentialsHandle(PCredHandle phCredential) |
667 | 0 | { |
668 | 0 | SECURITY_STATUS status; |
669 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
670 | |
|
671 | 0 | if (!(g_SspiW && g_SspiW->FreeCredentialsHandle)) |
672 | 0 | { |
673 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
674 | |
|
675 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
676 | 0 | } |
677 | | |
678 | 0 | status = g_SspiW->FreeCredentialsHandle(phCredential); |
679 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "FreeCredentialsHandle: %s (0x%08" PRIX32 ")", |
680 | 0 | GetSecurityStatusString(status), status); |
681 | 0 | return status; |
682 | 0 | } |
683 | | |
684 | | SECURITY_STATUS SEC_ENTRY sspi_ImportSecurityContextW(SEC_WCHAR* pszPackage, |
685 | | PSecBuffer pPackedContext, HANDLE pToken, |
686 | | PCtxtHandle phContext) |
687 | 0 | { |
688 | 0 | SECURITY_STATUS status; |
689 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
690 | |
|
691 | 0 | if (!(g_SspiW && g_SspiW->ImportSecurityContextW)) |
692 | 0 | { |
693 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
694 | |
|
695 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
696 | 0 | } |
697 | | |
698 | 0 | status = g_SspiW->ImportSecurityContextW(pszPackage, pPackedContext, pToken, phContext); |
699 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "ImportSecurityContextW: %s (0x%08" PRIX32 ")", |
700 | 0 | GetSecurityStatusString(status), status); |
701 | 0 | return status; |
702 | 0 | } |
703 | | |
704 | | SECURITY_STATUS SEC_ENTRY sspi_ImportSecurityContextA(SEC_CHAR* pszPackage, |
705 | | PSecBuffer pPackedContext, HANDLE pToken, |
706 | | PCtxtHandle phContext) |
707 | 0 | { |
708 | 0 | SECURITY_STATUS status; |
709 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
710 | |
|
711 | 0 | if (!(g_SspiA && g_SspiA->ImportSecurityContextA)) |
712 | 0 | { |
713 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
714 | |
|
715 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
716 | 0 | } |
717 | | |
718 | 0 | status = g_SspiA->ImportSecurityContextA(pszPackage, pPackedContext, pToken, phContext); |
719 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "ImportSecurityContextA: %s (0x%08" PRIX32 ")", |
720 | 0 | GetSecurityStatusString(status), status); |
721 | 0 | return status; |
722 | 0 | } |
723 | | |
724 | | SECURITY_STATUS SEC_ENTRY sspi_QueryCredentialsAttributesW(PCredHandle phCredential, |
725 | | ULONG ulAttribute, void* pBuffer) |
726 | 0 | { |
727 | 0 | SECURITY_STATUS status; |
728 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
729 | |
|
730 | 0 | if (!(g_SspiW && g_SspiW->QueryCredentialsAttributesW)) |
731 | 0 | { |
732 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
733 | |
|
734 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
735 | 0 | } |
736 | | |
737 | 0 | status = g_SspiW->QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer); |
738 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "QueryCredentialsAttributesW: %s (0x%08" PRIX32 ")", |
739 | 0 | GetSecurityStatusString(status), status); |
740 | 0 | return status; |
741 | 0 | } |
742 | | |
743 | | SECURITY_STATUS SEC_ENTRY sspi_QueryCredentialsAttributesA(PCredHandle phCredential, |
744 | | ULONG ulAttribute, void* pBuffer) |
745 | 0 | { |
746 | 0 | SECURITY_STATUS status; |
747 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
748 | |
|
749 | 0 | if (!(g_SspiA && g_SspiA->QueryCredentialsAttributesA)) |
750 | 0 | { |
751 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
752 | |
|
753 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
754 | 0 | } |
755 | | |
756 | 0 | status = g_SspiA->QueryCredentialsAttributesA(phCredential, ulAttribute, pBuffer); |
757 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "QueryCredentialsAttributesA: %s (0x%08" PRIX32 ")", |
758 | 0 | GetSecurityStatusString(status), status); |
759 | 0 | return status; |
760 | 0 | } |
761 | | |
762 | | /* Context Management */ |
763 | | |
764 | | SECURITY_STATUS SEC_ENTRY sspi_AcceptSecurityContext(PCredHandle phCredential, |
765 | | PCtxtHandle phContext, PSecBufferDesc pInput, |
766 | | ULONG fContextReq, ULONG TargetDataRep, |
767 | | PCtxtHandle phNewContext, |
768 | | PSecBufferDesc pOutput, PULONG pfContextAttr, |
769 | | PTimeStamp ptsTimeStamp) |
770 | 0 | { |
771 | 0 | SECURITY_STATUS status; |
772 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
773 | |
|
774 | 0 | if (!(g_SspiW && g_SspiW->AcceptSecurityContext)) |
775 | 0 | { |
776 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
777 | |
|
778 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
779 | 0 | } |
780 | | |
781 | 0 | status = |
782 | 0 | g_SspiW->AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep, |
783 | 0 | phNewContext, pOutput, pfContextAttr, ptsTimeStamp); |
784 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "AcceptSecurityContext: %s (0x%08" PRIX32 ")", |
785 | 0 | GetSecurityStatusString(status), status); |
786 | 0 | return status; |
787 | 0 | } |
788 | | |
789 | | SECURITY_STATUS SEC_ENTRY sspi_ApplyControlToken(PCtxtHandle phContext, PSecBufferDesc pInput) |
790 | 0 | { |
791 | 0 | SECURITY_STATUS status; |
792 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
793 | |
|
794 | 0 | if (!(g_SspiW && g_SspiW->ApplyControlToken)) |
795 | 0 | { |
796 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
797 | |
|
798 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
799 | 0 | } |
800 | | |
801 | 0 | status = g_SspiW->ApplyControlToken(phContext, pInput); |
802 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "ApplyControlToken: %s (0x%08" PRIX32 ")", |
803 | 0 | GetSecurityStatusString(status), status); |
804 | 0 | return status; |
805 | 0 | } |
806 | | |
807 | | SECURITY_STATUS SEC_ENTRY sspi_CompleteAuthToken(PCtxtHandle phContext, PSecBufferDesc pToken) |
808 | 0 | { |
809 | 0 | SECURITY_STATUS status; |
810 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
811 | |
|
812 | 0 | if (!(g_SspiW && g_SspiW->CompleteAuthToken)) |
813 | 0 | { |
814 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
815 | |
|
816 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
817 | 0 | } |
818 | | |
819 | 0 | status = g_SspiW->CompleteAuthToken(phContext, pToken); |
820 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "CompleteAuthToken: %s (0x%08" PRIX32 ")", |
821 | 0 | GetSecurityStatusString(status), status); |
822 | 0 | return status; |
823 | 0 | } |
824 | | |
825 | | SECURITY_STATUS SEC_ENTRY sspi_DeleteSecurityContext(PCtxtHandle phContext) |
826 | 0 | { |
827 | 0 | SECURITY_STATUS status; |
828 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
829 | |
|
830 | 0 | if (!(g_SspiW && g_SspiW->DeleteSecurityContext)) |
831 | 0 | { |
832 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
833 | |
|
834 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
835 | 0 | } |
836 | | |
837 | 0 | status = g_SspiW->DeleteSecurityContext(phContext); |
838 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "DeleteSecurityContext: %s (0x%08" PRIX32 ")", |
839 | 0 | GetSecurityStatusString(status), status); |
840 | 0 | return status; |
841 | 0 | } |
842 | | |
843 | | SECURITY_STATUS SEC_ENTRY sspi_FreeContextBuffer(void* pvContextBuffer) |
844 | 0 | { |
845 | 0 | SECURITY_STATUS status; |
846 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
847 | |
|
848 | 0 | if (!(g_SspiW && g_SspiW->FreeContextBuffer)) |
849 | 0 | { |
850 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
851 | |
|
852 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
853 | 0 | } |
854 | | |
855 | 0 | status = g_SspiW->FreeContextBuffer(pvContextBuffer); |
856 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "FreeContextBuffer: %s (0x%08" PRIX32 ")", |
857 | 0 | GetSecurityStatusString(status), status); |
858 | 0 | return status; |
859 | 0 | } |
860 | | |
861 | | SECURITY_STATUS SEC_ENTRY sspi_ImpersonateSecurityContext(PCtxtHandle phContext) |
862 | 0 | { |
863 | 0 | SECURITY_STATUS status; |
864 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
865 | |
|
866 | 0 | if (!(g_SspiW && g_SspiW->ImpersonateSecurityContext)) |
867 | 0 | { |
868 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
869 | |
|
870 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
871 | 0 | } |
872 | | |
873 | 0 | status = g_SspiW->ImpersonateSecurityContext(phContext); |
874 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "ImpersonateSecurityContext: %s (0x%08" PRIX32 ")", |
875 | 0 | GetSecurityStatusString(status), status); |
876 | 0 | return status; |
877 | 0 | } |
878 | | |
879 | | SECURITY_STATUS SEC_ENTRY sspi_InitializeSecurityContextW( |
880 | | PCredHandle phCredential, PCtxtHandle phContext, SEC_WCHAR* pszTargetName, ULONG fContextReq, |
881 | | ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput, ULONG Reserved2, |
882 | | PCtxtHandle phNewContext, PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry) |
883 | 0 | { |
884 | 0 | SECURITY_STATUS status; |
885 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
886 | |
|
887 | 0 | if (!(g_SspiW && g_SspiW->InitializeSecurityContextW)) |
888 | 0 | { |
889 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
890 | |
|
891 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
892 | 0 | } |
893 | | |
894 | 0 | status = g_SspiW->InitializeSecurityContextW( |
895 | 0 | phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, |
896 | 0 | Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry); |
897 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "InitializeSecurityContextW: %s (0x%08" PRIX32 ")", |
898 | 0 | GetSecurityStatusString(status), status); |
899 | 0 | return status; |
900 | 0 | } |
901 | | |
902 | | SECURITY_STATUS SEC_ENTRY sspi_InitializeSecurityContextA( |
903 | | PCredHandle phCredential, PCtxtHandle phContext, SEC_CHAR* pszTargetName, ULONG fContextReq, |
904 | | ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput, ULONG Reserved2, |
905 | | PCtxtHandle phNewContext, PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry) |
906 | 0 | { |
907 | 0 | SECURITY_STATUS status; |
908 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
909 | |
|
910 | 0 | if (!(g_SspiA && g_SspiA->InitializeSecurityContextA)) |
911 | 0 | { |
912 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
913 | |
|
914 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
915 | 0 | } |
916 | | |
917 | 0 | status = g_SspiA->InitializeSecurityContextA( |
918 | 0 | phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, |
919 | 0 | Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry); |
920 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "InitializeSecurityContextA: %s (0x%08" PRIX32 ")", |
921 | 0 | GetSecurityStatusString(status), status); |
922 | 0 | return status; |
923 | 0 | } |
924 | | |
925 | | SECURITY_STATUS SEC_ENTRY sspi_QueryContextAttributesW(PCtxtHandle phContext, ULONG ulAttribute, |
926 | | void* pBuffer) |
927 | 0 | { |
928 | 0 | SECURITY_STATUS status; |
929 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
930 | |
|
931 | 0 | if (!(g_SspiW && g_SspiW->QueryContextAttributesW)) |
932 | 0 | { |
933 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
934 | |
|
935 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
936 | 0 | } |
937 | | |
938 | 0 | status = g_SspiW->QueryContextAttributesW(phContext, ulAttribute, pBuffer); |
939 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "QueryContextAttributesW: %s (0x%08" PRIX32 ")", |
940 | 0 | GetSecurityStatusString(status), status); |
941 | 0 | return status; |
942 | 0 | } |
943 | | |
944 | | SECURITY_STATUS SEC_ENTRY sspi_QueryContextAttributesA(PCtxtHandle phContext, ULONG ulAttribute, |
945 | | void* pBuffer) |
946 | 0 | { |
947 | 0 | SECURITY_STATUS status; |
948 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
949 | |
|
950 | 0 | if (!(g_SspiA && g_SspiA->QueryContextAttributesA)) |
951 | 0 | { |
952 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
953 | |
|
954 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
955 | 0 | } |
956 | | |
957 | 0 | status = g_SspiA->QueryContextAttributesA(phContext, ulAttribute, pBuffer); |
958 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "QueryContextAttributesA: %s (0x%08" PRIX32 ")", |
959 | 0 | GetSecurityStatusString(status), status); |
960 | 0 | return status; |
961 | 0 | } |
962 | | |
963 | | SECURITY_STATUS SEC_ENTRY sspi_QuerySecurityContextToken(PCtxtHandle phContext, HANDLE* phToken) |
964 | 0 | { |
965 | 0 | SECURITY_STATUS status; |
966 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
967 | |
|
968 | 0 | if (!(g_SspiW && g_SspiW->QuerySecurityContextToken)) |
969 | 0 | { |
970 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
971 | |
|
972 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
973 | 0 | } |
974 | | |
975 | 0 | status = g_SspiW->QuerySecurityContextToken(phContext, phToken); |
976 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "QuerySecurityContextToken: %s (0x%08" PRIX32 ")", |
977 | 0 | GetSecurityStatusString(status), status); |
978 | 0 | return status; |
979 | 0 | } |
980 | | |
981 | | SECURITY_STATUS SEC_ENTRY sspi_SetContextAttributesW(PCtxtHandle phContext, ULONG ulAttribute, |
982 | | void* pBuffer, ULONG cbBuffer) |
983 | 0 | { |
984 | 0 | SECURITY_STATUS status; |
985 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
986 | |
|
987 | 0 | if (!(g_SspiW && g_SspiW->SetContextAttributesW)) |
988 | 0 | { |
989 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
990 | |
|
991 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
992 | 0 | } |
993 | | |
994 | 0 | status = g_SspiW->SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer); |
995 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "SetContextAttributesW: %s (0x%08" PRIX32 ")", |
996 | 0 | GetSecurityStatusString(status), status); |
997 | 0 | return status; |
998 | 0 | } |
999 | | |
1000 | | SECURITY_STATUS SEC_ENTRY sspi_SetContextAttributesA(PCtxtHandle phContext, ULONG ulAttribute, |
1001 | | void* pBuffer, ULONG cbBuffer) |
1002 | 0 | { |
1003 | 0 | SECURITY_STATUS status; |
1004 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
1005 | |
|
1006 | 0 | if (!(g_SspiA && g_SspiA->SetContextAttributesA)) |
1007 | 0 | { |
1008 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
1009 | |
|
1010 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
1011 | 0 | } |
1012 | | |
1013 | 0 | status = g_SspiA->SetContextAttributesA(phContext, ulAttribute, pBuffer, cbBuffer); |
1014 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "SetContextAttributesA: %s (0x%08" PRIX32 ")", |
1015 | 0 | GetSecurityStatusString(status), status); |
1016 | 0 | return status; |
1017 | 0 | } |
1018 | | |
1019 | | SECURITY_STATUS SEC_ENTRY sspi_RevertSecurityContext(PCtxtHandle phContext) |
1020 | 0 | { |
1021 | 0 | SECURITY_STATUS status; |
1022 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
1023 | |
|
1024 | 0 | if (!(g_SspiW && g_SspiW->RevertSecurityContext)) |
1025 | 0 | { |
1026 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
1027 | |
|
1028 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
1029 | 0 | } |
1030 | | |
1031 | 0 | status = g_SspiW->RevertSecurityContext(phContext); |
1032 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "RevertSecurityContext: %s (0x%08" PRIX32 ")", |
1033 | 0 | GetSecurityStatusString(status), status); |
1034 | 0 | return status; |
1035 | 0 | } |
1036 | | |
1037 | | /* Message Support */ |
1038 | | |
1039 | | SECURITY_STATUS SEC_ENTRY sspi_DecryptMessage(PCtxtHandle phContext, PSecBufferDesc pMessage, |
1040 | | ULONG MessageSeqNo, PULONG pfQOP) |
1041 | 0 | { |
1042 | 0 | SECURITY_STATUS status; |
1043 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
1044 | |
|
1045 | 0 | if (!(g_SspiW && g_SspiW->DecryptMessage)) |
1046 | 0 | { |
1047 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
1048 | |
|
1049 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
1050 | 0 | } |
1051 | | |
1052 | 0 | status = g_SspiW->DecryptMessage(phContext, pMessage, MessageSeqNo, pfQOP); |
1053 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "DecryptMessage: %s (0x%08" PRIX32 ")", |
1054 | 0 | GetSecurityStatusString(status), status); |
1055 | 0 | return status; |
1056 | 0 | } |
1057 | | |
1058 | | SECURITY_STATUS SEC_ENTRY sspi_EncryptMessage(PCtxtHandle phContext, ULONG fQOP, |
1059 | | PSecBufferDesc pMessage, ULONG MessageSeqNo) |
1060 | 0 | { |
1061 | 0 | SECURITY_STATUS status; |
1062 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
1063 | |
|
1064 | 0 | if (!(g_SspiW && g_SspiW->EncryptMessage)) |
1065 | 0 | { |
1066 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
1067 | |
|
1068 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
1069 | 0 | } |
1070 | | |
1071 | 0 | status = g_SspiW->EncryptMessage(phContext, fQOP, pMessage, MessageSeqNo); |
1072 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "EncryptMessage: %s (0x%08" PRIX32 ")", |
1073 | 0 | GetSecurityStatusString(status), status); |
1074 | 0 | return status; |
1075 | 0 | } |
1076 | | |
1077 | | SECURITY_STATUS SEC_ENTRY sspi_MakeSignature(PCtxtHandle phContext, ULONG fQOP, |
1078 | | PSecBufferDesc pMessage, ULONG MessageSeqNo) |
1079 | 0 | { |
1080 | 0 | SECURITY_STATUS status; |
1081 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
1082 | |
|
1083 | 0 | if (!(g_SspiW && g_SspiW->MakeSignature)) |
1084 | 0 | { |
1085 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
1086 | |
|
1087 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
1088 | 0 | } |
1089 | | |
1090 | 0 | status = g_SspiW->MakeSignature(phContext, fQOP, pMessage, MessageSeqNo); |
1091 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "MakeSignature: %s (0x%08" PRIX32 ")", |
1092 | 0 | GetSecurityStatusString(status), status); |
1093 | 0 | return status; |
1094 | 0 | } |
1095 | | |
1096 | | SECURITY_STATUS SEC_ENTRY sspi_VerifySignature(PCtxtHandle phContext, PSecBufferDesc pMessage, |
1097 | | ULONG MessageSeqNo, PULONG pfQOP) |
1098 | 0 | { |
1099 | 0 | SECURITY_STATUS status; |
1100 | 0 | InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL); |
1101 | |
|
1102 | 0 | if (!(g_SspiW && g_SspiW->VerifySignature)) |
1103 | 0 | { |
1104 | 0 | WLog_Print(g_Log, WLOG_WARN, "Security module does not provide an implementation"); |
1105 | |
|
1106 | 0 | return SEC_E_UNSUPPORTED_FUNCTION; |
1107 | 0 | } |
1108 | | |
1109 | 0 | status = g_SspiW->VerifySignature(phContext, pMessage, MessageSeqNo, pfQOP); |
1110 | 0 | WLog_Print(g_Log, WLOG_DEBUG, "VerifySignature: %s (0x%08" PRIX32 ")", |
1111 | 0 | GetSecurityStatusString(status), status); |
1112 | 0 | return status; |
1113 | 0 | } |
1114 | | |
1115 | | #if defined(__GNUC__) |
1116 | | #pragma GCC diagnostic pop |
1117 | | #endif |
1118 | | |
1119 | | void sspi_FreeAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity) |
1120 | 0 | { |
1121 | 0 | if (!identity) |
1122 | 0 | return; |
1123 | 0 | free(identity->User); |
1124 | 0 | identity->UserLength = (UINT32)0; |
1125 | 0 | identity->User = NULL; |
1126 | |
|
1127 | 0 | free(identity->Domain); |
1128 | 0 | identity->DomainLength = (UINT32)0; |
1129 | 0 | identity->Domain = NULL; |
1130 | |
|
1131 | 0 | if (identity->PasswordLength > 0) |
1132 | 0 | memset(identity->Password, 0, identity->PasswordLength); |
1133 | 0 | free(identity->Password); |
1134 | 0 | identity->Password = NULL; |
1135 | 0 | identity->PasswordLength = (UINT32)0; |
1136 | 0 | } |