ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 8752
Committed: Tue Jan 1 11:07:01 2019 UTC (6 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 41058 byte(s)
Log Message:
- Update copyright years

File Contents

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

Properties

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