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