/* client functions auto-generated by pidl */

#include "includes.h"
#include <tevent.h>
#include "lib/util/tevent_ntstatus.h"
#include "librpc/gen_ndr/ndr_ntlmssp.h"
#include "librpc/gen_ndr/ndr_ntlmssp_c.h"

/* ntlmssp - client functions generated by pidl */

struct dcerpc_decode_NEGOTIATE_MESSAGE_r_state {
	TALLOC_CTX *out_mem_ctx;
};

static void dcerpc_decode_NEGOTIATE_MESSAGE_r_done(struct tevent_req *subreq);

struct tevent_req *dcerpc_decode_NEGOTIATE_MESSAGE_r_send(TALLOC_CTX *mem_ctx,
	struct tevent_context *ev,
	struct dcerpc_binding_handle *h,
	struct decode_NEGOTIATE_MESSAGE *r)
{
	struct tevent_req *req;
	struct dcerpc_decode_NEGOTIATE_MESSAGE_r_state *state;
	struct tevent_req *subreq;

	req = tevent_req_create(mem_ctx, &state,
				struct dcerpc_decode_NEGOTIATE_MESSAGE_r_state);
	if (req == NULL) {
		return NULL;
	}

	state->out_mem_ctx = NULL;

	subreq = dcerpc_binding_handle_call_send(state, ev, h,
			NULL, &ndr_table_ntlmssp,
			NDR_DECODE_NEGOTIATE_MESSAGE, state, r);
	if (tevent_req_nomem(subreq, req)) {
		return tevent_req_post(req, ev);
	}
	tevent_req_set_callback(subreq, dcerpc_decode_NEGOTIATE_MESSAGE_r_done, req);

	return req;
}

static void dcerpc_decode_NEGOTIATE_MESSAGE_r_done(struct tevent_req *subreq)
{
	struct tevent_req *req =
		tevent_req_callback_data(subreq,
		struct tevent_req);
	NTSTATUS status;

	status = dcerpc_binding_handle_call_recv(subreq);
	if (!NT_STATUS_IS_OK(status)) {
		tevent_req_nterror(req, status);
		return;
	}

	tevent_req_done(req);
}

NTSTATUS dcerpc_decode_NEGOTIATE_MESSAGE_r_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx)
{
	struct dcerpc_decode_NEGOTIATE_MESSAGE_r_state *state =
		tevent_req_data(req,
		struct dcerpc_decode_NEGOTIATE_MESSAGE_r_state);
	NTSTATUS status;

	if (tevent_req_is_nterror(req, &status)) {
		tevent_req_received(req);
		return status;
	}

	talloc_steal(mem_ctx, state->out_mem_ctx);

	tevent_req_received(req);
	return NT_STATUS_OK;
}

NTSTATUS dcerpc_decode_NEGOTIATE_MESSAGE_r(struct dcerpc_binding_handle *h, TALLOC_CTX *mem_ctx, struct decode_NEGOTIATE_MESSAGE *r)
{
	NTSTATUS status;

	status = dcerpc_binding_handle_call(h,
			NULL, &ndr_table_ntlmssp,
			NDR_DECODE_NEGOTIATE_MESSAGE, mem_ctx, r);

	return status;
}

struct dcerpc_decode_NEGOTIATE_MESSAGE_state {
	struct decode_NEGOTIATE_MESSAGE orig;
	struct decode_NEGOTIATE_MESSAGE tmp;
	TALLOC_CTX *out_mem_ctx;
};

static void dcerpc_decode_NEGOTIATE_MESSAGE_done(struct tevent_req *subreq);

struct tevent_req *dcerpc_decode_NEGOTIATE_MESSAGE_send(TALLOC_CTX *mem_ctx,
							struct tevent_context *ev,
							struct dcerpc_binding_handle *h,
							struct NEGOTIATE_MESSAGE _negotiate /* [in]  */)
{
	struct tevent_req *req;
	struct dcerpc_decode_NEGOTIATE_MESSAGE_state *state;
	struct tevent_req *subreq;

