Add ntsvcs_getdevregprop command to rpcclient.
[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_get_device_list_size(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 *devicename = NULL;
86         uint32_t flags = 0;
87         uint32_t size = 0;
88
89         if (argc < 2 || argc > 4) {
90                 printf("usage: %s [devicename] <flags>\n", argv[0]);
91                 return WERR_OK;
92         }
93
94         devicename = argv[1];
95
96         if (argc >= 3) {
97                 flags = atoi(argv[2]);
98         }
99
100         status = rpccli_PNP_GetDeviceListSize(cli, mem_ctx,
101                                               devicename,
102                                               &size,
103                                               flags,
104                                               &werr);
105         if (!NT_STATUS_IS_OK(status)) {
106                 return ntstatus_to_werror(status);
107         }
108
109         if (W_ERROR_IS_OK(werr)) {
110                 printf("size: %d\n", size);
111         }
112
113         return werr;
114 }
115
116 static WERROR cmd_ntsvcs_hw_prof_flags(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         const char *devicepath = NULL;
124         uint32_t unk3 = 0;
125         uint16_t unk4 = 0;
126         const char *unk5 = NULL;
127         const char *unk5a = NULL;
128
129         if (argc < 2) {
130                 printf("usage: %s [devicepath]\n", argv[0]);
131                 return WERR_OK;
132         }
133
134         devicepath = argv[1];
135
136         status = rpccli_PNP_HwProfFlags(cli, mem_ctx,
137                                         0,
138                                         devicepath,
139                                         0,
140                                         &unk3,
141                                         &unk4,
142                                         unk5,
143                                         &unk5a,
144                                         0,
145                                         0,
146                                         &werr);
147         if (!NT_STATUS_IS_OK(status)) {
148                 return ntstatus_to_werror(status);
149         }
150
151         return werr;
152 }
153
154 static WERROR cmd_ntsvcs_get_hw_prof_info(struct rpc_pipe_client *cli,
155                                           TALLOC_CTX *mem_ctx,
156                                           int argc,
157                                           const char **argv)
158 {
159         NTSTATUS status;
160         WERROR werr;
161         uint32_t idx = 0;
162         struct PNP_HwProfInfo info;
163         uint32_t unknown1 = 0, unknown2 = 0;
164
165         ZERO_STRUCT(info);
166
167         status = rpccli_PNP_GetHwProfInfo(cli, mem_ctx,
168                                           idx,
169                                           &info,
170                                           unknown1,
171                                           unknown2,
172                                           &werr);
173         if (!NT_STATUS_IS_OK(status)) {
174                 return ntstatus_to_werror(status);
175         }
176
177         return werr;
178 }
179
180 static WERROR cmd_ntsvcs_get_dev_reg_prop(struct rpc_pipe_client *cli,
181                                           TALLOC_CTX *mem_ctx,
182                                           int argc,
183                                           const char **argv)
184 {
185         NTSTATUS status;
186         WERROR werr;
187         const char *devicepath = NULL;
188         uint32_t property = DEV_REGPROP_DESC;
189         uint32_t unknown1 = 0;
190         uint8_t buffer;
191         uint32_t buffer_size = 0;
192         uint32_t unknown2 = 0;
193         uint32_t unknown3 = 0;
194
195         if (argc < 2) {
196                 printf("usage: %s [devicepath]\n", argv[0]);
197                 return WERR_OK;
198         }
199
200         devicepath = argv[1];
201
202         status = rpccli_PNP_GetDeviceRegProp(cli, mem_ctx,
203                                              devicepath,
204                                              property,
205                                              &unknown1,
206                                              &buffer,
207                                              &buffer_size,
208                                              &unknown2,
209                                              unknown3,
210                                              &werr);
211         if (!NT_STATUS_IS_OK(status)) {
212                 return ntstatus_to_werror(status);
213         }
214
215         return werr;
216 }
217
218
219 struct cmd_set ntsvcs_commands[] = {
220
221         { "NTSVCS" },
222         { "ntsvcs_getversion", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_version, PI_NTSVCS, NULL, "Query NTSVCS version", "" },
223         { "ntsvcs_validatedevinst", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_validate_dev_inst, PI_NTSVCS, NULL, "Query NTSVCS device instance", "" },
224         { "ntsvcs_getdevlistsize", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_device_list_size, PI_NTSVCS, NULL, "Query NTSVCS get device list", "" },
225         { "ntsvcs_hwprofflags", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_hw_prof_flags, PI_NTSVCS, NULL, "Query NTSVCS HW prof flags", "" },
226         { "ntsvcs_hwprofinfo", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_hw_prof_info, PI_NTSVCS, NULL, "Query NTSVCS HW prof info", "" },
227         { "ntsvcs_getdevregprop", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_dev_reg_prop, PI_NTSVCS, NULL, "Query NTSVCS device registry property", "" },
228         { NULL }
229 };