summaryrefslogtreecommitdiff
path: root/source4/rpc_server
diff options
context:
space:
mode:
Diffstat (limited to 'source4/rpc_server')
-rw-r--r--source4/rpc_server/dcerpc_server.c45
-rw-r--r--source4/rpc_server/dcerpc_server.h24
-rw-r--r--source4/rpc_server/epmapper/rpc_epmapper.c8
-rw-r--r--source4/rpc_server/remote/dcesrv_remote.c83
4 files changed, 101 insertions, 59 deletions
diff --git a/source4/rpc_server/dcerpc_server.c b/source4/rpc_server/dcerpc_server.c
index 6e608fd30b..231778247f 100644
--- a/source4/rpc_server/dcerpc_server.c
+++ b/source4/rpc_server/dcerpc_server.c
@@ -69,11 +69,11 @@ static struct dcesrv_endpoint *find_endpoint(struct dcesrv_context *dce_ctx,
static BOOL interface_match(const struct dcesrv_interface *if1,
const struct dcesrv_interface *if2)
{
- if (if1->ndr->if_version != if2->ndr->if_version) {
+ if (if1->if_version != if2->if_version) {
return False;
}
- if (strcmp(if1->ndr->uuid, if2->ndr->uuid)==0) {
+ if (strcmp(if1->uuid, if2->uuid)==0) {
return True;
}
@@ -101,11 +101,11 @@ static const struct dcesrv_interface *find_interface(const struct dcesrv_endpoin
static BOOL interface_match_by_uuid(const struct dcesrv_interface *iface,
const char *uuid, uint32_t if_version)
{
- if (iface->ndr->if_version != if_version) {
+ if (iface->if_version != if_version) {
return False;
}
- if (strcmp(iface->ndr->uuid, uuid)==0) {
+ if (strcmp(iface->uuid, uuid)==0) {
return True;
}
@@ -177,7 +177,7 @@ NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
/* see if the interface is already registered on te endpoint */
if (find_interface(ep, iface)!=NULL) {
DEBUG(0,("dcesrv_interface_register: interface '%s' already registered on endpoint '%s'\n",
- iface->ndr->name, ep_name));
+ iface->name, ep_name));
return NT_STATUS_OBJECT_NAME_COLLISION;
}
@@ -208,7 +208,7 @@ NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
if (ep->sd != NULL) {
DEBUG(0,("dcesrv_interface_register: interface '%s' failed to setup a security descriptor\n"
" on endpoint '%s'\n",
- iface->ndr->name, ep_name));
+ iface->name, ep_name));
if (add_ep) free(ep);
free(ifl);
return NT_STATUS_OBJECT_NAME_COLLISION;
@@ -224,7 +224,7 @@ NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
}
DEBUG(4,("dcesrv_interface_register: interface '%s' registered on endpoint '%s'\n",
- iface->ndr->name, ep_name));
+ iface->name, ep_name));
return NT_STATUS_OK;
}
@@ -497,10 +497,10 @@ static NTSTATUS dcesrv_bind(struct dcesrv_call_state *call)
pkt.u.bind_ack.max_xmit_frag = 0x2000;
pkt.u.bind_ack.max_recv_frag = 0x2000;
pkt.u.bind_ack.assoc_group_id = call->pkt.u.bind.assoc_group_id;
- if (call->conn->iface && call->conn->iface->ndr) {
+ if (call->conn->iface) {
/* FIXME: Use pipe name as specified by endpoint instead of interface name */
pkt.u.bind_ack.secondary_address = talloc_asprintf(call, "\\PIPE\\%s",
- call->conn->iface->ndr->name);
+ call->conn->iface->name);
} else {
pkt.u.bind_ack.secondary_address = "";
}
@@ -631,23 +631,17 @@ static NTSTATUS dcesrv_request(struct dcesrv_call_state *call)
{
struct ndr_pull *pull;
struct ndr_push *push;
- uint16_t opnum;
void *r;
NTSTATUS status;
DATA_BLOB stub;
uint32_t total_length;
+ call->fault_code = 0;
if (!call->conn->iface) {
return dcesrv_fault(call, DCERPC_FAULT_UNK_IF);
}
- opnum = call->pkt.u.request.opnum;
-
- if (opnum >= call->conn->iface->ndr->num_calls) {
- return dcesrv_fault(call, DCERPC_FAULT_OP_RNG_ERROR);
- }
-
pull = ndr_pull_init_blob(&call->pkt.u.request.stub_and_verifier, call);
if (!pull) {
return NT_STATUS_NO_MEMORY;
@@ -657,21 +651,14 @@ static NTSTATUS dcesrv_request(struct dcesrv_call_state *call)
pull->flags |= LIBNDR_FLAG_OBJECT_PRESENT;
}
- r = talloc(call, call->conn->iface->ndr->calls[opnum].struct_size);
- if (!r) {
- return NT_STATUS_NO_MEMORY;
- }
-
if (!(call->pkt.drep[0] & DCERPC_DREP_LE)) {
pull->flags |= LIBNDR_FLAG_BIGENDIAN;
}
/* unravel the NDR for the packet */
- status = call->conn->iface->ndr->calls[opnum].ndr_pull(pull, NDR_IN, r);
+ status = call->conn->iface->ndr_pull(call, call, pull, &r);
if (!NT_STATUS_IS_OK(status)) {
- dcerpc_log_packet(call->conn->iface->ndr, opnum, NDR_IN,
- &call->pkt.u.request.stub_and_verifier);
- return dcesrv_fault(call, DCERPC_FAULT_NDR);
+ return dcesrv_fault(call, call->fault_code);
}
if (pull->offset != pull->data_size) {
@@ -680,13 +667,9 @@ static NTSTATUS dcesrv_request(struct dcesrv_call_state *call)
dump_data(10, pull->data+pull->offset, pull->data_size - pull->offset);
}
- call->fault_code = 0;
-
/* call the dispatch function */
status = call->conn->iface->dispatch(call, call, r);
if (!NT_STATUS_IS_OK(status)) {
- dcerpc_log_packet(call->conn->iface->ndr, opnum, NDR_IN,
- &call->pkt.u.request.stub_and_verifier);
return dcesrv_fault(call, call->fault_code);
}
@@ -705,9 +688,9 @@ static NTSTATUS dcesrv_request(struct dcesrv_call_state *call)
push->flags |= LIBNDR_FLAG_BIGENDIAN;
}
- status = call->conn->iface->ndr->calls[opnum].ndr_push(push, NDR_OUT, r);
+ status = call->conn->iface->ndr_push(call, call, push, r);
if (!NT_STATUS_IS_OK(status)) {
- return dcesrv_fault(call, DCERPC_FAULT_NDR);
+ return dcesrv_fault(call, call->fault_code);
}
stub = ndr_push_blob(push);
diff --git a/source4/rpc_server/dcerpc_server.h b/source4/rpc_server/dcerpc_server.h
index 12c93140ec..c919476d1b 100644
--- a/source4/rpc_server/dcerpc_server.h
+++ b/source4/rpc_server/dcerpc_server.h
@@ -35,12 +35,10 @@ struct dcesrv_connection;
struct dcesrv_call_state;
struct dcesrv_auth;
-/* the dispatch functions for an interface take this form */
-typedef NTSTATUS (*dcesrv_dispatch_fn_t)(struct dcesrv_call_state *, TALLOC_CTX *, void *);
-
struct dcesrv_interface {
- /* the ndr function table for the chosen interface */
- const struct dcerpc_interface_table *ndr;
+ const char *name;
+ const char *uuid;
+ uint32_t if_version;
/* this function is called when the client binds to this interface */
NTSTATUS (*bind)(struct dcesrv_call_state *, const struct dcesrv_interface *);
@@ -48,10 +46,22 @@ struct dcesrv_interface {
/* this function is called when the client disconnects the endpoint */
void (*unbind)(struct dcesrv_connection *, const struct dcesrv_interface *);
+
+ /* the ndr_pull function for the chosen interface.
+ */
+ NTSTATUS (*ndr_pull)(struct dcesrv_call_state *, TALLOC_CTX *, struct ndr_pull *, void **);;
+
/* the dispatch function for the chosen interface.
*/
- dcesrv_dispatch_fn_t dispatch;
-};
+ NTSTATUS (*dispatch)(struct dcesrv_call_state *, TALLOC_CTX *, void *);
+
+ /* the ndr_push function for the chosen interface.
+ */
+ NTSTATUS (*ndr_push)(struct dcesrv_call_state *, TALLOC_CTX *, struct ndr_push *,void *);
+
+ /* for any private use by the interface code */
+ const void *private;
+};
/* the state of an ongoing dcerpc call */
struct dcesrv_call_state {
diff --git a/source4/rpc_server/epmapper/rpc_epmapper.c b/source4/rpc_server/epmapper/rpc_epmapper.c
index 8f4450c2ef..8519f99486 100644
--- a/source4/rpc_server/epmapper/rpc_epmapper.c
+++ b/source4/rpc_server/epmapper/rpc_epmapper.c
@@ -72,12 +72,10 @@ static uint32_t build_ep_list(TALLOC_CTX *mem_ctx,
if (!*eps) {
return 0;
}
- (*eps)[total].name = iface->iface.ndr->name;
+ (*eps)[total].name = iface->iface.name;
(*eps)[total].ep_description = d->ep_description;
- GUID_from_string(iface->iface.ndr->uuid,
- &(*eps)[total].ep_description.object);
- (*eps)[total].ep_description.object_version =
- iface->iface.ndr->if_version;
+ GUID_from_string(iface->iface.uuid, &(*eps)[total].ep_description.object);
+ (*eps)[total].ep_description.object_version = iface->iface.if_version;
total++;
}
}
diff --git a/source4/rpc_server/remote/dcesrv_remote.c b/source4/rpc_server/remote/dcesrv_remote.c
index ab09920b99..3bf917ac71 100644
--- a/source4/rpc_server/remote/dcesrv_remote.c
+++ b/source4/rpc_server/remote/dcesrv_remote.c
@@ -24,7 +24,6 @@
struct dcesrv_remote_private {
struct dcerpc_pipe *c_pipe;
- void *private;
};
static NTSTATUS remote_op_bind(struct dcesrv_call_state *dce_call, const struct dcesrv_interface *iface)
@@ -34,7 +33,7 @@ static NTSTATUS remote_op_bind(struct dcesrv_call_state *dce_call, const struct
const char *binding = lp_parm_string(-1, "dcerpc_remote", "binding");
if (!binding) {
- printf("You must specify a ncacn binding string\n");
+ DEBUG(0,("You must specify a ncacn binding string\n"));
return NT_STATUS_INVALID_PARAMETER;
}
@@ -43,10 +42,13 @@ static NTSTATUS remote_op_bind(struct dcesrv_call_state *dce_call, const struct
return NT_STATUS_NO_MEMORY;
}
- status = dcerpc_pipe_connect(&(private->c_pipe), binding, iface->ndr->uuid, iface->ndr->if_version,
+ status = dcerpc_pipe_connect(&(private->c_pipe), binding, iface->uuid, iface->if_version,
lp_workgroup(),
lp_parm_string(-1, "dcerpc_remote", "username"),
lp_parm_string(-1, "dcerpc_remote", "password"));
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
dce_call->conn->private = private;
@@ -62,28 +64,53 @@ static void remote_op_unbind(struct dcesrv_connection *dce_conn, const struct dc
return;
}
-static NTSTATUS remote_op_dispatch(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
+static NTSTATUS remote_op_ndr_pull(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_pull *pull, void **r)
{
- struct dcesrv_remote_private *private = dce_call->conn->private;
+ NTSTATUS status;
+ const struct dcerpc_interface_table *table = dce_call->conn->iface->private;
uint16_t opnum = dce_call->pkt.u.request.opnum;
- const struct dcerpc_interface_call *call;
- const char *name;
- if (opnum >= dce_call->conn->iface->ndr->num_calls) {
+ dce_call->fault_code = 0;
+
+ if (opnum >= table->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];
+ *r = talloc(mem_ctx, table->calls[opnum].struct_size);
+ if (!*r) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ /* unravel the NDR for the packet */
+ status = table->calls[opnum].ndr_pull(pull, NDR_IN, *r);
+ if (!NT_STATUS_IS_OK(status)) {
+ dcerpc_log_packet(table, opnum, NDR_IN,
+ &dce_call->pkt.u.request.stub_and_verifier);
+ dce_call->fault_code = DCERPC_FAULT_NDR;
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+
+ return NT_STATUS_OK;
+}
+
+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;
+ uint16_t opnum = dce_call->pkt.u.request.opnum;
+ const struct dcerpc_interface_table *table = dce_call->conn->iface->private;
+ const struct dcerpc_interface_call *call;
+ const char *name;
+
+ name = table->calls[opnum].name;
+ call = &table->calls[opnum];
if (private->c_pipe->flags & DCERPC_DEBUG_PRINT_IN) {
ndr_print_function_debug(call->ndr_print, name, NDR_IN | NDR_SET_VALUES, r);
}
/* 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);
+ dcerpc_ndr_request(private->c_pipe, NULL, table, opnum, mem_ctx,r);
dce_call->fault_code = private->c_pipe->last_fault_code;
if (dce_call->fault_code != 0) {
@@ -98,13 +125,30 @@ static NTSTATUS remote_op_dispatch(struct dcesrv_call_state *dce_call, TALLOC_CT
return NT_STATUS_OK;
}
+static NTSTATUS remote_op_ndr_push(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_push *push, void *r)
+{
+ NTSTATUS status;
+ const struct dcerpc_interface_table *table = dce_call->conn->iface->private;
+ uint16_t opnum = dce_call->pkt.u.request.opnum;
+
+ /* unravel the NDR for the packet */
+ status = table->calls[opnum].ndr_push(push, NDR_OUT, r);
+ if (!NT_STATUS_IS_OK(status)) {
+ dce_call->fault_code = DCERPC_FAULT_NDR;
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+
+ return NT_STATUS_OK;
+}
+
static NTSTATUS remote_register_one_iface(struct dcesrv_context *dce_ctx, const struct dcesrv_interface *iface)
{
int i;
+ const struct dcerpc_interface_table *table = iface->private;
- for (i=0;i<iface->ndr->endpoints->count;i++) {
+ for (i=0;i<table->endpoints->count;i++) {
NTSTATUS ret;
- const char *name = iface->ndr->endpoints->names[i];
+ const char *name = table->endpoints->names[i];
ret = dcesrv_interface_register(dce_ctx, name, iface, NULL);
if (!NT_STATUS_IS_OK(ret)) {
@@ -150,11 +194,18 @@ static NTSTATUS remote_op_init_server(struct dcesrv_context *dce_ctx, const stru
static BOOL remote_fill_interface(struct dcesrv_interface *iface, const struct dcerpc_interface_table *if_tabl)
{
- iface->ndr = if_tabl;
-
+ iface->name = if_tabl->name;
+ iface->uuid = if_tabl->uuid;
+ iface->if_version = if_tabl->if_version;
+
iface->bind = remote_op_bind;
iface->unbind = remote_op_unbind;
+
+ iface->ndr_pull = remote_op_ndr_pull;
iface->dispatch = remote_op_dispatch;
+ iface->ndr_push = remote_op_ndr_push;
+
+ iface->private = if_tabl;
return True;
}