/[svn]/ircd-hybrid/trunk/include/client.h
ViewVC logotype

Contents of /ircd-hybrid/trunk/include/client.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1644 - (show annotations)
Tue Nov 6 22:20:16 2012 UTC (7 years, 7 months ago) by michael
File MIME type: text/x-csrc
File size: 20136 byte(s)
- More config subsystem cleanups

1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 *
4 * Copyright (C) 2002 by the past and present ircd coders, and others.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22 /*! \file client.h
23 * \brief Header including structures, macros and prototypes for client handling
24 * \version $Id$
25 */
26
27
28 #ifndef INCLUDED_client_h
29 #define INCLUDED_client_h
30
31 #include "list.h"
32 #include "fdlist.h"
33 #include "config.h"
34 #include "ircd_defs.h"
35 #include "dbuf.h"
36 #include "channel.h"
37
38
39 /*! \brief addr_mask_type enumeration */
40 enum addr_mask_type
41 {
42 HIDE_IP, /**< IP is hidden. Resolved hostname is shown instead */
43 SHOW_IP, /**< IP is shown. No parts of it are hidden or masked */
44 MASK_IP /**< IP is masked. 255.255.255.255 is shown instead */
45 };
46
47 /*! \brief Server structure */
48 struct Server
49 {
50 dlink_list server_list; /**< Servers on this server */
51 dlink_list client_list; /**< Clients on this server */
52 char by[NICKLEN + 1]; /**< who activated this connection */
53 };
54
55 /*! \brief ListTask structure */
56 struct ListTask
57 {
58 dlink_list show_mask; /**< show these channels.. */
59 dlink_list hide_mask; /**< ..and hide these ones */
60
61 unsigned int hash_index; /**< the bucket we are currently in */
62 unsigned int users_min;
63 unsigned int users_max;
64 unsigned int created_min;
65 unsigned int created_max;
66 unsigned int topicts_min;
67 unsigned int topicts_max;
68 };
69
70 /*! \brief LocalUser structure
71 *
72 * Allocated only for local clients, that are directly connected
73 * to \b this server with a socket.
74 */
75 struct LocalUser
76 {
77 dlink_node lclient_node;
78
79 char client_host[HOSTLEN + 1];
80 char client_server[HOSTLEN + 1];
81
82 unsigned int registration;
83 unsigned int cap_client; /**< Client capabilities (from us) */
84 unsigned int cap_active; /**< Active capabilities (to us) */
85 unsigned int caps; /**< capabilities bit-field */
86
87 unsigned int operflags; /**< IRC Operator privilege flags */
88 unsigned int random_ping; /**< Holding a 32bit value used for PING cookies */
89
90 unsigned int serial; /**< used to enforce 1 send per nick */
91
92 time_t lasttime; /**< ...should be only LOCAL clients? --msa */
93 time_t firsttime; /**< time client was created */
94 time_t since; /**< last time we parsed something */
95 time_t last_knock; /**< time of last knock */
96 time_t last_join_time; /**< when this client last
97 joined a channel */
98 time_t last_leave_time; /**< when this client last
99 * left a channel */
100 int join_leave_count; /**< count of JOIN/LEAVE in less than
101 MIN_JOIN_LEAVE_TIME seconds */
102 int oper_warn_count_down; /**< warn opers of this possible
103 spambot every time this gets to 0 */
104 time_t last_caller_id_time;
105 time_t first_received_message_time;
106 time_t last_nick_change;
107 time_t last_privmsg; /**< Last time we got a PRIVMSG */
108 time_t last_away; /**< Away since... */
109
110 int received_number_of_privmsgs;
111 unsigned int number_of_nick_changes;
112
113 struct ListTask *list_task;
114
115 struct dbuf_queue buf_sendq;
116 struct dbuf_queue buf_recvq;
117
118 struct {
119 unsigned int messages; /**< Statistics: protocol messages sent/received */
120 uint64_t bytes; /**< Statistics: total bytes sent/received */
121 } recv, send;
122
123 struct AuthRequest *auth;
124 struct Listener *listener; /**< listener accepted from */
125 dlink_list acceptlist; /**< clients I'll allow to talk to me */
126 dlink_list watches; /**< chain of Watch pointer blocks */
127 dlink_list confs; /**< Configuration record associated */
128 dlink_list invited; /**< chain of invite pointer blocks */
129 struct irc_ssaddr ip;
130 int aftype; /**< Makes life easier for DNS res in IPV6 */
131
132 char *passwd;
133 fde_t fd;
134
135 /* Anti-flood stuff. We track how many messages were parsed and how
136 * many we were allowed in the current second, and apply a simple
137 * decay to avoid flooding.
138 * -- adrian
139 */
140 int allow_read; /**< how many we're allowed to read in this second */
141 int sent_parsed; /**< how many messages we've parsed in this second */
142
143 char* response; /**< expected response from client */
144 char* auth_oper; /**< Operator to become if they supply the response.*/
145 };
146
147 /*! \brief Client structure */
148 struct Client
149 {
150 dlink_node node;
151 dlink_node lnode; /**< Used for Server->servers/users */
152
153 struct LocalUser *localClient;
154 struct Client *hnext; /**< For client hash table lookups by name */
155 struct Client *idhnext; /**< For SID hash table lookups by sid */
156 struct Server *serv; /**< ...defined, if this is a server */
157 struct Client *servptr; /**< Points to server this Client is on */
158 struct Client *from; /**< == self, if Local Client, *NEVER* NULL! */
159
160 time_t tsinfo; /**< TS on the nick, SVINFO on server */
161
162 unsigned int flags; /**< client flags */
163 unsigned int umodes; /**< opers, normal users subset */
164 unsigned int hopcount; /**< number of servers to this 0 = local */
165 unsigned int status; /**< Client type */
166 unsigned int handler; /**< Handler index */
167
168 dlink_list whowas;
169 dlink_list channel; /**< chain of channel pointer blocks */
170
171 char away[AWAYLEN + 1]; /**< Client's AWAY message. Can be set/unset via AWAY command */
172 char name[HOSTLEN + 1]; /**< unique name for a client nick or host */
173 char svid[HOSTLEN + 1]; /**< Services ID. XXX: Going with HOSTLEN for now. NICKLEN might be too small
174 if dealing with timestamps */
175 char id[IDLEN + 1]; /**< client ID, unique ID per client */
176 /*
177 * client->username is the username from ident or the USER message,
178 * If the client is idented the USER message is ignored, otherwise
179 * the username part of the USER message is put here prefixed with a
180 * tilde depending on the auth{} block. Once a client has registered,
181 * this field should be considered read-only.
182 */
183 char username[USERLEN + 1]; /* client's username */
184
185 /*
186 * client->host contains the resolved name or ip address
187 * as a string for the user, it may be fiddled with for oper spoofing etc.
188 * once it's changed the *real* address goes away. This should be
189 * considered a read-only field after the client has registered.
190 */
191 char host[HOSTLEN + 1]; /* client's hostname */
192
193 /*
194 * client->info for unix clients will normally contain the info from the
195 * gcos field in /etc/passwd but anything can go here.
196 */
197 char info[REALLEN + 1]; /* Free form additional client info */
198
199 /*
200 * client->sockhost contains the ip address gotten from the socket as a
201 * string, this field should be considered read-only once the connection
202 * has been made. (set in s_bsd.c only)
203 */
204 char sockhost[HOSTIPLEN + 1]; /* This is the host name from the
205 socket ip address as string */
206 };
207
208 /*
209 * status macros.
210 */
211 #define STAT_CONNECTING 0x01
212 #define STAT_HANDSHAKE 0x02
213 #define STAT_ME 0x04
214 #define STAT_UNKNOWN 0x08
215 #define STAT_SERVER 0x10
216 #define STAT_CLIENT 0x20
217
218 #define REG_NEED_USER 0x1
219 #define REG_NEED_NICK 0x2
220 #define REG_NEED_CAP 0x4
221 #define REG_INIT (REG_NEED_USER|REG_NEED_NICK)
222
223 #define HasID(x) ((x)->id[0] != '\0')
224 #define ID(x) (HasID(x) ? (x)->id : (x)->name)
225 #define ID_or_name(x,client_p) ((IsCapable(client_p, CAP_TS6) && HasID(x)) ? (x)->id : (x)->name)
226
227 #define IsRegistered(x) ((x)->status > STAT_UNKNOWN)
228 #define IsConnecting(x) ((x)->status == STAT_CONNECTING)
229 #define IsHandshake(x) ((x)->status == STAT_HANDSHAKE)
230 #define IsMe(x) ((x)->status == STAT_ME)
231 #define IsUnknown(x) ((x)->status == STAT_UNKNOWN)
232 #define IsServer(x) ((x)->status == STAT_SERVER)
233 #define IsClient(x) ((x)->status == STAT_CLIENT)
234
235 #define SetConnecting(x) {(x)->status = STAT_CONNECTING; \
236 (x)->handler = UNREGISTERED_HANDLER; }
237
238 #define SetHandshake(x) {(x)->status = STAT_HANDSHAKE; \
239 (x)->handler = UNREGISTERED_HANDLER; }
240
241 #define SetMe(x) {(x)->status = STAT_ME; \
242 (x)->handler = UNREGISTERED_HANDLER; }
243
244 #define SetUnknown(x) {(x)->status = STAT_UNKNOWN; \
245 (x)->handler = UNREGISTERED_HANDLER; }
246
247 #define SetServer(x) {(x)->status = STAT_SERVER; \
248 (x)->handler = SERVER_HANDLER; }
249
250 #define SetClient(x) {(x)->status = STAT_CLIENT; \
251 (x)->handler = HasUMode(x, UMODE_OPER) ? \
252 OPER_HANDLER : CLIENT_HANDLER; }
253
254 #define MyConnect(x) ((x)->localClient != NULL)
255 #define MyClient(x) (MyConnect(x) && IsClient(x))
256
257 /*
258 * ts stuff
259 */
260 #define TS_CURRENT 6 /**< current TS protocol version */
261 #define TS_MIN 5 /**< minimum supported TS protocol version */
262 #define TS_DOESTS 0x20000000
263 #define DoesTS(x) ((x)->tsinfo == TS_DOESTS)
264
265
266
267 #define CAP_MULTI_PREFIX 0x00000001
268
269 #define HasCap(x, y) ((x)->localClient->cap_active & (y))
270
271 /* housekeeping flags */
272 #define FLAGS_PINGSENT 0x00000001 /**< Unreplied ping sent */
273 #define FLAGS_DEADSOCKET 0x00000002 /**< Local socket is dead--Exiting soon */
274 #define FLAGS_KILLED 0x00000004 /**< Prevents "QUIT" from being sent for this */
275 #define FLAGS_CLOSING 0x00000008 /**< set when closing to suppress errors */
276 #define FLAGS_GOTID 0x00000010 /**< successful ident lookup achieved */
277 #define FLAGS_NEEDID 0x00000020 /**< auth{} block say must use ident return */
278 #define FLAGS_SENDQEX 0x00000040 /**< Sendq exceeded */
279 #define FLAGS_IPHASH 0x00000080 /**< iphashed this client */
280 #define FLAGS_MARK 0x00000100 /**< marked client */
281 #define FLAGS_CANFLOOD 0x00000200 /**< client has the ability to flood */
282 #define FLAGS_EXEMPTGLINE 0x00000400 /**< client can't be G-lined */
283 #define FLAGS_EXEMPTKLINE 0x00000800 /**< client is exempt from kline */
284 #define FLAGS_NOLIMIT 0x00001000 /**< client is exempt from limits */
285 #define FLAGS_PING_COOKIE 0x00002000 /**< PING Cookie */
286 #define FLAGS_IP_SPOOFING 0x00004000 /**< client IP is spoofed */
287 #define FLAGS_FLOODDONE 0x00008000 /**< Flood grace period has been ended. */
288 #define FLAGS_EOB 0x00010000 /**< server has sent us an EOB */
289 #define FLAGS_HIDDEN 0x00020000 /**< a hidden server. not shown in /links */
290 #define FLAGS_BLOCKED 0x00040000 /**< must wait for COMM_SELECT_WRITE */
291 #define FLAGS_USERHOST 0x00080000 /**< client is in userhost hash */
292 #define FLAGS_BURSTED 0x00100000 /**< user was already bursted */
293 #define FLAGS_EXEMPTRESV 0x00200000 /**< client is exempt from RESV */
294 #define FLAGS_GOTUSER 0x00400000 /**< if we received a USER command */
295 #define FLAGS_FINISHED_AUTH 0x00800000 /**< Client has been released from auth */
296 #define FLAGS_FLOOD_NOTICED 0x01000000 /**< Notice to opers about this flooder has been sent */
297 #define FLAGS_SERVICE 0x02000000 /**< Client/server is a network service */
298
299 #define HasFlag(x, y) ((x)->flags & (y))
300 #define AddFlag(x, y) ((x)->flags |= (y))
301 #define DelFlag(x, y) ((x)->flags &= ~(y))
302
303
304
305 /* umodes, settable flags */
306 #define UMODE_SERVNOTICE 0x00000001 /**< server notices such as kill */
307 #define UMODE_CCONN 0x00000002 /**< Client Connections */
308 #define UMODE_REJ 0x00000004 /**< Bot Rejections */
309 #define UMODE_SKILL 0x00000008 /**< Server Killed */
310 #define UMODE_FULL 0x00000010 /**< Full messages */
311 #define UMODE_SPY 0x00000020 /**< see STATS / LINKS */
312 #define UMODE_DEBUG 0x00000040 /**< 'debugging' info */
313 #define UMODE_NCHANGE 0x00000080 /**< Nick change notice */
314 #define UMODE_WALLOP 0x00000100 /**< send wallops to them */
315 #define UMODE_OPERWALL 0x00000200 /**< Operwalls */
316 #define UMODE_INVISIBLE 0x00000400 /**< makes user invisible */
317 #define UMODE_BOTS 0x00000800 /**< shows bots */
318 #define UMODE_EXTERNAL 0x00001000 /**< show servers introduced and splitting */
319 #define UMODE_CALLERID 0x00002000 /**< block unless caller id's */
320 #define UMODE_SOFTCALLERID 0x00004000 /**< block unless on common channel */
321 #define UMODE_UNAUTH 0x00008000 /**< show unauth connects here */
322 #define UMODE_LOCOPS 0x00010000 /**< show locops */
323 #define UMODE_DEAF 0x00020000 /**< don't receive channel messages */
324 #define UMODE_CCONN_FULL 0x00040000 /**< add unused fields to connection monitoring */
325 #define UMODE_REGISTERED 0x00080000 /**< User has identified for that nick. */
326 #define UMODE_REGONLY 0x00100000 /**< Only registered nicks may PM */
327 #define UMODE_HIDDEN 0x00200000 /**< Operator status is hidden */
328 #define UMODE_OPER 0x00400000 /**< Operator */
329 #define UMODE_ADMIN 0x00800000 /**< Admin on server */
330
331 #define UMODE_ALL UMODE_SERVNOTICE
332
333 #define HasUMode(x, y) ((x)->umodes & (y))
334 #define AddUMode(x, y) ((x)->umodes |= (y))
335 #define DelUMode(x, y) ((x)->umodes &= ~(y))
336
337 #define SEND_UMODES (UMODE_INVISIBLE | UMODE_OPER | UMODE_WALLOP |\
338 UMODE_REGONLY | UMODE_REGISTERED | UMODE_ADMIN |\
339 UMODE_HIDDEN)
340
341
342
343 /* oper priv flags */
344 #define OPER_FLAG_GLOBAL_KILL 0x00000001 /**< Oper can global kill */
345 #define OPER_FLAG_REMOTE 0x00000002 /**> Oper can do squits/connects */
346 #define OPER_FLAG_UNKLINE 0x00000004 /**< Oper can use unkline */
347 #define OPER_FLAG_GLINE 0x00000008 /**< Oper can use gline */
348 #define OPER_FLAG_N 0x00000010 /**< Oper can umode n */
349 #define OPER_FLAG_K 0x00000020 /**< Oper can kill/kline */
350 #define OPER_FLAG_X 0x00000040 /**< Oper can xline */
351 #define OPER_FLAG_DIE 0x00000080 /**< Oper can die */
352 #define OPER_FLAG_REHASH 0x00000100 /**< Oper can rehash */
353 #define OPER_FLAG_ADMIN 0x00000200 /**< Oper can set umode +a */
354 #define OPER_FLAG_OPERWALL 0x00000400 /**< Oper can use OPERWALL command */
355 #define OPER_FLAG_OPER_SPY 0x00000800 /* */
356 #define OPER_FLAG_REMOTEBAN 0x00001000 /**< Oper can set remote bans */
357 #define OPER_FLAG_GLOBOPS 0x00002000 /**< Oper can use GLOBOPS command */
358 #define OPER_FLAG_MODULE 0x00004000 /**< Oper can use MODULE commands */
359 #define OPER_FLAG_RESTART 0x00008000 /**< Oper can use RESTART command */
360 #define OPER_FLAG_DLINE 0x00010000 /**< Oper can use DLINE command */
361 #define OPER_FLAG_UNDLINE 0x00020000 /**< Oper can use UNDLINE command */
362 #define OPER_FLAG_SET 0x00040000 /**< Oper can use SET command */
363
364 #define HasOFlag(x, y) (MyConnect(x) ? (x)->localClient->operflags & (y) : 0)
365 #define AddOFlag(x, y) ((x)->localClient->operflags |= (y))
366 #define DelOFlag(x, y) ((x)->localClient->operflags &= ~(y))
367 #define ClrOFlag(x) ((x)->localClient->operflags = 0)
368
369
370
371 /* flags macros. */
372 #define IsAuthFinished(x) ((x)->flags & FLAGS_FINISHED_AUTH)
373 #define IsDead(x) ((x)->flags & FLAGS_DEADSOCKET)
374 #define SetDead(x) ((x)->flags |= FLAGS_DEADSOCKET)
375 #define IsClosing(x) ((x)->flags & FLAGS_CLOSING)
376 #define SetClosing(x) ((x)->flags |= FLAGS_CLOSING)
377 #define SetCanFlood(x) ((x)->flags |= FLAGS_CANFLOOD)
378 #define IsCanFlood(x) ((x)->flags & FLAGS_CANFLOOD)
379 #define IsDefunct(x) ((x)->flags & (FLAGS_DEADSOCKET|FLAGS_CLOSING| \
380 FLAGS_KILLED))
381
382 /* oper flags */
383 #define MyOper(x) (MyConnect(x) && HasUMode(x, UMODE_OPER))
384
385 #define SetOper(x) {(x)->umodes |= UMODE_OPER; \
386 if (!IsServer((x))) (x)->handler = OPER_HANDLER;}
387
388 #define ClearOper(x) {(x)->umodes &= ~(UMODE_OPER|UMODE_ADMIN); \
389 if (!HasUMode(x, UMODE_OPER) && !IsServer((x))) \
390 (x)->handler = CLIENT_HANDLER; }
391
392 #define SetSendQExceeded(x) ((x)->flags |= FLAGS_SENDQEX)
393 #define IsSendQExceeded(x) ((x)->flags & FLAGS_SENDQEX)
394
395 #define SetIpHash(x) ((x)->flags |= FLAGS_IPHASH)
396 #define ClearIpHash(x) ((x)->flags &= ~FLAGS_IPHASH)
397 #define IsIpHash(x) ((x)->flags & FLAGS_IPHASH)
398
399 #define SetUserHost(x) ((x)->flags |= FLAGS_USERHOST)
400 #define ClearUserHost(x) ((x)->flags &= ~FLAGS_USERHOST)
401 #define IsUserHostIp(x) ((x)->flags & FLAGS_USERHOST)
402
403 #define SetPingSent(x) ((x)->flags |= FLAGS_PINGSENT)
404 #define IsPingSent(x) ((x)->flags & FLAGS_PINGSENT)
405 #define ClearPingSent(x) ((x)->flags &= ~FLAGS_PINGSENT)
406
407 #define SetNeedId(x) ((x)->flags |= FLAGS_NEEDID)
408 #define IsNeedId(x) ((x)->flags & FLAGS_NEEDID)
409
410 #define SetGotId(x) ((x)->flags |= FLAGS_GOTID)
411 #define IsGotId(x) ((x)->flags & FLAGS_GOTID)
412
413 #define IsExemptKline(x) ((x)->flags & FLAGS_EXEMPTKLINE)
414 #define SetExemptKline(x) ((x)->flags |= FLAGS_EXEMPTKLINE)
415 #define IsExemptLimits(x) ((x)->flags & FLAGS_NOLIMIT)
416 #define SetExemptLimits(x) ((x)->flags |= FLAGS_NOLIMIT)
417 #define IsExemptGline(x) ((x)->flags & FLAGS_EXEMPTGLINE)
418 #define SetExemptGline(x) ((x)->flags |= FLAGS_EXEMPTGLINE)
419 #define IsExemptResv(x) ((x)->flags & FLAGS_EXEMPTRESV)
420 #define SetExemptResv(x) ((x)->flags |= FLAGS_EXEMPTRESV)
421 #define SetIPSpoof(x) ((x)->flags |= FLAGS_IP_SPOOFING)
422 #define IsIPSpoof(x) ((x)->flags & FLAGS_IP_SPOOFING)
423
424 #define IsFloodDone(x) ((x)->flags & FLAGS_FLOODDONE)
425 #define SetFloodDone(x) ((x)->flags |= FLAGS_FLOODDONE)
426 #define HasPingCookie(x) ((x)->flags & FLAGS_PING_COOKIE)
427 #define SetPingCookie(x) ((x)->flags |= FLAGS_PING_COOKIE)
428 #define IsHidden(x) ((x)->flags & FLAGS_HIDDEN)
429 #define SetHidden(x) ((x)->flags |= FLAGS_HIDDEN)
430
431 #define IsSendqBlocked(x) ((x)->flags & FLAGS_BLOCKED)
432 #define SetSendqBlocked(x) ((x)->flags |= FLAGS_BLOCKED)
433 #define ClearSendqBlocked(x) ((x)->flags &= ~FLAGS_BLOCKED)
434
435
436 extern struct Client me;
437 extern dlink_list listing_client_list;
438 extern dlink_list global_client_list;
439
440 extern int accept_message(struct Client *, struct Client *);
441 extern struct split_nuh_item *find_accept(const char *, const char *,
442 const char *, struct Client *, int);
443 extern void del_accept(struct split_nuh_item *, struct Client *);
444 extern void del_all_accepts(struct Client *);
445 extern void exit_client(struct Client *, struct Client *, const char *);
446 extern void check_conf_klines(void);
447 extern void init_client(void);
448 extern void dead_link_on_write(struct Client *, int);
449 extern void dead_link_on_read(struct Client *, int);
450 extern void exit_aborted_clients(void);
451 extern void free_exited_clients(void);
452 extern struct Client *make_client(struct Client *);
453 extern struct Client *find_chasing(struct Client *, struct Client *, const char *, int *);
454 extern struct Client *find_person(const struct Client *const, const char *);
455 extern const char *get_client_name(const struct Client *, enum addr_mask_type);
456
457 #endif /* INCLUDED_client_h */

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28