ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 7521
Committed: Sat Apr 2 15:55:37 2016 UTC (9 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 45043 byte(s)
Log Message:
- attach_connect_block(), check_server(): replace match() calls with irccmp() since the
  strings that are to be compared cannot contain wildcards anyway

File Contents

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

Properties

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