r14470: Remove some unnecessary headers.
[Samba.git] / source / torture / rpc / svcctl.c
blobdbdce859f88a81affdd48b1112d21686a7b6528f
1 /*
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.
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_svcctl_c.h"
25 #include "torture/rpc/rpc.h"
27 static BOOL test_EnumServicesStatus(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *h)
29 struct svcctl_EnumServicesStatusW r;
30 int i;
31 NTSTATUS status;
32 uint32_t resume_handle = 0;
33 struct ENUM_SERVICE_STATUS *service = NULL;
35 r.in.handle = h;
36 r.in.type = SERVICE_TYPE_WIN32;
37 r.in.state = SERVICE_STATE_ALL;
38 r.in.buf_size = 0;
39 r.in.resume_handle = &resume_handle;
40 r.out.service = NULL;
41 r.out.resume_handle = &resume_handle;
42 r.out.services_returned = 0;
43 r.out.bytes_needed = 0;
45 status = dcerpc_svcctl_EnumServicesStatusW(p, mem_ctx, &r);
47 if (!NT_STATUS_IS_OK(status)) {
48 printf("ËnumServicesStatus failed!\n");
49 return False;
52 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
53 r.in.buf_size = r.out.bytes_needed;
54 r.out.service = talloc_size(mem_ctx, r.out.bytes_needed);
56 status = dcerpc_svcctl_EnumServicesStatusW(p, mem_ctx, &r);
58 if (!NT_STATUS_IS_OK(status)) {
59 printf("ËnumServicesStatus failed!\n");
60 return False;
63 if (!W_ERROR_IS_OK(r.out.result)) {
64 printf("EnumServicesStatus failed\n");
65 return False;
67 service = (struct ENUM_SERVICE_STATUS *)r.out.service;
70 for(i = 0; i < r.out.services_returned; i++) {
71 printf("Type: %d, State: %d\n", service[i].status.type, service[i].status.state);
74 return True;
77 static BOOL test_OpenSCManager(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *h)
79 struct svcctl_OpenSCManagerW r;
80 NTSTATUS status;
82 r.in.MachineName = NULL;
83 r.in.DatabaseName = NULL;
84 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
85 r.out.handle = h;
87 status = dcerpc_svcctl_OpenSCManagerW(p, mem_ctx, &r);
88 if (!NT_STATUS_IS_OK(status)) {
89 printf("OpenSCManager failed!\n");
90 return False;
93 return True;
96 static BOOL test_CloseServiceHandle(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *h)
98 struct svcctl_CloseServiceHandle r;
99 NTSTATUS status;
100 r.in.handle = h;
101 r.out.handle = h;
102 status = dcerpc_svcctl_CloseServiceHandle(p, mem_ctx, &r);
103 if (!NT_STATUS_IS_OK(status)) {
104 printf("CloseServiceHandle failed\n");
105 return False;
108 return True;
111 BOOL torture_rpc_svcctl(void)
113 NTSTATUS status;
114 struct dcerpc_pipe *p;
115 struct policy_handle h;
116 TALLOC_CTX *mem_ctx;
117 BOOL ret = True;
119 mem_ctx = talloc_init("torture_rpc_svcctl");
121 status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_svcctl);
122 if (!NT_STATUS_IS_OK(status)) {
123 talloc_free(mem_ctx);
124 return False;
127 if (!test_OpenSCManager(p, mem_ctx, &h)) {
128 ret = False;
131 if (!test_EnumServicesStatus(p, mem_ctx, &h)) {
132 ret = False;
135 if (!test_CloseServiceHandle(p, mem_ctx, &h)) {
136 ret = False;
139 talloc_free(mem_ctx);
141 return ret;