2 Unix SMB/CIFS implementation.
3 DCE/RPC over named pipes support (glue between dcerpc and smb servers)
5 Copyright (C) Jelmer Vernooij 2005
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "lib/socket/socket.h"
24 #include "lib/events/events.h"
25 #include "rpc_server/dcerpc_server.h"
26 #include "ntvfs/ipc/ipc.h"
28 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)
30 *private_data = talloc_zero(mem_ctx, DATA_BLOB);
35 static NTSTATUS echo_pipe_trans(void *private_data, DATA_BLOB *in, DATA_BLOB *out)
37 memcpy(out->data, in->data, MIN(out->length,in->length));
42 static NTSTATUS echo_pipe_write(void *private_data, DATA_BLOB *out)
44 DATA_BLOB *cache = private_data;
45 return data_blob_append(cache, cache, out->data, out->length);
48 static NTSTATUS echo_pipe_read(void *private_data, DATA_BLOB *in)
51 DATA_BLOB *cache = private_data;
52 uint32_t numread = MIN(in->length, cache->length);
54 memcpy(in->data, cache->data, numread);
56 cache->length -= numread;
57 newdata = talloc_memdup(cache, cache+numread, cache->length);
59 return NT_STATUS_NO_MEMORY;
61 talloc_free(cache->data);
62 cache->data = newdata;
67 const struct named_pipe_ops echo_pipe_ops = {
68 .open = echo_pipe_open,
69 .write = echo_pipe_write,
70 .read = echo_pipe_read,
71 .trans = echo_pipe_trans
74 NTSTATUS np_echo_init(void)
76 return named_pipe_listen("\\PIPE\\NPECHO", &echo_pipe_ops, NULL);