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