ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 2830
Committed: Thu Jan 16 15:23:07 2014 UTC (10 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 58764 byte(s)
Log Message:
- Tweak reloading/rehasing config files server notice

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 michael 1309 * conf.c: Configuration file functions.
4 adx 30 *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26 michael 1011 #include "list.h"
27 adx 30 #include "ircd_defs.h"
28 michael 1309 #include "conf.h"
29 adx 30 #include "s_serv.h"
30     #include "resv.h"
31     #include "channel.h"
32     #include "client.h"
33     #include "event.h"
34     #include "hook.h"
35     #include "irc_string.h"
36     #include "s_bsd.h"
37     #include "ircd.h"
38     #include "listener.h"
39     #include "hostmask.h"
40     #include "modules.h"
41     #include "numeric.h"
42     #include "fdlist.h"
43 michael 1309 #include "log.h"
44 adx 30 #include "send.h"
45     #include "s_gline.h"
46     #include "memory.h"
47 michael 1654 #include "mempool.h"
48 adx 30 #include "irc_res.h"
49     #include "userhost.h"
50     #include "s_user.h"
51     #include "channel_mode.h"
52 michael 1243 #include "parse.h"
53     #include "s_misc.h"
54 michael 1622 #include "conf_db.h"
55 michael 1632 #include "conf_class.h"
56 michael 2150 #include "motd.h"
57 adx 30
58     struct config_server_hide ConfigServerHide;
59    
60     /* general conf items link list root, other than k lines etc. */
61 michael 1157 dlink_list service_items = { NULL, NULL, 0 };
62 adx 30 dlink_list server_items = { NULL, NULL, 0 };
63     dlink_list cluster_items = { NULL, NULL, 0 };
64     dlink_list oconf_items = { NULL, NULL, 0 };
65     dlink_list uconf_items = { NULL, NULL, 0 };
66     dlink_list xconf_items = { NULL, NULL, 0 };
67     dlink_list nresv_items = { NULL, NULL, 0 };
68 michael 2174 dlink_list cresv_items = { NULL, NULL, 0 };
69 adx 30
70     extern unsigned int lineno;
71     extern char linebuf[];
72     extern char conffilebuf[IRCD_BUFSIZE];
73     extern int yyparse(); /* defined in y.tab.c */
74    
75 michael 967 struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
76    
77 adx 30 /* internally defined functions */
78 michael 1325 static void read_conf(FILE *);
79 adx 30 static void clear_out_old_conf(void);
80     static void expire_tklines(dlink_list *);
81     static void garbage_collect_ip_entries(void);
82     static int hash_ip(struct irc_ssaddr *);
83 michael 1644 static int verify_access(struct Client *);
84 michael 1632 static int attach_iline(struct Client *, struct MaskItem *);
85 adx 30 static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
86 michael 1632 static dlink_list *map_to_list(enum maskitem_type);
87 adx 30 static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
88    
89    
90     /* usually, with hash tables, you use a prime number...
91     * but in this case I am dealing with ip addresses,
92     * not ascii strings.
93     */
94     #define IP_HASH_SIZE 0x1000
95    
96     struct ip_entry
97     {
98     struct irc_ssaddr ip;
99 michael 1644 unsigned int count;
100 adx 30 time_t last_attempt;
101     struct ip_entry *next;
102     };
103    
104     static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
105 michael 1654 static mp_pool_t *ip_entry_pool = NULL;
106 adx 30 static int ip_entries_count = 0;
107    
108    
109     /* conf_dns_callback()
110     *
111 michael 1632 * inputs - pointer to struct MaskItem
112 adx 30 * - pointer to DNSReply reply
113     * output - none
114     * side effects - called when resolver query finishes
115     * if the query resulted in a successful search, hp will contain
116     * a non-null pointer, otherwise hp will be null.
117     * if successful save hp in the conf item it was called with
118     */
119     static void
120 michael 992 conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
121 adx 30 {
122 michael 1632 struct MaskItem *conf = vptr;
123 adx 30
124 michael 1632 conf->dns_pending = 0;
125 adx 30
126 michael 992 if (addr != NULL)
127 michael 1632 memcpy(&conf->addr, addr, sizeof(conf->addr));
128 michael 992 else
129 michael 1632 conf->dns_failed = 1;
130 adx 30 }
131    
132     /* conf_dns_lookup()
133     *
134     * do a nameserver lookup of the conf host
135     * if the conf entry is currently doing a ns lookup do nothing, otherwise
136     * allocate a dns_query and start ns lookup.
137     */
138     static void
139 michael 1632 conf_dns_lookup(struct MaskItem *conf)
140 adx 30 {
141 michael 1632 if (!conf->dns_pending)
142 adx 30 {
143 michael 1632 conf->dns_pending = 1;
144     gethost_byname(conf_dns_callback, conf, conf->host);
145 adx 30 }
146     }
147    
148 michael 1632 struct MaskItem *
149     conf_make(enum maskitem_type type)
150     {
151     struct MaskItem *conf = MyMalloc(sizeof(*conf));
152     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     dlink_node *ptr = NULL, *ptr_next = NULL;
167 michael 1636 dlink_list *list = NULL;
168    
169     if (conf->node.next)
170     if ((list = map_to_list(conf->type)))
171     dlinkDelete(&conf->node, list);
172    
173 michael 1632 MyFree(conf->name);
174    
175     if (conf->dns_pending)
176     delete_resolver_queries(conf);
177     if (conf->passwd != NULL)
178     memset(conf->passwd, 0, strlen(conf->passwd));
179     if (conf->spasswd != NULL)
180     memset(conf->spasswd, 0, strlen(conf->spasswd));
181    
182     conf->class = NULL;
183    
184     MyFree(conf->passwd);
185     MyFree(conf->spasswd);
186     MyFree(conf->reason);
187 michael 2228 MyFree(conf->certfp);
188 michael 1632 MyFree(conf->user);
189     MyFree(conf->host);
190     #ifdef HAVE_LIBCRYPTO
191     MyFree(conf->cipher_list);
192    
193     if (conf->rsa_public_key)
194     RSA_free(conf->rsa_public_key);
195     #endif
196     DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head)
197     {
198     MyFree(ptr->data);
199 michael 2736 dlinkDelete(ptr, &conf->hub_list);
200 michael 1632 free_dlink_node(ptr);
201     }
202    
203     DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
204     {
205     MyFree(ptr->data);
206 michael 2736 dlinkDelete(ptr, &conf->leaf_list);
207 michael 1632 free_dlink_node(ptr);
208     }
209 adx 30
210 michael 1858 DLINK_FOREACH_SAFE(ptr, ptr_next, conf->exempt_list.head)
211     {
212     struct exempt *exptr = ptr->data;
213    
214 michael 2736 dlinkDelete(ptr, &conf->exempt_list);
215 michael 1858 MyFree(exptr->name);
216     MyFree(exptr->user);
217     MyFree(exptr->host);
218     MyFree(exptr);
219     }
220    
221 michael 1636 MyFree(conf);
222 adx 30 }
223    
224     /* check_client()
225     *
226     * inputs - pointer to client
227     * output - 0 = Success
228     * NOT_AUTHORIZED (-1) = Access denied (no I line match)
229     * IRCD_SOCKET_ERROR (-2) = Bad socket.
230     * I_LINE_FULL (-3) = I-line is full
231     * TOO_MANY (-4) = Too many connections from hostname
232     * BANNED_CLIENT (-5) = K-lined
233     * side effects - Ordinary client access check.
234     * Look for conf lines which have the same
235     * status as the flags passed.
236     */
237 michael 1644 int
238     check_client(struct Client *source_p)
239 adx 30 {
240     int i;
241    
242 michael 1644 if ((i = verify_access(source_p)))
243 michael 1247 ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
244 adx 30 source_p->name, source_p->sockhost);
245    
246     switch (i)
247     {
248     case TOO_MANY:
249 michael 1618 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
250 adx 30 "Too many on IP for %s (%s).",
251 michael 2182 get_client_name(source_p, SHOW_IP),
252     source_p->sockhost);
253 michael 1247 ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
254 michael 2182 get_client_name(source_p, SHOW_IP));
255 michael 896 ++ServerStats.is_ref;
256 adx 30 exit_client(source_p, &me, "No more connections allowed on that IP");
257     break;
258    
259     case I_LINE_FULL:
260 michael 1618 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
261     "auth{} block is full for %s (%s).",
262 michael 2182 get_client_name(source_p, SHOW_IP),
263     source_p->sockhost);
264 michael 1247 ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
265 michael 2182 get_client_name(source_p, SHOW_IP));
266 michael 896 ++ServerStats.is_ref;
267 adx 30 exit_client(source_p, &me,
268 michael 2182 "No more connections allowed in your connection class");
269 adx 30 break;
270    
271     case NOT_AUTHORIZED:
272 michael 896 ++ServerStats.is_ref;
273 adx 30 /* jdc - lists server name & port connections are on */
274     /* a purely cosmetical change */
275 michael 1618 sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
276 michael 2182 "Unauthorized client connection from %s [%s] on [%s/%u].",
277     get_client_name(source_p, SHOW_IP),
278     source_p->sockhost,
279     source_p->localClient->listener->name,
280     source_p->localClient->listener->port);
281 michael 1247 ilog(LOG_TYPE_IRCD,
282 michael 2182 "Unauthorized client connection from %s on [%s/%u].",
283     get_client_name(source_p, SHOW_IP),
284     source_p->localClient->listener->name,
285     source_p->localClient->listener->port);
286 adx 30
287 michael 1549 exit_client(source_p, &me, "You are not authorized to use this server");
288 adx 30 break;
289 michael 891
290 adx 30 case BANNED_CLIENT:
291 michael 1549 exit_client(source_p, &me, "Banned");
292 michael 896 ++ServerStats.is_ref;
293 adx 30 break;
294    
295     case 0:
296     default:
297     break;
298     }
299    
300 michael 1644 return (i < 0 ? 0 : 1);
301 adx 30 }
302    
303     /* verify_access()
304     *
305     * inputs - pointer to client to verify
306     * output - 0 if success -'ve if not
307     * side effect - find the first (best) I line to attach.
308     */
309     static int
310 michael 1644 verify_access(struct Client *client_p)
311 adx 30 {
312 michael 1949 struct MaskItem *conf = NULL;
313 adx 30 char non_ident[USERLEN + 1] = { '~', '\0' };
314    
315     if (IsGotId(client_p))
316     {
317 michael 1632 conf = find_address_conf(client_p->host, client_p->username,
318 michael 2182 &client_p->localClient->ip,
319     client_p->localClient->aftype,
320 adx 30 client_p->localClient->passwd);
321     }
322     else
323     {
324 michael 2182 strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
325 michael 1632 conf = find_address_conf(client_p->host,non_ident,
326 michael 2182 &client_p->localClient->ip,
327     client_p->localClient->aftype,
328     client_p->localClient->passwd);
329 adx 30 }
330    
331 michael 1632 if (conf != NULL)
332 adx 30 {
333 michael 1921 if (IsConfClient(conf))
334 adx 30 {
335 michael 1632 if (IsConfRedir(conf))
336 adx 30 {
337 michael 1834 sendto_one(client_p, form_str(RPL_REDIR),
338 adx 30 me.name, client_p->name,
339     conf->name ? conf->name : "",
340 michael 1632 conf->port);
341 michael 2182 return NOT_AUTHORIZED;
342 adx 30 }
343    
344 michael 1632 if (IsConfDoIdentd(conf))
345 michael 2182 SetNeedId(client_p);
346 adx 30
347     /* Thanks for spoof idea amm */
348 michael 1632 if (IsConfDoSpoofIp(conf))
349 adx 30 {
350 michael 1632 if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf))
351 michael 1618 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
352     "%s spoofing: %s as %s",
353 adx 30 client_p->name, client_p->host, conf->name);
354     strlcpy(client_p->host, conf->name, sizeof(client_p->host));
355 michael 2138 AddFlag(client_p, FLAGS_IP_SPOOFING | FLAGS_AUTH_SPOOF);
356 adx 30 }
357    
358 michael 2182 return attach_iline(client_p, conf);
359 adx 30 }
360 michael 1921 else if (IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf)))
361 adx 30 {
362 michael 1632 if (IsConfGline(conf))
363 adx 30 sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
364     client_p->name);
365 michael 1549 sendto_one(client_p, ":%s NOTICE %s :*** Banned: %s",
366 michael 1632 me.name, client_p->name, conf->reason);
367 michael 2182 return BANNED_CLIENT;
368 adx 30 }
369     }
370    
371 michael 2182 return NOT_AUTHORIZED;
372 adx 30 }
373    
374     /* attach_iline()
375     *
376     * inputs - client pointer
377     * - conf pointer
378     * output -
379     * side effects - do actual attach
380     */
381     static int
382 michael 1632 attach_iline(struct Client *client_p, struct MaskItem *conf)
383 adx 30 {
384 michael 1632 struct ClassItem *class = NULL;
385 adx 30 struct ip_entry *ip_found;
386     int a_limit_reached = 0;
387 michael 1644 unsigned int local = 0, global = 0, ident = 0;
388 adx 30
389 michael 2317 assert(conf->class);
390    
391 adx 30 ip_found = find_or_add_ip(&client_p->localClient->ip);
392     ip_found->count++;
393     SetIpHash(client_p);
394    
395 michael 1632 class = conf->class;
396 adx 30
397     count_user_host(client_p->username, client_p->host,
398     &global, &local, &ident);
399    
400     /* XXX blah. go down checking the various silly limits
401     * setting a_limit_reached if any limit is reached.
402     * - Dianora
403     */
404 michael 1632 if (class->max_total != 0 && class->ref_count >= class->max_total)
405 adx 30 a_limit_reached = 1;
406 michael 1632 else if (class->max_perip != 0 && ip_found->count > class->max_perip)
407 adx 30 a_limit_reached = 1;
408 michael 1632 else if (class->max_local != 0 && local >= class->max_local)
409 adx 30 a_limit_reached = 1;
410 michael 1632 else if (class->max_global != 0 && global >= class->max_global)
411 adx 30 a_limit_reached = 1;
412 michael 1632 else if (class->max_ident != 0 && ident >= class->max_ident &&
413 adx 30 client_p->username[0] != '~')
414     a_limit_reached = 1;
415    
416     if (a_limit_reached)
417     {
418 michael 1632 if (!IsConfExemptLimits(conf))
419 michael 624 return TOO_MANY; /* Already at maximum allowed */
420 adx 30
421     sendto_one(client_p,
422     ":%s NOTICE %s :*** Your connection class is full, "
423     "but you have exceed_limit = yes;", me.name, client_p->name);
424     }
425    
426     return attach_conf(client_p, conf);
427     }
428    
429     /* init_ip_hash_table()
430     *
431     * inputs - NONE
432     * output - NONE
433     * side effects - allocate memory for ip_entry(s)
434     * - clear the ip hash table
435     */
436     void
437     init_ip_hash_table(void)
438     {
439 michael 1964 ip_entry_pool = mp_pool_new(sizeof(struct ip_entry), MP_CHUNK_SIZE_IP_ENTRY);
440 adx 30 memset(ip_hash_table, 0, sizeof(ip_hash_table));
441     }
442    
443     /* find_or_add_ip()
444     *
445     * inputs - pointer to struct irc_ssaddr
446     * output - pointer to a struct ip_entry
447     * side effects -
448     *
449     * If the ip # was not found, a new struct ip_entry is created, and the ip
450     * count set to 0.
451     */
452     static struct ip_entry *
453     find_or_add_ip(struct irc_ssaddr *ip_in)
454     {
455     struct ip_entry *ptr, *newptr;
456     int hash_index = hash_ip(ip_in), res;
457     struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
458     #ifdef IPV6
459     struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
460     #endif
461    
462     for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
463     {
464     #ifdef IPV6
465     if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
466     continue;
467     if (ip_in->ss.ss_family == AF_INET6)
468     {
469     ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
470     res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
471     }
472     else
473     #endif
474     {
475     ptr_v4 = (struct sockaddr_in *)&ptr->ip;
476     res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
477     }
478     if (res == 0)
479     {
480     /* Found entry already in hash, return it. */
481     return ptr;
482     }
483     }
484    
485     if (ip_entries_count >= 2 * hard_fdlimit)
486     garbage_collect_ip_entries();
487    
488 michael 1654 newptr = mp_pool_get(ip_entry_pool);
489     memset(newptr, 0, sizeof(*newptr));
490 adx 30 ip_entries_count++;
491     memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr));
492    
493     newptr->next = ip_hash_table[hash_index];
494     ip_hash_table[hash_index] = newptr;
495    
496     return newptr;
497     }
498    
499     /* remove_one_ip()
500     *
501     * inputs - unsigned long IP address value
502     * output - NONE
503     * side effects - The ip address given, is looked up in ip hash table
504     * and number of ip#'s for that ip decremented.
505     * If ip # count reaches 0 and has expired,
506     * the struct ip_entry is returned to the ip_entry_heap
507     */
508     void
509     remove_one_ip(struct irc_ssaddr *ip_in)
510     {
511     struct ip_entry *ptr;
512     struct ip_entry *last_ptr = NULL;
513     int hash_index = hash_ip(ip_in), res;
514     struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
515     #ifdef IPV6
516     struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
517     #endif
518    
519     for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
520     {
521     #ifdef IPV6
522     if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
523     continue;
524     if (ip_in->ss.ss_family == AF_INET6)
525     {
526     ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
527     res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
528     }
529     else
530     #endif
531     {
532     ptr_v4 = (struct sockaddr_in *)&ptr->ip;
533     res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
534     }
535     if (res)
536     continue;
537     if (ptr->count > 0)
538     ptr->count--;
539     if (ptr->count == 0 &&
540 michael 2182 (CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time)
541 adx 30 {
542     if (last_ptr != NULL)
543 michael 2182 last_ptr->next = ptr->next;
544 adx 30 else
545 michael 2182 ip_hash_table[hash_index] = ptr->next;
546 adx 30
547 michael 1654 mp_pool_release(ptr);
548 adx 30 ip_entries_count--;
549     return;
550     }
551     last_ptr = ptr;
552     }
553     }
554    
555     /* hash_ip()
556     *
557     * input - pointer to an irc_inaddr
558     * output - integer value used as index into hash table
559     * side effects - hopefully, none
560     */
561     static int
562     hash_ip(struct irc_ssaddr *addr)
563     {
564     if (addr->ss.ss_family == AF_INET)
565     {
566     struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
567     int hash;
568 michael 1032 uint32_t ip;
569 adx 30
570     ip = ntohl(v4->sin_addr.s_addr);
571     hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
572     return hash;
573     }
574     #ifdef IPV6
575     else
576     {
577     int hash;
578     struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
579 michael 1032 uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
580 adx 30
581     hash = ip[0] ^ ip[3];
582     hash ^= hash >> 16;
583     hash ^= hash >> 8;
584     hash = hash & (IP_HASH_SIZE - 1);
585     return hash;
586     }
587     #else
588     return 0;
589     #endif
590     }
591    
592     /* count_ip_hash()
593     *
594     * inputs - pointer to counter of number of ips hashed
595     * - pointer to memory used for ip hash
596     * output - returned via pointers input
597     * side effects - NONE
598     *
599     * number of hashed ip #'s is counted up, plus the amount of memory
600     * used in the hash.
601     */
602     void
603 michael 948 count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored)
604 adx 30 {
605     struct ip_entry *ptr;
606     int i;
607    
608     *number_ips_stored = 0;
609     *mem_ips_stored = 0;
610    
611     for (i = 0; i < IP_HASH_SIZE; i++)
612     {
613     for (ptr = ip_hash_table[i]; ptr; ptr = ptr->next)
614     {
615     *number_ips_stored += 1;
616     *mem_ips_stored += sizeof(struct ip_entry);
617     }
618     }
619     }
620    
621     /* garbage_collect_ip_entries()
622     *
623     * input - NONE
624     * output - NONE
625     * side effects - free up all ip entries with no connections
626     */
627     static void
628     garbage_collect_ip_entries(void)
629     {
630     struct ip_entry *ptr;
631     struct ip_entry *last_ptr;
632     struct ip_entry *next_ptr;
633     int i;
634    
635     for (i = 0; i < IP_HASH_SIZE; i++)
636     {
637     last_ptr = NULL;
638    
639     for (ptr = ip_hash_table[i]; ptr; ptr = next_ptr)
640     {
641     next_ptr = ptr->next;
642    
643     if (ptr->count == 0 &&
644     (CurrentTime - ptr->last_attempt) >= ConfigFileEntry.throttle_time)
645     {
646     if (last_ptr != NULL)
647     last_ptr->next = ptr->next;
648     else
649     ip_hash_table[i] = ptr->next;
650 michael 1654 mp_pool_release(ptr);
651 adx 30 ip_entries_count--;
652     }
653     else
654     last_ptr = ptr;
655     }
656     }
657     }
658    
659     /* detach_conf()
660     *
661     * inputs - pointer to client to detach
662     * - type of conf to detach
663     * output - 0 for success, -1 for failure
664     * side effects - Disassociate configuration from the client.
665     * Also removes a class from the list if marked for deleting.
666     */
667 michael 1632 void
668     detach_conf(struct Client *client_p, enum maskitem_type type)
669 adx 30 {
670 michael 1632 dlink_node *ptr = NULL, *next_ptr = NULL;
671 adx 30
672     DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head)
673     {
674 michael 1645 struct MaskItem *conf = ptr->data;
675 adx 30
676 michael 1645 assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
677     assert(conf->ref_count > 0);
678     assert(conf->class->ref_count > 0);
679 adx 30
680 michael 1645 if (!(conf->type & type))
681     continue;
682 michael 671
683 michael 1645 dlinkDelete(ptr, &client_p->localClient->confs);
684     free_dlink_node(ptr);
685 michael 1644
686 michael 2278 if (conf->type == CONF_CLIENT)
687 michael 1645 remove_from_cidr_check(&client_p->localClient->ip, conf->class);
688 adx 30
689 michael 1645 if (--conf->class->ref_count == 0 && conf->class->active == 0)
690     {
691     class_free(conf->class);
692     conf->class = NULL;
693 adx 30 }
694 michael 1645
695     if (--conf->ref_count == 0 && conf->active == 0)
696     conf_free(conf);
697 adx 30 }
698     }
699    
700     /* attach_conf()
701     *
702     * inputs - client pointer
703     * - conf pointer
704     * output -
705     * side effects - Associate a specific configuration entry to a *local*
706     * client (this is the one which used in accepting the
707     * connection). Note, that this automatically changes the
708     * attachment if there was an old one...
709     */
710     int
711 michael 1632 attach_conf(struct Client *client_p, struct MaskItem *conf)
712 adx 30 {
713     if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
714     return 1;
715    
716 michael 1632 if (conf->type == CONF_CLIENT)
717     if (cidr_limit_reached(IsConfExemptLimits(conf),
718     &client_p->localClient->ip, conf->class))
719 michael 1394 return TOO_MANY; /* Already at maximum allowed */
720 adx 30
721 michael 1632 conf->class->ref_count++;
722 michael 1644 conf->ref_count++;
723 adx 30
724     dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
725    
726     return 0;
727     }
728    
729     /* attach_connect_block()
730     *
731     * inputs - pointer to server to attach
732     * - name of server
733     * - hostname of server
734     * output - true (1) if both are found, otherwise return false (0)
735     * side effects - find connect block and attach them to connecting client
736     */
737     int
738     attach_connect_block(struct Client *client_p, const char *name,
739     const char *host)
740     {
741     dlink_node *ptr;
742 michael 1632 struct MaskItem *conf = NULL;
743 adx 30
744     assert(client_p != NULL);
745     assert(host != NULL);
746    
747     if (client_p == NULL || host == NULL)
748     return 0;
749    
750     DLINK_FOREACH(ptr, server_items.head)
751     {
752     conf = ptr->data;
753    
754 michael 1652 if (match(conf->name, name) || match(conf->host, host))
755 adx 30 continue;
756    
757     attach_conf(client_p, conf);
758     return -1;
759     }
760    
761     return 0;
762     }
763    
764     /* find_conf_name()
765     *
766     * inputs - pointer to conf link list to search
767     * - pointer to name to find
768     * - int mask of type of conf to find
769     * output - NULL or pointer to conf found
770     * side effects - find a conf entry which matches the name
771     * and has the given mask.
772     */
773 michael 1632 struct MaskItem *
774     find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
775 adx 30 {
776     dlink_node *ptr;
777 michael 1632 struct MaskItem* conf;
778 adx 30
779     DLINK_FOREACH(ptr, list->head)
780     {
781     conf = ptr->data;
782    
783     if (conf->type == type)
784     {
785     if (conf->name && (irccmp(conf->name, name) == 0 ||
786 michael 1652 !match(conf->name, name)))
787 adx 30 return conf;
788     }
789     }
790    
791     return NULL;
792     }
793    
794     /* map_to_list()
795     *
796     * inputs - ConfType conf
797     * output - pointer to dlink_list to use
798     * side effects - none
799     */
800     static dlink_list *
801 michael 1632 map_to_list(enum maskitem_type type)
802 adx 30 {
803     switch(type)
804     {
805 michael 1632 case CONF_XLINE:
806 adx 30 return(&xconf_items);
807     break;
808 michael 1632 case CONF_ULINE:
809 adx 30 return(&uconf_items);
810     break;
811 michael 1632 case CONF_NRESV:
812 adx 30 return(&nresv_items);
813     break;
814 michael 1825 case CONF_CRESV:
815 michael 2174 return(&cresv_items);
816 michael 1632 case CONF_OPER:
817 adx 30 return(&oconf_items);
818     break;
819 michael 1632 case CONF_SERVER:
820 adx 30 return(&server_items);
821     break;
822 michael 1632 case CONF_SERVICE:
823 michael 1172 return(&service_items);
824     break;
825 michael 1632 case CONF_CLUSTER:
826 adx 30 return(&cluster_items);
827     break;
828     default:
829     return NULL;
830     }
831     }
832    
833     /* find_matching_name_conf()
834     *
835     * inputs - type of link list to look in
836     * - pointer to name string to find
837     * - pointer to user
838     * - pointer to host
839 michael 1644 * - optional flags to match on as well
840 michael 1632 * output - NULL or pointer to found struct MaskItem
841 adx 30 * side effects - looks for a match on name field
842     */
843 michael 1632 struct MaskItem *
844     find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
845 michael 1644 const char *host, unsigned int flags)
846 adx 30 {
847     dlink_node *ptr=NULL;
848 michael 1632 struct MaskItem *conf=NULL;
849 adx 30 dlink_list *list_p = map_to_list(type);
850    
851     switch (type)
852     {
853 michael 1632 case CONF_SERVICE:
854 michael 1157 DLINK_FOREACH(ptr, list_p->head)
855     {
856     conf = ptr->data;
857    
858     if (EmptyString(conf->name))
859     continue;
860     if ((name != NULL) && !irccmp(name, conf->name))
861     return conf;
862     }
863     break;
864    
865 michael 1632 case CONF_XLINE:
866     case CONF_ULINE:
867     case CONF_NRESV:
868 michael 1825 case CONF_CRESV:
869 adx 30 DLINK_FOREACH(ptr, list_p->head)
870     {
871     conf = ptr->data;
872    
873     if (EmptyString(conf->name))
874 michael 2182 continue;
875 michael 1653 if ((name != NULL) && !match(conf->name, name))
876 adx 30 {
877 michael 2182 if ((user == NULL && (host == NULL)))
878     return conf;
879     if ((conf->flags & flags) != flags)
880 adx 30 continue;
881 michael 2182 if (EmptyString(conf->user) || EmptyString(conf->host))
882     return conf;
883     if (!match(conf->user, user) && !match(conf->host, host))
884     return conf;
885 adx 30 }
886     }
887     break;
888    
889 michael 1632 case CONF_SERVER:
890 adx 30 DLINK_FOREACH(ptr, list_p->head)
891     {
892     conf = ptr->data;
893    
894 michael 1652 if ((name != NULL) && !match(name, conf->name))
895 adx 30 return conf;
896 michael 1652 else if ((host != NULL) && !match(host, conf->host))
897 adx 30 return conf;
898     }
899     break;
900    
901     default:
902     break;
903     }
904     return NULL;
905     }
906    
907     /* find_exact_name_conf()
908     *
909     * inputs - type of link list to look in
910     * - pointer to name string to find
911     * - pointer to user
912     * - pointer to host
913 michael 1632 * output - NULL or pointer to found struct MaskItem
914 adx 30 * side effects - looks for an exact match on name field
915     */
916 michael 1632 struct MaskItem *
917     find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
918 adx 30 const char *user, const char *host)
919     {
920     dlink_node *ptr = NULL;
921 michael 1632 struct MaskItem *conf;
922     dlink_list *list_p = map_to_list(type);
923 adx 30
924     switch(type)
925     {
926 michael 1632 case CONF_XLINE:
927     case CONF_ULINE:
928     case CONF_NRESV:
929 michael 1825 case CONF_CRESV:
930 adx 30
931     DLINK_FOREACH(ptr, list_p->head)
932     {
933     conf = ptr->data;
934 michael 1632
935 adx 30 if (EmptyString(conf->name))
936 michael 2182 continue;
937 adx 30
938     if (irccmp(conf->name, name) == 0)
939     {
940 michael 2182 if ((user == NULL && (host == NULL)))
941     return conf;
942     if (EmptyString(conf->user) || EmptyString(conf->host))
943     return conf;
944     if (!match(conf->user, user) && !match(conf->host, host))
945     return conf;
946 adx 30 }
947     }
948     break;
949    
950 michael 1632 case CONF_OPER:
951 adx 30 DLINK_FOREACH(ptr, list_p->head)
952     {
953     conf = ptr->data;
954 michael 1285
955 adx 30 if (EmptyString(conf->name))
956 michael 1285 continue;
957    
958     if (!irccmp(conf->name, name))
959 adx 30 {
960 michael 1285 if (!who)
961     return conf;
962 michael 1632 if (EmptyString(conf->user) || EmptyString(conf->host))
963 michael 1636 return NULL;
964 michael 1652 if (!match(conf->user, who->username))
965 michael 1285 {
966 michael 1632 switch (conf->htype)
967 michael 1285 {
968     case HM_HOST:
969 michael 1652 if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
970 michael 1637 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
971     return conf;
972 michael 1285 break;
973     case HM_IPV4:
974     if (who->localClient->aftype == AF_INET)
975 michael 1632 if (match_ipv4(&who->localClient->ip, &conf->addr, conf->bits))
976 michael 1637 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
977     return conf;
978 michael 1285 break;
979     #ifdef IPV6
980     case HM_IPV6:
981     if (who->localClient->aftype == AF_INET6)
982 michael 1632 if (match_ipv6(&who->localClient->ip, &conf->addr, conf->bits))
983 michael 1637 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
984     return conf;
985 michael 1285 break;
986     #endif
987     default:
988     assert(0);
989     }
990     }
991 adx 30 }
992     }
993 michael 1285
994 adx 30 break;
995    
996 michael 1632 case CONF_SERVER:
997 adx 30 DLINK_FOREACH(ptr, list_p->head)
998     {
999     conf = ptr->data;
1000 michael 1632
1001 adx 30 if (EmptyString(conf->name))
1002 michael 2182 continue;
1003 adx 30
1004     if (name == NULL)
1005     {
1006 michael 2182 if (EmptyString(conf->host))
1007     continue;
1008     if (irccmp(conf->host, host) == 0)
1009     return conf;
1010 adx 30 }
1011     else if (irccmp(conf->name, name) == 0)
1012 michael 2182 return conf;
1013 adx 30 }
1014 michael 2182
1015 adx 30 break;
1016    
1017     default:
1018     break;
1019     }
1020 michael 2182
1021     return NULL;
1022 adx 30 }
1023    
1024     /* rehash()
1025     *
1026     * Actual REHASH service routine. Called with sig == 0 if it has been called
1027     * as a result of an operator issuing this command, else assume it has been
1028     * called as a result of the server receiving a HUP signal.
1029     */
1030     int
1031     rehash(int sig)
1032     {
1033     if (sig != 0)
1034 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1035 michael 2830 "Got signal SIGHUP, reloading configuration file(s)");
1036 adx 30
1037     restart_resolver();
1038 michael 1001
1039 adx 30 /* don't close listeners until we know we can go ahead with the rehash */
1040    
1041     /* Check to see if we magically got(or lost) IPv6 support */
1042     check_can_use_v6();
1043    
1044     read_conf_files(0);
1045    
1046     if (ServerInfo.description != NULL)
1047     strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1048    
1049     load_conf_modules();
1050    
1051     rehashed_klines = 1;
1052    
1053 michael 1831 return 0;
1054 adx 30 }
1055    
1056     /* set_default_conf()
1057     *
1058     * inputs - NONE
1059     * output - NONE
1060     * side effects - Set default values here.
1061     * This is called **PRIOR** to parsing the
1062     * configuration file. If you want to do some validation
1063     * of values later, put them in validate_conf().
1064     */
1065     static void
1066     set_default_conf(void)
1067     {
1068     /* verify init_class() ran, this should be an unnecessary check
1069     * but its not much work.
1070     */
1071 michael 1644 assert(class_default == class_get_list()->tail->data);
1072 adx 30
1073     #ifdef HAVE_LIBCRYPTO
1074     ServerInfo.rsa_private_key = NULL;
1075     ServerInfo.rsa_private_key_file = NULL;
1076     #endif
1077    
1078     /* ServerInfo.name is not rehashable */
1079     /* ServerInfo.name = ServerInfo.name; */
1080     ServerInfo.description = NULL;
1081 michael 1646 ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1082     ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1083 adx 30
1084     memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
1085     ServerInfo.specific_ipv4_vhost = 0;
1086     memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
1087     ServerInfo.specific_ipv6_vhost = 0;
1088    
1089     ServerInfo.max_clients = MAXCLIENTS_MAX;
1090 michael 1751 ServerInfo.max_nick_length = 9;
1091     ServerInfo.max_topic_length = 80;
1092 michael 956
1093     ServerInfo.hub = 0;
1094 adx 30 ServerInfo.dns_host.sin_addr.s_addr = 0;
1095     ServerInfo.dns_host.sin_port = 0;
1096     AdminInfo.name = NULL;
1097     AdminInfo.email = NULL;
1098     AdminInfo.description = NULL;
1099    
1100 michael 1831 log_del_all();
1101 michael 1247
1102 adx 30 ConfigLoggingEntry.use_logging = 1;
1103    
1104 michael 1243 ConfigChannel.disable_fake_channels = 0;
1105 adx 30 ConfigChannel.knock_delay = 300;
1106     ConfigChannel.knock_delay_channel = 60;
1107 michael 1432 ConfigChannel.max_chans_per_user = 25;
1108 michael 1444 ConfigChannel.max_chans_per_oper = 50;
1109 adx 30 ConfigChannel.max_bans = 25;
1110     ConfigChannel.default_split_user_count = 0;
1111     ConfigChannel.default_split_server_count = 0;
1112 michael 1243 ConfigChannel.no_join_on_split = 0;
1113     ConfigChannel.no_create_on_split = 0;
1114 adx 30
1115 michael 1243 ConfigServerHide.flatten_links = 0;
1116 adx 30 ConfigServerHide.links_delay = 300;
1117 michael 1243 ConfigServerHide.hidden = 0;
1118     ConfigServerHide.hide_servers = 0;
1119 michael 1851 ConfigServerHide.hide_services = 0;
1120 michael 1646 ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
1121 michael 1243 ConfigServerHide.hide_server_ips = 0;
1122 michael 2196 ConfigServerHide.disable_remote_commands = 0;
1123 adx 30
1124 michael 876
1125 michael 1646 ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1126 michael 876 ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
1127 michael 2283 ConfigFileEntry.cycle_on_host_change = 1;
1128 michael 1459 ConfigFileEntry.glines = 0;
1129     ConfigFileEntry.gline_time = 12 * 3600;
1130     ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
1131 adx 30 ConfigFileEntry.gline_min_cidr = 16;
1132     ConfigFileEntry.gline_min_cidr6 = 48;
1133 michael 1243 ConfigFileEntry.invisible_on_connect = 1;
1134     ConfigFileEntry.tkline_expire_notices = 1;
1135     ConfigFileEntry.hide_spoof_ips = 1;
1136     ConfigFileEntry.ignore_bogus_ts = 0;
1137     ConfigFileEntry.disable_auth = 0;
1138 adx 30 ConfigFileEntry.kill_chase_time_limit = 90;
1139 michael 1119 ConfigFileEntry.default_floodcount = 8;
1140 michael 1243 ConfigFileEntry.failed_oper_notice = 1;
1141 michael 1119 ConfigFileEntry.dots_in_ident = 0;
1142 adx 30 ConfigFileEntry.min_nonwildcard = 4;
1143     ConfigFileEntry.min_nonwildcard_simple = 3;
1144     ConfigFileEntry.max_accept = 20;
1145 michael 1243 ConfigFileEntry.anti_nick_flood = 0;
1146 adx 30 ConfigFileEntry.max_nick_time = 20;
1147     ConfigFileEntry.max_nick_changes = 5;
1148 michael 1119 ConfigFileEntry.anti_spam_exit_message_time = 0;
1149 adx 30 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1150 michael 1119 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1151 michael 1243 ConfigFileEntry.warn_no_nline = 1;
1152     ConfigFileEntry.stats_o_oper_only = 0;
1153 adx 30 ConfigFileEntry.stats_k_oper_only = 1; /* masked */
1154     ConfigFileEntry.stats_i_oper_only = 1; /* masked */
1155 michael 1243 ConfigFileEntry.stats_P_oper_only = 0;
1156 michael 2269 ConfigFileEntry.stats_u_oper_only = 0;
1157 adx 30 ConfigFileEntry.caller_id_wait = 60;
1158 michael 1243 ConfigFileEntry.opers_bypass_callerid = 0;
1159 adx 30 ConfigFileEntry.pace_wait = 10;
1160     ConfigFileEntry.pace_wait_simple = 1;
1161 michael 1243 ConfigFileEntry.short_motd = 0;
1162     ConfigFileEntry.ping_cookie = 0;
1163     ConfigFileEntry.no_oper_flood = 0;
1164     ConfigFileEntry.true_no_oper_flood = 0;
1165     ConfigFileEntry.oper_pass_resv = 1;
1166 adx 30 ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
1167 michael 1119 ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
1168 adx 264 ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
1169 michael 1119 UMODE_OPERWALL | UMODE_WALLOP;
1170 michael 1243 ConfigFileEntry.use_egd = 0;
1171 adx 30 ConfigFileEntry.egdpool_path = NULL;
1172     ConfigFileEntry.throttle_time = 10;
1173     }
1174    
1175     static void
1176     validate_conf(void)
1177     {
1178     if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
1179     ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1180    
1181     if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1182     ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1183    
1184     if (ServerInfo.network_name == NULL)
1185 michael 1646 ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1186 adx 30
1187     if (ServerInfo.network_desc == NULL)
1188 michael 1646 ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1189 adx 30
1190 michael 1157 if (ConfigFileEntry.service_name == NULL)
1191 michael 1646 ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1192 michael 1157
1193 michael 876 ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
1194 adx 30 }
1195    
1196 michael 1363 /* read_conf()
1197     *
1198     * inputs - file descriptor pointing to config file to use
1199     * output - None
1200     * side effects - Read configuration file.
1201     */
1202     static void
1203     read_conf(FILE *file)
1204     {
1205     lineno = 0;
1206    
1207     set_default_conf(); /* Set default values prior to conf parsing */
1208     conf_parser_ctx.pass = 1;
1209 michael 2182 yyparse(); /* pick up the classes first */
1210 michael 1363
1211     rewind(file);
1212    
1213     conf_parser_ctx.pass = 2;
1214     yyparse(); /* Load the values from the conf */
1215     validate_conf(); /* Check to make sure some values are still okay. */
1216     /* Some global values are also loaded here. */
1217 michael 1632 class_delete_marked(); /* Make sure classes are valid */
1218 michael 1363 }
1219    
1220 adx 30 /* lookup_confhost()
1221     *
1222     * start DNS lookups of all hostnames in the conf
1223     * line and convert an IP addresses in a.b.c.d number for to IP#s.
1224     */
1225 michael 1647 void
1226 michael 1632 lookup_confhost(struct MaskItem *conf)
1227 adx 30 {
1228     struct addrinfo hints, *res;
1229    
1230     /* Do name lookup now on hostnames given and store the
1231     * ip numbers in conf structure.
1232     */
1233     memset(&hints, 0, sizeof(hints));
1234    
1235     hints.ai_family = AF_UNSPEC;
1236     hints.ai_socktype = SOCK_STREAM;
1237    
1238     /* Get us ready for a bind() and don't bother doing dns lookup */
1239     hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
1240    
1241 michael 1632 if (getaddrinfo(conf->host, NULL, &hints, &res))
1242 adx 30 {
1243 michael 1632 conf_dns_lookup(conf);
1244 adx 30 return;
1245     }
1246    
1247     assert(res != NULL);
1248    
1249 michael 1632 memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
1250     conf->addr.ss_len = res->ai_addrlen;
1251     conf->addr.ss.ss_family = res->ai_family;
1252    
1253 michael 1123 freeaddrinfo(res);
1254 adx 30 }
1255    
1256     /* conf_connect_allowed()
1257     *
1258     * inputs - pointer to inaddr
1259     * - int type ipv4 or ipv6
1260     * output - BANNED or accepted
1261     * side effects - none
1262     */
1263     int
1264     conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
1265     {
1266     struct ip_entry *ip_found;
1267 michael 1632 struct MaskItem *conf = find_dline_conf(addr, aftype);
1268 adx 30
1269     /* DLINE exempt also gets you out of static limits/pacing... */
1270 michael 1636 if (conf && (conf->type == CONF_EXEMPT))
1271 adx 30 return 0;
1272    
1273 michael 1632 if (conf != NULL)
1274 adx 30 return BANNED_CLIENT;
1275    
1276     ip_found = find_or_add_ip(addr);
1277    
1278     if ((CurrentTime - ip_found->last_attempt) <
1279     ConfigFileEntry.throttle_time)
1280     {
1281     ip_found->last_attempt = CurrentTime;
1282     return TOO_FAST;
1283     }
1284    
1285     ip_found->last_attempt = CurrentTime;
1286     return 0;
1287     }
1288    
1289     /* cleanup_tklines()
1290     *
1291     * inputs - NONE
1292     * output - NONE
1293     * side effects - call function to expire temporary k/d lines
1294     * This is an event started off in ircd.c
1295     */
1296     void
1297     cleanup_tklines(void *notused)
1298     {
1299 michael 1369 hostmask_expire_temporary();
1300 michael 1622 expire_tklines(&xconf_items);
1301 michael 1628 expire_tklines(&nresv_items);
1302 michael 2174 expire_tklines(&cresv_items);
1303 adx 30 }
1304    
1305     /* expire_tklines()
1306     *
1307     * inputs - tkline list pointer
1308     * output - NONE
1309     * side effects - expire tklines
1310     */
1311     static void
1312     expire_tklines(dlink_list *tklist)
1313     {
1314     dlink_node *ptr;
1315     dlink_node *next_ptr;
1316 michael 1632 struct MaskItem *conf;
1317 adx 30
1318     DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
1319     {
1320     conf = ptr->data;
1321    
1322 michael 1649 if (!conf->until || conf->until > CurrentTime)
1323 michael 1644 continue;
1324    
1325 michael 1632 if (conf->type == CONF_XLINE)
1326 adx 30 {
1327 michael 1644 if (ConfigFileEntry.tkline_expire_notices)
1328     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1329 michael 1618 "Temporary X-line for [%s] expired", conf->name);
1330 michael 1644 conf_free(conf);
1331 adx 30 }
1332 michael 1825 else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV)
1333 adx 30 {
1334 michael 1644 if (ConfigFileEntry.tkline_expire_notices)
1335     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1336 adx 30 "Temporary RESV for [%s] expired", conf->name);
1337 michael 1644 conf_free(conf);
1338 adx 30 }
1339     }
1340     }
1341    
1342     /* oper_privs_as_string()
1343     *
1344 michael 58 * inputs - pointer to client_p
1345 adx 30 * output - pointer to static string showing oper privs
1346     * side effects - return as string, the oper privs as derived from port
1347     */
1348 michael 58 static const struct oper_privs
1349     {
1350 michael 1644 const unsigned int flag;
1351 michael 58 const unsigned char c;
1352     } flag_list[] = {
1353 michael 2012 { OPER_FLAG_ADMIN, 'A' },
1354     { OPER_FLAG_REMOTEBAN, 'B' },
1355     { OPER_FLAG_DIE, 'D' },
1356     { OPER_FLAG_GLINE, 'G' },
1357     { OPER_FLAG_REHASH, 'H' },
1358     { OPER_FLAG_K, 'K' },
1359     { OPER_FLAG_OPERWALL, 'L' },
1360     { OPER_FLAG_KILL, 'N' },
1361     { OPER_FLAG_KILL_REMOTE, 'O' },
1362     { OPER_FLAG_CONNECT, 'P' },
1363     { OPER_FLAG_CONNECT_REMOTE, 'Q' },
1364     { OPER_FLAG_SQUIT, 'R' },
1365     { OPER_FLAG_SQUIT_REMOTE, 'S' },
1366     { OPER_FLAG_UNKLINE, 'U' },
1367     { OPER_FLAG_X, 'X' },
1368 michael 1294 { 0, '\0' }
1369 michael 58 };
1370 adx 30
1371     char *
1372     oper_privs_as_string(const unsigned int port)
1373     {
1374 michael 2694 static char privs_out[IRCD_BUFSIZE];
1375 michael 58 char *privs_ptr = privs_out;
1376 michael 1644 const struct oper_privs *opriv = flag_list;
1377 adx 30
1378 michael 1644 for (; opriv->flag; ++opriv)
1379 michael 58 {
1380 michael 1644 if (port & opriv->flag)
1381     *privs_ptr++ = opriv->c;
1382 michael 58 else
1383 michael 1644 *privs_ptr++ = ToLower(opriv->c);
1384 michael 58 }
1385    
1386     *privs_ptr = '\0';
1387    
1388 adx 30 return privs_out;
1389     }
1390    
1391     /*
1392     * Input: A client to find the active oper{} name for.
1393     * Output: The nick!user@host{oper} of the oper.
1394     * "oper" is server name for remote opers
1395     * Side effects: None.
1396     */
1397 michael 1364 const char *
1398 adx 30 get_oper_name(const struct Client *client_p)
1399     {
1400 michael 1364 dlink_node *cnode = NULL;
1401 adx 30 /* +5 for !,@,{,} and null */
1402 michael 1147 static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1403 adx 30
1404     if (MyConnect(client_p))
1405     {
1406 michael 1364 if ((cnode = client_p->localClient->confs.head))
1407 adx 30 {
1408 michael 1632 struct MaskItem *conf = cnode->data;
1409 adx 30
1410 michael 1632 if (IsConfOperator(conf))
1411 adx 30 {
1412 michael 2182 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1413 michael 1147 client_p->username, client_p->host, conf->name);
1414 michael 2182 return buffer;
1415 adx 30 }
1416     }
1417    
1418     /* Probably should assert here for now. If there is an oper out there
1419     * with no oper{} conf attached, it would be good for us to know...
1420     */
1421     assert(0); /* Oper without oper conf! */
1422     }
1423    
1424 michael 1147 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1425 michael 2182 client_p->username, client_p->host, client_p->servptr->name);
1426 adx 30 return buffer;
1427     }
1428    
1429     /* read_conf_files()
1430     *
1431     * inputs - cold start YES or NO
1432     * output - none
1433     * side effects - read all conf files needed, ircd.conf kline.conf etc.
1434     */
1435     void
1436     read_conf_files(int cold)
1437     {
1438     const char *filename;
1439 michael 2694 char chanmodes[IRCD_BUFSIZE];
1440     char chanlimit[IRCD_BUFSIZE];
1441 adx 30
1442 michael 967 conf_parser_ctx.boot = cold;
1443 michael 1622 filename = ConfigFileEntry.configfile;
1444 adx 30
1445     /* We need to know the initial filename for the yyerror() to report
1446     FIXME: The full path is in conffilenamebuf first time since we
1447     dont know anything else
1448    
1449     - Gozem 2002-07-21
1450     */
1451     strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1452    
1453 michael 1325 if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1454 adx 30 {
1455     if (cold)
1456     {
1457 michael 1247 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1458 adx 30 filename, strerror(errno));
1459     exit(-1);
1460     }
1461     else
1462     {
1463 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1464 michael 2182 "Unable to read configuration file '%s': %s",
1465     filename, strerror(errno));
1466 adx 30 return;
1467     }
1468     }
1469    
1470     if (!cold)
1471     clear_out_old_conf();
1472    
1473 michael 967 read_conf(conf_parser_ctx.conf_file);
1474 michael 1325 fclose(conf_parser_ctx.conf_file);
1475 adx 30
1476 michael 1831 log_reopen_all();
1477    
1478 michael 1751 add_isupport("NICKLEN", NULL, ServerInfo.max_nick_length);
1479 adx 30 add_isupport("NETWORK", ServerInfo.network_name, -1);
1480 michael 1751
1481     snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1482 adx 30 add_isupport("MAXLIST", chanmodes, -1);
1483     add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
1484 michael 1474 add_isupport("CHANTYPES", "#", -1);
1485 michael 1147
1486 michael 1474 snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1487 michael 1751 ConfigChannel.max_chans_per_user);
1488 adx 30 add_isupport("CHANLIMIT", chanlimit, -1);
1489 michael 1751 snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS");
1490 michael 100 add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
1491 michael 1751 add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length);
1492 adx 30 add_isupport("CHANMODES", chanmodes, -1);
1493    
1494     /*
1495     * message_locale may have changed. rebuild isupport since it relies
1496     * on strlen(form_str(RPL_ISUPPORT))
1497     */
1498     rebuild_isupport_message_line();
1499     }
1500    
1501     /* clear_out_old_conf()
1502     *
1503     * inputs - none
1504     * output - none
1505     * side effects - Clear out the old configuration
1506     */
1507     static void
1508     clear_out_old_conf(void)
1509     {
1510     dlink_node *ptr = NULL, *next_ptr = NULL;
1511 michael 1632 struct MaskItem *conf;
1512 adx 30 dlink_list *free_items [] = {
1513 michael 1383 &server_items, &oconf_items,
1514 michael 1921 &uconf_items, &xconf_items,
1515 michael 2174 &nresv_items, &cluster_items, &service_items, &cresv_items, NULL
1516 adx 30 };
1517    
1518     dlink_list ** iterator = free_items; /* C is dumb */
1519    
1520     /* We only need to free anything allocated by yyparse() here.
1521     * Resetting structs, etc, is taken care of by set_default_conf().
1522     */
1523    
1524     for (; *iterator != NULL; iterator++)
1525     {
1526     DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1527     {
1528     conf = ptr->data;
1529 michael 1632
1530     dlinkDelete(&conf->node, map_to_list(conf->type));
1531    
1532 adx 30 /* XXX This is less than pretty */
1533 michael 1632 if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
1534 adx 30 {
1535 michael 1644 if (!conf->ref_count)
1536 michael 2182 conf_free(conf);
1537 adx 30 }
1538 michael 1921 else if (conf->type == CONF_XLINE)
1539 adx 30 {
1540 michael 1649 if (!conf->until)
1541 michael 1632 conf_free(conf);
1542 adx 30 }
1543     else
1544 michael 1632 conf_free(conf);
1545 adx 30 }
1546     }
1547    
1548 michael 2150 motd_clear();
1549    
1550 michael 671 /*
1551     * don't delete the class table, rather mark all entries
1552 michael 1632 * for deletion. The table is cleaned up by class_delete_marked. - avalon
1553 adx 30 */
1554 michael 1632 class_mark_for_deletion();
1555 michael 671
1556 adx 30 clear_out_address_conf();
1557    
1558     /* clean out module paths */
1559     mod_clear_paths();
1560    
1561     /* clean out ServerInfo */
1562     MyFree(ServerInfo.description);
1563     ServerInfo.description = NULL;
1564     MyFree(ServerInfo.network_name);
1565     ServerInfo.network_name = NULL;
1566     MyFree(ServerInfo.network_desc);
1567     ServerInfo.network_desc = NULL;
1568     MyFree(ConfigFileEntry.egdpool_path);
1569     ConfigFileEntry.egdpool_path = NULL;
1570     #ifdef HAVE_LIBCRYPTO
1571     if (ServerInfo.rsa_private_key != NULL)
1572     {
1573     RSA_free(ServerInfo.rsa_private_key);
1574     ServerInfo.rsa_private_key = NULL;
1575     }
1576    
1577     MyFree(ServerInfo.rsa_private_key_file);
1578     ServerInfo.rsa_private_key_file = NULL;
1579 michael 1316
1580     if (ServerInfo.server_ctx)
1581     SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
1582     SSL_OP_NO_SSLv3|
1583     SSL_OP_NO_TLSv1);
1584     if (ServerInfo.client_ctx)
1585     SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
1586     SSL_OP_NO_SSLv3|
1587     SSL_OP_NO_TLSv1);
1588 adx 30 #endif
1589    
1590     /* clean out AdminInfo */
1591     MyFree(AdminInfo.name);
1592     AdminInfo.name = NULL;
1593     MyFree(AdminInfo.email);
1594     AdminInfo.email = NULL;
1595     MyFree(AdminInfo.description);
1596     AdminInfo.description = NULL;
1597    
1598     /* clean out listeners */
1599     close_listeners();
1600    
1601     /* clean out general */
1602 michael 1157 MyFree(ConfigFileEntry.service_name);
1603     ConfigFileEntry.service_name = NULL;
1604 adx 30 }
1605    
1606     /* conf_add_class_to_conf()
1607     *
1608     * inputs - pointer to config item
1609     * output - NONE
1610     * side effects - Add a class pointer to a conf
1611     */
1612     void
1613 michael 1632 conf_add_class_to_conf(struct MaskItem *conf, const char *class_name)
1614 adx 30 {
1615     if (class_name == NULL)
1616     {
1617 michael 1632 conf->class = class_default;
1618 michael 671
1619 michael 1632 if (conf->type == CONF_CLIENT)
1620 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1621 michael 2182 "Warning *** Defaulting to default class for %s@%s",
1622     conf->user, conf->host);
1623 adx 30 else
1624 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1625 michael 2182 "Warning *** Defaulting to default class for %s",
1626     conf->name);
1627 adx 30 }
1628     else
1629 michael 1632 conf->class = class_find(class_name, 1);
1630 adx 30
1631 michael 1632 if (conf->class == NULL)
1632 adx 30 {
1633 michael 1632 if (conf->type == CONF_CLIENT)
1634 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1635 michael 2182 "Warning *** Defaulting to default class for %s@%s",
1636     conf->user, conf->host);
1637 adx 30 else
1638 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1639 michael 2182 "Warning *** Defaulting to default class for %s",
1640     conf->name);
1641 michael 1632 conf->class = class_default;
1642 adx 30 }
1643     }
1644    
1645     /* yyerror()
1646     *
1647     * inputs - message from parser
1648     * output - NONE
1649     * side effects - message to opers and log file entry is made
1650     */
1651     void
1652     yyerror(const char *msg)
1653     {
1654     char newlinebuf[IRCD_BUFSIZE];
1655    
1656 michael 967 if (conf_parser_ctx.pass != 1)
1657 adx 30 return;
1658    
1659     strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1660 michael 1751 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1661 michael 1618 "\"%s\", line %u: %s: %s",
1662 adx 30 conffilebuf, lineno + 1, msg, newlinebuf);
1663 michael 1247 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1664 adx 30 conffilebuf, lineno + 1, msg, newlinebuf);
1665     }
1666    
1667 michael 1751 void
1668     conf_error_report(const char *msg)
1669     {
1670     char newlinebuf[IRCD_BUFSIZE];
1671    
1672     strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1673     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1674     "\"%s\", line %u: %s: %s",
1675     conffilebuf, lineno + 1, msg, newlinebuf);
1676     ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1677     conffilebuf, lineno + 1, msg, newlinebuf);
1678     }
1679    
1680 adx 30 /*
1681     * valid_tkline()
1682     *
1683     * inputs - pointer to ascii string to check
1684     * - whether the specified time is in seconds or minutes
1685     * output - -1 not enough parameters
1686     * - 0 if not an integer number, else the number
1687     * side effects - none
1688     * Originally written by Dianora (Diane, db@db.net)
1689     */
1690     time_t
1691 michael 2313 valid_tkline(const char *data, const int minutes)
1692 adx 30 {
1693 michael 2313 const unsigned char *p = (const unsigned char *)data;
1694     unsigned char tmpch = '\0';
1695 adx 30 time_t result = 0;
1696    
1697 michael 2313 while ((tmpch = *p++))
1698 adx 30 {
1699 michael 2313 if (!IsDigit(tmpch))
1700 michael 1121 return 0;
1701 michael 1120
1702     result *= 10;
1703 michael 2313 result += (tmpch & 0xF);
1704 adx 30 }
1705    
1706 michael 1120 /*
1707     * In the degenerate case where oper does a /quote kline 0 user@host :reason
1708 adx 30 * i.e. they specifically use 0, I am going to return 1 instead
1709     * as a return value of non-zero is used to flag it as a temporary kline
1710     */
1711     if (result == 0)
1712     result = 1;
1713    
1714     /*
1715     * If the incoming time is in seconds convert it to minutes for the purpose
1716     * of this calculation
1717     */
1718     if (!minutes)
1719 michael 2313 result = result / 60;
1720 adx 30
1721     if (result > MAX_TDKLINE_TIME)
1722     result = MAX_TDKLINE_TIME;
1723    
1724 michael 2313 result = result * 60; /* turn it into seconds */
1725 adx 30
1726     return result;
1727     }
1728    
1729 michael 2130 /* valid_wild_card_simple()
1730     *
1731     * inputs - data to check for sufficient non-wildcard characters
1732     * outputs - 1 if valid, else 0
1733     * side effects - none
1734     */
1735     int
1736     valid_wild_card_simple(const char *data)
1737     {
1738     const unsigned char *p = (const unsigned char *)data;
1739     unsigned char tmpch = '\0';
1740     int nonwild = 0;
1741    
1742     while ((tmpch = *p++))
1743     {
1744     if (tmpch == '\\')
1745     {
1746     ++p;
1747     if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1748     return 1;
1749     }
1750     else if (!IsMWildChar(tmpch))
1751     {
1752     if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1753     return 1;
1754     }
1755     }
1756    
1757     return 0;
1758     }
1759    
1760 adx 30 /* valid_wild_card()
1761     *
1762     * input - pointer to client
1763     * - int flag, 0 for no warning oper 1 for warning oper
1764     * - count of following varargs to check
1765     * output - 0 if not valid, 1 if valid
1766     * side effects - NOTICE is given to source_p if warn is 1
1767     */
1768     int
1769     valid_wild_card(struct Client *source_p, int warn, int count, ...)
1770     {
1771     char tmpch;
1772     int nonwild = 0;
1773     va_list args;
1774    
1775     /*
1776     * Now we must check the user and host to make sure there
1777     * are at least NONWILDCHARS non-wildcard characters in
1778     * them, otherwise assume they are attempting to kline
1779     * *@* or some variant of that. This code will also catch
1780     * people attempting to kline *@*.tld, as long as NONWILDCHARS
1781     * is greater than 3. In that case, there are only 3 non-wild
1782     * characters (tld), so if NONWILDCHARS is 4, the kline will
1783     * be disallowed.
1784     * -wnder
1785     */
1786    
1787     va_start(args, count);
1788    
1789     while (count--)
1790     {
1791 michael 2133 const char *p = va_arg(args, const char *);
1792 adx 30 if (p == NULL)
1793     continue;
1794    
1795     while ((tmpch = *p++))
1796     {
1797     if (!IsKWildChar(tmpch))
1798     {
1799     /*
1800     * If we find enough non-wild characters, we can
1801     * break - no point in searching further.
1802     */
1803     if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1804 michael 2659 {
1805     va_end(args);
1806 adx 30 return 1;
1807 michael 2659 }
1808 adx 30 }
1809     }
1810     }
1811    
1812     if (warn)
1813     sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask",
1814     me.name, source_p->name, ConfigFileEntry.min_nonwildcard);
1815 michael 2659 va_end(args);
1816 adx 30 return 0;
1817     }
1818    
1819     /* XXX should this go into a separate file ? -Dianora */
1820     /* parse_aline
1821     *
1822     * input - pointer to cmd name being used
1823     * - pointer to client using cmd
1824     * - parc parameter count
1825     * - parv[] list of parameters to parse
1826     * - parse_flags bit map of things to test
1827     * - pointer to user or string to parse into
1828     * - pointer to host or NULL to parse into if non NULL
1829     * - pointer to optional tkline time or NULL
1830     * - pointer to target_server to parse into if non NULL
1831     * - pointer to reason to parse into
1832     *
1833     * output - 1 if valid, -1 if not valid
1834     * side effects - A generalised k/d/x etc. line parser,
1835     * "ALINE [time] user@host|string [ON] target :reason"
1836     * will parse returning a parsed user, host if
1837     * h_p pointer is non NULL, string otherwise.
1838     * if tkline_time pointer is non NULL a tk line will be set
1839     * to non zero if found.
1840     * if tkline_time pointer is NULL and tk line is found,
1841     * error is reported.
1842     * if target_server is NULL and an "ON" is found error
1843     * is reported.
1844     * if reason pointer is NULL ignore pointer,
1845 db 936 * this allows use of parse_a_line in unkline etc.
1846 adx 30 *
1847     * - Dianora
1848     */
1849     int
1850     parse_aline(const char *cmd, struct Client *source_p,
1851 michael 2182 int parc, char **parv,
1852     int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1853     char **target_server, char **reason)
1854 adx 30 {
1855     int found_tkline_time=0;
1856     static char def_reason[] = "No Reason";
1857     static char user[USERLEN*4+1];
1858     static char host[HOSTLEN*4+1];
1859    
1860     parv++;
1861     parc--;
1862    
1863     found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1864    
1865     if (found_tkline_time != 0)
1866     {
1867     parv++;
1868     parc--;
1869    
1870     if (tkline_time != NULL)
1871     *tkline_time = found_tkline_time;
1872     else
1873     {
1874     sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
1875 michael 2182 me.name, source_p->name, cmd);
1876 adx 30 return -1;
1877     }
1878     }
1879    
1880     if (parc == 0)
1881     {
1882 michael 1834 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1883 adx 30 me.name, source_p->name, cmd);
1884     return -1;
1885     }
1886    
1887     if (h_p == NULL)
1888     *up_p = *parv;
1889     else
1890     {
1891     if (find_user_host(source_p, *parv, user, host, parse_flags) == 0)
1892     return -1;
1893    
1894     *up_p = user;
1895     *h_p = host;
1896     }
1897    
1898     parc--;
1899     parv++;
1900    
1901     if (parc != 0)
1902     {
1903     if (irccmp(*parv, "ON") == 0)
1904     {
1905     parc--;
1906     parv++;
1907    
1908     if (target_server == NULL)
1909     {
1910 michael 2182 sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
1911     me.name, source_p->name, cmd);
1912     return -1;
1913 adx 30 }
1914    
1915 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1916 adx 30 {
1917 michael 1834 sendto_one(source_p, form_str(ERR_NOPRIVS),
1918 adx 30 me.name, source_p->name, "remoteban");
1919     return -1;
1920     }
1921    
1922     if (parc == 0 || EmptyString(*parv))
1923     {
1924 michael 2182 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1925     me.name, source_p->name, cmd);
1926     return -1;
1927 adx 30 }
1928    
1929     *target_server = *parv;
1930     parc--;
1931     parv++;
1932     }
1933     else
1934     {
1935     /* Make sure target_server *is* NULL if no ON server found
1936     * caller probably NULL'd it first, but no harm to do it again -db
1937     */
1938     if (target_server != NULL)
1939 michael 2182 *target_server = NULL;
1940 adx 30 }
1941     }
1942    
1943     if (h_p != NULL)
1944     {
1945     if (strchr(user, '!') != NULL)
1946     {
1947     sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline",
1948     me.name, source_p->name);
1949     return -1;
1950     }
1951    
1952 michael 1243 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
1953 adx 30 return -1;
1954     }
1955     else
1956 michael 1243 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
1957 adx 30 return -1;
1958    
1959     if (reason != NULL)
1960     {
1961 michael 867 if (parc != 0 && !EmptyString(*parv))
1962 adx 30 {
1963     *reason = *parv;
1964 michael 1243 if (!valid_comment(source_p, *reason, 1))
1965 michael 2182 return -1;
1966 adx 30 }
1967     else
1968     *reason = def_reason;
1969     }
1970    
1971     return 1;
1972     }
1973    
1974     /* find_user_host()
1975     *
1976     * inputs - pointer to client placing kline
1977     * - pointer to user_host_or_nick
1978     * - pointer to user buffer
1979     * - pointer to host buffer
1980     * output - 0 if not ok to kline, 1 to kline i.e. if valid user host
1981     * side effects -
1982     */
1983     static int
1984     find_user_host(struct Client *source_p, char *user_host_or_nick,
1985     char *luser, char *lhost, unsigned int flags)
1986     {
1987     struct Client *target_p = NULL;
1988     char *hostp = NULL;
1989    
1990     if (lhost == NULL)
1991     {
1992     strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1993     return 1;
1994     }
1995    
1996     if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1997     {
1998     /* Explicit user@host mask given */
1999    
2000 michael 593 if (hostp != NULL) /* I'm a little user@host */
2001 adx 30 {
2002     *(hostp++) = '\0'; /* short and squat */
2003     if (*user_host_or_nick)
2004 michael 2182 strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
2005 adx 30 else
2006 michael 2182 strcpy(luser, "*");
2007    
2008 adx 30 if (*hostp)
2009 michael 2182 strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */
2010 adx 30 else
2011 michael 2182 strcpy(lhost, "*");
2012 adx 30 }
2013     else
2014     {
2015     luser[0] = '*'; /* no @ found, assume its *@somehost */
2016 michael 2182 luser[1] = '\0';
2017 adx 30 strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
2018     }
2019    
2020     return 1;
2021     }
2022 michael 1518 else
2023 adx 30 {
2024     /* Try to find user@host mask from nick */
2025     /* Okay to use source_p as the first param, because source_p == client_p */
2026     if ((target_p =
2027 michael 2475 find_chasing(source_p, user_host_or_nick, NULL)) == NULL)
2028 adx 30 return 0;
2029    
2030     if (IsExemptKline(target_p))
2031     {
2032     if (!IsServer(source_p))
2033 michael 2182 sendto_one(source_p,
2034     ":%s NOTICE %s :%s is E-lined",
2035     me.name, source_p->name, target_p->name);
2036 adx 30 return 0;
2037     }
2038    
2039     /*
2040     * turn the "user" bit into "*user", blow away '~'
2041     * if found in original user name (non-idented)
2042     */
2043     strlcpy(luser, target_p->username, USERLEN*4 + 1);
2044    
2045     if (target_p->username[0] == '~')
2046     luser[0] = '*';
2047    
2048     if (target_p->sockhost[0] == '\0' ||
2049     (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
2050     strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
2051     else
2052     strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
2053     return 1;
2054     }
2055    
2056     return 0;
2057     }
2058    
2059     /* valid_comment()
2060     *
2061     * inputs - pointer to client
2062     * - pointer to comment
2063     * output - 0 if no valid comment,
2064     * - 1 if valid
2065     * side effects - truncates reason where necessary
2066     */
2067     int
2068     valid_comment(struct Client *source_p, char *comment, int warn)
2069     {
2070     if (strlen(comment) > REASONLEN)
2071     comment[REASONLEN-1] = '\0';
2072    
2073     return 1;
2074     }
2075    
2076     /* match_conf_password()
2077     *
2078     * inputs - pointer to given password
2079     * - pointer to Conf
2080     * output - 1 or 0 if match
2081     * side effects - none
2082     */
2083     int
2084 michael 1632 match_conf_password(const char *password, const struct MaskItem *conf)
2085 adx 30 {
2086     const char *encr = NULL;
2087    
2088 michael 1632 if (EmptyString(password) || EmptyString(conf->passwd))
2089 adx 30 return 0;
2090    
2091 michael 1632 if (conf->flags & CONF_FLAGS_ENCRYPTED)
2092     encr = crypt(password, conf->passwd);
2093 adx 30 else
2094     encr = password;
2095    
2096 michael 1632 return !strcmp(encr, conf->passwd);
2097 adx 30 }
2098    
2099     /*
2100     * cluster_a_line
2101     *
2102     * inputs - client sending the cluster
2103     * - command name "KLINE" "XLINE" etc.
2104     * - capab -- CAP_KLN etc. from s_serv.h
2105 michael 1309 * - cluster type -- CLUSTER_KLINE etc. from conf.h
2106 adx 30 * - pattern and args to send along
2107     * output - none
2108     * side effects - Take source_p send the pattern with args given
2109     * along to all servers that match capab and cluster type
2110     */
2111     void
2112     cluster_a_line(struct Client *source_p, const char *command,
2113 michael 593 int capab, int cluster_type, const char *pattern, ...)
2114 adx 30 {
2115     va_list args;
2116     char buffer[IRCD_BUFSIZE];
2117 michael 593 const dlink_node *ptr = NULL;
2118 adx 30
2119     va_start(args, pattern);
2120     vsnprintf(buffer, sizeof(buffer), pattern, args);
2121     va_end(args);
2122    
2123     DLINK_FOREACH(ptr, cluster_items.head)
2124     {
2125 michael 1632 const struct MaskItem *conf = ptr->data;
2126 adx 30
2127     if (conf->flags & cluster_type)
2128     sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
2129 michael 2182 "%s %s %s", command, conf->name, buffer);
2130 adx 30 }
2131     }
2132    
2133     /*
2134     * split_nuh
2135     *
2136     * inputs - pointer to original mask (modified in place)
2137     * - pointer to pointer where nick should go
2138     * - pointer to pointer where user should go
2139     * - pointer to pointer where host should go
2140     * output - NONE
2141     * side effects - mask is modified in place
2142     * If nick pointer is NULL, ignore writing to it
2143     * this allows us to use this function elsewhere.
2144     *
2145     * mask nick user host
2146     * ---------------------- ------- ------- ------
2147     * Dianora!db@db.net Dianora db db.net
2148     * Dianora Dianora * *
2149     * db.net * * db.net
2150     * OR if nick pointer is NULL
2151     * Dianora - * Dianora
2152     * Dianora! Dianora * *
2153     * Dianora!@ Dianora * *
2154     * Dianora!db Dianora db *
2155     * Dianora!@db.net Dianora * db.net
2156     * db@db.net * db db.net
2157     * !@ * * *
2158     * @ * * *
2159     * ! * * *
2160     */
2161     void
2162 michael 593 split_nuh(struct split_nuh_item *const iptr)
2163 adx 30 {
2164     char *p = NULL, *q = NULL;
2165    
2166 michael 593 if (iptr->nickptr)
2167     strlcpy(iptr->nickptr, "*", iptr->nicksize);
2168     if (iptr->userptr)
2169     strlcpy(iptr->userptr, "*", iptr->usersize);
2170     if (iptr->hostptr)
2171     strlcpy(iptr->hostptr, "*", iptr->hostsize);
2172    
2173     if ((p = strchr(iptr->nuhmask, '!')))
2174 adx 30 {
2175     *p = '\0';
2176    
2177 michael 593 if (iptr->nickptr && *iptr->nuhmask != '\0')
2178     strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
2179 adx 30
2180 michael 2525 if ((q = strchr(++p, '@')))
2181     {
2182 michael 593 *q++ = '\0';
2183    
2184 adx 30 if (*p != '\0')
2185 michael 593 strlcpy(iptr->userptr, p, iptr->usersize);
2186 adx 30
2187 michael 593 if (*q != '\0')
2188     strlcpy(iptr->hostptr, q, iptr->hostsize);
2189 adx 30 }
2190     else
2191     {
2192     if (*p != '\0')
2193 michael 593 strlcpy(iptr->userptr, p, iptr->usersize);
2194 adx 30 }
2195     }
2196 michael 593 else
2197 adx 30 {
2198 michael 593 /* No ! found so lets look for a user@host */
2199     if ((p = strchr(iptr->nuhmask, '@')))
2200 adx 30 {
2201 michael 593 /* if found a @ */
2202     *p++ = '\0';
2203 adx 30
2204 michael 593 if (*iptr->nuhmask != '\0')
2205     strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
2206 adx 30
2207 michael 593 if (*p != '\0')
2208     strlcpy(iptr->hostptr, p, iptr->hostsize);
2209 adx 30 }
2210 michael 593 else
2211 adx 30 {
2212 michael 593 /* no @ found */
2213     if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
2214     strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
2215 adx 30 else
2216 michael 593 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
2217 adx 30 }
2218     }
2219     }

Properties

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