shlwapi/tests: Add some tests for memory stream.
[wine.git] / dlls / kerberos / krb5_ap.c
blob3827e5ccbc14588364ab9dffe646269b7e8aee18
1 /*
2 * Copyright 2017 Dmitry Timoshkov
3 * Copyright 2017 George Popoff
4 * Copyright 2008 Robert Shearman for CodeWeavers
5 * Copyright 2017 Hans Leidekker for CodeWeavers
7 * Kerberos5 Authentication Package
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
25 #include "wine/port.h"
27 #include <stdarg.h>
28 #ifdef HAVE_KRB5_KRB5_H
29 #include <krb5/krb5.h>
30 #endif
31 #ifdef SONAME_LIBGSSAPI_KRB5
32 # include <gssapi/gssapi.h>
33 # include <gssapi/gssapi_ext.h>
34 #endif
36 #include "ntstatus.h"
37 #define WIN32_NO_STATUS
38 #include "windef.h"
39 #include "winbase.h"
40 #include "winnls.h"
41 #include "rpc.h"
42 #include "sspi.h"
43 #include "ntsecapi.h"
44 #include "ntsecpkg.h"
45 #include "winternl.h"
46 #include "wine/heap.h"
47 #include "wine/library.h"
48 #include "wine/debug.h"
49 #include "wine/unicode.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(kerberos);
53 #define KERBEROS_MAX_BUF 12000
55 #define KERBEROS_CAPS \
56 ( SECPKG_FLAG_INTEGRITY \
57 | SECPKG_FLAG_PRIVACY \
58 | SECPKG_FLAG_TOKEN_ONLY \
59 | SECPKG_FLAG_DATAGRAM \
60 | SECPKG_FLAG_CONNECTION \
61 | SECPKG_FLAG_MULTI_REQUIRED \
62 | SECPKG_FLAG_EXTENDED_ERROR \
63 | SECPKG_FLAG_IMPERSONATION \
64 | SECPKG_FLAG_ACCEPT_WIN32_NAME \
65 | SECPKG_FLAG_NEGOTIABLE \
66 | SECPKG_FLAG_GSS_COMPATIBLE \
67 | SECPKG_FLAG_LOGON \
68 | SECPKG_FLAG_MUTUAL_AUTH \
69 | SECPKG_FLAG_DELEGATION \
70 | SECPKG_FLAG_READONLY_WITH_CHECKSUM \
71 | SECPKG_FLAG_RESTRICTED_TOKENS \
72 | SECPKG_FLAG_APPCONTAINER_CHECKS)
74 static WCHAR kerberos_name_W[] = {'K','e','r','b','e','r','o','s',0};
75 static WCHAR kerberos_comment_W[] = {'M','i','c','r','o','s','o','f','t',' ','K','e','r','b','e','r','o','s',' ','V','1','.','0',0};
76 static const SecPkgInfoW infoW =
78 KERBEROS_CAPS,
80 RPC_C_AUTHN_GSS_KERBEROS,
81 KERBEROS_MAX_BUF,
82 kerberos_name_W,
83 kerberos_comment_W
86 static ULONG kerberos_package_id;
87 static LSA_DISPATCH_TABLE lsa_dispatch;
89 #ifdef SONAME_LIBKRB5
91 static void *libkrb5_handle;
93 #define MAKE_FUNCPTR(f) static typeof(f) * p_##f
94 MAKE_FUNCPTR(krb5_cc_close);
95 MAKE_FUNCPTR(krb5_cc_default);
96 MAKE_FUNCPTR(krb5_cc_end_seq_get);
97 MAKE_FUNCPTR(krb5_cc_initialize);
98 MAKE_FUNCPTR(krb5_cc_next_cred);
99 MAKE_FUNCPTR(krb5_cc_start_seq_get);
100 MAKE_FUNCPTR(krb5_cc_store_cred);
101 MAKE_FUNCPTR(krb5_cccol_cursor_free);
102 MAKE_FUNCPTR(krb5_cccol_cursor_new);
103 MAKE_FUNCPTR(krb5_cccol_cursor_next);
104 MAKE_FUNCPTR(krb5_decode_ticket);
105 MAKE_FUNCPTR(krb5_free_context);
106 MAKE_FUNCPTR(krb5_free_cred_contents);
107 MAKE_FUNCPTR(krb5_free_principal);
108 MAKE_FUNCPTR(krb5_free_ticket);
109 MAKE_FUNCPTR(krb5_free_unparsed_name);
110 MAKE_FUNCPTR(krb5_get_init_creds_opt_alloc);
111 MAKE_FUNCPTR(krb5_get_init_creds_opt_free);
112 MAKE_FUNCPTR(krb5_get_init_creds_opt_set_out_ccache);
113 MAKE_FUNCPTR(krb5_get_init_creds_password);
114 MAKE_FUNCPTR(krb5_init_context);
115 MAKE_FUNCPTR(krb5_is_config_principal);
116 MAKE_FUNCPTR(krb5_parse_name_flags);
117 MAKE_FUNCPTR(krb5_unparse_name_flags);
118 #undef MAKE_FUNCPTR
120 static void load_krb5(void)
122 if (!(libkrb5_handle = wine_dlopen(SONAME_LIBKRB5, RTLD_NOW, NULL, 0)))
124 WARN("Failed to load %s, Kerberos support will be disabled\n", SONAME_LIBKRB5);
125 return;
128 #define LOAD_FUNCPTR(f) \
129 if (!(p_##f = wine_dlsym(libkrb5_handle, #f, NULL, 0))) \
131 ERR("Failed to load %s\n", #f); \
132 goto fail; \
135 LOAD_FUNCPTR(krb5_cc_close)
136 LOAD_FUNCPTR(krb5_cc_default)
137 LOAD_FUNCPTR(krb5_cc_end_seq_get)
138 LOAD_FUNCPTR(krb5_cc_initialize)
139 LOAD_FUNCPTR(krb5_cc_next_cred)
140 LOAD_FUNCPTR(krb5_cc_start_seq_get)
141 LOAD_FUNCPTR(krb5_cc_store_cred)
142 LOAD_FUNCPTR(krb5_cccol_cursor_free)
143 LOAD_FUNCPTR(krb5_cccol_cursor_new)
144 LOAD_FUNCPTR(krb5_cccol_cursor_next)
145 LOAD_FUNCPTR(krb5_decode_ticket)
146 LOAD_FUNCPTR(krb5_free_context)
147 LOAD_FUNCPTR(krb5_free_cred_contents)
148 LOAD_FUNCPTR(krb5_free_principal)
149 LOAD_FUNCPTR(krb5_free_ticket)
150 LOAD_FUNCPTR(krb5_free_unparsed_name)
151 LOAD_FUNCPTR(krb5_get_init_creds_opt_alloc)
152 LOAD_FUNCPTR(krb5_get_init_creds_opt_free)
153 LOAD_FUNCPTR(krb5_get_init_creds_opt_set_out_ccache)
154 LOAD_FUNCPTR(krb5_get_init_creds_password)
155 LOAD_FUNCPTR(krb5_init_context)
156 LOAD_FUNCPTR(krb5_is_config_principal)
157 LOAD_FUNCPTR(krb5_parse_name_flags)
158 LOAD_FUNCPTR(krb5_unparse_name_flags)
159 #undef LOAD_FUNCPTR
161 return;
163 fail:
164 wine_dlclose(libkrb5_handle, NULL, 0);
165 libkrb5_handle = NULL;
168 #else /* SONAME_LIBKRB5 */
170 static void load_krb5(void)
172 WARN("Kerberos support was not provided at compile time\n");
175 #endif /* SONAME_LIBKRB5 */
177 static const char *debugstr_us( const UNICODE_STRING *us )
179 if (!us) return "<null>";
180 return debugstr_wn( us->Buffer, us->Length / sizeof(WCHAR) );
183 static NTSTATUS NTAPI kerberos_LsaApInitializePackage(ULONG package_id, PLSA_DISPATCH_TABLE dispatch,
184 PLSA_STRING database, PLSA_STRING confidentiality, PLSA_STRING *package_name)
186 char *kerberos_name;
188 load_krb5();
190 kerberos_package_id = package_id;
191 lsa_dispatch = *dispatch;
193 kerberos_name = lsa_dispatch.AllocateLsaHeap(sizeof(MICROSOFT_KERBEROS_NAME_A));
194 if (!kerberos_name) return STATUS_NO_MEMORY;
196 memcpy(kerberos_name, MICROSOFT_KERBEROS_NAME_A, sizeof(MICROSOFT_KERBEROS_NAME_A));
198 *package_name = lsa_dispatch.AllocateLsaHeap(sizeof(**package_name));
199 if (!*package_name)
201 lsa_dispatch.FreeLsaHeap(kerberos_name);
202 return STATUS_NO_MEMORY;
205 RtlInitString(*package_name, kerberos_name);
207 return STATUS_SUCCESS;
210 #ifdef SONAME_LIBKRB5
212 struct ticket_info
214 ULONG count, allocated;
215 KERB_TICKET_CACHE_INFO *info;
218 static NTSTATUS krb5_error_to_status(krb5_error_code error)
220 switch (error)
222 case 0: return STATUS_SUCCESS;
223 default:
224 /* FIXME */
225 return STATUS_UNSUCCESSFUL;
229 static void free_ticket_info(struct ticket_info *info)
231 ULONG i;
233 for (i = 0; i < info->count; i++)
235 heap_free(info->info[i].RealmName.Buffer);
236 heap_free(info->info[i].ServerName.Buffer);
239 heap_free(info->info);
242 static WCHAR *utf8_to_wstr(const char *utf8)
244 int len;
245 WCHAR *wstr;
247 len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
248 wstr = heap_alloc(len * sizeof(WCHAR));
249 if (wstr)
250 MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, len);
252 return wstr;
255 static NTSTATUS copy_tickets_from_cache(krb5_context context, krb5_ccache cache, struct ticket_info *info)
257 NTSTATUS status;
258 krb5_cc_cursor cursor;
259 krb5_error_code error;
260 krb5_creds credentials;
261 krb5_ticket *ticket;
262 char *name_with_realm, *name_without_realm, *realm_name;
263 WCHAR *realm_nameW, *name_without_realmW;
265 error = p_krb5_cc_start_seq_get(context, cache, &cursor);
266 if (error) return krb5_error_to_status(error);
268 for (;;)
270 error = p_krb5_cc_next_cred(context, cache, &cursor, &credentials);
271 if (error)
273 if (error == KRB5_CC_END)
274 status = STATUS_SUCCESS;
275 else
276 status = krb5_error_to_status(error);
277 break;
280 if (p_krb5_is_config_principal(context, credentials.server))
282 p_krb5_free_cred_contents(context, &credentials);
283 continue;
286 if (info->count == info->allocated)
288 KERB_TICKET_CACHE_INFO *new_info;
289 ULONG new_allocated;
291 if (info->allocated)
293 new_allocated = info->allocated * 2;
294 new_info = heap_realloc(info->info, sizeof(*new_info) * new_allocated);
296 else
298 new_allocated = 16;
299 new_info = heap_alloc(sizeof(*new_info) * new_allocated);
301 if (!new_info)
303 p_krb5_free_cred_contents(context, &credentials);
304 status = STATUS_NO_MEMORY;
305 break;
308 info->info = new_info;
309 info->allocated = new_allocated;
312 error = p_krb5_unparse_name_flags(context, credentials.server, 0, &name_with_realm);
313 if (error)
315 p_krb5_free_cred_contents(context, &credentials);
316 status = krb5_error_to_status(error);
317 break;
320 TRACE("name_with_realm: %s\n", debugstr_a(name_with_realm));
322 error = p_krb5_unparse_name_flags(context, credentials.server,
323 KRB5_PRINCIPAL_UNPARSE_NO_REALM, &name_without_realm);
324 if (error)
326 p_krb5_free_unparsed_name(context, name_with_realm);
327 p_krb5_free_cred_contents(context, &credentials);
328 status = krb5_error_to_status(error);
329 break;
332 TRACE("name_without_realm: %s\n", debugstr_a(name_without_realm));
334 name_without_realmW = utf8_to_wstr(name_without_realm);
335 RtlInitUnicodeString(&info->info[info->count].ServerName, name_without_realmW);
337 realm_name = strchr(name_with_realm, '@');
338 if (!realm_name)
340 ERR("wrong name with realm %s\n", debugstr_a(name_with_realm));
341 realm_name = name_with_realm;
343 else
344 realm_name++;
346 /* realm_name - now contains only realm! */
348 realm_nameW = utf8_to_wstr(realm_name);
349 RtlInitUnicodeString(&info->info[info->count].RealmName, realm_nameW);
351 if (!credentials.times.starttime)
352 credentials.times.starttime = credentials.times.authtime;
354 /* TODO: if krb5_is_config_principal = true */
355 RtlSecondsSince1970ToTime(credentials.times.starttime, &info->info[info->count].StartTime);
356 RtlSecondsSince1970ToTime(credentials.times.endtime, &info->info[info->count].EndTime);
357 RtlSecondsSince1970ToTime(credentials.times.renew_till, &info->info[info->count].RenewTime);
359 info->info[info->count].TicketFlags = credentials.ticket_flags;
361 error = p_krb5_decode_ticket(&credentials.ticket, &ticket);
363 p_krb5_free_unparsed_name(context, name_with_realm);
364 p_krb5_free_unparsed_name(context, name_without_realm);
365 p_krb5_free_cred_contents(context, &credentials);
367 if (error)
369 status = krb5_error_to_status(error);
370 break;
373 info->info[info->count].EncryptionType = ticket->enc_part.enctype;
375 p_krb5_free_ticket(context, ticket);
377 info->count++;
380 p_krb5_cc_end_seq_get(context, cache, &cursor);
382 return status;
385 static inline void init_client_us(UNICODE_STRING *dst, void *client_ws, const UNICODE_STRING *src)
387 dst->Buffer = client_ws;
388 dst->Length = src->Length;
389 dst->MaximumLength = src->MaximumLength;
392 static NTSTATUS copy_to_client(PLSA_CLIENT_REQUEST lsa_req, struct ticket_info *info, void **out, ULONG *out_size)
394 NTSTATUS status;
395 ULONG i;
396 SIZE_T size, client_str_off;
397 char *client_resp, *client_ticket, *client_str;
398 KERB_QUERY_TKT_CACHE_RESPONSE resp;
400 size = sizeof(KERB_QUERY_TKT_CACHE_RESPONSE);
401 if (info->count != 0)
402 size += (info->count - 1) * sizeof(KERB_TICKET_CACHE_INFO);
404 client_str_off = size;
406 for (i = 0; i < info->count; i++)
408 size += info->info[i].RealmName.MaximumLength;
409 size += info->info[i].ServerName.MaximumLength;
412 status = lsa_dispatch.AllocateClientBuffer(lsa_req, size, (void **)&client_resp);
413 if (status != STATUS_SUCCESS) return status;
415 resp.MessageType = KerbQueryTicketCacheMessage;
416 resp.CountOfTickets = info->count;
417 size = FIELD_OFFSET(KERB_QUERY_TKT_CACHE_RESPONSE, Tickets);
418 status = lsa_dispatch.CopyToClientBuffer(lsa_req, size, client_resp, &resp);
419 if (status != STATUS_SUCCESS) goto fail;
421 if (!info->count)
423 *out = client_resp;
424 *out_size = sizeof(resp);
425 return STATUS_SUCCESS;
428 *out_size = size;
430 client_ticket = client_resp + size;
431 client_str = client_resp + client_str_off;
433 for (i = 0; i < info->count; i++)
435 KERB_TICKET_CACHE_INFO ticket;
437 ticket = info->info[i];
439 init_client_us(&ticket.RealmName, client_str, &info->info[i].RealmName);
441 size = info->info[i].RealmName.MaximumLength;
442 status = lsa_dispatch.CopyToClientBuffer(lsa_req, size, client_str, info->info[i].RealmName.Buffer);
443 if (status != STATUS_SUCCESS) goto fail;
444 client_str += size;
445 *out_size += size;
447 init_client_us(&ticket.ServerName, client_str, &info->info[i].ServerName);
449 size = info->info[i].ServerName.MaximumLength;
450 status = lsa_dispatch.CopyToClientBuffer(lsa_req, size, client_str, info->info[i].ServerName.Buffer);
451 if (status != STATUS_SUCCESS) goto fail;
452 client_str += size;
453 *out_size += size;
455 status = lsa_dispatch.CopyToClientBuffer(lsa_req, sizeof(ticket), client_ticket, &ticket);
456 if (status != STATUS_SUCCESS) goto fail;
458 client_ticket += sizeof(ticket);
459 *out_size += sizeof(ticket);
462 *out = client_resp;
463 return STATUS_SUCCESS;
465 fail:
466 lsa_dispatch.FreeClientBuffer(lsa_req, client_resp);
467 return status;
470 static NTSTATUS query_ticket_cache(PLSA_CLIENT_REQUEST lsa_req, void *in, ULONG in_len, void **out, ULONG *out_len)
472 NTSTATUS status;
473 KERB_QUERY_TKT_CACHE_REQUEST *query;
474 struct ticket_info info;
475 krb5_error_code error;
476 krb5_context context = NULL;
477 krb5_cccol_cursor cursor = NULL;
478 krb5_ccache cache;
480 if (!in || in_len != sizeof(KERB_QUERY_TKT_CACHE_REQUEST) || !out || !out_len)
481 return STATUS_INVALID_PARAMETER;
483 query = (KERB_QUERY_TKT_CACHE_REQUEST *)in;
485 if (query->LogonId.HighPart != 0 || query->LogonId.LowPart != 0)
486 return STATUS_ACCESS_DENIED;
488 info.count = 0;
489 info.allocated = 0;
490 info.info = NULL;
492 error = p_krb5_init_context(&context);
493 if (error)
495 status = krb5_error_to_status(error);
496 goto done;
499 error = p_krb5_cccol_cursor_new(context, &cursor);
500 if (error)
502 status = krb5_error_to_status(error);
503 goto done;
506 for (;;)
508 error = p_krb5_cccol_cursor_next(context, cursor, &cache);
509 if (error)
511 status = krb5_error_to_status(error);
512 goto done;
514 if (!cache) break;
516 status = copy_tickets_from_cache(context, cache, &info);
518 p_krb5_cc_close(context, cache);
520 if (status != STATUS_SUCCESS)
521 goto done;
524 status = copy_to_client(lsa_req, &info, out, out_len);
526 done:
527 if (cursor)
528 p_krb5_cccol_cursor_free(context, &cursor);
530 if (context)
531 p_krb5_free_context(context);
533 free_ticket_info(&info);
535 return status;
538 #else /* SONAME_LIBKRB5 */
540 static NTSTATUS query_ticket_cache(PLSA_CLIENT_REQUEST lsa_req, void *in, ULONG in_len, void **out, ULONG *out_len)
542 FIXME("%p,%p,%u,%p,%p: stub\n", lsa_req, in, in_len, out, out_len);
543 return STATUS_NOT_IMPLEMENTED;
546 #endif /* SONAME_LIBKRB5 */
548 static NTSTATUS NTAPI kerberos_LsaApCallPackageUntrusted(PLSA_CLIENT_REQUEST request,
549 PVOID in_buffer, PVOID client_buffer_base, ULONG in_buffer_length,
550 PVOID *out_buffer, PULONG out_buffer_length, PNTSTATUS status)
552 KERB_PROTOCOL_MESSAGE_TYPE msg;
554 TRACE("%p,%p,%p,%u,%p,%p,%p\n", request, in_buffer, client_buffer_base,
555 in_buffer_length, out_buffer, out_buffer_length, status);
557 if (!in_buffer || in_buffer_length < sizeof(msg))
558 return STATUS_INVALID_PARAMETER;
560 msg = *(KERB_PROTOCOL_MESSAGE_TYPE *)in_buffer;
562 switch (msg)
564 case KerbQueryTicketCacheMessage:
565 *status = query_ticket_cache(request, in_buffer, in_buffer_length, out_buffer, out_buffer_length);
566 break;
568 case KerbRetrieveTicketMessage:
569 FIXME("KerbRetrieveTicketMessage stub\n");
570 *status = STATUS_NOT_IMPLEMENTED;
571 break;
573 case KerbPurgeTicketCacheMessage:
574 FIXME("KerbPurgeTicketCacheMessage stub\n");
575 *status = STATUS_NOT_IMPLEMENTED;
576 break;
578 default: /* All other requests should call LsaApCallPackage */
579 WARN("%u => access denied\n", msg);
580 *status = STATUS_ACCESS_DENIED;
581 break;
584 return *status;
587 static NTSTATUS NTAPI kerberos_SpGetInfo(SecPkgInfoW *info)
589 TRACE("%p\n", info);
591 /* LSA will make a copy before forwarding the structure, so
592 * it's safe to put pointers to dynamic or constant data there.
594 *info = infoW;
596 return STATUS_SUCCESS;
599 #ifdef SONAME_LIBGSSAPI_KRB5
601 WINE_DECLARE_DEBUG_CHANNEL(winediag);
602 static void *libgssapi_krb5_handle;
604 #define MAKE_FUNCPTR(f) static typeof(f) * p##f
605 MAKE_FUNCPTR(gss_accept_sec_context);
606 MAKE_FUNCPTR(gss_acquire_cred);
607 MAKE_FUNCPTR(gss_delete_sec_context);
608 MAKE_FUNCPTR(gss_display_status);
609 MAKE_FUNCPTR(gss_get_mic);
610 MAKE_FUNCPTR(gss_import_name);
611 MAKE_FUNCPTR(gss_init_sec_context);
612 MAKE_FUNCPTR(gss_inquire_context);
613 MAKE_FUNCPTR(gss_release_buffer);
614 MAKE_FUNCPTR(gss_release_cred);
615 MAKE_FUNCPTR(gss_release_iov_buffer);
616 MAKE_FUNCPTR(gss_release_name);
617 MAKE_FUNCPTR(gss_unwrap);
618 MAKE_FUNCPTR(gss_unwrap_iov);
619 MAKE_FUNCPTR(gss_verify_mic);
620 MAKE_FUNCPTR(gss_wrap);
621 MAKE_FUNCPTR(gss_wrap_iov);
622 #undef MAKE_FUNCPTR
624 static BOOL load_gssapi_krb5(void)
626 if (!(libgssapi_krb5_handle = wine_dlopen( SONAME_LIBGSSAPI_KRB5, RTLD_NOW, NULL, 0 )))
628 ERR_(winediag)( "Failed to load libgssapi_krb5, Kerberos SSP support will not be available.\n" );
629 return FALSE;
632 #define LOAD_FUNCPTR(f) \
633 if (!(p##f = wine_dlsym( libgssapi_krb5_handle, #f, NULL, 0 ))) \
635 ERR( "Failed to load %s\n", #f ); \
636 goto fail; \
639 LOAD_FUNCPTR(gss_accept_sec_context)
640 LOAD_FUNCPTR(gss_acquire_cred)
641 LOAD_FUNCPTR(gss_delete_sec_context)
642 LOAD_FUNCPTR(gss_display_status)
643 LOAD_FUNCPTR(gss_get_mic)
644 LOAD_FUNCPTR(gss_import_name)
645 LOAD_FUNCPTR(gss_init_sec_context)
646 LOAD_FUNCPTR(gss_inquire_context)
647 LOAD_FUNCPTR(gss_release_buffer)
648 LOAD_FUNCPTR(gss_release_cred)
649 LOAD_FUNCPTR(gss_release_iov_buffer)
650 LOAD_FUNCPTR(gss_release_name)
651 LOAD_FUNCPTR(gss_unwrap)
652 LOAD_FUNCPTR(gss_unwrap_iov)
653 LOAD_FUNCPTR(gss_verify_mic)
654 LOAD_FUNCPTR(gss_wrap)
655 LOAD_FUNCPTR(gss_wrap_iov)
656 #undef LOAD_FUNCPTR
658 return TRUE;
660 fail:
661 wine_dlclose( libgssapi_krb5_handle, NULL, 0 );
662 libgssapi_krb5_handle = NULL;
663 return FALSE;
666 static void unload_gssapi_krb5(void)
668 wine_dlclose( libgssapi_krb5_handle, NULL, 0 );
669 libgssapi_krb5_handle = NULL;
672 static inline gss_cred_id_t credhandle_sspi_to_gss( LSA_SEC_HANDLE cred )
674 if (!cred) return GSS_C_NO_CREDENTIAL;
675 return (gss_cred_id_t)cred;
678 static inline void credhandle_gss_to_sspi( gss_cred_id_t handle, LSA_SEC_HANDLE *cred )
680 *cred = (LSA_SEC_HANDLE)handle;
683 static inline gss_ctx_id_t ctxthandle_sspi_to_gss( LSA_SEC_HANDLE ctxt )
685 if (!ctxt) return GSS_C_NO_CONTEXT;
686 return (gss_ctx_id_t)ctxt;
689 static inline void ctxthandle_gss_to_sspi( gss_ctx_id_t handle, LSA_SEC_HANDLE *ctxt )
691 *ctxt = (LSA_SEC_HANDLE)handle;
694 static NTSTATUS status_gss_to_sspi( OM_uint32 status )
696 switch (status)
698 case GSS_S_COMPLETE: return SEC_E_OK;
699 case GSS_S_BAD_MECH: return SEC_E_SECPKG_NOT_FOUND;
700 case GSS_S_BAD_SIG: return SEC_E_MESSAGE_ALTERED;
701 case GSS_S_NO_CRED: return SEC_E_NO_CREDENTIALS;
702 case GSS_S_NO_CONTEXT: return SEC_E_INVALID_HANDLE;
703 case GSS_S_DEFECTIVE_TOKEN: return SEC_E_INVALID_TOKEN;
704 case GSS_S_DEFECTIVE_CREDENTIAL: return SEC_E_NO_CREDENTIALS;
705 case GSS_S_CREDENTIALS_EXPIRED: return SEC_E_CONTEXT_EXPIRED;
706 case GSS_S_CONTEXT_EXPIRED: return SEC_E_CONTEXT_EXPIRED;
707 case GSS_S_BAD_QOP: return SEC_E_QOP_NOT_SUPPORTED;
708 case GSS_S_CONTINUE_NEEDED: return SEC_I_CONTINUE_NEEDED;
709 case GSS_S_DUPLICATE_TOKEN: return SEC_E_INVALID_TOKEN;
710 case GSS_S_OLD_TOKEN: return SEC_E_INVALID_TOKEN;
711 case GSS_S_UNSEQ_TOKEN: return SEC_E_OUT_OF_SEQUENCE;
712 case GSS_S_GAP_TOKEN: return SEC_E_OUT_OF_SEQUENCE;
713 case GSS_S_FAILURE: return SEC_E_INTERNAL_ERROR;
715 default:
716 FIXME( "couldn't convert status 0x%08x to NTSTATUS\n", status );
717 return SEC_E_INTERNAL_ERROR;
721 static void trace_gss_status_ex( OM_uint32 code, int type )
723 OM_uint32 ret, minor_status;
724 gss_buffer_desc buf;
725 OM_uint32 message_context = 0;
727 for (;;)
729 ret = pgss_display_status( &minor_status, code, type, GSS_C_NULL_OID, &message_context, &buf );
730 if (GSS_ERROR(ret))
732 TRACE( "gss_display_status(0x%08x,%d) returned %08x minor status %08x\n",
733 code, type, ret, minor_status );
734 return;
736 TRACE( "GSS-API error: 0x%08x: %s\n", code, debugstr_an(buf.value, buf.length) );
737 pgss_release_buffer( &minor_status, &buf );
739 if (!message_context) return;
743 static void trace_gss_status( OM_uint32 major_status, OM_uint32 minor_status )
745 if (TRACE_ON(kerberos))
747 trace_gss_status_ex( major_status, GSS_C_GSS_CODE );
748 trace_gss_status_ex( minor_status, GSS_C_MECH_CODE );
752 static void expirytime_gss_to_sspi( OM_uint32 expirytime, TimeStamp *timestamp )
754 FILETIME filetime;
755 ULARGE_INTEGER tmp;
757 GetSystemTimeAsFileTime( &filetime );
758 FileTimeToLocalFileTime( &filetime, &filetime );
759 tmp.QuadPart = ((ULONGLONG)filetime.dwLowDateTime | (ULONGLONG)filetime.dwHighDateTime << 32) + expirytime;
760 timestamp->LowPart = tmp.QuadPart;
761 timestamp->HighPart = tmp.QuadPart >> 32;
764 static NTSTATUS name_sspi_to_gss( const UNICODE_STRING *name_str, gss_name_t *name )
766 OM_uint32 ret, minor_status;
767 gss_OID type = GSS_C_NO_OID; /* FIXME: detect the appropriate value for this ourselves? */
768 gss_buffer_desc buf;
770 buf.length = WideCharToMultiByte( CP_UNIXCP, 0, name_str->Buffer, name_str->Length / sizeof(WCHAR), NULL, 0, NULL, NULL );
771 if (!(buf.value = heap_alloc( buf.length ))) return SEC_E_INSUFFICIENT_MEMORY;
772 WideCharToMultiByte( CP_UNIXCP, 0, name_str->Buffer, name_str->Length / sizeof(WCHAR), buf.value, buf.length, NULL, NULL );
774 ret = pgss_import_name( &minor_status, &buf, type, name );
775 TRACE( "gss_import_name returned %08x minor status %08x\n", ret, minor_status );
776 if (GSS_ERROR(ret)) trace_gss_status( ret, minor_status );
778 heap_free( buf.value );
779 return status_gss_to_sspi( ret );
782 static ULONG flags_isc_req_to_gss( ULONG flags )
784 ULONG ret = 0;
785 if (flags & ISC_REQ_DELEGATE) ret |= GSS_C_DELEG_FLAG;
786 if (flags & ISC_REQ_MUTUAL_AUTH) ret |= GSS_C_MUTUAL_FLAG;
787 if (flags & ISC_REQ_REPLAY_DETECT) ret |= GSS_C_REPLAY_FLAG;
788 if (flags & ISC_REQ_SEQUENCE_DETECT) ret |= GSS_C_SEQUENCE_FLAG;
789 if (flags & ISC_REQ_CONFIDENTIALITY) ret |= GSS_C_CONF_FLAG;
790 if (flags & ISC_REQ_INTEGRITY) ret |= GSS_C_INTEG_FLAG;
791 if (flags & ISC_REQ_NULL_SESSION) ret |= GSS_C_ANON_FLAG;
792 if (flags & ISC_REQ_USE_DCE_STYLE) ret |= GSS_C_DCE_STYLE;
793 if (flags & ISC_REQ_IDENTIFY) ret |= GSS_C_IDENTIFY_FLAG;
794 return ret;
797 static ULONG flags_gss_to_isc_ret( ULONG flags )
799 ULONG ret = 0;
800 if (flags & GSS_C_DELEG_FLAG) ret |= ISC_RET_DELEGATE;
801 if (flags & GSS_C_MUTUAL_FLAG) ret |= ISC_RET_MUTUAL_AUTH;
802 if (flags & GSS_C_REPLAY_FLAG) ret |= ISC_RET_REPLAY_DETECT;
803 if (flags & GSS_C_SEQUENCE_FLAG) ret |= ISC_RET_SEQUENCE_DETECT;
804 if (flags & GSS_C_CONF_FLAG) ret |= ISC_RET_CONFIDENTIALITY;
805 if (flags & GSS_C_INTEG_FLAG) ret |= ISC_RET_INTEGRITY;
806 if (flags & GSS_C_ANON_FLAG) ret |= ISC_RET_NULL_SESSION;
807 if (flags & GSS_C_DCE_STYLE) ret |= ISC_RET_USED_DCE_STYLE;
808 if (flags & GSS_C_IDENTIFY_FLAG) ret |= ISC_RET_IDENTIFY;
809 return ret;
812 static ULONG flags_gss_to_asc_ret( ULONG flags )
814 ULONG ret = 0;
815 if (flags & GSS_C_DELEG_FLAG) ret |= ASC_RET_DELEGATE;
816 if (flags & GSS_C_MUTUAL_FLAG) ret |= ASC_RET_MUTUAL_AUTH;
817 if (flags & GSS_C_REPLAY_FLAG) ret |= ASC_RET_REPLAY_DETECT;
818 if (flags & GSS_C_SEQUENCE_FLAG) ret |= ASC_RET_SEQUENCE_DETECT;
819 if (flags & GSS_C_CONF_FLAG) ret |= ASC_RET_CONFIDENTIALITY;
820 if (flags & GSS_C_INTEG_FLAG) ret |= ASC_RET_INTEGRITY;
821 if (flags & GSS_C_ANON_FLAG) ret |= ASC_RET_NULL_SESSION;
822 if (flags & GSS_C_DCE_STYLE) ret |= ASC_RET_USED_DCE_STYLE;
823 if (flags & GSS_C_IDENTIFY_FLAG) ret |= ASC_RET_IDENTIFY;
824 return ret;
827 static BOOL is_dce_style_context( gss_ctx_id_t ctxt_handle )
829 OM_uint32 ret, minor_status, flags;
830 ret = pgss_inquire_context( &minor_status, ctxt_handle, NULL, NULL, NULL, NULL, &flags, NULL, NULL );
831 return (ret == GSS_S_COMPLETE && (flags & GSS_C_DCE_STYLE));
834 static int get_buffer_index( SecBufferDesc *desc, DWORD type )
836 UINT i;
837 if (!desc) return -1;
838 for (i = 0; i < desc->cBuffers; i++)
840 if (desc->pBuffers[i].BufferType == type) return i;
842 return -1;
845 static char *get_user_at_domain( const WCHAR *user, ULONG user_len, const WCHAR *domain, ULONG domain_len )
847 int len_user, len_domain;
848 char *ret;
850 len_user = WideCharToMultiByte( CP_UNIXCP, 0, user, user_len, NULL, 0, NULL, NULL );
851 len_domain = WideCharToMultiByte( CP_UNIXCP, 0, domain, domain_len, NULL, 0, NULL, NULL );
852 if (!(ret = heap_alloc( len_user + len_domain + 2 ))) return NULL;
854 WideCharToMultiByte( CP_UNIXCP, 0, user, user_len, ret, len_user, NULL, NULL );
855 ret[len_user] = '@';
856 WideCharToMultiByte( CP_UNIXCP, 0, domain, domain_len, ret + len_user + 1, len_domain, NULL, NULL );
857 ret[len_user + len_domain + 1] = 0;
858 return ret;
861 static char *get_password( const WCHAR *passwd, ULONG passwd_len )
863 int len;
864 char *ret;
866 len = WideCharToMultiByte( CP_UNIXCP, WC_NO_BEST_FIT_CHARS, passwd, passwd_len, NULL, 0, NULL, NULL );
867 if (!(ret = heap_alloc( len + 1 ))) return NULL;
868 WideCharToMultiByte( CP_UNIXCP, 0, passwd, passwd_len, ret, len, NULL, NULL );
869 ret[len] = 0;
870 return ret;
873 static NTSTATUS init_creds( const SEC_WINNT_AUTH_IDENTITY_W *id )
875 char *user_at_domain, *password;
876 krb5_context ctx;
877 krb5_principal principal = NULL;
878 krb5_get_init_creds_opt *options = NULL;
879 krb5_ccache cache = NULL;
880 krb5_creds creds;
881 krb5_error_code err;
883 if (!id) return STATUS_SUCCESS;
884 if (id->Flags & SEC_WINNT_AUTH_IDENTITY_ANSI)
886 FIXME( "ANSI identity not supported\n" );
887 return SEC_E_UNSUPPORTED_FUNCTION;
889 if (!(user_at_domain = get_user_at_domain( id->User, id->UserLength, id->Domain, id->DomainLength )))
891 return SEC_E_INSUFFICIENT_MEMORY;
893 if (!(password = get_password( id->Password, id->PasswordLength )))
895 heap_free( user_at_domain );
896 return SEC_E_INSUFFICIENT_MEMORY;
899 if ((err = p_krb5_init_context( &ctx )))
901 heap_free( password );
902 heap_free( user_at_domain );
903 return krb5_error_to_status( err );
905 if ((err = p_krb5_parse_name_flags( ctx, user_at_domain, 0, &principal ))) goto done;
906 if ((err = p_krb5_cc_default( ctx, &cache ))) goto done;
907 if ((err = p_krb5_get_init_creds_opt_alloc( ctx, &options ))) goto done;
908 if ((err = p_krb5_get_init_creds_opt_set_out_ccache( ctx, options, cache ))) goto done;
909 if ((err = p_krb5_get_init_creds_password( ctx, &creds, principal, password, 0, NULL, 0, NULL, 0 ))) goto done;
910 if ((err = p_krb5_cc_initialize( ctx, cache, principal ))) goto done;
911 if ((err = p_krb5_cc_store_cred( ctx, cache, &creds ))) goto done;
913 TRACE( "success\n" );
914 p_krb5_free_cred_contents( ctx, &creds );
916 done:
917 if (cache) p_krb5_cc_close( ctx, cache );
918 if (principal) p_krb5_free_principal( ctx, principal );
919 if (options) p_krb5_get_init_creds_opt_free( ctx, options );
920 p_krb5_free_context( ctx );
921 heap_free( user_at_domain );
922 heap_free( password );
924 return krb5_error_to_status( err );
927 static NTSTATUS acquire_credentials_handle( UNICODE_STRING *principal_us, gss_cred_usage_t cred_usage,
928 LSA_SEC_HANDLE *credential, TimeStamp *ts_expiry )
930 OM_uint32 ret, minor_status, expiry_time;
931 gss_name_t principal = GSS_C_NO_NAME;
932 gss_cred_id_t cred_handle;
933 NTSTATUS status;
935 if (principal_us && ((status = name_sspi_to_gss( principal_us, &principal )) != SEC_E_OK)) return status;
937 ret = pgss_acquire_cred( &minor_status, principal, GSS_C_INDEFINITE, GSS_C_NULL_OID_SET, cred_usage,
938 &cred_handle, NULL, &expiry_time );
939 TRACE( "gss_acquire_cred returned %08x minor status %08x\n", ret, minor_status );
940 if (GSS_ERROR(ret)) trace_gss_status( ret, minor_status );
941 if (ret == GSS_S_COMPLETE)
943 credhandle_gss_to_sspi( cred_handle, credential );
944 expirytime_gss_to_sspi( expiry_time, ts_expiry );
947 if (principal != GSS_C_NO_NAME) pgss_release_name( &minor_status, &principal );
949 return status_gss_to_sspi( ret );
951 #endif /* SONAME_LIBGSSAPI_KRB5 */
953 static NTSTATUS NTAPI kerberos_SpAcquireCredentialsHandle(
954 UNICODE_STRING *principal_us, ULONG credential_use, LUID *logon_id, void *auth_data,
955 void *get_key_fn, void *get_key_arg, LSA_SEC_HANDLE *credential, TimeStamp *ts_expiry )
957 #ifdef SONAME_LIBGSSAPI_KRB5
958 gss_cred_usage_t cred_usage;
959 NTSTATUS status;
961 TRACE( "(%s 0x%08x %p %p %p %p %p %p)\n", debugstr_us(principal_us), credential_use,
962 logon_id, auth_data, get_key_fn, get_key_arg, credential, ts_expiry );
964 switch (credential_use)
966 case SECPKG_CRED_INBOUND:
967 cred_usage = GSS_C_ACCEPT;
968 break;
970 case SECPKG_CRED_OUTBOUND:
971 if ((status = init_creds( auth_data )) != STATUS_SUCCESS) return status;
972 cred_usage = GSS_C_INITIATE;
973 break;
975 case SECPKG_CRED_BOTH:
976 cred_usage = GSS_C_BOTH;
977 break;
979 default:
980 return SEC_E_UNKNOWN_CREDENTIALS;
983 return acquire_credentials_handle( principal_us, cred_usage, credential, ts_expiry );
984 #else
985 FIXME( "(%s 0x%08x %p %p %p %p %p %p)\n", debugstr_us(principal_us), credential_use,
986 logon_id, auth_data, get_key_fn, get_key_arg, credential, ts_expiry );
987 FIXME( "Wine was built without Kerberos support.\n" );
988 return SEC_E_UNSUPPORTED_FUNCTION;
989 #endif
992 static NTSTATUS NTAPI kerberos_SpFreeCredentialsHandle( LSA_SEC_HANDLE credential )
994 #ifdef SONAME_LIBGSSAPI_KRB5
995 OM_uint32 ret, minor_status;
996 gss_cred_id_t cred_handle;
998 TRACE( "(%lx)\n", credential );
1000 if (!credential) return SEC_E_INVALID_HANDLE;
1001 if (!(cred_handle = credhandle_sspi_to_gss( credential ))) return SEC_E_OK;
1003 ret = pgss_release_cred( &minor_status, &cred_handle );
1004 TRACE( "gss_release_cred returned %08x minor status %08x\n", ret, minor_status );
1005 if (GSS_ERROR(ret)) trace_gss_status( ret, minor_status );
1007 return status_gss_to_sspi( ret );
1008 #else
1009 FIXME( "(%lx)\n", credential );
1010 return SEC_E_UNSUPPORTED_FUNCTION;
1011 #endif
1014 static NTSTATUS NTAPI kerberos_SpInitLsaModeContext( LSA_SEC_HANDLE credential, LSA_SEC_HANDLE context,
1015 UNICODE_STRING *target_name, ULONG context_req, ULONG target_data_rep, SecBufferDesc *input,
1016 LSA_SEC_HANDLE *new_context, SecBufferDesc *output, ULONG *context_attr, TimeStamp *ts_expiry,
1017 BOOLEAN *mapped_context, SecBuffer *context_data )
1019 #ifdef SONAME_LIBGSSAPI_KRB5
1020 static const ULONG supported = ISC_REQ_CONFIDENTIALITY | ISC_REQ_INTEGRITY | ISC_REQ_SEQUENCE_DETECT |
1021 ISC_REQ_REPLAY_DETECT | ISC_REQ_MUTUAL_AUTH | ISC_REQ_USE_DCE_STYLE |
1022 ISC_REQ_IDENTIFY | ISC_REQ_CONNECTION;
1023 OM_uint32 ret, minor_status, ret_flags = 0, expiry_time, req_flags = flags_isc_req_to_gss( context_req );
1024 gss_cred_id_t cred_handle;
1025 gss_ctx_id_t ctxt_handle;
1026 gss_buffer_desc input_token, output_token;
1027 gss_name_t target = GSS_C_NO_NAME;
1028 NTSTATUS status;
1029 int idx;
1031 TRACE( "(%lx %lx %s 0x%08x %u %p %p %p %p %p %p %p)\n", credential, context, debugstr_us(target_name),
1032 context_req, target_data_rep, input, new_context, output, context_attr, ts_expiry,
1033 mapped_context, context_data );
1034 if (context_req & ~supported)
1035 FIXME( "flags 0x%08x not supported\n", context_req & ~supported );
1037 if (!context && !input && !credential) return SEC_E_INVALID_HANDLE;
1038 cred_handle = credhandle_sspi_to_gss( credential );
1039 ctxt_handle = ctxthandle_sspi_to_gss( context );
1041 if ((idx = get_buffer_index( input, SECBUFFER_TOKEN )) == -1) input_token.length = 0;
1042 else
1044 input_token.length = input->pBuffers[idx].cbBuffer;
1045 input_token.value = input->pBuffers[idx].pvBuffer;
1048 if ((idx = get_buffer_index( output, SECBUFFER_TOKEN )) == -1) return SEC_E_INVALID_TOKEN;
1049 output_token.length = 0;
1050 output_token.value = NULL;
1052 if (target_name && ((status = name_sspi_to_gss( target_name, &target )) != SEC_E_OK)) return status;
1054 ret = pgss_init_sec_context( &minor_status, cred_handle, &ctxt_handle, target, GSS_C_NO_OID, req_flags, 0,
1055 GSS_C_NO_CHANNEL_BINDINGS, &input_token, NULL, &output_token, &ret_flags,
1056 &expiry_time );
1057 TRACE( "gss_init_sec_context returned %08x minor status %08x ret_flags %08x\n", ret, minor_status, ret_flags );
1058 if (GSS_ERROR(ret)) trace_gss_status( ret, minor_status );
1059 if (ret == GSS_S_COMPLETE || ret == GSS_S_CONTINUE_NEEDED)
1061 if (output_token.length > output->pBuffers[idx].cbBuffer) /* FIXME: check if larger buffer exists */
1063 TRACE( "buffer too small %lu > %u\n", (SIZE_T)output_token.length, output->pBuffers[idx].cbBuffer );
1064 pgss_release_buffer( &minor_status, &output_token );
1065 pgss_delete_sec_context( &minor_status, &ctxt_handle, GSS_C_NO_BUFFER );
1066 return SEC_E_INCOMPLETE_MESSAGE;
1068 output->pBuffers[idx].cbBuffer = output_token.length;
1069 memcpy( output->pBuffers[idx].pvBuffer, output_token.value, output_token.length );
1070 pgss_release_buffer( &minor_status, &output_token );
1072 ctxthandle_gss_to_sspi( ctxt_handle, new_context );
1073 if (context_attr) *context_attr = flags_gss_to_isc_ret( ret_flags );
1074 expirytime_gss_to_sspi( expiry_time, ts_expiry );
1077 if (target != GSS_C_NO_NAME) pgss_release_name( &minor_status, &target );
1079 /* we do support user mode SSP/AP functions */
1080 *mapped_context = TRUE;
1081 /* FIXME: initialize context_data */
1083 return status_gss_to_sspi( ret );
1084 #else
1085 FIXME( "(%lx %lx %s 0x%08x %u %p %p %p %p %p %p %p)\n", credential, context, debugstr_us(target_name),
1086 context_req, target_data_rep, input, new_context, output, context_attr, ts_expiry,
1087 mapped_context, context_data );
1088 return SEC_E_UNSUPPORTED_FUNCTION;
1089 #endif
1092 static NTSTATUS NTAPI kerberos_SpAcceptLsaModeContext( LSA_SEC_HANDLE credential, LSA_SEC_HANDLE context,
1093 SecBufferDesc *input, ULONG context_req, ULONG target_data_rep, LSA_SEC_HANDLE *new_context,
1094 SecBufferDesc *output, ULONG *context_attr, TimeStamp *ts_expiry, BOOLEAN *mapped_context, SecBuffer *context_data )
1096 #ifdef SONAME_LIBGSSAPI_KRB5
1097 OM_uint32 ret, minor_status, ret_flags = 0, expiry_time;
1098 gss_cred_id_t cred_handle;
1099 gss_ctx_id_t ctxt_handle;
1100 gss_buffer_desc input_token, output_token;
1101 gss_name_t target = GSS_C_NO_NAME;
1102 int idx;
1104 TRACE( "(%lx %lx 0x%08x %u %p %p %p %p %p %p %p)\n", credential, context, context_req,
1105 target_data_rep, input, new_context, output, context_attr, ts_expiry,
1106 mapped_context, context_data );
1107 if (context_req) FIXME( "ignoring flags 0x%08x\n", context_req );
1109 if (!context && !input && !credential) return SEC_E_INVALID_HANDLE;
1110 cred_handle = credhandle_sspi_to_gss( credential );
1111 ctxt_handle = ctxthandle_sspi_to_gss( context );
1113 if (!input) input_token.length = 0;
1114 else
1116 if ((idx = get_buffer_index( input, SECBUFFER_TOKEN )) == -1) return SEC_E_INVALID_TOKEN;
1117 input_token.length = input->pBuffers[idx].cbBuffer;
1118 input_token.value = input->pBuffers[idx].pvBuffer;
1121 if ((idx = get_buffer_index( output, SECBUFFER_TOKEN )) == -1) return SEC_E_INVALID_TOKEN;
1122 output_token.length = 0;
1123 output_token.value = NULL;
1125 ret = pgss_accept_sec_context( &minor_status, &ctxt_handle, cred_handle, &input_token, GSS_C_NO_CHANNEL_BINDINGS,
1126 &target, NULL, &output_token, &ret_flags, &expiry_time, NULL );
1127 TRACE( "gss_accept_sec_context returned %08x minor status %08x ret_flags %08x\n", ret, minor_status, ret_flags );
1128 if (GSS_ERROR(ret)) trace_gss_status( ret, minor_status );
1129 if (ret == GSS_S_COMPLETE || ret == GSS_S_CONTINUE_NEEDED)
1131 if (output_token.length > output->pBuffers[idx].cbBuffer) /* FIXME: check if larger buffer exists */
1133 TRACE( "buffer too small %lu > %u\n", (SIZE_T)output_token.length, output->pBuffers[idx].cbBuffer );
1134 pgss_release_buffer( &minor_status, &output_token );
1135 pgss_delete_sec_context( &minor_status, &ctxt_handle, GSS_C_NO_BUFFER );
1136 return SEC_E_BUFFER_TOO_SMALL;
1138 output->pBuffers[idx].cbBuffer = output_token.length;
1139 memcpy( output->pBuffers[idx].pvBuffer, output_token.value, output_token.length );
1140 pgss_release_buffer( &minor_status, &output_token );
1142 ctxthandle_gss_to_sspi( ctxt_handle, new_context );
1143 if (context_attr) *context_attr = flags_gss_to_asc_ret( ret_flags );
1144 expirytime_gss_to_sspi( expiry_time, ts_expiry );
1147 /* we do support user mode SSP/AP functions */
1148 *mapped_context = TRUE;
1149 /* FIXME: initialize context_data */
1151 return status_gss_to_sspi( ret );
1152 #else
1153 FIXME( "(%lx %lx 0x%08x %u %p %p %p %p %p %p %p)\n", credential, context, context_req,
1154 target_data_rep, input, new_context, output, context_attr, ts_expiry,
1155 mapped_context, context_data );
1156 return SEC_E_UNSUPPORTED_FUNCTION;
1157 #endif
1160 static NTSTATUS NTAPI kerberos_SpDeleteContext( LSA_SEC_HANDLE context )
1162 #ifdef SONAME_LIBGSSAPI_KRB5
1163 OM_uint32 ret, minor_status;
1164 gss_ctx_id_t ctxt_handle;
1166 TRACE( "(%lx)\n", context );
1167 if (!context) return SEC_E_INVALID_HANDLE;
1168 if (!(ctxt_handle = ctxthandle_sspi_to_gss( context ))) return SEC_E_OK;
1170 ret = pgss_delete_sec_context( &minor_status, &ctxt_handle, GSS_C_NO_BUFFER );
1171 TRACE( "gss_delete_sec_context returned %08x minor status %08x\n", ret, minor_status );
1172 if (GSS_ERROR(ret)) trace_gss_status( ret, minor_status );
1174 return status_gss_to_sspi( ret );
1175 #else
1176 FIXME( "(%lx)\n", context );
1177 return SEC_E_UNSUPPORTED_FUNCTION;
1178 #endif
1181 static SecPkgInfoW *build_package_info( const SecPkgInfoW *info )
1183 SecPkgInfoW *ret;
1184 DWORD size_name = (strlenW(info->Name) + 1) * sizeof(WCHAR);
1185 DWORD size_comment = (strlenW(info->Comment) + 1) * sizeof(WCHAR);
1187 if (!(ret = heap_alloc( sizeof(*ret) + size_name + size_comment ))) return NULL;
1188 ret->fCapabilities = info->fCapabilities;
1189 ret->wVersion = info->wVersion;
1190 ret->wRPCID = info->wRPCID;
1191 ret->cbMaxToken = info->cbMaxToken;
1192 ret->Name = (SEC_WCHAR *)(ret + 1);
1193 memcpy( ret->Name, info->Name, size_name );
1194 ret->Comment = (SEC_WCHAR *)((char *)ret->Name + size_name);
1195 memcpy( ret->Comment, info->Comment, size_comment );
1196 return ret;
1199 static NTSTATUS NTAPI kerberos_SpQueryContextAttributes( LSA_SEC_HANDLE context, ULONG attribute, void *buffer )
1201 TRACE( "(%lx %u %p)\n", context, attribute, buffer );
1203 if (!context) return SEC_E_INVALID_HANDLE;
1205 switch (attribute)
1207 #define X(x) case (x) : FIXME(#x" stub\n"); break
1208 X(SECPKG_ATTR_ACCESS_TOKEN);
1209 X(SECPKG_ATTR_AUTHORITY);
1210 X(SECPKG_ATTR_DCE_INFO);
1211 X(SECPKG_ATTR_KEY_INFO);
1212 X(SECPKG_ATTR_LIFESPAN);
1213 X(SECPKG_ATTR_NAMES);
1214 X(SECPKG_ATTR_NATIVE_NAMES);
1215 X(SECPKG_ATTR_PACKAGE_INFO);
1216 X(SECPKG_ATTR_PASSWORD_EXPIRY);
1217 X(SECPKG_ATTR_SESSION_KEY);
1218 X(SECPKG_ATTR_STREAM_SIZES);
1219 X(SECPKG_ATTR_TARGET_INFORMATION);
1220 case SECPKG_ATTR_SIZES:
1222 SecPkgContext_Sizes *sizes = (SecPkgContext_Sizes *)buffer;
1223 ULONG size_max_signature = 37, size_security_trailer = 49;
1224 #ifdef SONAME_LIBGSSAPI_KRB5
1225 gss_ctx_id_t ctxt_handle;
1227 if (!(ctxt_handle = ctxthandle_sspi_to_gss( context ))) return SEC_E_INVALID_HANDLE;
1228 if (is_dce_style_context( ctxt_handle ))
1230 size_max_signature = 28;
1231 size_security_trailer = 76;
1233 #endif
1234 sizes->cbMaxToken = KERBEROS_MAX_BUF;
1235 sizes->cbMaxSignature = size_max_signature;
1236 sizes->cbBlockSize = 1;
1237 sizes->cbSecurityTrailer = size_security_trailer;
1238 return SEC_E_OK;
1240 case SECPKG_ATTR_NEGOTIATION_INFO:
1242 SecPkgContext_NegotiationInfoW *info = (SecPkgContext_NegotiationInfoW *)buffer;
1243 if (!(info->PackageInfo = build_package_info( &infoW ))) return SEC_E_INSUFFICIENT_MEMORY;
1244 info->NegotiationState = SECPKG_NEGOTIATION_COMPLETE;
1245 return SEC_E_OK;
1247 #undef X
1248 default:
1249 FIXME( "unknown attribute %u\n", attribute );
1250 break;
1253 return SEC_E_UNSUPPORTED_FUNCTION;
1256 static NTSTATUS NTAPI kerberos_SpInitialize(ULONG_PTR package_id, SECPKG_PARAMETERS *params,
1257 LSA_SECPKG_FUNCTION_TABLE *lsa_function_table)
1259 TRACE("%lu,%p,%p\n", package_id, params, lsa_function_table);
1261 #ifdef SONAME_LIBGSSAPI_KRB5
1262 if (load_gssapi_krb5()) return STATUS_SUCCESS;
1263 #endif
1265 return STATUS_UNSUCCESSFUL;
1268 static NTSTATUS NTAPI kerberos_SpShutdown(void)
1270 TRACE("\n");
1272 #ifdef SONAME_LIBGSSAPI_KRB5
1273 unload_gssapi_krb5();
1274 #endif
1276 return STATUS_SUCCESS;
1279 static SECPKG_FUNCTION_TABLE kerberos_table =
1281 kerberos_LsaApInitializePackage, /* InitializePackage */
1282 NULL, /* LsaLogonUser */
1283 NULL, /* CallPackage */
1284 NULL, /* LogonTerminated */
1285 kerberos_LsaApCallPackageUntrusted, /* CallPackageUntrusted */
1286 NULL, /* CallPackagePassthrough */
1287 NULL, /* LogonUserEx */
1288 NULL, /* LogonUserEx2 */
1289 kerberos_SpInitialize,
1290 kerberos_SpShutdown,
1291 kerberos_SpGetInfo,
1292 NULL, /* AcceptCredentials */
1293 kerberos_SpAcquireCredentialsHandle,
1294 NULL, /* SpQueryCredentialsAttributes */
1295 kerberos_SpFreeCredentialsHandle,
1296 NULL, /* SaveCredentials */
1297 NULL, /* GetCredentials */
1298 NULL, /* DeleteCredentials */
1299 kerberos_SpInitLsaModeContext,
1300 kerberos_SpAcceptLsaModeContext,
1301 kerberos_SpDeleteContext,
1302 NULL, /* ApplyControlToken */
1303 NULL, /* GetUserInfo */
1304 NULL, /* GetExtendedInformation */
1305 kerberos_SpQueryContextAttributes,
1306 NULL, /* SpAddCredentials */
1307 NULL, /* SetExtendedInformation */
1308 NULL, /* SetContextAttributes */
1309 NULL, /* SetCredentialsAttributes */
1310 NULL, /* ChangeAccountPassword */
1311 NULL, /* QueryMetaData */
1312 NULL, /* ExchangeMetaData */
1313 NULL, /* GetCredUIContext */
1314 NULL, /* UpdateCredentials */
1315 NULL, /* ValidateTargetInfo */
1316 NULL, /* PostLogonUser */
1319 NTSTATUS NTAPI SpLsaModeInitialize(ULONG lsa_version, PULONG package_version,
1320 PSECPKG_FUNCTION_TABLE *table, PULONG table_count)
1322 TRACE("%#x,%p,%p,%p\n", lsa_version, package_version, table, table_count);
1324 *package_version = SECPKG_INTERFACE_VERSION;
1325 *table = &kerberos_table;
1326 *table_count = 1;
1328 return STATUS_SUCCESS;
1331 static NTSTATUS NTAPI kerberos_SpInstanceInit(ULONG version, SECPKG_DLL_FUNCTIONS *dll_function_table, void **user_functions)
1333 TRACE("%#x,%p,%p\n", version, dll_function_table, user_functions);
1335 return STATUS_SUCCESS;
1338 static NTSTATUS SEC_ENTRY kerberos_SpMakeSignature( LSA_SEC_HANDLE context, ULONG quality_of_protection,
1339 SecBufferDesc *message, ULONG message_seq_no )
1341 #ifdef SONAME_LIBGSSAPI_KRB5
1342 OM_uint32 ret, minor_status;
1343 gss_buffer_desc data_buffer, token_buffer;
1344 gss_ctx_id_t ctxt_handle;
1345 int data_idx, token_idx;
1347 TRACE( "(%lx 0x%08x %p %u)\n", context, quality_of_protection, message, message_seq_no );
1348 if (quality_of_protection) FIXME( "ignoring quality_of_protection 0x%08x\n", quality_of_protection );
1349 if (message_seq_no) FIXME( "ignoring message_seq_no %u\n", message_seq_no );
1351 if (!context) return SEC_E_INVALID_HANDLE;
1352 ctxt_handle = ctxthandle_sspi_to_gss( context );
1354 /* FIXME: multiple data buffers, read-only buffers */
1355 if ((data_idx = get_buffer_index( message, SECBUFFER_DATA )) == -1) return SEC_E_INVALID_TOKEN;
1356 data_buffer.length = message->pBuffers[data_idx].cbBuffer;
1357 data_buffer.value = message->pBuffers[data_idx].pvBuffer;
1359 if ((token_idx = get_buffer_index( message, SECBUFFER_TOKEN )) == -1) return SEC_E_INVALID_TOKEN;
1360 token_buffer.length = 0;
1361 token_buffer.value = NULL;
1363 ret = pgss_get_mic( &minor_status, ctxt_handle, GSS_C_QOP_DEFAULT, &data_buffer, &token_buffer );
1364 TRACE( "gss_get_mic returned %08x minor status %08x\n", ret, minor_status );
1365 if (GSS_ERROR(ret)) trace_gss_status( ret, minor_status );
1366 if (ret == GSS_S_COMPLETE)
1368 memcpy( message->pBuffers[token_idx].pvBuffer, token_buffer.value, token_buffer.length );
1369 message->pBuffers[token_idx].cbBuffer = token_buffer.length;
1370 pgss_release_buffer( &minor_status, &token_buffer );
1373 return status_gss_to_sspi( ret );
1374 #else
1375 FIXME( "(%lx 0x%08x %p %u)\n", context, quality_of_protection, message, message_seq_no );
1376 return SEC_E_UNSUPPORTED_FUNCTION;
1377 #endif
1380 static NTSTATUS NTAPI kerberos_SpVerifySignature( LSA_SEC_HANDLE context, SecBufferDesc *message,
1381 ULONG message_seq_no, ULONG *quality_of_protection )
1383 #ifdef SONAME_LIBGSSAPI_KRB5
1384 OM_uint32 ret, minor_status;
1385 gss_buffer_desc data_buffer, token_buffer;
1386 gss_ctx_id_t ctxt_handle;
1387 int data_idx, token_idx;
1389 TRACE( "(%lx %p %u %p)\n", context, message, message_seq_no, quality_of_protection );
1390 if (message_seq_no) FIXME( "ignoring message_seq_no %u\n", message_seq_no );
1392 if (!context) return SEC_E_INVALID_HANDLE;
1393 ctxt_handle = ctxthandle_sspi_to_gss( context );
1395 if ((data_idx = get_buffer_index( message, SECBUFFER_DATA )) == -1) return SEC_E_INVALID_TOKEN;
1396 data_buffer.length = message->pBuffers[data_idx].cbBuffer;
1397 data_buffer.value = message->pBuffers[data_idx].pvBuffer;
1399 if ((token_idx = get_buffer_index( message, SECBUFFER_TOKEN )) == -1) return SEC_E_INVALID_TOKEN;
1400 token_buffer.length = message->pBuffers[token_idx].cbBuffer;
1401 token_buffer.value = message->pBuffers[token_idx].pvBuffer;
1403 ret = pgss_verify_mic( &minor_status, ctxt_handle, &data_buffer, &token_buffer, NULL );
1404 TRACE( "gss_verify_mic returned %08x minor status %08x\n", ret, minor_status );
1405 if (GSS_ERROR(ret)) trace_gss_status( ret, minor_status );
1406 if (ret == GSS_S_COMPLETE && quality_of_protection) *quality_of_protection = 0;
1408 return status_gss_to_sspi( ret );
1409 #else
1410 FIXME( "(%lx %p %u %p)\n", context, message, message_seq_no, quality_of_protection );
1411 return SEC_E_UNSUPPORTED_FUNCTION;
1412 #endif
1415 #ifdef SONAME_LIBGSSAPI_KRB5
1416 static NTSTATUS seal_message_iov( gss_ctx_id_t ctxt_handle, SecBufferDesc *message )
1418 gss_iov_buffer_desc iov[4];
1419 OM_uint32 ret, minor_status;
1420 int token_idx, data_idx, conf_state;
1422 /* FIXME: multiple data buffers, read-only buffers */
1423 if ((data_idx = get_buffer_index( message, SECBUFFER_DATA )) == -1) return SEC_E_INVALID_TOKEN;
1424 if ((token_idx = get_buffer_index( message, SECBUFFER_TOKEN )) == -1) return SEC_E_INVALID_TOKEN;
1426 iov[0].type = GSS_IOV_BUFFER_TYPE_SIGN_ONLY | GSS_IOV_BUFFER_FLAG_ALLOCATE;
1427 iov[0].buffer.length = 0;
1428 iov[0].buffer.value = NULL;
1430 iov[1].type = GSS_IOV_BUFFER_TYPE_DATA;
1431 iov[1].buffer.length = message->pBuffers[data_idx].cbBuffer;
1432 iov[1].buffer.value = message->pBuffers[data_idx].pvBuffer;
1434 iov[2].type = GSS_IOV_BUFFER_TYPE_SIGN_ONLY | GSS_IOV_BUFFER_FLAG_ALLOCATE;
1435 iov[2].buffer.length = 0;
1436 iov[2].buffer.value = NULL;
1438 iov[3].type = GSS_IOV_BUFFER_TYPE_HEADER | GSS_IOV_BUFFER_FLAG_ALLOCATE;
1439 iov[3].buffer.length = 0;
1440 iov[3].buffer.value = NULL;
1442 ret = pgss_wrap_iov( &minor_status, ctxt_handle, 1, GSS_C_QOP_DEFAULT, &conf_state, iov, 4 );
1443 TRACE( "gss_wrap_iov returned %08x minor status %08x\n", ret, minor_status );
1444 if (GSS_ERROR(ret)) trace_gss_status( ret, minor_status );
1445 if (ret == GSS_S_COMPLETE)
1447 memcpy( message->pBuffers[token_idx].pvBuffer, iov[3].buffer.value, iov[3].buffer.length );
1448 message->pBuffers[token_idx].cbBuffer = iov[3].buffer.length;
1449 pgss_release_iov_buffer( &minor_status, iov, 4 );
1452 return status_gss_to_sspi( ret );
1455 static NTSTATUS seal_message( gss_ctx_id_t ctxt_handle, SecBufferDesc *message )
1457 gss_buffer_desc input, output;
1458 OM_uint32 ret, minor_status;
1459 int token_idx, data_idx, conf_state;
1461 /* FIXME: multiple data buffers, read-only buffers */
1462 if ((data_idx = get_buffer_index( message, SECBUFFER_DATA )) == -1) return SEC_E_INVALID_TOKEN;
1463 if ((token_idx = get_buffer_index( message, SECBUFFER_TOKEN )) == -1) return SEC_E_INVALID_TOKEN;
1465 input.length = message->pBuffers[data_idx].cbBuffer;
1466 input.value = message->pBuffers[data_idx].pvBuffer;
1468 ret = pgss_wrap( &minor_status, ctxt_handle, 1, GSS_C_QOP_DEFAULT, &input, &conf_state, &output );
1469 TRACE( "gss_wrap returned %08x minor status %08x\n", ret, minor_status );
1470 if (GSS_ERROR(ret)) trace_gss_status( ret, minor_status );
1471 if (ret == GSS_S_COMPLETE)
1473 DWORD len_data = message->pBuffers[data_idx].cbBuffer, len_token = message->pBuffers[token_idx].cbBuffer;
1474 if (len_token < output.length - len_data)
1476 TRACE( "buffer too small %lu > %u\n", (SIZE_T)output.length - len_data, len_token );
1477 pgss_release_buffer( &minor_status, &output );
1478 return SEC_E_BUFFER_TOO_SMALL;
1480 memcpy( message->pBuffers[data_idx].pvBuffer, output.value, len_data );
1481 memcpy( message->pBuffers[token_idx].pvBuffer, (char *)output.value + len_data, output.length - len_data );
1482 message->pBuffers[token_idx].cbBuffer = output.length - len_data;
1483 pgss_release_buffer( &minor_status, &output );
1486 return status_gss_to_sspi( ret );
1488 #endif
1490 static NTSTATUS NTAPI kerberos_SpSealMessage( LSA_SEC_HANDLE context, ULONG quality_of_protection,
1491 SecBufferDesc *message, ULONG message_seq_no )
1493 #ifdef SONAME_LIBGSSAPI_KRB5
1494 gss_ctx_id_t ctxt_handle;
1496 TRACE( "(%lx 0x%08x %p %u)\n", context, quality_of_protection, message, message_seq_no );
1497 if (quality_of_protection)
1499 FIXME( "flags %08x not supported\n", quality_of_protection );
1500 return SEC_E_UNSUPPORTED_FUNCTION;
1502 if (message_seq_no) FIXME( "ignoring message_seq_no %u\n", message_seq_no );
1504 if (!context) return SEC_E_INVALID_HANDLE;
1505 ctxt_handle = ctxthandle_sspi_to_gss( context );
1507 if (is_dce_style_context( ctxt_handle )) return seal_message_iov( ctxt_handle, message );
1508 return seal_message( ctxt_handle, message );
1509 #else
1510 FIXME( "(%lx 0x%08x %p %u)\n", context, quality_of_protection, message, message_seq_no );
1511 return SEC_E_UNSUPPORTED_FUNCTION;
1512 #endif
1515 #ifdef SONAME_LIBGSSAPI_KRB5
1516 static NTSTATUS unseal_message_iov( gss_ctx_id_t ctxt_handle, SecBufferDesc *message, ULONG *quality_of_protection )
1518 gss_iov_buffer_desc iov[4];
1519 OM_uint32 ret, minor_status;
1520 int token_idx, data_idx, conf_state;
1522 if ((data_idx = get_buffer_index( message, SECBUFFER_DATA )) == -1) return SEC_E_INVALID_TOKEN;
1523 if ((token_idx = get_buffer_index( message, SECBUFFER_TOKEN )) == -1) return SEC_E_INVALID_TOKEN;
1525 iov[0].type = GSS_IOV_BUFFER_TYPE_SIGN_ONLY;
1526 iov[0].buffer.length = 0;
1527 iov[0].buffer.value = NULL;
1529 iov[1].type = GSS_IOV_BUFFER_TYPE_DATA;
1530 iov[1].buffer.length = message->pBuffers[data_idx].cbBuffer;
1531 iov[1].buffer.value = message->pBuffers[data_idx].pvBuffer;
1533 iov[2].type = GSS_IOV_BUFFER_TYPE_SIGN_ONLY;
1534 iov[2].buffer.length = 0;
1535 iov[2].buffer.value = NULL;
1537 iov[3].type = GSS_IOV_BUFFER_TYPE_HEADER;
1538 iov[3].buffer.length = message->pBuffers[token_idx].cbBuffer;
1539 iov[3].buffer.value = message->pBuffers[token_idx].pvBuffer;
1541 ret = pgss_unwrap_iov( &minor_status, ctxt_handle, &conf_state, NULL, iov, 4 );
1542 TRACE( "gss_unwrap_iov returned %08x minor status %08x\n", ret, minor_status );
1543 if (GSS_ERROR(ret)) trace_gss_status( ret, minor_status );
1544 if (ret == GSS_S_COMPLETE && quality_of_protection)
1546 *quality_of_protection = (conf_state ? 0 : SECQOP_WRAP_NO_ENCRYPT);
1548 return status_gss_to_sspi( ret );
1551 static NTSTATUS unseal_message( gss_ctx_id_t ctxt_handle, SecBufferDesc *message, ULONG *quality_of_protection )
1553 gss_buffer_desc input, output;
1554 OM_uint32 ret, minor_status;
1555 int token_idx, data_idx, conf_state;
1556 DWORD len_data, len_token;
1558 if ((data_idx = get_buffer_index( message, SECBUFFER_DATA )) == -1) return SEC_E_INVALID_TOKEN;
1559 if ((token_idx = get_buffer_index( message, SECBUFFER_TOKEN )) == -1) return SEC_E_INVALID_TOKEN;
1561 len_data = message->pBuffers[data_idx].cbBuffer;
1562 len_token = message->pBuffers[token_idx].cbBuffer;
1564 input.length = len_data + len_token;
1565 if (!(input.value = heap_alloc( input.length ))) return SEC_E_INSUFFICIENT_MEMORY;
1566 memcpy( input.value, message->pBuffers[data_idx].pvBuffer, len_data );
1567 memcpy( (char *)input.value + len_data, message->pBuffers[token_idx].pvBuffer, len_token );
1569 ret = pgss_unwrap( &minor_status, ctxt_handle, &input, &output, &conf_state, NULL );
1570 heap_free( input.value );
1571 TRACE( "gss_unwrap returned %08x minor status %08x\n", ret, minor_status );
1572 if (GSS_ERROR(ret)) trace_gss_status( ret, minor_status );
1573 if (ret == GSS_S_COMPLETE)
1575 if (quality_of_protection) *quality_of_protection = (conf_state ? 0 : SECQOP_WRAP_NO_ENCRYPT);
1576 memcpy( message->pBuffers[data_idx].pvBuffer, output.value, len_data );
1577 pgss_release_buffer( &minor_status, &output );
1580 return status_gss_to_sspi( ret );
1582 #endif
1584 static NTSTATUS NTAPI kerberos_SpUnsealMessage( LSA_SEC_HANDLE context, SecBufferDesc *message,
1585 ULONG message_seq_no, ULONG *quality_of_protection )
1587 #ifdef SONAME_LIBGSSAPI_KRB5
1588 gss_ctx_id_t ctxt_handle;
1590 TRACE( "(%lx %p %u %p)\n", context, message, message_seq_no, quality_of_protection );
1591 if (message_seq_no) FIXME( "ignoring message_seq_no %u\n", message_seq_no );
1593 if (!context) return SEC_E_INVALID_HANDLE;
1594 ctxt_handle = ctxthandle_sspi_to_gss( context );
1596 if (is_dce_style_context( ctxt_handle )) return unseal_message_iov( ctxt_handle, message, quality_of_protection );
1597 return unseal_message( ctxt_handle, message, quality_of_protection );
1598 #else
1599 FIXME( "(%lx %p %u %p)\n", context, message, message_seq_no, quality_of_protection );
1600 return SEC_E_UNSUPPORTED_FUNCTION;
1601 #endif
1604 static SECPKG_USER_FUNCTION_TABLE kerberos_user_table =
1606 kerberos_SpInstanceInit,
1607 NULL, /* SpInitUserModeContext */
1608 kerberos_SpMakeSignature,
1609 kerberos_SpVerifySignature,
1610 kerberos_SpSealMessage,
1611 kerberos_SpUnsealMessage,
1612 NULL, /* SpGetContextToken */
1613 NULL, /* SpQueryContextAttributes */
1614 NULL, /* SpCompleteAuthToken */
1615 NULL, /* SpDeleteContext */
1616 NULL, /* SpFormatCredentialsFn */
1617 NULL, /* SpMarshallSupplementalCreds */
1618 NULL, /* SpExportSecurityContext */
1619 NULL /* SpImportSecurityContext */
1622 NTSTATUS NTAPI SpUserModeInitialize(ULONG lsa_version, PULONG package_version,
1623 PSECPKG_USER_FUNCTION_TABLE *table, PULONG table_count)
1625 TRACE("%#x,%p,%p,%p\n", lsa_version, package_version, table, table_count);
1627 *package_version = SECPKG_INTERFACE_VERSION;
1628 *table = &kerberos_user_table;
1629 *table_count = 1;
1631 return STATUS_SUCCESS;