	req = tevent_req_create(mem_ctx, &state,
				struct dcerpc_decode_NEGOTIATE_MESSAGE_state);
	if (req == NULL) {
		return NULL;
	}
	state->out_mem_ctx = NULL;

	/* In parameters */
	state->orig.in.negotiate = _negotiate;

	/* Out parameters */

	/* make a temporary copy, that we pass to the dispatch function */
	state->tmp = state->orig;

	subreq = dcerpc_decode_NEGOTIATE_MESSAGE_r_send(state, ev, h, &state->tmp);
	if (tevent_req_nomem(subreq, req)) {
		return tevent_req_post(req, ev);
	}
	tevent_req_set_callback(subreq, dcerpc_decode_NEGOTIATE_MESSAGE_done, req);
	return req;
}

static void dcerpc_decode_NEGOTIATE_MESSAGE_done(struct tevent_req *subreq)
{
	struct tevent_req *req = tevent_req_callback_data(
		subreq, struct tevent_req);
	struct dcerpc_decode_NEGOTIATE_MESSAGE_state *state = tevent_req_data(
		req, struct dcerpc_decode_NEGOTIATE_MESSAGE_state);
	NTSTATUS status;
	TALLOC_CTX *mem_ctx;

	if (state->out_mem_ctx) {
		mem_ctx = state->out_mem_ctx;
	} else {
		mem_ctx = state;
	}

	status = dcerpc_decode_NEGOTIATE_MESSAGE_r_recv(subreq, mem_ctx);
	TALLOC_FREE(subreq);
	if (!NT_STATUS_IS_OK(status)) {
		tevent_req_nterror(req, status);
		return;
	}

	/* Copy out parameters */

	/* Reset temporary structure */
	ZERO_STRUCT(state->tmp);

	tevent_req_done(req);
}

NTSTATUS dcerpc_decode_NEGOTIATE_MESSAGE_recv(struct tevent_req *req,
					      TALLOC_CTX *mem_ctx)
{
	struct dcerpc_decode_NEGOTIATE_MESSAGE_state *state = tevent_req_data(
		req, struct dcerpc_decode_NEGOTIATE_MESSAGE_state);
	NTSTATUS status;

	if (tevent_req_is_nterror(req, &status)) {
		tevent_req_received(req);
		return status;
	}

	/* Steal possible out parameters to the callers context */
	talloc_steal(mem_ctx, state->out_mem_ctx);

	tevent_req_received(req);
	return NT_STATUS_OK;
}

NTSTATUS dcerpc_decode_NEGOTIATE_MESSAGE(struct dcerpc_binding_handle *h,
					 TALLOC_CTX *mem_ctx,
					 struct NEGOTIATE_MESSAGE _negotiate /* [in]  */)
{
	struct decode_NEGOTIATE_MESSAGE r;
	NTSTATUS status;

	/* In parameters */
	r.in.negotiate = _negotiate;

	status = dcerpc_decode_NEGOTIATE_MESSAGE_r(h, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	/* Return variables */

	/* Return result */

	return NT_STATUS_OK;
}

struct dcerpc_decode_CHALLENGE_MESSAGE_r_state {
	TALLOC_CTX *out_mem_ctx;
};

static void dcerpc_decode_CHALLENGE_MESSAGE_r_done(struct tevent_req *subreq);

struct tevent_req *dcerpc_decode_CHALLENGE_MESSAGE_r_send(TALLOC_CTX *mem_ctx,
	struct tevent_context *ev,
	struct dcerpc_binding_handle *h,
	struct decode_CHALLENGE_MESSAGE *r)
{
	struct tevent_req *req;
	struct dcerpc_decode_CHALLENGE_MESSAGE_r_state *state;
	struct tevent_req *subreq;

	req = tevent_req_create(mem_ctx, &state,
				struct dcerpc_decode_CHALLENGE_MESSAGE_r_state);
	if (req == NULL) {
		return NULL;
	}

	state->out_mem_ctx = NULL;

