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