ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 8451
Committed: Fri Mar 30 15:15:15 2018 UTC (5 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 43645 byte(s)
Log Message:
- conf.c:clear_out_old_conf(): free ConfigServerHide.hidden_name

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

Properties

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