	subreq = dcerpc_binding_handle_call_send(state, ev, h,
			NULL, &ndr_table_ntlmssp,
			NDR_DECODE_CHALLENGE_MESSAGE, state, r);
	if (tevent_req_nomem(subreq, req)) {
		return tevent_req_post(req, ev);
	}
	tevent_req_set_callback(subreq, dcerpc_decode_CHALLENGE_MESSAGE_r_done, req);

	return req;
}

static void dcerpc_decode_CHALLENGE_MESSAGE_r_done(struct tevent_req *subreq)
{
	struct tevent_req *req =
		tevent_req_callback_data(subreq,
		struct tevent_req);
	NTSTATUS status;

	status = dcerpc_binding_handle_call_recv(subreq);
	if (!NT_STATUS_IS_OK(status)) {
		tevent_req_nterror(req, status);
		return;
	}

	tevent_req_done(req);
}

NTSTATUS dcerpc_decode_CHALLENGE_MESSAGE_r_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx)
{
	struct dcerpc_decode_CHALLENGE_MESSAGE_r_state *state =
		tevent_req_data(req,
		struct dcerpc_decode_CHALLENGE_MESSAGE_r_state);
	NTSTATUS status;

	if (tevent_req_is_nterror(req, &status)) {
		tevent_req_received(req);
		return status;
	}

	talloc_steal(mem_ctx, state->out_mem_ctx);

	tevent_req_received(req);
	return NT_STATUS_OK;
}

NTSTATUS dcerpc_decode_CHALLENGE_MESSAGE_r(struct dcerpc_binding_handle *h, TALLOC_CTX *mem_ctx, struct decode_CHALLENGE_MESSAGE *r)
{
	NTSTATUS status;

	status = dcerpc_binding_handle_call(h,
			NULL, &ndr_table_ntlmssp,
			NDR_DECODE_CHALLENGE_MESSAGE, mem_ctx, r);

	return status;
}

struct dcerpc_decode_CHALLENGE_MESSAGE_state {
	struct decode_CHALLENGE_MESSAGE orig;
	struct decode_CHALLENGE_MESSAGE tmp;
	TALLOC_CTX *out_mem_ctx;
};

static void dcerpc_decode_CHALLENGE_MESSAGE_done(struct tevent_req *subreq);

struct tevent_req *dcerpc_decode_CHALLENGE_MESSAGE_send(TALLOC_CTX *mem_ctx,
							struct tevent_context *ev,
							struct dcerpc_binding_handle *h,
							struct CHALLENGE_MESSAGE _challenge /* [in]  */)
{
	struct tevent_req *req;
	struct dcerpc_decode_CHALLENGE_MESSAGE_state *state;
	struct tevent_req *subreq;

	req = tevent_req_create(mem_ctx, &state,
				struct dcerpc_decode_CHALLENGE_MESSAGE_state);
	if (req == NULL) {
		return NULL;
	}
	state->out_mem_ctx = NULL;

	/* In parameters */
	state->orig.in.challenge = _challenge;

	/* Out parameters */

	/* make a temporary copy, that we pass to the dispatch function */
	state->tmp = state->orig;

	subreq = dcerpc_decode_CHALLENGE_MESSAGE_r_send(state, ev, h, &state->tmp);
	if (tevent_req_nomem(subreq, req)) {
		return tevent_req_post(req, ev);
	}
	tevent_req_set_callback(subreq, dcerpc_decode_CHALLENGE_MESSAGE_done, req);
	return req;
}

static void dcerpc_decode_CHALLENGE_MESSAGE_done(struct tevent_req *subreq)
{
	struct tevent_req *req = tevent_req_callback_data(
		subreq, struct tevent_req);
	struct dcerpc_decode_CHALLENGE_MESSAGE_state *state = tevent_req_data(
		req, struct dcerpc_decode_CHALLENGE_MESSAGE_state);
	NTSTATUS status;
	TALLOC_CTX *mem_ctx;

	if (state->out_mem_ctx) {
		mem_ctx = state->out_mem_ctx;
	} else {
		mem_ctx = state;
	}

	status = dcerpc_decode_CHALLENGE_MESSAGE_r_recv(subreq, mem_ctx);
	TALLOC_FREE(subreq);
	if (!NT_STATUS_IS_OK(status)) {
		tevent_req_nterror(req, status);
		return;
	}

	/* Copy out parameters */

	/* Reset temporary structure */
	ZERO_STRUCT(state->tmp);

	tevent_req_done(req);
}

