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