ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 7282
Committed: Sun Feb 7 18:04:26 2016 UTC (8 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 48418 byte(s)
Log Message:
- Cleanup/separate RESV conf implementation

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

Properties

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