ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 4513
Committed: Sun Aug 17 18:25:52 2014 UTC (12 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 52087 byte(s)
Log Message:
- conf.c:rehash(): moved the strlcpy(me.info,...) to conf_parser.y

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     load_conf_modules();
783 michael 3929 check_conf_klines();
784 adx 30
785 michael 1831 return 0;
786 adx 30 }
787    
788     /* set_default_conf()
789     *
790     * inputs - NONE
791     * output - NONE
792     * side effects - Set default values here.
793     * This is called **PRIOR** to parsing the
794     * configuration file. If you want to do some validation
795     * of values later, put them in validate_conf().
796     */
797     static void
798     set_default_conf(void)
799     {
800     /* verify init_class() ran, this should be an unnecessary check
801     * but its not much work.
802     */
803 michael 1644 assert(class_default == class_get_list()->tail->data);
804 adx 30
805     #ifdef HAVE_LIBCRYPTO
806 michael 4496 #if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH)
807     {
808     EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
809    
810     if (key)
811     {
812     SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key);
813     EC_KEY_free(key);
814     }
815     }
816    
817     SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
818     #endif
819    
820 michael 4340 ConfigServerInfo.message_digest_algorithm = EVP_sha256();
821     ConfigServerInfo.rsa_private_key = NULL;
822     ConfigServerInfo.rsa_private_key_file = NULL;
823 adx 30 #endif
824    
825 michael 4340 /* ConfigServerInfo.name is not rehashable */
826     /* ConfigServerInfo.name = ConfigServerInfo.name; */
827     ConfigServerInfo.description = NULL;
828     ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
829     ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
830 adx 30
831 michael 4340 memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip));
832     ConfigServerInfo.specific_ipv4_vhost = 0;
833     memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6));
834     ConfigServerInfo.specific_ipv6_vhost = 0;
835 adx 30
836 michael 4340 ConfigServerInfo.max_clients = MAXCLIENTS_MAX;
837     ConfigServerInfo.max_nick_length = 9;
838     ConfigServerInfo.max_topic_length = 80;
839     ConfigServerInfo.hub = 0;
840 michael 4313
841 michael 4340 ConfigAdminInfo.name = NULL;
842     ConfigAdminInfo.email = NULL;
843     ConfigAdminInfo.description = NULL;
844 adx 30
845 michael 1831 log_del_all();
846 michael 1247
847 michael 4340 ConfigLog.use_logging = 1;
848 adx 30
849 michael 1243 ConfigChannel.disable_fake_channels = 0;
850 michael 3860 ConfigChannel.invite_client_count = 10;
851     ConfigChannel.invite_client_time = 300;
852     ConfigChannel.knock_client_count = 1;
853     ConfigChannel.knock_client_time = 300;
854 adx 30 ConfigChannel.knock_delay_channel = 60;
855 michael 3933 ConfigChannel.max_channels = 25;
856 adx 30 ConfigChannel.max_bans = 25;
857     ConfigChannel.default_split_user_count = 0;
858     ConfigChannel.default_split_server_count = 0;
859 michael 1243 ConfigChannel.no_join_on_split = 0;
860     ConfigChannel.no_create_on_split = 0;
861 adx 30
862 michael 1243 ConfigServerHide.flatten_links = 0;
863 adx 30 ConfigServerHide.links_delay = 300;
864 michael 1243 ConfigServerHide.hidden = 0;
865     ConfigServerHide.hide_servers = 0;
866 michael 1851 ConfigServerHide.hide_services = 0;
867 michael 1646 ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
868 michael 1243 ConfigServerHide.hide_server_ips = 0;
869 michael 2196 ConfigServerHide.disable_remote_commands = 0;
870 adx 30
871 michael 4340 ConfigGeneral.away_count = 2;
872     ConfigGeneral.away_time = 10;
873     ConfigGeneral.service_name = xstrdup(SERVICE_NAME_DEFAULT);
874     ConfigGeneral.max_watch = WATCHSIZE_DEFAULT;
875     ConfigGeneral.cycle_on_host_change = 1;
876     ConfigGeneral.glines = 0;
877     ConfigGeneral.gline_time = 12 * 3600;
878     ConfigGeneral.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
879     ConfigGeneral.gline_min_cidr = 16;
880     ConfigGeneral.gline_min_cidr6 = 48;
881     ConfigGeneral.invisible_on_connect = 1;
882     ConfigGeneral.tkline_expire_notices = 1;
883     ConfigGeneral.hide_spoof_ips = 1;
884     ConfigGeneral.ignore_bogus_ts = 0;
885     ConfigGeneral.disable_auth = 0;
886     ConfigGeneral.kill_chase_time_limit = 90;
887     ConfigGeneral.default_floodcount = 8;
888     ConfigGeneral.failed_oper_notice = 1;
889     ConfigGeneral.dots_in_ident = 0;
890     ConfigGeneral.min_nonwildcard = 4;
891     ConfigGeneral.min_nonwildcard_simple = 3;
892     ConfigGeneral.max_accept = 20;
893     ConfigGeneral.anti_nick_flood = 0;
894     ConfigGeneral.max_nick_time = 20;
895     ConfigGeneral.max_nick_changes = 5;
896     ConfigGeneral.anti_spam_exit_message_time = 0;
897     ConfigGeneral.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
898     ConfigGeneral.ts_max_delta = TS_MAX_DELTA_DEFAULT;
899     ConfigGeneral.warn_no_connect_block = 1;
900     ConfigGeneral.stats_e_disabled = 0;
901     ConfigGeneral.stats_o_oper_only = 0;
902     ConfigGeneral.stats_k_oper_only = 1; /* 1 = masked */
903     ConfigGeneral.stats_i_oper_only = 1; /* 1 = masked */
904     ConfigGeneral.stats_P_oper_only = 0;
905     ConfigGeneral.stats_u_oper_only = 0;
906     ConfigGeneral.caller_id_wait = 60;
907     ConfigGeneral.opers_bypass_callerid = 0;
908     ConfigGeneral.pace_wait = 10;
909     ConfigGeneral.pace_wait_simple = 1;
910     ConfigGeneral.short_motd = 0;
911     ConfigGeneral.ping_cookie = 0;
912     ConfigGeneral.no_oper_flood = 0;
913     ConfigGeneral.true_no_oper_flood = 0;
914     ConfigGeneral.oper_pass_resv = 1;
915     ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT;
916     ConfigGeneral.oper_only_umodes = UMODE_DEBUG;
917     ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP;
918     ConfigGeneral.throttle_count = 1;
919     ConfigGeneral.throttle_time = 1;
920 adx 30 }
921    
922     static void
923     validate_conf(void)
924     {
925 michael 4340 if (ConfigGeneral.ts_warn_delta < TS_WARN_DELTA_MIN)
926     ConfigGeneral.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
927 adx 30
928 michael 4340 if (ConfigGeneral.ts_max_delta < TS_MAX_DELTA_MIN)
929     ConfigGeneral.ts_max_delta = TS_MAX_DELTA_DEFAULT;
930 adx 30
931 michael 4340 if (ConfigServerInfo.network_name == NULL)
932     ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
933 adx 30
934 michael 4340 if (ConfigServerInfo.network_desc == NULL)
935     ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
936 adx 30
937 michael 4340 if (ConfigGeneral.service_name == NULL)
938     ConfigGeneral.service_name = xstrdup(SERVICE_NAME_DEFAULT);
939 michael 1157
940 michael 4340 ConfigGeneral.max_watch = IRCD_MAX(ConfigGeneral.max_watch, WATCHSIZE_MIN);
941 adx 30 }
942    
943 michael 2916 /* read_conf()
944 michael 1363 *
945     * inputs - file descriptor pointing to config file to use
946     * output - None
947     * side effects - Read configuration file.
948     */
949     static void
950     read_conf(FILE *file)
951     {
952     lineno = 0;
953    
954 michael 3375 set_default_conf(); /* Set default values prior to conf parsing */
955 michael 1363 conf_parser_ctx.pass = 1;
956 michael 3375 yyparse(); /* Pick up the classes first */
957 michael 1363
958     rewind(file);
959    
960     conf_parser_ctx.pass = 2;
961 michael 3375 yyparse(); /* Load the values from the conf */
962     validate_conf(); /* Check to make sure some values are still okay. */
963     /* Some global values are also loaded here. */
964     class_delete_marked(); /* Delete unused classes that are marked for deletion */
965 michael 1363 }
966    
967 adx 30 /* lookup_confhost()
968     *
969     * start DNS lookups of all hostnames in the conf
970     * line and convert an IP addresses in a.b.c.d number for to IP#s.
971     */
972 michael 1647 void
973 michael 1632 lookup_confhost(struct MaskItem *conf)
974 adx 30 {
975     struct addrinfo hints, *res;
976    
977 michael 3375 /*
978     * Do name lookup now on hostnames given and store the
979 adx 30 * ip numbers in conf structure.
980     */
981     memset(&hints, 0, sizeof(hints));
982    
983     hints.ai_family = AF_UNSPEC;
984     hints.ai_socktype = SOCK_STREAM;
985    
986     /* Get us ready for a bind() and don't bother doing dns lookup */
987     hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
988    
989 michael 1632 if (getaddrinfo(conf->host, NULL, &hints, &res))
990 adx 30 {
991 michael 1632 conf_dns_lookup(conf);
992 adx 30 return;
993     }
994    
995 michael 3235 assert(res);
996 adx 30
997 michael 1632 memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
998     conf->addr.ss_len = res->ai_addrlen;
999     conf->addr.ss.ss_family = res->ai_family;
1000    
1001 michael 1123 freeaddrinfo(res);
1002 adx 30 }
1003    
1004     /* conf_connect_allowed()
1005     *
1006     * inputs - pointer to inaddr
1007     * - int type ipv4 or ipv6
1008     * output - BANNED or accepted
1009     * side effects - none
1010     */
1011     int
1012     conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
1013     {
1014 michael 3877 struct ip_entry *ip_found = NULL;
1015 michael 1632 struct MaskItem *conf = find_dline_conf(addr, aftype);
1016 adx 30
1017     /* DLINE exempt also gets you out of static limits/pacing... */
1018 michael 1636 if (conf && (conf->type == CONF_EXEMPT))
1019 adx 30 return 0;
1020    
1021 michael 3235 if (conf)
1022 adx 30 return BANNED_CLIENT;
1023    
1024 michael 4325 ip_found = ipcache_find_or_add_address(addr);
1025 adx 30
1026 michael 4340 if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
1027 adx 30 {
1028 michael 4340 if (ip_found->connection_count >= ConfigGeneral.throttle_count)
1029 michael 3877 return TOO_FAST;
1030 michael 4055
1031     ++ip_found->connection_count;
1032 adx 30 }
1033 michael 3877 else
1034     ip_found->connection_count = 1;
1035 adx 30
1036     ip_found->last_attempt = CurrentTime;
1037     return 0;
1038     }
1039    
1040     /* cleanup_tklines()
1041     *
1042     * inputs - NONE
1043     * output - NONE
1044     * side effects - call function to expire temporary k/d lines
1045     * This is an event started off in ircd.c
1046     */
1047     void
1048 michael 4439 cleanup_tklines(void *unused)
1049 adx 30 {
1050 michael 1369 hostmask_expire_temporary();
1051 michael 2916 expire_tklines(&xconf_items);
1052 michael 1628 expire_tklines(&nresv_items);
1053 michael 2174 expire_tklines(&cresv_items);
1054 adx 30 }
1055    
1056     /* expire_tklines()
1057     *
1058     * inputs - tkline list pointer
1059     * output - NONE
1060     * side effects - expire tklines
1061     */
1062     static void
1063     expire_tklines(dlink_list *tklist)
1064     {
1065 michael 3235 dlink_node *ptr = NULL, *ptr_next = NULL;
1066     struct MaskItem *conf = NULL;
1067 adx 30
1068 michael 3235 DLINK_FOREACH_SAFE(ptr, ptr_next, tklist->head)
1069 adx 30 {
1070     conf = ptr->data;
1071    
1072 michael 1649 if (!conf->until || conf->until > CurrentTime)
1073 michael 1644 continue;
1074    
1075 michael 1632 if (conf->type == CONF_XLINE)
1076 adx 30 {
1077 michael 4340 if (ConfigGeneral.tkline_expire_notices)
1078 michael 1644 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1079 michael 1618 "Temporary X-line for [%s] expired", conf->name);
1080 michael 1644 conf_free(conf);
1081 adx 30 }
1082 michael 1825 else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV)
1083 adx 30 {
1084 michael 4340 if (ConfigGeneral.tkline_expire_notices)
1085 michael 1644 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1086 adx 30 "Temporary RESV for [%s] expired", conf->name);
1087 michael 1644 conf_free(conf);
1088 adx 30 }
1089     }
1090     }
1091    
1092     /* oper_privs_as_string()
1093     *
1094 michael 58 * inputs - pointer to client_p
1095 adx 30 * output - pointer to static string showing oper privs
1096     * side effects - return as string, the oper privs as derived from port
1097     */
1098 michael 58 static const struct oper_privs
1099     {
1100 michael 1644 const unsigned int flag;
1101 michael 58 const unsigned char c;
1102     } flag_list[] = {
1103 michael 2012 { OPER_FLAG_ADMIN, 'A' },
1104     { OPER_FLAG_REMOTEBAN, 'B' },
1105     { OPER_FLAG_DIE, 'D' },
1106     { OPER_FLAG_GLINE, 'G' },
1107     { OPER_FLAG_REHASH, 'H' },
1108 michael 4019 { OPER_FLAG_KLINE, 'K' },
1109 michael 2012 { OPER_FLAG_KILL, 'N' },
1110     { OPER_FLAG_KILL_REMOTE, 'O' },
1111     { OPER_FLAG_CONNECT, 'P' },
1112     { OPER_FLAG_CONNECT_REMOTE, 'Q' },
1113     { OPER_FLAG_SQUIT, 'R' },
1114     { OPER_FLAG_SQUIT_REMOTE, 'S' },
1115     { OPER_FLAG_UNKLINE, 'U' },
1116 michael 2852 { OPER_FLAG_XLINE, 'X' },
1117 michael 1294 { 0, '\0' }
1118 michael 58 };
1119 adx 30
1120     char *
1121     oper_privs_as_string(const unsigned int port)
1122     {
1123 michael 2694 static char privs_out[IRCD_BUFSIZE];
1124 michael 58 char *privs_ptr = privs_out;
1125 adx 30
1126 michael 3283 for (const struct oper_privs *opriv = flag_list; opriv->flag; ++opriv)
1127 michael 58 {
1128 michael 1644 if (port & opriv->flag)
1129     *privs_ptr++ = opriv->c;
1130 michael 58 else
1131 michael 1644 *privs_ptr++ = ToLower(opriv->c);
1132 michael 58 }
1133    
1134     *privs_ptr = '\0';
1135    
1136 adx 30 return privs_out;
1137     }
1138    
1139     /*
1140 michael 4298 * Input: A client to find the active operator {} name for.
1141 adx 30 * Output: The nick!user@host{oper} of the oper.
1142     * "oper" is server name for remote opers
1143     * Side effects: None.
1144     */
1145 michael 1364 const char *
1146 adx 30 get_oper_name(const struct Client *client_p)
1147     {
1148 michael 3009 const dlink_node *cnode = NULL;
1149 adx 30 /* +5 for !,@,{,} and null */
1150 michael 1147 static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1151 adx 30
1152     if (MyConnect(client_p))
1153     {
1154 michael 1364 if ((cnode = client_p->localClient->confs.head))
1155 adx 30 {
1156 michael 3009 const struct MaskItem *conf = cnode->data;
1157 adx 30
1158 michael 1632 if (IsConfOperator(conf))
1159 adx 30 {
1160 michael 2182 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1161 michael 1147 client_p->username, client_p->host, conf->name);
1162 michael 2182 return buffer;
1163 adx 30 }
1164     }
1165    
1166 michael 4298 /*
1167     * Probably should assert here for now. If there is an oper out there
1168     * with no operator {} conf attached, it would be good for us to know...
1169 adx 30 */
1170 michael 4298 assert(0); /* Oper without oper conf! */
1171 adx 30 }
1172    
1173 michael 1147 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1174 michael 2182 client_p->username, client_p->host, client_p->servptr->name);
1175 adx 30 return buffer;
1176     }
1177    
1178     /* read_conf_files()
1179     *
1180     * inputs - cold start YES or NO
1181     * output - none
1182     * side effects - read all conf files needed, ircd.conf kline.conf etc.
1183     */
1184     void
1185     read_conf_files(int cold)
1186     {
1187 michael 3375 const char *filename = NULL;
1188     char chanmodes[IRCD_BUFSIZE] = "";
1189     char chanlimit[IRCD_BUFSIZE] = "";
1190 adx 30
1191 michael 967 conf_parser_ctx.boot = cold;
1192 michael 4340 filename = ConfigGeneral.configfile;
1193 adx 30
1194     /* We need to know the initial filename for the yyerror() to report
1195     FIXME: The full path is in conffilenamebuf first time since we
1196 michael 4298 don't know anything else
1197 adx 30
1198 michael 2916 - Gozem 2002-07-21
1199 adx 30 */
1200     strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1201    
1202 michael 1325 if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1203 adx 30 {
1204     if (cold)
1205     {
1206 michael 1247 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1207 adx 30 filename, strerror(errno));
1208     exit(-1);
1209     }
1210     else
1211     {
1212 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1213 michael 2182 "Unable to read configuration file '%s': %s",
1214     filename, strerror(errno));
1215 adx 30 return;
1216     }
1217     }
1218    
1219     if (!cold)
1220     clear_out_old_conf();
1221    
1222 michael 967 read_conf(conf_parser_ctx.conf_file);
1223 michael 1325 fclose(conf_parser_ctx.conf_file);
1224 adx 30
1225 michael 1831 log_reopen_all();
1226    
1227 michael 4340 add_isupport("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1228     add_isupport("NETWORK", ConfigServerInfo.network_name, -1);
1229 michael 1751
1230     snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1231 adx 30 add_isupport("MAXLIST", chanmodes, -1);
1232 michael 4340 add_isupport("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1233 michael 1474 add_isupport("CHANTYPES", "#", -1);
1234 michael 1147
1235 michael 1474 snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1236 michael 3933 ConfigChannel.max_channels);
1237 adx 30 add_isupport("CHANLIMIT", chanlimit, -1);
1238 michael 4054 snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstMORS");
1239 michael 3421 add_isupport("CHANNELLEN", NULL, CHANNELLEN);
1240 michael 4340 add_isupport("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1241 adx 30 add_isupport("CHANMODES", chanmodes, -1);
1242    
1243     /*
1244     * message_locale may have changed. rebuild isupport since it relies
1245     * on strlen(form_str(RPL_ISUPPORT))
1246     */
1247     rebuild_isupport_message_line();
1248     }
1249    
1250     /* clear_out_old_conf()
1251     *
1252     * inputs - none
1253     * output - none
1254     * side effects - Clear out the old configuration
1255     */
1256     static void
1257     clear_out_old_conf(void)
1258     {
1259     dlink_node *ptr = NULL, *next_ptr = NULL;
1260 michael 1632 struct MaskItem *conf;
1261 adx 30 dlink_list *free_items [] = {
1262 michael 1383 &server_items, &oconf_items,
1263 michael 1921 &uconf_items, &xconf_items,
1264 michael 2174 &nresv_items, &cluster_items, &service_items, &cresv_items, NULL
1265 adx 30 };
1266    
1267     dlink_list ** iterator = free_items; /* C is dumb */
1268    
1269     /* We only need to free anything allocated by yyparse() here.
1270     * Resetting structs, etc, is taken care of by set_default_conf().
1271     */
1272 michael 2916
1273 adx 30 for (; *iterator != NULL; iterator++)
1274     {
1275     DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1276     {
1277     conf = ptr->data;
1278 michael 1632
1279     dlinkDelete(&conf->node, map_to_list(conf->type));
1280    
1281 adx 30 /* XXX This is less than pretty */
1282 michael 1632 if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
1283 adx 30 {
1284 michael 1644 if (!conf->ref_count)
1285 michael 2182 conf_free(conf);
1286 adx 30 }
1287 michael 1921 else if (conf->type == CONF_XLINE)
1288 adx 30 {
1289 michael 1649 if (!conf->until)
1290 michael 1632 conf_free(conf);
1291 adx 30 }
1292     else
1293 michael 1632 conf_free(conf);
1294 adx 30 }
1295     }
1296    
1297 michael 2150 motd_clear();
1298    
1299 michael 671 /*
1300     * don't delete the class table, rather mark all entries
1301 michael 1632 * for deletion. The table is cleaned up by class_delete_marked. - avalon
1302 adx 30 */
1303 michael 1632 class_mark_for_deletion();
1304 michael 671
1305 adx 30 clear_out_address_conf();
1306    
1307     /* clean out module paths */
1308     mod_clear_paths();
1309    
1310 michael 4340 /* clean out ConfigServerInfo */
1311     MyFree(ConfigServerInfo.description);
1312     ConfigServerInfo.description = NULL;
1313     MyFree(ConfigServerInfo.network_name);
1314     ConfigServerInfo.network_name = NULL;
1315     MyFree(ConfigServerInfo.network_desc);
1316     ConfigServerInfo.network_desc = NULL;
1317 adx 30 #ifdef HAVE_LIBCRYPTO
1318 michael 4340 if (ConfigServerInfo.rsa_private_key)
1319 adx 30 {
1320 michael 4340 RSA_free(ConfigServerInfo.rsa_private_key);
1321     ConfigServerInfo.rsa_private_key = NULL;
1322 adx 30 }
1323    
1324 michael 4340 MyFree(ConfigServerInfo.rsa_private_key_file);
1325     ConfigServerInfo.rsa_private_key_file = NULL;
1326 adx 30 #endif
1327    
1328 michael 4340 /* clean out ConfigAdminInfo */
1329     MyFree(ConfigAdminInfo.name);
1330     ConfigAdminInfo.name = NULL;
1331     MyFree(ConfigAdminInfo.email);
1332     ConfigAdminInfo.email = NULL;
1333     MyFree(ConfigAdminInfo.description);
1334     ConfigAdminInfo.description = NULL;
1335 adx 30
1336     /* clean out listeners */
1337     close_listeners();
1338    
1339     /* clean out general */
1340 michael 4340 MyFree(ConfigGeneral.service_name);
1341     ConfigGeneral.service_name = NULL;
1342 adx 30 }
1343    
1344     /* conf_add_class_to_conf()
1345     *
1346     * inputs - pointer to config item
1347     * output - NONE
1348 michael 2916 * side effects - Add a class pointer to a conf
1349 adx 30 */
1350     void
1351 michael 1632 conf_add_class_to_conf(struct MaskItem *conf, const char *class_name)
1352 adx 30 {
1353 michael 2916 if (class_name == NULL)
1354 adx 30 {
1355 michael 1632 conf->class = class_default;
1356 michael 671
1357 michael 1632 if (conf->type == CONF_CLIENT)
1358 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1359 michael 2182 "Warning *** Defaulting to default class for %s@%s",
1360     conf->user, conf->host);
1361 adx 30 else
1362 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1363 michael 2182 "Warning *** Defaulting to default class for %s",
1364     conf->name);
1365 adx 30 }
1366     else
1367 michael 1632 conf->class = class_find(class_name, 1);
1368 adx 30
1369 michael 1632 if (conf->class == NULL)
1370 adx 30 {
1371 michael 1632 if (conf->type == CONF_CLIENT)
1372 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1373 michael 2182 "Warning *** Defaulting to default class for %s@%s",
1374     conf->user, conf->host);
1375 adx 30 else
1376 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1377 michael 2182 "Warning *** Defaulting to default class for %s",
1378     conf->name);
1379 michael 1632 conf->class = class_default;
1380 adx 30 }
1381     }
1382    
1383     /* yyerror()
1384     *
1385     * inputs - message from parser
1386     * output - NONE
1387     * side effects - message to opers and log file entry is made
1388     */
1389     void
1390     yyerror(const char *msg)
1391     {
1392     char newlinebuf[IRCD_BUFSIZE];
1393    
1394 michael 967 if (conf_parser_ctx.pass != 1)
1395 adx 30 return;
1396    
1397     strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1398 michael 1751 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1399 michael 1618 "\"%s\", line %u: %s: %s",
1400 adx 30 conffilebuf, lineno + 1, msg, newlinebuf);
1401 michael 1247 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1402 adx 30 conffilebuf, lineno + 1, msg, newlinebuf);
1403     }
1404    
1405 michael 1751 void
1406     conf_error_report(const char *msg)
1407     {
1408     char newlinebuf[IRCD_BUFSIZE];
1409    
1410     strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1411     sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1412     "\"%s\", line %u: %s: %s",
1413     conffilebuf, lineno + 1, msg, newlinebuf);
1414     ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1415     conffilebuf, lineno + 1, msg, newlinebuf);
1416     }
1417    
1418 adx 30 /*
1419     * valid_tkline()
1420 michael 2916 *
1421 adx 30 * inputs - pointer to ascii string to check
1422     * - whether the specified time is in seconds or minutes
1423     * output - -1 not enough parameters
1424     * - 0 if not an integer number, else the number
1425     * side effects - none
1426     * Originally written by Dianora (Diane, db@db.net)
1427     */
1428     time_t
1429 michael 2313 valid_tkline(const char *data, const int minutes)
1430 adx 30 {
1431 michael 2313 const unsigned char *p = (const unsigned char *)data;
1432     unsigned char tmpch = '\0';
1433 adx 30 time_t result = 0;
1434    
1435 michael 2313 while ((tmpch = *p++))
1436 adx 30 {
1437 michael 2313 if (!IsDigit(tmpch))
1438 michael 1121 return 0;
1439 michael 1120
1440     result *= 10;
1441 michael 2313 result += (tmpch & 0xF);
1442 adx 30 }
1443    
1444 michael 1120 /*
1445 michael 2916 * In the degenerate case where oper does a /quote kline 0 user@host :reason
1446 adx 30 * i.e. they specifically use 0, I am going to return 1 instead
1447     * as a return value of non-zero is used to flag it as a temporary kline
1448     */
1449     if (result == 0)
1450     result = 1;
1451    
1452 michael 2916 /*
1453 adx 30 * If the incoming time is in seconds convert it to minutes for the purpose
1454     * of this calculation
1455     */
1456     if (!minutes)
1457 michael 2916 result = result / 60;
1458 adx 30
1459     if (result > MAX_TDKLINE_TIME)
1460     result = MAX_TDKLINE_TIME;
1461    
1462 michael 2313 result = result * 60; /* turn it into seconds */
1463 adx 30
1464     return result;
1465     }
1466    
1467 michael 2130 /* valid_wild_card_simple()
1468     *
1469     * inputs - data to check for sufficient non-wildcard characters
1470     * outputs - 1 if valid, else 0
1471     * side effects - none
1472     */
1473     int
1474     valid_wild_card_simple(const char *data)
1475     {
1476     const unsigned char *p = (const unsigned char *)data;
1477     unsigned char tmpch = '\0';
1478 michael 3870 unsigned int nonwild = 0;
1479 michael 2130
1480     while ((tmpch = *p++))
1481     {
1482 michael 4265 if (tmpch == '\\' && *p)
1483 michael 2130 {
1484     ++p;
1485 michael 4340 if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1486 michael 2130 return 1;
1487     }
1488     else if (!IsMWildChar(tmpch))
1489     {
1490 michael 4340 if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1491 michael 2130 return 1;
1492     }
1493     }
1494    
1495     return 0;
1496     }
1497    
1498 adx 30 /* valid_wild_card()
1499     *
1500     * input - pointer to client
1501     * - int flag, 0 for no warning oper 1 for warning oper
1502     * - count of following varargs to check
1503     * output - 0 if not valid, 1 if valid
1504     * side effects - NOTICE is given to source_p if warn is 1
1505     */
1506     int
1507     valid_wild_card(struct Client *source_p, int warn, int count, ...)
1508     {
1509 michael 3931 unsigned char tmpch = '\0';
1510 michael 3870 unsigned int nonwild = 0;
1511 adx 30 va_list args;
1512    
1513     /*
1514     * Now we must check the user and host to make sure there
1515     * are at least NONWILDCHARS non-wildcard characters in
1516     * them, otherwise assume they are attempting to kline
1517     * *@* or some variant of that. This code will also catch
1518     * people attempting to kline *@*.tld, as long as NONWILDCHARS
1519     * is greater than 3. In that case, there are only 3 non-wild
1520     * characters (tld), so if NONWILDCHARS is 4, the kline will
1521     * be disallowed.
1522     * -wnder
1523     */
1524    
1525     va_start(args, count);
1526    
1527     while (count--)
1528     {
1529 michael 3931 const unsigned char *p = va_arg(args, const unsigned char *);
1530 adx 30 if (p == NULL)
1531     continue;
1532    
1533     while ((tmpch = *p++))
1534     {
1535     if (!IsKWildChar(tmpch))
1536     {
1537     /*
1538     * If we find enough non-wild characters, we can
1539     * break - no point in searching further.
1540     */
1541 michael 4340 if (++nonwild >= ConfigGeneral.min_nonwildcard)
1542 michael 2659 {
1543     va_end(args);
1544 adx 30 return 1;
1545 michael 2659 }
1546 adx 30 }
1547     }
1548     }
1549    
1550     if (warn)
1551 michael 3110 sendto_one_notice(source_p, &me,
1552 michael 4058 ":Please include at least %u non-wildcard characters with the mask",
1553 michael 4340 ConfigGeneral.min_nonwildcard);
1554 michael 2659 va_end(args);
1555 adx 30 return 0;
1556     }
1557    
1558     /* XXX should this go into a separate file ? -Dianora */
1559     /* parse_aline
1560     *
1561     * input - pointer to cmd name being used
1562     * - pointer to client using cmd
1563     * - parc parameter count
1564     * - parv[] list of parameters to parse
1565     * - parse_flags bit map of things to test
1566     * - pointer to user or string to parse into
1567     * - pointer to host or NULL to parse into if non NULL
1568 michael 2916 * - pointer to optional tkline time or NULL
1569 adx 30 * - pointer to target_server to parse into if non NULL
1570     * - pointer to reason to parse into
1571     *
1572     * output - 1 if valid, -1 if not valid
1573     * side effects - A generalised k/d/x etc. line parser,
1574     * "ALINE [time] user@host|string [ON] target :reason"
1575     * will parse returning a parsed user, host if
1576     * h_p pointer is non NULL, string otherwise.
1577     * if tkline_time pointer is non NULL a tk line will be set
1578     * to non zero if found.
1579     * if tkline_time pointer is NULL and tk line is found,
1580     * error is reported.
1581     * if target_server is NULL and an "ON" is found error
1582     * is reported.
1583     * if reason pointer is NULL ignore pointer,
1584 db 936 * this allows use of parse_a_line in unkline etc.
1585 adx 30 *
1586     * - Dianora
1587     */
1588     int
1589     parse_aline(const char *cmd, struct Client *source_p,
1590 michael 2182 int parc, char **parv,
1591     int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1592     char **target_server, char **reason)
1593 adx 30 {
1594     int found_tkline_time=0;
1595 michael 3499 static char def_reason[] = CONF_NOREASON;
1596 adx 30 static char user[USERLEN*4+1];
1597     static char host[HOSTLEN*4+1];
1598    
1599     parv++;
1600     parc--;
1601    
1602     found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1603    
1604     if (found_tkline_time != 0)
1605     {
1606     parv++;
1607     parc--;
1608    
1609     if (tkline_time != NULL)
1610     *tkline_time = found_tkline_time;
1611     else
1612     {
1613 michael 3110 sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1614 adx 30 return -1;
1615     }
1616     }
1617    
1618     if (parc == 0)
1619     {
1620 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1621 adx 30 return -1;
1622     }
1623    
1624     if (h_p == NULL)
1625     *up_p = *parv;
1626     else
1627     {
1628     if (find_user_host(source_p, *parv, user, host, parse_flags) == 0)
1629     return -1;
1630    
1631     *up_p = user;
1632     *h_p = host;
1633     }
1634 michael 2916
1635 adx 30 parc--;
1636     parv++;
1637    
1638     if (parc != 0)
1639     {
1640     if (irccmp(*parv, "ON") == 0)
1641     {
1642     parc--;
1643     parv++;
1644    
1645     if (target_server == NULL)
1646     {
1647 michael 3110 sendto_one_notice(source_p, &me, ":ON server not supported by %s", cmd);
1648 michael 2182 return -1;
1649 adx 30 }
1650    
1651 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1652 adx 30 {
1653 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1654 adx 30 return -1;
1655     }
1656    
1657     if (parc == 0 || EmptyString(*parv))
1658     {
1659 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1660 michael 2182 return -1;
1661 adx 30 }
1662    
1663     *target_server = *parv;
1664     parc--;
1665     parv++;
1666     }
1667     else
1668     {
1669     /* Make sure target_server *is* NULL if no ON server found
1670     * caller probably NULL'd it first, but no harm to do it again -db
1671     */
1672     if (target_server != NULL)
1673 michael 2182 *target_server = NULL;
1674 adx 30 }
1675     }
1676    
1677     if (h_p != NULL)
1678     {
1679     if (strchr(user, '!') != NULL)
1680     {
1681 michael 3110 sendto_one_notice(source_p, &me, ":Invalid character '!' in kline");
1682 adx 30 return -1;
1683     }
1684    
1685 michael 1243 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
1686 adx 30 return -1;
1687     }
1688     else
1689 michael 1243 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
1690 adx 30 return -1;
1691    
1692     if (reason != NULL)
1693     {
1694 michael 867 if (parc != 0 && !EmptyString(*parv))
1695 adx 30 {
1696     *reason = *parv;
1697 michael 1243 if (!valid_comment(source_p, *reason, 1))
1698 michael 2182 return -1;
1699 adx 30 }
1700     else
1701     *reason = def_reason;
1702     }
1703    
1704     return 1;
1705     }
1706    
1707     /* find_user_host()
1708     *
1709     * inputs - pointer to client placing kline
1710     * - pointer to user_host_or_nick
1711     * - pointer to user buffer
1712     * - pointer to host buffer
1713     * output - 0 if not ok to kline, 1 to kline i.e. if valid user host
1714     * side effects -
1715     */
1716     static int
1717     find_user_host(struct Client *source_p, char *user_host_or_nick,
1718     char *luser, char *lhost, unsigned int flags)
1719     {
1720     struct Client *target_p = NULL;
1721     char *hostp = NULL;
1722    
1723     if (lhost == NULL)
1724     {
1725     strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1726     return 1;
1727     }
1728    
1729     if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1730     {
1731     /* Explicit user@host mask given */
1732    
1733 michael 593 if (hostp != NULL) /* I'm a little user@host */
1734 adx 30 {
1735     *(hostp++) = '\0'; /* short and squat */
1736     if (*user_host_or_nick)
1737 michael 2182 strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1738 adx 30 else
1739 michael 2182 strcpy(luser, "*");
1740    
1741 adx 30 if (*hostp)
1742 michael 2182 strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */
1743 adx 30 else
1744 michael 2182 strcpy(lhost, "*");
1745 adx 30 }
1746     else
1747     {
1748     luser[0] = '*'; /* no @ found, assume its *@somehost */
1749 michael 2182 luser[1] = '\0';
1750 adx 30 strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1751     }
1752 michael 2916
1753 adx 30 return 1;
1754     }
1755 michael 1518 else
1756 adx 30 {
1757     /* Try to find user@host mask from nick */
1758     /* Okay to use source_p as the first param, because source_p == client_p */
1759 michael 2916 if ((target_p =
1760 michael 3192 find_chasing(source_p, user_host_or_nick)) == NULL)
1761 michael 3737 return 0; /* find_chasing sends ERR_NOSUCHNICK */
1762 adx 30
1763     if (IsExemptKline(target_p))
1764     {
1765     if (!IsServer(source_p))
1766 michael 3110 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1767 adx 30 return 0;
1768     }
1769    
1770     /*
1771     * turn the "user" bit into "*user", blow away '~'
1772     * if found in original user name (non-idented)
1773     */
1774     strlcpy(luser, target_p->username, USERLEN*4 + 1);
1775    
1776     if (target_p->username[0] == '~')
1777     luser[0] = '*';
1778    
1779     if (target_p->sockhost[0] == '\0' ||
1780     (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
1781     strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
1782     else
1783     strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1784     return 1;
1785     }
1786    
1787     return 0;
1788     }
1789    
1790     /* valid_comment()
1791     *
1792     * inputs - pointer to client
1793     * - pointer to comment
1794     * output - 0 if no valid comment,
1795     * - 1 if valid
1796     * side effects - truncates reason where necessary
1797     */
1798     int
1799     valid_comment(struct Client *source_p, char *comment, int warn)
1800     {
1801     if (strlen(comment) > REASONLEN)
1802     comment[REASONLEN-1] = '\0';
1803    
1804     return 1;
1805     }
1806    
1807     /* match_conf_password()
1808     *
1809     * inputs - pointer to given password
1810     * - pointer to Conf
1811     * output - 1 or 0 if match
1812     * side effects - none
1813     */
1814     int
1815 michael 1632 match_conf_password(const char *password, const struct MaskItem *conf)
1816 adx 30 {
1817     const char *encr = NULL;
1818    
1819 michael 1632 if (EmptyString(password) || EmptyString(conf->passwd))
1820 adx 30 return 0;
1821    
1822 michael 1632 if (conf->flags & CONF_FLAGS_ENCRYPTED)
1823     encr = crypt(password, conf->passwd);
1824 adx 30 else
1825     encr = password;
1826    
1827 michael 3263 return encr && !strcmp(encr, conf->passwd);
1828 adx 30 }
1829    
1830     /*
1831     * cluster_a_line
1832     *
1833     * inputs - client sending the cluster
1834     * - command name "KLINE" "XLINE" etc.
1835 michael 3347 * - capab -- CAP_KLN etc. from server.h
1836 michael 1309 * - cluster type -- CLUSTER_KLINE etc. from conf.h
1837 adx 30 * - pattern and args to send along
1838     * output - none
1839     * side effects - Take source_p send the pattern with args given
1840     * along to all servers that match capab and cluster type
1841     */
1842     void
1843     cluster_a_line(struct Client *source_p, const char *command,
1844 michael 593 int capab, int cluster_type, const char *pattern, ...)
1845 adx 30 {
1846     va_list args;
1847 michael 3375 char buffer[IRCD_BUFSIZE] = "";
1848 michael 593 const dlink_node *ptr = NULL;
1849 adx 30
1850     va_start(args, pattern);
1851     vsnprintf(buffer, sizeof(buffer), pattern, args);
1852     va_end(args);
1853    
1854     DLINK_FOREACH(ptr, cluster_items.head)
1855     {
1856 michael 1632 const struct MaskItem *conf = ptr->data;
1857 adx 30
1858     if (conf->flags & cluster_type)
1859     sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
1860 michael 2182 "%s %s %s", command, conf->name, buffer);
1861 adx 30 }
1862     }
1863    
1864     /*
1865     * split_nuh
1866     *
1867     * inputs - pointer to original mask (modified in place)
1868     * - pointer to pointer where nick should go
1869     * - pointer to pointer where user should go
1870     * - pointer to pointer where host should go
1871     * output - NONE
1872     * side effects - mask is modified in place
1873     * If nick pointer is NULL, ignore writing to it
1874     * this allows us to use this function elsewhere.
1875     *
1876     * mask nick user host
1877     * ---------------------- ------- ------- ------
1878     * Dianora!db@db.net Dianora db db.net
1879     * Dianora Dianora * *
1880     * db.net * * db.net
1881     * OR if nick pointer is NULL
1882     * Dianora - * Dianora
1883     * Dianora! Dianora * *
1884     * Dianora!@ Dianora * *
1885     * Dianora!db Dianora db *
1886     * Dianora!@db.net Dianora * db.net
1887     * db@db.net * db db.net
1888     * !@ * * *
1889     * @ * * *
1890     * ! * * *
1891     */
1892     void
1893 michael 593 split_nuh(struct split_nuh_item *const iptr)
1894 adx 30 {
1895     char *p = NULL, *q = NULL;
1896    
1897 michael 593 if (iptr->nickptr)
1898     strlcpy(iptr->nickptr, "*", iptr->nicksize);
1899     if (iptr->userptr)
1900     strlcpy(iptr->userptr, "*", iptr->usersize);
1901     if (iptr->hostptr)
1902     strlcpy(iptr->hostptr, "*", iptr->hostsize);
1903    
1904     if ((p = strchr(iptr->nuhmask, '!')))
1905 adx 30 {
1906     *p = '\0';
1907    
1908 michael 3375 if (iptr->nickptr && *iptr->nuhmask)
1909 michael 593 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1910 adx 30
1911 michael 2525 if ((q = strchr(++p, '@')))
1912     {
1913 michael 593 *q++ = '\0';
1914    
1915 michael 3375 if (*p)
1916 michael 593 strlcpy(iptr->userptr, p, iptr->usersize);
1917 adx 30
1918 michael 3375 if (*q)
1919 michael 593 strlcpy(iptr->hostptr, q, iptr->hostsize);
1920 adx 30 }
1921     else
1922     {
1923 michael 3375 if (*p)
1924 michael 593 strlcpy(iptr->userptr, p, iptr->usersize);
1925 adx 30 }
1926     }
1927 michael 593 else
1928 adx 30 {
1929 michael 593 /* No ! found so lets look for a user@host */
1930     if ((p = strchr(iptr->nuhmask, '@')))
1931 adx 30 {
1932 michael 593 /* if found a @ */
1933     *p++ = '\0';
1934 adx 30
1935 michael 3375 if (*iptr->nuhmask)
1936 michael 593 strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
1937 adx 30
1938 michael 3375 if (*p)
1939 michael 593 strlcpy(iptr->hostptr, p, iptr->hostsize);
1940 adx 30 }
1941 michael 593 else
1942 adx 30 {
1943 michael 593 /* no @ found */
1944     if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
1945     strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
1946 adx 30 else
1947 michael 593 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1948 adx 30 }
1949     }
1950     }

Properties

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