ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 3009
Committed: Wed Feb 19 11:45:36 2014 UTC (11 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 58920 byte(s)
Log Message:
- conf.c:get_oper_name(): constification

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
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 "s_serv.h"
32 #include "resv.h"
33 #include "channel.h"
34 #include "client.h"
35 #include "event.h"
36 #include "hook.h"
37 #include "irc_string.h"
38 #include "s_bsd.h"
39 #include "ircd.h"
40 #include "listener.h"
41 #include "hostmask.h"
42 #include "modules.h"
43 #include "numeric.h"
44 #include "fdlist.h"
45 #include "log.h"
46 #include "send.h"
47 #include "s_gline.h"
48 #include "memory.h"
49 #include "mempool.h"
50 #include "irc_res.h"
51 #include "userhost.h"
52 #include "s_user.h"
53 #include "channel_mode.h"
54 #include "parse.h"
55 #include "s_misc.h"
56 #include "conf_db.h"
57 #include "conf_class.h"
58 #include "motd.h"
59
60
61 struct config_server_hide ConfigServerHide;
62 struct config_file_entry ConfigFileEntry;
63 struct logging_entry ConfigLoggingEntry = { .use_logging = 1 };
64 struct server_info ServerInfo;
65 struct admin_info AdminInfo;
66
67 /* general conf items link list root, other than k lines etc. */
68 dlink_list service_items = { NULL, NULL, 0 };
69 dlink_list server_items = { NULL, NULL, 0 };
70 dlink_list cluster_items = { NULL, NULL, 0 };
71 dlink_list oconf_items = { NULL, NULL, 0 };
72 dlink_list uconf_items = { NULL, NULL, 0 };
73 dlink_list xconf_items = { NULL, NULL, 0 };
74 dlink_list nresv_items = { NULL, NULL, 0 };
75 dlink_list cresv_items = { NULL, NULL, 0 };
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 struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
83
84 /* internally defined functions */
85 static void read_conf(FILE *);
86 static void clear_out_old_conf(void);
87 static void expire_tklines(dlink_list *);
88 static void garbage_collect_ip_entries(void);
89 static int hash_ip(struct irc_ssaddr *);
90 static int verify_access(struct Client *);
91 static int attach_iline(struct Client *, struct MaskItem *);
92 static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
93 static dlink_list *map_to_list(enum maskitem_type);
94 static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
95
96
97 /* usually, with hash tables, you use a prime number...
98 * but in this case I am dealing with ip addresses,
99 * not ascii strings.
100 */
101 #define IP_HASH_SIZE 0x1000
102
103 struct ip_entry
104 {
105 struct irc_ssaddr ip;
106 unsigned int count;
107 time_t last_attempt;
108 struct ip_entry *next;
109 };
110
111 static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
112 static mp_pool_t *ip_entry_pool = NULL;
113 static int ip_entries_count = 0;
114
115
116 /* conf_dns_callback()
117 *
118 * inputs - pointer to struct MaskItem
119 * - pointer to DNSReply reply
120 * output - none
121 * side effects - called when resolver query finishes
122 * if the query resulted in a successful search, hp will contain
123 * a non-null pointer, otherwise hp will be null.
124 * if successful save hp in the conf item it was called with
125 */
126 static void
127 conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
128 {
129 struct MaskItem *conf = vptr;
130
131 conf->dns_pending = 0;
132
133 if (addr != NULL)
134 memcpy(&conf->addr, addr, sizeof(conf->addr));
135 else
136 conf->dns_failed = 1;
137 }
138
139 /* conf_dns_lookup()
140 *
141 * do a nameserver lookup of the conf host
142 * if the conf entry is currently doing a ns lookup do nothing, otherwise
143 * allocate a dns_query and start ns lookup.
144 */
145 static void
146 conf_dns_lookup(struct MaskItem *conf)
147 {
148 if (!conf->dns_pending)
149 {
150 conf->dns_pending = 1;
151 gethost_byname(conf_dns_callback, conf, conf->host);
152 }
153 }
154
155 struct MaskItem *
156 conf_make(enum maskitem_type type)
157 {
158 struct MaskItem *conf = MyMalloc(sizeof(*conf));
159 dlink_list *list = NULL;
160
161 conf->type = type;
162 conf->active = 1;
163 conf->aftype = AF_INET;
164
165 if ((list = map_to_list(type)))
166 dlinkAdd(conf, &conf->node, list);
167 return conf;
168 }
169
170 void
171 conf_free(struct MaskItem *conf)
172 {
173 dlink_node *ptr = NULL, *ptr_next = NULL;
174 dlink_list *list = NULL;
175
176 if (conf->node.next)
177 if ((list = map_to_list(conf->type)))
178 dlinkDelete(&conf->node, list);
179
180 MyFree(conf->name);
181
182 if (conf->dns_pending)
183 delete_resolver_queries(conf);
184 if (conf->passwd != NULL)
185 memset(conf->passwd, 0, strlen(conf->passwd));
186 if (conf->spasswd != NULL)
187 memset(conf->spasswd, 0, strlen(conf->spasswd));
188
189 conf->class = NULL;
190
191 MyFree(conf->passwd);
192 MyFree(conf->spasswd);
193 MyFree(conf->reason);
194 MyFree(conf->certfp);
195 MyFree(conf->user);
196 MyFree(conf->host);
197 #ifdef HAVE_LIBCRYPTO
198 MyFree(conf->cipher_list);
199
200 if (conf->rsa_public_key)
201 RSA_free(conf->rsa_public_key);
202 #endif
203 DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head)
204 {
205 MyFree(ptr->data);
206 dlinkDelete(ptr, &conf->hub_list);
207 free_dlink_node(ptr);
208 }
209
210 DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
211 {
212 MyFree(ptr->data);
213 dlinkDelete(ptr, &conf->leaf_list);
214 free_dlink_node(ptr);
215 }
216
217 DLINK_FOREACH_SAFE(ptr, ptr_next, conf->exempt_list.head)
218 {
219 struct exempt *exptr = ptr->data;
220
221 dlinkDelete(ptr, &conf->exempt_list);
222 MyFree(exptr->name);
223 MyFree(exptr->user);
224 MyFree(exptr->host);
225 MyFree(exptr);
226 }
227
228 MyFree(conf);
229 }
230
231 /* check_client()
232 *
233 * inputs - pointer to client
234 * output - 0 = Success
235 * NOT_AUTHORIZED (-1) = Access denied (no I line match)
236 * IRCD_SOCKET_ERROR (-2) = Bad socket.
237 * I_LINE_FULL (-3) = I-line is full
238 * TOO_MANY (-4) = Too many connections from hostname
239 * BANNED_CLIENT (-5) = K-lined
240 * side effects - Ordinary client access check.
241 * Look for conf lines which have the same
242 * status as the flags passed.
243 */
244 int
245 check_client(struct Client *source_p)
246 {
247 int i;
248
249 if ((i = verify_access(source_p)))
250 ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
251 source_p->name, source_p->sockhost);
252
253 switch (i)
254 {
255 case TOO_MANY:
256 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
257 "Too many on IP for %s (%s).",
258 get_client_name(source_p, SHOW_IP),
259 source_p->sockhost);
260 ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
261 get_client_name(source_p, SHOW_IP));
262 ++ServerStats.is_ref;
263 exit_client(source_p, &me, "No more connections allowed on that IP");
264 break;
265
266 case I_LINE_FULL:
267 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
268 "auth{} block is full for %s (%s).",
269 get_client_name(source_p, SHOW_IP),
270 source_p->sockhost);
271 ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
272 get_client_name(source_p, SHOW_IP));
273 ++ServerStats.is_ref;
274 exit_client(source_p, &me,
275 "No more connections allowed in your connection class");
276 break;
277
278 case NOT_AUTHORIZED:
279 ++ServerStats.is_ref;
280 /* jdc - lists server name & port connections are on */
281 /* a purely cosmetical change */
282 sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
283 "Unauthorized client connection from %s [%s] on [%s/%u].",
284 get_client_name(source_p, SHOW_IP),
285 source_p->sockhost,
286 source_p->localClient->listener->name,
287 source_p->localClient->listener->port);
288 ilog(LOG_TYPE_IRCD,
289 "Unauthorized client connection from %s on [%s/%u].",
290 get_client_name(source_p, SHOW_IP),
291 source_p->localClient->listener->name,
292 source_p->localClient->listener->port);
293
294 exit_client(source_p, &me, "You are not authorized to use this server");
295 break;
296
297 case BANNED_CLIENT:
298 exit_client(source_p, &me, "Banned");
299 ++ServerStats.is_ref;
300 break;
301
302 case 0:
303 default:
304 break;
305 }
306
307 return (i < 0 ? 0 : 1);
308 }
309
310 /* verify_access()
311 *
312 * inputs - pointer to client to verify
313 * output - 0 if success -'ve if not
314 * side effect - find the first (best) I line to attach.
315 */
316 static int
317 verify_access(struct Client *client_p)
318 {
319 struct MaskItem *conf = NULL;
320 char non_ident[USERLEN + 1] = { '~', '\0' };
321
322 if (IsGotId(client_p))
323 {
324 conf = find_address_conf(client_p->host, client_p->username,
325 &client_p->localClient->ip,
326 client_p->localClient->aftype,
327 client_p->localClient->passwd);
328 }
329 else
330 {
331 strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
332 conf = find_address_conf(client_p->host,non_ident,
333 &client_p->localClient->ip,
334 client_p->localClient->aftype,
335 client_p->localClient->passwd);
336 }
337
338 if (conf != NULL)
339 {
340 if (IsConfClient(conf))
341 {
342 if (IsConfRedir(conf))
343 {
344 sendto_one(client_p, form_str(RPL_REDIR),
345 me.name, client_p->name,
346 conf->name ? conf->name : "",
347 conf->port);
348 return NOT_AUTHORIZED;
349 }
350
351 if (IsConfDoIdentd(conf))
352 SetNeedId(client_p);
353
354 /* Thanks for spoof idea amm */
355 if (IsConfDoSpoofIp(conf))
356 {
357 if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf))
358 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
359 "%s spoofing: %s as %s",
360 client_p->name, client_p->host, conf->name);
361 strlcpy(client_p->host, conf->name, sizeof(client_p->host));
362 AddFlag(client_p, FLAGS_IP_SPOOFING | FLAGS_AUTH_SPOOF);
363 }
364
365 return attach_iline(client_p, conf);
366 }
367 else if (IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf)))
368 {
369 if (IsConfGline(conf))
370 sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
371 client_p->name);
372 sendto_one(client_p, ":%s NOTICE %s :*** Banned: %s",
373 me.name, client_p->name, conf->reason);
374 return BANNED_CLIENT;
375 }
376 }
377
378 return NOT_AUTHORIZED;
379 }
380
381 /* attach_iline()
382 *
383 * inputs - client pointer
384 * - conf pointer
385 * output -
386 * side effects - do actual attach
387 */
388 static int
389 attach_iline(struct Client *client_p, struct MaskItem *conf)
390 {
391 struct ClassItem *class = NULL;
392 struct ip_entry *ip_found;
393 int a_limit_reached = 0;
394 unsigned int local = 0, global = 0, ident = 0;
395
396 assert(conf->class);
397
398 ip_found = find_or_add_ip(&client_p->localClient->ip);
399 ip_found->count++;
400 SetIpHash(client_p);
401
402 class = conf->class;
403
404 count_user_host(client_p->username, client_p->host,
405 &global, &local, &ident);
406
407 /* XXX blah. go down checking the various silly limits
408 * setting a_limit_reached if any limit is reached.
409 * - Dianora
410 */
411 if (class->max_total != 0 && class->ref_count >= class->max_total)
412 a_limit_reached = 1;
413 else if (class->max_perip != 0 && ip_found->count > class->max_perip)
414 a_limit_reached = 1;
415 else if (class->max_local != 0 && local >= class->max_local)
416 a_limit_reached = 1;
417 else if (class->max_global != 0 && global >= class->max_global)
418 a_limit_reached = 1;
419 else if (class->max_ident != 0 && ident >= class->max_ident &&
420 client_p->username[0] != '~')
421 a_limit_reached = 1;
422
423 if (a_limit_reached)
424 {
425 if (!IsConfExemptLimits(conf))
426 return TOO_MANY; /* Already at maximum allowed */
427
428 sendto_one(client_p,
429 ":%s NOTICE %s :*** Your connection class is full, "
430 "but you have exceed_limit = yes;", me.name, client_p->name);
431 }
432
433 return attach_conf(client_p, conf);
434 }
435
436 /* init_ip_hash_table()
437 *
438 * inputs - NONE
439 * output - NONE
440 * side effects - allocate memory for ip_entry(s)
441 * - clear the ip hash table
442 */
443 void
444 init_ip_hash_table(void)
445 {
446 ip_entry_pool = mp_pool_new(sizeof(struct ip_entry), MP_CHUNK_SIZE_IP_ENTRY);
447 memset(ip_hash_table, 0, sizeof(ip_hash_table));
448 }
449
450 /* find_or_add_ip()
451 *
452 * inputs - pointer to struct irc_ssaddr
453 * output - pointer to a struct ip_entry
454 * side effects -
455 *
456 * If the ip # was not found, a new struct ip_entry is created, and the ip
457 * count set to 0.
458 */
459 static struct ip_entry *
460 find_or_add_ip(struct irc_ssaddr *ip_in)
461 {
462 struct ip_entry *ptr, *newptr;
463 int hash_index = hash_ip(ip_in), res;
464 struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
465 #ifdef IPV6
466 struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
467 #endif
468
469 for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
470 {
471 #ifdef IPV6
472 if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
473 continue;
474 if (ip_in->ss.ss_family == AF_INET6)
475 {
476 ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
477 res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
478 }
479 else
480 #endif
481 {
482 ptr_v4 = (struct sockaddr_in *)&ptr->ip;
483 res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
484 }
485 if (res == 0)
486 {
487 /* Found entry already in hash, return it. */
488 return ptr;
489 }
490 }
491
492 if (ip_entries_count >= 2 * hard_fdlimit)
493 garbage_collect_ip_entries();
494
495 newptr = mp_pool_get(ip_entry_pool);
496 memset(newptr, 0, sizeof(*newptr));
497 ip_entries_count++;
498 memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr));
499
500 newptr->next = ip_hash_table[hash_index];
501 ip_hash_table[hash_index] = newptr;
502
503 return newptr;
504 }
505
506 /* remove_one_ip()
507 *
508 * inputs - unsigned long IP address value
509 * output - NONE
510 * side effects - The ip address given, is looked up in ip hash table
511 * and number of ip#'s for that ip decremented.
512 * If ip # count reaches 0 and has expired,
513 * the struct ip_entry is returned to the ip_entry_heap
514 */
515 void
516 remove_one_ip(struct irc_ssaddr *ip_in)
517 {
518 struct ip_entry *ptr;
519 struct ip_entry *last_ptr = NULL;
520 int hash_index = hash_ip(ip_in), res;
521 struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
522 #ifdef IPV6
523 struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
524 #endif
525
526 for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
527 {
528 #ifdef IPV6
529 if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
530 continue;
531 if (ip_in->ss.ss_family == AF_INET6)
532 {
533 ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
534 res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
535 }
536 else
537 #endif
538 {
539 ptr_v4 = (struct sockaddr_in *)&ptr->ip;
540 res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
541 }
542 if (res)
543 continue;
544 if (ptr->count > 0)
545 ptr->count--;
546 if (ptr->count == 0 &&
547 (CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time)
548 {
549 if (last_ptr != NULL)
550 last_ptr->next = ptr->next;
551 else
552 ip_hash_table[hash_index] = ptr->next;
553
554 mp_pool_release(ptr);
555 ip_entries_count--;
556 return;
557 }
558 last_ptr = ptr;
559 }
560 }
561
562 /* hash_ip()
563 *
564 * input - pointer to an irc_inaddr
565 * output - integer value used as index into hash table
566 * side effects - hopefully, none
567 */
568 static int
569 hash_ip(struct irc_ssaddr *addr)
570 {
571 if (addr->ss.ss_family == AF_INET)
572 {
573 struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
574 int hash;
575 uint32_t ip;
576
577 ip = ntohl(v4->sin_addr.s_addr);
578 hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
579 return hash;
580 }
581 #ifdef IPV6
582 else
583 {
584 int hash;
585 struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
586 uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
587
588 hash = ip[0] ^ ip[3];
589 hash ^= hash >> 16;
590 hash ^= hash >> 8;
591 hash = hash & (IP_HASH_SIZE - 1);
592 return hash;
593 }
594 #else
595 return 0;
596 #endif
597 }
598
599 /* count_ip_hash()
600 *
601 * inputs - pointer to counter of number of ips hashed
602 * - pointer to memory used for ip hash
603 * output - returned via pointers input
604 * side effects - NONE
605 *
606 * number of hashed ip #'s is counted up, plus the amount of memory
607 * used in the hash.
608 */
609 void
610 count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored)
611 {
612 struct ip_entry *ptr;
613 int i;
614
615 *number_ips_stored = 0;
616 *mem_ips_stored = 0;
617
618 for (i = 0; i < IP_HASH_SIZE; i++)
619 {
620 for (ptr = ip_hash_table[i]; ptr; ptr = ptr->next)
621 {
622 *number_ips_stored += 1;
623 *mem_ips_stored += sizeof(struct ip_entry);
624 }
625 }
626 }
627
628 /* garbage_collect_ip_entries()
629 *
630 * input - NONE
631 * output - NONE
632 * side effects - free up all ip entries with no connections
633 */
634 static void
635 garbage_collect_ip_entries(void)
636 {
637 struct ip_entry *ptr;
638 struct ip_entry *last_ptr;
639 struct ip_entry *next_ptr;
640 int i;
641
642 for (i = 0; i < IP_HASH_SIZE; i++)
643 {
644 last_ptr = NULL;
645
646 for (ptr = ip_hash_table[i]; ptr; ptr = next_ptr)
647 {
648 next_ptr = ptr->next;
649
650 if (ptr->count == 0 &&
651 (CurrentTime - ptr->last_attempt) >= ConfigFileEntry.throttle_time)
652 {
653 if (last_ptr != NULL)
654 last_ptr->next = ptr->next;
655 else
656 ip_hash_table[i] = ptr->next;
657 mp_pool_release(ptr);
658 ip_entries_count--;
659 }
660 else
661 last_ptr = ptr;
662 }
663 }
664 }
665
666 /* detach_conf()
667 *
668 * inputs - pointer to client to detach
669 * - type of conf to detach
670 * output - 0 for success, -1 for failure
671 * side effects - Disassociate configuration from the client.
672 * Also removes a class from the list if marked for deleting.
673 */
674 void
675 detach_conf(struct Client *client_p, enum maskitem_type type)
676 {
677 dlink_node *ptr = NULL, *next_ptr = NULL;
678
679 DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head)
680 {
681 struct MaskItem *conf = ptr->data;
682
683 assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
684 assert(conf->ref_count > 0);
685 assert(conf->class->ref_count > 0);
686
687 if (!(conf->type & type))
688 continue;
689
690 dlinkDelete(ptr, &client_p->localClient->confs);
691 free_dlink_node(ptr);
692
693 if (conf->type == CONF_CLIENT)
694 remove_from_cidr_check(&client_p->localClient->ip, conf->class);
695
696 if (--conf->class->ref_count == 0 && conf->class->active == 0)
697 {
698 class_free(conf->class);
699 conf->class = NULL;
700 }
701
702 if (--conf->ref_count == 0 && conf->active == 0)
703 conf_free(conf);
704 }
705 }
706
707 /* attach_conf()
708 *
709 * inputs - client pointer
710 * - conf pointer
711 * output -
712 * side effects - Associate a specific configuration entry to a *local*
713 * client (this is the one which used in accepting the
714 * connection). Note, that this automatically changes the
715 * attachment if there was an old one...
716 */
717 int
718 attach_conf(struct Client *client_p, struct MaskItem *conf)
719 {
720 if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
721 return 1;
722
723 if (conf->type == CONF_CLIENT)
724 if (cidr_limit_reached(IsConfExemptLimits(conf),
725 &client_p->localClient->ip, conf->class))
726 return TOO_MANY; /* Already at maximum allowed */
727
728 conf->class->ref_count++;
729 conf->ref_count++;
730
731 dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
732
733 return 0;
734 }
735
736 /* attach_connect_block()
737 *
738 * inputs - pointer to server to attach
739 * - name of server
740 * - hostname of server
741 * output - true (1) if both are found, otherwise return false (0)
742 * side effects - find connect block and attach them to connecting client
743 */
744 int
745 attach_connect_block(struct Client *client_p, const char *name,
746 const char *host)
747 {
748 dlink_node *ptr;
749 struct MaskItem *conf = NULL;
750
751 assert(client_p != NULL);
752 assert(host != NULL);
753
754 if (client_p == NULL || host == NULL)
755 return 0;
756
757 DLINK_FOREACH(ptr, server_items.head)
758 {
759 conf = ptr->data;
760
761 if (match(conf->name, name) || match(conf->host, host))
762 continue;
763
764 attach_conf(client_p, conf);
765 return -1;
766 }
767
768 return 0;
769 }
770
771 /* find_conf_name()
772 *
773 * inputs - pointer to conf link list to search
774 * - pointer to name to find
775 * - int mask of type of conf to find
776 * output - NULL or pointer to conf found
777 * side effects - find a conf entry which matches the name
778 * and has the given mask.
779 */
780 struct MaskItem *
781 find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
782 {
783 dlink_node *ptr;
784 struct MaskItem* conf;
785
786 DLINK_FOREACH(ptr, list->head)
787 {
788 conf = ptr->data;
789
790 if (conf->type == type)
791 {
792 if (conf->name && (irccmp(conf->name, name) == 0 ||
793 !match(conf->name, name)))
794 return conf;
795 }
796 }
797
798 return NULL;
799 }
800
801 /* map_to_list()
802 *
803 * inputs - ConfType conf
804 * output - pointer to dlink_list to use
805 * side effects - none
806 */
807 static dlink_list *
808 map_to_list(enum maskitem_type type)
809 {
810 switch(type)
811 {
812 case CONF_XLINE:
813 return(&xconf_items);
814 break;
815 case CONF_ULINE:
816 return(&uconf_items);
817 break;
818 case CONF_NRESV:
819 return(&nresv_items);
820 break;
821 case CONF_CRESV:
822 return(&cresv_items);
823 case CONF_OPER:
824 return(&oconf_items);
825 break;
826 case CONF_SERVER:
827 return(&server_items);
828 break;
829 case CONF_SERVICE:
830 return(&service_items);
831 break;
832 case CONF_CLUSTER:
833 return(&cluster_items);
834 break;
835 default:
836 return NULL;
837 }
838 }
839
840 /* find_matching_name_conf()
841 *
842 * inputs - type of link list to look in
843 * - pointer to name string to find
844 * - pointer to user
845 * - pointer to host
846 * - optional flags to match on as well
847 * output - NULL or pointer to found struct MaskItem
848 * side effects - looks for a match on name field
849 */
850 struct MaskItem *
851 find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
852 const char *host, unsigned int flags)
853 {
854 dlink_node *ptr=NULL;
855 struct MaskItem *conf=NULL;
856 dlink_list *list_p = map_to_list(type);
857
858 switch (type)
859 {
860 case CONF_SERVICE:
861 DLINK_FOREACH(ptr, list_p->head)
862 {
863 conf = ptr->data;
864
865 if (EmptyString(conf->name))
866 continue;
867 if ((name != NULL) && !irccmp(name, conf->name))
868 return conf;
869 }
870 break;
871
872 case CONF_XLINE:
873 case CONF_ULINE:
874 case CONF_NRESV:
875 case CONF_CRESV:
876 DLINK_FOREACH(ptr, list_p->head)
877 {
878 conf = ptr->data;
879
880 if (EmptyString(conf->name))
881 continue;
882 if ((name != NULL) && !match(conf->name, name))
883 {
884 if ((user == NULL && (host == NULL)))
885 return conf;
886 if ((conf->flags & flags) != flags)
887 continue;
888 if (EmptyString(conf->user) || EmptyString(conf->host))
889 return conf;
890 if (!match(conf->user, user) && !match(conf->host, host))
891 return conf;
892 }
893 }
894 break;
895
896 case CONF_SERVER:
897 DLINK_FOREACH(ptr, list_p->head)
898 {
899 conf = ptr->data;
900
901 if ((name != NULL) && !match(name, conf->name))
902 return conf;
903 else if ((host != NULL) && !match(host, conf->host))
904 return conf;
905 }
906 break;
907
908 default:
909 break;
910 }
911 return NULL;
912 }
913
914 /* find_exact_name_conf()
915 *
916 * inputs - type of link list to look in
917 * - pointer to name string to find
918 * - pointer to user
919 * - pointer to host
920 * output - NULL or pointer to found struct MaskItem
921 * side effects - looks for an exact match on name field
922 */
923 struct MaskItem *
924 find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
925 const char *user, const char *host)
926 {
927 dlink_node *ptr = NULL;
928 struct MaskItem *conf;
929 dlink_list *list_p = map_to_list(type);
930
931 switch(type)
932 {
933 case CONF_XLINE:
934 case CONF_ULINE:
935 case CONF_NRESV:
936 case CONF_CRESV:
937
938 DLINK_FOREACH(ptr, list_p->head)
939 {
940 conf = ptr->data;
941
942 if (EmptyString(conf->name))
943 continue;
944
945 if (irccmp(conf->name, name) == 0)
946 {
947 if ((user == NULL && (host == NULL)))
948 return conf;
949 if (EmptyString(conf->user) || EmptyString(conf->host))
950 return conf;
951 if (!match(conf->user, user) && !match(conf->host, host))
952 return conf;
953 }
954 }
955 break;
956
957 case CONF_OPER:
958 DLINK_FOREACH(ptr, list_p->head)
959 {
960 conf = ptr->data;
961
962 if (EmptyString(conf->name))
963 continue;
964
965 if (!irccmp(conf->name, name))
966 {
967 if (!who)
968 return conf;
969 if (EmptyString(conf->user) || EmptyString(conf->host))
970 return NULL;
971 if (!match(conf->user, who->username))
972 {
973 switch (conf->htype)
974 {
975 case HM_HOST:
976 if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
977 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
978 return conf;
979 break;
980 case HM_IPV4:
981 if (who->localClient->aftype == AF_INET)
982 if (match_ipv4(&who->localClient->ip, &conf->addr, conf->bits))
983 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
984 return conf;
985 break;
986 #ifdef IPV6
987 case HM_IPV6:
988 if (who->localClient->aftype == AF_INET6)
989 if (match_ipv6(&who->localClient->ip, &conf->addr, conf->bits))
990 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
991 return conf;
992 break;
993 #endif
994 default:
995 assert(0);
996 }
997 }
998 }
999 }
1000
1001 break;
1002
1003 case CONF_SERVER:
1004 DLINK_FOREACH(ptr, list_p->head)
1005 {
1006 conf = ptr->data;
1007
1008 if (EmptyString(conf->name))
1009 continue;
1010
1011 if (name == NULL)
1012 {
1013 if (EmptyString(conf->host))
1014 continue;
1015 if (irccmp(conf->host, host) == 0)
1016 return conf;
1017 }
1018 else if (irccmp(conf->name, name) == 0)
1019 return conf;
1020 }
1021
1022 break;
1023
1024 default:
1025 break;
1026 }
1027
1028 return NULL;
1029 }
1030
1031 /* rehash()
1032 *
1033 * Actual REHASH service routine. Called with sig == 0 if it has been called
1034 * as a result of an operator issuing this command, else assume it has been
1035 * called as a result of the server receiving a HUP signal.
1036 */
1037 int
1038 rehash(int sig)
1039 {
1040 if (sig != 0)
1041 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1042 "Got signal SIGHUP, reloading configuration file(s)");
1043
1044 restart_resolver();
1045
1046 /* don't close listeners until we know we can go ahead with the rehash */
1047
1048 /* Check to see if we magically got(or lost) IPv6 support */
1049 check_can_use_v6();
1050
1051 read_conf_files(0);
1052
1053 if (ServerInfo.description != NULL)
1054 strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1055
1056 load_conf_modules();
1057
1058 rehashed_klines = 1;
1059
1060 return 0;
1061 }
1062
1063 /* set_default_conf()
1064 *
1065 * inputs - NONE
1066 * output - NONE
1067 * side effects - Set default values here.
1068 * This is called **PRIOR** to parsing the
1069 * configuration file. If you want to do some validation
1070 * of values later, put them in validate_conf().
1071 */
1072 static void
1073 set_default_conf(void)
1074 {
1075 /* verify init_class() ran, this should be an unnecessary check
1076 * but its not much work.
1077 */
1078 assert(class_default == class_get_list()->tail->data);
1079
1080 #ifdef HAVE_LIBCRYPTO
1081 ServerInfo.rsa_private_key = NULL;
1082 ServerInfo.rsa_private_key_file = NULL;
1083 #endif
1084
1085 /* ServerInfo.name is not rehashable */
1086 /* ServerInfo.name = ServerInfo.name; */
1087 ServerInfo.description = NULL;
1088 ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1089 ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1090
1091 memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
1092 ServerInfo.specific_ipv4_vhost = 0;
1093 memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
1094 ServerInfo.specific_ipv6_vhost = 0;
1095
1096 ServerInfo.max_clients = MAXCLIENTS_MAX;
1097 ServerInfo.max_nick_length = 9;
1098 ServerInfo.max_topic_length = 80;
1099
1100 ServerInfo.hub = 0;
1101 ServerInfo.dns_host.sin_addr.s_addr = 0;
1102 ServerInfo.dns_host.sin_port = 0;
1103 AdminInfo.name = NULL;
1104 AdminInfo.email = NULL;
1105 AdminInfo.description = NULL;
1106
1107 log_del_all();
1108
1109 ConfigLoggingEntry.use_logging = 1;
1110
1111 ConfigChannel.disable_fake_channels = 0;
1112 ConfigChannel.knock_delay = 300;
1113 ConfigChannel.knock_delay_channel = 60;
1114 ConfigChannel.max_chans_per_user = 25;
1115 ConfigChannel.max_chans_per_oper = 50;
1116 ConfigChannel.max_bans = 25;
1117 ConfigChannel.default_split_user_count = 0;
1118 ConfigChannel.default_split_server_count = 0;
1119 ConfigChannel.no_join_on_split = 0;
1120 ConfigChannel.no_create_on_split = 0;
1121
1122 ConfigServerHide.flatten_links = 0;
1123 ConfigServerHide.links_delay = 300;
1124 ConfigServerHide.hidden = 0;
1125 ConfigServerHide.hide_servers = 0;
1126 ConfigServerHide.hide_services = 0;
1127 ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
1128 ConfigServerHide.hide_server_ips = 0;
1129 ConfigServerHide.disable_remote_commands = 0;
1130
1131 ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1132 ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
1133 ConfigFileEntry.cycle_on_host_change = 1;
1134 ConfigFileEntry.glines = 0;
1135 ConfigFileEntry.gline_time = 12 * 3600;
1136 ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
1137 ConfigFileEntry.gline_min_cidr = 16;
1138 ConfigFileEntry.gline_min_cidr6 = 48;
1139 ConfigFileEntry.invisible_on_connect = 1;
1140 ConfigFileEntry.tkline_expire_notices = 1;
1141 ConfigFileEntry.hide_spoof_ips = 1;
1142 ConfigFileEntry.ignore_bogus_ts = 0;
1143 ConfigFileEntry.disable_auth = 0;
1144 ConfigFileEntry.kill_chase_time_limit = 90;
1145 ConfigFileEntry.default_floodcount = 8;
1146 ConfigFileEntry.failed_oper_notice = 1;
1147 ConfigFileEntry.dots_in_ident = 0;
1148 ConfigFileEntry.min_nonwildcard = 4;
1149 ConfigFileEntry.min_nonwildcard_simple = 3;
1150 ConfigFileEntry.max_accept = 20;
1151 ConfigFileEntry.anti_nick_flood = 0;
1152 ConfigFileEntry.max_nick_time = 20;
1153 ConfigFileEntry.max_nick_changes = 5;
1154 ConfigFileEntry.anti_spam_exit_message_time = 0;
1155 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1156 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1157 ConfigFileEntry.warn_no_nline = 1;
1158 ConfigFileEntry.stats_o_oper_only = 0;
1159 ConfigFileEntry.stats_k_oper_only = 1; /* masked */
1160 ConfigFileEntry.stats_i_oper_only = 1; /* masked */
1161 ConfigFileEntry.stats_P_oper_only = 0;
1162 ConfigFileEntry.stats_u_oper_only = 0;
1163 ConfigFileEntry.caller_id_wait = 60;
1164 ConfigFileEntry.opers_bypass_callerid = 0;
1165 ConfigFileEntry.pace_wait = 10;
1166 ConfigFileEntry.pace_wait_simple = 1;
1167 ConfigFileEntry.short_motd = 0;
1168 ConfigFileEntry.ping_cookie = 0;
1169 ConfigFileEntry.no_oper_flood = 0;
1170 ConfigFileEntry.true_no_oper_flood = 0;
1171 ConfigFileEntry.oper_pass_resv = 1;
1172 ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
1173 ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
1174 ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
1175 UMODE_OPERWALL | UMODE_WALLOP;
1176 ConfigFileEntry.use_egd = 0;
1177 ConfigFileEntry.egdpool_path = NULL;
1178 ConfigFileEntry.throttle_time = 10;
1179 }
1180
1181 static void
1182 validate_conf(void)
1183 {
1184 if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
1185 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1186
1187 if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1188 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1189
1190 if (ServerInfo.network_name == NULL)
1191 ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1192
1193 if (ServerInfo.network_desc == NULL)
1194 ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1195
1196 if (ConfigFileEntry.service_name == NULL)
1197 ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1198
1199 ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
1200 }
1201
1202 /* read_conf()
1203 *
1204 * inputs - file descriptor pointing to config file to use
1205 * output - None
1206 * side effects - Read configuration file.
1207 */
1208 static void
1209 read_conf(FILE *file)
1210 {
1211 lineno = 0;
1212
1213 set_default_conf(); /* Set default values prior to conf parsing */
1214 conf_parser_ctx.pass = 1;
1215 yyparse(); /* pick up the classes first */
1216
1217 rewind(file);
1218
1219 conf_parser_ctx.pass = 2;
1220 yyparse(); /* Load the values from the conf */
1221 validate_conf(); /* Check to make sure some values are still okay. */
1222 /* Some global values are also loaded here. */
1223 class_delete_marked(); /* Make sure classes are valid */
1224 }
1225
1226 /* lookup_confhost()
1227 *
1228 * start DNS lookups of all hostnames in the conf
1229 * line and convert an IP addresses in a.b.c.d number for to IP#s.
1230 */
1231 void
1232 lookup_confhost(struct MaskItem *conf)
1233 {
1234 struct addrinfo hints, *res;
1235
1236 /* Do name lookup now on hostnames given and store the
1237 * ip numbers in conf structure.
1238 */
1239 memset(&hints, 0, sizeof(hints));
1240
1241 hints.ai_family = AF_UNSPEC;
1242 hints.ai_socktype = SOCK_STREAM;
1243
1244 /* Get us ready for a bind() and don't bother doing dns lookup */
1245 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
1246
1247 if (getaddrinfo(conf->host, NULL, &hints, &res))
1248 {
1249 conf_dns_lookup(conf);
1250 return;
1251 }
1252
1253 assert(res != NULL);
1254
1255 memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
1256 conf->addr.ss_len = res->ai_addrlen;
1257 conf->addr.ss.ss_family = res->ai_family;
1258
1259 freeaddrinfo(res);
1260 }
1261
1262 /* conf_connect_allowed()
1263 *
1264 * inputs - pointer to inaddr
1265 * - int type ipv4 or ipv6
1266 * output - BANNED or accepted
1267 * side effects - none
1268 */
1269 int
1270 conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
1271 {
1272 struct ip_entry *ip_found;
1273 struct MaskItem *conf = find_dline_conf(addr, aftype);
1274
1275 /* DLINE exempt also gets you out of static limits/pacing... */
1276 if (conf && (conf->type == CONF_EXEMPT))
1277 return 0;
1278
1279 if (conf != NULL)
1280 return BANNED_CLIENT;
1281
1282 ip_found = find_or_add_ip(addr);
1283
1284 if ((CurrentTime - ip_found->last_attempt) <
1285 ConfigFileEntry.throttle_time)
1286 {
1287 ip_found->last_attempt = CurrentTime;
1288 return TOO_FAST;
1289 }
1290
1291 ip_found->last_attempt = CurrentTime;
1292 return 0;
1293 }
1294
1295 /* cleanup_tklines()
1296 *
1297 * inputs - NONE
1298 * output - NONE
1299 * side effects - call function to expire temporary k/d lines
1300 * This is an event started off in ircd.c
1301 */
1302 void
1303 cleanup_tklines(void *notused)
1304 {
1305 hostmask_expire_temporary();
1306 expire_tklines(&xconf_items);
1307 expire_tklines(&nresv_items);
1308 expire_tklines(&cresv_items);
1309 }
1310
1311 /* expire_tklines()
1312 *
1313 * inputs - tkline list pointer
1314 * output - NONE
1315 * side effects - expire tklines
1316 */
1317 static void
1318 expire_tklines(dlink_list *tklist)
1319 {
1320 dlink_node *ptr;
1321 dlink_node *next_ptr;
1322 struct MaskItem *conf;
1323
1324 DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
1325 {
1326 conf = ptr->data;
1327
1328 if (!conf->until || conf->until > CurrentTime)
1329 continue;
1330
1331 if (conf->type == CONF_XLINE)
1332 {
1333 if (ConfigFileEntry.tkline_expire_notices)
1334 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1335 "Temporary X-line for [%s] expired", conf->name);
1336 conf_free(conf);
1337 }
1338 else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV)
1339 {
1340 if (ConfigFileEntry.tkline_expire_notices)
1341 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1342 "Temporary RESV for [%s] expired", conf->name);
1343 conf_free(conf);
1344 }
1345 }
1346 }
1347
1348 /* oper_privs_as_string()
1349 *
1350 * inputs - pointer to client_p
1351 * output - pointer to static string showing oper privs
1352 * side effects - return as string, the oper privs as derived from port
1353 */
1354 static const struct oper_privs
1355 {
1356 const unsigned int flag;
1357 const unsigned char c;
1358 } flag_list[] = {
1359 { OPER_FLAG_ADMIN, 'A' },
1360 { OPER_FLAG_REMOTEBAN, 'B' },
1361 { OPER_FLAG_DIE, 'D' },
1362 { OPER_FLAG_GLINE, 'G' },
1363 { OPER_FLAG_REHASH, 'H' },
1364 { OPER_FLAG_K, 'K' },
1365 { OPER_FLAG_OPERWALL, 'L' },
1366 { OPER_FLAG_KILL, 'N' },
1367 { OPER_FLAG_KILL_REMOTE, 'O' },
1368 { OPER_FLAG_CONNECT, 'P' },
1369 { OPER_FLAG_CONNECT_REMOTE, 'Q' },
1370 { OPER_FLAG_SQUIT, 'R' },
1371 { OPER_FLAG_SQUIT_REMOTE, 'S' },
1372 { OPER_FLAG_UNKLINE, 'U' },
1373 { OPER_FLAG_XLINE, 'X' },
1374 { 0, '\0' }
1375 };
1376
1377 char *
1378 oper_privs_as_string(const unsigned int port)
1379 {
1380 static char privs_out[IRCD_BUFSIZE];
1381 char *privs_ptr = privs_out;
1382 const struct oper_privs *opriv = flag_list;
1383
1384 for (; opriv->flag; ++opriv)
1385 {
1386 if (port & opriv->flag)
1387 *privs_ptr++ = opriv->c;
1388 else
1389 *privs_ptr++ = ToLower(opriv->c);
1390 }
1391
1392 *privs_ptr = '\0';
1393
1394 return privs_out;
1395 }
1396
1397 /*
1398 * Input: A client to find the active oper{} name for.
1399 * Output: The nick!user@host{oper} of the oper.
1400 * "oper" is server name for remote opers
1401 * Side effects: None.
1402 */
1403 const char *
1404 get_oper_name(const struct Client *client_p)
1405 {
1406 const dlink_node *cnode = NULL;
1407 /* +5 for !,@,{,} and null */
1408 static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1409
1410 if (MyConnect(client_p))
1411 {
1412 if ((cnode = client_p->localClient->confs.head))
1413 {
1414 const struct MaskItem *conf = cnode->data;
1415
1416 if (IsConfOperator(conf))
1417 {
1418 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1419 client_p->username, client_p->host, conf->name);
1420 return buffer;
1421 }
1422 }
1423
1424 /* Probably should assert here for now. If there is an oper out there
1425 * with no oper{} conf attached, it would be good for us to know...
1426 */
1427 assert(0); /* Oper without oper conf! */
1428 }
1429
1430 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1431 client_p->username, client_p->host, client_p->servptr->name);
1432 return buffer;
1433 }
1434
1435 /* read_conf_files()
1436 *
1437 * inputs - cold start YES or NO
1438 * output - none
1439 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1440 */
1441 void
1442 read_conf_files(int cold)
1443 {
1444 const char *filename;
1445 char chanmodes[IRCD_BUFSIZE];
1446 char chanlimit[IRCD_BUFSIZE];
1447
1448 conf_parser_ctx.boot = cold;
1449 filename = ConfigFileEntry.configfile;
1450
1451 /* We need to know the initial filename for the yyerror() to report
1452 FIXME: The full path is in conffilenamebuf first time since we
1453 dont know anything else
1454
1455 - Gozem 2002-07-21
1456 */
1457 strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1458
1459 if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1460 {
1461 if (cold)
1462 {
1463 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1464 filename, strerror(errno));
1465 exit(-1);
1466 }
1467 else
1468 {
1469 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1470 "Unable to read configuration file '%s': %s",
1471 filename, strerror(errno));
1472 return;
1473 }
1474 }
1475
1476 if (!cold)
1477 clear_out_old_conf();
1478
1479 read_conf(conf_parser_ctx.conf_file);
1480 fclose(conf_parser_ctx.conf_file);
1481
1482 log_reopen_all();
1483
1484 add_isupport("NICKLEN", NULL, ServerInfo.max_nick_length);
1485 add_isupport("NETWORK", ServerInfo.network_name, -1);
1486
1487 snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1488 add_isupport("MAXLIST", chanmodes, -1);
1489 add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
1490 add_isupport("CHANTYPES", "#", -1);
1491
1492 snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1493 ConfigChannel.max_chans_per_user);
1494 add_isupport("CHANLIMIT", chanlimit, -1);
1495 snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS");
1496 add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
1497 add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length);
1498 add_isupport("CHANMODES", chanmodes, -1);
1499
1500 /*
1501 * message_locale may have changed. rebuild isupport since it relies
1502 * on strlen(form_str(RPL_ISUPPORT))
1503 */
1504 rebuild_isupport_message_line();
1505 }
1506
1507 /* clear_out_old_conf()
1508 *
1509 * inputs - none
1510 * output - none
1511 * side effects - Clear out the old configuration
1512 */
1513 static void
1514 clear_out_old_conf(void)
1515 {
1516 dlink_node *ptr = NULL, *next_ptr = NULL;
1517 struct MaskItem *conf;
1518 dlink_list *free_items [] = {
1519 &server_items, &oconf_items,
1520 &uconf_items, &xconf_items,
1521 &nresv_items, &cluster_items, &service_items, &cresv_items, NULL
1522 };
1523
1524 dlink_list ** iterator = free_items; /* C is dumb */
1525
1526 /* We only need to free anything allocated by yyparse() here.
1527 * Resetting structs, etc, is taken care of by set_default_conf().
1528 */
1529
1530 for (; *iterator != NULL; iterator++)
1531 {
1532 DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1533 {
1534 conf = ptr->data;
1535
1536 dlinkDelete(&conf->node, map_to_list(conf->type));
1537
1538 /* XXX This is less than pretty */
1539 if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
1540 {
1541 if (!conf->ref_count)
1542 conf_free(conf);
1543 }
1544 else if (conf->type == CONF_XLINE)
1545 {
1546 if (!conf->until)
1547 conf_free(conf);
1548 }
1549 else
1550 conf_free(conf);
1551 }
1552 }
1553
1554 motd_clear();
1555
1556 /*
1557 * don't delete the class table, rather mark all entries
1558 * for deletion. The table is cleaned up by class_delete_marked. - avalon
1559 */
1560 class_mark_for_deletion();
1561
1562 clear_out_address_conf();
1563
1564 /* clean out module paths */
1565 mod_clear_paths();
1566
1567 /* clean out ServerInfo */
1568 MyFree(ServerInfo.description);
1569 ServerInfo.description = NULL;
1570 MyFree(ServerInfo.network_name);
1571 ServerInfo.network_name = NULL;
1572 MyFree(ServerInfo.network_desc);
1573 ServerInfo.network_desc = NULL;
1574 MyFree(ConfigFileEntry.egdpool_path);
1575 ConfigFileEntry.egdpool_path = NULL;
1576 #ifdef HAVE_LIBCRYPTO
1577 if (ServerInfo.rsa_private_key != NULL)
1578 {
1579 RSA_free(ServerInfo.rsa_private_key);
1580 ServerInfo.rsa_private_key = NULL;
1581 }
1582
1583 MyFree(ServerInfo.rsa_private_key_file);
1584 ServerInfo.rsa_private_key_file = NULL;
1585
1586 if (ServerInfo.server_ctx)
1587 SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
1588 SSL_OP_NO_SSLv3|
1589 SSL_OP_NO_TLSv1);
1590 if (ServerInfo.client_ctx)
1591 SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
1592 SSL_OP_NO_SSLv3|
1593 SSL_OP_NO_TLSv1);
1594 #endif
1595
1596 /* clean out AdminInfo */
1597 MyFree(AdminInfo.name);
1598 AdminInfo.name = NULL;
1599 MyFree(AdminInfo.email);
1600 AdminInfo.email = NULL;
1601 MyFree(AdminInfo.description);
1602 AdminInfo.description = NULL;
1603
1604 /* clean out listeners */
1605 close_listeners();
1606
1607 /* clean out general */
1608 MyFree(ConfigFileEntry.service_name);
1609 ConfigFileEntry.service_name = NULL;
1610 }
1611
1612 /* conf_add_class_to_conf()
1613 *
1614 * inputs - pointer to config item
1615 * output - NONE
1616 * side effects - Add a class pointer to a conf
1617 */
1618 void
1619 conf_add_class_to_conf(struct MaskItem *conf, const char *class_name)
1620 {
1621 if (class_name == NULL)
1622 {
1623 conf->class = class_default;
1624
1625 if (conf->type == CONF_CLIENT)
1626 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1627 "Warning *** Defaulting to default class for %s@%s",
1628 conf->user, conf->host);
1629 else
1630 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1631 "Warning *** Defaulting to default class for %s",
1632 conf->name);
1633 }
1634 else
1635 conf->class = class_find(class_name, 1);
1636
1637 if (conf->class == NULL)
1638 {
1639 if (conf->type == CONF_CLIENT)
1640 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1641 "Warning *** Defaulting to default class for %s@%s",
1642 conf->user, conf->host);
1643 else
1644 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1645 "Warning *** Defaulting to default class for %s",
1646 conf->name);
1647 conf->class = class_default;
1648 }
1649 }
1650
1651 /* yyerror()
1652 *
1653 * inputs - message from parser
1654 * output - NONE
1655 * side effects - message to opers and log file entry is made
1656 */
1657 void
1658 yyerror(const char *msg)
1659 {
1660 char newlinebuf[IRCD_BUFSIZE];
1661
1662 if (conf_parser_ctx.pass != 1)
1663 return;
1664
1665 strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1666 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1667 "\"%s\", line %u: %s: %s",
1668 conffilebuf, lineno + 1, msg, newlinebuf);
1669 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1670 conffilebuf, lineno + 1, msg, newlinebuf);
1671 }
1672
1673 void
1674 conf_error_report(const char *msg)
1675 {
1676 char newlinebuf[IRCD_BUFSIZE];
1677
1678 strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1679 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1680 "\"%s\", line %u: %s: %s",
1681 conffilebuf, lineno + 1, msg, newlinebuf);
1682 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1683 conffilebuf, lineno + 1, msg, newlinebuf);
1684 }
1685
1686 /*
1687 * valid_tkline()
1688 *
1689 * inputs - pointer to ascii string to check
1690 * - whether the specified time is in seconds or minutes
1691 * output - -1 not enough parameters
1692 * - 0 if not an integer number, else the number
1693 * side effects - none
1694 * Originally written by Dianora (Diane, db@db.net)
1695 */
1696 time_t
1697 valid_tkline(const char *data, const int minutes)
1698 {
1699 const unsigned char *p = (const unsigned char *)data;
1700 unsigned char tmpch = '\0';
1701 time_t result = 0;
1702
1703 while ((tmpch = *p++))
1704 {
1705 if (!IsDigit(tmpch))
1706 return 0;
1707
1708 result *= 10;
1709 result += (tmpch & 0xF);
1710 }
1711
1712 /*
1713 * In the degenerate case where oper does a /quote kline 0 user@host :reason
1714 * i.e. they specifically use 0, I am going to return 1 instead
1715 * as a return value of non-zero is used to flag it as a temporary kline
1716 */
1717 if (result == 0)
1718 result = 1;
1719
1720 /*
1721 * If the incoming time is in seconds convert it to minutes for the purpose
1722 * of this calculation
1723 */
1724 if (!minutes)
1725 result = result / 60;
1726
1727 if (result > MAX_TDKLINE_TIME)
1728 result = MAX_TDKLINE_TIME;
1729
1730 result = result * 60; /* turn it into seconds */
1731
1732 return result;
1733 }
1734
1735 /* valid_wild_card_simple()
1736 *
1737 * inputs - data to check for sufficient non-wildcard characters
1738 * outputs - 1 if valid, else 0
1739 * side effects - none
1740 */
1741 int
1742 valid_wild_card_simple(const char *data)
1743 {
1744 const unsigned char *p = (const unsigned char *)data;
1745 unsigned char tmpch = '\0';
1746 int nonwild = 0;
1747
1748 while ((tmpch = *p++))
1749 {
1750 if (tmpch == '\\')
1751 {
1752 ++p;
1753 if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1754 return 1;
1755 }
1756 else if (!IsMWildChar(tmpch))
1757 {
1758 if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1759 return 1;
1760 }
1761 }
1762
1763 return 0;
1764 }
1765
1766 /* valid_wild_card()
1767 *
1768 * input - pointer to client
1769 * - int flag, 0 for no warning oper 1 for warning oper
1770 * - count of following varargs to check
1771 * output - 0 if not valid, 1 if valid
1772 * side effects - NOTICE is given to source_p if warn is 1
1773 */
1774 int
1775 valid_wild_card(struct Client *source_p, int warn, int count, ...)
1776 {
1777 char tmpch;
1778 int nonwild = 0;
1779 va_list args;
1780
1781 /*
1782 * Now we must check the user and host to make sure there
1783 * are at least NONWILDCHARS non-wildcard characters in
1784 * them, otherwise assume they are attempting to kline
1785 * *@* or some variant of that. This code will also catch
1786 * people attempting to kline *@*.tld, as long as NONWILDCHARS
1787 * is greater than 3. In that case, there are only 3 non-wild
1788 * characters (tld), so if NONWILDCHARS is 4, the kline will
1789 * be disallowed.
1790 * -wnder
1791 */
1792
1793 va_start(args, count);
1794
1795 while (count--)
1796 {
1797 const char *p = va_arg(args, const char *);
1798 if (p == NULL)
1799 continue;
1800
1801 while ((tmpch = *p++))
1802 {
1803 if (!IsKWildChar(tmpch))
1804 {
1805 /*
1806 * If we find enough non-wild characters, we can
1807 * break - no point in searching further.
1808 */
1809 if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1810 {
1811 va_end(args);
1812 return 1;
1813 }
1814 }
1815 }
1816 }
1817
1818 if (warn)
1819 sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask",
1820 me.name, source_p->name, ConfigFileEntry.min_nonwildcard);
1821 va_end(args);
1822 return 0;
1823 }
1824
1825 /* XXX should this go into a separate file ? -Dianora */
1826 /* parse_aline
1827 *
1828 * input - pointer to cmd name being used
1829 * - pointer to client using cmd
1830 * - parc parameter count
1831 * - parv[] list of parameters to parse
1832 * - parse_flags bit map of things to test
1833 * - pointer to user or string to parse into
1834 * - pointer to host or NULL to parse into if non NULL
1835 * - pointer to optional tkline time or NULL
1836 * - pointer to target_server to parse into if non NULL
1837 * - pointer to reason to parse into
1838 *
1839 * output - 1 if valid, -1 if not valid
1840 * side effects - A generalised k/d/x etc. line parser,
1841 * "ALINE [time] user@host|string [ON] target :reason"
1842 * will parse returning a parsed user, host if
1843 * h_p pointer is non NULL, string otherwise.
1844 * if tkline_time pointer is non NULL a tk line will be set
1845 * to non zero if found.
1846 * if tkline_time pointer is NULL and tk line is found,
1847 * error is reported.
1848 * if target_server is NULL and an "ON" is found error
1849 * is reported.
1850 * if reason pointer is NULL ignore pointer,
1851 * this allows use of parse_a_line in unkline etc.
1852 *
1853 * - Dianora
1854 */
1855 int
1856 parse_aline(const char *cmd, struct Client *source_p,
1857 int parc, char **parv,
1858 int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1859 char **target_server, char **reason)
1860 {
1861 int found_tkline_time=0;
1862 static char def_reason[] = "No Reason";
1863 static char user[USERLEN*4+1];
1864 static char host[HOSTLEN*4+1];
1865
1866 parv++;
1867 parc--;
1868
1869 found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1870
1871 if (found_tkline_time != 0)
1872 {
1873 parv++;
1874 parc--;
1875
1876 if (tkline_time != NULL)
1877 *tkline_time = found_tkline_time;
1878 else
1879 {
1880 sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
1881 me.name, source_p->name, cmd);
1882 return -1;
1883 }
1884 }
1885
1886 if (parc == 0)
1887 {
1888 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1889 me.name, source_p->name, cmd);
1890 return -1;
1891 }
1892
1893 if (h_p == NULL)
1894 *up_p = *parv;
1895 else
1896 {
1897 if (find_user_host(source_p, *parv, user, host, parse_flags) == 0)
1898 return -1;
1899
1900 *up_p = user;
1901 *h_p = host;
1902 }
1903
1904 parc--;
1905 parv++;
1906
1907 if (parc != 0)
1908 {
1909 if (irccmp(*parv, "ON") == 0)
1910 {
1911 parc--;
1912 parv++;
1913
1914 if (target_server == NULL)
1915 {
1916 sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
1917 me.name, source_p->name, cmd);
1918 return -1;
1919 }
1920
1921 if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1922 {
1923 sendto_one(source_p, form_str(ERR_NOPRIVS),
1924 me.name, source_p->name, "remoteban");
1925 return -1;
1926 }
1927
1928 if (parc == 0 || EmptyString(*parv))
1929 {
1930 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1931 me.name, source_p->name, cmd);
1932 return -1;
1933 }
1934
1935 *target_server = *parv;
1936 parc--;
1937 parv++;
1938 }
1939 else
1940 {
1941 /* Make sure target_server *is* NULL if no ON server found
1942 * caller probably NULL'd it first, but no harm to do it again -db
1943 */
1944 if (target_server != NULL)
1945 *target_server = NULL;
1946 }
1947 }
1948
1949 if (h_p != NULL)
1950 {
1951 if (strchr(user, '!') != NULL)
1952 {
1953 sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline",
1954 me.name, source_p->name);
1955 return -1;
1956 }
1957
1958 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
1959 return -1;
1960 }
1961 else
1962 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
1963 return -1;
1964
1965 if (reason != NULL)
1966 {
1967 if (parc != 0 && !EmptyString(*parv))
1968 {
1969 *reason = *parv;
1970 if (!valid_comment(source_p, *reason, 1))
1971 return -1;
1972 }
1973 else
1974 *reason = def_reason;
1975 }
1976
1977 return 1;
1978 }
1979
1980 /* find_user_host()
1981 *
1982 * inputs - pointer to client placing kline
1983 * - pointer to user_host_or_nick
1984 * - pointer to user buffer
1985 * - pointer to host buffer
1986 * output - 0 if not ok to kline, 1 to kline i.e. if valid user host
1987 * side effects -
1988 */
1989 static int
1990 find_user_host(struct Client *source_p, char *user_host_or_nick,
1991 char *luser, char *lhost, unsigned int flags)
1992 {
1993 struct Client *target_p = NULL;
1994 char *hostp = NULL;
1995
1996 if (lhost == NULL)
1997 {
1998 strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1999 return 1;
2000 }
2001
2002 if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
2003 {
2004 /* Explicit user@host mask given */
2005
2006 if (hostp != NULL) /* I'm a little user@host */
2007 {
2008 *(hostp++) = '\0'; /* short and squat */
2009 if (*user_host_or_nick)
2010 strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
2011 else
2012 strcpy(luser, "*");
2013
2014 if (*hostp)
2015 strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */
2016 else
2017 strcpy(lhost, "*");
2018 }
2019 else
2020 {
2021 luser[0] = '*'; /* no @ found, assume its *@somehost */
2022 luser[1] = '\0';
2023 strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
2024 }
2025
2026 return 1;
2027 }
2028 else
2029 {
2030 /* Try to find user@host mask from nick */
2031 /* Okay to use source_p as the first param, because source_p == client_p */
2032 if ((target_p =
2033 find_chasing(source_p, user_host_or_nick, NULL)) == NULL)
2034 return 0;
2035
2036 if (IsExemptKline(target_p))
2037 {
2038 if (!IsServer(source_p))
2039 sendto_one(source_p,
2040 ":%s NOTICE %s :%s is E-lined",
2041 me.name, source_p->name, target_p->name);
2042 return 0;
2043 }
2044
2045 /*
2046 * turn the "user" bit into "*user", blow away '~'
2047 * if found in original user name (non-idented)
2048 */
2049 strlcpy(luser, target_p->username, USERLEN*4 + 1);
2050
2051 if (target_p->username[0] == '~')
2052 luser[0] = '*';
2053
2054 if (target_p->sockhost[0] == '\0' ||
2055 (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
2056 strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
2057 else
2058 strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
2059 return 1;
2060 }
2061
2062 return 0;
2063 }
2064
2065 /* valid_comment()
2066 *
2067 * inputs - pointer to client
2068 * - pointer to comment
2069 * output - 0 if no valid comment,
2070 * - 1 if valid
2071 * side effects - truncates reason where necessary
2072 */
2073 int
2074 valid_comment(struct Client *source_p, char *comment, int warn)
2075 {
2076 if (strlen(comment) > REASONLEN)
2077 comment[REASONLEN-1] = '\0';
2078
2079 return 1;
2080 }
2081
2082 /* match_conf_password()
2083 *
2084 * inputs - pointer to given password
2085 * - pointer to Conf
2086 * output - 1 or 0 if match
2087 * side effects - none
2088 */
2089 int
2090 match_conf_password(const char *password, const struct MaskItem *conf)
2091 {
2092 const char *encr = NULL;
2093
2094 if (EmptyString(password) || EmptyString(conf->passwd))
2095 return 0;
2096
2097 if (conf->flags & CONF_FLAGS_ENCRYPTED)
2098 encr = crypt(password, conf->passwd);
2099 else
2100 encr = password;
2101
2102 return !strcmp(encr, conf->passwd);
2103 }
2104
2105 /*
2106 * cluster_a_line
2107 *
2108 * inputs - client sending the cluster
2109 * - command name "KLINE" "XLINE" etc.
2110 * - capab -- CAP_KLN etc. from s_serv.h
2111 * - cluster type -- CLUSTER_KLINE etc. from conf.h
2112 * - pattern and args to send along
2113 * output - none
2114 * side effects - Take source_p send the pattern with args given
2115 * along to all servers that match capab and cluster type
2116 */
2117 void
2118 cluster_a_line(struct Client *source_p, const char *command,
2119 int capab, int cluster_type, const char *pattern, ...)
2120 {
2121 va_list args;
2122 char buffer[IRCD_BUFSIZE];
2123 const dlink_node *ptr = NULL;
2124
2125 va_start(args, pattern);
2126 vsnprintf(buffer, sizeof(buffer), pattern, args);
2127 va_end(args);
2128
2129 DLINK_FOREACH(ptr, cluster_items.head)
2130 {
2131 const struct MaskItem *conf = ptr->data;
2132
2133 if (conf->flags & cluster_type)
2134 sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
2135 "%s %s %s", command, conf->name, buffer);
2136 }
2137 }
2138
2139 /*
2140 * split_nuh
2141 *
2142 * inputs - pointer to original mask (modified in place)
2143 * - pointer to pointer where nick should go
2144 * - pointer to pointer where user should go
2145 * - pointer to pointer where host should go
2146 * output - NONE
2147 * side effects - mask is modified in place
2148 * If nick pointer is NULL, ignore writing to it
2149 * this allows us to use this function elsewhere.
2150 *
2151 * mask nick user host
2152 * ---------------------- ------- ------- ------
2153 * Dianora!db@db.net Dianora db db.net
2154 * Dianora Dianora * *
2155 * db.net * * db.net
2156 * OR if nick pointer is NULL
2157 * Dianora - * Dianora
2158 * Dianora! Dianora * *
2159 * Dianora!@ Dianora * *
2160 * Dianora!db Dianora db *
2161 * Dianora!@db.net Dianora * db.net
2162 * db@db.net * db db.net
2163 * !@ * * *
2164 * @ * * *
2165 * ! * * *
2166 */
2167 void
2168 split_nuh(struct split_nuh_item *const iptr)
2169 {
2170 char *p = NULL, *q = NULL;
2171
2172 if (iptr->nickptr)
2173 strlcpy(iptr->nickptr, "*", iptr->nicksize);
2174 if (iptr->userptr)
2175 strlcpy(iptr->userptr, "*", iptr->usersize);
2176 if (iptr->hostptr)
2177 strlcpy(iptr->hostptr, "*", iptr->hostsize);
2178
2179 if ((p = strchr(iptr->nuhmask, '!')))
2180 {
2181 *p = '\0';
2182
2183 if (iptr->nickptr && *iptr->nuhmask != '\0')
2184 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
2185
2186 if ((q = strchr(++p, '@')))
2187 {
2188 *q++ = '\0';
2189
2190 if (*p != '\0')
2191 strlcpy(iptr->userptr, p, iptr->usersize);
2192
2193 if (*q != '\0')
2194 strlcpy(iptr->hostptr, q, iptr->hostsize);
2195 }
2196 else
2197 {
2198 if (*p != '\0')
2199 strlcpy(iptr->userptr, p, iptr->usersize);
2200 }
2201 }
2202 else
2203 {
2204 /* No ! found so lets look for a user@host */
2205 if ((p = strchr(iptr->nuhmask, '@')))
2206 {
2207 /* if found a @ */
2208 *p++ = '\0';
2209
2210 if (*iptr->nuhmask != '\0')
2211 strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
2212
2213 if (*p != '\0')
2214 strlcpy(iptr->hostptr, p, iptr->hostsize);
2215 }
2216 else
2217 {
2218 /* no @ found */
2219 if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
2220 strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
2221 else
2222 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
2223 }
2224 }
2225 }

Properties

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