NTSTATUS dcerpc_decode_CHALLENGE_MESSAGE_recv(struct tevent_req *req,
					      TALLOC_CTX *mem_ctx)
{
	struct dcerpc_decode_CHALLENGE_MESSAGE_state *state = tevent_req_data(
		req, struct dcerpc_decode_CHALLENGE_MESSAGE_state);
	NTSTATUS status;

	if (tevent_req_is_nterror(req, &status)) {
		tevent_req_received(req);
		return status;
	}

	/* Steal possible out parameters to the callers context */
	talloc_steal(mem_ctx, state->out_mem_ctx);

	tevent_req_received(req);
	return NT_STATUS_OK;
}

NTSTATUS dcerpc_decode_CHALLENGE_MESSAGE(struct dcerpc_binding_handle *h,
					 TALLOC_CTX *mem_ctx,
					 struct CHALLENGE_MESSAGE _challenge /* [in]  */)
{
	struct decode_CHALLENGE_MESSAGE r;
	NTSTATUS status;

	/* In parameters */
	r.in.challenge = _challenge;

	status = dcerpc_decode_CHALLENGE_MESSAGE_r(h, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	/* Return variables */

	/* Return result */

	return NT_STATUS_OK;
}

struct dcerpc_decode_AUTHENTICATE_MESSAGE_r_state {
	TALLOC_CTX *out_mem_ctx;
};

static void dcerpc_decode_AUTHENTICATE_MESSAGE_r_done(struct tevent_req *subreq);

struct tevent_req *dcerpc_decode_AUTHENTICATE_MESSAGE_r_send(TALLOC_CTX *mem_ctx,
	struct tevent_context *ev,
	struct dcerpc_binding_handle *h,
	struct decode_AUTHENTICATE_MESSAGE *r)
{
	struct tevent_req *req;
	struct dcerpc_decode_AUTHENTICATE_MESSAGE_r_state *state;
	struct tevent_req *subreq;

	req = tevent_req_create(mem_ctx, &state,
				struct dcerpc_decode_AUTHENTICATE_MESSAGE_r_state);
	if (req == NULL) {
		return NULL;
	}

	state->out_mem_ctx = NULL;

	subreq = dcerpc_binding_handle_call_send(state, ev, h,
			NULL, &ndr_table_ntlmssp,
			NDR_DECODE_AUTHENTICATE_MESSAGE, state, r);
	if (tevent_req_nomem(subreq, req)) {
		return tevent_req_post(req, ev);
	}
	tevent_req_set_callback(subreq, dcerpc_decode_AUTHENTICATE_MESSAGE_r_done, req);

	return req;
}

static void dcerpc_decode_AUTHENTICATE_MESSAGE_r_done(struct tevent_req *subreq)
{
	struct tevent_req *req =
		tevent_req_callback_data(subreq,
		struct tevent_req);
	NTSTATUS status;

	status = dcerpc_binding_handle_call_recv(subreq);
	if (!NT_STATUS_IS_OK(status)) {
		tevent_req_nterror(req, status);
		return;
	}

	tevent_req_done(req);
}

NTSTATUS dcerpc_decode_AUTHENTICATE_MESSAGE_r_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx)
{
	struct dcerpc_decode_AUTHENTICATE_MESSAGE_r_state *state =
		tevent_req_data(req,
		struct dcerpc_decode_AUTHENTICATE_MESSAGE_r_state);
	NTSTATUS status;

	if (tevent_req_is_nterror(req, &status)) {
		tevent_req_received(req);
		return status;
	}

	talloc_steal(mem_ctx, state->out_mem_ctx);

	tevent_req_received(req);
	return NT_STATUS_OK;
}

