ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 7401
Committed: Sun Mar 6 16:15:22 2016 UTC (10 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 45678 byte(s)
Log Message:
- Cleanups to operator/connect block lookup routines

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

Properties

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