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