ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 4496
Committed: Sat Aug 16 18:13:37 2014 UTC (11 years ago) by michael
Content type: text/x-csrc
File size: 52192 byte(s)
Log Message:
- conf.c:set_default_conf(): really default to secp256r1

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

Properties

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