ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 2872
Committed: Sun Jan 19 17:25:38 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 58931 byte(s)
Log Message:
- Moved configuration related code from ircd.c to conf.c

File Contents

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

Properties

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