]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * s_conf.c: Configuration file functions. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
23 | * | |
cda8e9b8 | 24 | * $Id: s_conf.c 3550 2007-08-09 06:47:26Z nenolod $ |
212380e3 AC |
25 | */ |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "ircd_defs.h" | |
212380e3 AC |
29 | #include "s_conf.h" |
30 | #include "s_newconf.h" | |
31 | #include "s_serv.h" | |
32 | #include "s_stats.h" | |
33 | #include "channel.h" | |
34 | #include "class.h" | |
35 | #include "client.h" | |
36 | #include "common.h" | |
212380e3 | 37 | #include "hash.h" |
4562c604 | 38 | #include "match.h" |
212380e3 AC |
39 | #include "ircd.h" |
40 | #include "listener.h" | |
41 | #include "hostmask.h" | |
42 | #include "modules.h" | |
43 | #include "numeric.h" | |
4016731b | 44 | #include "logger.h" |
212380e3 | 45 | #include "send.h" |
212380e3 AC |
46 | #include "reject.h" |
47 | #include "cache.h" | |
48 | #include "blacklist.h" | |
422bb0b5 | 49 | #include "privilege.h" |
c6d72037 | 50 | #include "sslproc.h" |
212380e3 AC |
51 | |
52 | struct config_server_hide ConfigServerHide; | |
53 | ||
6ab8c0d3 | 54 | extern int yyparse(void); /* defined in y.tab.c */ |
212380e3 AC |
55 | extern char linebuf[]; |
56 | ||
57 | #ifndef INADDR_NONE | |
58 | #define INADDR_NONE ((unsigned int) 0xffffffff) | |
59 | #endif | |
60 | ||
398b6a73 | 61 | static rb_bh *confitem_heap = NULL; |
212380e3 | 62 | |
330fc5c1 AC |
63 | rb_dlink_list temp_klines[LAST_TEMP_TYPE]; |
64 | rb_dlink_list temp_dlines[LAST_TEMP_TYPE]; | |
65 | rb_dlink_list service_list; | |
212380e3 AC |
66 | |
67 | /* internally defined functions */ | |
68 | static void set_default_conf(void); | |
69 | static void validate_conf(void); | |
70 | static void read_conf(FILE *); | |
71 | static void clear_out_old_conf(void); | |
72 | ||
73 | static void expire_temp_kd(void *list); | |
74 | static void reorganise_temp_kd(void *list); | |
75 | ||
76 | FILE *conf_fbfile_in; | |
77 | extern char yytext[]; | |
78 | ||
79 | static int verify_access(struct Client *client_p, const char *username); | |
80 | static int attach_iline(struct Client *, struct ConfItem *); | |
81 | ||
82 | void | |
83 | init_s_conf(void) | |
84 | { | |
b2c190a6 | 85 | confitem_heap = rb_bh_create(sizeof(struct ConfItem), CONFITEM_HEAP_SIZE, "confitem_heap"); |
212380e3 | 86 | |
12aea5fe VY |
87 | rb_event_addish("expire_temp_klines", expire_temp_kd, &temp_klines[TEMP_MIN], 60); |
88 | rb_event_addish("expire_temp_dlines", expire_temp_kd, &temp_dlines[TEMP_MIN], 60); | |
212380e3 | 89 | |
12aea5fe | 90 | rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd, |
212380e3 | 91 | &temp_klines[TEMP_HOUR], 3600); |
12aea5fe | 92 | rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd, |
212380e3 | 93 | &temp_dlines[TEMP_HOUR], 3600); |
12aea5fe | 94 | rb_event_addish("expire_temp_klines_day", reorganise_temp_kd, |
212380e3 | 95 | &temp_klines[TEMP_DAY], 86400); |
12aea5fe | 96 | rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd, |
212380e3 | 97 | &temp_dlines[TEMP_DAY], 86400); |
12aea5fe | 98 | rb_event_addish("expire_temp_klines_week", reorganise_temp_kd, |
212380e3 | 99 | &temp_klines[TEMP_WEEK], 604800); |
12aea5fe | 100 | rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd, |
212380e3 AC |
101 | &temp_dlines[TEMP_WEEK], 604800); |
102 | } | |
103 | ||
104 | /* | |
105 | * make_conf | |
106 | * | |
107 | * inputs - none | |
108 | * output - pointer to new conf entry | |
109 | * side effects - none | |
110 | */ | |
111 | struct ConfItem * | |
112 | make_conf() | |
113 | { | |
114 | struct ConfItem *aconf; | |
115 | ||
398b6a73 | 116 | aconf = rb_bh_alloc(confitem_heap); |
212380e3 AC |
117 | aconf->status = CONF_ILLEGAL; |
118 | return (aconf); | |
119 | } | |
120 | ||
121 | /* | |
122 | * free_conf | |
123 | * | |
124 | * inputs - pointer to conf to free | |
125 | * output - none | |
126 | * side effects - crucial password fields are zeroed, conf is freed | |
127 | */ | |
128 | void | |
129 | free_conf(struct ConfItem *aconf) | |
130 | { | |
131 | s_assert(aconf != NULL); | |
132 | if(aconf == NULL) | |
133 | return; | |
134 | ||
135 | /* security.. */ | |
136 | if(aconf->passwd) | |
137 | memset(aconf->passwd, 0, strlen(aconf->passwd)); | |
138 | if(aconf->spasswd) | |
139 | memset(aconf->spasswd, 0, strlen(aconf->spasswd)); | |
140 | ||
637c4932 VY |
141 | rb_free(aconf->passwd); |
142 | rb_free(aconf->spasswd); | |
143 | rb_free(aconf->name); | |
144 | rb_free(aconf->className); | |
145 | rb_free(aconf->user); | |
146 | rb_free(aconf->host); | |
212380e3 | 147 | |
398b6a73 | 148 | rb_bh_free(confitem_heap, aconf); |
212380e3 AC |
149 | } |
150 | ||
151 | /* | |
152 | * check_client | |
153 | * | |
154 | * inputs - pointer to client | |
155 | * output - 0 = Success | |
156 | * NOT_AUTHORISED (-1) = Access denied (no I line match) | |
157 | * SOCKET_ERROR (-2) = Bad socket. | |
158 | * I_LINE_FULL (-3) = I-line is full | |
159 | * TOO_MANY (-4) = Too many connections from hostname | |
160 | * BANNED_CLIENT (-5) = K-lined | |
161 | * side effects - Ordinary client access check. | |
162 | * Look for conf lines which have the same | |
163 | * status as the flags passed. | |
164 | */ | |
165 | int | |
166 | check_client(struct Client *client_p, struct Client *source_p, const char *username) | |
167 | { | |
168 | int i; | |
169 | ||
212380e3 AC |
170 | if((i = verify_access(source_p, username))) |
171 | { | |
172 | ilog(L_FUSER, "Access denied: %s[%s]", | |
173 | source_p->name, source_p->sockhost); | |
174 | } | |
175 | ||
176 | switch (i) | |
177 | { | |
178 | case SOCKET_ERROR: | |
179 | exit_client(client_p, source_p, &me, "Socket Error"); | |
180 | break; | |
181 | ||
182 | case TOO_MANY_LOCAL: | |
606384ae JT |
183 | /* Note that these notices are sent to opers on other |
184 | * servers also, so even if local opers are allowed to | |
185 | * see the IP, we still cannot send it. | |
186 | */ | |
212380e3 AC |
187 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, |
188 | "Too many local connections for %s!%s%s@%s", | |
189 | source_p->name, IsGotId(source_p) ? "" : "~", | |
606384ae JT |
190 | source_p->username, |
191 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); | |
212380e3 AC |
192 | |
193 | ilog(L_FUSER, "Too many local connections from %s!%s%s@%s", | |
194 | source_p->name, IsGotId(source_p) ? "" : "~", | |
195 | source_p->username, source_p->sockhost); | |
196 | ||
47adde3d | 197 | ServerStats.is_ref++; |
212380e3 AC |
198 | exit_client(client_p, source_p, &me, "Too many host connections (local)"); |
199 | break; | |
200 | ||
201 | case TOO_MANY_GLOBAL: | |
202 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, | |
203 | "Too many global connections for %s!%s%s@%s", | |
204 | source_p->name, IsGotId(source_p) ? "" : "~", | |
606384ae JT |
205 | source_p->username, |
206 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); | |
212380e3 AC |
207 | ilog(L_FUSER, "Too many global connections from %s!%s%s@%s", |
208 | source_p->name, IsGotId(source_p) ? "" : "~", | |
209 | source_p->username, source_p->sockhost); | |
210 | ||
47adde3d | 211 | ServerStats.is_ref++; |
212380e3 AC |
212 | exit_client(client_p, source_p, &me, "Too many host connections (global)"); |
213 | break; | |
214 | ||
215 | case TOO_MANY_IDENT: | |
216 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, | |
217 | "Too many user connections for %s!%s%s@%s", | |
218 | source_p->name, IsGotId(source_p) ? "" : "~", | |
606384ae JT |
219 | source_p->username, |
220 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); | |
212380e3 AC |
221 | ilog(L_FUSER, "Too many user connections from %s!%s%s@%s", |
222 | source_p->name, IsGotId(source_p) ? "" : "~", | |
223 | source_p->username, source_p->sockhost); | |
224 | ||
47adde3d | 225 | ServerStats.is_ref++; |
212380e3 AC |
226 | exit_client(client_p, source_p, &me, "Too many user connections (global)"); |
227 | break; | |
228 | ||
229 | case I_LINE_FULL: | |
230 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, | |
231 | "I-line is full for %s!%s%s@%s (%s).", | |
232 | source_p->name, IsGotId(source_p) ? "" : "~", | |
233 | source_p->username, source_p->host, | |
4b7e6904 | 234 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : "255.255.255.255"); |
212380e3 AC |
235 | |
236 | ilog(L_FUSER, "Too many connections from %s!%s%s@%s.", | |
237 | source_p->name, IsGotId(source_p) ? "" : "~", | |
238 | source_p->username, source_p->sockhost); | |
239 | ||
47adde3d | 240 | ServerStats.is_ref++; |
212380e3 AC |
241 | exit_client(client_p, source_p, &me, |
242 | "No more connections allowed in your connection class"); | |
243 | break; | |
244 | ||
245 | case NOT_AUTHORISED: | |
246 | { | |
247 | int port = -1; | |
ccda6e3f | 248 | #ifdef RB_IPV6 |
212380e3 AC |
249 | if(source_p->localClient->ip.ss_family == AF_INET6) |
250 | port = ntohs(((struct sockaddr_in6 *)&source_p->localClient->listener->addr)->sin6_port); | |
251 | else | |
252 | #endif | |
253 | port = ntohs(((struct sockaddr_in *)&source_p->localClient->listener->addr)->sin_port); | |
254 | ||
47adde3d | 255 | ServerStats.is_ref++; |
212380e3 AC |
256 | /* jdc - lists server name & port connections are on */ |
257 | /* a purely cosmetical change */ | |
258 | /* why ipaddr, and not just source_p->sockhost? --fl */ | |
259 | #if 0 | |
260 | static char ipaddr[HOSTIPLEN]; | |
caa4d9d2 | 261 | rb_inet_ntop_sock(&source_p->localClient->ip, ipaddr, sizeof(ipaddr)); |
212380e3 AC |
262 | #endif |
263 | sendto_realops_snomask(SNO_UNAUTH, L_ALL, | |
264 | "Unauthorised client connection from " | |
265 | "%s!%s%s@%s [%s] on [%s/%u].", | |
266 | source_p->name, IsGotId(source_p) ? "" : "~", | |
267 | source_p->username, source_p->host, | |
268 | source_p->sockhost, | |
269 | source_p->localClient->listener->name, port); | |
270 | ||
271 | ilog(L_FUSER, | |
272 | "Unauthorised client connection from %s!%s%s@%s on [%s/%u].", | |
273 | source_p->name, IsGotId(source_p) ? "" : "~", | |
274 | source_p->username, source_p->sockhost, | |
275 | source_p->localClient->listener->name, port); | |
35f6f850 | 276 | add_reject(client_p, NULL, NULL); |
212380e3 AC |
277 | exit_client(client_p, source_p, &me, |
278 | "You are not authorised to use this server"); | |
279 | break; | |
280 | } | |
281 | case BANNED_CLIENT: | |
212380e3 | 282 | exit_client(client_p, client_p, &me, "*** Banned "); |
47adde3d | 283 | ServerStats.is_ref++; |
212380e3 AC |
284 | break; |
285 | ||
286 | case 0: | |
287 | default: | |
288 | break; | |
289 | } | |
290 | return (i); | |
291 | } | |
292 | ||
293 | /* | |
294 | * verify_access | |
295 | * | |
296 | * inputs - pointer to client to verify | |
297 | * - pointer to proposed username | |
298 | * output - 0 if success -'ve if not | |
299 | * side effect - find the first (best) I line to attach. | |
300 | */ | |
301 | static int | |
302 | verify_access(struct Client *client_p, const char *username) | |
303 | { | |
304 | struct ConfItem *aconf; | |
305 | char non_ident[USERLEN + 1]; | |
306 | ||
307 | if(IsGotId(client_p)) | |
308 | { | |
309 | aconf = find_address_conf(client_p->host, client_p->sockhost, | |
310 | client_p->username, client_p->username, | |
311 | (struct sockaddr *) &client_p->localClient->ip, | |
40c1fd47 VY |
312 | client_p->localClient->ip.ss_family, |
313 | client_p->localClient->auth_user); | |
212380e3 AC |
314 | } |
315 | else | |
316 | { | |
f427c8b0 | 317 | rb_strlcpy(non_ident, "~", sizeof(non_ident)); |
1f9de103 | 318 | rb_strlcat(non_ident, username, sizeof(non_ident)); |
212380e3 AC |
319 | aconf = find_address_conf(client_p->host, client_p->sockhost, |
320 | non_ident, client_p->username, | |
321 | (struct sockaddr *) &client_p->localClient->ip, | |
40c1fd47 VY |
322 | client_p->localClient->ip.ss_family, |
323 | client_p->localClient->auth_user); | |
212380e3 AC |
324 | } |
325 | ||
326 | if(aconf == NULL) | |
327 | return NOT_AUTHORISED; | |
328 | ||
329 | if(aconf->status & CONF_CLIENT) | |
330 | { | |
331 | if(aconf->flags & CONF_FLAGS_REDIR) | |
332 | { | |
88520303 | 333 | sendto_one_numeric(client_p, RPL_REDIR, form_str(RPL_REDIR), |
212380e3 AC |
334 | aconf->name ? aconf->name : "", aconf->port); |
335 | return (NOT_AUTHORISED); | |
336 | } | |
337 | ||
212380e3 AC |
338 | /* Thanks for spoof idea amm */ |
339 | if(IsConfDoSpoofIp(aconf)) | |
340 | { | |
341 | char *p; | |
342 | ||
343 | /* show_ip() depends on this --fl */ | |
344 | SetIPSpoof(client_p); | |
345 | ||
346 | if(IsConfSpoofNotice(aconf)) | |
347 | { | |
348 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
349 | "%s spoofing: %s as %s", | |
350 | client_p->name, | |
351 | show_ip(NULL, client_p) ? client_p->host : aconf->name, | |
352 | aconf->name); | |
353 | } | |
354 | ||
355 | /* user@host spoof */ | |
356 | if((p = strchr(aconf->name, '@')) != NULL) | |
357 | { | |
358 | char *host = p+1; | |
359 | *p = '\0'; | |
360 | ||
f427c8b0 | 361 | rb_strlcpy(client_p->username, aconf->name, |
212380e3 | 362 | sizeof(client_p->username)); |
f427c8b0 | 363 | rb_strlcpy(client_p->host, host, |
212380e3 AC |
364 | sizeof(client_p->host)); |
365 | *p = '@'; | |
366 | } | |
367 | else | |
f427c8b0 | 368 | rb_strlcpy(client_p->host, aconf->name, sizeof(client_p->host)); |
212380e3 AC |
369 | } |
370 | return (attach_iline(client_p, aconf)); | |
371 | } | |
372 | else if(aconf->status & CONF_KILL) | |
373 | { | |
374 | if(ConfigFileEntry.kline_with_reason) | |
375 | { | |
376 | sendto_one(client_p, | |
92fb5c31 | 377 | form_str(ERR_YOUREBANNEDCREEP), |
212380e3 AC |
378 | me.name, client_p->name, aconf->passwd); |
379 | } | |
35f6f850 | 380 | add_reject(client_p, aconf->user, aconf->host); |
212380e3 AC |
381 | return (BANNED_CLIENT); |
382 | } | |
212380e3 AC |
383 | |
384 | return NOT_AUTHORISED; | |
385 | } | |
386 | ||
387 | ||
388 | /* | |
389 | * add_ip_limit | |
390 | * | |
391 | * Returns 1 if successful 0 if not | |
392 | * | |
393 | * This checks if the user has exceed the limits for their class | |
394 | * unless of course they are exempt.. | |
395 | */ | |
396 | ||
397 | static int | |
398 | add_ip_limit(struct Client *client_p, struct ConfItem *aconf) | |
399 | { | |
b2c190a6 | 400 | rb_patricia_node_t *pnode; |
e33e589c | 401 | int bitlen; |
212380e3 AC |
402 | |
403 | /* If the limits are 0 don't do anything.. */ | |
e33e589c JT |
404 | if(ConfCidrAmount(aconf) == 0 |
405 | || (ConfCidrIpv4Bitlen(aconf) == 0 && ConfCidrIpv6Bitlen(aconf) == 0)) | |
212380e3 AC |
406 | return -1; |
407 | ||
b2c190a6 | 408 | pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip); |
212380e3 | 409 | |
e33e589c JT |
410 | if(GET_SS_FAMILY(&client_p->localClient->ip) == AF_INET) |
411 | bitlen = ConfCidrIpv4Bitlen(aconf); | |
412 | else | |
413 | bitlen = ConfCidrIpv6Bitlen(aconf); | |
414 | ||
212380e3 | 415 | if(pnode == NULL) |
e33e589c | 416 | pnode = make_and_lookup_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip, bitlen); |
212380e3 AC |
417 | |
418 | s_assert(pnode != NULL); | |
419 | ||
420 | if(pnode != NULL) | |
421 | { | |
e33e589c | 422 | if(((intptr_t)pnode->data) >= ConfCidrAmount(aconf) && !IsConfExemptLimits(aconf)) |
212380e3 AC |
423 | { |
424 | /* This should only happen if the limits are set to 0 */ | |
e33e589c | 425 | if((intptr_t)pnode->data == 0) |
212380e3 | 426 | { |
b2c190a6 | 427 | rb_patricia_remove(ConfIpLimits(aconf), pnode); |
212380e3 AC |
428 | } |
429 | return (0); | |
430 | } | |
431 | ||
e33e589c | 432 | pnode->data = (void *)(((intptr_t)pnode->data) + 1); |
212380e3 AC |
433 | } |
434 | return 1; | |
435 | } | |
436 | ||
437 | static void | |
438 | remove_ip_limit(struct Client *client_p, struct ConfItem *aconf) | |
439 | { | |
b2c190a6 | 440 | rb_patricia_node_t *pnode; |
212380e3 AC |
441 | |
442 | /* If the limits are 0 don't do anything.. */ | |
e33e589c JT |
443 | if(ConfCidrAmount(aconf) == 0 |
444 | || (ConfCidrIpv4Bitlen(aconf) == 0 && ConfCidrIpv6Bitlen(aconf) == 0)) | |
212380e3 AC |
445 | return; |
446 | ||
b2c190a6 | 447 | pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip); |
212380e3 AC |
448 | if(pnode == NULL) |
449 | return; | |
450 | ||
e33e589c JT |
451 | pnode->data = (void *)(((intptr_t)pnode->data) - 1); |
452 | if(((intptr_t)pnode->data) == 0) | |
212380e3 | 453 | { |
b2c190a6 | 454 | rb_patricia_remove(ConfIpLimits(aconf), pnode); |
212380e3 AC |
455 | } |
456 | ||
457 | } | |
458 | ||
459 | /* | |
460 | * attach_iline | |
461 | * | |
462 | * inputs - client pointer | |
463 | * - conf pointer | |
464 | * output - | |
465 | * side effects - do actual attach | |
466 | */ | |
467 | static int | |
468 | attach_iline(struct Client *client_p, struct ConfItem *aconf) | |
469 | { | |
470 | struct Client *target_p; | |
330fc5c1 | 471 | rb_dlink_node *ptr; |
212380e3 AC |
472 | int local_count = 0; |
473 | int global_count = 0; | |
474 | int ident_count = 0; | |
475 | int unidented = 0; | |
476 | ||
477 | if(IsConfExemptLimits(aconf)) | |
478 | return (attach_conf(client_p, aconf)); | |
479 | ||
480 | if(*client_p->username == '~') | |
481 | unidented = 1; | |
482 | ||
483 | ||
484 | /* find_hostname() returns the head of the list to search */ | |
5cefa1d6 | 485 | RB_DLINK_FOREACH(ptr, find_hostname(client_p->host)) |
212380e3 AC |
486 | { |
487 | target_p = ptr->data; | |
488 | ||
489 | if(irccmp(client_p->host, target_p->orighost) != 0) | |
490 | continue; | |
491 | ||
492 | if(MyConnect(target_p)) | |
493 | local_count++; | |
494 | ||
495 | global_count++; | |
496 | ||
497 | if(unidented) | |
498 | { | |
499 | if(*target_p->username == '~') | |
500 | ident_count++; | |
501 | } | |
502 | else if(irccmp(target_p->username, client_p->username) == 0) | |
503 | ident_count++; | |
504 | ||
505 | if(ConfMaxLocal(aconf) && local_count >= ConfMaxLocal(aconf)) | |
506 | return (TOO_MANY_LOCAL); | |
507 | else if(ConfMaxGlobal(aconf) && global_count >= ConfMaxGlobal(aconf)) | |
508 | return (TOO_MANY_GLOBAL); | |
509 | else if(ConfMaxIdent(aconf) && ident_count >= ConfMaxIdent(aconf)) | |
510 | return (TOO_MANY_IDENT); | |
511 | } | |
512 | ||
513 | ||
514 | return (attach_conf(client_p, aconf)); | |
515 | } | |
516 | ||
517 | /* | |
518 | * detach_conf | |
519 | * | |
520 | * inputs - pointer to client to detach | |
521 | * output - 0 for success, -1 for failure | |
522 | * side effects - Disassociate configuration from the client. | |
523 | * Also removes a class from the list if marked for deleting. | |
524 | */ | |
525 | int | |
526 | detach_conf(struct Client *client_p) | |
527 | { | |
528 | struct ConfItem *aconf; | |
529 | ||
530 | aconf = client_p->localClient->att_conf; | |
531 | ||
532 | if(aconf != NULL) | |
533 | { | |
534 | if(ClassPtr(aconf)) | |
535 | { | |
536 | remove_ip_limit(client_p, aconf); | |
537 | ||
538 | if(ConfCurrUsers(aconf) > 0) | |
539 | --ConfCurrUsers(aconf); | |
540 | ||
541 | if(ConfMaxUsers(aconf) == -1 && ConfCurrUsers(aconf) == 0) | |
542 | { | |
543 | free_class(ClassPtr(aconf)); | |
544 | ClassPtr(aconf) = NULL; | |
545 | } | |
546 | ||
547 | } | |
548 | ||
549 | aconf->clients--; | |
550 | if(!aconf->clients && IsIllegal(aconf)) | |
551 | free_conf(aconf); | |
552 | ||
553 | client_p->localClient->att_conf = NULL; | |
554 | return 0; | |
555 | } | |
556 | ||
557 | return -1; | |
558 | } | |
559 | ||
560 | /* | |
561 | * attach_conf | |
562 | * | |
563 | * inputs - client pointer | |
564 | * - conf pointer | |
565 | * output - | |
566 | * side effects - Associate a specific configuration entry to a *local* | |
567 | * client (this is the one which used in accepting the | |
568 | * connection). Note, that this automatically changes the | |
569 | * attachment if there was an old one... | |
570 | */ | |
571 | int | |
572 | attach_conf(struct Client *client_p, struct ConfItem *aconf) | |
573 | { | |
574 | if(IsIllegal(aconf)) | |
575 | return (NOT_AUTHORISED); | |
576 | ||
577 | if(ClassPtr(aconf)) | |
578 | { | |
579 | if(!add_ip_limit(client_p, aconf)) | |
580 | return (TOO_MANY_LOCAL); | |
581 | } | |
582 | ||
583 | if((aconf->status & CONF_CLIENT) && | |
584 | ConfCurrUsers(aconf) >= ConfMaxUsers(aconf) && ConfMaxUsers(aconf) > 0) | |
585 | { | |
586 | if(!IsConfExemptLimits(aconf)) | |
587 | { | |
588 | return (I_LINE_FULL); | |
589 | } | |
590 | else | |
591 | { | |
5366977b | 592 | sendto_one_notice(client_p, ":*** I: line is full, but you have an >I: line!"); |
212380e3 AC |
593 | } |
594 | ||
595 | } | |
596 | ||
597 | if(client_p->localClient->att_conf != NULL) | |
598 | detach_conf(client_p); | |
599 | ||
600 | client_p->localClient->att_conf = aconf; | |
601 | ||
602 | aconf->clients++; | |
603 | ConfCurrUsers(aconf)++; | |
604 | return (0); | |
605 | } | |
606 | ||
607 | /* | |
608 | * rehash | |
609 | * | |
610 | * Actual REHASH service routine. Called with sig == 0 if it has been called | |
611 | * as a result of an operator issuing this command, else assume it has been | |
612 | * called as a result of the server receiving a HUP signal. | |
613 | */ | |
614 | int | |
615 | rehash(int sig) | |
616 | { | |
617 | if(sig != 0) | |
618 | { | |
619 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
620 | "Got signal SIGHUP, reloading ircd conf. file"); | |
621 | } | |
622 | ||
623 | restart_resolver(); | |
624 | /* don't close listeners until we know we can go ahead with the rehash */ | |
625 | read_conf_files(NO); | |
626 | ||
627 | if(ServerInfo.description != NULL) | |
f427c8b0 | 628 | rb_strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
212380e3 | 629 | else |
f427c8b0 | 630 | rb_strlcpy(me.info, "unknown", sizeof(me.info)); |
212380e3 AC |
631 | |
632 | open_logfiles(); | |
633 | return (0); | |
634 | } | |
635 | ||
636 | static struct banconf_entry | |
637 | { | |
638 | const char **filename; | |
639 | void (*func) (FILE *); | |
640 | int perm; | |
641 | } banconfs[] = { | |
642 | { &ConfigFileEntry.klinefile, parse_k_file, 0 }, | |
643 | { &ConfigFileEntry.klinefile, parse_k_file, 1 }, | |
644 | { &ConfigFileEntry.dlinefile, parse_d_file, 0 }, | |
645 | { &ConfigFileEntry.dlinefile, parse_d_file, 1 }, | |
646 | { &ConfigFileEntry.xlinefile, parse_x_file, 0 }, | |
647 | { &ConfigFileEntry.xlinefile, parse_x_file, 1 }, | |
648 | { &ConfigFileEntry.resvfile, parse_resv_file,0 }, | |
649 | { &ConfigFileEntry.resvfile, parse_resv_file,1 }, | |
650 | { NULL, NULL, 0 } | |
651 | }; | |
652 | ||
653 | void | |
654 | rehash_bans(int sig) | |
655 | { | |
656 | FILE *file; | |
657 | char buf[MAXPATHLEN]; | |
658 | int i; | |
659 | ||
660 | if(sig != 0) | |
661 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
662 | "Got signal SIGUSR2, reloading ban confs"); | |
663 | ||
664 | clear_out_address_conf_bans(); | |
665 | clear_s_newconf_bans(); | |
666 | ||
667 | for(i = 0; banconfs[i].filename; i++) | |
668 | { | |
669 | if(banconfs[i].perm) | |
670 | snprintf(buf, sizeof(buf), "%s.perm", *banconfs[i].filename); | |
671 | else | |
672 | snprintf(buf, sizeof(buf), "%s", *banconfs[i].filename); | |
673 | ||
674 | if((file = fopen(buf, "r")) == NULL) | |
675 | { | |
676 | if(banconfs[i].perm) | |
677 | continue; | |
678 | ||
679 | ilog(L_MAIN, "Failed reading ban file %s", | |
680 | *banconfs[i].filename); | |
681 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
682 | "Can't open %s file bans could be missing!", | |
683 | *banconfs[i].filename); | |
684 | } | |
685 | else | |
686 | { | |
687 | (banconfs[i].func)(file); | |
688 | fclose(file); | |
689 | } | |
690 | } | |
691 | ||
692 | check_banned_lines(); | |
693 | } | |
694 | ||
695 | /* | |
696 | * set_default_conf() | |
697 | * | |
698 | * inputs - NONE | |
699 | * output - NONE | |
700 | * side effects - Set default values here. | |
701 | * This is called **PRIOR** to parsing the | |
702 | * configuration file. If you want to do some validation | |
703 | * of values later, put them in validate_conf(). | |
704 | */ | |
705 | ||
706 | #define YES 1 | |
707 | #define NO 0 | |
708 | #define UNSET -1 | |
709 | ||
710 | static void | |
711 | set_default_conf(void) | |
712 | { | |
713 | /* ServerInfo.name is not rehashable */ | |
714 | /* ServerInfo.name = ServerInfo.name; */ | |
715 | ServerInfo.description = NULL; | |
47a03750 VY |
716 | ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); |
717 | ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); | |
212380e3 AC |
718 | |
719 | memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip)); | |
720 | ServerInfo.specific_ipv4_vhost = 0; | |
ccda6e3f | 721 | #ifdef RB_IPV6 |
212380e3 AC |
722 | memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6)); |
723 | ServerInfo.specific_ipv6_vhost = 0; | |
724 | #endif | |
212380e3 AC |
725 | |
726 | /* Don't reset hub, as that will break lazylinks */ | |
727 | /* ServerInfo.hub = NO; */ | |
728 | AdminInfo.name = NULL; | |
729 | AdminInfo.email = NULL; | |
730 | AdminInfo.description = NULL; | |
731 | ||
47a03750 VY |
732 | ConfigFileEntry.default_operstring = rb_strdup("is an IRC operator"); |
733 | ConfigFileEntry.default_adminstring = rb_strdup("is a Server Administrator"); | |
734 | ConfigFileEntry.servicestring = rb_strdup("is a Network Service"); | |
212380e3 AC |
735 | |
736 | ConfigFileEntry.default_umodes = UMODE_INVISIBLE; | |
737 | ConfigFileEntry.failed_oper_notice = YES; | |
738 | ConfigFileEntry.anti_nick_flood = NO; | |
739 | ConfigFileEntry.disable_fake_channels = NO; | |
740 | ConfigFileEntry.max_nick_time = 20; | |
741 | ConfigFileEntry.max_nick_changes = 5; | |
742 | ConfigFileEntry.max_accept = 20; | |
743 | ConfigFileEntry.max_monitor = 60; | |
744 | ConfigFileEntry.nick_delay = 900; /* 15 minutes */ | |
745 | ConfigFileEntry.target_change = YES; | |
746 | ConfigFileEntry.anti_spam_exit_message_time = 0; | |
747 | ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; | |
748 | ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; | |
749 | ConfigFileEntry.client_exit = YES; | |
750 | ConfigFileEntry.dline_with_reason = YES; | |
751 | ConfigFileEntry.kline_with_reason = YES; | |
752 | ConfigFileEntry.kline_delay = 0; | |
753 | ConfigFileEntry.warn_no_nline = YES; | |
754 | ConfigFileEntry.non_redundant_klines = YES; | |
755 | ConfigFileEntry.stats_e_disabled = NO; | |
756 | ConfigFileEntry.stats_o_oper_only = NO; | |
757 | ConfigFileEntry.stats_k_oper_only = 1; /* masked */ | |
758 | ConfigFileEntry.stats_i_oper_only = 1; /* masked */ | |
759 | ConfigFileEntry.stats_P_oper_only = NO; | |
760 | ConfigFileEntry.stats_c_oper_only = NO; | |
761 | ConfigFileEntry.stats_y_oper_only = NO; | |
762 | ConfigFileEntry.stats_h_oper_only = NO; | |
763 | ConfigFileEntry.map_oper_only = YES; | |
764 | ConfigFileEntry.operspy_admin_only = NO; | |
765 | ConfigFileEntry.pace_wait = 10; | |
766 | ConfigFileEntry.caller_id_wait = 60; | |
767 | ConfigFileEntry.pace_wait_simple = 1; | |
768 | ConfigFileEntry.short_motd = NO; | |
769 | ConfigFileEntry.no_oper_flood = NO; | |
770 | ConfigFileEntry.fname_userlog = NULL; | |
771 | ConfigFileEntry.fname_fuserlog = NULL; | |
772 | ConfigFileEntry.fname_operlog = NULL; | |
773 | ConfigFileEntry.fname_foperlog = NULL; | |
774 | ConfigFileEntry.fname_serverlog = NULL; | |
212380e3 AC |
775 | ConfigFileEntry.fname_klinelog = NULL; |
776 | ConfigFileEntry.fname_operspylog = NULL; | |
777 | ConfigFileEntry.fname_ioerrorlog = NULL; | |
212380e3 | 778 | ConfigFileEntry.use_egd = NO; |
212380e3 AC |
779 | ConfigFileEntry.hide_spoof_ips = YES; |
780 | ConfigFileEntry.hide_error_messages = 1; | |
212380e3 AC |
781 | ConfigFileEntry.dots_in_ident = 0; |
782 | ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT; | |
212380e3 AC |
783 | ConfigFileEntry.egdpool_path = NULL; |
784 | ConfigFileEntry.use_whois_actually = YES; | |
785 | ConfigFileEntry.burst_away = NO; | |
786 | ConfigFileEntry.collision_fnc = YES; | |
787 | ConfigFileEntry.global_snotices = YES; | |
788 | ConfigFileEntry.operspy_dont_care_user_info = NO; | |
789 | ||
790 | #ifdef HAVE_LIBZ | |
791 | ConfigFileEntry.compression_level = 4; | |
792 | #endif | |
793 | ||
794 | ConfigFileEntry.oper_umodes = UMODE_LOCOPS | UMODE_SERVNOTICE | | |
795 | UMODE_OPERWALL | UMODE_WALLOP; | |
796 | ConfigFileEntry.oper_only_umodes = UMODE_SERVNOTICE; | |
797 | ConfigFileEntry.oper_snomask = SNO_GENERAL; | |
798 | ||
799 | ConfigChannel.use_except = YES; | |
800 | ConfigChannel.use_invex = YES; | |
801 | ConfigChannel.use_knock = YES; | |
802 | ConfigChannel.use_forward = YES; | |
803 | ConfigChannel.knock_delay = 300; | |
804 | ConfigChannel.knock_delay_channel = 60; | |
805 | ConfigChannel.max_chans_per_user = 15; | |
806 | ConfigChannel.max_bans = 25; | |
807 | ConfigChannel.max_bans_large = 500; | |
808 | ConfigChannel.burst_topicwho = NO; | |
212380e3 AC |
809 | ConfigChannel.kick_on_split_riding = NO; |
810 | ||
811 | ConfigChannel.default_split_user_count = 15000; | |
812 | ConfigChannel.default_split_server_count = 10; | |
813 | ConfigChannel.no_join_on_split = NO; | |
814 | ConfigChannel.no_create_on_split = YES; | |
815 | ||
816 | ConfigServerHide.flatten_links = 0; | |
817 | ConfigServerHide.links_delay = 300; | |
818 | ConfigServerHide.hidden = 0; | |
819 | ConfigServerHide.disable_hidden = 0; | |
820 | ||
821 | ConfigFileEntry.min_nonwildcard = 4; | |
822 | ConfigFileEntry.min_nonwildcard_simple = 3; | |
823 | ConfigFileEntry.default_floodcount = 8; | |
824 | ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT; | |
825 | ConfigFileEntry.tkline_expire_notices = 0; | |
826 | ||
827 | ConfigFileEntry.reject_after_count = 5; | |
828 | ConfigFileEntry.reject_ban_time = 300; | |
829 | ConfigFileEntry.reject_duration = 120; | |
43946961 JT |
830 | ConfigFileEntry.throttle_count = 4; |
831 | ConfigFileEntry.throttle_duration = 60; | |
c2d96fcb | 832 | |
101db4c4 | 833 | ServerInfo.default_max_clients = MAXCONNECTIONS; |
212380e3 AC |
834 | } |
835 | ||
836 | #undef YES | |
837 | #undef NO | |
838 | ||
839 | /* | |
840 | * read_conf() | |
841 | * | |
842 | * | |
843 | * inputs - file descriptor pointing to config file to use | |
844 | * output - None | |
845 | * side effects - Read configuration file. | |
846 | */ | |
847 | static void | |
848 | read_conf(FILE * file) | |
849 | { | |
850 | lineno = 0; | |
851 | ||
852 | set_default_conf(); /* Set default values prior to conf parsing */ | |
853 | yyparse(); /* Load the values from the conf */ | |
854 | validate_conf(); /* Check to make sure some values are still okay. */ | |
855 | /* Some global values are also loaded here. */ | |
856 | check_class(); /* Make sure classes are valid */ | |
422bb0b5 | 857 | privilegeset_delete_all_illegal(); |
212380e3 AC |
858 | } |
859 | ||
860 | static void | |
861 | validate_conf(void) | |
862 | { | |
863 | if(ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN) | |
864 | ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; | |
865 | ||
866 | if(ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN) | |
867 | ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; | |
868 | ||
212380e3 | 869 | if(ServerInfo.network_name == NULL) |
47a03750 | 870 | ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); |
212380e3 AC |
871 | |
872 | if(ServerInfo.network_desc == NULL) | |
47a03750 | 873 | ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); |
212380e3 | 874 | |
8bd5767b | 875 | if(ServerInfo.ssld_count < 1) |
c6d72037 VY |
876 | ServerInfo.ssld_count = 1; |
877 | ||
8bd5767b JT |
878 | if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params)) |
879 | { | |
880 | ilog(L_MAIN, "WARNING: Unable to setup SSL."); | |
881 | ssl_ok = 0; | |
882 | } else { | |
883 | ssl_ok = 1; | |
884 | send_new_ssl_certs(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params); | |
885 | } | |
886 | ||
887 | if(ServerInfo.ssld_count > get_ssld_count()) | |
888 | { | |
889 | int start = ServerInfo.ssld_count - get_ssld_count(); | |
890 | /* start up additional ssld if needed */ | |
891 | start_ssldaemon(start, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params); | |
892 | ||
c6d72037 VY |
893 | } |
894 | ||
212380e3 AC |
895 | if((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) || |
896 | (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX)) | |
897 | ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX; | |
898 | ||
212380e3 AC |
899 | if(!split_users || !split_servers || |
900 | (!ConfigChannel.no_create_on_split && !ConfigChannel.no_join_on_split)) | |
901 | { | |
b2c190a6 JT |
902 | rb_event_delete(check_splitmode_ev); |
903 | check_splitmode_ev = NULL; | |
212380e3 AC |
904 | splitmode = 0; |
905 | splitchecking = 0; | |
906 | } | |
907 | } | |
908 | ||
212380e3 AC |
909 | /* add_temp_kline() |
910 | * | |
911 | * inputs - pointer to struct ConfItem | |
912 | * output - none | |
913 | * Side effects - links in given struct ConfItem into | |
914 | * temporary kline link list | |
915 | */ | |
916 | void | |
917 | add_temp_kline(struct ConfItem *aconf) | |
918 | { | |
e3354945 | 919 | if(aconf->hold >= rb_current_time() + (10080 * 60)) |
212380e3 | 920 | { |
330fc5c1 | 921 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]); |
212380e3 AC |
922 | aconf->port = TEMP_WEEK; |
923 | } | |
e3354945 | 924 | else if(aconf->hold >= rb_current_time() + (1440 * 60)) |
212380e3 | 925 | { |
330fc5c1 | 926 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]); |
212380e3 AC |
927 | aconf->port = TEMP_DAY; |
928 | } | |
e3354945 | 929 | else if(aconf->hold >= rb_current_time() + (60 * 60)) |
212380e3 | 930 | { |
330fc5c1 | 931 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]); |
212380e3 AC |
932 | aconf->port = TEMP_HOUR; |
933 | } | |
934 | else | |
935 | { | |
330fc5c1 | 936 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_MIN]); |
212380e3 AC |
937 | aconf->port = TEMP_MIN; |
938 | } | |
939 | ||
940 | aconf->flags |= CONF_FLAGS_TEMPORARY; | |
40c1fd47 | 941 | add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); |
212380e3 AC |
942 | } |
943 | ||
944 | /* add_temp_dline() | |
945 | * | |
946 | * input - pointer to struct ConfItem | |
947 | * output - none | |
948 | * side effects - added to tdline link list and address hash | |
949 | */ | |
950 | void | |
951 | add_temp_dline(struct ConfItem *aconf) | |
952 | { | |
e3354945 | 953 | if(aconf->hold >= rb_current_time() + (10080 * 60)) |
212380e3 | 954 | { |
330fc5c1 | 955 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]); |
212380e3 AC |
956 | aconf->port = TEMP_WEEK; |
957 | } | |
e3354945 | 958 | else if(aconf->hold >= rb_current_time() + (1440 * 60)) |
212380e3 | 959 | { |
330fc5c1 | 960 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]); |
212380e3 AC |
961 | aconf->port = TEMP_DAY; |
962 | } | |
e3354945 | 963 | else if(aconf->hold >= rb_current_time() + (60 * 60)) |
212380e3 | 964 | { |
330fc5c1 | 965 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]); |
212380e3 AC |
966 | aconf->port = TEMP_HOUR; |
967 | } | |
968 | else | |
969 | { | |
330fc5c1 | 970 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_MIN]); |
212380e3 AC |
971 | aconf->port = TEMP_MIN; |
972 | } | |
973 | ||
974 | aconf->flags |= CONF_FLAGS_TEMPORARY; | |
40c1fd47 | 975 | add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, NULL, aconf); |
212380e3 AC |
976 | } |
977 | ||
978 | /* expire_tkline() | |
979 | * | |
980 | * inputs - list pointer | |
981 | * - type | |
982 | * output - NONE | |
983 | * side effects - expire tklines and moves them between lists | |
984 | */ | |
985 | static void | |
986 | expire_temp_kd(void *list) | |
987 | { | |
330fc5c1 | 988 | rb_dlink_node *ptr; |
637c4932 | 989 | rb_dlink_node *next_ptr; |
212380e3 AC |
990 | struct ConfItem *aconf; |
991 | ||
637c4932 | 992 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) |
212380e3 AC |
993 | { |
994 | aconf = ptr->data; | |
995 | ||
e3354945 | 996 | if(aconf->hold <= rb_current_time()) |
212380e3 AC |
997 | { |
998 | /* Alert opers that a TKline expired - Hwy */ | |
999 | if(ConfigFileEntry.tkline_expire_notices) | |
1000 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1001 | "Temporary K-line for [%s@%s] expired", | |
1002 | (aconf->user) ? aconf-> | |
1003 | user : "*", (aconf->host) ? aconf->host : "*"); | |
1004 | ||
1005 | delete_one_address_conf(aconf->host, aconf); | |
330fc5c1 | 1006 | rb_dlinkDestroy(ptr, list); |
212380e3 AC |
1007 | } |
1008 | } | |
1009 | } | |
1010 | ||
1011 | static void | |
1012 | reorganise_temp_kd(void *list) | |
1013 | { | |
1014 | struct ConfItem *aconf; | |
637c4932 | 1015 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 1016 | |
637c4932 | 1017 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) |
212380e3 AC |
1018 | { |
1019 | aconf = ptr->data; | |
1020 | ||
e3354945 | 1021 | if(aconf->hold < (rb_current_time() + (60 * 60))) |
212380e3 | 1022 | { |
330fc5c1 | 1023 | rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? |
212380e3 AC |
1024 | &temp_klines[TEMP_MIN] : &temp_dlines[TEMP_MIN]); |
1025 | aconf->port = TEMP_MIN; | |
1026 | } | |
1027 | else if(aconf->port > TEMP_HOUR) | |
1028 | { | |
e3354945 | 1029 | if(aconf->hold < (rb_current_time() + (1440 * 60))) |
212380e3 | 1030 | { |
330fc5c1 | 1031 | rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? |
212380e3 AC |
1032 | &temp_klines[TEMP_HOUR] : &temp_dlines[TEMP_HOUR]); |
1033 | aconf->port = TEMP_HOUR; | |
1034 | } | |
1035 | else if(aconf->port > TEMP_DAY && | |
e3354945 | 1036 | (aconf->hold < (rb_current_time() + (10080 * 60)))) |
212380e3 | 1037 | { |
330fc5c1 | 1038 | rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? |
212380e3 AC |
1039 | &temp_klines[TEMP_DAY] : &temp_dlines[TEMP_DAY]); |
1040 | aconf->port = TEMP_DAY; | |
1041 | } | |
1042 | } | |
1043 | } | |
1044 | } | |
1045 | ||
1046 | ||
1047 | /* const char* get_oper_name(struct Client *client_p) | |
1048 | * Input: A client to find the active oper{} name for. | |
1049 | * Output: The nick!user@host{oper} of the oper. | |
1050 | * "oper" is server name for remote opers | |
1051 | * Side effects: None. | |
1052 | */ | |
1053 | char * | |
1054 | get_oper_name(struct Client *client_p) | |
1055 | { | |
1056 | /* +5 for !,@,{,} and null */ | |
1057 | static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5]; | |
1058 | ||
1059 | if(MyOper(client_p)) | |
1060 | { | |
b2f0da88 | 1061 | rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", |
212380e3 AC |
1062 | client_p->name, client_p->username, |
1063 | client_p->host, client_p->localClient->opername); | |
1064 | return buffer; | |
1065 | } | |
1066 | ||
b2f0da88 | 1067 | rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", |
212380e3 AC |
1068 | client_p->name, client_p->username, |
1069 | client_p->host, client_p->servptr->name); | |
1070 | return buffer; | |
1071 | } | |
1072 | ||
1073 | /* | |
1074 | * get_printable_conf | |
1075 | * | |
1076 | * inputs - struct ConfItem | |
1077 | * | |
1078 | * output - name | |
1079 | * - host | |
1080 | * - pass | |
1081 | * - user | |
1082 | * - port | |
1083 | * | |
1084 | * side effects - | |
1085 | * Examine the struct struct ConfItem, setting the values | |
1086 | * of name, host, pass, user to values either | |
1087 | * in aconf, or "<NULL>" port is set to aconf->port in all cases. | |
1088 | */ | |
1089 | void | |
1090 | get_printable_conf(struct ConfItem *aconf, char **name, char **host, | |
1091 | char **pass, char **user, int *port, char **classname) | |
1092 | { | |
1093 | static char null[] = "<NULL>"; | |
1094 | static char zero[] = "default"; | |
1095 | ||
1096 | *name = EmptyString(aconf->name) ? null : aconf->name; | |
1097 | *host = EmptyString(aconf->host) ? null : aconf->host; | |
1098 | *pass = EmptyString(aconf->passwd) ? null : aconf->passwd; | |
1099 | *user = EmptyString(aconf->user) ? null : aconf->user; | |
1100 | *classname = EmptyString(aconf->className) ? zero : aconf->className; | |
1101 | *port = (int) aconf->port; | |
1102 | } | |
1103 | ||
54ac8b60 VY |
1104 | void |
1105 | get_printable_kline(struct Client *source_p, struct ConfItem *aconf, | |
1106 | char **host, char **reason, | |
1107 | char **user, char **oper_reason) | |
1108 | { | |
1109 | static char null[] = "<NULL>"; | |
1110 | ||
1111 | *host = EmptyString(aconf->host) ? null : aconf->host; | |
1112 | *reason = EmptyString(aconf->passwd) ? null : aconf->passwd; | |
1113 | *user = EmptyString(aconf->user) ? null : aconf->user; | |
1114 | ||
1115 | if(EmptyString(aconf->spasswd) || !IsOper(source_p)) | |
1116 | *oper_reason = NULL; | |
1117 | else | |
1118 | *oper_reason = aconf->spasswd; | |
212380e3 AC |
1119 | } |
1120 | ||
1121 | /* | |
1122 | * read_conf_files | |
1123 | * | |
1124 | * inputs - cold start YES or NO | |
1125 | * output - none | |
1126 | * side effects - read all conf files needed, ircd.conf kline.conf etc. | |
1127 | */ | |
1128 | void | |
1129 | read_conf_files(int cold) | |
1130 | { | |
1131 | const char *filename; | |
1132 | ||
1133 | conf_fbfile_in = NULL; | |
1134 | ||
1135 | filename = get_conf_name(CONF_TYPE); | |
1136 | ||
1137 | /* We need to know the initial filename for the yyerror() to report | |
1138 | FIXME: The full path is in conffilenamebuf first time since we | |
1139 | dont know anything else | |
1140 | ||
1141 | - Gozem 2002-07-21 | |
1142 | */ | |
f427c8b0 | 1143 | rb_strlcpy(conffilebuf, filename, sizeof(conffilebuf)); |
212380e3 AC |
1144 | |
1145 | if((conf_fbfile_in = fopen(filename, "r")) == NULL) | |
1146 | { | |
1147 | if(cold) | |
1148 | { | |
1149 | ilog(L_MAIN, "Failed in reading configuration file %s", filename); | |
1150 | exit(-1); | |
1151 | } | |
1152 | else | |
1153 | { | |
1154 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1155 | "Can't open file '%s' - aborting rehash!", filename); | |
1156 | return; | |
1157 | } | |
1158 | } | |
1159 | ||
1160 | if(!cold) | |
1161 | { | |
1162 | clear_out_old_conf(); | |
1163 | } | |
1164 | ||
1165 | read_conf(conf_fbfile_in); | |
1166 | fclose(conf_fbfile_in); | |
1167 | } | |
1168 | ||
8ac75529 AC |
1169 | /* |
1170 | * free an alias{} entry. | |
1171 | */ | |
1172 | static void | |
1173 | free_alias_cb(struct DictionaryElement *ptr, void *unused) | |
1174 | { | |
1175 | struct alias_entry *aptr = ptr->data; | |
1176 | ||
637c4932 VY |
1177 | rb_free(aptr->name); |
1178 | rb_free(aptr->target); | |
1179 | rb_free(aptr); | |
8ac75529 AC |
1180 | } |
1181 | ||
212380e3 AC |
1182 | /* |
1183 | * clear_out_old_conf | |
1184 | * | |
1185 | * inputs - none | |
1186 | * output - none | |
1187 | * side effects - Clear out the old configuration | |
1188 | */ | |
1189 | static void | |
1190 | clear_out_old_conf(void) | |
1191 | { | |
1192 | struct Class *cltmp; | |
330fc5c1 | 1193 | rb_dlink_node *ptr; |
637c4932 | 1194 | rb_dlink_node *next_ptr; |
212380e3 AC |
1195 | |
1196 | /* | |
1197 | * don't delete the class table, rather mark all entries | |
1198 | * for deletion. The table is cleaned up by check_class. - avalon | |
1199 | */ | |
5cefa1d6 | 1200 | RB_DLINK_FOREACH(ptr, class_list.head) |
212380e3 AC |
1201 | { |
1202 | cltmp = ptr->data; | |
1203 | MaxUsers(cltmp) = -1; | |
1204 | } | |
1205 | ||
1206 | clear_out_address_conf(); | |
1207 | clear_s_newconf(); | |
1208 | ||
1209 | /* clean out module paths */ | |
1210 | #ifndef STATIC_MODULES | |
1211 | mod_clear_paths(); | |
1212 | mod_add_path(MODULE_DIR); | |
1213 | mod_add_path(MODULE_DIR "/autoload"); | |
1214 | #endif | |
1215 | ||
1216 | /* clean out ServerInfo */ | |
637c4932 | 1217 | rb_free(ServerInfo.description); |
212380e3 | 1218 | ServerInfo.description = NULL; |
637c4932 | 1219 | rb_free(ServerInfo.network_name); |
212380e3 | 1220 | ServerInfo.network_name = NULL; |
637c4932 | 1221 | rb_free(ServerInfo.network_desc); |
212380e3 AC |
1222 | ServerInfo.network_desc = NULL; |
1223 | ||
c6d72037 VY |
1224 | ServerInfo.ssld_count = 1; |
1225 | ||
212380e3 | 1226 | /* clean out AdminInfo */ |
637c4932 | 1227 | rb_free(AdminInfo.name); |
212380e3 | 1228 | AdminInfo.name = NULL; |
637c4932 | 1229 | rb_free(AdminInfo.email); |
212380e3 | 1230 | AdminInfo.email = NULL; |
637c4932 | 1231 | rb_free(AdminInfo.description); |
212380e3 AC |
1232 | AdminInfo.description = NULL; |
1233 | ||
1234 | /* operator{} and class{} blocks are freed above */ | |
1235 | /* clean out listeners */ | |
1236 | close_listeners(); | |
1237 | ||
1238 | /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{} | |
1239 | * and gecos{} blocks are freed above too | |
1240 | */ | |
1241 | ||
1242 | /* clean out general */ | |
d61a1c7e JT |
1243 | rb_free(ConfigFileEntry.kline_reason); |
1244 | ConfigFileEntry.kline_reason = NULL; | |
1245 | ||
637c4932 | 1246 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head) |
212380e3 | 1247 | { |
637c4932 | 1248 | rb_free(ptr->data); |
330fc5c1 | 1249 | rb_dlinkDestroy(ptr, &service_list); |
212380e3 AC |
1250 | } |
1251 | ||
1252 | /* remove any aliases... -- nenolod */ | |
8ac75529 AC |
1253 | irc_dictionary_destroy(alias_dict, free_alias_cb, NULL); |
1254 | alias_dict = NULL; | |
212380e3 AC |
1255 | |
1256 | destroy_blacklists(); | |
1257 | ||
422bb0b5 JT |
1258 | privilegeset_mark_all_illegal(); |
1259 | ||
212380e3 AC |
1260 | /* OK, that should be everything... */ |
1261 | } | |
1262 | ||
1263 | ||
1264 | /* write_confitem() | |
1265 | * | |
1266 | * inputs - kline, dline or resv type flag | |
1267 | * - client pointer to report to | |
1268 | * - user name of target | |
1269 | * - host name of target | |
1270 | * - reason for target | |
1271 | * - time string | |
1272 | * - type of xline | |
1273 | * output - NONE | |
1274 | * side effects - This function takes care of finding the right conf | |
1275 | * file and adding the line to it, as well as notifying | |
1276 | * opers and the user. | |
1277 | */ | |
1278 | void | |
1279 | write_confitem(KlineType type, struct Client *source_p, char *user, | |
1280 | char *host, const char *reason, const char *oper_reason, | |
1281 | const char *current_date, int xtype) | |
1282 | { | |
1283 | char buffer[1024]; | |
1284 | FILE *out; | |
1285 | const char *filename; /* filename to use for kline */ | |
1286 | ||
1287 | filename = get_conf_name(type); | |
1288 | ||
1289 | if(type == KLINE_TYPE) | |
1290 | { | |
1291 | if(EmptyString(oper_reason)) | |
1292 | { | |
1293 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1294 | "%s added K-Line for [%s@%s] [%s]", | |
1295 | get_oper_name(source_p), user, | |
1296 | host, reason); | |
1297 | ilog(L_KLINE, "K %s 0 %s %s %s", | |
1298 | get_oper_name(source_p), user, host, reason); | |
1299 | } | |
1300 | else | |
1301 | { | |
1302 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1303 | "%s added K-Line for [%s@%s] [%s|%s]", | |
1304 | get_oper_name(source_p), user, | |
1305 | host, reason, oper_reason); | |
1306 | ilog(L_KLINE, "K %s 0 %s %s %s|%s", | |
1307 | get_oper_name(source_p), user, host, | |
1308 | reason, oper_reason); | |
1309 | } | |
1310 | ||
1311 | sendto_one_notice(source_p, ":Added K-Line [%s@%s]", | |
1312 | user, host); | |
1313 | } | |
1314 | else if(type == DLINE_TYPE) | |
1315 | { | |
1316 | if(EmptyString(oper_reason)) | |
1317 | { | |
1318 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1319 | "%s added D-Line for [%s] [%s]", | |
1320 | get_oper_name(source_p), host, reason); | |
1321 | ilog(L_KLINE, "D %s 0 %s %s", | |
1322 | get_oper_name(source_p), host, reason); | |
1323 | } | |
1324 | else | |
1325 | { | |
1326 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1327 | "%s added D-Line for [%s] [%s|%s]", | |
1328 | get_oper_name(source_p), host, | |
1329 | reason, oper_reason); | |
1330 | ilog(L_KLINE, "D %s 0 %s %s|%s", | |
1331 | get_oper_name(source_p), host, | |
1332 | reason, oper_reason); | |
1333 | } | |
1334 | ||
5366977b | 1335 | sendto_one_notice(source_p, ":Added D-Line [%s] to %s", host, filename); |
212380e3 AC |
1336 | |
1337 | } | |
1338 | else if(type == RESV_TYPE) | |
1339 | { | |
1340 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1341 | "%s added RESV for [%s] [%s]", | |
1342 | get_oper_name(source_p), host, reason); | |
1343 | ilog(L_KLINE, "R %s 0 %s %s", | |
1344 | get_oper_name(source_p), host, reason); | |
1345 | ||
1346 | sendto_one_notice(source_p, ":Added RESV for [%s] [%s]", | |
1347 | host, reason); | |
1348 | } | |
1349 | ||
1350 | if((out = fopen(filename, "a")) == NULL) | |
1351 | { | |
1352 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem opening %s ", filename); | |
1353 | sendto_one_notice(source_p, ":*** Problem opening file, added temporarily only"); | |
1354 | return; | |
1355 | } | |
1356 | ||
1357 | if(oper_reason == NULL) | |
1358 | oper_reason = ""; | |
1359 | ||
1360 | if(type == KLINE_TYPE) | |
1361 | { | |
b2f0da88 | 1362 | rb_snprintf(buffer, sizeof(buffer), |
212380e3 AC |
1363 | "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", |
1364 | user, host, reason, oper_reason, current_date, | |
8982edb0 | 1365 | get_oper_name(source_p), (long int)rb_current_time()); |
212380e3 AC |
1366 | } |
1367 | else if(type == DLINE_TYPE) | |
1368 | { | |
b2f0da88 | 1369 | rb_snprintf(buffer, sizeof(buffer), |
212380e3 | 1370 | "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host, |
8982edb0 | 1371 | reason, oper_reason, current_date, get_oper_name(source_p), (long int)rb_current_time()); |
212380e3 AC |
1372 | } |
1373 | else if(type == RESV_TYPE) | |
1374 | { | |
b2f0da88 | 1375 | rb_snprintf(buffer, sizeof(buffer), "\"%s\",\"%s\",\"%s\",%ld\n", |
8982edb0 | 1376 | host, reason, get_oper_name(source_p), (long int)rb_current_time()); |
212380e3 AC |
1377 | } |
1378 | ||
1379 | if(fputs(buffer, out) == -1) | |
1380 | { | |
1381 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem writing to %s", filename); | |
1382 | sendto_one_notice(source_p, ":*** Problem writing to file, added temporarily only"); | |
1383 | fclose(out); | |
1384 | return; | |
1385 | } | |
1386 | ||
1387 | if (fclose(out)) | |
1388 | { | |
1389 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem writing to %s", filename); | |
1390 | sendto_one_notice(source_p, ":*** Problem writing to file, added temporarily only"); | |
1391 | return; | |
1392 | } | |
1393 | } | |
1394 | ||
1395 | /* get_conf_name | |
1396 | * | |
1397 | * inputs - type of conf file to return name of file for | |
1398 | * output - pointer to filename for type of conf | |
1399 | * side effects - none | |
1400 | */ | |
1401 | const char * | |
1402 | get_conf_name(KlineType type) | |
1403 | { | |
1404 | if(type == CONF_TYPE) | |
1405 | { | |
1406 | return (ConfigFileEntry.configfile); | |
1407 | } | |
1408 | else if(type == DLINE_TYPE) | |
1409 | { | |
1410 | return (ConfigFileEntry.dlinefile); | |
1411 | } | |
1412 | else if(type == RESV_TYPE) | |
1413 | { | |
1414 | return (ConfigFileEntry.resvfile); | |
1415 | } | |
1416 | ||
1417 | return ConfigFileEntry.klinefile; | |
1418 | } | |
1419 | ||
1420 | /* | |
1421 | * conf_add_class_to_conf | |
1422 | * inputs - pointer to config item | |
1423 | * output - NONE | |
1424 | * side effects - Add a class pointer to a conf | |
1425 | */ | |
1426 | ||
1427 | void | |
1428 | conf_add_class_to_conf(struct ConfItem *aconf) | |
1429 | { | |
1430 | if(aconf->className == NULL) | |
1431 | { | |
47a03750 | 1432 | aconf->className = rb_strdup("default"); |
212380e3 AC |
1433 | ClassPtr(aconf) = default_class; |
1434 | return; | |
1435 | } | |
1436 | ||
1437 | ClassPtr(aconf) = find_class(aconf->className); | |
1438 | ||
1439 | if(ClassPtr(aconf) == default_class) | |
1440 | { | |
1441 | if(aconf->status == CONF_CLIENT) | |
1442 | { | |
1443 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1444 | "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s", | |
1445 | aconf->className, aconf->user, aconf->host); | |
1446 | } | |
1447 | ||
637c4932 | 1448 | rb_free(aconf->className); |
47a03750 | 1449 | aconf->className = rb_strdup("default"); |
212380e3 AC |
1450 | return; |
1451 | } | |
1452 | ||
1453 | if(ConfMaxUsers(aconf) < 0) | |
1454 | { | |
1455 | ClassPtr(aconf) = default_class; | |
637c4932 | 1456 | rb_free(aconf->className); |
47a03750 | 1457 | aconf->className = rb_strdup("default"); |
212380e3 AC |
1458 | return; |
1459 | } | |
1460 | } | |
1461 | ||
1462 | /* | |
1463 | * conf_add_d_conf | |
1464 | * inputs - pointer to config item | |
1465 | * output - NONE | |
1466 | * side effects - Add a d/D line | |
1467 | */ | |
1468 | void | |
1469 | conf_add_d_conf(struct ConfItem *aconf) | |
1470 | { | |
1471 | if(aconf->host == NULL) | |
1472 | return; | |
1473 | ||
1474 | aconf->user = NULL; | |
1475 | ||
1476 | /* XXX - Should 'd' ever be in the old conf? For new conf we don't | |
1477 | * need this anyway, so I will disable it for now... -A1kmm | |
1478 | */ | |
1479 | ||
1480 | if(parse_netmask(aconf->host, NULL, NULL) == HM_HOST) | |
1481 | { | |
1482 | ilog(L_MAIN, "Invalid Dline %s ignored", aconf->host); | |
1483 | free_conf(aconf); | |
1484 | } | |
1485 | else | |
1486 | { | |
40c1fd47 | 1487 | add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf); |
212380e3 AC |
1488 | } |
1489 | } | |
1490 | ||
decf0486 VY |
1491 | static char * |
1492 | strip_tabs(char *dest, const char *src, size_t len) | |
1493 | { | |
1494 | char *d = dest; | |
1495 | ||
1496 | if(dest == NULL || src == NULL) | |
1497 | return NULL; | |
1498 | ||
1499 | rb_strlcpy(dest, src, len); | |
1500 | ||
1501 | while(*d) | |
1502 | { | |
1503 | if(*d == '\t') | |
1504 | *d = ' '; | |
1505 | d++; | |
1506 | } | |
1507 | return dest; | |
1508 | } | |
212380e3 AC |
1509 | |
1510 | /* | |
1511 | * yyerror | |
1512 | * | |
1513 | * inputs - message from parser | |
1514 | * output - none | |
1515 | * side effects - message to opers and log file entry is made | |
1516 | */ | |
1517 | void | |
1518 | yyerror(const char *msg) | |
1519 | { | |
1520 | char newlinebuf[BUFSIZE]; | |
1521 | ||
9eea5de1 | 1522 | strip_tabs(newlinebuf, linebuf, strlen(linebuf)); |
212380e3 AC |
1523 | |
1524 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s at '%s'", | |
1525 | conffilebuf, lineno + 1, msg, newlinebuf); | |
1526 | ||
1527 | ilog(L_MAIN, "\"%s\", line %d: %s at '%s'", conffilebuf, lineno + 1, msg, newlinebuf); | |
1528 | } | |
1529 | ||
1530 | int | |
1531 | conf_fgets(char *lbuf, int max_size, FILE * fb) | |
1532 | { | |
1533 | char *buff; | |
1534 | ||
1535 | if((buff = fgets(lbuf, max_size, fb)) == NULL) | |
1536 | return (0); | |
1537 | ||
1538 | return (strlen(lbuf)); | |
1539 | } | |
1540 | ||
1541 | int | |
1542 | conf_yy_fatal_error(const char *msg) | |
1543 | { | |
1544 | return (0); | |
1545 | } |