Fix a memleak
[Samba.git] / source / rpcclient / cmd_ntsvcs.c
blob377a8a2a00efcb965b63c1744d4ed07ab16d243d
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
5 Copyright (C) Günther Deschner 2008
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.
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.
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/>.
21 #include "includes.h"
22 #include "rpcclient.h"
24 static WERROR cmd_ntsvcs_get_version(struct rpc_pipe_client *cli,
25 TALLOC_CTX *mem_ctx,
26 int argc,
27 const char **argv)
29 NTSTATUS status;
30 WERROR werr;
31 uint16_t version;
33 status = rpccli_PNP_GetVersion(cli, mem_ctx,
34 &version, &werr);
35 if (!NT_STATUS_IS_OK(status)) {
36 return ntstatus_to_werror(status);
39 if (W_ERROR_IS_OK(werr)) {
40 printf("version: %d\n", version);
43 return werr;
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)
51 NTSTATUS status;
52 WERROR werr;
53 const char *devicepath = NULL;
54 uint32_t flags = 0;
56 if (argc < 2 || argc > 3) {
57 printf("usage: %s [devicepath] <flags>\n", argv[0]);
58 return WERR_OK;
61 devicepath = argv[1];
63 if (argc >= 3) {
64 flags = atoi(argv[2]);
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);
75 return werr;
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)
83 NTSTATUS status;
84 WERROR werr;
85 const char *devicename = NULL;
86 uint32_t flags = 0;
87 uint32_t size = 0;
89 if (argc < 2 || argc > 4) {
90 printf("usage: %s [devicename] <flags>\n", argv[0]);
91 return WERR_OK;
94 devicename = argv[1];
96 if (argc >= 3) {
97 flags = atoi(argv[2]);
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);
109 if (W_ERROR_IS_OK(werr)) {
110 printf("size: %d\n", size);
113 return werr;
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)
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;
129 if (argc < 2) {
130 printf("usage: %s [devicepath]\n", argv[0]);
131 return WERR_OK;
134 devicepath = argv[1];
136 status = rpccli_PNP_HwProfFlags(cli, mem_ctx,
138 devicepath,
140 &unk3,
141 &unk4,
142 unk5,
143 &unk5a,
146 &werr);
147 if (!NT_STATUS_IS_OK(status)) {
148 return ntstatus_to_werror(status);
151 return werr;
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)
159 NTSTATUS status;
160 WERROR werr;
161 uint32_t idx = 0;
162 struct PNP_HwProfInfo info;
163 uint32_t unknown1 = 0, unknown2 = 0;
165 ZERO_STRUCT(info);
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);
177 return werr;
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)
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;
195 if (argc < 2) {
196 printf("usage: %s [devicepath]\n", argv[0]);
197 return WERR_OK;
200 devicepath = argv[1];
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);
215 return werr;
219 struct cmd_set ntsvcs_commands[] = {
221 { "NTSVCS" },
222 { "ntsvcs_getversion", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_version, &ndr_table_ntsvcs.syntax_id, NULL, "Query NTSVCS version", "" },
223 { "ntsvcs_validatedevinst", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_validate_dev_inst, &ndr_table_ntsvcs.syntax_id, NULL, "Query NTSVCS device instance", "" },
224 { "ntsvcs_getdevlistsize", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_device_list_size, &ndr_table_ntsvcs.syntax_id, NULL, "Query NTSVCS get device list", "" },
225 { "ntsvcs_hwprofflags", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_hw_prof_flags, &ndr_table_ntsvcs.syntax_id, NULL, "Query NTSVCS HW prof flags", "" },
226 { "ntsvcs_hwprofinfo", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_hw_prof_info, &ndr_table_ntsvcs.syntax_id, NULL, "Query NTSVCS HW prof info", "" },
227 { "ntsvcs_getdevregprop", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_dev_reg_prop, &ndr_table_ntsvcs.syntax_id, NULL, "Query NTSVCS device registry property", "" },
228 { NULL }