1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | RPC pipe client
|
---|
4 |
|
---|
5 | Copyright (C) GÃŒnther Deschner 2007
|
---|
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 3 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, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "includes.h"
|
---|
22 | #include "rpcclient.h"
|
---|
23 | #include "../librpc/gen_ndr/cli_wkssvc.h"
|
---|
24 |
|
---|
25 | static WERROR cmd_wkssvc_wkstagetinfo(struct rpc_pipe_client *cli,
|
---|
26 | TALLOC_CTX *mem_ctx,
|
---|
27 | int argc,
|
---|
28 | const char **argv)
|
---|
29 | {
|
---|
30 | NTSTATUS status;
|
---|
31 | WERROR werr;
|
---|
32 | uint32_t level = 100;
|
---|
33 | union wkssvc_NetWkstaInfo info;
|
---|
34 | const char *server_name;
|
---|
35 |
|
---|
36 | if (argc > 2) {
|
---|
37 | printf("usage: %s <level>\n", argv[0]);
|
---|
38 | return WERR_OK;
|
---|
39 | }
|
---|
40 |
|
---|
41 | if (argc > 1) {
|
---|
42 | level = atoi(argv[1]);
|
---|
43 | }
|
---|
44 |
|
---|
45 | server_name = cli->desthost;
|
---|
46 |
|
---|
47 | status = rpccli_wkssvc_NetWkstaGetInfo(cli, mem_ctx,
|
---|
48 | server_name,
|
---|
49 | level,
|
---|
50 | &info,
|
---|
51 | &werr);
|
---|
52 | if (!NT_STATUS_IS_OK(status)) {
|
---|
53 | return ntstatus_to_werror(status);
|
---|
54 | }
|
---|
55 |
|
---|
56 | return werr;
|
---|
57 | }
|
---|
58 |
|
---|
59 | static WERROR cmd_wkssvc_getjoininformation(struct rpc_pipe_client *cli,
|
---|
60 | TALLOC_CTX *mem_ctx,
|
---|
61 | int argc,
|
---|
62 | const char **argv)
|
---|
63 | {
|
---|
64 | const char *server_name;
|
---|
65 | const char *name_buffer;
|
---|
66 | enum wkssvc_NetJoinStatus name_type;
|
---|
67 | NTSTATUS status;
|
---|
68 | WERROR werr;
|
---|
69 |
|
---|
70 | server_name = cli->desthost;
|
---|
71 | name_buffer = "";
|
---|
72 |
|
---|
73 | status = rpccli_wkssvc_NetrGetJoinInformation(cli, mem_ctx,
|
---|
74 | server_name,
|
---|
75 | &name_buffer,
|
---|
76 | &name_type,
|
---|
77 | &werr);
|
---|
78 | if (!NT_STATUS_IS_OK(status)) {
|
---|
79 | return ntstatus_to_werror(status);
|
---|
80 | }
|
---|
81 |
|
---|
82 | if (W_ERROR_IS_OK(werr)) {
|
---|
83 | printf("%s (%d)\n", name_buffer, name_type);
|
---|
84 | }
|
---|
85 |
|
---|
86 | return werr;
|
---|
87 | }
|
---|
88 |
|
---|
89 | static WERROR cmd_wkssvc_messagebuffersend(struct rpc_pipe_client *cli,
|
---|
90 | TALLOC_CTX *mem_ctx,
|
---|
91 | int argc,
|
---|
92 | const char **argv)
|
---|
93 | {
|
---|
94 | const char *server_name = cli->desthost;
|
---|
95 | const char *message_name = cli->desthost;
|
---|
96 | const char *message_sender_name = cli->desthost;
|
---|
97 | smb_ucs2_t *message_buffer = NULL;
|
---|
98 | size_t message_size = 0;
|
---|
99 | const char *message = "my message";
|
---|
100 | NTSTATUS status;
|
---|
101 | WERROR werr;
|
---|
102 |
|
---|
103 | if (argc > 1) {
|
---|
104 | message = argv[1];
|
---|
105 | }
|
---|
106 |
|
---|
107 | if (!push_ucs2_talloc(mem_ctx, &message_buffer, message,
|
---|
108 | &message_size))
|
---|
109 | {
|
---|
110 | return WERR_NOMEM;
|
---|
111 | }
|
---|
112 |
|
---|
113 | status = rpccli_wkssvc_NetrMessageBufferSend(cli, mem_ctx,
|
---|
114 | server_name,
|
---|
115 | message_name,
|
---|
116 | message_sender_name,
|
---|
117 | (uint8_t *)message_buffer,
|
---|
118 | message_size,
|
---|
119 | &werr);
|
---|
120 | if (!NT_STATUS_IS_OK(status)) {
|
---|
121 | return ntstatus_to_werror(status);
|
---|
122 | }
|
---|
123 |
|
---|
124 | return werr;
|
---|
125 | }
|
---|
126 |
|
---|
127 | static WERROR cmd_wkssvc_enumeratecomputernames(struct rpc_pipe_client *cli,
|
---|
128 | TALLOC_CTX *mem_ctx,
|
---|
129 | int argc,
|
---|
130 | const char **argv)
|
---|
131 | {
|
---|
132 | const char *server_name;
|
---|
133 | enum wkssvc_ComputerNameType name_type = NetAllComputerNames;
|
---|
134 | NTSTATUS status;
|
---|
135 | struct wkssvc_ComputerNamesCtr *ctr = NULL;
|
---|
136 | WERROR werr;
|
---|
137 |
|
---|
138 | server_name = cli->desthost;
|
---|
139 |
|
---|
140 | if (argc >= 2) {
|
---|
141 | name_type = atoi(argv[1]);
|
---|
142 | }
|
---|
143 |
|
---|
144 | status = rpccli_wkssvc_NetrEnumerateComputerNames(cli, mem_ctx,
|
---|
145 | server_name,
|
---|
146 | name_type, 0,
|
---|
147 | &ctr,
|
---|
148 | &werr);
|
---|
149 | if (!NT_STATUS_IS_OK(status)) {
|
---|
150 | return ntstatus_to_werror(status);
|
---|
151 | }
|
---|
152 |
|
---|
153 | if (W_ERROR_IS_OK(werr)) {
|
---|
154 | int i=0;
|
---|
155 | for (i = 0; i < ctr->count; i++) {
|
---|
156 | printf("name: %d %s\n", i, ctr->computer_name->string);
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | return werr;
|
---|
161 | }
|
---|
162 |
|
---|
163 | static WERROR cmd_wkssvc_enumerateusers(struct rpc_pipe_client *cli,
|
---|
164 | TALLOC_CTX *mem_ctx,
|
---|
165 | int argc,
|
---|
166 | const char **argv)
|
---|
167 | {
|
---|
168 | const char *server_name;
|
---|
169 | NTSTATUS status;
|
---|
170 | struct wkssvc_NetWkstaEnumUsersInfo info;
|
---|
171 | WERROR werr;
|
---|
172 | uint32_t i, num_entries, resume_handle;
|
---|
173 |
|
---|
174 | server_name = cli->desthost;
|
---|
175 |
|
---|
176 | ZERO_STRUCT(info);
|
---|
177 |
|
---|
178 | if (argc >= 2) {
|
---|
179 | info.level = atoi(argv[1]);
|
---|
180 | }
|
---|
181 |
|
---|
182 | status = rpccli_wkssvc_NetWkstaEnumUsers(cli, mem_ctx, server_name,
|
---|
183 | &info, 1000, &num_entries,
|
---|
184 | &resume_handle, &werr);
|
---|
185 | if (!NT_STATUS_IS_OK(status)) {
|
---|
186 | return ntstatus_to_werror(status);
|
---|
187 | }
|
---|
188 | if (!W_ERROR_IS_OK(werr)) {
|
---|
189 | return werr;
|
---|
190 | }
|
---|
191 |
|
---|
192 | for (i=0; i<num_entries; i++) {
|
---|
193 | const char *user = NULL;
|
---|
194 | switch (info.level) {
|
---|
195 | case 0:
|
---|
196 | user = info.ctr.user0->user0[i].user_name;
|
---|
197 | break;
|
---|
198 | case 1:
|
---|
199 | user = talloc_asprintf(
|
---|
200 | talloc_tos(), "%s\\%s",
|
---|
201 | info.ctr.user1->user1[i].logon_domain,
|
---|
202 | info.ctr.user1->user1[i].user_name);
|
---|
203 | break;
|
---|
204 | }
|
---|
205 | printf("%s\n", user ? user : "(null)");
|
---|
206 | }
|
---|
207 |
|
---|
208 | return werr;
|
---|
209 | }
|
---|
210 |
|
---|
211 | struct cmd_set wkssvc_commands[] = {
|
---|
212 |
|
---|
213 | { "WKSSVC" },
|
---|
214 | { "wkssvc_wkstagetinfo", RPC_RTYPE_WERROR, NULL, cmd_wkssvc_wkstagetinfo, &ndr_table_wkssvc.syntax_id, NULL, "Query WKSSVC Workstation Information", "" },
|
---|
215 | { "wkssvc_getjoininformation", RPC_RTYPE_WERROR, NULL, cmd_wkssvc_getjoininformation, &ndr_table_wkssvc.syntax_id, NULL, "Query WKSSVC Join Information", "" },
|
---|
216 | { "wkssvc_messagebuffersend", RPC_RTYPE_WERROR, NULL, cmd_wkssvc_messagebuffersend, &ndr_table_wkssvc.syntax_id, NULL, "Send WKSSVC message", "" },
|
---|
217 | { "wkssvc_enumeratecomputernames", RPC_RTYPE_WERROR, NULL, cmd_wkssvc_enumeratecomputernames, &ndr_table_wkssvc.syntax_id, NULL, "Enumerate WKSSVC computer names", "" },
|
---|
218 | { "wkssvc_enumerateusers", RPC_RTYPE_WERROR, NULL,
|
---|
219 | cmd_wkssvc_enumerateusers, &ndr_table_wkssvc.syntax_id, NULL,
|
---|
220 | "Enumerate WKSSVC users", "" },
|
---|
221 | { NULL }
|
---|
222 | };
|
---|