Add ntsvcs_hwprofinfo command to rpcclient.
[gd/samba/.git] / source / 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 struct cmd_set ntsvcs_commands[] = {
181
182         { "NTSVCS" },
183         { "ntsvcs_getversion", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_version, PI_NTSVCS, NULL, "Query NTSVCS version", "" },
184         { "ntsvcs_validatedevinst", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_validate_dev_inst, PI_NTSVCS, NULL, "Query NTSVCS device instance", "" },
185         { "ntsvcs_getdevlistsize", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_device_list_size, PI_NTSVCS, NULL, "Query NTSVCS get device list", "" },
186         { "ntsvcs_hwprofflags", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_hw_prof_flags, PI_NTSVCS, NULL, "Query NTSVCS HW prof flags", "" },
187         { "ntsvcs_hwprofinfo", RPC_RTYPE_WERROR, NULL, cmd_ntsvcs_get_hw_prof_info, PI_NTSVCS, NULL, "Query NTSVCS HW prof info", "" },
188         { NULL }
189 };