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 |
#define CONF_NOREASON "<No reason supplied>" |
38 |
|
39 |
struct Client; |
40 |
|
41 |
extern struct Callback *client_check_cb; |
42 |
|
43 |
struct conf_parser_context |
44 |
{ |
45 |
unsigned int boot; |
46 |
unsigned int pass; |
47 |
FILE *conf_file; |
48 |
}; |
49 |
|
50 |
extern struct conf_parser_context conf_parser_ctx; |
51 |
|
52 |
typedef enum |
53 |
{ |
54 |
CONF_TYPE, |
55 |
CLASS_TYPE, |
56 |
OPER_TYPE, |
57 |
CLIENT_TYPE, |
58 |
SERVER_TYPE, |
59 |
HUB_TYPE, |
60 |
LEAF_TYPE, |
61 |
KLINE_TYPE, |
62 |
DLINE_TYPE, |
63 |
EXEMPTDLINE_TYPE, |
64 |
CLUSTER_TYPE, |
65 |
RKLINE_TYPE, |
66 |
RXLINE_TYPE, |
67 |
XLINE_TYPE, |
68 |
ULINE_TYPE, |
69 |
GLINE_TYPE, |
70 |
CRESV_TYPE, |
71 |
NRESV_TYPE, |
72 |
SERVICE_TYPE |
73 |
} ConfType; |
74 |
|
75 |
struct split_nuh_item |
76 |
{ |
77 |
dlink_node node; |
78 |
|
79 |
char *nuhmask; |
80 |
char *nickptr; |
81 |
char *userptr; |
82 |
char *hostptr; |
83 |
|
84 |
size_t nicksize; |
85 |
size_t usersize; |
86 |
size_t hostsize; |
87 |
}; |
88 |
|
89 |
struct ConfItem |
90 |
{ |
91 |
dlink_node node; /* link into known ConfItems of this type */ |
92 |
|
93 |
char *name; /* Primary key */ |
94 |
void *regexpname; |
95 |
unsigned int flags; |
96 |
ConfType type; |
97 |
}; |
98 |
|
99 |
/* |
100 |
* MatchItem - used for XLINE and ULINE types |
101 |
*/ |
102 |
struct MatchItem |
103 |
{ |
104 |
char *user; /* Used for ULINE only */ |
105 |
char *host; /* Used for ULINE only */ |
106 |
char *reason; |
107 |
char *oper_reason; |
108 |
int action; /* used for uline */ |
109 |
int count; /* How many times this matchitem has been matched */ |
110 |
int ref_count; /* How many times is this matchitem in use */ |
111 |
int illegal; /* Should it be deleted when possible? */ |
112 |
time_t hold; /* Hold action until this time (calendar time) */ |
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 * oper_reason; |
134 |
char * user; /* user part of user@host */ |
135 |
time_t hold; /* Hold action until this time (calendar time) */ |
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 |
unsigned int min_idle; |
157 |
unsigned int max_idle; |
158 |
unsigned int flags; |
159 |
int con_freq; |
160 |
int ping_freq; |
161 |
int ping_warning; |
162 |
int max_total; |
163 |
int max_local; |
164 |
int max_global; |
165 |
int max_ident; |
166 |
int max_perip; |
167 |
int curr_user_count; |
168 |
int cidr_bitlen_ipv4; |
169 |
int cidr_bitlen_ipv6; |
170 |
int number_per_cidr; |
171 |
int active; |
172 |
}; |
173 |
|
174 |
struct CidrItem |
175 |
{ |
176 |
dlink_node node; |
177 |
struct irc_ssaddr mask; |
178 |
int number_on_this_cidr; |
179 |
}; |
180 |
|
181 |
|
182 |
#define CONF_ILLEGAL 0x80000000 |
183 |
#define CONF_RESERVED 0x00000001 |
184 |
#define CONF_CLIENT 0x00000002 |
185 |
#define CONF_SERVER 0x00000004 |
186 |
#define CONF_OPERATOR 0x00000008 |
187 |
#define CONF_KLINE 0x00000010 |
188 |
#define CONF_CLASS 0x00000020 |
189 |
#define CONF_DLINE 0x00000040 |
190 |
#define CONF_XLINE 0x00000080 |
191 |
#define CONF_ULINE 0x00000100 |
192 |
#define CONF_EXEMPTDLINE 0x00000200 |
193 |
#define CONF_GLINE 0x00000400 |
194 |
#define CONF_SERVICE 0x00000800 |
195 |
|
196 |
#define CONF_SERVER_MASK CONF_SERVER |
197 |
#define CONF_CLIENT_MASK (CONF_CLIENT | CONF_OPERATOR | CONF_SERVER_MASK) |
198 |
|
199 |
/* XXX temporary hack */ |
200 |
#define CONF_CRESV 0x80000001 |
201 |
#define CONF_NRESV 0x80000002 |
202 |
|
203 |
#define IsConfIllegal(x) ((x)->status & CONF_ILLEGAL) |
204 |
#define SetConfIllegal(x) ((x)->status |= CONF_ILLEGAL) |
205 |
#define IsConfServer(x) ((x)->status == CONF_SERVER) |
206 |
#define SetConfServer(x) ((x)->status = CONF_SERVER) |
207 |
#define IsConfOperator(x) ((x)->status & CONF_OPERATOR) |
208 |
#define IsConfKill(x) ((x)->status == CONF_KLINE) |
209 |
#define IsConfClient(x) ((x)->status & CONF_CLIENT) |
210 |
#define IsConfUline(x) ((x)->status & CONF_ULINE) |
211 |
#define IsConfXline(x) ((x)->status & CONF_XLINE) |
212 |
#define IsConfGline(x) ((x)->status == CONF_GLINE) |
213 |
|
214 |
/* AccessItem->flags */ |
215 |
|
216 |
/* Generic flags... */ |
217 |
/* access flags... */ |
218 |
#define CONF_FLAGS_DO_IDENTD 0x00000001 |
219 |
#define CONF_FLAGS_LIMIT_IP 0x00000002 |
220 |
#define CONF_FLAGS_NO_TILDE 0x00000004 |
221 |
#define CONF_FLAGS_NEED_IDENTD 0x00000008 |
222 |
#define CONF_FLAGS_NOMATCH_IP 0x00000010 |
223 |
#define CONF_FLAGS_EXEMPTKLINE 0x00000020 |
224 |
#define CONF_FLAGS_NOLIMIT 0x00000040 |
225 |
#define CONF_FLAGS_SPOOF_IP 0x00000080 |
226 |
#define CONF_FLAGS_SPOOF_NOTICE 0x00000100 |
227 |
#define CONF_FLAGS_REDIR 0x00000200 |
228 |
#define CONF_FLAGS_EXEMPTGLINE 0x00000400 |
229 |
#define CONF_FLAGS_CAN_FLOOD 0x00000800 |
230 |
#define CONF_FLAGS_NEED_PASSWORD 0x00001000 |
231 |
/* server flags */ |
232 |
#define CONF_FLAGS_ALLOW_AUTO_CONN 0x00002000 |
233 |
#define CONF_FLAGS_ENCRYPTED 0x00004000 |
234 |
#define CONF_FLAGS_TEMPORARY 0x00008000 |
235 |
#define CONF_FLAGS_EXEMPTRESV 0x00010000 |
236 |
#define CONF_FLAGS_SSL 0x00020000 |
237 |
#define CONF_FLAGS_RANDOM_IDLE 0x00040000 |
238 |
#define CONF_FLAGS_HIDE_IDLE_FROM_OPERS 0x00080000 |
239 |
#define CONF_FLAGS_FAKE_IDLE 0x00100000 |
240 |
|
241 |
/* Macros for struct AccessItem */ |
242 |
#define IsLimitIp(x) ((x)->flags & CONF_FLAGS_LIMIT_IP) |
243 |
#define IsNoTilde(x) ((x)->flags & CONF_FLAGS_NO_TILDE) |
244 |
#define IsConfCanFlood(x) ((x)->flags & CONF_FLAGS_CAN_FLOOD) |
245 |
#define IsNeedPassword(x) ((x)->flags & CONF_FLAGS_NEED_PASSWORD) |
246 |
#define IsNeedIdentd(x) ((x)->flags & CONF_FLAGS_NEED_IDENTD) |
247 |
#define IsNoMatchIp(x) ((x)->flags & CONF_FLAGS_NOMATCH_IP) |
248 |
#define IsConfExemptKline(x) ((x)->flags & CONF_FLAGS_EXEMPTKLINE) |
249 |
#define IsConfExemptLimits(x) ((x)->flags & CONF_FLAGS_NOLIMIT) |
250 |
#define IsConfExemptGline(x) ((x)->flags & CONF_FLAGS_EXEMPTGLINE) |
251 |
#define IsConfExemptResv(x) ((x)->flags & CONF_FLAGS_EXEMPTRESV) |
252 |
#define IsConfDoIdentd(x) ((x)->flags & CONF_FLAGS_DO_IDENTD) |
253 |
#define IsConfDoSpoofIp(x) ((x)->flags & CONF_FLAGS_SPOOF_IP) |
254 |
#define IsConfSpoofNotice(x) ((x)->flags & CONF_FLAGS_SPOOF_NOTICE) |
255 |
#define IsConfEncrypted(x) ((x)->flags & CONF_FLAGS_ENCRYPTED) |
256 |
#define SetConfEncrypted(x) ((x)->flags |= CONF_FLAGS_ENCRYPTED) |
257 |
#define ClearConfEncrypted(x) ((x)->flags &= ~CONF_FLAGS_ENCRYPTED) |
258 |
#define IsConfAllowAutoConn(x) ((x)->flags & CONF_FLAGS_ALLOW_AUTO_CONN) |
259 |
#define SetConfAllowAutoConn(x) ((x)->flags |= CONF_FLAGS_ALLOW_AUTO_CONN) |
260 |
#define ClearConfAllowAutoConn(x) ((x)->flags &= ~CONF_FLAGS_ALLOW_AUTO_CONN) |
261 |
#define IsConfTemporary(x) ((x)->flags & CONF_FLAGS_TEMPORARY) |
262 |
#define SetConfTemporary(x) ((x)->flags |= CONF_FLAGS_TEMPORARY) |
263 |
#define IsConfRedir(x) ((x)->flags & CONF_FLAGS_REDIR) |
264 |
#define IsConfSSL(x) ((x)->flags & CONF_FLAGS_SSL) |
265 |
#define SetConfSSL(x) ((x)->flags |= CONF_FLAGS_SSL) |
266 |
#define ClearConfSSL(x) ((x)->flags &= ~CONF_FLAGS_SSL) |
267 |
|
268 |
/* shared/cluster server entry types |
269 |
* These defines are used for both shared and cluster. |
270 |
*/ |
271 |
#define SHARED_KLINE 0x0001 |
272 |
#define SHARED_UNKLINE 0x0002 |
273 |
#define SHARED_XLINE 0x0004 |
274 |
#define SHARED_UNXLINE 0x0008 |
275 |
#define SHARED_RESV 0x0010 |
276 |
#define SHARED_UNRESV 0x0020 |
277 |
#define SHARED_LOCOPS 0x0040 |
278 |
#define SHARED_DLINE 0x0080 |
279 |
#define SHARED_UNDLINE 0x0100 |
280 |
#define SHARED_ALL (SHARED_KLINE | SHARED_UNKLINE |\ |
281 |
SHARED_XLINE | SHARED_UNXLINE |\ |
282 |
SHARED_RESV | SHARED_UNRESV |\ |
283 |
SHARED_LOCOPS | SHARED_DLINE | SHARED_UNDLINE) |
284 |
|
285 |
struct config_file_entry |
286 |
{ |
287 |
const char *dpath; /* DPATH if set from command line */ |
288 |
const char *configfile; |
289 |
const char *klinefile; |
290 |
const char *xlinefile; |
291 |
const char *dlinefile; |
292 |
const char *cresvfile; |
293 |
const char *nresvfile; |
294 |
|
295 |
char *egdpool_path; |
296 |
char *service_name; |
297 |
|
298 |
MessageFile motd; |
299 |
MessageFile linksfile; |
300 |
|
301 |
int gline_min_cidr; |
302 |
int gline_min_cidr6; |
303 |
int dots_in_ident; |
304 |
int failed_oper_notice; |
305 |
int anti_spam_exit_message_time; |
306 |
unsigned int max_accept; |
307 |
unsigned int max_watch; |
308 |
int max_nick_time; |
309 |
unsigned int max_nick_changes; |
310 |
int ts_max_delta; |
311 |
int ts_warn_delta; |
312 |
int anti_nick_flood; |
313 |
int warn_no_nline; |
314 |
int invisible_on_connect; |
315 |
int stats_e_disabled; |
316 |
int stats_o_oper_only; |
317 |
int stats_k_oper_only; |
318 |
int stats_i_oper_only; |
319 |
int stats_P_oper_only; |
320 |
int short_motd; |
321 |
int no_oper_flood; |
322 |
int true_no_oper_flood; |
323 |
int oper_pass_resv; |
324 |
int glines; |
325 |
int hide_spoof_ips; |
326 |
int tkline_expire_notices; |
327 |
int opers_bypass_callerid; |
328 |
int ignore_bogus_ts; |
329 |
int pace_wait; |
330 |
int pace_wait_simple; |
331 |
int gline_time; |
332 |
int gline_request_time; |
333 |
int oper_only_umodes; |
334 |
int oper_umodes; |
335 |
int max_targets; |
336 |
int caller_id_wait; |
337 |
int min_nonwildcard; |
338 |
int min_nonwildcard_simple; |
339 |
int kill_chase_time_limit; |
340 |
int default_floodcount; |
341 |
/* 0 == don't use throttle... */ |
342 |
int throttle_time; |
343 |
int use_egd; |
344 |
int ping_cookie; |
345 |
int disable_auth; |
346 |
int disable_remote; |
347 |
}; |
348 |
|
349 |
struct config_channel_entry |
350 |
{ |
351 |
int disable_fake_channels; |
352 |
int restrict_channels; |
353 |
int knock_delay; |
354 |
int knock_delay_channel; |
355 |
unsigned int max_bans; |
356 |
unsigned int max_chans_per_user; |
357 |
unsigned int max_chans_per_oper; |
358 |
int no_create_on_split; |
359 |
int no_join_on_split; |
360 |
int quiet_on_ban; |
361 |
int default_split_server_count; |
362 |
int default_split_user_count; |
363 |
}; |
364 |
|
365 |
struct config_server_hide |
366 |
{ |
367 |
char *hidden_name; |
368 |
int flatten_links; |
369 |
int hide_servers; |
370 |
int links_delay; |
371 |
int links_disabled; |
372 |
int hidden; |
373 |
int hide_server_ips; |
374 |
}; |
375 |
|
376 |
struct server_info |
377 |
{ |
378 |
char *sid; |
379 |
char *name; |
380 |
char *description; |
381 |
char *network_name; |
382 |
char *network_desc; |
383 |
#ifdef HAVE_LIBCRYPTO |
384 |
char *rsa_private_key_file; |
385 |
RSA *rsa_private_key; |
386 |
SSL_CTX *server_ctx; |
387 |
SSL_CTX *client_ctx; |
388 |
#endif |
389 |
int hub; |
390 |
struct irc_ssaddr ip; |
391 |
struct irc_ssaddr ip6; |
392 |
unsigned int max_clients; |
393 |
unsigned int max_nick_length; |
394 |
unsigned int max_topic_length; |
395 |
int specific_ipv4_vhost; |
396 |
int specific_ipv6_vhost; |
397 |
struct sockaddr_in dns_host; |
398 |
int can_use_v6; |
399 |
}; |
400 |
|
401 |
struct admin_info |
402 |
{ |
403 |
char *name; |
404 |
char *description; |
405 |
char *email; |
406 |
}; |
407 |
|
408 |
struct logging_entry |
409 |
{ |
410 |
unsigned int use_logging; |
411 |
}; |
412 |
|
413 |
extern dlink_list class_items; |
414 |
extern dlink_list server_items; |
415 |
extern dlink_list cluster_items; |
416 |
extern dlink_list hub_items; |
417 |
extern dlink_list rxconf_items; |
418 |
extern dlink_list rkconf_items; |
419 |
extern dlink_list leaf_items; |
420 |
extern dlink_list service_items; |
421 |
extern dlink_list temporary_xlines; |
422 |
extern struct logging_entry ConfigLoggingEntry; |
423 |
extern struct config_file_entry ConfigFileEntry;/* defined in ircd.c*/ |
424 |
extern struct config_channel_entry ConfigChannel;/* defined in channel.c*/ |
425 |
extern struct config_server_hide ConfigServerHide; /* defined in s_conf.c */ |
426 |
extern struct server_info ServerInfo; /* defined in ircd.c */ |
427 |
extern struct admin_info AdminInfo; /* defined in ircd.c */ |
428 |
extern int valid_wild_card(struct Client *, int, int, ...); |
429 |
/* End GLOBAL section */ |
430 |
|
431 |
extern unsigned int get_sendq(struct Client *); |
432 |
extern unsigned int get_recvq(struct Client *); |
433 |
extern const char *get_client_class(struct Client *); |
434 |
struct ClassItem *get_client_class_ptr(struct Client *); |
435 |
extern int get_client_ping(struct Client *, int *); |
436 |
extern void check_class(void); |
437 |
extern void init_class(void); |
438 |
extern struct ConfItem *find_class(const char *); |
439 |
extern void init_ip_hash_table(void); |
440 |
extern void count_ip_hash(unsigned int *, uint64_t *); |
441 |
extern void remove_one_ip(struct irc_ssaddr *); |
442 |
extern struct ConfItem *make_conf_item(ConfType type); |
443 |
extern void free_access_item(struct AccessItem *); |
444 |
extern void read_conf_files(int); |
445 |
extern int attach_conf(struct Client *, struct ConfItem *); |
446 |
extern int attach_connect_block(struct Client *, const char *, const char *); |
447 |
|
448 |
extern int detach_conf(struct Client *, ConfType); |
449 |
|
450 |
extern struct ConfItem *find_conf_name(dlink_list *, const char *, ConfType); |
451 |
extern struct AccessItem *find_kill(struct Client *); |
452 |
extern struct AccessItem *find_gline(struct Client *); |
453 |
extern int conf_connect_allowed(struct irc_ssaddr *, int); |
454 |
extern char *oper_privs_as_string(const unsigned int); |
455 |
extern void split_nuh(struct split_nuh_item *); |
456 |
extern struct ConfItem *find_matching_name_conf(ConfType, const char *, |
457 |
const char *, const char *, int); |
458 |
extern struct ConfItem *find_exact_name_conf(ConfType, const struct Client *, const char *, |
459 |
const char *, const char *); |
460 |
extern void delete_conf_item(struct ConfItem *); |
461 |
extern void report_confitem_types(struct Client *, ConfType); |
462 |
extern void yyerror(const char *); |
463 |
extern void write_conf_line(struct Client *, struct ConfItem *, |
464 |
const char *, time_t); |
465 |
extern int remove_conf_line(ConfType, struct Client *, const char *, |
466 |
const char *); |
467 |
extern void add_temp_line(struct ConfItem *); |
468 |
extern void cleanup_tklines(void *); |
469 |
extern const char *get_conf_name(ConfType); |
470 |
extern int rehash(int); |
471 |
extern int conf_add_server(struct ConfItem *, const char *); |
472 |
extern void conf_add_class_to_conf(struct ConfItem *, const char *); |
473 |
|
474 |
/* XXX consider moving these into csvlib.h */ |
475 |
extern void parse_csv_file(FILE *, ConfType); |
476 |
extern int find_and_delete_temporary(const char *, const char *, int); |
477 |
extern const char *get_oper_name(const struct Client *); |
478 |
|
479 |
extern void *map_to_conf(struct ConfItem *); |
480 |
extern struct ConfItem *unmap_conf_item(void *); |
481 |
/* XXX should the parse_aline stuff go into another file ?? */ |
482 |
#define AWILD 0x1 /* check wild cards */ |
483 |
extern int parse_aline(const char *, struct Client *, int, char **, |
484 |
int, char **, char **, time_t *, char **, char **); |
485 |
extern int valid_comment(struct Client *, char *, int); |
486 |
|
487 |
|
488 |
#define TK_SECONDS 0 |
489 |
#define TK_MINUTES 1 |
490 |
extern time_t valid_tkline(const char *, int); |
491 |
extern int match_conf_password(const char *, const struct AccessItem *); |
492 |
|
493 |
#define NOT_AUTHORIZED (-1) |
494 |
#define I_LINE_FULL (-2) |
495 |
#define TOO_MANY (-3) |
496 |
#define BANNED_CLIENT (-4) |
497 |
#define TOO_FAST (-5) |
498 |
|
499 |
#define CLEANUP_TKLINES_TIME 60 |
500 |
|
501 |
extern void cluster_a_line(struct Client *, |
502 |
const char *, int, int, const char *,...); |
503 |
extern void rebuild_cidr_class(struct ConfItem *, struct ClassItem *); |
504 |
extern void conf_error_report(const char *); |
505 |
#endif /* INCLUDED_s_conf_h */ |