summaryrefslogtreecommitdiff
path: root/source4/rpc_server
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2003-12-13 10:58:48 +0000
committerAndrew Tridgell <tridge@samba.org>2003-12-13 10:58:48 +0000
commitd4705378ce88d1bb2f787338c531998d37d078ef (patch)
tree5c69c190347bd71067203aa89f0e99db4bc50a38 /source4/rpc_server
parent8faa77f177833eeee245391840d06771f46e0136 (diff)
downloadsamba-d4705378ce88d1bb2f787338c531998d37d078ef.tar.gz
samba-d4705378ce88d1bb2f787338c531998d37d078ef.tar.bz2
samba-d4705378ce88d1bb2f787338c531998d37d078ef.zip
dcerpc over tcp in the samba4 server now works to some extent. It
needs quite a bit more work to get it finished. The biggest missing feature is the lack of NTLMSSP which is needed for basic authentication over tcp (This used to be commit 9fb0f0369356909c99389e2cbc525be27c08793c)
Diffstat (limited to 'source4/rpc_server')
-rw-r--r--source4/rpc_server/dcerpc_server.c70
-rw-r--r--source4/rpc_server/dcerpc_server.h4
-rw-r--r--source4/rpc_server/dcerpc_tcp.c256
-rw-r--r--source4/rpc_server/echo/rpc_echo.c4
-rw-r--r--source4/rpc_server/epmapper/rpc_epmapper.c53
5 files changed, 340 insertions, 47 deletions
diff --git a/source4/rpc_server/dcerpc_server.c b/source4/rpc_server/dcerpc_server.c
index 67b36cdc48..81c9d4cb8f 100644
--- a/source4/rpc_server/dcerpc_server.c
+++ b/source4/rpc_server/dcerpc_server.c
@@ -25,11 +25,11 @@
/*
find the set of endpoint operations for an endpoint server
*/
-static const struct dcesrv_endpoint_ops *find_endpoint(struct server_context *smb,
+static const struct dcesrv_endpoint_ops *find_endpoint(struct dcesrv_context *dce,
const struct dcesrv_endpoint *endpoint)
{
struct dce_endpoint *ep;
- for (ep=smb->dcesrv.endpoint_list; ep; ep=ep->next) {
+ for (ep=dce->endpoint_list; ep; ep=ep->next) {
if (ep->endpoint_ops->query_endpoint(endpoint)) {
return ep->endpoint_ops;
}
@@ -54,7 +54,7 @@ static struct dcesrv_call_state *dcesrv_find_call(struct dcesrv_state *dce, uint
/*
register an endpoint server
*/
-BOOL dcesrv_endpoint_register(struct server_context *smb,
+BOOL dcesrv_endpoint_register(struct dcesrv_context *dce,
const struct dcesrv_endpoint_ops *ops)
{
struct dce_endpoint *ep;
@@ -63,26 +63,20 @@ BOOL dcesrv_endpoint_register(struct server_context *smb,
return False;
}
ep->endpoint_ops = ops;
- DLIST_ADD(smb->dcesrv.endpoint_list, ep);
+ DLIST_ADD(dce->endpoint_list, ep);
return True;
}
/*
connect to a dcerpc endpoint
*/
-NTSTATUS dcesrv_endpoint_connect(struct server_context *smb,
- const struct dcesrv_endpoint *endpoint,
- struct dcesrv_state **p)
+NTSTATUS dcesrv_endpoint_connect_ops(struct dcesrv_context *dce,
+ const struct dcesrv_endpoint *endpoint,
+ const struct dcesrv_endpoint_ops *ops,
+ struct dcesrv_state **p)
{
TALLOC_CTX *mem_ctx;
NTSTATUS status;
- const struct dcesrv_endpoint_ops *ops;
-
- /* make sure this endpoint exists */
- ops = find_endpoint(smb, endpoint);
- if (!ops) {
- return NT_STATUS_OBJECT_NAME_NOT_FOUND;
- }
mem_ctx = talloc_init("dcesrv_endpoint_connect");
if (!mem_ctx) {
@@ -95,7 +89,7 @@ NTSTATUS dcesrv_endpoint_connect(struct server_context *smb,
return NT_STATUS_NO_MEMORY;
}
- (*p)->smb = smb;
+ (*p)->dce = dce;
(*p)->mem_ctx = mem_ctx;
(*p)->endpoint = *endpoint;
(*p)->ops = ops;
@@ -117,6 +111,24 @@ NTSTATUS dcesrv_endpoint_connect(struct server_context *smb,
return NT_STATUS_OK;
}
+/*
+ connect to a dcerpc endpoint
+*/
+NTSTATUS dcesrv_endpoint_connect(struct dcesrv_context *dce,
+ const struct dcesrv_endpoint *endpoint,
+ struct dcesrv_state **p)
+{
+ const struct dcesrv_endpoint_ops *ops;
+
+ /* make sure this endpoint exists */
+ ops = find_endpoint(dce, endpoint);
+ if (!ops) {
+ return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ }
+
+ return dcesrv_endpoint_connect_ops(dce, endpoint, ops, p);
+}
+
/*
disconnect a link to an endpoint
@@ -646,27 +658,35 @@ int dcesrv_lookup_endpoints(const struct dcerpc_interface_table *table,
TALLOC_CTX *mem_ctx,
struct dcesrv_ep_iface **e)
{
- *e = talloc_p(mem_ctx, struct dcesrv_ep_iface);
+ int i;
+ *e = talloc_array_p(mem_ctx, struct dcesrv_ep_iface, table->endpoints->count);
if (! *e) {
return -1;
}
- (*e)->name = table->name;
- (*e)->uuid = table->uuid;
- (*e)->if_version = table->if_version;
- (*e)->endpoint.type = ENDPOINT_SMB;
- (*e)->endpoint.info.smb_pipe = table->endpoints->names[0];
+ for (i=0;i<table->endpoints->count;i++) {
+ (*e)[i].name = table->name;
+ (*e)[i].uuid = table->uuid;
+ (*e)[i].if_version = table->if_version;
+ if (strncmp(table->endpoints->names[i], "TCP-", 4) == 0) {
+ (*e)[i].endpoint.type = ENDPOINT_TCP;
+ (*e)[i].endpoint.info.tcp_port = atoi(table->endpoints->names[i]+4);
+ } else {
+ (*e)[i].endpoint.type = ENDPOINT_SMB;
+ (*e)[i].endpoint.info.smb_pipe = table->endpoints->names[i];
+ }
+ }
- return 1;
+ return i;
}
/*
initialise the dcerpc server subsystem
*/
-BOOL dcesrv_init(struct server_context *smb)
+BOOL dcesrv_init(struct dcesrv_context *dce)
{
- rpc_echo_init(smb);
- rpc_epmapper_init(smb);
+ rpc_echo_init(dce);
+ rpc_epmapper_init(dce);
return True;
}
diff --git a/source4/rpc_server/dcerpc_server.h b/source4/rpc_server/dcerpc_server.h
index 83e0ee249a..38340bcf16 100644
--- a/source4/rpc_server/dcerpc_server.h
+++ b/source4/rpc_server/dcerpc_server.h
@@ -71,7 +71,7 @@ struct dcesrv_handle {
/* the state associated with a dcerpc server connection */
struct dcesrv_state {
/* the top level context for this server */
- struct server_context *smb;
+ struct dcesrv_context *dce;
TALLOC_CTX *mem_ctx;
@@ -120,7 +120,7 @@ struct dcesrv_endpoint_ops {
void (*disconnect)(struct dcesrv_state *);
/* this function is used to ask an endpoint server for a list
- of endpoints it wants to handle */
+ of endpoints/interfaces it wants to handle */
int (*lookup_endpoints)(TALLOC_CTX *mem_ctx, struct dcesrv_ep_iface **);
};
diff --git a/source4/rpc_server/dcerpc_tcp.c b/source4/rpc_server/dcerpc_tcp.c
new file mode 100644
index 0000000000..110789dba6
--- /dev/null
+++ b/source4/rpc_server/dcerpc_tcp.c
@@ -0,0 +1,256 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ server side dcerpc over tcp code
+
+ Copyright (C) Andrew Tridgell 2003
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+
+struct rpc_listen {
+ struct dce_endpoint *e;
+ struct model_ops *model_ops;
+};
+
+
+/*
+ called when a RPC socket becomes writable
+*/
+static void dcerpc_write_handler(struct event_context *ev, struct fd_event *fde,
+ time_t t, uint16 flags)
+{
+ struct dcesrv_state *dce = fde->private;
+ DATA_BLOB blob;
+ NTSTATUS status;
+
+ blob = data_blob(NULL, 0x4000);
+ if (!blob.data) {
+ smb_panic("out of memory in rpc write handler");
+ }
+
+ status = dcesrv_output(dce, &blob);
+ if (!NT_STATUS_IS_OK(status)) {
+ fde->flags &= ~EVENT_FD_WRITE;
+ } else {
+ write_data(fde->fd, blob.data, blob.length);
+ }
+
+ data_blob_free(&blob);
+}
+
+/*
+ called when a RPC socket becomes readable
+*/
+static void dcerpc_read_handler(struct event_context *ev, struct fd_event *fde,
+ time_t t, uint16 flags)
+{
+ struct dcesrv_state *dce = fde->private;
+ DATA_BLOB blob;
+ ssize_t ret;
+
+ blob = data_blob(NULL, 0x4000);
+ if (!blob.data) {
+ smb_panic("out of memory in rpc read handler");
+ }
+
+ ret = read(fde->fd, blob.data, blob.length);
+ if (ret == 0) {
+ smb_panic("need a shutdown routine");
+ }
+ if (ret == -1 && errno != EINTR) {
+ smb_panic("need a shutdown routine");
+ }
+ if (ret == -1) {
+ return;
+ }
+
+ dcesrv_input(dce, &blob);
+
+ data_blob_free(&blob);
+
+ fde->flags |= EVENT_FD_WRITE;
+}
+
+
+
+
+/*
+ called when a RPC socket becomes readable
+*/
+static void dcerpc_io_handler(struct event_context *ev, struct fd_event *fde,
+ time_t t, uint16 flags)
+{
+ if (flags & EVENT_FD_WRITE) {
+ dcerpc_write_handler(ev, fde, t, flags);
+ }
+
+ if (flags & EVENT_FD_READ) {
+ dcerpc_read_handler(ev, fde, t, flags);
+ }
+}
+
+/*
+ initialise a server_context from a open socket and register a event handler
+ for reading from that socket
+*/
+void init_rpc_session(struct event_context *ev, void *private, int fd)
+{
+ struct dcesrv_context context;
+ struct dcesrv_state *dce;
+ struct fd_event fde;
+ struct rpc_listen *r = private;
+ struct dcesrv_endpoint endpoint;
+
+ set_socket_options(fd,"SO_KEEPALIVE");
+ set_socket_options(fd, lp_socket_options());
+
+ context.endpoint_list = NULL;
+ dcesrv_init(&context);
+
+ endpoint.type = ENDPOINT_TCP;
+ endpoint.info.tcp_port = 0;
+
+ dcesrv_endpoint_connect_ops(&context, &endpoint, r->e->endpoint_ops, &dce);
+
+ dce->dce = talloc_p(dce->mem_ctx, struct dcesrv_context);
+ *dce->dce = context;
+
+ set_blocking(fd, False);
+
+ /* setup a event handler for this socket. We are initially
+ only interested in reading from the socket */
+ fde.fd = fd;
+ fde.handler = dcerpc_io_handler;
+ fde.private = dce;
+ fde.flags = EVENT_FD_READ;
+
+ event_add_fd(ev, &fde);
+}
+
+
+/*
+ setup a single rpc listener
+ */
+static void setup_listen_rpc(struct event_context *events,
+ struct model_ops *model_ops,
+ struct in_addr *ifip, unsigned port,
+ struct dce_endpoint *e)
+{
+ struct fd_event fde;
+ struct rpc_listen *r;
+
+ fde.fd = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr, True);
+ if (fde.fd == -1) {
+ DEBUG(0,("Failed to open socket on %s:%u - %s\n",
+ inet_ntoa(*ifip), port, strerror(errno)));
+ return;
+ }
+
+ /* ready to listen */
+ set_socket_options(fde.fd, "SO_KEEPALIVE");
+ set_socket_options(fde.fd, lp_socket_options());
+
+ if (listen(fde.fd, SMBD_LISTEN_BACKLOG) == -1) {
+ DEBUG(0,("Failed to listen on %s:%d - %s\n",
+ inet_ntoa(*ifip), port, strerror(errno)));
+ close(fde.fd);
+ return;
+ }
+
+ r = malloc(sizeof(*r));
+ if (!r) {
+ return;
+ }
+
+ r->e = e;
+ r->model_ops = model_ops;
+
+ /* we are only interested in read events on the listen socket */
+ fde.flags = EVENT_FD_READ;
+ fde.private = r;
+ fde.handler = model_ops->accept_rpc_connection;
+
+ event_add_fd(events, &fde);
+}
+
+/*
+ add a socket address to the list of events, one event per dcerpc endpoint
+*/
+static void add_socket_rpc(struct event_context *events,
+ struct model_ops *model_ops,
+ struct in_addr *ifip)
+{
+ struct dcesrv_context dce;
+ TALLOC_CTX *mem_ctx;
+
+ mem_ctx = talloc_init("add_socket_rpc");
+ if (!mem_ctx) {
+ smb_panic("out of memory in add_socket_rpc");
+ }
+
+ dce.endpoint_list = NULL;
+
+ dcesrv_init(&dce);
+
+ while (dce.endpoint_list) {
+ struct dce_endpoint *e = dce.endpoint_list;
+ struct dcesrv_ep_iface *ifaces;
+ int count, i;
+
+ count = e->endpoint_ops->lookup_endpoints(mem_ctx, &ifaces);
+ for (i=0;i<count;i++) {
+ if (ifaces[i].endpoint.type == ENDPOINT_TCP) {
+ setup_listen_rpc(events, model_ops, ifip,
+ ifaces[i].endpoint.info.tcp_port,
+ e);
+ break;
+ }
+ }
+
+ DLIST_REMOVE(dce.endpoint_list, e);
+ }
+
+ talloc_destroy(mem_ctx);
+}
+
+/****************************************************************************
+ Open the listening sockets for RPC over TCP
+****************************************************************************/
+void open_sockets_rpc(struct event_context *events,
+ struct model_ops *model_ops)
+{
+ if (lp_interfaces() && lp_bind_interfaces_only()) {
+ int num_interfaces = iface_count();
+ int i;
+ for(i = 0; i < num_interfaces; i++) {
+ struct in_addr *ifip = iface_n_ip(i);
+ if (ifip == NULL) {
+ continue;
+ }
+ add_socket_rpc(events, model_ops, ifip);
+ }
+ } else {
+ TALLOC_CTX *mem_ctx = talloc_init("open_sockets_smbd");
+ struct in_addr *ifip = interpret_addr2(mem_ctx, lp_socket_address());
+ if (!mem_ctx) {
+ smb_panic("No memory");
+ }
+ add_socket_rpc(events, model_ops, ifip);
+ talloc_destroy(mem_ctx);
+ }
+}
diff --git a/source4/rpc_server/echo/rpc_echo.c b/source4/rpc_server/echo/rpc_echo.c
index f741e63d62..0f3c504c37 100644
--- a/source4/rpc_server/echo/rpc_echo.c
+++ b/source4/rpc_server/echo/rpc_echo.c
@@ -179,9 +179,9 @@ static const struct dcesrv_endpoint_ops rpc_echo_ops = {
/*
register with the dcerpc server
*/
-void rpc_echo_init(struct server_context *smb)
+void rpc_echo_init(struct dcesrv_context *dce)
{
- if (!dcesrv_endpoint_register(smb, &rpc_echo_ops)) {
+ if (!dcesrv_endpoint_register(dce, &rpc_echo_ops)) {
DEBUG(1,("Failed to register rpcecho endpoint\n"));
}
}
diff --git a/source4/rpc_server/epmapper/rpc_epmapper.c b/source4/rpc_server/epmapper/rpc_epmapper.c
index 2898a70159..32a239f44d 100644
--- a/source4/rpc_server/epmapper/rpc_epmapper.c
+++ b/source4/rpc_server/epmapper/rpc_epmapper.c
@@ -66,20 +66,37 @@ static BOOL fill_protocol_tower(TALLOC_CTX *mem_ctx, struct epm_towers *twr,
twr->floors[2].lhs.protocol = EPM_PROTOCOL_RPC_C;
twr->floors[2].lhs.info.lhs_data = data_blob(NULL, 0);
twr->floors[2].rhs.rhs_data = data_blob_talloc_zero(mem_ctx, 2);
-
- /* on a SMB pipe ... */
- twr->floors[3].lhs.protocol = EPM_PROTOCOL_SMB;
- twr->floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
- twr->floors[3].rhs.rhs_data.data = talloc_asprintf(mem_ctx, "\\PIPE\\%s",
- e->endpoint.info.smb_pipe);
- twr->floors[3].rhs.rhs_data.length = strlen(twr->floors[3].rhs.rhs_data.data)+1;
-
- /* on an NetBIOS link ... */
- twr->floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS;
- twr->floors[4].lhs.info.lhs_data = data_blob(NULL, 0);
- twr->floors[4].rhs.rhs_data.data = talloc_asprintf(mem_ctx, "\\\\%s",
- lp_netbios_name());
- twr->floors[4].rhs.rhs_data.length = strlen(twr->floors[4].rhs.rhs_data.data)+1;
+
+ switch (e->endpoint.type) {
+ case ENDPOINT_SMB:
+ /* on a SMB pipe ... */
+ twr->floors[3].lhs.protocol = EPM_PROTOCOL_SMB;
+ twr->floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
+ twr->floors[3].rhs.rhs_data.data = talloc_asprintf(mem_ctx, "\\PIPE\\%s",
+ e->endpoint.info.smb_pipe);
+ twr->floors[3].rhs.rhs_data.length = strlen(twr->floors[3].rhs.rhs_data.data)+1;
+
+ /* on an NetBIOS link ... */
+ twr->floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS;
+ twr->floors[4].lhs.info.lhs_data = data_blob(NULL, 0);
+ twr->floors[4].rhs.rhs_data.data = talloc_asprintf(mem_ctx, "\\\\%s",
+ lp_netbios_name());
+ twr->floors[4].rhs.rhs_data.length = strlen(twr->floors[4].rhs.rhs_data.data)+1;
+ break;
+
+ case ENDPOINT_TCP:
+ /* on a TCP connection ... */
+ twr->floors[3].lhs.protocol = EPM_PROTOCOL_TCP;
+ twr->floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
+ twr->floors[3].rhs.rhs_data = data_blob_talloc(mem_ctx, NULL, 2);
+ RSSVAL(twr->floors[3].rhs.rhs_data.data, 0, e->endpoint.info.tcp_port);
+
+ /* on an IP link ... */
+ twr->floors[4].lhs.protocol = EPM_PROTOCOL_IP;
+ twr->floors[4].lhs.info.lhs_data = data_blob(NULL, 0);
+ twr->floors[4].rhs.rhs_data = data_blob_talloc_zero(mem_ctx, 4);
+ break;
+ }
return True;
}
@@ -160,7 +177,7 @@ static NTSTATUS epm_Lookup(struct dcesrv_state *dce, TALLOC_CTX *mem_ctx,
}
h->data = eps;
- eps->count = build_ep_list(h->mem_ctx, dce->smb->dcesrv.endpoint_list, &eps->e);
+ eps->count = build_ep_list(h->mem_ctx, dce->dce->endpoint_list, &eps->e);
}
/* return the next N elements */
@@ -218,7 +235,7 @@ static NTSTATUS epm_Map(struct dcesrv_state *dce, TALLOC_CTX *mem_ctx,
struct dcesrv_ep_iface *eps;
struct epm_floor *floors;
- count = build_ep_list(mem_ctx, dce->smb->dcesrv.endpoint_list, &eps);
+ count = build_ep_list(mem_ctx, dce->dce->endpoint_list, &eps);
ZERO_STRUCTP(r->out.entry_handle);
r->out.num_towers = 1;
@@ -368,9 +385,9 @@ static const struct dcesrv_endpoint_ops rpc_epmapper_ops = {
/*
register with the dcerpc server
*/
-void rpc_epmapper_init(struct server_context *smb)
+void rpc_epmapper_init(struct dcesrv_context *dce)
{
- if (!dcesrv_endpoint_register(smb, &rpc_epmapper_ops)) {
+ if (!dcesrv_endpoint_register(dce, &rpc_epmapper_ops)) {
DEBUG(1,("Failed to register epmapper endpoint\n"));
}
}