s3: Use dbwrap_parse_record in fetch_share_mode_unlocked
[kai/samba.git] / source3 / rpcclient / cmd_ntsvcs.c
1 /*
2    Unix SMB/CIFS implementation.
3    RPC pipe client
4
5    Copyright (C) G√ľnther Deschner 2008
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/ndr_ntsvcs_c.h"
24
25 static WERROR cmd_ntsvcs_get_version(struct rpc_pipe_client *cli,
26                                      TALLOC_CTX *mem_ctx,
27                                      int argc,
28                                      const char **argv)
29 {
30         struct dcerpc_binding_handle *b = cli->binding_handle;
31         NTSTATUS status;
32         WERROR werr;
33         uint16_t version;
34
35         status = dcerpc_PNP_GetVersion(b, mem_ctx,
36                                        &version, &werr);
37         if (!NT_STATUS_IS_OK(status)) {
38                 return ntstatus_to_werror(status);
39         }
40
41         if (W_ERROR_IS_OK(werr)) {
42                 printf("version: %d\n", version);
43         }
44
45         return werr;
46 }
47
48 static WERROR cmd_ntsvcs_validate_dev_inst(struct rpc_pipe_client *cli,
49                                            TALLOC_CTX *mem_ctx,
50                                            int argc,
51                                            const char **argv)
52 {
53         struct dcerpc_binding_handle *b = cli->binding_handle;
54         NTSTATUS status;
55         WERROR werr;
56         const char *devicepath = NULL;
57         uint32_t flags = 0;
58
59         if (argc < 2 || argc > 3) {
60                 printf("usage: %s [devicepath] <flags>\n", argv[0]);
61                 return WERR_OK;
62         }
63
64         devicepath = argv[1];
65
66         if (argc >= 3) {
67                 flags = atoi(argv[2]);
68         }
69
70         status = dcerpc_PNP_ValidateDeviceInstance(b, mem_ctx,
71                                                    devicepath,
72                                                    flags,
73                                                    &werr);
74         if (!NT_STATUS_IS_OK(status)) {
75                 return ntstatus_to_werror(status);
76         }
77
78         return werr;
79 }
80
81 static WERROR cmd_ntsvcs_hw_prof_flags(struct rpc_pipe_client *cli,
82                                        TALLOC_CTX *mem_ctx,
83                                        int argc,
84                                        const char **argv)
85 {
86         struct dcerpc_binding_handle *b = cli->binding_handle;
87         NTSTATUS status;
88         WERROR werr;
89         const char *devicepath = NULL;
90         uint32_t profile_flags = 0;
91         uint16_t veto_type = 0;
92         const char *unk5 = NULL;
93         const char *unk5a = NULL;
94
95         if (argc < 2) {
96                 printf("usage: %s [devicepath]\n", argv[0]);
97                 return WERR_OK;
98         }
99
100         devicepath = argv[1];
101
102         status = dcerpc_PNP_HwProfFlags(b, mem_ctx,
103                                         0,
104                                         devicepath,
105                                         0,
106                                         &profile_flags,
107                                         &veto_type,
108                                         unk5,
109                                         &unk5a,
110                                         0,
111                                         0,
112                                         &werr);
113         if (!NT_STATUS_IS_OK(status)) {
114                 return ntstatus_to_werror(status);
115         }
116
117         return werr;
118 }
119
120 static WERROR cmd_ntsvcs_get_hw_prof_info(struct rpc_pipe_client *cli,
121                                           TALLOC_CTX *mem_ctx,
122                                           int argc,
123                                           const char **argv)
124 {
125         struct dcerpc_binding_handle *b = cli->binding_handle;
126         NTSTATUS status;
127         WERROR werr;
128         uint32_t idx = 0;
129         struct PNP_HwProfInfo info;
130         uint32_t size = 0, flags = 0;
131
132         ZERO_STRUCT(info);
133
134         status = dcerpc_PNP_GetHwProfInfo(b, mem_ctx,
135                                           idx,
136                                           &info,
137                                           size,
138                                           flags,
139                                           &werr);
140         if (!NT_STATUS_IS_OK(status)) {
141                 return ntstatus_to_werror(status);
142         }
143
144         return werr;
145 }
146
147 static WERROR cmd_ntsvcs_get_dev_reg_prop(struct rpc_pipe_client *cli,
148                                           TALLOC_CTX *mem_ctx,
149                                           int argc,
150                                           const char **argv)
151 {
152         struct dcerpc_binding_handle *b = cli->binding_handle;
153         NTSTATUS status;
154         WERROR werr;
155         const char *devicepath = NULL;
156         uint32_t property = DEV_REGPROP_DESC;
157         uint32_t reg_data_type = REG_NONE;
158         uint8_t *buffer;
159         uint32_t buffer_size = 0;
160         uint32_t needed = 0;
161         uint32_t flags = 0;
162
163         if (argc < 2) {
164                 printf("usage: %s [devicepath] [buffersize]\n", argv[0]);
165                 return WERR_OK;
166         }
167
168         devicepath = argv[1];
169
170         if (argc >= 3) {
171                 buffer_size = atoi(argv[2]);
172                 needed = buffer_size;
173         }
174
175         buffer = talloc_array(mem_ctx, uint8_t, buffer_size);
176         W_ERROR_HAVE_NO_MEMORY(buffer);
177
178         status = dcerpc_PNP_GetDeviceRegProp(b, mem_ctx,
179                                              devicepath,
180                                              property,
181                                              &reg_data_type,
182                                              buffer,
183                                              &buffer_size,
184                                              &needed,
185                                              flags,
186                                              &werr);
187         if (!NT_STATUS_IS_OK(status)) {
188                 return ntstatus_to_werror(status);
189         }
190
191         return werr;
192 }
193
194 static WERROR cmd_ntsvcs_get_dev_list_size(struct rpc_pipe_client *cli,
195                                            TALLOC_CTX *mem_ctx,
196                                            int argc,
197                                            const char **argv)
198 {
199         struct dcerpc_binding_handle *b = cli->binding_handle;
200         NTSTATUS status;
201         WERROR werr;
202         uint32_t size = 0;
203         uint32_t flags = 0;
204         const char *filter = NULL;
205
206         if (argc > 3) {
207                 printf("usage: %s [filter] [flags]\n", argv[0]);
208                 return WERR_OK;
209         }
210
211         if (argc >= 2) {
212                 filter = argv[1];
213         }
214
215         if (argc >= 3) {
216                 flags = atoi(argv[2]);
217         }
218
219         status = dcerpc_PNP_GetDeviceListSize(b, mem_ctx,
220                                               filter,
221                                               &size,
222                                               flags,
223                                               &werr);
224         if (!NT_STATUS_IS_OK(status)) {
225                 return ntstatus_to_werror(status);
226         }
227
228         printf("size: %d\n", size);
229
230         return werr;
231 }
232
233 static WERROR cmd_ntsvcs_get_dev_list(struct rpc_pipe_client *cli,
234                                       TALLOC_CTX *mem_ctx,
235                                       int argc,
236                                       const char **argv)
237 {
238         struct dcerpc_binding_handle *b = cli->binding_handle;
239         NTSTATUS status;
240         WERROR werr;
241         const char *filter = NULL;
242         uint16_t *buffer = NULL;
243         uint32_t length = 0;
244         uint32_t flags = 0;
245
246         if (argc > 4) {
247                 printf("usage: %s [filter] [length] [flags]\n", argv[0]);
248                 return WERR_OK;
249         }
250
251         if (argc >= 2) {
252                 filter = argv[1];
253         }
254
255         if (argc >= 3) {
256                 length = atoi(argv[2]);
257         }
258
259         if (argc >= 4) {
260                 flags = atoi(argv[3]);
261         }
262
263         buffer = talloc(mem_ctx, uint16_t);
264         if (!buffer) {
265                 return WERR_NOMEM;
266         }
267
268         status = dcerpc_PNP_GetDeviceList(b, mem_ctx,
269                                           filter,
270                                           buffer,
271                                           &length,
272                                           flags,
273                                           &werr);
274         if (!NT_STATUS_IS_OK(status)) {
275                 return ntstatus_to_werror(status);
276         }
277
278         printf("devlist needs size: %d\n", length);
279
280         return werr;
281 }
282
283 struct cmd_set ntsvcs_commands[] = {
284
285         { "NTSVCS" },
286         { "ntsvcs_getversion", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_version, &ndr_table_ntsvcs, NULL, "Query NTSVCS version", "" },
287         { "ntsvcs_validatedevinst", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_validate_dev_inst, &ndr_table_ntsvcs, NULL, "Query NTSVCS device instance", "" },
288         { "ntsvcs_hwprofflags", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_hw_prof_flags, &ndr_table_ntsvcs, NULL, "Query NTSVCS HW prof flags", "" },
289         { "ntsvcs_hwprofinfo", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_hw_prof_info, &ndr_table_ntsvcs, NULL, "Query NTSVCS HW prof info", "" },
290         { "ntsvcs_getdevregprop", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_dev_reg_prop, &ndr_table_ntsvcs, NULL, "Query NTSVCS device registry property", "" },
291         { "ntsvcs_getdevlistsize", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_dev_list_size, &ndr_table_ntsvcs, NULL, "Query NTSVCS device list size", "" },
292         { "ntsvcs_getdevlist", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_dev_list, &ndr_table_ntsvcs, NULL, "Query NTSVCS device list", "" },
293         { NULL }
294 };