2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Marcin Krzysztof Porwit 2005.
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.
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
)
34 if ( !prs_uint16("", ps
, depth
, &u
->unknown1
) )
36 if ( !prs_uint16("", ps
, depth
, &u
->unknown2
) )
42 /********************************************************************
43 ********************************************************************/
45 BOOL
eventlog_io_q_open_eventlog(const char *desc
, EVENTLOG_Q_OPEN_EVENTLOG
*q_u
,
46 prs_struct
*ps
, int depth
)
51 prs_debug(ps
, depth
, desc
, "eventlog_io_q_open_eventlog");
57 if ( !prs_pointer("", ps
, depth
, (void**)&q_u
->unknown0
, sizeof(EVENTLOG_OPEN_UNKNOWN0
), (PRS_POINTER_CAST
)prs_ev_open_unknown0
))
60 if ( !prs_unistr4("logname", ps
, depth
, &q_u
->logname
) )
65 if ( !prs_unistr4("servername", ps
, depth
, &q_u
->servername
) )
70 if ( !prs_uint32("unknown1", ps
, depth
, &q_u
->unknown1
) )
72 if ( !prs_uint32("unknown2", ps
, depth
, &q_u
->unknown2
) )
78 BOOL
eventlog_io_r_open_eventlog(const char *desc
, EVENTLOG_R_OPEN_EVENTLOG
*r_u
,
79 prs_struct
*ps
, int depth
)
84 prs_debug(ps
, depth
, desc
, "eventlog_io_r_open_eventlog");
90 if(!(smb_io_pol_hnd("log handle", &(r_u
->handle
), ps
, depth
)))
93 if(!(prs_ntstatus("status code", ps
, depth
, &r_u
->status
)))
99 BOOL
eventlog_io_q_get_num_records(const char *desc
, EVENTLOG_Q_GET_NUM_RECORDS
*q_u
,
100 prs_struct
*ps
, int depth
)
105 prs_debug(ps
, depth
, desc
, "eventlog_io_q_get_num_records");
111 if(!(smb_io_pol_hnd("log handle", &(q_u
->handle
), ps
, depth
)))
117 BOOL
eventlog_io_r_get_num_records(const char *desc
, EVENTLOG_R_GET_NUM_RECORDS
*r_u
,
118 prs_struct
*ps
, int depth
)
123 prs_debug(ps
, depth
, desc
, "eventlog_io_r_get_num_records");
129 if(!(prs_uint32("num records", ps
, depth
, &(r_u
->num_records
))))
132 if(!(prs_ntstatus("status code", ps
, depth
, &r_u
->status
)))
138 BOOL
eventlog_io_q_get_oldest_entry(const char *desc
, EVENTLOG_Q_GET_OLDEST_ENTRY
*q_u
,
139 prs_struct
*ps
, int depth
)
144 prs_debug(ps
, depth
, desc
, "eventlog_io_q_get_oldest_entry");
150 if(!(smb_io_pol_hnd("log handle", &(q_u
->handle
), ps
, depth
)))
156 BOOL
eventlog_io_r_get_oldest_entry(const char *desc
, EVENTLOG_R_GET_OLDEST_ENTRY
*r_u
,
157 prs_struct
*ps
, int depth
)
162 prs_debug(ps
, depth
, desc
, "eventlog_io_r_get_oldest_entry");
168 if(!(prs_uint32("oldest entry", ps
, depth
, &(r_u
->oldest_entry
))))
171 if(!(prs_ntstatus("status code", ps
, depth
, &r_u
->status
)))
177 BOOL
eventlog_io_q_close_eventlog(const char *desc
, EVENTLOG_Q_CLOSE_EVENTLOG
*q_u
,
178 prs_struct
*ps
, int depth
)
183 prs_debug(ps
, depth
, desc
, "eventlog_io_q_close_eventlog");
189 if(!(smb_io_pol_hnd("log handle", &(q_u
->handle
), ps
, depth
)))
195 BOOL
eventlog_io_r_close_eventlog(const char *desc
, EVENTLOG_R_CLOSE_EVENTLOG
*r_u
,
196 prs_struct
*ps
, int depth
)
201 prs_debug(ps
, depth
, desc
, "eventlog_io_r_close_eventlog");
207 if(!(smb_io_pol_hnd("log handle", &(r_u
->handle
), ps
, depth
)))
210 if(!(prs_ntstatus("status code", ps
, depth
, &r_u
->status
)))
216 BOOL
eventlog_io_q_read_eventlog(const char *desc
, EVENTLOG_Q_READ_EVENTLOG
*q_u
,
217 prs_struct
*ps
, int depth
)
222 prs_debug(ps
, depth
, desc
, "eventlog_io_q_read_eventlog");
228 if(!(smb_io_pol_hnd("log handle", &(q_u
->handle
), ps
, depth
)))
231 if(!(prs_uint32("read flags", ps
, depth
, &(q_u
->flags
))))
234 if(!(prs_uint32("read offset", ps
, depth
, &(q_u
->offset
))))
237 if(!(prs_uint32("read buf size", ps
, depth
, &(q_u
->max_read_size
))))
242 /** Structure of response seems to be:
243 DWORD num_bytes_in_resp -- MUST be the same as q_u->max_read_size
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
249 BOOL
eventlog_io_r_read_eventlog(const char *desc
,
250 EVENTLOG_Q_READ_EVENTLOG
*q_u
,
251 EVENTLOG_R_READ_EVENTLOG
*r_u
,
255 Eventlog_entry
*entry
;
256 uint32 record_written
= 0;
257 uint32 record_total
= 0;
262 prs_debug(ps
, depth
, desc
, "eventlog_io_r_read_eventlog");
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
) {
270 /* remove the size of the last entry from the list */
272 while(entry
->next
!= NULL
)
275 r_u
->num_bytes_in_resp
-= entry
->record
.length
;
277 /* do not output the last log 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
;
288 r_u
->real_size
= r_u
->bytes_in_next_record
;
292 if(!(prs_uint32("bytes in resp", ps
, depth
, &(q_u
->max_read_size
))))
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
))))
303 if(!(prs_uint32("reserved", ps
, depth
, &(entry
->record
.reserved1
))))
305 if(!(prs_uint32("record number", ps
, depth
, &(entry
->record
.record_number
))))
307 if(!(prs_uint32("time generated", ps
, depth
, &(entry
->record
.time_generated
))))
309 if(!(prs_uint32("time written", ps
, depth
, &(entry
->record
.time_written
))))
311 if(!(prs_uint32("event id", ps
, depth
, &(entry
->record
.event_id
))))
313 if(!(prs_uint16("event type", ps
, depth
, &(entry
->record
.event_type
))))
315 if(!(prs_uint16("num strings", ps
, depth
, &(entry
->record
.num_strings
))))
317 if(!(prs_uint16("event category", ps
, depth
, &(entry
->record
.event_category
))))
319 if(!(prs_uint16("reserved2", ps
, depth
, &(entry
->record
.reserved2
))))
321 if(!(prs_uint32("closing record", ps
, depth
, &(entry
->record
.closing_record_number
))))
323 if(!(prs_uint32("string offset", ps
, depth
, &(entry
->record
.string_offset
))))
325 if(!(prs_uint32("user sid length", ps
, depth
, &(entry
->record
.user_sid_length
))))
327 if(!(prs_uint32("user sid offset", ps
, depth
, &(entry
->record
.user_sid_offset
))))
329 if(!(prs_uint32("data length", ps
, depth
, &(entry
->record
.data_length
))))
331 if(!(prs_uint32("data offset", ps
, depth
, &(entry
->record
.data_offset
))))
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
))))
346 if(!(prs_uint32("length 2", ps
, depth
, &(entry
->record
.length
))))
352 } /* end of encoding EVENTLOGRECORD */
354 /* Now pad with whitespace until the end of the response buffer */
356 r_u
->end_of_entries_padding
=
357 SMB_CALLOC_ARRAY(uint8
,
358 q_u
->max_read_size
- r_u
->num_bytes_in_resp
);
360 if(!(prs_uint8s(False
, "end of entries padding", ps
,
361 depth
, r_u
->end_of_entries_padding
,
362 (q_u
->max_read_size
- r_u
->num_bytes_in_resp
))))
367 free(r_u
->end_of_entries_padding
);
369 /* We had better be DWORD aligned here */
371 if(!(prs_uint32("sent size", ps
, depth
, &(r_u
->sent_size
))))
373 if(!(prs_uint32("real size", ps
, depth
, &(r_u
->real_size
))))
375 if(!(prs_ntstatus("status code", ps
, depth
, &r_u
->status
)))
381 /** The windows client seems to be doing something funny with the file name
383 ClearEventLog(handle, "backup_file")
384 on the client side will result in the backup file name looking like this on the
386 \??\${CWD of client}\backup_file
387 If an absolute path gets specified, such as
388 ClearEventLog(handle, "C:\\temp\\backup_file")
389 then it is still mangled by the client into this:
390 \??\C:\temp\backup_file
391 when it is on the wire.
392 I'm not sure where the \?? is coming from, or why the ${CWD} of the client process
393 would be added in given that the backup file gets written on the server side. */
395 BOOL
eventlog_io_q_clear_eventlog(const char *desc
, EVENTLOG_Q_CLEAR_EVENTLOG
*q_u
,
396 prs_struct
*ps
, int depth
)
401 prs_debug(ps
, depth
, desc
, "eventlog_io_q_clear_eventlog");
406 if(!(smb_io_pol_hnd("log handle", &(q_u
->handle
), ps
, depth
)))
409 if ( !prs_unistr4("backupfile", ps
, depth
, &q_u
->backupfile
) )
416 BOOL
eventlog_io_r_clear_eventlog(const char *desc
, EVENTLOG_R_CLEAR_EVENTLOG
*r_u
,
417 prs_struct
*ps
, int depth
)
422 prs_debug(ps
, depth
, desc
, "eventlog_io_r_clear_eventlog");
427 if(!(prs_ntstatus("status code", ps
, depth
, &r_u
->status
)))