ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 8969
Committed: Sat May 18 11:58:06 2019 UTC (6 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 38970 byte(s)
Log Message:
- Move oper_privs_as_string() from conf.c to m_stats.c

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

Properties

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