unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive | README | LICENSE |
struct.h (96032B)
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 #define OPENSSL_NO_KRB5 32 #include <openssl/rsa.h> /* SSL stuff */ 33 #include <openssl/crypto.h> 34 #include <openssl/x509.h> 35 #include <openssl/pem.h> 36 #include <openssl/ssl.h> 37 #include <openssl/err.h> 38 #include <openssl/evp.h> 39 #include <openssl/rand.h> 40 #include <openssl/md5.h> 41 #include <openssl/ripemd.h> 42 #ifdef HAS_X509_check_host 43 #include <openssl/x509v3.h> 44 #endif 45 #include <jansson.h> 46 #include "common.h" 47 #include "sys.h" 48 #include <stdio.h> 49 #include <sys/types.h> 50 #ifndef _WIN32 51 #include <netinet/in.h> 52 #include <netdb.h> 53 #include <stddef.h> 54 #endif 55 56 #ifdef HAVE_SYSLOG 57 # include <syslog.h> 58 # ifdef SYSSYSLOGH 59 # include <sys/syslog.h> 60 # endif 61 #ifndef UNREAL_LOGGER_CODE 62 /* undef these as they cause confusion with our ULOG_xxx codes */ 63 #undef LOG_DEBUG 64 #undef LOG_INFO 65 #undef LOG_WARNING 66 #undef LOG_ERROR 67 #undef LOG_FATAL 68 #endif 69 #endif 70 #define PCRE2_CODE_UNIT_WIDTH 8 71 #include "pcre2.h" 72 73 #include "channel.h" 74 75 typedef struct LoopStruct LoopStruct; 76 typedef struct TKL TKL; 77 typedef struct Spamfilter Spamfilter; 78 typedef struct ServerBan ServerBan; 79 typedef struct BanException BanException; 80 typedef struct NameBan NameBan; 81 typedef struct SpamExcept SpamExcept; 82 typedef struct ConditionalConfig ConditionalConfig; 83 typedef struct ConfigEntry ConfigEntry; 84 typedef struct ConfigFile ConfigFile; 85 typedef struct ConfigFlag ConfigFlag; 86 typedef struct ConfigFlag_except ConfigFlag_except; 87 typedef struct ConfigFlag_ban ConfigFlag_ban; 88 typedef struct ConfigFlag_tld ConfigFlag_tld; 89 typedef struct ConfigItem ConfigItem; 90 typedef struct ConfigItem_me ConfigItem_me; 91 typedef struct ConfigItem_files ConfigItem_files; 92 typedef struct ConfigItem_admin ConfigItem_admin; 93 typedef struct ConfigItem_class ConfigItem_class; 94 typedef struct ConfigItem_oper ConfigItem_oper; 95 typedef struct ConfigItem_operclass ConfigItem_operclass; 96 typedef struct ConfigItem_mask ConfigItem_mask; 97 typedef struct ConfigItem_drpass ConfigItem_drpass; 98 typedef struct ConfigItem_ulines ConfigItem_ulines; 99 typedef struct ConfigItem_tld ConfigItem_tld; 100 typedef struct ConfigItem_listen ConfigItem_listen; 101 typedef struct ConfigItem_sni ConfigItem_sni; 102 typedef struct ConfigItem_allow ConfigItem_allow; 103 typedef struct ConfigFlag_allow ConfigFlag_allow; 104 typedef struct ConfigItem_allow_channel ConfigItem_allow_channel; 105 typedef struct ConfigItem_allow_dcc ConfigItem_allow_dcc; 106 typedef struct ConfigItem_vhost ConfigItem_vhost; 107 typedef struct ConfigItem_link ConfigItem_link; 108 typedef struct ConfigItem_ban ConfigItem_ban; 109 typedef struct ConfigItem_deny_dcc ConfigItem_deny_dcc; 110 typedef struct ConfigItem_deny_channel ConfigItem_deny_channel; 111 typedef struct ConfigItem_deny_version ConfigItem_deny_version; 112 typedef struct ConfigItem_alias ConfigItem_alias; 113 typedef struct ConfigItem_alias_format ConfigItem_alias_format; 114 typedef struct ConfigResource ConfigResource; 115 typedef struct ConfigItem_blacklist_module ConfigItem_blacklist_module; 116 typedef struct ConfigItem_help ConfigItem_help; 117 typedef struct ConfigItem_offchans ConfigItem_offchans; 118 typedef struct SecurityGroup SecurityGroup; 119 typedef struct Secret Secret; 120 typedef struct ListStruct ListStruct; 121 typedef struct ListStructPrio ListStructPrio; 122 123 #define CFG_TIME 0x0001 124 #define CFG_SIZE 0x0002 125 #define CFG_YESNO 0x0004 126 127 typedef struct Watch Watch; 128 typedef struct Client Client; 129 typedef struct LocalClient LocalClient; 130 typedef struct Channel Channel; 131 typedef struct User User; 132 typedef struct Server Server; 133 typedef struct RPCClient RPCClient; 134 typedef struct Link Link; 135 typedef struct Ban Ban; 136 typedef struct Mode Mode; 137 typedef struct MessageTag MessageTag; 138 typedef struct MOTDFile MOTDFile; /* represents a whole MOTD, including remote MOTD support info */ 139 typedef struct MOTDLine MOTDLine; /* one line of a MOTD stored as a linked list */ 140 141 typedef struct RealCommand RealCommand; 142 typedef struct CommandOverride CommandOverride; 143 typedef struct Member Member; 144 typedef struct Membership Membership; 145 146 typedef enum OperClassEntryType { OPERCLASSENTRY_ALLOW=1, OPERCLASSENTRY_DENY=2} OperClassEntryType; 147 148 typedef enum OperPermission { OPER_ALLOW=1, OPER_DENY=0} OperPermission; 149 150 typedef enum SendType { 151 SEND_TYPE_PRIVMSG = 0, 152 SEND_TYPE_NOTICE = 1, 153 SEND_TYPE_TAGMSG = 2 154 } SendType; 155 156 struct OperClassValidator; 157 typedef struct OperClassValidator OperClassValidator; 158 typedef struct OperClassACLPath OperClassACLPath; 159 typedef struct OperClass OperClass; 160 typedef struct OperClassACL OperClassACL; 161 typedef struct OperClassACLEntry OperClassACLEntry; 162 typedef struct OperClassACLEntryVar OperClassACLEntryVar; 163 typedef struct OperClassCheckParams OperClassCheckParams; 164 165 typedef OperPermission (*OperClassEntryEvalCallback)(OperClassACLEntryVar* variables,OperClassCheckParams* params); 166 167 #ifndef VMSP 168 #include "dbuf.h" /* THIS REALLY SHOULDN'T BE HERE!!! --msa */ 169 #endif 170 171 #define HOSTLEN 63 /* Length of hostname */ 172 #define NICKLEN 30 173 #define USERLEN 10 174 #define REALLEN 50 175 #define ACCOUNTLEN 30 176 #define MAXTOPICLEN 360 /* absolute maximum permitted topic length (above this = potential desync) */ 177 #define MAXAWAYLEN 360 /* absolute maximum permitted away length (above this = potential desync) */ 178 #define MAXKICKLEN 360 /* absolute maximum kick length (above this = only cutoff danger) */ 179 #define MAXQUITLEN 395 /* absolute maximum quit length (above this = only cutoff danger) */ 180 #define CHANNELLEN 32 181 #define PASSWDLEN 256 /* some insane large limit (previously: 20, 32, 48) */ 182 #define KEYLEN 23 183 #define LINKLEN 32 184 #define BUFSIZE 512 /* WARNING: *DONT* CHANGE THIS!!!! */ 185 #define MAXTAGSIZE 8192 /**< Maximum length of message tags (4K user + 4K server) */ 186 #define MAXLINELENGTH (MAXTAGSIZE+BUFSIZE) /**< Maximum length of a line on IRC: 4k client tags + 4k server tags + 512 bytes (IRCv3) */ 187 #define READBUFSIZE MAXLINELENGTH /* for the read buffer */ 188 #define MAXRECIPIENTS 20 189 #define MAXSILELENGTH NICKLEN+USERLEN+HOSTLEN+10 190 #define IDLEN 12 191 #define SIDLEN 3 192 #define SWHOISLEN 256 193 #define UMODETABLESZ (sizeof(long) * 8) 194 #define MAXCCUSERS 20 /* Maximum for set::anti-flood::max-concurrent-conversations */ 195 #define BATCHLEN 22 196 197 /* 198 * Watch it - Don't change this unless you also change the ERR_TOOMANYWATCH 199 * and PROTOCOL_SUPPORTED settings. 200 */ 201 #define MAXWATCH 128 202 203 #define USERHOST_REPLYLEN (NICKLEN+HOSTLEN+USERLEN+5) 204 205 /* NOTE: this must be down here so the stuff from struct.h IT uses works */ 206 #include "whowas.h" 207 208 /* Logging types */ 209 #define LOG_ERROR 0x0001 210 #define LOG_KILL 0x0002 211 #define LOG_SACMDS 0x0080 212 #define LOG_CHGCMDS 0x0100 213 #define LOG_OVERRIDE 0x0200 214 215 typedef enum LogFieldType { 216 LOG_FIELD_INTEGER, // and unsigned? 217 LOG_FIELD_STRING, 218 LOG_FIELD_CLIENT, 219 LOG_FIELD_CHANNEL, 220 LOG_FIELD_OBJECT 221 } LogFieldType; 222 223 typedef struct LogData { 224 LogFieldType type; 225 char *key; 226 union { 227 int64_t integer; 228 char *string; 229 Client *client; 230 Channel *channel; 231 json_t *object; 232 } value; 233 } LogData; 234 235 /** New log levels for unreal_log() */ 236 /* Note: the reason for these high numbers is so we can easily catch 237 * if someone makes a mistake to use LOG_INFO (from syslog.h) instead 238 * of the ULOG_xxx levels. 239 */ 240 typedef enum LogLevel { 241 ULOG_INVALID = 0, 242 ULOG_DEBUG = 1000, 243 ULOG_INFO = 2000, 244 ULOG_WARNING = 3000, 245 ULOG_ERROR = 4000, 246 ULOG_FATAL = 5000 247 } LogLevel; 248 249 /** Logging types (text, json, etc) */ 250 typedef enum LogType { 251 LOG_TYPE_INVALID = 0, 252 LOG_TYPE_TEXT = 1, 253 LOG_TYPE_JSON = 2, 254 } LogType; 255 256 #define LOG_CATEGORY_LEN 32 257 #define LOG_EVENT_ID_LEN 64 258 typedef struct LogSource LogSource; 259 struct LogSource { 260 LogSource *prev, *next; 261 LogLevel loglevel; 262 char negative; /**< 1 if negative match (eg !operoverride), 0 if normal */ 263 char subsystem[LOG_CATEGORY_LEN+1]; 264 char event_id[LOG_EVENT_ID_LEN+1]; 265 }; 266 267 typedef struct Log Log; 268 struct Log { 269 Log *prev, *next; 270 LogSource *sources; 271 int type; 272 char destination[CHANNELLEN+1]; 273 int show_event; 274 /* for destination::file */ 275 char *file; 276 char *filefmt; 277 long maxsize; 278 int logfd; 279 /* for destination::channel */ 280 int color; 281 int json_message_tag; 282 int oper_only; 283 }; 284 285 /** This is used for deciding the <index> in logs[<index>] and temp_logs[<index>] */ 286 typedef enum LogDestination { LOG_DEST_SNOMASK=0, LOG_DEST_OPER=1, LOG_DEST_REMOTE=2, LOG_DEST_CHANNEL=3, LOG_DEST_DISK=4 } LogDestination; 287 #define NUM_LOG_DESTINATIONS 5 288 289 /* 290 ** 'offsetof' is defined in ANSI-C. The following definition 291 ** is not absolutely portable (I have been told), but so far 292 ** it has worked on all machines I have needed it. The type 293 ** should be size_t but... --msa 294 */ 295 #ifndef offsetof 296 #define offsetof(t,m) (int)((&((t *)0L)->m)) 297 #endif 298 299 #define elementsof(x) (sizeof(x)/sizeof(x[0])) 300 301 /* Calculate the size of an array */ 302 #define ARRAY_SIZEOF(x) (sizeof((x))/sizeof((x)[0])) 303 304 /* 305 ** flags for bootup options (command line flags) 306 */ 307 #define BOOT_DEBUG 1 308 #define BOOT_TTY 2 309 #define BOOT_NOFORK 4 310 311 /* Length of the key that you feed into siphash_generate_key() 312 * DO NOT CHANGE THIS as the siphash code depends on it. 313 */ 314 #define SIPHASH_KEY_LENGTH 16 315 316 /** The length of a standard 'msgid' tag (note that special 317 * msgid tags will be longer). 318 * The 22 alphanumeric characters provide slightly more 319 * than 128 bits of randomness (62^22 > 2^128). 320 * See mtag_add_or_inherit_msgid() for more information. 321 */ 322 #define MSGIDLEN 22 323 324 /** This specifies the current client status or the client type - see @link ClientStatus @endlink in particular. 325 * You may think "server" or "client" are the only choices here, but there are many more 326 * such as states where the user is in the middle of an TLS handshake. 327 * @defgroup ClientStatuses Client statuses / types 328 * @{ 329 */ 330 typedef enum ClientStatus { 331 CLIENT_STATUS_RPC = -10, /**< RPC Client (either local or remote) */ 332 CLIENT_STATUS_CONTROL = -9, /**< Client is on the control channel */ 333 CLIENT_STATUS_LOG = -8, /**< Client is a log file */ 334 CLIENT_STATUS_TLS_STARTTLS_HANDSHAKE = -7, /**< Client is doing a STARTTLS handshake */ 335 CLIENT_STATUS_CONNECTING = -6, /**< Client is an outgoing connect */ 336 CLIENT_STATUS_TLS_CONNECT_HANDSHAKE = -5, /**< Client is doing an TLS handshake - outgoing connection */ 337 CLIENT_STATUS_TLS_ACCEPT_HANDSHAKE = -4, /**< Client is doing an TLS handshake - incoming connection */ 338 CLIENT_STATUS_HANDSHAKE = -3, /**< Client is doing a server handshake - outgoing connection */ 339 CLIENT_STATUS_ME = -2, /**< Client is &me (this server) */ 340 CLIENT_STATUS_UNKNOWN = -1, /**< Client is doing a hanshake. May become a server or user later, we don't know yet */ 341 CLIENT_STATUS_SERVER = 0, /**< Client is a server (fully authenticated) */ 342 CLIENT_STATUS_USER = 1, /**< Client is a user (fully authenticated) */ 343 } ClientStatus; 344 345 #define MyConnect(x) ((x)->local) /**< Is a locally connected client (server or user) */ 346 #define MyUser(x) (MyConnect(x) && IsUser(x)) /**< Is a locally connected user */ 347 #define IsUser(x) ((x)->status == CLIENT_STATUS_USER) /**< Is a user that has completed the connection handshake */ 348 #define IsRegistered(x) ((x)->status >= CLIENT_STATUS_SERVER) /**< Client has completed the connection handshake (user or server) */ 349 #define IsConnecting(x) ((x)->status == CLIENT_STATUS_CONNECTING) /**< Is an outgoing connect to another server */ 350 #define IsHandshake(x) ((x)->status == CLIENT_STATUS_HANDSHAKE) /**< Is doing a handshake (while connecting to another server) */ 351 #define IsMe(x) ((x)->status == CLIENT_STATUS_ME) /**< This is true for &me */ 352 /** Client is not fully registered yet. May become a user or a server, we don't know yet. */ 353 #define IsUnknown(x) (((x)->status == CLIENT_STATUS_UNKNOWN) || ((x)->status == CLIENT_STATUS_TLS_STARTTLS_HANDSHAKE)) 354 #define IsServer(x) ((x)->status == CLIENT_STATUS_SERVER) /**< Is a server that has completed the connection handshake */ 355 #define IsControl(x) ((x)->status == CLIENT_STATUS_CONTROL) /**< Is on the control channel (not an IRC client) */ 356 #define IsRPC(x) ((x)->status == CLIENT_STATUS_RPC) /**< Is doing RPC (not an IRC client) */ 357 #define IsLog(x) ((x)->status == CLIENT_STATUS_LOG) /**< Is a log file, not a user or server */ 358 #define IsStartTLSHandshake(x) ((x)->status == CLIENT_STATUS_TLS_STARTTLS_HANDSHAKE) /**< Currently doing a STARTTLS handshake */ 359 #define IsTLSAcceptHandshake(x) ((x)->status == CLIENT_STATUS_TLS_ACCEPT_HANDSHAKE) /**< Currently doing a TLS handshake - incoming */ 360 #define IsTLSConnectHandshake(x) ((x)->status == CLIENT_STATUS_TLS_CONNECT_HANDSHAKE) /**< Currently doing a TLS handshake - outgoing */ 361 #define IsTLSHandshake(x) (IsTLSAcceptHandshake(x) || IsTLSConnectHandshake(x) | IsStartTLSHandshake(x)) /**< Currently doing a TLS handshake (incoming/outgoing/STARTTLS) */ 362 363 #define SetStartTLSHandshake(x) ((x)->status = CLIENT_STATUS_TLS_STARTTLS_HANDSHAKE) 364 #define SetTLSAcceptHandshake(x) ((x)->status = CLIENT_STATUS_TLS_ACCEPT_HANDSHAKE) 365 #define SetTLSConnectHandshake(x) ((x)->status = CLIENT_STATUS_TLS_CONNECT_HANDSHAKE) 366 #define SetConnecting(x) ((x)->status = CLIENT_STATUS_CONNECTING) 367 #define SetHandshake(x) ((x)->status = CLIENT_STATUS_HANDSHAKE) 368 #define SetMe(x) ((x)->status = CLIENT_STATUS_ME) 369 #define SetUnknown(x) ((x)->status = CLIENT_STATUS_UNKNOWN) 370 #define SetServer(x) ((x)->status = CLIENT_STATUS_SERVER) 371 #define SetUser(x) ((x)->status = CLIENT_STATUS_USER) 372 #define SetLog(x) ((x)->status = CLIENT_STATUS_LOG) 373 #define SetControl(x) ((x)->status = CLIENT_STATUS_CONTROL) 374 #define SetRPC(x) ((x)->status = CLIENT_STATUS_RPC) 375 #define SetUser(x) ((x)->status = CLIENT_STATUS_USER) 376 377 /** @} */ 378 379 /** Used for checking certain properties of clients, such as IsSecure() and IsULine(). 380 * @defgroup ClientFlags Client flags 381 * @{ 382 */ 383 #define CLIENT_FLAG_PINGSENT 0x00000001 /**< PING sent, no reply yet */ 384 #define CLIENT_FLAG_DEAD 0x00000002 /**< Client is dead: already quit/exited and removed from all lists -- Remaining part will soon be freed in main loop */ 385 #define CLIENT_FLAG_DEADSOCKET 0x00000004 /**< Local socket is dead but otherwise the client still exists fully -- Will soon exit in main loop */ 386 #define CLIENT_FLAG_KILLED 0x00000008 /**< Prevents "QUIT" from being sent for this */ 387 #define CLIENT_FLAG_MONITOR_REHASH 0x00000010 /**< Client is monitoring rehash output */ 388 #define CLIENT_FLAG_OUTGOING 0x00000020 /**< Outgoing connection (do not touch cptr->listener->clients) */ 389 #define CLIENT_FLAG_CLOSING 0x00000040 /**< Set when closing to suppress errors */ 390 #define CLIENT_FLAG_LISTEN 0x00000080 /**< Used to mark clients which we listen() on */ 391 #define CLIENT_FLAG_DNSLOOKUP 0x00000100 /**< Client is doing a DNS lookup */ 392 #define CLIENT_FLAG_IDENTLOOKUP 0x00000200 /**< Client is doing an Ident lookup (RFC931) */ 393 #define CLIENT_FLAG_IDENTLOOKUPSENT 0x00000400 /**< Set if we havent writen to ident server */ 394 #define CLIENT_FLAG_LOCALHOST 0x00000800 /**< Set for localhost clients */ 395 #define CLIENT_FLAG_IDENTSUCCESS 0x00001000 /**< Successful ident lookup achieved */ 396 #define CLIENT_FLAG_USEIDENT 0x00002000 /**< The allow { } block says we should use the ident (if available) */ 397 #define CLIENT_FLAG_NEXTCALL 0x00004000 /**< Next call (don't ask...) */ 398 #define CLIENT_FLAG_ULINE 0x00008000 /**< User/server is considered U-lined (eg: services) */ 399 #define CLIENT_FLAG_SQUIT 0x00010000 /**< Server has been /SQUIT by an oper */ 400 #define CLIENT_FLAG_PROTOCTL 0x00020000 /**< Received at least 1 PROTOCTL message */ 401 #define CLIENT_FLAG_EAUTH 0x00040000 /**< Server authenticated via PROTOCTL EAUTH */ 402 #define CLIENT_FLAG_NETINFO 0x00080000 /**< Received a NETINFO message */ 403 #define CLIENT_FLAG_QUARANTINE 0x00100000 /**< Quarantined server (don't allow ircops on this server) */ 404 #define CLIENT_FLAG_DCCNOTICE 0x00200000 /**< Has the user seen a notice on how to use DCCALLOW already? */ 405 #define CLIENT_FLAG_SHUNNED 0x00400000 /**< Connection is shunned (user cannot execute any commands) */ 406 #define CLIENT_FLAG_VIRUS 0x00800000 /**< Tagged by spamfilter as a virus */ 407 #define CLIENT_FLAG_TLS 0x01000000 /**< Connection is using TLS */ 408 #define CLIENT_FLAG_NOFAKELAG 0x02000000 /**< Exemption from fake lag */ 409 #define CLIENT_FLAG_DCCBLOCK 0x04000000 /**< Block all DCC send requests */ 410 #define CLIENT_FLAG_MAP 0x08000000 /**< Show this entry in /MAP (only used in map module) */ 411 #define CLIENT_FLAG_PINGWARN 0x10000000 /**< Server ping warning (remote server slow with responding to PINGs) */ 412 #define CLIENT_FLAG_NOHANDSHAKEDELAY 0x20000000 /**< No handshake delay */ 413 #define CLIENT_FLAG_SERVER_DISCONNECT_LOGGED 0x40000000 /**< Server disconnect message is (already) logged */ 414 #define CLIENT_FLAG_ASYNC_RPC 0x80000000 /**< Asynchronous remote RPC request - special case for rehash etc. */ 415 416 /** @} */ 417 418 #define OPER_SNOMASKS "+bBcdfkqsSoO" 419 420 #define SEND_UMODES (SendUmodes) 421 #define ALL_UMODES (AllUmodes) 422 /* SEND_UMODES and ALL_UMODES are now handled by umode_get/umode_lget/umode_gget -- Syzop. */ 423 424 #define CLIENT_FLAG_ID (CLIENT_FLAG_USEIDENT|CLIENT_FLAG_IDENTSUCCESS) 425 426 /* PROTO_*: Server protocol extensions (acptr->local->proto). 427 * Note that client protocol extensions have been moved 428 * to the ClientCapability API which uses acptr->local->caps. 429 */ 430 #define PROTO_VL 0x000001 /* Negotiated VL protocol */ 431 #define PROTO_VHP 0x000002 /* Send hostnames in NICKv2 even if not sethosted */ 432 #define PROTO_CLK 0x000004 /* Send cloaked host in the NICK command (regardless of +x/-x) */ 433 #define PROTO_MLOCK 0x000008 /* server supports MLOCK */ 434 #define PROTO_EXTSWHOIS 0x000010 /* extended SWHOIS support */ 435 #define PROTO_SJSBY 0x000020 /* SJOIN setby information (TS and nick) */ 436 #define PROTO_MTAGS 0x000040 /* Support message tags and big buffers */ 437 #define PROTO_NEXTBANS 0x000080 /* Server supports named extended bans */ 438 439 /* For client capabilities: */ 440 #define CAP_INVERT 1L 441 442 /** HasCapabilityFast() checks for a token if you know exactly which bit to check */ 443 #define HasCapabilityFast(cptr, val) ((cptr)->local->caps & (val)) 444 /** HasCapability() checks for a token by name and is slightly slower */ 445 #define HasCapability(cptr, token) ((cptr)->local->caps & ClientCapabilityBit(token)) 446 #define SetCapabilityFast(cptr, val) do { (cptr)->local->caps |= (val); } while(0) 447 #define ClearCapabilityFast(cptr, val) do { (cptr)->local->caps &= ~(val); } while(0) 448 449 /* Usermode and snomask macros: */ 450 #define IsDeaf(x) ((x)->umodes & UMODE_DEAF) 451 #define IsOper(x) ((x)->umodes & UMODE_OPER) 452 #define IsInvisible(x) ((x)->umodes & UMODE_INVISIBLE) 453 #define IsRegNick(x) ((x)->umodes & UMODE_REGNICK) 454 #define IsHidden(x) ((x)->umodes & UMODE_HIDE) 455 #define IsSetHost(x) ((x)->umodes & UMODE_SETHOST) 456 #define IsHideOper(x) ((x)->umodes & UMODE_HIDEOPER) 457 #define SetOper(x) ((x)->umodes |= UMODE_OPER) 458 #define SetInvisible(x) ((x)->umodes |= UMODE_INVISIBLE) 459 #define SetRegNick(x) ((x)->umodes & UMODE_REGNICK) 460 #define SetHidden(x) ((x)->umodes |= UMODE_HIDE) 461 #define SetHideOper(x) ((x)->umodes |= UMODE_HIDEOPER) 462 #define IsSecureConnect(x) ((x)->umodes & UMODE_SECURE) 463 #define ClearOper(x) ((x)->umodes &= ~UMODE_OPER) 464 #define ClearInvisible(x) ((x)->umodes &= ~UMODE_INVISIBLE) 465 #define ClearHidden(x) ((x)->umodes &= ~UMODE_HIDE) 466 #define ClearHideOper(x) ((x)->umodes &= ~UMODE_HIDEOPER) 467 468 /* Client flags macros: to check for via IsXX(), 469 * to set via SetXX() and to clear the flag via ClearXX() 470 */ 471 /** 472 * @addtogroup ClientFlags 473 * @{ 474 */ 475 #define IsIdentLookup(x) ((x)->flags & CLIENT_FLAG_IDENTLOOKUP) /**< Is doing Ident lookups */ 476 #define IsClosing(x) ((x)->flags & CLIENT_FLAG_CLOSING) /**< Is closing the connection */ 477 #define IsDCCBlock(x) ((x)->flags & CLIENT_FLAG_DCCBLOCK) 478 #define IsDCCNotice(x) ((x)->flags & CLIENT_FLAG_DCCNOTICE) 479 #define IsDead(x) ((x)->flags & CLIENT_FLAG_DEAD) 480 #define IsDeadSocket(x) ((x)->flags & CLIENT_FLAG_DEADSOCKET) 481 #define IsServerDisconnectLogged(x) ((x)->flags & CLIENT_FLAG_SERVER_DISCONNECT_LOGGED) 482 #define IsUseIdent(x) ((x)->flags & CLIENT_FLAG_USEIDENT) 483 #define IsDNSLookup(x) ((x)->flags & CLIENT_FLAG_DNSLOOKUP) 484 #define IsEAuth(x) ((x)->flags & CLIENT_FLAG_EAUTH) 485 #define IsIdentSuccess(x) ((x)->flags & CLIENT_FLAG_IDENTSUCCESS) 486 #define IsKilled(x) ((x)->flags & CLIENT_FLAG_KILLED) 487 #define IsMonitorRehash(x) ((x)->flags & CLIENT_FLAG_MONITOR_REHASH) 488 #define IsListening(x) ((x)->flags & CLIENT_FLAG_LISTEN) 489 #define IsLocalhost(x) ((x)->flags & CLIENT_FLAG_LOCALHOST) 490 #define IsMap(x) ((x)->flags & CLIENT_FLAG_MAP) 491 #define IsNextCall(x) ((x)->flags & CLIENT_FLAG_NEXTCALL) 492 #define IsNetInfo(x) ((x)->flags & CLIENT_FLAG_NETINFO) 493 #define IsNoFakeLag(x) ((x)->flags & CLIENT_FLAG_NOFAKELAG) 494 #define IsOutgoing(x) ((x)->flags & CLIENT_FLAG_OUTGOING) 495 #define IsPingSent(x) ((x)->flags & CLIENT_FLAG_PINGSENT) 496 #define IsPingWarning(x) ((x)->flags & CLIENT_FLAG_PINGWARN) 497 #define IsNoHandshakeDelay(x) ((x)->flags & CLIENT_FLAG_NOHANDSHAKEDELAY) 498 #define IsProtoctlReceived(x) ((x)->flags & CLIENT_FLAG_PROTOCTL) 499 #define IsQuarantined(x) ((x)->flags & CLIENT_FLAG_QUARANTINE) 500 #define IsShunned(x) ((x)->flags & CLIENT_FLAG_SHUNNED) 501 #define IsSQuit(x) ((x)->flags & CLIENT_FLAG_SQUIT) 502 #define IsTLS(x) ((x)->flags & CLIENT_FLAG_TLS) 503 #define IsSecure(x) ((x)->flags & CLIENT_FLAG_TLS) 504 #define IsULine(x) ((x)->flags & CLIENT_FLAG_ULINE) 505 #define IsSvsCmdOk(x) (((x)->flags & CLIENT_FLAG_ULINE) || ((iConf.limit_svscmds == LIMIT_SVSCMDS_SERVERS) && (IsServer((x)) || IsMe((x))))) 506 #define IsVirus(x) ((x)->flags & CLIENT_FLAG_VIRUS) 507 #define IsIdentLookupSent(x) ((x)->flags & CLIENT_FLAG_IDENTLOOKUPSENT) 508 #define IsAsyncRPC(x) ((x)->flags & CLIENT_FLAG_ASYNC_RPC) 509 #define SetIdentLookup(x) do { (x)->flags |= CLIENT_FLAG_IDENTLOOKUP; } while(0) 510 #define SetClosing(x) do { (x)->flags |= CLIENT_FLAG_CLOSING; } while(0) 511 #define SetDCCBlock(x) do { (x)->flags |= CLIENT_FLAG_DCCBLOCK; } while(0) 512 #define SetDCCNotice(x) do { (x)->flags |= CLIENT_FLAG_DCCNOTICE; } while(0) 513 #define SetDead(x) do { (x)->flags |= CLIENT_FLAG_DEAD; } while(0) 514 #define SetDeadSocket(x) do { (x)->flags |= CLIENT_FLAG_DEADSOCKET; } while(0) 515 #define SetServerDisconnectLogged(x) do { (x)->flags |= CLIENT_FLAG_SERVER_DISCONNECT_LOGGED; } while(0) 516 #define SetUseIdent(x) do { (x)->flags |= CLIENT_FLAG_USEIDENT; } while(0) 517 #define SetDNSLookup(x) do { (x)->flags |= CLIENT_FLAG_DNSLOOKUP; } while(0) 518 #define SetEAuth(x) do { (x)->flags |= CLIENT_FLAG_EAUTH; } while(0) 519 #define SetIdentSuccess(x) do { (x)->flags |= CLIENT_FLAG_IDENTSUCCESS; } while(0) 520 #define SetKilled(x) do { (x)->flags |= CLIENT_FLAG_KILLED; } while(0) 521 #define SetMonitorRehash(x) do { (x)->flags |= CLIENT_FLAG_MONITOR_REHASH; } while(0) 522 #define SetListening(x) do { (x)->flags |= CLIENT_FLAG_LISTEN; } while(0) 523 #define SetLocalhost(x) do { (x)->flags |= CLIENT_FLAG_LOCALHOST; } while(0) 524 #define SetMap(x) do { (x)->flags |= CLIENT_FLAG_MAP; } while(0) 525 #define SetNextCall(x) do { (x)->flags |= CLIENT_FLAG_NEXTCALL; } while(0) 526 #define SetNetInfo(x) do { (x)->flags |= CLIENT_FLAG_NETINFO; } while(0) 527 #define SetNoFakeLag(x) do { (x)->flags |= CLIENT_FLAG_NOFAKELAG; } while(0) 528 #define SetOutgoing(x) do { (x)->flags |= CLIENT_FLAG_OUTGOING; } while(0) 529 #define SetPingSent(x) do { (x)->flags |= CLIENT_FLAG_PINGSENT; } while(0) 530 #define SetPingWarning(x) do { (x)->flags |= CLIENT_FLAG_PINGWARN; } while(0) 531 #define SetNoHandshakeDelay(x) do { (x)->flags |= CLIENT_FLAG_NOHANDSHAKEDELAY; } while(0) 532 #define SetProtoctlReceived(x) do { (x)->flags |= CLIENT_FLAG_PROTOCTL; } while(0) 533 #define SetQuarantined(x) do { (x)->flags |= CLIENT_FLAG_QUARANTINE; } while(0) 534 #define SetShunned(x) do { (x)->flags |= CLIENT_FLAG_SHUNNED; } while(0) 535 #define SetSQuit(x) do { (x)->flags |= CLIENT_FLAG_SQUIT; } while(0) 536 #define SetTLS(x) do { (x)->flags |= CLIENT_FLAG_TLS; } while(0) 537 #define SetULine(x) do { (x)->flags |= CLIENT_FLAG_ULINE; } while(0) 538 #define SetVirus(x) do { (x)->flags |= CLIENT_FLAG_VIRUS; } while(0) 539 #define SetIdentLookupSent(x) do { (x)->flags |= CLIENT_FLAG_IDENTLOOKUPSENT; } while(0) 540 #define SetAsyncRPC(x) do { (x)->flags |= CLIENT_FLAG_ASYNC_RPC; } while(0) 541 #define ClearIdentLookup(x) do { (x)->flags &= ~CLIENT_FLAG_IDENTLOOKUP; } while(0) 542 #define ClearClosing(x) do { (x)->flags &= ~CLIENT_FLAG_CLOSING; } while(0) 543 #define ClearDCCBlock(x) do { (x)->flags &= ~CLIENT_FLAG_DCCBLOCK; } while(0) 544 #define ClearDCCNotice(x) do { (x)->flags &= ~CLIENT_FLAG_DCCNOTICE; } while(0) 545 #define ClearDead(x) do { (x)->flags &= ~CLIENT_FLAG_DEAD; } while(0) 546 #define ClearDeadSocket(x) do { (x)->flags &= ~CLIENT_FLAG_DEADSOCKET; } while(0) 547 #define ClearUseIdent(x) do { (x)->flags &= ~CLIENT_FLAG_USEIDENT; } while(0) 548 #define ClearDNSLookup(x) do { (x)->flags &= ~CLIENT_FLAG_DNSLOOKUP; } while(0) 549 #define ClearEAuth(x) do { (x)->flags &= ~CLIENT_FLAG_EAUTH; } while(0) 550 #define ClearIdentSuccess(x) do { (x)->flags &= ~CLIENT_FLAG_IDENTSUCCESS; } while(0) 551 #define ClearKilled(x) do { (x)->flags &= ~CLIENT_FLAG_KILLED; } while(0) 552 #define ClearMonitorRehash(x) do { (x)->flags &= ~CLIENT_FLAG_MONITOR_REHASH; } while(0) 553 #define ClearListening(x) do { (x)->flags &= ~CLIENT_FLAG_LISTEN; } while(0) 554 #define ClearLocalhost(x) do { (x)->flags &= ~CLIENT_FLAG_LOCALHOST; } while(0) 555 #define ClearMap(x) do { (x)->flags &= ~CLIENT_FLAG_MAP; } while(0) 556 #define ClearNextCall(x) do { (x)->flags &= ~CLIENT_FLAG_NEXTCALL; } while(0) 557 #define ClearNetInfo(x) do { (x)->flags &= ~CLIENT_FLAG_NETINFO; } while(0) 558 #define ClearNoFakeLag(x) do { (x)->flags &= ~CLIENT_FLAG_NOFAKELAG; } while(0) 559 #define ClearOutgoing(x) do { (x)->flags &= ~CLIENT_FLAG_OUTGOING; } while(0) 560 #define ClearPingSent(x) do { (x)->flags &= ~CLIENT_FLAG_PINGSENT; } while(0) 561 #define ClearPingWarning(x) do { (x)->flags &= ~CLIENT_FLAG_PINGWARN; } while(0) 562 #define ClearNoHandshakeDelay(x) do { (x)->flags &= ~CLIENT_FLAG_NOHANDSHAKEDELAY; } while(0) 563 #define ClearProtoctlReceived(x) do { (x)->flags &= ~CLIENT_FLAG_PROTOCTL; } while(0) 564 #define ClearQuarantined(x) do { (x)->flags &= ~CLIENT_FLAG_QUARANTINE; } while(0) 565 #define ClearShunned(x) do { (x)->flags &= ~CLIENT_FLAG_SHUNNED; } while(0) 566 #define ClearSQuit(x) do { (x)->flags &= ~CLIENT_FLAG_SQUIT; } while(0) 567 #define ClearTLS(x) do { (x)->flags &= ~CLIENT_FLAG_TLS; } while(0) 568 #define ClearULine(x) do { (x)->flags &= ~CLIENT_FLAG_ULINE; } while(0) 569 #define ClearVirus(x) do { (x)->flags &= ~CLIENT_FLAG_VIRUS; } while(0) 570 #define ClearIdentLookupSent(x) do { (x)->flags &= ~CLIENT_FLAG_IDENTLOOKUPSENT; } while(0) 571 #define ClearAsyncRPC(x) do { (x)->flags &= ~CLIENT_FLAG_ASYNC_RPC; } while(0) 572 /** @} */ 573 574 #define IsIPV6(x) ((x)->local->socket_type == SOCKET_TYPE_IPV6) 575 #define IsUnixSocket(x) ((x)->local->socket_type == SOCKET_TYPE_UNIX) 576 #define SetIPV6(x) do { (x)->local->socket_type = SOCKET_TYPE_IPV6; } while(0) 577 #define SetUnixSocket(x) do { (x)->local->socket_type = SOCKET_TYPE_UNIX; } while(0) 578 579 /* Others that access client structs: */ 580 #define IsNotSpoof(x) ((x)->local->nospoof == 0) 581 #define GetHost(x) (IsHidden(x) ? (x)->user->virthost : (x)->user->realhost) 582 #define GetIP(x) (x->ip ? x->ip : "255.255.255.255") 583 #define IsLoggedIn(x) (x->user && (*x->user->account != '*') && !isdigit(*x->user->account)) /**< Logged into services */ 584 #define IsSynched(x) (x->server->flags.synced) 585 #define IsServerSent(x) (x->server && x->server->flags.server_sent) 586 587 /* And more that access client stuff - but actually modularized */ 588 #define GetReputation(client) (moddata_client_get(client, "reputation") ? atoi(moddata_client_get(client, "reputation")) : 0) /**< Get reputation value for a client */ 589 590 /* PROTOCTL (Server protocol) stuff */ 591 #ifndef DEBUGMODE 592 #define CHECKSERVERPROTO(x,y) (((x)->local->proto & y) == y) 593 #else 594 #define CHECKSERVERPROTO(x,y) (checkprotoflags(x, y, __FILE__, __LINE__)) 595 #endif 596 597 #define SupportVL(x) (CHECKSERVERPROTO(x, PROTO_VL)) 598 #define SupportSJSBY(x) (CHECKSERVERPROTO(x, PROTO_SJSBY)) 599 #define SupportVHP(x) (CHECKSERVERPROTO(x, PROTO_VHP)) 600 #define SupportCLK(x) (CHECKSERVERPROTO(x, PROTO_CLK)) 601 #define SupportMTAGS(x) (CHECKSERVERPROTO(x, PROTO_MTAGS)) 602 #define SupportNEXTBANS(x) (CHECKSERVERPROTO(x, PROTO_NEXTBANS)) 603 604 #define SetVL(x) ((x)->local->proto |= PROTO_VL) 605 #define SetSJSBY(x) ((x)->local->proto |= PROTO_SJSBY) 606 #define SetVHP(x) ((x)->local->proto |= PROTO_VHP) 607 #define SetCLK(x) ((x)->local->proto |= PROTO_CLK) 608 #define SetMTAGS(x) ((x)->local->proto |= PROTO_MTAGS) 609 #define SetNEXTBANS(x) ((x)->local->proto |= PROTO_NEXTBANS) 610 611 /* Dcc deny types (see src/s_extra.c) */ 612 #define DCCDENY_HARD 0 613 #define DCCDENY_SOFT 1 614 615 /* Linked list dcc flags */ 616 #define DCC_LINK_ME 1 /* My dcc allow */ 617 #define DCC_LINK_REMOTE 2 /* I need to remove dccallows from these clients when I die */ 618 619 /** Union for moddata objects */ 620 typedef union ModData ModData; 621 union ModData 622 { 623 int i; 624 long l; 625 long long ll; 626 char *str; 627 void *ptr; 628 }; 629 630 #ifndef _WIN32 631 #define CHECK_LIST_ENTRY(list) if (offsetof(typeof(*list),prev) != offsetof(ListStruct,prev)) \ 632 { \ 633 unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ 634 "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ 635 log_data_string("error_details", "->prev must be 1st struct member"), \ 636 log_data_string("file", __FILE__), \ 637 log_data_integer("line", __LINE__)); \ 638 abort(); \ 639 } \ 640 if (offsetof(typeof(*list),next) != offsetof(ListStruct,next)) \ 641 { \ 642 unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ 643 "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ 644 log_data_string("error_details", "->next must be 2nd struct member"), \ 645 log_data_string("file", __FILE__), \ 646 log_data_integer("line", __LINE__)); \ 647 abort(); \ 648 } 649 #else 650 #define CHECK_LIST_ENTRY(list) /* not available on Windows, typeof() not reliable */ 651 #endif 652 653 #ifndef _WIN32 654 #define CHECK_PRIO_LIST_ENTRY(list) if (offsetof(typeof(*list),prev) != offsetof(ListStructPrio,prev)) \ 655 { \ 656 unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ 657 "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ 658 log_data_string("error_details", "->prev must be 1st struct member"), \ 659 log_data_string("file", __FILE__), \ 660 log_data_integer("line", __LINE__)); \ 661 abort(); \ 662 } \ 663 if (offsetof(typeof(*list),next) != offsetof(ListStructPrio,next)) \ 664 { \ 665 unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ 666 "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ 667 log_data_string("error_details", "->next must be 2nd struct member"), \ 668 log_data_string("file", __FILE__), \ 669 log_data_integer("line", __LINE__)); \ 670 abort(); \ 671 } \ 672 if (offsetof(typeof(*list),priority) != offsetof(ListStructPrio,priority)) \ 673 { \ 674 unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ 675 "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ 676 log_data_string("error_details", "->priority must be 3rd struct member"), \ 677 log_data_string("file", __FILE__), \ 678 log_data_integer("line", __LINE__)); \ 679 abort(); \ 680 } 681 #else 682 #define CHECK_PRIO_LIST_ENTRY(list) /* not available on Windows, typeof() not reliable */ 683 #endif 684 685 #define CHECK_NULL_LIST_ITEM(item) if ((item)->prev || (item)->next) \ 686 { \ 687 unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION_DOUBLE_ADD", NULL, \ 688 "[BUG] $file:$line: List operation on item with non-NULL 'prev' or 'next' -- are you adding to a list twice?", \ 689 log_data_string("file", __FILE__), \ 690 log_data_integer("line", __LINE__)); \ 691 abort(); \ 692 } 693 694 /** These are the generic list functions that are used all around in UnrealIRCd. 695 * @defgroup ListFunctions List functions 696 * @{ 697 */ 698 699 /** Generic linked list HEAD */ 700 struct ListStruct { 701 ListStruct *prev, *next; 702 }; 703 704 /** Generic linked list HEAD with priority */ 705 struct ListStructPrio { 706 ListStructPrio *prev, *next; 707 int priority; 708 }; 709 710 /** Add an item to a standard linked list (in the front) 711 */ 712 #define AddListItem(item,list) do { \ 713 CHECK_LIST_ENTRY(list) \ 714 CHECK_LIST_ENTRY(item) \ 715 CHECK_NULL_LIST_ITEM(item) \ 716 add_ListItem((ListStruct *)item, (ListStruct **)&list); \ 717 } while(0) 718 719 /** Append an item to a standard linked list (at the back) 720 */ 721 #define AppendListItem(item,list) do { \ 722 CHECK_LIST_ENTRY(list) \ 723 CHECK_LIST_ENTRY(item) \ 724 CHECK_NULL_LIST_ITEM(item) \ 725 append_ListItem((ListStruct *)item, (ListStruct **)&list); \ 726 } while(0) 727 728 /** Delete an item from a standard linked list 729 */ 730 #define DelListItem(item,list) do { \ 731 CHECK_LIST_ENTRY(list) \ 732 CHECK_LIST_ENTRY(item) \ 733 del_ListItem((ListStruct *)item, (ListStruct **)&list); \ 734 } while(0) 735 736 /** Add an item to a standard linked list - UNCHECKED function, only use if absolutely necessary! 737 */ 738 #define AddListItemUnchecked(item,list) add_ListItem((ListStruct *)item, (ListStruct **)&list) 739 /** Append an item to a standard linked list - UNCHECKED function, only use if absolutely necessary! 740 */ 741 #define AppendListItemUnchecked(item,list) append_ListItem((ListStruct *)item, (ListStruct **)&list) 742 /** Delete an item from a standard linked list - UNCHECKED function, only use if absolutely necessary! 743 */ 744 #define DelListItemUnchecked(item,list) del_ListItem((ListStruct *)item, (ListStruct **)&list) 745 746 #define AddListItemPrio(item,list,prio) do { \ 747 CHECK_PRIO_LIST_ENTRY(list) \ 748 CHECK_PRIO_LIST_ENTRY(item) \ 749 CHECK_NULL_LIST_ITEM(item) \ 750 item->priority = prio; \ 751 add_ListItemPrio((ListStructPrio *)item, (ListStructPrio **)&list, prio); \ 752 } while(0) 753 754 #define DelListItemPrio(item,list,prio) do { \ 755 CHECK_PRIO_LIST_ENTRY(list) \ 756 CHECK_PRIO_LIST_ENTRY(item) \ 757 del_ListItem((ListStruct *)item, (ListStruct **)&list); \ 758 } while(0) 759 760 typedef struct NameList NameList; 761 /** Generic linked list where each entry has a name which you can use. 762 * Use this if you simply want to have a list of entries 763 * that only have a name and no other properties. 764 * 765 * Use the following functions to add, find and delete entries: 766 * add_name_list(), find_name_list(), del_name_list(), free_entire_name_list() 767 */ 768 struct NameList { 769 NameList *prev, *next; 770 char name[1]; 771 }; 772 773 /** Free an entire NameList */ 774 #define free_entire_name_list(list) do { _free_entire_name_list(list); list = NULL; } while(0) 775 /** Add an entry to a NameList */ 776 #define add_name_list(list, str) _add_name_list(&list, str) 777 /** Delete an entry from a NameList - AND free it */ 778 #define del_name_list(list, str) _del_name_list(&list, str) 779 780 extern void unreal_add_names(NameList **n, ConfigEntry *ce); 781 782 /** @} */ 783 784 typedef struct MultiLine MultiLine; 785 /** Multi-line list. 786 * @see addmultiline(), freemultiline(), sendnotice_multiline() 787 */ 788 struct MultiLine { 789 MultiLine *prev, *next; 790 char *line; 791 }; 792 793 struct MOTDFile 794 { 795 struct MOTDLine *lines; 796 struct tm last_modified; /* store the last modification time */ 797 }; 798 799 struct MOTDLine { 800 char *line; 801 struct MOTDLine *next; 802 }; 803 804 /** Current status of configuration in memory (what stage are we in..) */ 805 typedef enum ConfigStatus { 806 CONFIG_STATUS_NONE = 0, /**< Config files have not been parsed yet */ 807 CONFIG_STATUS_TEST = 1, /**< Currently running MOD_TEST() */ 808 CONFIG_STATUS_POSTTEST = 2, /**< Currently running post_config_test hooks */ 809 CONFIG_STATUS_PRE_INIT = 3, /**< In-between */ 810 CONFIG_STATUS_INIT = 4, /**< Currently running MOD_INIT() */ 811 CONFIG_STATUS_RUN_CONFIG = 5, /**< Currently running CONFIG_RUN hooks */ 812 CONFIG_STATUS_LOAD = 6, /**< Currently running MOD_LOAD() */ 813 CONFIG_STATUS_POSTLOAD = 7, /**< Doing post-load stuff like activating listeners */ 814 CONFIG_STATUS_COMPLETE = 8, /**< Load or rehash complete */ 815 CONFIG_STATUS_ROLLBACK = 99, /**< Configuration failed, rolling back changes */ 816 } ConfigStatus; 817 818 struct LoopStruct { 819 unsigned do_garbage_collect : 1; 820 unsigned config_test : 1; 821 unsigned booted : 1; 822 unsigned forked : 1; 823 unsigned do_bancheck : 1; /* perform *line bancheck? */ 824 unsigned do_bancheck_spamf_user : 1; /* perform 'user' spamfilter bancheck */ 825 unsigned do_bancheck_spamf_away : 1; /* perform 'away' spamfilter bancheck */ 826 unsigned terminating : 1; 827 unsigned config_load_failed : 1; 828 unsigned rehash_download_busy : 1; /* don't return "all downloads complete", needed for race condition */ 829 unsigned tainted : 1; 830 int rehashing; 831 ConfigStatus config_status; 832 Client *rehash_save_client; 833 void (*boot_function)(); 834 }; 835 836 /** Matching types for Match.type */ 837 typedef enum { 838 MATCH_SIMPLE=1, /**< Simple pattern with * and ? */ 839 MATCH_PCRE_REGEX=2, /**< PCRE2 Perl-like regex (new) */ 840 } MatchType; 841 842 /** Match struct, which allows various matching styles, see MATCH_* */ 843 typedef struct Match { 844 char *str; /**< Text of the glob/regex/whatever. Always set. */ 845 MatchType type; 846 union { 847 pcre2_code *pcre2_expr; /**< PCRE2 Perl-like Regex */ 848 } ext; 849 } Match; 850 851 typedef struct Whowas { 852 int hashv; 853 char *name; 854 char *username; 855 char *hostname; 856 char *virthost; 857 char *ip; 858 char *servername; 859 char *realname; 860 char *account; 861 long umodes; 862 time_t logon; 863 time_t logoff; 864 time_t connected_since; 865 WhoWasEvent event; 866 struct Client *online; /* Pointer to new nickname for chasing or NULL */ 867 struct Whowas *next; /* for hash table... */ 868 struct Whowas *prev; /* for hash table... */ 869 struct Whowas *cnext; /* for client struct linked list */ 870 struct Whowas *cprev; /* for client struct linked list */ 871 } WhoWas; 872 873 typedef struct SWhois SWhois; 874 struct SWhois { 875 SWhois *prev, *next; 876 int priority; 877 char *line; 878 char *setby; 879 }; 880 881 /** The command API - used by modules and the core to add commands, overrides, etc. 882 * See also https://www.unrealircd.org/docs/Dev:Command_API for a higher level overview and example. 883 * @defgroup CommandAPI Command API 884 * @{ 885 */ 886 /** Command can be called by unregistered users (still in handshake) */ 887 #define CMD_UNREGISTERED 0x0001 888 /** Command can be called by users (either directly connected, or remote) */ 889 #define CMD_USER 0x0002 890 /** Command can be called by servers */ 891 #define CMD_SERVER 0x0004 892 /** Command can be used by shunned users (only very few commands need this) */ 893 #define CMD_SHUN 0x0008 894 /** Command will NOT add fake lag (extremely rare, use with care) */ 895 #define CMD_NOLAG 0x0010 896 /** Command is actually an alias */ 897 #define CMD_ALIAS 0x0020 898 /** Command will reset the idle time (only for PRIVMSG) */ 899 #define CMD_RESETIDLE 0x0040 900 /** Command can be used by virus tagged users (only very few commands) */ 901 #define CMD_VIRUS 0x0080 902 /** Command requires IRCOp privileges */ 903 #define CMD_OPER 0x0200 904 /** Command is for control channel only (unrealircd.ctl socket) */ 905 #define CMD_CONTROL 0x0400 906 907 /** Command function - used by all command handlers. 908 * This is used in the code like <pre>CMD_FUNC(cmd_yourcmd)</pre> as a function definition. 909 * It allows UnrealIRCd devs to change the parameters in the function without 910 * (necessarily) breaking your code. 911 * @param client The client 912 * @param recv_mtags Received message tags for this command. 913 * @param parc Parameter count *plus* 1. 914 * @param parv Parameter values. 915 * @note Slightly confusing, but parc will be 2 if 1 parameter was provided. 916 * It is two because parv will still have 2 elements, parv[1] will be your first parameter, 917 * and parv[2] will be NULL. 918 * Note that reading parv[parc] and beyond is OUT OF BOUNDS and will cause a crash. 919 * E.g. parv[3] in the above example is out of bounds. 920 */ 921 #define CMD_FUNC(x) void (x) (Client *client, MessageTag *recv_mtags, int parc, const char *parv[]) 922 923 /** Call a command function - can be useful if you are calling another command function in your own module. 924 * For example in cmd_nick() we call cmd_nick_local() for local functions, 925 * and then we can just use CALL_CMD_FUNC(cmd_nick_local); and don't have 926 * to bother with passing the right command arguments. Which is nice because 927 * command arguments may change in future UnrealIRCd versions. 928 */ 929 #define CALL_CMD_FUNC(x) (x)(client, recv_mtags, parc, parv) 930 931 /** @} */ 932 933 /** Command override function - used by all command override handlers. 934 * This is used in the code like <pre>CMD_OVERRIDE_FUNC(ovr_somecmd)</pre> as a function definition. 935 * @param ovr The command override structure. 936 * @param cptr The client direction pointer. 937 * @param client The source client pointer (you usually need this one). 938 * @param recv_mtags Received message tags for this command. 939 * @param parc Parameter count *plus* 1. 940 * @param parv Parameter values. 941 * @note Slightly confusing, but parc will be 2 if 1 parameter was provided. 942 * It is two because parv will still have 2 elements, parv[1] will be your first parameter, 943 * and parv[2] will be NULL. 944 * Note that reading parv[parc] and beyond is OUT OF BOUNDS and will cause a crash. 945 * E.g. parv[3] in the above example. 946 */ 947 #define CMD_OVERRIDE_FUNC(x) void (x)(CommandOverride *ovr, Client *client, MessageTag *recv_mtags, int parc, const char *parv[]) 948 949 950 951 typedef void (*CmdFunc)(Client *client, MessageTag *mtags, int parc, const char *parv[]); 952 typedef void (*AliasCmdFunc)(Client *client, MessageTag *mtags, int parc, const char *parv[], const char *cmd); 953 typedef void (*OverrideCmdFunc)(CommandOverride *ovr, Client *client, MessageTag *mtags, int parc, const char *parv[]); 954 955 #include <sodium.h> 956 957 /* This is the 'chunk size', the size of encryption blocks. 958 * We choose 4K here since that is a decent amount as of 2021 and 959 * more would not benefit performance anyway. 960 * Note that you cannot change this value easily afterwards 961 * (you cannot read files with a different chunk size). 962 */ 963 #define UNREALDB_CRYPT_FILE_CHUNK_SIZE 4096 964 965 /** The salt length. Don't change. */ 966 #define UNREALDB_SALT_LEN 16 967 968 /** Database modes of operation (read or write) 969 * @ingroup UnrealDBFunctions 970 */ 971 typedef enum UnrealDBMode { 972 UNREALDB_MODE_READ = 0, 973 UNREALDB_MODE_WRITE = 1 974 } UnrealDBMode; 975 976 typedef enum UnrealDBCipher { 977 UNREALDB_CIPHER_XCHACHA20 = 0x0001 978 } UnrealDBCipher; 979 980 typedef enum UnrealDBKDF { 981 UNREALDB_KDF_ARGON2ID = 0x0001 982 } UnrealDBKDF; 983 984 /** Database configuration for a particular file */ 985 typedef struct UnrealDBConfig { 986 uint16_t kdf; /**< Key derivation function (always 0x01) */ 987 uint16_t t_cost; /**< Time cost (number of rounds) */ 988 uint16_t m_cost; /**< Memory cost (in number of bitshifts, eg 15 means 1<<15=32M) */ 989 uint16_t p_cost; /**< Parallel cost (number of concurrent threads) */ 990 uint16_t saltlen; /**< Length of the salt (normally UNREALDB_SALT_LEN) */ 991 char *salt; /**< Salt */ 992 uint16_t cipher; /**< Encryption cipher (always 0x01) */ 993 uint16_t keylen; /**< Key length */ 994 char *key; /**< The key used for encryption/decryption */ 995 } UnrealDBConfig; 996 997 /** Error codes returned by @ref UnrealDBFunctions 998 * @ingroup UnrealDBFunctions 999 */ 1000 typedef enum UnrealDBError { 1001 UNREALDB_ERROR_SUCCESS = 0, /**< Success, not an error */ 1002 UNREALDB_ERROR_FILENOTFOUND = 1, /**< File does not exist */ 1003 UNREALDB_ERROR_CRYPTED = 2, /**< File is crypted but no password provided */ 1004 UNREALDB_ERROR_NOTCRYPTED = 3, /**< File is not crypted and a password was provided */ 1005 UNREALDB_ERROR_HEADER = 4, /**< Header is corrupt, invalid or unknown format */ 1006 UNREALDB_ERROR_SECRET = 5, /**< Invalid secret { } block provided - either does not exist or does not meet requirements */ 1007 UNREALDB_ERROR_PASSWORD = 6, /**< Invalid password provided */ 1008 UNREALDB_ERROR_IO = 7, /**< I/O error */ 1009 UNREALDB_ERROR_API = 8, /**< API call violation, eg requesting to write on a file opened for reading */ 1010 UNREALDB_ERROR_INTERNAL = 9, /**< Internal error, eg crypto routine returned something unexpected */ 1011 } UnrealDBError; 1012 1013 /** Database handle 1014 * This is returned by unrealdb_open() and used by all other @ref UnrealDBFunctions 1015 * @ingroup UnrealDBFunctions 1016 */ 1017 typedef struct UnrealDB { 1018 FILE *fd; /**< File descriptor */ 1019 UnrealDBMode mode; /**< UNREALDB_MODE_READ / UNREALDB_MODE_WRITE */ 1020 int crypted; /**< Are we doing any encryption or just plaintext? */ 1021 uint64_t creationtime; /**< When this file was created/updates */ 1022 crypto_secretstream_xchacha20poly1305_state st; /**< Internal state for crypto engine */ 1023 char buf[UNREALDB_CRYPT_FILE_CHUNK_SIZE]; /**< Buffer used for reading/writing */ 1024 int buflen; /**< Length of current data in buffer */ 1025 UnrealDBError error_code; /**< Last error code. Whenever this happens we will set this, never overwrite, and block further I/O */ 1026 char *error_string; /**< Error string upon failure */ 1027 UnrealDBConfig *config; /**< Config */ 1028 } UnrealDB; 1029 1030 /** Used for speeding up reading/writing of DBs (so we don't have to run argon2 repeatedly) */ 1031 typedef struct SecretCache SecretCache; 1032 struct SecretCache { 1033 SecretCache *prev, *next; 1034 UnrealDBConfig *config; 1035 time_t cache_hit; 1036 }; 1037 1038 /** Used for storing secret { } blocks */ 1039 struct Secret { 1040 Secret *prev, *next; 1041 char *name; 1042 char *password; 1043 SecretCache *cache; 1044 }; 1045 1046 1047 /* tkl: 1048 * TKL_KILL|TKL_GLOBAL = Global K-Line (GLINE) 1049 * TKL_ZAP|TKL_GLOBAL = Global Z-Line (ZLINE) 1050 * TKL_KILL = Local K-Line 1051 * TKL_ZAP = Local Z-Line 1052 */ 1053 #define TKL_KILL 0x00000001 1054 #define TKL_ZAP 0x00000002 1055 #define TKL_GLOBAL 0x00000004 1056 #define TKL_SHUN 0x00000008 1057 #define TKL_SPAMF 0x00000020 1058 #define TKL_NAME 0x00000040 1059 #define TKL_EXCEPTION 0x00000080 1060 /* these are not real tkl types, but only used for exceptions: */ 1061 #define TKL_BLACKLIST 0x0001000 1062 #define TKL_CONNECT_FLOOD 0x0002000 1063 #define TKL_MAXPERIP 0x0004000 1064 #define TKL_HANDSHAKE_DATA_FLOOD 0x0008000 1065 #define TKL_ANTIRANDOM 0x0010000 1066 #define TKL_ANTIMIXEDUTF8 0x0020000 1067 #define TKL_BAN_VERSION 0x0040000 1068 1069 #define TKLIsServerBan(tkl) ((tkl)->type & (TKL_KILL|TKL_ZAP|TKL_SHUN)) 1070 #define TKLIsServerBanType(tpe) ((tpe) & (TKL_KILL|TKL_ZAP|TKL_SHUN)) 1071 #define TKLIsSpamfilter(tkl) ((tkl)->type & TKL_SPAMF) 1072 #define TKLIsSpamfilterType(tpe) ((tpe) & TKL_SPAMF) 1073 #define TKLIsNameBan(tkl) ((tkl)->type & TKL_NAME) 1074 #define TKLIsNameBanType(tpe) ((tpe) & TKL_NAME) 1075 #define TKLIsBanException(tkl) ((tkl)->type & TKL_EXCEPTION) 1076 #define TKLIsBanExceptionType(tpe) ((tpe) & TKL_EXCEPTION) 1077 1078 #define SPAMF_CHANMSG 0x0001 /* c */ 1079 #define SPAMF_USERMSG 0x0002 /* p */ 1080 #define SPAMF_USERNOTICE 0x0004 /* n */ 1081 #define SPAMF_CHANNOTICE 0x0008 /* N */ 1082 #define SPAMF_PART 0x0010 /* P */ 1083 #define SPAMF_QUIT 0x0020 /* q */ 1084 #define SPAMF_DCC 0x0040 /* d */ 1085 #define SPAMF_USER 0x0080 /* u */ 1086 #define SPAMF_AWAY 0x0100 /* a */ 1087 #define SPAMF_TOPIC 0x0200 /* t */ 1088 #define SPAMF_MTAG 0x0400 /* m */ 1089 1090 /* Other flags only for function calls: */ 1091 #define SPAMFLAG_NOWARN 0x0001 1092 1093 /* Ban actions. These must be ordered by severity (!) */ 1094 typedef enum BanAction { 1095 BAN_ACT_GZLINE =1100, 1096 BAN_ACT_GLINE =1000, 1097 BAN_ACT_SOFT_GLINE = 950, 1098 BAN_ACT_ZLINE = 900, 1099 BAN_ACT_KLINE = 800, 1100 BAN_ACT_SOFT_KLINE = 850, 1101 BAN_ACT_SHUN = 700, 1102 BAN_ACT_SOFT_SHUN = 650, 1103 BAN_ACT_KILL = 600, 1104 BAN_ACT_SOFT_KILL = 550, 1105 BAN_ACT_TEMPSHUN = 500, 1106 BAN_ACT_SOFT_TEMPSHUN = 450, 1107 BAN_ACT_VIRUSCHAN = 400, 1108 BAN_ACT_SOFT_VIRUSCHAN = 350, 1109 BAN_ACT_DCCBLOCK = 300, 1110 BAN_ACT_SOFT_DCCBLOCK = 250, 1111 BAN_ACT_BLOCK = 200, 1112 BAN_ACT_SOFT_BLOCK = 150, 1113 BAN_ACT_WARN = 100, 1114 BAN_ACT_SOFT_WARN = 50, 1115 } BanAction; 1116 1117 #define IsSoftBanAction(x) ((x == BAN_ACT_SOFT_GLINE) || (x == BAN_ACT_SOFT_KLINE) || \ 1118 (x == BAN_ACT_SOFT_SHUN) || (x == BAN_ACT_SOFT_KILL) || \ 1119 (x == BAN_ACT_SOFT_TEMPSHUN) || (x == BAN_ACT_SOFT_VIRUSCHAN) || \ 1120 (x == BAN_ACT_SOFT_DCCBLOCK) || (x == BAN_ACT_SOFT_BLOCK) || \ 1121 (x == BAN_ACT_SOFT_WARN)) 1122 1123 1124 /** Server ban sub-struct of TKL entry (KLINE/GLINE/ZLINE/GZLINE/SHUN) */ 1125 struct ServerBan { 1126 char *usermask; /**< User mask */ 1127 char *hostmask; /**< Host mask */ 1128 unsigned short subtype; /**< See TKL_SUBTYPE_* */ 1129 char *reason; /**< Reason */ 1130 }; 1131 1132 /* Name ban sub-struct of TKL entry (QLINE) */ 1133 struct NameBan { 1134 char hold; /**< nickname hold is used by services */ 1135 char *name; /**< the nick or channel that is banned */ 1136 char *reason; /**< Reason */ 1137 }; 1138 1139 /** Spamfilter sub-struct of TKL entry (Spamfilter) */ 1140 struct Spamfilter { 1141 unsigned short target; 1142 BanAction action; /**< Ban action, see BAN_ACT* */ 1143 Match *match; /**< Spamfilter matcher */ 1144 char *tkl_reason; /**< Reason to use for bans placed by this spamfilter, escaped by unreal_encodespace(). */ 1145 time_t tkl_duration; /**< Duration of bans placed by this spamfilter */ 1146 }; 1147 1148 /** Ban exception sub-struct of TKL entry (ELINE) */ 1149 struct BanException { 1150 char *usermask; /**< User mask */ 1151 char *hostmask; /**< Host mask */ 1152 SecurityGroup *match; /**< Security group (for config file items only) */ 1153 unsigned short subtype; /**< See TKL_SUBTYPE_* */ 1154 char *bantypes; /**< Exception types */ 1155 char *reason; /**< Reason */ 1156 }; 1157 1158 1159 #define TKL_SUBTYPE_NONE 0x0000 1160 #define TKL_SUBTYPE_SOFT 0x0001 /* (require SASL) */ 1161 1162 #define TKL_FLAG_CONFIG 0x0001 /* Entry from configuration file. Cannot be removed by using commands. */ 1163 1164 /** A TKL entry, such as a KLINE, GLINE, Spamfilter, QLINE, Exception, .. */ 1165 struct TKL { 1166 TKL *prev, *next; 1167 unsigned int type; /**< TKL type. One of TKL_*, such as TKL_KILL|TKL_GLOBAL for gline */ 1168 unsigned short flags; /**< One of TKL_FLAG_*, such as TKL_FLAG_CONFIG */ 1169 char *set_by; /**< By who was this entry added */ 1170 time_t set_at; /**< When this entry was added */ 1171 time_t expire_at; /**< When this entry will expire */ 1172 union { 1173 Spamfilter *spamfilter; 1174 ServerBan *serverban; 1175 NameBan *nameban; 1176 BanException *banexception; 1177 } ptr; 1178 }; 1179 1180 /** A spamfilter except entry */ 1181 struct SpamExcept { 1182 SpamExcept *prev, *next; 1183 char name[1]; 1184 }; 1185 1186 /** IRC Counts, used for /LUSERS */ 1187 typedef struct IRCCounts IRCCounts; 1188 struct IRCCounts { 1189 int clients; /* total */ 1190 int invisible; /* invisible */ 1191 int servers; /* servers */ 1192 int operators; /* operators */ 1193 int unknown; /* unknown local connections */ 1194 int channels; /* channels */ 1195 int me_clients; /* my clients */ 1196 int me_servers; /* my servers */ 1197 int me_max; /* local max */ 1198 int global_max; /* global max */ 1199 }; 1200 1201 /** The /LUSERS stats information */ 1202 extern MODVAR IRCCounts irccounts; 1203 1204 typedef struct NameValue NameValue; 1205 /** Name and value list used in a static array, such as in conf.c */ 1206 struct NameValue 1207 { 1208 long value; 1209 char *name; 1210 }; 1211 1212 /** Name and value list used in dynamic linked lists */ 1213 typedef struct NameValueList NameValueList; 1214 struct NameValueList { 1215 NameValueList *prev, *next; 1216 char *name; 1217 char *value; 1218 }; 1219 1220 typedef struct NameValuePrioList NameValuePrioList; 1221 struct NameValuePrioList { 1222 NameValuePrioList *prev, *next; 1223 int priority; 1224 char *name; 1225 char *value; 1226 }; 1227 1228 #include "modules.h" 1229 1230 /** A "real" command (internal interface, not for modules) */ 1231 struct RealCommand { 1232 RealCommand *prev, *next; 1233 char *cmd; 1234 CmdFunc func; 1235 AliasCmdFunc aliasfunc; 1236 int flags; 1237 unsigned int count; 1238 unsigned parameters : 5; 1239 unsigned long bytes; 1240 Module *owner; 1241 RealCommand *friend; /* cmd if token, token if cmd */ 1242 CommandOverride *overriders; 1243 #ifdef DEBUGMODE 1244 unsigned long lticks; 1245 unsigned long rticks; 1246 #endif 1247 }; 1248 1249 /** A command override */ 1250 struct CommandOverride { 1251 CommandOverride *prev, *next; 1252 int priority; 1253 Module *owner; 1254 RealCommand *command; 1255 OverrideCmdFunc func; 1256 }; 1257 1258 extern MODVAR Umode *usermodes; 1259 extern MODVAR Cmode *channelmodes; 1260 1261 extern Umode *UmodeAdd(Module *module, char ch, int options, int unset_on_deoper, int (*allowed)(Client *client, int what), long *mode); 1262 extern void UmodeDel(Umode *umode); 1263 1264 extern Cmode *CmodeAdd(Module *reserved, CmodeInfo req, Cmode_t *mode); 1265 extern void CmodeDel(Cmode *cmode); 1266 1267 extern void moddata_init(void); 1268 extern ModDataInfo *ModDataAdd(Module *module, ModDataInfo req); 1269 extern void ModDataDel(ModDataInfo *md); 1270 extern void unload_all_unused_moddata(void); 1271 1272 #define LISTENER_NORMAL 0x000001 1273 #define LISTENER_CLIENTSONLY 0x000002 1274 #define LISTENER_SERVERSONLY 0x000004 1275 #define LISTENER_TLS 0x000010 1276 #define LISTENER_BOUND 0x000020 1277 #define LISTENER_DEFER_ACCEPT 0x000040 1278 #define LISTENER_CONTROL 0x000080 /**< Control channel */ 1279 #define LISTENER_NO_CHECK_CONNECT_FLOOD 0x000100 /**< Don't check for connect-flood and max-unknown-connections-per-ip (eg for RPC) */ 1280 #define LISTENER_NO_CHECK_ZLINED 0x000200 /**< Don't check for zlines */ 1281 1282 #define IsServersOnlyListener(x) ((x) && ((x)->options & LISTENER_SERVERSONLY)) 1283 1284 #define CONNECT_TLS 0x000001 1285 #define CONNECT_AUTO 0x000002 1286 #define CONNECT_QUARANTINE 0x000004 1287 #define CONNECT_INSECURE 0x000008 1288 1289 #define TLSFLAG_FAILIFNOCERT 0x0001 1290 #define TLSFLAG_NOSTARTTLS 0x0002 1291 #define TLSFLAG_DISABLECLIENTCERT 0x0004 1292 1293 /** Flood counters for local clients */ 1294 typedef struct FloodCounter { 1295 int count; 1296 long t; 1297 } FloodCounter; 1298 1299 /** This is the list of different flood counters that we keep for local clients. */ 1300 /* IMPORTANT: If you change this, update floodoption_names[] in src/user.c too !!!!!!!!!!!! */ 1301 typedef enum FloodOption { 1302 FLD_NICK = 0, /**< nick-flood */ 1303 FLD_JOIN = 1, /**< join-flood */ 1304 FLD_AWAY = 2, /**< away-flood */ 1305 FLD_INVITE = 3, /**< invite-flood */ 1306 FLD_KNOCK = 4, /**< knock-flood */ 1307 FLD_CONVERSATIONS = 5, /**< max-concurrent-conversations */ 1308 FLD_LAG_PENALTY = 6, /**< lag-penalty / lag-penalty-bytes */ 1309 FLD_VHOST = 7, /**< vhost-flood */ 1310 } FloodOption; 1311 #define MAXFLOODOPTIONS 10 1312 1313 typedef struct TrafficStats TrafficStats; 1314 struct TrafficStats { 1315 long long messages_sent; /* IRC lines sent */ 1316 long long messages_received; /* IRC lines received */ 1317 long long bytes_sent; /* Bytes sent */ 1318 long long bytes_received; /* Received bytes */ 1319 }; 1320 1321 /** Socket type (IPv4, IPv6, UNIX) */ 1322 typedef enum { 1323 SOCKET_TYPE_IPV4=0, SOCKET_TYPE_IPV6=1, SOCKET_TYPE_UNIX=2 1324 } SocketType; 1325 1326 /** This shows the Client struct (any client), the User struct (a user), Server (a server) that are commonly accessed both in the core and by 3rd party coders. 1327 * @defgroup CommonStructs Common structs 1328 * @{ 1329 */ 1330 1331 /** A client on this or a remote server - can be a user, server, unknown, etc.. 1332 */ 1333 struct Client { 1334 struct list_head client_node; /**< For global client list (client_list) */ 1335 struct list_head lclient_node; /**< For local client list (lclient_list) */ 1336 struct list_head special_node; /**< For special lists (server || unknown || oper) */ 1337 LocalClient *local; /**< Additional information regarding locally connected clients */ 1338 User *user; /**< Additional information, if this client is a user */ 1339 Server *server; /**< Additional information, if this is a server */ 1340 RPCClient *rpc; /**< RPC Client, or NULL */ 1341 ClientStatus status; /**< Client status, one of CLIENT_STATUS_* */ 1342 struct list_head client_hash; /**< For name hash table (clientTable) */ 1343 char name[HOSTLEN + 1]; /**< Unique name of the client: nickname for users, hostname for servers */ 1344 time_t lastnick; /**< Timestamp on nick */ 1345 uint64_t flags; /**< Client flags (one or more of CLIENT_FLAG_*) */ 1346 long umodes; /**< Client usermodes (if user) */ 1347 Client *direction; /**< Direction from which this client originated. 1348 This always points to a directly connected server or &me. 1349 It is never NULL */ 1350 unsigned char hopcount; /**< Number of servers to this, 0 means local client */ 1351 char ident[USERLEN + 1]; /**< Ident of the user, if available. Otherwise set to "unknown". */ 1352 char info[REALLEN + 1]; /**< Additional client information text. For users this is gecos/realname */ 1353 char id[IDLEN + 1]; /**< Unique ID: SID or UID */ 1354 struct list_head id_hash; /**< For UID/SID hash table (idTable) */ 1355 Client *uplink; /**< Server on where this client is connected to (can be &me) */ 1356 char *ip; /**< IP address of user or server (never NULL) */ 1357 ModData moddata[MODDATA_MAX_CLIENT]; /**< Client attached module data, used by the ModData system */ 1358 }; 1359 1360 /** Local client information, use client->local to access these (see also @link Client @endlink). 1361 */ 1362 struct LocalClient { 1363 int fd; /**< File descriptor, can be <0 if socket has been closed already. */ 1364 SocketType socket_type; /**< Type of socket: IPv4, IPV6, UNIX */ 1365 SSL *ssl; /**< OpenSSL/LibreSSL struct for TLS connection */ 1366 time_t fake_lag; /**< Time when user will next be allowed to send something (actually fake_lag<currenttime+10) */ 1367 int fake_lag_msec; /**< Used for calculating 'fake_lag' penalty (modulo) */ 1368 time_t creationtime; /**< Time user was created (connected on IRC) */ 1369 time_t last_msg_received; /**< Last time any message was received */ 1370 dbuf sendQ; /**< Outgoing send queue (data to be sent) */ 1371 dbuf recvQ; /**< Incoming receive queue (incoming data yet to be parsed) */ 1372 ConfigItem_class *class; /**< The class { } block associated to this client */ 1373 int proto; /**< PROTOCTL options */ 1374 long caps; /**< User: enabled capabilities (via CAP command) */ 1375 time_t nexttarget; /**< Next time that a new target will be allowed (msg/notice/invite) */ 1376 u_char targets[MAXCCUSERS]; /**< Hash values of targets for target limiting */ 1377 ConfigItem_listen *listener; /**< If this client IsListening() then this is the listener configuration attached to it */ 1378 long serial; /**< Current serial number for send.c functions (to avoid sending duplicate messages) */ 1379 time_t next_nick_allowed; /**< Time the next nick change will be allowed */ 1380 time_t idle_since; /**< Last time a RESETIDLE message was received (PRIVMSG) */ 1381 TrafficStats traffic; /**< Traffic statistics */ 1382 ModData moddata[MODDATA_MAX_LOCAL_CLIENT]; /**< LocalClient attached module data, used by the ModData system */ 1383 char *error_str; /**< Quit reason set by dead_socket() in case of socket/buffer error, later used by exit_client() */ 1384 char sasl_agent[NICKLEN + 1]; /**< SASL: SASL Agent the user is interacting with */ 1385 unsigned char sasl_out; /**< SASL: Number of outgoing sasl messages */ 1386 unsigned char sasl_complete; /**< SASL: >0 if SASL authentication was successful */ 1387 time_t sasl_sent_time; /**< SASL: 0 or the time that the (last) AUTHENTICATE command has been sent */ 1388 char *sni_servername; /**< Servername as sent by client via SNI (Server Name Indication) in TLS, otherwise NULL */ 1389 int cap_protocol; /**< CAP protocol in use. At least 300 for any CAP capable client. 302 for 3.2, etc.. */ 1390 uint32_t nospoof; /**< Anti-spoofing random number (used in user handshake PING/PONG) */ 1391 char *passwd; /**< Password used during connect, if any (freed once connected and set to NULL) */ 1392 int authfd; /**< File descriptor for ident checking (RFC931) */ 1393 int identbufcnt; /**< Counter for 'ident' reading code */ 1394 struct hostent *hostp; /**< Host record for this client (used by DNS code) */ 1395 char sockhost[HOSTLEN + 1]; /**< Hostname from the socket */ 1396 u_short port; /**< Remote TCP port of client */ 1397 FloodCounter flood[MAXFLOODOPTIONS]; 1398 RPCClient *rpc; /**< RPC Client, or NULL */ 1399 }; 1400 1401 /** User information (persons, not servers), you use client->user to access these (see also @link Client @endlink). 1402 */ 1403 struct User { 1404 Membership *channel; /**< Channels that the user is in (linked list) */ 1405 Link *dccallow; /**< DCCALLOW list (linked list) */ 1406 char account[ACCOUNTLEN + 1]; /**< Services account name or ID (SVID) - use IsLoggedIn(client) to check if logged in */ 1407 int joined; /**< Number of channels joined */ 1408 char username[USERLEN + 1]; /**< Username, the user portion in nick!user@host. */ 1409 char realhost[HOSTLEN + 1]; /**< Realhost, the real host of the user (IP or hostname) - usually this is not shown to other users */ 1410 char cloakedhost[HOSTLEN + 1]; /**< Cloaked host - generated by cloaking algorithm */ 1411 char *virthost; /**< Virtual host - when user has user mode +x this is the active host */ 1412 char *server; /**< Server name the user is on (?) */ 1413 SWhois *swhois; /**< Special "additional" WHOIS entries such as "a Network Administrator" */ 1414 WhoWas *whowas; /**< Something for whowas :D :D */ 1415 char *snomask; /**< Server Notice Mask (snomask) - only for IRCOps */ 1416 char *operlogin; /**< Which oper { } block was used to oper up, otherwise NULL - used for auditting and by oper::maxlogins */ 1417 char *away; /**< AWAY message, or NULL if not away */ 1418 time_t away_since; /**< Last time the user went AWAY */ 1419 }; 1420 1421 /** Server information (local servers and remote servers), you use client->server to access these (see also @link Client @endlink). 1422 */ 1423 struct Server { 1424 char by[NICKLEN + 1]; /**< Uhhhh - who activated this connection - AGAIN? */ 1425 ConfigItem_link *conf; /**< link { } block associated with this server, or NULL */ 1426 long users; /**< Number of users on this server */ 1427 time_t boottime; /**< Startup time of server (boot time) */ 1428 struct { 1429 unsigned synced:1; /**< Server synchronization finished? (3.2beta18+) */ 1430 unsigned server_sent:1; /**< SERVER message sent to this link? (for outgoing links) */ 1431 } flags; 1432 struct { 1433 char *usermodes; /**< Usermodes that this server knows about */ 1434 char *chanmodes[4]; /**< Channel modes that this server knows (in 4 groups, like CHANMODES= in ISUPPORT/005) */ 1435 int protocol; /**< Link-protocol version */ 1436 char *software; /**< Name of the software (eg: unrealircd-X.Y.Z) */ 1437 char *nickchars; /**< Nick character sets active on this server) */ 1438 } features; 1439 }; 1440 1441 /** @} */ 1442 1443 typedef struct RPCClient RPCClient; 1444 /** RPC Client information */ 1445 struct RPCClient { 1446 char *rpc_user; /**< Name of the rpc-user block after authentication, NULL during pre-auth */ 1447 char *issuer; /**< Optional name of the issuer, set by rpc.set_issuer(), eg logged in user on admin panel, can be NULL */ 1448 json_t *rehash_request; /**< If a REHASH (request) is currently running, otherwise NULL */ 1449 LogSource *log_sources; /**< Subscribed to which log sources */ 1450 }; 1451 1452 struct MessageTag { 1453 MessageTag *prev, *next; 1454 char *name; 1455 char *value; 1456 }; 1457 1458 /* conf preprocessor */ 1459 typedef enum PreprocessorItem { 1460 PREPROCESSOR_ERROR = 0, 1461 PREPROCESSOR_DEFINE = 1, 1462 PREPROCESSOR_IF = 2, 1463 PREPROCESSOR_ENDIF = 3 1464 } PreprocessorItem; 1465 1466 typedef enum PreprocessorPhase { 1467 PREPROCESSOR_PHASE_INITIAL = 1, 1468 PREPROCESSOR_PHASE_SECONDARY = 2, 1469 PREPROCESSOR_PHASE_MODULE = 3 1470 } PreprocessorPhase; 1471 1472 typedef enum AuthenticationType { 1473 AUTHTYPE_INVALID = -1, 1474 AUTHTYPE_PLAINTEXT = 0, 1475 AUTHTYPE_TLS_CLIENTCERT = 1, 1476 AUTHTYPE_TLS_CLIENTCERTFP = 2, 1477 AUTHTYPE_SPKIFP = 3, 1478 AUTHTYPE_UNIXCRYPT = 4, 1479 AUTHTYPE_BCRYPT = 5, 1480 AUTHTYPE_ARGON2 = 6, 1481 } AuthenticationType; 1482 1483 typedef struct AuthConfig AuthConfig; 1484 /** Authentication Configuration - this can be a password or 1485 * other authentication method that was parsed from the 1486 * configuration file. 1487 */ 1488 struct AuthConfig { 1489 AuthenticationType type; /**< Type of data, one of AUTHTYPE_* */ 1490 char *data; /**< Data associated with this record */ 1491 }; 1492 1493 #ifndef HAVE_CRYPT 1494 #define crypt DES_crypt 1495 #endif 1496 1497 /* CRULE stuff */ 1498 1499 #define CRULE_ALL 0 1500 #define CRULE_AUTO 1 1501 1502 /* some constants and shared data types */ 1503 #define CR_MAXARGLEN 80 /**< Maximum arg length (must be > HOSTLEN) */ 1504 #define CR_MAXARGS 3 /**< Maximum number of args for a rule */ 1505 1506 /** Evaluation function for a connection rule. */ 1507 typedef int (*crule_funcptr) (int, void **); 1508 1509 /** CRULE - Node in a connection rule tree. */ 1510 struct CRuleNode { 1511 crule_funcptr funcptr; /**< Evaluation function for this node. */ 1512 int numargs; /**< Number of arguments. */ 1513 void *arg[CR_MAXARGS]; /**< Array of arguments. For operators, each arg 1514 is a tree element; for functions, each arg is 1515 a string. */ 1516 }; 1517 typedef struct CRuleNode CRuleNode; 1518 typedef struct CRuleNode* CRuleNodePtr; 1519 1520 1521 /* 1522 * conf2 stuff -stskeeps 1523 */ 1524 1525 typedef enum ConfigIfCondition { IF_DEFINED=1, IF_VALUE=2, IF_MODULE=3} ConfigIfCondition; 1526 1527 struct ConditionalConfig 1528 { 1529 ConditionalConfig *prev, *next; 1530 int priority; /**< Preprocessor level. Starts with 1, then 2, 3, .. */ 1531 ConfigIfCondition condition; /**< See ConfigIfCondition, one of: IF_* */ 1532 int negative; /**< For ! conditions */ 1533 char *name; /**< Name of the variable or module */ 1534 char *opt; /**< Only for IF_VALUE */ 1535 }; 1536 1537 /** Configuration file (config parser) */ 1538 struct ConfigFile 1539 { 1540 char *filename; /**< Filename of configuration file */ 1541 ConfigEntry *items; /**< All items in the configuration file */ 1542 ConfigFile *next; /**< Next configuration file */ 1543 }; 1544 1545 /** Configuration entry (config parser) */ 1546 struct ConfigEntry 1547 { 1548 char *name; /**< Variable name */ 1549 char *value; /**< Variable value, can be NULL */ 1550 ConfigEntry *next; /**< Next ConfigEntry */ 1551 ConfigEntry *items; /**< Items (children), can be NULL */ 1552 ConfigFile *file; /**< To which configfile does this belong? */ 1553 int line_number; /**< Line number of the variable name (this one is usually used for errors) */ 1554 int file_position_start; /**< Position (byte) within configuration file of the start of the block, rarely used */ 1555 int file_position_end; /**< Position (byte) within configuration file of the end of the block, rarely used */ 1556 int section_linenumber; /**< Line number of the section (only used internally for parse errors) */ 1557 ConfigEntry *parent; /**< Parent item, can be NULL */ 1558 ConditionalConfig *conditional_config; /**< Used for conditional config by the main parser */ 1559 unsigned escaped:1; 1560 }; 1561 1562 struct ConfigFlag 1563 { 1564 unsigned temporary : 1; 1565 unsigned permanent : 1; 1566 }; 1567 1568 /* configflag specialized for except socks/ban -Stskeeps */ 1569 1570 struct ConfigFlag_except 1571 { 1572 unsigned temporary : 1; 1573 unsigned type : 4; 1574 }; 1575 1576 struct ConfigFlag_ban 1577 { 1578 unsigned temporary : 1; 1579 unsigned type : 4; 1580 unsigned type2 : 2; 1581 }; 1582 1583 struct ConfigFlag_tld 1584 { 1585 unsigned temporary : 1; 1586 unsigned motdptr : 1; 1587 unsigned ruleclient : 1; 1588 }; 1589 1590 #define CONF_BAN_SERVER 1 1591 #define CONF_BAN_VERSION 2 1592 #define CONF_BAN_REALNAME 3 1593 1594 #define CONF_BAN_TYPE_CONF 0 1595 #define CONF_BAN_TYPE_AKILL 1 1596 #define CONF_BAN_TYPE_TEMPORARY 2 1597 1598 struct ConfigItem { 1599 ConfigItem *prev, *next; 1600 ConfigFlag flag; 1601 }; 1602 1603 struct ConfigItem_me { 1604 char *name, *info, *sid; 1605 }; 1606 1607 struct ConfigItem_files { 1608 char *motd_file, *rules_file, *smotd_file; 1609 char *botmotd_file, *opermotd_file, *svsmotd_file; 1610 char *pid_file, *tune_file; 1611 }; 1612 1613 struct ConfigItem_admin { 1614 ConfigItem_admin *prev, *next; 1615 ConfigFlag flag; 1616 char *line; 1617 }; 1618 1619 #define CLASS_OPT_NOFAKELAG 0x1 1620 1621 struct ConfigItem_class { 1622 ConfigItem_class *prev, *next; 1623 ConfigFlag flag; 1624 char *name; 1625 int pingfreq, connfreq, maxclients, sendq, recvq, clients; 1626 int xrefcount; /* EXTRA reference count, 'clients' also acts as a reference count but 1627 * link blocks also refer to classes so a 2nd ref. count was needed. 1628 */ 1629 unsigned int options; 1630 }; 1631 1632 struct ConfigFlag_allow { 1633 unsigned noident :1; 1634 unsigned useip :1; 1635 unsigned tls :1; 1636 unsigned reject_on_auth_failure :1; 1637 }; 1638 1639 /** allow { } block settings */ 1640 struct ConfigItem_allow { 1641 ConfigItem_allow *prev, *next; 1642 ConfigFlag flag; 1643 SecurityGroup *match; 1644 char *server; 1645 AuthConfig *auth; 1646 int maxperip; /**< Maximum connections permitted per IP address (locally) */ 1647 int global_maxperip; /**< Maximum connections permitted per IP address (globally) */ 1648 int port; 1649 ConfigItem_class *class; 1650 ConfigFlag_allow flags; 1651 int ipv6_clone_mask; 1652 }; 1653 1654 struct OperClassACLPath 1655 { 1656 OperClassACLPath *prev,*next; 1657 char *identifier; 1658 }; 1659 1660 struct OperClassACLEntryVar 1661 { 1662 OperClassACLEntryVar *prev,*next; 1663 char *name; 1664 char *value; 1665 }; 1666 1667 struct OperClassACLEntry 1668 { 1669 OperClassACLEntry *prev,*next; 1670 OperClassACLEntryVar *variables; 1671 OperClassEntryType type; 1672 }; 1673 1674 struct OperClassACL 1675 { 1676 OperClassACL *prev,*next; 1677 char *name; 1678 OperClassACLEntry *entries; 1679 OperClassACL *acls; 1680 }; 1681 1682 struct OperClass 1683 { 1684 char *ISA; 1685 char *name; 1686 OperClassACL *acls; 1687 }; 1688 1689 struct OperClassCheckParams 1690 { 1691 Client *client; 1692 Client *victim; 1693 Channel *channel; 1694 const void *extra; 1695 }; 1696 1697 struct ConfigItem_operclass { 1698 ConfigItem_operclass *prev, *next; 1699 OperClass *classStruct; 1700 }; 1701 1702 struct ConfigItem_oper { 1703 ConfigItem_oper *prev, *next; 1704 ConfigFlag flag; 1705 char *name, *snomask; 1706 SWhois *swhois; 1707 AuthConfig *auth; 1708 char *operclass; 1709 ConfigItem_class *class; 1710 SecurityGroup *match; 1711 unsigned long modes, require_modes; 1712 char *vhost; 1713 int maxlogins; 1714 int server_notice_colors; 1715 int server_notice_show_event; 1716 int auto_login; 1717 }; 1718 1719 /** The TLS options that are used in set::tls and otherblocks::tls-options. 1720 * NOTE: If you add something here then you must also update the 1721 * conf_tlsblock() function in s_conf.c to have it inherited 1722 * from set::tls to the other config blocks! 1723 */ 1724 typedef struct TLSOptions TLSOptions; 1725 struct TLSOptions { 1726 char *certificate_file; 1727 char *key_file; 1728 char *trusted_ca_file; 1729 unsigned int protocols; 1730 char *ciphers; 1731 char *ciphersuites; 1732 char *ecdh_curves; 1733 char *outdated_protocols; 1734 char *outdated_ciphers; 1735 long options; 1736 int renegotiate_bytes; 1737 int renegotiate_timeout; 1738 int sts_port; 1739 long sts_duration; 1740 int sts_preload; 1741 }; 1742 1743 struct ConfigItem_mask { 1744 ConfigItem_mask *prev, *next; 1745 ConfigFlag flag; 1746 char *mask; 1747 }; 1748 1749 struct ConfigItem_drpass { 1750 AuthConfig *restartauth; 1751 AuthConfig *dieauth; 1752 }; 1753 1754 struct ConfigItem_ulines { 1755 ConfigItem_ulines *prev, *next; 1756 ConfigFlag flag; 1757 char *servername; 1758 }; 1759 1760 #define TLD_TLS 0x1 1761 #define TLD_REMOTE 0x2 1762 1763 struct ConfigItem_tld { 1764 ConfigItem_tld *prev, *next; 1765 ConfigFlag_tld flag; 1766 SecurityGroup *match; 1767 char *channel; 1768 char *motd_file, *rules_file, *smotd_file; 1769 char *botmotd_file, *opermotd_file; 1770 MOTDFile rules, motd, smotd, botmotd, opermotd; 1771 u_short options; 1772 }; 1773 1774 #define WEB_OPT_ENABLE 0x1 1775 1776 typedef enum HttpMethod { 1777 HTTP_METHOD_NONE = 0, /**< No valid HTTP request (yet) */ 1778 HTTP_METHOD_HEAD = 1, /**< HEAD request */ 1779 HTTP_METHOD_GET = 2, /**< GET request */ 1780 HTTP_METHOD_PUT = 3, /**< PUT request */ 1781 HTTP_METHOD_POST = 4, /**< POST request */ 1782 } HttpMethod; 1783 1784 typedef enum TransferEncoding { 1785 TRANSFER_ENCODING_NONE=0, 1786 TRANSFER_ENCODING_CHUNKED=1 1787 } TransferEncoding; 1788 1789 typedef struct WebRequest WebRequest; 1790 struct WebRequest { 1791 HttpMethod method; /**< GET/PUT/POST */ 1792 char *uri; /**< Requested resource, eg "/api" */ 1793 NameValuePrioList *headers; /**< HTTP request headers */ 1794 int num_headers; /**< Number of HTTP request headers (also used for sorting the list) */ 1795 char request_header_parsed; /**< Done parsing? */ 1796 char *lefttoparse; /**< Leftover buffer to parse */ 1797 int lefttoparselen; /**< Length of lefttoparse buffer */ 1798 int pending_close; /**< Set to 1 when connection should be closed as soon as all data is sent (sendq==0) */ 1799 char *request_buffer; /**< Buffer for POST data */ 1800 int request_buffer_size; /**< Size of buffer for POST data */ 1801 int request_body_complete; /**< POST data has all been read */ 1802 long long content_length; /**< "Content-Length" as sent by the client */ 1803 long long chunk_remaining; 1804 TransferEncoding transfer_encoding; 1805 long long config_max_request_buffer_size; /**< CONFIG: Maximum request length allowed */ 1806 }; 1807 1808 typedef struct WebServer WebServer; 1809 struct WebServer { 1810 int (*handle_request)(Client *client, WebRequest *web); 1811 int (*handle_body)(Client *client, WebRequest *web, const char *buf, int length); 1812 }; 1813 1814 typedef enum WebSocketType { 1815 WEBSOCKET_TYPE_BINARY = 1, 1816 WEBSOCKET_TYPE_TEXT = 2 1817 } WebSocketType; 1818 1819 typedef struct WebSocketUser WebSocketUser; 1820 struct WebSocketUser { 1821 char get; /**< GET initiated */ 1822 char handshake_completed; /**< Handshake completed, use websocket frames */ 1823 char *handshake_key; /**< Handshake key (used during handshake) */ 1824 char *lefttoparse; /**< Leftover buffer to parse */ 1825 int lefttoparselen; /**< Length of lefttoparse buffer */ 1826 WebSocketType type; /**< WEBSOCKET_TYPE_BINARY or WEBSOCKET_TYPE_TEXT */ 1827 char *sec_websocket_protocol; /**< Only valid during parsing of the request, after that it is NULL again */ 1828 char *forwarded; /**< Unparsed `Forwarded:` header, RFC 7239 */ 1829 int secure; /**< If there is a Forwarded header, this indicates if the remote connection is secure */ 1830 }; 1831 1832 #define WEBSOCKET_MAGIC_KEY "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" /* see RFC6455 */ 1833 1834 /* Websocket operations: */ 1835 #define WSOP_CONTINUATION 0x00 1836 #define WSOP_TEXT 0x01 1837 #define WSOP_BINARY 0x02 1838 #define WSOP_CLOSE 0x08 1839 #define WSOP_PING 0x09 1840 #define WSOP_PONG 0x0a 1841 1842 struct ConfigItem_listen { 1843 ConfigItem_listen *prev, *next; 1844 ConfigFlag flag; 1845 SocketType socket_type; /**< Socket type, eg. SOCKET_TYPE_IPV4 or SOCKET_TYPE_UNIX */ 1846 char *file; /**< If the listener is a file, the full pathname */ 1847 char *ip; /**< IP bind address (if IP listener) */ 1848 int port; /**< Port to listen on (if IP listener) */ 1849 int mode; /**< Mode permissions (if file aka unix socket listener) */ 1850 int options; /**< e.g. LISTENER_BOUND if active */ 1851 int clients; /**< Clients connected to this socket / listener */ 1852 int fd; /**< File descriptor (if open), or -1 (if not open yet) */ 1853 char *spoof_ip; /**< listen::spoof-ip (only for listen::file, if you want to override 127.0.0.1) */ 1854 SSL_CTX *ssl_ctx; /**< SSL/TLS context */ 1855 TLSOptions *tls_options; /**< SSL/TLS options */ 1856 WebServer *webserver; /**< For the webserver module */ 1857 void (*start_handshake)(Client *client); /**< Function to call on accept() */ 1858 int websocket_options; /**< Websocket options (for the websocket module) */ 1859 int rpc_options; /**< For the RPC module */ 1860 char *websocket_forward; /**< For websocket module too */ 1861 }; 1862 1863 struct ConfigItem_sni { 1864 ConfigItem_sni *prev, *next; 1865 ConfigFlag flag; 1866 char *name; 1867 SSL_CTX *ssl_ctx; 1868 TLSOptions *tls_options; 1869 }; 1870 1871 struct ConfigItem_vhost { 1872 ConfigItem_vhost *prev, *next; 1873 ConfigFlag flag; 1874 SecurityGroup *match; 1875 char *login, *virthost, *virtuser; 1876 SWhois *swhois; 1877 AuthConfig *auth; 1878 }; 1879 1880 struct ConfigItem_link { 1881 ConfigItem_link *prev, *next; 1882 ConfigFlag flag; 1883 /* config options: */ 1884 char *servername; /**< Name of the server ('link <servername> { }') */ 1885 struct { 1886 SecurityGroup *match; /**< incoming mask(s) to accept */ 1887 } incoming; 1888 struct { 1889 char *file; /**< UNIX domain socket to connect to */ 1890 char *bind_ip; /**< Our IP to bind to when doing the connect */ 1891 char *hostname; /**< Hostname or IP to connect to */ 1892 int port; /**< Port to connect to */ 1893 int options; /**< Connect options like tls or autoconnect */ 1894 } outgoing; 1895 AuthConfig *auth; /**< authentication method (eg: password) */ 1896 char *hub; /**< Hub mask */ 1897 char *leaf; /**< Leaf mask */ 1898 int leaf_depth; /**< Leaf depth */ 1899 ConfigItem_class *class; /**< Class the server should use */ 1900 int options; /**< Generic options such as quarantine */ 1901 int verify_certificate; 1902 /* internal: */ 1903 int refcount; /**< Reference counter (used so we know if the struct may be freed) */ 1904 time_t hold; /**< For how long the server is "on hold" for outgoing connects (why?) */ 1905 char *connect_ip; /**< actual IP to use for outgoing connect (filled in after host is resolved) */ 1906 SSL_CTX *ssl_ctx; /**< SSL Context for outgoing connection (optional) */ 1907 TLSOptions *tls_options; /**< SSL Options for outgoing connection (optional) */ 1908 }; 1909 1910 struct ConfigItem_ban { 1911 ConfigItem_ban *prev, *next; 1912 ConfigFlag_ban flag; 1913 char *mask, *reason; 1914 unsigned short action; 1915 }; 1916 1917 struct ConfigItem_deny_dcc { 1918 ConfigItem_deny_dcc *prev, *next; 1919 ConfigFlag_ban flag; 1920 char *filename, *reason; 1921 }; 1922 1923 struct ConfigItem_deny_version { 1924 ConfigItem_deny_version *prev, *next; 1925 ConfigFlag flag; 1926 char *mask, *version, *flags; 1927 }; 1928 1929 struct ConfigItem_deny_channel { 1930 ConfigItem_deny_channel *prev, *next; 1931 ConfigFlag flag; 1932 char *channel, *reason, *redirect, *class; 1933 unsigned char warn; 1934 SecurityGroup *match; 1935 }; 1936 1937 struct ConfigItem_allow_channel { 1938 ConfigItem_allow_channel *prev, *next; 1939 ConfigFlag flag; 1940 char *channel, *class; 1941 SecurityGroup *match; 1942 }; 1943 1944 struct ConfigItem_allow_dcc { 1945 ConfigItem_allow_dcc *prev, *next; 1946 ConfigFlag_ban flag; 1947 char *filename; 1948 }; 1949 1950 typedef enum { 1951 ALIAS_SERVICES=1, ALIAS_STATS, ALIAS_NORMAL, ALIAS_COMMAND, ALIAS_CHANNEL, ALIAS_REAL 1952 } AliasType; 1953 1954 struct ConfigItem_alias { 1955 ConfigItem_alias *prev, *next; 1956 ConfigFlag flag; 1957 ConfigItem_alias_format *format; 1958 char *alias, *nick; 1959 AliasType type; 1960 unsigned int spamfilter:1; 1961 }; 1962 1963 struct ConfigItem_alias_format { 1964 ConfigItem_alias_format *prev, *next; 1965 ConfigFlag flag; 1966 char *nick; 1967 AliasType type; 1968 char *format, *parameters; 1969 Match *expr; 1970 }; 1971 1972 #define RESOURCE_REMOTE 0x1 1973 #define RESOURCE_DLQUEUED 0x2 1974 #define RESOURCE_INCLUDE 0x4 1975 1976 typedef struct ConfigEntryWrapper ConfigEntryWrapper; 1977 struct ConfigEntryWrapper { 1978 ConfigEntryWrapper *prev, *next; 1979 ConfigEntry *ce; 1980 }; 1981 1982 struct ConfigResource { 1983 ConfigResource *prev, *next; 1984 int type; 1985 ConfigEntryWrapper *wce; /**< The place(s) where this resource is begin used */ 1986 char *file; /**< File to read: can be a conf/something file or a downloaded file */ 1987 char *url; /**< URL, if it is an URL */ 1988 char *cache_file; /**< Set to filename of local cached copy, if it is available */ 1989 }; 1990 1991 struct ConfigItem_blacklist_module { 1992 ConfigItem_blacklist_module *prev, *next; 1993 char *name; 1994 }; 1995 1996 struct ConfigItem_help { 1997 ConfigItem_help *prev, *next; 1998 ConfigFlag flag; 1999 char *command; 2000 MOTDLine *text; 2001 }; 2002 2003 struct ConfigItem_offchans { 2004 ConfigItem_offchans *prev, *next; 2005 char name[CHANNELLEN+1]; 2006 char *topic; 2007 }; 2008 2009 #define SECURITYGROUPLEN 48 2010 struct SecurityGroup { 2011 SecurityGroup *prev, *next; 2012 int priority; 2013 char name[SECURITYGROUPLEN+1]; 2014 NameValuePrioList *printable_list; 2015 int printable_list_counter; 2016 /* Include */ 2017 int identified; 2018 int reputation_score; 2019 long connect_time; 2020 int webirc; 2021 int websocket; 2022 int tls; 2023 NameList *ip; 2024 ConfigItem_mask *mask; 2025 NameList *security_group; 2026 NameValuePrioList *extended; 2027 /* Exclude */ 2028 int exclude_identified; 2029 int exclude_reputation_score; 2030 long exclude_connect_time; 2031 int exclude_webirc; 2032 int exclude_websocket; 2033 int exclude_tls; 2034 NameList *exclude_ip; 2035 ConfigItem_mask *exclude_mask; 2036 NameList *exclude_security_group; 2037 NameValuePrioList *exclude_extended; 2038 }; 2039 2040 #define HM_HOST 1 2041 #define HM_IPV4 2 2042 #define HM_IPV6 3 2043 2044 #define SETTER_NICK 0 2045 #define SETTER_NICK_USER_HOST 1 2046 2047 /* 2048 * statistics structures 2049 */ 2050 typedef struct IRCStatistics IRCStatistics; 2051 struct IRCStatistics { 2052 unsigned int is_cl; /* number of client connections */ 2053 unsigned int is_sv; /* number of server connections */ 2054 unsigned int is_ni; /* connection but no idea who it was */ 2055 time_t is_cti; /* time spent connected by clients */ 2056 time_t is_sti; /* time spent connected by servers */ 2057 unsigned int is_ac; /* connections accepted */ 2058 unsigned int is_ref; /* accepts refused */ 2059 unsigned int is_unco; /* unknown commands */ 2060 unsigned int is_wrdi; /* command going in wrong direction */ 2061 unsigned int is_unpf; /* unknown prefix */ 2062 unsigned int is_empt; /* empty message */ 2063 unsigned int is_num; /* numeric message */ 2064 unsigned int is_kill; /* number of kills generated on collisions */ 2065 unsigned int is_fake; /* MODE 'fakes' */ 2066 unsigned int is_asuc; /* successful auth requests */ 2067 unsigned int is_abad; /* bad auth requests */ 2068 unsigned int is_udp; /* packets recv'd on udp port */ 2069 unsigned int is_loc; /* local connections made */ 2070 }; 2071 2072 #define EXTCMODETABLESZ 32 2073 2074 /* Number of maximum paramter modes to allow. 2075 * Don't set it unnecessarily high.. we only use k, l, L, j and f at the moment. 2076 */ 2077 #define MAXPARAMMODES 16 2078 2079 /** Channel Mode. 2080 * NOTE: you normally don't access these struct members directly. 2081 * For simple checking if a mode is set, use has_channel_mode() 2082 * Otherwise, see the extended channel modes API, CmodeAdd(), etc. 2083 */ 2084 struct Mode { 2085 Cmode_t mode; /**< Other ("extended") channel modes set on this channel */ 2086 void *mode_params[MAXPARAMMODES+1]; /**< Parameters for extended channel modes */ 2087 }; 2088 2089 /* flags for Link if used to contain Watch --k4be */ 2090 2091 /* WATCH type */ 2092 #define WATCH_FLAG_TYPE_WATCH (1<<0) /* added via /WATCH command */ 2093 #define WATCH_FLAG_TYPE_MONITOR (1<<1) /* added via /MONITOR command */ 2094 2095 /* behaviour switches */ 2096 #define WATCH_FLAG_AWAYNOTIFY (1<<8) /* should send AWAY notifications */ 2097 2098 /* watch triggering events */ 2099 #define WATCH_EVENT_ONLINE 0 2100 #define WATCH_EVENT_OFFLINE 1 2101 #define WATCH_EVENT_AWAY 2 2102 #define WATCH_EVENT_NOTAWAY 3 2103 #define WATCH_EVENT_REAWAY 4 2104 #define WATCH_EVENT_USERHOST 5 2105 #define WATCH_EVENT_REALNAME 6 2106 #define WATCH_EVENT_LOGGEDIN 7 2107 #define WATCH_EVENT_LOGGEDOUT 8 2108 2109 /* Used for notify-hash buckets... -Donwulff */ 2110 2111 struct Watch { 2112 Watch *hnext; 2113 time_t lasttime; 2114 Link *watch; 2115 char nick[1]; 2116 }; 2117 2118 /** General link structure used for certain chains (watch list, invite list, dccallow). 2119 * Note that these always require you to use the make_link() and free_link() functions. 2120 * Do not combine with other alloc/free functions!! 2121 */ 2122 struct Link { 2123 struct Link *next; 2124 int flags; 2125 union { 2126 Client *client; 2127 Channel *channel; 2128 Watch *wptr; 2129 /* there used to be 'char *cp' here too, 2130 * but in such a case you better use NameList 2131 * instead of Link! 2132 */ 2133 } value; 2134 }; 2135 2136 #define IsInvalidChannelTS(x) ((x) <= 1000000) /**< Invalid channel creation time */ 2137 2138 /** 2139 * @addtogroup CommonStructs 2140 * @{ 2141 */ 2142 2143 /** A channel on IRC */ 2144 struct Channel { 2145 struct Channel *nextch; /**< Next channel in linked list (channel) */ 2146 struct Channel *prevch; /**< Previous channel in linked list (channel) */ 2147 struct Channel *hnextch; /**< Next channel in hash table */ 2148 Mode mode; /**< Channel Mode set on this channel */ 2149 time_t creationtime; /**< When the channel was first created */ 2150 char *topic; /**< Channel TOPIC */ 2151 char *topic_nick; /**< Person (or server) who set the TOPIC */ 2152 time_t topic_time; /**< Time at which the topic was last set */ 2153 int users; /**< Number of users in the channel */ 2154 Member *members; /**< List of channel members (users in the channel) */ 2155 Ban *banlist; /**< List of bans (+b) */ 2156 Ban *exlist; /**< List of ban exceptions (+e) */ 2157 Ban *invexlist; /**< List of invite exceptions (+I) */ 2158 char *mode_lock; /**< Mode lock (MLOCK) applied to channel - usually by Services */ 2159 ModData moddata[MODDATA_MAX_CHANNEL]; /**< Channel attached module data, used by the ModData system */ 2160 char name[CHANNELLEN+1]; /**< Channel name */ 2161 }; 2162 2163 /** user/channel member struct (channel->members). 2164 * This is Member which is used in the linked list channel->members for each channel. 2165 * There is also Membership which is used in client->user->channels (see Membership for that). 2166 * Both must be kept synchronized 100% at all times. 2167 */ 2168 struct Member 2169 { 2170 struct Member *next; /**< Next entry in list */ 2171 Client *client; /**< The client */ 2172 char member_modes[MEMBERMODESLEN]; /**< The access of the user on this channel (eg "vhoqa") */ 2173 ModData moddata[MODDATA_MAX_MEMBER]; /** Member attached module data, used by the ModData system */ 2174 }; 2175 2176 /** user/channel membership struct (client->user->channels). 2177 * This is Membership which is used in the linked list client->user->channels for each user. 2178 * There is also Member which is used in channel->members (see Member for that). 2179 * Both must be kept synchronized 100% at all times. 2180 */ 2181 struct Membership 2182 { 2183 struct Membership *next; /**< Next entry in list */ 2184 struct Channel *channel; /**< The channel */ 2185 char member_modes[MEMBERMODESLEN]; /**< The (new) access of the user on this channel (eg "vhoqa") */ 2186 ModData moddata[MODDATA_MAX_MEMBERSHIP]; /**< Membership attached module data, used by the ModData system */ 2187 }; 2188 2189 /** @} */ 2190 2191 /** A ban, exempt or invite exception entry */ 2192 struct Ban { 2193 struct Ban *next; /**< Next entry in list */ 2194 char *banstr; /**< The string (eg: *!*@*.example.org) */ 2195 char *who; /**< Person or server who set the entry (eg: Nick) */ 2196 time_t when; /**< When the entry was added */ 2197 }; 2198 2199 /* Channel macros */ 2200 #define MODE_EXCEPT 0x0200 2201 #define MODE_BAN 0x0400 2202 #define MODE_INVEX 0x8000000 2203 2204 /* name invisible */ 2205 #define SecretChannel(x) ((x) && has_channel_mode((x), 's')) 2206 /* channel not shown but names are */ 2207 #define HiddenChannel(x) ((x) && has_channel_mode((x), 'p')) 2208 /* channel visible */ 2209 #define ShowChannel(v,c) (PubChannel(c) || IsMember((v),(c))) 2210 #define PubChannel(x) (!SecretChannel((x)) && !HiddenChannel((x))) 2211 2212 #define IsChannelName(name) ((name) && (*(name) == '#')) 2213 2214 #define IsMember(blah,chan) ((blah && blah->user && \ 2215 find_membership_link((blah->user)->channel, chan)) ? 1 : 0) 2216 2217 2218 /* Misc macros */ 2219 2220 #define BadPtr(x) (!(x) || (*(x) == '\0')) 2221 2222 /** Is valid character in nick? [not for external usage, use do_check_nickname instead!] */ 2223 #define isvalid(c) (char_atribs[(u_char)(c)]&ALLOWN) 2224 2225 2226 #define TStime() (timeofday) 2227 2228 /* used in SetMode() in channel.c and cmd_umode() in s_msg.c */ 2229 2230 #define MODE_NULL 0 2231 #define MODE_ADD 0x40000000 2232 #define MODE_DEL 0x20000000 2233 2234 /* return values for hunt_server() */ 2235 2236 #define HUNTED_NOSUCH (-1) /* if the hunted server is not found */ 2237 #define HUNTED_ISME 0 /* if this server should execute the command */ 2238 #define HUNTED_PASS 1 /* if message passed onwards successfully */ 2239 2240 /* used when sending to #mask or $mask */ 2241 2242 #define MATCH_SERVER 1 2243 #define MATCH_HOST 2 2244 2245 /* misc variable externs */ 2246 2247 extern MODVAR char *version, *infotext[], *dalinfotext[], *unrealcredits[], *unrealinfo[]; 2248 extern MODVAR char *generation, *creation; 2249 extern MODVAR char *gnulicense[]; 2250 /* misc defines */ 2251 2252 #define COMMA "," 2253 2254 #define isexcept void 2255 2256 extern MODVAR SSL_CTX *ctx; 2257 extern MODVAR SSL_CTX *ctx_server; 2258 extern MODVAR SSL_CTX *ctx_client; 2259 2260 #define TLS_PROTOCOL_TLSV1 0x0001 2261 #define TLS_PROTOCOL_TLSV1_1 0x0002 2262 #define TLS_PROTOCOL_TLSV1_2 0x0004 2263 #define TLS_PROTOCOL_TLSV1_3 0x0008 2264 2265 #define TLS_PROTOCOL_ALL 0xffff 2266 2267 struct ThrottlingBucket 2268 { 2269 struct ThrottlingBucket *prev, *next; 2270 char *ip; 2271 time_t since; 2272 char count; 2273 }; 2274 2275 typedef struct CoreChannelModeTable CoreChannelModeTable; 2276 struct CoreChannelModeTable { 2277 long mode; /**< Mode value (which bit will be set) */ 2278 char flag; /**< Mode letter (eg: 't') */ 2279 unsigned halfop : 1; /**< May halfop set this mode? 1/0 */ 2280 unsigned parameters : 1; /**< Mode requires a parameter? 1/0 */ 2281 }; 2282 2283 /** Parse channel mode */ 2284 typedef struct ParseMode ParseMode; 2285 struct ParseMode { 2286 int what; 2287 char modechar; 2288 char *param; 2289 Cmode *extm; 2290 const char *modebuf; /* curr pos */ 2291 const char *parabuf; /* curr pos */ 2292 char buf[512]; /* internal parse buffer */ 2293 }; 2294 2295 #define MAXMULTILINEMODES 3 2296 typedef struct MultiLineMode MultiLineMode; 2297 struct MultiLineMode { 2298 char *modeline[MAXMULTILINEMODES+1]; 2299 char *paramline[MAXMULTILINEMODES+1]; 2300 int numlines; 2301 }; 2302 2303 typedef struct PendingServer PendingServer; 2304 struct PendingServer { 2305 PendingServer *prev, *next; 2306 char sid[IDLEN+1]; 2307 }; 2308 2309 typedef struct PendingNet PendingNet; 2310 struct PendingNet { 2311 PendingNet *prev, *next; /* Previous and next in list */ 2312 Client *client; /**< Client to which these servers belong */ 2313 PendingServer *servers; /**< The list of servers connected to the client */ 2314 }; 2315 2316 extern void init_throttling(); 2317 extern struct ThrottlingBucket *find_throttling_bucket(Client *); 2318 extern void add_throttling_bucket(Client *); 2319 extern int throttle_can_connect(Client *); 2320 2321 typedef struct MaxTarget MaxTarget; 2322 struct MaxTarget { 2323 MaxTarget *prev, *next; 2324 char *cmd; 2325 int limit; 2326 }; 2327 #define MAXTARGETS_MAX 1000000 /* used for 'max' */ 2328 2329 #define VERIFY_OPERCOUNT(clnt,tag) { if (irccounts.operators < 0) verify_opercount(clnt,tag); } while(0) 2330 2331 #define MARK_AS_OFFICIAL_MODULE(modinf) do { if (modinf && modinf->handle) ModuleSetOptions(modinfo->handle, MOD_OPT_OFFICIAL, 1); } while(0) 2332 #define MARK_AS_GLOBAL_MODULE(modinf) do { if (modinf && modinf->handle) ModuleSetOptions(modinfo->handle, MOD_OPT_GLOBAL, 1); } while(0) 2333 2334 /* used for is_banned type field: */ 2335 #define BANCHK_JOIN 0x0001 /* checking if a ban forbids the person from joining */ 2336 #define BANCHK_MSG 0x0002 /* checking if a ban forbids the person from sending messages */ 2337 #define BANCHK_NICK 0x0004 /* checking if a ban forbids the person from changing his/her nick */ 2338 #define BANCHK_LEAVE_MSG 0x0008 /* checking if a ban forbids the person from leaving a message in PART or QUIT */ 2339 #define BANCHK_TKL 0x0010 /* called from a server ban routine, or other match_user() usage */ 2340 #define BANCHK_ALL (BANCHK_JOIN|BANCHK_MSG|BANCHK_NICK|BANCHK_LEAVE_MSG) /* all events except BANCHK_TKL which is special */ 2341 2342 #define TKLISTLEN 26 2343 #define TKLIPHASHLEN1 4 2344 #define TKLIPHASHLEN2 1021 2345 2346 #define MATCH_CHECK_IP 0x0001 2347 #define MATCH_CHECK_REAL_HOST 0x0002 2348 #define MATCH_CHECK_CLOAKED_HOST 0x0004 2349 #define MATCH_CHECK_VISIBLE_HOST 0x0008 2350 #define MATCH_CHECK_EXTENDED 0x0010 2351 2352 #define MATCH_CHECK_ALL (MATCH_CHECK_IP|MATCH_CHECK_REAL_HOST|MATCH_CHECK_CLOAKED_HOST|MATCH_CHECK_VISIBLE_HOST|MATCH_CHECK_EXTENDED) 2353 #define MATCH_CHECK_REAL (MATCH_CHECK_IP|MATCH_CHECK_REAL_HOST|MATCH_CHECK_EXTENDED) 2354 2355 #define MATCH_MASK_IS_UHOST 0x1000 2356 #define MATCH_MASK_IS_HOST 0x2000 2357 2358 typedef enum { 2359 POLICY_ALLOW=1, 2360 POLICY_WARN=2, 2361 POLICY_DENY=3 2362 } Policy; 2363 2364 #define NO_EXIT_CLIENT 99 2365 2366 /*-- badwords --*/ 2367 2368 #define MAX_MATCH 1 2369 #define MAX_WORDLEN 64 2370 2371 #define PATTERN "\\w*%s\\w*" 2372 #define REPLACEWORD "<censored>" 2373 2374 #define BADW_TYPE_INVALID 0x0 2375 #define BADW_TYPE_FAST 0x1 2376 #define BADW_TYPE_FAST_L 0x2 2377 #define BADW_TYPE_FAST_R 0x4 2378 #define BADW_TYPE_REGEX 0x8 2379 2380 #define BADWORD_REPLACE 1 2381 #define BADWORD_BLOCK 2 2382 2383 typedef struct ConfigItem_badword ConfigItem_badword; 2384 2385 struct ConfigItem_badword { 2386 ConfigItem_badword *prev, *next; 2387 ConfigFlag flag; 2388 char *word, *replace; 2389 unsigned short type; 2390 char action; 2391 pcre2_code *pcre2_expr; 2392 }; 2393 2394 /*-- end of badwords --*/ 2395 2396 /* Flags for 'sendflags' in 'sendto_channel' */ 2397 #define SEND_LOCAL 0x1 2398 #define SEND_REMOTE 0x2 2399 #define SEND_ALL (SEND_LOCAL|SEND_REMOTE) 2400 #define SKIP_DEAF 0x4 2401 #define SKIP_CTCP 0x8 2402 2403 typedef struct GeoIPResult GeoIPResult; 2404 struct GeoIPResult { 2405 char *country_code; 2406 char *country_name; 2407 }; 2408 2409 typedef enum WhoisConfigDetails { 2410 WHOIS_CONFIG_DETAILS_DEFAULT = 0, 2411 WHOIS_CONFIG_DETAILS_NONE = 1, 2412 WHOIS_CONFIG_DETAILS_LIMITED = 2, 2413 WHOIS_CONFIG_DETAILS_FULL = 3, 2414 } WhoisConfigDetails; 2415 2416 /* Options for StripControlCodesEx() */ 2417 #define UNRL_STRIP_LOW_ASCII 0x1 /**< Strip all ASCII < 32 (control codes) */ 2418 #define UNRL_STRIP_KEEP_LF 0x2 /**< Do not strip LF (line feed, \n) */ 2419 2420 /** JSON-RPC API Errors, according to jsonrpc.org spec */ 2421 typedef enum JsonRpcError { 2422 // Official JSON-RPC error codes: 2423 JSON_RPC_ERROR_PARSE_ERROR = -32700, /**< JSON parse error (fatal) */ 2424 JSON_RPC_ERROR_INVALID_REQUEST = -32600, /**< Invalid JSON-RPC Request */ 2425 JSON_RPC_ERROR_METHOD_NOT_FOUND = -32601, /**< Method not found */ 2426 JSON_RPC_ERROR_INVALID_PARAMS = -32602, /**< Method parameters invalid */ 2427 JSON_RPC_ERROR_INTERNAL_ERROR = -32603, /**< Internal server error */ 2428 // UnrealIRCd JSON-RPC server specific error codes: 2429 JSON_RPC_ERROR_API_CALL_DENIED = -32000, /**< The api user does not have enough permissions to do this call */ 2430 JSON_RPC_ERROR_SERVER_GONE = -32001, /**< The request was forwarded to a remote server, but this server went gone while processing the request */ 2431 JSON_RPC_ERROR_TIMEOUT = -32002, /**< The request was forwarded to a remote server, but the request/response timed out (15 seconds) */ 2432 JSON_RPC_ERROR_REMOTE_SERVER_NO_RPC = -32003, /**< The request was going to be forwarded to a remote server, but the remote server does not support JSON-RPC */ 2433 // UnrealIRCd specific application error codes: 2434 JSON_RPC_ERROR_NOT_FOUND = -1000, /**< Target not found (no such nick / channel / ..) */ 2435 JSON_RPC_ERROR_ALREADY_EXISTS = -1001, /**< Resource already exists by that name (eg on nickchange request, a gline, etc) */ 2436 JSON_RPC_ERROR_INVALID_NAME = -1002, /**< Name is not permitted (eg: nick, channel, ..) */ 2437 JSON_RPC_ERROR_USERNOTINCHANNEL = -1003, /**< The user is not in the channel */ 2438 JSON_RPC_ERROR_TOO_MANY_ENTRIES = -1004, /**< Too many entries (eg: banlist, ..) */ 2439 JSON_RPC_ERROR_DENIED = -1005, /**< Permission denied for user (unrelated to api user permissions) */ 2440 } JsonRpcError; 2441 2442 /** Require a parameter in an RPC command */ 2443 #define REQUIRE_PARAM_STRING(name, varname) do { \ 2444 varname = json_object_get_string(params, name); \ 2445 if (!varname) \ 2446 { \ 2447 rpc_error_fmt(client, request, JSON_RPC_ERROR_INVALID_PARAMS, "Missing parameter: '%s'", name); \ 2448 return; \ 2449 } \ 2450 } while(0) 2451 2452 #define REQUIRE_PARAM_INTEGER(name, varname) do { \ 2453 json_t *t = json_object_get(params, name); \ 2454 if (!t || !json_is_integer(t)) \ 2455 { \ 2456 rpc_error_fmt(client, request, JSON_RPC_ERROR_INVALID_PARAMS, "Missing parameter: '%s'", name); \ 2457 return; \ 2458 } \ 2459 varname = json_integer_value(t); \ 2460 } while(0) 2461 2462 #define REQUIRE_PARAM_BOOLEAN(name, varname) do { \ 2463 json_t *vvv = json_object_get(params, name); \ 2464 if (!v || !json_is_boolean(v)) \ 2465 { \ 2466 rpc_error_fmt(client, request, JSON_RPC_ERROR_INVALID_PARAMS, "Missing parameter: '%s'", name); \ 2467 return; \ 2468 } \ 2469 varname = json_is_true(v) ? 1 : 0; \ 2470 } while(0) 2471 2472 #define OPTIONAL_PARAM_STRING(name, varname) varname = json_object_get_string(params, name) 2473 #define OPTIONAL_PARAM_INTEGER(name, varname, def) varname = json_object_get_integer(params, name, def) 2474 #define OPTIONAL_PARAM_BOOLEAN(name, varname, def) varname = json_object_get_boolean(params, name, def) 2475 2476 #endif /* __struct_include__ */ 2477 2478 #include "dynconf.h"