ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/conf.c
Revision: 8865
Committed: Sat Feb 16 09:55:50 2019 UTC (5 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 40669 byte(s)
Log Message:
- The 'serverinfo::vhost' and 'serverinfo:vhost6' configuration directives have been deprecated. If you need to bind() a specific address you can specify one in the connect {} block
- The 'connect::vhost' configuration directive has been renamed to 'connect::bind'

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

Properties

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