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"
32 #include "lib/ldb/include/ldb.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;
132 * Decode a base64 string into a DATA_BLOB - simple and slow algorithm
134 static DATA_BLOB base64_decode_data_blob(TALLOC_CTX *mem_ctx, const char *s)
136 DATA_BLOB ret = data_blob_talloc(mem_ctx, s, strlen(s)+1);
137 ret.length = ldb_base64_decode((char *)ret.data);
142 * Encode a base64 string into a talloc()ed string caller to free.
144 static char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data)
146 return ldb_base64_encode(mem_ctx, (const char *)data.data, data.length);
150 * Decode a base64 string in-place - wrapper for the above
152 static void base64_decode_inplace(char *s)
154 ldb_base64_decode(s);
159 /* Authenticate a user with a plaintext password */
161 static BOOL check_plaintext_auth(const char *user, const char *pass,
162 BOOL stdout_diagnostics)
164 return (strcmp(pass, opt_password) == 0);
167 /* authenticate a user with an encrypted username/password */
169 static NTSTATUS local_pw_check_specified(const char *username,
171 const char *workstation,
172 const DATA_BLOB *challenge,
173 const DATA_BLOB *lm_response,
174 const DATA_BLOB *nt_response,
176 DATA_BLOB *lm_session_key,
177 DATA_BLOB *user_session_key,
182 struct samr_Password lm_pw, nt_pw;
183 struct samr_Password *lm_pwd, *nt_pwd;
184 TALLOC_CTX *mem_ctx = talloc_init("local_pw_check_specified");
186 nt_status = NT_STATUS_NO_MEMORY;
189 E_md4hash(opt_password, nt_pw.hash);
190 if (E_deshash(opt_password, lm_pw.hash)) {
198 nt_status = ntlm_password_check(mem_ctx,
199 MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT |
200 MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT,
207 lm_pwd, nt_pwd, user_session_key, lm_session_key);
209 if (NT_STATUS_IS_OK(nt_status)) {
213 *lp_winbind_separator(),
217 DEBUG(3, ("Login for user [%s]\\[%s]@[%s] failed due to [%s]\n",
218 domain, username, workstation,
219 nt_errstr(nt_status)));
221 talloc_free(mem_ctx);
224 *error_string = strdup(nt_errstr(nt_status));
231 static void manage_squid_basic_request(enum stdio_helper_mode stdio_helper_mode,
232 char *buf, int length, void **private,
233 unsigned int mux_id, void **private2)
238 pass=memchr(buf,' ',length);
240 DEBUG(2, ("Password not found. Denying access\n"));
241 mux_printf(mux_id, "ERR\n");
247 if (stdio_helper_mode == SQUID_2_5_BASIC) {
248 rfc1738_unescape(user);
249 rfc1738_unescape(pass);
252 if (check_plaintext_auth(user, pass, False)) {
253 mux_printf(mux_id, "OK\n");
255 mux_printf(mux_id, "ERR\n");
259 /* This is a bit hairy, but the basic idea is to do a password callback
260 to the calling application. The callback comes from within gensec */
262 static void manage_gensec_get_pw_request(enum stdio_helper_mode stdio_helper_mode,
263 char *buf, int length, void **private,
264 unsigned int mux_id, void **password)
267 if (strlen(buf) < 2) {
268 DEBUG(1, ("query [%s] invalid", buf));
269 mux_printf(mux_id, "BH\n");
273 if (strlen(buf) > 3) {
274 in = base64_decode_data_blob(NULL, buf + 3);
276 in = data_blob(NULL, 0);
279 if (strncmp(buf, "PW ", 3) == 0) {
281 *password = talloc_strndup(*private /* hopefully the right gensec context, useful to use for talloc */,
282 (const char *)in.data, in.length);
284 if (*password == NULL) {
285 DEBUG(1, ("Out of memory\n"));
286 mux_printf(mux_id, "BH\n");
291 mux_printf(mux_id, "OK\n");
295 DEBUG(1, ("Asked for (and expected) a password\n"));
296 mux_printf(mux_id, "BH\n");
301 * Callback for password credentails. This is not async, and when
302 * GENSEC and the credentails code is made async, it will look rather
306 static const char *get_password(struct cli_credentials *credentials)
308 char *password = NULL;
310 /* Ask for a password */
311 mux_printf((unsigned int)credentials->priv_data, "PW\n");
312 credentials->priv_data = NULL;
314 manage_squid_request(NUM_HELPER_MODES /* bogus */, manage_gensec_get_pw_request, (void **)&password);
318 static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
319 char *buf, int length, void **private,
320 unsigned int mux_id, void **private2)
323 DATA_BLOB out = data_blob(NULL, 0);
324 char *out_base64 = NULL;
325 const char *reply_arg = NULL;
326 struct gensec_ntlm_state {
327 struct gensec_security *gensec_state;
328 const char *set_password;
330 struct gensec_ntlm_state *state;
334 const char *reply_code;
335 struct cli_credentials *creds;
342 state = talloc_zero(NULL, struct gensec_ntlm_state);
344 mux_printf(mux_id, "BH No Memory\n");
349 state->set_password = opt_password;
353 if (strlen(buf) < 2) {
354 DEBUG(1, ("query [%s] invalid", buf));
355 mux_printf(mux_id, "BH\n");
359 if (strlen(buf) > 3) {
360 in = base64_decode_data_blob(NULL, buf + 3);
362 in = data_blob(NULL, 0);
365 if (strncmp(buf, "YR", 2) == 0) {
366 if (state->gensec_state) {
367 talloc_free(state->gensec_state);
368 state->gensec_state = NULL;
370 } else if ( (strncmp(buf, "OK", 2) == 0)) {
374 } else if ( (strncmp(buf, "TT ", 3) != 0) &&
375 (strncmp(buf, "KK ", 3) != 0) &&
376 (strncmp(buf, "AF ", 3) != 0) &&
377 (strncmp(buf, "NA ", 3) != 0) &&
378 (strncmp(buf, "UG", 2) != 0) &&
379 (strncmp(buf, "PW ", 3) != 0)) {
380 DEBUG(1, ("SPNEGO request [%s] invalid\n", buf));
381 mux_printf(mux_id, "BH\n");
387 if (!(state->gensec_state)) {
388 switch (stdio_helper_mode) {
389 case GSS_SPNEGO_CLIENT:
390 case NTLMSSP_CLIENT_1:
391 /* setup the client side */
393 nt_status = gensec_client_start(NULL, &state->gensec_state, NULL);
394 if (!NT_STATUS_IS_OK(nt_status)) {
399 case GSS_SPNEGO_SERVER:
400 case SQUID_2_5_NTLMSSP:
401 if (!NT_STATUS_IS_OK(gensec_server_start(NULL, &state->gensec_state, NULL))) {
409 creds = cli_credentials_init(state->gensec_state);
410 cli_credentials_set_conf(creds);
412 cli_credentials_set_username(creds, opt_username, CRED_SPECIFIED);
415 cli_credentials_set_domain(creds, opt_domain, CRED_SPECIFIED);
417 if (state->set_password) {
418 cli_credentials_set_password(creds, state->set_password, CRED_SPECIFIED);
420 cli_credentials_set_password_callback(creds, get_password);
421 creds->priv_data = (void*)mux_id;
423 if (opt_workstation) {
424 cli_credentials_set_workstation(creds, opt_workstation, CRED_SPECIFIED);
427 switch (stdio_helper_mode) {
428 case GSS_SPNEGO_SERVER:
429 case SQUID_2_5_NTLMSSP:
430 cli_credentials_set_machine_account(creds);
436 gensec_set_credentials(state->gensec_state, creds);
438 switch (stdio_helper_mode) {
439 case GSS_SPNEGO_CLIENT:
440 case GSS_SPNEGO_SERVER:
441 nt_status = gensec_start_mech_by_oid(state->gensec_state, GENSEC_OID_SPNEGO);
446 case NTLMSSP_CLIENT_1:
451 case SQUID_2_5_NTLMSSP:
452 nt_status = gensec_start_mech_by_oid(state->gensec_state, GENSEC_OID_NTLMSSP);
458 if (!NT_STATUS_IS_OK(nt_status)) {
459 DEBUG(1, ("GENSEC mech failed to start: %s\n", nt_errstr(nt_status)));
460 mux_printf(mux_id, "BH\n");
467 mem_ctx = talloc_named(NULL, 0, "manage_gensec_request internal mem_ctx");
469 if (strncmp(buf, "PW ", 3) == 0) {
470 state->set_password = talloc_strndup(state,
471 (const char *)in.data,
474 cli_credentials_set_password(gensec_get_credentials(state->gensec_state),
477 mux_printf(mux_id, "OK\n");
479 talloc_free(mem_ctx);
483 if (strncmp(buf, "UG", 2) == 0) {
485 char *grouplist = NULL;
486 struct auth_session_info *session_info;
488 nt_status = gensec_session_info(state->gensec_state, &session_info);
489 if (!NT_STATUS_IS_OK(nt_status)) {
490 DEBUG(1, ("gensec_session_info failed: %s\n", nt_errstr(nt_status)));
491 mux_printf(mux_id, "BH %s\n", nt_errstr(nt_status));
493 talloc_free(mem_ctx);
497 /* get the string onto the context */
498 grouplist = talloc_strdup(mem_ctx, "");
500 for (i=0; i<session_info->security_token->num_sids; i++) {
501 struct security_token *token = session_info->security_token;
502 const char *sidstr = dom_sid_string(session_info,
504 grouplist = talloc_asprintf_append(grouplist, "%s,", sidstr);
507 mux_printf(mux_id, "GL %s\n", grouplist);
508 talloc_free(session_info);
510 talloc_free(mem_ctx);
514 nt_status = gensec_update(state->gensec_state, mem_ctx, in, &out);
516 /* don't leak 'bad password'/'no such user' info to the network client */
517 nt_status = auth_nt_status_squash(nt_status);
520 out_base64 = base64_encode_data_blob(mem_ctx, out);
525 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
529 } else if (state->gensec_state->gensec_role == GENSEC_CLIENT) {
531 } else if (state->gensec_state->gensec_role == GENSEC_SERVER) {
538 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCESS_DENIED)) {
540 reply_arg = nt_errstr(nt_status);
541 DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
542 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_UNSUCCESSFUL)) {
544 reply_arg = nt_errstr(nt_status);
545 DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
546 } else if (!NT_STATUS_IS_OK(nt_status)) {
548 reply_arg = nt_errstr(nt_status);
549 DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
550 } else if /* OK */ (state->gensec_state->gensec_role == GENSEC_SERVER) {
551 struct auth_session_info *session_info;
553 nt_status = gensec_session_info(state->gensec_state, &session_info);
554 if (!NT_STATUS_IS_OK(nt_status)) {
556 reply_arg = nt_errstr(nt_status);
557 DEBUG(1, ("GENSEC failed to retreive the session info: %s\n", nt_errstr(nt_status)));
561 reply_arg = talloc_asprintf(state->gensec_state,
562 "%s%s%s", session_info->server_info->domain_name,
563 lp_winbind_separator(), session_info->server_info->account_name);
564 talloc_free(session_info);
566 } else if (state->gensec_state->gensec_role == GENSEC_CLIENT) {
568 reply_arg = out_base64;
573 switch (stdio_helper_mode) {
574 case GSS_SPNEGO_SERVER:
575 mux_printf(mux_id, "%s %s %s\n", reply_code,
576 out_base64 ? out_base64 : "*",
577 reply_arg ? reply_arg : "*");
581 mux_printf(mux_id, "%s %s\n", reply_code, out_base64);
582 } else if (reply_arg) {
583 mux_printf(mux_id, "%s %s\n", reply_code, reply_arg);
585 mux_printf(mux_id, "%s\n", reply_code);
589 talloc_free(mem_ctx);
593 static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mode,
594 char *buf, int length, void **private,
595 unsigned int mux_id, void **private2)
597 char *request, *parameter;
598 static DATA_BLOB challenge;
599 static DATA_BLOB lm_response;
600 static DATA_BLOB nt_response;
601 static char *full_username;
602 static char *username;
604 static char *plaintext_password;
605 static BOOL ntlm_server_1_user_session_key;
606 static BOOL ntlm_server_1_lm_session_key;
608 if (strequal(buf, ".")) {
609 if (!full_username && !username) {
610 mux_printf(mux_id, "Error: No username supplied!\n");
611 } else if (plaintext_password) {
612 /* handle this request as plaintext */
613 if (!full_username) {
614 if (asprintf(&full_username, "%s%c%s", domain, *lp_winbind_separator(), username) == -1) {
615 mux_printf(mux_id, "Error: Out of memory in asprintf!\n.\n");
619 if (check_plaintext_auth(full_username, plaintext_password, False)) {
620 mux_printf(mux_id, "Authenticated: Yes\n");
622 mux_printf(mux_id, "Authenticated: No\n");
624 } else if (!lm_response.data && !nt_response.data) {
625 mux_printf(mux_id, "Error: No password supplied!\n");
626 } else if (!challenge.data) {
627 mux_printf(mux_id, "Error: No lanman-challenge supplied!\n");
629 char *error_string = NULL;
631 DATA_BLOB user_session_key;
634 if (full_username && !username) {
638 if (!parse_ntlm_auth_domain_user(full_username, fstr_user, fstr_domain)) {
639 /* username might be 'tainted', don't print into our new-line deleimianted stream */
640 mux_printf(mux_id, "Error: Could not parse into domain and username\n");
644 username = smb_xstrdup(fstr_user);
645 domain = smb_xstrdup(fstr_domain);
649 domain = smb_xstrdup(lp_workgroup());
652 if (ntlm_server_1_lm_session_key)
653 flags |= NTLM_AUTH_FLAG_LMKEY;
655 if (ntlm_server_1_user_session_key)
656 flags |= NTLM_AUTH_FLAG_USER_SESSION_KEY;
658 if (!NT_STATUS_IS_OK(
659 local_pw_check_specified(username,
671 mux_printf(mux_id, "Authenticated: No\n");
672 mux_printf(mux_id, "Authentication-Error: %s\n.\n", error_string);
673 SAFE_FREE(error_string);
675 static char zeros[16];
677 char *hex_user_session_key;
679 mux_printf(mux_id, "Authenticated: Yes\n");
681 if (ntlm_server_1_lm_session_key
683 && (memcmp(zeros, lm_key.data,
684 lm_key.length) != 0)) {
685 hex_encode(lm_key.data,
688 mux_printf(mux_id, "LANMAN-Session-Key: %s\n", hex_lm_key);
689 SAFE_FREE(hex_lm_key);
692 if (ntlm_server_1_user_session_key
693 && user_session_key.length
694 && (memcmp(zeros, user_session_key.data,
695 user_session_key.length) != 0)) {
696 hex_encode(user_session_key.data,
697 user_session_key.length,
698 &hex_user_session_key);
699 mux_printf(mux_id, "User-Session-Key: %s\n", hex_user_session_key);
700 SAFE_FREE(hex_user_session_key);
704 /* clear out the state */
705 challenge = data_blob(NULL, 0);
706 nt_response = data_blob(NULL, 0);
707 lm_response = data_blob(NULL, 0);
708 SAFE_FREE(full_username);
711 SAFE_FREE(plaintext_password);
712 ntlm_server_1_user_session_key = False;
713 ntlm_server_1_lm_session_key = False;
714 mux_printf(mux_id, ".\n");
721 /* Indicates a base64 encoded structure */
722 parameter = strstr(request, ":: ");
724 parameter = strstr(request, ": ");
727 DEBUG(0, ("Parameter not found!\n"));
728 mux_printf(mux_id, "Error: Parameter not found!\n.\n");
745 base64_decode_inplace(parameter);
748 if (strequal(request, "LANMAN-Challenge")) {
749 challenge = strhex_to_data_blob(parameter);
750 if (challenge.length != 8) {
751 mux_printf(mux_id, "Error: hex decode of %s failed! (got %d bytes, expected 8)\n.\n",
753 (int)challenge.length);
754 challenge = data_blob(NULL, 0);
756 } else if (strequal(request, "NT-Response")) {
757 nt_response = strhex_to_data_blob(parameter);
758 if (nt_response.length < 24) {
759 mux_printf(mux_id, "Error: hex decode of %s failed! (only got %d bytes, needed at least 24)\n.\n",
761 (int)nt_response.length);
762 nt_response = data_blob(NULL, 0);
764 } else if (strequal(request, "LANMAN-Response")) {
765 lm_response = strhex_to_data_blob(parameter);
766 if (lm_response.length != 24) {
767 mux_printf(mux_id, "Error: hex decode of %s failed! (got %d bytes, expected 24)\n.\n",
769 (int)lm_response.length);
770 lm_response = data_blob(NULL, 0);
772 } else if (strequal(request, "Password")) {
773 plaintext_password = smb_xstrdup(parameter);
774 } else if (strequal(request, "NT-Domain")) {
775 domain = smb_xstrdup(parameter);
776 } else if (strequal(request, "Username")) {
777 username = smb_xstrdup(parameter);
778 } else if (strequal(request, "Full-Username")) {
779 full_username = smb_xstrdup(parameter);
780 } else if (strequal(request, "Request-User-Session-Key")) {
781 ntlm_server_1_user_session_key = strequal(parameter, "Yes");
782 } else if (strequal(request, "Request-LanMan-Session-Key")) {
783 ntlm_server_1_lm_session_key = strequal(parameter, "Yes");
785 mux_printf(mux_id, "Error: Unknown request %s\n.\n", request);
789 static void manage_squid_request(enum stdio_helper_mode helper_mode,
790 stdio_helper_function fn, void **private2)
792 char buf[SQUID_BUFFER_SIZE+1];
793 unsigned int mux_id = 0;
798 unsigned int max_mux;
799 void **private_pointers;
802 static struct mux_private *mux_private;
803 static void *normal_private;
806 /* this is not a typo - x_fgets doesn't work too well under squid */
807 if (fgets(buf, sizeof(buf)-1, stdin) == NULL) {
809 DEBUG(1, ("fgets() failed! dying..... errno=%d (%s)\n", ferror(stdin),
810 strerror(ferror(stdin))));
812 exit(1); /* BIIG buffer */
817 c=memchr(buf,'\n',sizeof(buf)-1);
826 DEBUG(0, ("Oversized message\n"));
827 x_fprintf(x_stdout, "ERR\n");
832 DEBUG(10, ("Got '%s' from squid (length: %d).\n",buf,length));
834 if (buf[0] == '\0') {
835 DEBUG(0, ("Invalid Request (empty)\n"));
836 x_fprintf(x_stdout, "ERR\n");
841 if (sscanf(buf, "%u ", &mux_id) != 1) {
842 DEBUG(0, ("Invalid Request - no multiplex id\n"));
843 x_fprintf(x_stdout, "ERR\n");
847 mux_private = talloc(NULL, struct mux_private);
848 mux_private->max_mux = 0;
849 mux_private->private_pointers = NULL;
854 DEBUG(0, ("Invalid Request - no data after multiplex id\n"));
855 x_fprintf(x_stdout, "ERR\n");
859 if (mux_id >= mux_private->max_mux) {
860 unsigned int prev_max = mux_private->max_mux;
861 mux_private->max_mux = mux_id + 1;
862 mux_private->private_pointers
863 = talloc_realloc(mux_private,
864 mux_private->private_pointers,
865 void *, mux_private->max_mux);
866 memset(&mux_private->private_pointers[prev_max], '\0',
867 (sizeof(*mux_private->private_pointers) * (mux_private->max_mux - prev_max)));
870 private = &mux_private->private_pointers[mux_id];
873 private = &normal_private;
876 fn(helper_mode, c, length, private, mux_id, private2);
879 static void squid_stream(enum stdio_helper_mode stdio_mode,
880 stdio_helper_function fn) {
881 /* initialize FDescs */
882 x_setbuf(x_stdout, NULL);
883 x_setbuf(x_stderr, NULL);
885 manage_squid_request(stdio_mode, fn, NULL);
902 OPT_USER_SESSION_KEY,
904 OPT_REQUIRE_MEMBERSHIP,
908 int main(int argc, const char **argv)
910 static const char *helper_protocol;
915 /* NOTE: DO NOT change this interface without considering the implications!
916 This is an external interface, which other programs will use to interact
920 /* We do not use single-letter command abbreviations, because they harm future
921 interface stability. */
923 struct poptOption long_options[] = {
925 { "helper-protocol", 0, POPT_ARG_STRING, &helper_protocol, OPT_DOMAIN, "operate as a stdio-based helper", "helper protocol to use"},
926 { "domain", 0, POPT_ARG_STRING, &opt_domain, OPT_DOMAIN, "domain name"},
927 { "workstation", 0, POPT_ARG_STRING, &opt_workstation, OPT_WORKSTATION, "workstation"},
928 { "username", 0, POPT_ARG_STRING, &opt_username, OPT_PASSWORD, "Username"},
929 { "password", 0, POPT_ARG_STRING, &opt_password, OPT_PASSWORD, "User's plaintext password"},
930 { "multiplex", 0, POPT_ARG_NONE, &opt_multiplex, OPT_MULTIPLEX, "Multiplex Mode"},
936 /* Samba client initialisation */
938 setup_logging(NULL, DEBUG_STDERR);
942 pc = poptGetContext("ntlm_auth", argc, argv, long_options, 0);
944 /* Parse command line options */
947 poptPrintHelp(pc, stderr, 0);
951 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
952 POPT_CONTEXT_KEEP_FIRST);
954 while((opt = poptGetNextOpt(pc)) != -1) {
960 fprintf(stderr, "%s: %s\n",
961 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
968 if (opt_domain == NULL) {
969 opt_domain = lp_workgroup();
972 if (helper_protocol) {
974 for (i=0; i<NUM_HELPER_MODES; i++) {
975 if (strcmp(helper_protocol, stdio_helper_protocols[i].name) == 0) {
976 squid_stream(stdio_helper_protocols[i].mode, stdio_helper_protocols[i].fn);
980 x_fprintf(x_stderr, "unknown helper protocol [%s]\n\nValid helper protools:\n\n", helper_protocol);
982 for (i=0; i<NUM_HELPER_MODES; i++) {
983 x_fprintf(x_stderr, "%s\n", stdio_helper_protocols[i].name);
990 x_fprintf(x_stderr, "username must be specified!\n\n");
991 poptPrintHelp(pc, stderr, 0);
995 if (opt_workstation == NULL) {
996 opt_workstation = lp_netbios_name();
1000 opt_password = getpass("password: ");
1006 asprintf(&user, "%s%c%s", opt_domain, *lp_winbind_separator(), opt_username);
1007 if (!check_plaintext_auth(user, opt_password, True)) {
1014 poptFreeContext(pc);