fcba6a1268cf8d4b0e882c18c8c443bcb2f1b39c
[samba.git] / source3 / rpc_server / srv_eventlog.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Marcin Krzysztof Porwit         2005.
5  *  Copyright (C) Gerald Carter                   2005 - 2007
6  *  
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 3 of the License, or
10  *  (at your option) any later version.
11  *  
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *  
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20  
21 #include "includes.h"
22
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_RPC_SRV
25
26 static BOOL proxy_eventlog_call(pipes_struct *p, uint8 opnum)
27 {
28         struct api_struct *fns;
29         int n_fns;
30
31         eventlog_get_pipe_fns(&fns, &n_fns);
32
33         if (opnum >= n_fns)
34                 return False;
35
36         if (fns[opnum].opnum != opnum) {
37                 smb_panic("EVENTLOG function table not sorted\n");
38         }
39
40         return fns[opnum].fn(p);
41 }
42
43 static BOOL api_eventlog_open_eventlog(pipes_struct *p)
44 {
45         EVENTLOG_Q_OPEN_EVENTLOG q_u;
46         EVENTLOG_R_OPEN_EVENTLOG r_u;
47         prs_struct *data = &p->in_data.data;
48         prs_struct *rdata = &p->out_data.rdata;
49
50         ZERO_STRUCT(q_u);
51         ZERO_STRUCT(r_u);
52
53         if (!(eventlog_io_q_open_eventlog("", &q_u, data, 0))) {
54                 DEBUG(0, ("eventlog_io_q_open_eventlog: unable to unmarshall EVENTLOG_Q_OPEN_EVENTLOG.\n"));
55                 return False;
56         }
57         
58         r_u.status = _eventlog_open_eventlog(p, &q_u, &r_u);
59
60         if (!(eventlog_io_r_open_eventlog("", &r_u, rdata, 0))) {
61                 DEBUG(0, ("eventlog_io_r_open_eventlog: unable to marshall EVENTLOG_R_OPEN_EVENTLOG.\n"));
62                 return False;
63         }
64
65         return True;
66 }
67
68 static BOOL api_eventlog_close_eventlog(pipes_struct *p)
69 {
70         return proxy_eventlog_call( p, NDR_EVENTLOG_CLOSEEVENTLOG );    
71 }
72
73 static BOOL api_eventlog_get_num_records(pipes_struct *p)
74 {
75         EVENTLOG_Q_GET_NUM_RECORDS q_u;
76         EVENTLOG_R_GET_NUM_RECORDS r_u;
77         prs_struct *data = &p->in_data.data;
78         prs_struct *rdata = &p->out_data.rdata;
79
80         ZERO_STRUCT(q_u);
81         ZERO_STRUCT(r_u);
82
83         if (!(eventlog_io_q_get_num_records("", &q_u, data, 0))) {
84                 DEBUG(0, ("eventlog_io_q_get_num_records: unable to unmarshall EVENTLOG_Q_GET_NUM_RECORDS.\n"));
85                 return False;
86         }
87     
88         r_u.status = _eventlog_get_num_records(p, &q_u, &r_u);
89     
90         if (!(eventlog_io_r_get_num_records("", &r_u, rdata, 0))) {
91                 DEBUG(0, ("eventlog_io_r_get_num_records: unable to marshall EVENTLOG_R_GET_NUM_RECORDS.\n"));
92                 return False;
93         }
94
95         return True;
96 }
97
98 static BOOL api_eventlog_get_oldest_entry(pipes_struct *p)
99 {
100         EVENTLOG_Q_GET_OLDEST_ENTRY q_u;
101         EVENTLOG_R_GET_OLDEST_ENTRY r_u;
102         prs_struct *data = &p->in_data.data;
103         prs_struct *rdata = &p->out_data.rdata;
104
105         ZERO_STRUCT(q_u);
106         ZERO_STRUCT(r_u);
107
108         if (!(eventlog_io_q_get_oldest_entry("", &q_u, data, 0))) {
109                 DEBUG(0, ("eventlog_io_q_get_oldest_entry: unable to unmarshall EVENTLOG_Q_GET_OLDEST_ENTRY.\n"));
110                 return False;
111         }
112
113         r_u.status = _eventlog_get_oldest_entry(p, &q_u, &r_u);
114     
115         if (!(eventlog_io_r_get_oldest_entry("", &r_u, rdata, 0))) {
116                 DEBUG(0, ("eventlog_io_r_get_oldest_entry: unable to marshall EVENTLOG_R_GET_OLDEST_ENTRY.\n"));
117                 return False;
118         }
119     
120         return True;
121 }
122
123 static BOOL api_eventlog_read_eventlog(pipes_struct *p)
124 {
125         EVENTLOG_Q_READ_EVENTLOG q_u;
126         EVENTLOG_R_READ_EVENTLOG r_u;
127         prs_struct *data = &p->in_data.data;
128         prs_struct *rdata = &p->out_data.rdata;
129
130         ZERO_STRUCT(q_u);
131         ZERO_STRUCT(r_u);
132
133         if (!(eventlog_io_q_read_eventlog("", &q_u, data, 0))) {
134                 DEBUG(0, ("eventlog_io_q_read_eventlog: unable to unmarshall EVENTLOG_Q_READ_EVENTLOG.\n"));
135                 return False;
136         }
137
138         r_u.status = _eventlog_read_eventlog(p, &q_u, &r_u);
139
140         if (!(eventlog_io_r_read_eventlog("", &q_u, &r_u, rdata, 0))) {
141                 DEBUG(0, ("eventlog_io_r_read_eventlog: unable to marshall EVENTLOG_R_READ_EVENTLOG.\n"));
142                 return False;
143         }
144
145         return True;
146 }
147
148 static BOOL api_eventlog_clear_eventlog(pipes_struct *p)
149 {
150         EVENTLOG_Q_CLEAR_EVENTLOG q_u;
151         EVENTLOG_R_CLEAR_EVENTLOG r_u;
152         prs_struct *data = &p->in_data.data;
153         prs_struct *rdata = &p->out_data.rdata;
154
155         ZERO_STRUCT(q_u);
156         ZERO_STRUCT(r_u);
157
158         if (!(eventlog_io_q_clear_eventlog("", &q_u, data, 0))) {
159                 DEBUG(0, ("eventlog_io_q_clear_eventlog: unable to unmarshall EVENTLOG_Q_CLEAR_EVENTLOG.\n"));
160                 return False;
161         }
162
163         r_u.status = _eventlog_clear_eventlog(p, &q_u, &r_u);
164
165         if (!(eventlog_io_r_clear_eventlog("", &r_u, rdata, 0))) {
166                 DEBUG(0, ("eventlog_io_q_clear_eventlog: unable to marshall EVENTLOG_Q_CLEAR_EVENTLOG.\n"));
167                 return False;
168         }
169
170         return True;
171 }
172
173 /*
174  \pipe\eventlog commands
175 */
176 struct api_struct api_eventlog_cmds[] =
177 {
178         {"EVENTLOG_OPENEVENTLOG",       EVENTLOG_OPENEVENTLOG,          api_eventlog_open_eventlog    },
179         {"EVENTLOG_CLOSEEVENTLOG",      EVENTLOG_CLOSEEVENTLOG,         api_eventlog_close_eventlog   },
180         {"EVENTLOG_GETNUMRECORDS",      EVENTLOG_GETNUMRECORDS,         api_eventlog_get_num_records  },
181         {"EVENTLOG_GETOLDESTENTRY",     EVENTLOG_GETOLDESTENTRY,        api_eventlog_get_oldest_entry },
182         {"EVENTLOG_READEVENTLOG",       EVENTLOG_READEVENTLOG,          api_eventlog_read_eventlog    },
183         {"EVENTLOG_CLEAREVENTLOG",      EVENTLOG_CLEAREVENTLOG,         api_eventlog_clear_eventlog   }
184 };
185
186 NTSTATUS rpc_eventlog2_init(void)
187 {
188         return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, 
189                 "eventlog", "eventlog", api_eventlog_cmds,
190                 sizeof(api_eventlog_cmds)/sizeof(struct api_struct));
191 }
192
193 void eventlog2_get_pipe_fns(struct api_struct **fns, int *n_fns)
194 {
195         *fns = api_eventlog_cmds;
196         *n_fns = sizeof(api_eventlog_cmds) / sizeof(struct api_struct);
197 }