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_EnumServicesStatus r;
29 uint32 resume_handle = 0;
30 struct ENUM_SERVICE_STATUS *service = talloc_p(mem_ctx, struct ENUM_SERVICE_STATUS);
33 r.in.type = SERVICE_TYPE_WIN32;
34 r.in.state = SERVICE_STATE_ALL;
35 r.in.buf_size = sizeof(struct ENUM_SERVICE_STATUS);
36 r.in.resume_handle = &resume_handle;
37 r.out.service = service;
38 r.out.resume_handle = &resume_handle;
40 status = dcerpc_svcctl_EnumServicesStatus(p, mem_ctx, &r);
42 if (!NT_STATUS_IS_OK(status)) {
43 printf("ËnumServicesStatus failed!\n");
47 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
48 r.in.buf_size = r.out.bytes_needed + sizeof(struct ENUM_SERVICE_STATUS);
49 service = talloc_realloc(mem_ctx, service, r.in.buf_size);
50 r.out.service = service;
52 status = dcerpc_svcctl_EnumServicesStatus(p, mem_ctx, &r);
54 if (!NT_STATUS_IS_OK(status)) {
55 printf("ËnumServicesStatus failed!\n");
59 if (!W_ERROR_IS_OK(r.out.result)) {
60 printf("EnumServicesStatus failed\n");
65 for(i = 0; i < r.out.services_returned; i++) {
66 printf("%s - %s\n", service[i].service_name, service[i].display_name);
72 static BOOL test_OpenSCManager(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *h)
74 struct svcctl_OpenSCManager r;
77 r.in.MachineName = NULL;
78 r.in.DatabaseName = NULL;
79 r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
82 status = dcerpc_svcctl_OpenSCManager(p, mem_ctx, &r);
83 if (!NT_STATUS_IS_OK(status)) {
84 printf("OpenSCManager failed!\n");
91 static BOOL test_CloseServiceHandle(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *h)
93 struct svcctl_CloseServiceHandle r;
97 status = dcerpc_svcctl_CloseServiceHandle(p, mem_ctx, &r);
98 if (!NT_STATUS_IS_OK(status)) {
99 printf("CloseServiceHandle failed\n");
106 BOOL torture_rpc_svcctl(int dummy)
109 struct dcerpc_pipe *p;
110 struct policy_handle h;
114 mem_ctx = talloc_init("torture_rpc_svcctl");
116 status = torture_rpc_connection(&p,
119 DCERPC_SVCCTL_VERSION);
120 if (!NT_STATUS_IS_OK(status)) {
124 if (!test_OpenSCManager(p, mem_ctx, &h)) {
128 if (!test_EnumServicesStatus(p, mem_ctx, &h)) {
132 if (!test_CloseServiceHandle(p, mem_ctx, &h)) {
136 talloc_destroy(mem_ctx);
138 torture_rpc_close(p);