r24741: More use of the torture API.
[kai/samba.git] / source4 / torture / rpc / initshutdown.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for initshutdown operations
4
5    Copyright (C) Tim Potter 2003
6    Copyright (C) Jelmer Vernooij 2004-2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_initshutdown_c.h"
25 #include "torture/rpc/rpc.h"
26
27 static void init_initshutdown_String(TALLOC_CTX *mem_ctx, struct initshutdown_String *name, const char *s)
28 {
29         name->name = talloc(mem_ctx, struct initshutdown_String_sub);
30         name->name->name = s;
31 }
32
33 static BOOL test_Init(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
34                         const char *msg, uint32_t timeout)
35 {
36         struct initshutdown_Init r;
37         NTSTATUS status;
38         uint16_t hostname = 0x0;
39         
40         r.in.hostname = &hostname;
41         r.in.message = talloc(mem_ctx, struct initshutdown_String);
42         init_initshutdown_String(mem_ctx, r.in.message, msg);
43         r.in.force_apps = 1;
44         r.in.timeout = timeout;
45         r.in.reboot = 1;
46
47         status = dcerpc_initshutdown_Init(p, mem_ctx, &r);
48
49         if (!NT_STATUS_IS_OK(status)) {
50                 printf("initshutdown_Init failed - %s\n", nt_errstr(status));
51                 return False;
52         }
53
54         if (!W_ERROR_IS_OK(r.out.result)) {
55                 printf("initshutdown_Init failed - %s\n", win_errstr(r.out.result));
56                 return False;
57         }
58
59         return True;
60 }
61
62 static BOOL test_InitEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
63                         const char *msg, uint32_t timeout)
64 {
65         struct initshutdown_InitEx r;
66         NTSTATUS status;
67         uint16_t hostname = 0x0;
68         
69         r.in.hostname = &hostname;
70         r.in.message = talloc(mem_ctx, struct initshutdown_String);
71         init_initshutdown_String(mem_ctx, r.in.message, msg);
72         r.in.force_apps = 1;
73         r.in.timeout = timeout;
74         r.in.reboot = 1;
75         r.in.reason = 0;
76
77         status = dcerpc_initshutdown_InitEx(p, mem_ctx, &r);
78
79         if (!NT_STATUS_IS_OK(status)) {
80                 printf("initshutdown_InitEx failed - %s\n", nt_errstr(status));
81                 return False;
82         }
83
84         if (!W_ERROR_IS_OK(r.out.result)) {
85                 printf("initshutdown_InitEx failed - %s\n", win_errstr(r.out.result));
86                 return False;
87         }
88
89         return True;
90 }
91
92 static BOOL test_Abort(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
93 {
94         struct initshutdown_Abort r;
95         NTSTATUS status;
96         uint16_t server = 0x0;
97
98         r.in.server = &server;
99         
100         status = dcerpc_initshutdown_Abort(p, mem_ctx, &r);
101
102         if (!NT_STATUS_IS_OK(status)) {
103                 printf("initshutdown_Abort failed - %s\n", nt_errstr(status));
104                 return False;
105         }
106
107         if (!W_ERROR_IS_OK(r.out.result)) {
108                 printf("initshutdown_Abort failed - %s\n", win_errstr(r.out.result));
109                 return False;
110         }
111
112         return True;
113 }
114
115 BOOL torture_rpc_initshutdown(struct torture_context *torture)
116 {
117     NTSTATUS status;
118     struct dcerpc_pipe *p;
119         TALLOC_CTX *mem_ctx;
120         BOOL ret = True;
121
122         mem_ctx = talloc_init("torture_rpc_initshutdown");
123
124         status = torture_rpc_connection(torture, &p, &ndr_table_initshutdown);
125
126         if (!NT_STATUS_IS_OK(status)) {
127                 talloc_free(mem_ctx);
128                 return False;
129         }
130
131         if (!torture_setting_bool(torture, "dangerous", False)) {
132                 torture_comment(torture, 
133                                                 "initshutdown tests disabled - enable dangerous tests to use\n");
134         } else {
135                 ret &= test_Init(p, mem_ctx, "spottyfood", 30);
136                 ret &= test_Abort(p, mem_ctx);
137                 ret &= test_InitEx(p, mem_ctx, "spottyfood", 30);
138                 ret &= test_Abort(p, mem_ctx);
139         }
140
141         talloc_free(mem_ctx);
142
143         return ret;
144 }