ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 1644
Committed: Tue Nov 6 22:20:16 2012 UTC (12 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 65525 byte(s)
Log Message:
- More config subsystem cleanups

File Contents

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

Properties

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