summaryrefslogtreecommitdiff
path: root/source4/ntvfs/ipc/np_echo.c
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2006-01-28 12:58:38 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:51:34 -0500
commitad6303f82fa862111c239b32b39f299e563a0802 (patch)
tree8534fe0fab5b44b8f50f70c46141225704e3de42 /source4/ntvfs/ipc/np_echo.c
parent654a21178fa7e908e3a2be42d5522ea1b1b23250 (diff)
downloadsamba-ad6303f82fa862111c239b32b39f299e563a0802.tar.gz
samba-ad6303f82fa862111c239b32b39f299e563a0802.tar.bz2
samba-ad6303f82fa862111c239b32b39f299e563a0802.zip
r13208: Clearly separate named pipes from the IPC$ NTVFS type.
This allows the easy addition of additional named pipes and removes the circular dependencies between the CIFS, RPC and RAP servers. Simple tests for a custom named pipe included. (This used to be commit 898d15acbd18e3b302a856c847e08c22c5024792)
Diffstat (limited to 'source4/ntvfs/ipc/np_echo.c')
-rw-r--r--source4/ntvfs/ipc/np_echo.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/source4/ntvfs/ipc/np_echo.c b/source4/ntvfs/ipc/np_echo.c
new file mode 100644
index 0000000000..bfa0083b79
--- /dev/null
+++ b/source4/ntvfs/ipc/np_echo.c
@@ -0,0 +1,77 @@
+/*
+ Unix SMB/CIFS implementation.
+ DCE/RPC over named pipes support (glue between dcerpc and smb servers)
+
+ Copyright (C) Jelmer Vernooij 2005
+
+ 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"
+#include "lib/socket/socket.h"
+#include "lib/events/events.h"
+#include "rpc_server/dcerpc_server.h"
+#include "ntvfs/ipc/ipc.h"
+
+static NTSTATUS echo_pipe_open (void *context_data, const char *path, struct auth_session_info *session_info, struct stream_connection *srv_conn, TALLOC_CTX *mem_ctx, void **private_data)
+{
+ *private_data = talloc_zero(mem_ctx, DATA_BLOB);
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS echo_pipe_trans(void *private_data, DATA_BLOB *in, DATA_BLOB *out)
+{
+ memcpy(out->data, in->data, MIN(out->length,in->length));
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS echo_pipe_write(void *private_data, DATA_BLOB *out)
+{
+ DATA_BLOB *cache = private_data;
+ return data_blob_append(cache, cache, out->data, out->length);
+}
+
+static NTSTATUS echo_pipe_read(void *private_data, DATA_BLOB *in)
+{
+ uint8_t *newdata;
+ DATA_BLOB *cache = private_data;
+ uint32_t numread = MIN(in->length, cache->length);
+
+ memcpy(in->data, cache->data, numread);
+
+ cache->length -= numread;
+ newdata = talloc_memdup(cache, cache+numread, cache->length);
+ if (newdata == NULL)
+ return NT_STATUS_NO_MEMORY;
+
+ talloc_free(cache->data);
+ cache->data = newdata;
+
+ return NT_STATUS_OK;
+}
+
+const struct named_pipe_ops echo_pipe_ops = {
+ .open = echo_pipe_open,
+ .write = echo_pipe_write,
+ .read = echo_pipe_read,
+ .trans = echo_pipe_trans
+};
+
+NTSTATUS np_echo_init(void)
+{
+ return named_pipe_listen("\\PIPE\\NPECHO", &echo_pipe_ops, NULL);
+}