ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/conf.c
Revision: 7479
Committed: Wed Mar 16 08:53:26 2016 UTC (8 years ago) by michael
Content type: text/x-csrc
File size: 45033 byte(s)
Log Message:
- conf.c:read_conf_files(): removed isupport_rebuild() call no longer needed

File Contents

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

Properties

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