first pass at updating head branch to be to be the same as the SAMBA_2_0 branch
[nivanova/samba-autobuild/.git] / source3 / rpc_client / cli_eventlog.c
1 /* 
2  *  Unix SMB/Netbios implementation.
3  *  Version 2.1.
4  *  RPC client routines: scheduler service
5  *  Copyright (C) Jean Francois Micouleau      1998-1999,
6  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1999,
7  *  Copyright (C) Andrew Tridgell              1992-1999.
8  *  
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *  
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *  
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #include "includes.h"
25
26 extern int DEBUGLEVEL;
27
28 /****************************************************************************
29 ****************************************************************************/
30 BOOL event_open(const char* srv_name, const char *log, POLICY_HND *hnd)
31 {
32         prs_struct rbuf;
33         prs_struct buf; 
34         EVENTLOG_Q_OPEN q;
35         BOOL p = False;
36         BOOL valid_pol = False;
37         
38         struct cli_connection *con = NULL;
39
40         if (!cli_connection_init(srv_name, PIPE_EVENTLOG, &con))
41         {
42                 return False;
43         }
44
45         prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
46         prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
47
48         /* store the parameters */
49         make_eventlog_q_open(&q, log, NULL);
50
51         /* turn parameters into data stream */
52         eventlog_io_q_open("", &q, &buf, 0);
53
54         /* send the data on \PIPE\ */
55         if (rpc_con_pipe_req(con, EVENTLOG_OPEN, &buf, &rbuf))
56         {
57                 EVENTLOG_R_OPEN r;
58
59                 eventlog_io_r_open("", &r, &rbuf, 0);
60                 p = rbuf.offset != 0;
61
62                 if (p && r.status != 0)
63                 {
64                         /* report error code */
65                         DEBUG(0,("event_open: %s\n", get_nt_error_msg(r.status)));
66                         p = False;
67                 }
68
69                 if (p)
70                 {
71                         /*copy handle */
72                         memcpy(hnd->data, r.pol.data, sizeof(hnd->data));
73                         valid_pol = register_policy_hnd(hnd) &&
74                                     set_policy_con(hnd, con, 
75                                                          cli_connection_unlink);
76                 }
77         }
78
79         prs_mem_free(&rbuf);
80         prs_mem_free(&buf );
81
82         return p;
83 }
84
85 /****************************************************************************
86 ****************************************************************************/
87 BOOL event_close( POLICY_HND *hnd)
88 {
89         prs_struct rbuf;
90         prs_struct buf; 
91         EVENTLOG_Q_CLOSE q;
92         BOOL p = False;
93
94         prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
95         prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
96
97         /* store the parameters */
98         make_eventlog_q_close(&q, hnd);
99
100         /* turn parameters into data stream */
101         eventlog_io_q_close("", &q, &buf, 0);
102
103         /* send the data on \PIPE\ */
104         if (rpc_hnd_pipe_req(hnd, EVENTLOG_CLOSE, &buf, &rbuf))
105         {
106                 EVENTLOG_R_CLOSE r;
107
108                 eventlog_io_r_close("", &r, &rbuf, 0);
109                 p = rbuf.offset != 0;
110
111                 if (p && r.status != 0)
112                 {
113                         /* report error code */
114                         DEBUG(0,("event_close: %s\n", get_nt_error_msg(r.status)));
115                         p = False;
116                 }
117
118         }
119
120         prs_mem_free(&rbuf);
121         prs_mem_free(&buf );
122
123         close_policy_hnd(hnd);
124
125         return p;
126 }
127
128 /****************************************************************************
129 ****************************************************************************/
130 BOOL event_numofeventlogrec( POLICY_HND *hnd, uint32 *number)
131 {
132         prs_struct rbuf;
133         prs_struct buf; 
134         EVENTLOG_Q_NUMOFEVENTLOGREC q;
135         BOOL p = False;
136
137         prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
138         prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
139
140         /* store the parameters */
141         make_eventlog_q_numofeventlogrec(&q, hnd);
142
143         /* turn parameters into data stream */
144         eventlog_io_q_numofeventlogrec("", &q, &buf, 0);
145
146         /* send the data on \PIPE\ */
147         if (rpc_hnd_pipe_req(hnd, EVENTLOG_NUMOFEVENTLOGRECORDS, &buf, &rbuf))
148         {
149                 EVENTLOG_R_NUMOFEVENTLOGREC r;
150
151                 eventlog_io_r_numofeventlogrec("", &r, &rbuf, 0);
152                 p = rbuf.offset != 0;
153
154                 if (p && r.status != 0)
155                 {
156                         /* report error code */
157                         DEBUG(0,("event_close: %s\n", get_nt_error_msg(r.status)));
158                         p = False;
159                 }
160
161                 if (p)
162                 {
163                         *number=r.number;
164                 }
165         }
166
167         prs_mem_free(&rbuf);
168         prs_mem_free(&buf );
169
170         return p;
171 }
172
173 /****************************************************************************
174 ****************************************************************************/
175 BOOL event_readeventlog(POLICY_HND *hnd, 
176                            uint32 number, uint32 flags, uint32 offset, 
177                            uint32 *number_of_bytes, EVENTLOGRECORD *ev)
178 {
179         prs_struct rbuf;
180         prs_struct buf; 
181         EVENTLOG_Q_READEVENTLOG q;
182         EVENTLOG_R_READEVENTLOG r;
183         BOOL p = False;
184
185         prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
186         prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
187
188         /* store the parameters */
189         make_eventlog_q_readeventlog(&q, hnd, flags, offset, *number_of_bytes);
190
191         /* turn parameters into data stream */
192         eventlog_io_q_readeventlog("", &q, &buf, 0);
193
194         /* send the data on \PIPE\ */
195         if (rpc_hnd_pipe_req(hnd, EVENTLOG_READEVENTLOG, &buf, &rbuf))
196         {
197                 r.event=ev;
198                 eventlog_io_r_readeventlog("", &r, &rbuf, 0);
199                 p = rbuf.offset != 0;
200
201                 if (p)
202                 {
203                         *number_of_bytes=r.real_size;           
204                 }
205         }
206
207         prs_mem_free(&rbuf);
208         prs_mem_free(&buf );
209
210         return p;
211 }
212