ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 1864
Committed: Thu Apr 25 17:07:20 2013 UTC (10 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 64837 byte(s)
Log Message:
- Fixed core on rehash with resv exempts

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

Properties

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