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_EnumServicesStatus(struct torture_context *tctx, struct dcerpc_pipe *p)
57 struct svcctl_EnumServicesStatusW r;
58 struct policy_handle h;
61 uint32_t resume_handle = 0;
62 struct ENUM_SERVICE_STATUS *service = NULL;
64 if (!test_OpenSCManager(p, tctx, &h))
68 r.in.type = SERVICE_TYPE_WIN32;
69 r.in.state = SERVICE_STATE_ALL;
71 r.in.resume_handle = &resume_handle;
73 r.out.resume_handle = &resume_handle;
74 r.out.services_returned = 0;
75 r.out.bytes_needed = 0;
77 status = dcerpc_svcctl_EnumServicesStatusW(p, tctx, &r);
79 torture_assert_ntstatus_ok(tctx, status, "EnumServicesStatus failed!");
81 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
82 r.in.buf_size = *r.out.bytes_needed;
83 r.out.service = talloc_array(tctx, uint8_t, *r.out.bytes_needed);
85 status = dcerpc_svcctl_EnumServicesStatusW(p, tctx, &r);
87 torture_assert_ntstatus_ok(tctx, status, "EnumServicesStatus failed!");
88 torture_assert_werr_ok(tctx, r.out.result, "EnumServicesStatus failed");
90 service = (struct ENUM_SERVICE_STATUS *)r.out.service;
93 for(i = 0; i < *r.out.services_returned; i++) {
94 printf("Type: %d, State: %d\n", service[i].status.type, service[i].status.state);
97 if (!test_CloseServiceHandle(p, tctx, &h))
103 static bool test_SCManager(struct torture_context *tctx,
104 struct dcerpc_pipe *p)
106 struct policy_handle h;
108 if (!test_OpenSCManager(p, tctx, &h))
111 if (!test_CloseServiceHandle(p, tctx, &h))
117 struct torture_suite *torture_rpc_svcctl(TALLOC_CTX *mem_ctx)
119 struct torture_suite *suite = torture_suite_create(mem_ctx, "SVCCTL");
120 struct torture_rpc_tcase *tcase;
122 tcase = torture_suite_add_rpc_iface_tcase(suite, "svcctl",
125 torture_rpc_tcase_add_test(tcase, "SCManager",
127 torture_rpc_tcase_add_test(tcase, "EnumServicesStatus",
128 test_EnumServicesStatus);