1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 * SPDX-License-Identifier: curl
23 ***************************************************************************/
25 #include "curl_setup.h"
27 #if defined(USE_NTLM) && !defined(USE_WINDOWS_SSPI)
32 * https://davenport.sourceforge.net/ntlm.html
33 * https://www.innovation.ch/java/ntlm.html
40 #include "curl_ntlm_core.h"
41 #include "curl_gethostname.h"
42 #include "curl_multibyte.h"
46 #include "vtls/vtls.h"
48 /* SSL backend-specific #if branches in this file must be kept in the order
49 documented in curl_ntlm_core. */
50 #if defined(NTLM_NEEDS_NSS_INIT)
51 #include "vtls/nssg.h" /* for Curl_nss_force_init() */
54 #define BUILDING_CURL_NTLM_MSGS_C
55 #include "vauth/vauth.h"
56 #include "vauth/ntlm.h"
57 #include "curl_endian.h"
58 #include "curl_printf.h"
60 /* The last #include files should be: */
61 #include "curl_memory.h"
64 /* "NTLMSSP" signature is always in ASCII regardless of the platform */
65 #define NTLMSSP_SIGNATURE "\x4e\x54\x4c\x4d\x53\x53\x50"
67 /* The fixed host name we provide, in order to not leak our real local host
68 name. Copy the name used by Firefox. */
69 #define NTLM_HOSTNAME "WORKSTATION"
72 # define DEBUG_OUT(x) x
73 static void ntlm_print_flags(FILE *handle, unsigned long flags)
75 if(flags & NTLMFLAG_NEGOTIATE_UNICODE)
76 fprintf(handle, "NTLMFLAG_NEGOTIATE_UNICODE ");
77 if(flags & NTLMFLAG_NEGOTIATE_OEM)
78 fprintf(handle, "NTLMFLAG_NEGOTIATE_OEM ");
79 if(flags & NTLMFLAG_REQUEST_TARGET)
80 fprintf(handle, "NTLMFLAG_REQUEST_TARGET ");
82 fprintf(handle, "NTLMFLAG_UNKNOWN_3 ");
83 if(flags & NTLMFLAG_NEGOTIATE_SIGN)
84 fprintf(handle, "NTLMFLAG_NEGOTIATE_SIGN ");
85 if(flags & NTLMFLAG_NEGOTIATE_SEAL)
86 fprintf(handle, "NTLMFLAG_NEGOTIATE_SEAL ");
87 if(flags & NTLMFLAG_NEGOTIATE_DATAGRAM_STYLE)
88 fprintf(handle, "NTLMFLAG_NEGOTIATE_DATAGRAM_STYLE ");
89 if(flags & NTLMFLAG_NEGOTIATE_LM_KEY)
90 fprintf(handle, "NTLMFLAG_NEGOTIATE_LM_KEY ");
91 if(flags & NTLMFLAG_NEGOTIATE_NETWARE)
92 fprintf(handle, "NTLMFLAG_NEGOTIATE_NETWARE ");
93 if(flags & NTLMFLAG_NEGOTIATE_NTLM_KEY)
94 fprintf(handle, "NTLMFLAG_NEGOTIATE_NTLM_KEY ");
96 fprintf(handle, "NTLMFLAG_UNKNOWN_10 ");
97 if(flags & NTLMFLAG_NEGOTIATE_ANONYMOUS)
98 fprintf(handle, "NTLMFLAG_NEGOTIATE_ANONYMOUS ");
99 if(flags & NTLMFLAG_NEGOTIATE_DOMAIN_SUPPLIED)
100 fprintf(handle, "NTLMFLAG_NEGOTIATE_DOMAIN_SUPPLIED ");
101 if(flags & NTLMFLAG_NEGOTIATE_WORKSTATION_SUPPLIED)
102 fprintf(handle, "NTLMFLAG_NEGOTIATE_WORKSTATION_SUPPLIED ");
103 if(flags & NTLMFLAG_NEGOTIATE_LOCAL_CALL)
104 fprintf(handle, "NTLMFLAG_NEGOTIATE_LOCAL_CALL ");
105 if(flags & NTLMFLAG_NEGOTIATE_ALWAYS_SIGN)
106 fprintf(handle, "NTLMFLAG_NEGOTIATE_ALWAYS_SIGN ");
107 if(flags & NTLMFLAG_TARGET_TYPE_DOMAIN)
108 fprintf(handle, "NTLMFLAG_TARGET_TYPE_DOMAIN ");
109 if(flags & NTLMFLAG_TARGET_TYPE_SERVER)
110 fprintf(handle, "NTLMFLAG_TARGET_TYPE_SERVER ");
111 if(flags & NTLMFLAG_TARGET_TYPE_SHARE)
112 fprintf(handle, "NTLMFLAG_TARGET_TYPE_SHARE ");
113 if(flags & NTLMFLAG_NEGOTIATE_NTLM2_KEY)
114 fprintf(handle, "NTLMFLAG_NEGOTIATE_NTLM2_KEY ");
115 if(flags & NTLMFLAG_REQUEST_INIT_RESPONSE)
116 fprintf(handle, "NTLMFLAG_REQUEST_INIT_RESPONSE ");
117 if(flags & NTLMFLAG_REQUEST_ACCEPT_RESPONSE)
118 fprintf(handle, "NTLMFLAG_REQUEST_ACCEPT_RESPONSE ");
119 if(flags & NTLMFLAG_REQUEST_NONNT_SESSION_KEY)
120 fprintf(handle, "NTLMFLAG_REQUEST_NONNT_SESSION_KEY ");
121 if(flags & NTLMFLAG_NEGOTIATE_TARGET_INFO)
122 fprintf(handle, "NTLMFLAG_NEGOTIATE_TARGET_INFO ");
124 fprintf(handle, "NTLMFLAG_UNKNOWN_24 ");
126 fprintf(handle, "NTLMFLAG_UNKNOWN_25 ");
128 fprintf(handle, "NTLMFLAG_UNKNOWN_26 ");
130 fprintf(handle, "NTLMFLAG_UNKNOWN_27 ");
132 fprintf(handle, "NTLMFLAG_UNKNOWN_28 ");
133 if(flags & NTLMFLAG_NEGOTIATE_128)
134 fprintf(handle, "NTLMFLAG_NEGOTIATE_128 ");
135 if(flags & NTLMFLAG_NEGOTIATE_KEY_EXCHANGE)
136 fprintf(handle, "NTLMFLAG_NEGOTIATE_KEY_EXCHANGE ");
137 if(flags & NTLMFLAG_NEGOTIATE_56)
138 fprintf(handle, "NTLMFLAG_NEGOTIATE_56 ");
141 static void ntlm_print_hex(FILE *handle, const char *buf, size_t len)
147 fprintf(stderr, "0x");
149 fprintf(stderr, "%02.2x", (unsigned int)*p++);
152 # define DEBUG_OUT(x) Curl_nop_stmt
156 * ntlm_decode_type2_target()
158 * This is used to decode the "target info" in the NTLM type-2 message
163 * data [in] - The session handle.
164 * type2ref [in] - The type-2 message.
165 * ntlm [in/out] - The NTLM data struct being used and modified.
167 * Returns CURLE_OK on success.
169 static CURLcode ntlm_decode_type2_target(struct Curl_easy *data,
170 const struct bufref *type2ref,
171 struct ntlmdata *ntlm)
173 unsigned short target_info_len = 0;
174 unsigned int target_info_offset = 0;
175 const unsigned char *type2 = Curl_bufref_ptr(type2ref);
176 size_t type2len = Curl_bufref_len(type2ref);
178 #if defined(CURL_DISABLE_VERBOSE_STRINGS)
183 target_info_len = Curl_read16_le(&type2[40]);
184 target_info_offset = Curl_read32_le(&type2[44]);
185 if(target_info_len > 0) {
186 if((target_info_offset > type2len) ||
187 (target_info_offset + target_info_len) > type2len ||
188 target_info_offset < 48) {
189 infof(data, "NTLM handshake failure (bad type-2 message). "
190 "Target Info Offset Len is set incorrect by the peer");
191 return CURLE_BAD_CONTENT_ENCODING;
194 free(ntlm->target_info); /* replace any previous data */
195 ntlm->target_info = malloc(target_info_len);
196 if(!ntlm->target_info)
197 return CURLE_OUT_OF_MEMORY;
199 memcpy(ntlm->target_info, &type2[target_info_offset], target_info_len);
203 ntlm->target_info_len = target_info_len;
209 NTLM message structure notes:
211 A 'short' is a 'network short', a little-endian 16-bit unsigned value.
213 A 'long' is a 'network long', a little-endian, 32-bit unsigned value.
215 A 'security buffer' represents a triplet used to point to a buffer,
216 consisting of two shorts and one long:
218 1. A 'short' containing the length of the buffer content in bytes.
219 2. A 'short' containing the allocated space for the buffer in bytes.
220 3. A 'long' containing the offset to the start of the buffer in bytes,
221 from the beginning of the NTLM message.
225 * Curl_auth_is_ntlm_supported()
227 * This is used to evaluate if NTLM is supported.
231 * Returns TRUE as NTLM as handled by libcurl.
233 bool Curl_auth_is_ntlm_supported(void)
239 * Curl_auth_decode_ntlm_type2_message()
241 * This is used to decode an NTLM type-2 message. The raw NTLM message is
242 * checked * for validity before the appropriate data for creating a type-3
243 * message is * written to the given NTLM data structure.
247 * data [in] - The session handle.
248 * type2ref [in] - The type-2 message.
249 * ntlm [in/out] - The NTLM data struct being used and modified.
251 * Returns CURLE_OK on success.
253 CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data,
254 const struct bufref *type2ref,
255 struct ntlmdata *ntlm)
257 static const char type2_marker[] = { 0x02, 0x00, 0x00, 0x00 };
259 /* NTLM type-2 message structure:
261 Index Description Content
262 0 NTLMSSP Signature Null-terminated ASCII "NTLMSSP"
264 8 NTLM Message Type long (0x02000000)
265 12 Target Name security buffer
268 (32) Context 8 bytes (two consecutive longs) (*)
269 (40) Target Information security buffer (*)
270 (48) OS Version Structure 8 bytes (*)
271 32 (48) (56) Start of data block (*)
275 CURLcode result = CURLE_OK;
276 const unsigned char *type2 = Curl_bufref_ptr(type2ref);
277 size_t type2len = Curl_bufref_len(type2ref);
279 #if defined(NTLM_NEEDS_NSS_INIT)
280 /* Make sure the crypto backend is initialized */
281 result = Curl_nss_force_init(data);
284 #elif defined(CURL_DISABLE_VERBOSE_STRINGS)
290 if((type2len < 32) ||
291 (memcmp(type2, NTLMSSP_SIGNATURE, 8) != 0) ||
292 (memcmp(type2 + 8, type2_marker, sizeof(type2_marker)) != 0)) {
293 /* This was not a good enough type-2 message */
294 infof(data, "NTLM handshake failure (bad type-2 message)");
295 return CURLE_BAD_CONTENT_ENCODING;
298 ntlm->flags = Curl_read32_le(&type2[20]);
299 memcpy(ntlm->nonce, &type2[24], 8);
301 if(ntlm->flags & NTLMFLAG_NEGOTIATE_TARGET_INFO) {
302 result = ntlm_decode_type2_target(data, type2ref, ntlm);
304 infof(data, "NTLM handshake failure (bad type-2 message)");
310 fprintf(stderr, "**** TYPE2 header flags=0x%08.8lx ", ntlm->flags);
311 ntlm_print_flags(stderr, ntlm->flags);
312 fprintf(stderr, "\n nonce=");
313 ntlm_print_hex(stderr, (char *)ntlm->nonce, 8);
314 fprintf(stderr, "\n****\n");
315 fprintf(stderr, "**** Header %s\n ", header);
321 /* copy the source to the destination and fill in zeroes in every
322 other destination byte! */
323 static void unicodecpy(unsigned char *dest, const char *src, size_t length)
326 for(i = 0; i < length; i++) {
327 dest[2 * i] = (unsigned char)src[i];
328 dest[2 * i + 1] = '\0';
333 * Curl_auth_create_ntlm_type1_message()
335 * This is used to generate an NTLM type-1 message ready for sending to the
336 * recipient using the appropriate compile time crypto API.
340 * data [in] - The session handle.
341 * userp [in] - The user name in the format User or Domain\User.
342 * passwdp [in] - The user's password.
343 * service [in] - The service type such as http, smtp, pop or imap.
344 * host [in] - The host name.
345 * ntlm [in/out] - The NTLM data struct being used and modified.
346 * out [out] - The result storage.
348 * Returns CURLE_OK on success.
350 CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data,
354 const char *hostname,
355 struct ntlmdata *ntlm,
358 /* NTLM type-1 message structure:
360 Index Description Content
361 0 NTLMSSP Signature Null-terminated ASCII "NTLMSSP"
363 8 NTLM Message Type long (0x01000000)
365 (16) Supplied Domain security buffer (*)
366 (24) Supplied Workstation security buffer (*)
367 (32) OS Version Structure 8 bytes (*)
368 (32) (40) Start of data block (*)
375 const char *host = ""; /* empty */
376 const char *domain = ""; /* empty */
380 size_t domoff = hostoff + hostlen; /* This is 0: remember that host and
388 /* Clean up any former leftovers and initialise to defaults */
389 Curl_auth_cleanup_ntlm(ntlm);
391 ntlmbuf = aprintf(NTLMSSP_SIGNATURE "%c"
392 "\x01%c%c%c" /* 32-bit type = 1 */
393 "%c%c%c%c" /* 32-bit NTLM flag field */
394 "%c%c" /* domain length */
395 "%c%c" /* domain allocated space */
396 "%c%c" /* domain name offset */
397 "%c%c" /* 2 zeroes */
398 "%c%c" /* host length */
399 "%c%c" /* host allocated space */
400 "%c%c" /* host name offset */
401 "%c%c" /* 2 zeroes */
403 "%s", /* domain string */
404 0, /* trailing zero */
405 0, 0, 0, /* part of type-1 long */
407 LONGQUARTET(NTLMFLAG_NEGOTIATE_OEM |
408 NTLMFLAG_REQUEST_TARGET |
409 NTLMFLAG_NEGOTIATE_NTLM_KEY |
410 NTLMFLAG_NEGOTIATE_NTLM2_KEY |
411 NTLMFLAG_NEGOTIATE_ALWAYS_SIGN),
420 host, /* this is empty */
421 domain /* this is empty */);
424 return CURLE_OUT_OF_MEMORY;
426 /* Initial packet length */
427 size = 32 + hostlen + domlen;
430 fprintf(stderr, "* TYPE1 header flags=0x%02.2x%02.2x%02.2x%02.2x "
432 LONGQUARTET(NTLMFLAG_NEGOTIATE_OEM |
433 NTLMFLAG_REQUEST_TARGET |
434 NTLMFLAG_NEGOTIATE_NTLM_KEY |
435 NTLMFLAG_NEGOTIATE_NTLM2_KEY |
436 NTLMFLAG_NEGOTIATE_ALWAYS_SIGN),
437 NTLMFLAG_NEGOTIATE_OEM |
438 NTLMFLAG_REQUEST_TARGET |
439 NTLMFLAG_NEGOTIATE_NTLM_KEY |
440 NTLMFLAG_NEGOTIATE_NTLM2_KEY |
441 NTLMFLAG_NEGOTIATE_ALWAYS_SIGN);
442 ntlm_print_flags(stderr,
443 NTLMFLAG_NEGOTIATE_OEM |
444 NTLMFLAG_REQUEST_TARGET |
445 NTLMFLAG_NEGOTIATE_NTLM_KEY |
446 NTLMFLAG_NEGOTIATE_NTLM2_KEY |
447 NTLMFLAG_NEGOTIATE_ALWAYS_SIGN);
448 fprintf(stderr, "\n****\n");
451 Curl_bufref_set(out, ntlmbuf, size, curl_free);
456 * Curl_auth_create_ntlm_type3_message()
458 * This is used to generate an already encoded NTLM type-3 message ready for
459 * sending to the recipient using the appropriate compile time crypto API.
463 * data [in] - The session handle.
464 * userp [in] - The user name in the format User or Domain\User.
465 * passwdp [in] - The user's password.
466 * ntlm [in/out] - The NTLM data struct being used and modified.
467 * out [out] - The result storage.
469 * Returns CURLE_OK on success.
471 CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
474 struct ntlmdata *ntlm,
477 /* NTLM type-3 message structure:
479 Index Description Content
480 0 NTLMSSP Signature Null-terminated ASCII "NTLMSSP"
482 8 NTLM Message Type long (0x03000000)
483 12 LM/LMv2 Response security buffer
484 20 NTLM/NTLMv2 Response security buffer
485 28 Target Name security buffer
486 36 User Name security buffer
487 44 Workstation Name security buffer
488 (52) Session Key security buffer (*)
490 (64) OS Version Structure 8 bytes (*)
491 52 (64) (72) Start of data block
495 CURLcode result = CURLE_OK;
497 unsigned char ntlmbuf[NTLM_BUFSIZE];
499 unsigned char lmresp[24]; /* fixed-size */
501 unsigned int ntresplen = 24;
502 unsigned char ntresp[24]; /* fixed-size */
503 unsigned char *ptr_ntresp = &ntresp[0];
504 unsigned char *ntlmv2resp = NULL;
505 bool unicode = (ntlm->flags & NTLMFLAG_NEGOTIATE_UNICODE) ? TRUE : FALSE;
506 char host[HOSTNAME_MAX + 1] = "";
508 const char *domain = "";
516 user = strchr(userp, '\\');
518 user = strchr(userp, '/');
522 domlen = (user - domain);
528 userlen = strlen(user);
530 #ifndef NTLM_HOSTNAME
531 /* Get the machine's un-qualified host name as NTLM doesn't like the fully
532 qualified domain name */
533 if(Curl_gethostname(host, sizeof(host))) {
534 infof(data, "gethostname() failed, continuing without");
538 hostlen = strlen(host);
541 (void)msnprintf(host, sizeof(host), "%s", NTLM_HOSTNAME);
542 hostlen = sizeof(NTLM_HOSTNAME)-1;
545 if(ntlm->flags & NTLMFLAG_NEGOTIATE_NTLM2_KEY) {
546 unsigned char ntbuffer[0x18];
547 unsigned char entropy[8];
548 unsigned char ntlmv2hash[0x18];
550 /* Full NTLM version 2
551 Although this cannot be negotiated, it is used here if available, as
552 servers featuring extended security are likely supporting also
554 result = Curl_rand(data, entropy, 8);
558 result = Curl_ntlm_core_mk_nt_hash(passwdp, ntbuffer);
562 result = Curl_ntlm_core_mk_ntlmv2_hash(user, userlen, domain, domlen,
563 ntbuffer, ntlmv2hash);
568 result = Curl_ntlm_core_mk_lmv2_resp(ntlmv2hash, entropy,
569 &ntlm->nonce[0], lmresp);
573 /* NTLMv2 response */
574 result = Curl_ntlm_core_mk_ntlmv2_resp(ntlmv2hash, entropy,
575 ntlm, &ntlmv2resp, &ntresplen);
579 ptr_ntresp = ntlmv2resp;
583 unsigned char ntbuffer[0x18];
584 unsigned char lmbuffer[0x18];
588 result = Curl_ntlm_core_mk_nt_hash(passwdp, ntbuffer);
592 Curl_ntlm_core_lm_resp(ntbuffer, &ntlm->nonce[0], ntresp);
594 result = Curl_ntlm_core_mk_lm_hash(passwdp, lmbuffer);
598 Curl_ntlm_core_lm_resp(lmbuffer, &ntlm->nonce[0], lmresp);
599 ntlm->flags &= ~NTLMFLAG_NEGOTIATE_NTLM2_KEY;
601 /* A safer but less compatible alternative is:
602 * Curl_ntlm_core_lm_resp(ntbuffer, &ntlm->nonce[0], lmresp);
603 * See https://davenport.sourceforge.net/ntlm.html#ntlmVersion2 */
608 userlen = userlen * 2;
609 hostlen = hostlen * 2;
612 lmrespoff = 64; /* size of the message header */
613 ntrespoff = lmrespoff + 0x18;
614 domoff = ntrespoff + ntresplen;
615 useroff = domoff + domlen;
616 hostoff = useroff + userlen;
618 /* Create the big type-3 message binary blob */
619 size = msnprintf((char *)ntlmbuf, NTLM_BUFSIZE,
620 NTLMSSP_SIGNATURE "%c"
621 "\x03%c%c%c" /* 32-bit type = 3 */
623 "%c%c" /* LanManager length */
624 "%c%c" /* LanManager allocated space */
625 "%c%c" /* LanManager offset */
626 "%c%c" /* 2 zeroes */
628 "%c%c" /* NT-response length */
629 "%c%c" /* NT-response allocated space */
630 "%c%c" /* NT-response offset */
631 "%c%c" /* 2 zeroes */
633 "%c%c" /* domain length */
634 "%c%c" /* domain allocated space */
635 "%c%c" /* domain name offset */
636 "%c%c" /* 2 zeroes */
638 "%c%c" /* user length */
639 "%c%c" /* user allocated space */
640 "%c%c" /* user offset */
641 "%c%c" /* 2 zeroes */
643 "%c%c" /* host length */
644 "%c%c" /* host allocated space */
645 "%c%c" /* host offset */
646 "%c%c" /* 2 zeroes */
648 "%c%c" /* session key length (unknown purpose) */
649 "%c%c" /* session key allocated space (unknown purpose) */
650 "%c%c" /* session key offset (unknown purpose) */
651 "%c%c" /* 2 zeroes */
653 "%c%c%c%c", /* flags */
658 /* LanManager response */
661 0, /* null-termination */
662 0, 0, 0, /* type-3 long, the 24 upper bits */
664 SHORTPAIR(0x18), /* LanManager response length, twice */
666 SHORTPAIR(lmrespoff),
669 SHORTPAIR(ntresplen), /* NT-response length, twice */
670 SHORTPAIR(ntresplen),
671 SHORTPAIR(ntrespoff),
694 LONGQUARTET(ntlm->flags));
696 DEBUGASSERT(size == 64);
697 DEBUGASSERT(size == (size_t)lmrespoff);
699 /* We append the binary hashes */
700 if(size < (NTLM_BUFSIZE - 0x18)) {
701 memcpy(&ntlmbuf[size], lmresp, 0x18);
706 fprintf(stderr, "**** TYPE3 header lmresp=");
707 ntlm_print_hex(stderr, (char *)&ntlmbuf[lmrespoff], 0x18);
710 /* ntresplen + size should not be risking an integer overflow here */
711 if(ntresplen + size > sizeof(ntlmbuf)) {
712 failf(data, "incoming NTLM message too big");
713 return CURLE_OUT_OF_MEMORY;
715 DEBUGASSERT(size == (size_t)ntrespoff);
716 memcpy(&ntlmbuf[size], ptr_ntresp, ntresplen);
720 fprintf(stderr, "\n ntresp=");
721 ntlm_print_hex(stderr, (char *)&ntlmbuf[ntrespoff], ntresplen);
724 free(ntlmv2resp);/* Free the dynamic buffer allocated for NTLMv2 */
727 fprintf(stderr, "\n flags=0x%02.2x%02.2x%02.2x%02.2x 0x%08.8x ",
728 LONGQUARTET(ntlm->flags), ntlm->flags);
729 ntlm_print_flags(stderr, ntlm->flags);
730 fprintf(stderr, "\n****\n");
733 /* Make sure that the domain, user and host strings fit in the
734 buffer before we copy them there. */
735 if(size + userlen + domlen + hostlen >= NTLM_BUFSIZE) {
736 failf(data, "user + domain + host name too big");
737 return CURLE_OUT_OF_MEMORY;
740 DEBUGASSERT(size == domoff);
742 unicodecpy(&ntlmbuf[size], domain, domlen / 2);
744 memcpy(&ntlmbuf[size], domain, domlen);
748 DEBUGASSERT(size == useroff);
750 unicodecpy(&ntlmbuf[size], user, userlen / 2);
752 memcpy(&ntlmbuf[size], user, userlen);
756 DEBUGASSERT(size == hostoff);
758 unicodecpy(&ntlmbuf[size], host, hostlen / 2);
760 memcpy(&ntlmbuf[size], host, hostlen);
764 /* Return the binary blob. */
765 result = Curl_bufref_memdup(out, ntlmbuf, size);
767 Curl_auth_cleanup_ntlm(ntlm);
773 * Curl_auth_cleanup_ntlm()
775 * This is used to clean up the NTLM specific data.
779 * ntlm [in/out] - The NTLM data struct being cleaned up.
782 void Curl_auth_cleanup_ntlm(struct ntlmdata *ntlm)
784 /* Free the target info */
785 Curl_safefree(ntlm->target_info);
787 /* Reset any variables */
788 ntlm->target_info_len = 0;
791 #endif /* USE_NTLM && !USE_WINDOWS_SSPI */