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