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