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