ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 3009
Committed: Wed Feb 19 11:45:36 2014 UTC (11 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 58920 byte(s)
Log Message:
- conf.c:get_oper_name(): constification

File Contents

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

Properties

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