ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 3022
Committed: Mon Feb 24 20:41:16 2014 UTC (11 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 58963 byte(s)
Log Message:
- Moved "struct config_channel_entry ConfigChannel" from channel.c to conf.c

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

Properties

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