a1acf1f25fa10c1d1e2a2f58069af4d6a8254fa7
[gd/samba/.git] / source / 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, write to the Free Software
19  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21  
22 #include "includes.h"
23
24 #undef DBGC_CLASS
25 #define DBGC_CLASS DBGC_RPC_SRV
26
27 static BOOL proxy_eventlog_call(pipes_struct *p, uint8 opnum)
28 {
29         struct api_struct *fns;
30         int n_fns;
31
32         eventlog_get_pipe_fns(&fns, &n_fns);
33
34         if (opnum >= n_fns)
35                 return False;
36
37         if (fns[opnum].opnum != opnum) {
38                 smb_panic("EVENTLOG function table not sorted\n");
39         }
40
41         return fns[opnum].fn(p);
42 }
43
44 static BOOL api_eventlog_open_eventlog(pipes_struct *p)
45 {
46         EVENTLOG_Q_OPEN_EVENTLOG q_u;
47         EVENTLOG_R_OPEN_EVENTLOG r_u;
48         prs_struct *data = &p->in_data.data;
49         prs_struct *rdata = &p->out_data.rdata;
50
51         ZERO_STRUCT(q_u);
52         ZERO_STRUCT(r_u);
53
54         if (!(eventlog_io_q_open_eventlog("", &q_u, data, 0))) {
55                 DEBUG(0, ("eventlog_io_q_open_eventlog: unable to unmarshall EVENTLOG_Q_OPEN_EVENTLOG.\n"));
56                 return False;
57         }
58         
59         r_u.status = _eventlog_open_eventlog(p, &q_u, &r_u);
60
61         if (!(eventlog_io_r_open_eventlog("", &r_u, rdata, 0))) {
62                 DEBUG(0, ("eventlog_io_r_open_eventlog: unable to marshall EVENTLOG_R_OPEN_EVENTLOG.\n"));
63                 return False;
64         }
65
66         return True;
67 }
68
69 static BOOL api_eventlog_close_eventlog(pipes_struct *p)
70 {
71         return proxy_eventlog_call( p, DCERPC_EVENTLOG_CLOSEEVENTLOG ); 
72 }
73
74 static BOOL api_eventlog_get_num_records(pipes_struct *p)
75 {
76         EVENTLOG_Q_GET_NUM_RECORDS q_u;
77         EVENTLOG_R_GET_NUM_RECORDS r_u;
78         prs_struct *data = &p->in_data.data;
79         prs_struct *rdata = &p->out_data.rdata;
80
81         ZERO_STRUCT(q_u);
82         ZERO_STRUCT(r_u);
83
84         if (!(eventlog_io_q_get_num_records("", &q_u, data, 0))) {
85                 DEBUG(0, ("eventlog_io_q_get_num_records: unable to unmarshall EVENTLOG_Q_GET_NUM_RECORDS.\n"));
86                 return False;
87         }
88     
89         r_u.status = _eventlog_get_num_records(p, &q_u, &r_u);
90     
91         if (!(eventlog_io_r_get_num_records("", &r_u, rdata, 0))) {
92                 DEBUG(0, ("eventlog_io_r_get_num_records: unable to marshall EVENTLOG_R_GET_NUM_RECORDS.\n"));
93                 return False;
94         }
95
96         return True;
97 }
98
99 static BOOL api_eventlog_get_oldest_entry(pipes_struct *p)
100 {
101         EVENTLOG_Q_GET_OLDEST_ENTRY q_u;
102         EVENTLOG_R_GET_OLDEST_ENTRY r_u;
103         prs_struct *data = &p->in_data.data;
104         prs_struct *rdata = &p->out_data.rdata;
105
106         ZERO_STRUCT(q_u);
107         ZERO_STRUCT(r_u);
108
109         if (!(eventlog_io_q_get_oldest_entry("", &q_u, data, 0))) {
110                 DEBUG(0, ("eventlog_io_q_get_oldest_entry: unable to unmarshall EVENTLOG_Q_GET_OLDEST_ENTRY.\n"));
111                 return False;
112         }
113
114         r_u.status = _eventlog_get_oldest_entry(p, &q_u, &r_u);
115     
116         if (!(eventlog_io_r_get_oldest_entry("", &r_u, rdata, 0))) {
117                 DEBUG(0, ("eventlog_io_r_get_oldest_entry: unable to marshall EVENTLOG_R_GET_OLDEST_ENTRY.\n"));
118                 return False;
119         }
120     
121         return True;
122 }
123
124 static BOOL api_eventlog_read_eventlog(pipes_struct *p)
125 {
126         EVENTLOG_Q_READ_EVENTLOG q_u;
127         EVENTLOG_R_READ_EVENTLOG r_u;
128         prs_struct *data = &p->in_data.data;
129         prs_struct *rdata = &p->out_data.rdata;
130
131         ZERO_STRUCT(q_u);
132         ZERO_STRUCT(r_u);
133
134         if (!(eventlog_io_q_read_eventlog("", &q_u, data, 0))) {
135                 DEBUG(0, ("eventlog_io_q_read_eventlog: unable to unmarshall EVENTLOG_Q_READ_EVENTLOG.\n"));
136                 return False;
137         }
138
139         r_u.status = _eventlog_read_eventlog(p, &q_u, &r_u);
140
141         if (!(eventlog_io_r_read_eventlog("", &q_u, &r_u, rdata, 0))) {
142                 DEBUG(0, ("eventlog_io_r_read_eventlog: unable to marshall EVENTLOG_R_READ_EVENTLOG.\n"));
143                 return False;
144         }
145
146         return True;
147 }
148
149 static BOOL api_eventlog_clear_eventlog(pipes_struct *p)
150 {
151         EVENTLOG_Q_CLEAR_EVENTLOG q_u;
152         EVENTLOG_R_CLEAR_EVENTLOG r_u;
153         prs_struct *data = &p->in_data.data;
154         prs_struct *rdata = &p->out_data.rdata;
155
156         ZERO_STRUCT(q_u);
157         ZERO_STRUCT(r_u);
158
159         if (!(eventlog_io_q_clear_eventlog("", &q_u, data, 0))) {
160                 DEBUG(0, ("eventlog_io_q_clear_eventlog: unable to unmarshall EVENTLOG_Q_CLEAR_EVENTLOG.\n"));
161                 return False;
162         }
163
164         r_u.status = _eventlog_clear_eventlog(p, &q_u, &r_u);
165
166         if (!(eventlog_io_r_clear_eventlog("", &r_u, rdata, 0))) {
167                 DEBUG(0, ("eventlog_io_q_clear_eventlog: unable to marshall EVENTLOG_Q_CLEAR_EVENTLOG.\n"));
168                 return False;
169         }
170
171         return True;
172 }
173
174 /*
175  \pipe\eventlog commands
176 */
177 struct api_struct api_eventlog_cmds[] =
178 {
179         {"EVENTLOG_OPENEVENTLOG",       EVENTLOG_OPENEVENTLOG,          api_eventlog_open_eventlog    },
180         {"EVENTLOG_CLOSEEVENTLOG",      EVENTLOG_CLOSEEVENTLOG,         api_eventlog_close_eventlog   },
181         {"EVENTLOG_GETNUMRECORDS",      EVENTLOG_GETNUMRECORDS,         api_eventlog_get_num_records  },
182         {"EVENTLOG_GETOLDESTENTRY",     EVENTLOG_GETOLDESTENTRY,        api_eventlog_get_oldest_entry },
183         {"EVENTLOG_READEVENTLOG",       EVENTLOG_READEVENTLOG,          api_eventlog_read_eventlog    },
184         {"EVENTLOG_CLEAREVENTLOG",      EVENTLOG_CLEAREVENTLOG,         api_eventlog_clear_eventlog   }
185 };
186
187 NTSTATUS rpc_eventlog2_init(void)
188 {
189         return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, 
190                 "eventlog", "eventlog", api_eventlog_cmds,
191                 sizeof(api_eventlog_cmds)/sizeof(struct api_struct));
192 }
193
194 void eventlog2_get_pipe_fns(struct api_struct **fns, int *n_fns)
195 {
196         *fns = api_eventlog_cmds;
197         *n_fns = sizeof(api_eventlog_cmds) / sizeof(struct api_struct);
198 }