1 /*
2  *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3  *
4  *  Copyright (c) 1997-2021 ircd-hybrid development team
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19  *  USA
20  */
21 
22 /*! \file conf.h
23  * \brief A header for the configuration functions.
24  * \version $Id: conf.h 9926 2021-04-16 14:42:12Z michael $
25  */
26 
27 #ifndef INCLUDED_conf_h
28 #define INCLUDED_conf_h
29 #include "config.h"
30 #include "client.h"
31 #include "conf_class.h"
32 #include "tls.h"
33 
34 
35 enum { CLEANUP_TKLINES_TIME = 60 };
36 
37 enum maskitem_type
38 {
39   CONF_CLIENT = 1,
40   CONF_SERVER,
41   CONF_KLINE,
42   CONF_DLINE,
43   CONF_EXEMPT,
44   CONF_OPER
45 };
46 
47 /* MaskItem->flags */
48 enum
49 {
50   CONF_FLAGS_NO_TILDE        = 1 <<  0,
51   CONF_FLAGS_NEED_IDENTD     = 1 <<  1,
52   CONF_FLAGS_EXEMPTKLINE     = 1 <<  2,
53   CONF_FLAGS_NOLIMIT         = 1 <<  3,
54   CONF_FLAGS_SPOOF_IP        = 1 <<  4,
55   CONF_FLAGS_REDIR           = 1 <<  5,
56   CONF_FLAGS_CAN_FLOOD       = 1 <<  6,
57   CONF_FLAGS_NEED_PASSWORD   = 1 <<  7,
58   CONF_FLAGS_ALLOW_AUTO_CONN = 1 <<  8,
59   CONF_FLAGS_ENCRYPTED       = 1 <<  9,
60   CONF_FLAGS_IN_DATABASE     = 1 << 10,
61   CONF_FLAGS_EXEMPTRESV      = 1 << 11,
62   CONF_FLAGS_TLS             = 1 << 12,
63   CONF_FLAGS_WEBIRC          = 1 << 13,
64   CONF_FLAGS_EXEMPTXLINE     = 1 << 14
65 };
66 
67 enum
68 {
69   NOT_AUTHORIZED = -1,
70   I_LINE_FULL    = -2,
71   TOO_MANY       = -3,
72   BANNED_CLIENT  = -4,
73   TOO_FAST       = -5
74 };
75 
76 #define CONF_NOREASON "<No reason supplied>"
77 
78 /* Macros for struct MaskItem */
79 #define IsConfWebIRC(x)           ((x)->flags & CONF_FLAGS_WEBIRC)
80 #define IsNoTilde(x)              ((x)->flags & CONF_FLAGS_NO_TILDE)
81 #define IsConfCanFlood(x)         ((x)->flags & CONF_FLAGS_CAN_FLOOD)
82 #define IsNeedPassword(x)         ((x)->flags & CONF_FLAGS_NEED_PASSWORD)
83 #define IsNeedIdentd(x)           ((x)->flags & CONF_FLAGS_NEED_IDENTD)
84 #define IsConfExemptKline(x)      ((x)->flags & CONF_FLAGS_EXEMPTKLINE)
85 #define IsConfExemptXline(x)      ((x)->flags & CONF_FLAGS_EXEMPTXLINE)
86 #define IsConfExemptLimits(x)     ((x)->flags & CONF_FLAGS_NOLIMIT)
87 #define IsConfExemptResv(x)       ((x)->flags & CONF_FLAGS_EXEMPTRESV)
88 #define IsConfDoSpoofIp(x)        ((x)->flags & CONF_FLAGS_SPOOF_IP)
89 #define IsConfAllowAutoConn(x)    ((x)->flags & CONF_FLAGS_ALLOW_AUTO_CONN)
90 #define SetConfAllowAutoConn(x)   ((x)->flags |= CONF_FLAGS_ALLOW_AUTO_CONN)
91 #define ClearConfAllowAutoConn(x) ((x)->flags &= ~CONF_FLAGS_ALLOW_AUTO_CONN)
92 #define IsConfRedir(x)            ((x)->flags & CONF_FLAGS_REDIR)
93 #define IsConfTLS(x)              ((x)->flags & CONF_FLAGS_TLS)
94 #define IsConfDatabase(x)         ((x)->flags & CONF_FLAGS_IN_DATABASE)
95 #define SetConfDatabase(x)        ((x)->flags |= CONF_FLAGS_IN_DATABASE)
96 
97 
98 #define IsConfKill(x)           ((x)->type == CONF_KLINE)
99 #define IsConfClient(x)         ((x)->type == CONF_CLIENT)
100 
101 struct split_nuh_item
102 {
103   dlink_node node;
104 
105   char *nuhmask;
106   char *nickptr;
107   char *userptr;
108   char *hostptr;
109 
110   size_t nicksize;
111   size_t usersize;
112   size_t hostsize;
113 };
114 
115 struct MaskItem
116 {
117   dlink_node         node;
118   dlink_list         leaf_list;
119   dlink_list         hub_list;
120   enum maskitem_type type;
121   bool       active;
122   bool       dns_failed;
123   bool       dns_pending;
124   unsigned int       flags;
125   unsigned int       modes;
126   unsigned int       port;
127   unsigned int       aftype;
128   unsigned int       htype;
129   unsigned int       ref_count;  /* Number of *LOCAL* clients using this */
130   int                bits;
131   uintmax_t          until;     /* Hold action until this time (calendar time) */
132   uintmax_t          setat;
133   uintmax_t          timeout;
134   struct irc_ssaddr  *bind;  /* ip to bind to for outgoing connect */
135   struct irc_ssaddr  *addr;  /* ip to connect to */
136   struct ClassItem  *class;  /* Class of connection */
137   char              *name;
138   char              *user;     /* user part of user@host */
139   char              *host;     /* host part of user@host */
140   char              *passwd;
141   char              *spasswd;  /* Password to send. */
142   char              *reason;
143   char              *certfp;
144   char              *whois;
145   char              *cipher_list;
146 };
147 
148 struct conf_parser_context
149 {
150   unsigned int boot;
151   unsigned int pass;
152   FILE *conf_file;
153 };
154 
155 struct config_general_entry
156 {
157   const char *dpath;
158   const char *mpath;
159   const char *spath;
160   const char *configfile;
161   const char *klinefile;
162   const char *xlinefile;
163   const char *dlinefile;
164   const char *resvfile;
165 
166   unsigned int dline_min_cidr;
167   unsigned int dline_min_cidr6;
168   unsigned int kline_min_cidr;
169   unsigned int kline_min_cidr6;
170   unsigned int specials_in_ident;
171   unsigned int failed_oper_notice;
172   unsigned int anti_spam_exit_message_time;
173   unsigned int max_accept;
174   unsigned int max_monitor;
175   unsigned int whowas_history_length;
176   unsigned int away_time;
177   unsigned int away_count;
178   unsigned int max_nick_time;
179   unsigned int max_nick_changes;
180   unsigned int ts_max_delta;
181   unsigned int ts_warn_delta;
182   unsigned int anti_nick_flood;
183   unsigned int warn_no_connect_block;
184   unsigned int invisible_on_connect;
185   unsigned int stats_e_disabled;
186   unsigned int stats_i_oper_only;
187   unsigned int stats_k_oper_only;
188   unsigned int stats_m_oper_only;
189   unsigned int stats_o_oper_only;
190   unsigned int stats_P_oper_only;
191   unsigned int stats_u_oper_only;
192   unsigned int short_motd;
193   unsigned int no_oper_flood;
194   unsigned int opers_bypass_callerid;
195   unsigned int pace_wait;
196   unsigned int pace_wait_simple;
197   unsigned int oper_only_umodes;
198   unsigned int oper_umodes;
199   unsigned int max_targets;
200   unsigned int caller_id_wait;
201   unsigned int min_nonwildcard;
202   unsigned int min_nonwildcard_simple;
203   unsigned int kill_chase_time_limit;
204   unsigned int default_floodcount;
205   unsigned int default_floodtime;
206   unsigned int throttle_count;
207   unsigned int throttle_time;
208   unsigned int ping_cookie;
209   unsigned int disable_auth;
210   unsigned int cycle_on_host_change;
211 };
212 
213 struct config_channel_entry
214 {
215   unsigned int enable_extbans;
216   unsigned int disable_fake_channels;
217   unsigned int invite_client_count;
218   unsigned int invite_client_time;
219   unsigned int invite_delay_channel;
220   unsigned int invite_expire_time;
221   unsigned int knock_client_count;
222   unsigned int knock_client_time;
223   unsigned int knock_delay_channel;
224   unsigned int max_invites;
225   unsigned int max_bans;
226   unsigned int max_bans_large;
227   unsigned int max_channels;
228   unsigned int default_join_flood_count;
229   unsigned int default_join_flood_time;
230 };
231 
232 struct config_serverhide_entry
233 {
234   char *hidden_name;
235   char *flatten_links_file;
236   unsigned int flatten_links;
237   unsigned int flatten_links_delay;
238   unsigned int disable_remote_commands;
239   unsigned int hide_servers;
240   unsigned int hide_services;
241   unsigned int hidden;
242   unsigned int hide_server_ips;
243 };
244 
245 struct config_serverinfo_entry
246 {
247   char *sid;
248   char *name;
249   char *description;
250   char *network_name;
251   char *network_description;
252   char *rsa_private_key_file;
253   char *tls_certificate_file;
254   char *tls_dh_param_file;
255   char *tls_supported_groups;
256   char *tls_cipher_list;
257   char *tls_cipher_suites;
258   char *tls_message_digest_algorithm;
259   tls_context_t tls_ctx;
260   tls_md_t message_digest_algorithm;
261   unsigned int hub;
262   unsigned int default_max_clients;
263   unsigned int max_nick_length;
264   unsigned int max_topic_length;
265 };
266 
267 struct config_admin_entry
268 {
269   char *name;
270   char *description;
271   char *email;
272 };
273 
274 struct config_log_entry
275 {
276   unsigned int use_logging;
277 };
278 
279 struct aline_ctx
280 {
281   bool add;
282   bool simple_mask;
283   char *mask;
284   char *user;
285   char *host;
286   char *reason;
287   char *server;
288   uintmax_t duration;
289 };
290 
291 extern dlink_list flatten_links;
292 extern dlink_list connect_items;
293 extern dlink_list operator_items;
294 extern struct conf_parser_context conf_parser_ctx;
295 extern struct config_log_entry ConfigLog;
296 extern struct config_general_entry ConfigGeneral;
297 extern struct config_channel_entry ConfigChannel;
298 extern struct config_serverhide_entry ConfigServerHide;
299 extern struct config_serverinfo_entry ConfigServerInfo;
300 extern struct config_admin_entry ConfigAdminInfo;
301 
302 extern bool valid_wild_card_simple(const char *);
303 extern bool valid_wild_card(int, ...);
304 
305 extern struct MaskItem *conf_make(enum maskitem_type);
306 extern void conf_read_files(bool);
307 extern int conf_attach(struct Client *, struct MaskItem *);
308 extern bool conf_check_client(struct Client *);
309 
310 
311 extern void conf_detach(struct Client *, enum maskitem_type);
312 extern struct MaskItem *find_conf_name(dlink_list *, const char *, enum maskitem_type);
313 extern int conf_connect_allowed(struct irc_ssaddr *);
314 extern void split_nuh(struct split_nuh_item *);
315 extern struct MaskItem *operator_find(const struct Client *, const char *);
316 extern struct MaskItem *connect_find(const char *, int (*)(const char *, const char *));
317 extern void conf_free(struct MaskItem *);
318 extern void yyerror(const char *);
319 extern void conf_error_report(const char *);
320 extern void cleanup_tklines(void *);
321 extern void conf_rehash(bool);
322 extern void conf_dns_lookup(struct MaskItem *);
323 extern void conf_add_class_to_conf(struct MaskItem *, const char *);
324 
325 extern const char *get_oper_name(const struct Client *);
326 
327 /* XXX should the parse_aline stuff go into another file ?? */
328 extern bool parse_aline(const char *, struct Client *, int, char **, struct aline_ctx *);
329 
330 extern bool match_conf_password(const char *, const struct MaskItem *);
331 #endif  /* INCLUDED_conf_h */
332