*/
#include "includes.h"
+#include "popt_common.h"
#include "utils/ntlm_auth.h"
#include "../libcli/auth/libcli_auth.h"
#include "../libcli/auth/spnego.h"
-#include "../libcli/auth/ntlmssp.h"
+#include "../auth/ntlmssp/ntlmssp.h"
#include "smb_krb5.h"
#include <iniparser.h>
#include "../lib/crypto/arcfour.h"
+#include "libads/kerberos_proto.h"
+#include "nsswitch/winbind_client.h"
+#include "librpc/gen_ndr/krb5pac.h"
+#include "../lib/util/asn1.h"
#ifndef PAM_WINBIND_CONFIG_FILE
#define PAM_WINBIND_CONFIG_FILE "/etc/security/pam_winbind.conf"
struct ntlmssp_state *ntlmssp_state;
uint32_t neg_flags;
char *want_feature_list;
+ char *spnego_mech;
+ char *spnego_mech_oid;
bool have_session_key;
DATA_BLOB session_key;
DATA_BLOB initial_message;
if (winbindd_request_response(WINBINDD_NETBIOS_NAME, NULL, &response) !=
NSS_STATUS_SUCCESS) {
DEBUG(0, ("could not obtain winbind netbios name!\n"));
- return global_myname();
+ return lp_netbios_name();
}
fstrcpy(winbind_netbios_name, response.data.netbios_name);
opt_pam_winbind_conf = PAM_WINBIND_CONFIG_FILE;
}
- d = iniparser_load(CONST_DISCARD(char *, opt_pam_winbind_conf));
+ d = iniparser_load(discard_const_p(char, opt_pam_winbind_conf));
if (!d) {
return 0;
}
- if (iniparser_getboolean(d, CONST_DISCARD(char *, "global:krb5_auth"), false)) {
+ if (iniparser_getboolean(d, discard_const_p(char, "global:krb5_auth"), false)) {
ctrl |= WINBIND_KRB5_AUTH;
}
return nt_status;
}
-static NTSTATUS winbind_pw_check(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
+static NTSTATUS winbind_pw_check(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *mem_ctx,
+ DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
{
static const char zeros[16] = { 0, };
NTSTATUS nt_status;
if (NT_STATUS_IS_OK(nt_status)) {
if (memcmp(lm_key, zeros, 8) != 0) {
- *lm_session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
+ *lm_session_key = data_blob_talloc(mem_ctx, NULL, 16);
memcpy(lm_session_key->data, lm_key, 8);
memset(lm_session_key->data+8, '\0', 8);
}
if (memcmp(user_sess_key, zeros, 16) != 0) {
- *user_session_key = data_blob_talloc(ntlmssp_state, user_sess_key, 16);
+ *user_session_key = data_blob_talloc(mem_ctx, user_sess_key, 16);
}
ntlmssp_state->callback_private = talloc_strdup(ntlmssp_state,
unix_name);
return nt_status;
}
-static NTSTATUS local_pw_check(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
+static NTSTATUS local_pw_check(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *mem_ctx,
+ DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
{
NTSTATUS nt_status;
struct samr_Password lm_pw, nt_pw;
nt_lm_owf_gen (opt_password, nt_pw.hash, lm_pw.hash);
- nt_status = ntlm_password_check(ntlmssp_state,
+ nt_status = ntlm_password_check(mem_ctx,
true, true, 0,
&ntlmssp_state->chal,
&ntlmssp_state->lm_resp,
}
status = ntlmssp_client_start(NULL,
- global_myname(),
+ lp_netbios_name(),
lp_workgroup(),
lp_client_ntlmv2_auth(),
client_ntlmssp_state);
bool is_standalone = false;
if (opt_password) {
- netbios_name = global_myname();
+ netbios_name = lp_netbios_name();
netbios_domain = lp_workgroup();
} else {
netbios_name = get_winbind_netbios_name();
return status;
}
+ (*ntlmssp_state)->neg_flags |=
+ (NTLMSSP_NEGOTIATE_SIGN |
+ NTLMSSP_NEGOTIATE_SEAL);
+
/* Have we been given a local password, or should we ask winbind? */
if (opt_password) {
(*ntlmssp_state)->check_password = local_pw_check;
* child of the trusted domain. If we ask the primary domain for
* ntlm_ccache_auth, it will fail. So, we have to ask the trusted
* domain's child for ccache_ntlm_auth. that is to say, we have to
- * set WBFALG_PAM_CONTACT_TRUSTDOM in request.flags.
+ * set WBFLAG_PAM_CONTACT_TRUSTDOM in request.flags.
*/
ctrl = get_pam_winbind_config();
- if (ctrl | WINBIND_KRB5_AUTH) {
+ if (ctrl & WINBIND_KRB5_AUTH) {
wb_request.flags |= WBFLAG_PAM_CONTACT_TRUSTDOM;
}
return NT_STATUS_MORE_PROCESSING_REQUIRED;
}
-static void manage_squid_ntlmssp_request(struct ntlm_auth_state *state,
- char *buf, int length)
+static void manage_squid_ntlmssp_request_int(struct ntlm_auth_state *state,
+ char *buf, int length,
+ TALLOC_CTX *mem_ctx,
+ char **response)
{
DATA_BLOB request, reply;
NTSTATUS nt_status;
if (strlen(buf) < 2) {
- DEBUG(1, ("NTLMSSP query [%s] invalid", buf));
- x_fprintf(x_stdout, "BH NTLMSSP query invalid\n");
+ DEBUG(1, ("NTLMSSP query [%s] invalid\n", buf));
+ *response = talloc_strdup(mem_ctx, "BH NTLMSSP query invalid");
return;
}
TALLOC_FREE(state->want_feature_list);
state->want_feature_list = talloc_strdup(state->mem_ctx,
buf+3);
- x_fprintf(x_stdout, "OK\n");
+ *response = talloc_strdup(mem_ctx, "OK");
return;
}
request = base64_decode_data_blob(buf + 3);
if (opt_password == NULL) {
DEBUG(1, ("Out of memory\n"));
- x_fprintf(x_stdout, "BH Out of memory\n");
+ *response = talloc_strdup(mem_ctx, "BH Out of memory");
data_blob_free(&request);
return;
}
- x_fprintf(x_stdout, "OK\n");
+ *response = talloc_strdup(mem_ctx, "OK");
data_blob_free(&request);
return;
}
if (strncmp(buf, "YR", 2) == 0) {
- if (state->ntlmssp_state)
- TALLOC_FREE(state->ntlmssp_state);
+ TALLOC_FREE(state->ntlmssp_state);
state->svr_state = SERVER_INITIAL;
} else if (strncmp(buf, "KK", 2) == 0) {
/* No special preprocessing required */
DEBUG(10, ("Requested negotiated NTLMSSP flags\n"));
if (state->svr_state == SERVER_FINISHED) {
- x_fprintf(x_stdout, "GF 0x%08x\n", state->neg_flags);
+ *response = talloc_asprintf(mem_ctx, "GF 0x%08x",
+ state->neg_flags);
}
else {
- x_fprintf(x_stdout, "BH\n");
+ *response = talloc_strdup(mem_ctx, "BH\n");
}
data_blob_free(&request);
return;
if(state->have_session_key) {
char *key64 = base64_encode_data_blob(state->mem_ctx,
state->session_key);
- x_fprintf(x_stdout, "GK %s\n", key64?key64:"<NULL>");
+ *response = talloc_asprintf(mem_ctx, "GK %s",
+ key64 ? key64 : "<NULL>");
TALLOC_FREE(key64);
} else {
- x_fprintf(x_stdout, "BH\n");
+ *response = talloc_strdup(mem_ctx, "BH");
}
data_blob_free(&request);
return;
} else {
- DEBUG(1, ("NTLMSSP query [%s] invalid", buf));
- x_fprintf(x_stdout, "BH NTLMSSP query invalid\n");
+ DEBUG(1, ("NTLMSSP query [%s] invalid\n", buf));
+ *response = talloc_strdup(mem_ctx, "BH NTLMSSP query invalid");
return;
}
nt_status = ntlm_auth_start_ntlmssp_server(
&state->ntlmssp_state);
if (!NT_STATUS_IS_OK(nt_status)) {
- x_fprintf(x_stdout, "BH %s\n", nt_errstr(nt_status));
+ *response = talloc_asprintf(
+ mem_ctx, "BH %s", nt_errstr(nt_status));
return;
}
ntlmssp_want_feature_list(state->ntlmssp_state,
if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
char *reply_base64 = base64_encode_data_blob(state->mem_ctx,
reply);
- x_fprintf(x_stdout, "TT %s\n", reply_base64);
+ *response = talloc_asprintf(mem_ctx, "TT %s", reply_base64);
TALLOC_FREE(reply_base64);
data_blob_free(&reply);
state->svr_state = SERVER_CHALLENGE;
DEBUG(10, ("NTLMSSP challenge\n"));
} else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCESS_DENIED)) {
- x_fprintf(x_stdout, "BH %s\n", nt_errstr(nt_status));
+ *response = talloc_asprintf(mem_ctx, "BH %s",
+ nt_errstr(nt_status));
DEBUG(0, ("NTLMSSP BH: %s\n", nt_errstr(nt_status)));
TALLOC_FREE(state->ntlmssp_state);
} else if (!NT_STATUS_IS_OK(nt_status)) {
- x_fprintf(x_stdout, "NA %s\n", nt_errstr(nt_status));
+ *response = talloc_asprintf(mem_ctx, "NA %s",
+ nt_errstr(nt_status));
DEBUG(10, ("NTLMSSP %s\n", nt_errstr(nt_status)));
} else {
- x_fprintf(x_stdout, "AF %s\n",
- (char *)state->ntlmssp_state->callback_private);
+ *response = talloc_asprintf(
+ mem_ctx, "AF %s",
+ (char *)state->ntlmssp_state->callback_private);
DEBUG(10, ("NTLMSSP OK!\n"));
if(state->have_session_key)
data_blob_free(&request);
}
+static void manage_squid_ntlmssp_request(struct ntlm_auth_state *state,
+ char *buf, int length)
+{
+ char *response;
+
+ manage_squid_ntlmssp_request_int(state, buf, length,
+ talloc_tos(), &response);
+
+ if (response == NULL) {
+ x_fprintf(x_stdout, "BH Out of memory\n");
+ return;
+ }
+ x_fprintf(x_stdout, "%s\n", response);
+ TALLOC_FREE(response);
+}
+
static void manage_client_ntlmssp_request(struct ntlm_auth_state *state,
char *buf, int length)
{
}
if (strlen(buf) < 2) {
- DEBUG(1, ("NTLMSSP query [%s] invalid", buf));
+ DEBUG(1, ("NTLMSSP query [%s] invalid\n", buf));
x_fprintf(x_stdout, "BH NTLMSSP query invalid\n");
return;
}
}
if (strncmp(buf, "YR", 2) == 0) {
- if (state->ntlmssp_state)
- TALLOC_FREE(state->ntlmssp_state);
+ TALLOC_FREE(state->ntlmssp_state);
state->cli_state = CLIENT_INITIAL;
} else if (strncmp(buf, "TT", 2) == 0) {
/* No special preprocessing required */
data_blob_free(&request);
return;
} else {
- DEBUG(1, ("NTLMSSP query [%s] invalid", buf));
+ DEBUG(1, ("NTLMSSP query [%s] invalid\n", buf));
x_fprintf(x_stdout, "BH NTLMSSP query invalid\n");
return;
}
DEBUG(10, ("NTLMSSP OK!\n"));
state->cli_state = CLIENT_FINISHED;
- if (state->ntlmssp_state)
- TALLOC_FREE(state->ntlmssp_state);
+ TALLOC_FREE(state->ntlmssp_state);
} else {
x_fprintf(x_stdout, "BH %s\n", nt_errstr(nt_status));
DEBUG(0, ("NTLMSSP BH: %s\n", nt_errstr(nt_status)));
state->cli_state = CLIENT_ERROR;
- if (state->ntlmssp_state)
- TALLOC_FREE(state->ntlmssp_state);
+ TALLOC_FREE(state->ntlmssp_state);
}
data_blob_free(&request);
ZERO_STRUCT(spnego);
- myname_lower = talloc_strdup(ctx, global_myname());
+ myname_lower = talloc_strdup(ctx, lp_netbios_name());
if (!myname_lower) {
return;
}
/* Server negTokenInit (mech offerings) */
spnego.type = SPNEGO_NEG_TOKEN_INIT;
- spnego.negTokenInit.mechTypes = talloc_array(ctx, const char *, 2);
+ spnego.negTokenInit.mechTypes = talloc_array(ctx, const char *, 4);
#ifdef HAVE_KRB5
spnego.negTokenInit.mechTypes[0] = talloc_strdup(ctx, OID_KERBEROS5_OLD);
- spnego.negTokenInit.mechTypes[1] = talloc_strdup(ctx, OID_NTLMSSP);
- spnego.negTokenInit.mechTypes[2] = NULL;
+ spnego.negTokenInit.mechTypes[1] = talloc_strdup(ctx, OID_KERBEROS5);
+ spnego.negTokenInit.mechTypes[2] = talloc_strdup(ctx, OID_NTLMSSP);
+ spnego.negTokenInit.mechTypes[3] = NULL;
#else
spnego.negTokenInit.mechTypes[0] = talloc_strdup(ctx, OID_NTLMSSP);
spnego.negTokenInit.mechTypes[1] = NULL;
static void manage_gss_spnego_request(struct ntlm_auth_state *state,
char *buf, int length)
{
- static struct ntlmssp_state *ntlmssp_state = NULL;
struct spnego_data request, response;
DATA_BLOB token;
+ DATA_BLOB raw_in_token = data_blob_null;
+ DATA_BLOB raw_out_token = data_blob_null;
NTSTATUS status;
ssize_t len;
TALLOC_CTX *ctx = talloc_tos();
const char *reply_code;
char *reply_base64;
char *reply_argument = NULL;
+ char *supportedMech = NULL;
if (strlen(buf) < 2) {
- DEBUG(1, ("SPENGO query [%s] invalid", buf));
+ DEBUG(1, ("SPENGO query [%s] invalid\n", buf));
x_fprintf(x_stdout, "BH SPENGO query invalid\n");
return;
}
if (strncmp(buf, "YR", 2) == 0) {
- if (ntlmssp_state)
- TALLOC_FREE(ntlmssp_state);
+ TALLOC_FREE(state->ntlmssp_state);
+ TALLOC_FREE(state->spnego_mech);
+ TALLOC_FREE(state->spnego_mech_oid);
} else if (strncmp(buf, "KK", 2) == 0) {
;
} else {
- DEBUG(1, ("SPENGO query [%s] invalid", buf));
+ DEBUG(1, ("SPENGO query [%s] invalid\n", buf));
x_fprintf(x_stdout, "BH SPENGO query invalid\n");
return;
}
}
token = base64_decode_data_blob(buf + 3);
+
+ if ((token.length >= 7)
+ && (strncmp((char *)token.data, "NTLMSSP", 7) == 0)) {
+ char *reply;
+
+ data_blob_free(&token);
+
+ DEBUG(10, ("Could not parse GSS-SPNEGO, trying raw "
+ "ntlmssp\n"));
+
+ manage_squid_ntlmssp_request_int(state, buf, length,
+ talloc_tos(), &reply);
+ if (reply == NULL) {
+ x_fprintf(x_stdout, "BH Out of memory\n");
+ return;
+ }
+
+ if (strncmp(reply, "AF ", 3) == 0) {
+ x_fprintf(x_stdout, "AF * %s\n", reply+3);
+ } else {
+ x_fprintf(x_stdout, "%s *\n", reply);
+ }
+
+ TALLOC_FREE(reply);
+ return;
+ }
+
+ ZERO_STRUCT(request);
len = spnego_read_data(ctx, token, &request);
data_blob_free(&token);
if (len == -1) {
- DEBUG(1, ("GSS-SPNEGO query [%s] invalid", buf));
+ DEBUG(1, ("GSS-SPNEGO query [%s] invalid\n", buf));
x_fprintf(x_stdout, "BH GSS-SPNEGO query invalid\n");
return;
}
if (request.type == SPNEGO_NEG_TOKEN_INIT) {
+#ifdef HAVE_KRB5
+ int krb5_idx = -1;
+#endif
+ int ntlm_idx = -1;
+ int used_idx = -1;
+ int i;
+
+ if (state->spnego_mech) {
+ DEBUG(1, ("Client restarted SPNEGO with NegTokenInit "
+ "while mech[%s] was already negotiated\n",
+ state->spnego_mech));
+ x_fprintf(x_stdout, "BH Client send NegTokenInit twice\n");
+ return;
+ }
/* Second request from Client. This is where the
client offers its mechanism to use. */
if ( (request.negTokenInit.mechTypes == NULL) ||
(request.negTokenInit.mechTypes[0] == NULL) ) {
- DEBUG(1, ("Client did not offer any mechanism"));
+ DEBUG(1, ("Client did not offer any mechanism\n"));
x_fprintf(x_stdout, "BH Client did not offer any "
"mechanism\n");
return;
}
status = NT_STATUS_UNSUCCESSFUL;
- if (strcmp(request.negTokenInit.mechTypes[0], OID_NTLMSSP) == 0) {
+ for (i = 0; request.negTokenInit.mechTypes[i] != NULL; i++) {
+ DEBUG(10,("got mech[%d][%s]\n",
+ i, request.negTokenInit.mechTypes[i]));
+#ifdef HAVE_KRB5
+ if (strcmp(request.negTokenInit.mechTypes[i], OID_KERBEROS5_OLD) == 0) {
+ krb5_idx = i;
+ break;
+ }
+ if (strcmp(request.negTokenInit.mechTypes[i], OID_KERBEROS5) == 0) {
+ krb5_idx = i;
+ break;
+ }
+#endif
+ if (strcmp(request.negTokenInit.mechTypes[i], OID_NTLMSSP) == 0) {
+ ntlm_idx = i;
+ break;
+ }
+ }
- if ( request.negTokenInit.mechToken.data == NULL ) {
- DEBUG(1, ("Client did not provide NTLMSSP data\n"));
- x_fprintf(x_stdout, "BH Client did not provide "
- "NTLMSSP data\n");
+ used_idx = ntlm_idx;
+#ifdef HAVE_KRB5
+ if (krb5_idx != -1) {
+ ntlm_idx = -1;
+ used_idx = krb5_idx;
+ }
+#endif
+ if (ntlm_idx > -1) {
+ state->spnego_mech = talloc_strdup(state, "ntlmssp");
+ if (state->spnego_mech == NULL) {
+ x_fprintf(x_stdout, "BH Out of memory\n");
return;
}
- if ( ntlmssp_state != NULL ) {
+ if (state->ntlmssp_state) {
DEBUG(1, ("Client wants a new NTLMSSP challenge, but "
"already got one\n"));
x_fprintf(x_stdout, "BH Client wants a new "
"NTLMSSP challenge, but "
"already got one\n");
- TALLOC_FREE(ntlmssp_state);
+ TALLOC_FREE(state->ntlmssp_state);
return;
}
- if (!NT_STATUS_IS_OK(status = ntlm_auth_start_ntlmssp_server(&ntlmssp_state))) {
+ status = ntlm_auth_start_ntlmssp_server(&state->ntlmssp_state);
+ if (!NT_STATUS_IS_OK(status)) {
x_fprintf(x_stdout, "BH %s\n", nt_errstr(status));
return;
}
-
- DEBUG(10, ("got NTLMSSP packet:\n"));
- dump_data(10, request.negTokenInit.mechToken.data,
- request.negTokenInit.mechToken.length);
-
- response.type = SPNEGO_NEG_TOKEN_TARG;
- response.negTokenTarg.supportedMech = talloc_strdup(ctx, OID_NTLMSSP);
- response.negTokenTarg.mechListMIC = data_blob_talloc(ctx, NULL, 0);
-
- status = ntlmssp_update(ntlmssp_state,
- request.negTokenInit.mechToken,
- &response.negTokenTarg.responseToken);
}
#ifdef HAVE_KRB5
- if (strcmp(request.negTokenInit.mechTypes[0], OID_KERBEROS5_OLD) == 0) {
-
- TALLOC_CTX *mem_ctx = talloc_init("manage_gss_spnego_request");
- char *principal;
- DATA_BLOB ap_rep;
- DATA_BLOB session_key;
- struct PAC_LOGON_INFO *logon_info = NULL;
-
- if ( request.negTokenInit.mechToken.data == NULL ) {
- DEBUG(1, ("Client did not provide Kerberos data\n"));
- x_fprintf(x_stdout, "BH Client did not provide "
- "Kerberos data\n");
+ if (krb5_idx > -1) {
+ state->spnego_mech = talloc_strdup(state, "krb5");
+ if (state->spnego_mech == NULL) {
+ x_fprintf(x_stdout, "BH Out of memory\n");
return;
}
-
- response.type = SPNEGO_NEG_TOKEN_TARG;
- response.negTokenTarg.supportedMech = talloc_strdup(ctx, OID_KERBEROS5_OLD);
- response.negTokenTarg.mechListMIC = data_blob_talloc(ctx, NULL, 0);
- response.negTokenTarg.responseToken = data_blob_talloc(ctx, NULL, 0);
-
- status = ads_verify_ticket(mem_ctx, lp_realm(), 0,
- &request.negTokenInit.mechToken,
- &principal, &logon_info, &ap_rep,
- &session_key, True);
-
- /* Now in "principal" we have the name we are
- authenticated as. */
-
- if (NT_STATUS_IS_OK(status)) {
-
- domain = strchr_m(principal, '@');
-
- if (domain == NULL) {
- DEBUG(1, ("Did not get a valid principal "
- "from ads_verify_ticket\n"));
- x_fprintf(x_stdout, "BH Did not get a "
- "valid principal from "
- "ads_verify_ticket\n");
- return;
- }
-
- *domain++ = '\0';
- domain = SMB_STRDUP(domain);
- user = SMB_STRDUP(principal);
-
- data_blob_free(&ap_rep);
- }
-
- TALLOC_FREE(mem_ctx);
}
#endif
+ if (used_idx > -1) {
+ state->spnego_mech_oid = talloc_strdup(state,
+ request.negTokenInit.mechTypes[used_idx]);
+ if (state->spnego_mech_oid == NULL) {
+ x_fprintf(x_stdout, "BH Out of memory\n");
+ return;
+ }
+ supportedMech = talloc_strdup(ctx, state->spnego_mech_oid);
+ if (supportedMech == NULL) {
+ x_fprintf(x_stdout, "BH Out of memory\n");
+ return;
+ }
+ status = NT_STATUS_MORE_PROCESSING_REQUIRED;
+ } else {
+ status = NT_STATUS_NOT_SUPPORTED;
+ }
+ if (used_idx == 0) {
+ status = NT_STATUS_OK;
+ raw_in_token = request.negTokenInit.mechToken;
+ }
} else {
+ if (state->spnego_mech == NULL) {
+ DEBUG(1,("Got netTokenTarg without negTokenInit\n"));
+ x_fprintf(x_stdout, "BH Got a negTokenTarg without "
+ "negTokenInit\n");
+ return;
+ }
- if ( (request.negTokenTarg.supportedMech == NULL) ||
- ( strcmp(request.negTokenTarg.supportedMech, OID_NTLMSSP) != 0 ) ) {
- /* Kerberos should never send a negTokenTarg, OID_NTLMSSP
- is the only one we support that sends this stuff */
- DEBUG(1, ("Got a negTokenTarg for something non-NTLMSSP: %s\n",
- request.negTokenTarg.supportedMech));
- x_fprintf(x_stdout, "BH Got a negTokenTarg for "
- "something non-NTLMSSP\n");
+ if ((request.negTokenTarg.supportedMech != NULL) &&
+ (strcmp(request.negTokenTarg.supportedMech, state->spnego_mech_oid) != 0 ) ) {
+ DEBUG(1, ("Got a negTokenTarg with mech[%s] while [%s] was already negotiated\n",
+ request.negTokenTarg.supportedMech,
+ state->spnego_mech_oid));
+ x_fprintf(x_stdout, "BH Got a negTokenTarg with speficied mech\n");
return;
}
- if (request.negTokenTarg.responseToken.data == NULL) {
- DEBUG(1, ("Got a negTokenTarg without a responseToken!\n"));
- x_fprintf(x_stdout, "BH Got a negTokenTarg without a "
- "responseToken!\n");
+ status = NT_STATUS_OK;
+ raw_in_token = request.negTokenTarg.responseToken;
+ }
+
+ if (!NT_STATUS_IS_OK(status)) {
+ /* error or more processing */
+ } else if (strcmp(state->spnego_mech, "ntlmssp") == 0) {
+
+ DEBUG(10, ("got NTLMSSP packet:\n"));
+ dump_data(10, raw_in_token.data, raw_in_token.length);
+
+ status = ntlmssp_update(state->ntlmssp_state,
+ raw_in_token,
+ &raw_out_token);
+ if (NT_STATUS_IS_OK(status)) {
+ user = talloc_strdup(ctx, state->ntlmssp_state->user);
+ domain = talloc_strdup(ctx, state->ntlmssp_state->domain);
+ }
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
+ TALLOC_FREE(state->ntlmssp_state);
+ }
+#ifdef HAVE_KRB5
+ } else if (strcmp(state->spnego_mech, "krb5") == 0) {
+ char *principal;
+ DATA_BLOB ap_rep;
+ DATA_BLOB session_key;
+ struct PAC_LOGON_INFO *logon_info = NULL;
+ DATA_BLOB ticket;
+ uint8_t tok_id[2];
+
+ if (!spnego_parse_krb5_wrap(ctx, raw_in_token,
+ &ticket, tok_id)) {
+ DEBUG(1, ("spnego_parse_krb5_wrap failed\n"));
+ x_fprintf(x_stdout, "BH spnego_parse_krb5_wrap failed\n");
return;
}
- status = ntlmssp_update(ntlmssp_state,
- request.negTokenTarg.responseToken,
- &response.negTokenTarg.responseToken);
+ status = ads_verify_ticket(ctx, lp_realm(), 0,
+ &ticket,
+ &principal, &logon_info, &ap_rep,
+ &session_key, True);
- response.type = SPNEGO_NEG_TOKEN_TARG;
- response.negTokenTarg.supportedMech = talloc_strdup(ctx, OID_NTLMSSP);
- response.negTokenTarg.mechListMIC = data_blob_talloc(ctx, NULL, 0);
+ /* Now in "principal" we have the name we are authenticated as. */
if (NT_STATUS_IS_OK(status)) {
- user = SMB_STRDUP(ntlmssp_state->user);
- domain = SMB_STRDUP(ntlmssp_state->domain);
- TALLOC_FREE(ntlmssp_state);
+
+ domain = strchr_m(principal, '@');
+
+ if (domain == NULL) {
+ DEBUG(1, ("Did not get a valid principal "
+ "from ads_verify_ticket\n"));
+ x_fprintf(x_stdout, "BH Did not get a "
+ "valid principal from "
+ "ads_verify_ticket\n");
+ return;
+ }
+
+ *domain++ = '\0';
+ domain = talloc_strdup(ctx, domain);
+ user = talloc_strdup(ctx, principal);
+
+ if (logon_info) {
+ netsamlogon_cache_store(
+ user, &logon_info->info3);
+ }
+
+ data_blob_free(&ap_rep);
+ data_blob_free(&session_key);
}
+ data_blob_free(&ticket);
+#endif
}
spnego_free_data(&request);
+ ZERO_STRUCT(response);
+ response.type = SPNEGO_NEG_TOKEN_TARG;
if (NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(state->spnego_mech);
+ TALLOC_FREE(state->spnego_mech_oid);
response.negTokenTarg.negResult = SPNEGO_ACCEPT_COMPLETED;
+ response.negTokenTarg.responseToken = raw_out_token;
reply_code = "AF";
reply_argument = talloc_asprintf(ctx, "%s\\%s", domain, user);
} else if (NT_STATUS_EQUAL(status,
NT_STATUS_MORE_PROCESSING_REQUIRED)) {
+ response.negTokenTarg.supportedMech = supportedMech;
+ response.negTokenTarg.responseToken = raw_out_token;
response.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
reply_code = "TT";
reply_argument = talloc_strdup(ctx, "*");
} else {
+ TALLOC_FREE(state->spnego_mech);
+ TALLOC_FREE(state->spnego_mech_oid);
+ data_blob_free(&raw_out_token);
response.negTokenTarg.negResult = SPNEGO_REJECT;
reply_code = "NA";
reply_argument = talloc_strdup(ctx, nt_errstr(status));
if (!reply_argument) {
DEBUG(1, ("Could not write SPNEGO data blob\n"));
x_fprintf(x_stdout, "BH Could not write SPNEGO data blob\n");
+ spnego_free_data(&response);
return;
}
- SAFE_FREE(user);
- SAFE_FREE(domain);
-
len = spnego_write_data(ctx, &token, &response);
spnego_free_data(&response);
spnego.type = SPNEGO_NEG_TOKEN_TARG;
spnego.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
- spnego.negTokenTarg.supportedMech = (char *)OID_NTLMSSP;
+ spnego.negTokenTarg.supportedMech = (const char *)OID_NTLMSSP;
spnego.negTokenTarg.responseToken = request;
spnego.negTokenTarg.mechListMIC = null_blob;
spnego.negTokenInit.mechListMIC.length);
principal[spnego.negTokenInit.mechListMIC.length] = '\0';
- retval = cli_krb5_get_ticket(principal, 0, &tkt, &session_key_krb5, 0, NULL, NULL, NULL);
-
+ retval = cli_krb5_get_ticket(ctx, principal, 0,
+ &tkt, &session_key_krb5,
+ 0, NULL, NULL, NULL);
if (retval) {
char *user = NULL;
return False;
}
- retval = cli_krb5_get_ticket(principal, 0, &tkt, &session_key_krb5, 0, NULL, NULL, NULL);
-
+ retval = cli_krb5_get_ticket(ctx, principal, 0,
+ &tkt, &session_key_krb5,
+ 0, NULL, NULL, NULL);
if (retval) {
DEBUG(10, ("Kinit suceeded, but getting a ticket failed: %s\n", error_message(retval)));
return False;
if (!NT_STATUS_IS_OK(
contact_winbind_auth_crap(username,
domain,
- global_myname(),
+ lp_netbios_name(),
&challenge,
&lm_response,
&nt_response,
state->helper_mode = stdio_mode;
while(1) {
+ TALLOC_CTX *frame = talloc_stackframe();
manage_squid_request(state, fn);
+ TALLOC_FREE(frame);
}
}
{ "request-lm-key", 0, POPT_ARG_NONE, &request_lm_key, OPT_LM_KEY, "Retrieve LM session key"},
{ "request-nt-key", 0, POPT_ARG_NONE, &request_user_session_key, OPT_USER_SESSION_KEY, "Retrieve User (NT) session key"},
{ "use-cached-creds", 0, POPT_ARG_NONE, &use_cached_creds, OPT_USE_CACHED_CREDS, "Use cached credentials if no password is given"},
- { "diagnostics", 0, POPT_ARG_NONE, &diagnostics, OPT_DIAGNOSTICS, "Perform diagnostics on the authentictaion chain"},
+ { "diagnostics", 0, POPT_ARG_NONE, &diagnostics,
+ OPT_DIAGNOSTICS,
+ "Perform diagnostics on the authentication chain"},
{ "require-membership-of", 0, POPT_ARG_STRING, &require_membership_of, OPT_REQUIRE_MEMBERSHIP, "Require that a user be a member of this group (either name or SID) for authentication to succeed" },
{ "pam-winbind-conf", 0, POPT_ARG_STRING, &opt_pam_winbind_conf, OPT_PAM_WINBIND_CONF, "Require that request must set WBFLAG_PAM_CONTACT_TRUSTDOM when krb5 auth is required" },
POPT_COMMON_CONFIGFILE
/* Samba client initialisation */
load_case_tables();
- dbf = x_stderr;
+ setup_logging("ntlm_auth", DEBUG_STDERR);
/* Parse options */
poptFreeContext(pc);
- if (!lp_load(get_dyn_CONFIGFILE(), True, False, False, True)) {
+ if (!lp_load_global(get_dyn_CONFIGFILE())) {
d_fprintf(stderr, "ntlm_auth: error opening config file %s. Error was %s\n",
get_dyn_CONFIGFILE(), strerror(errno));
exit(1);
break;
case OPT_REQUIRE_MEMBERSHIP:
- if (StrnCaseCmp("S-", require_membership_of, 2) == 0) {
+ if (strncasecmp_m("S-", require_membership_of, 2) == 0) {
require_membership_of_sid = require_membership_of;
}
break;