NTSTATUS dcerpc_decode_AUTHENTICATE_MESSAGE_r(struct dcerpc_binding_handle *h, TALLOC_CTX *mem_ctx, struct decode_AUTHENTICATE_MESSAGE *r)
{
	NTSTATUS status;

	status = dcerpc_binding_handle_call(h,
			NULL, &ndr_table_ntlmssp,
			NDR_DECODE_AUTHENTICATE_MESSAGE, mem_ctx, r);

	return status;
}

struct dcerpc_decode_AUTHENTICATE_MESSAGE_state {
	struct decode_AUTHENTICATE_MESSAGE orig;
	struct decode_AUTHENTICATE_MESSAGE tmp;
	TALLOC_CTX *out_mem_ctx;
};

static void dcerpc_decode_AUTHENTICATE_MESSAGE_done(struct tevent_req *subreq);

struct tevent_req *dcerpc_decode_AUTHENTICATE_MESSAGE_send(TALLOC_CTX *mem_ctx,
							   struct tevent_context *ev,
							   struct dcerpc_binding_handle *h,
							   struct AUTHENTICATE_MESSAGE _authenticate /* [in]  */)
{
	struct tevent_req *req;
	struct dcerpc_decode_AUTHENTICATE_MESSAGE_state *state;
	struct tevent_req *subreq;

	req = tevent_req_create(mem_ctx, &state,
				struct dcerpc_decode_AUTHENTICATE_MESSAGE_state);
	if (req == NULL) {
		return NULL;
	}
	state->out_mem_ctx = NULL;

	/* In parameters */
	state->orig.in.authenticate = _authenticate;

	/* Out parameters */

	/* make a temporary copy, that we pass to the dispatch function */
	state->tmp = state->orig;

	subreq = dcerpc_decode_AUTHENTICATE_MESSAGE_r_send(state, ev, h, &state->tmp);
	if (tevent_req_nomem(subreq, req)) {
		return tevent_req_post(req, ev);
	}
	tevent_req_set_callback(subreq, dcerpc_decode_AUTHENTICATE_MESSAGE_done, req);
	return req;
}

static void dcerpc_decode_AUTHENTICATE_MESSAGE_done(struct tevent_req *subreq)
{
	struct tevent_req *req = tevent_req_callback_data(
		subreq, struct tevent_req);
	struct dcerpc_decode_AUTHENTICATE_MESSAGE_state *state = tevent_req_data(
		req, struct dcerpc_decode_AUTHENTICATE_MESSAGE_state);
	NTSTATUS status;
	TALLOC_CTX *mem_ctx;

	if (state->out_mem_ctx) {
		mem_ctx = state->out_mem_ctx;
	} else {
		mem_ctx = state;
	}

	status = dcerpc_decode_AUTHENTICATE_MESSAGE_r_recv(subreq, mem_ctx);
	TALLOC_FREE(subreq);
	if (!NT_STATUS_IS_OK(status)) {
		tevent_req_nterror(req, status);
		return;
	}

	/* Copy out parameters */

	/* Reset temporary structure */
	ZERO_STRUCT(state->tmp);

	tevent_req_done(req);
}

NTSTATUS dcerpc_decode_AUTHENTICATE_MESSAGE_recv(struct tevent_req *req,
						 TALLOC_CTX *mem_ctx)
{
	struct dcerpc_decode_AUTHENTICATE_MESSAGE_state *state = tevent_req_data(
		req, struct dcerpc_decode_AUTHENTICATE_MESSAGE_state);
	NTSTATUS status;

	if (tevent_req_is_nterror(req, &status)) {
		tevent_req_received(req);
		return status;
	}

	/* Steal possible out parameters to the callers context */
	talloc_steal(mem_ctx, state->out_mem_ctx);

	tevent_req_received(req);
	return NT_STATUS_OK;
}

NTSTATUS dcerpc_decode_AUTHENTICATE_MESSAGE(struct dcerpc_binding_handle *h,
					    TALLOC_CTX *mem_ctx,
					    struct AUTHENTICATE_MESSAGE _authenticate /* [in]  */)
{
	struct decode_AUTHENTICATE_MESSAGE r;
	NTSTATUS status;

