Patch 2 of 3 from Debian Samba packagers:
[Samba.git] / source / rpc_server / srv_eventlog.c
blob516ea134f281065789e2e6cd79ef64e5a73e3e6a
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.
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.
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/>.
21 #include "includes.h"
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_RPC_SRV
26 static bool proxy_eventlog_call(pipes_struct *p, uint8 opnum)
28 struct api_struct *fns;
29 int n_fns;
31 eventlog_get_pipe_fns(&fns, &n_fns);
33 if (opnum >= n_fns)
34 return False;
36 if (fns[opnum].opnum != opnum) {
37 smb_panic("EVENTLOG function table not sorted\n");
40 return fns[opnum].fn(p);
43 static bool api_eventlog_open_eventlog(pipes_struct *p)
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;
50 ZERO_STRUCT(q_u);
51 ZERO_STRUCT(r_u);
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;
58 r_u.status = _eventlog_open_eventlog(p, &q_u, &r_u);
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;
65 return True;
68 static bool api_eventlog_close_eventlog(pipes_struct *p)
70 return proxy_eventlog_call( p, NDR_EVENTLOG_CLOSEEVENTLOG );
73 static bool api_eventlog_get_num_records(pipes_struct *p)
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;
80 ZERO_STRUCT(q_u);
81 ZERO_STRUCT(r_u);
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;
88 r_u.status = _eventlog_get_num_records(p, &q_u, &r_u);
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;
95 return True;
98 static bool api_eventlog_get_oldest_entry(pipes_struct *p)
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;
105 ZERO_STRUCT(q_u);
106 ZERO_STRUCT(r_u);
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;
113 r_u.status = _eventlog_get_oldest_entry(p, &q_u, &r_u);
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;
120 return True;
123 static bool api_eventlog_read_eventlog(pipes_struct *p)
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;
130 ZERO_STRUCT(q_u);
131 ZERO_STRUCT(r_u);
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;
138 r_u.status = _eventlog_read_eventlog(p, &q_u, &r_u);
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;
145 return True;
148 static bool api_eventlog_clear_eventlog(pipes_struct *p)
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;
155 ZERO_STRUCT(q_u);
156 ZERO_STRUCT(r_u);
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;
163 r_u.status = _eventlog_clear_eventlog(p, &q_u, &r_u);
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;
170 return True;
174 \pipe\eventlog commands
176 struct api_struct api_eventlog_cmds[] =
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 }
186 NTSTATUS rpc_eventlog2_init(void)
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));
193 void eventlog2_get_pipe_fns(struct api_struct **fns, int *n_fns)
195 *fns = api_eventlog_cmds;
196 *n_fns = sizeof(api_eventlog_cmds) / sizeof(struct api_struct);