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