Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : test suite for rpc ntsvcs operations
4 :
5 : Copyright (C) Guenther 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, write to the Free Software
19 : Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 : */
21 :
22 : #include "includes.h"
23 : #include "torture/rpc/torture_rpc.h"
24 : #include "librpc/gen_ndr/ndr_ntsvcs_c.h"
25 :
26 0 : static bool test_PNP_GetVersion(struct torture_context *tctx,
27 : struct dcerpc_pipe *p)
28 : {
29 0 : struct dcerpc_binding_handle *b = p->binding_handle;
30 : NTSTATUS status;
31 : struct PNP_GetVersion r;
32 0 : uint16_t version = 0;
33 :
34 0 : r.out.version = &version;
35 :
36 0 : status = dcerpc_PNP_GetVersion_r(b, tctx, &r);
37 :
38 0 : torture_assert_ntstatus_ok(tctx, status, "PNP_GetVersion");
39 0 : torture_assert_werr_ok(tctx, r.out.result, "PNP_GetVersion");
40 0 : torture_assert_int_equal(tctx, version, 0x400, "invalid version");
41 :
42 0 : return true;
43 : }
44 :
45 0 : static bool test_PNP_GetDeviceListSize(struct torture_context *tctx,
46 : struct dcerpc_pipe *p)
47 : {
48 0 : struct dcerpc_binding_handle *b = p->binding_handle;
49 : struct PNP_GetDeviceListSize r;
50 0 : uint32_t size = 0;
51 :
52 0 : r.in.devicename = NULL;
53 0 : r.in.flags = CM_GETIDLIST_FILTER_SERVICE;
54 0 : r.out.size = &size;
55 :
56 0 : torture_assert_ntstatus_ok(tctx,
57 : dcerpc_PNP_GetDeviceListSize_r(b, tctx, &r),
58 : "PNP_GetDeviceListSize");
59 0 : torture_assert_werr_equal(tctx, r.out.result, WERR_CM_INVALID_POINTER,
60 : "PNP_GetDeviceListSize");
61 :
62 0 : r.in.devicename = "Spooler";
63 :
64 0 : torture_assert_ntstatus_ok(tctx,
65 : dcerpc_PNP_GetDeviceListSize_r(b, tctx, &r),
66 : "PNP_GetDeviceListSize");
67 0 : torture_assert_werr_ok(tctx, r.out.result,
68 : "PNP_GetDeviceListSize");
69 :
70 0 : return true;
71 : }
72 :
73 0 : static bool test_PNP_GetDeviceList(struct torture_context *tctx,
74 : struct dcerpc_pipe *p)
75 : {
76 0 : struct dcerpc_binding_handle *b = p->binding_handle;
77 : struct PNP_GetDeviceList r;
78 0 : uint16_t *buffer = NULL;
79 0 : uint32_t length = 0;
80 :
81 0 : buffer = talloc_array(tctx, uint16_t, 0);
82 :
83 0 : r.in.filter = NULL;
84 0 : r.in.flags = CM_GETIDLIST_FILTER_SERVICE;
85 0 : r.in.length = &length;
86 0 : r.out.length = &length;
87 0 : r.out.buffer = buffer;
88 :
89 0 : torture_assert_ntstatus_ok(tctx,
90 : dcerpc_PNP_GetDeviceList_r(b, tctx, &r),
91 : "PNP_GetDeviceList failed");
92 0 : torture_assert_werr_equal(tctx, r.out.result, WERR_CM_INVALID_POINTER,
93 : "PNP_GetDeviceList failed");
94 :
95 0 : r.in.filter = "Spooler";
96 :
97 0 : torture_assert_ntstatus_ok(tctx,
98 : dcerpc_PNP_GetDeviceList_r(b, tctx, &r),
99 : "PNP_GetDeviceList failed");
100 :
101 0 : if (W_ERROR_EQUAL(r.out.result, WERR_CM_BUFFER_SMALL)) {
102 : struct PNP_GetDeviceListSize s;
103 :
104 0 : s.in.devicename = "Spooler";
105 0 : s.in.flags = CM_GETIDLIST_FILTER_SERVICE;
106 0 : s.out.size = &length;
107 :
108 0 : torture_assert_ntstatus_ok(tctx,
109 : dcerpc_PNP_GetDeviceListSize_r(b, tctx, &s),
110 : "PNP_GetDeviceListSize failed");
111 0 : torture_assert_werr_ok(tctx, s.out.result,
112 : "PNP_GetDeviceListSize failed");
113 : }
114 :
115 0 : buffer = talloc_array(tctx, uint16_t, length);
116 :
117 0 : r.in.length = &length;
118 0 : r.out.length = &length;
119 0 : r.out.buffer = buffer;
120 :
121 0 : torture_assert_ntstatus_ok(tctx,
122 : dcerpc_PNP_GetDeviceList_r(b, tctx, &r),
123 : "PNP_GetDeviceList failed");
124 :
125 0 : torture_assert_werr_ok(tctx, r.out.result,
126 : "PNP_GetDeviceList failed");
127 :
128 0 : return true;
129 : }
130 :
131 0 : static bool test_PNP_GetDeviceRegProp(struct torture_context *tctx,
132 : struct dcerpc_pipe *p)
133 : {
134 0 : struct dcerpc_binding_handle *b = p->binding_handle;
135 : NTSTATUS status;
136 : struct PNP_GetDeviceRegProp r;
137 :
138 0 : enum winreg_Type reg_data_type = REG_NONE;
139 0 : uint32_t buffer_size = 0;
140 0 : uint32_t needed = 0;
141 : uint8_t *buffer;
142 :
143 0 : buffer = talloc(tctx, uint8_t);
144 :
145 0 : r.in.devicepath = "ACPI\\ACPI0003\\1";
146 0 : r.in.property = DEV_REGPROP_DESC;
147 0 : r.in.flags = 0;
148 0 : r.in.reg_data_type = ®_data_type;
149 0 : r.in.buffer_size = &buffer_size;
150 0 : r.in.needed = &needed;
151 0 : r.out.buffer = buffer;
152 0 : r.out.reg_data_type = ®_data_type;
153 0 : r.out.buffer_size = &buffer_size;
154 0 : r.out.needed = &needed;
155 :
156 0 : status = dcerpc_PNP_GetDeviceRegProp_r(b, tctx, &r);
157 0 : torture_assert_ntstatus_ok(tctx, status, "PNP_GetDeviceRegProp");
158 :
159 0 : if (W_ERROR_EQUAL(r.out.result, WERR_CM_BUFFER_SMALL)) {
160 :
161 0 : buffer = talloc_array(tctx, uint8_t, needed);
162 0 : r.in.buffer_size = &needed;
163 :
164 0 : status = dcerpc_PNP_GetDeviceRegProp_r(b, tctx, &r);
165 0 : torture_assert_ntstatus_ok(tctx, status, "PNP_GetDeviceRegProp");
166 : }
167 :
168 0 : return true;
169 : }
170 :
171 964 : struct torture_suite *torture_rpc_ntsvcs(TALLOC_CTX *mem_ctx)
172 : {
173 : struct torture_rpc_tcase *tcase;
174 964 : struct torture_suite *suite = torture_suite_create(mem_ctx, "ntsvcs");
175 :
176 964 : tcase = torture_suite_add_rpc_iface_tcase(suite, "ntsvcs",
177 : &ndr_table_ntsvcs);
178 :
179 964 : torture_rpc_tcase_add_test(tcase, "PNP_GetDeviceRegProp",
180 : test_PNP_GetDeviceRegProp);
181 964 : torture_rpc_tcase_add_test(tcase, "PNP_GetDeviceList",
182 : test_PNP_GetDeviceList);
183 964 : torture_rpc_tcase_add_test(tcase, "PNP_GetDeviceListSize",
184 : test_PNP_GetDeviceListSize);
185 964 : torture_rpc_tcase_add_test(tcase, "PNP_GetVersion",
186 : test_PNP_GetVersion);
187 :
188 964 : return suite;
189 : }
|