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