ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/branches/newio/src/conf.c
Revision: 2417
Committed: Sun Jul 21 18:11:50 2013 UTC (10 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 59193 byte(s)
Log Message:
- Change command message handlers to int type

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

Properties

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