ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 7248
Committed: Thu Feb 4 17:21:58 2016 UTC (9 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 48545 byte(s)
Log Message:
- Move service {} block configuration management into its own module

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2916 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 7006 * Copyright (c) 1997-2016 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2916 /*! \file conf.c
23     * \brief Configuration file functions.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "ircd_defs.h"
30 michael 1309 #include "conf.h"
31 michael 7217 #include "conf_cluster.h"
32 michael 4545 #include "conf_pseudo.h"
33 michael 7234 #include "conf_resv.h"
34 michael 7248 #include "conf_service.h"
35 michael 7209 #include "conf_shared.h"
36 michael 3347 #include "server.h"
37 adx 30 #include "channel.h"
38     #include "client.h"
39     #include "event.h"
40     #include "irc_string.h"
41     #include "s_bsd.h"
42     #include "ircd.h"
43     #include "listener.h"
44     #include "hostmask.h"
45     #include "modules.h"
46     #include "numeric.h"
47     #include "fdlist.h"
48 michael 1309 #include "log.h"
49 adx 30 #include "send.h"
50     #include "memory.h"
51 michael 3322 #include "res.h"
52 adx 30 #include "userhost.h"
53 michael 3347 #include "user.h"
54 adx 30 #include "channel_mode.h"
55 michael 1243 #include "parse.h"
56 michael 3347 #include "misc.h"
57 michael 1622 #include "conf_db.h"
58 michael 1632 #include "conf_class.h"
59 michael 2150 #include "motd.h"
60 michael 4325 #include "ipcache.h"
61 michael 6185 #include "isupport.h"
62 adx 30
63 michael 2872
64 michael 5602 struct config_channel_entry ConfigChannel;
65 michael 5644 struct config_serverhide_entry ConfigServerHide;
66 michael 5602 struct config_general_entry ConfigGeneral;
67 michael 5644 struct config_log_entry ConfigLog = { .use_logging = 1 };
68     struct config_serverinfo_entry ConfigServerInfo;
69     struct config_admin_entry ConfigAdminInfo;
70 michael 5602 struct conf_parser_context conf_parser_ctx;
71    
72 adx 30 /* general conf items link list root, other than k lines etc. */
73 michael 4982 dlink_list server_items;
74 michael 6628 dlink_list operator_items;
75 michael 6716 dlink_list gecos_items;
76 michael 4982 dlink_list nresv_items;
77     dlink_list cresv_items;
78 adx 30
79     extern unsigned int lineno;
80     extern char linebuf[];
81     extern char conffilebuf[IRCD_BUFSIZE];
82     extern int yyparse(); /* defined in y.tab.c */
83    
84    
85     /* conf_dns_callback()
86     *
87 michael 1632 * inputs - pointer to struct MaskItem
88 adx 30 * - pointer to DNSReply reply
89     * output - none
90     * side effects - called when resolver query finishes
91     * if the query resulted in a successful search, hp will contain
92     * a non-null pointer, otherwise hp will be null.
93     * if successful save hp in the conf item it was called with
94     */
95     static void
96 michael 4408 conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength)
97 adx 30 {
98 michael 4874 struct MaskItem *const conf = vptr;
99 adx 30
100 michael 1632 conf->dns_pending = 0;
101 adx 30
102 michael 3235 if (addr)
103 michael 1632 memcpy(&conf->addr, addr, sizeof(conf->addr));
104 michael 992 else
105 michael 1632 conf->dns_failed = 1;
106 adx 30 }
107    
108     /* conf_dns_lookup()
109     *
110     * do a nameserver lookup of the conf host
111     * if the conf entry is currently doing a ns lookup do nothing, otherwise
112     * allocate a dns_query and start ns lookup.
113     */
114     static void
115 michael 1632 conf_dns_lookup(struct MaskItem *conf)
116 adx 30 {
117 michael 4982 if (conf->dns_pending)
118     return;
119    
120     conf->dns_pending = 1;
121    
122     if (conf->aftype == AF_INET)
123     gethost_byname_type(conf_dns_callback, conf, conf->host, T_A);
124     else
125     gethost_byname_type(conf_dns_callback, conf, conf->host, T_AAAA);
126     }
127    
128     /* map_to_list()
129     *
130     * inputs - ConfType conf
131     * output - pointer to dlink_list to use
132     * side effects - none
133     */
134     static dlink_list *
135     map_to_list(enum maskitem_type type)
136     {
137     switch (type)
138 adx 30 {
139 michael 4982 case CONF_XLINE:
140 michael 6716 return &gecos_items;
141 michael 4982 break;
142     case CONF_NRESV:
143     return &nresv_items;
144     break;
145     case CONF_CRESV:
146     return &cresv_items;
147     break;
148     case CONF_OPER:
149 michael 6628 return &operator_items;
150 michael 4982 break;
151     case CONF_SERVER:
152     return &server_items;
153     break;
154     default:
155     return NULL;
156 adx 30 }
157     }
158    
159 michael 1632 struct MaskItem *
160     conf_make(enum maskitem_type type)
161     {
162 michael 7032 struct MaskItem *const conf = xcalloc(sizeof(*conf));
163 michael 1632 dlink_list *list = NULL;
164    
165     conf->type = type;
166     conf->active = 1;
167     conf->aftype = AF_INET;
168    
169     if ((list = map_to_list(type)))
170     dlinkAdd(conf, &conf->node, list);
171     return conf;
172     }
173    
174     void
175     conf_free(struct MaskItem *conf)
176     {
177 michael 4815 dlink_node *node = NULL, *node_next = NULL;
178 michael 1636 dlink_list *list = NULL;
179    
180 michael 4511 if ((list = map_to_list(conf->type)))
181 michael 4523 dlinkFindDelete(list, conf);
182 michael 4511
183 michael 7032 xfree(conf->name);
184 michael 1632
185     if (conf->dns_pending)
186     delete_resolver_queries(conf);
187 michael 3235 if (conf->passwd)
188 michael 1632 memset(conf->passwd, 0, strlen(conf->passwd));
189 michael 3235 if (conf->spasswd)
190 michael 1632 memset(conf->spasswd, 0, strlen(conf->spasswd));
191    
192     conf->class = NULL;
193    
194 michael 7032 xfree(conf->passwd);
195     xfree(conf->spasswd);
196     xfree(conf->reason);
197     xfree(conf->certfp);
198     xfree(conf->whois);
199     xfree(conf->user);
200     xfree(conf->host);
201     xfree(conf->cipher_list);
202 michael 1632
203 michael 4815 DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head)
204 michael 1632 {
205 michael 7032 xfree(node->data);
206 michael 4815 dlinkDelete(node, &conf->hub_list);
207     free_dlink_node(node);
208 michael 1632 }
209    
210 michael 4815 DLINK_FOREACH_SAFE(node, node_next, conf->leaf_list.head)
211 michael 1632 {
212 michael 7032 xfree(node->data);
213 michael 4815 dlinkDelete(node, &conf->leaf_list);
214     free_dlink_node(node);
215 michael 1632 }
216 adx 30
217 michael 4815 DLINK_FOREACH_SAFE(node, node_next, conf->exempt_list.head)
218 michael 1858 {
219 michael 4815 struct exempt *exptr = node->data;
220 michael 1858
221 michael 4815 dlinkDelete(node, &conf->exempt_list);
222 michael 7032 xfree(exptr->name);
223     xfree(exptr->user);
224     xfree(exptr->host);
225     xfree(exptr);
226 michael 1858 }
227    
228 michael 7032 xfree(conf);
229 adx 30 }
230    
231 michael 4982 /* attach_iline()
232 adx 30 *
233 michael 4982 * inputs - client pointer
234     * - conf pointer
235     * output -
236     * side effects - do actual attach
237 adx 30 */
238 michael 4982 static int
239     attach_iline(struct Client *client_p, struct MaskItem *conf)
240 adx 30 {
241 michael 4982 const struct ClassItem *const class = conf->class;
242     struct ip_entry *ip_found;
243     int a_limit_reached = 0;
244     unsigned int local = 0, global = 0, ident = 0;
245 michael 2916
246 michael 4982 ip_found = ipcache_find_or_add_address(&client_p->connection->ip);
247     ip_found->count++;
248     AddFlag(client_p, FLAGS_IPHASH);
249 adx 30
250 michael 6441 userhost_count(client_p->username, client_p->host,
251     &global, &local, &ident);
252 adx 30
253 michael 4982 /* XXX blah. go down checking the various silly limits
254     * setting a_limit_reached if any limit is reached.
255     * - Dianora
256     */
257     if (class->max_total && class->ref_count >= class->max_total)
258     a_limit_reached = 1;
259     else if (class->max_perip && ip_found->count > class->max_perip)
260     a_limit_reached = 1;
261     else if (class->max_local && local >= class->max_local)
262     a_limit_reached = 1;
263     else if (class->max_global && global >= class->max_global)
264     a_limit_reached = 1;
265     else if (class->max_ident && ident >= class->max_ident &&
266     client_p->username[0] != '~')
267     a_limit_reached = 1;
268 adx 30
269 michael 4982 if (a_limit_reached)
270     {
271     if (!IsConfExemptLimits(conf))
272     return TOO_MANY; /* Already at maximum allowed */
273 adx 30
274 michael 4982 sendto_one_notice(client_p, &me, ":*** Your connection class is full, "
275     "but you have exceed_limit = yes;");
276 adx 30 }
277    
278 michael 4982 return attach_conf(client_p, conf);
279 adx 30 }
280    
281     /* verify_access()
282     *
283 michael 4982 * inputs - pointer to client to verify
284     * output - 0 if success -'ve if not
285     * side effect - find the first (best) I line to attach.
286 adx 30 */
287     static int
288 michael 1644 verify_access(struct Client *client_p)
289 adx 30 {
290 michael 1949 struct MaskItem *conf = NULL;
291 adx 30
292 michael 6313 if (HasFlag(client_p, FLAGS_GOTID))
293 adx 30 {
294 michael 1632 conf = find_address_conf(client_p->host, client_p->username,
295 michael 4588 &client_p->connection->ip,
296     client_p->connection->aftype,
297     client_p->connection->password);
298 adx 30 }
299     else
300     {
301 michael 5583 char non_ident[USERLEN + 1] = "~";
302    
303 michael 2182 strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
304 michael 4982 conf = find_address_conf(client_p->host, non_ident,
305 michael 4588 &client_p->connection->ip,
306     client_p->connection->aftype,
307     client_p->connection->password);
308 adx 30 }
309    
310 michael 5805 if (!conf)
311     return NOT_AUTHORIZED;
312    
313     assert(IsConfClient(conf) || IsConfKill(conf));
314    
315     if (IsConfClient(conf))
316 adx 30 {
317 michael 5805 if (IsConfRedir(conf))
318 adx 30 {
319 michael 5805 sendto_one_numeric(client_p, &me, RPL_REDIR,
320     conf->name ? conf->name : "",
321     conf->port);
322     return NOT_AUTHORIZED;
323     }
324 adx 30
325 michael 5805 if (IsConfDoSpoofIp(conf))
326     {
327     if (IsConfSpoofNotice(conf))
328 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s",
329 michael 5805 client_p->name, client_p->host, conf->name);
330 michael 4982
331 michael 5805 strlcpy(client_p->host, conf->name, sizeof(client_p->host));
332 adx 30 }
333 michael 4982
334 michael 5805 return attach_iline(client_p, conf);
335 adx 30 }
336    
337 michael 5805 sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
338     return BANNED_CLIENT;
339 adx 30 }
340    
341 michael 4982 /* check_client()
342 adx 30 *
343 michael 4982 * inputs - pointer to client
344     * output - 0 = Success
345     * NOT_AUTHORIZED (-1) = Access denied (no I line match)
346     * IRCD_SOCKET_ERROR (-2) = Bad socket.
347     * I_LINE_FULL (-3) = I-line is full
348     * TOO_MANY (-4) = Too many connections from hostname
349     * BANNED_CLIENT (-5) = K-lined
350     * side effects - Ordinary client access check.
351     * Look for conf lines which have the same
352     * status as the flags passed.
353 adx 30 */
354 michael 4982 int
355     check_client(struct Client *source_p)
356 adx 30 {
357 michael 4982 int i;
358 adx 30
359 michael 4982 if ((i = verify_access(source_p)))
360     ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
361     source_p->name, source_p->sockhost);
362 adx 30
363 michael 4982 switch (i)
364     {
365     case TOO_MANY:
366     sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
367     "Too many on IP for %s (%s).",
368     get_client_name(source_p, SHOW_IP),
369     source_p->sockhost);
370     ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
371     get_client_name(source_p, SHOW_IP));
372     ++ServerStats.is_ref;
373     exit_client(source_p, "No more connections allowed on that IP");
374     break;
375 adx 30
376 michael 4982 case I_LINE_FULL:
377     sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
378     "auth {} block is full for %s (%s).",
379     get_client_name(source_p, SHOW_IP),
380     source_p->sockhost);
381     ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
382     get_client_name(source_p, SHOW_IP));
383     ++ServerStats.is_ref;
384     exit_client(source_p, "No more connections allowed in your connection class");
385     break;
386 adx 30
387 michael 4982 case NOT_AUTHORIZED:
388     /* jdc - lists server name & port connections are on */
389     /* a purely cosmetical change */
390     sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
391     "Unauthorized client connection from %s [%s] on [%s/%u].",
392     get_client_name(source_p, SHOW_IP),
393     source_p->sockhost,
394     source_p->connection->listener->name,
395     source_p->connection->listener->port);
396     ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].",
397     get_client_name(source_p, SHOW_IP),
398     source_p->connection->listener->name,
399     source_p->connection->listener->port);
400 adx 30
401 michael 4982 ++ServerStats.is_ref;
402     exit_client(source_p, "You are not authorized to use this server");
403     break;
404    
405     case BANNED_CLIENT:
406     ++ServerStats.is_ref;
407     exit_client(source_p, "Banned");
408     break;
409    
410     case 0:
411     default:
412     break;
413 adx 30 }
414    
415 michael 4982 return !(i < 0);
416 adx 30 }
417    
418     /* detach_conf()
419     *
420     * inputs - pointer to client to detach
421     * - type of conf to detach
422     * output - 0 for success, -1 for failure
423     * side effects - Disassociate configuration from the client.
424     * Also removes a class from the list if marked for deleting.
425     */
426 michael 1632 void
427     detach_conf(struct Client *client_p, enum maskitem_type type)
428 adx 30 {
429 michael 4815 dlink_node *node = NULL, *node_next = NULL;
430 adx 30
431 michael 4815 DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head)
432 adx 30 {
433 michael 4815 struct MaskItem *conf = node->data;
434 adx 30
435 michael 1645 assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
436     assert(conf->ref_count > 0);
437     assert(conf->class->ref_count > 0);
438 adx 30
439 michael 1645 if (!(conf->type & type))
440     continue;
441 michael 671
442 michael 4815 dlinkDelete(node, &client_p->connection->confs);
443     free_dlink_node(node);
444 michael 1644
445 michael 2278 if (conf->type == CONF_CLIENT)
446 michael 4588 remove_from_cidr_check(&client_p->connection->ip, conf->class);
447 adx 30
448 michael 1645 if (--conf->class->ref_count == 0 && conf->class->active == 0)
449     {
450     class_free(conf->class);
451     conf->class = NULL;
452 adx 30 }
453 michael 1645
454     if (--conf->ref_count == 0 && conf->active == 0)
455     conf_free(conf);
456 adx 30 }
457     }
458    
459     /* attach_conf()
460     *
461     * inputs - client pointer
462     * - conf pointer
463     * output -
464     * side effects - Associate a specific configuration entry to a *local*
465     * client (this is the one which used in accepting the
466     * connection). Note, that this automatically changes the
467     * attachment if there was an old one...
468     */
469     int
470 michael 1632 attach_conf(struct Client *client_p, struct MaskItem *conf)
471 adx 30 {
472 michael 4588 if (dlinkFind(&client_p->connection->confs, conf))
473 adx 30 return 1;
474    
475 michael 1632 if (conf->type == CONF_CLIENT)
476     if (cidr_limit_reached(IsConfExemptLimits(conf),
477 michael 4588 &client_p->connection->ip, conf->class))
478 michael 1394 return TOO_MANY; /* Already at maximum allowed */
479 adx 30
480 michael 1632 conf->class->ref_count++;
481 michael 1644 conf->ref_count++;
482 adx 30
483 michael 4588 dlinkAdd(conf, make_dlink_node(), &client_p->connection->confs);
484 adx 30
485     return 0;
486     }
487    
488     /* attach_connect_block()
489     *
490     * inputs - pointer to server to attach
491     * - name of server
492     * - hostname of server
493     * output - true (1) if both are found, otherwise return false (0)
494     * side effects - find connect block and attach them to connecting client
495     */
496     int
497     attach_connect_block(struct Client *client_p, const char *name,
498     const char *host)
499     {
500 michael 4815 dlink_node *node = NULL;
501 adx 30
502 michael 5003 assert(host);
503 adx 30
504 michael 4815 DLINK_FOREACH(node, server_items.head)
505 adx 30 {
506 michael 4815 struct MaskItem *conf = node->data;
507 adx 30
508 michael 1652 if (match(conf->name, name) || match(conf->host, host))
509 adx 30 continue;
510    
511     attach_conf(client_p, conf);
512 michael 5776 return 1;
513 adx 30 }
514    
515     return 0;
516     }
517    
518     /* find_conf_name()
519     *
520     * inputs - pointer to conf link list to search
521     * - pointer to name to find
522     * - int mask of type of conf to find
523     * output - NULL or pointer to conf found
524     * side effects - find a conf entry which matches the name
525     * and has the given mask.
526     */
527 michael 1632 struct MaskItem *
528     find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
529 adx 30 {
530 michael 4815 dlink_node *node = NULL;
531 adx 30
532 michael 4815 DLINK_FOREACH(node, list->head)
533 adx 30 {
534 michael 4815 struct MaskItem *conf = node->data;
535 michael 2916
536 adx 30 if (conf->type == type)
537     {
538 michael 4596 if (conf->name && !irccmp(conf->name, name))
539     return conf;
540 adx 30 }
541     }
542    
543     return NULL;
544     }
545    
546     /* find_matching_name_conf()
547     *
548     * inputs - type of link list to look in
549     * - pointer to name string to find
550     * - pointer to user
551     * - pointer to host
552 michael 1644 * - optional flags to match on as well
553 michael 1632 * output - NULL or pointer to found struct MaskItem
554 adx 30 * side effects - looks for a match on name field
555     */
556 michael 1632 struct MaskItem *
557     find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
558 michael 1644 const char *host, unsigned int flags)
559 adx 30 {
560 michael 4815 dlink_node *node = NULL;
561     dlink_list *list = map_to_list(type);
562     struct MaskItem *conf = NULL;
563 adx 30
564     switch (type)
565     {
566 michael 1632 case CONF_XLINE:
567     case CONF_NRESV:
568 michael 1825 case CONF_CRESV:
569 michael 4815 DLINK_FOREACH(node, list->head)
570 adx 30 {
571 michael 4815 conf = node->data;
572 adx 30
573     if (EmptyString(conf->name))
574 michael 2182 continue;
575 michael 5003 if (name && !match(conf->name, name))
576 adx 30 {
577 michael 2182 if ((user == NULL && (host == NULL)))
578     return conf;
579 michael 7159 if ((conf->modes & flags) != flags)
580 adx 30 continue;
581 michael 2182 if (EmptyString(conf->user) || EmptyString(conf->host))
582     return conf;
583     if (!match(conf->user, user) && !match(conf->host, host))
584     return conf;
585 adx 30 }
586     }
587     break;
588    
589 michael 1632 case CONF_SERVER:
590 michael 4815 DLINK_FOREACH(node, list->head)
591 adx 30 {
592 michael 4815 conf = node->data;
593 adx 30
594 michael 5003 if (name && !match(name, conf->name))
595 adx 30 return conf;
596 michael 5003 if (host && !match(host, conf->host))
597 adx 30 return conf;
598     }
599     break;
600 michael 2916
601 adx 30 default:
602     break;
603     }
604     return NULL;
605     }
606    
607     /* find_exact_name_conf()
608     *
609     * inputs - type of link list to look in
610     * - pointer to name string to find
611     * - pointer to user
612     * - pointer to host
613 michael 1632 * output - NULL or pointer to found struct MaskItem
614 adx 30 * side effects - looks for an exact match on name field
615     */
616 michael 1632 struct MaskItem *
617     find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
618 adx 30 const char *user, const char *host)
619     {
620 michael 4815 dlink_node *node = NULL;
621     dlink_list *list = map_to_list(type);
622     struct MaskItem *conf = NULL;
623 adx 30
624     switch(type)
625     {
626 michael 1632 case CONF_XLINE:
627     case CONF_NRESV:
628 michael 1825 case CONF_CRESV:
629 adx 30
630 michael 4815 DLINK_FOREACH(node, list->head)
631 adx 30 {
632 michael 4815 conf = node->data;
633 michael 1632
634 adx 30 if (EmptyString(conf->name))
635 michael 2182 continue;
636 michael 2916
637 adx 30 if (irccmp(conf->name, name) == 0)
638     {
639 michael 2182 if ((user == NULL && (host == NULL)))
640     return conf;
641     if (EmptyString(conf->user) || EmptyString(conf->host))
642     return conf;
643     if (!match(conf->user, user) && !match(conf->host, host))
644     return conf;
645 adx 30 }
646     }
647     break;
648    
649 michael 1632 case CONF_OPER:
650 michael 4815 DLINK_FOREACH(node, list->head)
651 adx 30 {
652 michael 4815 conf = node->data;
653 michael 1285
654 adx 30 if (EmptyString(conf->name))
655 michael 1285 continue;
656    
657     if (!irccmp(conf->name, name))
658 adx 30 {
659 michael 1285 if (!who)
660     return conf;
661 michael 1632 if (EmptyString(conf->user) || EmptyString(conf->host))
662 michael 1636 return NULL;
663 michael 1652 if (!match(conf->user, who->username))
664 michael 1285 {
665 michael 1632 switch (conf->htype)
666 michael 1285 {
667     case HM_HOST:
668 michael 1652 if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
669 michael 1637 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
670     return conf;
671 michael 1285 break;
672     case HM_IPV4:
673 michael 4588 if (who->connection->aftype == AF_INET)
674     if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits))
675 michael 1637 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
676     return conf;
677 michael 1285 break;
678     case HM_IPV6:
679 michael 4588 if (who->connection->aftype == AF_INET6)
680     if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits))
681 michael 1637 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
682     return conf;
683 michael 1285 break;
684     default:
685     assert(0);
686     }
687     }
688 adx 30 }
689     }
690 michael 1285
691 adx 30 break;
692    
693 michael 1632 case CONF_SERVER:
694 michael 4815 DLINK_FOREACH(node, list->head)
695 adx 30 {
696 michael 4815 conf = node->data;
697 michael 1632
698 adx 30 if (EmptyString(conf->name))
699 michael 2182 continue;
700 michael 2916
701 adx 30 if (name == NULL)
702     {
703 michael 2182 if (EmptyString(conf->host))
704     continue;
705     if (irccmp(conf->host, host) == 0)
706     return conf;
707 adx 30 }
708     else if (irccmp(conf->name, name) == 0)
709 michael 2182 return conf;
710 adx 30 }
711 michael 2182
712 adx 30 break;
713    
714     default:
715     break;
716     }
717 michael 2182
718     return NULL;
719 adx 30 }
720    
721     /* set_default_conf()
722     *
723     * inputs - NONE
724     * output - NONE
725     * side effects - Set default values here.
726     * This is called **PRIOR** to parsing the
727     * configuration file. If you want to do some validation
728     * of values later, put them in validate_conf().
729     */
730     static void
731     set_default_conf(void)
732     {
733     /* verify init_class() ran, this should be an unnecessary check
734     * but its not much work.
735     */
736 michael 1644 assert(class_default == class_get_list()->tail->data);
737 adx 30
738 michael 4340 ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
739     ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
740 adx 30
741 michael 4340 memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip));
742     ConfigServerInfo.specific_ipv4_vhost = 0;
743     memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6));
744     ConfigServerInfo.specific_ipv6_vhost = 0;
745 adx 30
746 michael 5489 ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX;
747 michael 4340 ConfigServerInfo.max_nick_length = 9;
748     ConfigServerInfo.max_topic_length = 80;
749     ConfigServerInfo.hub = 0;
750 michael 4313
751 michael 1831 log_del_all();
752 michael 1247
753 michael 4340 ConfigLog.use_logging = 1;
754 adx 30
755 michael 1243 ConfigChannel.disable_fake_channels = 0;
756 michael 3860 ConfigChannel.invite_client_count = 10;
757     ConfigChannel.invite_client_time = 300;
758 michael 6792 ConfigChannel.invite_delay_channel = 5;
759 michael 3860 ConfigChannel.knock_client_count = 1;
760     ConfigChannel.knock_client_time = 300;
761 adx 30 ConfigChannel.knock_delay_channel = 60;
762 michael 3933 ConfigChannel.max_channels = 25;
763 adx 30 ConfigChannel.max_bans = 25;
764 michael 5489 ConfigChannel.default_join_flood_count = 18;
765     ConfigChannel.default_join_flood_time = 6;
766 adx 30
767 michael 1243 ConfigServerHide.flatten_links = 0;
768 michael 6597 ConfigServerHide.flatten_links_delay = 300;
769 michael 1243 ConfigServerHide.hidden = 0;
770     ConfigServerHide.hide_servers = 0;
771 michael 1851 ConfigServerHide.hide_services = 0;
772 michael 1646 ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
773 michael 1243 ConfigServerHide.hide_server_ips = 0;
774 michael 2196 ConfigServerHide.disable_remote_commands = 0;
775 adx 30
776 michael 4340 ConfigGeneral.away_count = 2;
777     ConfigGeneral.away_time = 10;
778 michael 6740 ConfigGeneral.max_watch = 50;
779 michael 4340 ConfigGeneral.cycle_on_host_change = 1;
780 michael 5805 ConfigGeneral.dline_min_cidr = 16;
781     ConfigGeneral.dline_min_cidr6 = 48;
782     ConfigGeneral.kline_min_cidr = 16;
783     ConfigGeneral.kline_min_cidr6 = 48;
784 michael 4340 ConfigGeneral.invisible_on_connect = 1;
785     ConfigGeneral.tkline_expire_notices = 1;
786     ConfigGeneral.ignore_bogus_ts = 0;
787     ConfigGeneral.disable_auth = 0;
788     ConfigGeneral.kill_chase_time_limit = 90;
789     ConfigGeneral.default_floodcount = 8;
790     ConfigGeneral.failed_oper_notice = 1;
791     ConfigGeneral.dots_in_ident = 0;
792     ConfigGeneral.min_nonwildcard = 4;
793     ConfigGeneral.min_nonwildcard_simple = 3;
794 michael 6740 ConfigGeneral.max_accept = 50;
795 michael 4340 ConfigGeneral.anti_nick_flood = 0;
796     ConfigGeneral.max_nick_time = 20;
797     ConfigGeneral.max_nick_changes = 5;
798     ConfigGeneral.anti_spam_exit_message_time = 0;
799 michael 6956 ConfigGeneral.ts_warn_delta = 30;
800     ConfigGeneral.ts_max_delta = 600;
801 michael 4340 ConfigGeneral.warn_no_connect_block = 1;
802     ConfigGeneral.stats_e_disabled = 0;
803 michael 5025 ConfigGeneral.stats_i_oper_only = 1; /* 1 = masked */
804 michael 4340 ConfigGeneral.stats_k_oper_only = 1; /* 1 = masked */
805 michael 5025 ConfigGeneral.stats_o_oper_only = 1;
806     ConfigGeneral.stats_m_oper_only = 1;
807 michael 4340 ConfigGeneral.stats_P_oper_only = 0;
808     ConfigGeneral.stats_u_oper_only = 0;
809     ConfigGeneral.caller_id_wait = 60;
810     ConfigGeneral.opers_bypass_callerid = 0;
811     ConfigGeneral.pace_wait = 10;
812     ConfigGeneral.pace_wait_simple = 1;
813     ConfigGeneral.short_motd = 0;
814     ConfigGeneral.ping_cookie = 0;
815     ConfigGeneral.no_oper_flood = 0;
816     ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT;
817 michael 5506 ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT |
818     UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE |
819     UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN;
820 michael 4340 ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP;
821     ConfigGeneral.throttle_count = 1;
822     ConfigGeneral.throttle_time = 1;
823 adx 30 }
824    
825     static void
826     validate_conf(void)
827     {
828 michael 5039 if (EmptyString(ConfigServerInfo.network_name))
829 michael 4340 ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
830 adx 30
831 michael 5039 if (EmptyString(ConfigServerInfo.network_desc))
832 michael 4340 ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
833 adx 30 }
834    
835 michael 2916 /* read_conf()
836 michael 1363 *
837     * inputs - file descriptor pointing to config file to use
838     * output - None
839     * side effects - Read configuration file.
840     */
841     static void
842     read_conf(FILE *file)
843     {
844     lineno = 0;
845    
846 michael 3375 set_default_conf(); /* Set default values prior to conf parsing */
847 michael 1363 conf_parser_ctx.pass = 1;
848 michael 3375 yyparse(); /* Pick up the classes first */
849 michael 1363
850     rewind(file);
851    
852     conf_parser_ctx.pass = 2;
853 michael 3375 yyparse(); /* Load the values from the conf */
854     validate_conf(); /* Check to make sure some values are still okay. */
855     /* Some global values are also loaded here. */
856     class_delete_marked(); /* Delete unused classes that are marked for deletion */
857 michael 1363 }
858    
859 michael 4982 /* conf_rehash()
860     *
861     * Actual REHASH service routine. Called with sig == 0 if it has been called
862     * as a result of an operator issuing this command, else assume it has been
863     * called as a result of the server receiving a HUP signal.
864     */
865 michael 5776 void
866 michael 4982 conf_rehash(int sig)
867     {
868     if (sig)
869 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
870 michael 4982 "Got signal SIGHUP, reloading configuration file(s)");
871    
872     restart_resolver();
873    
874     /* don't close listeners until we know we can go ahead with the rehash */
875    
876     read_conf_files(0);
877    
878     load_conf_modules();
879     check_conf_klines();
880     }
881    
882 adx 30 /* lookup_confhost()
883     *
884     * start DNS lookups of all hostnames in the conf
885     * line and convert an IP addresses in a.b.c.d number for to IP#s.
886     */
887 michael 1647 void
888 michael 1632 lookup_confhost(struct MaskItem *conf)
889 adx 30 {
890     struct addrinfo hints, *res;
891    
892 michael 3375 /*
893     * Do name lookup now on hostnames given and store the
894 adx 30 * ip numbers in conf structure.
895     */
896     memset(&hints, 0, sizeof(hints));
897    
898     hints.ai_family = AF_UNSPEC;
899     hints.ai_socktype = SOCK_STREAM;
900    
901     /* Get us ready for a bind() and don't bother doing dns lookup */
902     hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
903    
904 michael 1632 if (getaddrinfo(conf->host, NULL, &hints, &res))
905 adx 30 {
906 michael 1632 conf_dns_lookup(conf);
907 adx 30 return;
908     }
909    
910 michael 3235 assert(res);
911 adx 30
912 michael 1632 memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
913     conf->addr.ss_len = res->ai_addrlen;
914     conf->addr.ss.ss_family = res->ai_family;
915    
916 michael 1123 freeaddrinfo(res);
917 adx 30 }
918    
919     /* conf_connect_allowed()
920     *
921     * inputs - pointer to inaddr
922     * - int type ipv4 or ipv6
923     * output - BANNED or accepted
924     * side effects - none
925     */
926     int
927     conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
928     {
929 michael 3877 struct ip_entry *ip_found = NULL;
930 michael 6549 const struct MaskItem *conf = find_dline_conf(addr, aftype);
931 adx 30
932 michael 3235 if (conf)
933 michael 6549 {
934     /* DLINE exempt also gets you out of static limits/pacing... */
935     if (conf->type == CONF_EXEMPT)
936     return 0;
937 adx 30 return BANNED_CLIENT;
938 michael 6549 }
939 adx 30
940 michael 4325 ip_found = ipcache_find_or_add_address(addr);
941 adx 30
942 michael 4340 if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
943 adx 30 {
944 michael 4340 if (ip_found->connection_count >= ConfigGeneral.throttle_count)
945 michael 3877 return TOO_FAST;
946 michael 4055
947     ++ip_found->connection_count;
948 adx 30 }
949 michael 3877 else
950     ip_found->connection_count = 1;
951 adx 30
952     ip_found->last_attempt = CurrentTime;
953     return 0;
954     }
955    
956     /* expire_tklines()
957     *
958     * inputs - tkline list pointer
959     * output - NONE
960     * side effects - expire tklines
961     */
962     static void
963 michael 4815 expire_tklines(dlink_list *list)
964 adx 30 {
965 michael 4815 dlink_node *node = NULL, *node_next = NULL;
966 adx 30
967 michael 4815 DLINK_FOREACH_SAFE(node, node_next, list->head)
968 adx 30 {
969 michael 4815 struct MaskItem *conf = node->data;
970 adx 30
971 michael 1649 if (!conf->until || conf->until > CurrentTime)
972 michael 1644 continue;
973    
974 michael 5871 if (ConfigGeneral.tkline_expire_notices)
975 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "Temporary %s for [%s] expired",
976 michael 5871 (conf->type == CONF_XLINE) ? "X-line" : "RESV", conf->name);
977     conf_free(conf);
978 adx 30 }
979     }
980    
981 michael 4982 /* cleanup_tklines()
982     *
983     * inputs - NONE
984     * output - NONE
985     * side effects - call function to expire temporary k/d lines
986     * This is an event started off in ircd.c
987     */
988     void
989     cleanup_tklines(void *unused)
990     {
991     hostmask_expire_temporary();
992 michael 6716 expire_tklines(&gecos_items);
993 michael 4982 expire_tklines(&nresv_items);
994     expire_tklines(&cresv_items);
995     }
996    
997 adx 30 /* oper_privs_as_string()
998     *
999 michael 58 * inputs - pointer to client_p
1000 adx 30 * output - pointer to static string showing oper privs
1001     * side effects - return as string, the oper privs as derived from port
1002     */
1003 michael 7226 static const struct oper_flags
1004 michael 58 {
1005 michael 1644 const unsigned int flag;
1006 michael 58 const unsigned char c;
1007 michael 7226 } flag_table[] = {
1008 michael 2012 { OPER_FLAG_ADMIN, 'A' },
1009 michael 6691 { OPER_FLAG_CLOSE, 'B' },
1010     { OPER_FLAG_CONNECT, 'C' },
1011     { OPER_FLAG_CONNECT_REMOTE, 'D' },
1012     { OPER_FLAG_DIE, 'E' },
1013     { OPER_FLAG_DLINE, 'F' },
1014     { OPER_FLAG_GLOBOPS, 'G' },
1015     { OPER_FLAG_JOIN_RESV, 'H' },
1016     { OPER_FLAG_KILL, 'I' },
1017     { OPER_FLAG_KILL_REMOTE, 'J' },
1018 michael 4019 { OPER_FLAG_KLINE, 'K' },
1019 michael 6691 { OPER_FLAG_LOCOPS, 'L' },
1020     { OPER_FLAG_MODULE, 'M' },
1021     { OPER_FLAG_NICK_RESV, 'N' },
1022     { OPER_FLAG_OPME, 'O' },
1023     { OPER_FLAG_REHASH, 'P' },
1024     { OPER_FLAG_REMOTEBAN, 'Q' },
1025     { OPER_FLAG_RESTART, 'R' },
1026     { OPER_FLAG_RESV, 'S' },
1027     { OPER_FLAG_SET, 'T' },
1028     { OPER_FLAG_SQUIT, 'U' },
1029     { OPER_FLAG_SQUIT_REMOTE, 'V' },
1030     { OPER_FLAG_UNDLINE, 'W' },
1031     { OPER_FLAG_UNKLINE, 'X' },
1032     { OPER_FLAG_UNRESV, 'Y' },
1033     { OPER_FLAG_UNXLINE, 'Z' },
1034     { OPER_FLAG_WALLOPS, 'a' },
1035     { OPER_FLAG_XLINE, 'b' },
1036 michael 1294 { 0, '\0' }
1037 michael 58 };
1038 adx 30
1039 michael 5639 const char *
1040 michael 7226 oper_privs_as_string(const unsigned int flags)
1041 adx 30 {
1042 michael 7226 static char buf[sizeof(flag_table) / sizeof(struct oper_flags)];
1043     char *p = buf;
1044 adx 30
1045 michael 7226 for (const struct oper_flags *tab = flag_table; tab->flag; ++tab)
1046     if (flags & tab->flag)
1047     *p++ = tab->c;
1048 michael 58
1049 michael 7226 if (p == buf)
1050     *p++ = '0';
1051 michael 6700
1052 michael 7226 *p = '\0';
1053 michael 58
1054 michael 7226 return buf;
1055 adx 30 }
1056    
1057     /*
1058 michael 4298 * Input: A client to find the active operator {} name for.
1059 adx 30 * Output: The nick!user@host{oper} of the oper.
1060     * "oper" is server name for remote opers
1061     * Side effects: None.
1062     */
1063 michael 1364 const char *
1064 adx 30 get_oper_name(const struct Client *client_p)
1065     {
1066 michael 5514 static char buffer[IRCD_BUFSIZE];
1067 adx 30
1068 michael 4628 if (IsServer(client_p))
1069     return client_p->name;
1070    
1071 adx 30 if (MyConnect(client_p))
1072     {
1073 michael 4977 const dlink_node *const node = client_p->connection->confs.head;
1074    
1075     if (node)
1076 adx 30 {
1077 michael 4937 const struct MaskItem *const conf = node->data;
1078 adx 30
1079 michael 4937 if (conf->type == CONF_OPER)
1080 adx 30 {
1081 michael 2182 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1082 michael 1147 client_p->username, client_p->host, conf->name);
1083 michael 2182 return buffer;
1084 adx 30 }
1085     }
1086    
1087 michael 4298 /*
1088     * Probably should assert here for now. If there is an oper out there
1089     * with no operator {} conf attached, it would be good for us to know...
1090 adx 30 */
1091 michael 4298 assert(0); /* Oper without oper conf! */
1092 adx 30 }
1093    
1094 michael 1147 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1095 michael 2182 client_p->username, client_p->host, client_p->servptr->name);
1096 adx 30 return buffer;
1097     }
1098    
1099     /* clear_out_old_conf()
1100     *
1101     * inputs - none
1102     * output - none
1103     * side effects - Clear out the old configuration
1104     */
1105     static void
1106     clear_out_old_conf(void)
1107     {
1108 michael 4815 dlink_node *node = NULL, *node_next = NULL;
1109 adx 30 dlink_list *free_items [] = {
1110 michael 6628 &server_items, &operator_items,
1111 michael 7209 &gecos_items,
1112 michael 7248 &nresv_items, &cresv_items, NULL
1113 adx 30 };
1114    
1115     dlink_list ** iterator = free_items; /* C is dumb */
1116    
1117     /* We only need to free anything allocated by yyparse() here.
1118     * Resetting structs, etc, is taken care of by set_default_conf().
1119     */
1120 michael 2916
1121 michael 5003 for (; *iterator; iterator++)
1122 adx 30 {
1123 michael 4815 DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head)
1124 adx 30 {
1125 michael 4815 struct MaskItem *conf = node->data;
1126 michael 1632
1127 michael 4523 conf->active = 0;
1128 michael 1632
1129 michael 5847 if (!IsConfDatabase(conf))
1130 adx 30 {
1131 michael 5847 dlinkDelete(&conf->node, *iterator);
1132    
1133 michael 5843 if (!conf->ref_count)
1134 michael 2182 conf_free(conf);
1135 adx 30 }
1136     }
1137     }
1138    
1139 michael 7229 motd_clear(); /* Clear motd {} items and re-cache default motd */
1140 michael 2150
1141 michael 671 /*
1142 michael 5583 * Don't delete the class table, rather mark all entries for deletion.
1143     * The table is cleaned up by class_delete_marked. - avalon
1144 adx 30 */
1145 michael 1632 class_mark_for_deletion();
1146 michael 671
1147 adx 30 clear_out_address_conf();
1148    
1149 michael 7245 modules_conf_clear(); /* Clear modules {} items */
1150 adx 30
1151 michael 7229 motd_clear(); /* Clear motd {} items and re-cache default motd */
1152    
1153 michael 7217 cluster_clear(); /* Clear cluster {} items */
1154 michael 4545
1155 michael 7248 service_clear(); /* Clear service {} items */
1156    
1157 michael 7209 shared_clear(); /* Clear shared {} items */
1158    
1159 michael 7217 pseudo_clear(); /* Clear pseudo {} items */
1160    
1161 michael 5583 /* Clean out ConfigServerInfo */
1162 michael 7032 xfree(ConfigServerInfo.description);
1163 michael 4340 ConfigServerInfo.description = NULL;
1164 michael 7032 xfree(ConfigServerInfo.network_name);
1165 michael 4340 ConfigServerInfo.network_name = NULL;
1166 michael 7032 xfree(ConfigServerInfo.network_desc);
1167 michael 4340 ConfigServerInfo.network_desc = NULL;
1168 adx 30
1169 michael 7032 xfree(ConfigServerInfo.rsa_private_key_file);
1170 michael 4340 ConfigServerInfo.rsa_private_key_file = NULL;
1171 michael 7105 xfree(ConfigServerInfo.ssl_certificate_file);
1172     ConfigServerInfo.ssl_certificate_file = NULL;
1173     xfree(ConfigServerInfo.ssl_dh_param_file);
1174     ConfigServerInfo.ssl_dh_param_file = NULL;
1175     xfree(ConfigServerInfo.ssl_dh_elliptic_curve);
1176     ConfigServerInfo.ssl_dh_elliptic_curve = NULL;
1177     xfree(ConfigServerInfo.ssl_cipher_list);
1178     ConfigServerInfo.ssl_cipher_list = NULL;
1179     xfree(ConfigServerInfo.ssl_message_digest_algorithm);
1180     ConfigServerInfo.ssl_message_digest_algorithm = NULL;
1181 adx 30
1182 michael 5583 /* Clean out ConfigAdminInfo */
1183 michael 7032 xfree(ConfigAdminInfo.name);
1184 michael 4340 ConfigAdminInfo.name = NULL;
1185 michael 7032 xfree(ConfigAdminInfo.email);
1186 michael 4340 ConfigAdminInfo.email = NULL;
1187 michael 7032 xfree(ConfigAdminInfo.description);
1188 michael 4340 ConfigAdminInfo.description = NULL;
1189 adx 30
1190 michael 7032 xfree(ConfigServerHide.flatten_links_file);
1191 michael 6599 ConfigServerHide.flatten_links_file = NULL;
1192    
1193 michael 5583 /* Clean out listeners */
1194 michael 6367 listener_close_marked();
1195 adx 30 }
1196    
1197 michael 7105 static void
1198     conf_handle_tls(int cold)
1199     {
1200     if (!tls_new_cred())
1201     {
1202     if (cold)
1203     {
1204     ilog(LOG_TYPE_IRCD, "Error while initializing TLS");
1205 michael 7230 exit(EXIT_FAILURE);
1206 michael 7105 }
1207     else
1208     {
1209     /* Failed to load new settings/certs, old ones remain active */
1210     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
1211     "Error reloading TLS settings, check the ircd log"); // report_crypto_errors logs this
1212     }
1213     }
1214     }
1215    
1216 michael 4982 /* read_conf_files()
1217     *
1218     * inputs - cold start YES or NO
1219     * output - none
1220     * side effects - read all conf files needed, ircd.conf kline.conf etc.
1221     */
1222     void
1223     read_conf_files(int cold)
1224     {
1225     const char *filename = NULL;
1226     char chanmodes[IRCD_BUFSIZE] = "";
1227     char chanlimit[IRCD_BUFSIZE] = "";
1228    
1229     conf_parser_ctx.boot = cold;
1230     filename = ConfigGeneral.configfile;
1231    
1232     /* We need to know the initial filename for the yyerror() to report
1233     FIXME: The full path is in conffilenamebuf first time since we
1234     don't know anything else
1235    
1236     - Gozem 2002-07-21
1237     */
1238     strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1239    
1240     if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1241     {
1242     if (cold)
1243     {
1244     ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1245     filename, strerror(errno));
1246 michael 6645 exit(EXIT_FAILURE);
1247 michael 4982 }
1248     else
1249     {
1250 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1251 michael 4982 "Unable to read configuration file '%s': %s",
1252     filename, strerror(errno));
1253     return;
1254     }
1255     }
1256    
1257     if (!cold)
1258     clear_out_old_conf();
1259    
1260     read_conf(conf_parser_ctx.conf_file);
1261     fclose(conf_parser_ctx.conf_file);
1262    
1263     log_reopen_all();
1264 michael 7105 conf_handle_tls(cold);
1265 michael 4982
1266 michael 6185 isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1267     isupport_add("NETWORK", ConfigServerInfo.network_name, -1);
1268 michael 4982
1269 michael 6842 snprintf(chanmodes, sizeof(chanmodes), "beI:%u", ConfigChannel.max_bans);
1270 michael 6185 isupport_add("MAXLIST", chanmodes, -1);
1271     isupport_add("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1272     isupport_add("CHANTYPES", "#", -1);
1273 michael 4982
1274 michael 6842 snprintf(chanlimit, sizeof(chanlimit), "#:%u",
1275 michael 4982 ConfigChannel.max_channels);
1276 michael 6185 isupport_add("CHANLIMIT", chanlimit, -1);
1277 michael 6936 snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstCMORST");
1278 michael 6185 isupport_add("CHANNELLEN", NULL, CHANNELLEN);
1279     isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1280     isupport_add("CHANMODES", chanmodes, -1);
1281 michael 4982
1282     /*
1283     * message_locale may have changed. rebuild isupport since it relies
1284     * on strlen(form_str(RPL_ISUPPORT))
1285     */
1286 michael 6185 isupport_rebuild();
1287 michael 4982 }
1288    
1289 adx 30 /* conf_add_class_to_conf()
1290     *
1291     * inputs - pointer to config item
1292     * output - NONE
1293 michael 2916 * side effects - Add a class pointer to a conf
1294 adx 30 */
1295     void
1296 michael 5797 conf_add_class_to_conf(struct MaskItem *conf, const char *name)
1297 adx 30 {
1298 michael 5797 if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL)
1299 adx 30 {
1300 michael 1632 conf->class = class_default;
1301 michael 671
1302 michael 4941 if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1303 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1304 michael 2182 "Warning *** Defaulting to default class for %s@%s",
1305     conf->user, conf->host);
1306 adx 30 else
1307 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1308 michael 2182 "Warning *** Defaulting to default class for %s",
1309     conf->name);
1310 adx 30 }
1311     }
1312    
1313     /* yyerror()
1314     *
1315     * inputs - message from parser
1316     * output - NONE
1317     * side effects - message to opers and log file entry is made
1318     */
1319     void
1320     yyerror(const char *msg)
1321     {
1322     char newlinebuf[IRCD_BUFSIZE];
1323    
1324 michael 967 if (conf_parser_ctx.pass != 1)
1325 adx 30 return;
1326    
1327     strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1328 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1329 michael 1618 "\"%s\", line %u: %s: %s",
1330 adx 30 conffilebuf, lineno + 1, msg, newlinebuf);
1331 michael 1247 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1332 adx 30 conffilebuf, lineno + 1, msg, newlinebuf);
1333     }
1334    
1335 michael 1751 void
1336     conf_error_report(const char *msg)
1337     {
1338     char newlinebuf[IRCD_BUFSIZE];
1339    
1340     strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1341 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1342 michael 1751 "\"%s\", line %u: %s: %s",
1343     conffilebuf, lineno + 1, msg, newlinebuf);
1344     ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1345     conffilebuf, lineno + 1, msg, newlinebuf);
1346     }
1347    
1348 adx 30 /*
1349     * valid_tkline()
1350 michael 2916 *
1351 adx 30 * inputs - pointer to ascii string to check
1352     * - whether the specified time is in seconds or minutes
1353     * output - -1 not enough parameters
1354     * - 0 if not an integer number, else the number
1355     * side effects - none
1356     * Originally written by Dianora (Diane, db@db.net)
1357     */
1358     time_t
1359 michael 2313 valid_tkline(const char *data, const int minutes)
1360 adx 30 {
1361 michael 2313 const unsigned char *p = (const unsigned char *)data;
1362     unsigned char tmpch = '\0';
1363 adx 30 time_t result = 0;
1364    
1365 michael 2313 while ((tmpch = *p++))
1366 adx 30 {
1367 michael 2313 if (!IsDigit(tmpch))
1368 michael 1121 return 0;
1369 michael 1120
1370     result *= 10;
1371 michael 2313 result += (tmpch & 0xF);
1372 adx 30 }
1373    
1374 michael 1120 /*
1375 michael 2916 * In the degenerate case where oper does a /quote kline 0 user@host :reason
1376 michael 5583 * i.e. they specifically use 0, I am going to return 1 instead as a return
1377     * value of non-zero is used to flag it as a temporary kline
1378 adx 30 */
1379     if (result == 0)
1380     result = 1;
1381    
1382 michael 2916 /*
1383 adx 30 * If the incoming time is in seconds convert it to minutes for the purpose
1384     * of this calculation
1385     */
1386     if (!minutes)
1387 michael 2916 result = result / 60;
1388 adx 30
1389     if (result > MAX_TDKLINE_TIME)
1390     result = MAX_TDKLINE_TIME;
1391    
1392 michael 5583 result = result * 60; /* Turn it into seconds */
1393 adx 30
1394     return result;
1395     }
1396    
1397 michael 2130 /* valid_wild_card_simple()
1398     *
1399     * inputs - data to check for sufficient non-wildcard characters
1400     * outputs - 1 if valid, else 0
1401     * side effects - none
1402     */
1403     int
1404     valid_wild_card_simple(const char *data)
1405     {
1406     const unsigned char *p = (const unsigned char *)data;
1407     unsigned char tmpch = '\0';
1408 michael 6332 unsigned int nonwild = 0, wild = 0;
1409 michael 2130
1410     while ((tmpch = *p++))
1411     {
1412 michael 4265 if (tmpch == '\\' && *p)
1413 michael 2130 {
1414     ++p;
1415 michael 4340 if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1416 michael 2130 return 1;
1417     }
1418     else if (!IsMWildChar(tmpch))
1419     {
1420 michael 4340 if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1421 michael 2130 return 1;
1422     }
1423 michael 6332 else
1424     ++wild;
1425 michael 2130 }
1426    
1427 michael 6332 return !wild;
1428 michael 2130 }
1429    
1430 adx 30 /* valid_wild_card()
1431     *
1432     * input - pointer to client
1433     * - int flag, 0 for no warning oper 1 for warning oper
1434     * - count of following varargs to check
1435     * output - 0 if not valid, 1 if valid
1436     * side effects - NOTICE is given to source_p if warn is 1
1437     */
1438     int
1439 michael 5791 valid_wild_card(struct Client *source_p, int count, ...)
1440 adx 30 {
1441 michael 3931 unsigned char tmpch = '\0';
1442 michael 3870 unsigned int nonwild = 0;
1443 adx 30 va_list args;
1444    
1445     /*
1446     * Now we must check the user and host to make sure there
1447     * are at least NONWILDCHARS non-wildcard characters in
1448     * them, otherwise assume they are attempting to kline
1449     * *@* or some variant of that. This code will also catch
1450     * people attempting to kline *@*.tld, as long as NONWILDCHARS
1451     * is greater than 3. In that case, there are only 3 non-wild
1452     * characters (tld), so if NONWILDCHARS is 4, the kline will
1453     * be disallowed.
1454     * -wnder
1455     */
1456    
1457     va_start(args, count);
1458    
1459     while (count--)
1460     {
1461 michael 3931 const unsigned char *p = va_arg(args, const unsigned char *);
1462 adx 30 if (p == NULL)
1463     continue;
1464    
1465     while ((tmpch = *p++))
1466     {
1467     if (!IsKWildChar(tmpch))
1468     {
1469     /*
1470     * If we find enough non-wild characters, we can
1471     * break - no point in searching further.
1472     */
1473 michael 4340 if (++nonwild >= ConfigGeneral.min_nonwildcard)
1474 michael 2659 {
1475     va_end(args);
1476 adx 30 return 1;
1477 michael 2659 }
1478 adx 30 }
1479     }
1480     }
1481    
1482 michael 5791 if (IsClient(source_p))
1483 michael 3110 sendto_one_notice(source_p, &me,
1484 michael 4058 ":Please include at least %u non-wildcard characters with the mask",
1485 michael 4340 ConfigGeneral.min_nonwildcard);
1486 michael 2659 va_end(args);
1487 adx 30 return 0;
1488     }
1489    
1490 michael 4982 /* find_user_host()
1491     *
1492     * inputs - pointer to client placing kline
1493     * - pointer to user_host_or_nick
1494     * - pointer to user buffer
1495     * - pointer to host buffer
1496     * output - 0 if not ok to kline, 1 to kline i.e. if valid user host
1497     * side effects -
1498     */
1499     static int
1500     find_user_host(struct Client *source_p, char *user_host_or_nick,
1501 michael 5783 char *luser, char *lhost)
1502 michael 4982 {
1503     struct Client *target_p = NULL;
1504     char *hostp = NULL;
1505    
1506     if (lhost == NULL)
1507     {
1508     strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1509     return 1;
1510     }
1511    
1512     if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1513     {
1514     /* Explicit user@host mask given */
1515     if (hostp) /* I'm a little user@host */
1516     {
1517     *(hostp++) = '\0'; /* short and squat */
1518    
1519     if (*user_host_or_nick)
1520     strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1521     else
1522     strcpy(luser, "*");
1523    
1524     if (*hostp)
1525     strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */
1526     else
1527     strcpy(lhost, "*");
1528     }
1529     else
1530     {
1531     luser[0] = '*'; /* no @ found, assume its *@somehost */
1532     luser[1] = '\0';
1533     strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1534     }
1535    
1536     return 1;
1537     }
1538     else
1539     {
1540     /* Try to find user@host mask from nick */
1541     /* Okay to use source_p as the first param, because source_p == client_p */
1542     if ((target_p =
1543     find_chasing(source_p, user_host_or_nick)) == NULL)
1544     return 0; /* find_chasing sends ERR_NOSUCHNICK */
1545    
1546 michael 6313 if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
1547 michael 4982 {
1548     if (IsClient(source_p))
1549     sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1550     return 0;
1551     }
1552    
1553     /*
1554 michael 5583 * Turn the "user" bit into "*user", blow away '~'
1555 michael 4982 * if found in original user name (non-idented)
1556     */
1557     strlcpy(luser, target_p->username, USERLEN*4 + 1);
1558    
1559     if (target_p->username[0] == '~')
1560     luser[0] = '*';
1561    
1562 michael 6831 strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1563 michael 4982 return 1;
1564     }
1565    
1566     return 0;
1567     }
1568    
1569 adx 30 /* XXX should this go into a separate file ? -Dianora */
1570     /* parse_aline
1571     *
1572     * input - pointer to cmd name being used
1573     * - pointer to client using cmd
1574     * - parc parameter count
1575     * - parv[] list of parameters to parse
1576     * - parse_flags bit map of things to test
1577     * - pointer to user or string to parse into
1578     * - pointer to host or NULL to parse into if non NULL
1579 michael 2916 * - pointer to optional tkline time or NULL
1580 adx 30 * - pointer to target_server to parse into if non NULL
1581     * - pointer to reason to parse into
1582     *
1583 michael 5776 * output - 1 if valid, 0 if not valid
1584 adx 30 * side effects - A generalised k/d/x etc. line parser,
1585     * "ALINE [time] user@host|string [ON] target :reason"
1586     * will parse returning a parsed user, host if
1587     * h_p pointer is non NULL, string otherwise.
1588     * if tkline_time pointer is non NULL a tk line will be set
1589     * to non zero if found.
1590     * if tkline_time pointer is NULL and tk line is found,
1591     * error is reported.
1592     * if target_server is NULL and an "ON" is found error
1593     * is reported.
1594     * if reason pointer is NULL ignore pointer,
1595 db 936 * this allows use of parse_a_line in unkline etc.
1596 adx 30 *
1597     * - Dianora
1598     */
1599     int
1600     parse_aline(const char *cmd, struct Client *source_p,
1601 michael 2182 int parc, char **parv,
1602     int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1603     char **target_server, char **reason)
1604 adx 30 {
1605     int found_tkline_time=0;
1606 michael 5823 static char default_reason[] = CONF_NOREASON;
1607 adx 30 static char user[USERLEN*4+1];
1608     static char host[HOSTLEN*4+1];
1609    
1610     parv++;
1611     parc--;
1612    
1613     found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1614    
1615 michael 4982 if (found_tkline_time)
1616 adx 30 {
1617     parv++;
1618     parc--;
1619    
1620 michael 4982 if (tkline_time)
1621 adx 30 *tkline_time = found_tkline_time;
1622     else
1623     {
1624 michael 3110 sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1625 michael 5776 return 0;
1626 adx 30 }
1627     }
1628    
1629     if (parc == 0)
1630     {
1631 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1632 michael 5776 return 0;
1633 adx 30 }
1634    
1635     if (h_p == NULL)
1636     *up_p = *parv;
1637     else
1638     {
1639 michael 5783 if (find_user_host(source_p, *parv, user, host) == 0)
1640 michael 5776 return 0;
1641 adx 30
1642     *up_p = user;
1643     *h_p = host;
1644     }
1645 michael 2916
1646 adx 30 parc--;
1647     parv++;
1648    
1649 michael 4982 if (parc)
1650 adx 30 {
1651     if (irccmp(*parv, "ON") == 0)
1652     {
1653     parc--;
1654     parv++;
1655    
1656 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1657 adx 30 {
1658 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1659 michael 5776 return 0;
1660 adx 30 }
1661    
1662     if (parc == 0 || EmptyString(*parv))
1663     {
1664 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1665 michael 5776 return 0;
1666 adx 30 }
1667    
1668     *target_server = *parv;
1669     parc--;
1670     parv++;
1671     }
1672     else
1673     {
1674     /* Make sure target_server *is* NULL if no ON server found
1675     * caller probably NULL'd it first, but no harm to do it again -db
1676     */
1677 michael 4982 if (target_server)
1678 michael 2182 *target_server = NULL;
1679 adx 30 }
1680     }
1681    
1682 michael 4982 if (h_p)
1683 adx 30 {
1684 michael 4982 if (strchr(user, '!'))
1685 adx 30 {
1686 michael 3110 sendto_one_notice(source_p, &me, ":Invalid character '!' in kline");
1687 michael 5776 return 0;
1688 adx 30 }
1689    
1690 michael 5791 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 2, *up_p, *h_p))
1691 michael 5776 return 0;
1692 adx 30 }
1693     else
1694 michael 5791 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, *up_p))
1695 michael 5776 return 0;
1696 adx 30
1697 michael 4982 if (reason)
1698 adx 30 {
1699 michael 4982 if (parc && !EmptyString(*parv))
1700 adx 30 *reason = *parv;
1701     else
1702 michael 5823 *reason = default_reason;
1703 adx 30 }
1704    
1705     return 1;
1706     }
1707    
1708     /* match_conf_password()
1709     *
1710     * inputs - pointer to given password
1711     * - pointer to Conf
1712     * output - 1 or 0 if match
1713     * side effects - none
1714     */
1715     int
1716 michael 1632 match_conf_password(const char *password, const struct MaskItem *conf)
1717 adx 30 {
1718     const char *encr = NULL;
1719    
1720 michael 1632 if (EmptyString(password) || EmptyString(conf->passwd))
1721 adx 30 return 0;
1722    
1723 michael 1632 if (conf->flags & CONF_FLAGS_ENCRYPTED)
1724     encr = crypt(password, conf->passwd);
1725 adx 30 else
1726     encr = password;
1727    
1728 michael 3263 return encr && !strcmp(encr, conf->passwd);
1729 adx 30 }
1730    
1731     /*
1732     * split_nuh
1733     *
1734     * inputs - pointer to original mask (modified in place)
1735     * - pointer to pointer where nick should go
1736     * - pointer to pointer where user should go
1737     * - pointer to pointer where host should go
1738     * output - NONE
1739     * side effects - mask is modified in place
1740     * If nick pointer is NULL, ignore writing to it
1741     * this allows us to use this function elsewhere.
1742     *
1743     * mask nick user host
1744     * ---------------------- ------- ------- ------
1745     * Dianora!db@db.net Dianora db db.net
1746     * Dianora Dianora * *
1747     * db.net * * db.net
1748     * OR if nick pointer is NULL
1749     * Dianora - * Dianora
1750     * Dianora! Dianora * *
1751     * Dianora!@ Dianora * *
1752     * Dianora!db Dianora db *
1753     * Dianora!@db.net Dianora * db.net
1754     * db@db.net * db db.net
1755     * !@ * * *
1756     * @ * * *
1757     * ! * * *
1758     */
1759     void
1760 michael 593 split_nuh(struct split_nuh_item *const iptr)
1761 adx 30 {
1762     char *p = NULL, *q = NULL;
1763    
1764 michael 593 if (iptr->nickptr)
1765     strlcpy(iptr->nickptr, "*", iptr->nicksize);
1766 michael 4982
1767 michael 593 if (iptr->userptr)
1768     strlcpy(iptr->userptr, "*", iptr->usersize);
1769 michael 4982
1770 michael 593 if (iptr->hostptr)
1771     strlcpy(iptr->hostptr, "*", iptr->hostsize);
1772    
1773     if ((p = strchr(iptr->nuhmask, '!')))
1774 adx 30 {
1775     *p = '\0';
1776    
1777 michael 3375 if (iptr->nickptr && *iptr->nuhmask)
1778 michael 593 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1779 adx 30
1780 michael 2525 if ((q = strchr(++p, '@')))
1781     {
1782 michael 593 *q++ = '\0';
1783    
1784 michael 3375 if (*p)
1785 michael 593 strlcpy(iptr->userptr, p, iptr->usersize);
1786 adx 30
1787 michael 3375 if (*q)
1788 michael 593 strlcpy(iptr->hostptr, q, iptr->hostsize);
1789 adx 30 }
1790     else
1791     {
1792 michael 3375 if (*p)
1793 michael 593 strlcpy(iptr->userptr, p, iptr->usersize);
1794 adx 30 }
1795     }
1796 michael 593 else
1797 adx 30 {
1798 michael 593 /* No ! found so lets look for a user@host */
1799     if ((p = strchr(iptr->nuhmask, '@')))
1800 adx 30 {
1801 michael 593 /* if found a @ */
1802     *p++ = '\0';
1803 adx 30
1804 michael 3375 if (*iptr->nuhmask)
1805 michael 593 strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
1806 adx 30
1807 michael 3375 if (*p)
1808 michael 593 strlcpy(iptr->hostptr, p, iptr->hostsize);
1809 adx 30 }
1810 michael 593 else
1811 adx 30 {
1812 michael 5583 /* No @ found */
1813 michael 593 if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
1814     strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
1815 adx 30 else
1816 michael 593 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1817 adx 30 }
1818     }
1819     }

Properties

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