1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2016 ircd-hybrid development team |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file conf.c |
23 |
* \brief Configuration file functions. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "ircd_defs.h" |
30 |
#include "conf.h" |
31 |
#include "conf_cluster.h" |
32 |
#include "conf_gecos.h" |
33 |
#include "conf_pseudo.h" |
34 |
#include "conf_resv.h" |
35 |
#include "conf_service.h" |
36 |
#include "conf_shared.h" |
37 |
#include "server.h" |
38 |
#include "channel.h" |
39 |
#include "client.h" |
40 |
#include "event.h" |
41 |
#include "irc_string.h" |
42 |
#include "s_bsd.h" |
43 |
#include "ircd.h" |
44 |
#include "listener.h" |
45 |
#include "hostmask.h" |
46 |
#include "modules.h" |
47 |
#include "numeric.h" |
48 |
#include "fdlist.h" |
49 |
#include "log.h" |
50 |
#include "send.h" |
51 |
#include "memory.h" |
52 |
#include "res.h" |
53 |
#include "userhost.h" |
54 |
#include "user.h" |
55 |
#include "channel_mode.h" |
56 |
#include "parse.h" |
57 |
#include "misc.h" |
58 |
#include "conf_db.h" |
59 |
#include "conf_class.h" |
60 |
#include "motd.h" |
61 |
#include "ipcache.h" |
62 |
#include "isupport.h" |
63 |
|
64 |
|
65 |
struct config_channel_entry ConfigChannel; |
66 |
struct config_serverhide_entry ConfigServerHide; |
67 |
struct config_general_entry ConfigGeneral; |
68 |
struct config_log_entry ConfigLog = { .use_logging = 1 }; |
69 |
struct config_serverinfo_entry ConfigServerInfo; |
70 |
struct config_admin_entry ConfigAdminInfo; |
71 |
struct conf_parser_context conf_parser_ctx; |
72 |
|
73 |
/* general conf items link list root, other than k lines etc. */ |
74 |
dlink_list server_items; |
75 |
dlink_list operator_items; |
76 |
|
77 |
extern unsigned int lineno; |
78 |
extern char linebuf[]; |
79 |
extern char conffilebuf[IRCD_BUFSIZE]; |
80 |
extern int yyparse(); /* defined in y.tab.c */ |
81 |
|
82 |
|
83 |
/* conf_dns_callback() |
84 |
* |
85 |
* inputs - pointer to struct MaskItem |
86 |
* - pointer to DNSReply reply |
87 |
* output - none |
88 |
* side effects - called when resolver query finishes |
89 |
* if the query resulted in a successful search, hp will contain |
90 |
* a non-null pointer, otherwise hp will be null. |
91 |
* if successful save hp in the conf item it was called with |
92 |
*/ |
93 |
static void |
94 |
conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength) |
95 |
{ |
96 |
struct MaskItem *const conf = vptr; |
97 |
|
98 |
conf->dns_pending = 0; |
99 |
|
100 |
if (addr) |
101 |
memcpy(&conf->addr, addr, sizeof(conf->addr)); |
102 |
else |
103 |
conf->dns_failed = 1; |
104 |
} |
105 |
|
106 |
/* conf_dns_lookup() |
107 |
* |
108 |
* do a nameserver lookup of the conf host |
109 |
* if the conf entry is currently doing a ns lookup do nothing, otherwise |
110 |
* allocate a dns_query and start ns lookup. |
111 |
*/ |
112 |
static void |
113 |
conf_dns_lookup(struct MaskItem *conf) |
114 |
{ |
115 |
if (conf->dns_pending) |
116 |
return; |
117 |
|
118 |
conf->dns_pending = 1; |
119 |
|
120 |
if (conf->aftype == AF_INET) |
121 |
gethost_byname_type(conf_dns_callback, conf, conf->host, T_A); |
122 |
else |
123 |
gethost_byname_type(conf_dns_callback, conf, conf->host, T_AAAA); |
124 |
} |
125 |
|
126 |
/* map_to_list() |
127 |
* |
128 |
* inputs - ConfType conf |
129 |
* output - pointer to dlink_list to use |
130 |
* side effects - none |
131 |
*/ |
132 |
static dlink_list * |
133 |
map_to_list(enum maskitem_type type) |
134 |
{ |
135 |
switch (type) |
136 |
{ |
137 |
case CONF_OPER: |
138 |
return &operator_items; |
139 |
break; |
140 |
case CONF_SERVER: |
141 |
return &server_items; |
142 |
break; |
143 |
default: |
144 |
return NULL; |
145 |
} |
146 |
} |
147 |
|
148 |
struct MaskItem * |
149 |
conf_make(enum maskitem_type type) |
150 |
{ |
151 |
struct MaskItem *const conf = xcalloc(sizeof(*conf)); |
152 |
dlink_list *list = NULL; |
153 |
|
154 |
conf->type = type; |
155 |
conf->active = 1; |
156 |
conf->aftype = AF_INET; |
157 |
|
158 |
if ((list = map_to_list(type))) |
159 |
dlinkAdd(conf, &conf->node, list); |
160 |
return conf; |
161 |
} |
162 |
|
163 |
void |
164 |
conf_free(struct MaskItem *conf) |
165 |
{ |
166 |
dlink_node *node = NULL, *node_next = NULL; |
167 |
dlink_list *list = NULL; |
168 |
|
169 |
if ((list = map_to_list(conf->type))) |
170 |
dlinkFindDelete(list, conf); |
171 |
|
172 |
xfree(conf->name); |
173 |
|
174 |
if (conf->dns_pending) |
175 |
delete_resolver_queries(conf); |
176 |
if (conf->passwd) |
177 |
memset(conf->passwd, 0, strlen(conf->passwd)); |
178 |
if (conf->spasswd) |
179 |
memset(conf->spasswd, 0, strlen(conf->spasswd)); |
180 |
|
181 |
conf->class = NULL; |
182 |
|
183 |
xfree(conf->passwd); |
184 |
xfree(conf->spasswd); |
185 |
xfree(conf->reason); |
186 |
xfree(conf->certfp); |
187 |
xfree(conf->whois); |
188 |
xfree(conf->user); |
189 |
xfree(conf->host); |
190 |
xfree(conf->cipher_list); |
191 |
|
192 |
DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head) |
193 |
{ |
194 |
xfree(node->data); |
195 |
dlinkDelete(node, &conf->hub_list); |
196 |
free_dlink_node(node); |
197 |
} |
198 |
|
199 |
DLINK_FOREACH_SAFE(node, node_next, conf->leaf_list.head) |
200 |
{ |
201 |
xfree(node->data); |
202 |
dlinkDelete(node, &conf->leaf_list); |
203 |
free_dlink_node(node); |
204 |
} |
205 |
|
206 |
xfree(conf); |
207 |
} |
208 |
|
209 |
/* attach_iline() |
210 |
* |
211 |
* inputs - client pointer |
212 |
* - conf pointer |
213 |
* output - |
214 |
* side effects - do actual attach |
215 |
*/ |
216 |
static int |
217 |
attach_iline(struct Client *client_p, struct MaskItem *conf) |
218 |
{ |
219 |
const struct ClassItem *const class = conf->class; |
220 |
struct ip_entry *ip_found; |
221 |
int a_limit_reached = 0; |
222 |
unsigned int local = 0, global = 0, ident = 0; |
223 |
|
224 |
ip_found = ipcache_find_or_add_address(&client_p->connection->ip); |
225 |
ip_found->count++; |
226 |
AddFlag(client_p, FLAGS_IPHASH); |
227 |
|
228 |
userhost_count(client_p->username, client_p->host, |
229 |
&global, &local, &ident); |
230 |
|
231 |
/* XXX blah. go down checking the various silly limits |
232 |
* setting a_limit_reached if any limit is reached. |
233 |
* - Dianora |
234 |
*/ |
235 |
if (class->max_total && class->ref_count >= class->max_total) |
236 |
a_limit_reached = 1; |
237 |
else if (class->max_perip && ip_found->count > class->max_perip) |
238 |
a_limit_reached = 1; |
239 |
else if (class->max_local && local >= class->max_local) |
240 |
a_limit_reached = 1; |
241 |
else if (class->max_global && global >= class->max_global) |
242 |
a_limit_reached = 1; |
243 |
else if (class->max_ident && ident >= class->max_ident && |
244 |
client_p->username[0] != '~') |
245 |
a_limit_reached = 1; |
246 |
|
247 |
if (a_limit_reached) |
248 |
{ |
249 |
if (!IsConfExemptLimits(conf)) |
250 |
return TOO_MANY; /* Already at maximum allowed */ |
251 |
|
252 |
sendto_one_notice(client_p, &me, ":*** Your connection class is full, " |
253 |
"but you have exceed_limit = yes;"); |
254 |
} |
255 |
|
256 |
return attach_conf(client_p, conf); |
257 |
} |
258 |
|
259 |
/* verify_access() |
260 |
* |
261 |
* inputs - pointer to client to verify |
262 |
* output - 0 if success -'ve if not |
263 |
* side effect - find the first (best) I line to attach. |
264 |
*/ |
265 |
static int |
266 |
verify_access(struct Client *client_p) |
267 |
{ |
268 |
struct MaskItem *conf = NULL; |
269 |
|
270 |
if (HasFlag(client_p, FLAGS_GOTID)) |
271 |
{ |
272 |
conf = find_address_conf(client_p->host, client_p->username, |
273 |
&client_p->connection->ip, |
274 |
client_p->connection->aftype, |
275 |
client_p->connection->password); |
276 |
} |
277 |
else |
278 |
{ |
279 |
char non_ident[USERLEN + 1] = "~"; |
280 |
|
281 |
strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1); |
282 |
conf = find_address_conf(client_p->host, non_ident, |
283 |
&client_p->connection->ip, |
284 |
client_p->connection->aftype, |
285 |
client_p->connection->password); |
286 |
} |
287 |
|
288 |
if (!conf) |
289 |
return NOT_AUTHORIZED; |
290 |
|
291 |
assert(IsConfClient(conf) || IsConfKill(conf)); |
292 |
|
293 |
if (IsConfClient(conf)) |
294 |
{ |
295 |
if (IsConfRedir(conf)) |
296 |
{ |
297 |
sendto_one_numeric(client_p, &me, RPL_REDIR, |
298 |
conf->name ? conf->name : "", |
299 |
conf->port); |
300 |
return NOT_AUTHORIZED; |
301 |
} |
302 |
|
303 |
if (IsConfDoSpoofIp(conf)) |
304 |
{ |
305 |
if (IsConfSpoofNotice(conf)) |
306 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s", |
307 |
client_p->name, client_p->host, conf->name); |
308 |
|
309 |
strlcpy(client_p->host, conf->name, sizeof(client_p->host)); |
310 |
} |
311 |
|
312 |
return attach_iline(client_p, conf); |
313 |
} |
314 |
|
315 |
sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason); |
316 |
return BANNED_CLIENT; |
317 |
} |
318 |
|
319 |
/* check_client() |
320 |
* |
321 |
* inputs - pointer to client |
322 |
* output - 0 = Success |
323 |
* NOT_AUTHORIZED (-1) = Access denied (no I line match) |
324 |
* IRCD_SOCKET_ERROR (-2) = Bad socket. |
325 |
* I_LINE_FULL (-3) = I-line is full |
326 |
* TOO_MANY (-4) = Too many connections from hostname |
327 |
* BANNED_CLIENT (-5) = K-lined |
328 |
* side effects - Ordinary client access check. |
329 |
* Look for conf lines which have the same |
330 |
* status as the flags passed. |
331 |
*/ |
332 |
int |
333 |
check_client(struct Client *source_p) |
334 |
{ |
335 |
int i; |
336 |
|
337 |
if ((i = verify_access(source_p))) |
338 |
ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]", |
339 |
source_p->name, source_p->sockhost); |
340 |
|
341 |
switch (i) |
342 |
{ |
343 |
case TOO_MANY: |
344 |
sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE, |
345 |
"Too many on IP for %s (%s).", |
346 |
get_client_name(source_p, SHOW_IP), |
347 |
source_p->sockhost); |
348 |
ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.", |
349 |
get_client_name(source_p, SHOW_IP)); |
350 |
++ServerStats.is_ref; |
351 |
exit_client(source_p, "No more connections allowed on that IP"); |
352 |
break; |
353 |
|
354 |
case I_LINE_FULL: |
355 |
sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE, |
356 |
"auth {} block is full for %s (%s).", |
357 |
get_client_name(source_p, SHOW_IP), |
358 |
source_p->sockhost); |
359 |
ilog(LOG_TYPE_IRCD, "Too many connections from %s.", |
360 |
get_client_name(source_p, SHOW_IP)); |
361 |
++ServerStats.is_ref; |
362 |
exit_client(source_p, "No more connections allowed in your connection class"); |
363 |
break; |
364 |
|
365 |
case NOT_AUTHORIZED: |
366 |
/* jdc - lists server name & port connections are on */ |
367 |
/* a purely cosmetical change */ |
368 |
sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE, |
369 |
"Unauthorized client connection from %s [%s] on [%s/%u].", |
370 |
get_client_name(source_p, SHOW_IP), |
371 |
source_p->sockhost, |
372 |
source_p->connection->listener->name, |
373 |
source_p->connection->listener->port); |
374 |
ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].", |
375 |
get_client_name(source_p, SHOW_IP), |
376 |
source_p->connection->listener->name, |
377 |
source_p->connection->listener->port); |
378 |
|
379 |
++ServerStats.is_ref; |
380 |
exit_client(source_p, "You are not authorized to use this server"); |
381 |
break; |
382 |
|
383 |
case BANNED_CLIENT: |
384 |
++ServerStats.is_ref; |
385 |
exit_client(source_p, "Banned"); |
386 |
break; |
387 |
|
388 |
case 0: |
389 |
default: |
390 |
break; |
391 |
} |
392 |
|
393 |
return !(i < 0); |
394 |
} |
395 |
|
396 |
/* detach_conf() |
397 |
* |
398 |
* inputs - pointer to client to detach |
399 |
* - type of conf to detach |
400 |
* output - 0 for success, -1 for failure |
401 |
* side effects - Disassociate configuration from the client. |
402 |
* Also removes a class from the list if marked for deleting. |
403 |
*/ |
404 |
void |
405 |
detach_conf(struct Client *client_p, enum maskitem_type type) |
406 |
{ |
407 |
dlink_node *node = NULL, *node_next = NULL; |
408 |
|
409 |
DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head) |
410 |
{ |
411 |
struct MaskItem *conf = node->data; |
412 |
|
413 |
assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER)); |
414 |
assert(conf->ref_count > 0); |
415 |
assert(conf->class->ref_count > 0); |
416 |
|
417 |
if (!(conf->type & type)) |
418 |
continue; |
419 |
|
420 |
dlinkDelete(node, &client_p->connection->confs); |
421 |
free_dlink_node(node); |
422 |
|
423 |
if (conf->type == CONF_CLIENT) |
424 |
remove_from_cidr_check(&client_p->connection->ip, conf->class); |
425 |
|
426 |
if (--conf->class->ref_count == 0 && conf->class->active == 0) |
427 |
{ |
428 |
class_free(conf->class); |
429 |
conf->class = NULL; |
430 |
} |
431 |
|
432 |
if (--conf->ref_count == 0 && conf->active == 0) |
433 |
conf_free(conf); |
434 |
} |
435 |
} |
436 |
|
437 |
/* attach_conf() |
438 |
* |
439 |
* inputs - client pointer |
440 |
* - conf pointer |
441 |
* output - |
442 |
* side effects - Associate a specific configuration entry to a *local* |
443 |
* client (this is the one which used in accepting the |
444 |
* connection). Note, that this automatically changes the |
445 |
* attachment if there was an old one... |
446 |
*/ |
447 |
int |
448 |
attach_conf(struct Client *client_p, struct MaskItem *conf) |
449 |
{ |
450 |
if (dlinkFind(&client_p->connection->confs, conf)) |
451 |
return 1; |
452 |
|
453 |
if (conf->type == CONF_CLIENT) |
454 |
if (cidr_limit_reached(IsConfExemptLimits(conf), |
455 |
&client_p->connection->ip, conf->class)) |
456 |
return TOO_MANY; /* Already at maximum allowed */ |
457 |
|
458 |
conf->class->ref_count++; |
459 |
conf->ref_count++; |
460 |
|
461 |
dlinkAdd(conf, make_dlink_node(), &client_p->connection->confs); |
462 |
|
463 |
return 0; |
464 |
} |
465 |
|
466 |
/* attach_connect_block() |
467 |
* |
468 |
* inputs - pointer to server to attach |
469 |
* - name of server |
470 |
* - hostname of server |
471 |
* output - true (1) if both are found, otherwise return false (0) |
472 |
* side effects - find connect block and attach them to connecting client |
473 |
*/ |
474 |
int |
475 |
attach_connect_block(struct Client *client_p, const char *name, |
476 |
const char *host) |
477 |
{ |
478 |
dlink_node *node = NULL; |
479 |
|
480 |
assert(host); |
481 |
|
482 |
DLINK_FOREACH(node, server_items.head) |
483 |
{ |
484 |
struct MaskItem *conf = node->data; |
485 |
|
486 |
if (match(conf->name, name) || match(conf->host, host)) |
487 |
continue; |
488 |
|
489 |
attach_conf(client_p, conf); |
490 |
return 1; |
491 |
} |
492 |
|
493 |
return 0; |
494 |
} |
495 |
|
496 |
/* find_conf_name() |
497 |
* |
498 |
* inputs - pointer to conf link list to search |
499 |
* - pointer to name to find |
500 |
* - int mask of type of conf to find |
501 |
* output - NULL or pointer to conf found |
502 |
* side effects - find a conf entry which matches the name |
503 |
* and has the given mask. |
504 |
*/ |
505 |
struct MaskItem * |
506 |
find_conf_name(dlink_list *list, const char *name, enum maskitem_type type) |
507 |
{ |
508 |
dlink_node *node = NULL; |
509 |
|
510 |
DLINK_FOREACH(node, list->head) |
511 |
{ |
512 |
struct MaskItem *conf = node->data; |
513 |
|
514 |
if (conf->type == type) |
515 |
{ |
516 |
if (conf->name && !irccmp(conf->name, name)) |
517 |
return conf; |
518 |
} |
519 |
} |
520 |
|
521 |
return NULL; |
522 |
} |
523 |
|
524 |
/* find_matching_name_conf() |
525 |
* |
526 |
* inputs - type of link list to look in |
527 |
* - pointer to name string to find |
528 |
* - pointer to user |
529 |
* - pointer to host |
530 |
* - optional flags to match on as well |
531 |
* output - NULL or pointer to found struct MaskItem |
532 |
* side effects - looks for a match on name field |
533 |
*/ |
534 |
struct MaskItem * |
535 |
find_matching_name_conf(enum maskitem_type type, const char *name, const char *user, |
536 |
const char *host, unsigned int flags) |
537 |
{ |
538 |
dlink_node *node = NULL; |
539 |
dlink_list *list = map_to_list(type); |
540 |
struct MaskItem *conf = NULL; |
541 |
|
542 |
switch (type) |
543 |
{ |
544 |
case CONF_SERVER: |
545 |
DLINK_FOREACH(node, list->head) |
546 |
{ |
547 |
conf = node->data; |
548 |
|
549 |
if (name && !match(name, conf->name)) |
550 |
return conf; |
551 |
if (host && !match(host, conf->host)) |
552 |
return conf; |
553 |
} |
554 |
break; |
555 |
|
556 |
default: |
557 |
break; |
558 |
} |
559 |
return NULL; |
560 |
} |
561 |
|
562 |
/* find_exact_name_conf() |
563 |
* |
564 |
* inputs - type of link list to look in |
565 |
* - pointer to name string to find |
566 |
* - pointer to user |
567 |
* - pointer to host |
568 |
* output - NULL or pointer to found struct MaskItem |
569 |
* side effects - looks for an exact match on name field |
570 |
*/ |
571 |
struct MaskItem * |
572 |
find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name, |
573 |
const char *user, const char *host) |
574 |
{ |
575 |
dlink_node *node = NULL; |
576 |
dlink_list *list = map_to_list(type); |
577 |
struct MaskItem *conf = NULL; |
578 |
|
579 |
switch(type) |
580 |
{ |
581 |
case CONF_OPER: |
582 |
DLINK_FOREACH(node, list->head) |
583 |
{ |
584 |
conf = node->data; |
585 |
|
586 |
if (EmptyString(conf->name)) |
587 |
continue; |
588 |
|
589 |
if (!irccmp(conf->name, name)) |
590 |
{ |
591 |
if (!who) |
592 |
return conf; |
593 |
if (EmptyString(conf->user) || EmptyString(conf->host)) |
594 |
return NULL; |
595 |
if (!match(conf->user, who->username)) |
596 |
{ |
597 |
switch (conf->htype) |
598 |
{ |
599 |
case HM_HOST: |
600 |
if (!match(conf->host, who->host) || !match(conf->host, who->sockhost)) |
601 |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
602 |
return conf; |
603 |
break; |
604 |
case HM_IPV4: |
605 |
if (who->connection->aftype == AF_INET) |
606 |
if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits)) |
607 |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
608 |
return conf; |
609 |
break; |
610 |
case HM_IPV6: |
611 |
if (who->connection->aftype == AF_INET6) |
612 |
if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits)) |
613 |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
614 |
return conf; |
615 |
break; |
616 |
default: |
617 |
assert(0); |
618 |
} |
619 |
} |
620 |
} |
621 |
} |
622 |
|
623 |
break; |
624 |
|
625 |
case CONF_SERVER: |
626 |
DLINK_FOREACH(node, list->head) |
627 |
{ |
628 |
conf = node->data; |
629 |
|
630 |
if (EmptyString(conf->name)) |
631 |
continue; |
632 |
|
633 |
if (name == NULL) |
634 |
{ |
635 |
if (EmptyString(conf->host)) |
636 |
continue; |
637 |
if (irccmp(conf->host, host) == 0) |
638 |
return conf; |
639 |
} |
640 |
else if (irccmp(conf->name, name) == 0) |
641 |
return conf; |
642 |
} |
643 |
|
644 |
break; |
645 |
|
646 |
default: |
647 |
break; |
648 |
} |
649 |
|
650 |
return NULL; |
651 |
} |
652 |
|
653 |
/* set_default_conf() |
654 |
* |
655 |
* inputs - NONE |
656 |
* output - NONE |
657 |
* side effects - Set default values here. |
658 |
* This is called **PRIOR** to parsing the |
659 |
* configuration file. If you want to do some validation |
660 |
* of values later, put them in validate_conf(). |
661 |
*/ |
662 |
static void |
663 |
set_default_conf(void) |
664 |
{ |
665 |
/* verify init_class() ran, this should be an unnecessary check |
666 |
* but its not much work. |
667 |
*/ |
668 |
assert(class_default == class_get_list()->tail->data); |
669 |
|
670 |
ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT); |
671 |
ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT); |
672 |
|
673 |
memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip)); |
674 |
ConfigServerInfo.specific_ipv4_vhost = 0; |
675 |
memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6)); |
676 |
ConfigServerInfo.specific_ipv6_vhost = 0; |
677 |
|
678 |
ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX; |
679 |
ConfigServerInfo.max_nick_length = 9; |
680 |
ConfigServerInfo.max_topic_length = 80; |
681 |
ConfigServerInfo.hub = 0; |
682 |
ConfigServerInfo.libgeoip_database_options = 0; |
683 |
|
684 |
log_del_all(); |
685 |
|
686 |
ConfigLog.use_logging = 1; |
687 |
|
688 |
ConfigChannel.disable_fake_channels = 0; |
689 |
ConfigChannel.invite_client_count = 10; |
690 |
ConfigChannel.invite_client_time = 300; |
691 |
ConfigChannel.invite_delay_channel = 5; |
692 |
ConfigChannel.knock_client_count = 1; |
693 |
ConfigChannel.knock_client_time = 300; |
694 |
ConfigChannel.knock_delay_channel = 60; |
695 |
ConfigChannel.max_channels = 25; |
696 |
ConfigChannel.max_bans = 25; |
697 |
ConfigChannel.default_join_flood_count = 18; |
698 |
ConfigChannel.default_join_flood_time = 6; |
699 |
|
700 |
ConfigServerHide.flatten_links = 0; |
701 |
ConfigServerHide.flatten_links_delay = 300; |
702 |
ConfigServerHide.hidden = 0; |
703 |
ConfigServerHide.hide_servers = 0; |
704 |
ConfigServerHide.hide_services = 0; |
705 |
ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT); |
706 |
ConfigServerHide.hide_server_ips = 0; |
707 |
ConfigServerHide.disable_remote_commands = 0; |
708 |
|
709 |
ConfigGeneral.away_count = 2; |
710 |
ConfigGeneral.away_time = 10; |
711 |
ConfigGeneral.max_watch = 50; |
712 |
ConfigGeneral.cycle_on_host_change = 1; |
713 |
ConfigGeneral.dline_min_cidr = 16; |
714 |
ConfigGeneral.dline_min_cidr6 = 48; |
715 |
ConfigGeneral.kline_min_cidr = 16; |
716 |
ConfigGeneral.kline_min_cidr6 = 48; |
717 |
ConfigGeneral.invisible_on_connect = 1; |
718 |
ConfigGeneral.tkline_expire_notices = 1; |
719 |
ConfigGeneral.ignore_bogus_ts = 0; |
720 |
ConfigGeneral.disable_auth = 0; |
721 |
ConfigGeneral.kill_chase_time_limit = 90; |
722 |
ConfigGeneral.default_floodcount = 8; |
723 |
ConfigGeneral.failed_oper_notice = 1; |
724 |
ConfigGeneral.dots_in_ident = 0; |
725 |
ConfigGeneral.min_nonwildcard = 4; |
726 |
ConfigGeneral.min_nonwildcard_simple = 3; |
727 |
ConfigGeneral.max_accept = 50; |
728 |
ConfigGeneral.anti_nick_flood = 0; |
729 |
ConfigGeneral.max_nick_time = 20; |
730 |
ConfigGeneral.max_nick_changes = 5; |
731 |
ConfigGeneral.anti_spam_exit_message_time = 0; |
732 |
ConfigGeneral.ts_warn_delta = 30; |
733 |
ConfigGeneral.ts_max_delta = 600; |
734 |
ConfigGeneral.warn_no_connect_block = 1; |
735 |
ConfigGeneral.stats_e_disabled = 0; |
736 |
ConfigGeneral.stats_i_oper_only = 1; /* 1 = masked */ |
737 |
ConfigGeneral.stats_k_oper_only = 1; /* 1 = masked */ |
738 |
ConfigGeneral.stats_o_oper_only = 1; |
739 |
ConfigGeneral.stats_m_oper_only = 1; |
740 |
ConfigGeneral.stats_P_oper_only = 0; |
741 |
ConfigGeneral.stats_u_oper_only = 0; |
742 |
ConfigGeneral.caller_id_wait = 60; |
743 |
ConfigGeneral.opers_bypass_callerid = 0; |
744 |
ConfigGeneral.pace_wait = 10; |
745 |
ConfigGeneral.pace_wait_simple = 1; |
746 |
ConfigGeneral.short_motd = 0; |
747 |
ConfigGeneral.ping_cookie = 0; |
748 |
ConfigGeneral.no_oper_flood = 0; |
749 |
ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT; |
750 |
ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT | |
751 |
UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE | |
752 |
UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN; |
753 |
ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP; |
754 |
ConfigGeneral.throttle_count = 1; |
755 |
ConfigGeneral.throttle_time = 1; |
756 |
} |
757 |
|
758 |
static void |
759 |
validate_conf(void) |
760 |
{ |
761 |
if (EmptyString(ConfigServerInfo.network_name)) |
762 |
ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT); |
763 |
|
764 |
if (EmptyString(ConfigServerInfo.network_desc)) |
765 |
ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT); |
766 |
} |
767 |
|
768 |
/* read_conf() |
769 |
* |
770 |
* inputs - file descriptor pointing to config file to use |
771 |
* output - None |
772 |
* side effects - Read configuration file. |
773 |
*/ |
774 |
static void |
775 |
read_conf(FILE *file) |
776 |
{ |
777 |
lineno = 0; |
778 |
|
779 |
set_default_conf(); /* Set default values prior to conf parsing */ |
780 |
conf_parser_ctx.pass = 1; |
781 |
yyparse(); /* Pick up the classes first */ |
782 |
|
783 |
rewind(file); |
784 |
|
785 |
conf_parser_ctx.pass = 2; |
786 |
yyparse(); /* Load the values from the conf */ |
787 |
validate_conf(); /* Check to make sure some values are still okay. */ |
788 |
/* Some global values are also loaded here. */ |
789 |
class_delete_marked(); /* Delete unused classes that are marked for deletion */ |
790 |
} |
791 |
|
792 |
/* conf_rehash() |
793 |
* |
794 |
* Actual REHASH service routine. Called with sig == 0 if it has been called |
795 |
* as a result of an operator issuing this command, else assume it has been |
796 |
* called as a result of the server receiving a HUP signal. |
797 |
*/ |
798 |
void |
799 |
conf_rehash(int sig) |
800 |
{ |
801 |
if (sig) |
802 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
803 |
"Got signal SIGHUP, reloading configuration file(s)"); |
804 |
|
805 |
restart_resolver(); |
806 |
|
807 |
/* don't close listeners until we know we can go ahead with the rehash */ |
808 |
|
809 |
read_conf_files(0); |
810 |
|
811 |
load_conf_modules(); |
812 |
check_conf_klines(); |
813 |
} |
814 |
|
815 |
/* lookup_confhost() |
816 |
* |
817 |
* start DNS lookups of all hostnames in the conf |
818 |
* line and convert an IP addresses in a.b.c.d number for to IP#s. |
819 |
*/ |
820 |
void |
821 |
lookup_confhost(struct MaskItem *conf) |
822 |
{ |
823 |
struct addrinfo hints, *res; |
824 |
|
825 |
/* |
826 |
* Do name lookup now on hostnames given and store the |
827 |
* ip numbers in conf structure. |
828 |
*/ |
829 |
memset(&hints, 0, sizeof(hints)); |
830 |
|
831 |
hints.ai_family = AF_UNSPEC; |
832 |
hints.ai_socktype = SOCK_STREAM; |
833 |
|
834 |
/* Get us ready for a bind() and don't bother doing dns lookup */ |
835 |
hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; |
836 |
|
837 |
if (getaddrinfo(conf->host, NULL, &hints, &res)) |
838 |
{ |
839 |
conf_dns_lookup(conf); |
840 |
return; |
841 |
} |
842 |
|
843 |
assert(res); |
844 |
|
845 |
memcpy(&conf->addr, res->ai_addr, res->ai_addrlen); |
846 |
conf->addr.ss_len = res->ai_addrlen; |
847 |
conf->addr.ss.ss_family = res->ai_family; |
848 |
|
849 |
freeaddrinfo(res); |
850 |
} |
851 |
|
852 |
/* conf_connect_allowed() |
853 |
* |
854 |
* inputs - pointer to inaddr |
855 |
* - int type ipv4 or ipv6 |
856 |
* output - BANNED or accepted |
857 |
* side effects - none |
858 |
*/ |
859 |
int |
860 |
conf_connect_allowed(struct irc_ssaddr *addr, int aftype) |
861 |
{ |
862 |
struct ip_entry *ip_found = NULL; |
863 |
const struct MaskItem *conf = find_dline_conf(addr, aftype); |
864 |
|
865 |
if (conf) |
866 |
{ |
867 |
/* DLINE exempt also gets you out of static limits/pacing... */ |
868 |
if (conf->type == CONF_EXEMPT) |
869 |
return 0; |
870 |
return BANNED_CLIENT; |
871 |
} |
872 |
|
873 |
ip_found = ipcache_find_or_add_address(addr); |
874 |
|
875 |
if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time) |
876 |
{ |
877 |
if (ip_found->connection_count >= ConfigGeneral.throttle_count) |
878 |
return TOO_FAST; |
879 |
|
880 |
++ip_found->connection_count; |
881 |
} |
882 |
else |
883 |
ip_found->connection_count = 1; |
884 |
|
885 |
ip_found->last_attempt = CurrentTime; |
886 |
return 0; |
887 |
} |
888 |
|
889 |
/* cleanup_tklines() |
890 |
* |
891 |
* inputs - NONE |
892 |
* output - NONE |
893 |
* side effects - call function to expire temporary k/d lines |
894 |
* This is an event started off in ircd.c |
895 |
*/ |
896 |
void |
897 |
cleanup_tklines(void *unused) |
898 |
{ |
899 |
hostmask_expire_temporary(); |
900 |
gecos_expire(); |
901 |
resv_expire(); |
902 |
} |
903 |
|
904 |
/* oper_privs_as_string() |
905 |
* |
906 |
* inputs - pointer to client_p |
907 |
* output - pointer to static string showing oper privs |
908 |
* side effects - return as string, the oper privs as derived from port |
909 |
*/ |
910 |
static const struct oper_flags |
911 |
{ |
912 |
const unsigned int flag; |
913 |
const unsigned char c; |
914 |
} flag_table[] = { |
915 |
{ OPER_FLAG_ADMIN, 'A' }, |
916 |
{ OPER_FLAG_CLOSE, 'B' }, |
917 |
{ OPER_FLAG_CONNECT, 'C' }, |
918 |
{ OPER_FLAG_CONNECT_REMOTE, 'D' }, |
919 |
{ OPER_FLAG_DIE, 'E' }, |
920 |
{ OPER_FLAG_DLINE, 'F' }, |
921 |
{ OPER_FLAG_GLOBOPS, 'G' }, |
922 |
{ OPER_FLAG_JOIN_RESV, 'H' }, |
923 |
{ OPER_FLAG_KILL, 'I' }, |
924 |
{ OPER_FLAG_KILL_REMOTE, 'J' }, |
925 |
{ OPER_FLAG_KLINE, 'K' }, |
926 |
{ OPER_FLAG_LOCOPS, 'L' }, |
927 |
{ OPER_FLAG_MODULE, 'M' }, |
928 |
{ OPER_FLAG_NICK_RESV, 'N' }, |
929 |
{ OPER_FLAG_OPME, 'O' }, |
930 |
{ OPER_FLAG_REHASH, 'P' }, |
931 |
{ OPER_FLAG_REMOTEBAN, 'Q' }, |
932 |
{ OPER_FLAG_RESTART, 'R' }, |
933 |
{ OPER_FLAG_RESV, 'S' }, |
934 |
{ OPER_FLAG_SET, 'T' }, |
935 |
{ OPER_FLAG_SQUIT, 'U' }, |
936 |
{ OPER_FLAG_SQUIT_REMOTE, 'V' }, |
937 |
{ OPER_FLAG_UNDLINE, 'W' }, |
938 |
{ OPER_FLAG_UNKLINE, 'X' }, |
939 |
{ OPER_FLAG_UNRESV, 'Y' }, |
940 |
{ OPER_FLAG_UNXLINE, 'Z' }, |
941 |
{ OPER_FLAG_WALLOPS, 'a' }, |
942 |
{ OPER_FLAG_XLINE, 'b' }, |
943 |
{ 0, '\0' } |
944 |
}; |
945 |
|
946 |
const char * |
947 |
oper_privs_as_string(const unsigned int flags) |
948 |
{ |
949 |
static char buf[sizeof(flag_table) / sizeof(struct oper_flags)]; |
950 |
char *p = buf; |
951 |
|
952 |
for (const struct oper_flags *tab = flag_table; tab->flag; ++tab) |
953 |
if (flags & tab->flag) |
954 |
*p++ = tab->c; |
955 |
|
956 |
if (p == buf) |
957 |
*p++ = '0'; |
958 |
|
959 |
*p = '\0'; |
960 |
|
961 |
return buf; |
962 |
} |
963 |
|
964 |
/* |
965 |
* Input: A client to find the active operator {} name for. |
966 |
* Output: The nick!user@host{oper} of the oper. |
967 |
* "oper" is server name for remote opers |
968 |
* Side effects: None. |
969 |
*/ |
970 |
const char * |
971 |
get_oper_name(const struct Client *client_p) |
972 |
{ |
973 |
static char buffer[IRCD_BUFSIZE]; |
974 |
|
975 |
if (IsServer(client_p)) |
976 |
return client_p->name; |
977 |
|
978 |
if (MyConnect(client_p)) |
979 |
{ |
980 |
const dlink_node *const node = client_p->connection->confs.head; |
981 |
|
982 |
if (node) |
983 |
{ |
984 |
const struct MaskItem *const conf = node->data; |
985 |
|
986 |
if (conf->type == CONF_OPER) |
987 |
{ |
988 |
snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name, |
989 |
client_p->username, client_p->host, conf->name); |
990 |
return buffer; |
991 |
} |
992 |
} |
993 |
|
994 |
/* |
995 |
* Probably should assert here for now. If there is an oper out there |
996 |
* with no operator {} conf attached, it would be good for us to know... |
997 |
*/ |
998 |
assert(0); /* Oper without oper conf! */ |
999 |
} |
1000 |
|
1001 |
snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name, |
1002 |
client_p->username, client_p->host, client_p->servptr->name); |
1003 |
return buffer; |
1004 |
} |
1005 |
|
1006 |
/* clear_out_old_conf() |
1007 |
* |
1008 |
* inputs - none |
1009 |
* output - none |
1010 |
* side effects - Clear out the old configuration |
1011 |
*/ |
1012 |
static void |
1013 |
clear_out_old_conf(void) |
1014 |
{ |
1015 |
dlink_node *node = NULL, *node_next = NULL; |
1016 |
dlink_list *free_items [] = { |
1017 |
&server_items, &operator_items, NULL |
1018 |
}; |
1019 |
|
1020 |
dlink_list ** iterator = free_items; /* C is dumb */ |
1021 |
|
1022 |
/* We only need to free anything allocated by yyparse() here. |
1023 |
* Resetting structs, etc, is taken care of by set_default_conf(). |
1024 |
*/ |
1025 |
|
1026 |
for (; *iterator; iterator++) |
1027 |
{ |
1028 |
DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head) |
1029 |
{ |
1030 |
struct MaskItem *conf = node->data; |
1031 |
|
1032 |
conf->active = 0; |
1033 |
dlinkDelete(&conf->node, *iterator); |
1034 |
|
1035 |
if (!conf->ref_count) |
1036 |
conf_free(conf); |
1037 |
} |
1038 |
} |
1039 |
|
1040 |
motd_clear(); /* Clear motd {} items and re-cache default motd */ |
1041 |
|
1042 |
/* |
1043 |
* Don't delete the class table, rather mark all entries for deletion. |
1044 |
* The table is cleaned up by class_delete_marked. - avalon |
1045 |
*/ |
1046 |
class_mark_for_deletion(); |
1047 |
|
1048 |
clear_out_address_conf(); |
1049 |
|
1050 |
modules_conf_clear(); /* Clear modules {} items */ |
1051 |
|
1052 |
motd_clear(); /* Clear motd {} items and re-cache default motd */ |
1053 |
|
1054 |
cluster_clear(); /* Clear cluster {} items */ |
1055 |
|
1056 |
gecos_clear(); /* Clear gecos {} items */ |
1057 |
|
1058 |
resv_clear(); /* Clear resv {} items */ |
1059 |
|
1060 |
service_clear(); /* Clear service {} items */ |
1061 |
|
1062 |
shared_clear(); /* Clear shared {} items */ |
1063 |
|
1064 |
pseudo_clear(); /* Clear pseudo {} items */ |
1065 |
|
1066 |
#ifdef HAVE_LIBGEOIP |
1067 |
GeoIP_delete(GeoIPv4_ctx); |
1068 |
GeoIPv4_ctx = NULL; |
1069 |
GeoIP_delete(GeoIPv6_ctx); |
1070 |
GeoIPv6_ctx = NULL; |
1071 |
#endif |
1072 |
|
1073 |
/* Clean out ConfigServerInfo */ |
1074 |
xfree(ConfigServerInfo.description); |
1075 |
ConfigServerInfo.description = NULL; |
1076 |
xfree(ConfigServerInfo.network_name); |
1077 |
ConfigServerInfo.network_name = NULL; |
1078 |
xfree(ConfigServerInfo.network_desc); |
1079 |
ConfigServerInfo.network_desc = NULL; |
1080 |
xfree(ConfigServerInfo.libgeoip_ipv6_database_file); |
1081 |
ConfigServerInfo.libgeoip_ipv6_database_file = NULL; |
1082 |
xfree(ConfigServerInfo.libgeoip_ipv4_database_file); |
1083 |
ConfigServerInfo.libgeoip_ipv4_database_file = NULL; |
1084 |
xfree(ConfigServerInfo.rsa_private_key_file); |
1085 |
ConfigServerInfo.rsa_private_key_file = NULL; |
1086 |
xfree(ConfigServerInfo.ssl_certificate_file); |
1087 |
ConfigServerInfo.ssl_certificate_file = NULL; |
1088 |
xfree(ConfigServerInfo.ssl_dh_param_file); |
1089 |
ConfigServerInfo.ssl_dh_param_file = NULL; |
1090 |
xfree(ConfigServerInfo.ssl_dh_elliptic_curve); |
1091 |
ConfigServerInfo.ssl_dh_elliptic_curve = NULL; |
1092 |
xfree(ConfigServerInfo.ssl_cipher_list); |
1093 |
ConfigServerInfo.ssl_cipher_list = NULL; |
1094 |
xfree(ConfigServerInfo.ssl_message_digest_algorithm); |
1095 |
ConfigServerInfo.ssl_message_digest_algorithm = NULL; |
1096 |
|
1097 |
/* Clean out ConfigAdminInfo */ |
1098 |
xfree(ConfigAdminInfo.name); |
1099 |
ConfigAdminInfo.name = NULL; |
1100 |
xfree(ConfigAdminInfo.email); |
1101 |
ConfigAdminInfo.email = NULL; |
1102 |
xfree(ConfigAdminInfo.description); |
1103 |
ConfigAdminInfo.description = NULL; |
1104 |
|
1105 |
xfree(ConfigServerHide.flatten_links_file); |
1106 |
ConfigServerHide.flatten_links_file = NULL; |
1107 |
|
1108 |
/* Clean out listeners */ |
1109 |
listener_close_marked(); |
1110 |
} |
1111 |
|
1112 |
static void |
1113 |
conf_handle_tls(int cold) |
1114 |
{ |
1115 |
if (!tls_new_cred()) |
1116 |
{ |
1117 |
if (cold) |
1118 |
{ |
1119 |
ilog(LOG_TYPE_IRCD, "Error while initializing TLS"); |
1120 |
exit(EXIT_FAILURE); |
1121 |
} |
1122 |
else |
1123 |
{ |
1124 |
/* Failed to load new settings/certs, old ones remain active */ |
1125 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
1126 |
"Error reloading TLS settings, check the ircd log"); // report_crypto_errors logs this |
1127 |
} |
1128 |
} |
1129 |
} |
1130 |
|
1131 |
/* read_conf_files() |
1132 |
* |
1133 |
* inputs - cold start YES or NO |
1134 |
* output - none |
1135 |
* side effects - read all conf files needed, ircd.conf kline.conf etc. |
1136 |
*/ |
1137 |
void |
1138 |
read_conf_files(int cold) |
1139 |
{ |
1140 |
const char *filename = NULL; |
1141 |
char chanmodes[IRCD_BUFSIZE] = ""; |
1142 |
char chanlimit[IRCD_BUFSIZE] = ""; |
1143 |
|
1144 |
conf_parser_ctx.boot = cold; |
1145 |
filename = ConfigGeneral.configfile; |
1146 |
|
1147 |
/* We need to know the initial filename for the yyerror() to report |
1148 |
FIXME: The full path is in conffilenamebuf first time since we |
1149 |
don't know anything else |
1150 |
|
1151 |
- Gozem 2002-07-21 |
1152 |
*/ |
1153 |
strlcpy(conffilebuf, filename, sizeof(conffilebuf)); |
1154 |
|
1155 |
if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL) |
1156 |
{ |
1157 |
if (cold) |
1158 |
{ |
1159 |
ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s", |
1160 |
filename, strerror(errno)); |
1161 |
exit(EXIT_FAILURE); |
1162 |
} |
1163 |
else |
1164 |
{ |
1165 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1166 |
"Unable to read configuration file '%s': %s", |
1167 |
filename, strerror(errno)); |
1168 |
return; |
1169 |
} |
1170 |
} |
1171 |
|
1172 |
if (!cold) |
1173 |
clear_out_old_conf(); |
1174 |
|
1175 |
read_conf(conf_parser_ctx.conf_file); |
1176 |
fclose(conf_parser_ctx.conf_file); |
1177 |
|
1178 |
log_reopen_all(); |
1179 |
conf_handle_tls(cold); |
1180 |
|
1181 |
isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length); |
1182 |
isupport_add("NETWORK", ConfigServerInfo.network_name, -1); |
1183 |
|
1184 |
snprintf(chanmodes, sizeof(chanmodes), "beI:%u", ConfigChannel.max_bans); |
1185 |
isupport_add("MAXLIST", chanmodes, -1); |
1186 |
isupport_add("MAXTARGETS", NULL, ConfigGeneral.max_targets); |
1187 |
isupport_add("CHANTYPES", "#", -1); |
1188 |
|
1189 |
snprintf(chanlimit, sizeof(chanlimit), "#:%u", |
1190 |
ConfigChannel.max_channels); |
1191 |
isupport_add("CHANLIMIT", chanlimit, -1); |
1192 |
snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstCMORST"); |
1193 |
isupport_add("CHANNELLEN", NULL, CHANNELLEN); |
1194 |
isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length); |
1195 |
isupport_add("CHANMODES", chanmodes, -1); |
1196 |
|
1197 |
/* |
1198 |
* message_locale may have changed. rebuild isupport since it relies |
1199 |
* on strlen(form_str(RPL_ISUPPORT)) |
1200 |
*/ |
1201 |
isupport_rebuild(); |
1202 |
} |
1203 |
|
1204 |
/* conf_add_class_to_conf() |
1205 |
* |
1206 |
* inputs - pointer to config item |
1207 |
* output - NONE |
1208 |
* side effects - Add a class pointer to a conf |
1209 |
*/ |
1210 |
void |
1211 |
conf_add_class_to_conf(struct MaskItem *conf, const char *name) |
1212 |
{ |
1213 |
if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL) |
1214 |
{ |
1215 |
conf->class = class_default; |
1216 |
|
1217 |
if (conf->type == CONF_CLIENT || conf->type == CONF_OPER) |
1218 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1219 |
"Warning *** Defaulting to default class for %s@%s", |
1220 |
conf->user, conf->host); |
1221 |
else |
1222 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1223 |
"Warning *** Defaulting to default class for %s", |
1224 |
conf->name); |
1225 |
} |
1226 |
} |
1227 |
|
1228 |
/* yyerror() |
1229 |
* |
1230 |
* inputs - message from parser |
1231 |
* output - NONE |
1232 |
* side effects - message to opers and log file entry is made |
1233 |
*/ |
1234 |
void |
1235 |
yyerror(const char *msg) |
1236 |
{ |
1237 |
char newlinebuf[IRCD_BUFSIZE]; |
1238 |
|
1239 |
if (conf_parser_ctx.pass != 1) |
1240 |
return; |
1241 |
|
1242 |
strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf)); |
1243 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1244 |
"\"%s\", line %u: %s: %s", |
1245 |
conffilebuf, lineno + 1, msg, newlinebuf); |
1246 |
ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s", |
1247 |
conffilebuf, lineno + 1, msg, newlinebuf); |
1248 |
} |
1249 |
|
1250 |
void |
1251 |
conf_error_report(const char *msg) |
1252 |
{ |
1253 |
char newlinebuf[IRCD_BUFSIZE]; |
1254 |
|
1255 |
strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf)); |
1256 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
1257 |
"\"%s\", line %u: %s: %s", |
1258 |
conffilebuf, lineno + 1, msg, newlinebuf); |
1259 |
ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s", |
1260 |
conffilebuf, lineno + 1, msg, newlinebuf); |
1261 |
} |
1262 |
|
1263 |
/* |
1264 |
* valid_tkline() |
1265 |
* |
1266 |
* inputs - pointer to ascii string to check |
1267 |
* - whether the specified time is in seconds or minutes |
1268 |
* output - -1 not enough parameters |
1269 |
* - 0 if not an integer number, else the number |
1270 |
* side effects - none |
1271 |
* Originally written by Dianora (Diane, db@db.net) |
1272 |
*/ |
1273 |
uintmax_t |
1274 |
valid_tkline(const char *data, const int minutes) |
1275 |
{ |
1276 |
const unsigned char *p = (const unsigned char *)data; |
1277 |
unsigned char tmpch = '\0'; |
1278 |
uintmax_t result = 0; |
1279 |
|
1280 |
while ((tmpch = *p++)) |
1281 |
{ |
1282 |
if (!IsDigit(tmpch)) |
1283 |
return 0; |
1284 |
|
1285 |
result *= 10; |
1286 |
result += (tmpch & 0xF); |
1287 |
} |
1288 |
|
1289 |
/* |
1290 |
* In the degenerate case where oper does a /quote kline 0 user@host :reason |
1291 |
* i.e. they specifically use 0, I am going to return 1 instead as a return |
1292 |
* value of non-zero is used to flag it as a temporary kline |
1293 |
*/ |
1294 |
if (result == 0) |
1295 |
result = 1; |
1296 |
|
1297 |
/* |
1298 |
* If the incoming time is in seconds convert it to minutes for the purpose |
1299 |
* of this calculation |
1300 |
*/ |
1301 |
if (!minutes) |
1302 |
result = result / 60; |
1303 |
|
1304 |
if (result > MAX_TDKLINE_TIME) |
1305 |
result = MAX_TDKLINE_TIME; |
1306 |
|
1307 |
result = result * 60; /* Turn it into seconds */ |
1308 |
|
1309 |
return result; |
1310 |
} |
1311 |
|
1312 |
/* valid_wild_card_simple() |
1313 |
* |
1314 |
* inputs - data to check for sufficient non-wildcard characters |
1315 |
* outputs - 1 if valid, else 0 |
1316 |
* side effects - none |
1317 |
*/ |
1318 |
int |
1319 |
valid_wild_card_simple(const char *data) |
1320 |
{ |
1321 |
const unsigned char *p = (const unsigned char *)data; |
1322 |
unsigned char tmpch = '\0'; |
1323 |
unsigned int nonwild = 0, wild = 0; |
1324 |
|
1325 |
while ((tmpch = *p++)) |
1326 |
{ |
1327 |
if (tmpch == '\\' && *p) |
1328 |
{ |
1329 |
++p; |
1330 |
if (++nonwild >= ConfigGeneral.min_nonwildcard_simple) |
1331 |
return 1; |
1332 |
} |
1333 |
else if (!IsMWildChar(tmpch)) |
1334 |
{ |
1335 |
if (++nonwild >= ConfigGeneral.min_nonwildcard_simple) |
1336 |
return 1; |
1337 |
} |
1338 |
else |
1339 |
++wild; |
1340 |
} |
1341 |
|
1342 |
return !wild; |
1343 |
} |
1344 |
|
1345 |
/* valid_wild_card() |
1346 |
* |
1347 |
* input - pointer to client |
1348 |
* - int flag, 0 for no warning oper 1 for warning oper |
1349 |
* - count of following varargs to check |
1350 |
* output - 0 if not valid, 1 if valid |
1351 |
* side effects - NOTICE is given to source_p if warn is 1 |
1352 |
*/ |
1353 |
int |
1354 |
valid_wild_card(struct Client *source_p, int count, ...) |
1355 |
{ |
1356 |
unsigned char tmpch = '\0'; |
1357 |
unsigned int nonwild = 0; |
1358 |
va_list args; |
1359 |
|
1360 |
/* |
1361 |
* Now we must check the user and host to make sure there |
1362 |
* are at least NONWILDCHARS non-wildcard characters in |
1363 |
* them, otherwise assume they are attempting to kline |
1364 |
* *@* or some variant of that. This code will also catch |
1365 |
* people attempting to kline *@*.tld, as long as NONWILDCHARS |
1366 |
* is greater than 3. In that case, there are only 3 non-wild |
1367 |
* characters (tld), so if NONWILDCHARS is 4, the kline will |
1368 |
* be disallowed. |
1369 |
* -wnder |
1370 |
*/ |
1371 |
|
1372 |
va_start(args, count); |
1373 |
|
1374 |
while (count--) |
1375 |
{ |
1376 |
const unsigned char *p = va_arg(args, const unsigned char *); |
1377 |
if (p == NULL) |
1378 |
continue; |
1379 |
|
1380 |
while ((tmpch = *p++)) |
1381 |
{ |
1382 |
if (!IsKWildChar(tmpch)) |
1383 |
{ |
1384 |
/* |
1385 |
* If we find enough non-wild characters, we can |
1386 |
* break - no point in searching further. |
1387 |
*/ |
1388 |
if (++nonwild >= ConfigGeneral.min_nonwildcard) |
1389 |
{ |
1390 |
va_end(args); |
1391 |
return 1; |
1392 |
} |
1393 |
} |
1394 |
} |
1395 |
} |
1396 |
|
1397 |
if (IsClient(source_p)) |
1398 |
sendto_one_notice(source_p, &me, |
1399 |
":Please include at least %u non-wildcard characters with the mask", |
1400 |
ConfigGeneral.min_nonwildcard); |
1401 |
va_end(args); |
1402 |
return 0; |
1403 |
} |
1404 |
|
1405 |
/* find_user_host() |
1406 |
* |
1407 |
* inputs - pointer to client placing kline |
1408 |
* - pointer to user_host_or_nick |
1409 |
* - pointer to user buffer |
1410 |
* - pointer to host buffer |
1411 |
* output - 0 if not ok to kline, 1 to kline i.e. if valid user host |
1412 |
* side effects - |
1413 |
*/ |
1414 |
static int |
1415 |
find_user_host(struct Client *source_p, char *user_host_or_nick, |
1416 |
char *luser, char *lhost) |
1417 |
{ |
1418 |
struct Client *target_p = NULL; |
1419 |
char *hostp = NULL; |
1420 |
|
1421 |
if (lhost == NULL) |
1422 |
{ |
1423 |
strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); |
1424 |
return 1; |
1425 |
} |
1426 |
|
1427 |
if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*') |
1428 |
{ |
1429 |
/* Explicit user@host mask given */ |
1430 |
if (hostp) /* I'm a little user@host */ |
1431 |
{ |
1432 |
*(hostp++) = '\0'; /* short and squat */ |
1433 |
|
1434 |
if (*user_host_or_nick) |
1435 |
strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */ |
1436 |
else |
1437 |
strcpy(luser, "*"); |
1438 |
|
1439 |
if (*hostp) |
1440 |
strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */ |
1441 |
else |
1442 |
strcpy(lhost, "*"); |
1443 |
} |
1444 |
else |
1445 |
{ |
1446 |
luser[0] = '*'; /* no @ found, assume its *@somehost */ |
1447 |
luser[1] = '\0'; |
1448 |
strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1); |
1449 |
} |
1450 |
|
1451 |
return 1; |
1452 |
} |
1453 |
else |
1454 |
{ |
1455 |
/* Try to find user@host mask from nick */ |
1456 |
/* Okay to use source_p as the first param, because source_p == client_p */ |
1457 |
if ((target_p = |
1458 |
find_chasing(source_p, user_host_or_nick)) == NULL) |
1459 |
return 0; /* find_chasing sends ERR_NOSUCHNICK */ |
1460 |
|
1461 |
if (HasFlag(target_p, FLAGS_EXEMPTKLINE)) |
1462 |
{ |
1463 |
if (IsClient(source_p)) |
1464 |
sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name); |
1465 |
return 0; |
1466 |
} |
1467 |
|
1468 |
/* |
1469 |
* Turn the "user" bit into "*user", blow away '~' |
1470 |
* if found in original user name (non-idented) |
1471 |
*/ |
1472 |
strlcpy(luser, target_p->username, USERLEN*4 + 1); |
1473 |
|
1474 |
if (target_p->username[0] == '~') |
1475 |
luser[0] = '*'; |
1476 |
|
1477 |
strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1); |
1478 |
return 1; |
1479 |
} |
1480 |
|
1481 |
return 0; |
1482 |
} |
1483 |
|
1484 |
/* XXX should this go into a separate file ? -Dianora */ |
1485 |
/* parse_aline |
1486 |
* |
1487 |
* input - pointer to cmd name being used |
1488 |
* - pointer to client using cmd |
1489 |
* - parc parameter count |
1490 |
* - parv[] list of parameters to parse |
1491 |
* - parse_flags bit map of things to test |
1492 |
* - pointer to user or string to parse into |
1493 |
* - pointer to host or NULL to parse into if non NULL |
1494 |
* - pointer to optional tkline time or NULL |
1495 |
* - pointer to target_server to parse into if non NULL |
1496 |
* - pointer to reason to parse into |
1497 |
* |
1498 |
* output - 1 if valid, 0 if not valid |
1499 |
* side effects - A generalised k/d/x etc. line parser, |
1500 |
* "ALINE [time] user@host|string [ON] target :reason" |
1501 |
* will parse returning a parsed user, host if |
1502 |
* h_p pointer is non NULL, string otherwise. |
1503 |
* if tkline_time pointer is non NULL a tk line will be set |
1504 |
* to non zero if found. |
1505 |
* if tkline_time pointer is NULL and tk line is found, |
1506 |
* error is reported. |
1507 |
* if target_server is NULL and an "ON" is found error |
1508 |
* is reported. |
1509 |
* if reason pointer is NULL ignore pointer, |
1510 |
* this allows use of parse_a_line in unkline etc. |
1511 |
* |
1512 |
* - Dianora |
1513 |
*/ |
1514 |
int |
1515 |
parse_aline(const char *cmd, struct Client *source_p, |
1516 |
int parc, char **parv, |
1517 |
int parse_flags, char **up_p, char **h_p, uintmax_t *tkline_time, |
1518 |
char **target_server, char **reason) |
1519 |
{ |
1520 |
int found_tkline_time=0; |
1521 |
static char default_reason[] = CONF_NOREASON; |
1522 |
static char user[USERLEN*4+1]; |
1523 |
static char host[HOSTLEN*4+1]; |
1524 |
|
1525 |
parv++; |
1526 |
parc--; |
1527 |
|
1528 |
found_tkline_time = valid_tkline(*parv, TK_MINUTES); |
1529 |
|
1530 |
if (found_tkline_time) |
1531 |
{ |
1532 |
parv++; |
1533 |
parc--; |
1534 |
|
1535 |
if (tkline_time) |
1536 |
*tkline_time = found_tkline_time; |
1537 |
else |
1538 |
{ |
1539 |
sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd); |
1540 |
return 0; |
1541 |
} |
1542 |
} |
1543 |
|
1544 |
if (parc == 0) |
1545 |
{ |
1546 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd); |
1547 |
return 0; |
1548 |
} |
1549 |
|
1550 |
if (h_p == NULL) |
1551 |
*up_p = *parv; |
1552 |
else |
1553 |
{ |
1554 |
if (find_user_host(source_p, *parv, user, host) == 0) |
1555 |
return 0; |
1556 |
|
1557 |
*up_p = user; |
1558 |
*h_p = host; |
1559 |
} |
1560 |
|
1561 |
parc--; |
1562 |
parv++; |
1563 |
|
1564 |
if (parc) |
1565 |
{ |
1566 |
if (irccmp(*parv, "ON") == 0) |
1567 |
{ |
1568 |
parc--; |
1569 |
parv++; |
1570 |
|
1571 |
if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN)) |
1572 |
{ |
1573 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban"); |
1574 |
return 0; |
1575 |
} |
1576 |
|
1577 |
if (parc == 0 || EmptyString(*parv)) |
1578 |
{ |
1579 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd); |
1580 |
return 0; |
1581 |
} |
1582 |
|
1583 |
*target_server = *parv; |
1584 |
parc--; |
1585 |
parv++; |
1586 |
} |
1587 |
else |
1588 |
{ |
1589 |
/* Make sure target_server *is* NULL if no ON server found |
1590 |
* caller probably NULL'd it first, but no harm to do it again -db |
1591 |
*/ |
1592 |
if (target_server) |
1593 |
*target_server = NULL; |
1594 |
} |
1595 |
} |
1596 |
|
1597 |
if (h_p) |
1598 |
{ |
1599 |
if (strchr(user, '!')) |
1600 |
{ |
1601 |
sendto_one_notice(source_p, &me, ":Invalid character '!' in kline"); |
1602 |
return 0; |
1603 |
} |
1604 |
|
1605 |
if ((parse_flags & AWILD) && !valid_wild_card(source_p, 2, *up_p, *h_p)) |
1606 |
return 0; |
1607 |
} |
1608 |
else |
1609 |
if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, *up_p)) |
1610 |
return 0; |
1611 |
|
1612 |
if (reason) |
1613 |
{ |
1614 |
if (parc && !EmptyString(*parv)) |
1615 |
*reason = *parv; |
1616 |
else |
1617 |
*reason = default_reason; |
1618 |
} |
1619 |
|
1620 |
return 1; |
1621 |
} |
1622 |
|
1623 |
/* match_conf_password() |
1624 |
* |
1625 |
* inputs - pointer to given password |
1626 |
* - pointer to Conf |
1627 |
* output - 1 or 0 if match |
1628 |
* side effects - none |
1629 |
*/ |
1630 |
int |
1631 |
match_conf_password(const char *password, const struct MaskItem *conf) |
1632 |
{ |
1633 |
const char *encr = NULL; |
1634 |
|
1635 |
if (EmptyString(password) || EmptyString(conf->passwd)) |
1636 |
return 0; |
1637 |
|
1638 |
if (conf->flags & CONF_FLAGS_ENCRYPTED) |
1639 |
encr = crypt(password, conf->passwd); |
1640 |
else |
1641 |
encr = password; |
1642 |
|
1643 |
return encr && !strcmp(encr, conf->passwd); |
1644 |
} |
1645 |
|
1646 |
/* |
1647 |
* split_nuh |
1648 |
* |
1649 |
* inputs - pointer to original mask (modified in place) |
1650 |
* - pointer to pointer where nick should go |
1651 |
* - pointer to pointer where user should go |
1652 |
* - pointer to pointer where host should go |
1653 |
* output - NONE |
1654 |
* side effects - mask is modified in place |
1655 |
* If nick pointer is NULL, ignore writing to it |
1656 |
* this allows us to use this function elsewhere. |
1657 |
* |
1658 |
* mask nick user host |
1659 |
* ---------------------- ------- ------- ------ |
1660 |
* Dianora!db@db.net Dianora db db.net |
1661 |
* Dianora Dianora * * |
1662 |
* db.net * * db.net |
1663 |
* OR if nick pointer is NULL |
1664 |
* Dianora - * Dianora |
1665 |
* Dianora! Dianora * * |
1666 |
* Dianora!@ Dianora * * |
1667 |
* Dianora!db Dianora db * |
1668 |
* Dianora!@db.net Dianora * db.net |
1669 |
* db@db.net * db db.net |
1670 |
* !@ * * * |
1671 |
* @ * * * |
1672 |
* ! * * * |
1673 |
*/ |
1674 |
void |
1675 |
split_nuh(struct split_nuh_item *const iptr) |
1676 |
{ |
1677 |
char *p = NULL, *q = NULL; |
1678 |
|
1679 |
if (iptr->nickptr) |
1680 |
strlcpy(iptr->nickptr, "*", iptr->nicksize); |
1681 |
|
1682 |
if (iptr->userptr) |
1683 |
strlcpy(iptr->userptr, "*", iptr->usersize); |
1684 |
|
1685 |
if (iptr->hostptr) |
1686 |
strlcpy(iptr->hostptr, "*", iptr->hostsize); |
1687 |
|
1688 |
if ((p = strchr(iptr->nuhmask, '!'))) |
1689 |
{ |
1690 |
*p = '\0'; |
1691 |
|
1692 |
if (iptr->nickptr && *iptr->nuhmask) |
1693 |
strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize); |
1694 |
|
1695 |
if ((q = strchr(++p, '@'))) |
1696 |
{ |
1697 |
*q++ = '\0'; |
1698 |
|
1699 |
if (*p) |
1700 |
strlcpy(iptr->userptr, p, iptr->usersize); |
1701 |
|
1702 |
if (*q) |
1703 |
strlcpy(iptr->hostptr, q, iptr->hostsize); |
1704 |
} |
1705 |
else |
1706 |
{ |
1707 |
if (*p) |
1708 |
strlcpy(iptr->userptr, p, iptr->usersize); |
1709 |
} |
1710 |
} |
1711 |
else |
1712 |
{ |
1713 |
/* No ! found so lets look for a user@host */ |
1714 |
if ((p = strchr(iptr->nuhmask, '@'))) |
1715 |
{ |
1716 |
/* if found a @ */ |
1717 |
*p++ = '\0'; |
1718 |
|
1719 |
if (*iptr->nuhmask) |
1720 |
strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize); |
1721 |
|
1722 |
if (*p) |
1723 |
strlcpy(iptr->hostptr, p, iptr->hostsize); |
1724 |
} |
1725 |
else |
1726 |
{ |
1727 |
/* No @ found */ |
1728 |
if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:")) |
1729 |
strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize); |
1730 |
else |
1731 |
strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize); |
1732 |
} |
1733 |
} |
1734 |
} |