ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 7403
Committed: Sun Mar 6 16:33:12 2016 UTC (9 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 45628 byte(s)
Log Message:
- Remove useless parameters from operator_find()

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

Properties

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