	/* In parameters */
	r.in.authenticate = _authenticate;

	status = dcerpc_decode_AUTHENTICATE_MESSAGE_r(h, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	/* Return variables */

	/* Return result */

	return NT_STATUS_OK;
}

struct dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r_state {
	TALLOC_CTX *out_mem_ctx;
};

static void dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r_done(struct tevent_req *subreq);

struct tevent_req *dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r_send(TALLOC_CTX *mem_ctx,
	struct tevent_context *ev,
	struct dcerpc_binding_handle *h,
	struct decode_NTLMv2_CLIENT_CHALLENGE *r)
{
	struct tevent_req *req;
	struct dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r_state *state;
	struct tevent_req *subreq;

	req = tevent_req_create(mem_ctx, &state,
				struct dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r_state);
	if (req == NULL) {
		return NULL;
	}

	state->out_mem_ctx = NULL;

	subreq = dcerpc_binding_handle_call_send(state, ev, h,
			NULL, &ndr_table_ntlmssp,
			NDR_DECODE_NTLMV2_CLIENT_CHALLENGE, state, r);
	if (tevent_req_nomem(subreq, req)) {
		return tevent_req_post(req, ev);
	}
	tevent_req_set_callback(subreq, dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r_done, req);

	return req;
}

static void dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r_done(struct tevent_req *subreq)
{
	struct tevent_req *req =
		tevent_req_callback_data(subreq,
		struct tevent_req);
	NTSTATUS status;

	status = dcerpc_binding_handle_call_recv(subreq);
	if (!NT_STATUS_IS_OK(status)) {
		tevent_req_nterror(req, status);
		return;
	}

	tevent_req_done(req);
}

NTSTATUS dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx)
{
	struct dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r_state *state =
		tevent_req_data(req,
		struct dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r_state);
	NTSTATUS status;

	if (tevent_req_is_nterror(req, &status)) {
		tevent_req_received(req);
		return status;
	}

	talloc_steal(mem_ctx, state->out_mem_ctx);

	tevent_req_received(req);
	return NT_STATUS_OK;
}

NTSTATUS dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r(struct dcerpc_binding_handle *h, TALLOC_CTX *mem_ctx, struct decode_NTLMv2_CLIENT_CHALLENGE *r)
{
	NTSTATUS status;

	status = dcerpc_binding_handle_call(h,
			NULL, &ndr_table_ntlmssp,
			NDR_DECODE_NTLMV2_CLIENT_CHALLENGE, mem_ctx, r);

	return status;
}

struct dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_state {
	struct decode_NTLMv2_CLIENT_CHALLENGE orig;
	struct decode_NTLMv2_CLIENT_CHALLENGE tmp;
	TALLOC_CTX *out_mem_ctx;
};

static void dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_done(struct tevent_req *subreq);

struct tevent_req *dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_send(TALLOC_CTX *mem_ctx,
							      struct tevent_context *ev,
							      struct dcerpc_binding_handle *h,
							      struct NTLMv2_CLIENT_CHALLENGE _challenge /* [in]  */)
{
	struct tevent_req *req;
	struct dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_state *state;
	struct tevent_req *subreq;

	req = tevent_req_create(mem_ctx, &state,
				struct dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_state);
	if (req == NULL) {
		return NULL;
	}
	state->out_mem_ctx = NULL;

	/* In parameters */
	state->orig.in.challenge = _challenge;

	/* Out parameters */

	/* make a temporary copy, that we pass to the dispatch function */
	state->tmp = state->orig;

	subreq = dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r_send(state, ev, h, &state->tmp);
	if (tevent_req_nomem(subreq, req)) {
		return tevent_req_post(req, ev);
	}
	tevent_req_set_callback(subreq, dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_done, req);
	return req;
}

