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