25 |
|
#include "stdinc.h" |
26 |
|
#include "list.h" |
27 |
|
#include "ircd_defs.h" |
28 |
– |
#include "balloc.h" |
28 |
|
#include "conf.h" |
29 |
|
#include "s_serv.h" |
30 |
|
#include "resv.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 |
|
|
55 |
– |
struct Callback *client_check_cb = NULL; |
57 |
|
struct config_server_hide ConfigServerHide; |
58 |
|
|
59 |
|
/* general conf items link list root, other than k lines etc. */ |
63 |
|
dlink_list oconf_items = { NULL, NULL, 0 }; |
64 |
|
dlink_list uconf_items = { NULL, NULL, 0 }; |
65 |
|
dlink_list xconf_items = { NULL, NULL, 0 }; |
65 |
– |
dlink_list rxconf_items = { NULL, NULL, 0 }; |
66 |
– |
dlink_list rkconf_items = { NULL, NULL, 0 }; |
66 |
|
dlink_list nresv_items = { NULL, NULL, 0 }; |
68 |
– |
dlink_list class_items = { NULL, NULL, 0 }; |
69 |
– |
|
70 |
– |
dlink_list temporary_xlines = { NULL, NULL, 0 }; |
67 |
|
dlink_list temporary_resv = { NULL, NULL, 0 }; |
68 |
|
|
69 |
|
extern unsigned int lineno; |
76 |
|
/* internally defined functions */ |
77 |
|
static void read_conf(FILE *); |
78 |
|
static void clear_out_old_conf(void); |
83 |
– |
static void flush_deleted_I_P(void); |
79 |
|
static void expire_tklines(dlink_list *); |
80 |
|
static void garbage_collect_ip_entries(void); |
81 |
|
static int hash_ip(struct irc_ssaddr *); |
82 |
< |
static int verify_access(struct Client *, const char *); |
83 |
< |
static int attach_iline(struct Client *, struct ConfItem *); |
82 |
> |
static int verify_access(struct Client *); |
83 |
> |
static int attach_iline(struct Client *, struct MaskItem *); |
84 |
|
static struct ip_entry *find_or_add_ip(struct irc_ssaddr *); |
85 |
< |
static void parse_conf_file(int, int); |
91 |
< |
static dlink_list *map_to_list(ConfType); |
92 |
< |
static struct AccessItem *find_regexp_kline(const char *[]); |
85 |
> |
static dlink_list *map_to_list(enum maskitem_type); |
86 |
|
static int find_user_host(struct Client *, char *, char *, char *, unsigned int); |
87 |
|
|
95 |
– |
/* |
96 |
– |
* bit_len |
97 |
– |
*/ |
98 |
– |
static int cidr_limit_reached(int, struct irc_ssaddr *, struct ClassItem *); |
99 |
– |
static void remove_from_cidr_check(struct irc_ssaddr *, struct ClassItem *); |
100 |
– |
static void destroy_cidr_class(struct ClassItem *); |
101 |
– |
|
102 |
– |
static void flags_to_ascii(unsigned int, const unsigned int[], char *, int); |
103 |
– |
|
104 |
– |
/* address of default class conf */ |
105 |
– |
static struct ConfItem *class_default; |
88 |
|
|
89 |
|
/* usually, with hash tables, you use a prime number... |
90 |
|
* but in this case I am dealing with ip addresses, |
95 |
|
struct ip_entry |
96 |
|
{ |
97 |
|
struct irc_ssaddr ip; |
98 |
< |
int count; |
98 |
> |
unsigned int count; |
99 |
|
time_t last_attempt; |
100 |
|
struct ip_entry *next; |
101 |
|
}; |
102 |
|
|
103 |
|
static struct ip_entry *ip_hash_table[IP_HASH_SIZE]; |
104 |
< |
static BlockHeap *ip_entry_heap = NULL; |
104 |
> |
static mp_pool_t *ip_entry_pool = NULL; |
105 |
|
static int ip_entries_count = 0; |
106 |
|
|
107 |
|
|
126 |
– |
void * |
127 |
– |
map_to_conf(struct ConfItem *aconf) |
128 |
– |
{ |
129 |
– |
void *conf; |
130 |
– |
conf = (void *)((uintptr_t)aconf + |
131 |
– |
(uintptr_t)sizeof(struct ConfItem)); |
132 |
– |
return(conf); |
133 |
– |
} |
134 |
– |
|
135 |
– |
struct ConfItem * |
136 |
– |
unmap_conf_item(void *aconf) |
137 |
– |
{ |
138 |
– |
struct ConfItem *conf; |
139 |
– |
|
140 |
– |
conf = (struct ConfItem *)((uintptr_t)aconf - |
141 |
– |
(uintptr_t)sizeof(struct ConfItem)); |
142 |
– |
return(conf); |
143 |
– |
} |
144 |
– |
|
108 |
|
/* conf_dns_callback() |
109 |
|
* |
110 |
< |
* inputs - pointer to struct AccessItem |
110 |
> |
* inputs - pointer to struct MaskItem |
111 |
|
* - pointer to DNSReply reply |
112 |
|
* output - none |
113 |
|
* side effects - called when resolver query finishes |
118 |
|
static void |
119 |
|
conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name) |
120 |
|
{ |
121 |
< |
struct AccessItem *aconf = vptr; |
121 |
> |
struct MaskItem *conf = vptr; |
122 |
|
|
123 |
< |
aconf->dns_pending = 0; |
123 |
> |
conf->dns_pending = 0; |
124 |
|
|
125 |
|
if (addr != NULL) |
126 |
< |
memcpy(&aconf->addr, addr, sizeof(aconf->addr)); |
126 |
> |
memcpy(&conf->addr, addr, sizeof(conf->addr)); |
127 |
|
else |
128 |
< |
aconf->dns_failed = 1; |
128 |
> |
conf->dns_failed = 1; |
129 |
|
} |
130 |
|
|
131 |
|
/* conf_dns_lookup() |
135 |
|
* allocate a dns_query and start ns lookup. |
136 |
|
*/ |
137 |
|
static void |
138 |
< |
conf_dns_lookup(struct AccessItem *aconf) |
138 |
> |
conf_dns_lookup(struct MaskItem *conf) |
139 |
|
{ |
140 |
< |
if (!aconf->dns_pending) |
140 |
> |
if (!conf->dns_pending) |
141 |
|
{ |
142 |
< |
aconf->dns_pending = 1; |
143 |
< |
gethost_byname(conf_dns_callback, aconf, aconf->host); |
142 |
> |
conf->dns_pending = 1; |
143 |
> |
gethost_byname(conf_dns_callback, conf, conf->host); |
144 |
|
} |
145 |
|
} |
146 |
|
|
147 |
< |
/* make_conf_item() |
148 |
< |
* |
186 |
< |
* inputs - type of item |
187 |
< |
* output - pointer to new conf entry |
188 |
< |
* side effects - none |
189 |
< |
*/ |
190 |
< |
struct ConfItem * |
191 |
< |
make_conf_item(ConfType type) |
147 |
> |
struct MaskItem * |
148 |
> |
conf_make(enum maskitem_type type) |
149 |
|
{ |
150 |
< |
struct ConfItem *conf = NULL; |
151 |
< |
struct AccessItem *aconf = NULL; |
195 |
< |
struct ClassItem *aclass = NULL; |
196 |
< |
int status = 0; |
197 |
< |
|
198 |
< |
switch (type) |
199 |
< |
{ |
200 |
< |
case DLINE_TYPE: |
201 |
< |
case EXEMPTDLINE_TYPE: |
202 |
< |
case GLINE_TYPE: |
203 |
< |
case KLINE_TYPE: |
204 |
< |
case CLIENT_TYPE: |
205 |
< |
case OPER_TYPE: |
206 |
< |
case SERVER_TYPE: |
207 |
< |
conf = MyMalloc(sizeof(struct ConfItem) + |
208 |
< |
sizeof(struct AccessItem)); |
209 |
< |
aconf = map_to_conf(conf); |
210 |
< |
aconf->aftype = AF_INET; |
211 |
< |
|
212 |
< |
/* Yes, sigh. switch on type again */ |
213 |
< |
switch (type) |
214 |
< |
{ |
215 |
< |
case EXEMPTDLINE_TYPE: |
216 |
< |
status = CONF_EXEMPTDLINE; |
217 |
< |
break; |
218 |
< |
|
219 |
< |
case DLINE_TYPE: |
220 |
< |
status = CONF_DLINE; |
221 |
< |
break; |
222 |
< |
|
223 |
< |
case KLINE_TYPE: |
224 |
< |
status = CONF_KLINE; |
225 |
< |
break; |
226 |
< |
|
227 |
< |
case GLINE_TYPE: |
228 |
< |
status = CONF_GLINE; |
229 |
< |
break; |
230 |
< |
|
231 |
< |
case CLIENT_TYPE: |
232 |
< |
status = CONF_CLIENT; |
233 |
< |
break; |
234 |
< |
|
235 |
< |
case OPER_TYPE: |
236 |
< |
status = CONF_OPERATOR; |
237 |
< |
dlinkAdd(conf, &conf->node, &oconf_items); |
238 |
< |
break; |
239 |
< |
|
240 |
< |
case SERVER_TYPE: |
241 |
< |
status = CONF_SERVER; |
242 |
< |
dlinkAdd(conf, &conf->node, &server_items); |
243 |
< |
break; |
244 |
< |
|
245 |
< |
default: |
246 |
< |
break; |
247 |
< |
} |
248 |
< |
aconf->status = status; |
249 |
< |
break; |
250 |
< |
|
251 |
< |
case ULINE_TYPE: |
252 |
< |
conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) + |
253 |
< |
sizeof(struct MatchItem)); |
254 |
< |
dlinkAdd(conf, &conf->node, &uconf_items); |
255 |
< |
break; |
256 |
< |
|
257 |
< |
case XLINE_TYPE: |
258 |
< |
conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) + |
259 |
< |
sizeof(struct MatchItem)); |
260 |
< |
dlinkAdd(conf, &conf->node, &xconf_items); |
261 |
< |
break; |
262 |
< |
#ifdef HAVE_LIBPCRE |
263 |
< |
case RXLINE_TYPE: |
264 |
< |
conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) + |
265 |
< |
sizeof(struct MatchItem)); |
266 |
< |
dlinkAdd(conf, &conf->node, &rxconf_items); |
267 |
< |
break; |
268 |
< |
|
269 |
< |
case RKLINE_TYPE: |
270 |
< |
conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) + |
271 |
< |
sizeof(struct AccessItem)); |
272 |
< |
aconf = map_to_conf(conf); |
273 |
< |
aconf->status = CONF_KLINE; |
274 |
< |
dlinkAdd(conf, &conf->node, &rkconf_items); |
275 |
< |
break; |
276 |
< |
#endif |
277 |
< |
case CLUSTER_TYPE: |
278 |
< |
conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem)); |
279 |
< |
dlinkAdd(conf, &conf->node, &cluster_items); |
280 |
< |
break; |
281 |
< |
|
282 |
< |
case CRESV_TYPE: |
283 |
< |
conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) + |
284 |
< |
sizeof(struct ResvChannel)); |
285 |
< |
break; |
286 |
< |
|
287 |
< |
case NRESV_TYPE: |
288 |
< |
conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) + |
289 |
< |
sizeof(struct MatchItem)); |
290 |
< |
dlinkAdd(conf, &conf->node, &nresv_items); |
291 |
< |
break; |
292 |
< |
|
293 |
< |
case SERVICE_TYPE: |
294 |
< |
status = CONF_SERVICE; |
295 |
< |
conf = MyMalloc(sizeof(struct ConfItem)); |
296 |
< |
dlinkAdd(conf, &conf->node, &service_items); |
297 |
< |
break; |
298 |
< |
|
299 |
< |
case CLASS_TYPE: |
300 |
< |
conf = MyMalloc(sizeof(struct ConfItem) + |
301 |
< |
sizeof(struct ClassItem)); |
302 |
< |
dlinkAdd(conf, &conf->node, &class_items); |
303 |
< |
|
304 |
< |
aclass = map_to_conf(conf); |
305 |
< |
aclass->active = 1; |
306 |
< |
aclass->con_freq = DEFAULT_CONNECTFREQUENCY; |
307 |
< |
aclass->ping_freq = DEFAULT_PINGFREQUENCY; |
308 |
< |
aclass->max_total = MAXIMUM_LINKS_DEFAULT; |
309 |
< |
aclass->max_sendq = DEFAULT_SENDQ; |
310 |
< |
aclass->max_recvq = DEFAULT_RECVQ; |
311 |
< |
|
312 |
< |
break; |
313 |
< |
|
314 |
< |
default: |
315 |
< |
conf = NULL; |
316 |
< |
break; |
317 |
< |
} |
150 |
> |
struct MaskItem *conf = MyMalloc(sizeof(*conf)); |
151 |
> |
dlink_list *list = NULL; |
152 |
|
|
153 |
< |
/* XXX Yes, this will core if default is hit. I want it to for now - db */ |
154 |
< |
conf->type = type; |
153 |
> |
conf->type = type; |
154 |
> |
conf->active = 1; |
155 |
> |
conf->aftype = AF_INET; |
156 |
|
|
157 |
+ |
if ((list = map_to_list(type))) |
158 |
+ |
dlinkAdd(conf, &conf->node, list); |
159 |
|
return conf; |
160 |
|
} |
161 |
|
|
162 |
|
void |
163 |
< |
delete_conf_item(struct ConfItem *conf) |
163 |
> |
conf_free(struct MaskItem *conf) |
164 |
|
{ |
165 |
< |
dlink_node *m = NULL, *m_next = NULL; |
166 |
< |
struct MatchItem *match_item; |
167 |
< |
struct AccessItem *aconf; |
168 |
< |
ConfType type = conf->type; |
165 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
166 |
> |
dlink_list *list = NULL; |
167 |
> |
|
168 |
> |
if (conf->node.next) |
169 |
> |
if ((list = map_to_list(conf->type))) |
170 |
> |
dlinkDelete(&conf->node, list); |
171 |
|
|
172 |
|
MyFree(conf->name); |
334 |
– |
conf->name = NULL; |
173 |
|
|
174 |
< |
switch(type) |
175 |
< |
{ |
176 |
< |
case DLINE_TYPE: |
177 |
< |
case EXEMPTDLINE_TYPE: |
178 |
< |
case GLINE_TYPE: |
179 |
< |
case KLINE_TYPE: |
180 |
< |
case CLIENT_TYPE: |
181 |
< |
case OPER_TYPE: |
182 |
< |
case SERVER_TYPE: |
183 |
< |
aconf = map_to_conf(conf); |
184 |
< |
|
185 |
< |
if (aconf->dns_pending) |
186 |
< |
delete_resolver_queries(aconf); |
187 |
< |
if (aconf->passwd != NULL) |
350 |
< |
memset(aconf->passwd, 0, strlen(aconf->passwd)); |
351 |
< |
if (aconf->spasswd != NULL) |
352 |
< |
memset(aconf->spasswd, 0, strlen(aconf->spasswd)); |
353 |
< |
aconf->class_ptr = NULL; |
354 |
< |
|
355 |
< |
MyFree(aconf->passwd); |
356 |
< |
MyFree(aconf->spasswd); |
357 |
< |
MyFree(aconf->reason); |
358 |
< |
MyFree(aconf->oper_reason); |
359 |
< |
MyFree(aconf->user); |
360 |
< |
MyFree(aconf->host); |
174 |
> |
if (conf->dns_pending) |
175 |
> |
delete_resolver_queries(conf); |
176 |
> |
if (conf->passwd != NULL) |
177 |
> |
memset(conf->passwd, 0, strlen(conf->passwd)); |
178 |
> |
if (conf->spasswd != NULL) |
179 |
> |
memset(conf->spasswd, 0, strlen(conf->spasswd)); |
180 |
> |
|
181 |
> |
conf->class = NULL; |
182 |
> |
|
183 |
> |
MyFree(conf->passwd); |
184 |
> |
MyFree(conf->spasswd); |
185 |
> |
MyFree(conf->reason); |
186 |
> |
MyFree(conf->user); |
187 |
> |
MyFree(conf->host); |
188 |
|
#ifdef HAVE_LIBCRYPTO |
189 |
< |
MyFree(aconf->cipher_list); |
363 |
< |
|
364 |
< |
if (aconf->rsa_public_key) |
365 |
< |
RSA_free(aconf->rsa_public_key); |
366 |
< |
MyFree(aconf->rsa_public_key_file); |
367 |
< |
#endif |
368 |
< |
|
369 |
< |
/* Yes, sigh. switch on type again */ |
370 |
< |
switch(type) |
371 |
< |
{ |
372 |
< |
case EXEMPTDLINE_TYPE: |
373 |
< |
case DLINE_TYPE: |
374 |
< |
case GLINE_TYPE: |
375 |
< |
case KLINE_TYPE: |
376 |
< |
case CLIENT_TYPE: |
377 |
< |
MyFree(conf); |
378 |
< |
break; |
379 |
< |
|
380 |
< |
case OPER_TYPE: |
381 |
< |
aconf = map_to_conf(conf); |
382 |
< |
if (!IsConfIllegal(aconf)) |
383 |
< |
dlinkDelete(&conf->node, &oconf_items); |
384 |
< |
MyFree(conf); |
385 |
< |
break; |
386 |
< |
|
387 |
< |
case SERVER_TYPE: |
388 |
< |
aconf = map_to_conf(conf); |
389 |
< |
|
390 |
< |
DLINK_FOREACH_SAFE(m, m_next, aconf->hub_list.head) |
391 |
< |
{ |
392 |
< |
MyFree(m->data); |
393 |
< |
free_dlink_node(m); |
394 |
< |
} |
395 |
< |
|
396 |
< |
DLINK_FOREACH_SAFE(m, m_next, aconf->leaf_list.head) |
397 |
< |
{ |
398 |
< |
MyFree(m->data); |
399 |
< |
free_dlink_node(m); |
400 |
< |
} |
401 |
< |
|
402 |
< |
if (!IsConfIllegal(aconf)) |
403 |
< |
dlinkDelete(&conf->node, &server_items); |
404 |
< |
MyFree(conf); |
405 |
< |
break; |
406 |
< |
|
407 |
< |
default: |
408 |
< |
break; |
409 |
< |
} |
410 |
< |
break; |
411 |
< |
|
412 |
< |
case ULINE_TYPE: |
413 |
< |
match_item = map_to_conf(conf); |
414 |
< |
MyFree(match_item->user); |
415 |
< |
MyFree(match_item->host); |
416 |
< |
MyFree(match_item->reason); |
417 |
< |
MyFree(match_item->oper_reason); |
418 |
< |
dlinkDelete(&conf->node, &uconf_items); |
419 |
< |
MyFree(conf); |
420 |
< |
break; |
421 |
< |
|
422 |
< |
case XLINE_TYPE: |
423 |
< |
match_item = map_to_conf(conf); |
424 |
< |
MyFree(match_item->user); |
425 |
< |
MyFree(match_item->host); |
426 |
< |
MyFree(match_item->reason); |
427 |
< |
MyFree(match_item->oper_reason); |
428 |
< |
dlinkDelete(&conf->node, &xconf_items); |
429 |
< |
MyFree(conf); |
430 |
< |
break; |
431 |
< |
#ifdef HAVE_LIBPCRE |
432 |
< |
case RKLINE_TYPE: |
433 |
< |
aconf = map_to_conf(conf); |
434 |
< |
MyFree(aconf->regexuser); |
435 |
< |
MyFree(aconf->regexhost); |
436 |
< |
MyFree(aconf->user); |
437 |
< |
MyFree(aconf->host); |
438 |
< |
MyFree(aconf->reason); |
439 |
< |
MyFree(aconf->oper_reason); |
440 |
< |
dlinkDelete(&conf->node, &rkconf_items); |
441 |
< |
MyFree(conf); |
442 |
< |
break; |
189 |
> |
MyFree(conf->cipher_list); |
190 |
|
|
191 |
< |
case RXLINE_TYPE: |
192 |
< |
MyFree(conf->regexpname); |
446 |
< |
match_item = map_to_conf(conf); |
447 |
< |
MyFree(match_item->user); |
448 |
< |
MyFree(match_item->host); |
449 |
< |
MyFree(match_item->reason); |
450 |
< |
MyFree(match_item->oper_reason); |
451 |
< |
dlinkDelete(&conf->node, &rxconf_items); |
452 |
< |
MyFree(conf); |
453 |
< |
break; |
191 |
> |
if (conf->rsa_public_key) |
192 |
> |
RSA_free(conf->rsa_public_key); |
193 |
|
#endif |
194 |
< |
case NRESV_TYPE: |
195 |
< |
match_item = map_to_conf(conf); |
196 |
< |
MyFree(match_item->user); |
197 |
< |
MyFree(match_item->host); |
459 |
< |
MyFree(match_item->reason); |
460 |
< |
MyFree(match_item->oper_reason); |
461 |
< |
dlinkDelete(&conf->node, &nresv_items); |
462 |
< |
|
463 |
< |
if (conf->flags & CONF_FLAGS_TEMPORARY) |
464 |
< |
if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL) |
465 |
< |
free_dlink_node(m); |
466 |
< |
|
467 |
< |
MyFree(conf); |
468 |
< |
break; |
469 |
< |
|
470 |
< |
case CLUSTER_TYPE: |
471 |
< |
dlinkDelete(&conf->node, &cluster_items); |
472 |
< |
MyFree(conf); |
473 |
< |
break; |
474 |
< |
|
475 |
< |
case CRESV_TYPE: |
476 |
< |
if (conf->flags & CONF_FLAGS_TEMPORARY) |
477 |
< |
if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL) |
478 |
< |
free_dlink_node(m); |
479 |
< |
|
480 |
< |
MyFree(conf); |
481 |
< |
break; |
482 |
< |
|
483 |
< |
case CLASS_TYPE: |
484 |
< |
dlinkDelete(&conf->node, &class_items); |
485 |
< |
MyFree(conf); |
486 |
< |
break; |
487 |
< |
|
488 |
< |
case SERVICE_TYPE: |
489 |
< |
dlinkDelete(&conf->node, &service_items); |
490 |
< |
MyFree(conf); |
491 |
< |
break; |
492 |
< |
|
493 |
< |
default: |
494 |
< |
break; |
194 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head) |
195 |
> |
{ |
196 |
> |
MyFree(ptr->data); |
197 |
> |
free_dlink_node(ptr); |
198 |
|
} |
496 |
– |
} |
199 |
|
|
200 |
< |
/* free_access_item() |
499 |
< |
* |
500 |
< |
* inputs - pointer to conf to free |
501 |
< |
* output - none |
502 |
< |
* side effects - crucial password fields are zeroed, conf is freed |
503 |
< |
*/ |
504 |
< |
void |
505 |
< |
free_access_item(struct AccessItem *aconf) |
506 |
< |
{ |
507 |
< |
struct ConfItem *conf; |
508 |
< |
|
509 |
< |
if (aconf == NULL) |
510 |
< |
return; |
511 |
< |
conf = unmap_conf_item(aconf); |
512 |
< |
delete_conf_item(conf); |
513 |
< |
} |
514 |
< |
|
515 |
< |
static const unsigned int shared_bit_table[] = |
516 |
< |
{ 'K', 'k', 'U', 'X', 'x', 'Y', 'Q', 'q', 'R', 'L', 0}; |
517 |
< |
|
518 |
< |
/* report_confitem_types() |
519 |
< |
* |
520 |
< |
* inputs - pointer to client requesting confitem report |
521 |
< |
* - ConfType to report |
522 |
< |
* output - none |
523 |
< |
* side effects - |
524 |
< |
*/ |
525 |
< |
void |
526 |
< |
report_confitem_types(struct Client *source_p, ConfType type) |
527 |
< |
{ |
528 |
< |
dlink_node *ptr = NULL, *dptr = NULL; |
529 |
< |
struct ConfItem *conf = NULL; |
530 |
< |
struct AccessItem *aconf = NULL; |
531 |
< |
struct MatchItem *matchitem = NULL; |
532 |
< |
struct ClassItem *classitem = NULL; |
533 |
< |
char buf[12]; |
534 |
< |
char *p = NULL; |
535 |
< |
|
536 |
< |
switch (type) |
200 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head) |
201 |
|
{ |
202 |
< |
case XLINE_TYPE: |
203 |
< |
DLINK_FOREACH(ptr, xconf_items.head) |
204 |
< |
{ |
541 |
< |
conf = ptr->data; |
542 |
< |
matchitem = map_to_conf(conf); |
543 |
< |
|
544 |
< |
sendto_one(source_p, form_str(RPL_STATSXLINE), |
545 |
< |
me.name, source_p->name, |
546 |
< |
matchitem->hold ? "x": "X", matchitem->count, |
547 |
< |
conf->name, matchitem->reason); |
548 |
< |
} |
549 |
< |
break; |
550 |
< |
|
551 |
< |
#ifdef HAVE_LIBPCRE |
552 |
< |
case RXLINE_TYPE: |
553 |
< |
DLINK_FOREACH(ptr, rxconf_items.head) |
554 |
< |
{ |
555 |
< |
conf = ptr->data; |
556 |
< |
matchitem = map_to_conf(conf); |
557 |
< |
|
558 |
< |
sendto_one(source_p, form_str(RPL_STATSXLINE), |
559 |
< |
me.name, source_p->name, |
560 |
< |
"XR", matchitem->count, |
561 |
< |
conf->name, matchitem->reason); |
562 |
< |
} |
563 |
< |
break; |
564 |
< |
|
565 |
< |
case RKLINE_TYPE: |
566 |
< |
DLINK_FOREACH(ptr, rkconf_items.head) |
567 |
< |
{ |
568 |
< |
aconf = map_to_conf((conf = ptr->data)); |
569 |
< |
|
570 |
< |
sendto_one(source_p, form_str(RPL_STATSKLINE), me.name, |
571 |
< |
source_p->name, "KR", aconf->host, aconf->user, |
572 |
< |
aconf->reason, aconf->oper_reason ? aconf->oper_reason : ""); |
573 |
< |
} |
574 |
< |
break; |
575 |
< |
#endif |
576 |
< |
|
577 |
< |
case ULINE_TYPE: |
578 |
< |
DLINK_FOREACH(ptr, uconf_items.head) |
579 |
< |
{ |
580 |
< |
conf = ptr->data; |
581 |
< |
matchitem = map_to_conf(conf); |
582 |
< |
|
583 |
< |
p = buf; |
584 |
< |
|
585 |
< |
/* some of these are redundant for the sake of |
586 |
< |
* consistency with cluster{} flags |
587 |
< |
*/ |
588 |
< |
*p++ = 'c'; |
589 |
< |
flags_to_ascii(matchitem->action, shared_bit_table, p, 0); |
590 |
< |
|
591 |
< |
sendto_one(source_p, form_str(RPL_STATSULINE), |
592 |
< |
me.name, source_p->name, conf->name, |
593 |
< |
matchitem->user?matchitem->user: "*", |
594 |
< |
matchitem->host?matchitem->host: "*", buf); |
595 |
< |
} |
596 |
< |
|
597 |
< |
DLINK_FOREACH(ptr, cluster_items.head) |
598 |
< |
{ |
599 |
< |
conf = ptr->data; |
600 |
< |
|
601 |
< |
p = buf; |
602 |
< |
|
603 |
< |
*p++ = 'C'; |
604 |
< |
flags_to_ascii(conf->flags, shared_bit_table, p, 0); |
605 |
< |
|
606 |
< |
sendto_one(source_p, form_str(RPL_STATSULINE), |
607 |
< |
me.name, source_p->name, conf->name, |
608 |
< |
"*", "*", buf); |
609 |
< |
} |
610 |
< |
|
611 |
< |
break; |
612 |
< |
|
613 |
< |
case OPER_TYPE: |
614 |
< |
DLINK_FOREACH(ptr, oconf_items.head) |
615 |
< |
{ |
616 |
< |
conf = ptr->data; |
617 |
< |
aconf = map_to_conf(conf); |
618 |
< |
|
619 |
< |
/* Don't allow non opers to see oper privs */ |
620 |
< |
if (HasUMode(source_p, UMODE_OPER)) |
621 |
< |
sendto_one(source_p, form_str(RPL_STATSOLINE), |
622 |
< |
me.name, source_p->name, 'O', aconf->user, aconf->host, |
623 |
< |
conf->name, oper_privs_as_string(aconf->port), |
624 |
< |
aconf->class_ptr ? aconf->class_ptr->name : "<default>"); |
625 |
< |
else |
626 |
< |
sendto_one(source_p, form_str(RPL_STATSOLINE), |
627 |
< |
me.name, source_p->name, 'O', aconf->user, aconf->host, |
628 |
< |
conf->name, "0", |
629 |
< |
aconf->class_ptr ? aconf->class_ptr->name : "<default>"); |
630 |
< |
} |
631 |
< |
break; |
632 |
< |
|
633 |
< |
case CLASS_TYPE: |
634 |
< |
DLINK_FOREACH(ptr, class_items.head) |
635 |
< |
{ |
636 |
< |
conf = ptr->data; |
637 |
< |
classitem = map_to_conf(conf); |
638 |
< |
sendto_one(source_p, form_str(RPL_STATSYLINE), |
639 |
< |
me.name, source_p->name, 'Y', |
640 |
< |
conf->name, classitem->ping_freq, |
641 |
< |
classitem->con_freq, |
642 |
< |
classitem->max_total, classitem->max_sendq, |
643 |
< |
classitem->max_recvq, |
644 |
< |
classitem->curr_user_count, |
645 |
< |
classitem->number_per_cidr, classitem->cidr_bitlen_ipv4, |
646 |
< |
classitem->number_per_cidr, classitem->cidr_bitlen_ipv6, |
647 |
< |
classitem->active ? "active" : "disabled"); |
648 |
< |
} |
649 |
< |
break; |
650 |
< |
|
651 |
< |
case CONF_TYPE: |
652 |
< |
case CLIENT_TYPE: |
653 |
< |
break; |
654 |
< |
|
655 |
< |
case SERVICE_TYPE: |
656 |
< |
DLINK_FOREACH(ptr, service_items.head) |
657 |
< |
{ |
658 |
< |
conf = ptr->data; |
659 |
< |
sendto_one(source_p, form_str(RPL_STATSSERVICE), |
660 |
< |
me.name, source_p->name, 'S', "*", conf->name, 0, 0); |
661 |
< |
} |
662 |
< |
break; |
663 |
< |
|
664 |
< |
case SERVER_TYPE: |
665 |
< |
DLINK_FOREACH(ptr, server_items.head) |
666 |
< |
{ |
667 |
< |
p = buf; |
668 |
< |
|
669 |
< |
conf = ptr->data; |
670 |
< |
aconf = map_to_conf(conf); |
671 |
< |
|
672 |
< |
buf[0] = '\0'; |
673 |
< |
|
674 |
< |
if (IsConfAllowAutoConn(aconf)) |
675 |
< |
*p++ = 'A'; |
676 |
< |
if (IsConfSSL(aconf)) |
677 |
< |
*p++ = 'S'; |
678 |
< |
if (buf[0] == '\0') |
679 |
< |
*p++ = '*'; |
680 |
< |
|
681 |
< |
*p = '\0'; |
682 |
< |
|
683 |
< |
/* |
684 |
< |
* Allow admins to see actual ips unless hide_server_ips is enabled |
685 |
< |
*/ |
686 |
< |
if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN)) |
687 |
< |
sendto_one(source_p, form_str(RPL_STATSCLINE), |
688 |
< |
me.name, source_p->name, 'C', aconf->host, |
689 |
< |
buf, conf->name, aconf->port, |
690 |
< |
aconf->class_ptr ? aconf->class_ptr->name : "<default>"); |
691 |
< |
else |
692 |
< |
sendto_one(source_p, form_str(RPL_STATSCLINE), |
693 |
< |
me.name, source_p->name, 'C', |
694 |
< |
"*@127.0.0.1", buf, conf->name, aconf->port, |
695 |
< |
aconf->class_ptr ? aconf->class_ptr->name : "<default>"); |
696 |
< |
} |
697 |
< |
break; |
698 |
< |
|
699 |
< |
case HUB_TYPE: |
700 |
< |
DLINK_FOREACH(ptr, server_items.head) |
701 |
< |
{ |
702 |
< |
conf = ptr->data; |
703 |
< |
aconf = map_to_conf(conf); |
704 |
< |
|
705 |
< |
DLINK_FOREACH(dptr, aconf->hub_list.head) |
706 |
< |
sendto_one(source_p, form_str(RPL_STATSHLINE), me.name, |
707 |
< |
source_p->name, 'H', dptr->data, conf->name, 0, "*"); |
708 |
< |
} |
709 |
< |
break; |
710 |
< |
|
711 |
< |
case LEAF_TYPE: |
712 |
< |
DLINK_FOREACH(ptr, server_items.head) |
713 |
< |
{ |
714 |
< |
conf = ptr->data; |
715 |
< |
aconf = map_to_conf(conf); |
202 |
> |
MyFree(ptr->data); |
203 |
> |
free_dlink_node(ptr); |
204 |
> |
} |
205 |
|
|
206 |
< |
DLINK_FOREACH(dptr, aconf->leaf_list.head) |
207 |
< |
sendto_one(source_p, form_str(RPL_STATSLLINE), me.name, |
208 |
< |
source_p->name, 'L', dptr->data, conf->name, 0, "*"); |
720 |
< |
} |
721 |
< |
break; |
206 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, conf->exempt_list.head) |
207 |
> |
{ |
208 |
> |
struct exempt *exptr = ptr->data; |
209 |
|
|
210 |
< |
case GLINE_TYPE: |
211 |
< |
case KLINE_TYPE: |
212 |
< |
case DLINE_TYPE: |
213 |
< |
case EXEMPTDLINE_TYPE: |
727 |
< |
case CRESV_TYPE: |
728 |
< |
case NRESV_TYPE: |
729 |
< |
case CLUSTER_TYPE: |
730 |
< |
default: |
731 |
< |
break; |
210 |
> |
MyFree(exptr->name); |
211 |
> |
MyFree(exptr->user); |
212 |
> |
MyFree(exptr->host); |
213 |
> |
MyFree(exptr); |
214 |
|
} |
215 |
+ |
|
216 |
+ |
MyFree(conf); |
217 |
|
} |
218 |
|
|
219 |
|
/* check_client() |
229 |
|
* Look for conf lines which have the same |
230 |
|
* status as the flags passed. |
231 |
|
*/ |
232 |
< |
static void * |
233 |
< |
check_client(va_list args) |
232 |
> |
int |
233 |
> |
check_client(struct Client *source_p) |
234 |
|
{ |
751 |
– |
struct Client *source_p = va_arg(args, struct Client *); |
752 |
– |
const char *username = va_arg(args, const char *); |
235 |
|
int i; |
236 |
|
|
237 |
< |
/* I'm already in big trouble if source_p->localClient is NULL -db */ |
756 |
< |
if ((i = verify_access(source_p, username))) |
237 |
> |
if ((i = verify_access(source_p))) |
238 |
|
ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]", |
239 |
|
source_p->name, source_p->sockhost); |
240 |
|
|
292 |
|
break; |
293 |
|
} |
294 |
|
|
295 |
< |
return (i < 0 ? NULL : source_p); |
295 |
> |
return (i < 0 ? 0 : 1); |
296 |
|
} |
297 |
|
|
298 |
|
/* verify_access() |
299 |
|
* |
300 |
|
* inputs - pointer to client to verify |
820 |
– |
* - pointer to proposed username |
301 |
|
* output - 0 if success -'ve if not |
302 |
|
* side effect - find the first (best) I line to attach. |
303 |
|
*/ |
304 |
|
static int |
305 |
< |
verify_access(struct Client *client_p, const char *username) |
305 |
> |
verify_access(struct Client *client_p) |
306 |
|
{ |
307 |
< |
struct AccessItem *aconf = NULL, *rkconf = NULL; |
828 |
< |
struct ConfItem *conf = NULL; |
307 |
> |
struct MaskItem *conf = NULL; |
308 |
|
char non_ident[USERLEN + 1] = { '~', '\0' }; |
830 |
– |
const char *uhi[3]; |
309 |
|
|
310 |
|
if (IsGotId(client_p)) |
311 |
|
{ |
312 |
< |
aconf = find_address_conf(client_p->host, client_p->username, |
312 |
> |
conf = find_address_conf(client_p->host, client_p->username, |
313 |
|
&client_p->localClient->ip, |
314 |
|
client_p->localClient->aftype, |
315 |
|
client_p->localClient->passwd); |
316 |
|
} |
317 |
|
else |
318 |
|
{ |
319 |
< |
strlcpy(non_ident+1, username, sizeof(non_ident)-1); |
320 |
< |
aconf = find_address_conf(client_p->host,non_ident, |
319 |
> |
strlcpy(non_ident+1, client_p->username, sizeof(non_ident)-1); |
320 |
> |
conf = find_address_conf(client_p->host,non_ident, |
321 |
|
&client_p->localClient->ip, |
322 |
|
client_p->localClient->aftype, |
323 |
|
client_p->localClient->passwd); |
324 |
|
} |
325 |
|
|
326 |
< |
uhi[0] = IsGotId(client_p) ? client_p->username : non_ident; |
849 |
< |
uhi[1] = client_p->host; |
850 |
< |
uhi[2] = client_p->sockhost; |
851 |
< |
|
852 |
< |
rkconf = find_regexp_kline(uhi); |
853 |
< |
|
854 |
< |
if (aconf != NULL) |
326 |
> |
if (conf != NULL) |
327 |
|
{ |
328 |
< |
if (IsConfClient(aconf) && !rkconf) |
328 |
> |
if (IsConfClient(conf)) |
329 |
|
{ |
330 |
< |
conf = unmap_conf_item(aconf); |
859 |
< |
|
860 |
< |
if (IsConfRedir(aconf)) |
330 |
> |
if (IsConfRedir(conf)) |
331 |
|
{ |
332 |
|
sendto_one(client_p, form_str(RPL_REDIR), |
333 |
|
me.name, client_p->name, |
334 |
|
conf->name ? conf->name : "", |
335 |
< |
aconf->port); |
335 |
> |
conf->port); |
336 |
|
return(NOT_AUTHORIZED); |
337 |
|
} |
338 |
|
|
339 |
< |
if (IsConfDoIdentd(aconf)) |
339 |
> |
if (IsConfDoIdentd(conf)) |
340 |
|
SetNeedId(client_p); |
341 |
|
|
342 |
|
/* Thanks for spoof idea amm */ |
343 |
< |
if (IsConfDoSpoofIp(aconf)) |
343 |
> |
if (IsConfDoSpoofIp(conf)) |
344 |
|
{ |
345 |
< |
conf = unmap_conf_item(aconf); |
876 |
< |
|
877 |
< |
if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(aconf)) |
345 |
> |
if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf)) |
346 |
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
347 |
|
"%s spoofing: %s as %s", |
348 |
|
client_p->name, client_p->host, conf->name); |
352 |
|
|
353 |
|
return(attach_iline(client_p, conf)); |
354 |
|
} |
355 |
< |
else if (rkconf || IsConfKill(aconf) || (ConfigFileEntry.glines && IsConfGline(aconf))) |
355 |
> |
else if (IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf))) |
356 |
|
{ |
357 |
< |
/* XXX */ |
890 |
< |
aconf = rkconf ? rkconf : aconf; |
891 |
< |
if (IsConfGline(aconf)) |
357 |
> |
if (IsConfGline(conf)) |
358 |
|
sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name, |
359 |
|
client_p->name); |
360 |
|
sendto_one(client_p, ":%s NOTICE %s :*** Banned: %s", |
361 |
< |
me.name, client_p->name, aconf->reason); |
361 |
> |
me.name, client_p->name, conf->reason); |
362 |
|
return(BANNED_CLIENT); |
363 |
|
} |
364 |
|
} |
374 |
|
* side effects - do actual attach |
375 |
|
*/ |
376 |
|
static int |
377 |
< |
attach_iline(struct Client *client_p, struct ConfItem *conf) |
377 |
> |
attach_iline(struct Client *client_p, struct MaskItem *conf) |
378 |
|
{ |
379 |
< |
struct AccessItem *aconf; |
914 |
< |
struct ClassItem *aclass; |
379 |
> |
struct ClassItem *class = NULL; |
380 |
|
struct ip_entry *ip_found; |
381 |
|
int a_limit_reached = 0; |
382 |
< |
int local = 0, global = 0, ident = 0; |
382 |
> |
unsigned int local = 0, global = 0, ident = 0; |
383 |
|
|
384 |
|
ip_found = find_or_add_ip(&client_p->localClient->ip); |
385 |
|
ip_found->count++; |
386 |
|
SetIpHash(client_p); |
387 |
|
|
388 |
< |
aconf = map_to_conf(conf); |
924 |
< |
if (aconf->class_ptr == NULL) |
388 |
> |
if (conf->class == NULL) |
389 |
|
return NOT_AUTHORIZED; /* If class is missing, this is best */ |
390 |
|
|
391 |
< |
aclass = map_to_conf(aconf->class_ptr); |
391 |
> |
class = conf->class; |
392 |
|
|
393 |
|
count_user_host(client_p->username, client_p->host, |
394 |
|
&global, &local, &ident); |
397 |
|
* setting a_limit_reached if any limit is reached. |
398 |
|
* - Dianora |
399 |
|
*/ |
400 |
< |
if (aclass->max_total != 0 && aclass->curr_user_count >= aclass->max_total) |
400 |
> |
if (class->max_total != 0 && class->ref_count >= class->max_total) |
401 |
|
a_limit_reached = 1; |
402 |
< |
else if (aclass->max_perip != 0 && ip_found->count > aclass->max_perip) |
402 |
> |
else if (class->max_perip != 0 && ip_found->count > class->max_perip) |
403 |
|
a_limit_reached = 1; |
404 |
< |
else if (aclass->max_local != 0 && local >= aclass->max_local) |
404 |
> |
else if (class->max_local != 0 && local >= class->max_local) |
405 |
|
a_limit_reached = 1; |
406 |
< |
else if (aclass->max_global != 0 && global >= aclass->max_global) |
406 |
> |
else if (class->max_global != 0 && global >= class->max_global) |
407 |
|
a_limit_reached = 1; |
408 |
< |
else if (aclass->max_ident != 0 && ident >= aclass->max_ident && |
408 |
> |
else if (class->max_ident != 0 && ident >= class->max_ident && |
409 |
|
client_p->username[0] != '~') |
410 |
|
a_limit_reached = 1; |
411 |
|
|
412 |
|
if (a_limit_reached) |
413 |
|
{ |
414 |
< |
if (!IsConfExemptLimits(aconf)) |
414 |
> |
if (!IsConfExemptLimits(conf)) |
415 |
|
return TOO_MANY; /* Already at maximum allowed */ |
416 |
|
|
417 |
|
sendto_one(client_p, |
432 |
|
void |
433 |
|
init_ip_hash_table(void) |
434 |
|
{ |
435 |
< |
ip_entry_heap = BlockHeapCreate("ip", sizeof(struct ip_entry), |
972 |
< |
2 * hard_fdlimit); |
435 |
> |
ip_entry_pool = mp_pool_new(sizeof(struct ip_entry), MP_CHUNK_SIZE_IP_ENTRY); |
436 |
|
memset(ip_hash_table, 0, sizeof(ip_hash_table)); |
437 |
|
} |
438 |
|
|
481 |
|
if (ip_entries_count >= 2 * hard_fdlimit) |
482 |
|
garbage_collect_ip_entries(); |
483 |
|
|
484 |
< |
newptr = BlockHeapAlloc(ip_entry_heap); |
484 |
> |
newptr = mp_pool_get(ip_entry_pool); |
485 |
> |
memset(newptr, 0, sizeof(*newptr)); |
486 |
|
ip_entries_count++; |
487 |
|
memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr)); |
488 |
|
|
540 |
|
else |
541 |
|
ip_hash_table[hash_index] = ptr->next; |
542 |
|
|
543 |
< |
BlockHeapFree(ip_entry_heap, ptr); |
543 |
> |
mp_pool_release(ptr); |
544 |
|
ip_entries_count--; |
545 |
|
return; |
546 |
|
} |
643 |
|
last_ptr->next = ptr->next; |
644 |
|
else |
645 |
|
ip_hash_table[i] = ptr->next; |
646 |
< |
BlockHeapFree(ip_entry_heap, ptr); |
646 |
> |
mp_pool_release(ptr); |
647 |
|
ip_entries_count--; |
648 |
|
} |
649 |
|
else |
660 |
|
* side effects - Disassociate configuration from the client. |
661 |
|
* Also removes a class from the list if marked for deleting. |
662 |
|
*/ |
663 |
< |
int |
664 |
< |
detach_conf(struct Client *client_p, ConfType type) |
663 |
> |
void |
664 |
> |
detach_conf(struct Client *client_p, enum maskitem_type type) |
665 |
|
{ |
666 |
< |
dlink_node *ptr, *next_ptr; |
1203 |
< |
struct ConfItem *conf; |
1204 |
< |
struct ClassItem *aclass; |
1205 |
< |
struct AccessItem *aconf; |
1206 |
< |
struct ConfItem *aclass_conf; |
666 |
> |
dlink_node *ptr = NULL, *next_ptr = NULL; |
667 |
|
|
668 |
|
DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head) |
669 |
|
{ |
670 |
< |
conf = ptr->data; |
670 |
> |
struct MaskItem *conf = ptr->data; |
671 |
|
|
672 |
< |
if (type == CONF_TYPE || conf->type == type) |
673 |
< |
{ |
674 |
< |
dlinkDelete(ptr, &client_p->localClient->confs); |
1215 |
< |
free_dlink_node(ptr); |
1216 |
< |
|
1217 |
< |
switch (conf->type) |
1218 |
< |
{ |
1219 |
< |
case CLIENT_TYPE: |
1220 |
< |
case OPER_TYPE: |
1221 |
< |
case SERVER_TYPE: |
1222 |
< |
aconf = map_to_conf(conf); |
1223 |
< |
|
1224 |
< |
assert(aconf->clients > 0); |
1225 |
< |
|
1226 |
< |
if ((aclass_conf = aconf->class_ptr) != NULL) |
1227 |
< |
{ |
1228 |
< |
aclass = map_to_conf(aclass_conf); |
672 |
> |
assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER)); |
673 |
> |
assert(conf->ref_count > 0); |
674 |
> |
assert(conf->class->ref_count > 0); |
675 |
|
|
676 |
< |
assert(aclass->curr_user_count > 0); |
676 |
> |
if (!(conf->type & type)) |
677 |
> |
continue; |
678 |
|
|
679 |
< |
if (conf->type == CLIENT_TYPE) |
680 |
< |
remove_from_cidr_check(&client_p->localClient->ip, aclass); |
1234 |
< |
if (--aclass->curr_user_count == 0 && aclass->active == 0) |
1235 |
< |
delete_conf_item(aclass_conf); |
1236 |
< |
} |
679 |
> |
dlinkDelete(ptr, &client_p->localClient->confs); |
680 |
> |
free_dlink_node(ptr); |
681 |
|
|
682 |
< |
if (--aconf->clients == 0 && IsConfIllegal(aconf)) |
683 |
< |
delete_conf_item(conf); |
682 |
> |
if (conf->type == CONF_CLIENT) |
683 |
> |
remove_from_cidr_check(&client_p->localClient->ip, conf->class); |
684 |
|
|
685 |
< |
break; |
686 |
< |
default: |
687 |
< |
break; |
688 |
< |
} |
1245 |
< |
|
1246 |
< |
if (type != CONF_TYPE) |
1247 |
< |
return 0; |
685 |
> |
if (--conf->class->ref_count == 0 && conf->class->active == 0) |
686 |
> |
{ |
687 |
> |
class_free(conf->class); |
688 |
> |
conf->class = NULL; |
689 |
|
} |
1249 |
– |
} |
690 |
|
|
691 |
< |
return -1; |
691 |
> |
if (--conf->ref_count == 0 && conf->active == 0) |
692 |
> |
conf_free(conf); |
693 |
> |
} |
694 |
|
} |
695 |
|
|
696 |
|
/* attach_conf() |
704 |
|
* attachment if there was an old one... |
705 |
|
*/ |
706 |
|
int |
707 |
< |
attach_conf(struct Client *client_p, struct ConfItem *conf) |
707 |
> |
attach_conf(struct Client *client_p, struct MaskItem *conf) |
708 |
|
{ |
1267 |
– |
struct AccessItem *aconf = map_to_conf(conf); |
1268 |
– |
struct ClassItem *aclass = map_to_conf(aconf->class_ptr); |
1269 |
– |
|
709 |
|
if (dlinkFind(&client_p->localClient->confs, conf) != NULL) |
710 |
|
return 1; |
711 |
|
|
712 |
< |
if (IsConfIllegal(aconf)) /* TBV: can't happen */ |
713 |
< |
return NOT_AUTHORIZED; |
714 |
< |
|
1276 |
< |
if (conf->type == CLIENT_TYPE) |
1277 |
< |
if (cidr_limit_reached(IsConfExemptLimits(aconf), |
1278 |
< |
&client_p->localClient->ip, aclass)) |
712 |
> |
if (conf->type == CONF_CLIENT) |
713 |
> |
if (cidr_limit_reached(IsConfExemptLimits(conf), |
714 |
> |
&client_p->localClient->ip, conf->class)) |
715 |
|
return TOO_MANY; /* Already at maximum allowed */ |
716 |
|
|
717 |
< |
aclass->curr_user_count++; |
718 |
< |
aconf->clients++; |
717 |
> |
conf->class->ref_count++; |
718 |
> |
conf->ref_count++; |
719 |
|
|
720 |
|
dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs); |
721 |
|
|
735 |
|
const char *host) |
736 |
|
{ |
737 |
|
dlink_node *ptr; |
738 |
< |
struct ConfItem *conf; |
1303 |
< |
struct AccessItem *aconf; |
738 |
> |
struct MaskItem *conf = NULL; |
739 |
|
|
740 |
|
assert(client_p != NULL); |
741 |
|
assert(host != NULL); |
746 |
|
DLINK_FOREACH(ptr, server_items.head) |
747 |
|
{ |
748 |
|
conf = ptr->data; |
1314 |
– |
aconf = map_to_conf(conf); |
749 |
|
|
750 |
< |
if (match(conf->name, name) == 0 || match(aconf->host, host) == 0) |
750 |
> |
if (match(conf->name, name) || match(conf->host, host)) |
751 |
|
continue; |
752 |
|
|
753 |
|
attach_conf(client_p, conf); |
757 |
|
return 0; |
758 |
|
} |
759 |
|
|
1326 |
– |
/* find_conf_exact() |
1327 |
– |
* |
1328 |
– |
* inputs - type of ConfItem |
1329 |
– |
* - pointer to name to find |
1330 |
– |
* - pointer to username to find |
1331 |
– |
* - pointer to host to find |
1332 |
– |
* output - NULL or pointer to conf found |
1333 |
– |
* side effects - find a conf entry which matches the hostname |
1334 |
– |
* and has the same name. |
1335 |
– |
*/ |
1336 |
– |
struct ConfItem * |
1337 |
– |
find_conf_exact(ConfType type, const char *name, const char *user, |
1338 |
– |
const char *host) |
1339 |
– |
{ |
1340 |
– |
dlink_node *ptr; |
1341 |
– |
dlink_list *list_p; |
1342 |
– |
struct ConfItem *conf = NULL; |
1343 |
– |
struct AccessItem *aconf; |
1344 |
– |
|
1345 |
– |
/* Only valid for OPER_TYPE and ...? */ |
1346 |
– |
list_p = map_to_list(type); |
1347 |
– |
|
1348 |
– |
DLINK_FOREACH(ptr, (*list_p).head) |
1349 |
– |
{ |
1350 |
– |
conf = ptr->data; |
1351 |
– |
|
1352 |
– |
if (conf->name == NULL) |
1353 |
– |
continue; |
1354 |
– |
aconf = map_to_conf(conf); |
1355 |
– |
if (aconf->host == NULL) |
1356 |
– |
continue; |
1357 |
– |
if (irccmp(conf->name, name) != 0) |
1358 |
– |
continue; |
1359 |
– |
|
1360 |
– |
/* |
1361 |
– |
** Accept if the *real* hostname (usually sockethost) |
1362 |
– |
** socket host) matches *either* host or name field |
1363 |
– |
** of the configuration. |
1364 |
– |
*/ |
1365 |
– |
if (!match(aconf->host, host) || !match(aconf->user, user)) |
1366 |
– |
continue; |
1367 |
– |
if (type == OPER_TYPE) |
1368 |
– |
{ |
1369 |
– |
struct ClassItem *aclass = map_to_conf(aconf->class_ptr); |
1370 |
– |
|
1371 |
– |
if (aconf->clients >= aclass->max_total) |
1372 |
– |
continue; |
1373 |
– |
} |
1374 |
– |
|
1375 |
– |
return conf; |
1376 |
– |
} |
1377 |
– |
|
1378 |
– |
return NULL; |
1379 |
– |
} |
1380 |
– |
|
760 |
|
/* find_conf_name() |
761 |
|
* |
762 |
|
* inputs - pointer to conf link list to search |
766 |
|
* side effects - find a conf entry which matches the name |
767 |
|
* and has the given mask. |
768 |
|
*/ |
769 |
< |
struct ConfItem * |
770 |
< |
find_conf_name(dlink_list *list, const char *name, ConfType type) |
769 |
> |
struct MaskItem * |
770 |
> |
find_conf_name(dlink_list *list, const char *name, enum maskitem_type type) |
771 |
|
{ |
772 |
|
dlink_node *ptr; |
773 |
< |
struct ConfItem* conf; |
773 |
> |
struct MaskItem* conf; |
774 |
|
|
775 |
|
DLINK_FOREACH(ptr, list->head) |
776 |
|
{ |
779 |
|
if (conf->type == type) |
780 |
|
{ |
781 |
|
if (conf->name && (irccmp(conf->name, name) == 0 || |
782 |
< |
match(conf->name, name))) |
782 |
> |
!match(conf->name, name))) |
783 |
|
return conf; |
784 |
|
} |
785 |
|
} |
794 |
|
* side effects - none |
795 |
|
*/ |
796 |
|
static dlink_list * |
797 |
< |
map_to_list(ConfType type) |
797 |
> |
map_to_list(enum maskitem_type type) |
798 |
|
{ |
799 |
|
switch(type) |
800 |
|
{ |
801 |
< |
case RXLINE_TYPE: |
1423 |
< |
return(&rxconf_items); |
1424 |
< |
break; |
1425 |
< |
case XLINE_TYPE: |
801 |
> |
case CONF_XLINE: |
802 |
|
return(&xconf_items); |
803 |
|
break; |
804 |
< |
case ULINE_TYPE: |
804 |
> |
case CONF_ULINE: |
805 |
|
return(&uconf_items); |
806 |
|
break; |
807 |
< |
case NRESV_TYPE: |
807 |
> |
case CONF_NRESV: |
808 |
|
return(&nresv_items); |
809 |
|
break; |
810 |
< |
case OPER_TYPE: |
810 |
> |
case CONF_CRESV: |
811 |
> |
return(&resv_channel_list); |
812 |
> |
case CONF_OPER: |
813 |
|
return(&oconf_items); |
814 |
|
break; |
815 |
< |
case CLASS_TYPE: |
1438 |
< |
return(&class_items); |
1439 |
< |
break; |
1440 |
< |
case SERVER_TYPE: |
815 |
> |
case CONF_SERVER: |
816 |
|
return(&server_items); |
817 |
|
break; |
818 |
< |
case SERVICE_TYPE: |
818 |
> |
case CONF_SERVICE: |
819 |
|
return(&service_items); |
820 |
|
break; |
821 |
< |
case CLUSTER_TYPE: |
821 |
> |
case CONF_CLUSTER: |
822 |
|
return(&cluster_items); |
823 |
|
break; |
1449 |
– |
case CONF_TYPE: |
1450 |
– |
case GLINE_TYPE: |
1451 |
– |
case KLINE_TYPE: |
1452 |
– |
case DLINE_TYPE: |
1453 |
– |
case CRESV_TYPE: |
824 |
|
default: |
825 |
|
return NULL; |
826 |
|
} |
832 |
|
* - pointer to name string to find |
833 |
|
* - pointer to user |
834 |
|
* - pointer to host |
835 |
< |
* - optional action to match on as well |
836 |
< |
* output - NULL or pointer to found struct MatchItem |
835 |
> |
* - optional flags to match on as well |
836 |
> |
* output - NULL or pointer to found struct MaskItem |
837 |
|
* side effects - looks for a match on name field |
838 |
|
*/ |
839 |
< |
struct ConfItem * |
840 |
< |
find_matching_name_conf(ConfType type, const char *name, const char *user, |
841 |
< |
const char *host, int action) |
839 |
> |
struct MaskItem * |
840 |
> |
find_matching_name_conf(enum maskitem_type type, const char *name, const char *user, |
841 |
> |
const char *host, unsigned int flags) |
842 |
|
{ |
843 |
|
dlink_node *ptr=NULL; |
844 |
< |
struct ConfItem *conf=NULL; |
1475 |
< |
struct AccessItem *aconf=NULL; |
1476 |
< |
struct MatchItem *match_item=NULL; |
844 |
> |
struct MaskItem *conf=NULL; |
845 |
|
dlink_list *list_p = map_to_list(type); |
846 |
|
|
847 |
|
switch (type) |
848 |
|
{ |
849 |
< |
#ifdef HAVE_LIBPCRE |
1482 |
< |
case RXLINE_TYPE: |
1483 |
< |
DLINK_FOREACH(ptr, list_p->head) |
1484 |
< |
{ |
1485 |
< |
conf = ptr->data; |
1486 |
< |
assert(conf->regexpname); |
1487 |
< |
|
1488 |
< |
if (!ircd_pcre_exec(conf->regexpname, name)) |
1489 |
< |
return conf; |
1490 |
< |
} |
1491 |
< |
break; |
1492 |
< |
#endif |
1493 |
< |
case SERVICE_TYPE: |
849 |
> |
case CONF_SERVICE: |
850 |
|
DLINK_FOREACH(ptr, list_p->head) |
851 |
|
{ |
852 |
|
conf = ptr->data; |
858 |
|
} |
859 |
|
break; |
860 |
|
|
861 |
< |
case XLINE_TYPE: |
862 |
< |
case ULINE_TYPE: |
863 |
< |
case NRESV_TYPE: |
861 |
> |
case CONF_XLINE: |
862 |
> |
case CONF_ULINE: |
863 |
> |
case CONF_NRESV: |
864 |
> |
case CONF_CRESV: |
865 |
|
DLINK_FOREACH(ptr, list_p->head) |
866 |
|
{ |
867 |
|
conf = ptr->data; |
868 |
|
|
1512 |
– |
match_item = map_to_conf(conf); |
869 |
|
if (EmptyString(conf->name)) |
870 |
|
continue; |
871 |
< |
if ((name != NULL) && match_esc(conf->name, name)) |
871 |
> |
if ((name != NULL) && !match(conf->name, name)) |
872 |
|
{ |
873 |
|
if ((user == NULL && (host == NULL))) |
874 |
|
return conf; |
875 |
< |
if ((match_item->action & action) != action) |
875 |
> |
if ((conf->flags & flags) != flags) |
876 |
|
continue; |
877 |
< |
if (EmptyString(match_item->user) || EmptyString(match_item->host)) |
877 |
> |
if (EmptyString(conf->user) || EmptyString(conf->host)) |
878 |
|
return conf; |
879 |
< |
if (match(match_item->user, user) && match(match_item->host, host)) |
879 |
> |
if (!match(conf->user, user) && !match(conf->host, host)) |
880 |
|
return conf; |
881 |
|
} |
882 |
|
} |
883 |
|
break; |
884 |
|
|
885 |
< |
case SERVER_TYPE: |
885 |
> |
case CONF_SERVER: |
886 |
|
DLINK_FOREACH(ptr, list_p->head) |
887 |
|
{ |
888 |
|
conf = ptr->data; |
1533 |
– |
aconf = map_to_conf(conf); |
889 |
|
|
890 |
< |
if ((name != NULL) && match_esc(name, conf->name)) |
890 |
> |
if ((name != NULL) && !match(name, conf->name)) |
891 |
|
return conf; |
892 |
< |
else if ((host != NULL) && match_esc(host, aconf->host)) |
892 |
> |
else if ((host != NULL) && !match(host, conf->host)) |
893 |
|
return conf; |
894 |
|
} |
895 |
|
break; |
906 |
|
* - pointer to name string to find |
907 |
|
* - pointer to user |
908 |
|
* - pointer to host |
909 |
< |
* output - NULL or pointer to found struct MatchItem |
909 |
> |
* output - NULL or pointer to found struct MaskItem |
910 |
|
* side effects - looks for an exact match on name field |
911 |
|
*/ |
912 |
< |
struct ConfItem * |
913 |
< |
find_exact_name_conf(ConfType type, const struct Client *who, const char *name, |
912 |
> |
struct MaskItem * |
913 |
> |
find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name, |
914 |
|
const char *user, const char *host) |
915 |
|
{ |
916 |
|
dlink_node *ptr = NULL; |
917 |
< |
struct AccessItem *aconf; |
918 |
< |
struct ConfItem *conf; |
1564 |
< |
struct MatchItem *match_item; |
1565 |
< |
dlink_list *list_p; |
1566 |
< |
|
1567 |
< |
list_p = map_to_list(type); |
917 |
> |
struct MaskItem *conf; |
918 |
> |
dlink_list *list_p = map_to_list(type); |
919 |
|
|
920 |
|
switch(type) |
921 |
|
{ |
922 |
< |
case RXLINE_TYPE: |
923 |
< |
case XLINE_TYPE: |
924 |
< |
case ULINE_TYPE: |
925 |
< |
case NRESV_TYPE: |
922 |
> |
case CONF_XLINE: |
923 |
> |
case CONF_ULINE: |
924 |
> |
case CONF_NRESV: |
925 |
> |
case CONF_CRESV: |
926 |
|
|
927 |
|
DLINK_FOREACH(ptr, list_p->head) |
928 |
|
{ |
929 |
|
conf = ptr->data; |
930 |
< |
match_item = (struct MatchItem *)map_to_conf(conf); |
930 |
> |
|
931 |
|
if (EmptyString(conf->name)) |
932 |
|
continue; |
933 |
|
|
935 |
|
{ |
936 |
|
if ((user == NULL && (host == NULL))) |
937 |
|
return (conf); |
938 |
< |
if (EmptyString(match_item->user) || EmptyString(match_item->host)) |
938 |
> |
if (EmptyString(conf->user) || EmptyString(conf->host)) |
939 |
|
return (conf); |
940 |
< |
if (match(match_item->user, user) && match(match_item->host, host)) |
940 |
> |
if (!match(conf->user, user) && !match(conf->host, host)) |
941 |
|
return (conf); |
942 |
|
} |
943 |
|
} |
944 |
|
break; |
945 |
|
|
946 |
< |
case OPER_TYPE: |
946 |
> |
case CONF_OPER: |
947 |
|
DLINK_FOREACH(ptr, list_p->head) |
948 |
|
{ |
949 |
|
conf = ptr->data; |
1599 |
– |
aconf = map_to_conf(conf); |
950 |
|
|
951 |
|
if (EmptyString(conf->name)) |
952 |
|
continue; |
955 |
|
{ |
956 |
|
if (!who) |
957 |
|
return conf; |
958 |
< |
if (EmptyString(aconf->user) || EmptyString(aconf->host)) |
959 |
< |
return conf; |
960 |
< |
if (match(aconf->user, who->username)) |
958 |
> |
if (EmptyString(conf->user) || EmptyString(conf->host)) |
959 |
> |
return NULL; |
960 |
> |
if (!match(conf->user, who->username)) |
961 |
|
{ |
962 |
< |
switch (aconf->type) |
962 |
> |
switch (conf->htype) |
963 |
|
{ |
964 |
|
case HM_HOST: |
965 |
< |
if (match(aconf->host, who->host) || match(aconf->host, who->sockhost)) |
966 |
< |
return conf; |
965 |
> |
if (!match(conf->host, who->host) || !match(conf->host, who->sockhost)) |
966 |
> |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
967 |
> |
return conf; |
968 |
|
break; |
969 |
|
case HM_IPV4: |
970 |
|
if (who->localClient->aftype == AF_INET) |
971 |
< |
if (match_ipv4(&who->localClient->ip, &aconf->addr, aconf->bits)) |
972 |
< |
return conf; |
971 |
> |
if (match_ipv4(&who->localClient->ip, &conf->addr, conf->bits)) |
972 |
> |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
973 |
> |
return conf; |
974 |
|
break; |
975 |
|
#ifdef IPV6 |
976 |
|
case HM_IPV6: |
977 |
|
if (who->localClient->aftype == AF_INET6) |
978 |
< |
if (match_ipv6(&who->localClient->ip, &aconf->addr, aconf->bits)) |
979 |
< |
return conf; |
978 |
> |
if (match_ipv6(&who->localClient->ip, &conf->addr, conf->bits)) |
979 |
> |
if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total) |
980 |
> |
return conf; |
981 |
|
break; |
982 |
|
#endif |
983 |
|
default: |
989 |
|
|
990 |
|
break; |
991 |
|
|
992 |
< |
case SERVER_TYPE: |
992 |
> |
case CONF_SERVER: |
993 |
|
DLINK_FOREACH(ptr, list_p->head) |
994 |
|
{ |
995 |
|
conf = ptr->data; |
996 |
< |
aconf = (struct AccessItem *)map_to_conf(conf); |
996 |
> |
|
997 |
|
if (EmptyString(conf->name)) |
998 |
|
continue; |
999 |
|
|
1000 |
|
if (name == NULL) |
1001 |
|
{ |
1002 |
< |
if (EmptyString(aconf->host)) |
1002 |
> |
if (EmptyString(conf->host)) |
1003 |
|
continue; |
1004 |
< |
if (irccmp(aconf->host, host) == 0) |
1004 |
> |
if (irccmp(conf->host, host) == 0) |
1005 |
|
return(conf); |
1006 |
|
} |
1007 |
|
else if (irccmp(conf->name, name) == 0) |
1011 |
|
} |
1012 |
|
break; |
1013 |
|
|
1661 |
– |
case CLASS_TYPE: |
1662 |
– |
DLINK_FOREACH(ptr, list_p->head) |
1663 |
– |
{ |
1664 |
– |
conf = ptr->data; |
1665 |
– |
if (EmptyString(conf->name)) |
1666 |
– |
continue; |
1667 |
– |
|
1668 |
– |
if (irccmp(conf->name, name) == 0) |
1669 |
– |
return (conf); |
1670 |
– |
} |
1671 |
– |
break; |
1672 |
– |
|
1014 |
|
default: |
1015 |
|
break; |
1016 |
|
} |
1044 |
|
|
1045 |
|
load_conf_modules(); |
1046 |
|
|
1706 |
– |
flush_deleted_I_P(); |
1707 |
– |
|
1047 |
|
rehashed_klines = 1; |
1709 |
– |
/* XXX */ |
1710 |
– |
if (ConfigLoggingEntry.use_logging) |
1711 |
– |
log_close_all(); |
1048 |
|
|
1049 |
< |
return(0); |
1049 |
> |
return 0; |
1050 |
|
} |
1051 |
|
|
1052 |
|
/* set_default_conf() |
1064 |
|
/* verify init_class() ran, this should be an unnecessary check |
1065 |
|
* but its not much work. |
1066 |
|
*/ |
1067 |
< |
assert(class_default == (struct ConfItem *) class_items.tail->data); |
1067 |
> |
assert(class_default == class_get_list()->tail->data); |
1068 |
|
|
1069 |
|
#ifdef HAVE_LIBCRYPTO |
1070 |
|
ServerInfo.rsa_private_key = NULL; |
1074 |
|
/* ServerInfo.name is not rehashable */ |
1075 |
|
/* ServerInfo.name = ServerInfo.name; */ |
1076 |
|
ServerInfo.description = NULL; |
1077 |
< |
DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT); |
1078 |
< |
DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT); |
1077 |
> |
ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT); |
1078 |
> |
ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT); |
1079 |
|
|
1080 |
|
memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip)); |
1081 |
|
ServerInfo.specific_ipv4_vhost = 0; |
1083 |
|
ServerInfo.specific_ipv6_vhost = 0; |
1084 |
|
|
1085 |
|
ServerInfo.max_clients = MAXCLIENTS_MAX; |
1086 |
+ |
ServerInfo.max_nick_length = 9; |
1087 |
+ |
ServerInfo.max_topic_length = 80; |
1088 |
|
|
1089 |
|
ServerInfo.hub = 0; |
1090 |
|
ServerInfo.dns_host.sin_addr.s_addr = 0; |
1093 |
|
AdminInfo.email = NULL; |
1094 |
|
AdminInfo.description = NULL; |
1095 |
|
|
1096 |
< |
log_close_all(); |
1096 |
> |
log_del_all(); |
1097 |
|
|
1098 |
|
ConfigLoggingEntry.use_logging = 1; |
1099 |
|
|
1100 |
|
ConfigChannel.disable_fake_channels = 0; |
1763 |
– |
ConfigChannel.restrict_channels = 0; |
1101 |
|
ConfigChannel.knock_delay = 300; |
1102 |
|
ConfigChannel.knock_delay_channel = 60; |
1103 |
|
ConfigChannel.max_chans_per_user = 25; |
1104 |
|
ConfigChannel.max_chans_per_oper = 50; |
1768 |
– |
ConfigChannel.quiet_on_ban = 1; |
1105 |
|
ConfigChannel.max_bans = 25; |
1106 |
|
ConfigChannel.default_split_user_count = 0; |
1107 |
|
ConfigChannel.default_split_server_count = 0; |
1112 |
|
ConfigServerHide.links_delay = 300; |
1113 |
|
ConfigServerHide.hidden = 0; |
1114 |
|
ConfigServerHide.hide_servers = 0; |
1115 |
< |
DupString(ConfigServerHide.hidden_name, NETWORK_NAME_DEFAULT); |
1115 |
> |
ConfigServerHide.hide_services = 0; |
1116 |
> |
ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT); |
1117 |
|
ConfigServerHide.hide_server_ips = 0; |
1118 |
|
|
1119 |
|
|
1120 |
< |
DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT); |
1120 |
> |
ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT); |
1121 |
|
ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT; |
1122 |
|
ConfigFileEntry.glines = 0; |
1123 |
|
ConfigFileEntry.gline_time = 12 * 3600; |
1176 |
|
ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; |
1177 |
|
|
1178 |
|
if (ServerInfo.network_name == NULL) |
1179 |
< |
DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT); |
1179 |
> |
ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT); |
1180 |
|
|
1181 |
|
if (ServerInfo.network_desc == NULL) |
1182 |
< |
DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT); |
1182 |
> |
ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT); |
1183 |
|
|
1184 |
|
if (ConfigFileEntry.service_name == NULL) |
1185 |
< |
DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT); |
1185 |
> |
ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT); |
1186 |
|
|
1187 |
|
ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN); |
1188 |
|
} |
1208 |
|
yyparse(); /* Load the values from the conf */ |
1209 |
|
validate_conf(); /* Check to make sure some values are still okay. */ |
1210 |
|
/* Some global values are also loaded here. */ |
1211 |
< |
check_class(); /* Make sure classes are valid */ |
1211 |
> |
class_delete_marked(); /* Make sure classes are valid */ |
1212 |
|
} |
1213 |
|
|
1214 |
|
/* lookup_confhost() |
1216 |
|
* start DNS lookups of all hostnames in the conf |
1217 |
|
* line and convert an IP addresses in a.b.c.d number for to IP#s. |
1218 |
|
*/ |
1219 |
< |
static void |
1220 |
< |
lookup_confhost(struct ConfItem *conf) |
1219 |
> |
void |
1220 |
> |
lookup_confhost(struct MaskItem *conf) |
1221 |
|
{ |
1885 |
– |
struct AccessItem *aconf; |
1222 |
|
struct addrinfo hints, *res; |
1223 |
|
|
1888 |
– |
aconf = map_to_conf(conf); |
1889 |
– |
|
1890 |
– |
if (has_wildcards(aconf->host)) |
1891 |
– |
{ |
1892 |
– |
ilog(LOG_TYPE_IRCD, "Host/server name error: (%s) (%s)", |
1893 |
– |
aconf->host, conf->name); |
1894 |
– |
return; |
1895 |
– |
} |
1896 |
– |
|
1224 |
|
/* Do name lookup now on hostnames given and store the |
1225 |
|
* ip numbers in conf structure. |
1226 |
|
*/ |
1232 |
|
/* Get us ready for a bind() and don't bother doing dns lookup */ |
1233 |
|
hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; |
1234 |
|
|
1235 |
< |
if (getaddrinfo(aconf->host, NULL, &hints, &res)) |
1235 |
> |
if (getaddrinfo(conf->host, NULL, &hints, &res)) |
1236 |
|
{ |
1237 |
< |
conf_dns_lookup(aconf); |
1237 |
> |
conf_dns_lookup(conf); |
1238 |
|
return; |
1239 |
|
} |
1240 |
|
|
1241 |
|
assert(res != NULL); |
1242 |
|
|
1243 |
< |
memcpy(&aconf->addr, res->ai_addr, res->ai_addrlen); |
1244 |
< |
aconf->addr.ss_len = res->ai_addrlen; |
1245 |
< |
aconf->addr.ss.ss_family = res->ai_family; |
1243 |
> |
memcpy(&conf->addr, res->ai_addr, res->ai_addrlen); |
1244 |
> |
conf->addr.ss_len = res->ai_addrlen; |
1245 |
> |
conf->addr.ss.ss_family = res->ai_family; |
1246 |
> |
|
1247 |
|
freeaddrinfo(res); |
1248 |
|
} |
1249 |
|
|
1258 |
|
conf_connect_allowed(struct irc_ssaddr *addr, int aftype) |
1259 |
|
{ |
1260 |
|
struct ip_entry *ip_found; |
1261 |
< |
struct AccessItem *aconf = find_dline_conf(addr, aftype); |
1261 |
> |
struct MaskItem *conf = find_dline_conf(addr, aftype); |
1262 |
|
|
1263 |
|
/* DLINE exempt also gets you out of static limits/pacing... */ |
1264 |
< |
if (aconf && (aconf->status & CONF_EXEMPTDLINE)) |
1264 |
> |
if (conf && (conf->type == CONF_EXEMPT)) |
1265 |
|
return 0; |
1266 |
|
|
1267 |
< |
if (aconf != NULL) |
1267 |
> |
if (conf != NULL) |
1268 |
|
return BANNED_CLIENT; |
1269 |
|
|
1270 |
|
ip_found = find_or_add_ip(addr); |
1280 |
|
return 0; |
1281 |
|
} |
1282 |
|
|
1955 |
– |
static struct AccessItem * |
1956 |
– |
find_regexp_kline(const char *uhi[]) |
1957 |
– |
{ |
1958 |
– |
#ifdef HAVE_LIBPCRE |
1959 |
– |
const dlink_node *ptr = NULL; |
1960 |
– |
|
1961 |
– |
DLINK_FOREACH(ptr, rkconf_items.head) |
1962 |
– |
{ |
1963 |
– |
struct AccessItem *aptr = map_to_conf(ptr->data); |
1964 |
– |
|
1965 |
– |
assert(aptr->regexuser); |
1966 |
– |
assert(aptr->regexhost); |
1967 |
– |
|
1968 |
– |
if (!ircd_pcre_exec(aptr->regexuser, uhi[0]) && |
1969 |
– |
(!ircd_pcre_exec(aptr->regexhost, uhi[1]) || |
1970 |
– |
!ircd_pcre_exec(aptr->regexhost, uhi[2]))) |
1971 |
– |
return aptr; |
1972 |
– |
} |
1973 |
– |
#endif |
1974 |
– |
return NULL; |
1975 |
– |
} |
1976 |
– |
|
1283 |
|
/* find_kill() |
1284 |
|
* |
1285 |
|
* inputs - pointer to client structure |
1286 |
< |
* output - pointer to struct AccessItem if found |
1286 |
> |
* output - pointer to struct MaskItem if found |
1287 |
|
* side effects - See if this user is klined already, |
1288 |
< |
* and if so, return struct AccessItem pointer |
1288 |
> |
* and if so, return struct MaskItem pointer |
1289 |
|
*/ |
1290 |
< |
struct AccessItem * |
1290 |
> |
struct MaskItem * |
1291 |
|
find_kill(struct Client *client_p) |
1292 |
|
{ |
1293 |
< |
struct AccessItem *aconf = NULL; |
1988 |
< |
const char *uhi[3]; |
1989 |
< |
|
1990 |
< |
uhi[0] = client_p->username; |
1991 |
< |
uhi[1] = client_p->host; |
1992 |
< |
uhi[2] = client_p->sockhost; |
1293 |
> |
struct MaskItem *conf = NULL; |
1294 |
|
|
1295 |
|
assert(client_p != NULL); |
1296 |
|
|
1297 |
< |
aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip, |
1298 |
< |
CONF_KLINE, client_p->localClient->aftype, |
1299 |
< |
client_p->username, NULL, 1); |
1300 |
< |
if (aconf == NULL) |
2000 |
< |
aconf = find_regexp_kline(uhi); |
2001 |
< |
|
2002 |
< |
return aconf; |
1297 |
> |
conf = find_conf_by_address(client_p->host, &client_p->localClient->ip, |
1298 |
> |
CONF_KLINE, client_p->localClient->aftype, |
1299 |
> |
client_p->username, NULL, 1); |
1300 |
> |
return conf; |
1301 |
|
} |
1302 |
|
|
1303 |
< |
struct AccessItem * |
1303 |
> |
struct MaskItem * |
1304 |
|
find_gline(struct Client *client_p) |
1305 |
|
{ |
1306 |
< |
struct AccessItem *aconf; |
1306 |
> |
struct MaskItem *conf; |
1307 |
|
|
1308 |
|
assert(client_p != NULL); |
1309 |
|
|
1310 |
< |
aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip, |
1311 |
< |
CONF_GLINE, client_p->localClient->aftype, |
1312 |
< |
client_p->username, NULL, 1); |
1313 |
< |
return aconf; |
2016 |
< |
} |
2017 |
< |
|
2018 |
< |
/* add_temp_line() |
2019 |
< |
* |
2020 |
< |
* inputs - pointer to struct ConfItem |
2021 |
< |
* output - none |
2022 |
< |
* Side effects - links in given struct ConfItem into |
2023 |
< |
* temporary *line link list |
2024 |
< |
*/ |
2025 |
< |
void |
2026 |
< |
add_temp_line(struct ConfItem *conf) |
2027 |
< |
{ |
2028 |
< |
if (conf->type == XLINE_TYPE) |
2029 |
< |
{ |
2030 |
< |
conf->flags |= CONF_FLAGS_TEMPORARY; |
2031 |
< |
dlinkAdd(conf, make_dlink_node(), &temporary_xlines); |
2032 |
< |
} |
2033 |
< |
else if ((conf->type == NRESV_TYPE) || (conf->type == CRESV_TYPE)) |
2034 |
< |
{ |
2035 |
< |
conf->flags |= CONF_FLAGS_TEMPORARY; |
2036 |
< |
dlinkAdd(conf, make_dlink_node(), &temporary_resv); |
2037 |
< |
} |
1310 |
> |
conf = find_conf_by_address(client_p->host, &client_p->localClient->ip, |
1311 |
> |
CONF_GLINE, client_p->localClient->aftype, |
1312 |
> |
client_p->username, NULL, 1); |
1313 |
> |
return conf; |
1314 |
|
} |
1315 |
|
|
1316 |
|
/* cleanup_tklines() |
1324 |
|
cleanup_tklines(void *notused) |
1325 |
|
{ |
1326 |
|
hostmask_expire_temporary(); |
1327 |
< |
expire_tklines(&temporary_xlines); |
1328 |
< |
expire_tklines(&temporary_resv); |
1327 |
> |
expire_tklines(&xconf_items); |
1328 |
> |
expire_tklines(&nresv_items); |
1329 |
> |
expire_tklines(&resv_channel_list); |
1330 |
|
} |
1331 |
|
|
1332 |
|
/* expire_tklines() |
1340 |
|
{ |
1341 |
|
dlink_node *ptr; |
1342 |
|
dlink_node *next_ptr; |
1343 |
< |
struct ConfItem *conf; |
2067 |
< |
struct MatchItem *xconf; |
2068 |
< |
struct MatchItem *nconf; |
2069 |
< |
struct ResvChannel *cconf; |
1343 |
> |
struct MaskItem *conf; |
1344 |
|
|
1345 |
|
DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head) |
1346 |
|
{ |
1347 |
|
conf = ptr->data; |
1348 |
|
|
1349 |
< |
if (conf->type == XLINE_TYPE) |
1349 |
> |
if (!conf->until || conf->until > CurrentTime) |
1350 |
> |
continue; |
1351 |
> |
|
1352 |
> |
if (conf->type == CONF_XLINE) |
1353 |
|
{ |
1354 |
< |
xconf = (struct MatchItem *)map_to_conf(conf); |
1355 |
< |
if (xconf->hold <= CurrentTime) |
2079 |
< |
{ |
2080 |
< |
if (ConfigFileEntry.tkline_expire_notices) |
2081 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1354 |
> |
if (ConfigFileEntry.tkline_expire_notices) |
1355 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1356 |
|
"Temporary X-line for [%s] expired", conf->name); |
1357 |
< |
dlinkDelete(ptr, tklist); |
2084 |
< |
free_dlink_node(ptr); |
2085 |
< |
delete_conf_item(conf); |
2086 |
< |
} |
1357 |
> |
conf_free(conf); |
1358 |
|
} |
1359 |
< |
else if (conf->type == NRESV_TYPE) |
1359 |
> |
else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV) |
1360 |
|
{ |
1361 |
< |
nconf = (struct MatchItem *)map_to_conf(conf); |
1362 |
< |
if (nconf->hold <= CurrentTime) |
2092 |
< |
{ |
2093 |
< |
if (ConfigFileEntry.tkline_expire_notices) |
2094 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1361 |
> |
if (ConfigFileEntry.tkline_expire_notices) |
1362 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1363 |
|
"Temporary RESV for [%s] expired", conf->name); |
1364 |
< |
dlinkDelete(ptr, tklist); |
2097 |
< |
free_dlink_node(ptr); |
2098 |
< |
delete_conf_item(conf); |
2099 |
< |
} |
2100 |
< |
} |
2101 |
< |
else if (conf->type == CRESV_TYPE) |
2102 |
< |
{ |
2103 |
< |
cconf = (struct ResvChannel *)map_to_conf(conf); |
2104 |
< |
if (cconf->hold <= CurrentTime) |
2105 |
< |
{ |
2106 |
< |
if (ConfigFileEntry.tkline_expire_notices) |
2107 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
2108 |
< |
"Temporary RESV for [%s] expired", cconf->name); |
2109 |
< |
delete_channel_resv(cconf); |
2110 |
< |
} |
1364 |
> |
conf_free(conf); |
1365 |
|
} |
1366 |
|
} |
1367 |
|
} |
1374 |
|
*/ |
1375 |
|
static const struct oper_privs |
1376 |
|
{ |
1377 |
< |
const unsigned int oprivs; |
1377 |
> |
const unsigned int flag; |
1378 |
|
const unsigned char c; |
1379 |
|
} flag_list[] = { |
1380 |
< |
{ OPER_FLAG_ADMIN, 'A' }, |
1381 |
< |
{ OPER_FLAG_REMOTEBAN, 'B' }, |
1382 |
< |
{ OPER_FLAG_DIE, 'D' }, |
1383 |
< |
{ OPER_FLAG_GLINE, 'G' }, |
1384 |
< |
{ OPER_FLAG_REHASH, 'H' }, |
1385 |
< |
{ OPER_FLAG_K, 'K' }, |
1386 |
< |
{ OPER_FLAG_OPERWALL, 'L' }, |
1387 |
< |
{ OPER_FLAG_N, 'N' }, |
1388 |
< |
{ OPER_FLAG_GLOBAL_KILL, 'O' }, |
1389 |
< |
{ OPER_FLAG_REMOTE, 'R' }, |
1390 |
< |
{ OPER_FLAG_OPER_SPY, 'S' }, |
1391 |
< |
{ OPER_FLAG_UNKLINE, 'U' }, |
1392 |
< |
{ OPER_FLAG_X, 'X' }, |
1380 |
> |
{ OPER_FLAG_ADMIN, 'A' }, |
1381 |
> |
{ OPER_FLAG_REMOTEBAN, 'B' }, |
1382 |
> |
{ OPER_FLAG_DIE, 'D' }, |
1383 |
> |
{ OPER_FLAG_GLINE, 'G' }, |
1384 |
> |
{ OPER_FLAG_REHASH, 'H' }, |
1385 |
> |
{ OPER_FLAG_K, 'K' }, |
1386 |
> |
{ OPER_FLAG_OPERWALL, 'L' }, |
1387 |
> |
{ OPER_FLAG_KILL, 'N' }, |
1388 |
> |
{ OPER_FLAG_KILL_REMOTE, 'O' }, |
1389 |
> |
{ OPER_FLAG_CONNECT, 'P' }, |
1390 |
> |
{ OPER_FLAG_CONNECT_REMOTE, 'Q' }, |
1391 |
> |
{ OPER_FLAG_SQUIT, 'R' }, |
1392 |
> |
{ OPER_FLAG_SQUIT_REMOTE, 'S' }, |
1393 |
> |
{ OPER_FLAG_UNKLINE, 'U' }, |
1394 |
> |
{ OPER_FLAG_X, 'X' }, |
1395 |
|
{ 0, '\0' } |
1396 |
|
}; |
1397 |
|
|
1400 |
|
{ |
1401 |
|
static char privs_out[16]; |
1402 |
|
char *privs_ptr = privs_out; |
1403 |
< |
unsigned int i = 0; |
1403 |
> |
const struct oper_privs *opriv = flag_list; |
1404 |
|
|
1405 |
< |
for (; flag_list[i].oprivs; ++i) |
1405 |
> |
for (; opriv->flag; ++opriv) |
1406 |
|
{ |
1407 |
< |
if (port & flag_list[i].oprivs) |
1408 |
< |
*privs_ptr++ = flag_list[i].c; |
1407 |
> |
if (port & opriv->flag) |
1408 |
> |
*privs_ptr++ = opriv->c; |
1409 |
|
else |
1410 |
< |
*privs_ptr++ = ToLowerTab[flag_list[i].c]; |
1410 |
> |
*privs_ptr++ = ToLower(opriv->c); |
1411 |
|
} |
1412 |
|
|
1413 |
|
*privs_ptr = '\0'; |
1432 |
|
{ |
1433 |
|
if ((cnode = client_p->localClient->confs.head)) |
1434 |
|
{ |
1435 |
< |
struct ConfItem *conf = cnode->data; |
2180 |
< |
const struct AccessItem *aconf = map_to_conf(conf); |
1435 |
> |
struct MaskItem *conf = cnode->data; |
1436 |
|
|
1437 |
< |
if (IsConfOperator(aconf)) |
1437 |
> |
if (IsConfOperator(conf)) |
1438 |
|
{ |
1439 |
|
snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name, |
1440 |
|
client_p->username, client_p->host, conf->name); |
1467 |
|
char chanlimit[32]; |
1468 |
|
|
1469 |
|
conf_parser_ctx.boot = cold; |
1470 |
< |
filename = get_conf_name(CONF_TYPE); |
1470 |
> |
filename = ConfigFileEntry.configfile; |
1471 |
|
|
1472 |
|
/* We need to know the initial filename for the yyerror() to report |
1473 |
|
FIXME: The full path is in conffilenamebuf first time since we |
1500 |
|
read_conf(conf_parser_ctx.conf_file); |
1501 |
|
fclose(conf_parser_ctx.conf_file); |
1502 |
|
|
1503 |
+ |
log_reopen_all(); |
1504 |
+ |
|
1505 |
+ |
add_isupport("NICKLEN", NULL, ServerInfo.max_nick_length); |
1506 |
|
add_isupport("NETWORK", ServerInfo.network_name, -1); |
1507 |
< |
snprintf(chanmodes, sizeof(chanmodes), "beI:%d", |
1508 |
< |
ConfigChannel.max_bans); |
1507 |
> |
|
1508 |
> |
snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans); |
1509 |
|
add_isupport("MAXLIST", chanmodes, -1); |
1510 |
|
add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets); |
2253 |
– |
|
1511 |
|
add_isupport("CHANTYPES", "#", -1); |
1512 |
|
|
1513 |
|
snprintf(chanlimit, sizeof(chanlimit), "#:%d", |
1514 |
< |
ConfigChannel.max_chans_per_user); |
1514 |
> |
ConfigChannel.max_chans_per_user); |
1515 |
|
add_isupport("CHANLIMIT", chanlimit, -1); |
1516 |
< |
snprintf(chanmodes, sizeof(chanmodes), "%s", |
2260 |
< |
"beI,k,l,imnprstORS"); |
1516 |
> |
snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS"); |
1517 |
|
add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN); |
1518 |
< |
|
1518 |
> |
add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length); |
1519 |
|
add_isupport("EXCEPTS", "e", -1); |
1520 |
|
add_isupport("INVEX", "I", -1); |
1521 |
|
add_isupport("CHANMODES", chanmodes, -1); |
1525 |
|
* on strlen(form_str(RPL_ISUPPORT)) |
1526 |
|
*/ |
1527 |
|
rebuild_isupport_message_line(); |
2272 |
– |
|
2273 |
– |
parse_conf_file(KLINE_TYPE, cold); |
2274 |
– |
parse_conf_file(DLINE_TYPE, cold); |
2275 |
– |
parse_conf_file(XLINE_TYPE, cold); |
2276 |
– |
parse_conf_file(NRESV_TYPE, cold); |
2277 |
– |
parse_conf_file(CRESV_TYPE, cold); |
2278 |
– |
} |
2279 |
– |
|
2280 |
– |
/* parse_conf_file() |
2281 |
– |
* |
2282 |
– |
* inputs - type of conf file to parse |
2283 |
– |
* output - none |
2284 |
– |
* side effects - conf file for givenconf type is opened and read then parsed |
2285 |
– |
*/ |
2286 |
– |
static void |
2287 |
– |
parse_conf_file(int type, int cold) |
2288 |
– |
{ |
2289 |
– |
FILE *file = NULL; |
2290 |
– |
const char *filename = get_conf_name(type); |
2291 |
– |
|
2292 |
– |
if ((file = fopen(filename, "r")) == NULL) |
2293 |
– |
{ |
2294 |
– |
if (cold) |
2295 |
– |
ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s", |
2296 |
– |
filename, strerror(errno)); |
2297 |
– |
else |
2298 |
– |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
2299 |
– |
"Unable to read configuration file '%s': %s", |
2300 |
– |
filename, strerror(errno)); |
2301 |
– |
} |
2302 |
– |
else |
2303 |
– |
{ |
2304 |
– |
parse_csv_file(file, type); |
2305 |
– |
fclose(file); |
2306 |
– |
} |
1528 |
|
} |
1529 |
|
|
1530 |
|
/* clear_out_old_conf() |
1537 |
|
clear_out_old_conf(void) |
1538 |
|
{ |
1539 |
|
dlink_node *ptr = NULL, *next_ptr = NULL; |
1540 |
< |
struct ConfItem *conf; |
2320 |
< |
struct AccessItem *aconf; |
2321 |
< |
struct ClassItem *cltmp; |
1540 |
> |
struct MaskItem *conf; |
1541 |
|
dlink_list *free_items [] = { |
1542 |
|
&server_items, &oconf_items, |
1543 |
< |
&uconf_items, &xconf_items, &rxconf_items, &rkconf_items, |
1544 |
< |
&nresv_items, &cluster_items, &service_items, NULL |
1543 |
> |
&uconf_items, &xconf_items, |
1544 |
> |
&nresv_items, &cluster_items, &service_items, &resv_channel_list, NULL |
1545 |
|
}; |
1546 |
|
|
1547 |
|
dlink_list ** iterator = free_items; /* C is dumb */ |
1555 |
|
DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head) |
1556 |
|
{ |
1557 |
|
conf = ptr->data; |
2339 |
– |
/* XXX This is less than pretty */ |
2340 |
– |
if (conf->type == SERVER_TYPE) |
2341 |
– |
{ |
2342 |
– |
aconf = map_to_conf(conf); |
1558 |
|
|
1559 |
< |
if (aconf->clients != 0) |
2345 |
< |
{ |
2346 |
< |
SetConfIllegal(aconf); |
2347 |
< |
dlinkDelete(&conf->node, &server_items); |
2348 |
< |
} |
2349 |
< |
else |
2350 |
< |
{ |
2351 |
< |
delete_conf_item(conf); |
2352 |
< |
} |
2353 |
< |
} |
2354 |
< |
else if (conf->type == OPER_TYPE) |
2355 |
< |
{ |
2356 |
< |
aconf = map_to_conf(conf); |
1559 |
> |
dlinkDelete(&conf->node, map_to_list(conf->type)); |
1560 |
|
|
1561 |
< |
if (aconf->clients != 0) |
1562 |
< |
{ |
2360 |
< |
SetConfIllegal(aconf); |
2361 |
< |
dlinkDelete(&conf->node, &oconf_items); |
2362 |
< |
} |
2363 |
< |
else |
2364 |
< |
{ |
2365 |
< |
delete_conf_item(conf); |
2366 |
< |
} |
2367 |
< |
} |
2368 |
< |
else if (conf->type == XLINE_TYPE || |
2369 |
< |
conf->type == RXLINE_TYPE || |
2370 |
< |
conf->type == RKLINE_TYPE) |
1561 |
> |
/* XXX This is less than pretty */ |
1562 |
> |
if (conf->type == CONF_SERVER || conf->type == CONF_OPER) |
1563 |
|
{ |
1564 |
< |
/* temporary (r)xlines are also on |
1565 |
< |
* the (r)xconf items list */ |
2374 |
< |
if (conf->flags & CONF_FLAGS_TEMPORARY) |
2375 |
< |
continue; |
2376 |
< |
|
2377 |
< |
delete_conf_item(conf); |
1564 |
> |
if (!conf->ref_count) |
1565 |
> |
conf_free(conf); |
1566 |
|
} |
1567 |
< |
else |
1567 |
> |
else if (conf->type == CONF_XLINE) |
1568 |
|
{ |
1569 |
< |
delete_conf_item(conf); |
1569 |
> |
if (!conf->until) |
1570 |
> |
conf_free(conf); |
1571 |
|
} |
1572 |
+ |
else |
1573 |
+ |
conf_free(conf); |
1574 |
|
} |
1575 |
|
} |
1576 |
|
|
1577 |
|
/* |
1578 |
|
* don't delete the class table, rather mark all entries |
1579 |
< |
* for deletion. The table is cleaned up by check_class. - avalon |
1579 |
> |
* for deletion. The table is cleaned up by class_delete_marked. - avalon |
1580 |
|
*/ |
1581 |
< |
DLINK_FOREACH(ptr, class_items.head) |
2391 |
< |
{ |
2392 |
< |
cltmp = map_to_conf(ptr->data); |
2393 |
< |
|
2394 |
< |
if (ptr != class_items.tail) /* never mark the "default" class */ |
2395 |
< |
cltmp->active = 0; |
2396 |
< |
} |
1581 |
> |
class_mark_for_deletion(); |
1582 |
|
|
1583 |
|
clear_out_address_conf(); |
1584 |
|
|
1614 |
|
SSL_OP_NO_TLSv1); |
1615 |
|
#endif |
1616 |
|
|
2432 |
– |
/* clean out old resvs from the conf */ |
2433 |
– |
clear_conf_resv(); |
2434 |
– |
|
1617 |
|
/* clean out AdminInfo */ |
1618 |
|
MyFree(AdminInfo.name); |
1619 |
|
AdminInfo.name = NULL; |
1622 |
|
MyFree(AdminInfo.description); |
1623 |
|
AdminInfo.description = NULL; |
1624 |
|
|
2443 |
– |
/* operator{} and class{} blocks are freed above */ |
1625 |
|
/* clean out listeners */ |
1626 |
|
close_listeners(); |
1627 |
|
|
2447 |
– |
/* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, |
2448 |
– |
* exempt{} and gecos{} blocks are freed above too |
2449 |
– |
*/ |
2450 |
– |
|
1628 |
|
/* clean out general */ |
1629 |
|
MyFree(ConfigFileEntry.service_name); |
1630 |
|
ConfigFileEntry.service_name = NULL; |
1633 |
|
delete_isupport("EXCEPTS"); |
1634 |
|
} |
1635 |
|
|
2459 |
– |
/* flush_deleted_I_P() |
2460 |
– |
* |
2461 |
– |
* inputs - none |
2462 |
– |
* output - none |
2463 |
– |
* side effects - This function removes I/P conf items |
2464 |
– |
*/ |
2465 |
– |
static void |
2466 |
– |
flush_deleted_I_P(void) |
2467 |
– |
{ |
2468 |
– |
dlink_node *ptr; |
2469 |
– |
dlink_node *next_ptr; |
2470 |
– |
struct ConfItem *conf; |
2471 |
– |
struct AccessItem *aconf; |
2472 |
– |
dlink_list * free_items [] = { |
2473 |
– |
&server_items, &oconf_items, NULL |
2474 |
– |
}; |
2475 |
– |
dlink_list ** iterator = free_items; /* C is dumb */ |
2476 |
– |
|
2477 |
– |
/* flush out deleted I and P lines |
2478 |
– |
* although still in use. |
2479 |
– |
*/ |
2480 |
– |
for (; *iterator != NULL; iterator++) |
2481 |
– |
{ |
2482 |
– |
DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head) |
2483 |
– |
{ |
2484 |
– |
conf = ptr->data; |
2485 |
– |
aconf = (struct AccessItem *)map_to_conf(conf); |
2486 |
– |
|
2487 |
– |
if (IsConfIllegal(aconf)) |
2488 |
– |
{ |
2489 |
– |
dlinkDelete(ptr, *iterator); |
2490 |
– |
|
2491 |
– |
if (aconf->clients == 0) |
2492 |
– |
delete_conf_item(conf); |
2493 |
– |
} |
2494 |
– |
} |
2495 |
– |
} |
2496 |
– |
} |
2497 |
– |
|
2498 |
– |
/* get_conf_name() |
2499 |
– |
* |
2500 |
– |
* inputs - type of conf file to return name of file for |
2501 |
– |
* output - pointer to filename for type of conf |
2502 |
– |
* side effects - none |
2503 |
– |
*/ |
2504 |
– |
const char * |
2505 |
– |
get_conf_name(ConfType type) |
2506 |
– |
{ |
2507 |
– |
switch (type) |
2508 |
– |
{ |
2509 |
– |
case CONF_TYPE: |
2510 |
– |
return ConfigFileEntry.configfile; |
2511 |
– |
break; |
2512 |
– |
case KLINE_TYPE: |
2513 |
– |
return ConfigFileEntry.klinefile; |
2514 |
– |
break; |
2515 |
– |
case DLINE_TYPE: |
2516 |
– |
return ConfigFileEntry.dlinefile; |
2517 |
– |
break; |
2518 |
– |
case XLINE_TYPE: |
2519 |
– |
return ConfigFileEntry.xlinefile; |
2520 |
– |
break; |
2521 |
– |
case CRESV_TYPE: |
2522 |
– |
return ConfigFileEntry.cresvfile; |
2523 |
– |
break; |
2524 |
– |
case NRESV_TYPE: |
2525 |
– |
return ConfigFileEntry.nresvfile; |
2526 |
– |
break; |
2527 |
– |
default: |
2528 |
– |
return NULL; /* This should NEVER HAPPEN since we call this function |
2529 |
– |
only with the above values, this will cause us to core |
2530 |
– |
at some point if this happens so we know where it was */ |
2531 |
– |
} |
2532 |
– |
} |
2533 |
– |
|
2534 |
– |
#define BAD_PING (-1) |
2535 |
– |
|
2536 |
– |
/* get_conf_ping() |
2537 |
– |
* |
2538 |
– |
* inputs - pointer to struct AccessItem |
2539 |
– |
* - pointer to a variable that receives ping warning time |
2540 |
– |
* output - ping frequency |
2541 |
– |
* side effects - NONE |
2542 |
– |
*/ |
2543 |
– |
static int |
2544 |
– |
get_conf_ping(struct ConfItem *conf, int *pingwarn) |
2545 |
– |
{ |
2546 |
– |
struct ClassItem *aclass; |
2547 |
– |
struct AccessItem *aconf; |
2548 |
– |
|
2549 |
– |
if (conf != NULL) |
2550 |
– |
{ |
2551 |
– |
aconf = (struct AccessItem *)map_to_conf(conf); |
2552 |
– |
if (aconf->class_ptr != NULL) |
2553 |
– |
{ |
2554 |
– |
aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr); |
2555 |
– |
*pingwarn = aclass->ping_warning; |
2556 |
– |
return aclass->ping_freq; |
2557 |
– |
} |
2558 |
– |
} |
2559 |
– |
|
2560 |
– |
return BAD_PING; |
2561 |
– |
} |
2562 |
– |
|
2563 |
– |
/* get_client_class() |
2564 |
– |
* |
2565 |
– |
* inputs - pointer to client struct |
2566 |
– |
* output - pointer to name of class |
2567 |
– |
* side effects - NONE |
2568 |
– |
*/ |
2569 |
– |
const char * |
2570 |
– |
get_client_class(struct Client *target_p) |
2571 |
– |
{ |
2572 |
– |
dlink_node *cnode = NULL; |
2573 |
– |
struct AccessItem *aconf = NULL; |
2574 |
– |
|
2575 |
– |
assert(!IsMe(target_p)); |
2576 |
– |
|
2577 |
– |
if ((cnode = target_p->localClient->confs.head)) |
2578 |
– |
{ |
2579 |
– |
struct ConfItem *conf = cnode->data; |
2580 |
– |
|
2581 |
– |
assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) || |
2582 |
– |
(conf->type == OPER_TYPE)); |
2583 |
– |
|
2584 |
– |
aconf = map_to_conf(conf); |
2585 |
– |
if (aconf->class_ptr != NULL) |
2586 |
– |
return aconf->class_ptr->name; |
2587 |
– |
} |
2588 |
– |
|
2589 |
– |
return "default"; |
2590 |
– |
} |
2591 |
– |
|
2592 |
– |
/* get_client_ping() |
2593 |
– |
* |
2594 |
– |
* inputs - pointer to client struct |
2595 |
– |
* - pointer to a variable that receives ping warning time |
2596 |
– |
* output - ping frequency |
2597 |
– |
* side effects - NONE |
2598 |
– |
*/ |
2599 |
– |
int |
2600 |
– |
get_client_ping(struct Client *target_p, int *pingwarn) |
2601 |
– |
{ |
2602 |
– |
int ping = 0; |
2603 |
– |
dlink_node *cnode = NULL; |
2604 |
– |
|
2605 |
– |
if ((cnode = target_p->localClient->confs.head)) |
2606 |
– |
{ |
2607 |
– |
struct ConfItem *conf = cnode->data; |
2608 |
– |
|
2609 |
– |
assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) || |
2610 |
– |
(conf->type == OPER_TYPE)); |
2611 |
– |
|
2612 |
– |
ping = get_conf_ping(conf, pingwarn); |
2613 |
– |
if (ping > 0) |
2614 |
– |
return ping; |
2615 |
– |
} |
2616 |
– |
|
2617 |
– |
*pingwarn = 0; |
2618 |
– |
return DEFAULT_PINGFREQUENCY; |
2619 |
– |
} |
2620 |
– |
|
2621 |
– |
/* find_class() |
2622 |
– |
* |
2623 |
– |
* inputs - string name of class |
2624 |
– |
* output - corresponding Class pointer |
2625 |
– |
* side effects - NONE |
2626 |
– |
*/ |
2627 |
– |
struct ConfItem * |
2628 |
– |
find_class(const char *classname) |
2629 |
– |
{ |
2630 |
– |
struct ConfItem *conf; |
2631 |
– |
|
2632 |
– |
if ((conf = find_exact_name_conf(CLASS_TYPE, NULL, classname, NULL, NULL)) != NULL) |
2633 |
– |
return conf; |
2634 |
– |
|
2635 |
– |
return class_default; |
2636 |
– |
} |
2637 |
– |
|
2638 |
– |
/* check_class() |
2639 |
– |
* |
2640 |
– |
* inputs - NONE |
2641 |
– |
* output - NONE |
2642 |
– |
* side effects - |
2643 |
– |
*/ |
2644 |
– |
void |
2645 |
– |
check_class(void) |
2646 |
– |
{ |
2647 |
– |
dlink_node *ptr = NULL, *next_ptr = NULL; |
2648 |
– |
|
2649 |
– |
DLINK_FOREACH_SAFE(ptr, next_ptr, class_items.head) |
2650 |
– |
{ |
2651 |
– |
struct ClassItem *aclass = map_to_conf(ptr->data); |
2652 |
– |
|
2653 |
– |
if (!aclass->active && !aclass->curr_user_count) |
2654 |
– |
{ |
2655 |
– |
destroy_cidr_class(aclass); |
2656 |
– |
delete_conf_item(ptr->data); |
2657 |
– |
} |
2658 |
– |
} |
2659 |
– |
} |
2660 |
– |
|
2661 |
– |
/* init_class() |
2662 |
– |
* |
2663 |
– |
* inputs - NONE |
2664 |
– |
* output - NONE |
2665 |
– |
* side effects - |
2666 |
– |
*/ |
2667 |
– |
void |
2668 |
– |
init_class(void) |
2669 |
– |
{ |
2670 |
– |
struct ClassItem *aclass; |
2671 |
– |
|
2672 |
– |
class_default = make_conf_item(CLASS_TYPE); |
2673 |
– |
|
2674 |
– |
aclass = map_to_conf(class_default); |
2675 |
– |
aclass->active = 1; |
2676 |
– |
DupString(class_default->name, "default"); |
2677 |
– |
aclass->con_freq = DEFAULT_CONNECTFREQUENCY; |
2678 |
– |
aclass->ping_freq = DEFAULT_PINGFREQUENCY; |
2679 |
– |
aclass->max_total = MAXIMUM_LINKS_DEFAULT; |
2680 |
– |
aclass->max_sendq = DEFAULT_SENDQ; |
2681 |
– |
aclass->max_recvq = DEFAULT_RECVQ; |
2682 |
– |
|
2683 |
– |
client_check_cb = register_callback("check_client", check_client); |
2684 |
– |
} |
2685 |
– |
|
2686 |
– |
/* get_sendq() |
2687 |
– |
* |
2688 |
– |
* inputs - pointer to client |
2689 |
– |
* output - sendq for this client as found from its class |
2690 |
– |
* side effects - NONE |
2691 |
– |
*/ |
2692 |
– |
unsigned int |
2693 |
– |
get_sendq(struct Client *client_p) |
2694 |
– |
{ |
2695 |
– |
unsigned int sendq = DEFAULT_SENDQ; |
2696 |
– |
dlink_node *cnode; |
2697 |
– |
struct ConfItem *class_conf; |
2698 |
– |
struct ClassItem *aclass; |
2699 |
– |
struct AccessItem *aconf; |
2700 |
– |
|
2701 |
– |
assert(!IsMe(client_p)); |
2702 |
– |
|
2703 |
– |
if ((cnode = client_p->localClient->confs.head)) |
2704 |
– |
{ |
2705 |
– |
struct ConfItem *conf = cnode->data; |
2706 |
– |
|
2707 |
– |
assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) || |
2708 |
– |
(conf->type == OPER_TYPE)); |
2709 |
– |
|
2710 |
– |
aconf = map_to_conf(conf); |
2711 |
– |
|
2712 |
– |
if ((class_conf = aconf->class_ptr) == NULL) |
2713 |
– |
return DEFAULT_SENDQ; /* TBV: shouldn't be possible at all */ |
2714 |
– |
|
2715 |
– |
aclass = map_to_conf(class_conf); |
2716 |
– |
sendq = aclass->max_sendq; |
2717 |
– |
return sendq; |
2718 |
– |
} |
2719 |
– |
|
2720 |
– |
/* XXX return a default? |
2721 |
– |
* if here, then there wasn't an attached conf with a sendq |
2722 |
– |
* that is very bad -Dianora |
2723 |
– |
*/ |
2724 |
– |
return DEFAULT_SENDQ; |
2725 |
– |
} |
2726 |
– |
|
2727 |
– |
unsigned int |
2728 |
– |
get_recvq(struct Client *client_p) |
2729 |
– |
{ |
2730 |
– |
unsigned int recvq = DEFAULT_RECVQ; |
2731 |
– |
dlink_node *cnode; |
2732 |
– |
struct ConfItem *class_conf; |
2733 |
– |
struct ClassItem *aclass; |
2734 |
– |
struct AccessItem *aconf; |
2735 |
– |
|
2736 |
– |
assert(!IsMe(client_p)); |
2737 |
– |
|
2738 |
– |
if ((cnode = client_p->localClient->confs.head)) |
2739 |
– |
{ |
2740 |
– |
struct ConfItem *conf = cnode->data; |
2741 |
– |
|
2742 |
– |
assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) || |
2743 |
– |
(conf->type == OPER_TYPE)); |
2744 |
– |
|
2745 |
– |
aconf = map_to_conf(conf); |
2746 |
– |
|
2747 |
– |
if ((class_conf = aconf->class_ptr) == NULL) |
2748 |
– |
return DEFAULT_RECVQ; /* TBV: shouldn't be possible at all */ |
2749 |
– |
|
2750 |
– |
aclass = map_to_conf(class_conf); |
2751 |
– |
recvq = aclass->max_recvq; |
2752 |
– |
return recvq; |
2753 |
– |
} |
2754 |
– |
|
2755 |
– |
/* XXX return a default? |
2756 |
– |
* if here, then there wasn't an attached conf with a recvq |
2757 |
– |
* that is very bad -Dianora |
2758 |
– |
*/ |
2759 |
– |
return DEFAULT_RECVQ; |
2760 |
– |
} |
2761 |
– |
|
1636 |
|
/* conf_add_class_to_conf() |
1637 |
|
* |
1638 |
|
* inputs - pointer to config item |
1640 |
|
* side effects - Add a class pointer to a conf |
1641 |
|
*/ |
1642 |
|
void |
1643 |
< |
conf_add_class_to_conf(struct ConfItem *conf, const char *class_name) |
1643 |
> |
conf_add_class_to_conf(struct MaskItem *conf, const char *class_name) |
1644 |
|
{ |
2771 |
– |
struct AccessItem *aconf = map_to_conf(conf); |
2772 |
– |
struct ClassItem *class = NULL; |
2773 |
– |
|
1645 |
|
if (class_name == NULL) |
1646 |
|
{ |
1647 |
< |
aconf->class_ptr = class_default; |
1647 |
> |
conf->class = class_default; |
1648 |
|
|
1649 |
< |
if (conf->type == CLIENT_TYPE) |
1649 |
> |
if (conf->type == CONF_CLIENT) |
1650 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1651 |
|
"Warning *** Defaulting to default class for %s@%s", |
1652 |
< |
aconf->user, aconf->host); |
1652 |
> |
conf->user, conf->host); |
1653 |
|
else |
1654 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1655 |
|
"Warning *** Defaulting to default class for %s", |
1656 |
|
conf->name); |
1657 |
|
} |
1658 |
|
else |
1659 |
< |
aconf->class_ptr = find_class(class_name); |
1659 |
> |
conf->class = class_find(class_name, 1); |
1660 |
|
|
1661 |
< |
if (aconf->class_ptr) |
2791 |
< |
class = map_to_conf(aconf->class_ptr); |
2792 |
< |
|
2793 |
< |
if (aconf->class_ptr == NULL || !class->active) |
1661 |
> |
if (conf->class == NULL) |
1662 |
|
{ |
1663 |
< |
if (conf->type == CLIENT_TYPE) |
1663 |
> |
if (conf->type == CONF_CLIENT) |
1664 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1665 |
|
"Warning *** Defaulting to default class for %s@%s", |
1666 |
< |
aconf->user, aconf->host); |
1666 |
> |
conf->user, conf->host); |
1667 |
|
else |
1668 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1669 |
|
"Warning *** Defaulting to default class for %s", |
1670 |
|
conf->name); |
1671 |
< |
aconf->class_ptr = class_default; |
1671 |
> |
conf->class = class_default; |
1672 |
|
} |
1673 |
|
} |
1674 |
|
|
2807 |
– |
/* conf_add_server() |
2808 |
– |
* |
2809 |
– |
* inputs - pointer to config item |
2810 |
– |
* - pointer to link count already on this conf |
2811 |
– |
* output - NONE |
2812 |
– |
* side effects - Add a connect block |
2813 |
– |
*/ |
2814 |
– |
int |
2815 |
– |
conf_add_server(struct ConfItem *conf, const char *class_name) |
2816 |
– |
{ |
2817 |
– |
struct AccessItem *aconf = map_to_conf(conf); |
2818 |
– |
|
2819 |
– |
conf_add_class_to_conf(conf, class_name); |
2820 |
– |
|
2821 |
– |
if (!aconf->host || !conf->name) |
2822 |
– |
{ |
2823 |
– |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
2824 |
– |
"Bad connect block"); |
2825 |
– |
ilog(LOG_TYPE_IRCD, "Bad connect block"); |
2826 |
– |
return -1; |
2827 |
– |
} |
2828 |
– |
|
2829 |
– |
if (EmptyString(aconf->passwd)) |
2830 |
– |
{ |
2831 |
– |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
2832 |
– |
"Bad connect block, name %s", |
2833 |
– |
conf->name); |
2834 |
– |
ilog(LOG_TYPE_IRCD, "Bad connect block, host %s", conf->name); |
2835 |
– |
return -1; |
2836 |
– |
} |
2837 |
– |
|
2838 |
– |
lookup_confhost(conf); |
2839 |
– |
|
2840 |
– |
return 0; |
2841 |
– |
} |
2842 |
– |
|
1675 |
|
/* yyerror() |
1676 |
|
* |
1677 |
|
* inputs - message from parser |
1687 |
|
return; |
1688 |
|
|
1689 |
|
strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf)); |
1690 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1690 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1691 |
> |
"\"%s\", line %u: %s: %s", |
1692 |
> |
conffilebuf, lineno + 1, msg, newlinebuf); |
1693 |
> |
ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s", |
1694 |
> |
conffilebuf, lineno + 1, msg, newlinebuf); |
1695 |
> |
} |
1696 |
> |
|
1697 |
> |
void |
1698 |
> |
conf_error_report(const char *msg) |
1699 |
> |
{ |
1700 |
> |
char newlinebuf[IRCD_BUFSIZE]; |
1701 |
> |
|
1702 |
> |
strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf)); |
1703 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
1704 |
|
"\"%s\", line %u: %s: %s", |
1705 |
|
conffilebuf, lineno + 1, msg, newlinebuf); |
1706 |
|
ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s", |
1754 |
|
return result; |
1755 |
|
} |
1756 |
|
|
1757 |
+ |
/* valid_wild_card_simple() |
1758 |
+ |
* |
1759 |
+ |
* inputs - data to check for sufficient non-wildcard characters |
1760 |
+ |
* outputs - 1 if valid, else 0 |
1761 |
+ |
* side effects - none |
1762 |
+ |
*/ |
1763 |
+ |
int |
1764 |
+ |
valid_wild_card_simple(const char *data) |
1765 |
+ |
{ |
1766 |
+ |
const unsigned char *p = (const unsigned char *)data; |
1767 |
+ |
unsigned char tmpch = '\0'; |
1768 |
+ |
int nonwild = 0; |
1769 |
+ |
|
1770 |
+ |
while ((tmpch = *p++)) |
1771 |
+ |
{ |
1772 |
+ |
if (tmpch == '\\') |
1773 |
+ |
{ |
1774 |
+ |
++p; |
1775 |
+ |
if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple) |
1776 |
+ |
return 1; |
1777 |
+ |
} |
1778 |
+ |
else if (!IsMWildChar(tmpch)) |
1779 |
+ |
{ |
1780 |
+ |
if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple) |
1781 |
+ |
return 1; |
1782 |
+ |
} |
1783 |
+ |
} |
1784 |
+ |
|
1785 |
+ |
return 0; |
1786 |
+ |
} |
1787 |
+ |
|
1788 |
|
/* valid_wild_card() |
1789 |
|
* |
1790 |
|
* input - pointer to client |
1796 |
|
int |
1797 |
|
valid_wild_card(struct Client *source_p, int warn, int count, ...) |
1798 |
|
{ |
2923 |
– |
char *p; |
1799 |
|
char tmpch; |
1800 |
|
int nonwild = 0; |
1801 |
|
va_list args; |
1816 |
|
|
1817 |
|
while (count--) |
1818 |
|
{ |
1819 |
< |
p = va_arg(args, char *); |
1819 |
> |
const char *p = va_arg(args, const char *); |
1820 |
|
if (p == NULL) |
1821 |
|
continue; |
1822 |
|
|
2090 |
|
int |
2091 |
|
valid_comment(struct Client *source_p, char *comment, int warn) |
2092 |
|
{ |
3218 |
– |
if (strchr(comment, '"')) |
3219 |
– |
{ |
3220 |
– |
if (warn) |
3221 |
– |
sendto_one(source_p, ":%s NOTICE %s :Invalid character '\"' in comment", |
3222 |
– |
me.name, source_p->name); |
3223 |
– |
return 0; |
3224 |
– |
} |
3225 |
– |
|
2093 |
|
if (strlen(comment) > REASONLEN) |
2094 |
|
comment[REASONLEN-1] = '\0'; |
2095 |
|
|
2104 |
|
* side effects - none |
2105 |
|
*/ |
2106 |
|
int |
2107 |
< |
match_conf_password(const char *password, const struct AccessItem *aconf) |
2107 |
> |
match_conf_password(const char *password, const struct MaskItem *conf) |
2108 |
|
{ |
2109 |
|
const char *encr = NULL; |
2110 |
|
|
2111 |
< |
if (EmptyString(password) || EmptyString(aconf->passwd)) |
2111 |
> |
if (EmptyString(password) || EmptyString(conf->passwd)) |
2112 |
|
return 0; |
2113 |
|
|
2114 |
< |
if (aconf->flags & CONF_FLAGS_ENCRYPTED) |
2115 |
< |
encr = crypt(password, aconf->passwd); |
2114 |
> |
if (conf->flags & CONF_FLAGS_ENCRYPTED) |
2115 |
> |
encr = crypt(password, conf->passwd); |
2116 |
|
else |
2117 |
|
encr = password; |
2118 |
|
|
2119 |
< |
return !strcmp(encr, aconf->passwd); |
2119 |
> |
return !strcmp(encr, conf->passwd); |
2120 |
|
} |
2121 |
|
|
2122 |
|
/* |
2145 |
|
|
2146 |
|
DLINK_FOREACH(ptr, cluster_items.head) |
2147 |
|
{ |
2148 |
< |
const struct ConfItem *conf = ptr->data; |
2148 |
> |
const struct MaskItem *conf = ptr->data; |
2149 |
|
|
2150 |
|
if (conf->flags & cluster_type) |
2151 |
|
sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab, |
2239 |
|
} |
2240 |
|
} |
2241 |
|
} |
3375 |
– |
|
3376 |
– |
/* |
3377 |
– |
* flags_to_ascii |
3378 |
– |
* |
3379 |
– |
* inputs - flags is a bitmask |
3380 |
– |
* - pointer to table of ascii letters corresponding |
3381 |
– |
* to each bit |
3382 |
– |
* - flag 1 for convert ToLower if bit missing |
3383 |
– |
* 0 if ignore. |
3384 |
– |
* output - none |
3385 |
– |
* side effects - string pointed to by p has bitmap chars written to it |
3386 |
– |
*/ |
3387 |
– |
static void |
3388 |
– |
flags_to_ascii(unsigned int flags, const unsigned int bit_table[], char *p, |
3389 |
– |
int lowerit) |
3390 |
– |
{ |
3391 |
– |
unsigned int mask = 1; |
3392 |
– |
int i = 0; |
3393 |
– |
|
3394 |
– |
for (mask = 1; (mask != 0) && (bit_table[i] != 0); mask <<= 1, i++) |
3395 |
– |
{ |
3396 |
– |
if (flags & mask) |
3397 |
– |
*p++ = bit_table[i]; |
3398 |
– |
else if (lowerit) |
3399 |
– |
*p++ = ToLower(bit_table[i]); |
3400 |
– |
} |
3401 |
– |
*p = '\0'; |
3402 |
– |
} |
3403 |
– |
|
3404 |
– |
/* |
3405 |
– |
* cidr_limit_reached |
3406 |
– |
* |
3407 |
– |
* inputs - int flag allowing over_rule of limits |
3408 |
– |
* - pointer to the ip to be added |
3409 |
– |
* - pointer to the class |
3410 |
– |
* output - non zero if limit reached |
3411 |
– |
* 0 if limit not reached |
3412 |
– |
* side effects - |
3413 |
– |
*/ |
3414 |
– |
static int |
3415 |
– |
cidr_limit_reached(int over_rule, |
3416 |
– |
struct irc_ssaddr *ip, struct ClassItem *aclass) |
3417 |
– |
{ |
3418 |
– |
dlink_node *ptr = NULL; |
3419 |
– |
struct CidrItem *cidr; |
3420 |
– |
|
3421 |
– |
if (aclass->number_per_cidr <= 0) |
3422 |
– |
return 0; |
3423 |
– |
|
3424 |
– |
if (ip->ss.ss_family == AF_INET) |
3425 |
– |
{ |
3426 |
– |
if (aclass->cidr_bitlen_ipv4 <= 0) |
3427 |
– |
return 0; |
3428 |
– |
|
3429 |
– |
DLINK_FOREACH(ptr, aclass->list_ipv4.head) |
3430 |
– |
{ |
3431 |
– |
cidr = ptr->data; |
3432 |
– |
if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4)) |
3433 |
– |
{ |
3434 |
– |
if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr)) |
3435 |
– |
return -1; |
3436 |
– |
cidr->number_on_this_cidr++; |
3437 |
– |
return 0; |
3438 |
– |
} |
3439 |
– |
} |
3440 |
– |
cidr = MyMalloc(sizeof(struct CidrItem)); |
3441 |
– |
cidr->number_on_this_cidr = 1; |
3442 |
– |
cidr->mask = *ip; |
3443 |
– |
mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv4); |
3444 |
– |
dlinkAdd(cidr, &cidr->node, &aclass->list_ipv4); |
3445 |
– |
} |
3446 |
– |
#ifdef IPV6 |
3447 |
– |
else if (aclass->cidr_bitlen_ipv6 > 0) |
3448 |
– |
{ |
3449 |
– |
DLINK_FOREACH(ptr, aclass->list_ipv6.head) |
3450 |
– |
{ |
3451 |
– |
cidr = ptr->data; |
3452 |
– |
if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6)) |
3453 |
– |
{ |
3454 |
– |
if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr)) |
3455 |
– |
return -1; |
3456 |
– |
cidr->number_on_this_cidr++; |
3457 |
– |
return 0; |
3458 |
– |
} |
3459 |
– |
} |
3460 |
– |
cidr = MyMalloc(sizeof(struct CidrItem)); |
3461 |
– |
cidr->number_on_this_cidr = 1; |
3462 |
– |
cidr->mask = *ip; |
3463 |
– |
mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv6); |
3464 |
– |
dlinkAdd(cidr, &cidr->node, &aclass->list_ipv6); |
3465 |
– |
} |
3466 |
– |
#endif |
3467 |
– |
return 0; |
3468 |
– |
} |
3469 |
– |
|
3470 |
– |
/* |
3471 |
– |
* remove_from_cidr_check |
3472 |
– |
* |
3473 |
– |
* inputs - pointer to the ip to be removed |
3474 |
– |
* - pointer to the class |
3475 |
– |
* output - NONE |
3476 |
– |
* side effects - |
3477 |
– |
*/ |
3478 |
– |
static void |
3479 |
– |
remove_from_cidr_check(struct irc_ssaddr *ip, struct ClassItem *aclass) |
3480 |
– |
{ |
3481 |
– |
dlink_node *ptr = NULL; |
3482 |
– |
dlink_node *next_ptr = NULL; |
3483 |
– |
struct CidrItem *cidr; |
3484 |
– |
|
3485 |
– |
if (aclass->number_per_cidr == 0) |
3486 |
– |
return; |
3487 |
– |
|
3488 |
– |
if (ip->ss.ss_family == AF_INET) |
3489 |
– |
{ |
3490 |
– |
if (aclass->cidr_bitlen_ipv4 <= 0) |
3491 |
– |
return; |
3492 |
– |
|
3493 |
– |
DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head) |
3494 |
– |
{ |
3495 |
– |
cidr = ptr->data; |
3496 |
– |
if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4)) |
3497 |
– |
{ |
3498 |
– |
cidr->number_on_this_cidr--; |
3499 |
– |
if (cidr->number_on_this_cidr == 0) |
3500 |
– |
{ |
3501 |
– |
dlinkDelete(ptr, &aclass->list_ipv4); |
3502 |
– |
MyFree(cidr); |
3503 |
– |
return; |
3504 |
– |
} |
3505 |
– |
} |
3506 |
– |
} |
3507 |
– |
} |
3508 |
– |
#ifdef IPV6 |
3509 |
– |
else if (aclass->cidr_bitlen_ipv6 > 0) |
3510 |
– |
{ |
3511 |
– |
DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head) |
3512 |
– |
{ |
3513 |
– |
cidr = ptr->data; |
3514 |
– |
if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6)) |
3515 |
– |
{ |
3516 |
– |
cidr->number_on_this_cidr--; |
3517 |
– |
if (cidr->number_on_this_cidr == 0) |
3518 |
– |
{ |
3519 |
– |
dlinkDelete(ptr, &aclass->list_ipv6); |
3520 |
– |
MyFree(cidr); |
3521 |
– |
return; |
3522 |
– |
} |
3523 |
– |
} |
3524 |
– |
} |
3525 |
– |
} |
3526 |
– |
#endif |
3527 |
– |
} |
3528 |
– |
|
3529 |
– |
static void |
3530 |
– |
rebuild_cidr_list(int aftype, struct ConfItem *oldcl, struct ClassItem *newcl, |
3531 |
– |
dlink_list *old_list, dlink_list *new_list, int changed) |
3532 |
– |
{ |
3533 |
– |
dlink_node *ptr; |
3534 |
– |
struct Client *client_p; |
3535 |
– |
struct ConfItem *conf; |
3536 |
– |
struct AccessItem *aconf; |
3537 |
– |
|
3538 |
– |
if (!changed) |
3539 |
– |
{ |
3540 |
– |
*new_list = *old_list; |
3541 |
– |
old_list->head = old_list->tail = NULL; |
3542 |
– |
old_list->length = 0; |
3543 |
– |
return; |
3544 |
– |
} |
3545 |
– |
|
3546 |
– |
DLINK_FOREACH(ptr, local_client_list.head) |
3547 |
– |
{ |
3548 |
– |
client_p = ptr->data; |
3549 |
– |
if (client_p->localClient->aftype != aftype) |
3550 |
– |
continue; |
3551 |
– |
if (dlink_list_length(&client_p->localClient->confs) == 0) |
3552 |
– |
continue; |
3553 |
– |
|
3554 |
– |
conf = client_p->localClient->confs.tail->data; |
3555 |
– |
if (conf->type == CLIENT_TYPE) |
3556 |
– |
{ |
3557 |
– |
aconf = map_to_conf(conf); |
3558 |
– |
if (aconf->class_ptr == oldcl) |
3559 |
– |
cidr_limit_reached(1, &client_p->localClient->ip, newcl); |
3560 |
– |
} |
3561 |
– |
} |
3562 |
– |
} |
3563 |
– |
|
3564 |
– |
/* |
3565 |
– |
* rebuild_cidr_class |
3566 |
– |
* |
3567 |
– |
* inputs - pointer to old conf |
3568 |
– |
* - pointer to new_class |
3569 |
– |
* output - none |
3570 |
– |
* side effects - rebuilds the class link list of cidr blocks |
3571 |
– |
*/ |
3572 |
– |
void |
3573 |
– |
rebuild_cidr_class(struct ConfItem *conf, struct ClassItem *new_class) |
3574 |
– |
{ |
3575 |
– |
struct ClassItem *old_class = map_to_conf(conf); |
3576 |
– |
|
3577 |
– |
if (old_class->number_per_cidr > 0 && new_class->number_per_cidr > 0) |
3578 |
– |
{ |
3579 |
– |
if (old_class->cidr_bitlen_ipv4 > 0 && new_class->cidr_bitlen_ipv4 > 0) |
3580 |
– |
rebuild_cidr_list(AF_INET, conf, new_class, |
3581 |
– |
&old_class->list_ipv4, &new_class->list_ipv4, |
3582 |
– |
old_class->cidr_bitlen_ipv4 != new_class->cidr_bitlen_ipv4); |
3583 |
– |
|
3584 |
– |
#ifdef IPV6 |
3585 |
– |
if (old_class->cidr_bitlen_ipv6 > 0 && new_class->cidr_bitlen_ipv6 > 0) |
3586 |
– |
rebuild_cidr_list(AF_INET6, conf, new_class, |
3587 |
– |
&old_class->list_ipv6, &new_class->list_ipv6, |
3588 |
– |
old_class->cidr_bitlen_ipv6 != new_class->cidr_bitlen_ipv6); |
3589 |
– |
#endif |
3590 |
– |
} |
3591 |
– |
|
3592 |
– |
destroy_cidr_class(old_class); |
3593 |
– |
} |
3594 |
– |
|
3595 |
– |
/* |
3596 |
– |
* destroy_cidr_list |
3597 |
– |
* |
3598 |
– |
* inputs - pointer to class dlink list of cidr blocks |
3599 |
– |
* output - none |
3600 |
– |
* side effects - completely destroys the class link list of cidr blocks |
3601 |
– |
*/ |
3602 |
– |
static void |
3603 |
– |
destroy_cidr_list(dlink_list *list) |
3604 |
– |
{ |
3605 |
– |
dlink_node *ptr = NULL, *next_ptr = NULL; |
3606 |
– |
|
3607 |
– |
DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) |
3608 |
– |
{ |
3609 |
– |
dlinkDelete(ptr, list); |
3610 |
– |
MyFree(ptr->data); |
3611 |
– |
} |
3612 |
– |
} |
3613 |
– |
|
3614 |
– |
/* |
3615 |
– |
* destroy_cidr_class |
3616 |
– |
* |
3617 |
– |
* inputs - pointer to class |
3618 |
– |
* output - none |
3619 |
– |
* side effects - completely destroys the class link list of cidr blocks |
3620 |
– |
*/ |
3621 |
– |
static void |
3622 |
– |
destroy_cidr_class(struct ClassItem *aclass) |
3623 |
– |
{ |
3624 |
– |
destroy_cidr_list(&aclass->list_ipv4); |
3625 |
– |
destroy_cidr_list(&aclass->list_ipv6); |
3626 |
– |
} |