ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 2130
Committed: Wed May 29 15:32:28 2013 UTC (12 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 58460 byte(s)
Log Message:
- resv.c: move valid_wild_card_simple() to conf.c

File Contents

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

Properties

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