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