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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 static BOOL test_EnumServicesStatus(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *h)
26 struct svcctl_EnumServicesStatusW r;
29 uint32 resume_handle = 0;
30 struct ENUM_SERVICE_STATUS *service = NULL;
33 r.in.type = SERVICE_TYPE_WIN32;
34 r.in.state = SERVICE_STATE_ALL;
36 r.in.resume_handle = &resume_handle;
38 r.out.resume_handle = &resume_handle;
39 r.out.services_returned = 0;
40 r.out.bytes_needed = 0;
42 status = dcerpc_svcctl_EnumServicesStatusW(p, mem_ctx, &r);
44 if (!NT_STATUS_IS_OK(status)) {
45 printf("ËnumServicesStatus failed!\n");
49 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
50 r.in.buf_size = r.out.bytes_needed;
51 r.out.service = talloc(mem_ctx, r.out.bytes_needed);
53 status = dcerpc_svcctl_EnumServicesStatusW(p, mem_ctx, &r);
55 if (!NT_STATUS_IS_OK(status)) {
56 printf("ËnumServicesStatus failed!\n");
60 if (!W_ERROR_IS_OK(r.out.result)) {
61 printf("EnumServicesStatus failed\n");
64 service = (struct ENUM_SERVICE_STATUS *)r.out.service;
67 for(i = 0; i < r.out.services_returned; i++) {
68 printf("Type: %d, State: %d\n", service[i].status.type, service[i].status.state);
74 static BOOL test_OpenSCManager(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *h)
76 struct svcctl_OpenSCManagerW r;
79 r.in.MachineName = NULL;
80 r.in.DatabaseName = NULL;
81 r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
84 status = dcerpc_svcctl_OpenSCManagerW(p, mem_ctx, &r);
85 if (!NT_STATUS_IS_OK(status)) {
86 printf("OpenSCManager failed!\n");
93 static BOOL test_CloseServiceHandle(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *h)
95 struct svcctl_CloseServiceHandle r;
99 status = dcerpc_svcctl_CloseServiceHandle(p, mem_ctx, &r);
100 if (!NT_STATUS_IS_OK(status)) {
101 printf("CloseServiceHandle failed\n");
108 BOOL torture_rpc_svcctl(void)
111 struct dcerpc_pipe *p;
112 struct policy_handle h;
116 mem_ctx = talloc_init("torture_rpc_svcctl");
118 status = torture_rpc_connection(&p,
121 DCERPC_SVCCTL_VERSION);
122 if (!NT_STATUS_IS_OK(status)) {
126 if (!test_OpenSCManager(p, mem_ctx, &h)) {
130 if (!test_EnumServicesStatus(p, mem_ctx, &h)) {
134 if (!test_CloseServiceHandle(p, mem_ctx, &h)) {
138 talloc_destroy(mem_ctx);
140 torture_rpc_close(p);