1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* conf.c: Configuration file functions. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "list.h" |
27 |
#include "ircd_defs.h" |
28 |
#include "balloc.h" |
29 |
#include "conf.h" |
30 |
#include "s_serv.h" |
31 |
#include "resv.h" |
32 |
#include "channel.h" |
33 |
#include "client.h" |
34 |
#include "event.h" |
35 |
#include "hook.h" |
36 |
#include "irc_string.h" |
37 |
#include "s_bsd.h" |
38 |
#include "ircd.h" |
39 |
#include "listener.h" |
40 |
#include "hostmask.h" |
41 |
#include "modules.h" |
42 |
#include "numeric.h" |
43 |
#include "fdlist.h" |
44 |
#include "log.h" |
45 |
#include "send.h" |
46 |
#include "s_gline.h" |
47 |
#include "memory.h" |
48 |
#include "irc_res.h" |
49 |
#include "userhost.h" |
50 |
#include "s_user.h" |
51 |
#include "channel_mode.h" |
52 |
#include "parse.h" |
53 |
#include "s_misc.h" |
54 |
#include "conf_db.h" |
55 |
#include "conf_class.h" |
56 |
|
57 |
struct Callback *client_check_cb = NULL; |
58 |
struct config_server_hide ConfigServerHide; |
59 |
|
60 |
/* general conf items link list root, other than k lines etc. */ |
61 |
dlink_list service_items = { NULL, NULL, 0 }; |
62 |
dlink_list server_items = { NULL, NULL, 0 }; |
63 |
dlink_list cluster_items = { NULL, NULL, 0 }; |
64 |
dlink_list oconf_items = { NULL, NULL, 0 }; |
65 |
dlink_list uconf_items = { NULL, NULL, 0 }; |
66 |
dlink_list xconf_items = { NULL, NULL, 0 }; |
67 |
dlink_list rxconf_items = { NULL, NULL, 0 }; |
68 |
dlink_list rkconf_items = { NULL, NULL, 0 }; |
69 |
dlink_list nresv_items = { NULL, NULL, 0 }; |
70 |
dlink_list temporary_resv = { NULL, NULL, 0 }; |
71 |
|
72 |
extern unsigned int lineno; |
73 |
extern char linebuf[]; |
74 |
extern char conffilebuf[IRCD_BUFSIZE]; |
75 |
extern int yyparse(); /* defined in y.tab.c */ |
76 |
|
77 |
struct conf_parser_context conf_parser_ctx = { 0, 0, NULL }; |
78 |
|
79 |
/* internally defined functions */ |
80 |
static void read_conf(FILE *); |
81 |
static void clear_out_old_conf(void); |
82 |
static void expire_tklines(dlink_list *); |
83 |
static void garbage_collect_ip_entries(void); |
84 |
static int hash_ip(struct irc_ssaddr *); |
85 |
static int verify_access(struct Client *, const char *); |
86 |
static int attach_iline(struct Client *, struct MaskItem *); |
87 |
static struct ip_entry *find_or_add_ip(struct irc_ssaddr *); |
88 |
static dlink_list *map_to_list(enum maskitem_type); |
89 |
static struct MaskItem *find_regexp_kline(const char *[]); |
90 |
static int find_user_host(struct Client *, char *, char *, char *, unsigned int); |
91 |
|
92 |
/* |
93 |
* bit_len |
94 |
*/ |
95 |
static void flags_to_ascii(unsigned int, const unsigned int[], char *, int); |
96 |
|
97 |
/* usually, with hash tables, you use a prime number... |
98 |
* but in this case I am dealing with ip addresses, |
99 |
* not ascii strings. |
100 |
*/ |
101 |
#define IP_HASH_SIZE 0x1000 |
102 |
|
103 |
struct ip_entry |
104 |
{ |
105 |
struct irc_ssaddr ip; |
106 |
int count; |
107 |
time_t last_attempt; |
108 |
struct ip_entry *next; |
109 |
}; |
110 |
|
111 |
static struct ip_entry *ip_hash_table[IP_HASH_SIZE]; |
112 |
static BlockHeap *ip_entry_heap = NULL; |
113 |
static int ip_entries_count = 0; |
114 |
|
115 |
|
116 |
/* conf_dns_callback() |
117 |
* |
118 |
* inputs - pointer to struct MaskItem |
119 |
* - pointer to DNSReply reply |
120 |
* output - none |
121 |
* side effects - called when resolver query finishes |
122 |
* if the query resulted in a successful search, hp will contain |
123 |
* a non-null pointer, otherwise hp will be null. |
124 |
* if successful save hp in the conf item it was called with |
125 |
*/ |
126 |
static void |
127 |
conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name) |
128 |
{ |
129 |
struct MaskItem *conf = vptr; |
130 |
|
131 |
conf->dns_pending = 0; |
132 |
|
133 |
if (addr != NULL) |
134 |
memcpy(&conf->addr, addr, sizeof(conf->addr)); |
135 |
else |
136 |
conf->dns_failed = 1; |
137 |
} |
138 |
|
139 |
/* conf_dns_lookup() |
140 |
* |
141 |
* do a nameserver lookup of the conf host |
142 |
* if the conf entry is currently doing a ns lookup do nothing, otherwise |
143 |
* allocate a dns_query and start ns lookup. |
144 |
*/ |
145 |
static void |
146 |
conf_dns_lookup(struct MaskItem *conf) |
147 |
{ |
148 |
if (!conf->dns_pending) |
149 |
{ |
150 |
conf->dns_pending = 1; |
151 |
gethost_byname(conf_dns_callback, conf, conf->host); |
152 |
} |
153 |
} |
154 |
|
155 |
struct MaskItem * |
156 |
conf_make(enum maskitem_type type) |
157 |
{ |
158 |
struct MaskItem *conf = MyMalloc(sizeof(*conf)); |
159 |
dlink_list *list = NULL; |
160 |
|
161 |
conf->type = type; |
162 |
conf->active = 1; |
163 |
conf->aftype = AF_INET; |
164 |
|
165 |
if ((list = map_to_list(type))) |
166 |
dlinkAdd(conf, &conf->node, list); |
167 |
return conf; |
168 |
} |
169 |
|
170 |
void |
171 |
conf_free(struct MaskItem *conf) |
172 |
{ |
173 |
dlink_node *ptr = NULL, *ptr_next = NULL; |
174 |
dlink_list *list = NULL; |
175 |
|
176 |
if (conf->node.next) |
177 |
if ((list = map_to_list(conf->type))) |
178 |
dlinkDelete(&conf->node, list); |
179 |
|
180 |
MyFree(conf->name); |
181 |
|
182 |
if (conf->dns_pending) |
183 |
delete_resolver_queries(conf); |
184 |
if (conf->passwd != NULL) |
185 |
memset(conf->passwd, 0, strlen(conf->passwd)); |
186 |
if (conf->spasswd != NULL) |
187 |
memset(conf->spasswd, 0, strlen(conf->spasswd)); |
188 |
|
189 |
conf->class = NULL; |
190 |
|
191 |
MyFree(conf->passwd); |
192 |
MyFree(conf->spasswd); |
193 |
MyFree(conf->reason); |
194 |
MyFree(conf->user); |
195 |
MyFree(conf->host); |
196 |
MyFree(conf->regexuser); |
197 |
MyFree(conf->regexhost); |
198 |
#ifdef HAVE_LIBCRYPTO |
199 |
MyFree(conf->cipher_list); |
200 |
|
201 |
if (conf->rsa_public_key) |
202 |
RSA_free(conf->rsa_public_key); |
203 |
|
204 |
MyFree(conf->rsa_public_key_file); |
205 |
#endif |
206 |
DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head) |
207 |
{ |
208 |
MyFree(ptr->data); |
209 |
free_dlink_node(ptr); |
210 |
} |
211 |
|
212 |
DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head) |
213 |
{ |
214 |
MyFree(ptr->data); |
215 |
free_dlink_node(ptr); |
216 |
} |
217 |
|
218 |
MyFree(conf); |
219 |
} |
220 |
|
221 |
static const unsigned int shared_bit_table[] = |
222 |
{ 'K', 'k', 'U', 'X', 'x', 'Y', 'Q', 'q', 'R', 'L', 0}; |
223 |
|
224 |
/* report_confitem_types() |
225 |
* |
226 |
* inputs - pointer to client requesting confitem report |
227 |
* - ConfType to report |
228 |
* output - none |
229 |
* side effects - |
230 |
*/ |
231 |
void |
232 |
report_confitem_types(struct Client *source_p, enum maskitem_type type) |
233 |
{ |
234 |
dlink_node *ptr = NULL, *dptr = NULL; |
235 |
struct MaskItem *conf = NULL; |
236 |
const struct ClassItem *class = NULL; |
237 |
char buf[12]; |
238 |
char *p = NULL; |
239 |
|
240 |
switch (type) |
241 |
{ |
242 |
case CONF_XLINE: |
243 |
DLINK_FOREACH(ptr, xconf_items.head) |
244 |
{ |
245 |
conf = ptr->data; |
246 |
|
247 |
sendto_one(source_p, form_str(RPL_STATSXLINE), |
248 |
me.name, source_p->name, |
249 |
conf->hold ? "x": "X", conf->count, |
250 |
conf->name, conf->reason); |
251 |
} |
252 |
break; |
253 |
|
254 |
#ifdef HAVE_LIBPCRE |
255 |
case CONF_RXLINE: |
256 |
DLINK_FOREACH(ptr, rxconf_items.head) |
257 |
{ |
258 |
conf = ptr->data; |
259 |
|
260 |
sendto_one(source_p, form_str(RPL_STATSXLINE), |
261 |
me.name, source_p->name, |
262 |
"XR", conf->count, |
263 |
conf->name, conf->reason); |
264 |
} |
265 |
break; |
266 |
|
267 |
case CONF_RKLINE: |
268 |
DLINK_FOREACH(ptr, rkconf_items.head) |
269 |
{ |
270 |
conf = ptr->data; |
271 |
|
272 |
sendto_one(source_p, form_str(RPL_STATSKLINE), me.name, |
273 |
source_p->name, "KR", conf->host, conf->user, |
274 |
conf->reason); |
275 |
} |
276 |
break; |
277 |
#endif |
278 |
|
279 |
case CONF_ULINE: |
280 |
DLINK_FOREACH(ptr, uconf_items.head) |
281 |
{ |
282 |
conf = ptr->data; |
283 |
|
284 |
p = buf; |
285 |
|
286 |
/* some of these are redundant for the sake of |
287 |
* consistency with cluster{} flags |
288 |
*/ |
289 |
*p++ = 'c'; |
290 |
flags_to_ascii(conf->action /* XXX XXX */, shared_bit_table, p, 0); |
291 |
|
292 |
sendto_one(source_p, form_str(RPL_STATSULINE), |
293 |
me.name, source_p->name, conf->name, |
294 |
conf->user?conf->user: "*", |
295 |
conf->host?conf->host: "*", buf); |
296 |
} |
297 |
|
298 |
DLINK_FOREACH(ptr, cluster_items.head) |
299 |
{ |
300 |
conf = ptr->data; |
301 |
|
302 |
p = buf; |
303 |
|
304 |
*p++ = 'C'; |
305 |
flags_to_ascii(conf->flags /* XXX XXX */, shared_bit_table, p, 0); |
306 |
|
307 |
sendto_one(source_p, form_str(RPL_STATSULINE), |
308 |
me.name, source_p->name, conf->name, |
309 |
"*", "*", buf); |
310 |
} |
311 |
|
312 |
break; |
313 |
|
314 |
case CONF_OPER: |
315 |
DLINK_FOREACH(ptr, oconf_items.head) |
316 |
{ |
317 |
conf = ptr->data; |
318 |
|
319 |
/* Don't allow non opers to see oper privs */ |
320 |
if (HasUMode(source_p, UMODE_OPER)) |
321 |
sendto_one(source_p, form_str(RPL_STATSOLINE), |
322 |
me.name, source_p->name, 'O', conf->user, conf->host, |
323 |
conf->name, oper_privs_as_string(conf->port), |
324 |
conf->class ? conf->class->name : "<default>"); |
325 |
else |
326 |
sendto_one(source_p, form_str(RPL_STATSOLINE), |
327 |
me.name, source_p->name, 'O', conf->user, conf->host, |
328 |
conf->name, "0", |
329 |
conf->class ? conf->class->name : "<default>"); |
330 |
} |
331 |
break; |
332 |
|
333 |
case CONF_CLASS: |
334 |
DLINK_FOREACH(ptr, class_get_list()->head) |
335 |
{ |
336 |
class = ptr->data; |
337 |
sendto_one(source_p, form_str(RPL_STATSYLINE), |
338 |
me.name, source_p->name, 'Y', |
339 |
class->name, class->ping_freq, |
340 |
class->con_freq, |
341 |
class->max_total, class->max_sendq, |
342 |
class->max_recvq, |
343 |
class->ref_count, |
344 |
class->number_per_cidr, class->cidr_bitlen_ipv4, |
345 |
class->number_per_cidr, class->cidr_bitlen_ipv6, |
346 |
class->active ? "active" : "disabled"); |
347 |
} |
348 |
break; |
349 |
|
350 |
case CONF_SERVICE: |
351 |
DLINK_FOREACH(ptr, service_items.head) |
352 |
{ |
353 |
conf = ptr->data; |
354 |
sendto_one(source_p, form_str(RPL_STATSSERVICE), |
355 |
me.name, source_p->name, 'S', "*", conf->name, 0, 0); |
356 |
} |
357 |
break; |
358 |
|
359 |
case CONF_SERVER: |
360 |
DLINK_FOREACH(ptr, server_items.head) |
361 |
{ |
362 |
p = buf; |
363 |
|
364 |
conf = ptr->data; |
365 |
|
366 |
buf[0] = '\0'; |
367 |
|
368 |
if (IsConfAllowAutoConn(conf)) |
369 |
*p++ = 'A'; |
370 |
if (IsConfSSL(conf)) |
371 |
*p++ = 'S'; |
372 |
if (buf[0] == '\0') |
373 |
*p++ = '*'; |
374 |
|
375 |
*p = '\0'; |
376 |
|
377 |
/* |
378 |
* Allow admins to see actual ips unless hide_server_ips is enabled |
379 |
*/ |
380 |
if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN)) |
381 |
sendto_one(source_p, form_str(RPL_STATSCLINE), |
382 |
me.name, source_p->name, 'C', conf->host, |
383 |
buf, conf->name, conf->port, |
384 |
conf->class ? conf->class->name : "<default>"); |
385 |
else |
386 |
sendto_one(source_p, form_str(RPL_STATSCLINE), |
387 |
me.name, source_p->name, 'C', |
388 |
"*@127.0.0.1", buf, conf->name, conf->port, |
389 |
conf->class ? conf->class->name : "<default>"); |
390 |
} |
391 |
break; |
392 |
|
393 |
case CONF_HUB: |
394 |
DLINK_FOREACH(ptr, server_items.head) |
395 |
{ |
396 |
conf = ptr->data; |
397 |
|
398 |
DLINK_FOREACH(dptr, conf->hub_list.head) |
399 |
sendto_one(source_p, form_str(RPL_STATSHLINE), me.name, |
400 |
source_p->name, 'H', dptr->data, conf->name, 0, "*"); |
401 |
} |
402 |
|
403 |
DLINK_FOREACH(ptr, server_items.head) |
404 |
{ |
405 |
conf = ptr->data; |
406 |
|
407 |
DLINK_FOREACH(dptr, conf->leaf_list.head) |
408 |
sendto_one(source_p, form_str(RPL_STATSLLINE), me.name, |
409 |
source_p->name, 'L', dptr->data, conf->name, 0, "*"); |
410 |
} |
411 |
|
412 |
break; |
413 |
|
414 |
default: |
415 |
break; |
416 |
} |
417 |
} |
418 |
|
419 |
/* check_client() |
420 |
* |
421 |
* inputs - pointer to client |
422 |
* output - 0 = Success |
423 |
* NOT_AUTHORIZED (-1) = Access denied (no I line match) |
424 |
* IRCD_SOCKET_ERROR (-2) = Bad socket. |
425 |
* I_LINE_FULL (-3) = I-line is full |
426 |
* TOO_MANY (-4) = Too many connections from hostname |
427 |
* BANNED_CLIENT (-5) = K-lined |
428 |
* side effects - Ordinary client access check. |
429 |
* Look for conf lines which have the same |
430 |
* status as the flags passed. |
431 |
*/ |
432 |
void * |
433 |
check_client(va_list args) |
434 |
{ |
435 |
struct Client *source_p = va_arg(args, struct Client *); |
436 |
const char *username = va_arg(args, const char *); |
437 |
int i; |
438 |
|
439 |
/* I'm already in big trouble if source_p->localClient is NULL -db */ |
440 |
if ((i = verify_access(source_p, username))) |
441 |
ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]", |
442 |
source_p->name, source_p->sockhost); |
443 |
|
444 |
switch (i) |
445 |
{ |
446 |
case TOO_MANY: |
447 |
sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE, |
448 |
"Too many on IP for %s (%s).", |
449 |
get_client_name(source_p, SHOW_IP), |
450 |
source_p->sockhost); |
451 |
ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.", |
452 |
get_client_name(source_p, SHOW_IP)); |
453 |
++ServerStats.is_ref; |
454 |
exit_client(source_p, &me, "No more connections allowed on that IP"); |
455 |
break; |
456 |
|
457 |
case I_LINE_FULL: |
458 |
sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE, |
459 |
"auth{} block is full for %s (%s).", |
460 |
get_client_name(source_p, SHOW_IP), |
461 |
source_p->sockhost); |
462 |
ilog(LOG_TYPE_IRCD, "Too many connections from %s.", |
463 |
get_client_name(source_p, SHOW_IP)); |
464 |
++ServerStats.is_ref; |
465 |
exit_client(source_p, &me, |
466 |
"No more connections allowed in your connection class"); |
467 |
break; |
468 |
|
469 |
case NOT_AUTHORIZED: |
470 |
++ServerStats.is_ref; |
471 |
/* jdc - lists server name & port connections are on */ |
472 |
/* a purely cosmetical change */ |
473 |
sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE, |
474 |
"Unauthorized client connection from %s [%s] on [%s/%u].", |
475 |
get_client_name(source_p, SHOW_IP), |
476 |
source_p->sockhost, |
477 |
source_p->localClient->listener->name, |
478 |
source_p->localClient->listener->port); |
479 |
ilog(LOG_TYPE_IRCD, |
480 |
"Unauthorized client connection from %s on [%s/%u].", |
481 |
get_client_name(source_p, SHOW_IP), |
482 |
source_p->localClient->listener->name, |
483 |
source_p->localClient->listener->port); |
484 |
|
485 |
exit_client(source_p, &me, "You are not authorized to use this server"); |
486 |
break; |
487 |
|
488 |
case BANNED_CLIENT: |
489 |
exit_client(source_p, &me, "Banned"); |
490 |
++ServerStats.is_ref; |
491 |
break; |
492 |
|
493 |
case 0: |
494 |
default: |
495 |
break; |
496 |
} |
497 |
|
498 |
return (i < 0 ? NULL : source_p); |
499 |
} |
500 |
|
501 |
/* verify_access() |
502 |
* |
503 |
* inputs - pointer to client to verify |
504 |
* - pointer to proposed username |
505 |
* output - 0 if success -'ve if not |
506 |
* side effect - find the first (best) I line to attach. |
507 |
*/ |
508 |
static int |
509 |
verify_access(struct Client *client_p, const char *username) |
510 |
{ |
511 |
struct MaskItem *conf = NULL, *rkconf = NULL; |
512 |
char non_ident[USERLEN + 1] = { '~', '\0' }; |
513 |
const char *uhi[3]; |
514 |
|
515 |
if (IsGotId(client_p)) |
516 |
{ |
517 |
conf = find_address_conf(client_p->host, client_p->username, |
518 |
&client_p->localClient->ip, |
519 |
client_p->localClient->aftype, |
520 |
client_p->localClient->passwd); |
521 |
} |
522 |
else |
523 |
{ |
524 |
strlcpy(non_ident+1, username, sizeof(non_ident)-1); |
525 |
conf = find_address_conf(client_p->host,non_ident, |
526 |
&client_p->localClient->ip, |
527 |
client_p->localClient->aftype, |
528 |
client_p->localClient->passwd); |
529 |
} |
530 |
|
531 |
uhi[0] = IsGotId(client_p) ? client_p->username : non_ident; |
532 |
uhi[1] = client_p->host; |
533 |
uhi[2] = client_p->sockhost; |
534 |
|
535 |
rkconf = find_regexp_kline(uhi); |
536 |
|
537 |
if (conf != NULL) |
538 |
{ |
539 |
if (IsConfClient(conf) && !rkconf) |
540 |
{ |
541 |
if (IsConfRedir(conf)) |
542 |
{ |
543 |
sendto_one(client_p, form_str(RPL_REDIR), |
544 |
me.name, client_p->name, |
545 |
conf->name ? conf->name : "", |
546 |
conf->port); |
547 |
return(NOT_AUTHORIZED); |
548 |
} |
549 |
|
550 |
if (IsConfDoIdentd(conf)) |
551 |
SetNeedId(client_p); |
552 |
|
553 |
/* Thanks for spoof idea amm */ |
554 |
if (IsConfDoSpoofIp(conf)) |
555 |
{ |
556 |
if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf)) |
557 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
558 |
"%s spoofing: %s as %s", |
559 |
client_p->name, client_p->host, conf->name); |
560 |
strlcpy(client_p->host, conf->name, sizeof(client_p->host)); |
561 |
SetIPSpoof(client_p); |
562 |
} |
563 |
|
564 |
return(attach_iline(client_p, conf)); |
565 |
} |
566 |
else if (rkconf || IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf))) |
567 |
{ |
568 |
/* XXX */ |
569 |
conf = rkconf ? rkconf : conf; |
570 |
if (IsConfGline(conf)) |
571 |
sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name, |
572 |
client_p->name); |
573 |
sendto_one(client_p, ":%s NOTICE %s :*** Banned: %s", |
574 |
me.name, client_p->name, conf->reason); |
575 |
return(BANNED_CLIENT); |
576 |
} |
577 |
} |
578 |
|
579 |
return(NOT_AUTHORIZED); |
580 |
} |
581 |
|
582 |
/* attach_iline() |
583 |
* |
584 |
* inputs - client pointer |
585 |
* - conf pointer |
586 |
* output - |
587 |
* side effects - do actual attach |
588 |
*/ |
589 |
static int |
590 |
attach_iline(struct Client *client_p, struct MaskItem *conf) |
591 |
{ |
592 |
// struct MaskItem *conf = NULL; |
593 |
struct ClassItem *class = NULL; |
594 |
struct ip_entry *ip_found; |
595 |
int a_limit_reached = 0; |
596 |
int local = 0, global = 0, ident = 0; |
597 |
|
598 |
ip_found = find_or_add_ip(&client_p->localClient->ip); |
599 |
ip_found->count++; |
600 |
SetIpHash(client_p); |
601 |
|
602 |
if (conf->class == NULL) |
603 |
return NOT_AUTHORIZED; /* If class is missing, this is best */ |
604 |
|
605 |
class = conf->class; |
606 |
|
607 |
count_user_host(client_p->username, client_p->host, |
608 |
&global, &local, &ident); |
609 |
|
610 |
/* XXX blah. go down checking the various silly limits |
611 |
* setting a_limit_reached if any limit is reached. |
612 |
* - Dianora |
613 |
*/ |
614 |
if (class->max_total != 0 && class->ref_count >= class->max_total) |
615 |
a_limit_reached = 1; |
616 |
else if (class->max_perip != 0 && ip_found->count > class->max_perip) |
617 |
a_limit_reached = 1; |
618 |
else if (class->max_local != 0 && local >= class->max_local) |
619 |
a_limit_reached = 1; |
620 |
else if (class->max_global != 0 && global >= class->max_global) |
621 |
a_limit_reached = 1; |
622 |
else if (class->max_ident != 0 && ident >= class->max_ident && |
623 |
client_p->username[0] != '~') |
624 |
a_limit_reached = 1; |
625 |
|
626 |
if (a_limit_reached) |
627 |
{ |
628 |
if (!IsConfExemptLimits(conf)) |
629 |
return TOO_MANY; /* Already at maximum allowed */ |
630 |
|
631 |
sendto_one(client_p, |
632 |
":%s NOTICE %s :*** Your connection class is full, " |
633 |
"but you have exceed_limit = yes;", me.name, client_p->name); |
634 |
} |
635 |
|
636 |
return attach_conf(client_p, conf); |
637 |
} |
638 |
|
639 |
/* init_ip_hash_table() |
640 |
* |
641 |
* inputs - NONE |
642 |
* output - NONE |
643 |
* side effects - allocate memory for ip_entry(s) |
644 |
* - clear the ip hash table |
645 |
*/ |
646 |
void |
647 |
init_ip_hash_table(void) |
648 |
{ |
649 |
ip_entry_heap = BlockHeapCreate("ip", sizeof(struct ip_entry), |
650 |
2 * hard_fdlimit); |
651 |
memset(ip_hash_table, 0, sizeof(ip_hash_table)); |
652 |
} |
653 |
|
654 |
/* find_or_add_ip() |
655 |
* |
656 |
* inputs - pointer to struct irc_ssaddr |
657 |
* output - pointer to a struct ip_entry |
658 |
* side effects - |
659 |
* |
660 |
* If the ip # was not found, a new struct ip_entry is created, and the ip |
661 |
* count set to 0. |
662 |
*/ |
663 |
static struct ip_entry * |
664 |
find_or_add_ip(struct irc_ssaddr *ip_in) |
665 |
{ |
666 |
struct ip_entry *ptr, *newptr; |
667 |
int hash_index = hash_ip(ip_in), res; |
668 |
struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4; |
669 |
#ifdef IPV6 |
670 |
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6; |
671 |
#endif |
672 |
|
673 |
for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next) |
674 |
{ |
675 |
#ifdef IPV6 |
676 |
if (ptr->ip.ss.ss_family != ip_in->ss.ss_family) |
677 |
continue; |
678 |
if (ip_in->ss.ss_family == AF_INET6) |
679 |
{ |
680 |
ptr_v6 = (struct sockaddr_in6 *)&ptr->ip; |
681 |
res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr)); |
682 |
} |
683 |
else |
684 |
#endif |
685 |
{ |
686 |
ptr_v4 = (struct sockaddr_in *)&ptr->ip; |
687 |
res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr)); |
688 |
} |
689 |
if (res == 0) |
690 |
{ |
691 |
/* Found entry already in hash, return it. */ |
692 |
return ptr; |
693 |
} |
694 |
} |
695 |
|
696 |
if (ip_entries_count >= 2 * hard_fdlimit) |
697 |
garbage_collect_ip_entries(); |
698 |
|
699 |
newptr = BlockHeapAlloc(ip_entry_heap); |
700 |
ip_entries_count++; |
701 |
memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr)); |
702 |
|
703 |
newptr->next = ip_hash_table[hash_index]; |
704 |
ip_hash_table[hash_index] = newptr; |
705 |
|
706 |
return newptr; |
707 |
} |
708 |
|
709 |
/* remove_one_ip() |
710 |
* |
711 |
* inputs - unsigned long IP address value |
712 |
* output - NONE |
713 |
* side effects - The ip address given, is looked up in ip hash table |
714 |
* and number of ip#'s for that ip decremented. |
715 |
* If ip # count reaches 0 and has expired, |
716 |
* the struct ip_entry is returned to the ip_entry_heap |
717 |
*/ |
718 |
void |
719 |
remove_one_ip(struct irc_ssaddr *ip_in) |
720 |
{ |
721 |
struct ip_entry *ptr; |
722 |
struct ip_entry *last_ptr = NULL; |
723 |
int hash_index = hash_ip(ip_in), res; |
724 |
struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4; |
725 |
#ifdef IPV6 |
726 |
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6; |
727 |
#endif |
728 |
|
729 |
for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next) |
730 |
{ |
731 |
#ifdef IPV6 |
732 |
if (ptr->ip.ss.ss_family != ip_in->ss.ss_family) |
733 |
continue; |
734 |
if (ip_in->ss.ss_family == AF_INET6) |
735 |
{ |
736 |
ptr_v6 = (struct sockaddr_in6 *)&ptr->ip; |
737 |
res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr)); |
738 |
} |
739 |
else |
740 |
#endif |
741 |
{ |
742 |
ptr_v4 = (struct sockaddr_in *)&ptr->ip; |
743 |
res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr)); |
744 |
} |
745 |
if (res) |
746 |
continue; |
747 |
if (ptr->count > 0) |
748 |
ptr->count--; |
749 |
if (ptr->count == 0 && |
750 |
(CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time) |
751 |
{ |
752 |
if (last_ptr != NULL) |
753 |
last_ptr->next = ptr->next; |
754 |
else |
755 |
ip_hash_table[hash_index] = ptr->next; |
756 |
|
757 |
BlockHeapFree(ip_entry_heap, ptr); |
758 |
ip_entries_count--; |
759 |
return; |
760 |
} |
761 |
last_ptr = ptr; |
762 |
} |
763 |
} |
764 |
|
765 |
/* hash_ip() |
766 |
* |
767 |
* input - pointer to an irc_inaddr |
768 |
* output - integer value used as index into hash table |
769 |
* side effects - hopefully, none |
770 |
*/ |
771 |
static int |
772 |
hash_ip(struct irc_ssaddr *addr) |
773 |
{ |
774 |
if (addr->ss.ss_family == AF_INET) |
775 |
{ |
776 |
struct sockaddr_in *v4 = (struct sockaddr_in *)addr; |
777 |
int hash; |
778 |
uint32_t ip; |
779 |
|
780 |
ip = ntohl(v4->sin_addr.s_addr); |
781 |
hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1); |
782 |
return hash; |
783 |
} |
784 |
#ifdef IPV6 |
785 |
else |
786 |
{ |
787 |
int hash; |
788 |
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr; |
789 |
uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr; |
790 |
|
791 |
hash = ip[0] ^ ip[3]; |
792 |
hash ^= hash >> 16; |
793 |
hash ^= hash >> 8; |
794 |
hash = hash & (IP_HASH_SIZE - 1); |
795 |
return hash; |
796 |
} |
797 |
#else |
798 |
return 0; |
799 |
#endif |
800 |
} |
801 |
|
802 |
/* count_ip_hash() |
803 |
* |
804 |
* inputs - pointer to counter of number of ips hashed |
805 |
* - pointer to memory used for ip hash |
806 |
* output - returned via pointers input |
807 |
* side effects - NONE |
808 |
* |
809 |
* number of hashed ip #'s is counted up, plus the amount of memory |
810 |
* used in the hash. |
811 |
*/ |
812 |
void |
813 |
count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored) |
814 |
{ |
815 |
struct ip_entry *ptr; |
816 |
int i; |
817 |
|
818 |
*number_ips_stored = 0; |
819 |
*mem_ips_stored = 0; |
820 |
|
821 |
for (i = 0; i < IP_HASH_SIZE; i++) |
822 |
{ |
823 |
for (ptr = ip_hash_table[i]; ptr; ptr = ptr->next) |
824 |
{ |
825 |
*number_ips_stored += 1; |
826 |
*mem_ips_stored += sizeof(struct ip_entry); |
827 |
} |
828 |
} |
829 |
} |
830 |
|
831 |
/* garbage_collect_ip_entries() |
832 |
* |
833 |
* input - NONE |
834 |
* output - NONE |
835 |
* side effects - free up all ip entries with no connections |
836 |
*/ |
837 |
static void |
838 |
garbage_collect_ip_entries(void) |
839 |
{ |
840 |
struct ip_entry *ptr; |
841 |
struct ip_entry *last_ptr; |
842 |
struct ip_entry *next_ptr; |
843 |
int i; |
844 |
|
845 |
for (i = 0; i < IP_HASH_SIZE; i++) |
846 |
{ |
847 |
last_ptr = NULL; |
848 |
|
849 |
for (ptr = ip_hash_table[i]; ptr; ptr = next_ptr) |
850 |
{ |
851 |
next_ptr = ptr->next; |
852 |
|
853 |
if (ptr->count == 0 && |
854 |
(CurrentTime - ptr->last_attempt) >= ConfigFileEntry.throttle_time) |
855 |
{ |
856 |
if (last_ptr != NULL) |
857 |
last_ptr->next = ptr->next; |
858 |
else |
859 |
ip_hash_table[i] = ptr->next; |
860 |
BlockHeapFree(ip_entry_heap, ptr); |
861 |
ip_entries_count--; |
862 |
} |
863 |
else |
864 |
last_ptr = ptr; |
865 |
} |
866 |
} |
867 |
} |
868 |
|
869 |
/* detach_conf() |
870 |
* |
871 |
* inputs - pointer to client to detach |
872 |
* - type of conf to detach |
873 |
* output - 0 for success, -1 for failure |
874 |
* side effects - Disassociate configuration from the client. |
875 |
* Also removes a class from the list if marked for deleting. |
876 |
*/ |
877 |
void |
878 |
detach_conf(struct Client *client_p, enum maskitem_type type) |
879 |
{ |
880 |
dlink_node *ptr = NULL, *next_ptr = NULL; |
881 |
struct MaskItem *conf = NULL; |
882 |
|
883 |
DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head) |
884 |
{ |
885 |
conf = ptr->data; |
886 |
|
887 |
if (conf->type & type) |
888 |
{ |
889 |
dlinkDelete(ptr, &client_p->localClient->confs); |
890 |
free_dlink_node(ptr); |
891 |
|
892 |
switch (conf->type) |
893 |
{ |
894 |
case CONF_CLIENT: |
895 |
case CONF_OPER: |
896 |
case CONF_SERVER: |
897 |
assert(conf->clients > 0); |
898 |
|
899 |
assert(conf->class->ref_count > 0); |
900 |
|
901 |
if (conf->type == CONF_CLIENT) |
902 |
remove_from_cidr_check(&client_p->localClient->ip, conf->class); |
903 |
if (--conf->class->ref_count == 0 && conf->class->active == 0) |
904 |
class_free(conf->class); |
905 |
if (--conf->clients == 0 && conf->active == 0) |
906 |
conf_free(conf); |
907 |
|
908 |
break; |
909 |
default: |
910 |
break; |
911 |
} |
912 |
} |
913 |
} |
914 |
} |
915 |
|
916 |
/* attach_conf() |
917 |
* |
918 |
* inputs - client pointer |
919 |
* - conf pointer |
920 |
* output - |
921 |
* side effects - Associate a specific configuration entry to a *local* |
922 |
* client (this is the one which used in accepting the |
923 |
* connection). Note, that this automatically changes the |
924 |
* attachment if there was an old one... |
925 |
*/ |
926 |
int |
927 |
attach_conf(struct Client *client_p, struct MaskItem *conf) |
928 |
{ |
929 |
if (dlinkFind(&client_p->localClient->confs, conf) != NULL) |
930 |
return 1; |
931 |
|
932 |
if (conf->type == CONF_CLIENT) |
933 |
if (cidr_limit_reached(IsConfExemptLimits(conf), |
934 |
&client_p->localClient->ip, conf->class)) |
935 |
return TOO_MANY; /* Already at maximum allowed */ |
936 |
|
937 |
conf->class->ref_count++; |
938 |
conf->clients++; |
939 |
|
940 |
dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs); |
941 |
|
942 |
return 0; |
943 |
} |
944 |
|
945 |
/* attach_connect_block() |
946 |
* |
947 |
* inputs - pointer to server to attach |
948 |
* - name of server |
949 |
* - hostname of server |
950 |
* output - true (1) if both are found, otherwise return false (0) |
951 |
* side effects - find connect block and attach them to connecting client |
952 |
*/ |
953 |
int |
954 |
attach_connect_block(struct Client *client_p, const char *name, |
955 |
const char *host) |
956 |
{ |
957 |
dlink_node *ptr; |
958 |
struct MaskItem *conf = NULL; |
959 |
|
960 |
assert(client_p != NULL); |
961 |
assert(host != NULL); |
962 |
|
963 |
if (client_p == NULL || host == NULL) |
964 |
return 0; |
965 |
|
966 |
DLINK_FOREACH(ptr, server_items.head) |
967 |
{ |
968 |
conf = ptr->data; |
969 |
|
970 |
if (match(conf->name, name) == 0 || match(conf->host, host) == 0) |
971 |
continue; |
972 |
|
973 |
attach_conf(client_p, conf); |
974 |
return -1; |
975 |
} |
976 |
|
977 |
return 0; |
978 |
} |
979 |
|
980 |
/* find_conf_name() |
981 |
* |
982 |
* inputs - pointer to conf link list to search |
983 |
* - pointer to name to find |
984 |
* - int mask of type of conf to find |
985 |
* output - NULL or pointer to conf found |
986 |
* side effects - find a conf entry which matches the name |
987 |
* and has the given mask. |
988 |
*/ |
989 |
struct MaskItem * |
990 |
find_conf_name(dlink_list *list, const char *name, enum maskitem_type type) |
991 |
{ |
992 |
dlink_node *ptr; |
993 |
struct MaskItem* conf; |
994 |
|
995 |
DLINK_FOREACH(ptr, list->head) |
996 |
{ |
997 |
conf = ptr->data; |
998 |
|
999 |
if (conf->type == type) |
1000 |
{ |
1001 |
if (conf->name && (irccmp(conf->name, name) == 0 || |
1002 |
match(conf->name, name))) |
1003 |
return conf; |
1004 |
} |
1005 |
} |
1006 |
|
1007 |
return NULL; |
1008 |
} |
1009 |
|
1010 |
/* map_to_list() |
1011 |
* |
1012 |
* inputs - ConfType conf |
1013 |
* output - pointer to dlink_list to use |
1014 |
* side effects - none |
1015 |
*/ |
1016 |
static dlink_list * |
1017 |
map_to_list(enum maskitem_type type) |
1018 |
{ |
1019 |
switch(type) |
1020 |
{ |
1021 |
case CONF_RXLINE: |
1022 |
return(&rxconf_items); |
1023 |
break; |
1024 |
case CONF_XLINE: |
1025 |
return(&xconf_items); |
1026 |
break; |
1027 |
case CONF_ULINE: |
1028 |
return(&uconf_items); |
1029 |
break; |
1030 |
case CONF_NRESV: |
1031 |
return(&nresv_items); |
1032 |
break; |
1033 |
case CONF_OPER: |
1034 |
return(&oconf_items); |
1035 |
break; |
1036 |
case CONF_SERVER: |
1037 |
return(&server_items); |
1038 |
break; |
1039 |
case CONF_SERVICE: |
1040 |
return(&service_items); |
1041 |
break; |
1042 |
case CONF_CLUSTER: |
1043 |
return(&cluster_items); |
1044 |
break; |
1045 |
default: |
1046 |
return NULL; |
1047 |
} |
1048 |
} |
1049 |
|
1050 |
/* find_matching_name_conf() |
1051 |
* |
1052 |
* inputs - type of link list to look in |
1053 |
* - pointer to name string to find |
1054 |
* - pointer to user |
1055 |
* - pointer to host |
1056 |
* - optional action to match on as well |
1057 |
* output - NULL or pointer to found struct MaskItem |
1058 |
* side effects - looks for a match on name field |
1059 |
*/ |
1060 |
struct MaskItem * |
1061 |
find_matching_name_conf(enum maskitem_type type, const char *name, const char *user, |
1062 |
const char *host, unsigned int action) |
1063 |
{ |
1064 |
dlink_node *ptr=NULL; |
1065 |
struct MaskItem *conf=NULL; |
1066 |
dlink_list *list_p = map_to_list(type); |
1067 |
|
1068 |
switch (type) |
1069 |
{ |
1070 |
#ifdef HAVE_LIBPCRE |
1071 |
case CONF_RXLINE: |
1072 |
DLINK_FOREACH(ptr, list_p->head) |
1073 |
{ |
1074 |
conf = ptr->data; |
1075 |
assert(conf->regexpname); |
1076 |
|
1077 |
if (!ircd_pcre_exec(conf->regexuser, name)) |
1078 |
return conf; |
1079 |
} |
1080 |
break; |
1081 |
#endif |
1082 |
case CONF_SERVICE: |
1083 |
DLINK_FOREACH(ptr, list_p->head) |
1084 |
{ |
1085 |
conf = ptr->data; |
1086 |
|
1087 |
if (EmptyString(conf->name)) |
1088 |
continue; |
1089 |
if ((name != NULL) && !irccmp(name, conf->name)) |
1090 |
return conf; |
1091 |
} |
1092 |
break; |
1093 |
|
1094 |
case CONF_XLINE: |
1095 |
case CONF_ULINE: |
1096 |
case CONF_NRESV: |
1097 |
DLINK_FOREACH(ptr, list_p->head) |
1098 |
{ |
1099 |
conf = ptr->data; |
1100 |
|
1101 |
if (EmptyString(conf->name)) |
1102 |
continue; |
1103 |
if ((name != NULL) && match_esc(conf->name, name)) |
1104 |
{ |
1105 |
if ((user == NULL && (host == NULL))) |
1106 |
return conf; |
1107 |
if ((conf->action & action) != action) |
1108 |
continue; |
1109 |
if (EmptyString(conf->user) || EmptyString(conf->host)) |
1110 |
return conf; |
1111 |
if (match(conf->user, user) && match(conf->host, host)) |
1112 |
return conf; |
1113 |
} |
1114 |
} |
1115 |
break; |
1116 |
|
1117 |
case CONF_SERVER: |
1118 |
DLINK_FOREACH(ptr, list_p->head) |
1119 |
{ |
1120 |
conf = ptr->data; |
1121 |
|
1122 |
if ((name != NULL) && match(name, conf->name)) |
1123 |
return conf; |
1124 |
else if ((host != NULL) && match(host, conf->host)) |
1125 |
return conf; |
1126 |
} |
1127 |
break; |
1128 |
|
1129 |
default: |
1130 |
break; |
1131 |
} |
1132 |
return NULL; |
1133 |
} |
1134 |
|
1135 |
/* find_exact_name_conf() |
1136 |
* |
1137 |
* inputs - type of link list to look in |
1138 |
* - pointer to name string to find |
1139 |
* - pointer to user |
1140 |
* - pointer to host |
1141 |
* output - NULL or pointer to found struct MaskItem |
1142 |
* side effects - looks for an exact match on name field |
1143 |
*/ |
1144 |
struct MaskItem * |
1145 |
find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name, |
1146 |
const char *user, const char *host) |
1147 |
{ |
1148 |
dlink_node *ptr = NULL; |
1149 |
struct MaskItem *conf; |
1150 |
dlink_list *list_p = map_to_list(type); |
1151 |
|
1152 |
switch(type) |
1153 |
{ |
1154 |
case CONF_RXLINE: |
1155 |
case CONF_XLINE: |
1156 |
case CONF_ULINE: |
1157 |
case CONF_NRESV: |
1158 |
|
1159 |
DLINK_FOREACH(ptr, list_p->head) |
1160 |
{ |
1161 |
conf = ptr->data; |
1162 |
|
1163 |
if (EmptyString(conf->name)) |
1164 |
continue; |
1165 |
|
1166 |
if (irccmp(conf->name, name) == 0) |
1167 |
{ |
1168 |
if ((user == NULL && (host == NULL))) |
1169 |
return (conf); |
1170 |
if (EmptyString(conf->user) || EmptyString(conf->host)) |
1171 |
return (conf); |
1172 |
if (match(conf->user, user) && match(conf->host, host)) |
1173 |
return (conf); |
1174 |
} |
1175 |
} |
1176 |
break; |
1177 |
|
1178 |
case CONF_OPER: |
1179 |
DLINK_FOREACH(ptr, list_p->head) |
1180 |
{ |
1181 |
conf = ptr->data; |
1182 |
|
1183 |
if (EmptyString(conf->name)) |
1184 |
continue; |
1185 |
|
1186 |
if (!irccmp(conf->name, name)) |
1187 |
{ |
1188 |
if (!who) |
1189 |
return conf; |
1190 |
if (EmptyString(conf->user) || EmptyString(conf->host)) |
1191 |
return NULL; |
1192 |
if (match(conf->user, who->username)) |
1193 |
{ |
1194 |
switch (conf->htype) |
1195 |
{ |
1196 |
case HM_HOST: |
1197 |
if (match(conf->host, who->host) || match(conf->host, who->sockhost)) |
1198 |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
1199 |
return conf; |
1200 |
break; |
1201 |
case HM_IPV4: |
1202 |
if (who->localClient->aftype == AF_INET) |
1203 |
if (match_ipv4(&who->localClient->ip, &conf->addr, conf->bits)) |
1204 |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
1205 |
return conf; |
1206 |
break; |
1207 |
#ifdef IPV6 |
1208 |
case HM_IPV6: |
1209 |
if (who->localClient->aftype == AF_INET6) |
1210 |
if (match_ipv6(&who->localClient->ip, &conf->addr, conf->bits)) |
1211 |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
1212 |
return conf; |
1213 |
break; |
1214 |
#endif |
1215 |
default: |
1216 |
assert(0); |
1217 |
} |
1218 |
} |
1219 |
} |
1220 |
} |
1221 |
|
1222 |
break; |
1223 |
|
1224 |
case CONF_SERVER: |
1225 |
DLINK_FOREACH(ptr, list_p->head) |
1226 |
{ |
1227 |
conf = ptr->data; |
1228 |
|
1229 |
if (EmptyString(conf->name)) |
1230 |
continue; |
1231 |
|
1232 |
if (name == NULL) |
1233 |
{ |
1234 |
if (EmptyString(conf->host)) |
1235 |
continue; |
1236 |
if (irccmp(conf->host, host) == 0) |
1237 |
return(conf); |
1238 |
} |
1239 |
else if (irccmp(conf->name, name) == 0) |
1240 |
{ |
1241 |
return (conf); |
1242 |
} |
1243 |
} |
1244 |
break; |
1245 |
|
1246 |
default: |
1247 |
break; |
1248 |
} |
1249 |
return(NULL); |
1250 |
} |
1251 |
|
1252 |
/* rehash() |
1253 |
* |
1254 |
* Actual REHASH service routine. Called with sig == 0 if it has been called |
1255 |
* as a result of an operator issuing this command, else assume it has been |
1256 |
* called as a result of the server receiving a HUP signal. |
1257 |
*/ |
1258 |
int |
1259 |
rehash(int sig) |
1260 |
{ |
1261 |
if (sig != 0) |
1262 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1263 |
"Got signal SIGHUP, reloading ircd.conf file"); |
1264 |
|
1265 |
restart_resolver(); |
1266 |
|
1267 |
/* don't close listeners until we know we can go ahead with the rehash */ |
1268 |
|
1269 |
/* Check to see if we magically got(or lost) IPv6 support */ |
1270 |
check_can_use_v6(); |
1271 |
|
1272 |
read_conf_files(0); |
1273 |
|
1274 |
if (ServerInfo.description != NULL) |
1275 |
strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
1276 |
|
1277 |
load_conf_modules(); |
1278 |
|
1279 |
rehashed_klines = 1; |
1280 |
/* XXX */ |
1281 |
if (ConfigLoggingEntry.use_logging) |
1282 |
log_close_all(); |
1283 |
|
1284 |
return(0); |
1285 |
} |
1286 |
|
1287 |
/* set_default_conf() |
1288 |
* |
1289 |
* inputs - NONE |
1290 |
* output - NONE |
1291 |
* side effects - Set default values here. |
1292 |
* This is called **PRIOR** to parsing the |
1293 |
* configuration file. If you want to do some validation |
1294 |
* of values later, put them in validate_conf(). |
1295 |
*/ |
1296 |
static void |
1297 |
set_default_conf(void) |
1298 |
{ |
1299 |
/* verify init_class() ran, this should be an unnecessary check |
1300 |
* but its not much work. |
1301 |
*/ |
1302 |
assert(class_default == class_items.tail->data); |
1303 |
|
1304 |
#ifdef HAVE_LIBCRYPTO |
1305 |
ServerInfo.rsa_private_key = NULL; |
1306 |
ServerInfo.rsa_private_key_file = NULL; |
1307 |
#endif |
1308 |
|
1309 |
/* ServerInfo.name is not rehashable */ |
1310 |
/* ServerInfo.name = ServerInfo.name; */ |
1311 |
ServerInfo.description = NULL; |
1312 |
DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT); |
1313 |
DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT); |
1314 |
|
1315 |
memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip)); |
1316 |
ServerInfo.specific_ipv4_vhost = 0; |
1317 |
memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6)); |
1318 |
ServerInfo.specific_ipv6_vhost = 0; |
1319 |
|
1320 |
ServerInfo.max_clients = MAXCLIENTS_MAX; |
1321 |
|
1322 |
ServerInfo.hub = 0; |
1323 |
ServerInfo.dns_host.sin_addr.s_addr = 0; |
1324 |
ServerInfo.dns_host.sin_port = 0; |
1325 |
AdminInfo.name = NULL; |
1326 |
AdminInfo.email = NULL; |
1327 |
AdminInfo.description = NULL; |
1328 |
|
1329 |
log_close_all(); |
1330 |
|
1331 |
ConfigLoggingEntry.use_logging = 1; |
1332 |
|
1333 |
ConfigChannel.disable_fake_channels = 0; |
1334 |
ConfigChannel.restrict_channels = 0; |
1335 |
ConfigChannel.knock_delay = 300; |
1336 |
ConfigChannel.knock_delay_channel = 60; |
1337 |
ConfigChannel.max_chans_per_user = 25; |
1338 |
ConfigChannel.max_chans_per_oper = 50; |
1339 |
ConfigChannel.quiet_on_ban = 1; |
1340 |
ConfigChannel.max_bans = 25; |
1341 |
ConfigChannel.default_split_user_count = 0; |
1342 |
ConfigChannel.default_split_server_count = 0; |
1343 |
ConfigChannel.no_join_on_split = 0; |
1344 |
ConfigChannel.no_create_on_split = 0; |
1345 |
|
1346 |
ConfigServerHide.flatten_links = 0; |
1347 |
ConfigServerHide.links_delay = 300; |
1348 |
ConfigServerHide.hidden = 0; |
1349 |
ConfigServerHide.hide_servers = 0; |
1350 |
DupString(ConfigServerHide.hidden_name, NETWORK_NAME_DEFAULT); |
1351 |
ConfigServerHide.hide_server_ips = 0; |
1352 |
|
1353 |
|
1354 |
DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT); |
1355 |
ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT; |
1356 |
ConfigFileEntry.glines = 0; |
1357 |
ConfigFileEntry.gline_time = 12 * 3600; |
1358 |
ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT; |
1359 |
ConfigFileEntry.gline_min_cidr = 16; |
1360 |
ConfigFileEntry.gline_min_cidr6 = 48; |
1361 |
ConfigFileEntry.invisible_on_connect = 1; |
1362 |
ConfigFileEntry.tkline_expire_notices = 1; |
1363 |
ConfigFileEntry.hide_spoof_ips = 1; |
1364 |
ConfigFileEntry.ignore_bogus_ts = 0; |
1365 |
ConfigFileEntry.disable_auth = 0; |
1366 |
ConfigFileEntry.disable_remote = 0; |
1367 |
ConfigFileEntry.kill_chase_time_limit = 90; |
1368 |
ConfigFileEntry.default_floodcount = 8; |
1369 |
ConfigFileEntry.failed_oper_notice = 1; |
1370 |
ConfigFileEntry.dots_in_ident = 0; |
1371 |
ConfigFileEntry.min_nonwildcard = 4; |
1372 |
ConfigFileEntry.min_nonwildcard_simple = 3; |
1373 |
ConfigFileEntry.max_accept = 20; |
1374 |
ConfigFileEntry.anti_nick_flood = 0; |
1375 |
ConfigFileEntry.max_nick_time = 20; |
1376 |
ConfigFileEntry.max_nick_changes = 5; |
1377 |
ConfigFileEntry.anti_spam_exit_message_time = 0; |
1378 |
ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; |
1379 |
ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; |
1380 |
ConfigFileEntry.warn_no_nline = 1; |
1381 |
ConfigFileEntry.stats_o_oper_only = 0; |
1382 |
ConfigFileEntry.stats_k_oper_only = 1; /* masked */ |
1383 |
ConfigFileEntry.stats_i_oper_only = 1; /* masked */ |
1384 |
ConfigFileEntry.stats_P_oper_only = 0; |
1385 |
ConfigFileEntry.caller_id_wait = 60; |
1386 |
ConfigFileEntry.opers_bypass_callerid = 0; |
1387 |
ConfigFileEntry.pace_wait = 10; |
1388 |
ConfigFileEntry.pace_wait_simple = 1; |
1389 |
ConfigFileEntry.short_motd = 0; |
1390 |
ConfigFileEntry.ping_cookie = 0; |
1391 |
ConfigFileEntry.no_oper_flood = 0; |
1392 |
ConfigFileEntry.true_no_oper_flood = 0; |
1393 |
ConfigFileEntry.oper_pass_resv = 1; |
1394 |
ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT; |
1395 |
ConfigFileEntry.oper_only_umodes = UMODE_DEBUG; |
1396 |
ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | |
1397 |
UMODE_OPERWALL | UMODE_WALLOP; |
1398 |
ConfigFileEntry.use_egd = 0; |
1399 |
ConfigFileEntry.egdpool_path = NULL; |
1400 |
ConfigFileEntry.throttle_time = 10; |
1401 |
} |
1402 |
|
1403 |
static void |
1404 |
validate_conf(void) |
1405 |
{ |
1406 |
if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN) |
1407 |
ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; |
1408 |
|
1409 |
if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN) |
1410 |
ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; |
1411 |
|
1412 |
if (ServerInfo.network_name == NULL) |
1413 |
DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT); |
1414 |
|
1415 |
if (ServerInfo.network_desc == NULL) |
1416 |
DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT); |
1417 |
|
1418 |
if (ConfigFileEntry.service_name == NULL) |
1419 |
DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT); |
1420 |
|
1421 |
ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN); |
1422 |
} |
1423 |
|
1424 |
/* read_conf() |
1425 |
* |
1426 |
* inputs - file descriptor pointing to config file to use |
1427 |
* output - None |
1428 |
* side effects - Read configuration file. |
1429 |
*/ |
1430 |
static void |
1431 |
read_conf(FILE *file) |
1432 |
{ |
1433 |
lineno = 0; |
1434 |
|
1435 |
set_default_conf(); /* Set default values prior to conf parsing */ |
1436 |
conf_parser_ctx.pass = 1; |
1437 |
yyparse(); /* pick up the classes first */ |
1438 |
|
1439 |
rewind(file); |
1440 |
|
1441 |
conf_parser_ctx.pass = 2; |
1442 |
yyparse(); /* Load the values from the conf */ |
1443 |
validate_conf(); /* Check to make sure some values are still okay. */ |
1444 |
/* Some global values are also loaded here. */ |
1445 |
class_delete_marked(); /* Make sure classes are valid */ |
1446 |
} |
1447 |
|
1448 |
/* lookup_confhost() |
1449 |
* |
1450 |
* start DNS lookups of all hostnames in the conf |
1451 |
* line and convert an IP addresses in a.b.c.d number for to IP#s. |
1452 |
*/ |
1453 |
static void |
1454 |
lookup_confhost(struct MaskItem *conf) |
1455 |
{ |
1456 |
struct addrinfo hints, *res; |
1457 |
|
1458 |
if (has_wildcards(conf->host)) |
1459 |
{ |
1460 |
ilog(LOG_TYPE_IRCD, "Host/server name error: (%s) (%s)", |
1461 |
conf->host, conf->name); |
1462 |
return; |
1463 |
} |
1464 |
|
1465 |
/* Do name lookup now on hostnames given and store the |
1466 |
* ip numbers in conf structure. |
1467 |
*/ |
1468 |
memset(&hints, 0, sizeof(hints)); |
1469 |
|
1470 |
hints.ai_family = AF_UNSPEC; |
1471 |
hints.ai_socktype = SOCK_STREAM; |
1472 |
|
1473 |
/* Get us ready for a bind() and don't bother doing dns lookup */ |
1474 |
hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; |
1475 |
|
1476 |
if (getaddrinfo(conf->host, NULL, &hints, &res)) |
1477 |
{ |
1478 |
conf_dns_lookup(conf); |
1479 |
return; |
1480 |
} |
1481 |
|
1482 |
assert(res != NULL); |
1483 |
|
1484 |
memcpy(&conf->addr, res->ai_addr, res->ai_addrlen); |
1485 |
conf->addr.ss_len = res->ai_addrlen; |
1486 |
conf->addr.ss.ss_family = res->ai_family; |
1487 |
|
1488 |
freeaddrinfo(res); |
1489 |
} |
1490 |
|
1491 |
/* conf_connect_allowed() |
1492 |
* |
1493 |
* inputs - pointer to inaddr |
1494 |
* - int type ipv4 or ipv6 |
1495 |
* output - BANNED or accepted |
1496 |
* side effects - none |
1497 |
*/ |
1498 |
int |
1499 |
conf_connect_allowed(struct irc_ssaddr *addr, int aftype) |
1500 |
{ |
1501 |
struct ip_entry *ip_found; |
1502 |
struct MaskItem *conf = find_dline_conf(addr, aftype); |
1503 |
|
1504 |
/* DLINE exempt also gets you out of static limits/pacing... */ |
1505 |
if (conf && (conf->type == CONF_EXEMPT)) |
1506 |
return 0; |
1507 |
|
1508 |
if (conf != NULL) |
1509 |
return BANNED_CLIENT; |
1510 |
|
1511 |
ip_found = find_or_add_ip(addr); |
1512 |
|
1513 |
if ((CurrentTime - ip_found->last_attempt) < |
1514 |
ConfigFileEntry.throttle_time) |
1515 |
{ |
1516 |
ip_found->last_attempt = CurrentTime; |
1517 |
return TOO_FAST; |
1518 |
} |
1519 |
|
1520 |
ip_found->last_attempt = CurrentTime; |
1521 |
return 0; |
1522 |
} |
1523 |
|
1524 |
static struct MaskItem * |
1525 |
find_regexp_kline(const char *uhi[]) |
1526 |
{ |
1527 |
#ifdef HAVE_LIBPCRE |
1528 |
const dlink_node *ptr = NULL; |
1529 |
|
1530 |
DLINK_FOREACH(ptr, rkconf_items.head) |
1531 |
{ |
1532 |
struct MaskItem *aptr = ptr->data; |
1533 |
|
1534 |
assert(aptr->regexuser); |
1535 |
assert(aptr->regexhost); |
1536 |
|
1537 |
if (!ircd_pcre_exec(aptr->regexuser, uhi[0]) && |
1538 |
(!ircd_pcre_exec(aptr->regexhost, uhi[1]) || |
1539 |
!ircd_pcre_exec(aptr->regexhost, uhi[2]))) |
1540 |
return aptr; |
1541 |
} |
1542 |
#endif |
1543 |
return NULL; |
1544 |
} |
1545 |
|
1546 |
/* find_kill() |
1547 |
* |
1548 |
* inputs - pointer to client structure |
1549 |
* output - pointer to struct MaskItem if found |
1550 |
* side effects - See if this user is klined already, |
1551 |
* and if so, return struct MaskItem pointer |
1552 |
*/ |
1553 |
struct MaskItem * |
1554 |
find_kill(struct Client *client_p) |
1555 |
{ |
1556 |
struct MaskItem *conf = NULL; |
1557 |
const char *uhi[3]; |
1558 |
|
1559 |
uhi[0] = client_p->username; |
1560 |
uhi[1] = client_p->host; |
1561 |
uhi[2] = client_p->sockhost; |
1562 |
|
1563 |
assert(client_p != NULL); |
1564 |
|
1565 |
conf = find_conf_by_address(client_p->host, &client_p->localClient->ip, |
1566 |
CONF_KLINE, client_p->localClient->aftype, |
1567 |
client_p->username, NULL, 1); |
1568 |
if (conf == NULL) |
1569 |
conf = find_regexp_kline(uhi); |
1570 |
|
1571 |
return conf; |
1572 |
} |
1573 |
|
1574 |
struct MaskItem * |
1575 |
find_gline(struct Client *client_p) |
1576 |
{ |
1577 |
struct MaskItem *conf; |
1578 |
|
1579 |
assert(client_p != NULL); |
1580 |
|
1581 |
conf = find_conf_by_address(client_p->host, &client_p->localClient->ip, |
1582 |
CONF_GLINE, client_p->localClient->aftype, |
1583 |
client_p->username, NULL, 1); |
1584 |
return conf; |
1585 |
} |
1586 |
|
1587 |
/* cleanup_tklines() |
1588 |
* |
1589 |
* inputs - NONE |
1590 |
* output - NONE |
1591 |
* side effects - call function to expire temporary k/d lines |
1592 |
* This is an event started off in ircd.c |
1593 |
*/ |
1594 |
void |
1595 |
cleanup_tklines(void *notused) |
1596 |
{ |
1597 |
hostmask_expire_temporary(); |
1598 |
expire_tklines(&xconf_items); |
1599 |
expire_tklines(&nresv_items); |
1600 |
expire_tklines(&resv_channel_list); |
1601 |
} |
1602 |
|
1603 |
/* expire_tklines() |
1604 |
* |
1605 |
* inputs - tkline list pointer |
1606 |
* output - NONE |
1607 |
* side effects - expire tklines |
1608 |
*/ |
1609 |
static void |
1610 |
expire_tklines(dlink_list *tklist) |
1611 |
{ |
1612 |
dlink_node *ptr; |
1613 |
dlink_node *next_ptr; |
1614 |
struct MaskItem *conf; |
1615 |
|
1616 |
DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head) |
1617 |
{ |
1618 |
conf = ptr->data; |
1619 |
|
1620 |
if (conf->type == CONF_XLINE) |
1621 |
{ |
1622 |
if (conf->hold && conf->hold <= CurrentTime) |
1623 |
{ |
1624 |
if (ConfigFileEntry.tkline_expire_notices) |
1625 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1626 |
"Temporary X-line for [%s] expired", conf->name); |
1627 |
conf_free(conf); |
1628 |
} |
1629 |
} |
1630 |
else if (conf->type == CONF_NRESV) |
1631 |
{ |
1632 |
if (conf->hold && conf->hold <= CurrentTime) |
1633 |
{ |
1634 |
if (ConfigFileEntry.tkline_expire_notices) |
1635 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1636 |
"Temporary RESV for [%s] expired", conf->name); |
1637 |
conf_free(conf); |
1638 |
} |
1639 |
} |
1640 |
else if (conf->type == CONF_CRESV) |
1641 |
{ /* XXX XXX */ |
1642 |
if (conf->hold && conf->hold <= CurrentTime) |
1643 |
{ |
1644 |
if (ConfigFileEntry.tkline_expire_notices) |
1645 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1646 |
"Temporary RESV for [%s] expired", conf->name); |
1647 |
delete_channel_resv(conf); |
1648 |
} |
1649 |
} |
1650 |
} |
1651 |
} |
1652 |
|
1653 |
/* oper_privs_as_string() |
1654 |
* |
1655 |
* inputs - pointer to client_p |
1656 |
* output - pointer to static string showing oper privs |
1657 |
* side effects - return as string, the oper privs as derived from port |
1658 |
*/ |
1659 |
static const struct oper_privs |
1660 |
{ |
1661 |
const unsigned int oprivs; |
1662 |
const unsigned char c; |
1663 |
} flag_list[] = { |
1664 |
{ OPER_FLAG_ADMIN, 'A' }, |
1665 |
{ OPER_FLAG_REMOTEBAN, 'B' }, |
1666 |
{ OPER_FLAG_DIE, 'D' }, |
1667 |
{ OPER_FLAG_GLINE, 'G' }, |
1668 |
{ OPER_FLAG_REHASH, 'H' }, |
1669 |
{ OPER_FLAG_K, 'K' }, |
1670 |
{ OPER_FLAG_OPERWALL, 'L' }, |
1671 |
{ OPER_FLAG_N, 'N' }, |
1672 |
{ OPER_FLAG_GLOBAL_KILL, 'O' }, |
1673 |
{ OPER_FLAG_REMOTE, 'R' }, |
1674 |
{ OPER_FLAG_OPER_SPY, 'S' }, |
1675 |
{ OPER_FLAG_UNKLINE, 'U' }, |
1676 |
{ OPER_FLAG_X, 'X' }, |
1677 |
{ 0, '\0' } |
1678 |
}; |
1679 |
|
1680 |
char * |
1681 |
oper_privs_as_string(const unsigned int port) |
1682 |
{ |
1683 |
static char privs_out[16]; |
1684 |
char *privs_ptr = privs_out; |
1685 |
unsigned int i = 0; |
1686 |
|
1687 |
for (; flag_list[i].oprivs; ++i) |
1688 |
{ |
1689 |
if (port & flag_list[i].oprivs) |
1690 |
*privs_ptr++ = flag_list[i].c; |
1691 |
else |
1692 |
*privs_ptr++ = ToLowerTab[flag_list[i].c]; |
1693 |
} |
1694 |
|
1695 |
*privs_ptr = '\0'; |
1696 |
|
1697 |
return privs_out; |
1698 |
} |
1699 |
|
1700 |
/* |
1701 |
* Input: A client to find the active oper{} name for. |
1702 |
* Output: The nick!user@host{oper} of the oper. |
1703 |
* "oper" is server name for remote opers |
1704 |
* Side effects: None. |
1705 |
*/ |
1706 |
const char * |
1707 |
get_oper_name(const struct Client *client_p) |
1708 |
{ |
1709 |
dlink_node *cnode = NULL; |
1710 |
/* +5 for !,@,{,} and null */ |
1711 |
static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5]; |
1712 |
|
1713 |
if (MyConnect(client_p)) |
1714 |
{ |
1715 |
if ((cnode = client_p->localClient->confs.head)) |
1716 |
{ |
1717 |
struct MaskItem *conf = cnode->data; |
1718 |
|
1719 |
if (IsConfOperator(conf)) |
1720 |
{ |
1721 |
snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name, |
1722 |
client_p->username, client_p->host, conf->name); |
1723 |
return buffer; |
1724 |
} |
1725 |
} |
1726 |
|
1727 |
/* Probably should assert here for now. If there is an oper out there |
1728 |
* with no oper{} conf attached, it would be good for us to know... |
1729 |
*/ |
1730 |
assert(0); /* Oper without oper conf! */ |
1731 |
} |
1732 |
|
1733 |
snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name, |
1734 |
client_p->username, client_p->host, client_p->servptr->name); |
1735 |
return buffer; |
1736 |
} |
1737 |
|
1738 |
/* read_conf_files() |
1739 |
* |
1740 |
* inputs - cold start YES or NO |
1741 |
* output - none |
1742 |
* side effects - read all conf files needed, ircd.conf kline.conf etc. |
1743 |
*/ |
1744 |
void |
1745 |
read_conf_files(int cold) |
1746 |
{ |
1747 |
const char *filename; |
1748 |
char chanmodes[32]; |
1749 |
char chanlimit[32]; |
1750 |
|
1751 |
conf_parser_ctx.boot = cold; |
1752 |
filename = ConfigFileEntry.configfile; |
1753 |
|
1754 |
/* We need to know the initial filename for the yyerror() to report |
1755 |
FIXME: The full path is in conffilenamebuf first time since we |
1756 |
dont know anything else |
1757 |
|
1758 |
- Gozem 2002-07-21 |
1759 |
*/ |
1760 |
strlcpy(conffilebuf, filename, sizeof(conffilebuf)); |
1761 |
|
1762 |
if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL) |
1763 |
{ |
1764 |
if (cold) |
1765 |
{ |
1766 |
ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s", |
1767 |
filename, strerror(errno)); |
1768 |
exit(-1); |
1769 |
} |
1770 |
else |
1771 |
{ |
1772 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1773 |
"Unable to read configuration file '%s': %s", |
1774 |
filename, strerror(errno)); |
1775 |
return; |
1776 |
} |
1777 |
} |
1778 |
|
1779 |
if (!cold) |
1780 |
clear_out_old_conf(); |
1781 |
|
1782 |
read_conf(conf_parser_ctx.conf_file); |
1783 |
fclose(conf_parser_ctx.conf_file); |
1784 |
|
1785 |
add_isupport("NETWORK", ServerInfo.network_name, -1); |
1786 |
snprintf(chanmodes, sizeof(chanmodes), "beI:%d", |
1787 |
ConfigChannel.max_bans); |
1788 |
add_isupport("MAXLIST", chanmodes, -1); |
1789 |
add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets); |
1790 |
|
1791 |
add_isupport("CHANTYPES", "#", -1); |
1792 |
|
1793 |
snprintf(chanlimit, sizeof(chanlimit), "#:%d", |
1794 |
ConfigChannel.max_chans_per_user); |
1795 |
add_isupport("CHANLIMIT", chanlimit, -1); |
1796 |
snprintf(chanmodes, sizeof(chanmodes), "%s", |
1797 |
"beI,k,l,imnprstORS"); |
1798 |
add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN); |
1799 |
|
1800 |
add_isupport("EXCEPTS", "e", -1); |
1801 |
add_isupport("INVEX", "I", -1); |
1802 |
add_isupport("CHANMODES", chanmodes, -1); |
1803 |
|
1804 |
/* |
1805 |
* message_locale may have changed. rebuild isupport since it relies |
1806 |
* on strlen(form_str(RPL_ISUPPORT)) |
1807 |
*/ |
1808 |
rebuild_isupport_message_line(); |
1809 |
} |
1810 |
|
1811 |
/* clear_out_old_conf() |
1812 |
* |
1813 |
* inputs - none |
1814 |
* output - none |
1815 |
* side effects - Clear out the old configuration |
1816 |
*/ |
1817 |
static void |
1818 |
clear_out_old_conf(void) |
1819 |
{ |
1820 |
dlink_node *ptr = NULL, *next_ptr = NULL; |
1821 |
struct MaskItem *conf; |
1822 |
dlink_list *free_items [] = { |
1823 |
&server_items, &oconf_items, |
1824 |
&uconf_items, &xconf_items, &rxconf_items, &rkconf_items, |
1825 |
&nresv_items, &cluster_items, &service_items, NULL |
1826 |
}; |
1827 |
|
1828 |
dlink_list ** iterator = free_items; /* C is dumb */ |
1829 |
|
1830 |
/* We only need to free anything allocated by yyparse() here. |
1831 |
* Resetting structs, etc, is taken care of by set_default_conf(). |
1832 |
*/ |
1833 |
|
1834 |
for (; *iterator != NULL; iterator++) |
1835 |
{ |
1836 |
DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head) |
1837 |
{ |
1838 |
conf = ptr->data; |
1839 |
|
1840 |
dlinkDelete(&conf->node, map_to_list(conf->type)); |
1841 |
|
1842 |
/* XXX This is less than pretty */ |
1843 |
if (conf->type == CONF_SERVER || conf->type == CONF_OPER) |
1844 |
{ |
1845 |
if (!conf->clients) |
1846 |
conf_free(conf); |
1847 |
} |
1848 |
else if (conf->type == CONF_XLINE || |
1849 |
conf->type == CONF_RXLINE || |
1850 |
conf->type == CONF_RKLINE) |
1851 |
{ |
1852 |
if (!conf->hold) |
1853 |
conf_free(conf); |
1854 |
} |
1855 |
else |
1856 |
conf_free(conf); |
1857 |
} |
1858 |
} |
1859 |
|
1860 |
/* |
1861 |
* don't delete the class table, rather mark all entries |
1862 |
* for deletion. The table is cleaned up by class_delete_marked. - avalon |
1863 |
*/ |
1864 |
class_mark_for_deletion(); |
1865 |
|
1866 |
clear_out_address_conf(); |
1867 |
|
1868 |
/* clean out module paths */ |
1869 |
mod_clear_paths(); |
1870 |
|
1871 |
/* clean out ServerInfo */ |
1872 |
MyFree(ServerInfo.description); |
1873 |
ServerInfo.description = NULL; |
1874 |
MyFree(ServerInfo.network_name); |
1875 |
ServerInfo.network_name = NULL; |
1876 |
MyFree(ServerInfo.network_desc); |
1877 |
ServerInfo.network_desc = NULL; |
1878 |
MyFree(ConfigFileEntry.egdpool_path); |
1879 |
ConfigFileEntry.egdpool_path = NULL; |
1880 |
#ifdef HAVE_LIBCRYPTO |
1881 |
if (ServerInfo.rsa_private_key != NULL) |
1882 |
{ |
1883 |
RSA_free(ServerInfo.rsa_private_key); |
1884 |
ServerInfo.rsa_private_key = NULL; |
1885 |
} |
1886 |
|
1887 |
MyFree(ServerInfo.rsa_private_key_file); |
1888 |
ServerInfo.rsa_private_key_file = NULL; |
1889 |
|
1890 |
if (ServerInfo.server_ctx) |
1891 |
SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2| |
1892 |
SSL_OP_NO_SSLv3| |
1893 |
SSL_OP_NO_TLSv1); |
1894 |
if (ServerInfo.client_ctx) |
1895 |
SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2| |
1896 |
SSL_OP_NO_SSLv3| |
1897 |
SSL_OP_NO_TLSv1); |
1898 |
#endif |
1899 |
|
1900 |
/* clean out old resvs from the conf */ |
1901 |
clear_conf_resv(); |
1902 |
|
1903 |
/* clean out AdminInfo */ |
1904 |
MyFree(AdminInfo.name); |
1905 |
AdminInfo.name = NULL; |
1906 |
MyFree(AdminInfo.email); |
1907 |
AdminInfo.email = NULL; |
1908 |
MyFree(AdminInfo.description); |
1909 |
AdminInfo.description = NULL; |
1910 |
|
1911 |
/* operator{} and class{} blocks are freed above */ |
1912 |
/* clean out listeners */ |
1913 |
close_listeners(); |
1914 |
|
1915 |
/* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, |
1916 |
* exempt{} and gecos{} blocks are freed above too |
1917 |
*/ |
1918 |
|
1919 |
/* clean out general */ |
1920 |
MyFree(ConfigFileEntry.service_name); |
1921 |
ConfigFileEntry.service_name = NULL; |
1922 |
|
1923 |
delete_isupport("INVEX"); |
1924 |
delete_isupport("EXCEPTS"); |
1925 |
} |
1926 |
|
1927 |
#define BAD_PING (-1) |
1928 |
|
1929 |
/* get_conf_ping() |
1930 |
* |
1931 |
* inputs - pointer to struct MaskItem |
1932 |
* - pointer to a variable that receives ping warning time |
1933 |
* output - ping frequency |
1934 |
* side effects - NONE |
1935 |
*/ |
1936 |
int |
1937 |
get_conf_ping(const struct MaskItem *conf, int *pingwarn) |
1938 |
{ |
1939 |
if (conf != NULL) |
1940 |
{ |
1941 |
if (conf->class) |
1942 |
{ |
1943 |
*pingwarn = conf->class->ping_warning; |
1944 |
return conf->class->ping_freq; |
1945 |
} |
1946 |
} |
1947 |
|
1948 |
return BAD_PING; |
1949 |
} |
1950 |
|
1951 |
/* conf_add_class_to_conf() |
1952 |
* |
1953 |
* inputs - pointer to config item |
1954 |
* output - NONE |
1955 |
* side effects - Add a class pointer to a conf |
1956 |
*/ |
1957 |
void |
1958 |
conf_add_class_to_conf(struct MaskItem *conf, const char *class_name) |
1959 |
{ |
1960 |
struct ClassItem *class = NULL; |
1961 |
|
1962 |
if (class_name == NULL) |
1963 |
{ |
1964 |
conf->class = class_default; |
1965 |
|
1966 |
if (conf->type == CONF_CLIENT) |
1967 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1968 |
"Warning *** Defaulting to default class for %s@%s", |
1969 |
conf->user, conf->host); |
1970 |
else |
1971 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1972 |
"Warning *** Defaulting to default class for %s", |
1973 |
conf->name); |
1974 |
} |
1975 |
else |
1976 |
conf->class = class_find(class_name, 1); |
1977 |
|
1978 |
if (conf->class == NULL) |
1979 |
{ |
1980 |
if (conf->type == CONF_CLIENT) |
1981 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1982 |
"Warning *** Defaulting to default class for %s@%s", |
1983 |
conf->user, conf->host); |
1984 |
else |
1985 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1986 |
"Warning *** Defaulting to default class for %s", |
1987 |
conf->name); |
1988 |
conf->class = class_default; |
1989 |
} |
1990 |
} |
1991 |
|
1992 |
/* conf_add_server() |
1993 |
* |
1994 |
* inputs - pointer to config item |
1995 |
* - pointer to link count already on this conf |
1996 |
* output - NONE |
1997 |
* side effects - Add a connect block |
1998 |
*/ |
1999 |
int |
2000 |
conf_add_server(struct MaskItem *conf, const char *class_name) |
2001 |
{ |
2002 |
conf_add_class_to_conf(conf, class_name); |
2003 |
|
2004 |
if (!conf->host || !conf->name) |
2005 |
{ |
2006 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
2007 |
"Bad connect block"); |
2008 |
ilog(LOG_TYPE_IRCD, "Bad connect block"); |
2009 |
return -1; |
2010 |
} |
2011 |
|
2012 |
if (EmptyString(conf->passwd)) |
2013 |
{ |
2014 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
2015 |
"Bad connect block, name %s", |
2016 |
conf->name); |
2017 |
ilog(LOG_TYPE_IRCD, "Bad connect block, host %s", conf->name); |
2018 |
return -1; |
2019 |
} |
2020 |
|
2021 |
lookup_confhost(conf); |
2022 |
|
2023 |
return 0; |
2024 |
} |
2025 |
|
2026 |
/* yyerror() |
2027 |
* |
2028 |
* inputs - message from parser |
2029 |
* output - NONE |
2030 |
* side effects - message to opers and log file entry is made |
2031 |
*/ |
2032 |
void |
2033 |
yyerror(const char *msg) |
2034 |
{ |
2035 |
char newlinebuf[IRCD_BUFSIZE]; |
2036 |
|
2037 |
if (conf_parser_ctx.pass != 1) |
2038 |
return; |
2039 |
|
2040 |
strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf)); |
2041 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
2042 |
"\"%s\", line %u: %s: %s", |
2043 |
conffilebuf, lineno + 1, msg, newlinebuf); |
2044 |
ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s", |
2045 |
conffilebuf, lineno + 1, msg, newlinebuf); |
2046 |
} |
2047 |
|
2048 |
/* |
2049 |
* valid_tkline() |
2050 |
* |
2051 |
* inputs - pointer to ascii string to check |
2052 |
* - whether the specified time is in seconds or minutes |
2053 |
* output - -1 not enough parameters |
2054 |
* - 0 if not an integer number, else the number |
2055 |
* side effects - none |
2056 |
* Originally written by Dianora (Diane, db@db.net) |
2057 |
*/ |
2058 |
time_t |
2059 |
valid_tkline(const char *p, int minutes) |
2060 |
{ |
2061 |
time_t result = 0; |
2062 |
|
2063 |
for (; *p; ++p) |
2064 |
{ |
2065 |
if (!IsDigit(*p)) |
2066 |
return 0; |
2067 |
|
2068 |
result *= 10; |
2069 |
result += ((*p) & 0xF); |
2070 |
} |
2071 |
|
2072 |
/* |
2073 |
* In the degenerate case where oper does a /quote kline 0 user@host :reason |
2074 |
* i.e. they specifically use 0, I am going to return 1 instead |
2075 |
* as a return value of non-zero is used to flag it as a temporary kline |
2076 |
*/ |
2077 |
if (result == 0) |
2078 |
result = 1; |
2079 |
|
2080 |
/* |
2081 |
* If the incoming time is in seconds convert it to minutes for the purpose |
2082 |
* of this calculation |
2083 |
*/ |
2084 |
if (!minutes) |
2085 |
result = result / (time_t)60; |
2086 |
|
2087 |
if (result > MAX_TDKLINE_TIME) |
2088 |
result = MAX_TDKLINE_TIME; |
2089 |
|
2090 |
result = result * (time_t)60; /* turn it into seconds */ |
2091 |
|
2092 |
return result; |
2093 |
} |
2094 |
|
2095 |
/* valid_wild_card() |
2096 |
* |
2097 |
* input - pointer to client |
2098 |
* - int flag, 0 for no warning oper 1 for warning oper |
2099 |
* - count of following varargs to check |
2100 |
* output - 0 if not valid, 1 if valid |
2101 |
* side effects - NOTICE is given to source_p if warn is 1 |
2102 |
*/ |
2103 |
int |
2104 |
valid_wild_card(struct Client *source_p, int warn, int count, ...) |
2105 |
{ |
2106 |
char *p; |
2107 |
char tmpch; |
2108 |
int nonwild = 0; |
2109 |
va_list args; |
2110 |
|
2111 |
/* |
2112 |
* Now we must check the user and host to make sure there |
2113 |
* are at least NONWILDCHARS non-wildcard characters in |
2114 |
* them, otherwise assume they are attempting to kline |
2115 |
* *@* or some variant of that. This code will also catch |
2116 |
* people attempting to kline *@*.tld, as long as NONWILDCHARS |
2117 |
* is greater than 3. In that case, there are only 3 non-wild |
2118 |
* characters (tld), so if NONWILDCHARS is 4, the kline will |
2119 |
* be disallowed. |
2120 |
* -wnder |
2121 |
*/ |
2122 |
|
2123 |
va_start(args, count); |
2124 |
|
2125 |
while (count--) |
2126 |
{ |
2127 |
p = va_arg(args, char *); |
2128 |
if (p == NULL) |
2129 |
continue; |
2130 |
|
2131 |
while ((tmpch = *p++)) |
2132 |
{ |
2133 |
if (!IsKWildChar(tmpch)) |
2134 |
{ |
2135 |
/* |
2136 |
* If we find enough non-wild characters, we can |
2137 |
* break - no point in searching further. |
2138 |
*/ |
2139 |
if (++nonwild >= ConfigFileEntry.min_nonwildcard) |
2140 |
return 1; |
2141 |
} |
2142 |
} |
2143 |
} |
2144 |
|
2145 |
if (warn) |
2146 |
sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask", |
2147 |
me.name, source_p->name, ConfigFileEntry.min_nonwildcard); |
2148 |
return 0; |
2149 |
} |
2150 |
|
2151 |
/* XXX should this go into a separate file ? -Dianora */ |
2152 |
/* parse_aline |
2153 |
* |
2154 |
* input - pointer to cmd name being used |
2155 |
* - pointer to client using cmd |
2156 |
* - parc parameter count |
2157 |
* - parv[] list of parameters to parse |
2158 |
* - parse_flags bit map of things to test |
2159 |
* - pointer to user or string to parse into |
2160 |
* - pointer to host or NULL to parse into if non NULL |
2161 |
* - pointer to optional tkline time or NULL |
2162 |
* - pointer to target_server to parse into if non NULL |
2163 |
* - pointer to reason to parse into |
2164 |
* |
2165 |
* output - 1 if valid, -1 if not valid |
2166 |
* side effects - A generalised k/d/x etc. line parser, |
2167 |
* "ALINE [time] user@host|string [ON] target :reason" |
2168 |
* will parse returning a parsed user, host if |
2169 |
* h_p pointer is non NULL, string otherwise. |
2170 |
* if tkline_time pointer is non NULL a tk line will be set |
2171 |
* to non zero if found. |
2172 |
* if tkline_time pointer is NULL and tk line is found, |
2173 |
* error is reported. |
2174 |
* if target_server is NULL and an "ON" is found error |
2175 |
* is reported. |
2176 |
* if reason pointer is NULL ignore pointer, |
2177 |
* this allows use of parse_a_line in unkline etc. |
2178 |
* |
2179 |
* - Dianora |
2180 |
*/ |
2181 |
int |
2182 |
parse_aline(const char *cmd, struct Client *source_p, |
2183 |
int parc, char **parv, |
2184 |
int parse_flags, char **up_p, char **h_p, time_t *tkline_time, |
2185 |
char **target_server, char **reason) |
2186 |
{ |
2187 |
int found_tkline_time=0; |
2188 |
static char def_reason[] = "No Reason"; |
2189 |
static char user[USERLEN*4+1]; |
2190 |
static char host[HOSTLEN*4+1]; |
2191 |
|
2192 |
parv++; |
2193 |
parc--; |
2194 |
|
2195 |
found_tkline_time = valid_tkline(*parv, TK_MINUTES); |
2196 |
|
2197 |
if (found_tkline_time != 0) |
2198 |
{ |
2199 |
parv++; |
2200 |
parc--; |
2201 |
|
2202 |
if (tkline_time != NULL) |
2203 |
*tkline_time = found_tkline_time; |
2204 |
else |
2205 |
{ |
2206 |
sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s", |
2207 |
me.name, source_p->name, cmd); |
2208 |
return -1; |
2209 |
} |
2210 |
} |
2211 |
|
2212 |
if (parc == 0) |
2213 |
{ |
2214 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
2215 |
me.name, source_p->name, cmd); |
2216 |
return -1; |
2217 |
} |
2218 |
|
2219 |
if (h_p == NULL) |
2220 |
*up_p = *parv; |
2221 |
else |
2222 |
{ |
2223 |
if (find_user_host(source_p, *parv, user, host, parse_flags) == 0) |
2224 |
return -1; |
2225 |
|
2226 |
*up_p = user; |
2227 |
*h_p = host; |
2228 |
} |
2229 |
|
2230 |
parc--; |
2231 |
parv++; |
2232 |
|
2233 |
if (parc != 0) |
2234 |
{ |
2235 |
if (irccmp(*parv, "ON") == 0) |
2236 |
{ |
2237 |
parc--; |
2238 |
parv++; |
2239 |
|
2240 |
if (target_server == NULL) |
2241 |
{ |
2242 |
sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s", |
2243 |
me.name, source_p->name, cmd); |
2244 |
return -1; |
2245 |
} |
2246 |
|
2247 |
if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN)) |
2248 |
{ |
2249 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
2250 |
me.name, source_p->name, "remoteban"); |
2251 |
return -1; |
2252 |
} |
2253 |
|
2254 |
if (parc == 0 || EmptyString(*parv)) |
2255 |
{ |
2256 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
2257 |
me.name, source_p->name, cmd); |
2258 |
return -1; |
2259 |
} |
2260 |
|
2261 |
*target_server = *parv; |
2262 |
parc--; |
2263 |
parv++; |
2264 |
} |
2265 |
else |
2266 |
{ |
2267 |
/* Make sure target_server *is* NULL if no ON server found |
2268 |
* caller probably NULL'd it first, but no harm to do it again -db |
2269 |
*/ |
2270 |
if (target_server != NULL) |
2271 |
*target_server = NULL; |
2272 |
} |
2273 |
} |
2274 |
|
2275 |
if (h_p != NULL) |
2276 |
{ |
2277 |
if (strchr(user, '!') != NULL) |
2278 |
{ |
2279 |
sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline", |
2280 |
me.name, source_p->name); |
2281 |
return -1; |
2282 |
} |
2283 |
|
2284 |
if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p)) |
2285 |
return -1; |
2286 |
} |
2287 |
else |
2288 |
if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p)) |
2289 |
return -1; |
2290 |
|
2291 |
if (reason != NULL) |
2292 |
{ |
2293 |
if (parc != 0 && !EmptyString(*parv)) |
2294 |
{ |
2295 |
*reason = *parv; |
2296 |
if (!valid_comment(source_p, *reason, 1)) |
2297 |
return -1; |
2298 |
} |
2299 |
else |
2300 |
*reason = def_reason; |
2301 |
} |
2302 |
|
2303 |
return 1; |
2304 |
} |
2305 |
|
2306 |
/* find_user_host() |
2307 |
* |
2308 |
* inputs - pointer to client placing kline |
2309 |
* - pointer to user_host_or_nick |
2310 |
* - pointer to user buffer |
2311 |
* - pointer to host buffer |
2312 |
* output - 0 if not ok to kline, 1 to kline i.e. if valid user host |
2313 |
* side effects - |
2314 |
*/ |
2315 |
static int |
2316 |
find_user_host(struct Client *source_p, char *user_host_or_nick, |
2317 |
char *luser, char *lhost, unsigned int flags) |
2318 |
{ |
2319 |
struct Client *target_p = NULL; |
2320 |
char *hostp = NULL; |
2321 |
|
2322 |
if (lhost == NULL) |
2323 |
{ |
2324 |
strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); |
2325 |
return 1; |
2326 |
} |
2327 |
|
2328 |
if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*') |
2329 |
{ |
2330 |
/* Explicit user@host mask given */ |
2331 |
|
2332 |
if (hostp != NULL) /* I'm a little user@host */ |
2333 |
{ |
2334 |
*(hostp++) = '\0'; /* short and squat */ |
2335 |
if (*user_host_or_nick) |
2336 |
strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */ |
2337 |
else |
2338 |
strcpy(luser, "*"); |
2339 |
if (*hostp) |
2340 |
strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */ |
2341 |
else |
2342 |
strcpy(lhost, "*"); |
2343 |
} |
2344 |
else |
2345 |
{ |
2346 |
luser[0] = '*'; /* no @ found, assume its *@somehost */ |
2347 |
luser[1] = '\0'; |
2348 |
strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1); |
2349 |
} |
2350 |
|
2351 |
return 1; |
2352 |
} |
2353 |
else |
2354 |
{ |
2355 |
/* Try to find user@host mask from nick */ |
2356 |
/* Okay to use source_p as the first param, because source_p == client_p */ |
2357 |
if ((target_p = |
2358 |
find_chasing(source_p, source_p, user_host_or_nick, NULL)) == NULL) |
2359 |
return 0; |
2360 |
|
2361 |
if (IsExemptKline(target_p)) |
2362 |
{ |
2363 |
if (!IsServer(source_p)) |
2364 |
sendto_one(source_p, |
2365 |
":%s NOTICE %s :%s is E-lined", |
2366 |
me.name, source_p->name, target_p->name); |
2367 |
return 0; |
2368 |
} |
2369 |
|
2370 |
/* |
2371 |
* turn the "user" bit into "*user", blow away '~' |
2372 |
* if found in original user name (non-idented) |
2373 |
*/ |
2374 |
strlcpy(luser, target_p->username, USERLEN*4 + 1); |
2375 |
|
2376 |
if (target_p->username[0] == '~') |
2377 |
luser[0] = '*'; |
2378 |
|
2379 |
if (target_p->sockhost[0] == '\0' || |
2380 |
(target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0')) |
2381 |
strlcpy(lhost, target_p->host, HOSTLEN*4 + 1); |
2382 |
else |
2383 |
strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1); |
2384 |
return 1; |
2385 |
} |
2386 |
|
2387 |
return 0; |
2388 |
} |
2389 |
|
2390 |
/* valid_comment() |
2391 |
* |
2392 |
* inputs - pointer to client |
2393 |
* - pointer to comment |
2394 |
* output - 0 if no valid comment, |
2395 |
* - 1 if valid |
2396 |
* side effects - truncates reason where necessary |
2397 |
*/ |
2398 |
int |
2399 |
valid_comment(struct Client *source_p, char *comment, int warn) |
2400 |
{ |
2401 |
if (strchr(comment, '"')) |
2402 |
{ |
2403 |
if (warn) |
2404 |
sendto_one(source_p, ":%s NOTICE %s :Invalid character '\"' in comment", |
2405 |
me.name, source_p->name); |
2406 |
return 0; |
2407 |
} |
2408 |
|
2409 |
if (strlen(comment) > REASONLEN) |
2410 |
comment[REASONLEN-1] = '\0'; |
2411 |
|
2412 |
return 1; |
2413 |
} |
2414 |
|
2415 |
/* match_conf_password() |
2416 |
* |
2417 |
* inputs - pointer to given password |
2418 |
* - pointer to Conf |
2419 |
* output - 1 or 0 if match |
2420 |
* side effects - none |
2421 |
*/ |
2422 |
int |
2423 |
match_conf_password(const char *password, const struct MaskItem *conf) |
2424 |
{ |
2425 |
const char *encr = NULL; |
2426 |
|
2427 |
if (EmptyString(password) || EmptyString(conf->passwd)) |
2428 |
return 0; |
2429 |
|
2430 |
if (conf->flags & CONF_FLAGS_ENCRYPTED) |
2431 |
encr = crypt(password, conf->passwd); |
2432 |
else |
2433 |
encr = password; |
2434 |
|
2435 |
return !strcmp(encr, conf->passwd); |
2436 |
} |
2437 |
|
2438 |
/* |
2439 |
* cluster_a_line |
2440 |
* |
2441 |
* inputs - client sending the cluster |
2442 |
* - command name "KLINE" "XLINE" etc. |
2443 |
* - capab -- CAP_KLN etc. from s_serv.h |
2444 |
* - cluster type -- CLUSTER_KLINE etc. from conf.h |
2445 |
* - pattern and args to send along |
2446 |
* output - none |
2447 |
* side effects - Take source_p send the pattern with args given |
2448 |
* along to all servers that match capab and cluster type |
2449 |
*/ |
2450 |
void |
2451 |
cluster_a_line(struct Client *source_p, const char *command, |
2452 |
int capab, int cluster_type, const char *pattern, ...) |
2453 |
{ |
2454 |
va_list args; |
2455 |
char buffer[IRCD_BUFSIZE]; |
2456 |
const dlink_node *ptr = NULL; |
2457 |
|
2458 |
va_start(args, pattern); |
2459 |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
2460 |
va_end(args); |
2461 |
|
2462 |
DLINK_FOREACH(ptr, cluster_items.head) |
2463 |
{ |
2464 |
const struct MaskItem *conf = ptr->data; |
2465 |
|
2466 |
if (conf->flags & cluster_type) |
2467 |
sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab, |
2468 |
"%s %s %s", command, conf->name, buffer); |
2469 |
} |
2470 |
} |
2471 |
|
2472 |
/* |
2473 |
* split_nuh |
2474 |
* |
2475 |
* inputs - pointer to original mask (modified in place) |
2476 |
* - pointer to pointer where nick should go |
2477 |
* - pointer to pointer where user should go |
2478 |
* - pointer to pointer where host should go |
2479 |
* output - NONE |
2480 |
* side effects - mask is modified in place |
2481 |
* If nick pointer is NULL, ignore writing to it |
2482 |
* this allows us to use this function elsewhere. |
2483 |
* |
2484 |
* mask nick user host |
2485 |
* ---------------------- ------- ------- ------ |
2486 |
* Dianora!db@db.net Dianora db db.net |
2487 |
* Dianora Dianora * * |
2488 |
* db.net * * db.net |
2489 |
* OR if nick pointer is NULL |
2490 |
* Dianora - * Dianora |
2491 |
* Dianora! Dianora * * |
2492 |
* Dianora!@ Dianora * * |
2493 |
* Dianora!db Dianora db * |
2494 |
* Dianora!@db.net Dianora * db.net |
2495 |
* db@db.net * db db.net |
2496 |
* !@ * * * |
2497 |
* @ * * * |
2498 |
* ! * * * |
2499 |
*/ |
2500 |
void |
2501 |
split_nuh(struct split_nuh_item *const iptr) |
2502 |
{ |
2503 |
char *p = NULL, *q = NULL; |
2504 |
|
2505 |
if (iptr->nickptr) |
2506 |
strlcpy(iptr->nickptr, "*", iptr->nicksize); |
2507 |
if (iptr->userptr) |
2508 |
strlcpy(iptr->userptr, "*", iptr->usersize); |
2509 |
if (iptr->hostptr) |
2510 |
strlcpy(iptr->hostptr, "*", iptr->hostsize); |
2511 |
|
2512 |
if ((p = strchr(iptr->nuhmask, '!'))) |
2513 |
{ |
2514 |
*p = '\0'; |
2515 |
|
2516 |
if (iptr->nickptr && *iptr->nuhmask != '\0') |
2517 |
strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize); |
2518 |
|
2519 |
if ((q = strchr(++p, '@'))) { |
2520 |
*q++ = '\0'; |
2521 |
|
2522 |
if (*p != '\0') |
2523 |
strlcpy(iptr->userptr, p, iptr->usersize); |
2524 |
|
2525 |
if (*q != '\0') |
2526 |
strlcpy(iptr->hostptr, q, iptr->hostsize); |
2527 |
} |
2528 |
else |
2529 |
{ |
2530 |
if (*p != '\0') |
2531 |
strlcpy(iptr->userptr, p, iptr->usersize); |
2532 |
} |
2533 |
} |
2534 |
else |
2535 |
{ |
2536 |
/* No ! found so lets look for a user@host */ |
2537 |
if ((p = strchr(iptr->nuhmask, '@'))) |
2538 |
{ |
2539 |
/* if found a @ */ |
2540 |
*p++ = '\0'; |
2541 |
|
2542 |
if (*iptr->nuhmask != '\0') |
2543 |
strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize); |
2544 |
|
2545 |
if (*p != '\0') |
2546 |
strlcpy(iptr->hostptr, p, iptr->hostsize); |
2547 |
} |
2548 |
else |
2549 |
{ |
2550 |
/* no @ found */ |
2551 |
if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:")) |
2552 |
strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize); |
2553 |
else |
2554 |
strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize); |
2555 |
} |
2556 |
} |
2557 |
} |
2558 |
|
2559 |
/* |
2560 |
* flags_to_ascii |
2561 |
* |
2562 |
* inputs - flags is a bitmask |
2563 |
* - pointer to table of ascii letters corresponding |
2564 |
* to each bit |
2565 |
* - flag 1 for convert ToLower if bit missing |
2566 |
* 0 if ignore. |
2567 |
* output - none |
2568 |
* side effects - string pointed to by p has bitmap chars written to it |
2569 |
*/ |
2570 |
static void |
2571 |
flags_to_ascii(unsigned int flags, const unsigned int bit_table[], char *p, |
2572 |
int lowerit) |
2573 |
{ |
2574 |
unsigned int mask = 1; |
2575 |
int i = 0; |
2576 |
|
2577 |
for (mask = 1; (mask != 0) && (bit_table[i] != 0); mask <<= 1, i++) |
2578 |
{ |
2579 |
if (flags & mask) |
2580 |
*p++ = bit_table[i]; |
2581 |
else if (lowerit) |
2582 |
*p++ = ToLower(bit_table[i]); |
2583 |
} |
2584 |
*p = '\0'; |
2585 |
} |