r25035: Fix some more warnings, use service pointer rather than service number in...
[kai/samba.git] / source4 / torture / rpc / eventlog.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for eventlog rpc operations
4
5    Copyright (C) Tim Potter 2003,2005
6    Copyright (C) Jelmer Vernooij 2004
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_eventlog.h"
25 #include "librpc/gen_ndr/ndr_eventlog_c.h"
26 #include "librpc/gen_ndr/ndr_lsa.h"
27 #include "torture/rpc/rpc.h"
28
29 static void init_lsa_String(struct lsa_String *name, const char *s)
30 {
31         name->string = s;
32         name->length = 2*strlen_m(s);
33         name->size = name->length;
34 }
35
36 static bool get_policy_handle(struct torture_context *tctx, 
37                                                           struct dcerpc_pipe *p,
38                                                           struct policy_handle *handle)
39 {
40         struct eventlog_OpenEventLogW r;
41         struct eventlog_OpenUnknown0 unknown0;
42
43         unknown0.unknown0 = 0x005c;
44         unknown0.unknown1 = 0x0001;
45
46         r.in.unknown0 = &unknown0;
47         init_lsa_String(&r.in.logname, "dns server");
48         init_lsa_String(&r.in.servername, NULL);
49         r.in.unknown2 = 0x00000001;
50         r.in.unknown3 = 0x00000001;
51         r.out.handle = handle;
52
53         torture_assert_ntstatus_ok(tctx, 
54                         dcerpc_eventlog_OpenEventLogW(p, tctx, &r), 
55                         "OpenEventLog failed");
56
57         torture_assert_ntstatus_ok(tctx, r.out.result, "OpenEventLog failed");
58
59         return true;
60 }
61
62
63
64 static bool test_GetNumRecords(struct torture_context *tctx, struct dcerpc_pipe *p)
65 {
66         struct eventlog_GetNumRecords r;
67         struct eventlog_CloseEventLog cr;
68         struct policy_handle handle;
69
70         if (!get_policy_handle(tctx, p, &handle))
71                 return false;
72
73         r.in.handle = &handle;
74
75         torture_assert_ntstatus_ok(tctx, 
76                         dcerpc_eventlog_GetNumRecords(p, tctx, &r), 
77                         "GetNumRecords failed");
78
79         torture_comment(tctx, "%d records\n", *r.out.number);
80
81         cr.in.handle = cr.out.handle = &handle;
82
83         torture_assert_ntstatus_ok(tctx, 
84                                         dcerpc_eventlog_CloseEventLog(p, tctx, &cr), 
85                                         "CloseEventLog failed");
86         return true;
87 }
88
89 static bool test_ReadEventLog(struct torture_context *tctx, 
90                                                           struct dcerpc_pipe *p)
91 {
92         NTSTATUS status;
93         struct eventlog_ReadEventLogW r;
94         struct eventlog_CloseEventLog cr;
95         struct policy_handle handle;
96
97         if (!get_policy_handle(tctx, p, &handle))
98                 return false;
99
100         r.in.offset = 0;
101         r.in.handle = &handle;
102         r.in.flags = EVENTLOG_BACKWARDS_READ|EVENTLOG_SEQUENTIAL_READ;
103
104         while (1) {
105                 DATA_BLOB blob;
106                 struct eventlog_Record rec;
107                 struct ndr_pull *ndr;
108
109                 /* Read first for number of bytes in record */
110
111                 r.in.number_of_bytes = 0;
112                 r.out.data = NULL;
113
114                 status = dcerpc_eventlog_ReadEventLogW(p, tctx, &r);
115
116                 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_END_OF_FILE)) {
117                         break;
118                 }
119
120                 torture_assert_ntstatus_ok(tctx, status, "ReadEventLog failed");
121
122                 torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_BUFFER_TOO_SMALL,
123                         "ReadEventLog failed");
124                 
125                 /* Now read the actual record */
126
127                 r.in.number_of_bytes = *r.out.real_size;
128                 r.out.data = talloc_array(tctx, uint8_t, r.in.number_of_bytes);
129
130                 status = dcerpc_eventlog_ReadEventLogW(p, tctx, &r);
131
132                 torture_assert_ntstatus_ok(tctx, status, "ReadEventLog failed");
133                 
134                 /* Decode a user-marshalled record */
135
136                 blob.length = *r.out.sent_size;
137                 blob.data = talloc_steal(tctx, r.out.data);
138
139                 ndr = ndr_pull_init_blob(&blob, tctx);
140
141                 status = ndr_pull_eventlog_Record(
142                         ndr, NDR_SCALARS|NDR_BUFFERS, &rec);
143
144                 NDR_PRINT_DEBUG(eventlog_Record, &rec);
145
146                 torture_assert_ntstatus_ok(tctx, status, 
147                                 "ReadEventLog failed parsing event log record");
148
149                 r.in.offset++;
150         }
151
152         cr.in.handle = cr.out.handle = &handle;
153
154         torture_assert_ntstatus_ok(tctx, 
155                                         dcerpc_eventlog_CloseEventLog(p, tctx, &cr), 
156                                         "CloseEventLog failed");
157
158         return true;
159 }
160
161 static bool test_FlushEventLog(struct torture_context *tctx, 
162                                                            struct dcerpc_pipe *p)
163 {
164         struct eventlog_FlushEventLog r;
165         struct eventlog_CloseEventLog cr;
166         struct policy_handle handle;
167
168         if (!get_policy_handle(tctx, p, &handle))
169                 return false;
170
171         r.in.handle = &handle;
172
173         /* Huh?  Does this RPC always return access denied? */
174         torture_assert_ntstatus_equal(tctx, 
175                         dcerpc_eventlog_FlushEventLog(p, tctx, &r),
176                         NT_STATUS_ACCESS_DENIED, 
177                         "FlushEventLog failed");
178
179         cr.in.handle = cr.out.handle = &handle;
180
181         torture_assert_ntstatus_ok(tctx, 
182                                         dcerpc_eventlog_CloseEventLog(p, tctx, &cr), 
183                                         "CloseEventLog failed");
184
185         return true;
186 }
187
188 static bool test_ClearEventLog(struct torture_context *tctx, 
189                                struct dcerpc_pipe *p)
190 {
191         struct eventlog_ClearEventLogW r;
192         struct eventlog_CloseEventLog cr;
193         struct policy_handle handle;
194
195         if (!get_policy_handle(tctx, p, &handle))
196                 return false;
197
198         r.in.handle = &handle;
199         r.in.unknown = NULL;
200
201         torture_assert_ntstatus_ok(tctx, 
202                         dcerpc_eventlog_ClearEventLogW(p, tctx, &r), 
203                         "ClearEventLog failed");
204
205         cr.in.handle = cr.out.handle = &handle;
206
207         torture_assert_ntstatus_ok(tctx, 
208                                         dcerpc_eventlog_CloseEventLog(p, tctx, &cr), 
209                                         "CloseEventLog failed");
210
211         return true;
212 }
213
214 static bool test_OpenEventLog(struct torture_context *tctx, 
215                                                           struct dcerpc_pipe *p)
216 {
217         struct policy_handle handle;
218         struct eventlog_CloseEventLog cr;
219
220         if (!get_policy_handle(tctx, p, &handle))
221                 return false;
222
223         cr.in.handle = cr.out.handle = &handle;
224
225         torture_assert_ntstatus_ok(tctx, 
226                                         dcerpc_eventlog_CloseEventLog(p, tctx, &cr), 
227                                         "CloseEventLog failed");
228
229         return true;
230 }
231
232 struct torture_suite *torture_rpc_eventlog(TALLOC_CTX *mem_ctx)
233 {
234         struct torture_suite *suite;
235         struct torture_rpc_tcase *tcase;
236         struct torture_test *test;
237
238         suite = torture_suite_create(mem_ctx, "EVENTLOG");
239         tcase = torture_suite_add_rpc_iface_tcase(suite, "eventlog", 
240                                                   &ndr_table_eventlog);
241
242         torture_rpc_tcase_add_test(tcase, "OpenEventLog", test_OpenEventLog);
243         test = torture_rpc_tcase_add_test(tcase, "ClearEventLog", 
244                                           test_ClearEventLog);
245         test->dangerous = true;
246         torture_rpc_tcase_add_test(tcase, "GetNumRecords", test_GetNumRecords);
247         torture_rpc_tcase_add_test(tcase, "ReadEventLog", test_ReadEventLog);
248         torture_rpc_tcase_add_test(tcase, "FlushEventLog", test_FlushEventLog);
249
250         return suite;
251 }