24#include <freerdp/config.h>
26#include <freerdp/build-config.h>
27#include <freerdp/peer.h>
30#include <winpr/wtypes.h>
31#include <winpr/assert.h>
32#include <winpr/library.h>
33#include <winpr/registry.h>
34#include <winpr/sspi.h>
36#include <freerdp/log.h>
39#include "credssp_auth.h"
41#define TAG FREERDP_TAG("core.auth")
43#define SERVER_KEY "Software\\" FREERDP_VENDOR_STRING "\\" FREERDP_PRODUCT_STRING "\\Server"
49 AUTH_STATE_IN_PROGRESS,
53struct rdp_credssp_auth
55 const rdpContext* rdp_ctx;
56 SecurityFunctionTable* table;
58 SEC_WINNT_AUTH_IDENTITY identity;
71 SECURITY_STATUS sspi_error;
72 enum AUTH_STATE state;
76static const char* credssp_auth_state_string(
const rdpCredsspAuth* auth)
81 case AUTH_STATE_INITIAL:
82 return "AUTH_STATE_INITIAL";
83 case AUTH_STATE_CREDS:
84 return "AUTH_STATE_CREDS";
85 case AUTH_STATE_IN_PROGRESS:
86 return "AUTH_STATE_IN_PROGRESS";
87 case AUTH_STATE_FINAL:
88 return "AUTH_STATE_FINAL";
90 return "AUTH_STATE_UNKNOWN";
93static BOOL parseKerberosDeltat(
const char* value, INT32* dest,
const char* message);
94static BOOL credssp_auth_setup_identity(rdpCredsspAuth* auth);
95static SecurityFunctionTable* auth_resolve_sspi_table(
const rdpSettings* settings);
97#define log_status(status, level, ...) \
98 log_status_((status), (level), __FILE__, __func__, __LINE__, __VA_ARGS__)
100WINPR_ATTR_FORMAT_ARG(6, 7)
101static BOOL log_status_(SECURITY_STATUS status, DWORD level, const
char* file, const
char* fkt,
102 size_t line, WINPR_FORMAT_ARG const
char* what, ...)
104 static wLog* log = NULL;
108 if (WLog_IsLevelActive(log, level))
110 char fwhat[128] = { 0 };
113 (void)vsnprintf(fwhat,
sizeof(fwhat) - 1, what, ap);
116 WLog_PrintTextMessage(log, level, line, file, fkt,
"%s status %s [0x%08" PRIx32
"]", fwhat,
117 GetSecurityStatusString(status),
118 WINPR_CXX_COMPAT_CAST(uint32_t, status));
124static BOOL credssp_auth_update_name_cache(rdpCredsspAuth* auth, TCHAR* name)
128 free(auth->pkgNameA);
129 auth->pkgNameA = NULL;
132 auth->pkgNameA = ConvertWCharToUtf8Alloc(name, NULL);
134 auth->pkgNameA = _strdup(name);
138rdpCredsspAuth* credssp_auth_new(
const rdpContext* rdp_ctx)
140 rdpCredsspAuth* auth = calloc(1,
sizeof(rdpCredsspAuth));
143 auth->rdp_ctx = rdp_ctx;
151 WINPR_ASSERT(auth->rdp_ctx);
153 const rdpSettings* settings = auth->rdp_ctx->settings;
154 WINPR_ASSERT(settings);
156 if (!credssp_auth_update_name_cache(auth, pkg_name))
159 auth->table = auth_resolve_sspi_table(settings);
162 WLog_ERR(TAG,
"Unable to initialize sspi table");
167 WINPR_ASSERT(auth->table->QuerySecurityPackageInfo);
168 const SECURITY_STATUS status = auth->table->QuerySecurityPackageInfo(pkg_name, &auth->info);
169 if (status != SEC_E_OK)
170 return log_status(status, WLOG_ERROR,
"QuerySecurityPackageInfo (%s)",
171 credssp_auth_pkg_name(auth));
173 if (!credssp_auth_update_name_cache(auth, auth->info->Name))
176 WLog_DBG(TAG,
"Using package: %s (cbMaxToken: %u bytes)", credssp_auth_pkg_name(auth),
177 auth->info->cbMaxToken);
180 if (!credssp_auth_setup_identity(auth))
183 auth->bindings = bindings;
188static BOOL credssp_auth_setup_auth_data(rdpCredsspAuth* auth,
189 const SEC_WINNT_AUTH_IDENTITY* identity,
192 WINPR_ASSERT(pAuthData);
196 identityEx->Version = SEC_WINNT_AUTH_IDENTITY_VERSION;
197 identityEx->Length =
sizeof(SEC_WINNT_AUTH_IDENTITY_EX);
198 identityEx->User = identity->User;
199 identityEx->UserLength = identity->UserLength;
200 identityEx->Domain = identity->Domain;
201 identityEx->DomainLength = identity->DomainLength;
202 identityEx->Password = identity->Password;
203 identityEx->PasswordLength = identity->PasswordLength;
204 identityEx->Flags = identity->Flags;
205 identityEx->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
206 identityEx->Flags |= SEC_WINNT_AUTH_IDENTITY_EXTENDED;
208 if (auth->package_list)
210 const size_t len = _wcslen(auth->package_list);
211 if (len > UINT32_MAX)
214 identityEx->PackageList = (UINT16*)auth->package_list;
215 identityEx->PackageListLength = (UINT32)len;
218 pAuthData->ntlmSettings = &auth->ntlmSettings;
219 pAuthData->kerberosSettings = &auth->kerberosSettings;
224static BOOL credssp_auth_client_init_cred_attributes(rdpCredsspAuth* auth)
228 if (!utils_str_is_empty(auth->kerberosSettings.kdcUrl))
230 SECURITY_STATUS status = ERROR_INTERNAL_ERROR;
231 SSIZE_T str_size = 0;
233 str_size = ConvertUtf8ToWChar(auth->kerberosSettings.kdcUrl, NULL, 0);
234 if ((str_size <= 0) || (str_size >= UINT16_MAX / 2))
238 const size_t buffer_size =
240 if (buffer_size > UINT32_MAX)
246 secAttr->Version = KDC_PROXY_SETTINGS_V1;
247 secAttr->ProxyServerLength = (UINT16)((
size_t)str_size *
sizeof(WCHAR));
250 if (ConvertUtf8ToWChar(auth->kerberosSettings.kdcUrl, (WCHAR*)(secAttr + 1),
251 (
size_t)str_size) <= 0)
258 if (auth->table->SetCredentialsAttributesW)
259 status = auth->table->SetCredentialsAttributesW(&auth->credentials,
260 SECPKG_CRED_ATTR_KDC_PROXY_SETTINGS,
261 (
void*)secAttr, (UINT32)buffer_size);
263 status = SEC_E_UNSUPPORTED_FUNCTION;
265 if (auth->table->SetCredentialsAttributesA)
266 status = auth->table->SetCredentialsAttributesA(&auth->credentials,
267 SECPKG_CRED_ATTR_KDC_PROXY_SETTINGS,
268 (
void*)secAttr, (UINT32)buffer_size);
270 status = SEC_E_UNSUPPORTED_FUNCTION;
273 if (status != SEC_E_OK)
275 WLog_WARN(TAG,
"Explicit Kerberos KDC URL (%s) injection is not supported",
276 auth->kerberosSettings.kdcUrl);
285BOOL credssp_auth_setup_client(rdpCredsspAuth* auth,
const char* target_service,
286 const char* target_hostname,
const SEC_WINNT_AUTH_IDENTITY* identity,
289 void* pAuthData = NULL;
293 WINPR_ASSERT(auth->table);
294 WINPR_ASSERT(auth->info);
296 WINPR_ASSERT(auth->state == AUTH_STATE_INITIAL);
299 if (!credssp_auth_set_spn(auth, target_service, target_hostname))
304 credssp_auth_setup_auth_data(auth, identity, &winprAuthData);
308 auth->kerberosSettings.pkinitX509Identity = _strdup(pkinit);
309 if (!auth->kerberosSettings.pkinitX509Identity)
311 WLog_ERR(TAG,
"unable to copy pkinitArgs");
316 pAuthData = (
void*)&winprAuthData;
319 WINPR_ASSERT(auth->table->AcquireCredentialsHandle);
320 const SECURITY_STATUS status =
321 auth->table->AcquireCredentialsHandle(NULL, auth->info->Name, SECPKG_CRED_OUTBOUND, NULL,
322 pAuthData, NULL, NULL, &auth->credentials, NULL);
324 if (status != SEC_E_OK)
325 return log_status(status, WLOG_ERROR,
"AcquireCredentialsHandleA");
327 if (!credssp_auth_client_init_cred_attributes(auth))
329 WLog_ERR(TAG,
"Fatal error setting credential attributes");
333 auth->state = AUTH_STATE_CREDS;
334 WLog_DBG(TAG,
"Acquired client credentials");
339BOOL credssp_auth_setup_server(rdpCredsspAuth* auth)
341 void* pAuthData = NULL;
345 WINPR_ASSERT(auth->table);
347 WINPR_ASSERT(auth->state == AUTH_STATE_INITIAL);
349 if (auth->ntlmSettings.samFile || auth->ntlmSettings.hashCallback ||
350 auth->kerberosSettings.keytab)
352 credssp_auth_setup_auth_data(auth, &auth->identity, &winprAuthData);
353 pAuthData = &winprAuthData;
356 WINPR_ASSERT(auth->table->AcquireCredentialsHandle);
357 const SECURITY_STATUS status =
358 auth->table->AcquireCredentialsHandle(NULL, auth->info->Name, SECPKG_CRED_INBOUND, NULL,
359 pAuthData, NULL, NULL, &auth->credentials, NULL);
360 if (status != SEC_E_OK)
361 return log_status(status, WLOG_ERROR,
"AcquireCredentialsHandleA");
363 auth->state = AUTH_STATE_CREDS;
364 WLog_DBG(TAG,
"Acquired server credentials");
371void credssp_auth_set_flags(rdpCredsspAuth* auth, ULONG flags)
415int credssp_auth_authenticate(rdpCredsspAuth* auth)
417 SECURITY_STATUS status = ERROR_INTERNAL_ERROR;
419 SecBufferDesc input_buffer_desc = { SECBUFFER_VERSION, 1, input_buffers };
423 WINPR_ASSERT(auth->table);
425 SecBufferDesc output_buffer_desc = { SECBUFFER_VERSION, 1, &auth->output_buffer };
429 case AUTH_STATE_CREDS:
430 case AUTH_STATE_IN_PROGRESS:
432 case AUTH_STATE_INITIAL:
433 case AUTH_STATE_FINAL:
434 WLog_ERR(TAG,
"context in invalid state!");
442 context = &auth->context;
443 if (!auth->context.dwLower && !auth->context.dwUpper)
446 input_buffers[0] = auth->input_buffer;
450 input_buffer_desc.cBuffers = 2;
452 input_buffers[1].BufferType = SECBUFFER_CHANNEL_BINDINGS;
453 input_buffers[1].cbBuffer = auth->bindings->BindingsLength;
454 input_buffers[1].pvBuffer = auth->bindings->Bindings;
458 sspi_SecBufferFree(&auth->output_buffer);
459 auth->output_buffer.BufferType = SECBUFFER_TOKEN;
460 if (!sspi_SecBufferAlloc(&auth->output_buffer, auth->info->cbMaxToken))
465 WINPR_ASSERT(auth->table->AcceptSecurityContext);
466 status = auth->table->AcceptSecurityContext(
467 &auth->credentials, context, &input_buffer_desc, auth->flags, SECURITY_NATIVE_DREP,
468 &auth->context, &output_buffer_desc, &auth->flags, NULL);
472 WINPR_ASSERT(auth->table->InitializeSecurityContext);
473 status = auth->table->InitializeSecurityContext(
474 &auth->credentials, context, auth->spn, auth->flags, 0, SECURITY_NATIVE_DREP,
475 &input_buffer_desc, 0, &auth->context, &output_buffer_desc, &auth->flags, NULL);
478 if (status == SEC_E_OK)
480 WLog_DBG(TAG,
"Authentication complete (output token size: %" PRIu32
" bytes)",
481 auth->output_buffer.cbBuffer);
482 auth->state = AUTH_STATE_FINAL;
486 WINPR_ASSERT(auth->table->QueryContextAttributes);
488 auth->table->QueryContextAttributes(&auth->context, SECPKG_ATTR_SIZES, &auth->sizes);
489 (void)log_status(status, WLOG_DEBUG,
"QueryContextAttributes");
490 WLog_DBG(TAG,
"Context sizes: cbMaxSignature=%" PRIu32
", cbSecurityTrailer=%" PRIu32
"",
491 auth->sizes.cbMaxSignature, auth->sizes.cbSecurityTrailer);
495 else if (status == SEC_I_CONTINUE_NEEDED)
497 WLog_DBG(TAG,
"Authentication in progress... (output token size: %" PRIu32
")",
498 auth->output_buffer.cbBuffer);
499 auth->state = AUTH_STATE_IN_PROGRESS;
504 (void)log_status(status, WLOG_ERROR,
505 auth->server ?
"AcceptSecurityContext" :
"InitializeSecurityContext");
506 auth->sspi_error = status;
512BOOL credssp_auth_encrypt(rdpCredsspAuth* auth,
const SecBuffer* plaintext,
SecBuffer* ciphertext,
513 size_t* signature_length, ULONG sequence)
515 SECURITY_STATUS status = ERROR_INTERNAL_ERROR;
517 SecBufferDesc buffer_desc = { SECBUFFER_VERSION, 2, buffers };
520 WINPR_ASSERT(auth && auth->table);
521 WINPR_ASSERT(plaintext);
522 WINPR_ASSERT(ciphertext);
526 case AUTH_STATE_INITIAL:
527 WLog_ERR(TAG,
"Invalid state %s", credssp_auth_state_string(auth));
534 buf = calloc(1, plaintext->cbBuffer + auth->sizes.cbSecurityTrailer);
538 buffers[0].BufferType = SECBUFFER_TOKEN;
539 buffers[0].cbBuffer = auth->sizes.cbSecurityTrailer;
540 buffers[0].pvBuffer = buf;
542 buffers[1].BufferType = SECBUFFER_DATA;
543 if (plaintext->BufferType & SECBUFFER_READONLY)
544 buffers[1].BufferType |= SECBUFFER_READONLY;
545 buffers[1].pvBuffer = buf + auth->sizes.cbSecurityTrailer;
546 buffers[1].cbBuffer = plaintext->cbBuffer;
547 CopyMemory(buffers[1].pvBuffer, plaintext->pvBuffer, plaintext->cbBuffer);
549 WINPR_ASSERT(auth->table->EncryptMessage);
550 status = auth->table->EncryptMessage(&auth->context, 0, &buffer_desc, sequence);
551 if (status != SEC_E_OK)
554 return log_status(status, WLOG_ERROR,
"EncryptMessage");
557 if (buffers[0].cbBuffer < auth->sizes.cbSecurityTrailer)
560 MoveMemory(((BYTE*)buffers[0].pvBuffer) + buffers[0].cbBuffer, buffers[1].pvBuffer,
561 buffers[1].cbBuffer);
563 auth->sizes.cbSecurityTrailer = buffers[0].cbBuffer;
566 ciphertext->cbBuffer = buffers[0].cbBuffer + buffers[1].cbBuffer;
567 ciphertext->pvBuffer = buf;
569 if (signature_length)
570 *signature_length = buffers[0].cbBuffer;
576BOOL credssp_auth_decrypt(rdpCredsspAuth* auth,
const SecBuffer* ciphertext,
SecBuffer* plaintext,
580 SecBufferDesc buffer_desc = { SECBUFFER_VERSION, 2, buffers };
583 WINPR_ASSERT(auth && auth->table);
584 WINPR_ASSERT(ciphertext);
585 WINPR_ASSERT(plaintext);
589 case AUTH_STATE_INITIAL:
590 WLog_ERR(TAG,
"Invalid state %s", credssp_auth_state_string(auth));
597 if (ciphertext->cbBuffer < auth->sizes.cbSecurityTrailer)
599 WLog_ERR(TAG,
"Encrypted message buffer too small");
605 buffers[0].BufferType = SECBUFFER_TOKEN;
606 buffers[0].pvBuffer = ciphertext->pvBuffer;
607 buffers[0].cbBuffer = auth->sizes.cbSecurityTrailer;
609 buffers[1].BufferType = SECBUFFER_DATA;
610 if (!sspi_SecBufferAlloc(&buffers[1], ciphertext->cbBuffer - auth->sizes.cbSecurityTrailer))
612 CopyMemory(buffers[1].pvBuffer, (BYTE*)ciphertext->pvBuffer + auth->sizes.cbSecurityTrailer,
613 buffers[1].cbBuffer);
615 WINPR_ASSERT(auth->table->DecryptMessage);
616 const SECURITY_STATUS status =
617 auth->table->DecryptMessage(&auth->context, &buffer_desc, sequence, &fqop);
618 if (status != SEC_E_OK)
620 WLog_ERR(TAG,
"DecryptMessage failed with %s [0x%08" PRIx32
"]",
621 GetSecurityStatusString(status), WINPR_CXX_COMPAT_CAST(uint32_t, status));
622 sspi_SecBufferFree(&buffers[1]);
626 *plaintext = buffers[1];
631BOOL credssp_auth_impersonate(rdpCredsspAuth* auth)
633 WINPR_ASSERT(auth && auth->table);
635 WINPR_ASSERT(auth->table->ImpersonateSecurityContext);
636 const SECURITY_STATUS status = auth->table->ImpersonateSecurityContext(&auth->context);
638 if (status != SEC_E_OK)
640 WLog_ERR(TAG,
"ImpersonateSecurityContext failed with %s [0x%08" PRIx32
"]",
641 GetSecurityStatusString(status), WINPR_CXX_COMPAT_CAST(uint32_t, status));
648BOOL credssp_auth_revert_to_self(rdpCredsspAuth* auth)
650 WINPR_ASSERT(auth && auth->table);
652 WINPR_ASSERT(auth->table->RevertSecurityContext);
653 const SECURITY_STATUS status = auth->table->RevertSecurityContext(&auth->context);
655 if (status != SEC_E_OK)
657 WLog_ERR(TAG,
"RevertSecurityContext failed with %s [0x%08" PRIx32
"]",
658 GetSecurityStatusString(status), WINPR_CXX_COMPAT_CAST(uint32_t, status));
665void credssp_auth_take_input_buffer(rdpCredsspAuth* auth,
SecBuffer* buffer)
668 WINPR_ASSERT(buffer);
670 sspi_SecBufferFree(&auth->input_buffer);
672 auth->input_buffer = *buffer;
673 auth->input_buffer.BufferType = SECBUFFER_TOKEN;
680const SecBuffer* credssp_auth_get_output_buffer(
const rdpCredsspAuth* auth)
683 return &auth->output_buffer;
686BOOL credssp_auth_have_output_token(rdpCredsspAuth* auth)
689 return auth->output_buffer.cbBuffer ? TRUE : FALSE;
692BOOL credssp_auth_is_complete(
const rdpCredsspAuth* auth)
695 return auth->state == AUTH_STATE_FINAL;
698size_t credssp_auth_trailer_size(
const rdpCredsspAuth* auth)
701 return auth->sizes.cbSecurityTrailer;
704const char* credssp_auth_pkg_name(
const rdpCredsspAuth* auth)
706 WINPR_ASSERT(auth && auth->info);
707 return auth->pkgNameA;
710INT32 credssp_auth_sspi_error(
const rdpCredsspAuth* auth)
713 return auth->sspi_error;
716void credssp_auth_tableAndContext(rdpCredsspAuth* auth, SecurityFunctionTable** ptable,
720 WINPR_ASSERT(ptable);
721 WINPR_ASSERT(pcontext);
723 *ptable = auth->table;
724 *pcontext = auth->context;
727void credssp_auth_free(rdpCredsspAuth* auth)
739 case AUTH_STATE_IN_PROGRESS:
740 case AUTH_STATE_FINAL:
741 WINPR_ASSERT(auth->table->DeleteSecurityContext);
742 auth->table->DeleteSecurityContext(&auth->context);
745 case AUTH_STATE_CREDS:
746 WINPR_ASSERT(auth->table->FreeCredentialsHandle);
747 auth->table->FreeCredentialsHandle(&auth->credentials);
749 case AUTH_STATE_INITIAL:
756 WINPR_ASSERT(auth->table->FreeContextBuffer);
757 auth->table->FreeContextBuffer(auth->info);
761 sspi_FreeAuthIdentity(&auth->identity);
763 krb_settings = &auth->kerberosSettings;
764 ntlm_settings = &auth->ntlmSettings;
766 free(krb_settings->kdcUrl);
767 free(krb_settings->cache);
768 free(krb_settings->keytab);
769 free(krb_settings->armorCache);
770 free(krb_settings->pkinitX509Anchors);
771 free(krb_settings->pkinitX509Identity);
772 free(ntlm_settings->samFile);
774 free(auth->package_list);
776 sspi_SecBufferFree(&auth->input_buffer);
777 sspi_SecBufferFree(&auth->output_buffer);
778 credssp_auth_update_name_cache(auth, NULL);
782static void auth_get_sspi_module_from_reg(
char** sspi_module)
788 WINPR_ASSERT(sspi_module);
791 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, SERVER_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey) !=
795 if (RegQueryValueExA(hKey,
"SspiModule", NULL, &dwType, NULL, &dwSize) != ERROR_SUCCESS)
801 char*
module = (LPSTR)calloc(dwSize + sizeof(CHAR), sizeof(char));
808 if (RegQueryValueExA(hKey,
"SspiModule", NULL, &dwType, (BYTE*)module, &dwSize) !=
817 *sspi_module =
module;
820static SecurityFunctionTable* auth_resolve_sspi_table(
const rdpSettings* settings)
822 char* sspi_module = NULL;
824 WINPR_ASSERT(settings);
826 if (settings->ServerMode)
827 auth_get_sspi_module_from_reg(&sspi_module);
829 if (sspi_module || settings->SspiModule)
831 const char* module_name = sspi_module ? sspi_module : settings->SspiModule;
833 const char* proc_name =
"InitSecurityInterfaceW";
835 const char* proc_name =
"InitSecurityInterfaceA";
838 HMODULE hSSPI = LoadLibraryX(module_name);
842 WLog_ERR(TAG,
"Failed to load SSPI module: %s", module_name);
847 WLog_INFO(TAG,
"Using SSPI Module: %s", module_name);
849 INIT_SECURITY_INTERFACE InitSecurityInterface_ptr =
850 GetProcAddressAs(hSSPI, proc_name, INIT_SECURITY_INTERFACE);
851 if (!InitSecurityInterface_ptr)
853 WLog_ERR(TAG,
"Failed to load SSPI module: %s, no function %s", module_name, proc_name);
858 return InitSecurityInterface_ptr();
861 return InitSecurityInterfaceEx(0);
864static BOOL credssp_auth_setup_identity(rdpCredsspAuth* auth)
866 const rdpSettings* settings = NULL;
869 freerdp_peer* peer = NULL;
872 WINPR_ASSERT(auth->rdp_ctx);
874 peer = auth->rdp_ctx->peer;
875 settings = auth->rdp_ctx->settings;
876 WINPR_ASSERT(settings);
878 krb_settings = &auth->kerberosSettings;
879 ntlm_settings = &auth->ntlmSettings;
881 if (settings->KerberosLifeTime)
882 parseKerberosDeltat(settings->KerberosLifeTime, &krb_settings->lifeTime,
"lifetime");
883 if (settings->KerberosStartTime)
884 parseKerberosDeltat(settings->KerberosStartTime, &krb_settings->startTime,
"starttime");
885 if (settings->KerberosRenewableLifeTime)
886 parseKerberosDeltat(settings->KerberosRenewableLifeTime, &krb_settings->renewLifeTime,
889 if (settings->KerberosKdcUrl)
891 krb_settings->kdcUrl = _strdup(settings->KerberosKdcUrl);
892 if (!krb_settings->kdcUrl)
894 WLog_ERR(TAG,
"unable to copy kdcUrl");
899 if (settings->KerberosCache)
901 krb_settings->cache = _strdup(settings->KerberosCache);
902 if (!krb_settings->cache)
904 WLog_ERR(TAG,
"unable to copy cache name");
909 if (settings->KerberosKeytab)
911 krb_settings->keytab = _strdup(settings->KerberosKeytab);
912 if (!krb_settings->keytab)
914 WLog_ERR(TAG,
"unable to copy keytab name");
919 if (settings->KerberosArmor)
921 krb_settings->armorCache = _strdup(settings->KerberosArmor);
922 if (!krb_settings->armorCache)
924 WLog_ERR(TAG,
"unable to copy armorCache");
929 if (settings->PkinitAnchors)
931 krb_settings->pkinitX509Anchors = _strdup(settings->PkinitAnchors);
932 if (!krb_settings->pkinitX509Anchors)
934 WLog_ERR(TAG,
"unable to copy pkinitX509Anchors");
939 if (settings->NtlmSamFile)
941 ntlm_settings->samFile = _strdup(settings->NtlmSamFile);
942 if (!ntlm_settings->samFile)
944 WLog_ERR(TAG,
"unable to copy samFile");
949 if (peer && peer->SspiNtlmHashCallback)
951 ntlm_settings->hashCallback = peer->SspiNtlmHashCallback;
952 ntlm_settings->hashCallbackArg = peer;
955 if (settings->AuthenticationPackageList)
957 auth->package_list = ConvertUtf8ToWCharAlloc(settings->AuthenticationPackageList, NULL);
958 if (!auth->package_list)
962 auth->identity.Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
963 auth->identity.Flags |= SEC_WINNT_AUTH_IDENTITY_EXTENDED;
968BOOL credssp_auth_set_spn(rdpCredsspAuth* auth,
const char* service,
const char* hostname)
979 spn = _strdup(hostname);
982 length = strlen(service) + strlen(hostname) + 2;
983 spn = calloc(length + 1,
sizeof(
char));
987 (void)sprintf_s(spn, length,
"%s/%s", service, hostname);
993 auth->spn = ConvertUtf8ToWCharAlloc(spn, NULL);
1002static const char* parseInt(
const char* v, INT32* r)
1007 if (!*v || !((*v >=
'0') && (*v <=
'9')))
1010 for (; *v && (*v >=
'0') && (*v <=
'9'); v++)
1012 *r = (*r * 10) + (*v -
'0');
1018static BOOL parseKerberosDeltat(
const char* value, INT32* dest,
const char* message)
1021 const char* ptr = NULL;
1023 WINPR_ASSERT(value);
1025 WINPR_ASSERT(message);
1032 ptr = strchr(value,
':');
1037 value = parseInt(value, &v);
1038 if (!value || *value !=
':')
1040 WLog_ERR(TAG,
"Invalid value for %s", message);
1046 value = parseInt(value + 1, &v);
1047 if (!value || (*value != 0 && *value !=
':') || (v > 60))
1049 WLog_ERR(TAG,
"Invalid value for %s", message);
1057 value = parseInt(value + 1, &v);
1058 if (!value || (*value != 0) || (v > 60))
1060 WLog_ERR(TAG,
"Invalid value for %s", message);
1069 value = parseInt(value, &v);
1072 WLog_ERR(TAG,
"Invalid value for %s", message);
1076 if (!*value || isspace(*value))
1108 WLog_ERR(TAG,
"invalid value for unit %c when parsing %s", *value, message);
1112 if ((maxValue > 0) && (v > maxValue))
1114 WLog_ERR(TAG,
"invalid value for unit %c when parsing %s", *value, message);
1118 *dest += (v * factor);
1123 value = parseInt(value, &v);
1124 if (!value || !*value)
1126 WLog_ERR(TAG,
"Invalid value for %s", message);