1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* conf.h: A header for the configuration functions. |
4 |
* |
5 |
* Copyright (C) 2005 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#ifndef INCLUDED_s_conf_h |
26 |
#define INCLUDED_s_conf_h |
27 |
#include "config.h" |
28 |
#ifdef HAVE_LIBCRYPTO |
29 |
#include <openssl/rsa.h> |
30 |
#endif |
31 |
#include "ircd_defs.h" |
32 |
#include "motd.h" /* MessageFile */ |
33 |
#include "client.h" |
34 |
#include "hook.h" |
35 |
|
36 |
|
37 |
struct Client; |
38 |
|
39 |
extern struct Callback *client_check_cb; |
40 |
|
41 |
struct conf_parser_context |
42 |
{ |
43 |
unsigned int boot; |
44 |
unsigned int pass; |
45 |
FILE *conf_file; |
46 |
}; |
47 |
|
48 |
extern struct conf_parser_context conf_parser_ctx; |
49 |
|
50 |
typedef enum |
51 |
{ |
52 |
CONF_TYPE, |
53 |
CLASS_TYPE, |
54 |
OPER_TYPE, |
55 |
CLIENT_TYPE, |
56 |
SERVER_TYPE, |
57 |
HUB_TYPE, |
58 |
LEAF_TYPE, |
59 |
KLINE_TYPE, |
60 |
DLINE_TYPE, |
61 |
EXEMPTDLINE_TYPE, |
62 |
CLUSTER_TYPE, |
63 |
RKLINE_TYPE, |
64 |
RXLINE_TYPE, |
65 |
XLINE_TYPE, |
66 |
ULINE_TYPE, |
67 |
GLINE_TYPE, |
68 |
CRESV_TYPE, |
69 |
NRESV_TYPE, |
70 |
SERVICE_TYPE |
71 |
} ConfType; |
72 |
|
73 |
struct split_nuh_item |
74 |
{ |
75 |
dlink_node node; |
76 |
|
77 |
char *nuhmask; |
78 |
char *nickptr; |
79 |
char *userptr; |
80 |
char *hostptr; |
81 |
|
82 |
size_t nicksize; |
83 |
size_t usersize; |
84 |
size_t hostsize; |
85 |
}; |
86 |
|
87 |
struct ConfItem |
88 |
{ |
89 |
dlink_node node; /* link into known ConfItems of this type */ |
90 |
|
91 |
char *name; /* Primary key */ |
92 |
void *regexpname; |
93 |
unsigned int flags; |
94 |
ConfType type; |
95 |
}; |
96 |
|
97 |
/* |
98 |
* MatchItem - used for XLINE and ULINE types |
99 |
*/ |
100 |
struct MatchItem |
101 |
{ |
102 |
char *user; /* Used for ULINE only */ |
103 |
char *host; /* Used for ULINE only */ |
104 |
char *reason; |
105 |
char *oper_reason; |
106 |
int action; /* used for uline */ |
107 |
int count; /* How many times this matchitem has been matched */ |
108 |
int ref_count; /* How many times is this matchitem in use */ |
109 |
int illegal; /* Should it be deleted when possible? */ |
110 |
unsigned int flags; |
111 |
time_t hold; /* Hold action until this time (calendar time) */ |
112 |
time_t setat; |
113 |
}; |
114 |
|
115 |
struct AccessItem |
116 |
{ |
117 |
dlink_node node; |
118 |
unsigned int dns_failed; |
119 |
unsigned int dns_pending; |
120 |
unsigned int status; /* If CONF_ILLEGAL, delete when no clients */ |
121 |
unsigned int flags; |
122 |
unsigned int modes; |
123 |
unsigned int port; |
124 |
int clients; /* Number of *LOCAL* clients using this */ |
125 |
int bits; |
126 |
int type; |
127 |
struct irc_ssaddr bind; /* ip to bind to for outgoing connect */ |
128 |
struct irc_ssaddr addr; /* ip to connect to */ |
129 |
char * host; /* host part of user@host */ |
130 |
char * passwd; |
131 |
char * spasswd; /* Password to send. */ |
132 |
char * reason; |
133 |
char * user; /* user part of user@host */ |
134 |
time_t hold; /* Hold action until this time (calendar time) */ |
135 |
time_t setat; |
136 |
struct ConfItem *class_ptr; /* Class of connection */ |
137 |
int aftype; |
138 |
#ifdef HAVE_LIBCRYPTO |
139 |
/* certs */ |
140 |
char *cipher_list; |
141 |
char * rsa_public_key_file; |
142 |
RSA * rsa_public_key; |
143 |
#endif |
144 |
void *regexuser; |
145 |
void *regexhost; |
146 |
dlink_list leaf_list; |
147 |
dlink_list hub_list; |
148 |
}; |
149 |
|
150 |
struct ClassItem |
151 |
{ |
152 |
dlink_list list_ipv4; /* base of per cidr ipv4 client link list */ |
153 |
dlink_list list_ipv6; /* base of per cidr ipv6 client link list */ |
154 |
unsigned int max_sendq; |
155 |
unsigned int max_recvq; |
156 |
int con_freq; |
157 |
int ping_freq; |
158 |
int ping_warning; |
159 |
int max_total; |
160 |
int max_local; |
161 |
int max_global; |
162 |
int max_ident; |
163 |
int max_perip; |
164 |
int curr_user_count; |
165 |
int cidr_bitlen_ipv4; |
166 |
int cidr_bitlen_ipv6; |
167 |
int number_per_cidr; |
168 |
int active; |
169 |
}; |
170 |
|
171 |
struct CidrItem |
172 |
{ |
173 |
dlink_node node; |
174 |
struct irc_ssaddr mask; |
175 |
int number_on_this_cidr; |
176 |
}; |
177 |
|
178 |
|
179 |
#define CONF_ILLEGAL 0x80000000 |
180 |
#define CONF_RESERVED 0x00000001 |
181 |
#define CONF_CLIENT 0x00000002 |
182 |
#define CONF_SERVER 0x00000004 |
183 |
#define CONF_OPERATOR 0x00000008 |
184 |
#define CONF_KLINE 0x00000010 |
185 |
#define CONF_CLASS 0x00000020 |
186 |
#define CONF_DLINE 0x00000040 |
187 |
#define CONF_XLINE 0x00000080 |
188 |
#define CONF_ULINE 0x00000100 |
189 |
#define CONF_EXEMPTDLINE 0x00000200 |
190 |
#define CONF_GLINE 0x00000400 |
191 |
#define CONF_SERVICE 0x00000800 |
192 |
|
193 |
#define CONF_SERVER_MASK CONF_SERVER |
194 |
#define CONF_CLIENT_MASK (CONF_CLIENT | CONF_OPERATOR | CONF_SERVER_MASK) |
195 |
|
196 |
/* XXX temporary hack */ |
197 |
#define CONF_CRESV 0x80000001 |
198 |
#define CONF_NRESV 0x80000002 |
199 |
|
200 |
#define IsConfIllegal(x) ((x)->status & CONF_ILLEGAL) |
201 |
#define SetConfIllegal(x) ((x)->status |= CONF_ILLEGAL) |
202 |
#define IsConfServer(x) ((x)->status == CONF_SERVER) |
203 |
#define SetConfServer(x) ((x)->status = CONF_SERVER) |
204 |
#define IsConfOperator(x) ((x)->status & CONF_OPERATOR) |
205 |
#define IsConfKill(x) ((x)->status == CONF_KLINE) |
206 |
#define IsConfClient(x) ((x)->status & CONF_CLIENT) |
207 |
#define IsConfUline(x) ((x)->status & CONF_ULINE) |
208 |
#define IsConfXline(x) ((x)->status & CONF_XLINE) |
209 |
#define IsConfGline(x) ((x)->status == CONF_GLINE) |
210 |
|
211 |
/* AccessItem->flags */ |
212 |
|
213 |
/* Generic flags... */ |
214 |
/* access flags... */ |
215 |
#define CONF_FLAGS_DO_IDENTD 0x00000001 |
216 |
#define CONF_FLAGS_LIMIT_IP 0x00000002 |
217 |
#define CONF_FLAGS_NO_TILDE 0x00000004 |
218 |
#define CONF_FLAGS_NEED_IDENTD 0x00000008 |
219 |
#define CONF_FLAGS_NOMATCH_IP 0x00000010 |
220 |
#define CONF_FLAGS_EXEMPTKLINE 0x00000020 |
221 |
#define CONF_FLAGS_NOLIMIT 0x00000040 |
222 |
#define CONF_FLAGS_SPOOF_IP 0x00000080 |
223 |
#define CONF_FLAGS_SPOOF_NOTICE 0x00000100 |
224 |
#define CONF_FLAGS_REDIR 0x00000200 |
225 |
#define CONF_FLAGS_EXEMPTGLINE 0x00000400 |
226 |
#define CONF_FLAGS_CAN_FLOOD 0x00000800 |
227 |
#define CONF_FLAGS_NEED_PASSWORD 0x00001000 |
228 |
/* server flags */ |
229 |
#define CONF_FLAGS_ALLOW_AUTO_CONN 0x00002000 |
230 |
#define CONF_FLAGS_ENCRYPTED 0x00004000 |
231 |
#define CONF_FLAGS_IN_DATABASE 0x00008000 |
232 |
#define CONF_FLAGS_EXEMPTRESV 0x00010000 |
233 |
#define CONF_FLAGS_SSL 0x00020000 |
234 |
#define CONF_FLAGS_MAINCONF 0x00040000 |
235 |
|
236 |
/* Macros for struct AccessItem */ |
237 |
#define IsLimitIp(x) ((x)->flags & CONF_FLAGS_LIMIT_IP) |
238 |
#define IsNoTilde(x) ((x)->flags & CONF_FLAGS_NO_TILDE) |
239 |
#define IsConfCanFlood(x) ((x)->flags & CONF_FLAGS_CAN_FLOOD) |
240 |
#define IsNeedPassword(x) ((x)->flags & CONF_FLAGS_NEED_PASSWORD) |
241 |
#define IsNeedIdentd(x) ((x)->flags & CONF_FLAGS_NEED_IDENTD) |
242 |
#define IsNoMatchIp(x) ((x)->flags & CONF_FLAGS_NOMATCH_IP) |
243 |
#define IsConfExemptKline(x) ((x)->flags & CONF_FLAGS_EXEMPTKLINE) |
244 |
#define IsConfExemptLimits(x) ((x)->flags & CONF_FLAGS_NOLIMIT) |
245 |
#define IsConfExemptGline(x) ((x)->flags & CONF_FLAGS_EXEMPTGLINE) |
246 |
#define IsConfExemptResv(x) ((x)->flags & CONF_FLAGS_EXEMPTRESV) |
247 |
#define IsConfDoIdentd(x) ((x)->flags & CONF_FLAGS_DO_IDENTD) |
248 |
#define IsConfDoSpoofIp(x) ((x)->flags & CONF_FLAGS_SPOOF_IP) |
249 |
#define IsConfSpoofNotice(x) ((x)->flags & CONF_FLAGS_SPOOF_NOTICE) |
250 |
#define IsConfEncrypted(x) ((x)->flags & CONF_FLAGS_ENCRYPTED) |
251 |
#define SetConfEncrypted(x) ((x)->flags |= CONF_FLAGS_ENCRYPTED) |
252 |
#define ClearConfEncrypted(x) ((x)->flags &= ~CONF_FLAGS_ENCRYPTED) |
253 |
#define IsConfAllowAutoConn(x) ((x)->flags & CONF_FLAGS_ALLOW_AUTO_CONN) |
254 |
#define SetConfAllowAutoConn(x) ((x)->flags |= CONF_FLAGS_ALLOW_AUTO_CONN) |
255 |
#define ClearConfAllowAutoConn(x) ((x)->flags &= ~CONF_FLAGS_ALLOW_AUTO_CONN) |
256 |
#define IsConfRedir(x) ((x)->flags & CONF_FLAGS_REDIR) |
257 |
#define IsConfSSL(x) ((x)->flags & CONF_FLAGS_SSL) |
258 |
#define SetConfSSL(x) ((x)->flags |= CONF_FLAGS_SSL) |
259 |
#define ClearConfSSL(x) ((x)->flags &= ~CONF_FLAGS_SSL) |
260 |
#define IsConfDatabase(x) ((x)->flags & CONF_FLAGS_IN_DATABASE) |
261 |
#define SetConfDatabase(x) ((x)->flags |= CONF_FLAGS_IN_DATABASE) |
262 |
|
263 |
|
264 |
/* shared/cluster server entry types |
265 |
* These defines are used for both shared and cluster. |
266 |
*/ |
267 |
#define SHARED_KLINE 0x0001 |
268 |
#define SHARED_UNKLINE 0x0002 |
269 |
#define SHARED_XLINE 0x0004 |
270 |
#define SHARED_UNXLINE 0x0008 |
271 |
#define SHARED_RESV 0x0010 |
272 |
#define SHARED_UNRESV 0x0020 |
273 |
#define SHARED_LOCOPS 0x0040 |
274 |
#define SHARED_DLINE 0x0080 |
275 |
#define SHARED_UNDLINE 0x0100 |
276 |
#define SHARED_ALL (SHARED_KLINE | SHARED_UNKLINE |\ |
277 |
SHARED_XLINE | SHARED_UNXLINE |\ |
278 |
SHARED_RESV | SHARED_UNRESV |\ |
279 |
SHARED_LOCOPS | SHARED_DLINE | SHARED_UNDLINE) |
280 |
|
281 |
struct config_file_entry |
282 |
{ |
283 |
const char *dpath; /* DPATH if set from command line */ |
284 |
const char *configfile; |
285 |
const char *klinefile; |
286 |
const char *xlinefile; |
287 |
const char *dlinefile; |
288 |
const char *cresvfile; |
289 |
const char *nresvfile; |
290 |
|
291 |
char *egdpool_path; |
292 |
char *service_name; |
293 |
|
294 |
MessageFile motd; |
295 |
MessageFile linksfile; |
296 |
|
297 |
int gline_min_cidr; |
298 |
int gline_min_cidr6; |
299 |
int dots_in_ident; |
300 |
int failed_oper_notice; |
301 |
int anti_spam_exit_message_time; |
302 |
unsigned int max_accept; |
303 |
unsigned int max_watch; |
304 |
int max_nick_time; |
305 |
unsigned int max_nick_changes; |
306 |
int ts_max_delta; |
307 |
int ts_warn_delta; |
308 |
int anti_nick_flood; |
309 |
int warn_no_nline; |
310 |
int invisible_on_connect; |
311 |
int stats_e_disabled; |
312 |
int stats_o_oper_only; |
313 |
int stats_k_oper_only; |
314 |
int stats_i_oper_only; |
315 |
int stats_P_oper_only; |
316 |
int short_motd; |
317 |
int no_oper_flood; |
318 |
int true_no_oper_flood; |
319 |
int oper_pass_resv; |
320 |
int glines; |
321 |
int hide_spoof_ips; |
322 |
int tkline_expire_notices; |
323 |
int opers_bypass_callerid; |
324 |
int ignore_bogus_ts; |
325 |
int pace_wait; |
326 |
int pace_wait_simple; |
327 |
int gline_time; |
328 |
int gline_request_time; |
329 |
int oper_only_umodes; |
330 |
int oper_umodes; |
331 |
int max_targets; |
332 |
int caller_id_wait; |
333 |
int min_nonwildcard; |
334 |
int min_nonwildcard_simple; |
335 |
int kill_chase_time_limit; |
336 |
int default_floodcount; |
337 |
/* 0 == don't use throttle... */ |
338 |
int throttle_time; |
339 |
int use_egd; |
340 |
int ping_cookie; |
341 |
int disable_auth; |
342 |
int disable_remote; |
343 |
}; |
344 |
|
345 |
struct config_channel_entry |
346 |
{ |
347 |
int disable_fake_channels; |
348 |
int restrict_channels; |
349 |
int knock_delay; |
350 |
int knock_delay_channel; |
351 |
unsigned int max_bans; |
352 |
unsigned int max_chans_per_user; |
353 |
unsigned int max_chans_per_oper; |
354 |
int no_create_on_split; |
355 |
int no_join_on_split; |
356 |
int quiet_on_ban; |
357 |
int default_split_server_count; |
358 |
int default_split_user_count; |
359 |
}; |
360 |
|
361 |
struct config_server_hide |
362 |
{ |
363 |
char *hidden_name; |
364 |
int flatten_links; |
365 |
int hide_servers; |
366 |
int links_delay; |
367 |
int links_disabled; |
368 |
int hidden; |
369 |
int hide_server_ips; |
370 |
}; |
371 |
|
372 |
struct server_info |
373 |
{ |
374 |
char *sid; |
375 |
char *name; |
376 |
char *description; |
377 |
char *network_name; |
378 |
char *network_desc; |
379 |
#ifdef HAVE_LIBCRYPTO |
380 |
char *rsa_private_key_file; |
381 |
RSA *rsa_private_key; |
382 |
SSL_CTX *server_ctx; |
383 |
SSL_CTX *client_ctx; |
384 |
#endif |
385 |
int hub; |
386 |
struct irc_ssaddr ip; |
387 |
struct irc_ssaddr ip6; |
388 |
unsigned int max_clients; |
389 |
int specific_ipv4_vhost; |
390 |
int specific_ipv6_vhost; |
391 |
struct sockaddr_in dns_host; |
392 |
int can_use_v6; |
393 |
}; |
394 |
|
395 |
struct admin_info |
396 |
{ |
397 |
char *name; |
398 |
char *description; |
399 |
char *email; |
400 |
}; |
401 |
|
402 |
struct logging_entry |
403 |
{ |
404 |
unsigned int use_logging; |
405 |
}; |
406 |
|
407 |
extern dlink_list class_items; |
408 |
extern dlink_list server_items; |
409 |
extern dlink_list cluster_items; |
410 |
extern dlink_list hub_items; |
411 |
extern dlink_list xconf_items; |
412 |
extern dlink_list rxconf_items; |
413 |
extern dlink_list rkconf_items; |
414 |
extern dlink_list leaf_items; |
415 |
extern dlink_list service_items; |
416 |
extern struct logging_entry ConfigLoggingEntry; |
417 |
extern struct config_file_entry ConfigFileEntry;/* defined in ircd.c*/ |
418 |
extern struct config_channel_entry ConfigChannel;/* defined in channel.c*/ |
419 |
extern struct config_server_hide ConfigServerHide; /* defined in s_conf.c */ |
420 |
extern struct server_info ServerInfo; /* defined in ircd.c */ |
421 |
extern struct admin_info AdminInfo; /* defined in ircd.c */ |
422 |
extern int valid_wild_card(struct Client *, int, int, ...); |
423 |
/* End GLOBAL section */ |
424 |
|
425 |
extern unsigned int get_sendq(struct Client *); |
426 |
extern unsigned int get_recvq(struct Client *); |
427 |
extern const char *get_client_class(struct Client *); |
428 |
extern int get_client_ping(struct Client *, int *); |
429 |
extern void check_class(void); |
430 |
extern void init_class(void); |
431 |
extern struct ConfItem *find_class(const char *); |
432 |
extern void init_ip_hash_table(void); |
433 |
extern void count_ip_hash(unsigned int *, uint64_t *); |
434 |
extern void remove_one_ip(struct irc_ssaddr *); |
435 |
extern struct ConfItem *make_conf_item(ConfType type); |
436 |
extern void free_access_item(struct AccessItem *); |
437 |
extern void read_conf_files(int); |
438 |
extern int attach_conf(struct Client *, struct ConfItem *); |
439 |
extern int attach_connect_block(struct Client *, const char *, const char *); |
440 |
|
441 |
extern int detach_conf(struct Client *, ConfType); |
442 |
|
443 |
extern struct ConfItem *find_conf_name(dlink_list *, const char *, ConfType); |
444 |
extern struct ConfItem *find_conf_exact(ConfType, const char *, const char *, const char *); |
445 |
extern struct AccessItem *find_kill(struct Client *); |
446 |
extern struct AccessItem *find_gline(struct Client *); |
447 |
extern int conf_connect_allowed(struct irc_ssaddr *, int); |
448 |
extern char *oper_privs_as_string(const unsigned int); |
449 |
extern void split_nuh(struct split_nuh_item *); |
450 |
extern struct ConfItem *find_matching_name_conf(ConfType, const char *, |
451 |
const char *, const char *, int); |
452 |
extern struct ConfItem *find_exact_name_conf(ConfType, const struct Client *, const char *, |
453 |
const char *, const char *); |
454 |
extern void delete_conf_item(struct ConfItem *); |
455 |
extern void report_confitem_types(struct Client *, ConfType); |
456 |
extern void yyerror(const char *); |
457 |
extern void cleanup_tklines(void *); |
458 |
extern int rehash(int); |
459 |
extern int conf_add_server(struct ConfItem *, const char *); |
460 |
extern void conf_add_class_to_conf(struct ConfItem *, const char *); |
461 |
|
462 |
extern const char *get_oper_name(const struct Client *); |
463 |
|
464 |
extern void *map_to_conf(struct ConfItem *); |
465 |
extern struct ConfItem *unmap_conf_item(void *); |
466 |
/* XXX should the parse_aline stuff go into another file ?? */ |
467 |
#define AWILD 0x1 /* check wild cards */ |
468 |
extern int parse_aline(const char *, struct Client *, int, char **, |
469 |
int, char **, char **, time_t *, char **, char **); |
470 |
extern int valid_comment(struct Client *, char *, int); |
471 |
|
472 |
|
473 |
#define TK_SECONDS 0 |
474 |
#define TK_MINUTES 1 |
475 |
extern time_t valid_tkline(const char *, int); |
476 |
extern int match_conf_password(const char *, const struct AccessItem *); |
477 |
|
478 |
#define NOT_AUTHORIZED (-1) |
479 |
#define I_LINE_FULL (-2) |
480 |
#define TOO_MANY (-3) |
481 |
#define BANNED_CLIENT (-4) |
482 |
#define TOO_FAST (-5) |
483 |
|
484 |
#define CLEANUP_TKLINES_TIME 60 |
485 |
|
486 |
extern void cluster_a_line(struct Client *, |
487 |
const char *, int, int, const char *,...); |
488 |
extern void rebuild_cidr_class(struct ConfItem *, struct ClassItem *); |
489 |
#endif /* INCLUDED_s_conf_h */ |