ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/conf.c
Revision: 7208
Committed: Wed Feb 3 15:06:47 2016 UTC (8 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 48593 byte(s)
Log Message:
- Clustering has been broken in -r7158. Rewrote most of the shared/cluster implementation to be less obscure.
  This introduces a little bit of code duplication, but increases readability, is less error prone, and
  reduces memory consumption a bit. 

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

Properties

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