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 "smb_build.h"
32 #define SQUID_BUFFER_SIZE 2010
34 enum stdio_helper_mode {
45 #define NTLM_AUTH_FLAG_USER_SESSION_KEY 0x0004
46 #define NTLM_AUTH_FLAG_LMKEY 0x0008
49 typedef void (*stdio_helper_function)(enum stdio_helper_mode stdio_helper_mode,
50 char *buf, int length, void **private,
51 unsigned int mux_id, void **private2);
53 static void manage_squid_basic_request (enum stdio_helper_mode stdio_helper_mode,
54 char *buf, int length, void **private,
55 unsigned int mux_id, void **private2);
57 static void manage_gensec_request (enum stdio_helper_mode stdio_helper_mode,
58 char *buf, int length, void **private,
59 unsigned int mux_id, void **private2);
61 static void manage_ntlm_server_1_request (enum stdio_helper_mode stdio_helper_mode,
62 char *buf, int length, void **private,
63 unsigned int mux_id, void **private2);
65 static void manage_squid_request(enum stdio_helper_mode helper_mode,
66 stdio_helper_function fn, void **private2);
69 enum stdio_helper_mode mode;
71 stdio_helper_function fn;
72 } stdio_helper_protocols[] = {
73 { SQUID_2_4_BASIC, "squid-2.4-basic", manage_squid_basic_request},
74 { SQUID_2_5_BASIC, "squid-2.5-basic", manage_squid_basic_request},
75 { SQUID_2_5_NTLMSSP, "squid-2.5-ntlmssp", manage_gensec_request},
76 { GSS_SPNEGO_CLIENT, "gss-spnego-client", manage_gensec_request},
77 { GSS_SPNEGO_SERVER, "gss-spnego", manage_gensec_request},
78 { NTLMSSP_CLIENT_1, "ntlmssp-client-1", manage_gensec_request},
79 { NTLM_SERVER_1, "ntlm-server-1", manage_ntlm_server_1_request},
80 { NUM_HELPER_MODES, NULL, NULL}
83 extern int winbindd_fd;
85 static const char *opt_username;
86 static const char *opt_domain;
87 static const char *opt_workstation;
88 static const char *opt_password;
89 static int opt_multiplex;
92 static void mux_printf(unsigned int mux_id, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
94 static void mux_printf(unsigned int mux_id, const char *format, ...)
99 x_fprintf(x_stdout, "%d ", mux_id);
102 va_start(ap, format);
103 x_vfprintf(x_stdout, format, ap);
109 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
110 form DOMAIN/user into a domain and a user */
112 static BOOL parse_ntlm_auth_domain_user(const char *domuser, fstring domain,
116 char *p = strchr(domuser,*lp_winbind_separator());
123 fstrcpy(domain, domuser);
124 domain[PTR_DIFF(p, domuser)] = 0;
129 /* Authenticate a user with a plaintext password */
131 static BOOL check_plaintext_auth(const char *user, const char *pass,
132 BOOL stdout_diagnostics)
134 return (strcmp(pass, opt_password) == 0);
137 /* authenticate a user with an encrypted username/password */
139 static NTSTATUS local_pw_check_specified(const char *username,
141 const char *workstation,
142 const DATA_BLOB *challenge,
143 const DATA_BLOB *lm_response,
144 const DATA_BLOB *nt_response,
146 DATA_BLOB *lm_session_key,
147 DATA_BLOB *user_session_key,
152 struct samr_Password lm_pw, nt_pw;
153 struct samr_Password *lm_pwd, *nt_pwd;
154 TALLOC_CTX *mem_ctx = talloc_init("local_pw_check_specified");
156 nt_status = NT_STATUS_NO_MEMORY;
159 E_md4hash(opt_password, nt_pw.hash);
160 if (E_deshash(opt_password, lm_pw.hash)) {
168 nt_status = ntlm_password_check(mem_ctx,
169 MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT |
170 MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT,
177 lm_pwd, nt_pwd, user_session_key, lm_session_key);
179 if (NT_STATUS_IS_OK(nt_status)) {
183 *lp_winbind_separator(),
187 DEBUG(3, ("Login for user [%s]\\[%s]@[%s] failed due to [%s]\n",
188 domain, username, workstation,
189 nt_errstr(nt_status)));
191 talloc_free(mem_ctx);
194 *error_string = strdup(nt_errstr(nt_status));
201 static void manage_squid_basic_request(enum stdio_helper_mode stdio_helper_mode,
202 char *buf, int length, void **private,
203 unsigned int mux_id, void **private2)
208 pass=memchr(buf,' ',length);
210 DEBUG(2, ("Password not found. Denying access\n"));
211 mux_printf(mux_id, "ERR\n");
217 if (stdio_helper_mode == SQUID_2_5_BASIC) {
218 rfc1738_unescape(user);
219 rfc1738_unescape(pass);
222 if (check_plaintext_auth(user, pass, False)) {
223 mux_printf(mux_id, "OK\n");
225 mux_printf(mux_id, "ERR\n");
229 /* This is a bit hairy, but the basic idea is to do a password callback
230 to the calling application. The callback comes from within gensec */
232 static void manage_gensec_get_pw_request(enum stdio_helper_mode stdio_helper_mode,
233 char *buf, int length, void **private,
234 unsigned int mux_id, void **password)
237 if (strlen(buf) < 2) {
238 DEBUG(1, ("query [%s] invalid", buf));
239 mux_printf(mux_id, "BH\n");
243 if (strlen(buf) > 3) {
244 in = base64_decode_data_blob(NULL, buf + 3);
246 in = data_blob(NULL, 0);
249 if (strncmp(buf, "PW ", 3) == 0) {
251 *password = talloc_strndup(*private /* hopefully the right gensec context, useful to use for talloc */,
252 (const char *)in.data, in.length);
254 if (*password == NULL) {
255 DEBUG(1, ("Out of memory\n"));
256 mux_printf(mux_id, "BH\n");
261 mux_printf(mux_id, "OK\n");
265 DEBUG(1, ("Asked for (and expected) a password\n"));
266 mux_printf(mux_id, "BH\n");
271 * Callback for password credentails. This is not async, and when
272 * GENSEC and the credentails code is made async, it will look rather
276 static const char *get_password(struct cli_credentials *credentials)
278 char *password = NULL;
280 /* Ask for a password */
281 mux_printf((unsigned int)credentials->priv_data, "PW\n");
282 credentials->priv_data = NULL;
284 manage_squid_request(NUM_HELPER_MODES /* bogus */, manage_gensec_get_pw_request, (void **)&password);
288 static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
289 char *buf, int length, void **private,
290 unsigned int mux_id, void **private2)
293 DATA_BLOB out = data_blob(NULL, 0);
294 char *out_base64 = NULL;
295 const char *reply_arg = NULL;
296 struct gensec_ntlm_state {
297 struct gensec_security *gensec_state;
298 const char *set_password;
300 struct gensec_ntlm_state *state;
304 const char *reply_code;
305 struct cli_credentials *creds;
312 state = talloc_zero(NULL, struct gensec_ntlm_state);
314 mux_printf(mux_id, "BH No Memory\n");
319 state->set_password = opt_password;
323 if (strlen(buf) < 2) {
324 DEBUG(1, ("query [%s] invalid", buf));
325 mux_printf(mux_id, "BH\n");
329 if (strlen(buf) > 3) {
330 in = base64_decode_data_blob(NULL, buf + 3);
332 in = data_blob(NULL, 0);
335 if (strncmp(buf, "YR", 2) == 0) {
336 if (state->gensec_state) {
337 talloc_free(state->gensec_state);
338 state->gensec_state = NULL;
340 } else if ( (strncmp(buf, "OK", 2) == 0)) {
344 } else if ( (strncmp(buf, "TT ", 3) != 0) &&
345 (strncmp(buf, "KK ", 3) != 0) &&
346 (strncmp(buf, "AF ", 3) != 0) &&
347 (strncmp(buf, "NA ", 3) != 0) &&
348 (strncmp(buf, "UG", 2) != 0) &&
349 (strncmp(buf, "PW ", 3) != 0)) {
350 DEBUG(1, ("SPNEGO request [%s] invalid\n", buf));
351 mux_printf(mux_id, "BH\n");
357 if (!(state->gensec_state)) {
358 switch (stdio_helper_mode) {
359 case GSS_SPNEGO_CLIENT:
360 case NTLMSSP_CLIENT_1:
361 /* setup the client side */
363 nt_status = gensec_client_start(NULL, &state->gensec_state, NULL);
364 if (!NT_STATUS_IS_OK(nt_status)) {
369 case GSS_SPNEGO_SERVER:
370 case SQUID_2_5_NTLMSSP:
371 if (!NT_STATUS_IS_OK(gensec_server_start(NULL, &state->gensec_state, NULL))) {
379 creds = cli_credentials_init(state->gensec_state);
380 cli_credentials_set_conf(creds);
382 cli_credentials_set_username(creds, opt_username, CRED_SPECIFIED);
385 cli_credentials_set_domain(creds, opt_domain, CRED_SPECIFIED);
387 if (state->set_password) {
388 cli_credentials_set_password(creds, state->set_password, CRED_SPECIFIED);
390 cli_credentials_set_password_callback(creds, get_password);
391 creds->priv_data = (void*)mux_id;
393 if (opt_workstation) {
394 cli_credentials_set_workstation(creds, opt_workstation, CRED_SPECIFIED);
397 switch (stdio_helper_mode) {
398 case GSS_SPNEGO_SERVER:
399 case SQUID_2_5_NTLMSSP:
400 cli_credentials_set_machine_account(creds);
406 gensec_set_credentials(state->gensec_state, creds);
408 switch (stdio_helper_mode) {
409 case GSS_SPNEGO_CLIENT:
410 case GSS_SPNEGO_SERVER:
411 nt_status = gensec_start_mech_by_oid(state->gensec_state, GENSEC_OID_SPNEGO);
416 case NTLMSSP_CLIENT_1:
420 case SQUID_2_5_NTLMSSP:
421 nt_status = gensec_start_mech_by_oid(state->gensec_state, GENSEC_OID_NTLMSSP);
427 if (!NT_STATUS_IS_OK(nt_status)) {
428 DEBUG(1, ("GENSEC mech failed to start: %s\n", nt_errstr(nt_status)));
429 mux_printf(mux_id, "BH\n");
436 mem_ctx = talloc_named(NULL, 0, "manage_gensec_request internal mem_ctx");
438 if (strncmp(buf, "PW ", 3) == 0) {
439 state->set_password = talloc_strndup(state,
440 (const char *)in.data,
443 cli_credentials_set_password(gensec_get_credentials(state->gensec_state),
446 mux_printf(mux_id, "OK\n");
448 talloc_free(mem_ctx);
452 if (strncmp(buf, "UG", 2) == 0) {
454 char *grouplist = NULL;
455 struct auth_session_info *session_info;
457 if (!NT_STATUS_IS_OK(gensec_session_info(state->gensec_state, &session_info))) {
458 DEBUG(1, ("gensec_session_info failed: %s\n", nt_errstr(nt_status)));
459 mux_printf(mux_id, "BH %s\n", nt_errstr(nt_status));
461 talloc_free(mem_ctx);
465 /* get the string onto the context */
466 grouplist = talloc_strdup(mem_ctx, "");
468 for (i=0; i<session_info->security_token->num_sids; i++) {
469 struct security_token *token = session_info->security_token;
470 const char *sidstr = dom_sid_string(session_info,
472 grouplist = talloc_asprintf_append(grouplist, "%s,", sidstr);
475 mux_printf(mux_id, "GL %s\n", grouplist);
476 talloc_free(session_info);
478 talloc_free(mem_ctx);
482 nt_status = gensec_update(state->gensec_state, mem_ctx, in, &out);
484 /* don't leak 'bad password'/'no such user' info to the network client */
485 nt_status = auth_nt_status_squash(nt_status);
488 out_base64 = base64_encode_data_blob(mem_ctx, out);
493 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
497 } else if (state->gensec_state->gensec_role == GENSEC_CLIENT) {
499 } else if (state->gensec_state->gensec_role == GENSEC_SERVER) {
506 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCESS_DENIED)) {
508 reply_arg = nt_errstr(nt_status);
509 DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
510 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_UNSUCCESSFUL)) {
512 reply_arg = nt_errstr(nt_status);
513 DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
514 } else if (!NT_STATUS_IS_OK(nt_status)) {
516 reply_arg = nt_errstr(nt_status);
517 DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
518 } else if /* OK */ (state->gensec_state->gensec_role == GENSEC_SERVER) {
519 struct auth_session_info *session_info;
521 nt_status = gensec_session_info(state->gensec_state, &session_info);
522 if (!NT_STATUS_IS_OK(nt_status)) {
524 reply_arg = nt_errstr(nt_status);
525 DEBUG(1, ("GENSEC failed to retreive the session info: %s\n", nt_errstr(nt_status)));
529 reply_arg = talloc_asprintf(state->gensec_state,
530 "%s%s%s", session_info->server_info->domain_name,
531 lp_winbind_separator(), session_info->server_info->account_name);
532 talloc_free(session_info);
534 } else if (state->gensec_state->gensec_role == GENSEC_CLIENT) {
536 reply_arg = out_base64;
541 switch (stdio_helper_mode) {
542 case GSS_SPNEGO_SERVER:
543 mux_printf(mux_id, "%s %s %s\n", reply_code,
544 out_base64 ? out_base64 : "*",
545 reply_arg ? reply_arg : "*");
549 mux_printf(mux_id, "%s %s\n", reply_code, out_base64);
550 } else if (reply_arg) {
551 mux_printf(mux_id, "%s %s\n", reply_code, reply_arg);
553 mux_printf(mux_id, "%s\n", reply_code);
557 talloc_free(mem_ctx);
561 static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mode,
562 char *buf, int length, void **private,
563 unsigned int mux_id, void **private2)
565 char *request, *parameter;
566 static DATA_BLOB challenge;
567 static DATA_BLOB lm_response;
568 static DATA_BLOB nt_response;
569 static char *full_username;
570 static char *username;
572 static char *plaintext_password;
573 static BOOL ntlm_server_1_user_session_key;
574 static BOOL ntlm_server_1_lm_session_key;
576 if (strequal(buf, ".")) {
577 if (!full_username && !username) {
578 mux_printf(mux_id, "Error: No username supplied!\n");
579 } else if (plaintext_password) {
580 /* handle this request as plaintext */
581 if (!full_username) {
582 if (asprintf(&full_username, "%s%c%s", domain, *lp_winbind_separator(), username) == -1) {
583 mux_printf(mux_id, "Error: Out of memory in asprintf!\n.\n");
587 if (check_plaintext_auth(full_username, plaintext_password, False)) {
588 mux_printf(mux_id, "Authenticated: Yes\n");
590 mux_printf(mux_id, "Authenticated: No\n");
592 } else if (!lm_response.data && !nt_response.data) {
593 mux_printf(mux_id, "Error: No password supplied!\n");
594 } else if (!challenge.data) {
595 mux_printf(mux_id, "Error: No lanman-challenge supplied!\n");
597 char *error_string = NULL;
599 DATA_BLOB user_session_key;
602 if (full_username && !username) {
606 if (!parse_ntlm_auth_domain_user(full_username, fstr_user, fstr_domain)) {
607 /* username might be 'tainted', don't print into our new-line deleimianted stream */
608 mux_printf(mux_id, "Error: Could not parse into domain and username\n");
612 username = smb_xstrdup(fstr_user);
613 domain = smb_xstrdup(fstr_domain);
617 domain = smb_xstrdup(lp_workgroup());
620 if (ntlm_server_1_lm_session_key)
621 flags |= NTLM_AUTH_FLAG_LMKEY;
623 if (ntlm_server_1_user_session_key)
624 flags |= NTLM_AUTH_FLAG_USER_SESSION_KEY;
626 if (!NT_STATUS_IS_OK(
627 local_pw_check_specified(username,
639 mux_printf(mux_id, "Authenticated: No\n");
640 mux_printf(mux_id, "Authentication-Error: %s\n.\n", error_string);
641 SAFE_FREE(error_string);
643 static char zeros[16];
645 char *hex_user_session_key;
647 mux_printf(mux_id, "Authenticated: Yes\n");
649 if (ntlm_server_1_lm_session_key
651 && (memcmp(zeros, lm_key.data,
652 lm_key.length) != 0)) {
653 hex_encode(lm_key.data,
656 mux_printf(mux_id, "LANMAN-Session-Key: %s\n", hex_lm_key);
657 SAFE_FREE(hex_lm_key);
660 if (ntlm_server_1_user_session_key
661 && user_session_key.length
662 && (memcmp(zeros, user_session_key.data,
663 user_session_key.length) != 0)) {
664 hex_encode(user_session_key.data,
665 user_session_key.length,
666 &hex_user_session_key);
667 mux_printf(mux_id, "User-Session-Key: %s\n", hex_user_session_key);
668 SAFE_FREE(hex_user_session_key);
672 /* clear out the state */
673 challenge = data_blob(NULL, 0);
674 nt_response = data_blob(NULL, 0);
675 lm_response = data_blob(NULL, 0);
676 SAFE_FREE(full_username);
679 SAFE_FREE(plaintext_password);
680 ntlm_server_1_user_session_key = False;
681 ntlm_server_1_lm_session_key = False;
682 mux_printf(mux_id, ".\n");
689 /* Indicates a base64 encoded structure */
690 parameter = strstr(request, ":: ");
692 parameter = strstr(request, ": ");
695 DEBUG(0, ("Parameter not found!\n"));
696 mux_printf(mux_id, "Error: Parameter not found!\n.\n");
713 base64_decode_inplace(parameter);
716 if (strequal(request, "LANMAN-Challenge")) {
717 challenge = strhex_to_data_blob(parameter);
718 if (challenge.length != 8) {
719 mux_printf(mux_id, "Error: hex decode of %s failed! (got %d bytes, expected 8)\n.\n",
721 (int)challenge.length);
722 challenge = data_blob(NULL, 0);
724 } else if (strequal(request, "NT-Response")) {
725 nt_response = strhex_to_data_blob(parameter);
726 if (nt_response.length < 24) {
727 mux_printf(mux_id, "Error: hex decode of %s failed! (only got %d bytes, needed at least 24)\n.\n",
729 (int)nt_response.length);
730 nt_response = data_blob(NULL, 0);
732 } else if (strequal(request, "LANMAN-Response")) {
733 lm_response = strhex_to_data_blob(parameter);
734 if (lm_response.length != 24) {
735 mux_printf(mux_id, "Error: hex decode of %s failed! (got %d bytes, expected 24)\n.\n",
737 (int)lm_response.length);
738 lm_response = data_blob(NULL, 0);
740 } else if (strequal(request, "Password")) {
741 plaintext_password = smb_xstrdup(parameter);
742 } else if (strequal(request, "NT-Domain")) {
743 domain = smb_xstrdup(parameter);
744 } else if (strequal(request, "Username")) {
745 username = smb_xstrdup(parameter);
746 } else if (strequal(request, "Full-Username")) {
747 full_username = smb_xstrdup(parameter);
748 } else if (strequal(request, "Request-User-Session-Key")) {
749 ntlm_server_1_user_session_key = strequal(parameter, "Yes");
750 } else if (strequal(request, "Request-LanMan-Session-Key")) {
751 ntlm_server_1_lm_session_key = strequal(parameter, "Yes");
753 mux_printf(mux_id, "Error: Unknown request %s\n.\n", request);
757 static void manage_squid_request(enum stdio_helper_mode helper_mode,
758 stdio_helper_function fn, void **private2)
760 char buf[SQUID_BUFFER_SIZE+1];
766 unsigned int max_mux;
767 void **private_pointers;
770 static struct mux_private *mux_private;
771 static void *normal_private;
774 /* this is not a typo - x_fgets doesn't work too well under squid */
775 if (fgets(buf, sizeof(buf)-1, stdin) == NULL) {
777 DEBUG(1, ("fgets() failed! dying..... errno=%d (%s)\n", ferror(stdin),
778 strerror(ferror(stdin))));
780 exit(1); /* BIIG buffer */
785 c=memchr(buf,'\n',sizeof(buf)-1);
794 DEBUG(0, ("Oversized message\n"));
795 x_fprintf(x_stdout, "ERR\n");
800 DEBUG(10, ("Got '%s' from squid (length: %d).\n",buf,length));
802 if (buf[0] == '\0') {
803 DEBUG(0, ("Invalid Request (empty)\n"));
804 x_fprintf(x_stdout, "ERR\n");
809 if (sscanf(buf, "%u ", &mux_id) != 1) {
810 DEBUG(0, ("Invalid Request - no multiplex id\n"));
811 x_fprintf(x_stdout, "ERR\n");
815 mux_private = talloc(NULL, struct mux_private);
816 mux_private->max_mux = 0;
817 mux_private->private_pointers = NULL;
822 DEBUG(0, ("Invalid Request - no data after multiplex id\n"));
823 x_fprintf(x_stdout, "ERR\n");
827 if (mux_id >= mux_private->max_mux) {
828 unsigned int prev_max = mux_private->max_mux;
829 mux_private->max_mux = mux_id + 1;
830 mux_private->private_pointers
831 = talloc_realloc(mux_private,
832 mux_private->private_pointers,
833 void *, mux_private->max_mux);
834 memset(&mux_private->private_pointers[prev_max], '\0',
835 (sizeof(*mux_private->private_pointers) * (mux_private->max_mux - prev_max)));
838 private = &mux_private->private_pointers[mux_id];
841 private = &normal_private;
844 fn(helper_mode, c, length, private, mux_id, private2);
847 static void squid_stream(enum stdio_helper_mode stdio_mode,
848 stdio_helper_function fn) {
849 /* initialize FDescs */
850 x_setbuf(x_stdout, NULL);
851 x_setbuf(x_stderr, NULL);
853 manage_squid_request(stdio_mode, fn, NULL);
870 OPT_USER_SESSION_KEY,
872 OPT_REQUIRE_MEMBERSHIP,
876 int main(int argc, const char **argv)
878 static const char *helper_protocol;
883 /* NOTE: DO NOT change this interface without considering the implications!
884 This is an external interface, which other programs will use to interact
888 /* We do not use single-letter command abbreviations, because they harm future
889 interface stability. */
891 struct poptOption long_options[] = {
893 { "helper-protocol", 0, POPT_ARG_STRING, &helper_protocol, OPT_DOMAIN, "operate as a stdio-based helper", "helper protocol to use"},
894 { "domain", 0, POPT_ARG_STRING, &opt_domain, OPT_DOMAIN, "domain name"},
895 { "workstation", 0, POPT_ARG_STRING, &opt_workstation, OPT_WORKSTATION, "workstation"},
896 { "username", 0, POPT_ARG_STRING, &opt_username, OPT_PASSWORD, "Username"},
897 { "password", 0, POPT_ARG_STRING, &opt_password, OPT_PASSWORD, "User's plaintext password"},
898 { "multiplex", 0, POPT_ARG_NONE, &opt_multiplex, OPT_MULTIPLEX, "Multiplex Mode"},
904 /* Samba client initialisation */
906 setup_logging(NULL, DEBUG_STDERR);
910 pc = poptGetContext("ntlm_auth", argc, argv, long_options, 0);
912 /* Parse command line options */
915 poptPrintHelp(pc, stderr, 0);
919 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
920 POPT_CONTEXT_KEEP_FIRST);
922 while((opt = poptGetNextOpt(pc)) != -1) {
928 fprintf(stderr, "%s: %s\n",
929 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
934 ntlm_auth_init_subsystems;
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)) {