2 Unix SMB/CIFS implementation.
3 test suite for eventlog rpc operations
5 Copyright (C) Tim Potter 2003,2005
6 Copyright (C) Jelmer Vernooij 2004
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.
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.
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/>.
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 #include "param/param.h"
30 static void init_lsa_String(struct lsa_String *name, const char *s)
33 name->length = 2*strlen_m(s);
34 name->size = name->length;
37 static bool get_policy_handle(struct torture_context *tctx,
38 struct dcerpc_pipe *p,
39 struct policy_handle *handle)
41 struct eventlog_OpenEventLogW r;
42 struct eventlog_OpenUnknown0 unknown0;
43 struct lsa_String logname, servername;
45 unknown0.unknown0 = 0x005c;
46 unknown0.unknown1 = 0x0001;
48 r.in.unknown0 = &unknown0;
49 init_lsa_String(r.in.logname, "dns server");
50 init_lsa_String(r.in.servername, NULL);
51 r.in.logname = &logname;
52 r.in.servername = &servername;
53 r.in.unknown2 = 0x00000001;
54 r.in.unknown3 = 0x00000001;
55 r.out.handle = handle;
57 torture_assert_ntstatus_ok(tctx,
58 dcerpc_eventlog_OpenEventLogW(p, tctx, &r),
59 "OpenEventLog failed");
61 torture_assert_ntstatus_ok(tctx, r.out.result, "OpenEventLog failed");
68 static bool test_GetNumRecords(struct torture_context *tctx, struct dcerpc_pipe *p)
70 struct eventlog_GetNumRecords r;
71 struct eventlog_CloseEventLog cr;
72 struct policy_handle handle;
75 if (!get_policy_handle(tctx, p, &handle))
79 r.in.handle = &handle;
80 r.out.number = &number;
82 torture_assert_ntstatus_ok(tctx,
83 dcerpc_eventlog_GetNumRecords(p, tctx, &r),
84 "GetNumRecords failed");
86 torture_comment(tctx, "%d records\n", *r.out.number);
88 cr.in.handle = cr.out.handle = &handle;
90 torture_assert_ntstatus_ok(tctx,
91 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
92 "CloseEventLog failed");
96 static bool test_ReadEventLog(struct torture_context *tctx,
97 struct dcerpc_pipe *p)
100 struct eventlog_ReadEventLogW r;
101 struct eventlog_CloseEventLog cr;
102 struct policy_handle handle;
104 if (!get_policy_handle(tctx, p, &handle))
109 r.in.handle = &handle;
110 r.in.flags = EVENTLOG_BACKWARDS_READ|EVENTLOG_SEQUENTIAL_READ;
114 struct eventlog_Record rec;
115 struct ndr_pull *ndr;
116 enum ndr_err_code ndr_err;
117 uint32_t sent_size = 0;
118 uint32_t real_size = 0;
120 /* Read first for number of bytes in record */
122 r.in.number_of_bytes = 0;
124 r.out.sent_size = &sent_size;
125 r.out.real_size = &real_size;
127 status = dcerpc_eventlog_ReadEventLogW(p, tctx, &r);
129 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_END_OF_FILE)) {
133 torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_BUFFER_TOO_SMALL,
134 "ReadEventLog failed");
136 /* Now read the actual record */
138 r.in.number_of_bytes = *r.out.real_size;
139 r.out.data = talloc_array(tctx, uint8_t, r.in.number_of_bytes);
141 status = dcerpc_eventlog_ReadEventLogW(p, tctx, &r);
143 torture_assert_ntstatus_ok(tctx, status, "ReadEventLog failed");
145 /* Decode a user-marshalled record */
147 blob.length = *r.out.sent_size;
148 blob.data = talloc_steal(tctx, r.out.data);
150 ndr = ndr_pull_init_blob(&blob, tctx, lp_iconv_convenience(tctx->lp_ctx));
152 ndr_err = ndr_pull_eventlog_Record(
153 ndr, NDR_SCALARS|NDR_BUFFERS, &rec);
154 status = ndr_map_error2ntstatus(ndr_err);
156 NDR_PRINT_DEBUG(eventlog_Record, &rec);
158 torture_assert_ntstatus_ok(tctx, status,
159 "ReadEventLog failed parsing event log record");
164 cr.in.handle = cr.out.handle = &handle;
166 torture_assert_ntstatus_ok(tctx,
167 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
168 "CloseEventLog failed");
173 static bool test_FlushEventLog(struct torture_context *tctx,
174 struct dcerpc_pipe *p)
176 struct eventlog_FlushEventLog r;
177 struct eventlog_CloseEventLog cr;
178 struct policy_handle handle;
180 if (!get_policy_handle(tctx, p, &handle))
183 r.in.handle = &handle;
185 /* Huh? Does this RPC always return access denied? */
186 torture_assert_ntstatus_equal(tctx,
187 dcerpc_eventlog_FlushEventLog(p, tctx, &r),
188 NT_STATUS_ACCESS_DENIED,
189 "FlushEventLog failed");
191 cr.in.handle = cr.out.handle = &handle;
193 torture_assert_ntstatus_ok(tctx,
194 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
195 "CloseEventLog failed");
200 static bool test_ClearEventLog(struct torture_context *tctx,
201 struct dcerpc_pipe *p)
203 struct eventlog_ClearEventLogW r;
204 struct eventlog_CloseEventLog cr;
205 struct policy_handle handle;
207 if (!get_policy_handle(tctx, p, &handle))
210 r.in.handle = &handle;
211 r.in.backupfile = NULL;
213 torture_assert_ntstatus_ok(tctx,
214 dcerpc_eventlog_ClearEventLogW(p, tctx, &r),
215 "ClearEventLog failed");
217 cr.in.handle = cr.out.handle = &handle;
219 torture_assert_ntstatus_ok(tctx,
220 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
221 "CloseEventLog failed");
226 static bool test_OpenEventLog(struct torture_context *tctx,
227 struct dcerpc_pipe *p)
229 struct policy_handle handle;
230 struct eventlog_CloseEventLog cr;
232 if (!get_policy_handle(tctx, p, &handle))
235 cr.in.handle = cr.out.handle = &handle;
237 torture_assert_ntstatus_ok(tctx,
238 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
239 "CloseEventLog failed");
244 struct torture_suite *torture_rpc_eventlog(TALLOC_CTX *mem_ctx)
246 struct torture_suite *suite;
247 struct torture_rpc_tcase *tcase;
248 struct torture_test *test;
250 suite = torture_suite_create(mem_ctx, "EVENTLOG");
251 tcase = torture_suite_add_rpc_iface_tcase(suite, "eventlog",
252 &ndr_table_eventlog);
254 torture_rpc_tcase_add_test(tcase, "OpenEventLog", test_OpenEventLog);
255 test = torture_rpc_tcase_add_test(tcase, "ClearEventLog",
257 test->dangerous = true;
258 torture_rpc_tcase_add_test(tcase, "GetNumRecords", test_GetNumRecords);
259 torture_rpc_tcase_add_test(tcase, "ReadEventLog", test_ReadEventLog);
260 torture_rpc_tcase_add_test(tcase, "FlushEventLog", test_FlushEventLog);