2 Unix SMB/CIFS implementation.
3 test suite for srvsvc rpc operations
5 Copyright (C) Jelmer Vernooij 2004
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.
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.
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/>.
22 #include "torture/torture.h"
23 #include "librpc/gen_ndr/ndr_svcctl_c.h"
24 #include "torture/rpc/rpc.h"
26 static bool test_OpenSCManager(struct dcerpc_pipe *p, struct torture_context *tctx, struct policy_handle *h)
28 struct svcctl_OpenSCManagerW r;
30 r.in.MachineName = NULL;
31 r.in.DatabaseName = NULL;
32 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
35 torture_assert_ntstatus_ok(tctx,
36 dcerpc_svcctl_OpenSCManagerW(p, tctx, &r),
37 "OpenSCManager failed!");
42 static bool test_CloseServiceHandle(struct dcerpc_pipe *p, struct torture_context *tctx, struct policy_handle *h)
44 struct svcctl_CloseServiceHandle r;
48 torture_assert_ntstatus_ok(tctx,
49 dcerpc_svcctl_CloseServiceHandle(p, tctx, &r),
50 "CloseServiceHandle failed");
55 static bool test_OpenService(struct dcerpc_pipe *p, struct torture_context *tctx,
56 struct policy_handle *h, const char *name, struct policy_handle *s)
58 struct svcctl_OpenServiceW r;
60 r.in.scmanager_handle = h;
61 r.in.ServiceName = name;
62 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
65 torture_assert_ntstatus_ok(tctx,
66 dcerpc_svcctl_OpenServiceW(p, tctx, &r),
67 "OpenServiceW failed!");
68 torture_assert_werr_ok(tctx, r.out.result, "OpenServiceW failed!");
74 static bool test_QueryServiceStatusEx(struct torture_context *tctx, struct dcerpc_pipe *p)
76 struct svcctl_QueryServiceStatusEx r;
77 struct policy_handle h, s;
80 uint32_t info_level = 0;
82 uint32_t buf_size = 0;
83 uint32_t bytes_needed = 0;
85 if (!test_OpenSCManager(p, tctx, &h))
88 if (!test_OpenService(p, tctx, &h, "Netlogon", &s))
91 buffer = talloc(tctx, uint8_t);
95 r.in.buf_size = buf_size;
96 r.out.buffer = buffer;
97 r.out.bytes_needed = &bytes_needed;
99 status = dcerpc_svcctl_QueryServiceStatusEx(p, tctx, &r);
100 torture_assert_ntstatus_ok(tctx, status, "QueryServiceStatusEx failed!");
102 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
103 r.in.buf_size = bytes_needed;
104 buffer = talloc_array(tctx, uint8_t, bytes_needed);
105 r.out.buffer = buffer;
107 status = dcerpc_svcctl_QueryServiceStatusEx(p, tctx, &r);
108 torture_assert_ntstatus_ok(tctx, status, "QueryServiceStatusEx failed!");
109 torture_assert_werr_ok(tctx, r.out.result, "QueryServiceStatusEx failed!");
112 if (!test_CloseServiceHandle(p, tctx, &s))
115 if (!test_CloseServiceHandle(p, tctx, &h))
121 static bool test_QueryServiceConfig2W(struct torture_context *tctx, struct dcerpc_pipe *p)
123 struct svcctl_QueryServiceConfig2W r;
124 struct policy_handle h, s;
127 uint32_t info_level = 0;
129 uint32_t buf_size = 0;
130 uint32_t bytes_needed = 0;
132 if (!test_OpenSCManager(p, tctx, &h))
135 if (!test_OpenService(p, tctx, &h, "Netlogon", &s))
138 buffer = talloc(tctx, uint8_t);
142 r.in.buf_size = buf_size;
143 r.out.buffer = buffer;
144 r.out.bytes_needed = &bytes_needed;
146 status = dcerpc_svcctl_QueryServiceConfig2W(p, tctx, &r);
147 torture_assert_ntstatus_ok(tctx, status, "QueryServiceConfig2W failed!");
149 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
150 r.in.buf_size = bytes_needed;
151 buffer = talloc_array(tctx, uint8_t, bytes_needed);
152 r.out.buffer = buffer;
154 status = dcerpc_svcctl_QueryServiceConfig2W(p, tctx, &r);
155 torture_assert_ntstatus_ok(tctx, status, "QueryServiceConfig2W failed!");
156 torture_assert_werr_ok(tctx, r.out.result, "QueryServiceConfig2W failed!");
159 if (!test_CloseServiceHandle(p, tctx, &s))
162 if (!test_CloseServiceHandle(p, tctx, &h))
168 static bool test_EnumServicesStatus(struct torture_context *tctx, struct dcerpc_pipe *p)
170 struct svcctl_EnumServicesStatusW r;
171 struct policy_handle h;
174 uint32_t resume_handle = 0;
175 struct ENUM_SERVICE_STATUS *service = NULL;
176 uint32_t bytes_needed = 0;
177 uint32_t services_returned = 0;
179 if (!test_OpenSCManager(p, tctx, &h))
183 r.in.type = SERVICE_TYPE_WIN32;
184 r.in.state = SERVICE_STATE_ALL;
186 r.in.resume_handle = &resume_handle;
187 r.out.service = NULL;
188 r.out.resume_handle = &resume_handle;
189 r.out.services_returned = &services_returned;
190 r.out.bytes_needed = &bytes_needed;
192 status = dcerpc_svcctl_EnumServicesStatusW(p, tctx, &r);
194 torture_assert_ntstatus_ok(tctx, status, "EnumServicesStatus failed!");
196 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
197 r.in.buf_size = bytes_needed;
198 r.out.service = talloc_array(tctx, uint8_t, bytes_needed);
200 status = dcerpc_svcctl_EnumServicesStatusW(p, tctx, &r);
202 torture_assert_ntstatus_ok(tctx, status, "EnumServicesStatus failed!");
203 torture_assert_werr_ok(tctx, r.out.result, "EnumServicesStatus failed");
205 service = (struct ENUM_SERVICE_STATUS *)r.out.service;
208 for(i = 0; i < services_returned; i++) {
209 printf("Type: %d, State: %d\n", service[i].status.type, service[i].status.state);
212 if (!test_CloseServiceHandle(p, tctx, &h))
218 static bool test_SCManager(struct torture_context *tctx,
219 struct dcerpc_pipe *p)
221 struct policy_handle h;
223 if (!test_OpenSCManager(p, tctx, &h))
226 if (!test_CloseServiceHandle(p, tctx, &h))
232 struct torture_suite *torture_rpc_svcctl(TALLOC_CTX *mem_ctx)
234 struct torture_suite *suite = torture_suite_create(mem_ctx, "SVCCTL");
235 struct torture_rpc_tcase *tcase;
237 tcase = torture_suite_add_rpc_iface_tcase(suite, "svcctl", &ndr_table_svcctl);
239 torture_rpc_tcase_add_test(tcase, "SCManager",
241 torture_rpc_tcase_add_test(tcase, "EnumServicesStatus",
242 test_EnumServicesStatus);
243 torture_rpc_tcase_add_test(tcase, "QueryServiceStatusEx",
244 test_QueryServiceStatusEx);
245 torture_rpc_tcase_add_test(tcase, "QueryServiceConfig2W",
246 test_QueryServiceConfig2W);