okay :) all cmd_() functions now take int argc, char **argv :) that
[samba.git] / source / rpcclient / cmd_eventlog.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 2.1.
4    Copyright (C) Luke Kenneth Casson Leighton 1996-1999,
5    Copyright (C) Andrew Tridgell              1994-1999,
6    Copyright (C) Jean Francois Micouleau      1998-1999.
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
24 #ifdef SYSLOG
25 #undef SYSLOG
26 #endif
27
28 #include "includes.h"
29 #include "nterr.h"
30
31 extern int DEBUGLEVEL;
32
33 #define DEBUG_TESTING
34
35 extern struct cli_state *smb_cli;
36 extern FILE* out_hnd;
37
38
39 /****************************************************************************
40 ****************************************************************************/
41 void cmd_eventlog(struct client_info *info, int argc, char *argv[])
42 {
43         uint16 nt_pipe_fnum;
44         BOOL res  = True;
45         BOOL res1 = True;
46         POLICY_HND hnd;
47         uint32 number = 0;
48         uint32 flags;
49         uint32 offset;
50         uint32 num_of_bytes;
51         EVENTLOGRECORD ev;
52         
53         fstring journal;
54         fstring temp;
55         
56         flags=EVENTLOG_READ_SEQUENTIAL|EVENTLOG_READ_BACKWARD;
57
58         while (next_token(NULL, temp, NULL, sizeof(temp)))
59         {
60                 fstrcpy(journal, temp);
61         }
62
63         /* open scheduler session. */
64         res1 = res1 ? cli_nt_session_open(smb_cli, PIPE_EVENTLOG, &nt_pipe_fnum) : False;
65
66         res1 = res1 ? do_event_open(smb_cli, nt_pipe_fnum, journal, &hnd) : False;
67
68         res = res1 ? do_event_numofeventlogrec(smb_cli, nt_pipe_fnum, &hnd, &number) : False;
69         
70         fprintf(out_hnd, "Number of events: %d\n", number);
71
72         display_eventlog_eventrecord(out_hnd, ACTION_HEADER, &ev);
73
74         for (offset = 0; offset < number && res; offset++)
75         {
76                 num_of_bytes=0;
77         
78                 /* try once with a empty buffer */
79                 res = res ? do_event_readeventlog(smb_cli, nt_pipe_fnum, &hnd, number, 
80                                                   flags, offset, &num_of_bytes, &ev) : False;
81         
82                 /* and try again with the correct size */
83                 res = res ? do_event_readeventlog(smb_cli, nt_pipe_fnum, &hnd, number, 
84                                                   flags, offset, &num_of_bytes, &ev) : False;
85
86                 display_eventlog_eventrecord(out_hnd, ACTION_ENUMERATE, &ev);
87         }
88
89         display_eventlog_eventrecord(out_hnd, ACTION_FOOTER, &ev);
90                         
91         res1 = res1 ? do_event_close(smb_cli, nt_pipe_fnum, &hnd): False;
92
93         /* close the session */
94         cli_nt_session_close(smb_cli, nt_pipe_fnum);
95 }