From 5a6978205edc2217006762bfe540e8f62caad74b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 14 Aug 2023 12:48:28 +0200 Subject: [PATCH] librpc/rpc: allow dcesrv_context to propose the preferred ndr syntax This allows specific services to use ndr64. Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett --- librpc/rpc/dcesrv_core.c | 16 ++++++++++++---- librpc/rpc/dcesrv_core.h | 6 ++++++ librpc/rpc/dcesrv_reply.c | 4 ++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/librpc/rpc/dcesrv_core.c b/librpc/rpc/dcesrv_core.c index ee0ac2ce7ad..00ac8e421e3 100644 --- a/librpc/rpc/dcesrv_core.c +++ b/librpc/rpc/dcesrv_core.c @@ -704,10 +704,7 @@ _PUBLIC_ NTSTATUS dcesrv_endpoint_connect(struct dcesrv_context *dce_ctx, p->default_auth_state = auth; - /* - * For now we only support NDR32. - */ - p->preferred_transfer = &ndr_transfer_syntax_ndr; + p->preferred_transfer = dce_ctx->preferred_transfer; *_p = p; return NT_STATUS_OK; @@ -1594,6 +1591,8 @@ static NTSTATUS dcesrv_check_or_create_context(struct dcesrv_call_state *call, context->context_id = ctx->context_id; context->iface = iface; context->transfer_syntax = *selected_transfer; + context->ndr64 = ndr_syntax_id_equal(&context->transfer_syntax, + &ndr_transfer_syntax_ndr64); DLIST_ADD(call->conn->contexts, context); call->context = context; talloc_set_destructor(context, dcesrv_connection_context_destructor); @@ -2034,6 +2033,10 @@ static NTSTATUS dcesrv_request(struct dcesrv_call_state *call) return dcesrv_fault(call, faultcode); } + if (call->context->ndr64) { + call->ndr_pull->flags |= LIBNDR_FLAG_NDR64; + } + /* unravel the NDR for the packet */ status = call->context->iface->ndr_pull(call, call, pull, &call->r); if (!NT_STATUS_IS_OK(status)) { @@ -2566,6 +2569,11 @@ _PUBLIC_ NTSTATUS dcesrv_init_context(TALLOC_CTX *mem_ctx, dce_ctx->broken_connections = NULL; dce_ctx->callbacks = cb; + /* + * For now we only support NDR32. + */ + dce_ctx->preferred_transfer = &ndr_transfer_syntax_ndr; + *_dce_ctx = dce_ctx; return NT_STATUS_OK; } diff --git a/librpc/rpc/dcesrv_core.h b/librpc/rpc/dcesrv_core.h index 3e23e125cbc..98f8dd97506 100644 --- a/librpc/rpc/dcesrv_core.h +++ b/librpc/rpc/dcesrv_core.h @@ -232,6 +232,7 @@ struct dcesrv_connection_context { /* the negotiated transfer syntax */ struct ndr_syntax_id transfer_syntax; + bool ndr64; }; @@ -454,6 +455,11 @@ struct dcesrv_context { struct dcesrv_connection *broken_connections; + /* + * Our preferred transfer syntax. + */ + const struct ndr_syntax_id *preferred_transfer; + struct dcesrv_context_callbacks *callbacks; }; diff --git a/librpc/rpc/dcesrv_reply.c b/librpc/rpc/dcesrv_reply.c index 5b4429956e7..bc103e51171 100644 --- a/librpc/rpc/dcesrv_reply.c +++ b/librpc/rpc/dcesrv_reply.c @@ -168,6 +168,10 @@ _PUBLIC_ NTSTATUS dcesrv_reply(struct dcesrv_call_state *call) push->flags |= LIBNDR_FLAG_BIGENDIAN; } + if (context->ndr64) { + push->flags |= LIBNDR_FLAG_NDR64; + } + status = context->iface->ndr_push(call, call, push, call->r); if (!NT_STATUS_IS_OK(status)) { return dcesrv_fault(call, call->fault_code);