implement IAUTH client code to query a separate server before allowing
[ircu2.10.12-pk.git] / include / client.h
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  *
21  * $Id$
22  */
23 #ifndef INCLUDED_client_h
24 #define INCLUDED_client_h
25 #ifndef INCLUDED_ircd_defs_h
26 #include "ircd_defs.h"
27 #endif
28 #ifndef INCLUDED_dbuf_h
29 #include "dbuf.h"
30 #endif
31 #ifndef INCLUDED_msgq_h
32 #include "msgq.h"
33 #endif
34 #ifndef INCLUDED_ircd_events_h
35 #include "ircd_events.h"
36 #endif
37 #ifndef INCLUDED_ircd_handler_h
38 #include "ircd_handler.h"
39 #endif
40 #ifndef INCLUDED_sys_types_h
41 #include <sys/types.h>          /* time_t, size_t */
42 #define INCLUDED_sys_types_h
43 #endif
44 #ifndef INCLUDED_netinet_in_h
45 #include <netinet/in.h>         /* in_addr */
46 #define INCLUDED_netinet_in_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 typedef unsigned long flagpage_t;
69
70 #define FLAGSET_NBITS (8 * sizeof(flagpage_t))
71 #define FLAGSET_INDEX(flag) (flag / FLAGSET_NBITS)
72 #define FLAGSET_MASK(flag) (1<<(flag % FLAGSET_NBITS))
73
74 #define DECLARE_FLAGSET(name,max) \
75   struct name \
76   { \
77     unsigned long bits[((max + FLAGSET_NBITS - 1) / FLAGSET_NBITS)]; \
78   };
79
80 #define FLAGSET_ISSET(set,flag) ((set).bits[FLAGSET_INDEX(flag)] & FLAGSET_MASK(flag))
81 #define FLAGSET_SET(set, flag) (set).bits[FLAGSET_INDEX(flag)] |= FLAGSET_MASK(flag)
82 #define FLAGSET_CLEAR(set, flag) (set).bits[FLAGSET_INDEX(flag)] &= ~FLAGSET_MASK(flag)
83
84 #define infousermodes "dioswkgx"
85
86 enum Priv
87   {
88     PRIV_CHAN_LIMIT, /* no channel limit on oper */
89     PRIV_MODE_LCHAN, /* oper can mode local chans */
90     PRIV_WALK_LCHAN, /* oper can walk thru local modes */
91     PRIV_DEOP_LCHAN, /* no deop oper on local chans */
92     PRIV_SHOW_INVIS, /* show local invisible users */
93     PRIV_SHOW_ALL_INVIS, /* show all invisible users */
94     PRIV_UNLIMIT_QUERY, /* unlimit who queries */
95     PRIV_KILL, /* oper can KILL */
96     PRIV_LOCAL_KILL, /* oper can local KILL */
97     PRIV_REHASH, /* oper can REHASH */
98     PRIV_RESTART, /* oper can RESTART */
99     PRIV_DIE, /* oper can DIE */
100     PRIV_GLINE, /* oper can GLINE */
101     PRIV_LOCAL_GLINE, /* oper can local GLINE */
102     PRIV_JUPE, /* oper can JUPE */
103     PRIV_LOCAL_JUPE, /* oper can local JUPE */
104     PRIV_OPMODE, /* oper can OP/CLEARMODE */
105     PRIV_LOCAL_OPMODE, /* oper can local OP/CLEARMODE */
106     PRIV_SET,  /* oper can SET */
107     PRIV_WHOX, /* oper can use /who x */
108     PRIV_BADCHAN, /* oper can BADCHAN */
109     PRIV_LOCAL_BADCHAN, /* oper can local BADCHAN */
110     PRIV_SEE_CHAN, /* oper can see in secret chans */
111     PRIV_PROPAGATE, /* propagate oper status */
112     PRIV_DISPLAY, /* "Is an oper" displayed */
113     PRIV_SEE_OPERS, /* display hidden opers */
114     PRIV_WIDE_GLINE, /* oper can set wider G-lines */
115     PRIV_LIST_CHAN, /* oper can list secret channels */
116     PRIV_FORCE_OPMODE, /* can hack modes on quarantined channels */
117     PRIV_FORCE_LOCAL_OPMODE, /* can hack modes on quarantined local channels */
118     PRIV_LAST_PRIV /* must be the same as the last priv */
119   };
120
121 enum Flag
122   {
123     FLAG_PINGSENT,                  /* Unreplied ping sent */
124     FLAG_DEADSOCKET,                /* Local socket is dead--Exiting soon */
125     FLAG_KILLED,                    /* Prevents "QUIT" from being sent for this */
126     FLAG_BLOCKED,                   /* socket is in a blocked condition */
127     FLAG_CLOSING,                   /* set when closing to suppress errors */
128     FLAG_UPING,                     /* has active UDP ping request */
129     FLAG_CHKACCESS,                 /* ok to check clients access if set */
130     FLAG_HUB,                       /* server is a hub */
131     FLAG_SERVICE,                   /* server is a service */
132     FLAG_LOCAL,                     /* set for local clients */
133     FLAG_GOTID,                     /* successful ident lookup achieved */
134     FLAG_DOID,                      /* I-lines say must use ident return */
135     FLAG_NONL,                      /* No \n in buffer */
136     FLAG_TS8,                       /* Why do you want to know? */
137     FLAG_MAP,                       /* Show server on the map */
138     FLAG_JUNCTION,                  /* Junction causing the net.burst */
139     FLAG_BURST,                     /* Server is receiving a net.burst */
140     FLAG_BURST_ACK,                 /* Server is waiting for eob ack */
141     FLAG_IPCHECK,                   /* Added or updated IPregistry data */
142     FLAG_IAUTHED,                   /* Got IAUTH response for user */
143     FLAG_LOCOP,                     /* Local operator -- SRB */
144     FLAG_SERVNOTICE,                /* server notices such as kill */
145     FLAG_OPER,                      /* Operator */
146     FLAG_INVISIBLE,                 /* makes user invisible */
147     FLAG_WALLOP,                    /* send wallops to them */
148     FLAG_DEAF,                      /* Makes user deaf */
149     FLAG_CHSERV,                    /* Disallow KICK or MODE -o on the user;
150                                        don't display channels in /whois */
151     FLAG_DEBUG,                     /* send global debug/anti-hack info */
152     FLAG_ACCOUNT,                   /* account name has been set */
153     FLAG_HIDDENHOST,                /* user's host is hidden */
154     FLAG_LAST_FLAG,
155     FLAG_LOCAL_UMODES = FLAG_LOCOP, /* First local mode flag */
156     FLAG_GLOBAL_UMODES = FLAG_OPER  /* First global mode flag */
157   };
158
159 DECLARE_FLAGSET(Privs, PRIV_LAST_PRIV);
160 DECLARE_FLAGSET(Flags, FLAG_LAST_FLAG);
161
162 struct Connection
163 {
164   /*
165    *  The following fields are allocated only for local clients
166    *  (directly connected to *this* server with a socket.
167    *  The first of them *MUST* be the "count"--it is the field
168    *  to which the allocation is tied to! *Never* refer to
169    *  these fields, if (from != self).
170    */
171   unsigned long       con_magic; /* magic number */
172   struct Connection*  con_next;  /* Next connection with queued data */
173   struct Connection** con_prev_p; /* What points to us */
174   struct Client*      con_client; /* Client associated with connection */
175   unsigned int        con_count; /* Amount of data in buffer */
176   int                 con_fd;    /* >= 0, for local clients */
177   int                 con_freeflag; /* indicates if connection can be freed */
178   int                 con_error; /* last socket level error for client */
179   unsigned int        con_snomask; /* mask for server messages */
180   time_t              con_nextnick; /* Next time a nick change is allowed */
181   time_t              con_nexttarget;/* Next time a target change is allowed */
182   unsigned int        con_cookie; /* Random number the user must PONG */
183   struct MsgQ         con_sendQ; /* Outgoing message queue--if socket full */
184   struct DBuf         con_recvQ; /* Hold for data incoming yet to be parsed */
185   unsigned int        con_sendM; /* Statistics: protocol messages send */
186   unsigned int        con_sendK; /* Statistics: total k-bytes send */
187   unsigned int        con_receiveM;/* Statistics: protocol messages received */
188   unsigned int        con_receiveK; /* Statistics: total k-bytes received */
189   unsigned short      con_sendB; /* counters to count upto 1-k lots of bytes */
190   unsigned short      con_receiveB; /* sent and received. */
191   struct Listener*    con_listener; /* listening client which we accepted
192                                        from */
193   struct SLink*       con_confs; /* Configuration record associated */
194   HandlerType         con_handler; /* message index into command table
195                                       for parsing */
196   struct hostent*    con_dns_reply; /* DNS reply used during client
197                                         registration */
198   struct ListingArgs* con_listing;
199   unsigned int        con_max_sendq; /* cached max send queue for client */
200   unsigned int        con_ping_freq; /* cached ping freq from client conf
201                                         class */
202   unsigned short      con_lastsq; /* # 2k blocks when sendqueued called last */
203   unsigned short      con_port;  /* and the remote port# too :-) */
204   unsigned char       con_targets[MAXTARGETS]; /* Hash values of current
205                                                   targets */
206   char con_sock_ip[SOCKIPLEN + 1]; /* this is the ip address as a string */
207   char con_sockhost[HOSTLEN + 1]; /* This is the host name from the socket and
208                                     after which the connection was accepted. */
209   char con_passwd[PASSWDLEN + 1];
210   char con_buffer[BUFSIZE];     /* Incoming message buffer; or the error that
211                                    caused this clients socket to be `dead' */
212   struct Socket       con_socket; /* socket descriptor for client */
213   struct Timer        con_proc; /* process latent messages from client */
214   struct AuthRequest* con_auth; /* auth request for client */
215   struct IAuthRequest* con_iauth; /* iauth request for client */
216 };
217
218 #define CONNECTION_MAGIC 0x12f955f3
219
220 struct Client {
221   unsigned long  cli_magic;     /* magic number */
222   struct Client* cli_next;      /* link in GlobalClientList */
223   struct Client* cli_prev;      /* link in GlobalClientList */
224   struct Client* cli_hnext;     /* link in hash table bucket or this */
225   struct Connection* cli_connect; /* Connection structure associated with us */
226   struct User*   cli_user;      /* ...defined, if this is a User */
227   struct Server* cli_serv;      /* ...defined, if this is a server */
228   struct Whowas* cli_whowas;    /* Pointer to ww struct to be freed on quit */
229   char           cli_yxx[4];    /* Numeric Nick: YMM if this is a server,
230                                    XX0 if this is a user */
231   /*
232    * XXX - move these to local part for next release
233    * (lasttime, since)
234    */
235   time_t         cli_lasttime;  /* last time data read from socket */
236   time_t         cli_since;     /* last time we parsed something, flood control */
237                                 
238   time_t         cli_firsttime; /* time client was created */
239   time_t         cli_lastnick;  /* TimeStamp on nick */
240   int            cli_marker;    /* /who processing marker */
241   struct Flags   cli_flags;     /* client flags */
242   unsigned int   cli_hopcount;  /* number of servers to this 0 = local */
243   struct in_addr cli_ip;        /* Real ip# NOT defined for remote servers! */
244   short          cli_status;    /* Client type */
245   unsigned char  cli_local;     /* local or remote client */
246   struct Privs   cli_privs;     /* Oper privileges */
247   char cli_name[HOSTLEN + 1];   /* Unique name of the client, nick or host */
248   char cli_username[USERLEN + 1]; /* username here now for auth stuff */
249   char cli_info[REALLEN + 1];   /* Free form additional client information */
250 };
251
252 #define CLIENT_MAGIC 0x4ca08286
253
254 #define cli_verify(cli)         ((cli)->cli_magic == CLIENT_MAGIC)
255 #define cli_magic(cli)          ((cli)->cli_magic)
256 #define cli_next(cli)           ((cli)->cli_next)
257 #define cli_prev(cli)           ((cli)->cli_prev)
258 #define cli_hnext(cli)          ((cli)->cli_hnext)
259 #define cli_connect(cli)        ((cli)->cli_connect)
260 #define cli_from(cli)           ((cli)->cli_connect->con_client)
261 #define cli_user(cli)           ((cli)->cli_user)
262 #define cli_serv(cli)           ((cli)->cli_serv)
263 #define cli_whowas(cli)         ((cli)->cli_whowas)
264 #define cli_yxx(cli)            ((cli)->cli_yxx)
265 #define cli_lasttime(cli)       ((cli)->cli_lasttime)
266 #define cli_since(cli)          ((cli)->cli_since)
267 #define cli_firsttime(cli)      ((cli)->cli_firsttime)
268 #define cli_lastnick(cli)       ((cli)->cli_lastnick)
269 #define cli_marker(cli)         ((cli)->cli_marker)
270 #define cli_flags(cli)          ((cli)->cli_flags)
271 #define cli_hopcount(cli)       ((cli)->cli_hopcount)
272 #define cli_ip(cli)             ((cli)->cli_ip)
273 #define cli_status(cli)         ((cli)->cli_status)
274 #define cli_local(cli)          ((cli)->cli_local)
275 #define cli_privs(cli)          ((cli)->cli_privs)
276 #define cli_name(cli)           ((cli)->cli_name)
277 #define cli_username(cli)       ((cli)->cli_username)
278 #define cli_info(cli)           ((cli)->cli_info)
279
280 #define cli_count(cli)          ((cli)->cli_connect->con_count)
281 #define cli_fd(cli)             ((cli)->cli_connect->con_fd)
282 #define cli_freeflag(cli)       ((cli)->cli_connect->con_freeflag)
283 #define cli_error(cli)          ((cli)->cli_connect->con_error)
284 #define cli_snomask(cli)        ((cli)->cli_connect->con_snomask)
285 #define cli_nextnick(cli)       ((cli)->cli_connect->con_nextnick)
286 #define cli_nexttarget(cli)     ((cli)->cli_connect->con_nexttarget)
287 #define cli_cookie(cli)         ((cli)->cli_connect->con_cookie)
288 #define cli_sendQ(cli)          ((cli)->cli_connect->con_sendQ)
289 #define cli_recvQ(cli)          ((cli)->cli_connect->con_recvQ)
290 #define cli_sendM(cli)          ((cli)->cli_connect->con_sendM)
291 #define cli_sendK(cli)          ((cli)->cli_connect->con_sendK)
292 #define cli_receiveM(cli)       ((cli)->cli_connect->con_receiveM)
293 #define cli_receiveK(cli)       ((cli)->cli_connect->con_receiveK)
294 #define cli_sendB(cli)          ((cli)->cli_connect->con_sendB)
295 #define cli_receiveB(cli)       ((cli)->cli_connect->con_receiveB)
296 #define cli_listener(cli)       ((cli)->cli_connect->con_listener)
297 #define cli_confs(cli)          ((cli)->cli_connect->con_confs)
298 #define cli_handler(cli)        ((cli)->cli_connect->con_handler)
299 #define cli_dns_reply(cli)      ((cli)->cli_connect->con_dns_reply)
300 #define cli_listing(cli)        ((cli)->cli_connect->con_listing)
301 #define cli_max_sendq(cli)      ((cli)->cli_connect->con_max_sendq)
302 #define cli_ping_freq(cli)      ((cli)->cli_connect->con_ping_freq)
303 #define cli_lastsq(cli)         ((cli)->cli_connect->con_lastsq)
304 #define cli_port(cli)           ((cli)->cli_connect->con_port)
305 #define cli_targets(cli)        ((cli)->cli_connect->con_targets)
306 #define cli_sock_ip(cli)        ((cli)->cli_connect->con_sock_ip)
307 #define cli_sockhost(cli)       ((cli)->cli_connect->con_sockhost)
308 #define cli_passwd(cli)         ((cli)->cli_connect->con_passwd)
309 #define cli_buffer(cli)         ((cli)->cli_connect->con_buffer)
310 #define cli_socket(cli)         ((cli)->cli_connect->con_socket)
311 #define cli_proc(cli)           ((cli)->cli_connect->con_proc)
312 #define cli_auth(cli)           ((cli)->cli_connect->con_auth)
313 #define cli_iauth(cli)          ((cli)->cli_connect->con_iauth)
314
315 #define con_verify(con)         ((con)->con_magic == CONNECTION_MAGIC)
316 #define con_magic(con)          ((con)->con_magic)
317 #define con_next(con)           ((con)->con_next)
318 #define con_prev_p(con)         ((con)->con_prev_p)
319 #define con_client(con)         ((con)->con_client)
320 #define con_count(con)          ((con)->con_count)
321 #define con_fd(con)             ((con)->con_fd)
322 #define con_freeflag(con)       ((con)->con_freeflag)
323 #define con_error(con)          ((con)->con_error)
324 #define con_snomask(con)        ((con)->con_snomask)
325 #define con_nextnick(con)       ((con)->con_nextnick)
326 #define con_nexttarget(con)     ((con)->con_nexttarget)
327 #define con_cookie(con)         ((con)->con_cookie)
328 #define con_sendQ(con)          ((con)->con_sendQ)
329 #define con_recvQ(con)          ((con)->con_recvQ)
330 #define con_sendM(con)          ((con)->con_sendM)
331 #define con_sendK(con)          ((con)->con_sendK)
332 #define con_receiveM(con)       ((con)->con_receiveM)
333 #define con_receiveK(con)       ((con)->con_receiveK)
334 #define con_sendB(con)          ((con)->con_sendB)
335 #define con_receiveB(con)       ((con)->con_receiveB)
336 #define con_listener(con)       ((con)->con_listener)
337 #define con_confs(con)          ((con)->con_confs)
338 #define con_handler(con)        ((con)->con_handler)
339 #define con_dns_reply(con)      ((con)->con_dns_reply)
340 #define con_listing(con)        ((con)->con_listing)
341 #define con_max_sendq(con)      ((con)->con_max_sendq)
342 #define con_ping_freq(con)      ((con)->con_ping_freq)
343 #define con_lastsq(con)         ((con)->con_lastsq)
344 #define con_port(con)           ((con)->con_port)
345 #define con_targets(con)        ((con)->con_targets)
346 #define con_sock_ip(con)        ((con)->con_sock_ip)
347 #define con_sockhost(con)       ((con)->con_sockhost)
348 #define con_passwd(con)         ((con)->con_passwd)
349 #define con_buffer(con)         ((con)->con_buffer)
350 #define con_socket(con)         ((con)->con_socket)
351 #define con_proc(con)           ((con)->con_proc)
352 #define con_auth(con)           ((con)->con_auth)
353 #define con_iauth(con)          ((con)->con_iauth)
354
355 #define STAT_CONNECTING         0x001 /* connecting to another server */
356 #define STAT_HANDSHAKE          0x002 /* pass - server sent */
357 #define STAT_ME                 0x004 /* this server */
358 #define STAT_UNKNOWN            0x008 /* unidentified connection */
359 #define STAT_UNKNOWN_USER       0x010 /* Connect to client port */
360 #define STAT_UNKNOWN_SERVER     0x020 /* Connect to server port */
361 #define STAT_SERVER             0x040
362 #define STAT_USER               0x080
363
364 /*
365  * status macros.
366  */
367 #define IsRegistered(x)         (cli_status(x) & (STAT_SERVER | STAT_USER))
368 #define IsConnecting(x)         (cli_status(x) == STAT_CONNECTING)
369 #define IsHandshake(x)          (cli_status(x) == STAT_HANDSHAKE)
370 #define IsMe(x)                 (cli_status(x) == STAT_ME)
371 #define IsUnknown(x)            (cli_status(x) & \
372         (STAT_UNKNOWN | STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER))
373
374 #define IsServerPort(x)         (cli_status(x) == STAT_UNKNOWN_SERVER )
375 #define IsUserPort(x)           (cli_status(x) == STAT_UNKNOWN_USER )
376 #define IsClient(x)             (cli_status(x) & \
377         (STAT_HANDSHAKE | STAT_ME | STAT_UNKNOWN |\
378          STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER | STAT_SERVER | STAT_USER))
379
380 #define IsTrusted(x)            (cli_status(x) & \
381         (STAT_CONNECTING | STAT_HANDSHAKE | STAT_ME | STAT_SERVER))
382
383 #define IsServer(x)             (cli_status(x) == STAT_SERVER)
384 #define IsUser(x)               (cli_status(x) == STAT_USER)
385
386
387 #define SetConnecting(x)        (cli_status(x) = STAT_CONNECTING)
388 #define SetHandshake(x)         (cli_status(x) = STAT_HANDSHAKE)
389 #define SetServer(x)            (cli_status(x) = STAT_SERVER)
390 #define SetMe(x)                (cli_status(x) = STAT_ME)
391 #define SetUser(x)              (cli_status(x) = STAT_USER)
392
393 #define MyConnect(x)    (cli_from(x) == (x))
394 #define MyUser(x)       (MyConnect(x) && IsUser(x))
395 #define MyOper(x)       (MyConnect(x) && IsOper(x))
396 #define Protocol(x)     ((cli_serv(x))->prot)
397
398 #define PARSE_AS_SERVER(x) (cli_status(x) & \
399             (STAT_SERVER | STAT_CONNECTING | STAT_HANDSHAKE))
400
401 /*
402  * flags macros
403  */
404 #define FlagSet(fset, flag) FLAGSET_SET(*fset, flag)
405 #define FlagClr(fset, flag) FLAGSET_CLEAR(*fset, flag)
406 #define FlagHas(fset, flag) FLAGSET_ISSET(*fset, flag)
407 #define SetFlag(cli, flag)      FlagSet(&cli_flags(cli), flag)
408 #define ClrFlag(cli, flag)      FlagClr(&cli_flags(cli), flag)
409 #define HasFlag(cli, flag)      FlagHas(&cli_flags(cli), flag)
410
411 #define DoAccess(x)             HasFlag(x, FLAG_CHKACCESS)
412 #define IsAnOper(x)             (HasFlag(x, FLAG_OPER) || HasFlag(x, FLAG_LOCOP))
413 #define IsBlocked(x)            HasFlag(x, FLAG_BLOCKED)
414 #define IsBurst(x)              HasFlag(x, FLAG_BURST)
415 #define IsBurstAck(x)           HasFlag(x, FLAG_BURST_ACK)
416 #define IsBurstOrBurstAck(x)    (HasFlag(x, FLAG_BURST) || HasFlag(x, FLAG_BURST_ACK))
417 #define IsChannelService(x)     HasFlag(x, FLAG_CHSERV)
418 #define IsDead(x)               HasFlag(x, FLAG_DEADSOCKET)
419 #define IsDeaf(x)               HasFlag(x, FLAG_DEAF)
420 #define IsIPChecked(x)          HasFlag(x, FLAG_IPCHECK)
421 #define IsIAuthed(x)            HasFlag(x, FLAG_IAUTHED)
422 #define IsIdented(x)            HasFlag(x, FLAG_GOTID)
423 #define IsInvisible(x)          HasFlag(x, FLAG_INVISIBLE)
424 #define IsJunction(x)           HasFlag(x, FLAG_JUNCTION)
425 #define IsLocOp(x)              HasFlag(x, FLAG_LOCOP)
426 #define IsLocal(x)              HasFlag(x, FLAG_LOCAL)
427 #define IsOper(x)               HasFlag(x, FLAG_OPER)
428 #define IsUPing(x)              HasFlag(x, FLAG_UPING)
429 #define NoNewLine(x)            HasFlag(x, FLAG_NONL)
430 #define SendDebug(x)            HasFlag(x, FLAG_DEBUG)
431 #define SendServNotice(x)       HasFlag(x, FLAG_SERVNOTICE)
432 #define SendWallops(x)          HasFlag(x, FLAG_WALLOP)
433 #define IsHub(x)                HasFlag(x, FLAG_HUB)
434 #define IsService(x)            HasFlag(x, FLAG_SERVICE)
435 #define IsAccount(x)            HasFlag(x, FLAG_ACCOUNT)
436 #define IsHiddenHost(x)         HasFlag(x, FLAG_HIDDENHOST)
437 #define IsPingSent(x)           HasFlag(x, FLAG_PINGSENT)
438
439 #define IsPrivileged(x)         (IsAnOper(x) || IsServer(x))
440 #define HasHiddenHost(x)        (IsHiddenHost(x) && IsAccount(x))
441
442 #define SetAccess(x)            SetFlag(x, FLAG_CHKACCESS)
443 #define SetBurst(x)             SetFlag(x, FLAG_BURST)
444 #define SetBurstAck(x)          SetFlag(x, FLAG_BURST_ACK)
445 #define SetChannelService(x)    SetFlag(x, FLAG_CHSERV)
446 #define SetDeaf(x)              SetFlag(x, FLAG_DEAF)
447 #define SetDebug(x)             SetFlag(x, FLAG_DEBUG)
448 #define SetGotId(x)             SetFlag(x, FLAG_GOTID)
449 #define SetIPChecked(x)         SetFlag(x, FLAG_IPCHECK)
450 #define SetIAuthed(x)           SetFlag(x, FLAG_IAUTHED)
451 #define SetInvisible(x)         SetFlag(x, FLAG_INVISIBLE)
452 #define SetJunction(x)          SetFlag(x, FLAG_JUNCTION)
453 #define SetLocOp(x)             SetFlag(x, FLAG_LOCOP)
454 #define SetOper(x)              SetFlag(x, FLAG_OPER)
455 #define SetUPing(x)             SetFlag(x, FLAG_UPING)
456 #define SetWallops(x)           SetFlag(x, FLAG_WALLOP)
457 #define SetServNotice(x)        SetFlag(x, FLAG_SERVNOTICE)
458 #define SetHub(x)               SetFlag(x, FLAG_HUB)
459 #define SetService(x)           SetFlag(x, FLAG_SERVICE)
460 #define SetAccount(x)           SetFlag(x, FLAG_ACCOUNT)
461 #define SetHiddenHost(x)        SetFlag(x, FLAG_HIDDENHOST)
462 #define SetPingSent(x)          SetFlag(x, FLAG_PINGSENT)
463
464 #define SeeOper(sptr,acptr) (IsAnOper(acptr) && (HasPriv(acptr, PRIV_DISPLAY) \
465                             || HasPriv(sptr, PRIV_SEE_OPERS)))
466
467 #define ClearAccess(x)          ClrFlag(x, FLAG_CHKACCESS)
468 #define ClearBurst(x)           ClrFlag(x, FLAG_BURST)
469 #define ClearBurstAck(x)        ClrFlag(x, FLAG_BURST_ACK)
470 #define ClearChannelService(x)  ClrFlag(x, FLAG_CHSERV)
471 #define ClearDeaf(x)            ClrFlag(x, FLAG_DEAF)
472 #define ClearDebug(x)           ClrFlag(x, FLAG_DEBUG)
473 #define ClearIPChecked(x)       ClrFlag(x, FLAG_IPCHECK)
474 #define ClearInvisible(x)       ClrFlag(x, FLAG_INVISIBLE)
475 #define ClearLocOp(x)           ClrFlag(x, FLAG_LOCOP)
476 #define ClearOper(x)            ClrFlag(x, FLAG_OPER)
477 #define ClearUPing(x)           ClrFlag(x, FLAG_UPING)
478 #define ClearWallops(x)         ClrFlag(x, FLAG_WALLOP)
479 #define ClearServNotice(x)      ClrFlag(x, FLAG_SERVNOTICE)
480 #define ClearHiddenHost(x)      ClrFlag(x, FLAG_HIDDENHOST)
481 #define ClearPingSent(x)        ClrFlag(x, FLAG_PINGSENT)
482
483 /* free flags */
484 #define FREEFLAG_SOCKET 0x0001  /* socket needs to be freed */
485 #define FREEFLAG_TIMER  0x0002  /* timer needs to be freed */
486
487 /* server notice stuff */
488
489 #define SNO_ADD         1
490 #define SNO_DEL         2
491 #define SNO_SET         3
492                                 /* DON'T CHANGE THESE VALUES ! */
493                                 /* THE CLIENTS DEPEND ON IT  ! */
494 #define SNO_OLDSNO      0x1     /* unsorted old messages */
495 #define SNO_SERVKILL    0x2     /* server kills (nick collisions) */
496 #define SNO_OPERKILL    0x4     /* oper kills */
497 #define SNO_HACK2       0x8     /* desyncs */
498 #define SNO_HACK3       0x10    /* temporary desyncs */
499 #define SNO_UNAUTH      0x20    /* unauthorized connections */
500 #define SNO_TCPCOMMON   0x40    /* common TCP or socket errors */
501 #define SNO_TOOMANY     0x80    /* too many connections */
502 #define SNO_HACK4       0x100   /* Uworld actions on channels */
503 #define SNO_GLINE       0x200   /* glines */
504 #define SNO_NETWORK     0x400   /* net join/break, etc */
505 #define SNO_IPMISMATCH  0x800   /* IP mismatches */
506 #define SNO_THROTTLE    0x1000  /* host throttle add/remove notices */
507 #define SNO_OLDREALOP   0x2000  /* old oper-only messages */
508 #define SNO_CONNEXIT    0x4000  /* client connect/exit (ugh) */
509 #define SNO_AUTO        0x8000  /* AUTO G-Lines */
510 #define SNO_DEBUG       0x10000 /* debugging messages (DEBUGMODE only) */
511
512 #ifdef DEBUGMODE
513 # define SNO_ALL        0x1ffff  /* Don't make it larger then significant,
514                                   * that looks nicer */
515 #else
516 # define SNO_ALL        0xffff
517 #endif
518
519 #define SNO_USER        (SNO_ALL & ~SNO_OPER)
520
521 #define SNO_DEFAULT (SNO_NETWORK|SNO_OPERKILL|SNO_GLINE)
522 #define SNO_OPERDEFAULT (SNO_DEFAULT|SNO_HACK2|SNO_HACK4|SNO_THROTTLE|SNO_OLDSNO)
523 #define SNO_OPER (SNO_CONNEXIT|SNO_OLDREALOP)
524 #define SNO_NOISY (SNO_SERVKILL|SNO_UNAUTH)
525
526 #define PrivSet(fset, flag) FLAGSET_SET(*fset, flag)
527 #define PrivClr(fset, flag) FLAGSET_CLEAR(*fset, flag)
528 #define PrivHas(fset, flag) FLAGSET_ISSET(*fset, flag)
529
530 #define GrantPriv(cli, priv)    (PrivSet(&(cli_privs(cli)), priv))
531 #define RevokePriv(cli, priv)   (PrivClr(&(cli_privs(cli)), priv))
532 #define HasPriv(cli, priv)      (PrivHas(&(cli_privs(cli)), priv))
533
534 typedef enum ShowIPType {
535   HIDE_IP,
536   SHOW_IP,
537   MASK_IP
538 } ShowIPType;
539
540 extern const char* get_client_name(const struct Client* sptr, int showip);
541 extern const char* client_get_default_umode(const struct Client* sptr);
542 extern int client_get_ping(const struct Client* local_client);
543 extern void client_drop_sendq(struct Connection* con);
544 extern void client_add_sendq(struct Connection* con,
545                              struct Connection** con_p);
546 extern void client_set_privs(struct Client *client, struct ConfItem *oper);
547 extern int client_report_privs(struct Client* to, struct Client* client);
548
549 #endif /* INCLUDED_client_h */
550