2 Unix SMB/CIFS implementation.
4 Winbind status program.
6 Copyright (C) Tim Potter 2000-2002
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2003
8 Copyright (C) Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it> 2000
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #define DBGC_CLASS DBGC_WINBIND
30 #define SQUID_BUFFER_SIZE 2010
41 extern int winbindd_fd;
43 static const char *opt_username;
44 static const char *opt_domain;
45 static const char *opt_workstation;
46 static const char *opt_password;
47 static DATA_BLOB opt_challenge;
48 static DATA_BLOB opt_lm_response;
49 static DATA_BLOB opt_nt_response;
50 static int request_lm_key;
51 static int request_nt_key;
54 static char winbind_separator(void)
56 struct winbindd_response response;
63 ZERO_STRUCT(response);
65 /* Send off request */
67 if (winbindd_request(WINBINDD_INFO, NULL, &response) !=
69 d_printf("could not obtain winbind separator!\n");
73 sep = response.data.info.winbind_separator;
77 d_printf("winbind separator was NULL!\n");
84 static const char *get_winbind_domain(void)
86 struct winbindd_response response;
88 static fstring winbind_domain;
89 if (*winbind_domain) {
90 return winbind_domain;
93 ZERO_STRUCT(response);
95 /* Send off request */
97 if (winbindd_request(WINBINDD_DOMAIN_NAME, NULL, &response) !=
99 d_printf("could not obtain winbind domain name!\n");
103 fstrcpy(winbind_domain, response.data.domain_name);
105 return winbind_domain;
109 static const char *get_winbind_netbios_name(void)
111 struct winbindd_response response;
113 static fstring winbind_netbios_name;
115 if (*winbind_netbios_name) {
116 return winbind_netbios_name;
119 ZERO_STRUCT(response);
121 /* Send off request */
123 if (winbindd_request(WINBINDD_NETBIOS_NAME, NULL, &response) !=
124 NSS_STATUS_SUCCESS) {
125 d_printf("could not obtain winbind netbios name!\n");
129 fstrcpy(winbind_netbios_name, response.data.netbios_name);
131 return winbind_netbios_name;
135 /* Authenticate a user with a plaintext password */
137 static BOOL check_plaintext_auth(const char *user, const char *pass, BOOL stdout_diagnostics)
139 struct winbindd_request request;
140 struct winbindd_response response;
143 /* Send off request */
145 ZERO_STRUCT(request);
146 ZERO_STRUCT(response);
148 fstrcpy(request.data.auth.user, user);
149 fstrcpy(request.data.auth.pass, pass);
151 result = winbindd_request(WINBINDD_PAM_AUTH, &request, &response);
153 /* Display response */
155 if (stdout_diagnostics) {
156 if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0)) {
157 d_printf("Reading winbind reply failed! (0x01)\n");
160 d_printf("%s: %s (0x%x)\n",
161 response.data.auth.nt_status_string,
162 response.data.auth.error_string,
163 response.data.auth.nt_status);
165 if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0)) {
166 DEBUG(1, ("Reading winbind reply failed! (0x01)\n"));
169 DEBUG(3, ("%s: %s (0x%x)\n",
170 response.data.auth.nt_status_string,
171 response.data.auth.error_string,
172 response.data.auth.nt_status));
175 return (result == NSS_STATUS_SUCCESS);
178 /* authenticate a user with an encrypted username/password */
180 static NTSTATUS contact_winbind_auth_crap(const char *username,
182 const char *workstation,
183 const DATA_BLOB *challenge,
184 const DATA_BLOB *lm_response,
185 const DATA_BLOB *nt_response,
193 struct winbindd_request request;
194 struct winbindd_response response;
196 static uint8 zeros[16];
198 ZERO_STRUCT(request);
199 ZERO_STRUCT(response);
201 request.flags = flags;
203 fstrcpy(request.data.auth_crap.user, username);
205 fstrcpy(request.data.auth_crap.domain, domain);
206 fstrcpy(request.data.auth_crap.workstation, workstation);
208 memcpy(request.data.auth_crap.chal, challenge->data, MIN(challenge->length, 8));
210 if (lm_response && lm_response->length) {
211 memcpy(request.data.auth_crap.lm_resp, lm_response->data, MIN(lm_response->length, sizeof(request.data.auth_crap.lm_resp)));
212 request.data.auth_crap.lm_resp_len = lm_response->length;
215 if (nt_response && nt_response->length) {
216 memcpy(request.data.auth_crap.nt_resp, nt_response->data, MIN(nt_response->length, sizeof(request.data.auth_crap.nt_resp)));
217 request.data.auth_crap.nt_resp_len = nt_response->length;
220 result = winbindd_request(WINBINDD_PAM_AUTH_CRAP, &request, &response);
222 /* Display response */
224 if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0)) {
225 nt_status = NT_STATUS_UNSUCCESSFUL;
227 *error_string = smb_xstrdup("Reading winbind reply failed!");
231 nt_status = (NT_STATUS(response.data.auth.nt_status));
232 if (!NT_STATUS_IS_OK(nt_status)) {
234 *error_string = smb_xstrdup(response.data.auth.error_string);
238 if ((flags & WBFLAG_PAM_LMKEY) && lm_key
239 && (memcmp(zeros, response.data.auth.first_8_lm_hash,
240 sizeof(response.data.auth.first_8_lm_hash)) != 0)) {
241 memcpy(lm_key, response.data.auth.first_8_lm_hash,
242 sizeof(response.data.auth.first_8_lm_hash));
244 if ((flags & WBFLAG_PAM_NTKEY) && nt_key
245 && (memcmp(zeros, response.data.auth.nt_session_key,
246 sizeof(response.data.auth.nt_session_key)) != 0)) {
247 memcpy(nt_key, response.data.auth.nt_session_key,
248 sizeof(response.data.auth.nt_session_key));
253 static NTSTATUS winbind_pw_check(struct ntlmssp_state *ntlmssp_state)
255 return contact_winbind_auth_crap(ntlmssp_state->user, ntlmssp_state->domain,
256 ntlmssp_state->workstation,
257 &ntlmssp_state->chal,
258 &ntlmssp_state->lm_resp,
259 &ntlmssp_state->nt_resp,
266 static void manage_squid_ntlmssp_request(enum squid_mode squid_mode,
267 char *buf, int length)
269 static NTLMSSP_STATE *ntlmssp_state = NULL;
270 DATA_BLOB request, reply;
273 if (strlen(buf) < 2) {
274 DEBUG(1, ("NTLMSSP query [%s] invalid", buf));
275 x_fprintf(x_stdout, "BH\n");
279 if (strlen(buf) > 3) {
280 request = base64_decode_data_blob(buf + 3);
281 } else if (strcmp(buf, "YR") == 0) {
282 request = data_blob(NULL, 0);
284 ntlmssp_server_end(&ntlmssp_state);
286 DEBUG(1, ("NTLMSSP query [%s] invalid", buf));
287 x_fprintf(x_stdout, "BH\n");
291 if (!ntlmssp_state) {
292 ntlmssp_server_start(&ntlmssp_state);
293 ntlmssp_state->check_password = winbind_pw_check;
294 ntlmssp_state->get_domain = get_winbind_domain;
295 ntlmssp_state->get_global_myname = get_winbind_netbios_name;
298 DEBUG(10, ("got NTLMSSP packet:\n"));
299 dump_data(10, request.data, request.length);
301 nt_status = ntlmssp_server_update(ntlmssp_state, request, &reply);
303 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
304 char *reply_base64 = base64_encode_data_blob(reply);
305 x_fprintf(x_stdout, "TT %s\n", reply_base64);
306 SAFE_FREE(reply_base64);
307 data_blob_free(&reply);
308 DEBUG(10, ("NTLMSSP challenge\n"));
309 } else if (!NT_STATUS_IS_OK(nt_status)) {
310 x_fprintf(x_stdout, "NA %s\n", nt_errstr(nt_status));
311 DEBUG(10, ("NTLMSSP %s\n", nt_errstr(nt_status)));
313 x_fprintf(x_stdout, "AF %s\\%s\n", ntlmssp_state->domain, ntlmssp_state->user);
314 DEBUG(10, ("NTLMSSP OK!\n"));
317 data_blob_free(&request);
320 static void manage_squid_basic_request(enum squid_mode squid_mode,
321 char *buf, int length)
326 pass=memchr(buf,' ',length);
328 DEBUG(2, ("Password not found. Denying access\n"));
329 x_fprintf(x_stderr, "ERR\n");
335 if (squid_mode == SQUID_2_5_BASIC) {
336 rfc1738_unescape(user);
337 rfc1738_unescape(pass);
340 if (check_plaintext_auth(user, pass, False)) {
341 x_fprintf(x_stdout, "OK\n");
343 x_fprintf(x_stdout, "ERR\n");
347 static void offer_gss_spnego_mechs(void) {
357 /* Server negTokenInit (mech offerings) */
358 spnego.type = SPNEGO_NEG_TOKEN_INIT;
359 spnego.negTokenInit.mechTypes = smb_xmalloc(sizeof(char *) * 2);
360 spnego.negTokenInit.mechTypes[0] = smb_xstrdup(OID_NTLMSSP);
361 spnego.negTokenInit.mechTypes[1] = NULL;
364 asn1_push_tag(&asn1, ASN1_SEQUENCE(0));
365 asn1_push_tag(&asn1, ASN1_CONTEXT(0));
366 asn1_write_GeneralString(&asn1, "NONE");
369 spnego.negTokenInit.mechListMIC = data_blob(asn1.data, asn1.length);
372 len = write_spnego_data(&token, &spnego);
373 free_spnego_data(&spnego);
376 DEBUG(1, ("Could not write SPNEGO data blob\n"));
377 x_fprintf(x_stdout, "BH\n");
381 reply_base64 = base64_encode_data_blob(token);
382 x_fprintf(x_stdout, "TT %s *\n", reply_base64);
384 SAFE_FREE(reply_base64);
385 data_blob_free(&token);
386 DEBUG(10, ("sent SPNEGO negTokenInit\n"));
390 static void manage_gss_spnego_request(enum squid_mode squid_mode,
391 char *buf, int length)
393 static NTLMSSP_STATE *ntlmssp_state = NULL;
395 DATA_BLOB request, token;
399 const char *reply_code;
401 pstring reply_argument;
403 if (strlen(buf) < 2) {
405 if (ntlmssp_state != NULL) {
406 DEBUG(1, ("Request for initial SPNEGO request where "
407 "we already have a state\n"));
408 x_fprintf(x_stdout, "BH\n");
412 DEBUG(1, ("NTLMSSP query [%s] invalid", buf));
413 x_fprintf(x_stdout, "BH\n");
417 if ( (strlen(buf) == 2) && (strcmp(buf, "YR") == 0) ) {
419 /* Initial request, get the negTokenInit offering
422 offer_gss_spnego_mechs();
426 /* All subsequent requests are "KK" (Knock, Knock ;)) and have
427 a blob. This might be negTokenInit or negTokenTarg */
429 if ( (strlen(buf) <= 3) || (strncmp(buf, "KK", 2) != 0) ) {
430 DEBUG(1, ("GSS-SPNEGO query [%s] invalid\n", buf));
431 x_fprintf(x_stdout, "BH\n");
435 request = base64_decode_data_blob(buf + 3);
436 len = read_spnego_data(request, &spnego);
437 data_blob_free(&request);
440 DEBUG(1, ("GSS-SPNEGO query [%s] invalid", buf));
441 x_fprintf(x_stdout, "BH\n");
445 if (spnego.type == SPNEGO_NEG_TOKEN_INIT) {
447 /* Second request from Client. This is where the
448 client offers its mechanism to use. We currently
449 only support NTLMSSP, the decision for Kerberos
450 would be taken here. */
452 if ( (spnego.negTokenInit.mechTypes == NULL) ||
453 (spnego.negTokenInit.mechTypes[0] == NULL) ) {
454 DEBUG(1, ("Client did not offer any mechanism"));
455 x_fprintf(x_stdout, "BH\n");
459 if ( strcmp(spnego.negTokenInit.mechTypes[0], OID_NTLMSSP) != 0 ) {
460 DEBUG(1, ("Client did not choose NTLMSSP but %s\n",
461 spnego.negTokenInit.mechTypes[0]));
462 x_fprintf(x_stdout, "BH\n");
466 if ( spnego.negTokenInit.mechToken.data == NULL ) {
467 DEBUG(1, ("Client did not provide NTLMSSP data\n"));
468 x_fprintf(x_stdout, "BH\n");
472 if ( ntlmssp_state != NULL ) {
473 DEBUG(1, ("Client wants a new NTLMSSP challenge, but "
474 "already got one\n"));
475 x_fprintf(x_stdout, "BH\n");
476 ntlmssp_server_end(&ntlmssp_state);
480 ntlmssp_server_start(&ntlmssp_state);
481 ntlmssp_state->check_password = winbind_pw_check;
482 ntlmssp_state->get_domain = get_winbind_domain;
483 ntlmssp_state->get_global_myname = get_winbind_netbios_name;
485 DEBUG(10, ("got NTLMSSP packet:\n"));
486 dump_data(10, spnego.negTokenInit.mechToken.data,
487 spnego.negTokenInit.mechToken.length);
489 free_spnego_data(&spnego);
491 spnego.type = SPNEGO_NEG_TOKEN_TARG;
492 spnego.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
493 spnego.negTokenTarg.supportedMech = strdup(OID_NTLMSSP);
495 status = ntlmssp_server_update(ntlmssp_state,
496 spnego.negTokenInit.mechToken,
497 &spnego.negTokenTarg.responseToken);
501 /* spnego.type == SPNEGO_NEG_TOKEN_TARG */
505 if (spnego.negTokenTarg.responseToken.data == NULL) {
506 DEBUG(1, ("Got a negTokenArg without a responseToken!\n"));
507 x_fprintf(x_stdout, "BH\n");
511 status = ntlmssp_server_update(ntlmssp_state,
512 spnego.negTokenTarg.responseToken,
515 data_blob_free(&spnego.negTokenTarg.responseToken);
517 spnego.negTokenTarg.responseToken = response;
521 if (NT_STATUS_IS_OK(status)) {
522 spnego.negTokenTarg.negResult = SPNEGO_ACCEPT_COMPLETED;
524 pstr_sprintf(reply_argument, "%s\\%s",
525 ntlmssp_state->domain, ntlmssp_state->user);
526 } else if (NT_STATUS_EQUAL(status,
527 NT_STATUS_MORE_PROCESSING_REQUIRED)) {
528 spnego.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
530 pstr_sprintf(reply_argument, "*");
532 spnego.negTokenTarg.negResult = SPNEGO_REJECT;
534 pstrcpy(reply_argument, nt_errstr(status));
537 len = write_spnego_data(&token, &spnego);
538 free_spnego_data(&spnego);
541 DEBUG(1, ("Could not write SPNEGO data blob\n"));
542 x_fprintf(x_stdout, "BH\n");
546 reply_base64 = base64_encode_data_blob(token);
548 x_fprintf(x_stdout, "%s %s %s\n",
549 reply_code, reply_base64, reply_argument);
551 SAFE_FREE(reply_base64);
552 data_blob_free(&token);
554 if (NT_STATUS_IS_OK(status)) {
555 ntlmssp_server_end(&ntlmssp_state);
561 static NTLMSSP_CLIENT_STATE *client_ntlmssp_state = NULL;
563 static void manage_client_ntlmssp_init(SPNEGO_DATA spnego)
566 DATA_BLOB null_blob = data_blob(NULL, 0);
568 char *to_server_base64;
569 const char *my_mechs[] = {OID_NTLMSSP, NULL};
571 DEBUG(10, ("Got spnego negTokenInit with NTLMSSP\n"));
573 if (client_ntlmssp_state != NULL) {
574 DEBUG(1, ("Request for initial SPNEGO request where "
575 "we already have a state\n"));
576 x_fprintf(x_stdout, "BH\n");
580 if ( (opt_username == NULL) || (opt_domain == NULL) ) {
581 DEBUG(1, ("Need username and domain for NTLMSSP\n"));
582 x_fprintf(x_stdout, "BH\n");
586 if (opt_password == NULL) {
588 /* Request a password from the calling process. After
589 sending it, the calling process should retry with
592 DEBUG(10, ("Requesting password\n"));
593 x_fprintf(x_stdout, "PW\n");
597 status = ntlmssp_client_start(&client_ntlmssp_state);
599 if (!NT_STATUS_IS_OK(status)) {
600 DEBUG(1, ("Could not start NTLMSSP client: %s\n",
602 x_fprintf(x_stdout, "BH\n");
603 ntlmssp_client_end(&client_ntlmssp_state);
607 status = ntlmssp_set_username(client_ntlmssp_state, opt_username);
609 if (!NT_STATUS_IS_OK(status)) {
610 DEBUG(1, ("Could not set username: %s\n",
612 x_fprintf(x_stdout, "BH\n");
613 ntlmssp_client_end(&client_ntlmssp_state);
617 status = ntlmssp_set_domain(client_ntlmssp_state, opt_domain);
619 if (!NT_STATUS_IS_OK(status)) {
620 DEBUG(1, ("Could not set domain: %s\n",
622 x_fprintf(x_stdout, "BH\n");
623 ntlmssp_client_end(&client_ntlmssp_state);
627 status = ntlmssp_set_password(client_ntlmssp_state, opt_password);
629 if (!NT_STATUS_IS_OK(status)) {
630 DEBUG(1, ("Could not set password: %s\n",
632 x_fprintf(x_stdout, "BH\n");
633 ntlmssp_client_end(&client_ntlmssp_state);
637 spnego.type = SPNEGO_NEG_TOKEN_INIT;
638 spnego.negTokenInit.mechTypes = my_mechs;
639 spnego.negTokenInit.reqFlags = 0;
640 spnego.negTokenInit.mechListMIC = null_blob;
642 status = ntlmssp_client_update(client_ntlmssp_state, null_blob,
643 &spnego.negTokenInit.mechToken);
645 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
646 DEBUG(1, ("Expected MORE_PROCESSING_REQUIRED, got: %s\n",
648 x_fprintf(x_stdout, "BH\n");
649 ntlmssp_client_end(&client_ntlmssp_state);
653 write_spnego_data(&to_server, &spnego);
654 data_blob_free(&spnego.negTokenInit.mechToken);
656 to_server_base64 = base64_encode_data_blob(to_server);
657 data_blob_free(&to_server);
658 x_fprintf(x_stdout, "KK %s\n", to_server_base64);
659 SAFE_FREE(to_server_base64);
663 static void manage_client_ntlmssp_targ(SPNEGO_DATA spnego)
666 DATA_BLOB null_blob = data_blob(NULL, 0);
669 char *to_server_base64;
671 DEBUG(10, ("Got spnego negTokenTarg with NTLMSSP\n"));
673 if (client_ntlmssp_state == NULL) {
674 DEBUG(1, ("Got NTLMSSP tArg without a client state\n"));
675 x_fprintf(x_stdout, "BH\n");
676 ntlmssp_client_end(&client_ntlmssp_state);
680 if (spnego.negTokenTarg.negResult == SPNEGO_REJECT) {
681 x_fprintf(x_stdout, "NA\n");
682 ntlmssp_client_end(&client_ntlmssp_state);
686 if (spnego.negTokenTarg.negResult == SPNEGO_ACCEPT_COMPLETED) {
687 x_fprintf(x_stdout, "AF\n");
688 ntlmssp_client_end(&client_ntlmssp_state);
692 status = ntlmssp_client_update(client_ntlmssp_state,
693 spnego.negTokenTarg.responseToken,
696 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
697 DEBUG(1, ("Expected MORE_PROCESSING_REQUIRED from "
698 "ntlmssp_client_update, got: %s\n",
700 x_fprintf(x_stdout, "BH\n");
701 data_blob_free(&request);
702 ntlmssp_client_end(&client_ntlmssp_state);
706 spnego.type = SPNEGO_NEG_TOKEN_TARG;
707 spnego.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
708 spnego.negTokenTarg.supportedMech = OID_NTLMSSP;
709 spnego.negTokenTarg.responseToken = request;
710 spnego.negTokenTarg.mechListMIC = null_blob;
712 write_spnego_data(&to_server, &spnego);
713 data_blob_free(&request);
715 to_server_base64 = base64_encode_data_blob(to_server);
716 data_blob_free(&to_server);
717 x_fprintf(x_stdout, "KK %s\n", to_server_base64);
718 SAFE_FREE(to_server_base64);
722 static void manage_client_krb5_init(SPNEGO_DATA spnego)
724 DEBUG(1, ("to be done ... \n"));
725 x_fprintf(x_stdout, "BH\n");
729 static void manage_client_krb5_targ(SPNEGO_DATA spnego)
731 DEBUG(1, ("Got a negTokenTarg with a Kerberos token. This should not "
733 x_fprintf(x_stdout, "BH\n");
737 static void manage_gss_spnego_client_request(enum squid_mode squid_mode,
738 char *buf, int length)
744 if (strlen(buf) <= 3) {
745 DEBUG(1, ("SPNEGO query [%s] too short\n", buf));
746 x_fprintf(x_stdout, "BH\n");
750 request = base64_decode_data_blob(buf+3);
752 if (strncmp(buf, "PW ", 3) == 0) {
754 /* We asked for a password and obviously got it :-) */
756 opt_password = strndup(request.data, request.length);
758 if (opt_password == NULL) {
759 DEBUG(1, ("Out of memory\n"));
760 x_fprintf(x_stdout, "BH\n");
761 data_blob_free(&request);
765 x_fprintf(x_stdout, "OK\n");
766 data_blob_free(&request);
770 if ( (strncmp(buf, "TT ", 3) != 0) &&
771 (strncmp(buf, "AF ", 3) != 0) &&
772 (strncmp(buf, "NA ", 3) != 0) ) {
773 DEBUG(1, ("SPNEGO request [%s] invalid\n", buf));
774 x_fprintf(x_stdout, "BH\n");
775 data_blob_free(&request);
779 /* So we got a server challenge to generate a SPNEGO
780 client-to-server request... */
782 len = read_spnego_data(request, &spnego);
783 data_blob_free(&request);
786 DEBUG(1, ("Could not read SPNEGO data for [%s]\n", buf));
787 x_fprintf(x_stdout, "BH\n");
791 if (spnego.type == SPNEGO_NEG_TOKEN_INIT) {
793 /* The server offers a list of mechanisms */
795 const char **mechType = spnego.negTokenInit.mechTypes;
797 while (*mechType != NULL) {
799 if (strcmp(*mechType, OID_NTLMSSP) == 0) {
800 manage_client_ntlmssp_init(spnego);
804 if (strcmp(*mechType, OID_KERBEROS5_OLD) == 0) {
805 manage_client_krb5_init(spnego);
812 DEBUG(1, ("Server offered no compatible mechanism\n"));
813 x_fprintf(x_stdout, "BH\n");
817 if (spnego.type == SPNEGO_NEG_TOKEN_TARG) {
819 if (strcmp(spnego.negTokenTarg.supportedMech,
821 manage_client_ntlmssp_targ(spnego);
825 if (strcmp(spnego.negTokenTarg.supportedMech,
826 OID_KERBEROS5_OLD) == 0) {
827 manage_client_krb5_targ(spnego);
833 DEBUG(1, ("Got an SPNEGO token I could not handle [%s]!\n", buf));
834 x_fprintf(x_stdout, "BH\n");
838 free_spnego_data(&spnego);
842 static void manage_squid_request(enum squid_mode squid_mode)
844 char buf[SQUID_BUFFER_SIZE+1];
849 /* this is not a typo - x_fgets doesn't work too well under squid */
850 if (fgets(buf, sizeof(buf)-1, stdin) == NULL) {
851 DEBUG(1, ("fgets() failed! dying..... errno=%d (%s)\n", ferror(stdin),
852 strerror(ferror(stdin))));
853 exit(1); /* BIIG buffer */
856 c=memchr(buf,'\n',sizeof(buf)-1);
865 DEBUG(2, ("Oversized message\n"));
866 x_fprintf(x_stderr, "ERR\n");
871 DEBUG(10, ("Got '%s' from squid (length: %d).\n",buf,length));
873 if (buf[0] == '\0') {
874 DEBUG(2, ("Invalid Request\n"));
875 x_fprintf(x_stderr, "ERR\n");
879 if (squid_mode == SQUID_2_5_BASIC || squid_mode == SQUID_2_4_BASIC) {
880 manage_squid_basic_request(squid_mode, buf, length);
881 } else if (squid_mode == SQUID_2_5_NTLMSSP) {
882 manage_squid_ntlmssp_request(squid_mode, buf, length);
883 } else if (squid_mode == GSS_SPNEGO) {
884 manage_gss_spnego_request(squid_mode, buf, length);
885 } else if (squid_mode == GSS_SPNEGO_CLIENT) {
886 manage_gss_spnego_client_request(squid_mode, buf, length);
891 static void squid_stream(enum squid_mode squid_mode) {
892 /* initialize FDescs */
893 x_setbuf(x_stdout, NULL);
894 x_setbuf(x_stderr, NULL);
896 manage_squid_request(squid_mode);
901 /* Authenticate a user with a challenge/response */
903 static BOOL check_auth_crap(void)
912 static uint8 zeros[16];
914 x_setbuf(x_stdout, NULL);
917 flags |= WBFLAG_PAM_LMKEY;
920 flags |= WBFLAG_PAM_NTKEY;
922 nt_status = contact_winbind_auth_crap(opt_username, opt_domain,
932 if (!NT_STATUS_IS_OK(nt_status)) {
933 x_fprintf(x_stdout, "%s (0x%x)\n",
935 NT_STATUS_V(nt_status));
936 SAFE_FREE(error_string);
941 && (memcmp(zeros, lm_key,
942 sizeof(lm_key)) != 0)) {
946 x_fprintf(x_stdout, "LM_KEY: %s\n", hex_lm_key);
947 SAFE_FREE(hex_lm_key);
950 && (memcmp(zeros, nt_key,
951 sizeof(nt_key)) != 0)) {
955 x_fprintf(x_stdout, "NT_KEY: %s\n", hex_nt_key);
956 SAFE_FREE(hex_nt_key);
963 Authenticate a user with a challenge/response, checking session key
964 and valid authentication types
967 static DATA_BLOB get_challenge(void)
969 static DATA_BLOB chal;
970 if (opt_challenge.length)
971 return opt_challenge;
973 chal = data_blob(NULL, 8);
975 generate_random_buffer(chal.data, chal.length, False);
980 * Test LM authentication, no NT response supplied
983 static BOOL test_lm(void)
987 DATA_BLOB lm_response = data_blob(NULL, 24);
992 DATA_BLOB chall = get_challenge();
998 flags |= WBFLAG_PAM_LMKEY;
999 flags |= WBFLAG_PAM_NTKEY;
1001 SMBencrypt(opt_password, chall.data, lm_response.data);
1002 E_deshash(opt_password, lm_hash);
1004 nt_status = contact_winbind_auth_crap(opt_username, opt_domain, opt_workstation,
1013 data_blob_free(&lm_response);
1015 if (!NT_STATUS_IS_OK(nt_status)) {
1016 d_printf("%s (0x%x)\n",
1018 NT_STATUS_V(nt_status));
1022 if (memcmp(lm_hash, lm_key,
1023 sizeof(lm_key)) != 0) {
1024 DEBUG(1, ("LM Key does not match expectations!\n"));
1025 DEBUG(1, ("lm_key:\n"));
1026 dump_data(1, lm_key, 8);
1027 DEBUG(1, ("expected:\n"));
1028 dump_data(1, lm_hash, 8);
1030 if (memcmp(lm_hash, nt_key, 8) != 0) {
1031 DEBUG(1, ("Session Key (first 8, lm hash) does not match expectations!\n"));
1032 DEBUG(1, ("nt_key:\n"));
1033 dump_data(1, nt_key, 8);
1034 DEBUG(1, ("expected:\n"));
1035 dump_data(1, lm_hash, 8);
1041 * Test the normal 'LM and NTLM' combination
1044 static BOOL test_lm_ntlm(void)
1049 DATA_BLOB lm_response = data_blob(NULL, 24);
1050 DATA_BLOB nt_response = data_blob(NULL, 24);
1051 DATA_BLOB session_key = data_blob(NULL, 16);
1057 DATA_BLOB chall = get_challenge();
1060 ZERO_STRUCT(lm_key);
1061 ZERO_STRUCT(nt_key);
1063 flags |= WBFLAG_PAM_LMKEY;
1064 flags |= WBFLAG_PAM_NTKEY;
1066 SMBencrypt(opt_password,chall.data,lm_response.data);
1067 E_deshash(opt_password, lm_hash);
1069 SMBNTencrypt(opt_password,chall.data,nt_response.data);
1071 E_md4hash(opt_password, nt_hash);
1072 SMBsesskeygen_ntv1(nt_hash, NULL, session_key.data);
1074 nt_status = contact_winbind_auth_crap(opt_username, opt_domain,
1084 data_blob_free(&lm_response);
1086 if (!NT_STATUS_IS_OK(nt_status)) {
1087 d_printf("%s (0x%x)\n",
1089 NT_STATUS_V(nt_status));
1090 SAFE_FREE(error_string);
1094 if (memcmp(lm_hash, lm_key,
1095 sizeof(lm_key)) != 0) {
1096 DEBUG(1, ("LM Key does not match expectations!\n"));
1097 DEBUG(1, ("lm_key:\n"));
1098 dump_data(1, lm_key, 8);
1099 DEBUG(1, ("expected:\n"));
1100 dump_data(1, lm_hash, 8);
1103 if (memcmp(session_key.data, nt_key,
1104 sizeof(nt_key)) != 0) {
1105 DEBUG(1, ("NT Session Key does not match expectations!\n"));
1106 DEBUG(1, ("nt_key:\n"));
1107 dump_data(1, nt_key, 16);
1108 DEBUG(1, ("expected:\n"));
1109 dump_data(1, session_key.data, session_key.length);
1116 * Test the NTLM response only, no LM.
1119 static BOOL test_ntlm(void)
1124 DATA_BLOB nt_response = data_blob(NULL, 24);
1125 DATA_BLOB session_key = data_blob(NULL, 16);
1131 DATA_BLOB chall = get_challenge();
1134 ZERO_STRUCT(lm_key);
1135 ZERO_STRUCT(nt_key);
1137 flags |= WBFLAG_PAM_LMKEY;
1138 flags |= WBFLAG_PAM_NTKEY;
1140 SMBNTencrypt(opt_password,chall.data,nt_response.data);
1141 E_md4hash(opt_password, nt_hash);
1142 SMBsesskeygen_ntv1(nt_hash, NULL, session_key.data);
1144 E_deshash(opt_password, lm_hash);
1146 nt_status = contact_winbind_auth_crap(opt_username, opt_domain,
1156 data_blob_free(&nt_response);
1158 if (!NT_STATUS_IS_OK(nt_status)) {
1159 d_printf("%s (0x%x)\n",
1161 NT_STATUS_V(nt_status));
1162 SAFE_FREE(error_string);
1166 if (memcmp(lm_hash, lm_key,
1167 sizeof(lm_key)) != 0) {
1168 DEBUG(1, ("LM Key does not match expectations!\n"));
1169 DEBUG(1, ("lm_key:\n"));
1170 dump_data(1, lm_key, 8);
1171 DEBUG(1, ("expected:\n"));
1172 dump_data(1, lm_hash, 8);
1175 if (memcmp(session_key.data, nt_key,
1176 sizeof(nt_key)) != 0) {
1177 DEBUG(1, ("NT Session Key does not match expectations!\n"));
1178 DEBUG(1, ("nt_key:\n"));
1179 dump_data(1, nt_key, 16);
1180 DEBUG(1, ("expected:\n"));
1181 dump_data(1, session_key.data, session_key.length);
1188 * Test the NTLM response only, but in the LM field.
1191 static BOOL test_ntlm_in_lm(void)
1196 DATA_BLOB nt_response = data_blob(NULL, 24);
1201 DATA_BLOB chall = get_challenge();
1204 ZERO_STRUCT(nt_key);
1206 flags |= WBFLAG_PAM_LMKEY;
1207 flags |= WBFLAG_PAM_NTKEY;
1209 SMBNTencrypt(opt_password,chall.data,nt_response.data);
1211 E_deshash(opt_password, lm_hash);
1213 nt_status = contact_winbind_auth_crap(opt_username, opt_domain,
1223 data_blob_free(&nt_response);
1225 if (!NT_STATUS_IS_OK(nt_status)) {
1226 d_printf("%s (0x%x)\n",
1228 NT_STATUS_V(nt_status));
1229 SAFE_FREE(error_string);
1233 if (memcmp(lm_hash, lm_key,
1234 sizeof(lm_key)) != 0) {
1235 DEBUG(1, ("LM Key does not match expectations!\n"));
1236 DEBUG(1, ("lm_key:\n"));
1237 dump_data(1, lm_key, 8);
1238 DEBUG(1, ("expected:\n"));
1239 dump_data(1, lm_hash, 8);
1242 if (memcmp(lm_hash, nt_key, 8) != 0) {
1243 DEBUG(1, ("Session Key (first 8 lm hash) does not match expectations!\n"));
1244 DEBUG(1, ("nt_key:\n"));
1245 dump_data(1, nt_key, 16);
1246 DEBUG(1, ("expected:\n"));
1247 dump_data(1, lm_hash, 8);
1254 * Test the NTLM response only, but in the both the NT and LM fields.
1257 static BOOL test_ntlm_in_both(void)
1262 DATA_BLOB nt_response = data_blob(NULL, 24);
1263 DATA_BLOB session_key = data_blob(NULL, 16);
1269 DATA_BLOB chall = get_challenge();
1272 ZERO_STRUCT(lm_key);
1273 ZERO_STRUCT(nt_key);
1275 flags |= WBFLAG_PAM_LMKEY;
1276 flags |= WBFLAG_PAM_NTKEY;
1278 SMBNTencrypt(opt_password,chall.data,nt_response.data);
1279 E_md4hash(opt_password, nt_hash);
1280 SMBsesskeygen_ntv1(nt_hash, NULL, session_key.data);
1282 E_deshash(opt_password, lm_hash);
1284 nt_status = contact_winbind_auth_crap(opt_username, opt_domain,
1294 data_blob_free(&nt_response);
1296 if (!NT_STATUS_IS_OK(nt_status)) {
1297 d_printf("%s (0x%x)\n",
1299 NT_STATUS_V(nt_status));
1300 SAFE_FREE(error_string);
1304 if (memcmp(lm_hash, lm_key,
1305 sizeof(lm_key)) != 0) {
1306 DEBUG(1, ("LM Key does not match expectations!\n"));
1307 DEBUG(1, ("lm_key:\n"));
1308 dump_data(1, lm_key, 8);
1309 DEBUG(1, ("expected:\n"));
1310 dump_data(1, lm_hash, 8);
1313 if (memcmp(session_key.data, nt_key,
1314 sizeof(nt_key)) != 0) {
1315 DEBUG(1, ("NT Session Key does not match expectations!\n"));
1316 DEBUG(1, ("nt_key:\n"));
1317 dump_data(1, nt_key, 16);
1318 DEBUG(1, ("expected:\n"));
1319 dump_data(1, session_key.data, session_key.length);
1328 * Test the NTLMv2 response only
1331 static BOOL test_ntlmv2(void)
1336 DATA_BLOB ntlmv2_response = data_blob(NULL, 0);
1337 DATA_BLOB nt_session_key = data_blob(NULL, 0);
1338 DATA_BLOB names_blob = NTLMv2_generate_names_blob(get_winbind_netbios_name(), get_winbind_domain());
1341 DATA_BLOB chall = get_challenge();
1344 ZERO_STRUCT(nt_key);
1346 flags |= WBFLAG_PAM_NTKEY;
1348 if (!SMBNTLMv2encrypt(opt_username, opt_domain, opt_password, &chall,
1350 NULL, &ntlmv2_response,
1352 data_blob_free(&names_blob);
1355 data_blob_free(&names_blob);
1357 nt_status = contact_winbind_auth_crap(opt_username, opt_domain,
1367 data_blob_free(&ntlmv2_response);
1369 if (!NT_STATUS_IS_OK(nt_status)) {
1370 d_printf("%s (0x%x)\n",
1372 NT_STATUS_V(nt_status));
1373 SAFE_FREE(error_string);
1377 if (memcmp(nt_session_key.data, nt_key,
1378 sizeof(nt_key)) != 0) {
1379 DEBUG(1, ("NT Session Key does not match expectations!\n"));
1380 DEBUG(1, ("nt_key:\n"));
1381 dump_data(1, nt_key, 16);
1382 DEBUG(1, ("expected:\n"));
1383 dump_data(1, nt_session_key.data, nt_session_key.length);
1390 * Test the NTLMv2 and LMv2 responses
1393 static BOOL test_lmv2_ntlmv2(void)
1398 DATA_BLOB ntlmv2_response = data_blob(NULL, 0);
1399 DATA_BLOB lmv2_response = data_blob(NULL, 0);
1400 DATA_BLOB nt_session_key = data_blob(NULL, 0);
1401 DATA_BLOB names_blob = NTLMv2_generate_names_blob(get_winbind_netbios_name(), get_winbind_domain());
1404 DATA_BLOB chall = get_challenge();
1407 ZERO_STRUCT(nt_key);
1409 flags |= WBFLAG_PAM_NTKEY;
1411 if (!SMBNTLMv2encrypt(opt_username, opt_domain, opt_password, &chall,
1413 &lmv2_response, &ntlmv2_response,
1415 data_blob_free(&names_blob);
1418 data_blob_free(&names_blob);
1420 nt_status = contact_winbind_auth_crap(opt_username, opt_domain,
1430 data_blob_free(&lmv2_response);
1431 data_blob_free(&ntlmv2_response);
1433 if (!NT_STATUS_IS_OK(nt_status)) {
1434 d_printf("%s (0x%x)\n",
1436 NT_STATUS_V(nt_status));
1437 SAFE_FREE(error_string);
1441 if (memcmp(nt_session_key.data, nt_key,
1442 sizeof(nt_key)) != 0) {
1443 DEBUG(1, ("NT Session Key does not match expectations!\n"));
1444 DEBUG(1, ("nt_key:\n"));
1445 dump_data(1, nt_key, 16);
1446 DEBUG(1, ("expected:\n"));
1447 dump_data(1, nt_session_key.data, nt_session_key.length);
1454 * Test the LMv2 response only
1457 static BOOL test_lmv2(void)
1462 DATA_BLOB lmv2_response = data_blob(NULL, 0);
1464 DATA_BLOB chall = get_challenge();
1467 if (!SMBNTLMv2encrypt(opt_username, opt_domain, opt_password, &chall,
1469 &lmv2_response, NULL,
1474 nt_status = contact_winbind_auth_crap(opt_username, opt_domain,
1484 data_blob_free(&lmv2_response);
1486 if (!NT_STATUS_IS_OK(nt_status)) {
1487 d_printf("%s (0x%x)\n",
1489 NT_STATUS_V(nt_status));
1490 SAFE_FREE(error_string);
1498 * Test the normal 'LM and NTLM' combination but deliberately break one
1501 static BOOL test_ntlm_broken(BOOL break_lm)
1506 DATA_BLOB lm_response = data_blob(NULL, 24);
1507 DATA_BLOB nt_response = data_blob(NULL, 24);
1508 DATA_BLOB session_key = data_blob(NULL, 16);
1514 DATA_BLOB chall = get_challenge();
1517 ZERO_STRUCT(lm_key);
1518 ZERO_STRUCT(nt_key);
1520 flags |= WBFLAG_PAM_LMKEY;
1521 flags |= WBFLAG_PAM_NTKEY;
1523 SMBencrypt(opt_password,chall.data,lm_response.data);
1524 E_deshash(opt_password, lm_hash);
1526 SMBNTencrypt(opt_password,chall.data,nt_response.data);
1528 E_md4hash(opt_password, nt_hash);
1529 SMBsesskeygen_ntv1(nt_hash, NULL, session_key.data);
1532 lm_response.data[0]++;
1534 nt_response.data[0]++;
1536 nt_status = contact_winbind_auth_crap(opt_username, opt_domain,
1546 data_blob_free(&lm_response);
1548 if (!NT_STATUS_IS_OK(nt_status)) {
1549 d_printf("%s (0x%x)\n",
1551 NT_STATUS_V(nt_status));
1552 SAFE_FREE(error_string);
1556 if (memcmp(lm_hash, lm_key,
1557 sizeof(lm_key)) != 0) {
1558 DEBUG(1, ("LM Key does not match expectations!\n"));
1559 DEBUG(1, ("lm_key:\n"));
1560 dump_data(1, lm_key, 8);
1561 DEBUG(1, ("expected:\n"));
1562 dump_data(1, lm_hash, 8);
1565 if (memcmp(session_key.data, nt_key,
1566 sizeof(nt_key)) != 0) {
1567 DEBUG(1, ("NT Session Key does not match expectations!\n"));
1568 DEBUG(1, ("nt_key:\n"));
1569 dump_data(1, nt_key, 16);
1570 DEBUG(1, ("expected:\n"));
1571 dump_data(1, session_key.data, session_key.length);
1577 static BOOL test_ntlm_lm_broken(void)
1579 return test_ntlm_broken(True);
1582 static BOOL test_ntlm_ntlm_broken(void)
1584 return test_ntlm_broken(False);
1587 static BOOL test_ntlmv2_broken(BOOL break_lmv2)
1592 DATA_BLOB ntlmv2_response = data_blob(NULL, 0);
1593 DATA_BLOB lmv2_response = data_blob(NULL, 0);
1594 DATA_BLOB nt_session_key = data_blob(NULL, 0);
1595 DATA_BLOB names_blob = NTLMv2_generate_names_blob(get_winbind_netbios_name(), get_winbind_domain());
1598 DATA_BLOB chall = get_challenge();
1601 ZERO_STRUCT(nt_key);
1603 flags |= WBFLAG_PAM_NTKEY;
1605 if (!SMBNTLMv2encrypt(opt_username, opt_domain, opt_password, &chall,
1607 &lmv2_response, &ntlmv2_response,
1609 data_blob_free(&names_blob);
1612 data_blob_free(&names_blob);
1614 /* Heh - this should break the appropriate password hash nicely! */
1617 lmv2_response.data[0]++;
1619 ntlmv2_response.data[0]++;
1621 nt_status = contact_winbind_auth_crap(opt_username, opt_domain,
1631 data_blob_free(&lmv2_response);
1632 data_blob_free(&ntlmv2_response);
1634 if (!NT_STATUS_IS_OK(nt_status)) {
1635 d_printf("%s (0x%x)\n",
1637 NT_STATUS_V(nt_status));
1638 SAFE_FREE(error_string);
1645 static BOOL test_ntlmv2_lmv2_broken(void)
1647 return test_ntlmv2_broken(True);
1650 static BOOL test_ntlmv2_ntlmv2_broken(void)
1652 return test_ntlmv2_broken(False);
1667 check we get the correct session key in each case
1668 check what values we get for the LM session key
1677 {test_lm_ntlm, "LM and NTLM"},
1678 {test_ntlm, "NTLM"},
1679 {test_ntlm_in_lm, "NTLM in LM"},
1680 {test_ntlm_in_both, "NTLM in both"},
1681 {test_ntlmv2, "NTLMv2"},
1682 {test_lmv2_ntlmv2, "NTLMv2 and LMv2"},
1683 {test_lmv2, "LMv2"},
1684 {test_ntlmv2_lmv2_broken, "NTLMv2 and LMv2, LMv2 broken"},
1685 {test_ntlmv2_ntlmv2_broken, "NTLMv2 and LMv2, NTLMv2 broken"},
1686 {test_ntlm_lm_broken, "NTLM and LM, LM broken"},
1687 {test_ntlm_ntlm_broken, "NTLM and LM, NTLM broken"}
1690 static BOOL diagnose_ntlm_auth(void)
1695 for (i=0; test_table[i].fn; i++) {
1696 if (!test_table[i].fn()) {
1697 DEBUG(1, ("Test %s failed!\n", test_table[i].name));
1708 OPT_USERNAME = 1000,
1721 int main(int argc, const char **argv)
1724 static const char *helper_protocol;
1725 static int diagnostics;
1727 static const char *hex_challenge;
1728 static const char *hex_lm_response;
1729 static const char *hex_nt_response;
1733 size_t challenge_len;
1734 size_t lm_response_len;
1735 size_t nt_response_len;
1739 /* NOTE: DO NOT change this interface without considering the implications!
1740 This is an external interface, which other programs will use to interact
1744 /* We do not use single-letter command abbreviations, because they harm future
1745 interface stability. */
1747 struct poptOption long_options[] = {
1749 { "helper-protocol", 0, POPT_ARG_STRING, &helper_protocol, OPT_DOMAIN, "operate as a stdio-based helper", "helper protocol to use"},
1750 { "username", 0, POPT_ARG_STRING, &opt_username, OPT_USERNAME, "username"},
1751 { "domain", 0, POPT_ARG_STRING, &opt_domain, OPT_DOMAIN, "domain name"},
1752 { "workstation", 0, POPT_ARG_STRING, &opt_workstation, OPT_WORKSTATION, "workstation"},
1753 { "challenge", 0, POPT_ARG_STRING, &hex_challenge, OPT_CHALLENGE, "challenge (HEX encoded)"},
1754 { "lm-response", 0, POPT_ARG_STRING, &hex_lm_response, OPT_LM, "LM Response to the challenge (HEX encoded)"},
1755 { "nt-response", 0, POPT_ARG_STRING, &hex_nt_response, OPT_NT, "NT or NTLMv2 Response to the challenge (HEX encoded)"},
1756 { "password", 0, POPT_ARG_STRING, &opt_password, OPT_PASSWORD, "User's plaintext password"},
1757 { "request-lm-key", 0, POPT_ARG_NONE, &request_lm_key, OPT_LM_KEY, "Retreive LM session key"},
1758 { "request-nt-key", 0, POPT_ARG_NONE, &request_nt_key, OPT_NT_KEY, "Retreive NT session key"},
1759 { "diagnostics", 0, POPT_ARG_NONE, &diagnostics, OPT_DIAGNOSTICS, "Perform diagnostics on the authentictaion chain"},
1764 /* Samba client initialisation */
1768 /* Samba client initialisation */
1770 if (!lp_load(dyn_CONFIGFILE, True, False, False)) {
1771 d_fprintf(stderr, "wbinfo: error opening config file %s. Error was %s\n",
1772 dyn_CONFIGFILE, strerror(errno));
1778 pc = poptGetContext("ntlm_auth", argc, argv, long_options, 0);
1780 /* Parse command line options */
1783 poptPrintHelp(pc, stderr, 0);
1787 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
1788 POPT_CONTEXT_KEEP_FIRST);
1790 while((opt = poptGetNextOpt(pc)) != -1) {
1793 challenge = smb_xmalloc((strlen(hex_challenge))/2+1);
1794 if ((challenge_len = strhex_to_str(challenge,
1795 strlen(hex_challenge),
1796 hex_challenge)) != 8) {
1797 x_fprintf(x_stderr, "hex decode of %s failed (only got %u bytes)!\n",
1798 hex_challenge, challenge_len);
1801 opt_challenge = data_blob(challenge, challenge_len);
1802 SAFE_FREE(challenge);
1805 lm_response = smb_xmalloc((strlen(hex_lm_response))/2+1);
1806 lm_response_len = strhex_to_str(lm_response,
1807 strlen(hex_lm_response),
1809 if (lm_response_len != 24) {
1810 x_fprintf(x_stderr, "hex decode of %s failed!\n", hex_lm_response);
1813 opt_lm_response = data_blob(lm_response, lm_response_len);
1814 SAFE_FREE(lm_response);
1817 nt_response = smb_xmalloc((strlen(hex_nt_response)+2)/2+1);
1818 nt_response_len = strhex_to_str(nt_response,
1819 strlen(hex_nt_response),
1821 if (nt_response_len < 24) {
1822 x_fprintf(x_stderr, "hex decode of %s failed!\n", hex_nt_response);
1825 opt_nt_response = data_blob(nt_response, nt_response_len);
1826 SAFE_FREE(nt_response);
1831 if (helper_protocol) {
1832 if (strcmp(helper_protocol, "squid-2.5-ntlmssp")== 0) {
1833 squid_stream(SQUID_2_5_NTLMSSP);
1834 } else if (strcmp(helper_protocol, "squid-2.5-basic")== 0) {
1835 squid_stream(SQUID_2_5_BASIC);
1836 } else if (strcmp(helper_protocol, "squid-2.4-basic")== 0) {
1837 squid_stream(SQUID_2_4_BASIC);
1838 } else if (strcmp(helper_protocol, "gss-spnego")== 0) {
1839 squid_stream(GSS_SPNEGO);
1840 } else if (strcmp(helper_protocol, "gss-spnego-client") == 0) {
1841 squid_stream(GSS_SPNEGO_CLIENT);
1843 x_fprintf(x_stderr, "unknown helper protocol [%s]\n", helper_protocol);
1848 if (!opt_username) {
1849 x_fprintf(x_stderr, "username must be specified!\n\n");
1850 poptPrintHelp(pc, stderr, 0);
1854 if (opt_domain == NULL) {
1855 opt_domain = get_winbind_domain();
1858 if (opt_workstation == NULL) {
1859 opt_workstation = "";
1862 if (opt_challenge.length) {
1863 if (!check_auth_crap()) {
1869 if (!opt_password) {
1870 opt_password = getpass("password: ");
1874 if (!diagnose_ntlm_auth()) {
1880 fstr_sprintf(user, "%s%c%s", opt_domain, winbind_separator(), opt_username);
1881 if (!check_plaintext_auth(user, opt_password, True)) {
1888 poptFreeContext(pc);