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