ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 8391
Committed: Sat Mar 17 21:45:30 2018 UTC (7 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 43623 byte(s)
Log Message:
- Clean up some awful CONF_SERVER handling in serv_connect()

File Contents

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

Properties

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