1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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);
}
|