ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 4511
Committed: Sun Aug 17 14:50:39 2014 UTC (9 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 52193 byte(s)
Log Message:
- conf.c:conf_free(): fixed possible infinite loop with /stats c as reported by Adam.
  We now assume that all MaskItem are linked onto some list

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

Properties

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