2 Unix SMB/CIFS implementation.
3 test suite for srvsvc rpc operations
5 Copyright (C) Jelmer Vernooij 2004
6 Copyright (C) Guenther Deschner 2008
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_svcctl_c.h"
25 #include "librpc/gen_ndr/ndr_svcctl.h"
26 #include "torture/rpc/rpc.h"
27 #include "param/param.h"
29 static bool test_OpenSCManager(struct dcerpc_pipe *p, struct torture_context *tctx, struct policy_handle *h)
31 struct svcctl_OpenSCManagerW r;
33 r.in.MachineName = NULL;
34 r.in.DatabaseName = NULL;
35 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
38 torture_assert_ntstatus_ok(tctx,
39 dcerpc_svcctl_OpenSCManagerW(p, tctx, &r),
40 "OpenSCManager failed!");
45 static bool test_CloseServiceHandle(struct dcerpc_pipe *p, struct torture_context *tctx, struct policy_handle *h)
47 struct svcctl_CloseServiceHandle r;
51 torture_assert_ntstatus_ok(tctx,
52 dcerpc_svcctl_CloseServiceHandle(p, tctx, &r),
53 "CloseServiceHandle failed");
58 static bool test_OpenService(struct dcerpc_pipe *p, struct torture_context *tctx,
59 struct policy_handle *h, const char *name, struct policy_handle *s)
61 struct svcctl_OpenServiceW r;
63 r.in.scmanager_handle = h;
64 r.in.ServiceName = name;
65 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
68 torture_assert_ntstatus_ok(tctx,
69 dcerpc_svcctl_OpenServiceW(p, tctx, &r),
70 "OpenServiceW failed!");
71 torture_assert_werr_ok(tctx, r.out.result, "OpenServiceW failed!");
77 static bool test_QueryServiceStatusEx(struct torture_context *tctx, struct dcerpc_pipe *p)
79 struct svcctl_QueryServiceStatusEx r;
80 struct policy_handle h, s;
83 uint32_t info_level = SVC_STATUS_PROCESS_INFO;
88 if (!test_OpenSCManager(p, tctx, &h))
91 if (!test_OpenService(p, tctx, &h, "Netlogon", &s))
94 buffer = talloc(tctx, uint8_t);
97 r.in.info_level = info_level;
98 r.in.offered = offered;
99 r.out.buffer = buffer;
100 r.out.needed = &needed;
102 status = dcerpc_svcctl_QueryServiceStatusEx(p, tctx, &r);
103 torture_assert_ntstatus_ok(tctx, status, "QueryServiceStatusEx failed!");
105 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
106 r.in.offered = needed;
107 buffer = talloc_array(tctx, uint8_t, needed);
108 r.out.buffer = buffer;
110 status = dcerpc_svcctl_QueryServiceStatusEx(p, tctx, &r);
111 torture_assert_ntstatus_ok(tctx, status, "QueryServiceStatusEx failed!");
112 torture_assert_werr_ok(tctx, r.out.result, "QueryServiceStatusEx failed!");
115 if (!test_CloseServiceHandle(p, tctx, &s))
118 if (!test_CloseServiceHandle(p, tctx, &h))
124 static bool test_QueryServiceConfig2W(struct torture_context *tctx, struct dcerpc_pipe *p)
126 struct svcctl_QueryServiceConfig2W r;
127 struct policy_handle h, s;
130 uint32_t info_level = SERVICE_CONFIG_DESCRIPTION;
132 uint32_t offered = 0;
135 if (!test_OpenSCManager(p, tctx, &h))
138 if (!test_OpenService(p, tctx, &h, "Netlogon", &s))
141 buffer = talloc(tctx, uint8_t);
144 r.in.info_level = info_level;
145 r.in.offered = offered;
146 r.out.buffer = buffer;
147 r.out.needed = &needed;
149 status = dcerpc_svcctl_QueryServiceConfig2W(p, tctx, &r);
150 torture_assert_ntstatus_ok(tctx, status, "QueryServiceConfig2W failed!");
152 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
153 r.in.offered = needed;
154 buffer = talloc_array(tctx, uint8_t, needed);
155 r.out.buffer = buffer;
157 status = dcerpc_svcctl_QueryServiceConfig2W(p, tctx, &r);
158 torture_assert_ntstatus_ok(tctx, status, "QueryServiceConfig2W failed!");
159 torture_assert_werr_ok(tctx, r.out.result, "QueryServiceConfig2W failed!");
162 r.in.info_level = SERVICE_CONFIG_FAILURE_ACTIONS;
163 r.in.offered = offered;
164 r.out.buffer = buffer;
165 r.out.needed = &needed;
167 status = dcerpc_svcctl_QueryServiceConfig2W(p, tctx, &r);
168 torture_assert_ntstatus_ok(tctx, status, "QueryServiceConfig2W failed!");
170 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
171 r.in.offered = needed;
172 buffer = talloc_array(tctx, uint8_t, needed);
173 r.out.buffer = buffer;
175 status = dcerpc_svcctl_QueryServiceConfig2W(p, tctx, &r);
176 torture_assert_ntstatus_ok(tctx, status, "QueryServiceConfig2W failed!");
177 torture_assert_werr_ok(tctx, r.out.result, "QueryServiceConfig2W failed!");
180 if (!test_CloseServiceHandle(p, tctx, &s))
183 if (!test_CloseServiceHandle(p, tctx, &h))
189 static bool test_EnumServicesStatus(struct torture_context *tctx, struct dcerpc_pipe *p)
191 struct svcctl_EnumServicesStatusW r;
192 struct policy_handle h;
195 uint32_t resume_handle = 0;
196 struct ENUM_SERVICE_STATUSW *service = NULL;
198 uint32_t services_returned = 0;
200 if (!test_OpenSCManager(p, tctx, &h))
204 r.in.type = SERVICE_TYPE_WIN32;
205 r.in.state = SERVICE_STATE_ALL;
207 r.in.resume_handle = &resume_handle;
208 r.out.service = NULL;
209 r.out.resume_handle = &resume_handle;
210 r.out.services_returned = &services_returned;
211 r.out.needed = &needed;
213 status = dcerpc_svcctl_EnumServicesStatusW(p, tctx, &r);
215 torture_assert_ntstatus_ok(tctx, status, "EnumServicesStatus failed!");
217 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
218 r.in.offered = needed;
219 r.out.service = talloc_array(tctx, uint8_t, needed);
221 status = dcerpc_svcctl_EnumServicesStatusW(p, tctx, &r);
223 torture_assert_ntstatus_ok(tctx, status, "EnumServicesStatus failed!");
224 torture_assert_werr_ok(tctx, r.out.result, "EnumServicesStatus failed");
227 if (services_returned > 0) {
229 enum ndr_err_code ndr_err;
231 struct ndr_pull *ndr;
233 blob.length = r.in.offered;
234 blob.data = talloc_steal(tctx, r.out.service);
236 ndr = ndr_pull_init_blob(&blob, tctx, lp_iconv_convenience(tctx->lp_ctx));
238 service = talloc_array(tctx, struct ENUM_SERVICE_STATUSW, services_returned);
243 ndr_err = ndr_pull_ENUM_SERVICE_STATUSW_array(
244 ndr, services_returned, service);
245 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
250 for(i = 0; i < services_returned; i++) {
252 printf("%-20s \"%s\", Type: %d, State: %d\n",
253 service[i].service_name, service[i].display_name,
254 service[i].status.type, service[i].status.state);
257 if (!test_CloseServiceHandle(p, tctx, &h))
263 static bool test_SCManager(struct torture_context *tctx,
264 struct dcerpc_pipe *p)
266 struct policy_handle h;
268 if (!test_OpenSCManager(p, tctx, &h))
271 if (!test_CloseServiceHandle(p, tctx, &h))
277 struct torture_suite *torture_rpc_svcctl(TALLOC_CTX *mem_ctx)
279 struct torture_suite *suite = torture_suite_create(mem_ctx, "SVCCTL");
280 struct torture_rpc_tcase *tcase;
282 tcase = torture_suite_add_rpc_iface_tcase(suite, "svcctl", &ndr_table_svcctl);
284 torture_rpc_tcase_add_test(tcase, "SCManager",
286 torture_rpc_tcase_add_test(tcase, "EnumServicesStatus",
287 test_EnumServicesStatus);
288 torture_rpc_tcase_add_test(tcase, "QueryServiceStatusEx",
289 test_QueryServiceStatusEx);
290 torture_rpc_tcase_add_test(tcase, "QueryServiceConfig2W",
291 test_QueryServiceConfig2W);