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