static void dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_done(struct tevent_req *subreq)
{
	struct tevent_req *req = tevent_req_callback_data(
		subreq, struct tevent_req);
	struct dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_state *state = tevent_req_data(
		req, struct dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_state);
	NTSTATUS status;
	TALLOC_CTX *mem_ctx;

	if (state->out_mem_ctx) {
		mem_ctx = state->out_mem_ctx;
	} else {
		mem_ctx = state;
	}

	status = dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r_recv(subreq, mem_ctx);
	TALLOC_FREE(subreq);
	if (!NT_STATUS_IS_OK(status)) {
		tevent_req_nterror(req, status);
		return;
	}

	/* Copy out parameters */

	/* Reset temporary structure */
	ZERO_STRUCT(state->tmp);

	tevent_req_done(req);
}

NTSTATUS dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_recv(struct tevent_req *req,
						    TALLOC_CTX *mem_ctx)
{
	struct dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_state *state = tevent_req_data(
		req, struct dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_state);
	NTSTATUS status;

	if (tevent_req_is_nterror(req, &status)) {
		tevent_req_received(req);
		return status;
	}

	/* Steal possible out parameters to the callers context */
	talloc_steal(mem_ctx, state->out_mem_ctx);

	tevent_req_received(req);
	return NT_STATUS_OK;
}

NTSTATUS dcerpc_decode_NTLMv2_CLIENT_CHALLENGE(struct dcerpc_binding_handle *h,
					       TALLOC_CTX *mem_ctx,
					       struct NTLMv2_CLIENT_CHALLENGE _challenge /* [in]  */)
{
	struct decode_NTLMv2_CLIENT_CHALLENGE r;
	NTSTATUS status;

	/* In parameters */
	r.in.challenge = _challenge;

	status = dcerpc_decode_NTLMv2_CLIENT_CHALLENGE_r(h, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	/* Return variables */

	/* Return result */

	return NT_STATUS_OK;
}

struct dcerpc_decode_NTLMv2_RESPONSE_r_state {
	TALLOC_CTX *out_mem_ctx;
};

static void dcerpc_decode_NTLMv2_RESPONSE_r_done(struct tevent_req *subreq);

struct tevent_req *dcerpc_decode_NTLMv2_RESPONSE_r_send(TALLOC_CTX *mem_ctx,
	struct tevent_context *ev,
	struct dcerpc_binding_handle *h,
	struct decode_NTLMv2_RESPONSE *r)
{
	struct tevent_req *req;
	struct dcerpc_decode_NTLMv2_RESPONSE_r_state *state;
	struct tevent_req *subreq;

	req = tevent_req_create(mem_ctx, &state,
				struct dcerpc_decode_NTLMv2_RESPONSE_r_state);
	if (req == NULL) {
		return NULL;
	}

	state->out_mem_ctx = NULL;

	subreq = dcerpc_binding_handle_call_send(state, ev, h,
			NULL, &ndr_table_ntlmssp,
			NDR_DECODE_NTLMV2_RESPONSE, state, r);
	if (tevent_req_nomem(subreq, req)) {
		return tevent_req_post(req, ev);
	}
	tevent_req_set_callback(subreq, dcerpc_decode_NTLMv2_RESPONSE_r_done, req);

	return req;
}

static void dcerpc_decode_NTLMv2_RESPONSE_r_done(struct tevent_req *subreq)
{
	struct tevent_req *req =
		tevent_req_callback_data(subreq,
		struct tevent_req);
	NTSTATUS status;

	status = dcerpc_binding_handle_call_recv(subreq);
	if (!NT_STATUS_IS_OK(status)) {
		tevent_req_nterror(req, status);
		return;
	}

	tevent_req_done(req);
}

NTSTATUS dcerpc_decode_NTLMv2_RESPONSE_r_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx)
{
	struct dcerpc_decode_NTLMv2_RESPONSE_r_state *state =
		tevent_req_data(req,
		struct dcerpc_decode_NTLMv2_RESPONSE_r_state);
	NTSTATUS status;

	if (tevent_req_is_nterror(req, &status)) {
		tevent_req_received(req);
		return status;
	}

	talloc_steal(mem_ctx, state->out_mem_ctx);

	tevent_req_received(req);
	return NT_STATUS_OK;
}

