#include <ldb.h>
#include "auth/credentials/credentials.h"
#include "auth/gensec/gensec.h"
+#include "auth/gensec/gensec_internal.h" /* TODO: remove this */
#include "auth/auth.h"
#include "librpc/gen_ndr/ndr_netlogon.h"
#include "auth/auth_sam.h"
#include "lib/messaging/irpc.h"
#include "auth/ntlmssp/ntlmssp.h"
#include "param/param.h"
+#include "lib/util/base64.h"
+#include "lib/util/xfile.h"
#define INITIAL_BUFFER_SIZE 300
#define MAX_BUFFER_SIZE 63000
static const char *opt_password;
static int opt_multiplex;
static int use_cached_creds;
+static int opt_allow_mschapv2;
static void mux_printf(unsigned int mux_id, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
if (!mem_ctx) {
nt_status = NT_STATUS_NO_MEMORY;
} else {
+ uint32_t logon_parameters = 0;
E_md4hash(opt_password, nt_pw.hash);
if (E_deshash(opt_password, lm_pw.hash)) {
}
nt_pwd = &nt_pw;
+ if (opt_allow_mschapv2) {
+ logon_parameters |= MSV1_0_ALLOW_MSVCHAPV2;
+ }
nt_status = ntlm_password_check(mem_ctx,
lpcfg_lanman_auth(lp_ctx),
lpcfg_ntlm_auth(lp_ctx),
+ logon_parameters |
MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT |
MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT,
challenge,
static const char *get_password(struct cli_credentials *credentials)
{
char *password = NULL;
-
+ void *cb = cli_credentials_callback_data_void(credentials);
+
/* Ask for a password */
- mux_printf((unsigned int)(uintptr_t)credentials->priv_data, "PW\n");
- credentials->priv_data = NULL;
+ mux_printf((unsigned int)(uintptr_t)cb, "PW\n");
+ cli_credentials_set_callback_data(credentials, NULL);
manage_squid_request(cmdline_lp_ctx, NUM_HELPER_MODES /* bogus */, manage_gensec_get_pw_request, (void **)&password);
return password;
case NTLMSSP_CLIENT_1:
/* setup the client side */
- nt_status = gensec_client_start(NULL, &state->gensec_state, ev,
+ nt_status = gensec_client_start(NULL, &state->gensec_state,
lpcfg_gensec_settings(NULL, lp_ctx));
if (!NT_STATUS_IS_OK(nt_status)) {
talloc_free(mem_ctx);
case SQUID_2_5_NTLMSSP:
{
const char *winbind_method[] = { "winbind", NULL };
- struct auth_context *auth_context;
+ struct auth4_context *auth_context;
- msg = imessaging_client_init(state, lpcfg_imessaging_path(state, lp_ctx), ev);
+ msg = imessaging_client_init(state, lp_ctx, ev);
if (!msg) {
talloc_free(mem_ctx);
exit(1);
exit(1);
}
- if (!NT_STATUS_IS_OK(gensec_server_start(state, ev,
+ if (!NT_STATUS_IS_OK(gensec_server_start(state,
lpcfg_gensec_settings(state, lp_ctx),
auth_context, &state->gensec_state))) {
talloc_free(mem_ctx);
if (state->set_password) {
cli_credentials_set_password(creds, state->set_password, CRED_SPECIFIED);
} else {
+ void *cb = (void*)(uintptr_t)mux_id;
+ cli_credentials_set_callback_data(creds, cb);
cli_credentials_set_password_callback(creds, get_password);
- creds->priv_data = (void*)(uintptr_t)mux_id;
}
if (opt_workstation) {
cli_credentials_set_workstation(creds, opt_workstation, CRED_SPECIFIED);
char *grouplist = NULL;
struct auth_session_info *session_info;
- nt_status = gensec_session_info(state->gensec_state, &session_info);
+ nt_status = gensec_session_info(state->gensec_state, mem_ctx, &session_info);
if (!NT_STATUS_IS_OK(nt_status)) {
DEBUG(1, ("gensec_session_info failed: %s\n", nt_errstr(nt_status)));
mux_printf(mux_id, "BH %s\n", nt_errstr(nt_status));
if (strncmp(buf, "GK", 2) == 0) {
char *base64_key;
DEBUG(10, ("Requested session key\n"));
- nt_status = gensec_session_key(state->gensec_state, &session_key);
+ nt_status = gensec_session_key(state->gensec_state, mem_ctx, &session_key);
if(!NT_STATUS_IS_OK(nt_status)) {
DEBUG(1, ("gensec_session_key failed: %s\n", nt_errstr(nt_status)));
mux_printf(mux_id, "BH No session key\n");
return;
} else {
base64_key = base64_encode_data_blob(state, session_key);
+ SMB_ASSERT(base64_key != NULL);
mux_printf(mux_id, "GK %s\n", base64_key);
talloc_free(base64_key);
}
return;
}
- nt_status = gensec_update(state->gensec_state, mem_ctx, in, &out);
+ nt_status = gensec_update_ev(state->gensec_state, mem_ctx, ev, in, &out);
/* don't leak 'bad password'/'no such user' info to the network client */
nt_status = nt_status_squash(nt_status);
if (out.length) {
out_base64 = base64_encode_data_blob(mem_ctx, out);
+ SMB_ASSERT(out_base64 != NULL);
} else {
out_base64 = NULL;
}
} else if /* OK */ (state->gensec_state->gensec_role == GENSEC_SERVER) {
struct auth_session_info *session_info;
- nt_status = gensec_session_info(state->gensec_state, &session_info);
+ nt_status = gensec_session_info(state->gensec_state, mem_ctx, &session_info);
if (!NT_STATUS_IS_OK(nt_status)) {
reply_code = "BH Failed to retrive session info";
reply_arg = nt_errstr(nt_status);
SAFE_FREE(error_string);
} else {
static char zeros[16];
- char *hex_lm_key;
- char *hex_user_session_key;
mux_printf(mux_id, "Authenticated: Yes\n");
&& lm_key.length
&& (memcmp(zeros, lm_key.data,
lm_key.length) != 0)) {
- hex_encode(lm_key.data,
- lm_key.length,
- &hex_lm_key);
+ char hex_lm_key[lm_key.length*2+1];
+ hex_encode_buf(hex_lm_key, lm_key.data,
+ lm_key.length);
mux_printf(mux_id, "LANMAN-Session-Key: %s\n", hex_lm_key);
- SAFE_FREE(hex_lm_key);
}
if (ntlm_server_1_user_session_key
&& user_session_key.length
&& (memcmp(zeros, user_session_key.data,
user_session_key.length) != 0)) {
- hex_encode(user_session_key.data,
- user_session_key.length,
- &hex_user_session_key);
+ char hex_user_session_key[
+ user_session_key.length*2+1];
+ hex_encode_buf(hex_user_session_key,
+ user_session_key.data,
+ user_session_key.length);
mux_printf(mux_id, "User-Session-Key: %s\n", hex_user_session_key);
- SAFE_FREE(hex_user_session_key);
}
}
}
OPT_REQUIRE_MEMBERSHIP,
OPT_MULTIPLEX,
OPT_USE_CACHED_CREDS,
+ OPT_ALLOW_MSCHAPV2,
};
int main(int argc, const char **argv)
{ "password", 0, POPT_ARG_STRING, &opt_password, OPT_PASSWORD, "User's plaintext password"},
{ "multiplex", 0, POPT_ARG_NONE, &opt_multiplex, OPT_MULTIPLEX, "Multiplex Mode"},
{ "use-cached-creds", 0, POPT_ARG_NONE, &use_cached_creds, OPT_USE_CACHED_CREDS, "silently ignored for compatibility reasons"},
+ { "allow-mschapv2", 0, POPT_ARG_NONE, &opt_allow_mschapv2, OPT_ALLOW_MSCHAPV2, "Explicitly allow MSCHAPv2" },
POPT_COMMON_SAMBA
POPT_COMMON_VERSION
{ NULL }
return 1;
}
- gensec_init(cmdline_lp_ctx);
+ gensec_init();
if (opt_domain == NULL) {
opt_domain = lpcfg_workgroup(cmdline_lp_ctx);
}
if (!opt_password) {
- opt_password = getpass("password: ");
+ char pwd[256] = {0};
+ int rc;
+
+ rc = samba_getpass("Password: ", pwd, sizeof(pwd), false, false);
+ if (rc == 0) {
+ opt_password = smb_xstrdup(pwd);
+ }
}
{