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;
44 unknown0.unknown0 = 0x005c;
45 unknown0.unknown1 = 0x0001;
47 r.in.unknown0 = &unknown0;
48 init_lsa_String(&r.in.logname, "dns server");
49 init_lsa_String(&r.in.servername, NULL);
50 r.in.unknown2 = 0x00000001;
51 r.in.unknown3 = 0x00000001;
52 r.out.handle = handle;
54 torture_assert_ntstatus_ok(tctx,
55 dcerpc_eventlog_OpenEventLogW(p, tctx, &r),
56 "OpenEventLog failed");
58 torture_assert_ntstatus_ok(tctx, r.out.result, "OpenEventLog failed");
65 static bool test_GetNumRecords(struct torture_context *tctx, struct dcerpc_pipe *p)
67 struct eventlog_GetNumRecords r;
68 struct eventlog_CloseEventLog cr;
69 struct policy_handle handle;
71 if (!get_policy_handle(tctx, p, &handle))
74 r.in.handle = &handle;
76 torture_assert_ntstatus_ok(tctx,
77 dcerpc_eventlog_GetNumRecords(p, tctx, &r),
78 "GetNumRecords failed");
80 torture_comment(tctx, "%d records\n", *r.out.number);
82 cr.in.handle = cr.out.handle = &handle;
84 torture_assert_ntstatus_ok(tctx,
85 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
86 "CloseEventLog failed");
90 static bool test_ReadEventLog(struct torture_context *tctx,
91 struct dcerpc_pipe *p)
94 struct eventlog_ReadEventLogW r;
95 struct eventlog_CloseEventLog cr;
96 struct policy_handle handle;
98 if (!get_policy_handle(tctx, p, &handle))
102 r.in.handle = &handle;
103 r.in.flags = EVENTLOG_BACKWARDS_READ|EVENTLOG_SEQUENTIAL_READ;
107 struct eventlog_Record rec;
108 struct ndr_pull *ndr;
109 enum ndr_err_code ndr_err;
111 /* Read first for number of bytes in record */
113 r.in.number_of_bytes = 0;
116 status = dcerpc_eventlog_ReadEventLogW(p, tctx, &r);
118 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_END_OF_FILE)) {
122 torture_assert_ntstatus_ok(tctx, status, "ReadEventLog failed");
124 torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_BUFFER_TOO_SMALL,
125 "ReadEventLog failed");
127 /* Now read the actual record */
129 r.in.number_of_bytes = *r.out.real_size;
130 r.out.data = talloc_array(tctx, uint8_t, r.in.number_of_bytes);
132 status = dcerpc_eventlog_ReadEventLogW(p, tctx, &r);
134 torture_assert_ntstatus_ok(tctx, status, "ReadEventLog failed");
136 /* Decode a user-marshalled record */
138 blob.length = *r.out.sent_size;
139 blob.data = talloc_steal(tctx, r.out.data);
141 ndr = ndr_pull_init_blob(&blob, tctx, lp_iconv_convenience(tctx->lp_ctx));
143 ndr_err = ndr_pull_eventlog_Record(
144 ndr, NDR_SCALARS|NDR_BUFFERS, &rec);
145 status = ndr_map_error2ntstatus(ndr_err);
147 NDR_PRINT_DEBUG(eventlog_Record, &rec);
149 torture_assert_ntstatus_ok(tctx, status,
150 "ReadEventLog failed parsing event log record");
155 cr.in.handle = cr.out.handle = &handle;
157 torture_assert_ntstatus_ok(tctx,
158 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
159 "CloseEventLog failed");
164 static bool test_FlushEventLog(struct torture_context *tctx,
165 struct dcerpc_pipe *p)
167 struct eventlog_FlushEventLog r;
168 struct eventlog_CloseEventLog cr;
169 struct policy_handle handle;
171 if (!get_policy_handle(tctx, p, &handle))
174 r.in.handle = &handle;
176 /* Huh? Does this RPC always return access denied? */
177 torture_assert_ntstatus_equal(tctx,
178 dcerpc_eventlog_FlushEventLog(p, tctx, &r),
179 NT_STATUS_ACCESS_DENIED,
180 "FlushEventLog failed");
182 cr.in.handle = cr.out.handle = &handle;
184 torture_assert_ntstatus_ok(tctx,
185 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
186 "CloseEventLog failed");
191 static bool test_ClearEventLog(struct torture_context *tctx,
192 struct dcerpc_pipe *p)
194 struct eventlog_ClearEventLogW r;
195 struct eventlog_CloseEventLog cr;
196 struct policy_handle handle;
198 if (!get_policy_handle(tctx, p, &handle))
201 r.in.handle = &handle;
204 torture_assert_ntstatus_ok(tctx,
205 dcerpc_eventlog_ClearEventLogW(p, tctx, &r),
206 "ClearEventLog failed");
208 cr.in.handle = cr.out.handle = &handle;
210 torture_assert_ntstatus_ok(tctx,
211 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
212 "CloseEventLog failed");
217 static bool test_OpenEventLog(struct torture_context *tctx,
218 struct dcerpc_pipe *p)
220 struct policy_handle handle;
221 struct eventlog_CloseEventLog cr;
223 if (!get_policy_handle(tctx, p, &handle))
226 cr.in.handle = cr.out.handle = &handle;
228 torture_assert_ntstatus_ok(tctx,
229 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
230 "CloseEventLog failed");
235 struct torture_suite *torture_rpc_eventlog(TALLOC_CTX *mem_ctx)
237 struct torture_suite *suite;
238 struct torture_rpc_tcase *tcase;
239 struct torture_test *test;
241 suite = torture_suite_create(mem_ctx, "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 test = torture_rpc_tcase_add_test(tcase, "ClearEventLog",
248 test->dangerous = true;
249 torture_rpc_tcase_add_test(tcase, "GetNumRecords", test_GetNumRecords);
250 torture_rpc_tcase_add_test(tcase, "ReadEventLog", test_ReadEventLog);
251 torture_rpc_tcase_add_test(tcase, "FlushEventLog", test_FlushEventLog);