NTSTATUS dcerpc_decode_NTLMv2_RESPONSE_r(struct dcerpc_binding_handle *h, TALLOC_CTX *mem_ctx, struct decode_NTLMv2_RESPONSE *r)
{
	NTSTATUS status;

	status = dcerpc_binding_handle_call(h,
			NULL, &ndr_table_ntlmssp,
			NDR_DECODE_NTLMV2_RESPONSE, mem_ctx, r);

	return status;
}

struct dcerpc_decode_NTLMv2_RESPONSE_state {
	struct decode_NTLMv2_RESPONSE orig;
	struct decode_NTLMv2_RESPONSE tmp;
	TALLOC_CTX *out_mem_ctx;
};

static void dcerpc_decode_NTLMv2_RESPONSE_done(struct tevent_req *subreq);

struct tevent_req *dcerpc_decode_NTLMv2_RESPONSE_send(TALLOC_CTX *mem_ctx,
						      struct tevent_context *ev,
						      struct dcerpc_binding_handle *h,
						      struct NTLMv2_RESPONSE _response /* [in]  */)
{
	struct tevent_req *req;
	struct dcerpc_decode_NTLMv2_RESPONSE_state *state;
	struct tevent_req *subreq;

	req = tevent_req_create(mem_ctx, &state,
				struct dcerpc_decode_NTLMv2_RESPONSE_state);
	if (req == NULL) {
		return NULL;
	}
	state->out_mem_ctx = NULL;

	/* In parameters */
	state->orig.in.response = _response;

	/* Out parameters */

	/* make a temporary copy, that we pass to the dispatch function */
	state->tmp = state->orig;

	subreq = dcerpc_decode_NTLMv2_RESPONSE_r_send(state, ev, h, &state->tmp);
	if (tevent_req_nomem(subreq, req)) {
		return tevent_req_post(req, ev);
	}
	tevent_req_set_callback(subreq, dcerpc_decode_NTLMv2_RESPONSE_done, req);
	return req;
}

static void dcerpc_decode_NTLMv2_RESPONSE_done(struct tevent_req *subreq)
{
	struct tevent_req *req = tevent_req_callback_data(
		subreq, struct tevent_req);
	struct dcerpc_decode_NTLMv2_RESPONSE_state *state = tevent_req_data(
		req, struct dcerpc_decode_NTLMv2_RESPONSE_state);
	NTSTATUS status;
	TALLOC_CTX *mem_ctx;

	if (state->out_mem_ctx) {
		mem_ctx = state->out_mem_ctx;
	} else {
		mem_ctx = state;
	}

	status = dcerpc_decode_NTLMv2_RESPONSE_r_recv(subreq, mem_ctx);
	TALLOC_FREE(subreq);
	if (!NT_STATUS_IS_OK(status)) {
		tevent_req_nterror(req, status);
		return;
	}

	/* Copy out parameters */

	/* Reset temporary structure */
	ZERO_STRUCT(state->tmp);

	tevent_req_done(req);
}

NTSTATUS dcerpc_decode_NTLMv2_RESPONSE_recv(struct tevent_req *req,
					    TALLOC_CTX *mem_ctx)
{
	struct dcerpc_decode_NTLMv2_RESPONSE_state *state = tevent_req_data(
		req, struct dcerpc_decode_NTLMv2_RESPONSE_state);
	NTSTATUS status;

	if (tevent_req_is_nterror(req, &status)) {
		tevent_req_received(req);
		return status;
	}

	/* Steal possible out parameters to the callers context */
	talloc_steal(mem_ctx, state->out_mem_ctx);

	tevent_req_received(req);
	return NT_STATUS_OK;
}

NTSTATUS dcerpc_decode_NTLMv2_RESPONSE(struct dcerpc_binding_handle *h,
				       TALLOC_CTX *mem_ctx,
				       struct NTLMv2_RESPONSE _response /* [in]  */)
{
	struct decode_NTLMv2_RESPONSE r;
	NTSTATUS status;

	/* In parameters */
	r.in.response = _response;

	status = dcerpc_decode_NTLMv2_RESPONSE_r(h, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	/* Return variables */

	/* Return result */

	return NT_STATUS_OK;
}

