]> jfr.im git - solanum.git/blame - ircd/logger.c
doc/reference.conf: document the auth::umodes configuration option
[solanum.git] / ircd / logger.c
CommitLineData
212380e3 1/*
a6f63a82 2 * Solanum: a slightly advanced ircd
212380e3
AC
3 *
4 * Copyright (C) 2003 Lee H <lee@leeh.co.uk>
5 * Copyright (C) 2003-2005 ircd-ratbox development team
3fc0499e 6 * Copyright (C) 2008 Ariadne Conill <ariadne@dereferenced.org>
212380e3
AC
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * 1.Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
ba1a1399 14 *
212380e3
AC
15 * 2.Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
ba1a1399 18 *
212380e3
AC
19 * 3.The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
212380e3
AC
33 */
34
35#include "stdinc.h"
36#include "ircd_defs.h"
4016731b 37#include "logger.h"
212380e3 38#include "s_conf.h"
212380e3
AC
39#include "send.h"
40#include "client.h"
41#include "s_serv.h"
42
43static FILE *log_main;
44static FILE *log_user;
45static FILE *log_fuser;
46static FILE *log_oper;
47static FILE *log_foper;
48static FILE *log_server;
49static FILE *log_kill;
212380e3
AC
50static FILE *log_kline;
51static FILE *log_operspy;
52static FILE *log_ioerror;
53
54struct log_struct
55{
56 char **name;
57 FILE **logfile;
58};
59
60static struct log_struct log_table[LAST_LOGFILE] =
61{
62 { NULL, &log_main },
63 { &ConfigFileEntry.fname_userlog, &log_user },
64 { &ConfigFileEntry.fname_fuserlog, &log_fuser },
65 { &ConfigFileEntry.fname_operlog, &log_oper },
66 { &ConfigFileEntry.fname_foperlog, &log_foper },
67 { &ConfigFileEntry.fname_serverlog, &log_server },
68 { &ConfigFileEntry.fname_killlog, &log_kill },
69 { &ConfigFileEntry.fname_klinelog, &log_kline },
212380e3
AC
70 { &ConfigFileEntry.fname_operspylog, &log_operspy },
71 { &ConfigFileEntry.fname_ioerrorlog, &log_ioerror }
72};
73
cdf7c361
AS
74static void
75verify_logfile_access(const char *filename)
76{
77 char *dirname, *d;
78 char buf[512];
79 d = rb_dirname(filename);
80 dirname = LOCAL_COPY(d);
81 rb_free(d);
55abcbb2 82
cdf7c361
AS
83 if(access(dirname, F_OK) == -1)
84 {
5203cba5 85 snprintf(buf, sizeof(buf), "WARNING: Unable to access logfile %s - parent directory %s does not exist", filename, dirname);
cdf7c361
AS
86 if(testing_conf || server_state_foreground)
87 fprintf(stderr, "%s\n", buf);
88 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf);
89 return;
90 }
91
92 if(access(filename, F_OK) == -1)
93 {
94 if(access(dirname, W_OK) == -1)
95 {
5203cba5 96 snprintf(buf, sizeof(buf), "WARNING: Unable to access logfile %s - access to parent directory %s failed: %s",
cdf7c361
AS
97 filename, dirname, strerror(errno));
98 if(testing_conf || server_state_foreground)
99 fprintf(stderr, "%s\n", buf);
100 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf);
101 }
102 return;
103 }
55abcbb2 104
cdf7c361
AS
105 if(access(filename, W_OK) == -1)
106 {
5203cba5 107 snprintf(buf, sizeof(buf), "WARNING: Access denied for logfile %s: %s", filename, strerror(errno));
cdf7c361 108 if(testing_conf || server_state_foreground)
55abcbb2 109 fprintf(stderr, "%s\n", buf);
cdf7c361
AS
110 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s", buf);
111 return;
112 }
113 return;
114}
115
212380e3
AC
116void
117init_main_logfile(void)
118{
cdf7c361 119 verify_logfile_access(logFileName);
212380e3 120 if(log_main == NULL)
cdf7c361 121 {
9b6ff0c8 122 log_main = fopen(logFileName, "a");
cdf7c361 123 }
212380e3
AC
124}
125
126void
127open_logfiles(void)
128{
129 int i;
130
ea82a3ca 131 close_logfiles();
212380e3 132
9b6ff0c8 133 log_main = fopen(logFileName, "a");
212380e3
AC
134
135 /* log_main is handled above, so just do the rest */
136 for(i = 1; i < LAST_LOGFILE; i++)
137 {
ea82a3ca
VY
138 /* reopen those with paths */
139 if(!EmptyString(*log_table[i].name))
cdf7c361
AS
140 {
141 verify_logfile_access(*log_table[i].name);
ea82a3ca 142 *log_table[i].logfile = fopen(*log_table[i].name, "a");
cdf7c361 143 }
ea82a3ca 144 }
55abcbb2 145}
ea82a3ca
VY
146
147void
148close_logfiles(void)
149{
150 int i;
151
152 if(log_main != NULL)
153 fclose(log_main);
154
155 /* log_main is handled above, so just do the rest */
156 for(i = 1; i < LAST_LOGFILE; i++)
157 {
212380e3
AC
158 if(*log_table[i].logfile != NULL)
159 {
160 fclose(*log_table[i].logfile);
161 *log_table[i].logfile = NULL;
162 }
212380e3 163 }
ea82a3ca 164}
212380e3
AC
165
166void
167ilog(ilogfile dest, const char *format, ...)
168{
169 FILE *logfile = *log_table[dest].logfile;
170 char buf[BUFSIZE];
b3a987ed 171 char buf2[MAX_DATE_STRING + 1 + BUFSIZE + 1];
212380e3
AC
172 va_list args;
173
174 if(logfile == NULL)
175 return;
176
177 va_start(args, format);
5203cba5 178 vsnprintf(buf, sizeof(buf), format, args);
212380e3
AC
179 va_end(args);
180
5203cba5 181 snprintf(buf2, sizeof(buf2), "%s %s\n",
b52c2949 182 smalldate(rb_current_time()), buf);
212380e3
AC
183
184 if(fputs(buf2, logfile) < 0)
185 {
186 fclose(logfile);
187 *log_table[dest].logfile = NULL;
b7bb9657 188 return;
212380e3
AC
189 }
190
191 fflush(logfile);
192}
193
194static void
ba1a1399 195_iprint(const char *domain, const char *buf)
212380e3
AC
196{
197 if (domain == NULL || buf == NULL)
198 return;
199
200 fprintf(stderr, "%8s: %s\n", domain, buf);
201}
202
7ad083b0
EM
203void
204idebug(const char *format, ...)
205{
206#ifndef NDEBUG
207 char buf[BUFSIZE];
208 va_list args;
209
210 va_start(args, format);
211 vsnprintf(buf, sizeof(buf), format, args);
212 va_end(args);
213
214 _iprint("debug", buf);
215
216 ilog(L_MAIN, "%s", buf);
217#endif
218}
219
212380e3
AC
220void
221inotice(const char *format, ...)
222{
223 char buf[BUFSIZE];
224 va_list args;
225
226 va_start(args, format);
5203cba5 227 vsnprintf(buf, sizeof(buf), format, args);
212380e3
AC
228 va_end(args);
229
230 _iprint("notice", buf);
231
232 ilog(L_MAIN, "%s", buf);
233}
234
235void
236iwarn(const char *format, ...)
237{
238 char buf[BUFSIZE];
239 va_list args;
240
241 va_start(args, format);
5203cba5 242 vsnprintf(buf, sizeof(buf), format, args);
212380e3
AC
243 va_end(args);
244
245 _iprint("warning", buf);
246
247 ilog(L_MAIN, "%s", buf);
248}
249
250void
251ierror(const char *format, ...)
252{
253 char buf[BUFSIZE];
254 va_list args;
255
256 va_start(args, format);
5203cba5 257 vsnprintf(buf, sizeof(buf), format, args);
212380e3
AC
258 va_end(args);
259
260 _iprint("error", buf);
261
262 ilog(L_MAIN, "%s", buf);
263}
264
265void
266report_operspy(struct Client *source_p, const char *token, const char *arg)
267{
268 /* if its not my client its already propagated */
269 if(MyClient(source_p))
270 sendto_match_servs(source_p, "*", CAP_ENCAP, NOCAPS,
271 "ENCAP * OPERSPY %s %s",
272 token, arg ? arg : "");
273
274 sendto_realops_snomask(SNO_OPERSPY,
275 ConfigFileEntry.operspy_admin_only ? L_ADMIN : L_ALL,
276 "OPERSPY %s %s %s",
277 get_oper_name(source_p), token,
278 arg ? arg : "");
279
280 ilog(L_OPERSPY, "OPERSPY %s %s %s",
281 get_oper_name(source_p), token, arg ? arg : "");
282}
283
284const char *
b52c2949 285smalldate(time_t ltime)
212380e3
AC
286{
287 static char buf[MAX_DATE_STRING];
288 struct tm *lt;
212380e3
AC
289
290 lt = localtime(&ltime);
291
5203cba5 292 snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d",
212380e3
AC
293 lt->tm_year + 1900, lt->tm_mon + 1,
294 lt->tm_mday, lt->tm_hour, lt->tm_min);
295
296 return buf;
297}
298
212380e3 299void
ba1a1399 300ilog_error(const char *error)
212380e3 301{
db6b1735
JT
302 int e;
303 const char *errstr;
212380e3 304
db6b1735
JT
305 e = errno;
306 errstr = strerror(e);
307
308 ilog(L_IOERROR, "%s: %d (%s)", error, e, errstr);
309 sendto_realops_snomask(SNO_DEBUG, L_ALL, "%s: %d (%s)",
310 error, e, errstr);
212380e3 311}