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 "lib/cmdline/popt_common.h"
28 #include "auth/auth.h"
30 #include "libcli/auth/libcli_auth.h"
31 #include "librpc/gen_ndr/ndr_security.h"
33 #define SQUID_BUFFER_SIZE 2010
35 enum stdio_helper_mode {
46 #define NTLM_AUTH_FLAG_USER_SESSION_KEY 0x0004
47 #define NTLM_AUTH_FLAG_LMKEY 0x0008
50 typedef void (*stdio_helper_function)(enum stdio_helper_mode stdio_helper_mode,
51 char *buf, int length, void **private,
52 unsigned int mux_id, void **private2);
54 static void manage_squid_basic_request (enum stdio_helper_mode stdio_helper_mode,
55 char *buf, int length, void **private,
56 unsigned int mux_id, void **private2);
58 static void manage_gensec_request (enum stdio_helper_mode stdio_helper_mode,
59 char *buf, int length, void **private,
60 unsigned int mux_id, void **private2);
62 static void manage_ntlm_server_1_request (enum stdio_helper_mode stdio_helper_mode,
63 char *buf, int length, void **private,
64 unsigned int mux_id, void **private2);
66 static void manage_squid_request(enum stdio_helper_mode helper_mode,
67 stdio_helper_function fn, void **private2);
70 enum stdio_helper_mode mode;
72 stdio_helper_function fn;
73 } stdio_helper_protocols[] = {
74 { SQUID_2_4_BASIC, "squid-2.4-basic", manage_squid_basic_request},
75 { SQUID_2_5_BASIC, "squid-2.5-basic", manage_squid_basic_request},
76 { SQUID_2_5_NTLMSSP, "squid-2.5-ntlmssp", manage_gensec_request},
77 { GSS_SPNEGO_CLIENT, "gss-spnego-client", manage_gensec_request},
78 { GSS_SPNEGO_SERVER, "gss-spnego", manage_gensec_request},
79 { NTLMSSP_CLIENT_1, "ntlmssp-client-1", manage_gensec_request},
80 { NTLM_SERVER_1, "ntlm-server-1", manage_ntlm_server_1_request},
81 { NUM_HELPER_MODES, NULL, NULL}
84 extern int winbindd_fd;
86 static const char *opt_username;
87 static const char *opt_domain;
88 static const char *opt_workstation;
89 static const char *opt_password;
90 static int opt_multiplex;
93 static void mux_printf(unsigned int mux_id, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
95 static void mux_printf(unsigned int mux_id, const char *format, ...)
100 x_fprintf(x_stdout, "%d ", mux_id);
103 va_start(ap, format);
104 x_vfprintf(x_stdout, format, ap);
110 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
111 form DOMAIN/user into a domain and a user */
113 static BOOL parse_ntlm_auth_domain_user(const char *domuser, fstring domain,
117 char *p = strchr(domuser,*lp_winbind_separator());
124 fstrcpy(domain, domuser);
125 domain[PTR_DIFF(p, domuser)] = 0;
130 /* Authenticate a user with a plaintext password */
132 static BOOL check_plaintext_auth(const char *user, const char *pass,
133 BOOL stdout_diagnostics)
135 return (strcmp(pass, opt_password) == 0);
138 /* authenticate a user with an encrypted username/password */
140 static NTSTATUS local_pw_check_specified(const char *username,
142 const char *workstation,
143 const DATA_BLOB *challenge,
144 const DATA_BLOB *lm_response,
145 const DATA_BLOB *nt_response,
147 DATA_BLOB *lm_session_key,
148 DATA_BLOB *user_session_key,
153 struct samr_Password lm_pw, nt_pw;
154 struct samr_Password *lm_pwd, *nt_pwd;
155 TALLOC_CTX *mem_ctx = talloc_init("local_pw_check_specified");
157 nt_status = NT_STATUS_NO_MEMORY;
160 E_md4hash(opt_password, nt_pw.hash);
161 if (E_deshash(opt_password, lm_pw.hash)) {
169 nt_status = ntlm_password_check(mem_ctx,
170 MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT |
171 MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT,
178 lm_pwd, nt_pwd, user_session_key, lm_session_key);
180 if (NT_STATUS_IS_OK(nt_status)) {
184 *lp_winbind_separator(),
188 DEBUG(3, ("Login for user [%s]\\[%s]@[%s] failed due to [%s]\n",
189 domain, username, workstation,
190 nt_errstr(nt_status)));
192 talloc_free(mem_ctx);
195 *error_string = strdup(nt_errstr(nt_status));
202 static void manage_squid_basic_request(enum stdio_helper_mode stdio_helper_mode,
203 char *buf, int length, void **private,
204 unsigned int mux_id, void **private2)
209 pass=memchr(buf,' ',length);
211 DEBUG(2, ("Password not found. Denying access\n"));
212 mux_printf(mux_id, "ERR\n");
218 if (stdio_helper_mode == SQUID_2_5_BASIC) {
219 rfc1738_unescape(user);
220 rfc1738_unescape(pass);
223 if (check_plaintext_auth(user, pass, False)) {
224 mux_printf(mux_id, "OK\n");
226 mux_printf(mux_id, "ERR\n");
230 /* This is a bit hairy, but the basic idea is to do a password callback
231 to the calling application. The callback comes from within gensec */
233 static void manage_gensec_get_pw_request(enum stdio_helper_mode stdio_helper_mode,
234 char *buf, int length, void **private,
235 unsigned int mux_id, void **password)
238 if (strlen(buf) < 2) {
239 DEBUG(1, ("query [%s] invalid", buf));
240 mux_printf(mux_id, "BH\n");
244 if (strlen(buf) > 3) {
245 in = base64_decode_data_blob(NULL, buf + 3);
247 in = data_blob(NULL, 0);
250 if (strncmp(buf, "PW ", 3) == 0) {
252 *password = talloc_strndup(*private /* hopefully the right gensec context, useful to use for talloc */,
253 (const char *)in.data, in.length);
255 if (*password == NULL) {
256 DEBUG(1, ("Out of memory\n"));
257 mux_printf(mux_id, "BH\n");
262 mux_printf(mux_id, "OK\n");
266 DEBUG(1, ("Asked for (and expected) a password\n"));
267 mux_printf(mux_id, "BH\n");
272 * Callback for password credentails. This is not async, and when
273 * GENSEC and the credentails code is made async, it will look rather
277 static const char *get_password(struct cli_credentials *credentials)
279 char *password = NULL;
281 /* Ask for a password */
282 mux_printf((unsigned int)credentials->priv_data, "PW\n");
283 credentials->priv_data = NULL;
285 manage_squid_request(NUM_HELPER_MODES /* bogus */, manage_gensec_get_pw_request, (void **)&password);
289 static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
290 char *buf, int length, void **private,
291 unsigned int mux_id, void **private2)
294 DATA_BLOB out = data_blob(NULL, 0);
295 char *out_base64 = NULL;
296 const char *reply_arg = NULL;
297 struct gensec_ntlm_state {
298 struct gensec_security *gensec_state;
299 const char *set_password;
301 struct gensec_ntlm_state *state;
305 const char *reply_code;
306 struct cli_credentials *creds;
313 state = talloc_zero(NULL, struct gensec_ntlm_state);
315 mux_printf(mux_id, "BH No Memory\n");
320 state->set_password = opt_password;
324 if (strlen(buf) < 2) {
325 DEBUG(1, ("query [%s] invalid", buf));
326 mux_printf(mux_id, "BH\n");
330 if (strlen(buf) > 3) {
331 in = base64_decode_data_blob(NULL, buf + 3);
333 in = data_blob(NULL, 0);
336 if (strncmp(buf, "YR", 2) == 0) {
337 if (state->gensec_state) {
338 talloc_free(state->gensec_state);
339 state->gensec_state = NULL;
341 } else if ( (strncmp(buf, "OK", 2) == 0)) {
345 } else if ( (strncmp(buf, "TT ", 3) != 0) &&
346 (strncmp(buf, "KK ", 3) != 0) &&
347 (strncmp(buf, "AF ", 3) != 0) &&
348 (strncmp(buf, "NA ", 3) != 0) &&
349 (strncmp(buf, "UG", 2) != 0) &&
350 (strncmp(buf, "PW ", 3) != 0)) {
351 DEBUG(1, ("SPNEGO request [%s] invalid\n", buf));
352 mux_printf(mux_id, "BH\n");
358 if (!(state->gensec_state)) {
359 switch (stdio_helper_mode) {
360 case GSS_SPNEGO_CLIENT:
361 case NTLMSSP_CLIENT_1:
362 /* setup the client side */
364 nt_status = gensec_client_start(NULL, &state->gensec_state, NULL);
365 if (!NT_STATUS_IS_OK(nt_status)) {
370 case GSS_SPNEGO_SERVER:
371 case SQUID_2_5_NTLMSSP:
372 if (!NT_STATUS_IS_OK(gensec_server_start(NULL, &state->gensec_state, NULL))) {
380 creds = cli_credentials_init(state->gensec_state);
381 cli_credentials_set_conf(creds);
383 cli_credentials_set_username(creds, opt_username, CRED_SPECIFIED);
386 cli_credentials_set_domain(creds, opt_domain, CRED_SPECIFIED);
388 if (state->set_password) {
389 cli_credentials_set_password(creds, state->set_password, CRED_SPECIFIED);
391 cli_credentials_set_password_callback(creds, get_password);
392 creds->priv_data = (void*)mux_id;
394 if (opt_workstation) {
395 cli_credentials_set_workstation(creds, opt_workstation, CRED_SPECIFIED);
398 switch (stdio_helper_mode) {
399 case GSS_SPNEGO_SERVER:
400 case SQUID_2_5_NTLMSSP:
401 cli_credentials_set_machine_account(creds);
407 gensec_set_credentials(state->gensec_state, creds);
409 switch (stdio_helper_mode) {
410 case GSS_SPNEGO_CLIENT:
411 case GSS_SPNEGO_SERVER:
412 nt_status = gensec_start_mech_by_oid(state->gensec_state, GENSEC_OID_SPNEGO);
417 case NTLMSSP_CLIENT_1:
421 case SQUID_2_5_NTLMSSP:
422 nt_status = gensec_start_mech_by_oid(state->gensec_state, GENSEC_OID_NTLMSSP);
428 if (!NT_STATUS_IS_OK(nt_status)) {
429 DEBUG(1, ("GENSEC mech failed to start: %s\n", nt_errstr(nt_status)));
430 mux_printf(mux_id, "BH\n");
437 mem_ctx = talloc_named(NULL, 0, "manage_gensec_request internal mem_ctx");
439 if (strncmp(buf, "PW ", 3) == 0) {
440 state->set_password = talloc_strndup(state,
441 (const char *)in.data,
444 cli_credentials_set_password(gensec_get_credentials(state->gensec_state),
447 mux_printf(mux_id, "OK\n");
449 talloc_free(mem_ctx);
453 if (strncmp(buf, "UG", 2) == 0) {
455 char *grouplist = NULL;
456 struct auth_session_info *session_info;
458 if (!NT_STATUS_IS_OK(gensec_session_info(state->gensec_state, &session_info))) {
459 DEBUG(1, ("gensec_session_info failed: %s\n", nt_errstr(nt_status)));
460 mux_printf(mux_id, "BH %s\n", nt_errstr(nt_status));
462 talloc_free(mem_ctx);
466 /* get the string onto the context */
467 grouplist = talloc_strdup(mem_ctx, "");
469 for (i=0; i<session_info->security_token->num_sids; i++) {
470 struct security_token *token = session_info->security_token;
471 const char *sidstr = dom_sid_string(session_info,
473 grouplist = talloc_asprintf_append(grouplist, "%s,", sidstr);
476 mux_printf(mux_id, "GL %s\n", grouplist);
477 talloc_free(session_info);
479 talloc_free(mem_ctx);
483 nt_status = gensec_update(state->gensec_state, mem_ctx, in, &out);
485 /* don't leak 'bad password'/'no such user' info to the network client */
486 nt_status = auth_nt_status_squash(nt_status);
489 out_base64 = base64_encode_data_blob(mem_ctx, out);
494 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
498 } else if (state->gensec_state->gensec_role == GENSEC_CLIENT) {
500 } else if (state->gensec_state->gensec_role == GENSEC_SERVER) {
507 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCESS_DENIED)) {
509 reply_arg = nt_errstr(nt_status);
510 DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
511 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_UNSUCCESSFUL)) {
513 reply_arg = nt_errstr(nt_status);
514 DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
515 } else if (!NT_STATUS_IS_OK(nt_status)) {
517 reply_arg = nt_errstr(nt_status);
518 DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
519 } else if /* OK */ (state->gensec_state->gensec_role == GENSEC_SERVER) {
520 struct auth_session_info *session_info;
522 nt_status = gensec_session_info(state->gensec_state, &session_info);
523 if (!NT_STATUS_IS_OK(nt_status)) {
525 reply_arg = nt_errstr(nt_status);
526 DEBUG(1, ("GENSEC failed to retreive the session info: %s\n", nt_errstr(nt_status)));
530 reply_arg = talloc_asprintf(state->gensec_state,
531 "%s%s%s", session_info->server_info->domain_name,
532 lp_winbind_separator(), session_info->server_info->account_name);
533 talloc_free(session_info);
535 } else if (state->gensec_state->gensec_role == GENSEC_CLIENT) {
537 reply_arg = out_base64;
542 switch (stdio_helper_mode) {
543 case GSS_SPNEGO_SERVER:
544 mux_printf(mux_id, "%s %s %s\n", reply_code,
545 out_base64 ? out_base64 : "*",
546 reply_arg ? reply_arg : "*");
550 mux_printf(mux_id, "%s %s\n", reply_code, out_base64);
551 } else if (reply_arg) {
552 mux_printf(mux_id, "%s %s\n", reply_code, reply_arg);
554 mux_printf(mux_id, "%s\n", reply_code);
558 talloc_free(mem_ctx);
562 static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mode,
563 char *buf, int length, void **private,
564 unsigned int mux_id, void **private2)
566 char *request, *parameter;
567 static DATA_BLOB challenge;
568 static DATA_BLOB lm_response;
569 static DATA_BLOB nt_response;
570 static char *full_username;
571 static char *username;
573 static char *plaintext_password;
574 static BOOL ntlm_server_1_user_session_key;
575 static BOOL ntlm_server_1_lm_session_key;
577 if (strequal(buf, ".")) {
578 if (!full_username && !username) {
579 mux_printf(mux_id, "Error: No username supplied!\n");
580 } else if (plaintext_password) {
581 /* handle this request as plaintext */
582 if (!full_username) {
583 if (asprintf(&full_username, "%s%c%s", domain, *lp_winbind_separator(), username) == -1) {
584 mux_printf(mux_id, "Error: Out of memory in asprintf!\n.\n");
588 if (check_plaintext_auth(full_username, plaintext_password, False)) {
589 mux_printf(mux_id, "Authenticated: Yes\n");
591 mux_printf(mux_id, "Authenticated: No\n");
593 } else if (!lm_response.data && !nt_response.data) {
594 mux_printf(mux_id, "Error: No password supplied!\n");
595 } else if (!challenge.data) {
596 mux_printf(mux_id, "Error: No lanman-challenge supplied!\n");
598 char *error_string = NULL;
600 DATA_BLOB user_session_key;
603 if (full_username && !username) {
607 if (!parse_ntlm_auth_domain_user(full_username, fstr_user, fstr_domain)) {
608 /* username might be 'tainted', don't print into our new-line deleimianted stream */
609 mux_printf(mux_id, "Error: Could not parse into domain and username\n");
613 username = smb_xstrdup(fstr_user);
614 domain = smb_xstrdup(fstr_domain);
618 domain = smb_xstrdup(lp_workgroup());
621 if (ntlm_server_1_lm_session_key)
622 flags |= NTLM_AUTH_FLAG_LMKEY;
624 if (ntlm_server_1_user_session_key)
625 flags |= NTLM_AUTH_FLAG_USER_SESSION_KEY;
627 if (!NT_STATUS_IS_OK(
628 local_pw_check_specified(username,
640 mux_printf(mux_id, "Authenticated: No\n");
641 mux_printf(mux_id, "Authentication-Error: %s\n.\n", error_string);
642 SAFE_FREE(error_string);
644 static char zeros[16];
646 char *hex_user_session_key;
648 mux_printf(mux_id, "Authenticated: Yes\n");
650 if (ntlm_server_1_lm_session_key
652 && (memcmp(zeros, lm_key.data,
653 lm_key.length) != 0)) {
654 hex_encode(lm_key.data,
657 mux_printf(mux_id, "LANMAN-Session-Key: %s\n", hex_lm_key);
658 SAFE_FREE(hex_lm_key);
661 if (ntlm_server_1_user_session_key
662 && user_session_key.length
663 && (memcmp(zeros, user_session_key.data,
664 user_session_key.length) != 0)) {
665 hex_encode(user_session_key.data,
666 user_session_key.length,
667 &hex_user_session_key);
668 mux_printf(mux_id, "User-Session-Key: %s\n", hex_user_session_key);
669 SAFE_FREE(hex_user_session_key);
673 /* clear out the state */
674 challenge = data_blob(NULL, 0);
675 nt_response = data_blob(NULL, 0);
676 lm_response = data_blob(NULL, 0);
677 SAFE_FREE(full_username);
680 SAFE_FREE(plaintext_password);
681 ntlm_server_1_user_session_key = False;
682 ntlm_server_1_lm_session_key = False;
683 mux_printf(mux_id, ".\n");
690 /* Indicates a base64 encoded structure */
691 parameter = strstr(request, ":: ");
693 parameter = strstr(request, ": ");
696 DEBUG(0, ("Parameter not found!\n"));
697 mux_printf(mux_id, "Error: Parameter not found!\n.\n");
714 base64_decode_inplace(parameter);
717 if (strequal(request, "LANMAN-Challenge")) {
718 challenge = strhex_to_data_blob(parameter);
719 if (challenge.length != 8) {
720 mux_printf(mux_id, "Error: hex decode of %s failed! (got %d bytes, expected 8)\n.\n",
722 (int)challenge.length);
723 challenge = data_blob(NULL, 0);
725 } else if (strequal(request, "NT-Response")) {
726 nt_response = strhex_to_data_blob(parameter);
727 if (nt_response.length < 24) {
728 mux_printf(mux_id, "Error: hex decode of %s failed! (only got %d bytes, needed at least 24)\n.\n",
730 (int)nt_response.length);
731 nt_response = data_blob(NULL, 0);
733 } else if (strequal(request, "LANMAN-Response")) {
734 lm_response = strhex_to_data_blob(parameter);
735 if (lm_response.length != 24) {
736 mux_printf(mux_id, "Error: hex decode of %s failed! (got %d bytes, expected 24)\n.\n",
738 (int)lm_response.length);
739 lm_response = data_blob(NULL, 0);
741 } else if (strequal(request, "Password")) {
742 plaintext_password = smb_xstrdup(parameter);
743 } else if (strequal(request, "NT-Domain")) {
744 domain = smb_xstrdup(parameter);
745 } else if (strequal(request, "Username")) {
746 username = smb_xstrdup(parameter);
747 } else if (strequal(request, "Full-Username")) {
748 full_username = smb_xstrdup(parameter);
749 } else if (strequal(request, "Request-User-Session-Key")) {
750 ntlm_server_1_user_session_key = strequal(parameter, "Yes");
751 } else if (strequal(request, "Request-LanMan-Session-Key")) {
752 ntlm_server_1_lm_session_key = strequal(parameter, "Yes");
754 mux_printf(mux_id, "Error: Unknown request %s\n.\n", request);
758 static void manage_squid_request(enum stdio_helper_mode helper_mode,
759 stdio_helper_function fn, void **private2)
761 char buf[SQUID_BUFFER_SIZE+1];
767 unsigned int max_mux;
768 void **private_pointers;
771 static struct mux_private *mux_private;
772 static void *normal_private;
775 /* this is not a typo - x_fgets doesn't work too well under squid */
776 if (fgets(buf, sizeof(buf)-1, stdin) == NULL) {
778 DEBUG(1, ("fgets() failed! dying..... errno=%d (%s)\n", ferror(stdin),
779 strerror(ferror(stdin))));
781 exit(1); /* BIIG buffer */
786 c=memchr(buf,'\n',sizeof(buf)-1);
795 DEBUG(0, ("Oversized message\n"));
796 x_fprintf(x_stdout, "ERR\n");
801 DEBUG(10, ("Got '%s' from squid (length: %d).\n",buf,length));
803 if (buf[0] == '\0') {
804 DEBUG(0, ("Invalid Request (empty)\n"));
805 x_fprintf(x_stdout, "ERR\n");
810 if (sscanf(buf, "%u ", &mux_id) != 1) {
811 DEBUG(0, ("Invalid Request - no multiplex id\n"));
812 x_fprintf(x_stdout, "ERR\n");
816 mux_private = talloc(NULL, struct mux_private);
817 mux_private->max_mux = 0;
818 mux_private->private_pointers = NULL;
823 DEBUG(0, ("Invalid Request - no data after multiplex id\n"));
824 x_fprintf(x_stdout, "ERR\n");
828 if (mux_id >= mux_private->max_mux) {
829 unsigned int prev_max = mux_private->max_mux;
830 mux_private->max_mux = mux_id + 1;
831 mux_private->private_pointers
832 = talloc_realloc(mux_private,
833 mux_private->private_pointers,
834 void *, mux_private->max_mux);
835 memset(&mux_private->private_pointers[prev_max], '\0',
836 (sizeof(*mux_private->private_pointers) * (mux_private->max_mux - prev_max)));
839 private = &mux_private->private_pointers[mux_id];
842 private = &normal_private;
845 fn(helper_mode, c, length, private, mux_id, private2);
848 static void squid_stream(enum stdio_helper_mode stdio_mode,
849 stdio_helper_function fn) {
850 /* initialize FDescs */
851 x_setbuf(x_stdout, NULL);
852 x_setbuf(x_stderr, NULL);
854 manage_squid_request(stdio_mode, fn, NULL);
871 OPT_USER_SESSION_KEY,
873 OPT_REQUIRE_MEMBERSHIP,
877 int main(int argc, const char **argv)
879 static const char *helper_protocol;
884 /* NOTE: DO NOT change this interface without considering the implications!
885 This is an external interface, which other programs will use to interact
889 /* We do not use single-letter command abbreviations, because they harm future
890 interface stability. */
892 struct poptOption long_options[] = {
894 { "helper-protocol", 0, POPT_ARG_STRING, &helper_protocol, OPT_DOMAIN, "operate as a stdio-based helper", "helper protocol to use"},
895 { "domain", 0, POPT_ARG_STRING, &opt_domain, OPT_DOMAIN, "domain name"},
896 { "workstation", 0, POPT_ARG_STRING, &opt_workstation, OPT_WORKSTATION, "workstation"},
897 { "username", 0, POPT_ARG_STRING, &opt_username, OPT_PASSWORD, "Username"},
898 { "password", 0, POPT_ARG_STRING, &opt_password, OPT_PASSWORD, "User's plaintext password"},
899 { "multiplex", 0, POPT_ARG_NONE, &opt_multiplex, OPT_MULTIPLEX, "Multiplex Mode"},
905 /* Samba client initialisation */
907 setup_logging(NULL, DEBUG_STDERR);
911 pc = poptGetContext("ntlm_auth", argc, argv, long_options, 0);
913 /* Parse command line options */
916 poptPrintHelp(pc, stderr, 0);
920 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
921 POPT_CONTEXT_KEEP_FIRST);
923 while((opt = poptGetNextOpt(pc)) != -1) {
929 fprintf(stderr, "%s: %s\n",
930 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
937 if (opt_domain == NULL) {
938 opt_domain = lp_workgroup();
941 if (helper_protocol) {
943 for (i=0; i<NUM_HELPER_MODES; i++) {
944 if (strcmp(helper_protocol, stdio_helper_protocols[i].name) == 0) {
945 squid_stream(stdio_helper_protocols[i].mode, stdio_helper_protocols[i].fn);
949 x_fprintf(x_stderr, "unknown helper protocol [%s]\n\nValid helper protools:\n\n", helper_protocol);
951 for (i=0; i<NUM_HELPER_MODES; i++) {
952 x_fprintf(x_stderr, "%s\n", stdio_helper_protocols[i].name);
959 x_fprintf(x_stderr, "username must be specified!\n\n");
960 poptPrintHelp(pc, stderr, 0);
964 if (opt_workstation == NULL) {
965 opt_workstation = lp_netbios_name();
969 opt_password = getpass("password: ");
975 asprintf(&user, "%s%c%s", opt_domain, *lp_winbind_separator(), opt_username);
976 if (!check_plaintext_auth(user, opt_password, True)) {