ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 2228
Committed: Thu Jun 13 19:46:30 2013 UTC (12 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 59337 byte(s)
Log Message:
- Implement certificate fingerprint validation for oper{} and connect{} blocks.
  Some code taken from oftc-hybrid. Hello, stu!

File Contents

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

Properties

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