r5037: got rid of all of the TALLOC_DEPRECATED stuff. My apologies for the
[bbaumbach/samba-autobuild/.git] / source4 / torture / rpc / eventlog.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for eventlog rpc operations
4
5    Copyright (C) Tim Potter 2003
6    Copyright (C) Jelmer Vernooij 2004
7    
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.
12    
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.
17    
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.
21 */
22
23 #include "includes.h"
24 #include "librpc/gen_ndr/ndr_eventlog.h"
25
26 static void init_eventlog_String(struct eventlog_String *name, const char *s)
27 {
28         name->name = s;
29         name->name_len = 2*strlen_m(s);
30         name->name_size = name->name_len;
31 }
32
33 static BOOL test_GetNumRecords(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle)
34 {
35         NTSTATUS status;
36         struct eventlog_GetNumRecords r;
37
38         printf("\ntesting GetNumRecords\n");
39
40         r.in.handle = handle;
41
42         status = dcerpc_eventlog_GetNumRecords(p, mem_ctx, &r);
43
44         if (!NT_STATUS_IS_OK(status)) {
45                 printf("GetNumRecords failed - %s\n", nt_errstr(status));
46                 return False;
47         }
48
49         printf("%d records\n", r.out.number);
50
51         return True;
52 }
53
54 static BOOL test_ReadEventLog(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, uint32_t offset)
55 {
56         NTSTATUS status;
57         struct eventlog_ReadEventLogW r;
58
59         printf("\ntesting ReadEventLog\n");
60
61         r.in.flags = 0x0;
62         r.in.offset = offset;
63         r.in.handle = handle;
64         r.in.number_of_bytes = 0x0;
65
66         status = dcerpc_eventlog_ReadEventLogW(p, mem_ctx, &r);
67
68         if (!NT_STATUS_IS_OK(status)) {
69                 printf("ReadEventLog failed - %s\n", nt_errstr(status));
70                 return False;
71         }
72
73         if (NT_STATUS_IS_OK(r.out.result)) {
74                 /* No data */
75                 return True;
76         }
77
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;
81         }
82
83         r.in.number_of_bytes = r.out.real_size;
84
85         status = dcerpc_eventlog_ReadEventLogW(p, mem_ctx, &r);
86
87         if (!NT_STATUS_IS_OK(status)) {
88                 printf("ReadEventLog failed - %s\n", nt_errstr(status));
89                 return False;
90         }
91
92
93         return True;
94 }
95
96 static BOOL test_CloseEventLog(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
97                         struct policy_handle *handle)
98 {
99         NTSTATUS status;
100         struct eventlog_CloseEventLog r;
101
102         r.in.handle = r.out.handle = handle;
103
104         printf("Testing CloseEventLog\n");
105
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;
110         }
111
112         return True;
113 }
114
115 static BOOL test_OpenEventLog(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle)
116 {
117         NTSTATUS status;
118         struct eventlog_OpenEventLogW r;
119         struct eventlog_OpenUnknown0 unknown0;
120
121         printf("\ntesting OpenEventLog\n");
122
123         unknown0.unknown0 = 0x005c;
124         unknown0.unknown1 = 0x0001;
125
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;
132
133         status = dcerpc_eventlog_OpenEventLogW(p, mem_ctx, &r);
134
135         if (!NT_STATUS_IS_OK(status)) {
136                 printf("OpenEventLog failed - %s\n", nt_errstr(status));
137                 return False;
138         }
139
140         if (!NT_STATUS_IS_OK(r.out.result)) {
141                 printf("OpenEventLog failed - %s\n", nt_errstr(r.out.result));
142                 return False;
143         }
144
145         return True;
146 }
147
148 BOOL torture_rpc_eventlog(void)
149 {
150     NTSTATUS status;
151     struct dcerpc_pipe *p;
152         struct policy_handle handle;
153         TALLOC_CTX *mem_ctx;
154         BOOL ret = True;
155
156         mem_ctx = talloc_init("torture_rpc_atsvc");
157
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;
164         }
165
166         if (!test_OpenEventLog(p, mem_ctx, &handle)) {
167                 return False;
168         }
169
170         test_GetNumRecords(p, mem_ctx, &handle);
171
172         test_ReadEventLog(p, mem_ctx, &handle, 0);
173
174         test_CloseEventLog(p, mem_ctx, &handle);
175
176         talloc_free(mem_ctx);
177
178     torture_rpc_close(p);
179
180         return ret;
181 }