ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 7330
Committed: Fri Feb 19 17:50:13 2016 UTC (9 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 46694 byte(s)
Log Message:
- Now that we got time_t to work nicely on openbsd with snprintf's conversion specifiers,
  we ran into a similiar issue on Raspbian/ARMv7's time_t which is of signed 32 bit and
  doesn't cope at all with %j. Instead of doing tricks, get rid of time_t everywhere and
  forever and use uintmax_t instead which has at least a 'standardized' conversion specifier
  associated with it.

File Contents

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

Properties

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