1 /************************************************************************
2  *   Unreal Internet Relay Chat Daemon, include/struct.h
3  *   Copyright (C) 1990 Jarkko Oikarinen and
4  *                      University of Oulu, Computing Center
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 1, or (at your option)
9  *   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., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  *   $Id$
21  */
22 
23 #ifndef	__struct_include__
24 #define __struct_include__
25 
26 #include "config.h"
27 #include "sys.h"
28 /* need to include ssl stuff here coz otherwise you get
29  * conflicting types with isalnum/isalpha/etc @ redhat. -- Syzop
30  */
31 #if defined(USE_SSL)
32 #define OPENSSL_NO_KRB5
33 #include <openssl/rsa.h>       /* SSL stuff */
34 #include <openssl/crypto.h>
35 #include <openssl/x509.h>
36 #include <openssl/pem.h>
37 #include <openssl/ssl.h>
38 #include <openssl/err.h>
39 #include <openssl/evp.h>
40 #include <openssl/rand.h>
41 #include <openssl/md5.h>
42 #include <openssl/ripemd.h>
43 #endif
44 #include "common.h"
45 #include "sys.h"
46 #include "hash.h"
47 #include <stdio.h>
48 #include <sys/types.h>
49 #ifndef _WIN32
50 #include <netinet/in.h>
51 #include <netdb.h>
52 #endif
53 #ifdef STDDEFH
54 # include <stddef.h>
55 #endif
56 #include "md5.h"
57 
58 #ifdef HAVE_SYSLOG
59 # include <syslog.h>
60 # ifdef SYSSYSLOGH
61 #  include <sys/syslog.h>
62 # endif
63 #endif
64 #ifdef ZIP_LINKS
65 #include "zip.h"
66 #endif
67 #include "auth.h"
68 #include "tre/regex.h"
69 
70 #include "channel.h"
71 
72 #if defined(_MSC_VER)
73 /* needed to workaround a warning / prototype/dll inconsistency crap */
74 #define vsnprintf unrl_vsnprintf
75 #endif
76 
77 extern MODVAR int sendanyways;
78 
79 
80 typedef struct aloopStruct LoopStruct;
81 typedef struct ConfItem aConfItem;
82 typedef struct t_kline aTKline;
83 typedef struct _spamfilter Spamfilter;
84 typedef struct _spamexcept SpamExcept;
85 /* New Config Stuff */
86 typedef struct _configentry ConfigEntry;
87 typedef struct _configfile ConfigFile;
88 typedef struct _configflag ConfigFlag;
89 typedef struct _configflag_except ConfigFlag_except;
90 typedef struct _configflag_ban ConfigFlag_ban;
91 typedef struct _configflag_tld ConfigFlag_tld;
92 typedef struct _configitem ConfigItem;
93 typedef struct _configitem_me ConfigItem_me;
94 typedef struct _configitem_files ConfigItem_files;
95 typedef struct _configitem_admin ConfigItem_admin;
96 typedef struct _configitem_class ConfigItem_class;
97 typedef struct _configitem_oper ConfigItem_oper;
98 typedef struct _configitem_oper_from ConfigItem_oper_from;
99 typedef struct _configitem_drpass ConfigItem_drpass;
100 typedef struct _configitem_ulines ConfigItem_ulines;
101 typedef struct _configitem_tld ConfigItem_tld;
102 typedef struct _configitem_listen ConfigItem_listen;
103 typedef struct _configitem_allow ConfigItem_allow;
104 typedef struct _configflag_allow ConfigFlag_allow;
105 typedef struct _configitem_allow_channel ConfigItem_allow_channel;
106 typedef struct _configitem_allow_dcc ConfigItem_allow_dcc;
107 typedef struct _configitem_vhost ConfigItem_vhost;
108 typedef struct _configitem_except ConfigItem_except;
109 typedef struct _configitem_link	ConfigItem_link;
110 typedef struct _configitem_cgiirc ConfigItem_cgiirc;
111 typedef struct _configitem_ban ConfigItem_ban;
112 typedef struct _configitem_badword ConfigItem_badword;
113 typedef struct _configitem_deny_dcc ConfigItem_deny_dcc;
114 typedef struct _configitem_deny_link ConfigItem_deny_link;
115 typedef struct _configitem_deny_channel ConfigItem_deny_channel;
116 typedef struct _configitem_deny_version ConfigItem_deny_version;
117 typedef struct _configitem_log ConfigItem_log;
118 typedef struct _configitem_unknown ConfigItem_unknown;
119 typedef struct _configitem_unknown_ext ConfigItem_unknown_ext;
120 typedef struct _configitem_alias ConfigItem_alias;
121 typedef struct _configitem_alias_format ConfigItem_alias_format;
122 typedef struct _configitem_include ConfigItem_include;
123 typedef struct _configitem_help ConfigItem_help;
124 typedef struct _configitem_offchans ConfigItem_offchans;
125 typedef struct liststruct ListStruct;
126 
127 #define CFG_TIME 0x0001
128 #define CFG_SIZE 0x0002
129 #define CFG_YESNO 0x0004
130 
131 typedef struct Watch aWatch;
132 typedef struct Client aClient;
133 typedef struct Channel aChannel;
134 typedef struct User anUser;
135 typedef struct Server aServer;
136 typedef struct SLink Link;
137 typedef struct SBan Ban;
138 typedef struct SMode Mode;
139 typedef struct SChanFloodProt ChanFloodProt;
140 typedef struct SRemoveFld RemoveFld;
141 typedef struct ListOptions LOpts;
142 typedef struct FloodOpt aFloodOpt;
143 typedef struct Motd aMotdFile; /* represents a whole MOTD, including remote MOTD support info */
144 typedef struct MotdItem aMotdLine; /* one line of a MOTD stored as a linked list */
145 #ifdef USE_LIBCURL
146 typedef struct MotdDownload aMotdDownload; /* used to coordinate download of a remote MOTD */
147 #endif
148 
149 typedef struct trecord aTrecord;
150 typedef struct Command aCommand;
151 typedef struct _cmdoverride Cmdoverride;
152 typedef struct SMember Member;
153 typedef struct SMembership Membership;
154 typedef struct SMembershipL MembershipL;
155 typedef struct JFlood aJFlood;
156 typedef struct PendingNet aPendingNet;
157 
158 #ifdef ZIP_LINKS
159 typedef struct  Zdata   aZdata;
160 #endif
161 
162 #ifdef NEED_U_INT32_T
163 typedef unsigned int u_int32_t;	/* XXX Hope this works! */
164 #endif
165 
166 #ifndef VMSP
167 #include "class.h"
168 #include "dbuf.h"		/* THIS REALLY SHOULDN'T BE HERE!!! --msa */
169 #endif
170 
171 #define	HOSTLEN		63	/* Length of hostname.  Updated to         */
172 				/* comply with RFC1123                     */
173 
174 #define	NICKLEN		30
175 #define	USERLEN		10
176 #define	REALLEN	 	50
177 #define SVIDLEN		30
178 #define	TOPICLEN	307
179 #define	CHANNELLEN	32
180 #define	PASSWDLEN 	48	/* was 20, then 32, now 48. */
181 #define	KEYLEN		23
182 #define LINKLEN		32
183 #define	BUFSIZE		512	/* WARNING: *DONT* CHANGE THIS!!!! */
184 #define	MAXRECIPIENTS 	20
185 #define	MAXKILLS	20
186 #define	MAXSILELENGTH	NICKLEN+USERLEN+HOSTLEN+10
187 #define UMODETABLESZ (sizeof(long) * 8)
188 /*
189  * Watch it - Don't change this unless you also change the ERR_TOOMANYWATCH
190  * and PROTOCOL_SUPPORTED settings.
191  */
192 #define MAXWATCH	128
193 
194 #define	USERHOST_REPLYLEN	(NICKLEN+HOSTLEN+USERLEN+5)
195 
196 /* NOTE: this must be down here so the stuff from struct.h IT uses works */
197 #include "whowas.h"
198 
199 /* Logging types */
200 #define LOG_ERROR 0x0001
201 #define LOG_KILL  0x0002
202 #define LOG_TKL   0x0004
203 #define LOG_KLINE 0x0008
204 #define LOG_CLIENT 0x0010
205 #define LOG_SERVER 0x0020
206 #define LOG_OPER   0x0040
207 #define LOG_SACMDS 0x0080
208 #define LOG_CHGCMDS 0x0100
209 #define LOG_OVERRIDE 0x0200
210 #define LOG_SPAMFILTER 0x0400
211 
212 
213 /*
214 ** 'offsetof' is defined in ANSI-C. The following definition
215 ** is not absolutely portable (I have been told), but so far
216 ** it has worked on all machines I have needed it. The type
217 ** should be size_t but...  --msa
218 */
219 #ifndef offsetof
220 #define	offsetof(t,m) (int)((&((t *)0L)->m))
221 #endif
222 
223 #define	elementsof(x) (sizeof(x)/sizeof(x[0]))
224 
225 /*
226 ** flags for bootup options (command line flags)
227 */
228 #define	BOOT_CONSOLE	1
229 #define	BOOT_QUICK	2
230 #define	BOOT_DEBUG	4
231 #define	BOOT_INETD	8
232 #define	BOOT_TTY	16
233 #define	BOOT_OPER	32
234 #define	BOOT_AUTODIE	64
235 #define BOOT_NOFORK     128
236 
237 #define	STAT_LOG	-7	/* logfile for -x */
238 #define	STAT_CONNECTING	-6
239 #define STAT_SSL_STARTTLS_HANDSHAKE -8
240 #define STAT_SSL_CONNECT_HANDSHAKE -5
241 #define STAT_SSL_ACCEPT_HANDSHAKE -4
242 #define	STAT_HANDSHAKE	-3
243 #define	STAT_ME		-2
244 #define	STAT_UNKNOWN	-1
245 #define	STAT_SERVER	0
246 #define	STAT_CLIENT	1
247 
248 /*
249  * status macros.
250  */
251 #define	IsRegisteredUser(x)	((x)->status == STAT_CLIENT)
252 #define	IsRegistered(x)		((x)->status >= STAT_SERVER)
253 #define	IsConnecting(x)		((x)->status == STAT_CONNECTING)
254 #define	IsHandshake(x)		((x)->status == STAT_HANDSHAKE)
255 #define	IsMe(x)			((x)->status == STAT_ME)
256 #define	IsUnknown(x)		((x)->status == STAT_UNKNOWN)
257 #define	IsServer(x)		((x)->status == STAT_SERVER)
258 #define	IsClient(x)		((x)->status == STAT_CLIENT)
259 #define	IsLog(x)		((x)->status == STAT_LOG)
260 
261 #ifdef USE_SSL
262 #define IsSSLStartTLSHandshake(x)	((x)->status == STAT_SSL_STARTTLS_HANDSHAKE)
263 #define IsSSLAcceptHandshake(x)	((x)->status == STAT_SSL_ACCEPT_HANDSHAKE)
264 #define IsSSLConnectHandshake(x)	((x)->status == STAT_SSL_CONNECT_HANDSHAKE)
265 #define IsSSLHandshake(x) (IsSSLAcceptHandshake(x) || IsSSLConnectHandshake(x) | IsSSLStartTLSHandshake(x))
266 #define SetSSLStartTLSHandshake(x)	((x)->status = STAT_SSL_STARTTLS_HANDSHAKE)
267 #define SetSSLAcceptHandshake(x)	((x)->status = STAT_SSL_ACCEPT_HANDSHAKE)
268 #define SetSSLConnectHandshake(x)	((x)->status = STAT_SSL_CONNECT_HANDSHAKE)
269 #endif
270 
271 #define	SetConnecting(x)	((x)->status = STAT_CONNECTING)
272 #define	SetHandshake(x)		((x)->status = STAT_HANDSHAKE)
273 #define	SetMe(x)		((x)->status = STAT_ME)
274 #define	SetUnknown(x)		((x)->status = STAT_UNKNOWN)
275 #define	SetServer(x)		((x)->status = STAT_SERVER)
276 #define	SetClient(x)		((x)->status = STAT_CLIENT)
277 #define	SetLog(x)		((x)->status = STAT_LOG)
278 
279 #define IsSynched(x)	(x->serv->flags.synced)
280 #define IsServerSent(x) (x->serv && x->serv->flags.server_sent)
281 
282 /* opt.. */
283 #define OPT_SJOIN	0x0001
284 #define OPT_NOT_SJOIN	0x0002
285 #define OPT_NICKv2	0x0004
286 #define OPT_NOT_NICKv2	0x0008
287 #define OPT_SJOIN2	0x0010
288 #define OPT_NOT_SJOIN2	0x0020
289 #define OPT_UMODE2	0x0040
290 #define OPT_NOT_UMODE2	0x0080
291 #define OPT_SJ3		0x0100
292 #define OPT_NOT_SJ3	0x0200
293 #define OPT_SJB64	0x0400
294 #define OPT_NOT_SJB64	0x0800
295 #define OPT_VHP		0x1000
296 #define OPT_NOT_VHP	0x2000
297 #define OPT_TKLEXT	0x4000
298 #define OPT_NOT_TKLEXT	0x8000
299 #define OPT_NICKIP	0x10000
300 #define OPT_NOT_NICKIP  0x20000
301 #define OPT_CLK	0x10000
302 #define OPT_NOT_CLK  0x20000
303 
304 /* client->flags (32 bits): 28 used, 4 free */
305 #define	FLAGS_PINGSENT   0x0001	/* Unreplied ping sent */
306 #define	FLAGS_DEADSOCKET 0x0002	/* Local socket is dead--Exiting soon */
307 #define	FLAGS_KILLED     0x0004	/* Prevents "QUIT" from being sent for this */
308 #define	FLAGS_BLOCKED    0x0008	/* socket is in a blocked condition */
309 #define FLAGS_OUTGOING   0x0010 /* outgoing connection, do not touch cptr->listener->clients */
310 #define	FLAGS_CLOSING    0x0020	/* set when closing to suppress errors */
311 #define	FLAGS_LISTEN     0x0040	/* used to mark clients which we listen() on */
312 #define	FLAGS_CHKACCESS  0x0080	/* ok to check clients access if set */
313 #define	FLAGS_DOINGDNS	 0x0100	/* client is waiting for a DNS response */
314 #define	FLAGS_AUTH       0x0200	/* client is waiting on rfc931 response */
315 #define	FLAGS_WRAUTH	 0x0400	/* set if we havent writen to ident server */
316 #define	FLAGS_LOCAL      0x0800	/* set for local clients */
317 #define	FLAGS_GOTID      0x1000	/* successful ident lookup achieved */
318 #define	FLAGS_DOID       0x2000	/* I-lines say must use ident return */
319 #define	FLAGS_NONL       0x4000	/* No \n in buffer */
320 #define FLAGS_CGIIRC     0x8000 /* CGI IRC host: flag set = ip/host data has been filled in already */
321 #define FLAGS_ULINE      0x10000	/* User/server is considered U-lined */
322 #define FLAGS_SQUIT      0x20000	/* Server has been /squit by an oper */
323 #define FLAGS_PROTOCTL   0x40000	/* Received a PROTOCTL message */
324 #define FLAGS_PING       0x80000
325 #define FLAGS_EAUTH      0x100000
326 #define FLAGS_NETINFO    0x200000
327 #define FLAGS_HYBNOTICE  0x400000
328 #define FLAGS_QUARANTINE 0x800000
329 #ifdef ZIP_LINKS
330 #define FLAGS_ZIP        0x1000000
331 #endif
332 #define FLAGS_DCCNOTICE  0x2000000 /* Has the user seen a notice on how to use DCCALLOW already? */
333 #define FLAGS_SHUNNED    0x4000000
334 #define FLAGS_VIRUS      0x8000000 /* tagged by spamfilter */
335 #ifdef USE_SSL
336 #define FLAGS_SSL        0x10000000
337 #endif
338 #define FLAGS_NOFAKELAG  0x20000000 /* Exception from fake lag */
339 #define FLAGS_DCCBLOCK   0x40000000 /* Block all DCC send requests */
340 #define FLAGS_MAP        0x80000000	/* Show this entry in /map */
341 /* Dec 26th, 1997 - added flags2 when I ran out of room in flags -DuffJ */
342 
343 /* Dec 26th, 1997 - having a go at
344  * splitting flags into flags and umodes
345  * -DuffJ
346  */
347 
348 #define SNO_DEFOPER "+kscfvGqo"
349 #define SNO_DEFUSER "+ks"
350 
351 #define SEND_UMODES (SendUmodes)
352 #define ALL_UMODES (AllUmodes)
353 /* SEND_UMODES and ALL_UMODES are now handled by umode_get/umode_lget/umode_gget -- Syzop. */
354 
355 #define	FLAGS_ID	(FLAGS_DOID|FLAGS_GOTID)
356 
357 #define PROTO_NOQUIT	0x0001	/* Negotiated NOQUIT protocol */
358 #define PROTO_TOKEN		0x0002	/* Negotiated TOKEN protocol */
359 #define PROTO_SJOIN		0x0004	/* Negotiated SJOIN protocol */
360 #define PROTO_NICKv2	0x0008	/* Negotiated NICKv2 protocol */
361 #define PROTO_SJOIN2	0x0010	/* Negotiated SJOIN2 protocol */
362 #define PROTO_UMODE2	0x0020	/* Negotiated UMODE2 protocol */
363 #define PROTO_NS		0x0040	/* Negotiated NS protocol */
364 #define PROTO_ZIP		0x0080	/* Negotiated ZIP protocol */
365 #define PROTO_VL		0x0100	/* Negotiated VL protocol */
366 #define PROTO_SJ3		0x0200	/* Negotiated SJ3 protocol */
367 #define PROTO_VHP		0x0400	/* Send hostnames in NICKv2 even if not sethosted */
368 #define PROTO_SJB64		0x0800
369 #define PROTO_TKLEXT	0x1000	/* TKL extension: 10 parameters instead of 8 (3.2RC2) */
370 #define PROTO_NICKIP	0x2000  /* Send IP addresses in the NICK command */
371 #define PROTO_NAMESX	0x4000  /* Send all rights in NAMES output */
372 #define PROTO_CLK		0x8000	/* Send cloaked host in the NICK command (regardless of +x/-x) */
373 #define PROTO_UHNAMES	0x10000  /* Send n!u@h in NAMES */
374 #define PROTO_CLICAP	0x20000  /* client capability negotiation in process */
375 #define PROTO_STARTTLS	0x40000	 /* client supports STARTTLS */
376 #define PROTO_SASL	0x80000  /* client is doing SASL */
377 #define PROTO_AWAY_NOTIFY	0x100000	/* client supports away-notify */
378 #define PROTO_ACCOUNT_NOTIFY	0x200000	/* client supports account-notify */
379 #define PROTO_MLOCK		0x400000	/* server supports MLOCK */
380 
381 /*
382  * flags macros.
383  */
384 #define IsVictim(x)             ((x)->umodes & UMODE_VICTIM)
385 #define IsDeaf(x)               ((x)->umodes & UMODE_DEAF)
386 #define IsKillsF(x)		((x)->user->snomask & SNO_KILLS)
387 #define IsClientF(x)		((x)->user->snomask & SNO_CLIENT)
388 #define IsFloodF(x)		((x)->user->snomask & SNO_FLOOD)
389 #define IsEyes(x)		((x)->user->snomask & SNO_EYES)
390 #define IsWhois(x)	        ((x)->umodes & UMODE_WHOIS)
391 #define IsKix(x)		((x)->umodes & UMODE_KIX)
392 #define IsHelpOp(x)		((x)->umodes & UMODE_HELPOP)
393 #define IsAdmin(x)		((x)->umodes & UMODE_ADMIN)
394 
395 #ifdef STRIPBADWORDS
396 #define IsFilteringWords(x)	((x)->umodes & UMODE_STRIPBADWORDS)
397 #endif
398 #define IsNetAdmin(x)		((x)->umodes & UMODE_NETADMIN)
399 #define IsCoAdmin(x)		((x)->umodes & UMODE_COADMIN)
400 #define IsSAdmin(x)		((x)->umodes & UMODE_SADMIN)
401 #define SendFailops(x)		((x)->umodes & UMODE_FAILOP)
402 #define	IsOper(x)		((x)->umodes & UMODE_OPER)
403 #define	IsLocOp(x)		((x)->umodes & UMODE_LOCOP)
404 #define	IsInvisible(x)		((x)->umodes & UMODE_INVISIBLE)
405 #define IsServices(x)		((x)->umodes & UMODE_SERVICES)
406 #define	IsAnOper(x)		((x)->umodes & (UMODE_OPER|UMODE_LOCOP))
407 #define IsARegNick(x)		((x)->umodes & (UMODE_REGNICK))
408 #define IsRegNick(x)		((x)->umodes & UMODE_REGNICK)
409 #define IsLoggedIn(x)		(IsRegNick(x) || (x->user && (*x->user->svid != '*') && !isdigit(*x->user->svid))) /* registered nick (+r) or just logged into services (may be -r) */
410 #define IsRegNickMsg(x)		((x)->umodes & UMODE_RGSTRONLY)
411 #define IsNoCTCP(x)		((x)->umodes & UMODE_NOCTCP)
412 #define IsWebTV(x)		((x)->umodes & UMODE_WEBTV)
413 #define	IsPerson(x)		((x)->user && IsClient(x))
414 #define	IsPrivileged(x)		(IsAnOper(x) || IsServer(x))
415 #define	SendWallops(x)		(!IsMe(x) && IsPerson(x) && ((x)->umodes & UMODE_WALLOP))
416 #define	SendServNotice(x)	(((x)->user) && ((x)->user->snomask & SNO_SNOTICE))
417 #define	IsListening(x)		((x)->flags & FLAGS_LISTEN)
418 // #define	DoAccess(x)		((x)->flags & FLAGS_CHKACCESS)
419 #define	IsLocal(x)		((x)->flags & FLAGS_LOCAL)
420 #define	IsDead(x)		((x)->flags & FLAGS_DEADSOCKET)
421 #define GotProtoctl(x)		((x)->flags & FLAGS_PROTOCTL)
422 #define IsBlocked(x)		((x)->flags & FLAGS_BLOCKED)
423 #define IsOutgoing(x)		((x)->flags & FLAGS_OUTGOING)
424 #define GotNetInfo(x) 		((x)->flags & FLAGS_NETINFO)
425 #define SetNetInfo(x)		((x)->flags |= FLAGS_NETINFO)
426 #define IsCGIIRC(x)			((x)->flags & FLAGS_CGIIRC)
427 #define SetEAuth(x)		((x)->flags |= FLAGS_EAUTH)
428 #define IsEAuth(x)		((x)->flags & FLAGS_EAUTH)
429 #define IsShunned(x)		((x)->flags & FLAGS_SHUNNED)
430 #define SetShunned(x)		((x)->flags |= FLAGS_SHUNNED)
431 #define ClearShunned(x)		((x)->flags &= ~FLAGS_SHUNNED)
432 #define IsVirus(x)			((x)->flags & FLAGS_VIRUS)
433 #define SetVirus(x)			((x)->flags |= FLAGS_VIRUS)
434 #define ClearVirus(x)		((x)->flags &= ~FLAGS_VIRUS)
435 #ifdef USE_SSL
436 #define IsSecure(x)		((x)->flags & FLAGS_SSL)
437 #else
438 #define IsSecure(x)		(0)
439 #endif
440 
441 #ifdef ZIP_LINKS
442 #define IsZipped(x) 	((x)->flags & FLAGS_ZIP)
443 #define IsZipStart(x)	(((x)->flags & FLAGS_ZIP) && ((x)->zip->first == 1))
444 #else
445 #define IsZipped(x)		(0)
446 #define IsZipStart(x)	(0)
447 #endif
448 
449 /* Fake lag exception */
450 #define IsNoFakeLag(x)      ((x)->flags & FLAGS_NOFAKELAG)
451 #define SetNoFakeLag(x)     ((x)->flags |= FLAGS_NOFAKELAG)
452 #define ClearNoFakeLag(x)   ((x)->flags &= ~FLAGS_NOFAKELAG)
453 
454 #define IsHybNotice(x)		((x)->flags & FLAGS_HYBNOTICE)
455 #define SetHybNotice(x)         ((x)->flags |= FLAGS_HYBNOTICE)
456 #define ClearHybNotice(x)	((x)->flags &= ~FLAGS_HYBNOTICE)
457 #define IsHidden(x)             ((x)->umodes & UMODE_HIDE)
458 #define IsSetHost(x)			((x)->umodes & UMODE_SETHOST)
459 #define IsHideOper(x)		((x)->umodes & UMODE_HIDEOPER)
460 #ifdef USE_SSL
461 #define IsSSL(x)		IsSecure(x)
462 #endif
463 #define	IsNotSpoof(x)		((x)->nospoof == 0)
464 
465 #define GetHost(x)			(IsHidden(x) ? (x)->user->virthost : (x)->user->realhost)
466 #define GetIP(x)			((x->user && x->user->ip_str) ? x->user->ip_str : (MyConnect(x) ? Inet_ia2p(&x->ip) : NULL))
467 
468 #define SetKillsF(x)		((x)->user->snomask |= SNO_KILLS)
469 #define SetClientF(x)		((x)->user->snomask |= SNO_CLIENT)
470 #define SetFloodF(x)		((x)->user->snomask |= SNO_FLOOD)
471 #define SetHelpOp(x)		((x)->umodes |= UMODE_HELPOP)
472 #define	SetOper(x)		((x)->umodes |= UMODE_OPER)
473 #define	SetLocOp(x)    		((x)->umodes |= UMODE_LOCOP)
474 #define SetAdmin(x)		((x)->umodes |= UMODE_ADMIN)
475 #define SetSAdmin(x)		((x)->umodes |= UMODE_SADMIN)
476 #define SetNetAdmin(x)		((x)->umodes |= UMODE_NETADMIN)
477 #define SetCoAdmin(x)		((x)->umodes |= UMODE_COADMIN)
478 #define	SetInvisible(x)		((x)->umodes |= UMODE_INVISIBLE)
479 #define SetEyes(x)		((x)->user->snomask |= SNO_EYES)
480 #define	SetWallops(x)  		((x)->umodes |= UMODE_WALLOP)
481 #define	SetDNS(x)		((x)->flags |= FLAGS_DOINGDNS)
482 #define	DoingDNS(x)		((x)->flags & FLAGS_DOINGDNS)
483 #define	SetAccess(x)		((x)->flags |= FLAGS_CHKACCESS); Debug((DEBUG_DEBUG, "SetAccess(%s)", (x)->name))
484 #define SetBlocked(x)		((x)->flags |= FLAGS_BLOCKED)
485 #define SetOutgoing(x)		do { x->flags |= FLAGS_OUTGOING; } while(0)
486 #define SetCGIIRC(x)		do { x->flags |= FLAGS_CGIIRC; } while(0)
487 #define	DoingAuth(x)		((x)->flags & FLAGS_AUTH)
488 #define	NoNewLine(x)		((x)->flags & FLAGS_NONL)
489 #define IsDCCNotice(x)		((x)->flags & FLAGS_DCCNOTICE)
490 #define SetDCCNotice(x)		do { x->flags |= FLAGS_DCCNOTICE; } while(0)
491 #define SetRegNick(x)		((x)->umodes & UMODE_REGNICK)
492 #define SetHidden(x)            ((x)->umodes |= UMODE_HIDE)
493 #define SetHideOper(x)      ((x)->umodes |= UMODE_HIDEOPER)
494 #define IsSecureConnect(x)	((x)->umodes & UMODE_SECURE)
495 #define ClearAdmin(x)		((x)->umodes &= ~UMODE_ADMIN)
496 #define ClearNetAdmin(x)	((x)->umodes &= ~UMODE_NETADMIN)
497 #define ClearCoAdmin(x)		((x)->umodes &= ~UMODE_COADMIN)
498 #define ClearSAdmin(x)		((x)->umodes &= ~UMODE_SADMIN)
499 #define ClearKillsF(x)		((x)->user->snomask &= ~SNO_KILLS)
500 #define ClearClientF(x)		((x)->user->snomask &= ~SNO_CLIENT)
501 #define ClearFloodF(x)		((x)->user->snomask &= ~SNO_FLOOD)
502 #define ClearEyes(x)		((x)->user->snomask &= ~SNO_EYES)
503 #define ClearHelpOp(x)		((x)->umodes &= ~UMODE_HELPOP)
504 #define ClearFailops(x)		((x)->umodes &= ~UMODE_FAILOP)
505 #define	ClearOper(x)		((x)->umodes &= ~UMODE_OPER)
506 #define	ClearInvisible(x)	((x)->umodes &= ~UMODE_INVISIBLE)
507 #define ClearServices(x)	((x)->umodes &= ~UMODE_SERVICES)
508 #define	ClearWallops(x)		((x)->umodes &= ~UMODE_WALLOP)
509 #define	ClearDNS(x)		((x)->flags &= ~FLAGS_DOINGDNS)
510 #define	ClearAuth(x)		((x)->flags &= ~FLAGS_AUTH)
511 #define	ClearAccess(x)		((x)->flags &= ~FLAGS_CHKACCESS)
512 #define ClearBlocked(x)		((x)->flags &= ~FLAGS_BLOCKED)
513 #define ClearHidden(x)          ((x)->umodes &= ~UMODE_HIDE)
514 #define ClearHideOper(x)    ((x)->umodes &= ~UMODE_HIDEOPER)
515 
516 #ifdef ZIP_LINKS
517 #define SetZipped(x)        ((x)->flags |= FLAGS_ZIP)
518 #define ClearZipped(x)      ((x)->flags &= ~FLAGS_ZIP)
519 #endif
520 
521 /*
522  * ProtoCtl options
523  */
524 #ifndef DEBUGMODE
525 #define CHECKPROTO(x,y)	((x)->proto & y)
526 #else
527 #define CHECKPROTO(x,y) (checkprotoflags(x, y, __FILE__, __LINE__))
528 #endif
529 
530 #define DontSendQuit(x)		(CHECKPROTO(x, PROTO_NOQUIT))
531 #define IsToken(x)		(CHECKPROTO(x, PROTO_TOKEN))
532 #define SupportSJOIN(x)		(CHECKPROTO(x, PROTO_SJOIN))
533 #define SupportNICKv2(x)	(CHECKPROTO(x, PROTO_NICKv2))
534 #define SupportNICKIP(x)	(CHECKPROTO(x, PROTO_NICKIP))
535 #define SupportSJOIN2(x)	(CHECKPROTO(x, PROTO_SJOIN2))
536 #define SupportUMODE2(x)	(CHECKPROTO(x, PROTO_UMODE2))
537 #define SupportNS(x)		(CHECKPROTO(x, PROTO_NS))
538 #define SupportVL(x)		(CHECKPROTO(x, PROTO_VL))
539 #define SupportSJ3(x)		(CHECKPROTO(x, PROTO_SJ3))
540 #define SupportVHP(x)		(CHECKPROTO(x, PROTO_VHP))
541 #define SupportTKLEXT(x)	(CHECKPROTO(x, PROTO_TKLEXT))
542 #define SupportNAMESX(x)	(CHECKPROTO(x, PROTO_NAMESX))
543 #define SupportCLK(x)		(CHECKPROTO(x, PROTO_CLK))
544 #define SupportUHNAMES(x)	(CHECKPROTO(x, PROTO_UHNAMES))
545 
546 #define SetSJOIN(x)		((x)->proto |= PROTO_SJOIN)
547 #define SetNoQuit(x)		((x)->proto |= PROTO_NOQUIT)
548 #define SetToken(x)		((x)->proto |= PROTO_TOKEN)
549 #define SetNICKv2(x)		((x)->proto |= PROTO_NICKv2)
550 #define SetSJOIN2(x)		((x)->proto |= PROTO_SJOIN2)
551 #define SetUMODE2(x)		((x)->proto |= PROTO_UMODE2)
552 #define SetNS(x)		((x)->proto |= PROTO_NS)
553 #define SetVL(x)		((x)->proto |= PROTO_VL)
554 #define SetSJ3(x)		((x)->proto |= PROTO_SJ3)
555 #define SetVHP(x)		((x)->proto |= PROTO_VHP)
556 #define SetTKLEXT(x)	((x)->proto |= PROTO_TKLEXT)
557 #define SetNAMESX(x)	((x)->proto |= PROTO_NAMESX)
558 #define SetCLK(x)		((x)->proto |= PROTO_CLK)
559 #define SetUHNAMES(x)	((x)->proto |= PROTO_UHNAMES)
560 
561 #define ClearSJOIN(x)		((x)->proto &= ~PROTO_SJOIN)
562 #define ClearNoQuit(x)		((x)->proto &= ~PROTO_NOQUIT)
563 #define ClearToken(x)		((x)->proto &= ~PROTO_TOKEN)
564 #define ClearNICKv2(x)		((x)->proto &= ~PROTO_NICKv2)
565 #define ClearSJOIN2(x)		((x)->proto &= ~PROTO_SJOIN2)
566 #define ClearUMODE2(x)		((x)->proto &= ~PROTO_UMODE2)
567 #define ClearVL(x)		((x)->proto &= ~PROTO_VL)
568 #define ClearVHP(x)		((x)->proto &= ~PROTO_VHP)
569 #define ClearSJ3(x)		((x)->proto &= ~PROTO_SJ3)
570 
571 /*
572  * defined operator access levels
573  */
574 #define OFLAG_REHASH	0x00000001	/* Oper can /rehash server */
575 #define OFLAG_DIE		0x00000002	/* Oper can /die the server */
576 #define OFLAG_RESTART	0x00000004	/* Oper can /restart the server */
577 #define OFLAG_DCCDENY	0x00000008	/* Oper can use /dccdeny and /undccdeny */
578 #define OFLAG_HELPOP	0x00000010	/* Oper can send /HelpOps */
579 #define OFLAG_GLOBOP	0x00000020	/* Oper can send /GlobOps */
580 #define OFLAG_WALLOP	0x00000040	/* Oper can send /WallOps */
581 #define OFLAG_LOCOP		0x00000080	/* Oper can send /LocOps */
582 #define OFLAG_LROUTE	0x00000100	/* Oper can do local routing */
583 #define OFLAG_GROUTE	0x00000200	/* Oper can do global routing */
584 #define OFLAG_LKILL		0x00000400	/* Oper can do local kills */
585 #define OFLAG_GKILL		0x00000800	/* Oper can do global kills */
586 #define OFLAG_KLINE		0x00001000	/* Oper can /kline users */
587 #define OFLAG_UNKLINE	0x00002000	/* Oper can /unkline users */
588 #define OFLAG_LNOTICE	0x00004000	/* Oper can send local serv notices */
589 #define OFLAG_GNOTICE	0x00008000	/* Oper can send global notices */
590 #define OFLAG_ADMIN		0x00010000	/* Admin */
591 #define OFLAG_ADDLINE	0x00020000	/* Oper can use /addline */
592 #define OFLAG_ZLINE		0x00080000	/* Oper can use /zline and /unzline */
593 #define OFLAG_NETADMIN	0x00200000	/* netadmin gets +N */
594 #define OFLAG_COADMIN	0x00800000	/* co admin gets +C */
595 #define OFLAG_SADMIN	0x01000000	/* services admin gets +a */
596 #define OFLAG_WHOIS     0x02000000	/* gets auto +W on oper up */
597 #define OFLAG_HIDE      0x04000000	/* gets auto +x on oper up */
598 #define OFLAG_TKL       0x10000000	/* can use G:lines and shuns */
599 #define OFLAG_GZL       0x20000000	/* can use global Z:lines */
600 #define OFLAG_OVERRIDE	0x40000000	/* can use oper-override */
601 #define OFLAG_UMODEQ	0x80000000	/* can set +q */
602 #define OFLAG_LOCAL	(OFLAG_REHASH|OFLAG_HELPOP|OFLAG_GLOBOP|OFLAG_WALLOP|OFLAG_LOCOP|OFLAG_LROUTE|OFLAG_LKILL|OFLAG_KLINE|OFLAG_UNKLINE|OFLAG_LNOTICE)
603 #define OFLAG_GLOBAL	(OFLAG_LOCAL|OFLAG_GROUTE|OFLAG_GKILL|OFLAG_GNOTICE)
604 #define OFLAG_ISGLOBAL	(OFLAG_GROUTE|OFLAG_GKILL|OFLAG_GNOTICE|OFLAG_TKL|OFLAG_GZL|OFLAG_OVERRIDE)
605 #define OFLAG_NADMIN	(OFLAG_NETADMIN | OFLAG_SADMIN | OFLAG_ADMIN | OFLAG_GLOBAL | OFLAG_UMODEQ | OFLAG_DCCDENY)
606 #define OFLAG_ADMIN_	(OFLAG_ADMIN | OFLAG_GLOBAL | OFLAG_DCCDENY)
607 #define OFLAG_COADMIN_	(OFLAG_COADMIN | OFLAG_GLOBAL | OFLAG_DCCDENY)
608 #define OFLAG_SADMIN_	(OFLAG_SADMIN | OFLAG_GLOBAL | OFLAG_UMODEQ | OFLAG_DCCDENY)
609 
610 #define OPCanOverride(x) ((x)->oflag & OFLAG_OVERRIDE)
611 #define OPCanUmodeq(x)	((x)->oflag & OFLAG_UMODEQ)
612 #define OPCanDCCDeny(x)	((x)->oflag & OFLAG_DCCDENY)
613 #define OPCanTKL(x)	((x)->oflag & OFLAG_TKL)
614 #define OPCanGZL(x)	((x)->oflag & OFLAG_GZL)
615 #define OPCanAddline(x)   ((x)->oflag & OFLAG_ADDLINE)
616 #define OPCanZline(x)   ((x)->oflag & OFLAG_ZLINE)
617 #define OPCanRehash(x)	((x)->oflag & OFLAG_REHASH)
618 #define OPCanDie(x)	((x)->oflag & OFLAG_DIE)
619 #define OPCanRestart(x)	((x)->oflag & OFLAG_RESTART)
620 #define OPCanHelpOp(x)	((x)->oflag & OFLAG_HELPOP)
621 #define OPCanGlobOps(x)	((x)->oflag & OFLAG_GLOBOP)
622 #define OPCanWallOps(x)	((x)->oflag & OFLAG_WALLOP)
623 #define OPCanLocOps(x)	((x)->oflag & OFLAG_LOCOP)
624 #define OPCanLRoute(x)	((x)->oflag & OFLAG_LROUTE)
625 #define OPCanGRoute(x)	((x)->oflag & OFLAG_GROUTE)
626 #define OPCanLKill(x)	((x)->oflag & OFLAG_LKILL)
627 #define OPCanGKill(x)	((x)->oflag & OFLAG_GKILL)
628 #define OPCanKline(x)	((x)->oflag & OFLAG_KLINE)
629 #define OPCanUnKline(x)	((x)->oflag & OFLAG_UNKLINE)
630 #define OPCanLNotice(x)	((x)->oflag & OFLAG_LNOTICE)
631 #define OPCanGNotice(x)	((x)->oflag & OFLAG_GNOTICE)
632 #define OPIsAdmin(x)	((x)->oflag & OFLAG_ADMIN)
633 #define OPIsSAdmin(x)	((x)->oflag & OFLAG_SADMIN)
634 #define OPIsNetAdmin(x) ((x)->oflag & OFLAG_NETADMIN)
635 #define OPIsCoAdmin(x)	((x)->oflag & OFLAG_COADMIN)
636 #define OPIsWhois(x)    ((x)->oflag & OFLAG_WHOIS)
637 #ifdef SHOW_SECRET
638 #define OPCanSeeSecret(x) IsAnOper(x)
639 #else
640 #define OPCanSeeSecret(x) IsNetAdmin(x)
641 #endif
642 
643 #define OPSetRehash(x)	((x)->oflag |= OFLAG_REHASH)
644 #define OPSetDie(x)	((x)->oflag |= OFLAG_DIE)
645 #define OPSetRestart(x)	((x)->oflag |= OFLAG_RESTART)
646 #define OPSetHelpOp(x)	((x)->oflag |= OFLAG_HELPOP)
647 #define OPSetGlobOps(x)	((x)->oflag |= OFLAG_GLOBOP)
648 #define OPSetWallOps(x)	((x)->oflag |= OFLAG_WALLOP)
649 #define OPSetLocOps(x)	((x)->oflag |= OFLAG_LOCOP)
650 #define OPSetLRoute(x)	((x)->oflag |= OFLAG_LROUTE)
651 #define OPSetGRoute(x)	((x)->oflag |= OFLAG_GROUTE)
652 #define OPSetLKill(x)	((x)->oflag |= OFLAG_LKILL)
653 #define OPSetGKill(x)	((x)->oflag |= OFLAG_GKILL)
654 #define OPSetKline(x)	((x)->oflag |= OFLAG_KLINE)
655 #define OPSetUnKline(x)	((x)->oflag |= OFLAG_UNKLINE)
656 #define OPSetLNotice(x)	((x)->oflag |= OFLAG_LNOTICE)
657 #define OPSetGNotice(x)	((x)->oflag |= OFLAG_GNOTICE)
658 #define OPSSetAdmin(x)	((x)->oflag |= OFLAG_ADMIN)
659 #define OPSSetSAdmin(x)	((x)->oflag |= OFLAG_SADMIN)
660 #define OPSSetNetAdmin(x) ((x)->oflag |= OFLAG_NETADMIN)
661 #define OPSSetCoAdmin(x) ((x)->oflag |= OFLAG_COADMIN)
662 #define OPSetZLine(x)	((x)->oflag |= OFLAG_ZLINE)
663 #define OPSetWhois(x)   ((x)->oflag |= OFLAG_WHOIS)
664 #define OPClearRehash(x)	((x)->oflag &= ~OFLAG_REHASH)
665 #define OPClearDie(x)		((x)->oflag &= ~OFLAG_DIE)
666 #define OPClearRestart(x)	((x)->oflag &= ~OFLAG_RESTART)
667 #define OPClearHelpOp(x)	((x)->oflag &= ~OFLAG_HELPOP)
668 #define OPClearGlobOps(x)	((x)->oflag &= ~OFLAG_GLOBOP)
669 #define OPClearWallOps(x)	((x)->oflag &= ~OFLAG_WALLOP)
670 #define OPClearLocOps(x)	((x)->oflag &= ~OFLAG_LOCOP)
671 #define OPClearLRoute(x)	((x)->oflag &= ~OFLAG_LROUTE)
672 #define OPClearGRoute(x)	((x)->oflag &= ~OFLAG_GROUTE)
673 #define OPClearLKill(x)		((x)->oflag &= ~OFLAG_LKILL)
674 #define OPClearGKill(x)		((x)->oflag &= ~OFLAG_GKILL)
675 #define OPClearKline(x)		((x)->oflag &= ~OFLAG_KLINE)
676 #define OPClearUnKline(x)	((x)->oflag &= ~OFLAG_UNKLINE)
677 #define OPClearLNotice(x)	((x)->oflag &= ~OFLAG_LNOTICE)
678 #define OPClearGNotice(x)	((x)->oflag &= ~OFLAG_GNOTICE)
679 #define OPClearAdmin(x)		((x)->oflag &= ~OFLAG_ADMIN)
680 #define OPClearSAdmin(x)	((x)->oflag &= ~OFLAG_SADMIN)
681 #define OPClearNetAdmin(x)	((x)->oflag &= ~OFLAG_NETADMIN)
682 #define OPClearCoAdmin(x)	((x)->oflag &= ~OFLAG_COADMIN)
683 #define OPClearZLine(x)		((x)->oflag &= ~OFLAG_ZLINE)
684 #define OPClearWhois(x)         ((x)->oflag &= ~OFLAG_WHOIS)
685 /*
686  * defined debugging levels
687  */
688 #define	DEBUG_FATAL  0
689 #define	DEBUG_ERROR  1		/* report_error() and other errors that are found */
690 #define	DEBUG_NOTICE 3
691 #define	DEBUG_DNS    4		/* used by all DNS related routines - a *lot* */
692 #define	DEBUG_INFO   5		/* general usful info */
693 #define	DEBUG_NUM    6		/* numerics */
694 #define	DEBUG_SEND   7		/* everything that is sent out */
695 #define	DEBUG_DEBUG  8		/* anything to do with debugging, ie unimportant :) */
696 #define	DEBUG_MALLOC 9		/* malloc/free calls */
697 #define	DEBUG_LIST  10		/* debug list use */
698 
699 /* blah */
700 #define IsSkoAdmin(sptr) (IsAdmin(sptr) || IsNetAdmin(sptr) || IsSAdmin(sptr))
701 
702 /*
703  * defines for curses in client
704  */
705 #define	DUMMY_TERM	0
706 #define	CURSES_TERM	1
707 #define	TERMCAP_TERM	2
708 
709 /* Dcc deny types (see src/s_extra.c) */
710 #define DCCDENY_HARD	0
711 #define DCCDENY_SOFT	1
712 
713 /* Linked list dcc flags */
714 #define DCC_LINK_ME		1 /* My dcc allow */
715 #define DCC_LINK_REMOTE	2 /* I need to remove dccallows from these clients when I die */
716 
717 struct irc_netmask
718 {
719 	short int type;
720 	struct IN_ADDR mask;
721 	short int bits;
722 };
723 
724 struct FloodOpt {
725 	unsigned short nmsg;
726 	TS   firstmsg;
727 };
728 
729 #ifdef USE_LIBCURL
730 struct Motd;
731 struct MotdDownload
732 {
733 	struct Motd *themotd;
734 };
735 #endif /* USE_LIBCURL */
736 
737 struct Motd
738 {
739 	struct MotdItem *lines;
740 	struct tm last_modified; /* store the last modification time */
741 
742 #ifdef USE_LIBCURL
743 	/*
744 	  This pointer is used to communicate with an asynchronous MOTD
745 	  download. The problem is that a download may take 10 seconds or
746 	  more to complete and, in that time, the IRCd could be rehashed.
747 	  This would mean that TLD blocks are reallocated and thus the
748 	  aMotd structs would be free()d in the meantime.
749 
750 	  To prevent such a situation from leading to a segfault, we
751 	  introduce this remote control pointer. It works like this:
752 	  1. read_motd() is called with a URL. A new MotdDownload is
753 	     allocated and the pointer is placed here. This pointer is
754 	     also passed to the asynchrnous download handler.
755 	  2.a. The download is completed and read_motd_asynch_downloaded()
756 	       is called with the same pointer. From this function, this pointer
757 	       if free()d. No other code may free() the pointer. Not even free_motd().
758 	    OR
759 	  2.b. The user rehashes the IRCd before the download is completed.
760 	       free_motd() is called, which sets motd_download->themotd to NULL
761 	       to signal to read_motd_asynch_downloaded() that it should ignore
762 	       the download. read_motd_asynch_downloaded() is eventually called
763 	       and frees motd_download.
764 	 */
765 	struct MotdDownload *motd_download;
766 #endif /* USE_LIBCURL */
767 };
768 
769 struct MotdItem {
770 	char *line;
771 	struct MotdItem *next;
772 };
773 
774 struct aloopStruct {
775 	unsigned do_garbage_collect : 1;
776 	unsigned ircd_booted : 1;
777 	unsigned do_bancheck : 1; /* perform *line bancheck? */
778 	unsigned do_bancheck_spamf_user : 1; /* perform 'user' spamfilter bancheck */
779 	unsigned do_bancheck_spamf_away : 1; /* perform 'away' spamfilter bancheck */
780 	unsigned ircd_rehashing : 1;
781 	unsigned tainted : 1;
782 	aClient *rehash_save_cptr, *rehash_save_sptr;
783 	int rehash_save_sig;
784 };
785 
786 typedef struct Whowas {
787 	int  hashv;
788 	char *name;
789 	char *username;
790 	char *hostname;
791 	char *virthost;
792 	char *servername;
793 	char *realname;
794 	long umodes;
795 	TS   logoff;
796 	struct Client *online;	/* Pointer to new nickname for chasing or NULL */
797 	struct Whowas *next;	/* for hash table... */
798 	struct Whowas *prev;	/* for hash table... */
799 	struct Whowas *cnext;	/* for client struct linked list */
800 	struct Whowas *cprev;	/* for client struct linked list */
801 } aWhowas;
802 
803 /*
804  * Client structures
805  */
806 struct User {
807 	Membership *channel;		/* chain of channel pointer blocks */
808 	Link *invited;		/* chain of invite pointer blocks */
809 	Link *silence;		/* chain of silence pointer blocks */
810 	Link *dccallow;		/* chain of dccallowed entries */
811 	char *away;		/* pointer to away message */
812 
813 	/*
814 	 * svid: a value that is assigned by services to this user record.
815 	 * in previous versions of Unreal, this was strictly a timestamp value,
816 	 * which is less useful in the modern world of IRC where nicks are grouped to
817 	 * accounts, so it is now a string.
818 	 */
819 	char svid[SVIDLEN + 1];
820 
821 	signed char refcnt;	/* Number of times this block is referenced */
822 	unsigned short joined;		/* number of channels joined */
823 	char username[USERLEN + 1];
824 	char realhost[HOSTLEN + 1];
825 	char cloakedhost[HOSTLEN + 1]; /* cloaked host (masked host for caching). NOT NECESSARILY THE SAME AS virthost. */
826 	char *virthost;
827 	char *server;
828 	char *swhois;		/* special whois thing */
829 	LOpts *lopt;            /* Saved /list options */
830 	aWhowas *whowas;
831 	int snomask;
832 #ifdef	LIST_DEBUG
833 	aClient *bcptr;
834 #endif
835 	char *ip_str;		/* The IP in string form */
836 	char *operlogin;	/* Only used if person is/was opered, used for oper::maxlogins */
837 	struct {
838 		time_t nick_t;
839 		unsigned char nick_c;
840 #ifdef NO_FLOOD_AWAY
841 		time_t away_t;			/* last time the user set away */
842 		unsigned char away_c;	/* number of times away has been set */
843 #endif
844 	} flood;
845 #ifdef JOINTHROTTLE
846 	aJFlood *jflood;
847 #endif
848 	TS lastaway;
849 };
850 
851 struct Server {
852 	struct Server 	*nexts;
853 	anUser 		*user;		/* who activated this connection */
854 	char 		*up;		/* uplink for this server */
855 	char 		by[NICKLEN + 1];
856 	ConfigItem_link *conf;
857 	TS   		timestamp;		/* Remotely determined connect try time */
858 	unsigned short  numeric;	/* NS numeric, 0 if none */
859 	long		 users;
860 #ifdef	LIST_DEBUG
861 	aClient *bcptr;
862 #endif
863 	struct {
864 		unsigned synced:1;		/* Server linked? (3.2beta18+) */
865 		unsigned server_sent:1;		/* SERVER message sent to this link? (for outgoing links) */
866 	} flags;
867 };
868 
869 #define M_UNREGISTERED	0x0001
870 #define M_USER			0x0002
871 #define M_SERVER		0x0004
872 #define M_SHUN			0x0008
873 #define M_NOLAG			0x0010
874 #define M_ALIAS			0x0020
875 #define M_RESETIDLE		0x0040
876 #define M_VIRUS			0x0080
877 #define M_ANNOUNCE		0x0100
878 
879 
880 /* tkl:
881  *   TKL_KILL|TKL_GLOBAL 	= Global K:Line (G:Line)
882  *   TKL_ZAP|TKL_GLOBAL		= Global Z:Line (ZLINE)
883  *   TKL_KILL			= Timed local K:Line
884  *   TKL_ZAP			= Local Z:Line
885  */
886 #define TKL_KILL	0x0001
887 #define TKL_ZAP		0x0002
888 #define TKL_GLOBAL	0x0004
889 #define TKL_SHUN	0x0008
890 #define TKL_QUIET	0x0010
891 #define TKL_SPAMF	0x0020
892 #define TKL_NICK	0x0040
893 
894 #define SPAMF_CHANMSG		0x0001 /* c */
895 #define SPAMF_USERMSG		0x0002 /* p */
896 #define SPAMF_USERNOTICE	0x0004 /* n */
897 #define SPAMF_CHANNOTICE	0x0008 /* N */
898 #define SPAMF_PART			0x0010 /* P */
899 #define SPAMF_QUIT			0x0020 /* q */
900 #define SPAMF_DCC			0x0040 /* d */
901 #define SPAMF_USER			0x0080 /* u */
902 #define SPAMF_AWAY			0x0100 /* a */
903 #define SPAMF_TOPIC			0x0200 /* t */
904 
905 /* Other flags only for function calls: */
906 #define SPAMFLAG_NOWARN		0x0001
907 
908 struct _spamfilter {
909 	unsigned short action; /* see BAN_ACT* */
910 	regex_t expr;
911 	char *tkl_reason; /* spamfilter reason field [escaped by unreal_encodespace()!] */
912 	TS tkl_duration;
913 };
914 
915 struct t_kline {
916 	aTKline *prev, *next;
917 	int type;
918 	unsigned short subtype; /* subtype (currently spamfilter only), see SPAMF_* */
919 	union {
920 		Spamfilter *spamf;
921 		struct irc_netmask *netmask;
922 	} ptr;
923 	char usermask[USERLEN + 3];
924 	char *hostmask, *reason, *setby;
925 	TS expire_at, set_at;
926 };
927 
928 struct _spamexcept {
929 	SpamExcept *prev, *next;
930 	char name[1];
931 };
932 
933 typedef struct ircstatsx {
934 	int  clients;		/* total */
935 	int  invisible;		/* invisible */
936 	unsigned short  servers;		/* servers */
937 	int  operators;		/* operators */
938 	int  unknown;		/* unknown local connections */
939 	int  channels;		/* channels */
940 	int  me_clients;	/* my clients */
941 	unsigned short  me_servers;	/* my servers */
942 	int  me_max;		/* local max */
943 	int  global_max;	/* global max */
944 } ircstats;
945 
946 extern MODVAR ircstats IRCstats;
947 
948 #include "modules.h"
949 
950 extern MODVAR Umode *Usermode_Table;
951 extern MODVAR short	 Usermode_highest;
952 
953 extern MODVAR Snomask *Snomask_Table;
954 extern MODVAR short Snomask_highest;
955 
956 #ifdef EXTCMODE
957 extern MODVAR Cmode *Channelmode_Table;
958 extern MODVAR unsigned short Channelmode_highest;
959 #endif
960 
961 extern Umode *UmodeAdd(Module *module, char ch, int options, int (*allowed)(aClient *sptr, int what), long *mode);
962 extern void UmodeDel(Umode *umode);
963 
964 extern Snomask *SnomaskAdd(Module *module, char ch, int (*allowed)(aClient *sptr, int what), long *mode);
965 extern void SnomaskDel(Snomask *sno);
966 
967 #ifdef EXTCMODE
968 extern Cmode *CmodeAdd(Module *reserved, CmodeInfo req, Cmode_t *mode);
969 extern void CmodeDel(Cmode *cmode);
970 #endif
971 
972 typedef struct {
973 	EXTCM_PAR_HEADER
974 	unsigned short num;
975 	unsigned short t;
976 } aModejEntry;
977 
978 #define LISTENER_NORMAL		0x000001
979 #define LISTENER_CLIENTSONLY	0x000002
980 #define LISTENER_SERVERSONLY	0x000004
981 #define LISTENER_REMOTEADMIN	0x000008
982 #define LISTENER_JAVACLIENT	0x000010
983 #define LISTENER_MASK		0x000020
984 #define LISTENER_SSL		0x000040
985 #define LISTENER_BOUND		0x000080
986 
987 #define IsServersOnlyListener(x)	((x) && ((x)->umodes & LISTENER_SERVERSONLY))
988 
989 #define CONNECT_SSL		0x000001
990 #define CONNECT_ZIP		0x000002
991 #define CONNECT_AUTO		0x000004
992 #define CONNECT_QUARANTINE	0x000008
993 #define CONNECT_NODNSCACHE	0x000010
994 #define CONNECT_NOHOSTCHECK	0x000020
995 
996 #define SSLFLAG_FAILIFNOCERT 	0x1
997 #define SSLFLAG_VERIFYCERT 	0x2
998 #define SSLFLAG_DONOTACCEPTSELFSIGNED 0x4
999 #define SSLFLAG_NOSTARTTLS	0x8
1000 
1001 struct Client {
1002 	struct Client *next, *prev, *hnext;
1003 	anUser *user;		/* ...defined, if this is a User */
1004 	aServer *serv;		/* ...defined, if this is a server */
1005 	TS   lastnick;		/* TimeStamp on nick */
1006 	long flags;		/* client flags */
1007 	long umodes;		/* client usermodes */
1008 	aClient *from;		/* == self, if Local Client, *NEVER* NULL! */
1009 	int  fd;		/* >= 0, for local clients */
1010 	unsigned char hopcount;		/* number of servers to this 0 = local */
1011 	char name[HOSTLEN + 1];	/* Unique name of the client, nick or host */
1012 	char username[USERLEN + 1];	/* username here now for auth stuff */
1013 	char info[REALLEN + 1];	/* Free form additional client information */
1014 	aClient *srvptr;	/* Server introducing this.  May be &me */
1015 	short status;		/* client type */
1016 	/*
1017 	   ** The following fields are allocated only for local clients
1018 	   ** (directly connected to *this* server with a socket.
1019 	   ** The first of them *MUST* be the "count"--it is the field
1020 	   ** to which the allocation is tied to! *Never* refer to
1021 	   ** these fields, if (from != self).
1022 	 */
1023 	int  count;		/* Amount of data in buffer */
1024 #if 1
1025 	int  oflag;		/* oper access flags (removed from anUser for mem considerations) */
1026 	TS   since;		/* time they will next be allowed to send something */
1027 	TS   firsttime;		/* Time it was created */
1028 	TS   lasttime;		/* last time any message was received */
1029 	TS   last;		/* last time a RESETIDLE message was received */
1030 	TS   nexttarget;	/* next time that a new target will be allowed (msg/notice/invite) */
1031  	TS   nextnick;		/* Time the next nick change will be allowed */
1032 	u_char targets[MAXTARGETS];	/* hash values of targets */
1033 #endif
1034 	char buffer[BUFSIZE];	/* Incoming message buffer */
1035 	short lastsq;		/* # of 2k blocks when sendqueued called last */
1036 	dbuf sendQ;		/* Outgoing message queue--if socket full */
1037 	dbuf recvQ;		/* Hold for data incoming yet to be parsed */
1038 	u_int32_t nospoof;	/* Anti-spoofing random number */
1039 	int proto;		/* ProtoCtl options */
1040 	long sendM;		/* Statistics: protocol messages send */
1041 	long sendK;		/* Statistics: total k-bytes send */
1042 	long receiveM;		/* Statistics: protocol messages received */
1043 #ifdef ZIP_LINKS
1044 	struct Zdata *zip;	/* zip data */
1045 #elif defined(_WIN32)
1046 	void *zip_NOTUSED; /* (win32 binary compatability) */
1047 #endif
1048 #ifdef USE_SSL
1049 	SSL		*ssl;
1050 #elif defined(_WIN32)
1051 	void	*ssl_NOTUSED; /* (win32 binary compatability) */
1052 #endif
1053 #ifndef NO_FDLIST
1054 	long lastrecvM;		/* to check for activity --Mika */
1055 	int  priority;
1056 #endif
1057 	long receiveK;		/* Statistics: total k-bytes received */
1058 	u_short sendB;		/* counters to count upto 1-k lots of bytes */
1059 	u_short receiveB;	/* sent and received. */
1060 	aClient *listener;
1061 	ConfigItem_class *class;		/* Configuration record associated */
1062 	int authfd;		/* fd for rfc931 authentication */
1063         short slot;         /* my offset in the local fd table */
1064 	struct IN_ADDR ip;	/* keep real ip# too */
1065 	u_short port;		/* and the remote port# too :-) */
1066 	struct hostent *hostp;
1067 	u_short watches;	/* Keep track of count of notifies */
1068 	Link *watch;		/* Links to clients notify-structures */
1069 	char sockhost[HOSTLEN + 1];	/* This is the host name from the socket
1070 					   ** and after which the connection was
1071 					   ** accepted.
1072 					 */
1073 	char *passwd;
1074 #ifdef DEBUGMODE
1075 	TS   cputime;
1076 #endif
1077 	char *error_str;	/* Quit reason set by dead_link in case of socket/buffer error */
1078 
1079 	char sasl_agent[NICKLEN + 1];
1080 	unsigned char sasl_out;
1081 	unsigned char sasl_complete;
1082 	u_short sasl_cookie;
1083 };
1084 
1085 
1086 #define	CLIENT_LOCAL_SIZE sizeof(aClient)
1087 #define	CLIENT_REMOTE_SIZE offsetof(aClient,count)
1088 
1089 /*
1090  * conf2 stuff -stskeeps
1091 */
1092 
1093 /* Config flags */
1094 
1095 struct _configfile
1096 {
1097         char            *cf_filename;
1098         ConfigEntry     *cf_entries;
1099         ConfigFile     *cf_next;
1100 };
1101 
1102 struct _configentry
1103 {
1104         ConfigFile	*ce_fileptr;
1105         int 	 	ce_varlinenum, ce_fileposstart, ce_fileposend, ce_sectlinenum;
1106         char 		*ce_varname, *ce_vardata;
1107         ConfigEntry     *ce_entries, *ce_prevlevel, *ce_next;
1108 };
1109 
1110 struct _configflag
1111 {
1112 	unsigned	temporary : 1;
1113 	unsigned	permanent : 1;
1114 };
1115 
1116 /* configflag specialized for except socks/ban -Stskeeps */
1117 
1118 struct _configflag_except
1119 {
1120 	unsigned	temporary : 1;
1121 	unsigned	type	  : 2;
1122 };
1123 
1124 struct _configflag_ban
1125 {
1126 	unsigned	temporary : 1;
1127 	unsigned	type	  : 4;
1128 	unsigned	type2	  : 2;
1129 };
1130 
1131 struct _configflag_tld
1132 {
1133 	unsigned	temporary : 1;
1134 	unsigned	motdptr   : 1;
1135 	unsigned	rulesptr  : 1;
1136 };
1137 
1138 #define CONF_BAN_NICK		1
1139 #define CONF_BAN_IP		2
1140 #define CONF_BAN_SERVER		3
1141 #define CONF_BAN_USER   	4
1142 #define CONF_BAN_REALNAME 	5
1143 #define CONF_BAN_VERSION        6
1144 
1145 #define CONF_BAN_TYPE_CONF	0
1146 #define CONF_BAN_TYPE_AKILL	1
1147 #define CONF_BAN_TYPE_TEMPORARY 2
1148 
1149 /* Ban actions. These must be ordered by severity (!) */
1150 #define BAN_ACT_GZLINE		1100
1151 #define BAN_ACT_GLINE		1000
1152 #define BAN_ACT_ZLINE		 900
1153 #define BAN_ACT_KLINE		 800
1154 #define BAN_ACT_SHUN		 700
1155 #define BAN_ACT_KILL		 600
1156 #define BAN_ACT_TEMPSHUN	 500
1157 #define BAN_ACT_VIRUSCHAN	 400
1158 #define BAN_ACT_DCCBLOCK	 300
1159 #define BAN_ACT_BLOCK		 200
1160 #define BAN_ACT_WARN		 100
1161 
1162 
1163 #define CRULE_ALL		0
1164 #define CRULE_AUTO		1
1165 
1166 #define CONF_EXCEPT_BAN		1
1167 #define CONF_EXCEPT_TKL		2
1168 #define CONF_EXCEPT_THROTTLE	3
1169 
1170 
1171 struct _configitem {
1172 	ConfigFlag flag;
1173 	ConfigItem *prev, *next;
1174 };
1175 
1176 struct _configitem_me {
1177 	char	   *name, *info;
1178 	unsigned short	   numeric;
1179 };
1180 
1181 struct _configitem_files {
1182 	char	*motd_file, *rules_file, *smotd_file;
1183 	char	*botmotd_file, *opermotd_file, *svsmotd_file;
1184 	char	*pid_file, *tune_file;
1185 };
1186 
1187 struct _configitem_admin {
1188 	ConfigItem *prev, *next;
1189 	ConfigFlag flag;
1190 	char	   *line;
1191 };
1192 
1193 #define CLASS_OPT_NOFAKELAG		0x1
1194 
1195 struct _configitem_class {
1196 	ConfigItem *prev, *next;
1197 	ConfigFlag flag;
1198 	char	   *name;
1199 	int	   pingfreq, connfreq, maxclients, sendq, recvq, clients;
1200 	int xrefcount; /* EXTRA reference count, 'clients' also acts as a reference count but
1201 	                * link blocks also refer to classes so a 2nd ref. count was needed.
1202 	                */
1203 	unsigned int options;
1204 };
1205 
1206 struct _configflag_allow {
1207 	unsigned	noident :1;
1208 	unsigned	useip :1;
1209 	unsigned	ssl :1;
1210 	unsigned	nopasscont :1;
1211 };
1212 
1213 struct _configitem_allow {
1214 	ConfigItem			*prev, *next;
1215 	ConfigFlag			flag;
1216 	char				*ip, *hostname, *server;
1217 	anAuthStruct		*auth;
1218 	unsigned short		maxperip;
1219 	int					port;
1220 	ConfigItem_class	*class;
1221 	struct irc_netmask	*netmask;
1222 	ConfigFlag_allow	flags;
1223 #ifdef INET6
1224 	unsigned short ipv6_clone_mask;
1225 #endif /* INET6 */
1226 };
1227 
1228 struct _configitem_oper {
1229 	ConfigItem       *prev, *next;
1230 	ConfigFlag 	 flag;
1231 	char		 *name, *swhois, *snomask;
1232 	anAuthStruct	 *auth;
1233 	ConfigItem_class *class;
1234 	ConfigItem	 *from;
1235 	unsigned long	 modes, require_modes;
1236 	long		 oflags;
1237 	int			maxlogins;
1238 };
1239 
1240 struct _configitem_oper_from {
1241 	ConfigItem       *prev, *next;
1242 	ConfigFlag 	 flag;
1243 	char		 *name;
1244 	struct irc_netmask	*netmask;
1245 };
1246 
1247 struct _configitem_drpass {
1248 	anAuthStruct	 *restartauth;
1249 	anAuthStruct	 *dieauth;
1250 };
1251 
1252 struct _configitem_ulines {
1253 	ConfigItem       *prev, *next;
1254 	ConfigFlag 	 flag;
1255 	char 		 *servername;
1256 };
1257 
1258 #define TLD_SSL		0x1
1259 #define TLD_REMOTE	0x2
1260 
1261 struct _configitem_tld {
1262 	ConfigItem 	*prev, *next;
1263 	ConfigFlag_tld 	flag;
1264 	char 		*mask, *channel;
1265 	char 		*motd_file, *rules_file, *smotd_file;
1266 	char 		*botmotd_file, *opermotd_file;
1267 	aMotdFile	rules, motd, smotd, botmotd, opermotd;
1268 	u_short		options;
1269 };
1270 
1271 struct _configitem_listen {
1272 	ConfigItem 	*prev, *next;
1273 	ConfigFlag 	flag;
1274 	char		*ip;
1275 	int		port;
1276 	int		options, clients;
1277 	aClient		*listener;
1278 };
1279 
1280 struct _configitem_vhost {
1281 	ConfigItem 	*prev, *next;
1282 	ConfigFlag 	flag;
1283 	ConfigItem       *from;
1284 	char		*login, *virthost, *virtuser, *swhois;
1285 	anAuthStruct	*auth;
1286 };
1287 
1288 struct _configitem_link {
1289 	ConfigItem	*prev, *next;
1290 	ConfigFlag	flag;
1291 	char		*servername, *username, *hostname, *bindip, *hubmask, *leafmask, *connpwd;
1292 	anAuthStruct	*recvauth;
1293 	u_short		port, options;
1294 	unsigned char 	leafdepth;
1295 	int		refcount;
1296 	ConfigItem_class	*class;
1297 	struct IN_ADDR 		ipnum;
1298 	time_t			hold;
1299 #ifdef USE_SSL
1300 	char		*ciphers;
1301 #elif defined(_WIN32)
1302 	void *ciphers_NOTUSED;
1303 #endif
1304 #ifdef ZIP_LINKS
1305 	int compression_level;
1306 #endif
1307 };
1308 
1309 typedef enum {
1310 	CGIIRC_PASS=1, CGIIRC_WEBIRC=2
1311 } CGIIRCType;
1312 
1313 struct _configitem_cgiirc {
1314 	ConfigItem  *prev, *next;
1315 	ConfigFlag  flag;
1316 	CGIIRCType type;
1317 	char *username;
1318 	char *hostname;
1319 	anAuthStruct *auth;
1320 };
1321 
1322 struct _configitem_except {
1323 	ConfigItem      *prev, *next;
1324 	ConfigFlag_except      flag;
1325 	int type;
1326 	char		*mask;
1327 	struct irc_netmask *netmask;
1328 };
1329 
1330 struct _configitem_ban {
1331 	ConfigItem		*prev, *next;
1332 	ConfigFlag_ban	flag;
1333 	char			*mask, *reason;
1334 	struct irc_netmask	*netmask;
1335 	unsigned short action;
1336 };
1337 
1338 typedef struct _iplist IPList;
1339 struct _iplist {
1340 	IPList *prev, *next;
1341 	char *mask;
1342 /*	struct irc_netmask  *netmask; */
1343 };
1344 
1345 #ifdef FAST_BADWORD_REPLACE
1346 #define BADW_TYPE_INVALID 0x0
1347 #define BADW_TYPE_FAST    0x1
1348 #define BADW_TYPE_FAST_L  0x2
1349 #define BADW_TYPE_FAST_R  0x4
1350 #define BADW_TYPE_REGEX   0x8
1351 #endif
1352 
1353 #define BADWORD_REPLACE 1
1354 #define BADWORD_BLOCK 2
1355 
1356 struct _configitem_badword {
1357 	ConfigItem      *prev, *next;
1358 	ConfigFlag	flag;
1359 	char		*word, *replace;
1360 #ifdef FAST_BADWORD_REPLACE
1361 	unsigned short	type;
1362 #endif
1363 	char		action;
1364 	regex_t 	expr;
1365 };
1366 
1367 struct _configitem_deny_dcc {
1368 	ConfigItem		*prev, *next;
1369 	ConfigFlag_ban		flag;
1370 	char			*filename, *reason;
1371 };
1372 
1373 struct _configitem_deny_link {
1374 	ConfigItem              *prev, *next;
1375 	ConfigFlag_except       flag;
1376 	char			*mask, *rule, *prettyrule;
1377 };
1378 
1379 struct _configitem_deny_version {
1380 	ConfigItem		*prev, *next;
1381 	ConfigFlag		flag;
1382 	char 			*mask, *version, *flags;
1383 };
1384 
1385 struct _configitem_deny_channel {
1386 	ConfigItem		*prev, *next;
1387 	ConfigFlag		flag;
1388 	char			*channel, *reason, *redirect, *class;
1389 	unsigned char	warn;
1390 };
1391 
1392 struct _configitem_allow_channel {
1393 	ConfigItem		*prev, *next;
1394 	ConfigFlag		flag;
1395 	char			*channel, *class;
1396 };
1397 
1398 struct _configitem_allow_dcc {
1399 	ConfigItem		*prev, *next;
1400 	ConfigFlag_ban	flag;
1401 	char			*filename;
1402 };
1403 
1404 struct _configitem_log {
1405 	ConfigItem *prev, *next;
1406 	ConfigFlag flag;
1407 	char *file;
1408 	long maxsize;
1409 	int  flags;
1410 };
1411 
1412 struct _configitem_unknown {
1413 	ConfigItem *prev, *next;
1414 	ConfigFlag flag;
1415 	ConfigEntry *ce;
1416 };
1417 
1418 struct _configitem_unknown_ext {
1419 	ConfigItem *prev, *next;
1420 	ConfigFlag flag;
1421 	char *ce_varname, *ce_vardata;
1422 	ConfigFile      *ce_fileptr;
1423 	int             ce_varlinenum;
1424 	ConfigEntry     *ce_entries;
1425 };
1426 
1427 
1428 typedef enum {
1429 	ALIAS_SERVICES=1, ALIAS_STATS, ALIAS_NORMAL, ALIAS_COMMAND, ALIAS_CHANNEL, ALIAS_REAL
1430 } AliasType;
1431 
1432 struct _configitem_alias {
1433 	ConfigItem *prev, *next;
1434 	ConfigFlag flag;
1435 	ConfigItem_alias_format *format;
1436 	char *alias, *nick;
1437 	AliasType type;
1438 	unsigned int spamfilter:1;
1439 };
1440 
1441 struct _configitem_alias_format {
1442 	ConfigItem *prev, *next;
1443 	ConfigFlag flag;
1444 	char *nick;
1445 	AliasType type;
1446 	char *format, *parameters;
1447 	regex_t expr;
1448 };
1449 
1450 /**
1451  * In a rehash scenario, conf_include will contain all of the included
1452  * configs that are actually in use. It also will contain includes
1453  * that are being processed so that the configuration may be updated.
1454  * INCLUDE_NOTLOADED is set on all of the config files that are being
1455  * loaded and unset on already-loaded files. See
1456  * unload_loaded_includes() and load_includes().
1457  */
1458 #define INCLUDE_NOTLOADED  0x1
1459 #define INCLUDE_REMOTE     0x2
1460 #define INCLUDE_DLQUEUED   0x4
1461 /**
1462  * Marks that an include was loaded without error. This seems to
1463  * overlap with the INCLUDE_NOTLOADED meaning(?). --binki
1464  */
1465 #define INCLUDE_USED       0x8
1466 
1467 struct _configitem_include {
1468 	ConfigItem *prev, *next;
1469 	ConfigFlag_ban flag;
1470 	char *file;
1471 #ifdef USE_LIBCURL
1472 	char *url;
1473 	char *errorbuf;
1474 #endif
1475 	char *included_from;
1476 	int included_from_line;
1477 };
1478 
1479 struct _configitem_help {
1480 	ConfigItem *prev, *next;
1481 	ConfigFlag flag;
1482 	char *command;
1483 	aMotdLine *text;
1484 };
1485 
1486 struct _configitem_offchans {
1487 	ConfigItem *prev, *next;
1488 	char chname[CHANNELLEN+1];
1489 	char *topic;
1490 };
1491 
1492 #define HM_HOST 1
1493 #define HM_IPV4 2
1494 #define HM_IPV6 3
1495 
1496 /*
1497  * statistics structures
1498  */
1499 struct stats {
1500 	unsigned int is_cl;	/* number of client connections */
1501 	unsigned int is_sv;	/* number of server connections */
1502 	unsigned int is_ni;	/* connection but no idea who it was */
1503 	unsigned short is_cbs;	/* bytes sent to clients */
1504 	unsigned short is_cbr;	/* bytes received to clients */
1505 	unsigned short is_sbs;	/* bytes sent to servers */
1506 	unsigned short is_sbr;	/* bytes received to servers */
1507 	unsigned long is_cks;	/* k-bytes sent to clients */
1508 	unsigned long is_ckr;	/* k-bytes received to clients */
1509 	unsigned long is_sks;	/* k-bytes sent to servers */
1510 	unsigned long is_skr;	/* k-bytes received to servers */
1511 	TS   is_cti;		/* time spent connected by clients */
1512 	TS   is_sti;		/* time spent connected by servers */
1513 	unsigned int is_ac;	/* connections accepted */
1514 	unsigned int is_ref;	/* accepts refused */
1515 	unsigned int is_unco;	/* unknown commands */
1516 	unsigned int is_wrdi;	/* command going in wrong direction */
1517 	unsigned int is_unpf;	/* unknown prefix */
1518 	unsigned int is_empt;	/* empty message */
1519 	unsigned int is_num;	/* numeric message */
1520 	unsigned int is_kill;	/* number of kills generated on collisions */
1521 	unsigned int is_fake;	/* MODE 'fakes' */
1522 	unsigned int is_asuc;	/* successful auth requests */
1523 	unsigned int is_abad;	/* bad auth requests */
1524 	unsigned int is_udp;	/* packets recv'd on udp port */
1525 	unsigned int is_loc;	/* local connections made */
1526 };
1527 
1528 typedef struct _MemoryInfo {
1529 	unsigned int classes;
1530 	unsigned long classesmem;
1531 } MemoryInfo;
1532 
1533 struct ListOptions {
1534 	LOpts *next;
1535 	Link *yeslist, *nolist;
1536 	unsigned int  starthash;
1537 	short int showall;
1538 	unsigned short usermin;
1539 	int  usermax;
1540 	TS   currenttime;
1541 	TS   chantimemin;
1542 	TS   chantimemax;
1543 	TS   topictimemin;
1544 	TS   topictimemax;
1545 };
1546 
1547 #ifdef EXTCMODE
1548 #define EXTCMODETABLESZ 32
1549 #endif /* EXTCMODE */
1550 
1551 /* this can be like ~60-90 bytes, therefore it's in a seperate struct */
1552 #define FLD_CTCP	0 /* c */
1553 #define FLD_JOIN	1 /* j */
1554 #define FLD_KNOCK	2 /* k */
1555 #define FLD_MSG		3 /* m */
1556 #define FLD_NICK	4 /* n */
1557 #define FLD_TEXT	5 /* t */
1558 
1559 #define NUMFLD	6 /* 6 flood types */
1560 
1561 struct SRemoveFld {
1562 	struct SRemoveFld *prev, *next;
1563 	aChannel *chptr;
1564 	char m; /* mode to be removed */
1565 	time_t when; /* scheduled at */
1566 };
1567 
1568 struct SChanFloodProt {
1569 	unsigned short	per; /* setting: per <XX> seconds */
1570 	time_t			t[NUMFLD]; /* runtime: timers */
1571 	unsigned short	c[NUMFLD]; /* runtime: counters */
1572 	unsigned short	l[NUMFLD]; /* setting: limit */
1573 	unsigned char	a[NUMFLD]; /* setting: action */
1574 	unsigned char	r[NUMFLD]; /* setting: remove-after <this> minutes */
1575 	unsigned long	timer_flags; /* if a "-m timer" is running this is & MODE_MODERATED etc.. */
1576 };
1577 
1578 /* mode structure for channels */
1579 struct SMode {
1580 	long mode;
1581 #ifdef EXTCMODE
1582 	Cmode_t extmode;
1583 	CmodeParam *extmodeparam;
1584 #endif
1585 	int  limit;
1586 	char key[KEYLEN + 1];
1587 	char link[LINKLEN + 1];
1588 #ifdef NEWCHFLOODPROT
1589 	ChanFloodProt *floodprot;
1590 #else
1591 	/* x:y */
1592 	unsigned short  msgs;		/* x */
1593 	unsigned short  per;		/* y */
1594 	unsigned char	 kmode;	/* mode  0 = kick  1 = ban */
1595 #endif
1596 };
1597 
1598 /* Used for notify-hash buckets... -Donwulff */
1599 
1600 struct Watch {
1601 	aWatch *hnext;
1602 	TS   lasttime;
1603 	Link *watch;
1604 	char nick[1];
1605 };
1606 
1607 /* general link structure used for chains */
1608 
1609 struct SLink {
1610 	struct SLink *next;
1611 	int  flags;
1612 	union {
1613 		aClient *cptr;
1614 		aChannel *chptr;
1615 		ListStruct *aconf;
1616 		aWatch *wptr;
1617 		aName *whowas;
1618 		char *cp;
1619 		struct {
1620 			char *banstr;
1621 			char *who;
1622 			TS   when;
1623 		} ban;
1624 	} value;
1625 };
1626 
1627 struct SMember
1628 {
1629 	struct SMember *next;
1630 	aClient	      *cptr;
1631 	int		flags;
1632 };
1633 
1634 struct Channel {
1635 	struct Channel *nextch, *prevch, *hnextch;
1636 	Mode mode;
1637 	TS   creationtime;
1638 	char *topic;
1639 	char *topic_nick;
1640 	TS   topic_time;
1641 	unsigned short users;
1642 	Member *members;
1643 	Link *invites;
1644 	Ban *banlist;
1645 	Ban *exlist;		/* exceptions */
1646 	Ban *invexlist;         /* invite list */
1647 #ifdef JOINTHROTTLE
1648 	aJFlood *jflood;
1649 #endif
1650 	char *mode_lock;
1651 	char chname[1];
1652 };
1653 
1654 struct SMembershipL
1655 {
1656 	struct SMembership 	*next;
1657 	struct Channel		*chptr;
1658 	int			flags;
1659 	aFloodOpt		flood;
1660 };
1661 
1662 struct SMembership
1663 {
1664 	struct SMembership 	*next;
1665 	struct Channel		*chptr;
1666 	int			flags;
1667 };
1668 
1669 struct SBan {
1670 	struct SBan *next;
1671 	char *banstr;
1672 	char *who;
1673 	TS   when;
1674 };
1675 
1676 struct DSlink {
1677 	struct DSlink *next;
1678 	struct DSlink *prev;
1679 	union {
1680 		aClient *cptr;
1681 		aChannel *chptr;
1682 		ListStruct *aconf;
1683 		char *cp;
1684 	} value;
1685 };
1686 #define AddListItem(item,list) add_ListItem((ListStruct *)item, (ListStruct **)&list)
1687 #define DelListItem(item,list) del_ListItem((ListStruct *)item, (ListStruct **)&list)
1688 /* Backwards compatibility */
1689 #define add_ConfigItem(item,list) add_ListItem((ListStruct *)item, (ListStruct **)&list)
1690 #define del_ConfigItem(item,list) del_ListItem((ListStruct *)item, (ListStruct **)&list)
1691 
1692 struct liststruct {
1693 	ListStruct *prev, *next;
1694 };
1695 
1696 /* channel structure */
1697 
1698 
1699 /*
1700 ** Channel Related macros follow
1701 */
1702 
1703 /* Channel related flags */
1704 
1705 #define	CHFL_CHANOP     0x0001	/* Channel operator */
1706 #define	CHFL_VOICE      0x0002	/* the power to speak */
1707 
1708 #define	CHFL_DEOPPED	0x0004	/* Is de-opped by a server */
1709 #define	CHFL_SERVOPOK   0x0008	/* Server op allowed */
1710 #define	CHFL_ZOMBIE     0x0010	/* Kicked from channel */
1711 /* Bans are stored in separate linked list, so phase this out? */
1712 #define	CHFL_BAN     	0x0020	/* ban channel flag */
1713 #define CHFL_CHANOWNER 	0x0040	/* channel owner */
1714 #define CHFL_CHANPROT  	0x0080	/* chan op protection */
1715 #define CHFL_HALFOP	0x0100	/* halfop */
1716 #define CHFL_EXCEPT	0x0200	/* phase this out ? +e */
1717 #define CHFL_INVEX	0x0400  /* invite exception */
1718 
1719 #define	CHFL_OVERLAP    (CHFL_CHANOWNER|CHFL_CHANPROT|CHFL_CHANOP|CHFL_VOICE|CHFL_HALFOP)
1720 
1721 /* Channel macros */
1722 
1723 #define	MODE_CHANOP		CHFL_CHANOP
1724 #define	MODE_VOICE		CHFL_VOICE
1725 #define	MODE_PRIVATE		0x0004
1726 #define	MODE_SECRET		0x0008
1727 #define	MODE_MODERATED  	0x0010
1728 #define	MODE_TOPICLIMIT 	0x0020
1729 #define MODE_CHANOWNER		0x0040
1730 #define MODE_CHANPROT		0x0080
1731 #define	MODE_HALFOP		0x0100
1732 #define MODE_EXCEPT		0x0200
1733 #define	MODE_BAN		0x0400
1734 #define	MODE_INVITEONLY 	0x0800
1735 #define	MODE_NOPRIVMSGS 	0x1000
1736 #define	MODE_KEY		0x2000
1737 #define	MODE_LIMIT		0x4000
1738 #define MODE_RGSTR		0x8000
1739 #define MODE_RGSTRONLY 		0x10000
1740 #define MODE_LINK		0x20000
1741 #define MODE_NOCOLOR		0x40000
1742 #define MODE_OPERONLY   	0x80000
1743 #define MODE_ADMONLY   		0x100000
1744 #define MODE_NOKICKS   		0x200000
1745 #define MODE_STRIP	   	0x400000
1746 #define MODE_NOKNOCK		0x800000
1747 #define MODE_NOINVITE  		0x1000000
1748 #define MODE_FLOODLIMIT		0x2000000
1749 #define MODE_MODREG		0x4000000
1750 #define MODE_INVEX		0x8000000
1751 #define MODE_NOCTCP		0x10000000
1752 #define MODE_AUDITORIUM		0x20000000
1753 #define MODE_ONLYSECURE		0x40000000
1754 #define MODE_NONICKCHANGE	0x80000000
1755 
1756 #define is_halfop is_half_op
1757 /*
1758  * mode flags which take another parameter (With PARAmeterS)
1759  */
1760 #define	MODE_WPARAS (MODE_HALFOP|MODE_CHANOP|MODE_VOICE|MODE_CHANOWNER|MODE_CHANPROT|MODE_BAN|MODE_KEY|MODE_LINK|MODE_LIMIT|MODE_EXCEPT|MODE_INVEX)
1761 /*
1762  * Undefined here, these are used in conjunction with the above modes in
1763  * the source.
1764 #define	MODE_DEL       0x200000000
1765 #define	MODE_ADD       0x400000000
1766  */
1767 
1768 #define	HoldChannel(x)		(!(x))
1769 /* name invisible */
1770 #define	SecretChannel(x)	((x) && ((x)->mode.mode & MODE_SECRET))
1771 /* channel not shown but names are */
1772 #define	HiddenChannel(x)	((x) && ((x)->mode.mode & MODE_PRIVATE))
1773 /* channel visible */
1774 #define	ShowChannel(v,c)	(PubChannel(c) || IsMember((v),(c)))
1775 #define	PubChannel(x)		((!x) || ((x)->mode.mode &\
1776 				 (MODE_PRIVATE | MODE_SECRET)) == 0)
1777 
1778 #define	IsChannelName(name) ((name) && (*(name) == '#'))
1779 
1780 #define IsMember(blah,chan) ((blah && blah->user && \
1781                 find_membership_link((blah->user)->channel, chan)) ? 1 : 0)
1782 
1783 
1784 /* Misc macros */
1785 
1786 #define	BadPtr(x) (!(x) || (*(x) == '\0'))
1787 
1788 /** Is valid character in nick? [not for external usage, use do_check_nickname instead!] */
1789 #define isvalid(c)   (char_atribs[(u_char)(c)]&ALLOWN)
1790 
1791 /* remote fds are set to -256, else its a local fd (a local fd
1792  * can get -1 or -2 in case it has been closed). -- Syzop
1793  */
1794 #define	MyConnect(x)			((x)->fd != -256)
1795 #define	MyClient(x)			(MyConnect(x) && IsClient(x))
1796 #define	MyOper(x)			(MyConnect(x) && IsAnOper(x))
1797 
1798 #ifdef CLEAN_COMPILE
1799 #define TStime() (time(NULL) + TSoffset)
1800 #else
1801 #define TStime() (timeofday == 0 ? (timeofday = time(NULL) + TSoffset) : timeofday)
1802 #endif
1803 
1804 /* Lifted somewhat from Undernet code --Rak */
1805 
1806 #define IsSendable(x)		(DBufLength(&x->sendQ) < 2048)
1807 #define DoList(x)		((x)->user && (x)->user->lopt)
1808 
1809 /* String manipulation macros */
1810 
1811 /* strncopynt --> strncpyzt to avoid confusion, sematics changed
1812    N must be now the number of bytes in the array --msa */
1813 #define	strncpyzt(x, y, N) do{(void)strncpy(x,y,N);x[N-1]='\0';}while(0)
1814 #define	StrEq(x,y)	(!strcmp((x),(y)))
1815 
1816 /* used in SetMode() in channel.c and m_umode() in s_msg.c */
1817 
1818 #define	MODE_NULL      0
1819 #define	MODE_ADD       0x40000000
1820 #define	MODE_DEL       0x20000000
1821 
1822 /* return values for hunt_server() */
1823 
1824 #define	HUNTED_NOSUCH	(-1)	/* if the hunted server is not found */
1825 #define	HUNTED_ISME	0	/* if this server should execute the command */
1826 #define	HUNTED_PASS	1	/* if message passed onwards successfully */
1827 
1828 /* used when sending to #mask or $mask */
1829 
1830 #define	MATCH_SERVER  1
1831 #define	MATCH_HOST    2
1832 
1833 /* used for async dns values */
1834 
1835 #define	ASYNC_NONE	(-1)
1836 #define	ASYNC_CLIENT	0
1837 #define	ASYNC_CONNECT	1
1838 #define	ASYNC_CONF	2
1839 #define	ASYNC_SERVER	3
1840 
1841 /* misc variable externs */
1842 
1843 extern MODVAR char *version, *infotext[], *dalinfotext[], *unrealcredits[], *unrealinfo[];
1844 extern MODVAR char *generation, *creation;
1845 extern MODVAR char *gnulicense[];
1846 /* misc defines */
1847 
1848 #define	FLUSH_BUFFER	-2
1849 #define	COMMA		","
1850 
1851 #define PARTFMT		":%s PART %s"
1852 #define PARTFMT2	":%s PART %s :%s"
1853 
1854 #define isexcept void
1855 
1856 #ifdef USE_SSL
1857 #include "ssl.h"
1858 #endif
1859 #define EVENT_HASHES EVENT_DRUGS
1860 #include "events.h"
1861 struct Command {
1862 	aCommand		*prev, *next;
1863 	char 			*cmd;
1864 	int			(*func) ();
1865 	int			flags;
1866 	unsigned int    	count;
1867 	unsigned		parameters : 5;
1868 	unsigned long   	bytes;
1869 	Module 			*owner;
1870 	aCommand		*friend; /* cmd if token, token if cmd */
1871 	Cmdoverride		*overriders;
1872 	Cmdoverride		*overridetail;
1873 #ifdef DEBUGMODE
1874 	unsigned long 		lticks;
1875 	unsigned long 		rticks;
1876 #endif
1877 };
1878 
1879 struct _cmdoverride {
1880 	Cmdoverride		*prev, *next;
1881 	Module			*owner;
1882 	aCommand		*command;
1883 	int			(*func)();
1884 };
1885 
1886 #ifdef THROTTLING
1887 
1888 struct ThrottlingBucket
1889 {
1890 	struct ThrottlingBucket *prev, *next;
1891 	struct IN_ADDR	in;
1892 	time_t		since;
1893 	char		count;
1894 };
1895 
1896 typedef struct {
1897 	long mode;
1898 	char flag;
1899 	unsigned  halfop : 1;       /* 1 = yes 0 = no */
1900 	unsigned  parameters : 1;
1901 } aCtab;
1902 
1903 #ifdef JOINTHROTTLE
1904 /** A jointhrottle item, this is a double linked list.
1905  * prev_u    Previous entry of user
1906  * next_u    Next entry of user
1907  * prev_c    Previous entry of channel
1908  * next_c    Next entry of channel
1909  * chptr     The channel this entry applies to
1910  * cptr      The user this entry applies to
1911  * firstjoin Timestamp of "first join" (since last timer reset)
1912  * numjoin   Number of joins since that period
1913  * CLARIFICATION:
1914  * Why a double linked list? Well, the following operations need to be performed:
1915  * - if user quits, entry must be removed
1916  * - if channel is destroyed, entry must be removed
1917  * (and of course, more, but these are the most important ones affecting this decision)
1918  * While it would be possible to have a linked list only by user (for example),
1919  * that would mean that upon channel destroy ALL entries would have to be searched
1920  * trough, which might mean for example 800*8=6400 entries in a peak situation
1921  * (such as after a server restart and hundreds of clients connecting&joining).
1922  * For obvious reasons, that would be a very bad idea :).
1923  * So this costs us 2 pointers (8b on ia32) per entry, but in case of channel destroy
1924  * it means we only have for example 20 entries to scan trough rather than 2000.
1925  * Worth the extra memory :). -- Syzop
1926  * Note that in normal situations it won't be that bad since we will try to
1927  * regulary free up some entries.
1928  */
1929 struct JFlood {
1930 	aJFlood *prev_u, *next_u;
1931 	aJFlood *prev_c, *next_c;
1932 	aChannel *chptr;
1933 	aClient *cptr;
1934 	time_t firstjoin;
1935 	unsigned short numjoins;
1936 };
1937 #endif
1938 
1939 struct PendingNet {
1940         aPendingNet *prev, *next; /* Previous and next in list */
1941         aClient *sptr; /**< Client to which these servers belong */
1942         int numservers; /**< Amount of servers in list */
1943         int servers[1]; /** The list of servers (array of integer server numerics) */
1944 };
1945 
1946 void	init_throttling_hash();
1947 int	hash_throttling(struct IN_ADDR *in);
1948 struct	ThrottlingBucket	*find_throttling_bucket(struct IN_ADDR *in);
1949 void	add_throttling_bucket(struct IN_ADDR *in);
1950 void	del_throttling_bucket(struct ThrottlingBucket *bucket);
1951 int	throttle_can_connect(aClient *, struct IN_ADDR *in);
1952 
1953 #endif
1954 
1955 #define VERIFY_OPERCOUNT(clnt,tag) { if (IRCstats.operators < 0) verify_opercount(clnt,tag); } while(0)
1956 
1957 #define MARK_AS_OFFICIAL_MODULE(modinf)	do { if (modinf && modinf->handle) ModuleSetOptions(modinfo->handle, MOD_OPT_OFFICIAL);  } while(0)
1958 
1959 /* old.. please don't use anymore */
1960 #define CHANOPPFX "@"
1961 
1962 /* used for is_banned type field: */
1963 #define BANCHK_JOIN		0	/* checking if a ban forbids the person from joining */
1964 #define BANCHK_MSG		1	/* checking if a ban forbids the person from sending messages */
1965 #define BANCHK_NICK		2	/* checking if a ban forbids the person from changing his/her nick */
1966 
1967 #define TKLISTLEN 26
1968 
1969 #endif /* __struct_include__ */
1970 
1971 #include "dynconf.h"
1972