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;
72 if (!get_policy_handle(tctx, p, &handle))
76 r.in.handle = &handle;
77 r.out.number = &number;
79 torture_assert_ntstatus_ok(tctx,
80 dcerpc_eventlog_GetNumRecords(p, tctx, &r),
81 "GetNumRecords failed");
83 torture_comment(tctx, "%d records\n", *r.out.number);
85 cr.in.handle = cr.out.handle = &handle;
87 torture_assert_ntstatus_ok(tctx,
88 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
89 "CloseEventLog failed");
93 static bool test_ReadEventLog(struct torture_context *tctx,
94 struct dcerpc_pipe *p)
97 struct eventlog_ReadEventLogW r;
98 struct eventlog_CloseEventLog cr;
99 struct policy_handle handle;
101 if (!get_policy_handle(tctx, p, &handle))
106 r.in.handle = &handle;
107 r.in.flags = EVENTLOG_BACKWARDS_READ|EVENTLOG_SEQUENTIAL_READ;
111 struct eventlog_Record rec;
112 struct ndr_pull *ndr;
113 enum ndr_err_code ndr_err;
114 uint32_t sent_size = 0;
115 uint32_t real_size = 0;
117 /* Read first for number of bytes in record */
119 r.in.number_of_bytes = 0;
121 r.out.sent_size = &sent_size;
122 r.out.real_size = &real_size;
124 status = dcerpc_eventlog_ReadEventLogW(p, tctx, &r);
126 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_END_OF_FILE)) {
130 torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_BUFFER_TOO_SMALL,
131 "ReadEventLog failed");
133 /* Now read the actual record */
135 r.in.number_of_bytes = *r.out.real_size;
136 r.out.data = talloc_array(tctx, uint8_t, r.in.number_of_bytes);
138 status = dcerpc_eventlog_ReadEventLogW(p, tctx, &r);
140 torture_assert_ntstatus_ok(tctx, status, "ReadEventLog failed");
142 /* Decode a user-marshalled record */
144 blob.length = *r.out.sent_size;
145 blob.data = talloc_steal(tctx, r.out.data);
147 ndr = ndr_pull_init_blob(&blob, tctx, lp_iconv_convenience(tctx->lp_ctx));
149 ndr_err = ndr_pull_eventlog_Record(
150 ndr, NDR_SCALARS|NDR_BUFFERS, &rec);
151 status = ndr_map_error2ntstatus(ndr_err);
153 NDR_PRINT_DEBUG(eventlog_Record, &rec);
155 torture_assert_ntstatus_ok(tctx, status,
156 "ReadEventLog failed parsing event log record");
161 cr.in.handle = cr.out.handle = &handle;
163 torture_assert_ntstatus_ok(tctx,
164 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
165 "CloseEventLog failed");
170 static bool test_FlushEventLog(struct torture_context *tctx,
171 struct dcerpc_pipe *p)
173 struct eventlog_FlushEventLog r;
174 struct eventlog_CloseEventLog cr;
175 struct policy_handle handle;
177 if (!get_policy_handle(tctx, p, &handle))
180 r.in.handle = &handle;
182 /* Huh? Does this RPC always return access denied? */
183 torture_assert_ntstatus_equal(tctx,
184 dcerpc_eventlog_FlushEventLog(p, tctx, &r),
185 NT_STATUS_ACCESS_DENIED,
186 "FlushEventLog failed");
188 cr.in.handle = cr.out.handle = &handle;
190 torture_assert_ntstatus_ok(tctx,
191 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
192 "CloseEventLog failed");
197 static bool test_ClearEventLog(struct torture_context *tctx,
198 struct dcerpc_pipe *p)
200 struct eventlog_ClearEventLogW r;
201 struct eventlog_CloseEventLog cr;
202 struct policy_handle handle;
204 if (!get_policy_handle(tctx, p, &handle))
207 r.in.handle = &handle;
210 torture_assert_ntstatus_ok(tctx,
211 dcerpc_eventlog_ClearEventLogW(p, tctx, &r),
212 "ClearEventLog failed");
214 cr.in.handle = cr.out.handle = &handle;
216 torture_assert_ntstatus_ok(tctx,
217 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
218 "CloseEventLog failed");
223 static bool test_OpenEventLog(struct torture_context *tctx,
224 struct dcerpc_pipe *p)
226 struct policy_handle handle;
227 struct eventlog_CloseEventLog cr;
229 if (!get_policy_handle(tctx, p, &handle))
232 cr.in.handle = cr.out.handle = &handle;
234 torture_assert_ntstatus_ok(tctx,
235 dcerpc_eventlog_CloseEventLog(p, tctx, &cr),
236 "CloseEventLog failed");
241 struct torture_suite *torture_rpc_eventlog(TALLOC_CTX *mem_ctx)
243 struct torture_suite *suite;
244 struct torture_rpc_tcase *tcase;
245 struct torture_test *test;
247 suite = torture_suite_create(mem_ctx, "EVENTLOG");
248 tcase = torture_suite_add_rpc_iface_tcase(suite, "eventlog",
249 &ndr_table_eventlog);
251 torture_rpc_tcase_add_test(tcase, "OpenEventLog", test_OpenEventLog);
252 test = torture_rpc_tcase_add_test(tcase, "ClearEventLog",
254 test->dangerous = true;
255 torture_rpc_tcase_add_test(tcase, "GetNumRecords", test_GetNumRecords);
256 torture_rpc_tcase_add_test(tcase, "ReadEventLog", test_ReadEventLog);
257 torture_rpc_tcase_add_test(tcase, "FlushEventLog", test_FlushEventLog);