ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/conf.c
Revision: 2852
Committed: Sat Jan 18 16:30:48 2014 UTC (10 years, 2 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/conf.c
File size: 58764 byte(s)
Log Message:
- Added 'unxline' oper privilege for better fine tuning

File Contents

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

Properties

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