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