summaryrefslogtreecommitdiff
path: root/source4/rpc_server
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2003-12-10 22:21:04 +0000
committerAndrew Tridgell <tridge@samba.org>2003-12-10 22:21:04 +0000
commit188b2054a80ec16e7fb9ed7b6b1e8fce9b52458f (patch)
tree211e23ff3fa9a7d1911acd3557ce970af6aa782d /source4/rpc_server
parent3c76426f2e343df2194825ae2e0ef84f4ad4c6ac (diff)
downloadsamba-188b2054a80ec16e7fb9ed7b6b1e8fce9b52458f.tar.gz
samba-188b2054a80ec16e7fb9ed7b6b1e8fce9b52458f.tar.bz2
samba-188b2054a80ec16e7fb9ed7b6b1e8fce9b52458f.zip
initial rpc server side infrastructure
(This used to be commit 3706af7a6cb2090e0baeff5ee54bf49ebda2cce1)
Diffstat (limited to 'source4/rpc_server')
-rw-r--r--source4/rpc_server/dcerpc_server.c141
-rw-r--r--source4/rpc_server/dcerpc_server.h72
-rw-r--r--source4/rpc_server/rpc_echo.c67
3 files changed, 280 insertions, 0 deletions
diff --git a/source4/rpc_server/dcerpc_server.c b/source4/rpc_server/dcerpc_server.c
new file mode 100644
index 0000000000..c01dc4d9db
--- /dev/null
+++ b/source4/rpc_server/dcerpc_server.c
@@ -0,0 +1,141 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ server side dcerpc core 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"
+
+/*
+ find the set of endpoint operations for an endpoint server
+*/
+static const struct dcesrv_endpoint_ops *find_endpoint(struct server_context *smb,
+ const struct dcesrv_endpoint *endpoint)
+{
+ struct dce_endpoint *ep;
+ for (ep=smb->dcesrv.endpoint_list; ep; ep=ep->next) {
+ if (ep->endpoint_ops->query(endpoint)) {
+ return ep->endpoint_ops;
+ }
+ }
+ return NULL;
+}
+
+
+/*
+ register an endpoint server
+*/
+BOOL dcesrv_endpoint_register(struct server_context *smb,
+ const struct dcesrv_endpoint_ops *ops)
+{
+ struct dce_endpoint *ep;
+ ep = malloc(sizeof(*ep));
+ if (!ep) {
+ return False;
+ }
+ ep->endpoint_ops = ops;
+ DLIST_ADD(smb->dcesrv.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)
+{
+ 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) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ *p = talloc(mem_ctx, sizeof(struct dcesrv_state));
+ if (! *p) {
+ talloc_destroy(mem_ctx);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ (*p)->mem_ctx = mem_ctx;
+ (*p)->endpoint = *endpoint;
+ (*p)->ops = ops;
+ (*p)->private = NULL;
+
+ /* make sure the endpoint server likes the connection */
+ status = ops->connect(*p);
+ if (!NT_STATUS_IS_OK(status)) {
+ talloc_destroy(mem_ctx);
+ return status;
+ }
+
+ return NT_STATUS_OK;
+}
+
+
+/*
+ disconnect a link to an endpoint
+*/
+void dcesrv_endpoint_disconnect(struct dcesrv_state *p)
+{
+ p->ops->disconnect(p);
+ talloc_destroy(p->mem_ctx);
+}
+
+
+
+/*
+ a useful function for implementing the query endpoint op
+ */
+BOOL dcesrv_table_query(const struct dcerpc_interface_table *table,
+ const struct dcesrv_endpoint *ep)
+{
+ int i;
+ const struct dcerpc_endpoint_list *endpoints = table->endpoints;
+
+ if (ep->type != ENDPOINT_SMB) {
+ return False;
+ }
+
+ for (i=0;i<endpoints->count;i++) {
+ if (strcasecmp(ep->info.smb_pipe, endpoints->names[i]) == 0) {
+ return True;
+ }
+ }
+ return False;
+}
+
+
+/*
+ initialise the dcerpc server subsystem
+*/
+BOOL dcesrv_init(struct server_context *smb)
+{
+ rpc_echo_init(smb);
+ return True;
+}
diff --git a/source4/rpc_server/dcerpc_server.h b/source4/rpc_server/dcerpc_server.h
new file mode 100644
index 0000000000..b28f40768a
--- /dev/null
+++ b/source4/rpc_server/dcerpc_server.h
@@ -0,0 +1,72 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ server side dcerpc defines
+
+ 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.
+*/
+
+
+enum endpoint_type {ENDPOINT_SMB, ENDPOINT_TCP};
+
+/* a description of a single dcerpc endpoint */
+struct dcesrv_endpoint {
+ enum endpoint_type type;
+ union {
+ const char *smb_pipe;
+ uint32 tcp_port;
+ } info;
+};
+
+
+/* the state associated with a dcerpc server connection */
+struct dcesrv_state {
+ TALLOC_CTX *mem_ctx;
+
+ /* the endpoint that was opened */
+ struct dcesrv_endpoint endpoint;
+
+ /* endpoint operations provided by the endpoint server */
+ const struct dcesrv_endpoint_ops *ops;
+
+ /* private data for the endpoint server */
+ void *private;
+};
+
+
+struct dcesrv_endpoint_ops {
+ /* the query function is used to ask an endpoint server if it
+ handles a particular endpoint */
+ BOOL (*query)(const struct dcesrv_endpoint *);
+
+ /* connect() is called when a connection is made to an endpoint */
+ NTSTATUS (*connect)(struct dcesrv_state *);
+
+ /* disconnect() is called when the endpoint is disconnected */
+ void (*disconnect)(struct dcesrv_state *);
+};
+
+
+/* server-wide context information for the dcerpc server */
+struct dcesrv_context {
+
+ /* the list of endpoints servers that have registered */
+ struct dce_endpoint {
+ struct dce_endpoint *next, *prev;
+ const struct dcesrv_endpoint_ops *endpoint_ops;
+ } *endpoint_list;
+};
diff --git a/source4/rpc_server/rpc_echo.c b/source4/rpc_server/rpc_echo.c
new file mode 100644
index 0000000000..51914f7946
--- /dev/null
+++ b/source4/rpc_server/rpc_echo.c
@@ -0,0 +1,67 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ endpoint server for the echo pipe
+
+ 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"
+
+
+
+/**************************************************************************
+ all the code below this point is boilerplate that will be auto-generated
+***************************************************************************/
+
+
+/*
+ return True if we want to handle the given endpoint
+*/
+static BOOL op_query(const struct dcesrv_endpoint *ep)
+{
+ return dcesrv_table_query(&dcerpc_table_rpcecho, ep);
+}
+
+
+/* op_connect is called when a connection is made to an endpoint */
+static NTSTATUS op_connect(struct dcesrv_state *dce)
+{
+ return NT_STATUS_OK;
+}
+
+static void op_disconnect(struct dcesrv_state *dce)
+{
+ /* nothing to do */
+}
+
+
+static const struct dcesrv_endpoint_ops rpc_echo_ops = {
+ op_query,
+ op_connect,
+ op_disconnect
+};
+
+/*
+ register with the dcerpc server
+*/
+void rpc_echo_init(struct server_context *smb)
+{
+ if (!dcesrv_endpoint_register(smb, &rpc_echo_ops)) {
+ DEBUG(1,("Failed to register rpcecho endpoint\n"));
+ }
+}