ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 7403
Committed: Sun Mar 6 16:33:12 2016 UTC (9 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 45628 byte(s)
Log Message:
- Remove useless parameters from operator_find()

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

Properties

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