1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | RPC pipe client
|
---|
4 |
|
---|
5 | Copyright (C) Tim Potter 2003
|
---|
6 |
|
---|
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.
|
---|
11 |
|
---|
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.
|
---|
16 |
|
---|
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.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "includes.h"
|
---|
23 | #include "rpcclient.h"
|
---|
24 |
|
---|
25 | static NTSTATUS cmd_echo_add_one(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
|
---|
26 | int argc, const char **argv)
|
---|
27 | {
|
---|
28 | uint32 request = 1, response;
|
---|
29 | NTSTATUS result;
|
---|
30 |
|
---|
31 | if (argc > 2) {
|
---|
32 | printf("Usage: %s [num]\n", argv[0]);
|
---|
33 | return NT_STATUS_OK;
|
---|
34 | }
|
---|
35 |
|
---|
36 | if (argc == 2)
|
---|
37 | request = atoi(argv[1]);
|
---|
38 |
|
---|
39 | result = rpccli_echo_add_one(cli, mem_ctx, request, &response);
|
---|
40 |
|
---|
41 | if (!NT_STATUS_IS_OK(result))
|
---|
42 | goto done;
|
---|
43 |
|
---|
44 | printf("%d + 1 = %d\n", request, response);
|
---|
45 |
|
---|
46 | done:
|
---|
47 | return result;
|
---|
48 | }
|
---|
49 |
|
---|
50 | static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
|
---|
51 | int argc, const char **argv)
|
---|
52 | {
|
---|
53 | uint32 size, i;
|
---|
54 | NTSTATUS result;
|
---|
55 | char *in_data = NULL, *out_data = NULL;
|
---|
56 |
|
---|
57 | if (argc != 2) {
|
---|
58 | printf("Usage: %s num\n", argv[0]);
|
---|
59 | return NT_STATUS_OK;
|
---|
60 | }
|
---|
61 |
|
---|
62 | size = atoi(argv[1]);
|
---|
63 | in_data = SMB_MALLOC(size);
|
---|
64 |
|
---|
65 | for (i = 0; i < size; i++)
|
---|
66 | in_data[i] = i & 0xff;
|
---|
67 |
|
---|
68 | result = rpccli_echo_data(cli, mem_ctx, size, in_data, &out_data);
|
---|
69 |
|
---|
70 | if (!NT_STATUS_IS_OK(result))
|
---|
71 | goto done;
|
---|
72 |
|
---|
73 | for (i = 0; i < size; i++) {
|
---|
74 | if (in_data[i] != out_data[i]) {
|
---|
75 | printf("mismatch at offset %d, %d != %d\n",
|
---|
76 | i, in_data[i], out_data[i]);
|
---|
77 | result = NT_STATUS_UNSUCCESSFUL;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | done:
|
---|
82 | SAFE_FREE(in_data);
|
---|
83 |
|
---|
84 | return result;
|
---|
85 | }
|
---|
86 |
|
---|
87 | static NTSTATUS cmd_echo_source_data(struct rpc_pipe_client *cli,
|
---|
88 | TALLOC_CTX *mem_ctx, int argc,
|
---|
89 | const char **argv)
|
---|
90 | {
|
---|
91 | uint32 size, i;
|
---|
92 | NTSTATUS result;
|
---|
93 | char *out_data = NULL;
|
---|
94 |
|
---|
95 | if (argc != 2) {
|
---|
96 | printf("Usage: %s num\n", argv[0]);
|
---|
97 | return NT_STATUS_OK;
|
---|
98 | }
|
---|
99 |
|
---|
100 | size = atoi(argv[1]);
|
---|
101 |
|
---|
102 | result = rpccli_echo_source_data(cli, mem_ctx, size, &out_data);
|
---|
103 |
|
---|
104 | if (!NT_STATUS_IS_OK(result))
|
---|
105 | goto done;
|
---|
106 |
|
---|
107 | for (i = 0; i < size; i++) {
|
---|
108 | if (out_data && out_data[i] != (i & 0xff)) {
|
---|
109 | printf("mismatch at offset %d, %d != %d\n",
|
---|
110 | i, out_data[i], i & 0xff);
|
---|
111 | result = NT_STATUS_UNSUCCESSFUL;
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | done:
|
---|
116 | return result;
|
---|
117 | }
|
---|
118 |
|
---|
119 | static NTSTATUS cmd_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
|
---|
120 | int argc, const char **argv)
|
---|
121 | {
|
---|
122 | uint32 size, i;
|
---|
123 | NTSTATUS result;
|
---|
124 | char *in_data = NULL;
|
---|
125 |
|
---|
126 | if (argc != 2) {
|
---|
127 | printf("Usage: %s num\n", argv[0]);
|
---|
128 | return NT_STATUS_OK;
|
---|
129 | }
|
---|
130 |
|
---|
131 | size = atoi(argv[1]);
|
---|
132 | in_data = SMB_MALLOC(size);
|
---|
133 |
|
---|
134 | for (i = 0; i < size; i++)
|
---|
135 | in_data[i] = i & 0xff;
|
---|
136 |
|
---|
137 | result = rpccli_echo_sink_data(cli, mem_ctx, size, in_data);
|
---|
138 |
|
---|
139 | if (!NT_STATUS_IS_OK(result))
|
---|
140 | goto done;
|
---|
141 |
|
---|
142 | done:
|
---|
143 | SAFE_FREE(in_data);
|
---|
144 |
|
---|
145 | return result;
|
---|
146 | }
|
---|
147 |
|
---|
148 | /* List of commands exported by this module */
|
---|
149 |
|
---|
150 | struct cmd_set echo_commands[] = {
|
---|
151 |
|
---|
152 | { "ECHO" },
|
---|
153 |
|
---|
154 | { "echoaddone", RPC_RTYPE_NTSTATUS, cmd_echo_add_one, NULL, PI_ECHO, NULL, "Add one to a number", "" },
|
---|
155 | { "echodata", RPC_RTYPE_NTSTATUS, cmd_echo_data, NULL, PI_ECHO, NULL, "Echo data", "" },
|
---|
156 | { "sinkdata", RPC_RTYPE_NTSTATUS, cmd_echo_sink_data, NULL, PI_ECHO, NULL, "Sink data", "" },
|
---|
157 | { "sourcedata", RPC_RTYPE_NTSTATUS, cmd_echo_source_data, NULL, PI_ECHO, NULL, "Source data", "" },
|
---|
158 | { NULL }
|
---|
159 | };
|
---|