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.
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
;
32 uint32_t resume_handle
= 0;
33 struct ENUM_SERVICE_STATUS
*service
= NULL
;
36 r
.in
.type
= SERVICE_TYPE_WIN32
;
37 r
.in
.state
= SERVICE_STATE_ALL
;
39 r
.in
.resume_handle
= &resume_handle
;
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");
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");
63 if (!W_ERROR_IS_OK(r
.out
.result
)) {
64 printf("EnumServicesStatus failed\n");
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
);
77 static BOOL
test_OpenSCManager(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
, struct policy_handle
*h
)
79 struct svcctl_OpenSCManagerW r
;
82 r
.in
.MachineName
= NULL
;
83 r
.in
.DatabaseName
= NULL
;
84 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
87 status
= dcerpc_svcctl_OpenSCManagerW(p
, mem_ctx
, &r
);
88 if (!NT_STATUS_IS_OK(status
)) {
89 printf("OpenSCManager failed!\n");
96 static BOOL
test_CloseServiceHandle(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
, struct policy_handle
*h
)
98 struct svcctl_CloseServiceHandle r
;
102 status
= dcerpc_svcctl_CloseServiceHandle(p
, mem_ctx
, &r
);
103 if (!NT_STATUS_IS_OK(status
)) {
104 printf("CloseServiceHandle failed\n");
111 BOOL
torture_rpc_svcctl(void)
114 struct dcerpc_pipe
*p
;
115 struct policy_handle h
;
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
);
127 if (!test_OpenSCManager(p
, mem_ctx
, &h
)) {
131 if (!test_EnumServicesStatus(p
, mem_ctx
, &h
)) {
135 if (!test_CloseServiceHandle(p
, mem_ctx
, &h
)) {
139 talloc_free(mem_ctx
);