]>
Commit | Line | Data |
---|---|---|
212380e3 | 1 | /* |
3a2ff95d | 2 | * charybdis: an advanced Internet Relay Chat Daemon(ircd). |
212380e3 | 3 | * |
4 | * Copyright (C) 2003 Lee H <lee@leeh.co.uk> | |
5 | * Copyright (C) 2003-2005 ircd-ratbox development team | |
3a2ff95d | 6 | * Copyright (C) 2008 William Pitcock <nenolod@sacredspiral.co.uk> |
212380e3 | 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. | |
3a2ff95d | 14 | * |
212380e3 | 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. | |
3a2ff95d | 18 | * |
212380e3 | 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. | |
33 | * | |
9b6ff0c8 | 34 | * $Id: s_log.c 3209 2007-02-11 16:54:43Z jilles $ |
212380e3 | 35 | */ |
36 | ||
37 | #include "stdinc.h" | |
38 | #include "ircd_defs.h" | |
d3455e2c | 39 | #include "logger.h" |
212380e3 | 40 | #include "s_conf.h" |
41 | #include "sprintf_irc.h" | |
42 | #include "send.h" | |
43 | #include "client.h" | |
44 | #include "s_serv.h" | |
45 | ||
46 | static FILE *log_main; | |
47 | static FILE *log_user; | |
48 | static FILE *log_fuser; | |
49 | static FILE *log_oper; | |
50 | static FILE *log_foper; | |
51 | static FILE *log_server; | |
52 | static FILE *log_kill; | |
53 | static FILE *log_gline; | |
54 | static FILE *log_kline; | |
55 | static FILE *log_operspy; | |
56 | static FILE *log_ioerror; | |
57 | ||
58 | struct log_struct | |
59 | { | |
60 | char **name; | |
61 | FILE **logfile; | |
62 | }; | |
63 | ||
64 | static struct log_struct log_table[LAST_LOGFILE] = | |
65 | { | |
66 | { NULL, &log_main }, | |
67 | { &ConfigFileEntry.fname_userlog, &log_user }, | |
68 | { &ConfigFileEntry.fname_fuserlog, &log_fuser }, | |
69 | { &ConfigFileEntry.fname_operlog, &log_oper }, | |
70 | { &ConfigFileEntry.fname_foperlog, &log_foper }, | |
71 | { &ConfigFileEntry.fname_serverlog, &log_server }, | |
72 | { &ConfigFileEntry.fname_killlog, &log_kill }, | |
73 | { &ConfigFileEntry.fname_klinelog, &log_kline }, | |
74 | { &ConfigFileEntry.fname_glinelog, &log_gline }, | |
75 | { &ConfigFileEntry.fname_operspylog, &log_operspy }, | |
76 | { &ConfigFileEntry.fname_ioerrorlog, &log_ioerror } | |
77 | }; | |
78 | ||
79 | void | |
80 | init_main_logfile(void) | |
81 | { | |
82 | if(log_main == NULL) | |
9b6ff0c8 | 83 | log_main = fopen(logFileName, "a"); |
212380e3 | 84 | } |
85 | ||
86 | void | |
87 | open_logfiles(void) | |
88 | { | |
89 | int i; | |
90 | ||
91 | if(log_main != NULL) | |
92 | fclose(log_main); | |
93 | ||
9b6ff0c8 | 94 | log_main = fopen(logFileName, "a"); |
212380e3 | 95 | |
96 | /* log_main is handled above, so just do the rest */ | |
97 | for(i = 1; i < LAST_LOGFILE; i++) | |
98 | { | |
99 | /* close open logfiles */ | |
100 | if(*log_table[i].logfile != NULL) | |
101 | { | |
102 | fclose(*log_table[i].logfile); | |
103 | *log_table[i].logfile = NULL; | |
104 | } | |
105 | ||
106 | /* reopen those with paths */ | |
107 | if(!EmptyString(*log_table[i].name)) | |
108 | *log_table[i].logfile = fopen(*log_table[i].name, "a"); | |
109 | } | |
110 | } | |
111 | ||
112 | void | |
113 | ilog(ilogfile dest, const char *format, ...) | |
114 | { | |
115 | FILE *logfile = *log_table[dest].logfile; | |
116 | char buf[BUFSIZE]; | |
117 | char buf2[BUFSIZE]; | |
118 | va_list args; | |
119 | ||
120 | if(logfile == NULL) | |
121 | return; | |
122 | ||
123 | va_start(args, format); | |
e49c49f9 | 124 | rb_vsnprintf(buf, sizeof(buf), format, args); |
212380e3 | 125 | va_end(args); |
126 | ||
38e6acdd | 127 | rb_snprintf(buf2, sizeof(buf2), "%s %s\n", smalldate(), buf); |
212380e3 | 128 | |
129 | if(fputs(buf2, logfile) < 0) | |
130 | { | |
131 | fclose(logfile); | |
132 | *log_table[dest].logfile = NULL; | |
133 | } | |
134 | ||
135 | fflush(logfile); | |
136 | } | |
137 | ||
138 | static void | |
3a2ff95d | 139 | _iprint(const char *domain, const char *buf) |
212380e3 | 140 | { |
141 | if (domain == NULL || buf == NULL) | |
142 | return; | |
143 | ||
144 | fprintf(stderr, "%8s: %s\n", domain, buf); | |
145 | } | |
146 | ||
147 | void | |
148 | inotice(const char *format, ...) | |
149 | { | |
150 | char buf[BUFSIZE]; | |
151 | va_list args; | |
152 | ||
153 | va_start(args, format); | |
a5497589 | 154 | rb_vsnprintf(buf, sizeof(buf), format, args); |
212380e3 | 155 | va_end(args); |
156 | ||
157 | _iprint("notice", buf); | |
158 | ||
159 | ilog(L_MAIN, "%s", buf); | |
160 | } | |
161 | ||
162 | void | |
163 | iwarn(const char *format, ...) | |
164 | { | |
165 | char buf[BUFSIZE]; | |
166 | va_list args; | |
167 | ||
168 | va_start(args, format); | |
a5497589 | 169 | rb_vsnprintf(buf, sizeof(buf), format, args); |
212380e3 | 170 | va_end(args); |
171 | ||
172 | _iprint("warning", buf); | |
173 | ||
174 | ilog(L_MAIN, "%s", buf); | |
175 | } | |
176 | ||
177 | void | |
178 | ierror(const char *format, ...) | |
179 | { | |
180 | char buf[BUFSIZE]; | |
181 | va_list args; | |
182 | ||
183 | va_start(args, format); | |
a5497589 | 184 | rb_vsnprintf(buf, sizeof(buf), format, args); |
212380e3 | 185 | va_end(args); |
186 | ||
187 | _iprint("error", buf); | |
188 | ||
189 | ilog(L_MAIN, "%s", buf); | |
190 | } | |
191 | ||
192 | void | |
193 | report_operspy(struct Client *source_p, const char *token, const char *arg) | |
194 | { | |
195 | /* if its not my client its already propagated */ | |
196 | if(MyClient(source_p)) | |
197 | sendto_match_servs(source_p, "*", CAP_ENCAP, NOCAPS, | |
198 | "ENCAP * OPERSPY %s %s", | |
199 | token, arg ? arg : ""); | |
200 | ||
201 | sendto_realops_snomask(SNO_OPERSPY, | |
202 | ConfigFileEntry.operspy_admin_only ? L_ADMIN : L_ALL, | |
203 | "OPERSPY %s %s %s", | |
204 | get_oper_name(source_p), token, | |
205 | arg ? arg : ""); | |
206 | ||
207 | ilog(L_OPERSPY, "OPERSPY %s %s %s", | |
208 | get_oper_name(source_p), token, arg ? arg : ""); | |
209 | } | |
210 | ||
211 | const char * | |
212 | smalldate(void) | |
213 | { | |
214 | static char buf[MAX_DATE_STRING]; | |
215 | struct tm *lt; | |
9f6bbe3c | 216 | time_t ltime = rb_current_time(); |
212380e3 | 217 | |
218 | lt = localtime(<ime); | |
219 | ||
38e6acdd | 220 | rb_snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d", |
212380e3 | 221 | lt->tm_year + 1900, lt->tm_mon + 1, |
222 | lt->tm_mday, lt->tm_hour, lt->tm_min); | |
223 | ||
224 | return buf; | |
225 | } | |
226 | ||
212380e3 | 227 | void |
3a2ff95d | 228 | ilog_error(const char *error) |
212380e3 | 229 | { |
d7b7d8bb | 230 | ilog(L_IOERROR, "%s: %d (%s)", error, errno, strerror(errno)); |
212380e3 | 231 | |
d7b7d8bb | 232 | sendto_realops_snomask(SNO_DEBUG, L_ALL, "%s: %d (%s)", error, errno, strerror(errno)); |
212380e3 | 233 | } |