ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/conf.c
Revision: 1922
Committed: Tue Apr 30 15:08:42 2013 UTC (10 years, 11 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/conf.c
File size: 57739 byte(s)
Log Message:
- Moved report_confitem_types() to m_stats.c

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

Properties

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