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"
29 static void init_lsa_String(struct lsa_String *name, const char *s)
32 name->length = 2*strlen_m(s);
33 name->size = name->length;
36 static bool get_policy_handle(struct torture_context *tctx,
37 struct dcerpc_pipe *p,
38 struct policy_handle *handle)
40 struct eventlog_OpenEventLogW r;
41 struct eventlog_OpenUnknown0 unknown0;
43 unknown0.unknown0 = 0x005c;
44 unknown0.unknown1 = 0x0001;
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;
53 torture_assert_ntstatus_ok(tctx,
54 dcerpc_eventlog_OpenEventLogW(p, tctx, &r),
55 "OpenEventLog failed");
57 torture_assert_ntstatus_ok(tctx, r.out.result, "OpenEventLog failed");
64 static bool test_GetNumRecords(struct torture_context *tctx, struct dcerpc_pipe *p)
66 struct eventlog_GetNumRecords r;
67 struct eventlog_CloseEventLog cr;
68 struct policy_handle handle;
70 if (!get_policy_handle(tctx, p, &handle))
73 r.in.handle = &handle;
75 torture_assert_ntstatus_ok(tctx,
76 dcerpc_eventlog_GetNumRecords(p, tctx, &r),
77 "GetNumRecords failed");
79 torture_comment(tctx, "%d records\n", *r.out.number);
81 cr.in.handle = cr.out.handle = &handle;
83 torture_assert_ntstatus_ok(tctx,
84 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
85 "CloseEventLog failed");
89 static bool test_ReadEventLog(struct torture_context *tctx,
90 struct dcerpc_pipe *p)
93 struct eventlog_ReadEventLogW r;
94 struct eventlog_CloseEventLog cr;
95 struct policy_handle handle;
97 if (!get_policy_handle(tctx, p, &handle))
101 r.in.handle = &handle;
102 r.in.flags = EVENTLOG_BACKWARDS_READ|EVENTLOG_SEQUENTIAL_READ;
106 struct eventlog_Record rec;
107 struct ndr_pull *ndr;
109 /* Read first for number of bytes in record */
111 r.in.number_of_bytes = 0;
114 status = dcerpc_eventlog_ReadEventLogW(p, tctx, &r);
116 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_END_OF_FILE)) {
120 torture_assert_ntstatus_ok(tctx, status, "ReadEventLog failed");
122 torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_BUFFER_TOO_SMALL,
123 "ReadEventLog failed");
125 /* Now read the actual record */
127 r.in.number_of_bytes = *r.out.real_size;
128 r.out.data = talloc_size(tctx, r.in.number_of_bytes);
130 status = dcerpc_eventlog_ReadEventLogW(p, tctx, &r);
132 torture_assert_ntstatus_ok(tctx, status, "ReadEventLog failed");
134 /* Decode a user-marshalled record */
136 blob.length = *r.out.sent_size;
137 blob.data = talloc_steal(tctx, r.out.data);
139 ndr = ndr_pull_init_blob(&blob, tctx);
141 status = ndr_pull_eventlog_Record(
142 ndr, NDR_SCALARS|NDR_BUFFERS, &rec);
144 NDR_PRINT_DEBUG(eventlog_Record, &rec);
146 torture_assert_ntstatus_ok(tctx, status,
147 "ReadEventLog failed parsing event log record");
152 cr.in.handle = cr.out.handle = &handle;
154 torture_assert_ntstatus_ok(tctx,
155 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
156 "CloseEventLog failed");
161 static bool test_FlushEventLog(struct torture_context *tctx,
162 struct dcerpc_pipe *p)
164 struct eventlog_FlushEventLog r;
165 struct eventlog_CloseEventLog cr;
166 struct policy_handle handle;
168 if (!get_policy_handle(tctx, p, &handle))
171 r.in.handle = &handle;
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");
179 cr.in.handle = cr.out.handle = &handle;
181 torture_assert_ntstatus_ok(tctx,
182 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
183 "CloseEventLog failed");
188 static bool test_ClearEventLog(struct torture_context *tctx,
189 struct dcerpc_pipe *p)
191 struct eventlog_ClearEventLogW r;
192 struct eventlog_CloseEventLog cr;
193 struct policy_handle handle;
195 if (!torture_setting_bool(tctx, "dangerous", false)) {
196 torture_skip(tctx, "ClearEventLog test disabled - enable dangerous tests to use");
199 if (!get_policy_handle(tctx, p, &handle))
202 r.in.handle = &handle;
205 torture_assert_ntstatus_ok(tctx,
206 dcerpc_eventlog_ClearEventLogW(p, tctx, &r),
207 "ClearEventLog failed");
209 cr.in.handle = cr.out.handle = &handle;
211 torture_assert_ntstatus_ok(tctx,
212 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
213 "CloseEventLog failed");
218 static bool test_OpenEventLog(struct torture_context *tctx,
219 struct dcerpc_pipe *p)
221 struct policy_handle handle;
222 struct eventlog_CloseEventLog cr;
224 if (!get_policy_handle(tctx, p, &handle))
227 cr.in.handle = cr.out.handle = &handle;
229 torture_assert_ntstatus_ok(tctx,
230 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
231 "CloseEventLog failed");
236 struct torture_suite *torture_rpc_eventlog(void)
238 struct torture_suite *suite;
239 struct torture_rpc_tcase *tcase;
241 suite = torture_suite_create(talloc_autofree_context(), "EVENTLOG");
242 tcase = torture_suite_add_rpc_iface_tcase(suite, "eventlog",
243 &ndr_table_eventlog);
245 torture_rpc_tcase_add_test(tcase, "OpenEventLog", test_OpenEventLog);
246 torture_rpc_tcase_add_test(tcase, "ClearEventLog", test_ClearEventLog);
247 torture_rpc_tcase_add_test(tcase, "GetNumRecords", test_GetNumRecords);
248 torture_rpc_tcase_add_test(tcase, "ReadEventLog", test_ReadEventLog);
249 torture_rpc_tcase_add_test(tcase, "FlushEventLog", test_FlushEventLog);