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_EnumServicesStatus(struct torture_context *tctx, struct dcerpc_pipe *p)
123 struct svcctl_EnumServicesStatusW r;
124 struct policy_handle h;
127 uint32_t resume_handle = 0;
128 struct ENUM_SERVICE_STATUS *service = NULL;
129 uint32_t bytes_needed = 0;
130 uint32_t services_returned = 0;
132 if (!test_OpenSCManager(p, tctx, &h))
136 r.in.type = SERVICE_TYPE_WIN32;
137 r.in.state = SERVICE_STATE_ALL;
139 r.in.resume_handle = &resume_handle;
140 r.out.service = NULL;
141 r.out.resume_handle = &resume_handle;
142 r.out.services_returned = &services_returned;
143 r.out.bytes_needed = &bytes_needed;
145 status = dcerpc_svcctl_EnumServicesStatusW(p, tctx, &r);
147 torture_assert_ntstatus_ok(tctx, status, "EnumServicesStatus failed!");
149 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
150 r.in.buf_size = bytes_needed;
151 r.out.service = talloc_array(tctx, uint8_t, bytes_needed);
153 status = dcerpc_svcctl_EnumServicesStatusW(p, tctx, &r);
155 torture_assert_ntstatus_ok(tctx, status, "EnumServicesStatus failed!");
156 torture_assert_werr_ok(tctx, r.out.result, "EnumServicesStatus failed");
158 service = (struct ENUM_SERVICE_STATUS *)r.out.service;
161 for(i = 0; i < services_returned; i++) {
162 printf("Type: %d, State: %d\n", service[i].status.type, service[i].status.state);
165 if (!test_CloseServiceHandle(p, tctx, &h))
171 static bool test_SCManager(struct torture_context *tctx,
172 struct dcerpc_pipe *p)
174 struct policy_handle h;
176 if (!test_OpenSCManager(p, tctx, &h))
179 if (!test_CloseServiceHandle(p, tctx, &h))
185 struct torture_suite *torture_rpc_svcctl(TALLOC_CTX *mem_ctx)
187 struct torture_suite *suite = torture_suite_create(mem_ctx, "SVCCTL");
188 struct torture_rpc_tcase *tcase;
190 tcase = torture_suite_add_rpc_iface_tcase(suite, "svcctl", &ndr_table_svcctl);
192 torture_rpc_tcase_add_test(tcase, "SCManager",
194 torture_rpc_tcase_add_test(tcase, "EnumServicesStatus",
195 test_EnumServicesStatus);
196 torture_rpc_tcase_add_test(tcase, "QueryServiceStatusEx",
197 test_QueryServiceStatusEx);