summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2004-12-07 09:26:00 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:06:25 -0500
commit9b50dba87e7c668aac4aa7ba7b72ed20a50a95bc (patch)
treedb2f7dfda733acd364cd4c83934d06dbd1c16c63
parentcdeadf87ac767b8b60f08f62dc8c5efb4f4b609b (diff)
downloadsamba-9b50dba87e7c668aac4aa7ba7b72ed20a50a95bc.tar.gz
samba-9b50dba87e7c668aac4aa7ba7b72ed20a50a95bc.tar.bz2
samba-9b50dba87e7c668aac4aa7ba7b72ed20a50a95bc.zip
r4086: - make dcerpc_ndr_request_table_send() the default and rename it to just
dcerpc_ndr_request_send() - this allows us to call dcerpc_log_packet() when we receive a packet we can't parse correctly metze (This used to be commit a7a6cea112a180a28188997ca99f30d8dd286bb8)
-rw-r--r--source4/build/pidl/client.pm2
-rw-r--r--source4/build/pidl/proxy.pm2
-rw-r--r--source4/librpc/rpc/dcerpc.c72
-rw-r--r--source4/librpc/rpc/dcerpc.h7
-rw-r--r--source4/rpc_server/remote/dcesrv_remote.c38
5 files changed, 56 insertions, 65 deletions
diff --git a/source4/build/pidl/client.pm b/source4/build/pidl/client.pm
index 43808ce3fb..c16662e3ac 100644
--- a/source4/build/pidl/client.pm
+++ b/source4/build/pidl/client.pm
@@ -25,7 +25,7 @@ struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ct
NDR_PRINT_IN_DEBUG($name, r);
}
- return dcerpc_ndr_request_table_send(p, NULL, &dcerpc_table_$interface->{NAME}, DCERPC_$uname, mem_ctx, r);
+ return dcerpc_ndr_request_send(p, NULL, &dcerpc_table_$interface->{NAME}, DCERPC_$uname, mem_ctx, r);
}
NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)
diff --git a/source4/build/pidl/proxy.pm b/source4/build/pidl/proxy.pm
index bf3990da47..7d37c04471 100644
--- a/source4/build/pidl/proxy.pm
+++ b/source4/build/pidl/proxy.pm
@@ -105,7 +105,7 @@ static struct rpc_request *dcom_proxy_$interface->{NAME}_$name\_send(struct dcom
NDR_PRINT_IN_DEBUG($name, r);
}
- return dcerpc_ndr_request_table_send(p, &d->ipid, &dcerpc_table_$interface->{NAME}, DCERPC_$uname, mem_ctx, r);
+ return dcerpc_ndr_request_send(p, &d->ipid, &dcerpc_table_$interface->{NAME}, DCERPC_$uname, mem_ctx, r);
}
static NTSTATUS dcom_proxy_$interface->{NAME}_$name(struct dcom_interface_p *d, TALLOC_CTX *mem_ctx, struct $name *r)
diff --git a/source4/librpc/rpc/dcerpc.c b/source4/librpc/rpc/dcerpc.c
index 2ff3d23335..3cd069c794 100644
--- a/source4/librpc/rpc/dcerpc.c
+++ b/source4/librpc/rpc/dcerpc.c
@@ -1156,38 +1156,21 @@ static NTSTATUS dcerpc_ndr_validate_out(struct dcerpc_pipe *p,
/*
send a rpc request given a dcerpc_call structure
*/
-struct rpc_request *dcerpc_ndr_request_table_send(struct dcerpc_pipe *p,
+struct rpc_request *dcerpc_ndr_request_send(struct dcerpc_pipe *p,
const struct GUID *object,
const struct dcerpc_interface_table *table,
uint32_t opnum,
TALLOC_CTX *mem_ctx,
void *r)
{
- const struct dcerpc_interface_call *call = &table->calls[opnum];
-
- return dcerpc_ndr_request_send(p, object, opnum, mem_ctx, call->ndr_push, call->ndr_pull, r, call->struct_size);
-}
-
-
-/*
- send a rpc request with a given set of ndr helper functions
-
- call dcerpc_ndr_request_recv() to receive the answer
-*/
-struct rpc_request *dcerpc_ndr_request_send(struct dcerpc_pipe *p,
- const struct GUID *object,
- uint32_t opnum,
- TALLOC_CTX *mem_ctx,
- NTSTATUS (*ndr_push)(struct ndr_push *, int, void *),
- NTSTATUS (*ndr_pull)(struct ndr_pull *, int, void *),
- void *struct_ptr,
- size_t struct_size)
-{
+ const struct dcerpc_interface_call *call;
struct ndr_push *push;
NTSTATUS status;
DATA_BLOB request;
struct rpc_request *req;
+ call = &table->calls[opnum];
+
/* setup for a ndr_push_* call */
push = ndr_push_init();
if (!push) {
@@ -1199,7 +1182,7 @@ struct rpc_request *dcerpc_ndr_request_send(struct dcerpc_pipe *p,
}
/* push the structure into a blob */
- status = ndr_push(push, NDR_IN, struct_ptr);
+ status = call->ndr_push(push, NDR_IN, r);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(2,("Unable to ndr_push structure in dcerpc_ndr_request_send - %s\n",
nt_errstr(status)));
@@ -1211,8 +1194,8 @@ struct rpc_request *dcerpc_ndr_request_send(struct dcerpc_pipe *p,
request = ndr_push_blob(push);
if (p->flags & DCERPC_DEBUG_VALIDATE_IN) {
- status = dcerpc_ndr_validate_in(p, mem_ctx, request, struct_size,
- ndr_push, ndr_pull);
+ status = dcerpc_ndr_validate_in(p, mem_ctx, request, call->struct_size,
+ call->ndr_push, call->ndr_pull);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(2,("Validation failed in dcerpc_ndr_request_send - %s\n",
nt_errstr(status)));
@@ -1228,10 +1211,9 @@ struct rpc_request *dcerpc_ndr_request_send(struct dcerpc_pipe *p,
req = dcerpc_request_send(p, object, opnum, mem_ctx, &request);
if (req != NULL) {
- req->ndr.ndr_push = ndr_push;
- req->ndr.ndr_pull = ndr_pull;
- req->ndr.struct_ptr = struct_ptr;
- req->ndr.struct_size = struct_size;
+ req->ndr.table = table;
+ req->ndr.opnum = opnum;
+ req->ndr.struct_ptr = r;
req->ndr.mem_ctx = mem_ctx;
}
@@ -1249,14 +1231,18 @@ NTSTATUS dcerpc_ndr_request_recv(struct rpc_request *req)
NTSTATUS status;
DATA_BLOB response;
struct ndr_pull *pull;
- struct rpc_request_ndr ndr = req->ndr;
uint_t flags;
+ TALLOC_CTX *mem_ctx = req->ndr.mem_ctx;
+ void *r = req->ndr.struct_ptr;
+ uint32_t opnum = req->ndr.opnum;
+ const struct dcerpc_interface_table *table = req->ndr.table;
+ const struct dcerpc_interface_call *call = &table->calls[opnum];
/* make sure the recv code doesn't free the request, as we
need to grab the flags element before it is freed */
talloc_increase_ref_count(req);
- status = dcerpc_request_recv(req, ndr.mem_ctx, &response);
+ status = dcerpc_request_recv(req, mem_ctx, &response);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
@@ -1265,7 +1251,7 @@ NTSTATUS dcerpc_ndr_request_recv(struct rpc_request *req)
talloc_free(req);
/* prepare for ndr_pull_* */
- pull = ndr_pull_init_flags(p, &response, ndr.mem_ctx);
+ pull = ndr_pull_init_flags(p, &response, mem_ctx);
if (!pull) {
return NT_STATUS_NO_MEMORY;
}
@@ -1278,15 +1264,19 @@ NTSTATUS dcerpc_ndr_request_recv(struct rpc_request *req)
dump_data(10, pull->data, pull->data_size);
/* pull the structure from the blob */
- status = ndr.ndr_pull(pull, NDR_OUT, ndr.struct_ptr);
+ status = call->ndr_pull(pull, NDR_OUT, r);
if (!NT_STATUS_IS_OK(status)) {
+ dcerpc_log_packet(table, opnum, NDR_OUT,
+ &response);
return status;
}
if (p->flags & DCERPC_DEBUG_VALIDATE_OUT) {
- status = dcerpc_ndr_validate_out(p, ndr.mem_ctx, ndr.struct_ptr, ndr.struct_size,
- ndr.ndr_push, ndr.ndr_pull);
+ status = dcerpc_ndr_validate_out(p, mem_ctx, r, call->struct_size,
+ call->ndr_push, call->ndr_pull);
if (!NT_STATUS_IS_OK(status)) {
+ dcerpc_log_packet(table, opnum, NDR_OUT,
+ &response);
return status;
}
}
@@ -1312,17 +1302,15 @@ NTSTATUS dcerpc_ndr_request_recv(struct rpc_request *req)
standard format
*/
NTSTATUS dcerpc_ndr_request(struct dcerpc_pipe *p,
- struct GUID *object,
- uint32_t opnum,
- TALLOC_CTX *mem_ctx,
- NTSTATUS (*ndr_push)(struct ndr_push *, int, void *),
- NTSTATUS (*ndr_pull)(struct ndr_pull *, int, void *),
- void *struct_ptr,
- size_t struct_size)
+ const struct GUID *object,
+ const struct dcerpc_interface_table *table,
+ uint32_t opnum,
+ TALLOC_CTX *mem_ctx,
+ void *r)
{
struct rpc_request *req;
- req = dcerpc_ndr_request_send(p, object, opnum, mem_ctx, ndr_push, ndr_pull, struct_ptr, struct_size);
+ req = dcerpc_ndr_request_send(p, object, table, opnum, mem_ctx, r);
if (req == NULL) {
return NT_STATUS_NO_MEMORY;
}
diff --git a/source4/librpc/rpc/dcerpc.h b/source4/librpc/rpc/dcerpc.h
index 47f13e643d..1b2feeadb2 100644
--- a/source4/librpc/rpc/dcerpc.h
+++ b/source4/librpc/rpc/dcerpc.h
@@ -181,11 +181,10 @@ struct rpc_request {
uint32_t fault_code;
/* use by the ndr level async recv call */
- struct rpc_request_ndr {
- NTSTATUS (*ndr_push)(struct ndr_push *, int, void *);
- NTSTATUS (*ndr_pull)(struct ndr_pull *, int, void *);
+ struct {
+ const struct dcerpc_interface_table *table;
+ uint32_t opnum;
void *struct_ptr;
- size_t struct_size;
TALLOC_CTX *mem_ctx;
} ndr;
diff --git a/source4/rpc_server/remote/dcesrv_remote.c b/source4/rpc_server/remote/dcesrv_remote.c
index 1ea6c1e4ea..ab09920b99 100644
--- a/source4/rpc_server/remote/dcesrv_remote.c
+++ b/source4/rpc_server/remote/dcesrv_remote.c
@@ -65,33 +65,37 @@ static void remote_op_unbind(struct dcesrv_connection *dce_conn, const struct dc
static NTSTATUS remote_op_dispatch(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
{
struct dcesrv_remote_private *private = dce_call->conn->private;
- NTSTATUS status;
uint16_t opnum = dce_call->pkt.u.request.opnum;
- const char *name = dce_call->conn->iface->ndr->calls[opnum].name;
- ndr_push_flags_fn_t ndr_push_fn = dce_call->conn->iface->ndr->calls[opnum].ndr_push;
- ndr_pull_flags_fn_t ndr_pull_fn = dce_call->conn->iface->ndr->calls[opnum].ndr_pull;
- ndr_print_function_t ndr_print_fn = dce_call->conn->iface->ndr->calls[opnum].ndr_print;
- size_t struct_size = dce_call->conn->iface->ndr->calls[opnum].struct_size;
+ const struct dcerpc_interface_call *call;
+ const char *name;
+
+ if (opnum >= dce_call->conn->iface->ndr->num_calls) {
+ dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+
+ name = dce_call->conn->iface->ndr->calls[opnum].name;
+ call = &dce_call->conn->iface->ndr->calls[opnum];
if (private->c_pipe->flags & DCERPC_DEBUG_PRINT_IN) {
- ndr_print_function_debug(ndr_print_fn, name, NDR_IN | NDR_SET_VALUES, r);
+ ndr_print_function_debug(call->ndr_print, name, NDR_IN | NDR_SET_VALUES, r);
}
- status = dcerpc_ndr_request(private->c_pipe, NULL, opnum, mem_ctx,
- (ndr_push_flags_fn_t) ndr_push_fn,
- (ndr_pull_flags_fn_t) ndr_pull_fn,
- r, struct_size);
+ /* we didn't use the return code of this function as we only check the last_fault_code */
+ dcerpc_ndr_request(private->c_pipe, NULL, dce_call->conn->iface->ndr,
+ opnum, mem_ctx,r);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0,("dcesrv_remote: call[%s] failed with: %s!\n",name, nt_errstr(status)));
- return status;
+ dce_call->fault_code = private->c_pipe->last_fault_code;
+ if (dce_call->fault_code != 0) {
+ DEBUG(0,("dcesrv_remote: call[%s] failed with: %s!\n",name, dcerpc_errstr(mem_ctx, dce_call->fault_code)));
+ return NT_STATUS_NET_WRITE_FAULT;
}
- if (NT_STATUS_IS_OK(status) && (private->c_pipe->flags & DCERPC_DEBUG_PRINT_OUT)) {
- ndr_print_function_debug(ndr_print_fn, name, NDR_OUT, r);
+ if ((dce_call->fault_code == 0) && (private->c_pipe->flags & DCERPC_DEBUG_PRINT_OUT)) {
+ ndr_print_function_debug(call->ndr_print, name, NDR_OUT, r);
}
- return status;
+ return NT_STATUS_OK;
}
static NTSTATUS remote_register_one_iface(struct dcesrv_context *dce_ctx, const struct dcesrv_interface *iface)