[GLUE] Rsync SAMBA_3_0 SVN r25598 in order to create the v3-0-test branch.
[Samba.git] / source / rpc_parse / parse_eventlog.c
blob436f35aff6a770958342deaa3bbedfb489578f21
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Marcin Krzysztof Porwit 2005.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "includes.h"
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_RPC_PARSE
26 /********************************************************************
27 ********************************************************************/
29 BOOL prs_ev_open_unknown0( const char *desc, prs_struct *ps, int depth, EVENTLOG_OPEN_UNKNOWN0 *u )
31 if ( !u )
32 return False;
34 if ( !prs_uint16("", ps, depth, &u->unknown1) )
35 return False;
36 if ( !prs_uint16("", ps, depth, &u->unknown2) )
37 return False;
39 return True;
42 /********************************************************************
43 ********************************************************************/
45 BOOL eventlog_io_q_open_eventlog(const char *desc, EVENTLOG_Q_OPEN_EVENTLOG *q_u,
46 prs_struct *ps, int depth)
48 if(q_u == NULL)
49 return False;
51 prs_debug(ps, depth, desc, "eventlog_io_q_open_eventlog");
52 depth++;
54 if(!prs_align(ps))
55 return False;
57 if ( !prs_pointer("", ps, depth, (void*)&q_u->unknown0, sizeof(EVENTLOG_OPEN_UNKNOWN0), (PRS_POINTER_CAST)prs_ev_open_unknown0))
58 return False;
60 if ( !prs_unistr4("logname", ps, depth, &q_u->logname) )
61 return False;
62 if ( !prs_align(ps) )
63 return False;
65 if ( !prs_unistr4("servername", ps, depth, &q_u->servername) )
66 return False;
67 if ( !prs_align(ps) )
68 return False;
70 if ( !prs_uint32("unknown1", ps, depth, &q_u->unknown1) )
71 return False;
72 if ( !prs_uint32("unknown2", ps, depth, &q_u->unknown2) )
73 return False;
75 return True;
78 BOOL eventlog_io_r_open_eventlog(const char *desc, EVENTLOG_R_OPEN_EVENTLOG *r_u,
79 prs_struct *ps, int depth)
81 if(r_u == NULL)
82 return False;
84 prs_debug(ps, depth, desc, "eventlog_io_r_open_eventlog");
85 depth++;
87 if(!prs_align(ps))
88 return False;
90 if(!(smb_io_pol_hnd("log handle", &(r_u->handle), ps, depth)))
91 return False;
93 if(!(prs_ntstatus("status code", ps, depth, &r_u->status)))
94 return False;
96 return True;
99 BOOL eventlog_io_q_get_num_records(const char *desc, EVENTLOG_Q_GET_NUM_RECORDS *q_u,
100 prs_struct *ps, int depth)
102 if(q_u == NULL)
103 return False;
105 prs_debug(ps, depth, desc, "eventlog_io_q_get_num_records");
106 depth++;
108 if(!(prs_align(ps)))
109 return False;
111 if(!(smb_io_pol_hnd("log handle", &(q_u->handle), ps, depth)))
112 return False;
114 return True;
117 BOOL eventlog_io_r_get_num_records(const char *desc, EVENTLOG_R_GET_NUM_RECORDS *r_u,
118 prs_struct *ps, int depth)
120 if(r_u == NULL)
121 return False;
123 prs_debug(ps, depth, desc, "eventlog_io_r_get_num_records");
124 depth++;
126 if(!(prs_align(ps)))
127 return False;
129 if(!(prs_uint32("num records", ps, depth, &(r_u->num_records))))
130 return False;
132 if(!(prs_ntstatus("status code", ps, depth, &r_u->status)))
133 return False;
135 return True;
138 BOOL eventlog_io_q_get_oldest_entry(const char *desc, EVENTLOG_Q_GET_OLDEST_ENTRY *q_u,
139 prs_struct *ps, int depth)
141 if(q_u == NULL)
142 return False;
144 prs_debug(ps, depth, desc, "eventlog_io_q_get_oldest_entry");
145 depth++;
147 if(!(prs_align(ps)))
148 return False;
150 if(!(smb_io_pol_hnd("log handle", &(q_u->handle), ps, depth)))
151 return False;
153 return True;
156 BOOL eventlog_io_r_get_oldest_entry(const char *desc, EVENTLOG_R_GET_OLDEST_ENTRY *r_u,
157 prs_struct *ps, int depth)
159 if(r_u == NULL)
160 return False;
162 prs_debug(ps, depth, desc, "eventlog_io_r_get_oldest_entry");
163 depth++;
165 if(!(prs_align(ps)))
166 return False;
168 if(!(prs_uint32("oldest entry", ps, depth, &(r_u->oldest_entry))))
169 return False;
171 if(!(prs_ntstatus("status code", ps, depth, &r_u->status)))
172 return False;
174 return True;
177 BOOL eventlog_io_q_close_eventlog(const char *desc, EVENTLOG_Q_CLOSE_EVENTLOG *q_u,
178 prs_struct *ps, int depth)
180 if(q_u == NULL)
181 return False;
183 prs_debug(ps, depth, desc, "eventlog_io_q_close_eventlog");
184 depth++;
186 if(!(prs_align(ps)))
187 return False;
189 if(!(smb_io_pol_hnd("log handle", &(q_u->handle), ps, depth)))
190 return False;
192 return True;
195 BOOL eventlog_io_r_close_eventlog(const char *desc, EVENTLOG_R_CLOSE_EVENTLOG *r_u,
196 prs_struct *ps, int depth)
198 if(r_u == NULL)
199 return False;
201 prs_debug(ps, depth, desc, "eventlog_io_r_close_eventlog");
202 depth++;
204 if(!(prs_align(ps)))
205 return False;
207 if(!(smb_io_pol_hnd("log handle", &(r_u->handle), ps, depth)))
208 return False;
210 if(!(prs_ntstatus("status code", ps, depth, &r_u->status)))
211 return False;
213 return True;
216 BOOL eventlog_io_q_read_eventlog(const char *desc, EVENTLOG_Q_READ_EVENTLOG *q_u,
217 prs_struct *ps, int depth)
219 if(q_u == NULL)
220 return False;
222 prs_debug(ps, depth, desc, "eventlog_io_q_read_eventlog");
223 depth++;
225 if(!(prs_align(ps)))
226 return False;
228 if(!(smb_io_pol_hnd("log handle", &(q_u->handle), ps, depth)))
229 return False;
231 if(!(prs_uint32("read flags", ps, depth, &(q_u->flags))))
232 return False;
234 if(!(prs_uint32("read offset", ps, depth, &(q_u->offset))))
235 return False;
237 if(!(prs_uint32("read buf size", ps, depth, &(q_u->max_read_size))))
238 return False;
240 return True;
242 /** Structure of response seems to be:
243 DWORD num_bytes_in_resp -- MUST be the same as q_u->max_read_size
244 for i=0..n
245 EVENTLOGRECORD record
246 DWORD sent_size -- sum of EVENTLOGRECORD lengths if records returned, 0 otherwise
247 DWORD real_size -- 0 if records returned, otherwise length of next record to be returned
248 WERROR status */
249 BOOL eventlog_io_r_read_eventlog(const char *desc,
250 EVENTLOG_Q_READ_EVENTLOG *q_u,
251 EVENTLOG_R_READ_EVENTLOG *r_u,
252 prs_struct *ps,
253 int depth)
255 Eventlog_entry *entry;
256 uint32 record_written = 0;
257 uint32 record_total = 0;
259 if(r_u == NULL)
260 return False;
262 prs_debug(ps, depth, desc, "eventlog_io_r_read_eventlog");
263 depth++;
265 /* First, see if we've read more logs than we can output */
267 if(r_u->num_bytes_in_resp > q_u->max_read_size) {
268 entry = r_u->entry;
270 /* remove the size of the last entry from the list */
272 while(entry->next != NULL)
273 entry = entry->next;
275 r_u->num_bytes_in_resp -= entry->record.length;
277 /* do not output the last log entry */
279 r_u->num_records--;
282 entry = r_u->entry;
283 record_total = r_u->num_records;
285 if(r_u->num_bytes_in_resp != 0)
286 r_u->sent_size = r_u->num_bytes_in_resp;
287 else
288 r_u->real_size = r_u->bytes_in_next_record;
290 if(!(prs_align(ps)))
291 return False;
292 if(!(prs_uint32("bytes in resp", ps, depth, &(q_u->max_read_size))))
293 return False;
295 while(entry != NULL && record_written < record_total)
297 DEBUG(11, ("eventlog_io_r_read_eventlog: writing record [%d] out of [%d].\n", record_written, record_total));
299 /* Encode the actual eventlog record record */
301 if(!(prs_uint32("length", ps, depth, &(entry->record.length))))
302 return False;
303 if(!(prs_uint32("reserved", ps, depth, &(entry->record.reserved1))))
304 return False;
305 if(!(prs_uint32("record number", ps, depth, &(entry->record.record_number))))
306 return False;
307 if(!(prs_uint32("time generated", ps, depth, &(entry->record.time_generated))))
308 return False;
309 if(!(prs_uint32("time written", ps, depth, &(entry->record.time_written))))
310 return False;
311 if(!(prs_uint32("event id", ps, depth, &(entry->record.event_id))))
312 return False;
313 if(!(prs_uint16("event type", ps, depth, &(entry->record.event_type))))
314 return False;
315 if(!(prs_uint16("num strings", ps, depth, &(entry->record.num_strings))))
316 return False;
317 if(!(prs_uint16("event category", ps, depth, &(entry->record.event_category))))
318 return False;
319 if(!(prs_uint16("reserved2", ps, depth, &(entry->record.reserved2))))
320 return False;
321 if(!(prs_uint32("closing record", ps, depth, &(entry->record.closing_record_number))))
322 return False;
323 if(!(prs_uint32("string offset", ps, depth, &(entry->record.string_offset))))
324 return False;
325 if(!(prs_uint32("user sid length", ps, depth, &(entry->record.user_sid_length))))
326 return False;
327 if(!(prs_uint32("user sid offset", ps, depth, &(entry->record.user_sid_offset))))
328 return False;
329 if(!(prs_uint32("data length", ps, depth, &(entry->record.data_length))))
330 return False;
331 if(!(prs_uint32("data offset", ps, depth, &(entry->record.data_offset))))
332 return False;
333 if(!(prs_align(ps)))
334 return False;
336 /* Now encoding data */
338 if(!(prs_uint8s(False, "buffer", ps, depth, entry->data,
339 entry->record.length - sizeof(Eventlog_record) - sizeof(entry->record.length))))
341 return False;
344 if(!(prs_align(ps)))
345 return False;
346 if(!(prs_uint32("length 2", ps, depth, &(entry->record.length))))
347 return False;
349 entry = entry->next;
350 record_written++;
352 } /* end of encoding EVENTLOGRECORD */
354 /* Now pad with whitespace until the end of the response buffer */
356 if (q_u->max_read_size - r_u->num_bytes_in_resp) {
357 if (!r_u->end_of_entries_padding) {
358 return False;
361 if(!(prs_uint8s(False, "end of entries padding", ps,
362 depth, r_u->end_of_entries_padding,
363 (q_u->max_read_size - r_u->num_bytes_in_resp)))) {
364 free(r_u->end_of_entries_padding);
365 return False;
368 free(r_u->end_of_entries_padding);
371 /* We had better be DWORD aligned here */
373 if(!(prs_uint32("sent size", ps, depth, &(r_u->sent_size))))
374 return False;
375 if(!(prs_uint32("real size", ps, depth, &(r_u->real_size))))
376 return False;
377 if(!(prs_ntstatus("status code", ps, depth, &r_u->status)))
378 return False;
380 return True;
383 /** The windows client seems to be doing something funny with the file name
384 A call like
385 ClearEventLog(handle, "backup_file")
386 on the client side will result in the backup file name looking like this on the
387 server side:
388 \??\${CWD of client}\backup_file
389 If an absolute path gets specified, such as
390 ClearEventLog(handle, "C:\\temp\\backup_file")
391 then it is still mangled by the client into this:
392 \??\C:\temp\backup_file
393 when it is on the wire.
394 I'm not sure where the \?? is coming from, or why the ${CWD} of the client process
395 would be added in given that the backup file gets written on the server side. */
397 BOOL eventlog_io_q_clear_eventlog(const char *desc, EVENTLOG_Q_CLEAR_EVENTLOG *q_u,
398 prs_struct *ps, int depth)
400 if(q_u == NULL)
401 return False;
403 prs_debug(ps, depth, desc, "eventlog_io_q_clear_eventlog");
404 depth++;
406 if(!prs_align(ps))
407 return False;
408 if(!(smb_io_pol_hnd("log handle", &(q_u->handle), ps, depth)))
409 return False;
411 if ( !prs_unistr4("backupfile", ps, depth, &q_u->backupfile) )
412 return False;
414 return True;
418 BOOL eventlog_io_r_clear_eventlog(const char *desc, EVENTLOG_R_CLEAR_EVENTLOG *r_u,
419 prs_struct *ps, int depth)
421 if(r_u == NULL)
422 return False;
424 prs_debug(ps, depth, desc, "eventlog_io_r_clear_eventlog");
425 depth++;
427 if(!prs_align(ps))
428 return False;
429 if(!(prs_ntstatus("status code", ps, depth, &r_u->status)))
430 return False;
432 return True;