r3513: Add (the infrastructure for) DCOM support. Contents:
[Samba/gebeck_regimport.git] / source4 / torture / rpc / eventlog.c
blob91e012cdec7728135008c26845fb388441340ce0
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for eventlog rpc operations
5 Copyright (C) Tim Potter 2003
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
24 #include "librpc/gen_ndr/ndr_eventlog.h"
26 static void init_eventlog_String(struct eventlog_String *name, const char *s)
28 name->name = s;
29 name->name_len = 2*strlen_m(s);
30 name->name_size = name->name_len;
33 static BOOL test_GetNumRecords(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle)
35 NTSTATUS status;
36 struct eventlog_GetNumRecords r;
38 printf("\ntesting GetNumRecords\n");
40 r.in.handle = handle;
42 status = dcerpc_eventlog_GetNumRecords(p, mem_ctx, &r);
44 if (!NT_STATUS_IS_OK(status)) {
45 printf("GetNumRecords failed - %s\n", nt_errstr(status));
46 return False;
49 printf("%d records\n", r.out.number);
51 return True;
54 static BOOL test_ReadEventLog(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, uint32_t offset)
56 NTSTATUS status;
57 struct eventlog_ReadEventLogW r;
59 printf("\ntesting ReadEventLog\n");
61 r.in.flags = 0x0;
62 r.in.offset = offset;
63 r.in.handle = handle;
64 r.in.number_of_bytes = 0x0;
66 status = dcerpc_eventlog_ReadEventLogW(p, mem_ctx, &r);
68 if (!NT_STATUS_IS_OK(status)) {
69 printf("ReadEventLog failed - %s\n", nt_errstr(status));
70 return False;
73 if (NT_STATUS_IS_OK(r.out.result)) {
74 /* No data */
75 return True;
78 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_BUFFER_TOO_SMALL)) {
79 printf("ReadEventLog failed - %s\n", nt_errstr(r.out.result));
80 return False;
83 r.in.number_of_bytes = r.out.real_size;
85 status = dcerpc_eventlog_ReadEventLogW(p, mem_ctx, &r);
87 if (!NT_STATUS_IS_OK(status)) {
88 printf("ReadEventLog failed - %s\n", nt_errstr(status));
89 return False;
93 return True;
96 static BOOL test_CloseEventLog(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
97 struct policy_handle *handle)
99 NTSTATUS status;
100 struct eventlog_CloseEventLog r;
102 r.in.handle = r.out.handle = handle;
104 printf("Testing CloseEventLog\n");
106 status = dcerpc_eventlog_CloseEventLog(p, mem_ctx, &r);
107 if (!NT_STATUS_IS_OK(status)) {
108 printf("CloseEventLog failed - %s\n", nt_errstr(status));
109 return False;
112 return True;
115 static BOOL test_OpenEventLog(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle)
117 NTSTATUS status;
118 struct eventlog_OpenEventLogW r;
119 struct eventlog_OpenUnknown0 unknown0;
121 printf("\ntesting OpenEventLog\n");
123 unknown0.unknown0 = 0x005c;
124 unknown0.unknown1 = 0x0001;
126 r.in.unknown0 = &unknown0;
127 init_eventlog_String(&r.in.source, "system");
128 init_eventlog_String(&r.in.unknown1, NULL);
129 r.in.unknown2 = 0x00000001;
130 r.in.unknown3 = 0x00000001;
131 r.out.handle = handle;
133 status = dcerpc_eventlog_OpenEventLogW(p, mem_ctx, &r);
135 if (!NT_STATUS_IS_OK(status)) {
136 printf("OpenEventLog failed - %s\n", nt_errstr(status));
137 return False;
140 if (!NT_STATUS_IS_OK(r.out.result)) {
141 printf("OpenEventLog failed - %s\n", nt_errstr(r.out.result));
142 return False;
145 return True;
148 BOOL torture_rpc_eventlog(void)
150 NTSTATUS status;
151 struct dcerpc_pipe *p;
152 struct policy_handle handle;
153 TALLOC_CTX *mem_ctx;
154 BOOL ret = True;
156 mem_ctx = talloc_init("torture_rpc_atsvc");
158 status = torture_rpc_connection(&p,
159 DCERPC_EVENTLOG_NAME,
160 DCERPC_EVENTLOG_UUID,
161 DCERPC_EVENTLOG_VERSION);
162 if (!NT_STATUS_IS_OK(status)) {
163 return False;
166 if (!test_OpenEventLog(p, mem_ctx, &handle)) {
167 return False;
170 test_GetNumRecords(p, mem_ctx, &handle);
172 test_ReadEventLog(p, mem_ctx, &handle, 0);
174 test_CloseEventLog(p, mem_ctx, &handle);
176 talloc_destroy(mem_ctx);
178 torture_rpc_close(p);
180 return ret;