ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/conf.c
Revision: 7623
Committed: Thu Jun 23 12:42:04 2016 UTC (7 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 44834 byte(s)
Log Message:
- Change userhost.c to deal with ip addresses only. Also we no longer care about usernames/ident replies.
  Due to the hash function in hash.c not ideal for ip addresses, we'll be using either iphash.c, or
  patricia.c soon for this.

File Contents

# Content
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 #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 get_client_name(source_p, SHOW_IP),
344 source_p->sockhost);
345 ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
346 get_client_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 get_client_name(source_p, SHOW_IP),
355 source_p->sockhost);
356 ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
357 get_client_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 get_client_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 get_client_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 /* attach_connect_block()
463 *
464 * inputs - pointer to server to attach
465 * - name of server
466 * - hostname of server
467 * output - true (1) if both are found, otherwise return false (0)
468 * side effects - find connect block and attach them to connecting client
469 */
470 int
471 attach_connect_block(struct Client *client_p, const char *name,
472 const char *host)
473 {
474 dlink_node *node = NULL;
475
476 assert(host);
477
478 DLINK_FOREACH(node, connect_items.head)
479 {
480 struct MaskItem *conf = node->data;
481
482 if (irccmp(conf->name, name) ||
483 irccmp(conf->host, host))
484 continue;
485
486 attach_conf(client_p, conf);
487 return 1;
488 }
489
490 return 0;
491 }
492
493 /* find_conf_name()
494 *
495 * inputs - pointer to conf link list to search
496 * - pointer to name to find
497 * - int mask of type of conf to find
498 * output - NULL or pointer to conf found
499 * side effects - find a conf entry which matches the name
500 * and has the given mask.
501 */
502 struct MaskItem *
503 find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
504 {
505 dlink_node *node = NULL;
506
507 DLINK_FOREACH(node, list->head)
508 {
509 struct MaskItem *conf = node->data;
510
511 if (conf->type == type)
512 {
513 if (conf->name && !irccmp(conf->name, name))
514 return conf;
515 }
516 }
517
518 return NULL;
519 }
520
521 /* find_matching_name_conf()
522 *
523 * inputs - type of link list to look in
524 * - pointer to name string to find
525 * - pointer to user
526 * - pointer to host
527 * - optional flags to match on as well
528 * output - NULL or pointer to found struct MaskItem
529 * side effects - looks for a match on name field
530 */
531 struct MaskItem *
532 connect_find(const char *name, const char *host, int (*compare)(const char *, const char *))
533 {
534 dlink_node *node = NULL;
535
536 DLINK_FOREACH(node, connect_items.head)
537 {
538 struct MaskItem *conf = node->data;
539
540 if (name && !compare(name, conf->name))
541 return conf;
542 if (host && !compare(host, conf->host))
543 return conf;
544 }
545
546 return NULL;
547 }
548
549 /* find_exact_name_conf()
550 *
551 * inputs - type of link list to look in
552 * - pointer to name string to find
553 * - pointer to user
554 * - pointer to host
555 * output - NULL or pointer to found struct MaskItem
556 * side effects - looks for an exact match on name field
557 */
558 struct MaskItem *
559 operator_find(const struct Client *who, const char *name)
560 {
561 dlink_node *node = NULL;
562
563 DLINK_FOREACH(node, operator_items.head)
564 {
565 struct MaskItem *conf = node->data;
566
567 if (!irccmp(conf->name, name))
568 {
569 if (!who)
570 return conf;
571
572 if (!match(conf->user, who->username))
573 {
574 switch (conf->htype)
575 {
576 case HM_HOST:
577 if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
578 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
579 return conf;
580 break;
581 case HM_IPV4:
582 if (who->connection->aftype == AF_INET)
583 if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits))
584 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
585 return conf;
586 break;
587 case HM_IPV6:
588 if (who->connection->aftype == AF_INET6)
589 if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits))
590 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
591 return conf;
592 break;
593 default:
594 assert(0);
595 }
596 }
597 }
598 }
599
600 return NULL;
601 }
602
603 /* set_default_conf()
604 *
605 * inputs - NONE
606 * output - NONE
607 * side effects - Set default values here.
608 * This is called **PRIOR** to parsing the
609 * configuration file. If you want to do some validation
610 * of values later, put them in validate_conf().
611 */
612 static void
613 set_default_conf(void)
614 {
615 /* verify init_class() ran, this should be an unnecessary check
616 * but its not much work.
617 */
618 assert(class_default == class_get_list()->tail->data);
619
620 ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
621 ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
622
623 memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip));
624 ConfigServerInfo.specific_ipv4_vhost = 0;
625 memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6));
626 ConfigServerInfo.specific_ipv6_vhost = 0;
627
628 ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX;
629 ConfigServerInfo.max_nick_length = 9;
630 ConfigServerInfo.max_topic_length = 80;
631 ConfigServerInfo.hub = 0;
632 ConfigServerInfo.libgeoip_database_options = 0;
633
634 log_del_all();
635
636 ConfigLog.use_logging = 1;
637
638 ConfigChannel.disable_fake_channels = 0;
639 ConfigChannel.invite_client_count = 10;
640 ConfigChannel.invite_client_time = 300;
641 ConfigChannel.invite_delay_channel = 5;
642 ConfigChannel.knock_client_count = 1;
643 ConfigChannel.knock_client_time = 300;
644 ConfigChannel.knock_delay_channel = 60;
645 ConfigChannel.max_channels = 25;
646 ConfigChannel.max_bans = 25;
647 ConfigChannel.default_join_flood_count = 18;
648 ConfigChannel.default_join_flood_time = 6;
649
650 ConfigServerHide.flatten_links = 0;
651 ConfigServerHide.flatten_links_delay = 300;
652 ConfigServerHide.hidden = 0;
653 ConfigServerHide.hide_servers = 0;
654 ConfigServerHide.hide_services = 0;
655 ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
656 ConfigServerHide.hide_server_ips = 0;
657 ConfigServerHide.disable_remote_commands = 0;
658
659 ConfigGeneral.away_count = 2;
660 ConfigGeneral.away_time = 10;
661 ConfigGeneral.max_watch = 50;
662 ConfigGeneral.whowas_history_length = 15000;
663 ConfigGeneral.cycle_on_host_change = 1;
664 ConfigGeneral.dline_min_cidr = 16;
665 ConfigGeneral.dline_min_cidr6 = 48;
666 ConfigGeneral.kline_min_cidr = 16;
667 ConfigGeneral.kline_min_cidr6 = 48;
668 ConfigGeneral.invisible_on_connect = 1;
669 ConfigGeneral.tkline_expire_notices = 1;
670 ConfigGeneral.ignore_bogus_ts = 0;
671 ConfigGeneral.disable_auth = 0;
672 ConfigGeneral.kill_chase_time_limit = 90;
673 ConfigGeneral.default_floodcount = 8;
674 ConfigGeneral.failed_oper_notice = 1;
675 ConfigGeneral.dots_in_ident = 0;
676 ConfigGeneral.min_nonwildcard = 4;
677 ConfigGeneral.min_nonwildcard_simple = 3;
678 ConfigGeneral.max_accept = 50;
679 ConfigGeneral.anti_nick_flood = 0;
680 ConfigGeneral.max_nick_time = 20;
681 ConfigGeneral.max_nick_changes = 5;
682 ConfigGeneral.anti_spam_exit_message_time = 0;
683 ConfigGeneral.ts_warn_delta = 30;
684 ConfigGeneral.ts_max_delta = 600;
685 ConfigGeneral.warn_no_connect_block = 1;
686 ConfigGeneral.stats_e_disabled = 0;
687 ConfigGeneral.stats_i_oper_only = 1; /* 1 = masked */
688 ConfigGeneral.stats_k_oper_only = 1; /* 1 = masked */
689 ConfigGeneral.stats_o_oper_only = 1;
690 ConfigGeneral.stats_m_oper_only = 1;
691 ConfigGeneral.stats_P_oper_only = 0;
692 ConfigGeneral.stats_u_oper_only = 0;
693 ConfigGeneral.caller_id_wait = 60;
694 ConfigGeneral.opers_bypass_callerid = 0;
695 ConfigGeneral.pace_wait = 10;
696 ConfigGeneral.pace_wait_simple = 1;
697 ConfigGeneral.short_motd = 0;
698 ConfigGeneral.ping_cookie = 0;
699 ConfigGeneral.no_oper_flood = 0;
700 ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT;
701 ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT |
702 UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE |
703 UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN;
704 ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP;
705 ConfigGeneral.throttle_count = 1;
706 ConfigGeneral.throttle_time = 1;
707 }
708
709 static void
710 validate_conf(void)
711 {
712 if (EmptyString(ConfigServerInfo.network_name))
713 ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
714
715 if (EmptyString(ConfigServerInfo.network_desc))
716 ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
717 }
718
719 /* read_conf()
720 *
721 * inputs - file descriptor pointing to config file to use
722 * output - None
723 * side effects - Read configuration file.
724 */
725 static void
726 read_conf(FILE *file)
727 {
728 lineno = 0;
729
730 set_default_conf(); /* Set default values prior to conf parsing */
731 conf_parser_ctx.pass = 1;
732 yyparse(); /* Pick up the classes first */
733
734 rewind(file);
735
736 conf_parser_ctx.pass = 2;
737 yyparse(); /* Load the values from the conf */
738 validate_conf(); /* Check to make sure some values are still okay. */
739 /* Some global values are also loaded here. */
740 whowas_trim(); /* Attempt to trim whowas list if necessary */
741 class_delete_marked(); /* Delete unused classes that are marked for deletion */
742 }
743
744 /* conf_rehash()
745 *
746 * Actual REHASH service routine. Called with sig == 0 if it has been called
747 * as a result of an operator issuing this command, else assume it has been
748 * called as a result of the server receiving a HUP signal.
749 */
750 void
751 conf_rehash(int sig)
752 {
753 if (sig)
754 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
755 "Got signal SIGHUP, reloading configuration file(s)");
756
757 restart_resolver();
758
759 /* don't close listeners until we know we can go ahead with the rehash */
760
761 read_conf_files(0);
762
763 load_conf_modules();
764 check_conf_klines();
765 }
766
767 /* lookup_confhost()
768 *
769 * start DNS lookups of all hostnames in the conf
770 * line and convert an IP addresses in a.b.c.d number for to IP#s.
771 */
772 void
773 lookup_confhost(struct MaskItem *conf)
774 {
775 struct addrinfo hints, *res;
776
777 /*
778 * Do name lookup now on hostnames given and store the
779 * ip numbers in conf structure.
780 */
781 memset(&hints, 0, sizeof(hints));
782
783 hints.ai_family = AF_UNSPEC;
784 hints.ai_socktype = SOCK_STREAM;
785
786 /* Get us ready for a bind() and don't bother doing dns lookup */
787 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
788
789 if (getaddrinfo(conf->host, NULL, &hints, &res))
790 {
791 conf_dns_lookup(conf);
792 return;
793 }
794
795 assert(res);
796
797 memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
798 conf->addr.ss_len = res->ai_addrlen;
799 conf->addr.ss.ss_family = res->ai_family;
800
801 freeaddrinfo(res);
802 }
803
804 /* conf_connect_allowed()
805 *
806 * inputs - pointer to inaddr
807 * - int type ipv4 or ipv6
808 * output - BANNED or accepted
809 * side effects - none
810 */
811 int
812 conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
813 {
814 struct ip_entry *ip_found = NULL;
815 const struct MaskItem *conf = find_dline_conf(addr, aftype);
816
817 if (conf)
818 {
819 /* DLINE exempt also gets you out of static limits/pacing... */
820 if (conf->type == CONF_EXEMPT)
821 return 0;
822 return BANNED_CLIENT;
823 }
824
825 ip_found = ipcache_find_or_add_address(addr);
826
827 if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
828 {
829 if (ip_found->connection_count >= ConfigGeneral.throttle_count)
830 return TOO_FAST;
831
832 ++ip_found->connection_count;
833 }
834 else
835 ip_found->connection_count = 1;
836
837 ip_found->last_attempt = CurrentTime;
838 return 0;
839 }
840
841 /* cleanup_tklines()
842 *
843 * inputs - NONE
844 * output - NONE
845 * side effects - call function to expire temporary k/d lines
846 * This is an event started off in ircd.c
847 */
848 void
849 cleanup_tklines(void *unused)
850 {
851 hostmask_expire_temporary();
852 gecos_expire();
853 resv_expire();
854 }
855
856 /* oper_privs_as_string()
857 *
858 * inputs - pointer to client_p
859 * output - pointer to static string showing oper privs
860 * side effects - return as string, the oper privs as derived from port
861 */
862 static const struct oper_flags
863 {
864 const unsigned int flag;
865 const unsigned char c;
866 } flag_table[] = {
867 { OPER_FLAG_ADMIN, 'A' },
868 { OPER_FLAG_CLOSE, 'B' },
869 { OPER_FLAG_CONNECT, 'C' },
870 { OPER_FLAG_CONNECT_REMOTE, 'D' },
871 { OPER_FLAG_DIE, 'E' },
872 { OPER_FLAG_DLINE, 'F' },
873 { OPER_FLAG_GLOBOPS, 'G' },
874 { OPER_FLAG_JOIN_RESV, 'H' },
875 { OPER_FLAG_KILL, 'I' },
876 { OPER_FLAG_KILL_REMOTE, 'J' },
877 { OPER_FLAG_KLINE, 'K' },
878 { OPER_FLAG_LOCOPS, 'L' },
879 { OPER_FLAG_MODULE, 'M' },
880 { OPER_FLAG_NICK_RESV, 'N' },
881 { OPER_FLAG_OPME, 'O' },
882 { OPER_FLAG_REHASH, 'P' },
883 { OPER_FLAG_REMOTEBAN, 'Q' },
884 { OPER_FLAG_RESTART, 'R' },
885 { OPER_FLAG_RESV, 'S' },
886 { OPER_FLAG_SET, 'T' },
887 { OPER_FLAG_SQUIT, 'U' },
888 { OPER_FLAG_SQUIT_REMOTE, 'V' },
889 { OPER_FLAG_UNDLINE, 'W' },
890 { OPER_FLAG_UNKLINE, 'X' },
891 { OPER_FLAG_UNRESV, 'Y' },
892 { OPER_FLAG_UNXLINE, 'Z' },
893 { OPER_FLAG_WALLOPS, 'a' },
894 { OPER_FLAG_XLINE, 'b' },
895 { 0, '\0' }
896 };
897
898 const char *
899 oper_privs_as_string(const unsigned int flags)
900 {
901 static char buf[sizeof(flag_table) / sizeof(struct oper_flags)];
902 char *p = buf;
903
904 for (const struct oper_flags *tab = flag_table; tab->flag; ++tab)
905 if (flags & tab->flag)
906 *p++ = tab->c;
907
908 if (p == buf)
909 *p++ = '0';
910
911 *p = '\0';
912
913 return buf;
914 }
915
916 /*
917 * Input: A client to find the active operator {} name for.
918 * Output: The nick!user@host{oper} of the oper.
919 * "oper" is server name for remote opers
920 * Side effects: None.
921 */
922 const char *
923 get_oper_name(const struct Client *client_p)
924 {
925 static char buffer[IRCD_BUFSIZE];
926
927 if (IsServer(client_p))
928 return client_p->name;
929
930 if (MyConnect(client_p))
931 {
932 const dlink_node *const node = client_p->connection->confs.head;
933
934 if (node)
935 {
936 const struct MaskItem *const conf = node->data;
937
938 if (conf->type == CONF_OPER)
939 {
940 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
941 client_p->username, client_p->host, conf->name);
942 return buffer;
943 }
944 }
945
946 /*
947 * Probably should assert here for now. If there is an oper out there
948 * with no operator {} conf attached, it would be good for us to know...
949 */
950 assert(0); /* Oper without oper conf! */
951 }
952
953 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
954 client_p->username, client_p->host, client_p->servptr->name);
955 return buffer;
956 }
957
958 /* clear_out_old_conf()
959 *
960 * inputs - none
961 * output - none
962 * side effects - Clear out the old configuration
963 */
964 static void
965 clear_out_old_conf(void)
966 {
967 dlink_node *node = NULL, *node_next = NULL;
968 dlink_list *free_items [] = {
969 &connect_items, &operator_items, NULL
970 };
971
972 dlink_list ** iterator = free_items; /* C is dumb */
973
974 /* We only need to free anything allocated by yyparse() here.
975 * Resetting structs, etc, is taken care of by set_default_conf().
976 */
977
978 for (; *iterator; iterator++)
979 {
980 DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head)
981 {
982 struct MaskItem *conf = node->data;
983
984 conf->active = 0;
985 dlinkDelete(&conf->node, *iterator);
986
987 if (!conf->ref_count)
988 conf_free(conf);
989 }
990 }
991
992 /*
993 * Don't delete the class table, rather mark all entries for deletion.
994 * The table is cleaned up by class_delete_marked. - avalon
995 */
996 class_mark_for_deletion();
997
998 clear_out_address_conf();
999
1000 modules_conf_clear(); /* Clear modules {} items */
1001
1002 motd_clear(); /* Clear motd {} items and re-cache default motd */
1003
1004 cluster_clear(); /* Clear cluster {} items */
1005
1006 gecos_clear(); /* Clear gecos {} items */
1007
1008 resv_clear(); /* Clear resv {} items */
1009
1010 service_clear(); /* Clear service {} items */
1011
1012 shared_clear(); /* Clear shared {} items */
1013
1014 pseudo_clear(); /* Clear pseudo {} items */
1015
1016 #ifdef HAVE_LIBGEOIP
1017 GeoIP_delete(GeoIPv4_ctx);
1018 GeoIPv4_ctx = NULL;
1019 GeoIP_delete(GeoIPv6_ctx);
1020 GeoIPv6_ctx = NULL;
1021 #endif
1022
1023 /* Clean out ConfigServerInfo */
1024 xfree(ConfigServerInfo.description);
1025 ConfigServerInfo.description = NULL;
1026 xfree(ConfigServerInfo.network_name);
1027 ConfigServerInfo.network_name = NULL;
1028 xfree(ConfigServerInfo.network_desc);
1029 ConfigServerInfo.network_desc = NULL;
1030 xfree(ConfigServerInfo.libgeoip_ipv6_database_file);
1031 ConfigServerInfo.libgeoip_ipv6_database_file = NULL;
1032 xfree(ConfigServerInfo.libgeoip_ipv4_database_file);
1033 ConfigServerInfo.libgeoip_ipv4_database_file = NULL;
1034 xfree(ConfigServerInfo.rsa_private_key_file);
1035 ConfigServerInfo.rsa_private_key_file = NULL;
1036 xfree(ConfigServerInfo.ssl_certificate_file);
1037 ConfigServerInfo.ssl_certificate_file = NULL;
1038 xfree(ConfigServerInfo.ssl_dh_param_file);
1039 ConfigServerInfo.ssl_dh_param_file = NULL;
1040 xfree(ConfigServerInfo.ssl_dh_elliptic_curve);
1041 ConfigServerInfo.ssl_dh_elliptic_curve = NULL;
1042 xfree(ConfigServerInfo.ssl_cipher_list);
1043 ConfigServerInfo.ssl_cipher_list = NULL;
1044 xfree(ConfigServerInfo.ssl_message_digest_algorithm);
1045 ConfigServerInfo.ssl_message_digest_algorithm = NULL;
1046
1047 /* Clean out ConfigAdminInfo */
1048 xfree(ConfigAdminInfo.name);
1049 ConfigAdminInfo.name = NULL;
1050 xfree(ConfigAdminInfo.email);
1051 ConfigAdminInfo.email = NULL;
1052 xfree(ConfigAdminInfo.description);
1053 ConfigAdminInfo.description = NULL;
1054
1055 xfree(ConfigServerHide.flatten_links_file);
1056 ConfigServerHide.flatten_links_file = NULL;
1057
1058 /* Clean out listeners */
1059 listener_close_marked();
1060 }
1061
1062 static void
1063 conf_handle_tls(int cold)
1064 {
1065 if (!tls_new_cred())
1066 {
1067 if (cold)
1068 {
1069 ilog(LOG_TYPE_IRCD, "Error while initializing TLS");
1070 exit(EXIT_FAILURE);
1071 }
1072 else
1073 {
1074 /* Failed to load new settings/certs, old ones remain active */
1075 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
1076 "Error reloading TLS settings, check the ircd log"); // report_crypto_errors logs this
1077 }
1078 }
1079 }
1080
1081 /* read_conf_files()
1082 *
1083 * inputs - cold start YES or NO
1084 * output - none
1085 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1086 */
1087 void
1088 read_conf_files(int cold)
1089 {
1090 const char *filename = NULL;
1091 char chanmodes[IRCD_BUFSIZE] = "";
1092 char chanlimit[IRCD_BUFSIZE] = "";
1093
1094 conf_parser_ctx.boot = cold;
1095 filename = ConfigGeneral.configfile;
1096
1097 /* We need to know the initial filename for the yyerror() to report
1098 FIXME: The full path is in conffilenamebuf first time since we
1099 don't know anything else
1100
1101 - Gozem 2002-07-21
1102 */
1103 strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1104
1105 if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1106 {
1107 if (cold)
1108 {
1109 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1110 filename, strerror(errno));
1111 exit(EXIT_FAILURE);
1112 }
1113 else
1114 {
1115 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1116 "Unable to read configuration file '%s': %s",
1117 filename, strerror(errno));
1118 return;
1119 }
1120 }
1121
1122 if (!cold)
1123 clear_out_old_conf();
1124
1125 read_conf(conf_parser_ctx.conf_file);
1126 fclose(conf_parser_ctx.conf_file);
1127
1128 log_reopen_all();
1129 conf_handle_tls(cold);
1130
1131 isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1132 isupport_add("NETWORK", ConfigServerInfo.network_name, -1);
1133
1134 snprintf(chanmodes, sizeof(chanmodes), "beI:%u", ConfigChannel.max_bans);
1135 isupport_add("MAXLIST", chanmodes, -1);
1136 isupport_add("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1137 isupport_add("CHANTYPES", "#", -1);
1138
1139 snprintf(chanlimit, sizeof(chanlimit), "#:%u",
1140 ConfigChannel.max_channels);
1141 isupport_add("CHANLIMIT", chanlimit, -1);
1142 snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstCMORST");
1143 isupport_add("CHANNELLEN", NULL, CHANNELLEN);
1144 isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1145 isupport_add("CHANMODES", chanmodes, -1);
1146 }
1147
1148 /* conf_add_class_to_conf()
1149 *
1150 * inputs - pointer to config item
1151 * output - NONE
1152 * side effects - Add a class pointer to a conf
1153 */
1154 void
1155 conf_add_class_to_conf(struct MaskItem *conf, const char *name)
1156 {
1157 if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL)
1158 {
1159 conf->class = class_default;
1160
1161 if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1162 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1163 "Warning *** Defaulting to default class for %s@%s",
1164 conf->user, conf->host);
1165 else
1166 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1167 "Warning *** Defaulting to default class for %s",
1168 conf->name);
1169 }
1170 }
1171
1172 /* yyerror()
1173 *
1174 * inputs - message from parser
1175 * output - NONE
1176 * side effects - message to opers and log file entry is made
1177 */
1178 void
1179 yyerror(const char *msg)
1180 {
1181 char newlinebuf[IRCD_BUFSIZE];
1182
1183 if (conf_parser_ctx.pass != 1)
1184 return;
1185
1186 strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1187 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1188 "\"%s\", line %u: %s: %s",
1189 conffilebuf, lineno + 1, msg, newlinebuf);
1190 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1191 conffilebuf, lineno + 1, msg, newlinebuf);
1192 }
1193
1194 void
1195 conf_error_report(const char *msg)
1196 {
1197 char newlinebuf[IRCD_BUFSIZE];
1198
1199 strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1200 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1201 "\"%s\", line %u: %s: %s",
1202 conffilebuf, lineno + 1, msg, newlinebuf);
1203 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1204 conffilebuf, lineno + 1, msg, newlinebuf);
1205 }
1206
1207 /*
1208 * valid_tkline()
1209 *
1210 * inputs - pointer to ascii string to check
1211 * - whether the specified time is in seconds or minutes
1212 * output - -1 not enough parameters
1213 * - 0 if not an integer number, else the number
1214 * side effects - none
1215 * Originally written by Dianora (Diane, db@db.net)
1216 */
1217 uintmax_t
1218 valid_tkline(const char *data, const int minutes)
1219 {
1220 const unsigned char *p = (const unsigned char *)data;
1221 unsigned char tmpch = '\0';
1222 uintmax_t result = 0;
1223
1224 while ((tmpch = *p++))
1225 {
1226 if (!IsDigit(tmpch))
1227 return 0;
1228
1229 result *= 10;
1230 result += (tmpch & 0xF);
1231 }
1232
1233 /*
1234 * In the degenerate case where oper does a /quote kline 0 user@host :reason
1235 * i.e. they specifically use 0, I am going to return 1 instead as a return
1236 * value of non-zero is used to flag it as a temporary kline
1237 */
1238 if (result == 0)
1239 result = 1;
1240
1241 /*
1242 * If the incoming time is in seconds convert it to minutes for the purpose
1243 * of this calculation
1244 */
1245 if (!minutes)
1246 result = result / 60;
1247
1248 if (result > MAX_TDKLINE_TIME)
1249 result = MAX_TDKLINE_TIME;
1250
1251 result = result * 60; /* Turn it into seconds */
1252
1253 return result;
1254 }
1255
1256 /* valid_wild_card_simple()
1257 *
1258 * inputs - data to check for sufficient non-wildcard characters
1259 * outputs - 1 if valid, else 0
1260 * side effects - none
1261 */
1262 int
1263 valid_wild_card_simple(const char *data)
1264 {
1265 const unsigned char *p = (const unsigned char *)data;
1266 unsigned char tmpch = '\0';
1267 unsigned int nonwild = 0, wild = 0;
1268
1269 while ((tmpch = *p++))
1270 {
1271 if (tmpch == '\\' && *p)
1272 {
1273 ++p;
1274 if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1275 return 1;
1276 }
1277 else if (!IsMWildChar(tmpch))
1278 {
1279 if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1280 return 1;
1281 }
1282 else
1283 ++wild;
1284 }
1285
1286 return !wild;
1287 }
1288
1289 /* valid_wild_card()
1290 *
1291 * input - pointer to client
1292 * - int flag, 0 for no warning oper 1 for warning oper
1293 * - count of following varargs to check
1294 * output - 0 if not valid, 1 if valid
1295 * side effects - NOTICE is given to source_p if warn is 1
1296 */
1297 int
1298 valid_wild_card(int count, ...)
1299 {
1300 unsigned char tmpch = '\0';
1301 unsigned int nonwild = 0;
1302 va_list args;
1303
1304 /*
1305 * Now we must check the user and host to make sure there
1306 * are at least NONWILDCHARS non-wildcard characters in
1307 * them, otherwise assume they are attempting to kline
1308 * *@* or some variant of that. This code will also catch
1309 * people attempting to kline *@*.tld, as long as NONWILDCHARS
1310 * is greater than 3. In that case, there are only 3 non-wild
1311 * characters (tld), so if NONWILDCHARS is 4, the kline will
1312 * be disallowed.
1313 * -wnder
1314 */
1315
1316 va_start(args, count);
1317
1318 while (count--)
1319 {
1320 const unsigned char *p = va_arg(args, const unsigned char *);
1321 if (p == NULL)
1322 continue;
1323
1324 while ((tmpch = *p++))
1325 {
1326 if (!IsKWildChar(tmpch))
1327 {
1328 /*
1329 * If we find enough non-wild characters, we can
1330 * break - no point in searching further.
1331 */
1332 if (++nonwild >= ConfigGeneral.min_nonwildcard)
1333 {
1334 va_end(args);
1335 return 1;
1336 }
1337 }
1338 }
1339 }
1340
1341 va_end(args);
1342 return 0;
1343 }
1344
1345 /* find_user_host()
1346 *
1347 * inputs - pointer to client placing kline
1348 * - pointer to user_host_or_nick
1349 * - pointer to user buffer
1350 * - pointer to host buffer
1351 * output - 0 if not ok to kline, 1 to kline i.e. if valid user host
1352 * side effects -
1353 */
1354 static int
1355 find_user_host(struct Client *source_p, char *user_host_or_nick,
1356 char *luser, char *lhost)
1357 {
1358 struct Client *target_p = NULL;
1359 char *hostp = NULL;
1360
1361 if (lhost == NULL)
1362 {
1363 strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1364 return 1;
1365 }
1366
1367 if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1368 {
1369 /* Explicit user@host mask given */
1370 if (hostp) /* I'm a little user@host */
1371 {
1372 *(hostp++) = '\0'; /* short and squat */
1373
1374 if (*user_host_or_nick)
1375 strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1376 else
1377 strcpy(luser, "*");
1378
1379 if (*hostp)
1380 strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */
1381 else
1382 strcpy(lhost, "*");
1383 }
1384 else
1385 {
1386 luser[0] = '*'; /* no @ found, assume its *@somehost */
1387 luser[1] = '\0';
1388 strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1389 }
1390
1391 return 1;
1392 }
1393 else
1394 {
1395 /* Try to find user@host mask from nick */
1396 /* Okay to use source_p as the first param, because source_p == client_p */
1397 if ((target_p =
1398 find_chasing(source_p, user_host_or_nick)) == NULL)
1399 return 0; /* find_chasing sends ERR_NOSUCHNICK */
1400
1401 if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
1402 {
1403 if (IsClient(source_p))
1404 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1405 return 0;
1406 }
1407
1408 /*
1409 * Turn the "user" bit into "*user", blow away '~'
1410 * if found in original user name (non-idented)
1411 */
1412 strlcpy(luser, target_p->username, USERLEN*4 + 1);
1413
1414 if (target_p->username[0] == '~')
1415 luser[0] = '*';
1416
1417 strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1418 return 1;
1419 }
1420
1421 return 0;
1422 }
1423
1424 /* XXX should this go into a separate file ? -Dianora */
1425 /* parse_aline
1426 *
1427 * input - pointer to cmd name being used
1428 * - pointer to client using cmd
1429 * - parc parameter count
1430 * - parv[] list of parameters to parse
1431 * - parse_flags bit map of things to test
1432 * - pointer to user or string to parse into
1433 * - pointer to host or NULL to parse into if non NULL
1434 * - pointer to optional tkline time or NULL
1435 * - pointer to target_server to parse into if non NULL
1436 * - pointer to reason to parse into
1437 *
1438 * output - 1 if valid, 0 if not valid
1439 * side effects - A generalised k/d/x etc. line parser,
1440 * "ALINE [time] user@host|string [ON] target :reason"
1441 * will parse returning a parsed user, host if
1442 * h_p pointer is non NULL, string otherwise.
1443 * if tkline_time pointer is non NULL a tk line will be set
1444 * to non zero if found.
1445 * if tkline_time pointer is NULL and tk line is found,
1446 * error is reported.
1447 * if target_server is NULL and an "ON" is found error
1448 * is reported.
1449 * if reason pointer is NULL ignore pointer,
1450 * this allows use of parse_a_line in unkline etc.
1451 *
1452 * - Dianora
1453 */
1454 int
1455 parse_aline(const char *cmd, struct Client *source_p,
1456 int parc, char **parv,
1457 char **up_p, char **h_p, uintmax_t *tkline_time,
1458 char **target_server, char **reason)
1459 {
1460 uintmax_t found_tkline_time=0;
1461 static char default_reason[] = CONF_NOREASON;
1462 static char user[USERLEN*4+1];
1463 static char host[HOSTLEN*4+1];
1464
1465 parv++;
1466 parc--;
1467
1468 found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1469
1470 if (found_tkline_time)
1471 {
1472 parv++;
1473 parc--;
1474
1475 if (tkline_time)
1476 *tkline_time = found_tkline_time;
1477 else
1478 {
1479 sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1480 return 0;
1481 }
1482 }
1483
1484 if (parc == 0)
1485 {
1486 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1487 return 0;
1488 }
1489
1490 if (h_p == NULL)
1491 *up_p = *parv;
1492 else
1493 {
1494 if (find_user_host(source_p, *parv, user, host) == 0)
1495 return 0;
1496
1497 *up_p = user;
1498 *h_p = host;
1499 }
1500
1501 parc--;
1502 parv++;
1503
1504 if (parc)
1505 {
1506 if (irccmp(*parv, "ON") == 0)
1507 {
1508 parc--;
1509 parv++;
1510
1511 if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1512 {
1513 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1514 return 0;
1515 }
1516
1517 if (parc == 0 || EmptyString(*parv))
1518 {
1519 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1520 return 0;
1521 }
1522
1523 *target_server = *parv;
1524 parc--;
1525 parv++;
1526 }
1527 else
1528 {
1529 /* Make sure target_server *is* NULL if no ON server found
1530 * caller probably NULL'd it first, but no harm to do it again -db
1531 */
1532 if (target_server)
1533 *target_server = NULL;
1534 }
1535 }
1536
1537 if (reason)
1538 {
1539 if (parc && !EmptyString(*parv))
1540 *reason = *parv;
1541 else
1542 *reason = default_reason;
1543 }
1544
1545 return 1;
1546 }
1547
1548 /* match_conf_password()
1549 *
1550 * inputs - pointer to given password
1551 * - pointer to Conf
1552 * output - 1 or 0 if match
1553 * side effects - none
1554 */
1555 int
1556 match_conf_password(const char *password, const struct MaskItem *conf)
1557 {
1558 const char *encr = NULL;
1559
1560 if (EmptyString(password) || EmptyString(conf->passwd))
1561 return 0;
1562
1563 if (conf->flags & CONF_FLAGS_ENCRYPTED)
1564 encr = crypt(password, conf->passwd);
1565 else
1566 encr = password;
1567
1568 return encr && !strcmp(encr, conf->passwd);
1569 }
1570
1571 /*
1572 * split_nuh
1573 *
1574 * inputs - pointer to original mask (modified in place)
1575 * - pointer to pointer where nick should go
1576 * - pointer to pointer where user should go
1577 * - pointer to pointer where host should go
1578 * output - NONE
1579 * side effects - mask is modified in place
1580 * If nick pointer is NULL, ignore writing to it
1581 * this allows us to use this function elsewhere.
1582 *
1583 * mask nick user host
1584 * ---------------------- ------- ------- ------
1585 * Dianora!db@db.net Dianora db db.net
1586 * Dianora Dianora * *
1587 * db.net * * db.net
1588 * OR if nick pointer is NULL
1589 * Dianora - * Dianora
1590 * Dianora! Dianora * *
1591 * Dianora!@ Dianora * *
1592 * Dianora!db Dianora db *
1593 * Dianora!@db.net Dianora * db.net
1594 * db@db.net * db db.net
1595 * !@ * * *
1596 * @ * * *
1597 * ! * * *
1598 */
1599 void
1600 split_nuh(struct split_nuh_item *const iptr)
1601 {
1602 char *p = NULL, *q = NULL;
1603
1604 if (iptr->nickptr)
1605 strlcpy(iptr->nickptr, "*", iptr->nicksize);
1606
1607 if (iptr->userptr)
1608 strlcpy(iptr->userptr, "*", iptr->usersize);
1609
1610 if (iptr->hostptr)
1611 strlcpy(iptr->hostptr, "*", iptr->hostsize);
1612
1613 if ((p = strchr(iptr->nuhmask, '!')))
1614 {
1615 *p = '\0';
1616
1617 if (iptr->nickptr && *iptr->nuhmask)
1618 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1619
1620 if ((q = strchr(++p, '@')))
1621 {
1622 *q++ = '\0';
1623
1624 if (*p)
1625 strlcpy(iptr->userptr, p, iptr->usersize);
1626
1627 if (*q)
1628 strlcpy(iptr->hostptr, q, iptr->hostsize);
1629 }
1630 else
1631 {
1632 if (*p)
1633 strlcpy(iptr->userptr, p, iptr->usersize);
1634 }
1635 }
1636 else
1637 {
1638 /* No ! found so lets look for a user@host */
1639 if ((p = strchr(iptr->nuhmask, '@')))
1640 {
1641 /* if found a @ */
1642 *p++ = '\0';
1643
1644 if (*iptr->nuhmask)
1645 strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
1646
1647 if (*p)
1648 strlcpy(iptr->hostptr, p, iptr->hostsize);
1649 }
1650 else
1651 {
1652 /* No @ found */
1653 if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
1654 strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
1655 else
1656 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1657 }
1658 }
1659 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision