2 Unix SMB/CIFS implementation.
4 Winbind status program.
6 Copyright (C) Tim Potter 2000-2003
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2003-2004
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.
26 #include "system/filesys.h"
27 #include "system/passwd.h"
28 #include "lib/cmdline/popt_common.h"
29 #include "auth/auth.h"
30 #include "librpc/gen_ndr/ndr_security.h"
32 #include "smb_build.h"
34 #define SQUID_BUFFER_SIZE 2010
36 enum stdio_helper_mode {
47 #define NTLM_AUTH_FLAG_USER_SESSION_KEY 0x0004
48 #define NTLM_AUTH_FLAG_LMKEY 0x0008
51 typedef void (*stdio_helper_function)(enum stdio_helper_mode stdio_helper_mode,
52 char *buf, int length, void **private,
53 unsigned int mux_id, void **private2);
55 static void manage_squid_basic_request (enum stdio_helper_mode stdio_helper_mode,
56 char *buf, int length, void **private,
57 unsigned int mux_id, void **private2);
59 static void manage_gensec_request (enum stdio_helper_mode stdio_helper_mode,
60 char *buf, int length, void **private,
61 unsigned int mux_id, void **private2);
63 static void manage_ntlm_server_1_request (enum stdio_helper_mode stdio_helper_mode,
64 char *buf, int length, void **private,
65 unsigned int mux_id, void **private2);
67 static void manage_squid_request(enum stdio_helper_mode helper_mode,
68 stdio_helper_function fn, void **private2);
71 enum stdio_helper_mode mode;
73 stdio_helper_function fn;
74 } stdio_helper_protocols[] = {
75 { SQUID_2_4_BASIC, "squid-2.4-basic", manage_squid_basic_request},
76 { SQUID_2_5_BASIC, "squid-2.5-basic", manage_squid_basic_request},
77 { SQUID_2_5_NTLMSSP, "squid-2.5-ntlmssp", manage_gensec_request},
78 { GSS_SPNEGO_CLIENT, "gss-spnego-client", manage_gensec_request},
79 { GSS_SPNEGO_SERVER, "gss-spnego", manage_gensec_request},
80 { NTLMSSP_CLIENT_1, "ntlmssp-client-1", manage_gensec_request},
81 { NTLM_SERVER_1, "ntlm-server-1", manage_ntlm_server_1_request},
82 { NUM_HELPER_MODES, NULL, NULL}
85 extern int winbindd_fd;
87 static const char *opt_username;
88 static const char *opt_domain;
89 static const char *opt_workstation;
90 static const char *opt_password;
91 static int opt_multiplex;
94 static void mux_printf(unsigned int mux_id, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
96 static void mux_printf(unsigned int mux_id, const char *format, ...)
101 x_fprintf(x_stdout, "%d ", mux_id);
104 va_start(ap, format);
105 x_vfprintf(x_stdout, format, ap);
111 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
112 form DOMAIN/user into a domain and a user */
114 static BOOL parse_ntlm_auth_domain_user(const char *domuser, fstring domain,
118 char *p = strchr(domuser,*lp_winbind_separator());
125 fstrcpy(domain, domuser);
126 domain[PTR_DIFF(p, domuser)] = 0;
131 /* Authenticate a user with a plaintext password */
133 static BOOL check_plaintext_auth(const char *user, const char *pass,
134 BOOL stdout_diagnostics)
136 return (strcmp(pass, opt_password) == 0);
139 /* authenticate a user with an encrypted username/password */
141 static NTSTATUS local_pw_check_specified(const char *username,
143 const char *workstation,
144 const DATA_BLOB *challenge,
145 const DATA_BLOB *lm_response,
146 const DATA_BLOB *nt_response,
148 DATA_BLOB *lm_session_key,
149 DATA_BLOB *user_session_key,
154 struct samr_Password lm_pw, nt_pw;
155 struct samr_Password *lm_pwd, *nt_pwd;
156 TALLOC_CTX *mem_ctx = talloc_init("local_pw_check_specified");
158 nt_status = NT_STATUS_NO_MEMORY;
161 E_md4hash(opt_password, nt_pw.hash);
162 if (E_deshash(opt_password, lm_pw.hash)) {
170 nt_status = ntlm_password_check(mem_ctx,
171 MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT |
172 MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT,
179 lm_pwd, nt_pwd, user_session_key, lm_session_key);
181 if (NT_STATUS_IS_OK(nt_status)) {
185 *lp_winbind_separator(),
189 DEBUG(3, ("Login for user [%s]\\[%s]@[%s] failed due to [%s]\n",
190 domain, username, workstation,
191 nt_errstr(nt_status)));
193 talloc_free(mem_ctx);
196 *error_string = strdup(nt_errstr(nt_status));
203 static void manage_squid_basic_request(enum stdio_helper_mode stdio_helper_mode,
204 char *buf, int length, void **private,
205 unsigned int mux_id, void **private2)
210 pass=memchr(buf,' ',length);
212 DEBUG(2, ("Password not found. Denying access\n"));
213 mux_printf(mux_id, "ERR\n");
219 if (stdio_helper_mode == SQUID_2_5_BASIC) {
220 rfc1738_unescape(user);
221 rfc1738_unescape(pass);
224 if (check_plaintext_auth(user, pass, False)) {
225 mux_printf(mux_id, "OK\n");
227 mux_printf(mux_id, "ERR\n");
231 /* This is a bit hairy, but the basic idea is to do a password callback
232 to the calling application. The callback comes from within gensec */
234 static void manage_gensec_get_pw_request(enum stdio_helper_mode stdio_helper_mode,
235 char *buf, int length, void **private,
236 unsigned int mux_id, void **password)
239 if (strlen(buf) < 2) {
240 DEBUG(1, ("query [%s] invalid", buf));
241 mux_printf(mux_id, "BH\n");
245 if (strlen(buf) > 3) {
246 in = base64_decode_data_blob(NULL, buf + 3);
248 in = data_blob(NULL, 0);
251 if (strncmp(buf, "PW ", 3) == 0) {
253 *password = talloc_strndup(*private /* hopefully the right gensec context, useful to use for talloc */,
254 (const char *)in.data, in.length);
256 if (*password == NULL) {
257 DEBUG(1, ("Out of memory\n"));
258 mux_printf(mux_id, "BH\n");
263 mux_printf(mux_id, "OK\n");
267 DEBUG(1, ("Asked for (and expected) a password\n"));
268 mux_printf(mux_id, "BH\n");
273 * Callback for password credentails. This is not async, and when
274 * GENSEC and the credentails code is made async, it will look rather
278 static const char *get_password(struct cli_credentials *credentials)
280 char *password = NULL;
282 /* Ask for a password */
283 mux_printf((unsigned int)credentials->priv_data, "PW\n");
284 credentials->priv_data = NULL;
286 manage_squid_request(NUM_HELPER_MODES /* bogus */, manage_gensec_get_pw_request, (void **)&password);
290 static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
291 char *buf, int length, void **private,
292 unsigned int mux_id, void **private2)
295 DATA_BLOB out = data_blob(NULL, 0);
296 char *out_base64 = NULL;
297 const char *reply_arg = NULL;
298 struct gensec_ntlm_state {
299 struct gensec_security *gensec_state;
300 const char *set_password;
302 struct gensec_ntlm_state *state;
306 const char *reply_code;
307 struct cli_credentials *creds;
314 state = talloc_zero(NULL, struct gensec_ntlm_state);
316 mux_printf(mux_id, "BH No Memory\n");
321 state->set_password = opt_password;
325 if (strlen(buf) < 2) {
326 DEBUG(1, ("query [%s] invalid", buf));
327 mux_printf(mux_id, "BH\n");
331 if (strlen(buf) > 3) {
332 in = base64_decode_data_blob(NULL, buf + 3);
334 in = data_blob(NULL, 0);
337 if (strncmp(buf, "YR", 2) == 0) {
338 if (state->gensec_state) {
339 talloc_free(state->gensec_state);
340 state->gensec_state = NULL;
342 } else if ( (strncmp(buf, "OK", 2) == 0)) {
346 } else if ( (strncmp(buf, "TT ", 3) != 0) &&
347 (strncmp(buf, "KK ", 3) != 0) &&
348 (strncmp(buf, "AF ", 3) != 0) &&
349 (strncmp(buf, "NA ", 3) != 0) &&
350 (strncmp(buf, "UG", 2) != 0) &&
351 (strncmp(buf, "PW ", 3) != 0)) {
352 DEBUG(1, ("SPNEGO request [%s] invalid\n", buf));
353 mux_printf(mux_id, "BH\n");
359 if (!(state->gensec_state)) {
360 switch (stdio_helper_mode) {
361 case GSS_SPNEGO_CLIENT:
362 case NTLMSSP_CLIENT_1:
363 /* setup the client side */
365 nt_status = gensec_client_start(NULL, &state->gensec_state, NULL);
366 if (!NT_STATUS_IS_OK(nt_status)) {
371 case GSS_SPNEGO_SERVER:
372 case SQUID_2_5_NTLMSSP:
373 if (!NT_STATUS_IS_OK(gensec_server_start(NULL, &state->gensec_state, NULL))) {
381 creds = cli_credentials_init(state->gensec_state);
382 cli_credentials_set_conf(creds);
384 cli_credentials_set_username(creds, opt_username, CRED_SPECIFIED);
387 cli_credentials_set_domain(creds, opt_domain, CRED_SPECIFIED);
389 if (state->set_password) {
390 cli_credentials_set_password(creds, state->set_password, CRED_SPECIFIED);
392 cli_credentials_set_password_callback(creds, get_password);
393 creds->priv_data = (void*)mux_id;
395 if (opt_workstation) {
396 cli_credentials_set_workstation(creds, opt_workstation, CRED_SPECIFIED);
399 switch (stdio_helper_mode) {
400 case GSS_SPNEGO_SERVER:
401 case SQUID_2_5_NTLMSSP:
402 cli_credentials_set_machine_account(creds);
408 gensec_set_credentials(state->gensec_state, creds);
410 switch (stdio_helper_mode) {
411 case GSS_SPNEGO_CLIENT:
412 case GSS_SPNEGO_SERVER:
413 nt_status = gensec_start_mech_by_oid(state->gensec_state, GENSEC_OID_SPNEGO);
418 case NTLMSSP_CLIENT_1:
422 case SQUID_2_5_NTLMSSP:
423 nt_status = gensec_start_mech_by_oid(state->gensec_state, GENSEC_OID_NTLMSSP);
429 if (!NT_STATUS_IS_OK(nt_status)) {
430 DEBUG(1, ("GENSEC mech failed to start: %s\n", nt_errstr(nt_status)));
431 mux_printf(mux_id, "BH\n");
438 mem_ctx = talloc_named(NULL, 0, "manage_gensec_request internal mem_ctx");
440 if (strncmp(buf, "PW ", 3) == 0) {
441 state->set_password = talloc_strndup(state,
442 (const char *)in.data,
445 cli_credentials_set_password(gensec_get_credentials(state->gensec_state),
448 mux_printf(mux_id, "OK\n");
450 talloc_free(mem_ctx);
454 if (strncmp(buf, "UG", 2) == 0) {
456 char *grouplist = NULL;
457 struct auth_session_info *session_info;
459 if (!NT_STATUS_IS_OK(gensec_session_info(state->gensec_state, &session_info))) {
460 DEBUG(1, ("gensec_session_info failed: %s\n", nt_errstr(nt_status)));
461 mux_printf(mux_id, "BH %s\n", nt_errstr(nt_status));
463 talloc_free(mem_ctx);
467 /* get the string onto the context */
468 grouplist = talloc_strdup(mem_ctx, "");
470 for (i=0; i<session_info->security_token->num_sids; i++) {
471 struct security_token *token = session_info->security_token;
472 const char *sidstr = dom_sid_string(session_info,
474 grouplist = talloc_asprintf_append(grouplist, "%s,", sidstr);
477 mux_printf(mux_id, "GL %s\n", grouplist);
478 talloc_free(session_info);
480 talloc_free(mem_ctx);
484 nt_status = gensec_update(state->gensec_state, mem_ctx, in, &out);
486 /* don't leak 'bad password'/'no such user' info to the network client */
487 nt_status = auth_nt_status_squash(nt_status);
490 out_base64 = base64_encode_data_blob(mem_ctx, out);
495 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
499 } else if (state->gensec_state->gensec_role == GENSEC_CLIENT) {
501 } else if (state->gensec_state->gensec_role == GENSEC_SERVER) {
508 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCESS_DENIED)) {
510 reply_arg = nt_errstr(nt_status);
511 DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
512 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_UNSUCCESSFUL)) {
514 reply_arg = nt_errstr(nt_status);
515 DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
516 } else if (!NT_STATUS_IS_OK(nt_status)) {
518 reply_arg = nt_errstr(nt_status);
519 DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
520 } else if /* OK */ (state->gensec_state->gensec_role == GENSEC_SERVER) {
521 struct auth_session_info *session_info;
523 nt_status = gensec_session_info(state->gensec_state, &session_info);
524 if (!NT_STATUS_IS_OK(nt_status)) {
526 reply_arg = nt_errstr(nt_status);
527 DEBUG(1, ("GENSEC failed to retreive the session info: %s\n", nt_errstr(nt_status)));
531 reply_arg = talloc_asprintf(state->gensec_state,
532 "%s%s%s", session_info->server_info->domain_name,
533 lp_winbind_separator(), session_info->server_info->account_name);
534 talloc_free(session_info);
536 } else if (state->gensec_state->gensec_role == GENSEC_CLIENT) {
538 reply_arg = out_base64;
543 switch (stdio_helper_mode) {
544 case GSS_SPNEGO_SERVER:
545 mux_printf(mux_id, "%s %s %s\n", reply_code,
546 out_base64 ? out_base64 : "*",
547 reply_arg ? reply_arg : "*");
551 mux_printf(mux_id, "%s %s\n", reply_code, out_base64);
552 } else if (reply_arg) {
553 mux_printf(mux_id, "%s %s\n", reply_code, reply_arg);
555 mux_printf(mux_id, "%s\n", reply_code);
559 talloc_free(mem_ctx);
563 static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mode,
564 char *buf, int length, void **private,
565 unsigned int mux_id, void **private2)
567 char *request, *parameter;
568 static DATA_BLOB challenge;
569 static DATA_BLOB lm_response;
570 static DATA_BLOB nt_response;
571 static char *full_username;
572 static char *username;
574 static char *plaintext_password;
575 static BOOL ntlm_server_1_user_session_key;
576 static BOOL ntlm_server_1_lm_session_key;
578 if (strequal(buf, ".")) {
579 if (!full_username && !username) {
580 mux_printf(mux_id, "Error: No username supplied!\n");
581 } else if (plaintext_password) {
582 /* handle this request as plaintext */
583 if (!full_username) {
584 if (asprintf(&full_username, "%s%c%s", domain, *lp_winbind_separator(), username) == -1) {
585 mux_printf(mux_id, "Error: Out of memory in asprintf!\n.\n");
589 if (check_plaintext_auth(full_username, plaintext_password, False)) {
590 mux_printf(mux_id, "Authenticated: Yes\n");
592 mux_printf(mux_id, "Authenticated: No\n");
594 } else if (!lm_response.data && !nt_response.data) {
595 mux_printf(mux_id, "Error: No password supplied!\n");
596 } else if (!challenge.data) {
597 mux_printf(mux_id, "Error: No lanman-challenge supplied!\n");
599 char *error_string = NULL;
601 DATA_BLOB user_session_key;
604 if (full_username && !username) {
608 if (!parse_ntlm_auth_domain_user(full_username, fstr_user, fstr_domain)) {
609 /* username might be 'tainted', don't print into our new-line deleimianted stream */
610 mux_printf(mux_id, "Error: Could not parse into domain and username\n");
614 username = smb_xstrdup(fstr_user);
615 domain = smb_xstrdup(fstr_domain);
619 domain = smb_xstrdup(lp_workgroup());
622 if (ntlm_server_1_lm_session_key)
623 flags |= NTLM_AUTH_FLAG_LMKEY;
625 if (ntlm_server_1_user_session_key)
626 flags |= NTLM_AUTH_FLAG_USER_SESSION_KEY;
628 if (!NT_STATUS_IS_OK(
629 local_pw_check_specified(username,
641 mux_printf(mux_id, "Authenticated: No\n");
642 mux_printf(mux_id, "Authentication-Error: %s\n.\n", error_string);
643 SAFE_FREE(error_string);
645 static char zeros[16];
647 char *hex_user_session_key;
649 mux_printf(mux_id, "Authenticated: Yes\n");
651 if (ntlm_server_1_lm_session_key
653 && (memcmp(zeros, lm_key.data,
654 lm_key.length) != 0)) {
655 hex_encode(lm_key.data,
658 mux_printf(mux_id, "LANMAN-Session-Key: %s\n", hex_lm_key);
659 SAFE_FREE(hex_lm_key);
662 if (ntlm_server_1_user_session_key
663 && user_session_key.length
664 && (memcmp(zeros, user_session_key.data,
665 user_session_key.length) != 0)) {
666 hex_encode(user_session_key.data,
667 user_session_key.length,
668 &hex_user_session_key);
669 mux_printf(mux_id, "User-Session-Key: %s\n", hex_user_session_key);
670 SAFE_FREE(hex_user_session_key);
674 /* clear out the state */
675 challenge = data_blob(NULL, 0);
676 nt_response = data_blob(NULL, 0);
677 lm_response = data_blob(NULL, 0);
678 SAFE_FREE(full_username);
681 SAFE_FREE(plaintext_password);
682 ntlm_server_1_user_session_key = False;
683 ntlm_server_1_lm_session_key = False;
684 mux_printf(mux_id, ".\n");
691 /* Indicates a base64 encoded structure */
692 parameter = strstr(request, ":: ");
694 parameter = strstr(request, ": ");
697 DEBUG(0, ("Parameter not found!\n"));
698 mux_printf(mux_id, "Error: Parameter not found!\n.\n");
715 base64_decode_inplace(parameter);
718 if (strequal(request, "LANMAN-Challenge")) {
719 challenge = strhex_to_data_blob(parameter);
720 if (challenge.length != 8) {
721 mux_printf(mux_id, "Error: hex decode of %s failed! (got %d bytes, expected 8)\n.\n",
723 (int)challenge.length);
724 challenge = data_blob(NULL, 0);
726 } else if (strequal(request, "NT-Response")) {
727 nt_response = strhex_to_data_blob(parameter);
728 if (nt_response.length < 24) {
729 mux_printf(mux_id, "Error: hex decode of %s failed! (only got %d bytes, needed at least 24)\n.\n",
731 (int)nt_response.length);
732 nt_response = data_blob(NULL, 0);
734 } else if (strequal(request, "LANMAN-Response")) {
735 lm_response = strhex_to_data_blob(parameter);
736 if (lm_response.length != 24) {
737 mux_printf(mux_id, "Error: hex decode of %s failed! (got %d bytes, expected 24)\n.\n",
739 (int)lm_response.length);
740 lm_response = data_blob(NULL, 0);
742 } else if (strequal(request, "Password")) {
743 plaintext_password = smb_xstrdup(parameter);
744 } else if (strequal(request, "NT-Domain")) {
745 domain = smb_xstrdup(parameter);
746 } else if (strequal(request, "Username")) {
747 username = smb_xstrdup(parameter);
748 } else if (strequal(request, "Full-Username")) {
749 full_username = smb_xstrdup(parameter);
750 } else if (strequal(request, "Request-User-Session-Key")) {
751 ntlm_server_1_user_session_key = strequal(parameter, "Yes");
752 } else if (strequal(request, "Request-LanMan-Session-Key")) {
753 ntlm_server_1_lm_session_key = strequal(parameter, "Yes");
755 mux_printf(mux_id, "Error: Unknown request %s\n.\n", request);
759 static void manage_squid_request(enum stdio_helper_mode helper_mode,
760 stdio_helper_function fn, void **private2)
762 char buf[SQUID_BUFFER_SIZE+1];
768 unsigned int max_mux;
769 void **private_pointers;
772 static struct mux_private *mux_private;
773 static void *normal_private;
776 /* this is not a typo - x_fgets doesn't work too well under squid */
777 if (fgets(buf, sizeof(buf)-1, stdin) == NULL) {
779 DEBUG(1, ("fgets() failed! dying..... errno=%d (%s)\n", ferror(stdin),
780 strerror(ferror(stdin))));
782 exit(1); /* BIIG buffer */
787 c=memchr(buf,'\n',sizeof(buf)-1);
796 DEBUG(0, ("Oversized message\n"));
797 x_fprintf(x_stdout, "ERR\n");
802 DEBUG(10, ("Got '%s' from squid (length: %d).\n",buf,length));
804 if (buf[0] == '\0') {
805 DEBUG(0, ("Invalid Request (empty)\n"));
806 x_fprintf(x_stdout, "ERR\n");
811 if (sscanf(buf, "%u ", &mux_id) != 1) {
812 DEBUG(0, ("Invalid Request - no multiplex id\n"));
813 x_fprintf(x_stdout, "ERR\n");
817 mux_private = talloc(NULL, struct mux_private);
818 mux_private->max_mux = 0;
819 mux_private->private_pointers = NULL;
824 DEBUG(0, ("Invalid Request - no data after multiplex id\n"));
825 x_fprintf(x_stdout, "ERR\n");
829 if (mux_id >= mux_private->max_mux) {
830 unsigned int prev_max = mux_private->max_mux;
831 mux_private->max_mux = mux_id + 1;
832 mux_private->private_pointers
833 = talloc_realloc(mux_private,
834 mux_private->private_pointers,
835 void *, mux_private->max_mux);
836 memset(&mux_private->private_pointers[prev_max], '\0',
837 (sizeof(*mux_private->private_pointers) * (mux_private->max_mux - prev_max)));
840 private = &mux_private->private_pointers[mux_id];
843 private = &normal_private;
846 fn(helper_mode, c, length, private, mux_id, private2);
849 static void squid_stream(enum stdio_helper_mode stdio_mode,
850 stdio_helper_function fn) {
851 /* initialize FDescs */
852 x_setbuf(x_stdout, NULL);
853 x_setbuf(x_stderr, NULL);
855 manage_squid_request(stdio_mode, fn, NULL);
872 OPT_USER_SESSION_KEY,
874 OPT_REQUIRE_MEMBERSHIP,
878 int main(int argc, const char **argv)
880 static const char *helper_protocol;
885 /* NOTE: DO NOT change this interface without considering the implications!
886 This is an external interface, which other programs will use to interact
890 /* We do not use single-letter command abbreviations, because they harm future
891 interface stability. */
893 struct poptOption long_options[] = {
895 { "helper-protocol", 0, POPT_ARG_STRING, &helper_protocol, OPT_DOMAIN, "operate as a stdio-based helper", "helper protocol to use"},
896 { "domain", 0, POPT_ARG_STRING, &opt_domain, OPT_DOMAIN, "domain name"},
897 { "workstation", 0, POPT_ARG_STRING, &opt_workstation, OPT_WORKSTATION, "workstation"},
898 { "username", 0, POPT_ARG_STRING, &opt_username, OPT_PASSWORD, "Username"},
899 { "password", 0, POPT_ARG_STRING, &opt_password, OPT_PASSWORD, "User's plaintext password"},
900 { "multiplex", 0, POPT_ARG_NONE, &opt_multiplex, OPT_MULTIPLEX, "Multiplex Mode"},
906 /* Samba client initialisation */
908 setup_logging(NULL, DEBUG_STDERR);
912 pc = poptGetContext("ntlm_auth", argc, argv, long_options, 0);
914 /* Parse command line options */
917 poptPrintHelp(pc, stderr, 0);
921 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
922 POPT_CONTEXT_KEEP_FIRST);
924 while((opt = poptGetNextOpt(pc)) != -1) {
930 fprintf(stderr, "%s: %s\n",
931 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
936 ntlm_auth_init_subsystems;
939 if (opt_domain == NULL) {
940 opt_domain = lp_workgroup();
943 if (helper_protocol) {
945 for (i=0; i<NUM_HELPER_MODES; i++) {
946 if (strcmp(helper_protocol, stdio_helper_protocols[i].name) == 0) {
947 squid_stream(stdio_helper_protocols[i].mode, stdio_helper_protocols[i].fn);
951 x_fprintf(x_stderr, "unknown helper protocol [%s]\n\nValid helper protools:\n\n", helper_protocol);
953 for (i=0; i<NUM_HELPER_MODES; i++) {
954 x_fprintf(x_stderr, "%s\n", stdio_helper_protocols[i].name);
961 x_fprintf(x_stderr, "username must be specified!\n\n");
962 poptPrintHelp(pc, stderr, 0);
966 if (opt_workstation == NULL) {
967 opt_workstation = lp_netbios_name();
971 opt_password = getpass("password: ");
977 asprintf(&user, "%s%c%s", opt_domain, *lp_winbind_separator(), opt_username);
978 if (!check_plaintext_auth(user, opt_password, True)) {