#include "system/filesys.h"
#include "srv_pipe_internal.h"
#include "../librpc/gen_ndr/ndr_schannel.h"
+#include "../librpc/gen_ndr/dcerpc.h"
+#include "../librpc/rpc/rpc_common.h"
#include "../libcli/auth/schannel.h"
#include "../libcli/auth/spnego.h"
-#include "dcesrv_ntlmssp.h"
-#include "dcesrv_gssapi.h"
-#include "dcesrv_spnego.h"
+#include "dcesrv_auth_generic.h"
#include "rpc_server.h"
#include "rpc_dce.h"
#include "smbd/smbd.h"
#include "ntdomain.h"
#include "rpc_server/srv_pipe.h"
#include "rpc_server/rpc_contexts.h"
+#include "lib/param/param.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_SRV
* the pipe gets closed. JRA.
*/
if (p->fault_state) {
- setup_fault_pdu(p, NT_STATUS(DCERPC_FAULT_OP_RNG_ERROR));
+ setup_fault_pdu(p, NT_STATUS(p->fault_state));
return true;
}
/* we have to check all now since win2k introduced a new UUID on the lsaprpc pipe */
if (rpc_srv_pipe_exists_by_id(abstract) &&
- ndr_syntax_id_equal(transfer, &ndr_transfer_syntax)) {
+ ndr_syntax_id_equal(transfer, &ndr_transfer_syntax_ndr)) {
DEBUG(3, ("check_bind_req: %s -> %s rpc service\n",
rpc_srv_get_pipe_cli_name(abstract),
rpc_srv_get_pipe_srv_name(abstract)));
return false;
}
- context_fns = SMB_MALLOC_P(struct pipe_rpc_fns);
+ context_fns = talloc(p, struct pipe_rpc_fns);
if (context_fns == NULL) {
- DEBUG(0,("check_bind_req: malloc() failed!\n"));
- return False;
+ DEBUG(0,("check_bind_req: talloc() failed!\n"));
+ return false;
}
context_fns->next = context_fns->prev = NULL;
/**
* Is a named pipe known?
- * @param[in] cli_filename The pipe name requested by the client
+ * @param[in] pipename Just the filename
* @result Do we want to serve this?
*/
-bool is_known_pipename(const char *cli_filename, struct ndr_syntax_id *syntax)
+bool is_known_pipename(const char *pipename, struct ndr_syntax_id *syntax)
{
- const char *pipename = cli_filename;
NTSTATUS status;
- if (strnequal(pipename, "\\PIPE\\", 6)) {
- pipename += 5;
- }
-
- if (*pipename == '\\') {
- pipename += 1;
- }
-
if (lp_disable_spoolss() && strequal(pipename, "spoolss")) {
DEBUG(10, ("refusing spoolss access\n"));
return false;
status = smb_probe_module("rpc", pipename);
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(10, ("is_known_pipename: %s unknown\n", cli_filename));
+ DEBUG(10, ("is_known_pipename: %s unknown\n", pipename));
return false;
}
DEBUG(10, ("is_known_pipename: %s loaded dynamically\n", pipename));
return false;
}
-/*******************************************************************
- Handle the first part of a SPNEGO bind auth.
-*******************************************************************/
-
-static bool pipe_spnego_auth_bind(struct pipes_struct *p,
- TALLOC_CTX *mem_ctx,
- struct dcerpc_auth *auth_info,
- DATA_BLOB *response)
-{
- struct spnego_context *spnego_ctx;
- NTSTATUS status;
-
- status = spnego_server_auth_start(p,
- (auth_info->auth_level ==
- DCERPC_AUTH_LEVEL_INTEGRITY),
- (auth_info->auth_level ==
- DCERPC_AUTH_LEVEL_PRIVACY),
- true,
- &auth_info->credentials,
- response,
- &spnego_ctx);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("Failed SPNEGO negotiate (%s)\n",
- nt_errstr(status)));
- return false;
- }
-
- /* Make sure data is bound to the memctx, to be freed the caller */
- talloc_steal(mem_ctx, response->data);
-
- p->auth.auth_ctx = spnego_ctx;
- p->auth.auth_type = DCERPC_AUTH_TYPE_SPNEGO;
-
- DEBUG(10, ("SPNEGO auth started\n"));
-
- return true;
-}
-
/*******************************************************************
Handle an schannel bind auth.
*******************************************************************/
struct netlogon_creds_CredentialState *creds;
enum ndr_err_code ndr_err;
struct schannel_state *schannel_auth;
+ struct loadparm_context *lp_ctx;
ndr_err = ndr_pull_struct_blob(
&auth_info->credentials, mem_ctx, &neg,
return false;
}
+ lp_ctx = loadparm_init_s3(p, loadparm_s3_helpers());
+ if (!lp_ctx) {
+ DEBUG(0,("pipe_schannel_auth_bind: loadparm_init_s3() failed!\n"));
+ return false;
+ }
+
/*
* The neg.oem_netbios_computer.a key here must match the remote computer name
* given in the DOM_CLNT_SRV.uni_comp_name used on all netlogon pipe
*/
become_root();
- status = schannel_get_creds_state(p, lp_private_dir(),
+ status = schannel_get_creds_state(p, lp_ctx,
neg.oem_netbios_computer.a, &creds);
unbecome_root();
-
+
+ talloc_unlink(p, lp_ctx);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("pipe_schannel_auth_bind: Attempt to bind using schannel without successful serverauth2\n"));
return False;
}
- schannel_auth = talloc(p, struct schannel_state);
+ schannel_auth = talloc_zero(p, struct schannel_state);
if (!schannel_auth) {
TALLOC_FREE(creds);
return False;
}
schannel_auth->state = SCHANNEL_STATE_START;
- schannel_auth->seq_num = 0;
schannel_auth->initiator = false;
schannel_auth->creds = creds;
Handle an NTLMSSP bind auth.
*******************************************************************/
-static bool pipe_ntlmssp_auth_bind(struct pipes_struct *p,
+static bool pipe_auth_generic_bind(struct pipes_struct *p,
TALLOC_CTX *mem_ctx,
struct dcerpc_auth *auth_info,
DATA_BLOB *response)
{
- struct auth_ntlmssp_state *ntlmssp_state = NULL;
+ struct gensec_security *gensec_security = NULL;
NTSTATUS status;
- if (strncmp((char *)auth_info->credentials.data, "NTLMSSP", 7) != 0) {
- DEBUG(0, ("Failed to read NTLMSSP in blob\n"));
- return false;
- }
-
- /* We have an NTLMSSP blob. */
- status = ntlmssp_server_auth_start(p,
- (auth_info->auth_level ==
- DCERPC_AUTH_LEVEL_INTEGRITY),
- (auth_info->auth_level ==
- DCERPC_AUTH_LEVEL_PRIVACY),
- true,
- &auth_info->credentials,
- response,
- &ntlmssp_state);
+ status = auth_generic_server_authtype_start(p,
+ auth_info->auth_type,
+ auth_info->auth_level,
+ &auth_info->credentials,
+ response,
+ p->remote_address,
+ &gensec_security);
if (!NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
- DEBUG(0, (__location__ ": auth_ntlmssp_start failed: %s\n",
+ DEBUG(0, (__location__ ": auth_generic_server_authtype_start failed: %s\n",
nt_errstr(status)));
return false;
}
/* Make sure data is bound to the memctx, to be freed the caller */
talloc_steal(mem_ctx, response->data);
- p->auth.auth_ctx = ntlmssp_state;
- p->auth.auth_type = DCERPC_AUTH_TYPE_NTLMSSP;
-
- DEBUG(10, (__location__ ": NTLMSSP auth started\n"));
+ p->auth.auth_ctx = gensec_security;
+ p->auth.auth_type = auth_info->auth_type;
return true;
}
the pipe struct.
*******************************************************************/
-static bool pipe_ntlmssp_verify_final(TALLOC_CTX *mem_ctx,
- struct auth_ntlmssp_state *ntlmssp_ctx,
+static bool pipe_auth_generic_verify_final(TALLOC_CTX *mem_ctx,
+ struct gensec_security *gensec_security,
enum dcerpc_AuthLevel auth_level,
- struct client_address *client_id,
- struct auth_serversupplied_info **session_info)
+ struct auth_session_info **session_info)
{
NTSTATUS status;
bool ret;
ensure the underlying NTLMSSP flags are also set. If not we should
refuse the bind. */
- status = ntlmssp_server_check_flags(ntlmssp_ctx,
+ status = auth_generic_server_check_flags(gensec_security,
(auth_level ==
DCERPC_AUTH_LEVEL_INTEGRITY),
(auth_level ==
TALLOC_FREE(*session_info);
- status = ntlmssp_server_get_user_info(ntlmssp_ctx,
+ status = auth_generic_server_get_user_info(gensec_security,
mem_ctx, session_info);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, (__location__ ": failed to obtain the server info "
return true;
}
-/*******************************************************************
- Handle a GSSAPI bind auth.
-*******************************************************************/
-
-static bool pipe_gssapi_auth_bind(struct pipes_struct *p,
- TALLOC_CTX *mem_ctx,
- struct dcerpc_auth *auth_info,
- DATA_BLOB *response)
-{
- NTSTATUS status;
- struct gse_context *gse_ctx = NULL;
-
- status = gssapi_server_auth_start(p,
- (auth_info->auth_level ==
- DCERPC_AUTH_LEVEL_INTEGRITY),
- (auth_info->auth_level ==
- DCERPC_AUTH_LEVEL_PRIVACY),
- true,
- &auth_info->credentials,
- response,
- &gse_ctx);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("Failed to init dcerpc gssapi server (%s)\n",
- nt_errstr(status)));
- goto err;
- }
-
- /* Make sure data is bound to the memctx, to be freed the caller */
- talloc_steal(mem_ctx, response->data);
-
- p->auth.auth_ctx = gse_ctx;
- p->auth.auth_type = DCERPC_AUTH_TYPE_KRB5;
-
- DEBUG(10, ("KRB5 auth started\n"));
-
- return true;
-
-err:
- TALLOC_FREE(gse_ctx);
- return false;
-}
-
-static NTSTATUS pipe_gssapi_verify_final(TALLOC_CTX *mem_ctx,
- struct gse_context *gse_ctx,
- struct client_address *client_id,
- struct auth_serversupplied_info **session_info)
-{
- NTSTATUS status;
- bool bret;
-
- /* Finally - if the pipe negotiated integrity (sign) or privacy (seal)
- ensure the underlying flags are also set. If not we should
- refuse the bind. */
-
- status = gssapi_server_check_flags(gse_ctx);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("Requested Security Layers not honored!\n"));
- return status;
- }
-
- status = gssapi_server_get_user_info(gse_ctx, mem_ctx,
- client_id, session_info);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, (__location__ ": failed to obtain the server info "
- "for authenticated user: %s\n", nt_errstr(status)));
- return status;
- }
-
- /*
- * We're an authenticated bind over smb, so the session key needs to
- * be set to "SystemLibraryDTC". Weird, but this is what Windows
- * does. See the RPC-SAMBA3SESSIONKEY.
- */
-
- bret = session_info_set_session_key((*session_info), generic_session_key());
- if (!bret) {
- return NT_STATUS_ACCESS_DENIED;
- }
-
- return NT_STATUS_OK;
-}
-
static NTSTATUS pipe_auth_verify_final(struct pipes_struct *p)
{
- enum spnego_mech auth_type;
- struct auth_ntlmssp_state *ntlmssp_ctx;
- struct spnego_context *spnego_ctx;
- struct gse_context *gse_ctx;
- void *mech_ctx;
- NTSTATUS status;
+ struct gensec_security *gensec_security;
switch (p->auth.auth_type) {
case DCERPC_AUTH_TYPE_NTLMSSP:
- ntlmssp_ctx = talloc_get_type_abort(p->auth.auth_ctx,
- struct auth_ntlmssp_state);
- if (!pipe_ntlmssp_verify_final(p, ntlmssp_ctx,
- p->auth.auth_level,
- p->client_id,
- &p->session_info)) {
- return NT_STATUS_ACCESS_DENIED;
- }
- break;
case DCERPC_AUTH_TYPE_KRB5:
- gse_ctx = talloc_get_type_abort(p->auth.auth_ctx,
- struct gse_context);
- status = pipe_gssapi_verify_final(p, gse_ctx,
- p->client_id,
- &p->session_info);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(1, ("gssapi bind failed with: %s",
- nt_errstr(status)));
- return status;
- }
- break;
case DCERPC_AUTH_TYPE_SPNEGO:
- spnego_ctx = talloc_get_type_abort(p->auth.auth_ctx,
- struct spnego_context);
- status = spnego_get_negotiated_mech(spnego_ctx,
- &auth_type, &mech_ctx);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("Bad SPNEGO state (%s)\n",
- nt_errstr(status)));
- return status;
- }
- switch(auth_type) {
- case SPNEGO_KRB5:
- gse_ctx = talloc_get_type_abort(mech_ctx,
- struct gse_context);
- status = pipe_gssapi_verify_final(p, gse_ctx,
- p->client_id,
- &p->session_info);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(1, ("gssapi bind failed with: %s",
- nt_errstr(status)));
- return status;
- }
- break;
- case SPNEGO_NTLMSSP:
- ntlmssp_ctx = talloc_get_type_abort(mech_ctx,
- struct auth_ntlmssp_state);
- if (!pipe_ntlmssp_verify_final(p, ntlmssp_ctx,
- p->auth.auth_level,
- p->client_id,
- &p->session_info)) {
- return NT_STATUS_ACCESS_DENIED;
- }
- break;
- default:
- DEBUG(0, (__location__ ": incorrect spnego type "
- "(%d).\n", auth_type));
+ gensec_security = talloc_get_type_abort(p->auth.auth_ctx,
+ struct gensec_security);
+ if (!pipe_auth_generic_verify_final(p, gensec_security,
+ p->auth.auth_level,
+ &p->session_info)) {
return NT_STATUS_ACCESS_DENIED;
}
break;
/* Rejection reason: abstract syntax not supported */
bind_ack_ctx.result = DCERPC_BIND_PROVIDER_REJECT;
bind_ack_ctx.reason = DCERPC_BIND_REASON_ASYNTAX;
- bind_ack_ctx.syntax = null_ndr_syntax_id;
+ bind_ack_ctx.syntax = ndr_syntax_id_null;
}
/*
switch (auth_type) {
case DCERPC_AUTH_TYPE_NTLMSSP:
- if (!pipe_ntlmssp_auth_bind(p, pkt,
- &auth_info, &auth_resp)) {
+ if (!pipe_auth_generic_bind(p, pkt,
+ &auth_info, &auth_resp)) {
goto err_exit;
}
assoc_gid = 0x7a77;
break;
case DCERPC_AUTH_TYPE_SPNEGO:
- if (!pipe_spnego_auth_bind(p, pkt,
- &auth_info, &auth_resp)) {
- goto err_exit;
- }
- break;
-
case DCERPC_AUTH_TYPE_KRB5:
- if (!pipe_gssapi_auth_bind(p, pkt,
- &auth_info, &auth_resp)) {
+ if (!pipe_auth_generic_bind(p, pkt,
+ &auth_info, &auth_resp)) {
goto err_exit;
}
break;
{
struct dcerpc_auth auth_info;
DATA_BLOB response = data_blob_null;
- struct auth_ntlmssp_state *ntlmssp_ctx;
- struct spnego_context *spnego_ctx;
- struct gse_context *gse_ctx;
+ struct gensec_security *gensec_security;
NTSTATUS status;
DEBUG(5, ("api_pipe_bind_auth3: decode request. %d\n", __LINE__));
if (pkt->auth_length == 0) {
- DEBUG(0, ("No auth field sent for bind request!\n"));
+ DEBUG(1, ("No auth field sent for bind request!\n"));
goto err;
}
if (pkt->frag_length < RPC_HEADER_LEN
+ DCERPC_AUTH_TRAILER_LENGTH
+ pkt->auth_length) {
- DEBUG(0,("api_pipe_ntlmssp_auth_process: auth_len "
+ DEBUG(1,("api_pipe_ntlmssp_auth_process: auth_len "
"%u is too large.\n",
(unsigned int)pkt->auth_length));
goto err;
&pkt->u.auth3.auth_info,
&auth_info, p->endian);
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("Failed to unmarshall dcerpc_auth.\n"));
+ DEBUG(1, ("Failed to unmarshall dcerpc_auth.\n"));
goto err;
}
*/
if (auth_info.auth_type != p->auth.auth_type) {
- DEBUG(0, ("Auth type mismatch! Client sent %d, "
+ DEBUG(1, ("Auth type mismatch! Client sent %d, "
"but auth was started as type %d!\n",
auth_info.auth_type, p->auth.auth_type));
goto err;
switch (auth_info.auth_type) {
case DCERPC_AUTH_TYPE_NTLMSSP:
- ntlmssp_ctx = talloc_get_type_abort(p->auth.auth_ctx,
- struct auth_ntlmssp_state);
- status = ntlmssp_server_step(ntlmssp_ctx,
- pkt, &auth_info.credentials,
- &response);
- break;
case DCERPC_AUTH_TYPE_KRB5:
- gse_ctx = talloc_get_type_abort(p->auth.auth_ctx,
- struct gse_context);
- status = gssapi_server_step(gse_ctx,
- pkt, &auth_info.credentials,
- &response);
- break;
case DCERPC_AUTH_TYPE_SPNEGO:
- spnego_ctx = talloc_get_type_abort(p->auth.auth_ctx,
- struct spnego_context);
- status = spnego_server_step(spnego_ctx,
- pkt, &auth_info.credentials,
- &response);
+ gensec_security = talloc_get_type_abort(p->auth.auth_ctx,
+ struct gensec_security);
+ status = auth_generic_server_step(gensec_security,
+ pkt, &auth_info.credentials,
+ &response);
break;
default:
- DEBUG(0, (__location__ ": incorrect auth type (%u).\n",
+ DEBUG(1, (__location__ ": incorrect auth type (%u).\n",
(unsigned int)auth_info.auth_type));
return false;
}
if (NT_STATUS_EQUAL(status,
NT_STATUS_MORE_PROCESSING_REQUIRED) ||
response.length) {
- DEBUG(0, (__location__ ": This was supposed to be the final "
+ DEBUG(1, (__location__ ": This was supposed to be the final "
"leg, but crypto machinery claims a response is "
"needed, aborting auth!\n"));
data_blob_free(&response);
goto err;
}
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("Auth failed (%s)\n", nt_errstr(status)));
+ DEBUG(2, ("Auth failed (%s)\n", nt_errstr(status)));
goto err;
}
/* Now verify auth was indeed successful and extract server info */
status = pipe_auth_verify_final(p);
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("Auth Verify failed (%s)\n", nt_errstr(status)));
+ DEBUG(2, ("Auth Verify failed (%s)\n", nt_errstr(status)));
goto err;
}
DATA_BLOB auth_resp = data_blob_null;
DATA_BLOB auth_blob = data_blob_null;
int pad_len = 0;
- struct auth_ntlmssp_state *ntlmssp_ctx;
- struct spnego_context *spnego_ctx;
- struct gse_context *gse_ctx;
+ struct gensec_security *gensec_security;
DEBUG(5,("api_pipe_alter_context: make response. %d\n", __LINE__));
/* Rejection reason: abstract syntax not supported */
bind_ack_ctx.result = DCERPC_BIND_PROVIDER_REJECT;
bind_ack_ctx.reason = DCERPC_BIND_REASON_ASYNTAX;
- bind_ack_ctx.syntax = null_ndr_syntax_id;
+ bind_ack_ctx.syntax = ndr_syntax_id_null;
}
/*
switch (auth_info.auth_type) {
case DCERPC_AUTH_TYPE_SPNEGO:
- spnego_ctx = talloc_get_type_abort(p->auth.auth_ctx,
- struct spnego_context);
- status = spnego_server_step(spnego_ctx,
- pkt,
- &auth_info.credentials,
- &auth_resp);
- break;
-
case DCERPC_AUTH_TYPE_KRB5:
- gse_ctx = talloc_get_type_abort(p->auth.auth_ctx,
- struct gse_context);
- status = gssapi_server_step(gse_ctx,
- pkt,
- &auth_info.credentials,
- &auth_resp);
- break;
case DCERPC_AUTH_TYPE_NTLMSSP:
- ntlmssp_ctx = talloc_get_type_abort(p->auth.auth_ctx,
- struct auth_ntlmssp_state);
- status = ntlmssp_server_step(ntlmssp_ctx,
+ gensec_security = talloc_get_type_abort(p->auth.auth_ctx,
+ struct gensec_security);
+ status = auth_generic_server_step(gensec_security,
pkt,
&auth_info.credentials,
&auth_resp);
struct ncacn_packet *pkt)
{
bool ret = False;
- bool changed_user = False;
- PIPE_RPC_FNS *pipe_fns;
-
- if (p->pipe_bound &&
- ((p->auth.auth_type == DCERPC_AUTH_TYPE_NTLMSSP) ||
- (p->auth.auth_type == DCERPC_AUTH_TYPE_KRB5) ||
- (p->auth.auth_type == DCERPC_AUTH_TYPE_SPNEGO))) {
- if(!become_authenticated_pipe_user(p->session_info)) {
- data_blob_free(&p->out_data.rdata);
- return False;
- }
- changed_user = True;
+ struct pipe_rpc_fns *pipe_fns;
+
+ if (!p->pipe_bound) {
+ DEBUG(1, ("Pipe not bound!\n"));
+ data_blob_free(&p->out_data.rdata);
+ return false;
+ }
+
+ if (!become_authenticated_pipe_user(p->session_info)) {
+ DEBUG(1, ("Failed to become pipe user!\n"));
+ data_blob_free(&p->out_data.rdata);
+ return false;
}
/* get the set of RPC functions for this context */
pkt->u.request.context_id));
}
- if (changed_user) {
- unbecome_authenticated_pipe_user();
- }
+ unbecome_authenticated_pipe_user();
return ret;
}
return False;
}
- if (p->bad_handle_fault_state) {
- DEBUG(4,("api_rpcTNP: bad handle fault return.\n"));
- p->bad_handle_fault_state = False;
- setup_fault_pdu(p, NT_STATUS(DCERPC_FAULT_CONTEXT_MISMATCH));
- return True;
- }
-
- if (p->rng_fault_state) {
- DEBUG(4, ("api_rpcTNP: rng fault return\n"));
- p->rng_fault_state = False;
- setup_fault_pdu(p, NT_STATUS(DCERPC_FAULT_OP_RNG_ERROR));
- return True;
+ if (p->fault_state) {
+ DEBUG(4,("api_rpcTNP: fault(%d) return.\n", p->fault_state));
+ setup_fault_pdu(p, NT_STATUS(p->fault_state));
+ p->fault_state = 0;
+ return true;
}
if (DEBUGLEVEL >= 50) {
data_blob_free(&p->in_data.data);
p->in_data.pdu_needed_len = 0;
p->in_data.pdu.length = 0;
- p->fault_state = True;
+ p->fault_state = DCERPC_FAULT_CANT_PERFORM;
DEBUG(10, ("Setting fault state\n"));
}