1 /* 2 * IRC - Internet Relay Chat, include/client.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 2, 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 /** @file 21 * @brief Structures and functions for handling local clients. 22 * @version $Id$ 23 */ 24 #ifndef INCLUDED_client_h 25 #define INCLUDED_client_h 26 #ifndef INCLUDED_ircd_defs_h 27 #include "ircd_defs.h" 28 #endif 29 #ifndef INCLUDED_dbuf_h 30 #include "dbuf.h" 31 #endif 32 #ifndef INCLUDED_msgq_h 33 #include "msgq.h" 34 #endif 35 #ifndef INCLUDED_ircd_events_h 36 #include "ircd_events.h" 37 #endif 38 #ifndef INCLUDED_ircd_handler_h 39 #include "ircd_handler.h" 40 #endif 41 #ifndef INCLUDED_res_h 42 #include "res.h" 43 #endif 44 #ifndef INCLUDED_sys_types_h 45 #include <sys/types.h> /* time_t, size_t */ 46 #define INCLUDED_sys_types_h 47 #endif 48 49 struct ConfItem; 50 struct Listener; 51 struct ListingArgs; 52 struct SLink; 53 struct Server; 54 struct User; 55 struct Whowas; 56 struct hostent; 57 struct Privs; 58 struct AuthRequest; 59 60 /* 61 * Structures 62 * 63 * Only put structures here that are being used in a very large number of 64 * source files. Other structures go in the header file of there corresponding 65 * source file, or in the source file itself (when only used in that file). 66 */ 67 68 /** Single element in a flag bitset array. */ 69 typedef unsigned long flagpage_t; 70 71 /** Number of bits in a flagpage_t. */ 72 #define FLAGSET_NBITS (8 * sizeof(flagpage_t)) 73 /** Element number for flag \a flag. */ 74 #define FLAGSET_INDEX(flag) ((flag) / FLAGSET_NBITS) 75 /** Element bit for flag \a flag. */ 76 #define FLAGSET_MASK(flag) (1ul<<((flag) % FLAGSET_NBITS)) 77 78 /** Declare a flagset structure of a particular size. */ 79 #define DECLARE_FLAGSET(name,max) \ 80 struct name \ 81 { \ 82 unsigned long bits[((max + FLAGSET_NBITS - 1) / FLAGSET_NBITS)]; \ 83 } 84 85 /** Test whether a flag is set in a flagset. */ 86 #define FlagHas(set,flag) ((set)->bits[FLAGSET_INDEX(flag)] & FLAGSET_MASK(flag)) 87 /** Set a flag in a flagset. */ 88 #define FlagSet(set,flag) ((set)->bits[FLAGSET_INDEX(flag)] |= FLAGSET_MASK(flag)) 89 /** Clear a flag in a flagset. */ 90 #define FlagClr(set,flag) ((set)->bits[FLAGSET_INDEX(flag)] &= ~FLAGSET_MASK(flag)) 91 92 /** String containing valid user modes, in no particular order. */ 93 #define infousermodes "diOoswkgx" 94 95 /** Operator privileges. */ 96 enum Priv 97 { 98 PRIV_CHAN_LIMIT, /**< no channel limit on oper */ 99 PRIV_MODE_LCHAN, /**< oper can mode local chans */ 100 PRIV_WALK_LCHAN, /**< oper can walk through local modes */ 101 PRIV_DEOP_LCHAN, /**< no deop oper on local chans */ 102 PRIV_SHOW_INVIS, /**< show local invisible users */ 103 PRIV_SHOW_ALL_INVIS, /**< show all invisible users */ 104 PRIV_UNLIMIT_QUERY, /**< unlimit who queries */ 105 PRIV_KILL, /**< oper can KILL */ 106 PRIV_LOCAL_KILL, /**< oper can local KILL */ 107 PRIV_REHASH, /**< oper can REHASH */ 108 PRIV_RESTART, /**< oper can RESTART */ 109 PRIV_DIE, /**< oper can DIE */ 110 PRIV_GLINE, /**< oper can GLINE */ 111 PRIV_LOCAL_GLINE, /**< oper can local GLINE */ 112 PRIV_JUPE, /**< oper can JUPE */ 113 PRIV_LOCAL_JUPE, /**< oper can local JUPE */ 114 PRIV_OPMODE, /**< oper can OP/CLEARMODE */ 115 PRIV_LOCAL_OPMODE, /**< oper can local OP/CLEARMODE */ 116 PRIV_SET, /**< oper can SET */ 117 PRIV_WHOX, /**< oper can use /who x */ 118 PRIV_BADCHAN, /**< oper can BADCHAN */ 119 PRIV_LOCAL_BADCHAN, /**< oper can local BADCHAN */ 120 PRIV_SEE_CHAN, /**< oper can see in secret chans */ 121 PRIV_PROPAGATE, /**< propagate oper status */ 122 PRIV_DISPLAY, /**< "Is an oper" displayed */ 123 PRIV_SEE_OPERS, /**< display hidden opers */ 124 PRIV_WIDE_GLINE, /**< oper can set wider G-lines */ 125 PRIV_LIST_CHAN, /**< oper can list secret channels */ 126 PRIV_FORCE_OPMODE, /**< can hack modes on quarantined channels */ 127 PRIV_FORCE_LOCAL_OPMODE, /**< can hack modes on quarantined local channels */ 128 PRIV_APASS_OPMODE, /**< can hack modes +A/-A/+U/-U */ 129 PRIV_LAST_PRIV /**< number of privileges */ 130 }; 131 132 /** Client flags and modes. 133 * Note that flags at least FLAG_LOCAL_UMODES but less than 134 * FLAG_GLOBAL_UMODES are treated as local modes, and flags at least 135 * FLAG_GLOBAL_UMODES (but less than FLAG_LAST_FLAG) are treated as 136 * global modes. 137 */ 138 enum Flag 139 { 140 FLAG_PINGSENT, /**< Unreplied ping sent */ 141 FLAG_DEADSOCKET, /**< Local socket is dead--Exiting soon */ 142 FLAG_KILLED, /**< Prevents "QUIT" from being sent for this */ 143 FLAG_BLOCKED, /**< socket is in a blocked condition */ 144 FLAG_CLOSING, /**< set when closing to suppress errors */ 145 FLAG_UPING, /**< has active UDP ping request */ 146 FLAG_HUB, /**< server is a hub */ 147 FLAG_IPV6, /**< server understands P10 IPv6 addrs */ 148 FLAG_SERVICE, /**< server is a service */ 149 FLAG_GOTID, /**< successful ident lookup achieved */ 150 FLAG_NONL, /**< No \n in buffer */ 151 FLAG_TS8, /**< Why do you want to know? */ 152 FLAG_MAP, /**< Show server on the map */ 153 FLAG_JUNCTION, /**< Junction causing the net.burst. */ 154 FLAG_BURST, /**< Server is receiving a net.burst */ 155 FLAG_BURST_ACK, /**< Server is waiting for eob ack */ 156 FLAG_IPCHECK, /**< Added or updated IPregistry data */ 157 FLAG_LOCOP, /**< Local operator -- SRB */ 158 FLAG_SERVNOTICE, /**< server notices such as kill */ 159 FLAG_OPER, /**< Operator */ 160 FLAG_INVISIBLE, /**< makes user invisible */ 161 FLAG_WALLOP, /**< send wallops to them */ 162 FLAG_DEAF, /**< Makes user deaf */ 163 FLAG_CHSERV, /**< Disallow KICK or MODE -o on the user; 164 don't display channels in /whois */ 165 FLAG_DEBUG, /**< send global debug/anti-hack info */ 166 FLAG_ACCOUNT, /**< account name has been set */ 167 FLAG_HIDDENHOST, /**< user's host is hidden */ 168 FLAG_LAST_FLAG, /**< number of flags */ 169 FLAG_LOCAL_UMODES = FLAG_LOCOP, /**< First local mode flag */ 170 FLAG_GLOBAL_UMODES = FLAG_OPER /**< First global mode flag */ 171 }; 172 173 /** Declare flagset type for operator privileges. */ 174 DECLARE_FLAGSET(Privs, PRIV_LAST_PRIV); 175 /** Declare flagset type for user flags. */ 176 DECLARE_FLAGSET(Flags, FLAG_LAST_FLAG); 177 178 #include "capab.h" /* client capabilities */ 179 180 /** Represents a local connection. 181 * This contains a lot of stuff irrelevant to server connections, but 182 * those are so rare as to not be worth special-casing. 183 */ 184 struct Connection 185 { 186 unsigned long con_magic; /**< magic number */ 187 struct Connection* con_next; /**< Next connection with queued data */ 188 struct Connection** con_prev_p; /**< What points to us */ 189 struct Client* con_client; /**< Client associated with connection */ 190 unsigned int con_count; /**< Amount of data in buffer */ 191 int con_freeflag; /**< indicates if connection can be freed */ 192 int con_error; /**< last socket level error for client */ 193 int con_sentalong; /**< sentalong marker for connection */ 194 unsigned int con_snomask; /**< mask for server messages */ 195 time_t con_nextnick; /**< Next time a nick change is allowed */ 196 time_t con_nexttarget;/**< Next time a target change is allowed */ 197 time_t con_lasttime; /**< Last time data read from socket */ 198 time_t con_since; /**< Last time we accepted a command */ 199 struct MsgQ con_sendQ; /**< Outgoing message queue */ 200 struct DBuf con_recvQ; /**< Incoming data yet to be parsed */ 201 unsigned int con_sendM; /**< Stats: protocol messages sent */ 202 unsigned int con_receiveM; /**< Stats: protocol messages received */ 203 uint64_t con_sendB; /**< Bytes sent. */ 204 uint64_t con_receiveB; /**< Bytes received. */ 205 struct Listener* con_listener; /**< Listening socket which we accepted 206 from. */ 207 struct SLink* con_confs; /**< Associated configuration records. */ 208 HandlerType con_handler; /**< Message index into command table 209 for parsing. */ 210 struct ListingArgs* con_listing; /**< Current LIST status. */ 211 unsigned int con_max_sendq; /**< cached max send queue for client */ 212 unsigned int con_ping_freq; /**< cached ping freq */ 213 unsigned short con_lastsq; /**< # 2k blocks when sendqueued 214 called last. */ 215 unsigned char con_targets[MAXTARGETS]; /**< Hash values of 216 current targets. */ 217 char con_sock_ip[SOCKIPLEN + 1]; /**< Remote IP address as a string. */ 218 char con_sockhost[HOSTLEN + 1]; /**< This is the host name from 219 the socket and after which the 220 connection was accepted. */ 221 char con_passwd[PASSWDLEN + 1]; /**< Password given by user. */ 222 char con_buffer[BUFSIZE]; /**< Incoming message buffer; or 223 the error that caused this 224 clients socket to close. */ 225 struct Socket con_socket; /**< socket descriptor for 226 client */ 227 struct Timer con_proc; /**< process latent messages from 228 client */ 229 struct Privs con_privs; /**< Oper privileges */ 230 struct CapSet con_capab; /**< Client capabilities (from us) */ 231 struct CapSet con_active; /**< Active capabilities (to us) */ 232 struct AuthRequest* con_auth; /**< Auth request for client */ 233 const struct wline* con_wline; /**< WebIRC authorization for client */ 234 }; 235 236 /** Magic constant to identify valid Connection structures. */ 237 #define CONNECTION_MAGIC 0x12f955f3 238 239 /** Represents a client anywhere on the network. */ 240 struct Client { 241 unsigned long cli_magic; /**< magic number */ 242 struct Client* cli_next; /**< link in GlobalClientList */ 243 struct Client* cli_prev; /**< link in GlobalClientList */ 244 struct Client* cli_hnext; /**< link in hash table bucket or this */ 245 struct Connection* cli_connect; /**< Connection structure associated with us */ 246 struct User* cli_user; /**< Defined if this client is a user */ 247 struct Server* cli_serv; /**< Defined if this client is a server */ 248 struct Whowas* cli_whowas; /**< Pointer to ww struct to be freed on quit */ 249 char cli_yxx[4]; /**< Numeric Nick: YY if this is a 250 server, XXX if this is a user */ 251 time_t cli_firsttime; /**< time client was created */ 252 time_t cli_lastnick; /**< TimeStamp on nick */ 253 int cli_marker; /**< /who processing marker */ 254 struct Flags cli_flags; /**< client flags */ 255 unsigned int cli_hopcount; /**< number of servers to this 0 = local */ 256 struct irc_in_addr cli_ip; /**< Real IP of client */ 257 short cli_status; /**< Client type */ 258 char cli_name[HOSTLEN + 1]; /**< Unique name of the client, nick or host */ 259 char cli_username[USERLEN + 1]; /**< Username determined by ident lookup */ 260 char cli_info[REALLEN + 1]; /**< Free form additional client information */ 261 }; 262 263 /** Magic constant to identify valid Client structures. */ 264 #define CLIENT_MAGIC 0x4ca08286 265 266 /** Verify that a client is valid. */ 267 #define cli_verify(cli) ((cli)->cli_magic == CLIENT_MAGIC) 268 /** Get client's magic number. */ 269 #define cli_magic(cli) ((cli)->cli_magic) 270 /** Get global next client. */ 271 #define cli_next(cli) ((cli)->cli_next) 272 /** Get global previous client. */ 273 #define cli_prev(cli) ((cli)->cli_prev) 274 /** Get next client in hash bucket chain. */ 275 #define cli_hnext(cli) ((cli)->cli_hnext) 276 /** Get connection associated with client. */ 277 #define cli_connect(cli) ((cli)->cli_connect) 278 /** Get local client that links us to \a cli. */ 279 #define cli_from(cli) con_client(cli_connect(cli)) 280 /** Get User structure for client, if client is a user. */ 281 #define cli_user(cli) ((cli)->cli_user) 282 /** Get Server structure for client, if client is a server. */ 283 #define cli_serv(cli) ((cli)->cli_serv) 284 /** Get Whowas link for client. */ 285 #define cli_whowas(cli) ((cli)->cli_whowas) 286 /** Get client numnick. */ 287 #define cli_yxx(cli) ((cli)->cli_yxx) 288 /** Get time we last read data from the client socket. */ 289 #define cli_lasttime(cli) con_lasttime(cli_connect(cli)) 290 /** Get time we last parsed something from the client. */ 291 #define cli_since(cli) con_since(cli_connect(cli)) 292 /** Get time client was created. */ 293 #define cli_firsttime(cli) ((cli)->cli_firsttime) 294 /** Get time client last changed nickname. */ 295 #define cli_lastnick(cli) ((cli)->cli_lastnick) 296 /** Get WHO marker for client. */ 297 #define cli_marker(cli) ((cli)->cli_marker) 298 /** Get flags flagset for client. */ 299 #define cli_flags(cli) ((cli)->cli_flags) 300 /** Get hop count to client. */ 301 #define cli_hopcount(cli) ((cli)->cli_hopcount) 302 /** Get client IP address. */ 303 #define cli_ip(cli) ((cli)->cli_ip) 304 /** Get status bitmask for client. */ 305 #define cli_status(cli) ((cli)->cli_status) 306 /** Return non-zero if the client is local. */ 307 #define cli_local(cli) (cli_from(cli) == cli) 308 /** Get oper privileges for client. */ 309 #define cli_privs(cli) con_privs(cli_connect(cli)) 310 /** Get client capabilities for client */ 311 #define cli_capab(cli) con_capab(cli_connect(cli)) 312 /** Get active client capabilities for client */ 313 #define cli_active(cli) con_active(cli_connect(cli)) 314 /** Get client name. */ 315 #define cli_name(cli) ((cli)->cli_name) 316 /** Get client username (ident). */ 317 #define cli_username(cli) ((cli)->cli_username) 318 /** Get client realname (information field). */ 319 #define cli_info(cli) ((cli)->cli_info) 320 /** Get client account string. */ 321 #define cli_account(cli) (cli_user(cli) ? cli_user(cli)->account : "0") 322 323 /** Get number of incoming bytes queued for client. */ 324 #define cli_count(cli) con_count(cli_connect(cli)) 325 /** Get file descriptor for sending in client's direction. */ 326 #define cli_fd(cli) con_fd(cli_connect(cli)) 327 /** Get free flags for the client's connection. */ 328 #define cli_freeflag(cli) con_freeflag(cli_connect(cli)) 329 /** Get last error code for the client's connection. */ 330 #define cli_error(cli) con_error(cli_connect(cli)) 331 /** Get server notice mask for the client. */ 332 #define cli_snomask(cli) con_snomask(cli_connect(cli)) 333 /** Get next time a nick change is allowed for the client. */ 334 #define cli_nextnick(cli) con_nextnick(cli_connect(cli)) 335 /** Get next time a target change is allowed for the client. */ 336 #define cli_nexttarget(cli) con_nexttarget(cli_connect(cli)) 337 /** Get SendQ for client. */ 338 #define cli_sendQ(cli) con_sendQ(cli_connect(cli)) 339 /** Get RecvQ for client. */ 340 #define cli_recvQ(cli) con_recvQ(cli_connect(cli)) 341 /** Get count of messages sent to client. */ 342 #define cli_sendM(cli) con_sendM(cli_connect(cli)) 343 /** Get number of messages received from client. */ 344 #define cli_receiveM(cli) con_receiveM(cli_connect(cli)) 345 /** Get number of bytes (modulo 1024) sent to client. */ 346 #define cli_sendB(cli) con_sendB(cli_connect(cli)) 347 /** Get number of bytes (modulo 1024) received from client. */ 348 #define cli_receiveB(cli) con_receiveB(cli_connect(cli)) 349 /** Get listener that accepted the client's connection. */ 350 #define cli_listener(cli) con_listener(cli_connect(cli)) 351 /** Get list of attached conf lines. */ 352 #define cli_confs(cli) con_confs(cli_connect(cli)) 353 /** Get handler type for client. */ 354 #define cli_handler(cli) con_handler(cli_connect(cli)) 355 /** Get LIST status for client. */ 356 #define cli_listing(cli) con_listing(cli_connect(cli)) 357 /** Get cached max SendQ for client. */ 358 #define cli_max_sendq(cli) con_max_sendq(cli_connect(cli)) 359 /** Get ping frequency for client. */ 360 #define cli_ping_freq(cli) con_ping_freq(cli_connect(cli)) 361 /** Get lastsq for client's connection. */ 362 #define cli_lastsq(cli) con_lastsq(cli_connect(cli)) 363 /** Get the array of current targets for the client. */ 364 #define cli_targets(cli) con_targets(cli_connect(cli)) 365 /** Get the string form of the client's IP address. */ 366 #define cli_sock_ip(cli) con_sock_ip(cli_connect(cli)) 367 /** Get the resolved hostname for the client. */ 368 #define cli_sockhost(cli) con_sockhost(cli_connect(cli)) 369 /** Get the client's password. */ 370 #define cli_passwd(cli) con_passwd(cli_connect(cli)) 371 /** Get the unprocessed input buffer for a client's connection. */ 372 #define cli_buffer(cli) con_buffer(cli_connect(cli)) 373 /** Get the Socket structure for sending to a client. */ 374 #define cli_socket(cli) con_socket(cli_connect(cli)) 375 /** Get Timer for processing waiting messages from the client. */ 376 #define cli_proc(cli) con_proc(cli_connect(cli)) 377 /** Get auth request for client. */ 378 #define cli_auth(cli) con_auth(cli_connect(cli)) 379 /** Get WebIRC authorization for client. */ 380 #define cli_wline(cli) con_wline(cli_connect(cli)) 381 /** Get sentalong marker for client. */ 382 #define cli_sentalong(cli) con_sentalong(cli_connect(cli)) 383 384 /** Verify that a connection is valid. */ 385 #define con_verify(con) ((con)->con_magic == CONNECTION_MAGIC) 386 /** Get connection's magic number. */ 387 #define con_magic(con) ((con)->con_magic) 388 /** Get global next connection. */ 389 #define con_next(con) ((con)->con_next) 390 /** Get global previous connection. */ 391 #define con_prev_p(con) ((con)->con_prev_p) 392 /** Get locally connected client for connection. */ 393 #define con_client(con) ((con)->con_client) 394 /** Get number of unprocessed data bytes from connection. */ 395 #define con_count(con) ((con)->con_count) 396 /** Get file descriptor for connection. */ 397 #define con_fd(con) s_fd(&(con)->con_socket) 398 /** Get freeable flags for connection. */ 399 #define con_freeflag(con) ((con)->con_freeflag) 400 /** Get last error code on connection. */ 401 #define con_error(con) ((con)->con_error) 402 /** Get sentalong marker for connection. */ 403 #define con_sentalong(con) ((con)->con_sentalong) 404 /** Get server notice mask for connection. */ 405 #define con_snomask(con) ((con)->con_snomask) 406 /** Get next nick change time for connection. */ 407 #define con_nextnick(con) ((con)->con_nextnick) 408 /** Get next new target time for connection. */ 409 #define con_nexttarget(con) ((con)->con_nexttarget) 410 /** Get last time we read from the connection. */ 411 #define con_lasttime(con) ((con)->con_lasttime) 412 /** Get last time we accepted a command from the connection. */ 413 #define con_since(con) ((con)->con_since) 414 /** Get SendQ for connection. */ 415 #define con_sendQ(con) ((con)->con_sendQ) 416 /** Get RecvQ for connection. */ 417 #define con_recvQ(con) ((con)->con_recvQ) 418 /** Get number of messages sent to connection. */ 419 #define con_sendM(con) ((con)->con_sendM) 420 /** Get number of messages received from connection. */ 421 #define con_receiveM(con) ((con)->con_receiveM) 422 /** Get number of bytes (modulo 1024) sent to connection. */ 423 #define con_sendB(con) ((con)->con_sendB) 424 /** Get number of bytes (modulo 1024) received from connection. */ 425 #define con_receiveB(con) ((con)->con_receiveB) 426 /** Get listener that accepted the connection. */ 427 #define con_listener(con) ((con)->con_listener) 428 /** Get list of ConfItems attached to the connection. */ 429 #define con_confs(con) ((con)->con_confs) 430 /** Get command handler for the connection. */ 431 #define con_handler(con) ((con)->con_handler) 432 /** Get the LIST status for the connection. */ 433 #define con_listing(con) ((con)->con_listing) 434 /** Get the maximum permitted SendQ size for the connection. */ 435 #define con_max_sendq(con) ((con)->con_max_sendq) 436 /** Get the ping frequency for the connection. */ 437 #define con_ping_freq(con) ((con)->con_ping_freq) 438 /** Get the lastsq for the connection. */ 439 #define con_lastsq(con) ((con)->con_lastsq) 440 /** Get the current targets array for the connection. */ 441 #define con_targets(con) ((con)->con_targets) 442 /** Get the string-formatted IP address for the connection. */ 443 #define con_sock_ip(con) ((con)->con_sock_ip) 444 /** Get the resolved hostname for the connection. */ 445 #define con_sockhost(con) ((con)->con_sockhost) 446 /** Get the password sent by the remote end of the connection. */ 447 #define con_passwd(con) ((con)->con_passwd) 448 /** Get the buffer of unprocessed incoming data from the connection. */ 449 #define con_buffer(con) ((con)->con_buffer) 450 /** Get the Socket for the connection. */ 451 #define con_socket(con) ((con)->con_socket) 452 /** Get the Timer for processing more data from the connection. */ 453 #define con_proc(con) ((con)->con_proc) 454 /** Get the oper privilege set for the connection. */ 455 #define con_privs(con) (&(con)->con_privs) 456 /** Get the peer's capabilities for the connection. */ 457 #define con_capab(con) (&(con)->con_capab) 458 /** Get the active capabilities for the connection. */ 459 #define con_active(con) (&(con)->con_active) 460 /** Get the auth request for the connection. */ 461 #define con_auth(con) ((con)->con_auth) 462 /** Get the WebIRC block (if any) used by the connection. */ 463 #define con_wline(con) ((con)->con_wline) 464 465 #define STAT_CONNECTING 0x001 /**< connecting to another server */ 466 #define STAT_HANDSHAKE 0x002 /**< pass - server sent */ 467 #define STAT_ME 0x004 /**< this server */ 468 #define STAT_UNKNOWN 0x008 /**< unidentified connection */ 469 #define STAT_UNKNOWN_USER 0x010 /**< connection on a client port */ 470 #define STAT_UNKNOWN_SERVER 0x020 /**< connection on a server port */ 471 #define STAT_SERVER 0x040 /**< fully registered server */ 472 #define STAT_USER 0x080 /**< fully registered user */ 473 #define STAT_WEBIRC 0x100 /**< connection on a webirc port */ 474 475 /* 476 * status macros. 477 */ 478 /** Return non-zero if the client is registered. */ 479 #define IsRegistered(x) (cli_status(x) & (STAT_SERVER | STAT_USER)) 480 /** Return non-zero if the client is an outbound connection that is 481 * still connecting. */ 482 #define IsConnecting(x) (cli_status(x) == STAT_CONNECTING) 483 /** Return non-zero if the client is an outbound connection that has 484 * sent our password. */ 485 #define IsHandshake(x) (cli_status(x) == STAT_HANDSHAKE) 486 /** Return non-zero if the client is this server. */ 487 #define IsMe(x) (cli_status(x) == STAT_ME) 488 /** Return non-zero if the client has not yet registered. */ 489 #define IsUnknown(x) (cli_status(x) & \ 490 (STAT_UNKNOWN | STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER | STAT_WEBIRC)) 491 /** Return non-zero if the client is an unregistered connection on a 492 * server port. */ 493 #define IsServerPort(x) (cli_status(x) == STAT_UNKNOWN_SERVER ) 494 /** Return non-zero if the client is an unregistered connection on a 495 * user port. */ 496 #define IsUserPort(x) (cli_status(x) == STAT_UNKNOWN_USER ) 497 /** Return non-zero if the client is an unregistered connection on a 498 * WebIRC port that has not yet sent WEBIRC. */ 499 #define IsWebircPort(x) (cli_status(x) == STAT_WEBIRC) 500 /** Return non-zero if the client is a real client connection. */ 501 #define IsClient(x) (cli_status(x) & \ 502 (STAT_HANDSHAKE | STAT_ME | STAT_UNKNOWN |\ 503 STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER | STAT_SERVER | STAT_USER)) 504 /** Return non-zero if the client ignores flood limits. */ 505 #define IsTrusted(x) (cli_status(x) & \ 506 (STAT_CONNECTING | STAT_HANDSHAKE | STAT_ME | STAT_SERVER)) 507 /** Return non-zero if the client is a registered server. */ 508 #define IsServer(x) (cli_status(x) == STAT_SERVER) 509 /** Return non-zero if the client is a registered user. */ 510 #define IsUser(x) (cli_status(x) == STAT_USER) 511 512 513 /** Mark a client with STAT_CONNECTING. */ 514 #define SetConnecting(x) (cli_status(x) = STAT_CONNECTING) 515 /** Mark a client with STAT_HANDSHAKE. */ 516 #define SetHandshake(x) (cli_status(x) = STAT_HANDSHAKE) 517 /** Mark a client with STAT_SERVER. */ 518 #define SetServer(x) (cli_status(x) = STAT_SERVER) 519 /** Mark a client with STAT_ME. */ 520 #define SetMe(x) (cli_status(x) = STAT_ME) 521 /** Mark a client with STAT_USER. */ 522 #define SetUser(x) (cli_status(x) = STAT_USER) 523 524 /** Return non-zero if a client is directly connected to me. */ 525 #define MyConnect(x) (cli_from(x) == (x)) 526 /** Return non-zero if a client is a locally connected user. */ 527 #define MyUser(x) (MyConnect(x) && IsUser(x)) 528 /** Return non-zero if a client is a locally connected IRC operator. */ 529 #define MyOper(x) (MyConnect(x) && IsOper(x)) 530 /** Return protocol version used by a server. */ 531 #define Protocol(x) ((cli_serv(x))->prot) 532 533 /* 534 * flags macros 535 */ 536 /** Set a flag in a client's flags. */ 537 #define SetFlag(cli, flag) FlagSet(&cli_flags(cli), flag) 538 /** Clear a flag from a client's flags. */ 539 #define ClrFlag(cli, flag) FlagClr(&cli_flags(cli), flag) 540 /** Return non-zero if a flag is set in a client's flags. */ 541 #define HasFlag(cli, flag) FlagHas(&cli_flags(cli), flag) 542 543 /** Return non-zero if the client is an IRC operator (global or local). */ 544 #define IsAnOper(x) (IsOper(x) || IsLocOp(x)) 545 /** Return non-zero if the client's connection is blocked. */ 546 #define IsBlocked(x) HasFlag(x, FLAG_BLOCKED) 547 /** Return non-zero if the client's connection is still being burst. */ 548 #define IsBurst(x) HasFlag(x, FLAG_BURST) 549 /** Return non-zero if we have received the peer's entire burst but 550 * not their EOB ack. */ 551 #define IsBurstAck(x) HasFlag(x, FLAG_BURST_ACK) 552 /** Return non-zero if we are still bursting to the client. */ 553 #define IsBurstOrBurstAck(x) (HasFlag(x, FLAG_BURST) || HasFlag(x, FLAG_BURST_ACK)) 554 /** Return non-zero if the client has set mode +k (channel service). */ 555 #define IsChannelService(x) HasFlag(x, FLAG_CHSERV) 556 /** Return non-zero if the client's socket is disconnected. */ 557 #define IsDead(x) HasFlag(x, FLAG_DEADSOCKET) 558 /** Return non-zero if the client has set mode +d (deaf). */ 559 #define IsDeaf(x) HasFlag(x, FLAG_DEAF) 560 /** Return non-zero if the client has been IP-checked for clones. */ 561 #define IsIPChecked(x) HasFlag(x, FLAG_IPCHECK) 562 /** Return non-zero if we have received an ident response for the client. */ 563 #define IsGotId(x) HasFlag(x, FLAG_GOTID) 564 /** Return non-zero if the client has set mode +i (invisible). */ 565 #define IsInvisible(x) HasFlag(x, FLAG_INVISIBLE) 566 /** Return non-zero if the client caused a net.burst. */ 567 #define IsJunction(x) HasFlag(x, FLAG_JUNCTION) 568 /** Return non-zero if the client has set mode +O (local operator) locally. */ 569 #define IsLocOp(x) (MyConnect(x) && HasFlag(x, FLAG_LOCOP)) 570 /** Return non-zero if the client has set mode +o (global operator). */ 571 #define IsOper(x) HasFlag(x, FLAG_OPER) 572 /** Return non-zero if the client has an active UDP ping request. */ 573 #define IsUPing(x) HasFlag(x, FLAG_UPING) 574 /** Return non-zero if the client has no '\n' in its buffer. */ 575 #define NoNewLine(x) HasFlag(x, FLAG_NONL) 576 /** Return non-zero if the client has set mode +g (debugging). */ 577 #define SendDebug(x) HasFlag(x, FLAG_DEBUG) 578 /** Return non-zero if the client has set mode +s (server notices). */ 579 #define SendServNotice(x) HasFlag(x, FLAG_SERVNOTICE) 580 /** Return non-zero if the client has set mode +w (wallops). */ 581 #define SendWallops(x) HasFlag(x, FLAG_WALLOP) 582 /** Return non-zero if the client claims to be a hub. */ 583 #define IsHub(x) HasFlag(x, FLAG_HUB) 584 /** Return non-zero if the client understands IPv6 addresses in P10. */ 585 #define IsIPv6(x) HasFlag(x, FLAG_IPV6) 586 /** Return non-zero if the client claims to be a services server. */ 587 #define IsService(x) HasFlag(x, FLAG_SERVICE) 588 /** Return non-zero if the client has an account stamp. */ 589 #define IsAccount(x) HasFlag(x, FLAG_ACCOUNT) 590 /** Return non-zero if the client has set mode +x (hidden host). */ 591 #define IsHiddenHost(x) HasFlag(x, FLAG_HIDDENHOST) 592 /** Return non-zero if the client has an active PING request. */ 593 #define IsPingSent(x) HasFlag(x, FLAG_PINGSENT) 594 595 /** Return non-zero if the client has operator or server privileges. */ 596 #define IsPrivileged(x) (IsAnOper(x) || IsServer(x)) 597 /** Return non-zero if the client's host is hidden. */ 598 #define HasHiddenHost(x) (IsHiddenHost(x) && IsAccount(x)) 599 600 /** Mark a client as having an in-progress net.burst. */ 601 #define SetBurst(x) SetFlag(x, FLAG_BURST) 602 /** Mark a client as being between EOB and EOB ACK. */ 603 #define SetBurstAck(x) SetFlag(x, FLAG_BURST_ACK) 604 /** Mark a client as having mode +k (channel service). */ 605 #define SetChannelService(x) SetFlag(x, FLAG_CHSERV) 606 /** Mark a client as having mode +d (deaf). */ 607 #define SetDeaf(x) SetFlag(x, FLAG_DEAF) 608 /** Mark a client as having mode +g (debugging). */ 609 #define SetDebug(x) SetFlag(x, FLAG_DEBUG) 610 /** Mark a client as having ident looked up. */ 611 #define SetGotId(x) SetFlag(x, FLAG_GOTID) 612 /** Mark a client as being IP-checked. */ 613 #define SetIPChecked(x) SetFlag(x, FLAG_IPCHECK) 614 /** Mark a client as having mode +i (invisible). */ 615 #define SetInvisible(x) SetFlag(x, FLAG_INVISIBLE) 616 /** Mark a client as causing a net.join. */ 617 #define SetJunction(x) SetFlag(x, FLAG_JUNCTION) 618 /** Mark a client as having mode +O (local operator). */ 619 #define SetLocOp(x) SetFlag(x, FLAG_LOCOP) 620 /** Mark a client as having mode +o (global operator). */ 621 #define SetOper(x) SetFlag(x, FLAG_OPER) 622 /** Mark a client as having a pending UDP ping. */ 623 #define SetUPing(x) SetFlag(x, FLAG_UPING) 624 /** Mark a client as having mode +w (wallops). */ 625 #define SetWallops(x) SetFlag(x, FLAG_WALLOP) 626 /** Mark a client as having mode +s (server notices). */ 627 #define SetServNotice(x) SetFlag(x, FLAG_SERVNOTICE) 628 /** Mark a client as being a hub server. */ 629 #define SetHub(x) SetFlag(x, FLAG_HUB) 630 /** Mark a client as being an IPv6-grokking server. */ 631 #define SetIPv6(x) SetFlag(x, FLAG_IPV6) 632 /** Mark a client as being a services server. */ 633 #define SetService(x) SetFlag(x, FLAG_SERVICE) 634 /** Mark a client as having an account stamp. */ 635 #define SetAccount(x) SetFlag(x, FLAG_ACCOUNT) 636 /** Mark a client as having mode +x (hidden host). */ 637 #define SetHiddenHost(x) SetFlag(x, FLAG_HIDDENHOST) 638 /** Mark a client as having a pending PING. */ 639 #define SetPingSent(x) SetFlag(x, FLAG_PINGSENT) 640 641 /** Return non-zero if \a sptr sees \a acptr as an operator. */ 642 #define SeeOper(sptr,acptr) (IsAnOper(acptr) && (HasPriv(acptr, PRIV_DISPLAY) \ 643 || HasPriv(sptr, PRIV_SEE_OPERS))) 644 645 /** Clear the client's net.burst in-progress flag. */ 646 #define ClearBurst(x) ClrFlag(x, FLAG_BURST) 647 /** Clear the client's between EOB and EOB ACK flag. */ 648 #define ClearBurstAck(x) ClrFlag(x, FLAG_BURST_ACK) 649 /** Remove mode +k (channel service) from the client. */ 650 #define ClearChannelService(x) ClrFlag(x, FLAG_CHSERV) 651 /** Remove mode +d (deaf) from the client. */ 652 #define ClearDeaf(x) ClrFlag(x, FLAG_DEAF) 653 /** Remove mode +g (debugging) from the client. */ 654 #define ClearDebug(x) ClrFlag(x, FLAG_DEBUG) 655 /** Remove the client's IP-checked flag. */ 656 #define ClearIPChecked(x) ClrFlag(x, FLAG_IPCHECK) 657 /** Remove mode +i (invisible) from the client. */ 658 #define ClearInvisible(x) ClrFlag(x, FLAG_INVISIBLE) 659 /** Remove mode +O (local operator) from the client. */ 660 #define ClearLocOp(x) ClrFlag(x, FLAG_LOCOP) 661 /** Remove mode +o (global operator) from the client. */ 662 #define ClearOper(x) ClrFlag(x, FLAG_OPER) 663 /** Clear the client's pending UDP ping flag. */ 664 #define ClearUPing(x) ClrFlag(x, FLAG_UPING) 665 /** Remove mode +w (wallops) from the client. */ 666 #define ClearWallops(x) ClrFlag(x, FLAG_WALLOP) 667 /** Remove mode +s (server notices) from the client. */ 668 #define ClearServNotice(x) ClrFlag(x, FLAG_SERVNOTICE) 669 /** Remove mode +x (hidden host) from the client. */ 670 #define ClearHiddenHost(x) ClrFlag(x, FLAG_HIDDENHOST) 671 /** Clear the client's pending PING flag. */ 672 #define ClearPingSent(x) ClrFlag(x, FLAG_PINGSENT) 673 /** Clear the client's HUB flag. */ 674 #define ClearHub(x) ClrFlag(x, FLAG_HUB) 675 676 /* free flags */ 677 #define FREEFLAG_SOCKET 0x0001 /**< socket needs to be freed */ 678 #define FREEFLAG_TIMER 0x0002 /**< timer needs to be freed */ 679 680 /* server notice stuff */ 681 682 #define SNO_ADD 1 /**< Perform "or" on server notice mask. */ 683 #define SNO_DEL 2 /**< Perform "and ~x" on server notice mask. */ 684 #define SNO_SET 3 /**< Set server notice mask. */ 685 /* DON'T CHANGE THESE VALUES ! */ 686 /* THE CLIENTS DEPEND ON IT ! */ 687 #define SNO_OLDSNO 0x1 /**< unsorted old messages */ 688 #define SNO_SERVKILL 0x2 /**< server kills (nick collisions) */ 689 #define SNO_OPERKILL 0x4 /**< oper kills */ 690 #define SNO_HACK2 0x8 /**< desyncs */ 691 #define SNO_HACK3 0x10 /**< temporary desyncs */ 692 #define SNO_UNAUTH 0x20 /**< unauthorized connections */ 693 #define SNO_TCPCOMMON 0x40 /**< common TCP or socket errors */ 694 #define SNO_TOOMANY 0x80 /**< too many connections */ 695 #define SNO_HACK4 0x100 /**< Uworld actions on channels */ 696 #define SNO_GLINE 0x200 /**< glines */ 697 #define SNO_NETWORK 0x400 /**< net join/break, etc */ 698 #define SNO_IPMISMATCH 0x800 /**< IP mismatches */ 699 #define SNO_THROTTLE 0x1000 /**< host throttle add/remove notices */ 700 #define SNO_OLDREALOP 0x2000 /**< old oper-only messages */ 701 #define SNO_CONNEXIT 0x4000 /**< client connect/exit (ugh) */ 702 #define SNO_AUTO 0x8000 /**< AUTO G-Lines */ 703 #define SNO_DEBUG 0x10000 /**< debugging messages (DEBUGMODE only) */ 704 #define SNO_AUTH 0x20000 /**< IAuth notices */ 705 706 /** Bitmask of all valid server notice bits. */ 707 #ifdef DEBUGMODE 708 # define SNO_ALL 0x3ffff 709 #else 710 # define SNO_ALL 0x2ffff 711 #endif 712 713 /** Server notice bits allowed to normal users. */ 714 #define SNO_USER (SNO_ALL & ~SNO_OPER) 715 716 /** Server notice bits enabled by default for normal users. */ 717 #define SNO_DEFAULT (SNO_NETWORK|SNO_OPERKILL|SNO_GLINE) 718 /** Server notice bits enabled by default for IRC operators. */ 719 #define SNO_OPERDEFAULT (SNO_DEFAULT|SNO_HACK2|SNO_HACK4|SNO_THROTTLE|SNO_OLDSNO) 720 /** Server notice bits reserved to IRC operators. */ 721 #define SNO_OPER (SNO_CONNEXIT|SNO_OLDREALOP|SNO_AUTH) 722 /** Noisy server notice bits that cause other bits to be cleared during connect. */ 723 #define SNO_NOISY (SNO_SERVKILL|SNO_UNAUTH) 724 725 /** Test whether a privilege has been granted to a client. */ 726 #define HasPriv(cli, priv) FlagHas(cli_privs(cli), priv) 727 /** Grant a privilege to a client. */ 728 #define SetPriv(cli, priv) FlagSet(cli_privs(cli), priv) 729 /** Revoke a privilege from a client. */ 730 #define ClrPriv(cli, priv) FlagClr(cli_privs(cli), priv) 731 732 /** Test whether a client has a capability */ 733 #define HasCap(cli, cap) CapHas(cli_capab(cli), (cap)) 734 /** Test whether a client has the capability active */ 735 #define CapActive(cli, cap) CapHas(cli_active(cli), (cap)) 736 737 #define HIDE_IP 0 /**< Do not show IP address in get_client_name() */ 738 #define SHOW_IP 1 /**< Show ident and IP address in get_client_name() */ 739 740 extern const char* get_client_name(const struct Client* sptr, int showip); 741 extern const char* client_get_default_umode(const struct Client* sptr); 742 extern int client_get_ping(const struct Client* local_client); 743 extern void client_drop_sendq(struct Connection* con); 744 extern void client_add_sendq(struct Connection* con, 745 struct Connection** con_p); 746 extern void client_set_privs(struct Client *client, struct ConfItem *oper, 747 int forceOper); 748 extern int client_report_privs(struct Client* to, struct Client* client); 749 750 #endif /* INCLUDED_client_h */ 751 752