r14470: Remove some unnecessary headers.
[gd/samba-autobuild/.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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "torture/torture.h"
25 #include "librpc/gen_ndr/ndr_initshutdown_c.h"
26 #include "torture/rpc/rpc.h"
27
28 static void init_initshutdown_String(TALLOC_CTX *mem_ctx, struct initshutdown_String *name, const char *s)
29 {
30         name->name = talloc(mem_ctx, struct initshutdown_String_sub);
31         name->name->name = s;
32 }
33
34 static BOOL test_Init(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
35                         const char *msg, uint32_t timeout)
36 {
37         struct initshutdown_Init r;
38         NTSTATUS status;
39         uint16_t hostname = 0x0;
40         
41         r.in.hostname = &hostname;
42         r.in.message = talloc(mem_ctx, struct initshutdown_String);
43         init_initshutdown_String(mem_ctx, r.in.message, msg);
44         r.in.force_apps = 1;
45         r.in.timeout = timeout;
46         r.in.reboot = 1;
47
48         status = dcerpc_initshutdown_Init(p, mem_ctx, &r);
49
50         if (!NT_STATUS_IS_OK(status)) {
51                 printf("initshutdown_Init failed - %s\n", nt_errstr(status));
52                 return False;
53         }
54
55         if (!W_ERROR_IS_OK(r.out.result)) {
56                 printf("initshutdown_Init failed - %s\n", win_errstr(r.out.result));
57                 return False;
58         }
59
60         return True;
61 }
62
63 static BOOL test_InitEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
64                         const char *msg, uint32_t timeout)
65 {
66         struct initshutdown_InitEx r;
67         NTSTATUS status;
68         uint16_t hostname = 0x0;
69         
70         r.in.hostname = &hostname;
71         r.in.message = talloc(mem_ctx, struct initshutdown_String);
72         init_initshutdown_String(mem_ctx, r.in.message, msg);
73         r.in.force_apps = 1;
74         r.in.timeout = timeout;
75         r.in.reboot = 1;
76         r.in.reason = 0;
77
78         status = dcerpc_initshutdown_InitEx(p, mem_ctx, &r);
79
80         if (!NT_STATUS_IS_OK(status)) {
81                 printf("initshutdown_InitEx failed - %s\n", nt_errstr(status));
82                 return False;
83         }
84
85         if (!W_ERROR_IS_OK(r.out.result)) {
86                 printf("initshutdown_InitEx failed - %s\n", win_errstr(r.out.result));
87                 return False;
88         }
89
90         return True;
91 }
92
93 static BOOL test_Abort(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
94 {
95         struct initshutdown_Abort r;
96         NTSTATUS status;
97         uint16_t server = 0x0;
98
99         r.in.server = &server;
100         
101         status = dcerpc_initshutdown_Abort(p, mem_ctx, &r);
102
103         if (!NT_STATUS_IS_OK(status)) {
104                 printf("initshutdown_Abort failed - %s\n", nt_errstr(status));
105                 return False;
106         }
107
108         if (!W_ERROR_IS_OK(r.out.result)) {
109                 printf("initshutdown_Abort failed - %s\n", win_errstr(r.out.result));
110                 return False;
111         }
112
113         return True;
114 }
115
116 BOOL torture_rpc_initshutdown(void)
117 {
118     NTSTATUS status;
119     struct dcerpc_pipe *p;
120         TALLOC_CTX *mem_ctx;
121         BOOL ret = True;
122
123         mem_ctx = talloc_init("torture_rpc_initshutdown");
124
125         status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_initshutdown);
126
127         if (!NT_STATUS_IS_OK(status)) {
128                 talloc_free(mem_ctx);
129                 return False;
130         }
131
132         if (!lp_parm_bool(-1, "torture", "dangerous", False)) {
133                 printf("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 }