]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * s_conf.c: Configuration file functions. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
23 | * | |
cda8e9b8 | 24 | * $Id: s_conf.c 3550 2007-08-09 06:47:26Z nenolod $ |
212380e3 AC |
25 | */ |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "ircd_defs.h" | |
212380e3 AC |
29 | #include "s_conf.h" |
30 | #include "s_newconf.h" | |
31 | #include "s_serv.h" | |
32 | #include "s_stats.h" | |
33 | #include "channel.h" | |
34 | #include "class.h" | |
35 | #include "client.h" | |
36 | #include "common.h" | |
212380e3 AC |
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" | |
212380e3 AC |
45 | #include "s_log.h" |
46 | #include "send.h" | |
47 | #include "s_gline.h" | |
212380e3 AC |
48 | #include "patricia.h" |
49 | #include "reject.h" | |
50 | #include "cache.h" | |
51 | #include "blacklist.h" | |
52 | ||
53 | struct config_server_hide ConfigServerHide; | |
54 | ||
55 | extern int yyparse(); /* defined in y.tab.c */ | |
56 | extern char linebuf[]; | |
57 | ||
58 | #ifndef INADDR_NONE | |
59 | #define INADDR_NONE ((unsigned int) 0xffffffff) | |
60 | #endif | |
61 | ||
62 | static BlockHeap *confitem_heap = NULL; | |
63 | ||
330fc5c1 AC |
64 | rb_dlink_list temp_klines[LAST_TEMP_TYPE]; |
65 | rb_dlink_list temp_dlines[LAST_TEMP_TYPE]; | |
66 | rb_dlink_list service_list; | |
212380e3 AC |
67 | |
68 | /* internally defined functions */ | |
69 | static void set_default_conf(void); | |
70 | static void validate_conf(void); | |
71 | static void read_conf(FILE *); | |
72 | static void clear_out_old_conf(void); | |
73 | ||
74 | static void expire_temp_kd(void *list); | |
75 | static void reorganise_temp_kd(void *list); | |
76 | ||
77 | FILE *conf_fbfile_in; | |
78 | extern char yytext[]; | |
79 | ||
80 | static int verify_access(struct Client *client_p, const char *username); | |
81 | static int attach_iline(struct Client *, struct ConfItem *); | |
82 | ||
83 | void | |
84 | init_s_conf(void) | |
85 | { | |
86 | confitem_heap = BlockHeapCreate(sizeof(struct ConfItem), CONFITEM_HEAP_SIZE); | |
87 | ||
88 | eventAddIsh("expire_temp_klines", expire_temp_kd, &temp_klines[TEMP_MIN], 60); | |
89 | eventAddIsh("expire_temp_dlines", expire_temp_kd, &temp_dlines[TEMP_MIN], 60); | |
90 | ||
91 | eventAddIsh("expire_temp_klines_hour", reorganise_temp_kd, | |
92 | &temp_klines[TEMP_HOUR], 3600); | |
93 | eventAddIsh("expire_temp_dlines_hour", reorganise_temp_kd, | |
94 | &temp_dlines[TEMP_HOUR], 3600); | |
95 | eventAddIsh("expire_temp_klines_day", reorganise_temp_kd, | |
96 | &temp_klines[TEMP_DAY], 86400); | |
97 | eventAddIsh("expire_temp_dlines_day", reorganise_temp_kd, | |
98 | &temp_dlines[TEMP_DAY], 86400); | |
99 | eventAddIsh("expire_temp_klines_week", reorganise_temp_kd, | |
100 | &temp_klines[TEMP_WEEK], 604800); | |
101 | eventAddIsh("expire_temp_dlines_week", reorganise_temp_kd, | |
102 | &temp_dlines[TEMP_WEEK], 604800); | |
103 | } | |
104 | ||
105 | /* | |
106 | * make_conf | |
107 | * | |
108 | * inputs - none | |
109 | * output - pointer to new conf entry | |
110 | * side effects - none | |
111 | */ | |
112 | struct ConfItem * | |
113 | make_conf() | |
114 | { | |
115 | struct ConfItem *aconf; | |
116 | ||
117 | aconf = BlockHeapAlloc(confitem_heap); | |
118 | aconf->status = CONF_ILLEGAL; | |
119 | return (aconf); | |
120 | } | |
121 | ||
122 | /* | |
123 | * free_conf | |
124 | * | |
125 | * inputs - pointer to conf to free | |
126 | * output - none | |
127 | * side effects - crucial password fields are zeroed, conf is freed | |
128 | */ | |
129 | void | |
130 | free_conf(struct ConfItem *aconf) | |
131 | { | |
132 | s_assert(aconf != NULL); | |
133 | if(aconf == NULL) | |
134 | return; | |
135 | ||
136 | /* security.. */ | |
137 | if(aconf->passwd) | |
138 | memset(aconf->passwd, 0, strlen(aconf->passwd)); | |
139 | if(aconf->spasswd) | |
140 | memset(aconf->spasswd, 0, strlen(aconf->spasswd)); | |
141 | ||
637c4932 VY |
142 | rb_free(aconf->passwd); |
143 | rb_free(aconf->spasswd); | |
144 | rb_free(aconf->name); | |
145 | rb_free(aconf->className); | |
146 | rb_free(aconf->user); | |
147 | rb_free(aconf->host); | |
212380e3 AC |
148 | |
149 | BlockHeapFree(confitem_heap, aconf); | |
150 | } | |
151 | ||
152 | /* | |
153 | * check_client | |
154 | * | |
155 | * inputs - pointer to client | |
156 | * output - 0 = Success | |
157 | * NOT_AUTHORISED (-1) = Access denied (no I line match) | |
158 | * SOCKET_ERROR (-2) = Bad socket. | |
159 | * I_LINE_FULL (-3) = I-line is full | |
160 | * TOO_MANY (-4) = Too many connections from hostname | |
161 | * BANNED_CLIENT (-5) = K-lined | |
162 | * side effects - Ordinary client access check. | |
163 | * Look for conf lines which have the same | |
164 | * status as the flags passed. | |
165 | */ | |
166 | int | |
167 | check_client(struct Client *client_p, struct Client *source_p, const char *username) | |
168 | { | |
169 | int i; | |
170 | ||
212380e3 AC |
171 | if((i = verify_access(source_p, username))) |
172 | { | |
173 | ilog(L_FUSER, "Access denied: %s[%s]", | |
174 | source_p->name, source_p->sockhost); | |
175 | } | |
176 | ||
177 | switch (i) | |
178 | { | |
179 | case SOCKET_ERROR: | |
180 | exit_client(client_p, source_p, &me, "Socket Error"); | |
181 | break; | |
182 | ||
183 | case TOO_MANY_LOCAL: | |
606384ae JT |
184 | /* Note that these notices are sent to opers on other |
185 | * servers also, so even if local opers are allowed to | |
186 | * see the IP, we still cannot send it. | |
187 | */ | |
212380e3 AC |
188 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, |
189 | "Too many local connections for %s!%s%s@%s", | |
190 | source_p->name, IsGotId(source_p) ? "" : "~", | |
606384ae JT |
191 | source_p->username, |
192 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); | |
212380e3 AC |
193 | |
194 | ilog(L_FUSER, "Too many local connections from %s!%s%s@%s", | |
195 | source_p->name, IsGotId(source_p) ? "" : "~", | |
196 | source_p->username, source_p->sockhost); | |
197 | ||
198 | ServerStats->is_ref++; | |
199 | exit_client(client_p, source_p, &me, "Too many host connections (local)"); | |
200 | break; | |
201 | ||
202 | case TOO_MANY_GLOBAL: | |
203 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, | |
204 | "Too many global connections for %s!%s%s@%s", | |
205 | source_p->name, IsGotId(source_p) ? "" : "~", | |
606384ae JT |
206 | source_p->username, |
207 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); | |
212380e3 AC |
208 | ilog(L_FUSER, "Too many global connections from %s!%s%s@%s", |
209 | source_p->name, IsGotId(source_p) ? "" : "~", | |
210 | source_p->username, source_p->sockhost); | |
211 | ||
212 | ServerStats->is_ref++; | |
213 | exit_client(client_p, source_p, &me, "Too many host connections (global)"); | |
214 | break; | |
215 | ||
216 | case TOO_MANY_IDENT: | |
217 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, | |
218 | "Too many user connections for %s!%s%s@%s", | |
219 | source_p->name, IsGotId(source_p) ? "" : "~", | |
606384ae JT |
220 | source_p->username, |
221 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); | |
212380e3 AC |
222 | ilog(L_FUSER, "Too many user connections from %s!%s%s@%s", |
223 | source_p->name, IsGotId(source_p) ? "" : "~", | |
224 | source_p->username, source_p->sockhost); | |
225 | ||
226 | ServerStats->is_ref++; | |
227 | exit_client(client_p, source_p, &me, "Too many user connections (global)"); | |
228 | break; | |
229 | ||
230 | case I_LINE_FULL: | |
231 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, | |
232 | "I-line is full for %s!%s%s@%s (%s).", | |
233 | source_p->name, IsGotId(source_p) ? "" : "~", | |
234 | source_p->username, source_p->host, | |
4b7e6904 | 235 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : "255.255.255.255"); |
212380e3 AC |
236 | |
237 | ilog(L_FUSER, "Too many connections from %s!%s%s@%s.", | |
238 | source_p->name, IsGotId(source_p) ? "" : "~", | |
239 | source_p->username, source_p->sockhost); | |
240 | ||
241 | ServerStats->is_ref++; | |
242 | exit_client(client_p, source_p, &me, | |
243 | "No more connections allowed in your connection class"); | |
244 | break; | |
245 | ||
246 | case NOT_AUTHORISED: | |
247 | { | |
248 | int port = -1; | |
249 | #ifdef IPV6 | |
250 | if(source_p->localClient->ip.ss_family == AF_INET6) | |
251 | port = ntohs(((struct sockaddr_in6 *)&source_p->localClient->listener->addr)->sin6_port); | |
252 | else | |
253 | #endif | |
254 | port = ntohs(((struct sockaddr_in *)&source_p->localClient->listener->addr)->sin_port); | |
255 | ||
256 | ServerStats->is_ref++; | |
257 | /* jdc - lists server name & port connections are on */ | |
258 | /* a purely cosmetical change */ | |
259 | /* why ipaddr, and not just source_p->sockhost? --fl */ | |
260 | #if 0 | |
261 | static char ipaddr[HOSTIPLEN]; | |
262 | inetntop_sock(&source_p->localClient->ip, ipaddr, sizeof(ipaddr)); | |
263 | #endif | |
264 | sendto_realops_snomask(SNO_UNAUTH, L_ALL, | |
265 | "Unauthorised client connection from " | |
266 | "%s!%s%s@%s [%s] on [%s/%u].", | |
267 | source_p->name, IsGotId(source_p) ? "" : "~", | |
268 | source_p->username, source_p->host, | |
269 | source_p->sockhost, | |
270 | source_p->localClient->listener->name, port); | |
271 | ||
272 | ilog(L_FUSER, | |
273 | "Unauthorised client connection from %s!%s%s@%s on [%s/%u].", | |
274 | source_p->name, IsGotId(source_p) ? "" : "~", | |
275 | source_p->username, source_p->sockhost, | |
276 | source_p->localClient->listener->name, port); | |
35f6f850 | 277 | add_reject(client_p, NULL, NULL); |
212380e3 AC |
278 | exit_client(client_p, source_p, &me, |
279 | "You are not authorised to use this server"); | |
280 | break; | |
281 | } | |
282 | case BANNED_CLIENT: | |
212380e3 AC |
283 | exit_client(client_p, client_p, &me, "*** Banned "); |
284 | ServerStats->is_ref++; | |
285 | break; | |
286 | ||
287 | case 0: | |
288 | default: | |
289 | break; | |
290 | } | |
291 | return (i); | |
292 | } | |
293 | ||
294 | /* | |
295 | * verify_access | |
296 | * | |
297 | * inputs - pointer to client to verify | |
298 | * - pointer to proposed username | |
299 | * output - 0 if success -'ve if not | |
300 | * side effect - find the first (best) I line to attach. | |
301 | */ | |
302 | static int | |
303 | verify_access(struct Client *client_p, const char *username) | |
304 | { | |
305 | struct ConfItem *aconf; | |
306 | char non_ident[USERLEN + 1]; | |
307 | ||
308 | if(IsGotId(client_p)) | |
309 | { | |
310 | aconf = find_address_conf(client_p->host, client_p->sockhost, | |
311 | client_p->username, client_p->username, | |
312 | (struct sockaddr *) &client_p->localClient->ip, | |
313 | client_p->localClient->ip.ss_family); | |
314 | } | |
315 | else | |
316 | { | |
317 | strlcpy(non_ident, "~", sizeof(non_ident)); | |
318 | strlcat(non_ident, username, sizeof(non_ident)); | |
319 | aconf = find_address_conf(client_p->host, client_p->sockhost, | |
320 | non_ident, client_p->username, | |
321 | (struct sockaddr *) &client_p->localClient->ip, | |
322 | client_p->localClient->ip.ss_family); | |
323 | } | |
324 | ||
325 | if(aconf == NULL) | |
326 | return NOT_AUTHORISED; | |
327 | ||
328 | if(aconf->status & CONF_CLIENT) | |
329 | { | |
330 | if(aconf->flags & CONF_FLAGS_REDIR) | |
331 | { | |
88520303 | 332 | sendto_one_numeric(client_p, RPL_REDIR, form_str(RPL_REDIR), |
212380e3 AC |
333 | aconf->name ? aconf->name : "", aconf->port); |
334 | return (NOT_AUTHORISED); | |
335 | } | |
336 | ||
212380e3 AC |
337 | /* Thanks for spoof idea amm */ |
338 | if(IsConfDoSpoofIp(aconf)) | |
339 | { | |
340 | char *p; | |
341 | ||
342 | /* show_ip() depends on this --fl */ | |
343 | SetIPSpoof(client_p); | |
344 | ||
345 | if(IsConfSpoofNotice(aconf)) | |
346 | { | |
347 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
348 | "%s spoofing: %s as %s", | |
349 | client_p->name, | |
350 | show_ip(NULL, client_p) ? client_p->host : aconf->name, | |
351 | aconf->name); | |
352 | } | |
353 | ||
354 | /* user@host spoof */ | |
355 | if((p = strchr(aconf->name, '@')) != NULL) | |
356 | { | |
357 | char *host = p+1; | |
358 | *p = '\0'; | |
359 | ||
360 | strlcpy(client_p->username, aconf->name, | |
361 | sizeof(client_p->username)); | |
362 | strlcpy(client_p->host, host, | |
363 | sizeof(client_p->host)); | |
364 | *p = '@'; | |
365 | } | |
366 | else | |
367 | strlcpy(client_p->host, aconf->name, sizeof(client_p->host)); | |
368 | } | |
369 | return (attach_iline(client_p, aconf)); | |
370 | } | |
371 | else if(aconf->status & CONF_KILL) | |
372 | { | |
373 | if(ConfigFileEntry.kline_with_reason) | |
374 | { | |
375 | sendto_one(client_p, | |
92fb5c31 | 376 | form_str(ERR_YOUREBANNEDCREEP), |
212380e3 AC |
377 | me.name, client_p->name, aconf->passwd); |
378 | } | |
35f6f850 | 379 | add_reject(client_p, aconf->user, aconf->host); |
212380e3 AC |
380 | return (BANNED_CLIENT); |
381 | } | |
382 | else if(aconf->status & CONF_GLINE) | |
383 | { | |
5366977b | 384 | sendto_one_notice(client_p, ":*** G-lined"); |
212380e3 AC |
385 | |
386 | if(ConfigFileEntry.kline_with_reason) | |
387 | sendto_one(client_p, | |
92fb5c31 | 388 | form_str(ERR_YOUREBANNEDCREEP), |
212380e3 AC |
389 | me.name, client_p->name, aconf->passwd); |
390 | ||
35f6f850 | 391 | add_reject(client_p, aconf->user, aconf->host); |
212380e3 AC |
392 | return (BANNED_CLIENT); |
393 | } | |
394 | ||
395 | return NOT_AUTHORISED; | |
396 | } | |
397 | ||
398 | ||
399 | /* | |
400 | * add_ip_limit | |
401 | * | |
402 | * Returns 1 if successful 0 if not | |
403 | * | |
404 | * This checks if the user has exceed the limits for their class | |
405 | * unless of course they are exempt.. | |
406 | */ | |
407 | ||
408 | static int | |
409 | add_ip_limit(struct Client *client_p, struct ConfItem *aconf) | |
410 | { | |
411 | patricia_node_t *pnode; | |
412 | ||
413 | /* If the limits are 0 don't do anything.. */ | |
414 | if(ConfCidrAmount(aconf) == 0 || ConfCidrBitlen(aconf) == 0) | |
415 | return -1; | |
416 | ||
417 | pnode = match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip); | |
418 | ||
419 | if(pnode == NULL) | |
420 | pnode = make_and_lookup_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip, ConfCidrBitlen(aconf)); | |
421 | ||
422 | s_assert(pnode != NULL); | |
423 | ||
424 | if(pnode != NULL) | |
425 | { | |
426 | if(((long) pnode->data) >= ConfCidrAmount(aconf) | |
427 | && !IsConfExemptLimits(aconf)) | |
428 | { | |
429 | /* This should only happen if the limits are set to 0 */ | |
430 | if((unsigned long) pnode->data == 0) | |
431 | { | |
432 | patricia_remove(ConfIpLimits(aconf), pnode); | |
433 | } | |
434 | return (0); | |
435 | } | |
436 | ||
437 | pnode->data++; | |
438 | } | |
439 | return 1; | |
440 | } | |
441 | ||
442 | static void | |
443 | remove_ip_limit(struct Client *client_p, struct ConfItem *aconf) | |
444 | { | |
445 | patricia_node_t *pnode; | |
446 | ||
447 | /* If the limits are 0 don't do anything.. */ | |
448 | if(ConfCidrAmount(aconf) == 0 || ConfCidrBitlen(aconf) == 0) | |
449 | return; | |
450 | ||
451 | pnode = match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip); | |
452 | if(pnode == NULL) | |
453 | return; | |
454 | ||
455 | pnode->data--; | |
456 | if(((unsigned long) pnode->data) == 0) | |
457 | { | |
458 | patricia_remove(ConfIpLimits(aconf), pnode); | |
459 | } | |
460 | ||
461 | } | |
462 | ||
463 | /* | |
464 | * attach_iline | |
465 | * | |
466 | * inputs - client pointer | |
467 | * - conf pointer | |
468 | * output - | |
469 | * side effects - do actual attach | |
470 | */ | |
471 | static int | |
472 | attach_iline(struct Client *client_p, struct ConfItem *aconf) | |
473 | { | |
474 | struct Client *target_p; | |
330fc5c1 | 475 | rb_dlink_node *ptr; |
212380e3 AC |
476 | int local_count = 0; |
477 | int global_count = 0; | |
478 | int ident_count = 0; | |
479 | int unidented = 0; | |
480 | ||
481 | if(IsConfExemptLimits(aconf)) | |
482 | return (attach_conf(client_p, aconf)); | |
483 | ||
484 | if(*client_p->username == '~') | |
485 | unidented = 1; | |
486 | ||
487 | ||
488 | /* find_hostname() returns the head of the list to search */ | |
5cefa1d6 | 489 | RB_DLINK_FOREACH(ptr, find_hostname(client_p->host)) |
212380e3 AC |
490 | { |
491 | target_p = ptr->data; | |
492 | ||
493 | if(irccmp(client_p->host, target_p->orighost) != 0) | |
494 | continue; | |
495 | ||
496 | if(MyConnect(target_p)) | |
497 | local_count++; | |
498 | ||
499 | global_count++; | |
500 | ||
501 | if(unidented) | |
502 | { | |
503 | if(*target_p->username == '~') | |
504 | ident_count++; | |
505 | } | |
506 | else if(irccmp(target_p->username, client_p->username) == 0) | |
507 | ident_count++; | |
508 | ||
509 | if(ConfMaxLocal(aconf) && local_count >= ConfMaxLocal(aconf)) | |
510 | return (TOO_MANY_LOCAL); | |
511 | else if(ConfMaxGlobal(aconf) && global_count >= ConfMaxGlobal(aconf)) | |
512 | return (TOO_MANY_GLOBAL); | |
513 | else if(ConfMaxIdent(aconf) && ident_count >= ConfMaxIdent(aconf)) | |
514 | return (TOO_MANY_IDENT); | |
515 | } | |
516 | ||
517 | ||
518 | return (attach_conf(client_p, aconf)); | |
519 | } | |
520 | ||
521 | /* | |
522 | * detach_conf | |
523 | * | |
524 | * inputs - pointer to client to detach | |
525 | * output - 0 for success, -1 for failure | |
526 | * side effects - Disassociate configuration from the client. | |
527 | * Also removes a class from the list if marked for deleting. | |
528 | */ | |
529 | int | |
530 | detach_conf(struct Client *client_p) | |
531 | { | |
532 | struct ConfItem *aconf; | |
533 | ||
534 | aconf = client_p->localClient->att_conf; | |
535 | ||
536 | if(aconf != NULL) | |
537 | { | |
538 | if(ClassPtr(aconf)) | |
539 | { | |
540 | remove_ip_limit(client_p, aconf); | |
541 | ||
542 | if(ConfCurrUsers(aconf) > 0) | |
543 | --ConfCurrUsers(aconf); | |
544 | ||
545 | if(ConfMaxUsers(aconf) == -1 && ConfCurrUsers(aconf) == 0) | |
546 | { | |
547 | free_class(ClassPtr(aconf)); | |
548 | ClassPtr(aconf) = NULL; | |
549 | } | |
550 | ||
551 | } | |
552 | ||
553 | aconf->clients--; | |
554 | if(!aconf->clients && IsIllegal(aconf)) | |
555 | free_conf(aconf); | |
556 | ||
557 | client_p->localClient->att_conf = NULL; | |
558 | return 0; | |
559 | } | |
560 | ||
561 | return -1; | |
562 | } | |
563 | ||
564 | /* | |
565 | * attach_conf | |
566 | * | |
567 | * inputs - client pointer | |
568 | * - conf pointer | |
569 | * output - | |
570 | * side effects - Associate a specific configuration entry to a *local* | |
571 | * client (this is the one which used in accepting the | |
572 | * connection). Note, that this automatically changes the | |
573 | * attachment if there was an old one... | |
574 | */ | |
575 | int | |
576 | attach_conf(struct Client *client_p, struct ConfItem *aconf) | |
577 | { | |
578 | if(IsIllegal(aconf)) | |
579 | return (NOT_AUTHORISED); | |
580 | ||
581 | if(ClassPtr(aconf)) | |
582 | { | |
583 | if(!add_ip_limit(client_p, aconf)) | |
584 | return (TOO_MANY_LOCAL); | |
585 | } | |
586 | ||
587 | if((aconf->status & CONF_CLIENT) && | |
588 | ConfCurrUsers(aconf) >= ConfMaxUsers(aconf) && ConfMaxUsers(aconf) > 0) | |
589 | { | |
590 | if(!IsConfExemptLimits(aconf)) | |
591 | { | |
592 | return (I_LINE_FULL); | |
593 | } | |
594 | else | |
595 | { | |
5366977b | 596 | sendto_one_notice(client_p, ":*** I: line is full, but you have an >I: line!"); |
212380e3 AC |
597 | } |
598 | ||
599 | } | |
600 | ||
601 | if(client_p->localClient->att_conf != NULL) | |
602 | detach_conf(client_p); | |
603 | ||
604 | client_p->localClient->att_conf = aconf; | |
605 | ||
606 | aconf->clients++; | |
607 | ConfCurrUsers(aconf)++; | |
608 | return (0); | |
609 | } | |
610 | ||
611 | /* | |
612 | * rehash | |
613 | * | |
614 | * Actual REHASH service routine. Called with sig == 0 if it has been called | |
615 | * as a result of an operator issuing this command, else assume it has been | |
616 | * called as a result of the server receiving a HUP signal. | |
617 | */ | |
618 | int | |
619 | rehash(int sig) | |
620 | { | |
621 | if(sig != 0) | |
622 | { | |
623 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
624 | "Got signal SIGHUP, reloading ircd conf. file"); | |
625 | } | |
626 | ||
627 | restart_resolver(); | |
628 | /* don't close listeners until we know we can go ahead with the rehash */ | |
629 | read_conf_files(NO); | |
630 | ||
631 | if(ServerInfo.description != NULL) | |
632 | strlcpy(me.info, ServerInfo.description, sizeof(me.info)); | |
633 | else | |
634 | strlcpy(me.info, "unknown", sizeof(me.info)); | |
635 | ||
636 | open_logfiles(); | |
637 | return (0); | |
638 | } | |
639 | ||
640 | static struct banconf_entry | |
641 | { | |
642 | const char **filename; | |
643 | void (*func) (FILE *); | |
644 | int perm; | |
645 | } banconfs[] = { | |
646 | { &ConfigFileEntry.klinefile, parse_k_file, 0 }, | |
647 | { &ConfigFileEntry.klinefile, parse_k_file, 1 }, | |
648 | { &ConfigFileEntry.dlinefile, parse_d_file, 0 }, | |
649 | { &ConfigFileEntry.dlinefile, parse_d_file, 1 }, | |
650 | { &ConfigFileEntry.xlinefile, parse_x_file, 0 }, | |
651 | { &ConfigFileEntry.xlinefile, parse_x_file, 1 }, | |
652 | { &ConfigFileEntry.resvfile, parse_resv_file,0 }, | |
653 | { &ConfigFileEntry.resvfile, parse_resv_file,1 }, | |
654 | { NULL, NULL, 0 } | |
655 | }; | |
656 | ||
657 | void | |
658 | rehash_bans(int sig) | |
659 | { | |
660 | FILE *file; | |
661 | char buf[MAXPATHLEN]; | |
662 | int i; | |
663 | ||
664 | if(sig != 0) | |
665 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
666 | "Got signal SIGUSR2, reloading ban confs"); | |
667 | ||
668 | clear_out_address_conf_bans(); | |
669 | clear_s_newconf_bans(); | |
670 | ||
671 | for(i = 0; banconfs[i].filename; i++) | |
672 | { | |
673 | if(banconfs[i].perm) | |
674 | snprintf(buf, sizeof(buf), "%s.perm", *banconfs[i].filename); | |
675 | else | |
676 | snprintf(buf, sizeof(buf), "%s", *banconfs[i].filename); | |
677 | ||
678 | if((file = fopen(buf, "r")) == NULL) | |
679 | { | |
680 | if(banconfs[i].perm) | |
681 | continue; | |
682 | ||
683 | ilog(L_MAIN, "Failed reading ban file %s", | |
684 | *banconfs[i].filename); | |
685 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
686 | "Can't open %s file bans could be missing!", | |
687 | *banconfs[i].filename); | |
688 | } | |
689 | else | |
690 | { | |
691 | (banconfs[i].func)(file); | |
692 | fclose(file); | |
693 | } | |
694 | } | |
695 | ||
696 | check_banned_lines(); | |
697 | } | |
698 | ||
699 | /* | |
700 | * set_default_conf() | |
701 | * | |
702 | * inputs - NONE | |
703 | * output - NONE | |
704 | * side effects - Set default values here. | |
705 | * This is called **PRIOR** to parsing the | |
706 | * configuration file. If you want to do some validation | |
707 | * of values later, put them in validate_conf(). | |
708 | */ | |
709 | ||
710 | #define YES 1 | |
711 | #define NO 0 | |
712 | #define UNSET -1 | |
713 | ||
714 | static void | |
715 | set_default_conf(void) | |
716 | { | |
717 | /* ServerInfo.name is not rehashable */ | |
718 | /* ServerInfo.name = ServerInfo.name; */ | |
719 | ServerInfo.description = NULL; | |
47a03750 VY |
720 | ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); |
721 | ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); | |
212380e3 AC |
722 | |
723 | memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip)); | |
724 | ServerInfo.specific_ipv4_vhost = 0; | |
725 | #ifdef IPV6 | |
726 | memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6)); | |
727 | ServerInfo.specific_ipv6_vhost = 0; | |
728 | #endif | |
212380e3 AC |
729 | |
730 | /* Don't reset hub, as that will break lazylinks */ | |
731 | /* ServerInfo.hub = NO; */ | |
732 | AdminInfo.name = NULL; | |
733 | AdminInfo.email = NULL; | |
734 | AdminInfo.description = NULL; | |
735 | ||
47a03750 VY |
736 | ConfigFileEntry.default_operstring = rb_strdup("is an IRC operator"); |
737 | ConfigFileEntry.default_adminstring = rb_strdup("is a Server Administrator"); | |
738 | ConfigFileEntry.servicestring = rb_strdup("is a Network Service"); | |
212380e3 AC |
739 | |
740 | ConfigFileEntry.default_umodes = UMODE_INVISIBLE; | |
741 | ConfigFileEntry.failed_oper_notice = YES; | |
742 | ConfigFileEntry.anti_nick_flood = NO; | |
743 | ConfigFileEntry.disable_fake_channels = NO; | |
744 | ConfigFileEntry.max_nick_time = 20; | |
745 | ConfigFileEntry.max_nick_changes = 5; | |
746 | ConfigFileEntry.max_accept = 20; | |
747 | ConfigFileEntry.max_monitor = 60; | |
748 | ConfigFileEntry.nick_delay = 900; /* 15 minutes */ | |
749 | ConfigFileEntry.target_change = YES; | |
750 | ConfigFileEntry.anti_spam_exit_message_time = 0; | |
751 | ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; | |
752 | ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; | |
753 | ConfigFileEntry.client_exit = YES; | |
754 | ConfigFileEntry.dline_with_reason = YES; | |
755 | ConfigFileEntry.kline_with_reason = YES; | |
756 | ConfigFileEntry.kline_delay = 0; | |
757 | ConfigFileEntry.warn_no_nline = YES; | |
758 | ConfigFileEntry.non_redundant_klines = YES; | |
759 | ConfigFileEntry.stats_e_disabled = NO; | |
760 | ConfigFileEntry.stats_o_oper_only = NO; | |
761 | ConfigFileEntry.stats_k_oper_only = 1; /* masked */ | |
762 | ConfigFileEntry.stats_i_oper_only = 1; /* masked */ | |
763 | ConfigFileEntry.stats_P_oper_only = NO; | |
764 | ConfigFileEntry.stats_c_oper_only = NO; | |
765 | ConfigFileEntry.stats_y_oper_only = NO; | |
766 | ConfigFileEntry.stats_h_oper_only = NO; | |
767 | ConfigFileEntry.map_oper_only = YES; | |
768 | ConfigFileEntry.operspy_admin_only = NO; | |
769 | ConfigFileEntry.pace_wait = 10; | |
770 | ConfigFileEntry.caller_id_wait = 60; | |
771 | ConfigFileEntry.pace_wait_simple = 1; | |
772 | ConfigFileEntry.short_motd = NO; | |
773 | ConfigFileEntry.no_oper_flood = NO; | |
774 | ConfigFileEntry.fname_userlog = NULL; | |
775 | ConfigFileEntry.fname_fuserlog = NULL; | |
776 | ConfigFileEntry.fname_operlog = NULL; | |
777 | ConfigFileEntry.fname_foperlog = NULL; | |
778 | ConfigFileEntry.fname_serverlog = NULL; | |
779 | ConfigFileEntry.fname_glinelog = NULL; | |
780 | ConfigFileEntry.fname_klinelog = NULL; | |
781 | ConfigFileEntry.fname_operspylog = NULL; | |
782 | ConfigFileEntry.fname_ioerrorlog = NULL; | |
783 | ConfigFileEntry.glines = NO; | |
784 | ConfigFileEntry.use_egd = NO; | |
785 | ConfigFileEntry.gline_time = 12 * 3600; | |
786 | ConfigFileEntry.gline_min_cidr = 16; | |
787 | ConfigFileEntry.gline_min_cidr6 = 48; | |
788 | ConfigFileEntry.hide_spoof_ips = YES; | |
789 | ConfigFileEntry.hide_error_messages = 1; | |
212380e3 AC |
790 | ConfigFileEntry.dots_in_ident = 0; |
791 | ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT; | |
47a03750 | 792 | ConfigFileEntry.servlink_path = rb_strdup(SLPATH); |
212380e3 AC |
793 | ConfigFileEntry.egdpool_path = NULL; |
794 | ConfigFileEntry.use_whois_actually = YES; | |
795 | ConfigFileEntry.burst_away = NO; | |
796 | ConfigFileEntry.collision_fnc = YES; | |
797 | ConfigFileEntry.global_snotices = YES; | |
798 | ConfigFileEntry.operspy_dont_care_user_info = NO; | |
799 | ||
800 | #ifdef HAVE_LIBZ | |
801 | ConfigFileEntry.compression_level = 4; | |
802 | #endif | |
803 | ||
804 | ConfigFileEntry.oper_umodes = UMODE_LOCOPS | UMODE_SERVNOTICE | | |
805 | UMODE_OPERWALL | UMODE_WALLOP; | |
806 | ConfigFileEntry.oper_only_umodes = UMODE_SERVNOTICE; | |
807 | ConfigFileEntry.oper_snomask = SNO_GENERAL; | |
808 | ||
809 | ConfigChannel.use_except = YES; | |
810 | ConfigChannel.use_invex = YES; | |
811 | ConfigChannel.use_knock = YES; | |
812 | ConfigChannel.use_forward = YES; | |
813 | ConfigChannel.knock_delay = 300; | |
814 | ConfigChannel.knock_delay_channel = 60; | |
815 | ConfigChannel.max_chans_per_user = 15; | |
816 | ConfigChannel.max_bans = 25; | |
817 | ConfigChannel.max_bans_large = 500; | |
818 | ConfigChannel.burst_topicwho = NO; | |
212380e3 AC |
819 | ConfigChannel.kick_on_split_riding = NO; |
820 | ||
821 | ConfigChannel.default_split_user_count = 15000; | |
822 | ConfigChannel.default_split_server_count = 10; | |
823 | ConfigChannel.no_join_on_split = NO; | |
824 | ConfigChannel.no_create_on_split = YES; | |
825 | ||
826 | ConfigServerHide.flatten_links = 0; | |
827 | ConfigServerHide.links_delay = 300; | |
828 | ConfigServerHide.hidden = 0; | |
829 | ConfigServerHide.disable_hidden = 0; | |
830 | ||
831 | ConfigFileEntry.min_nonwildcard = 4; | |
832 | ConfigFileEntry.min_nonwildcard_simple = 3; | |
833 | ConfigFileEntry.default_floodcount = 8; | |
834 | ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT; | |
835 | ConfigFileEntry.tkline_expire_notices = 0; | |
836 | ||
837 | ConfigFileEntry.reject_after_count = 5; | |
838 | ConfigFileEntry.reject_ban_time = 300; | |
839 | ConfigFileEntry.reject_duration = 120; | |
54015b5f | 840 | ConfigFileEntry.max_unknown_ip = 2; |
c2d96fcb | 841 | |
b2f0da88 | 842 | ServerInfo.max_clients = rb_get_maxconnections() - MAX_BUFFER; |
212380e3 AC |
843 | } |
844 | ||
845 | #undef YES | |
846 | #undef NO | |
847 | ||
848 | /* | |
849 | * read_conf() | |
850 | * | |
851 | * | |
852 | * inputs - file descriptor pointing to config file to use | |
853 | * output - None | |
854 | * side effects - Read configuration file. | |
855 | */ | |
856 | static void | |
857 | read_conf(FILE * file) | |
858 | { | |
859 | lineno = 0; | |
860 | ||
861 | set_default_conf(); /* Set default values prior to conf parsing */ | |
862 | yyparse(); /* Load the values from the conf */ | |
863 | validate_conf(); /* Check to make sure some values are still okay. */ | |
864 | /* Some global values are also loaded here. */ | |
865 | check_class(); /* Make sure classes are valid */ | |
866 | } | |
867 | ||
868 | static void | |
869 | validate_conf(void) | |
870 | { | |
871 | if(ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN) | |
872 | ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; | |
873 | ||
874 | if(ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN) | |
875 | ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; | |
876 | ||
877 | if(ConfigFileEntry.servlink_path == NULL) | |
47a03750 | 878 | ConfigFileEntry.servlink_path = rb_strdup(SLPATH); |
212380e3 AC |
879 | |
880 | if(ServerInfo.network_name == NULL) | |
47a03750 | 881 | ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); |
212380e3 AC |
882 | |
883 | if(ServerInfo.network_desc == NULL) | |
47a03750 | 884 | ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); |
212380e3 AC |
885 | |
886 | if((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) || | |
887 | (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX)) | |
888 | ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX; | |
889 | ||
212380e3 AC |
890 | if(!split_users || !split_servers || |
891 | (!ConfigChannel.no_create_on_split && !ConfigChannel.no_join_on_split)) | |
892 | { | |
893 | eventDelete(check_splitmode, 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 >= CurrentTime + (10080 * 60)) | |
939 | { | |
330fc5c1 | 940 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]); |
212380e3 AC |
941 | aconf->port = TEMP_WEEK; |
942 | } | |
943 | else if(aconf->hold >= CurrentTime + (1440 * 60)) | |
944 | { | |
330fc5c1 | 945 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]); |
212380e3 AC |
946 | aconf->port = TEMP_DAY; |
947 | } | |
948 | else if(aconf->hold >= CurrentTime + (60 * 60)) | |
949 | { | |
330fc5c1 | 950 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]); |
212380e3 AC |
951 | aconf->port = TEMP_HOUR; |
952 | } | |
953 | else | |
954 | { | |
330fc5c1 | 955 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_MIN]); |
212380e3 AC |
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 >= CurrentTime + (10080 * 60)) | |
973 | { | |
330fc5c1 | 974 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]); |
212380e3 AC |
975 | aconf->port = TEMP_WEEK; |
976 | } | |
977 | else if(aconf->hold >= CurrentTime + (1440 * 60)) | |
978 | { | |
330fc5c1 | 979 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]); |
212380e3 AC |
980 | aconf->port = TEMP_DAY; |
981 | } | |
982 | else if(aconf->hold >= CurrentTime + (60 * 60)) | |
983 | { | |
330fc5c1 | 984 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]); |
212380e3 AC |
985 | aconf->port = TEMP_HOUR; |
986 | } | |
987 | else | |
988 | { | |
330fc5c1 | 989 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_MIN]); |
212380e3 AC |
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 | { | |
330fc5c1 | 1007 | rb_dlink_node *ptr; |
637c4932 | 1008 | rb_dlink_node *next_ptr; |
212380e3 AC |
1009 | struct ConfItem *aconf; |
1010 | ||
637c4932 | 1011 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) |
212380e3 AC |
1012 | { |
1013 | aconf = ptr->data; | |
1014 | ||
1015 | if(aconf->hold <= CurrentTime) | |
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); | |
330fc5c1 | 1025 | rb_dlinkDestroy(ptr, list); |
212380e3 AC |
1026 | } |
1027 | } | |
1028 | } | |
1029 | ||
1030 | static void | |
1031 | reorganise_temp_kd(void *list) | |
1032 | { | |
1033 | struct ConfItem *aconf; | |
637c4932 | 1034 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 1035 | |
637c4932 | 1036 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) |
212380e3 AC |
1037 | { |
1038 | aconf = ptr->data; | |
1039 | ||
1040 | if(aconf->hold < (CurrentTime + (60 * 60))) | |
1041 | { | |
330fc5c1 | 1042 | rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? |
212380e3 AC |
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 < (CurrentTime + (1440 * 60))) | |
1049 | { | |
330fc5c1 | 1050 | rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? |
212380e3 AC |
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 < (CurrentTime + (10080 * 60)))) | |
1056 | { | |
330fc5c1 | 1057 | rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? |
212380e3 AC |
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 | { | |
b2f0da88 | 1080 | rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", |
212380e3 AC |
1081 | client_p->name, client_p->username, |
1082 | client_p->host, client_p->localClient->opername); | |
1083 | return buffer; | |
1084 | } | |
1085 | ||
b2f0da88 | 1086 | rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", |
212380e3 AC |
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 | ||
8ac75529 AC |
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 | ||
637c4932 VY |
1196 | rb_free(aptr->name); |
1197 | rb_free(aptr->target); | |
1198 | rb_free(aptr); | |
8ac75529 AC |
1199 | } |
1200 | ||
212380e3 AC |
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; | |
330fc5c1 | 1212 | rb_dlink_node *ptr; |
637c4932 | 1213 | rb_dlink_node *next_ptr; |
212380e3 AC |
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 | */ | |
5cefa1d6 | 1219 | RB_DLINK_FOREACH(ptr, class_list.head) |
212380e3 AC |
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 */ | |
637c4932 | 1236 | rb_free(ServerInfo.description); |
212380e3 | 1237 | ServerInfo.description = NULL; |
637c4932 | 1238 | rb_free(ServerInfo.network_name); |
212380e3 | 1239 | ServerInfo.network_name = NULL; |
637c4932 | 1240 | rb_free(ServerInfo.network_desc); |
212380e3 AC |
1241 | ServerInfo.network_desc = NULL; |
1242 | ||
1243 | /* clean out AdminInfo */ | |
637c4932 | 1244 | rb_free(AdminInfo.name); |
212380e3 | 1245 | AdminInfo.name = NULL; |
637c4932 | 1246 | rb_free(AdminInfo.email); |
212380e3 | 1247 | AdminInfo.email = NULL; |
637c4932 | 1248 | rb_free(AdminInfo.description); |
212380e3 AC |
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 */ | |
637c4932 | 1260 | rb_free(ConfigFileEntry.servlink_path); |
212380e3 AC |
1261 | ConfigFileEntry.servlink_path = NULL; |
1262 | ||
637c4932 | 1263 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head) |
212380e3 | 1264 | { |
637c4932 | 1265 | rb_free(ptr->data); |
330fc5c1 | 1266 | rb_dlinkDestroy(ptr, &service_list); |
212380e3 AC |
1267 | } |
1268 | ||
1269 | /* remove any aliases... -- nenolod */ | |
8ac75529 AC |
1270 | irc_dictionary_destroy(alias_dict, free_alias_cb, NULL); |
1271 | alias_dict = NULL; | |
212380e3 AC |
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 | ||
5366977b | 1350 | sendto_one_notice(source_p, ":Added D-Line [%s] to %s", host, filename); |
212380e3 AC |
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 | { | |
b2f0da88 | 1377 | rb_snprintf(buffer, sizeof(buffer), |
212380e3 AC |
1378 | "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", |
1379 | user, host, reason, oper_reason, current_date, | |
1380 | get_oper_name(source_p), CurrentTime); | |
1381 | } | |
1382 | else if(type == DLINE_TYPE) | |
1383 | { | |
b2f0da88 | 1384 | rb_snprintf(buffer, sizeof(buffer), |
212380e3 AC |
1385 | "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host, |
1386 | reason, oper_reason, current_date, get_oper_name(source_p), CurrentTime); | |
1387 | } | |
1388 | else if(type == RESV_TYPE) | |
1389 | { | |
b2f0da88 | 1390 | rb_snprintf(buffer, sizeof(buffer), "\"%s\",\"%s\",\"%s\",%ld\n", |
212380e3 AC |
1391 | host, reason, get_oper_name(source_p), CurrentTime); |
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 | { | |
47a03750 | 1447 | aconf->className = rb_strdup("default"); |
212380e3 AC |
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 | ||
637c4932 | 1463 | rb_free(aconf->className); |
47a03750 | 1464 | aconf->className = rb_strdup("default"); |
212380e3 AC |
1465 | return; |
1466 | } | |
1467 | ||
1468 | if(ConfMaxUsers(aconf) < 0) | |
1469 | { | |
1470 | ClassPtr(aconf) = default_class; | |
637c4932 | 1471 | rb_free(aconf->className); |
47a03750 | 1472 | aconf->className = rb_strdup("default"); |
212380e3 AC |
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 | } |