ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 8279
Committed: Tue Feb 20 19:30:13 2018 UTC (7 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 44920 byte(s)
Log Message:
- Update copyright years

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

Properties

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