1 /*
2  *  ircd-ratbox: A slightly useful ircd.
3  *  s_conf.h: A header for the configuration functions.
4  *
5  *  Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6  *  Copyright (C) 1996-2002 Hybrid Development Team
7  *  Copyright (C) 2002-2012 ircd-ratbox development team
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
22  *  USA
23  *
24  *  $Id: s_conf.h 28755 2015-10-13 14:48:47Z androsyn $
25  */
26 
27 #ifndef INCLUDED_s_conf_h
28 #define INCLUDED_s_conf_h
29 
30 #ifdef USE_CHALLENGE
31 #include <openssl/rsa.h>
32 #endif
33 
34 
35 struct Client;
36 struct DNSReply;
37 struct hostent;
38 
39 struct ConfItem
40 {
41 	unsigned int status;	/* If CONF_ILLEGAL, delete when no clients */
42 	unsigned int flags;
43 	int clients;		/* Number of *LOCAL* clients using this */
44 
45 	union
46 	{
47 		char *name;	/* IRC name, nick, server name, or original u@h */
48 		const char *oper;
49 	} info;
50 
51 	char *host;		/* host part of user@host */
52 	char *passwd;		/* doubles as kline reason *ugh* */
53 	char *spasswd;		/* Password to send. */
54 	char *user;		/* user part of user@host */
55 	int port;
56 	time_t hold;		/* Hold action until this time (calendar time) */
57 	struct Class *c_class;	/* Class of connection */
58 	rb_patricia_node_t *pnode;
59 };
60 
61 #define CONF_ILLEGAL            0x80000000
62 #define CONF_SKIPUSER		0x0001	/* skip username checks (ie, *@x) */
63 #define CONF_CLIENT             0x0002
64 #define CONF_KILL               0x0040
65 #define CONF_XLINE		0x0080
66 #define CONF_RESV_CHANNEL	0x0100
67 #define CONF_RESV_NICK		0x0200
68 #define CONF_GLINE             0x10000
69 #define CONF_DLINE             0x20000
70 #define CONF_EXEMPTDLINE      0x100000
71 
72 #define IsIllegal(x)    ((x)->status & CONF_ILLEGAL)
73 
74 /* aConfItem->flags */
75 
76 /* Generic flags... */
77 /* access flags... */
78 #define CONF_FLAGS_NO_TILDE             0x00000001
79 #define CONF_FLAGS_NEED_IDENTD          0x00000002
80 #define CONF_FLAGS_EXEMPTKLINE          0x00000004
81 #define CONF_FLAGS_NOLIMIT              0x00000008
82 #define CONF_FLAGS_SPOOF_IP             0x00000010
83 #define CONF_FLAGS_SPOOF_NOTICE		0x00000020
84 #define CONF_FLAGS_REDIR                0x00000040
85 #define CONF_FLAGS_EXEMPTGLINE          0x00000080
86 #define CONF_FLAGS_EXEMPTRESV		0x00000100	/* exempt from resvs */
87 #define CONF_FLAGS_EXEMPTFLOOD          0x00000200
88 #define CONF_FLAGS_EXEMPTSPAMBOT	0x00000400
89 #define CONF_FLAGS_EXEMPTSHIDE		0x00000800
90 #define CONF_FLAGS_EXEMPTJUPE		0x00001000	/* exempt from resv generating warnings */
91 #define CONF_FLAGS_NEED_SSL		0x00002000
92 /* server flags */
93 #define CONF_FLAGS_ENCRYPTED            0x00004000
94 #define CONF_FLAGS_COMPRESSED           0x00008000
95 #define CONF_FLAGS_TEMPORARY            0x00010000
96 #define CONF_FLAGS_TB			0x00020000
97 #define CONF_FLAGS_LOCKED		0x00040000
98 
99 /* Macros for struct ConfItem */
100 #define IsConfBan(x)		((x)->status & (CONF_KILL|CONF_XLINE|CONF_DLINE|\
101 						CONF_RESV_CHANNEL|CONF_RESV_NICK))
102 
103 #define IsNoTilde(x)            ((x)->flags & CONF_FLAGS_NO_TILDE)
104 #define IsNeedIdentd(x)         ((x)->flags & CONF_FLAGS_NEED_IDENTD)
105 #define IsConfExemptKline(x)    ((x)->flags & CONF_FLAGS_EXEMPTKLINE)
106 #define IsConfExemptLimits(x)   ((x)->flags & CONF_FLAGS_NOLIMIT)
107 #define IsConfExemptGline(x)    ((x)->flags & CONF_FLAGS_EXEMPTGLINE)
108 #define IsConfExemptFlood(x)    ((x)->flags & CONF_FLAGS_EXEMPTFLOOD)
109 #define IsConfExemptSpambot(x)	((x)->flags & CONF_FLAGS_EXEMPTSPAMBOT)
110 #define IsConfExemptShide(x)	((x)->flags & CONF_FLAGS_EXEMPTSHIDE)
111 #define IsConfExemptJupe(x)	((x)->flags & CONF_FLAGS_EXEMPTJUPE)
112 #define IsConfExemptResv(x)	((x)->flags & CONF_FLAGS_EXEMPTRESV)
113 #define IsConfDoSpoofIp(x)      ((x)->flags & CONF_FLAGS_SPOOF_IP)
114 #define IsConfSpoofNotice(x)    ((x)->flags & CONF_FLAGS_SPOOF_NOTICE)
115 #define IsConfEncrypted(x)      ((x)->flags & CONF_FLAGS_ENCRYPTED)
116 #define IsConfCompressed(x)     ((x)->flags & CONF_FLAGS_COMPRESSED)
117 #define IsConfTburst(x)		((x)->flags & CONF_FLAGS_TB)
118 #define IsConfLocked(x)		((x)->flags & CONF_FLAGS_LOCKED)
119 #define IsConfSSLNeeded(x)	((x)->flags & CONF_FLAGS_NEED_SSL)
120 
121 /* flag definitions for opers now in client.h */
122 
123 struct config_file_entry
124 {
125 	const char *dpath;	/* DPATH if set from command line */
126 	const char *configfile;
127 
128 	char *default_operstring;
129 	char *default_adminstring;
130 	char *kline_reason;
131 
132 	char *fname_userlog;
133 	char *fname_fuserlog;
134 	char *fname_operlog;
135 	char *fname_foperlog;
136 	char *fname_serverlog;
137 	char *fname_killlog;
138 	char *fname_glinelog;
139 	char *fname_klinelog;
140 	char *fname_operspylog;
141 	char *fname_ioerrorlog;
142 
143 	unsigned char compression_level;
144 	int disable_fake_channels;
145 	int dot_in_ip6_addr;
146 	int dots_in_ident;
147 	int failed_oper_notice;
148 	int anti_nick_flood;
149 	int anti_spam_exit_message_time;
150 	int max_accept;
151 	int max_monitor;
152 	int max_nick_time;
153 	int max_nick_changes;
154 	int ts_max_delta;
155 	int ts_warn_delta;
156 	int dline_with_reason;
157 	int kline_with_reason;
158 	int kline_delay;
159 	int warn_no_nline;
160 	int nick_delay;
161 	int non_redundant_klines;
162 	int stats_e_disabled;
163 	int stats_c_oper_only;
164 	int stats_y_oper_only;
165 	int stats_h_oper_only;
166 	int stats_o_oper_only;
167 	int stats_k_oper_only;
168 	int stats_i_oper_only;
169 	int stats_P_oper_only;
170 	int map_oper_only;
171 	int operspy_admin_only;
172 	int pace_wait;
173 	int pace_wait_simple;
174 	int short_motd;
175 	int default_invisible;
176 	int no_oper_flood;
177 	int glines;
178 	int gline_time;
179 	int gline_min_cidr;
180 	int gline_min_cidr6;
181 	int hide_server;
182 	int hide_error_messages;
183 	int client_exit;
184 	int oper_only_umodes;
185 	int oper_umodes;
186 	int max_targets;
187 	int caller_id_wait;
188 	int min_nonwildcard;
189 	int min_nonwildcard_simple;
190 	int default_floodcount;
191 	int client_flood;
192 	int ping_cookie;
193 	int tkline_expire_notices;
194 	int use_whois_actually;
195 	int disable_auth;
196 	int connect_timeout;
197 	int post_registration_delay;
198 	int burst_away;
199 	int reject_after_count;
200 	int reject_duration;
201 	int throttle_count;
202 	int throttle_duration;
203 	int target_change;
204 	int collision_fnc;
205 	int hide_spoof_ips;
206 	int global_cidr_ipv4_bitlen;
207 	int global_cidr_ipv4_count;
208 	int global_cidr_ipv6_bitlen;
209 	int global_cidr_ipv6_count;
210 	int global_cidr;
211 #ifdef RB_IPV6
212 	int fallback_to_ip6_int;
213 #endif
214 };
215 
216 struct config_channel_entry
217 {
218 	int use_except;
219 	int use_invex;
220 	int use_knock;
221 	int use_sslonly;
222 	int knock_delay;
223 	int knock_delay_channel;
224 	int max_bans;
225 	int max_chans_per_user;
226 	int no_create_on_split;
227 	int no_join_on_split;
228 	int quiet_on_ban;
229 	int default_split_server_count;
230 	int default_split_user_count;
231 	int no_oper_resvs;
232 	int burst_topicwho;
233 	int invite_ops_only;
234 	int topiclen;
235 };
236 
237 struct config_server_hide
238 {
239 	int flatten_links;
240 	int links_delay;
241 	int links_disabled;
242 	int hidden;
243 	int disable_hidden;
244 };
245 
246 struct server_info
247 {
248 	char *name;
249 	char sid[4];
250 	char *description;
251 	char *network_name;
252 	char *network_desc;
253 	int hub;
254 	int default_max_clients;
255 	struct sockaddr_in ip;
256 #ifdef RB_IPV6
257 	struct sockaddr_in6 ip6;
258 #endif
259 	int specific_ipv4_vhost;
260 #ifdef RB_IPV6
261 	int specific_ipv6_vhost;
262 #endif
263 	char *ssl_private_key;
264 	char *ssl_ca_cert;
265 	char *ssl_cert;
266 	char *ssl_dh_params;
267 	int ssld_count;
268 	char *vhost_dns;
269 #ifdef RB_IPV6
270 	char *vhost6_dns;
271 #endif
272 	char *bandb_path;
273 };
274 
275 struct admin_info
276 {
277 	char *name;
278 	char *description;
279 	char *email;
280 };
281 
282 /* All variables are GLOBAL */
283 extern int specific_ipv4_vhost;	/* used in s_bsd.c */
284 extern int specific_ipv6_vhost;
285 extern struct config_file_entry ConfigFileEntry;	/* defined in ircd.c */
286 extern struct config_channel_entry ConfigChannel;	/* defined in channel.c */
287 extern struct config_server_hide ConfigServerHide;	/* defined in s_conf.c */
288 extern struct server_info ServerInfo;	/* defined in ircd.c */
289 extern struct admin_info AdminInfo;	/* defined in ircd.c */
290 /* End GLOBAL section */
291 
292 #ifdef ENABLE_SERVICES
293 extern rb_dlink_list service_list;
294 #endif
295 
296 typedef enum temp_list
297 {
298 	TEMP_MIN,
299 	TEMP_HOUR,
300 	TEMP_DAY,
301 	TEMP_WEEK,
302 	LAST_TEMP_TYPE
303 } temp_list;
304 
305 extern rb_dlink_list temp_klines[LAST_TEMP_TYPE];
306 extern rb_dlink_list temp_dlines[LAST_TEMP_TYPE];
307 
308 void init_s_conf(void);
309 
310 struct ConfItem *make_conf(void);
311 void free_conf(struct ConfItem *);
312 
313 int attach_conf(struct Client *, struct ConfItem *);
314 int check_client(struct Client *client_p, struct Client *source_p, const char *);
315 
316 int detach_conf(struct Client *);
317 
318 struct ConfItem *conf_connect_allowed(struct sockaddr *addr, int);
319 
320 struct ConfItem *find_tkline(const char *, const char *, struct sockaddr *);
321 
322 void get_printable_conf(struct ConfItem *,
323 			const char **, const char **, const char **, const char **, int *,
324 			const char **);
325 void get_printable_kline(struct Client *, struct ConfItem *, const char **, const char **,
326 			 const char **, const char **);
327 
328 void yyerror(const char *);
329 int conf_yy_fatal_error(const char *);
330 int conf_fgets(char *, int, FILE *);
331 
332 const char *make_ban_reason(const char *reason, const char *oper_reason);
333 
334 void add_temp_kline(struct ConfItem *);
335 void add_temp_dline(struct ConfItem *);
336 void report_temp_klines(struct Client *);
337 void show_temp_klines(struct Client *, rb_dlink_list *);
338 
339 void rehash(int);
340 void rehash_bans(int);
341 
342 int conf_add_server(struct ConfItem *, int);
343 void conf_add_class_to_conf(struct ConfItem *, const char *);
344 void conf_add_me(struct ConfItem *);
345 void conf_add_class(struct ConfItem *, int);
346 void conf_add_d_conf(struct ConfItem *);
347 void flush_expired_ips(void *);
348 
349 const char *get_oper_name(struct Client *client_p);
350 const char *get_class_name(struct ConfItem *aconf);
351 void set_default_conf();
352 
353 
354 #define NOT_AUTHORISED  (-1)
355 #define I_SOCKET_ERROR    (-2)
356 #define I_LINE_FULL     (-3)
357 #define BANNED_CLIENT   (-4)
358 #define TOO_MANY_LOCAL	(-6)
359 #define TOO_MANY_GLOBAL (-7)
360 #define TOO_MANY_IDENT	(-8)
361 #define TOO_MANY_GLOBAL_CIDR (-9)
362 
363 #endif /* INCLUDED_s_conf_h */
364