ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 2150
Committed: Fri May 31 18:39:43 2013 UTC (12 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 58537 byte(s)
Log Message:
- Implement motd{} configuration blocks based on ircu's implementation

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     dlink_list temporary_resv = { NULL, NULL, 0 };
69    
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     MyFree(conf->user);
188     MyFree(conf->host);
189     #ifdef HAVE_LIBCRYPTO
190     MyFree(conf->cipher_list);
191    
192     if (conf->rsa_public_key)
193     RSA_free(conf->rsa_public_key);
194     #endif
195     DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head)
196     {
197     MyFree(ptr->data);
198     free_dlink_node(ptr);
199     }
200    
201     DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
202     {
203     MyFree(ptr->data);
204     free_dlink_node(ptr);
205     }
206 adx 30
207 michael 1858 DLINK_FOREACH_SAFE(ptr, ptr_next, conf->exempt_list.head)
208     {
209     struct exempt *exptr = ptr->data;
210    
211     MyFree(exptr->name);
212     MyFree(exptr->user);
213     MyFree(exptr->host);
214     MyFree(exptr);
215     }
216    
217 michael 1636 MyFree(conf);
218 adx 30 }
219    
220     /* check_client()
221     *
222     * inputs - pointer to client
223     * output - 0 = Success
224     * NOT_AUTHORIZED (-1) = Access denied (no I line match)
225     * IRCD_SOCKET_ERROR (-2) = Bad socket.
226     * I_LINE_FULL (-3) = I-line is full
227     * TOO_MANY (-4) = Too many connections from hostname
228     * BANNED_CLIENT (-5) = K-lined
229     * side effects - Ordinary client access check.
230     * Look for conf lines which have the same
231     * status as the flags passed.
232     */
233 michael 1644 int
234     check_client(struct Client *source_p)
235 adx 30 {
236     int i;
237    
238 michael 1644 if ((i = verify_access(source_p)))
239 michael 1247 ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
240 adx 30 source_p->name, source_p->sockhost);
241    
242     switch (i)
243     {
244     case TOO_MANY:
245 michael 1618 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
246 adx 30 "Too many on IP for %s (%s).",
247     get_client_name(source_p, SHOW_IP),
248     source_p->sockhost);
249 michael 1247 ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
250 adx 30 get_client_name(source_p, SHOW_IP));
251 michael 896 ++ServerStats.is_ref;
252 adx 30 exit_client(source_p, &me, "No more connections allowed on that IP");
253     break;
254    
255     case I_LINE_FULL:
256 michael 1618 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
257     "auth{} block is full for %s (%s).",
258 adx 30 get_client_name(source_p, SHOW_IP),
259     source_p->sockhost);
260 michael 1247 ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
261 adx 30 get_client_name(source_p, SHOW_IP));
262 michael 896 ++ServerStats.is_ref;
263 adx 30 exit_client(source_p, &me,
264     "No more connections allowed in your connection class");
265     break;
266    
267     case NOT_AUTHORIZED:
268 michael 896 ++ServerStats.is_ref;
269 adx 30 /* jdc - lists server name & port connections are on */
270     /* a purely cosmetical change */
271 michael 1618 sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
272 adx 30 "Unauthorized client connection from %s [%s] on [%s/%u].",
273     get_client_name(source_p, SHOW_IP),
274 michael 891 source_p->sockhost,
275 adx 30 source_p->localClient->listener->name,
276     source_p->localClient->listener->port);
277 michael 1247 ilog(LOG_TYPE_IRCD,
278 adx 30 "Unauthorized client connection from %s on [%s/%u].",
279     get_client_name(source_p, SHOW_IP),
280     source_p->localClient->listener->name,
281     source_p->localClient->listener->port);
282    
283 michael 1549 exit_client(source_p, &me, "You are not authorized to use this server");
284 adx 30 break;
285 michael 891
286 adx 30 case BANNED_CLIENT:
287 michael 1549 exit_client(source_p, &me, "Banned");
288 michael 896 ++ServerStats.is_ref;
289 adx 30 break;
290    
291     case 0:
292     default:
293     break;
294     }
295    
296 michael 1644 return (i < 0 ? 0 : 1);
297 adx 30 }
298    
299     /* verify_access()
300     *
301     * inputs - pointer to client to verify
302     * output - 0 if success -'ve if not
303     * side effect - find the first (best) I line to attach.
304     */
305     static int
306 michael 1644 verify_access(struct Client *client_p)
307 adx 30 {
308 michael 1949 struct MaskItem *conf = NULL;
309 adx 30 char non_ident[USERLEN + 1] = { '~', '\0' };
310    
311     if (IsGotId(client_p))
312     {
313 michael 1632 conf = find_address_conf(client_p->host, client_p->username,
314 adx 30 &client_p->localClient->ip,
315     client_p->localClient->aftype,
316     client_p->localClient->passwd);
317     }
318     else
319     {
320 michael 1644 strlcpy(non_ident+1, client_p->username, sizeof(non_ident)-1);
321 michael 1632 conf = find_address_conf(client_p->host,non_ident,
322 adx 30 &client_p->localClient->ip,
323     client_p->localClient->aftype,
324     client_p->localClient->passwd);
325     }
326    
327 michael 1632 if (conf != NULL)
328 adx 30 {
329 michael 1921 if (IsConfClient(conf))
330 adx 30 {
331 michael 1632 if (IsConfRedir(conf))
332 adx 30 {
333 michael 1834 sendto_one(client_p, form_str(RPL_REDIR),
334 adx 30 me.name, client_p->name,
335     conf->name ? conf->name : "",
336 michael 1632 conf->port);
337 adx 30 return(NOT_AUTHORIZED);
338     }
339    
340 michael 1632 if (IsConfDoIdentd(conf))
341 adx 30 SetNeedId(client_p);
342    
343     /* Thanks for spoof idea amm */
344 michael 1632 if (IsConfDoSpoofIp(conf))
345 adx 30 {
346 michael 1632 if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf))
347 michael 1618 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
348     "%s spoofing: %s as %s",
349 adx 30 client_p->name, client_p->host, conf->name);
350     strlcpy(client_p->host, conf->name, sizeof(client_p->host));
351 michael 2138 AddFlag(client_p, FLAGS_IP_SPOOFING | FLAGS_AUTH_SPOOF);
352 adx 30 }
353    
354     return(attach_iline(client_p, conf));
355     }
356 michael 1921 else if (IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf)))
357 adx 30 {
358 michael 1632 if (IsConfGline(conf))
359 adx 30 sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
360     client_p->name);
361 michael 1549 sendto_one(client_p, ":%s NOTICE %s :*** Banned: %s",
362 michael 1632 me.name, client_p->name, conf->reason);
363 adx 30 return(BANNED_CLIENT);
364     }
365     }
366    
367     return(NOT_AUTHORIZED);
368     }
369    
370     /* attach_iline()
371     *
372     * inputs - client pointer
373     * - conf pointer
374     * output -
375     * side effects - do actual attach
376     */
377     static int
378 michael 1632 attach_iline(struct Client *client_p, struct MaskItem *conf)
379 adx 30 {
380 michael 1632 struct ClassItem *class = NULL;
381 adx 30 struct ip_entry *ip_found;
382     int a_limit_reached = 0;
383 michael 1644 unsigned int local = 0, global = 0, ident = 0;
384 adx 30
385     ip_found = find_or_add_ip(&client_p->localClient->ip);
386     ip_found->count++;
387     SetIpHash(client_p);
388    
389 michael 1632 if (conf->class == NULL)
390 adx 30 return NOT_AUTHORIZED; /* If class is missing, this is best */
391    
392 michael 1632 class = conf->class;
393 adx 30
394     count_user_host(client_p->username, client_p->host,
395     &global, &local, &ident);
396    
397     /* XXX blah. go down checking the various silly limits
398     * setting a_limit_reached if any limit is reached.
399     * - Dianora
400     */
401 michael 1632 if (class->max_total != 0 && class->ref_count >= class->max_total)
402 adx 30 a_limit_reached = 1;
403 michael 1632 else if (class->max_perip != 0 && ip_found->count > class->max_perip)
404 adx 30 a_limit_reached = 1;
405 michael 1632 else if (class->max_local != 0 && local >= class->max_local)
406 adx 30 a_limit_reached = 1;
407 michael 1632 else if (class->max_global != 0 && global >= class->max_global)
408 adx 30 a_limit_reached = 1;
409 michael 1632 else if (class->max_ident != 0 && ident >= class->max_ident &&
410 adx 30 client_p->username[0] != '~')
411     a_limit_reached = 1;
412    
413     if (a_limit_reached)
414     {
415 michael 1632 if (!IsConfExemptLimits(conf))
416 michael 624 return TOO_MANY; /* Already at maximum allowed */
417 adx 30
418     sendto_one(client_p,
419     ":%s NOTICE %s :*** Your connection class is full, "
420     "but you have exceed_limit = yes;", me.name, client_p->name);
421     }
422    
423     return attach_conf(client_p, conf);
424     }
425    
426     /* init_ip_hash_table()
427     *
428     * inputs - NONE
429     * output - NONE
430     * side effects - allocate memory for ip_entry(s)
431     * - clear the ip hash table
432     */
433     void
434     init_ip_hash_table(void)
435     {
436 michael 1964 ip_entry_pool = mp_pool_new(sizeof(struct ip_entry), MP_CHUNK_SIZE_IP_ENTRY);
437 adx 30 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 adx 30 ConfigChannel.max_bans = 25;
1107     ConfigChannel.default_split_user_count = 0;
1108     ConfigChannel.default_split_server_count = 0;
1109 michael 1243 ConfigChannel.no_join_on_split = 0;
1110     ConfigChannel.no_create_on_split = 0;
1111 adx 30
1112 michael 1243 ConfigServerHide.flatten_links = 0;
1113 adx 30 ConfigServerHide.links_delay = 300;
1114 michael 1243 ConfigServerHide.hidden = 0;
1115     ConfigServerHide.hide_servers = 0;
1116 michael 1851 ConfigServerHide.hide_services = 0;
1117 michael 1646 ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
1118 michael 1243 ConfigServerHide.hide_server_ips = 0;
1119 adx 30
1120 michael 876
1121 michael 1646 ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1122 michael 876 ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
1123 michael 1459 ConfigFileEntry.glines = 0;
1124     ConfigFileEntry.gline_time = 12 * 3600;
1125     ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
1126 adx 30 ConfigFileEntry.gline_min_cidr = 16;
1127     ConfigFileEntry.gline_min_cidr6 = 48;
1128 michael 1243 ConfigFileEntry.invisible_on_connect = 1;
1129     ConfigFileEntry.tkline_expire_notices = 1;
1130     ConfigFileEntry.hide_spoof_ips = 1;
1131     ConfigFileEntry.ignore_bogus_ts = 0;
1132     ConfigFileEntry.disable_auth = 0;
1133     ConfigFileEntry.disable_remote = 0;
1134 adx 30 ConfigFileEntry.kill_chase_time_limit = 90;
1135 michael 1119 ConfigFileEntry.default_floodcount = 8;
1136 michael 1243 ConfigFileEntry.failed_oper_notice = 1;
1137 michael 1119 ConfigFileEntry.dots_in_ident = 0;
1138 adx 30 ConfigFileEntry.min_nonwildcard = 4;
1139     ConfigFileEntry.min_nonwildcard_simple = 3;
1140     ConfigFileEntry.max_accept = 20;
1141 michael 1243 ConfigFileEntry.anti_nick_flood = 0;
1142 adx 30 ConfigFileEntry.max_nick_time = 20;
1143     ConfigFileEntry.max_nick_changes = 5;
1144 michael 1119 ConfigFileEntry.anti_spam_exit_message_time = 0;
1145 adx 30 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1146 michael 1119 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1147 michael 1243 ConfigFileEntry.warn_no_nline = 1;
1148     ConfigFileEntry.stats_o_oper_only = 0;
1149 adx 30 ConfigFileEntry.stats_k_oper_only = 1; /* masked */
1150     ConfigFileEntry.stats_i_oper_only = 1; /* masked */
1151 michael 1243 ConfigFileEntry.stats_P_oper_only = 0;
1152 adx 30 ConfigFileEntry.caller_id_wait = 60;
1153 michael 1243 ConfigFileEntry.opers_bypass_callerid = 0;
1154 adx 30 ConfigFileEntry.pace_wait = 10;
1155     ConfigFileEntry.pace_wait_simple = 1;
1156 michael 1243 ConfigFileEntry.short_motd = 0;
1157     ConfigFileEntry.ping_cookie = 0;
1158     ConfigFileEntry.no_oper_flood = 0;
1159     ConfigFileEntry.true_no_oper_flood = 0;
1160     ConfigFileEntry.oper_pass_resv = 1;
1161 adx 30 ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
1162 michael 1119 ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
1163 adx 264 ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
1164 michael 1119 UMODE_OPERWALL | UMODE_WALLOP;
1165 michael 1243 ConfigFileEntry.use_egd = 0;
1166 adx 30 ConfigFileEntry.egdpool_path = NULL;
1167     ConfigFileEntry.throttle_time = 10;
1168     }
1169    
1170     static void
1171     validate_conf(void)
1172     {
1173     if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
1174     ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1175    
1176     if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1177     ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1178    
1179     if (ServerInfo.network_name == NULL)
1180 michael 1646 ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1181 adx 30
1182     if (ServerInfo.network_desc == NULL)
1183 michael 1646 ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1184 adx 30
1185 michael 1157 if (ConfigFileEntry.service_name == NULL)
1186 michael 1646 ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1187 michael 1157
1188 michael 876 ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
1189 adx 30 }
1190    
1191 michael 1363 /* read_conf()
1192     *
1193     * inputs - file descriptor pointing to config file to use
1194     * output - None
1195     * side effects - Read configuration file.
1196     */
1197     static void
1198     read_conf(FILE *file)
1199     {
1200     lineno = 0;
1201    
1202     set_default_conf(); /* Set default values prior to conf parsing */
1203     conf_parser_ctx.pass = 1;
1204     yyparse(); /* pick up the classes first */
1205    
1206     rewind(file);
1207    
1208     conf_parser_ctx.pass = 2;
1209     yyparse(); /* Load the values from the conf */
1210     validate_conf(); /* Check to make sure some values are still okay. */
1211     /* Some global values are also loaded here. */
1212 michael 1632 class_delete_marked(); /* Make sure classes are valid */
1213 michael 1363 }
1214    
1215 adx 30 /* lookup_confhost()
1216     *
1217     * start DNS lookups of all hostnames in the conf
1218     * line and convert an IP addresses in a.b.c.d number for to IP#s.
1219     */
1220 michael 1647 void
1221 michael 1632 lookup_confhost(struct MaskItem *conf)
1222 adx 30 {
1223     struct addrinfo hints, *res;
1224    
1225     /* Do name lookup now on hostnames given and store the
1226     * ip numbers in conf structure.
1227     */
1228     memset(&hints, 0, sizeof(hints));
1229    
1230     hints.ai_family = AF_UNSPEC;
1231     hints.ai_socktype = SOCK_STREAM;
1232    
1233     /* Get us ready for a bind() and don't bother doing dns lookup */
1234     hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
1235    
1236 michael 1632 if (getaddrinfo(conf->host, NULL, &hints, &res))
1237 adx 30 {
1238 michael 1632 conf_dns_lookup(conf);
1239 adx 30 return;
1240     }
1241    
1242     assert(res != NULL);
1243    
1244 michael 1632 memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
1245     conf->addr.ss_len = res->ai_addrlen;
1246     conf->addr.ss.ss_family = res->ai_family;
1247    
1248 michael 1123 freeaddrinfo(res);
1249 adx 30 }
1250    
1251     /* conf_connect_allowed()
1252     *
1253     * inputs - pointer to inaddr
1254     * - int type ipv4 or ipv6
1255     * output - BANNED or accepted
1256     * side effects - none
1257     */
1258     int
1259     conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
1260     {
1261     struct ip_entry *ip_found;
1262 michael 1632 struct MaskItem *conf = find_dline_conf(addr, aftype);
1263 adx 30
1264     /* DLINE exempt also gets you out of static limits/pacing... */
1265 michael 1636 if (conf && (conf->type == CONF_EXEMPT))
1266 adx 30 return 0;
1267    
1268 michael 1632 if (conf != NULL)
1269 adx 30 return BANNED_CLIENT;
1270    
1271     ip_found = find_or_add_ip(addr);
1272    
1273     if ((CurrentTime - ip_found->last_attempt) <
1274     ConfigFileEntry.throttle_time)
1275     {
1276     ip_found->last_attempt = CurrentTime;
1277     return TOO_FAST;
1278     }
1279    
1280     ip_found->last_attempt = CurrentTime;
1281     return 0;
1282     }
1283    
1284     /* find_kill()
1285     *
1286     * inputs - pointer to client structure
1287 michael 1632 * output - pointer to struct MaskItem if found
1288 adx 30 * side effects - See if this user is klined already,
1289 michael 1632 * and if so, return struct MaskItem pointer
1290 adx 30 */
1291 michael 1632 struct MaskItem *
1292 adx 30 find_kill(struct Client *client_p)
1293     {
1294 michael 1632 struct MaskItem *conf = NULL;
1295 adx 30
1296     assert(client_p != NULL);
1297    
1298 michael 1632 conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
1299     CONF_KLINE, client_p->localClient->aftype,
1300     client_p->username, NULL, 1);
1301     return conf;
1302 adx 30 }
1303    
1304 michael 1632 struct MaskItem *
1305 adx 30 find_gline(struct Client *client_p)
1306     {
1307 michael 1632 struct MaskItem *conf;
1308 adx 30
1309     assert(client_p != NULL);
1310    
1311 michael 1632 conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
1312     CONF_GLINE, client_p->localClient->aftype,
1313     client_p->username, NULL, 1);
1314     return conf;
1315 adx 30 }
1316    
1317     /* cleanup_tklines()
1318     *
1319     * inputs - NONE
1320     * output - NONE
1321     * side effects - call function to expire temporary k/d lines
1322     * This is an event started off in ircd.c
1323     */
1324     void
1325     cleanup_tklines(void *notused)
1326     {
1327 michael 1369 hostmask_expire_temporary();
1328 michael 1622 expire_tklines(&xconf_items);
1329 michael 1628 expire_tklines(&nresv_items);
1330     expire_tklines(&resv_channel_list);
1331 adx 30 }
1332    
1333     /* expire_tklines()
1334     *
1335     * inputs - tkline list pointer
1336     * output - NONE
1337     * side effects - expire tklines
1338     */
1339     static void
1340     expire_tklines(dlink_list *tklist)
1341     {
1342     dlink_node *ptr;
1343     dlink_node *next_ptr;
1344 michael 1632 struct MaskItem *conf;
1345 adx 30
1346     DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
1347     {
1348     conf = ptr->data;
1349    
1350 michael 1649 if (!conf->until || conf->until > CurrentTime)
1351 michael 1644 continue;
1352    
1353 michael 1632 if (conf->type == CONF_XLINE)
1354 adx 30 {
1355 michael 1644 if (ConfigFileEntry.tkline_expire_notices)
1356     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1357 michael 1618 "Temporary X-line for [%s] expired", conf->name);
1358 michael 1644 conf_free(conf);
1359 adx 30 }
1360 michael 1825 else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV)
1361 adx 30 {
1362 michael 1644 if (ConfigFileEntry.tkline_expire_notices)
1363     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1364 adx 30 "Temporary RESV for [%s] expired", conf->name);
1365 michael 1644 conf_free(conf);
1366 adx 30 }
1367     }
1368     }
1369    
1370     /* oper_privs_as_string()
1371     *
1372 michael 58 * inputs - pointer to client_p
1373 adx 30 * output - pointer to static string showing oper privs
1374     * side effects - return as string, the oper privs as derived from port
1375     */
1376 michael 58 static const struct oper_privs
1377     {
1378 michael 1644 const unsigned int flag;
1379 michael 58 const unsigned char c;
1380     } flag_list[] = {
1381 michael 2012 { OPER_FLAG_ADMIN, 'A' },
1382     { OPER_FLAG_REMOTEBAN, 'B' },
1383     { OPER_FLAG_DIE, 'D' },
1384     { OPER_FLAG_GLINE, 'G' },
1385     { OPER_FLAG_REHASH, 'H' },
1386     { OPER_FLAG_K, 'K' },
1387     { OPER_FLAG_OPERWALL, 'L' },
1388     { OPER_FLAG_KILL, 'N' },
1389     { OPER_FLAG_KILL_REMOTE, 'O' },
1390     { OPER_FLAG_CONNECT, 'P' },
1391     { OPER_FLAG_CONNECT_REMOTE, 'Q' },
1392     { OPER_FLAG_SQUIT, 'R' },
1393     { OPER_FLAG_SQUIT_REMOTE, 'S' },
1394     { OPER_FLAG_UNKLINE, 'U' },
1395     { OPER_FLAG_X, 'X' },
1396 michael 1294 { 0, '\0' }
1397 michael 58 };
1398 adx 30
1399     char *
1400     oper_privs_as_string(const unsigned int port)
1401     {
1402 michael 58 static char privs_out[16];
1403     char *privs_ptr = privs_out;
1404 michael 1644 const struct oper_privs *opriv = flag_list;
1405 adx 30
1406 michael 1644 for (; opriv->flag; ++opriv)
1407 michael 58 {
1408 michael 1644 if (port & opriv->flag)
1409     *privs_ptr++ = opriv->c;
1410 michael 58 else
1411 michael 1644 *privs_ptr++ = ToLower(opriv->c);
1412 michael 58 }
1413    
1414     *privs_ptr = '\0';
1415    
1416 adx 30 return privs_out;
1417     }
1418    
1419     /*
1420     * Input: A client to find the active oper{} name for.
1421     * Output: The nick!user@host{oper} of the oper.
1422     * "oper" is server name for remote opers
1423     * Side effects: None.
1424     */
1425 michael 1364 const char *
1426 adx 30 get_oper_name(const struct Client *client_p)
1427     {
1428 michael 1364 dlink_node *cnode = NULL;
1429 adx 30 /* +5 for !,@,{,} and null */
1430 michael 1147 static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1431 adx 30
1432     if (MyConnect(client_p))
1433     {
1434 michael 1364 if ((cnode = client_p->localClient->confs.head))
1435 adx 30 {
1436 michael 1632 struct MaskItem *conf = cnode->data;
1437 adx 30
1438 michael 1632 if (IsConfOperator(conf))
1439 adx 30 {
1440 michael 1147 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1441     client_p->username, client_p->host, conf->name);
1442 adx 30 return buffer;
1443     }
1444     }
1445    
1446     /* Probably should assert here for now. If there is an oper out there
1447     * with no oper{} conf attached, it would be good for us to know...
1448     */
1449     assert(0); /* Oper without oper conf! */
1450     }
1451    
1452 michael 1147 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1453     client_p->username, client_p->host, client_p->servptr->name);
1454 adx 30 return buffer;
1455     }
1456    
1457     /* read_conf_files()
1458     *
1459     * inputs - cold start YES or NO
1460     * output - none
1461     * side effects - read all conf files needed, ircd.conf kline.conf etc.
1462     */
1463     void
1464     read_conf_files(int cold)
1465     {
1466     const char *filename;
1467     char chanmodes[32];
1468     char chanlimit[32];
1469    
1470 michael 967 conf_parser_ctx.boot = cold;
1471 michael 1622 filename = ConfigFileEntry.configfile;
1472 adx 30
1473     /* We need to know the initial filename for the yyerror() to report
1474     FIXME: The full path is in conffilenamebuf first time since we
1475     dont know anything else
1476    
1477     - Gozem 2002-07-21
1478     */
1479     strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1480    
1481 michael 1325 if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1482 adx 30 {
1483     if (cold)
1484     {
1485 michael 1247 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1486 adx 30 filename, strerror(errno));
1487     exit(-1);
1488     }
1489     else
1490     {
1491 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1492 adx 30 "Unable to read configuration file '%s': %s",
1493     filename, strerror(errno));
1494     return;
1495     }
1496     }
1497    
1498     if (!cold)
1499     clear_out_old_conf();
1500    
1501 michael 967 read_conf(conf_parser_ctx.conf_file);
1502 michael 1325 fclose(conf_parser_ctx.conf_file);
1503 adx 30
1504 michael 1831 log_reopen_all();
1505    
1506 michael 1751 add_isupport("NICKLEN", NULL, ServerInfo.max_nick_length);
1507 adx 30 add_isupport("NETWORK", ServerInfo.network_name, -1);
1508 michael 1751
1509     snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1510 adx 30 add_isupport("MAXLIST", chanmodes, -1);
1511     add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
1512 michael 1474 add_isupport("CHANTYPES", "#", -1);
1513 michael 1147
1514 michael 1474 snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1515 michael 1751 ConfigChannel.max_chans_per_user);
1516 adx 30 add_isupport("CHANLIMIT", chanlimit, -1);
1517 michael 1751 snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS");
1518 michael 100 add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
1519 michael 1751 add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length);
1520 michael 1495 add_isupport("EXCEPTS", "e", -1);
1521     add_isupport("INVEX", "I", -1);
1522 adx 30 add_isupport("CHANMODES", chanmodes, -1);
1523    
1524     /*
1525     * message_locale may have changed. rebuild isupport since it relies
1526     * on strlen(form_str(RPL_ISUPPORT))
1527     */
1528     rebuild_isupport_message_line();
1529     }
1530    
1531     /* clear_out_old_conf()
1532     *
1533     * inputs - none
1534     * output - none
1535     * side effects - Clear out the old configuration
1536     */
1537     static void
1538     clear_out_old_conf(void)
1539     {
1540     dlink_node *ptr = NULL, *next_ptr = NULL;
1541 michael 1632 struct MaskItem *conf;
1542 adx 30 dlink_list *free_items [] = {
1543 michael 1383 &server_items, &oconf_items,
1544 michael 1921 &uconf_items, &xconf_items,
1545 michael 1825 &nresv_items, &cluster_items, &service_items, &resv_channel_list, NULL
1546 adx 30 };
1547    
1548     dlink_list ** iterator = free_items; /* C is dumb */
1549    
1550     /* We only need to free anything allocated by yyparse() here.
1551     * Resetting structs, etc, is taken care of by set_default_conf().
1552     */
1553    
1554     for (; *iterator != NULL; iterator++)
1555     {
1556     DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1557     {
1558     conf = ptr->data;
1559 michael 1632
1560     dlinkDelete(&conf->node, map_to_list(conf->type));
1561    
1562 adx 30 /* XXX This is less than pretty */
1563 michael 1632 if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
1564 adx 30 {
1565 michael 1644 if (!conf->ref_count)
1566 michael 1632 conf_free(conf);
1567 adx 30 }
1568 michael 1921 else if (conf->type == CONF_XLINE)
1569 adx 30 {
1570 michael 1649 if (!conf->until)
1571 michael 1632 conf_free(conf);
1572 adx 30 }
1573     else
1574 michael 1632 conf_free(conf);
1575 adx 30 }
1576     }
1577    
1578 michael 2150 motd_clear();
1579    
1580 michael 671 /*
1581     * don't delete the class table, rather mark all entries
1582 michael 1632 * for deletion. The table is cleaned up by class_delete_marked. - avalon
1583 adx 30 */
1584 michael 1632 class_mark_for_deletion();
1585 michael 671
1586 adx 30 clear_out_address_conf();
1587    
1588     /* clean out module paths */
1589     mod_clear_paths();
1590    
1591     /* clean out ServerInfo */
1592     MyFree(ServerInfo.description);
1593     ServerInfo.description = NULL;
1594     MyFree(ServerInfo.network_name);
1595     ServerInfo.network_name = NULL;
1596     MyFree(ServerInfo.network_desc);
1597     ServerInfo.network_desc = NULL;
1598     MyFree(ConfigFileEntry.egdpool_path);
1599     ConfigFileEntry.egdpool_path = NULL;
1600     #ifdef HAVE_LIBCRYPTO
1601     if (ServerInfo.rsa_private_key != NULL)
1602     {
1603     RSA_free(ServerInfo.rsa_private_key);
1604     ServerInfo.rsa_private_key = NULL;
1605     }
1606    
1607     MyFree(ServerInfo.rsa_private_key_file);
1608     ServerInfo.rsa_private_key_file = NULL;
1609 michael 1316
1610     if (ServerInfo.server_ctx)
1611     SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
1612     SSL_OP_NO_SSLv3|
1613     SSL_OP_NO_TLSv1);
1614     if (ServerInfo.client_ctx)
1615     SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
1616     SSL_OP_NO_SSLv3|
1617     SSL_OP_NO_TLSv1);
1618 adx 30 #endif
1619    
1620     /* clean out AdminInfo */
1621     MyFree(AdminInfo.name);
1622     AdminInfo.name = NULL;
1623     MyFree(AdminInfo.email);
1624     AdminInfo.email = NULL;
1625     MyFree(AdminInfo.description);
1626     AdminInfo.description = NULL;
1627    
1628     /* clean out listeners */
1629     close_listeners();
1630    
1631     /* clean out general */
1632 michael 1157 MyFree(ConfigFileEntry.service_name);
1633     ConfigFileEntry.service_name = NULL;
1634    
1635 adx 30 delete_isupport("INVEX");
1636     delete_isupport("EXCEPTS");
1637     }
1638    
1639     /* conf_add_class_to_conf()
1640     *
1641     * inputs - pointer to config item
1642     * output - NONE
1643     * side effects - Add a class pointer to a conf
1644     */
1645     void
1646 michael 1632 conf_add_class_to_conf(struct MaskItem *conf, const char *class_name)
1647 adx 30 {
1648     if (class_name == NULL)
1649     {
1650 michael 1632 conf->class = class_default;
1651 michael 671
1652 michael 1632 if (conf->type == CONF_CLIENT)
1653 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1654 adx 30 "Warning *** Defaulting to default class for %s@%s",
1655 michael 1632 conf->user, conf->host);
1656 adx 30 else
1657 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1658 adx 30 "Warning *** Defaulting to default class for %s",
1659     conf->name);
1660     }
1661     else
1662 michael 1632 conf->class = class_find(class_name, 1);
1663 adx 30
1664 michael 1632 if (conf->class == NULL)
1665 adx 30 {
1666 michael 1632 if (conf->type == CONF_CLIENT)
1667 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1668 adx 30 "Warning *** Defaulting to default class for %s@%s",
1669 michael 1632 conf->user, conf->host);
1670 adx 30 else
1671 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1672 adx 30 "Warning *** Defaulting to default class for %s",
1673     conf->name);
1674 michael 1632 conf->class = class_default;
1675 adx 30 }
1676     }
1677    
1678     /* yyerror()
1679     *
1680     * inputs - message from parser
1681     * output - NONE
1682     * side effects - message to opers and log file entry is made
1683     */
1684     void
1685     yyerror(const char *msg)
1686     {
1687     char newlinebuf[IRCD_BUFSIZE];
1688    
1689 michael 967 if (conf_parser_ctx.pass != 1)
1690 adx 30 return;
1691    
1692     strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1693 michael 1751 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1694 michael 1618 "\"%s\", line %u: %s: %s",
1695 adx 30 conffilebuf, lineno + 1, msg, newlinebuf);
1696 michael 1247 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1697 adx 30 conffilebuf, lineno + 1, msg, newlinebuf);
1698     }
1699    
1700 michael 1751 void
1701     conf_error_report(const char *msg)
1702     {
1703     char newlinebuf[IRCD_BUFSIZE];
1704    
1705     strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1706     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1707     "\"%s\", line %u: %s: %s",
1708     conffilebuf, lineno + 1, msg, newlinebuf);
1709     ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1710     conffilebuf, lineno + 1, msg, newlinebuf);
1711     }
1712    
1713 adx 30 /*
1714     * valid_tkline()
1715     *
1716     * inputs - pointer to ascii string to check
1717     * - whether the specified time is in seconds or minutes
1718     * output - -1 not enough parameters
1719     * - 0 if not an integer number, else the number
1720     * side effects - none
1721     * Originally written by Dianora (Diane, db@db.net)
1722     */
1723     time_t
1724 michael 1120 valid_tkline(const char *p, int minutes)
1725 adx 30 {
1726     time_t result = 0;
1727    
1728 michael 1120 for (; *p; ++p)
1729 adx 30 {
1730 michael 1120 if (!IsDigit(*p))
1731 michael 1121 return 0;
1732 michael 1120
1733     result *= 10;
1734     result += ((*p) & 0xF);
1735 adx 30 }
1736    
1737 michael 1120 /*
1738     * In the degenerate case where oper does a /quote kline 0 user@host :reason
1739 adx 30 * i.e. they specifically use 0, I am going to return 1 instead
1740     * as a return value of non-zero is used to flag it as a temporary kline
1741     */
1742     if (result == 0)
1743     result = 1;
1744    
1745     /*
1746     * If the incoming time is in seconds convert it to minutes for the purpose
1747     * of this calculation
1748     */
1749     if (!minutes)
1750     result = result / (time_t)60;
1751    
1752     if (result > MAX_TDKLINE_TIME)
1753     result = MAX_TDKLINE_TIME;
1754    
1755     result = result * (time_t)60; /* turn it into seconds */
1756    
1757     return result;
1758     }
1759    
1760 michael 2130 /* valid_wild_card_simple()
1761     *
1762     * inputs - data to check for sufficient non-wildcard characters
1763     * outputs - 1 if valid, else 0
1764     * side effects - none
1765     */
1766     int
1767     valid_wild_card_simple(const char *data)
1768     {
1769     const unsigned char *p = (const unsigned char *)data;
1770     unsigned char tmpch = '\0';
1771     int nonwild = 0;
1772    
1773     while ((tmpch = *p++))
1774     {
1775     if (tmpch == '\\')
1776     {
1777     ++p;
1778     if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1779     return 1;
1780     }
1781     else if (!IsMWildChar(tmpch))
1782     {
1783     if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1784     return 1;
1785     }
1786     }
1787    
1788     return 0;
1789     }
1790    
1791 adx 30 /* valid_wild_card()
1792     *
1793     * input - pointer to client
1794     * - int flag, 0 for no warning oper 1 for warning oper
1795     * - count of following varargs to check
1796     * output - 0 if not valid, 1 if valid
1797     * side effects - NOTICE is given to source_p if warn is 1
1798     */
1799     int
1800     valid_wild_card(struct Client *source_p, int warn, int count, ...)
1801     {
1802     char tmpch;
1803     int nonwild = 0;
1804     va_list args;
1805    
1806     /*
1807     * Now we must check the user and host to make sure there
1808     * are at least NONWILDCHARS non-wildcard characters in
1809     * them, otherwise assume they are attempting to kline
1810     * *@* or some variant of that. This code will also catch
1811     * people attempting to kline *@*.tld, as long as NONWILDCHARS
1812     * is greater than 3. In that case, there are only 3 non-wild
1813     * characters (tld), so if NONWILDCHARS is 4, the kline will
1814     * be disallowed.
1815     * -wnder
1816     */
1817    
1818     va_start(args, count);
1819    
1820     while (count--)
1821     {
1822 michael 2133 const char *p = va_arg(args, const char *);
1823 adx 30 if (p == NULL)
1824     continue;
1825    
1826     while ((tmpch = *p++))
1827     {
1828     if (!IsKWildChar(tmpch))
1829     {
1830     /*
1831     * If we find enough non-wild characters, we can
1832     * break - no point in searching further.
1833     */
1834     if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1835     return 1;
1836     }
1837     }
1838     }
1839    
1840     if (warn)
1841     sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask",
1842     me.name, source_p->name, ConfigFileEntry.min_nonwildcard);
1843     return 0;
1844     }
1845    
1846     /* XXX should this go into a separate file ? -Dianora */
1847     /* parse_aline
1848     *
1849     * input - pointer to cmd name being used
1850     * - pointer to client using cmd
1851     * - parc parameter count
1852     * - parv[] list of parameters to parse
1853     * - parse_flags bit map of things to test
1854     * - pointer to user or string to parse into
1855     * - pointer to host or NULL to parse into if non NULL
1856     * - pointer to optional tkline time or NULL
1857     * - pointer to target_server to parse into if non NULL
1858     * - pointer to reason to parse into
1859     *
1860     * output - 1 if valid, -1 if not valid
1861     * side effects - A generalised k/d/x etc. line parser,
1862     * "ALINE [time] user@host|string [ON] target :reason"
1863     * will parse returning a parsed user, host if
1864     * h_p pointer is non NULL, string otherwise.
1865     * if tkline_time pointer is non NULL a tk line will be set
1866     * to non zero if found.
1867     * if tkline_time pointer is NULL and tk line is found,
1868     * error is reported.
1869     * if target_server is NULL and an "ON" is found error
1870     * is reported.
1871     * if reason pointer is NULL ignore pointer,
1872 db 936 * this allows use of parse_a_line in unkline etc.
1873 adx 30 *
1874     * - Dianora
1875     */
1876     int
1877     parse_aline(const char *cmd, struct Client *source_p,
1878     int parc, char **parv,
1879     int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1880     char **target_server, char **reason)
1881     {
1882     int found_tkline_time=0;
1883     static char def_reason[] = "No Reason";
1884     static char user[USERLEN*4+1];
1885     static char host[HOSTLEN*4+1];
1886    
1887     parv++;
1888     parc--;
1889    
1890     found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1891    
1892     if (found_tkline_time != 0)
1893     {
1894     parv++;
1895     parc--;
1896    
1897     if (tkline_time != NULL)
1898     *tkline_time = found_tkline_time;
1899     else
1900     {
1901     sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
1902     me.name, source_p->name, cmd);
1903     return -1;
1904     }
1905     }
1906    
1907     if (parc == 0)
1908     {
1909 michael 1834 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1910 adx 30 me.name, source_p->name, cmd);
1911     return -1;
1912     }
1913    
1914     if (h_p == NULL)
1915     *up_p = *parv;
1916     else
1917     {
1918     if (find_user_host(source_p, *parv, user, host, parse_flags) == 0)
1919     return -1;
1920    
1921     *up_p = user;
1922     *h_p = host;
1923     }
1924    
1925     parc--;
1926     parv++;
1927    
1928     if (parc != 0)
1929     {
1930     if (irccmp(*parv, "ON") == 0)
1931     {
1932     parc--;
1933     parv++;
1934    
1935     if (target_server == NULL)
1936     {
1937     sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
1938     me.name, source_p->name, cmd);
1939     return -1;
1940     }
1941    
1942 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1943 adx 30 {
1944 michael 1834 sendto_one(source_p, form_str(ERR_NOPRIVS),
1945 adx 30 me.name, source_p->name, "remoteban");
1946     return -1;
1947     }
1948    
1949     if (parc == 0 || EmptyString(*parv))
1950     {
1951 michael 1834 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1952 adx 30 me.name, source_p->name, cmd);
1953     return -1;
1954     }
1955    
1956     *target_server = *parv;
1957     parc--;
1958     parv++;
1959     }
1960     else
1961     {
1962     /* Make sure target_server *is* NULL if no ON server found
1963     * caller probably NULL'd it first, but no harm to do it again -db
1964     */
1965     if (target_server != NULL)
1966     *target_server = NULL;
1967     }
1968     }
1969    
1970     if (h_p != NULL)
1971     {
1972     if (strchr(user, '!') != NULL)
1973     {
1974     sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline",
1975     me.name, source_p->name);
1976     return -1;
1977     }
1978    
1979 michael 1243 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
1980 adx 30 return -1;
1981     }
1982     else
1983 michael 1243 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
1984 adx 30 return -1;
1985    
1986     if (reason != NULL)
1987     {
1988 michael 867 if (parc != 0 && !EmptyString(*parv))
1989 adx 30 {
1990     *reason = *parv;
1991 michael 1243 if (!valid_comment(source_p, *reason, 1))
1992 adx 30 return -1;
1993     }
1994     else
1995     *reason = def_reason;
1996     }
1997    
1998     return 1;
1999     }
2000    
2001     /* find_user_host()
2002     *
2003     * inputs - pointer to client placing kline
2004     * - pointer to user_host_or_nick
2005     * - pointer to user buffer
2006     * - pointer to host buffer
2007     * output - 0 if not ok to kline, 1 to kline i.e. if valid user host
2008     * side effects -
2009     */
2010     static int
2011     find_user_host(struct Client *source_p, char *user_host_or_nick,
2012     char *luser, char *lhost, unsigned int flags)
2013     {
2014     struct Client *target_p = NULL;
2015     char *hostp = NULL;
2016    
2017     if (lhost == NULL)
2018     {
2019     strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
2020     return 1;
2021     }
2022    
2023     if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
2024     {
2025     /* Explicit user@host mask given */
2026    
2027 michael 593 if (hostp != NULL) /* I'm a little user@host */
2028 adx 30 {
2029     *(hostp++) = '\0'; /* short and squat */
2030     if (*user_host_or_nick)
2031     strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
2032     else
2033     strcpy(luser, "*");
2034     if (*hostp)
2035     strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */
2036     else
2037     strcpy(lhost, "*");
2038     }
2039     else
2040     {
2041     luser[0] = '*'; /* no @ found, assume its *@somehost */
2042     luser[1] = '\0';
2043     strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
2044     }
2045    
2046     return 1;
2047     }
2048 michael 1518 else
2049 adx 30 {
2050     /* Try to find user@host mask from nick */
2051     /* Okay to use source_p as the first param, because source_p == client_p */
2052     if ((target_p =
2053     find_chasing(source_p, source_p, user_host_or_nick, NULL)) == NULL)
2054     return 0;
2055    
2056     if (IsExemptKline(target_p))
2057     {
2058     if (!IsServer(source_p))
2059     sendto_one(source_p,
2060     ":%s NOTICE %s :%s is E-lined",
2061     me.name, source_p->name, target_p->name);
2062     return 0;
2063     }
2064    
2065     /*
2066     * turn the "user" bit into "*user", blow away '~'
2067     * if found in original user name (non-idented)
2068     */
2069     strlcpy(luser, target_p->username, USERLEN*4 + 1);
2070    
2071     if (target_p->username[0] == '~')
2072     luser[0] = '*';
2073    
2074     if (target_p->sockhost[0] == '\0' ||
2075     (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
2076     strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
2077     else
2078     strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
2079     return 1;
2080     }
2081    
2082     return 0;
2083     }
2084    
2085     /* valid_comment()
2086     *
2087     * inputs - pointer to client
2088     * - pointer to comment
2089     * output - 0 if no valid comment,
2090     * - 1 if valid
2091     * side effects - truncates reason where necessary
2092     */
2093     int
2094     valid_comment(struct Client *source_p, char *comment, int warn)
2095     {
2096     if (strlen(comment) > REASONLEN)
2097     comment[REASONLEN-1] = '\0';
2098    
2099     return 1;
2100     }
2101    
2102     /* match_conf_password()
2103     *
2104     * inputs - pointer to given password
2105     * - pointer to Conf
2106     * output - 1 or 0 if match
2107     * side effects - none
2108     */
2109     int
2110 michael 1632 match_conf_password(const char *password, const struct MaskItem *conf)
2111 adx 30 {
2112     const char *encr = NULL;
2113    
2114 michael 1632 if (EmptyString(password) || EmptyString(conf->passwd))
2115 adx 30 return 0;
2116    
2117 michael 1632 if (conf->flags & CONF_FLAGS_ENCRYPTED)
2118     encr = crypt(password, conf->passwd);
2119 adx 30 else
2120     encr = password;
2121    
2122 michael 1632 return !strcmp(encr, conf->passwd);
2123 adx 30 }
2124    
2125     /*
2126     * cluster_a_line
2127     *
2128     * inputs - client sending the cluster
2129     * - command name "KLINE" "XLINE" etc.
2130     * - capab -- CAP_KLN etc. from s_serv.h
2131 michael 1309 * - cluster type -- CLUSTER_KLINE etc. from conf.h
2132 adx 30 * - pattern and args to send along
2133     * output - none
2134     * side effects - Take source_p send the pattern with args given
2135     * along to all servers that match capab and cluster type
2136     */
2137     void
2138     cluster_a_line(struct Client *source_p, const char *command,
2139 michael 593 int capab, int cluster_type, const char *pattern, ...)
2140 adx 30 {
2141     va_list args;
2142     char buffer[IRCD_BUFSIZE];
2143 michael 593 const dlink_node *ptr = NULL;
2144 adx 30
2145     va_start(args, pattern);
2146     vsnprintf(buffer, sizeof(buffer), pattern, args);
2147     va_end(args);
2148    
2149     DLINK_FOREACH(ptr, cluster_items.head)
2150     {
2151 michael 1632 const struct MaskItem *conf = ptr->data;
2152 adx 30
2153     if (conf->flags & cluster_type)
2154     sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
2155     "%s %s %s", command, conf->name, buffer);
2156     }
2157     }
2158    
2159     /*
2160     * split_nuh
2161     *
2162     * inputs - pointer to original mask (modified in place)
2163     * - pointer to pointer where nick should go
2164     * - pointer to pointer where user should go
2165     * - pointer to pointer where host should go
2166     * output - NONE
2167     * side effects - mask is modified in place
2168     * If nick pointer is NULL, ignore writing to it
2169     * this allows us to use this function elsewhere.
2170     *
2171     * mask nick user host
2172     * ---------------------- ------- ------- ------
2173     * Dianora!db@db.net Dianora db db.net
2174     * Dianora Dianora * *
2175     * db.net * * db.net
2176     * OR if nick pointer is NULL
2177     * Dianora - * Dianora
2178     * Dianora! Dianora * *
2179     * Dianora!@ Dianora * *
2180     * Dianora!db Dianora db *
2181     * Dianora!@db.net Dianora * db.net
2182     * db@db.net * db db.net
2183     * !@ * * *
2184     * @ * * *
2185     * ! * * *
2186     */
2187     void
2188 michael 593 split_nuh(struct split_nuh_item *const iptr)
2189 adx 30 {
2190     char *p = NULL, *q = NULL;
2191    
2192 michael 593 if (iptr->nickptr)
2193     strlcpy(iptr->nickptr, "*", iptr->nicksize);
2194     if (iptr->userptr)
2195     strlcpy(iptr->userptr, "*", iptr->usersize);
2196     if (iptr->hostptr)
2197     strlcpy(iptr->hostptr, "*", iptr->hostsize);
2198    
2199     if ((p = strchr(iptr->nuhmask, '!')))
2200 adx 30 {
2201     *p = '\0';
2202    
2203 michael 593 if (iptr->nickptr && *iptr->nuhmask != '\0')
2204     strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
2205 adx 30
2206 michael 593 if ((q = strchr(++p, '@'))) {
2207     *q++ = '\0';
2208    
2209 adx 30 if (*p != '\0')
2210 michael 593 strlcpy(iptr->userptr, p, iptr->usersize);
2211 adx 30
2212 michael 593 if (*q != '\0')
2213     strlcpy(iptr->hostptr, q, iptr->hostsize);
2214 adx 30 }
2215     else
2216     {
2217     if (*p != '\0')
2218 michael 593 strlcpy(iptr->userptr, p, iptr->usersize);
2219 adx 30 }
2220     }
2221 michael 593 else
2222 adx 30 {
2223 michael 593 /* No ! found so lets look for a user@host */
2224     if ((p = strchr(iptr->nuhmask, '@')))
2225 adx 30 {
2226 michael 593 /* if found a @ */
2227     *p++ = '\0';
2228 adx 30
2229 michael 593 if (*iptr->nuhmask != '\0')
2230     strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
2231 adx 30
2232 michael 593 if (*p != '\0')
2233     strlcpy(iptr->hostptr, p, iptr->hostsize);
2234 adx 30 }
2235 michael 593 else
2236 adx 30 {
2237 michael 593 /* no @ found */
2238     if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
2239     strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
2240 adx 30 else
2241 michael 593 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
2242 adx 30 }
2243     }
2244     }

Properties

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