]> jfr.im git - irc/evilnet/x3.git/blob - src/hash.h
Added SASL support for Nefarious 2
[irc/evilnet/x3.git] / src / hash.h
1 /* hash.h - IRC network state database
2 * Copyright 2000-2004 srvx Development Team
3 *
4 * This file is part of x3.
5 *
6 * x3 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 3 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 srvx; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 */
20
21 #ifndef HASH_H
22 #define HASH_H
23
24 #include "common.h"
25 #include "dict.h"
26 #include "policer.h"
27
28 #define MODE_CHANOP 0x00000001 /* +o USER */
29 #define MODE_VOICE 0x00000002 /* +v USER */
30 #define MODE_PRIVATE 0x00000004 /* +p */
31 #define MODE_SECRET 0x00000008 /* +s */
32 #define MODE_MODERATED 0x00000010 /* +m */
33 #define MODE_TOPICLIMIT 0x00000020 /* +t */
34 #define MODE_INVITEONLY 0x00000040 /* +i */
35 #define MODE_NOPRIVMSGS 0x00000080 /* +n */
36 #define MODE_KEY 0x00000100 /* +k KEY */
37 #define MODE_BAN 0x00000200 /* +b BAN */
38 #define MODE_LIMIT 0x00000400 /* +l LIMIT */
39 #define MODE_DELAYJOINS 0x00000800 /* +D */
40 #define MODE_REGONLY 0x00001000 /* ircu +r */
41 #define MODE_NOCOLORS 0x00002000 /* +c */
42 #define MODE_NOCTCPS 0x00004000 /* +C */
43 #define MODE_REGISTERED 0x00008000 /* Bahamut +r */
44 #define MODE_STRIPCOLOR 0x00010000 /* +S Strip mirc color codes */
45 #define MODE_MODUNREG 0x00020000 /* +M mod unregister */
46 #define MODE_NONOTICE 0x00040000 /* +N no notices */
47 #define MODE_OPERSONLY 0x00080000 /* +O Opers only */
48 #define MODE_NOQUITMSGS 0x00100000 /* +Q suppress messages from quit notices */
49 #define MODE_NOAMSG 0x00200000 /* +T no multi-target messages */
50 #define MODE_SSLONLY 0x00400000 /* +Z ssl only */
51 #define MODE_HALFOP 0x00800000 /* +h USER */
52 #define MODE_EXEMPT 0x01000000 /* +e exempt */
53 #define MODE_HIDEMODE 0x02000000 /* +L hide modes */
54 #define MODE_APASS 0x04000000 /* +A adminpass */
55 #define MODE_UPASS 0x08000000 /* +U userpass */
56 #define MODE_ADMINSONLY 0x10000000 /* +a Admins only */
57 #define MODE_REMOVE 0x80000000
58
59 #define FLAGS_OPER 0x00000001 /* Operator +o */
60 #define FLAGS_LOCOP 0x00000002 /* Local operator +O */
61 #define FLAGS_INVISIBLE 0x00000004 /* invisible +i */
62 #define FLAGS_WALLOP 0x00000008 /* receives wallops +w */
63 #define FLAGS_DUMMY 0x00000010 /* user is not announced to other servers */
64 #define FLAGS_DEAF 0x00000020 /* deaf +d */
65 #define FLAGS_SERVICE 0x00000040 /* cannot be kicked, killed or deoped +k */
66 #define FLAGS_GLOBAL 0x00000080 /* receives global messages +g */
67 #define FLAGS_SETHOST 0x00000100 /* sethost +h */
68 #define FLAGS_PERSISTENT 0x00000200 /* for reserved nicks, this isn't just one-shot */
69 #define FLAGS_GAGGED 0x00000400 /* for gagged users */
70 #define FLAGS_AWAY 0x00000800 /* for away users */
71 #define FLAGS_STAMPED 0x00001000 /* for users who have been stamped */
72 #define FLAGS_HIDDEN_HOST 0x00002000 /* user's host is masked by their account +x */
73 #define FLAGS_REGNICK 0x00004000 /* user owns their current nick */
74 #define FLAGS_REGISTERING 0x00008000 /* user has issued account register command, is waiting for email cookie */
75 #define FLAGS_BOT 0x00010000 /* Bot +B */
76 #define FLAGS_HIDECHANS 0x00020000 /* Hidden channels +n */
77 #define FLAGS_HIDEIDLE 0x00040000 /* Hidden idle time +I */
78 #define FLAGS_XTRAOP 0x00080000 /* user is XtraOP +X */
79 #define FLAGS_CLOAKHOST 0x00100000 /* user has cloaked host +C */
80 #define FLAGS_CLOAKIP 0x00200000 /* user has cloaked ip +c */
81 #define FLAGS_ADMIN 0x00400000 /* Admin +a */
82 #define FLAGS_SSL 0x00800000 /* user is using a secure connection +z */
83 #define FLAGS_PRIVDEAF 0x01000000 /* user is deaf to private messages +D */
84 #define FLAGS_ACCOUNTONLY 0x02000000 /* user only receives PMs from authed users +R */
85 #define FLAGS_WHOIS 0x04000000 /* user receives notices when /whois'ed +W */
86 #define FLAGS_HIDEOPER 0x08000000 /* user is a hidden IRCop +H */
87 #define FLAGS_NOLINK 0x10000000 /* user has opted out of channel redirection +L */
88 #define FLAGS_COMMONCHANSONLY 0x20000000 /* user only receives PMs from users on same cahnnels +q */
89
90 #define IsOper(x) ((x)->modes & FLAGS_OPER)
91 #define IsService(x) ((x)->modes & FLAGS_SERVICE)
92 #define IsDeaf(x) ((x)->modes & FLAGS_DEAF)
93 #define IsInvisible(x) ((x)->modes & FLAGS_INVISIBLE)
94 #define IsGlobal(x) ((x)->modes & FLAGS_GLOBAL)
95 #define IsWallOp(x) ((x)->modes & FLAGS_WALLOP)
96 #define IsBotM(x) ((x)->modes & FLAGS_BOT)
97 #define IsHideChans(x) ((x)->modes & FLAGS_HIDECHANS)
98 #define IsHideIdle(x) ((x)->modes & FLAGS_HIDEIDLE)
99 #define IsXtraOp(x) ((x)->modes & FLAGS_XTRAOP)
100 #define IsSetHost(x) ((x)->modes & FLAGS_SETHOST)
101 #define IsGagged(x) ((x)->modes & FLAGS_GAGGED)
102 #define IsPersistent(x) ((x)->modes & FLAGS_PERSISTENT)
103 #define IsAway(x) ((x)->modes & FLAGS_AWAY)
104 #define IsStamped(x) ((x)->modes & FLAGS_STAMPED)
105 #define IsHiddenHost(x) ((x)->modes & FLAGS_HIDDEN_HOST)
106 #define IsReggedNick(x) ((x)->modes & FLAGS_REGNICK)
107 #define IsRegistering(x) ((x)->modes & FLAGS_REGISTERING)
108 #define IsDummy(x) ((x)->modes & FLAGS_DUMMY)
109 #define IsFakeHost(x) ((x)->fakehost[0] != '\0')
110 #define IsLocal(x) ((x)->uplink == self)
111 #define IsAdmin(x) ((x)->modes & FLAGS_ADMIN)
112 #define IsSSL(x) ((x)->modes & FLAGS_SSL)
113 #define IsPrivDeaf(x) ((x)->modes & FLAGS_PRIVDEAF)
114 #define IsAccountOnly(x) ((x)->modes & FLAGS_ACCOUNTONLY)
115 #define IsWhoisNotice(x) ((x)->modes & FLAGS_WHOIS)
116 #define IsHideOper(x) ((x)->modes & FLAGS_HIDEOPER)
117 #define IsNoRedirect(x) ((x)->modes & FLAGS_NOLINK)
118 #define IsCommonChansOnly(x) ((x)->modes & FLAGS_COMMONCHANSONLY)
119
120 #define NICKLEN 30
121 #define USERLEN 10
122 #define HOSTLEN 75
123 #define SOCKIPLEN 45
124 #define ACCOUNTLEN 15
125 #define REALLEN 50
126 #define TOPICLEN 250
127 #define CHANNELLEN 200
128 #define MARKLEN 200
129 #define MAXOPLEVEL 999
130
131 #define MAXMODEPARAMS 6
132 #define MAXBANS 128
133 #define MAXEXEMPTS 45
134
135 /* IDLEN is 6 because it takes 5.33 Base64 digits to store 32 bytes. */
136 #define IDLEN 6
137
138 /** Operator privileges. */
139 enum Priv {
140 PRIV_CHAN_LIMIT, /**< no channel limit on oper */
141 PRIV_MODE_LCHAN, /**< oper can mode local chans */
142 PRIV_WALK_LCHAN, /**< oper can walk through local modes */
143 PRIV_DEOP_LCHAN, /**< no deop oper on local chans */
144 PRIV_SHOW_INVIS, /**< show local invisible users */
145 PRIV_SHOW_ALL_INVIS, /**< show all invisible users */
146 PRIV_UNLIMIT_QUERY, /**< unlimit who queries */
147 PRIV_KILL, /**< oper can KILL */
148 PRIV_LOCAL_KILL, /**< oper can local KILL */
149 PRIV_REHASH, /**< oper can REHASH */
150 PRIV_REMOTEREHASH, /**< oper can remote REHASH */
151 PRIV_RESTART, /**< oper can RESTART */
152 PRIV_DIE, /**< oper can DIE */
153 PRIV_ZLINE, /**< oper can ZLINE */
154 PRIV_LOCAL_ZLINE, /**< oper can local ZLINE */
155 PRIV_GLINE, /**< oper can GLINE */
156 PRIV_LOCAL_GLINE, /**< oper can local GLINE */
157 PRIV_SHUN, /**< oper can SHUN */
158 PRIV_LOCAL_SHUN, /**< oper can local SHUN */
159 PRIV_JUPE, /**< oper can JUPE */
160 PRIV_LOCAL_JUPE, /**< oper can local JUPE */
161 PRIV_OPMODE, /**< oper can OP/CLEARMODE */
162 PRIV_LOCAL_OPMODE, /**< oper can local OP/CLEARMODE */
163 PRIV_SET, /**< oper can SET */
164 PRIV_WHOX, /**< oper can use /who x */
165 PRIV_BADCHAN, /**< oper can BADCHAN */
166 PRIV_LOCAL_BADCHAN, /**< oper can local BADCHAN */
167 PRIV_SEE_CHAN, /**< oper can see in secret chans */
168 PRIV_PROPAGATE, /**< propagate oper status */
169 PRIV_DISPLAY, /**< "Is an oper" displayed */
170 PRIV_DISPLAY_MODE, /**< oper can set +H hide oper */
171 PRIV_SEE_OPERS, /**< display hidden opers */
172 PRIV_WIDE_GLINE, /**< oper can set wider G-lines */
173 PRIV_WIDE_ZLINE, /**< oper can set wider Z-Lines */
174 PRIV_WIDE_SHUN, /**< oper can set wider G-lines */
175 PRIV_LIST_CHAN, /**< oper can list secret channels */
176 PRIV_FORCE_OPMODE, /**< can hack modes on quarantined channels */
177 PRIV_FORCE_LOCAL_OPMODE, /**< can hack modes on quarantined local channels */
178 PRIV_CHECK, /**< oper can use CHECK */
179 PRIV_SEE_SECRET_CHAN, /**< oper can see +s channels in whois */
180 PRIV_WHOIS_NOTICE, /**< oper can set/unset user mode +W */
181 PRIV_HIDE_IDLE, /**< oper can set/unset user mode +I */
182 PRIV_XTRAOP, /**< oper can set/unset user mode +X */
183 PRIV_HIDE_CHANNELS, /**< oper can set/unset user mode +n */
184 PRIV_FREEFORM, /**< oper can set any host on themseves using set host
185 as long as its a valid host */
186 PRIV_REMOVE, /**< oper can force remove deactivated glines,
187 shuns and zlines. */
188 PRIV_SPAMFILTER, /**< oper can set spamfilters via SPAMFILTER */
189 PRIV_LAST_PRIV /**< number of privileges */
190 };
191
192 /** Number of bits */
193 #define _PRIV_NBITS (8 * sizeof(unsigned long))
194 /** Element number for priv \a priv. */
195 #define _PRIV_IDX(priv) ((priv) / _PRIV_NBITS)
196 /** Element bit for priv \a priv. */
197 #define _PRIV_BIT(priv) (1UL << ((priv) % _PRIV_NBITS))
198
199 /** Operator privileges. */
200 struct Privs {
201 unsigned long priv_mask[(PRIV_LAST_PRIV + _PRIV_NBITS - 1) / _PRIV_NBITS];
202 };
203
204 DECLARE_LIST(userList, struct userNode*);
205 DECLARE_LIST(modeList, struct modeNode*);
206 DECLARE_LIST(banList, struct banNode*);
207 DECLARE_LIST(exemptList, struct exemptNode*);
208 DECLARE_LIST(channelList, struct chanNode*);
209 DECLARE_LIST(serverList, struct server*);
210
211 struct userNode {
212 char *nick; /* Unique name of the client, nick or host */
213 char ident[USERLEN + 1]; /* Per-host identification for user */
214 char info[REALLEN + 1]; /* Free form additional client information */
215 char hostname[HOSTLEN + 1]; /* DNS name or IP address */
216 char fakehost[HOSTLEN + 1]; /* Assigned fake host */
217 char crypthost[HOSTLEN + 30]; /* Crypted hostname */
218 char cryptip[SOCKIPLEN + 30]; /* Crypted IP */
219 #ifdef WITH_PROTOCOL_P10
220 char numeric[COMBO_NUMERIC_LEN+1];
221 unsigned int num_local : 18;
222 #endif
223 unsigned int loc; /* Is user connecting via LOC? */
224 unsigned int no_notice; /* Does the users client not see notices? */
225 unsigned int dead : 1; /* Is user waiting to be recycled? */
226 irc_in_addr_t ip; /* User's IP address */
227 long modes; /* user flags +isw etc... */
228
229 // sethost - reed/apples
230 char sethost[USERLEN + HOSTLEN + 2]; /* 1 for '\0' and 1 for @ = 2 */
231
232 /* GeoIP Data */
233 char *country_name;
234
235 /* GeoIP City Data */
236 char *country_code;
237 char *city;
238 char *region;
239 char *postal_code;
240 float latitude;
241 float longitude;
242 int dma_code;
243 int area_code;
244
245 char *mark; /* only filled if they are marked */
246 char *version_reply; /* only filled in if a version query was triggered */
247 char *sslfp; /* only filled in if a mark SSLCLIFP is received */
248
249 time_t timestamp; /* Time of last nick change */
250 time_t idle_since;
251 struct server *uplink; /* Server that user is connected to */
252 struct modeList channels; /* Vector of channels user is in */
253 struct Privs privs;
254
255 /* from nickserv */
256 struct handle_info *handle_info;
257 struct userNode *next_authed;
258 struct policer auth_policer;
259 };
260
261 #define privs(cli) ((cli)->privs)
262 #define PrivSet(pset, priv) ((pset)->priv_mask[_PRIV_IDX(priv)] |= \
263 _PRIV_BIT(priv))
264 #define PrivClr(pset, priv) ((pset)->priv_mask[_PRIV_IDX(priv)] &= \
265 ~(_PRIV_BIT(priv)))
266 #define PrivHas(pset, priv) ((pset)->priv_mask[_PRIV_IDX(priv)] & \
267 _PRIV_BIT(priv))
268
269 #define PRIV_ADD 1
270 #define PRIV_DEL 0
271
272 #define GrantPriv(cli, priv) (PrivSet(&(privs(cli)), priv))
273 #define RevokePriv(cli, priv) (PrivClr(&(privs(cli)), priv))
274 #define HasPriv(cli, priv) (PrivHas(&(privs(cli)), priv))
275
276 struct chanNode {
277 chan_mode_t modes;
278 unsigned int limit, locks;
279 char key[KEYLEN + 1];
280 char upass[KEYLEN + 1];
281 char apass[KEYLEN + 1];
282 time_t timestamp; /* creation time */
283
284 char topic[TOPICLEN + 1];
285 char topic_nick[NICKLEN + 1];
286 time_t topic_time;
287
288 struct modeList members;
289 struct banList banlist;
290 struct exemptList exemptlist;
291 struct policer join_policer;
292 unsigned int join_flooded : 1;
293 unsigned int bad_channel : 1;
294
295 struct chanData *channel_info;
296 struct channel_help *channel_help;
297 char name[1];
298 };
299
300 struct banNode {
301 char ban[NICKLEN + USERLEN + HOSTLEN + 3]; /* 1 for '\0', 1 for ! and 1 for @ = 3 */
302 char who[NICKLEN + 1]; /* who set ban */
303 time_t set; /* time ban was set */
304 };
305
306 struct exemptNode {
307 char exempt[NICKLEN + USERLEN + HOSTLEN + 3]; /* 1 for '\0', 1 for ! and 1 for @ = 3 */
308 char who[NICKLEN + 1]; /* who set exempt */
309 time_t set; /* time exempt was set */
310 };
311
312 struct modeNode {
313 struct chanNode *channel;
314 struct userNode *user;
315 long modes;
316 short oplevel;
317 time_t idle_since;
318 };
319
320 #define SERVERNAMEMAX 64
321 #define SERVERDESCRIPTMAX 128
322
323 struct server {
324 char name[SERVERNAMEMAX+1];
325 time_t boot;
326 time_t link_time;
327 char description[SERVERDESCRIPTMAX+1];
328 #ifdef WITH_PROTOCOL_P10
329 char numeric[COMBO_NUMERIC_LEN+1];
330 unsigned int num_mask;
331 #endif
332 unsigned int hops, clients, max_clients;
333 unsigned int burst : 1, self_burst : 1;
334 struct server *uplink;
335 #ifdef WITH_PROTOCOL_P10
336 struct userNode **users; /* flat indexed by numeric */
337 #else
338 dict_t users; /* indexed by nick */
339 #endif
340 struct serverList children;
341 };
342
343 struct waitingConnection {
344 char *server;
345 char *target;
346 };
347
348 struct routingPlan {
349 dict_t servers;
350 };
351
352 struct routingPlanServer {
353 char *uplink;
354 char *secondaryuplink;
355 unsigned int port;
356 int karma;
357 int offline;
358 };
359
360 /* Ported from X2 */
361 struct routeList {
362 char* server; /* Name of the server */
363 unsigned int port; /* connection port */
364 char *uplink; /* Server its linked to (towards us) */
365 char *secondaryuplink;
366 int outsideness; /* 0 means leaf, 1 second layer, etc. my uplink is highest */
367 struct routeList *next;
368 };
369
370 /* Ported from X2 */
371 struct route {
372 int count; /* how many servers we have */
373 int maxdepth; /* biggest outsideness value */
374 int centered; /* set to TRUE when changerouteUplinks is run */
375 struct routeList *servers;
376 };
377
378
379 extern struct server *self;
380 extern dict_t channels;
381 extern dict_t clients;
382 extern dict_t servers;
383 extern unsigned int max_clients, invis_clients;
384 extern time_t max_clients_time;
385 extern struct userList curr_opers, curr_helpers;
386
387 struct server* GetServerH(const char *name); /* using full name */
388 struct userNode* GetUserH(const char *nick); /* using nick */
389 struct chanNode* GetChannel(const char *name);
390 struct modeNode* GetUserMode(struct chanNode* channel, struct userNode* user);
391 int userList_contains(struct userList *list, struct userNode *user);
392 unsigned int IsUserP(struct userNode *user);
393
394 typedef int (*server_link_func_t) (struct server *server, void *extra);
395 void reg_server_link_func(server_link_func_t handler, void *extra);
396 void call_server_link_funcs(struct server *server);
397
398 typedef void (*sasl_input_func_t) (struct server* source ,const char *identifier, const char *subcmd, const char *data, const char *ext, void *extra);
399 void reg_sasl_input_func(sasl_input_func_t handler, void *extra);
400 void call_sasl_input_func(struct server* source ,const char *identifier, const char *subcmd, const char *data, const char *ext);
401 void unreg_sasl_input_func(sasl_input_func_t handler, void *extra);
402
403 typedef int (*new_user_func_t) (struct userNode *user, void *extra);
404 void reg_new_user_func(new_user_func_t handler, void *extra);
405 void call_new_user_funcs(struct userNode *user);
406 typedef void (*del_user_func_t) (struct userNode *user, struct userNode *killer, const char *why, void *extra);
407 void reg_del_user_func(del_user_func_t handler, void *extra);
408 void call_del_user_funcs(struct userNode *user, struct userNode *killer, const char *why);
409 void unreg_del_user_func(del_user_func_t handler, void *extra);
410 void ReintroduceUser(struct userNode* user);
411 typedef void (*nick_change_func_t)(struct userNode *user, const char *old_nick, void *extra);
412 void reg_nick_change_func(nick_change_func_t handler, void *extra);
413 void NickChange(struct userNode* user, const char *new_nick, int no_announce);
414 void SVSNickChange(struct userNode* user, const char *new_nick);
415
416 typedef void (*account_func_t) (struct userNode *user, const char *stamp);
417 void reg_account_func(account_func_t handler);
418 void call_account_func(struct userNode *user, const char *stamp);
419 void StampUser(struct userNode *user, const char *stamp, time_t timestamp);
420 void assign_fakehost(struct userNode *user, const char *host, int announce);
421 void set_geoip_info(struct userNode *user);
422
423 typedef void (*new_channel_func_t) (struct chanNode *chan, void *extra);
424 void reg_new_channel_func(new_channel_func_t handler, void *extra);
425 typedef int (*join_func_t) (struct modeNode *mNode, void *extra);
426 void reg_join_func(join_func_t handler, void *extra);
427 typedef void (*del_channel_func_t) (struct chanNode *chan, void *extra);
428 void reg_del_channel_func(del_channel_func_t handler, void *extra);
429
430 struct chanNode* AddChannel(const char *name, time_t time_, const char *modes, char *banlist, char *exemptlist);
431 void LockChannel(struct chanNode *channel);
432 void UnlockChannel(struct chanNode *channel);
433
434 struct modeNode* AddChannelUser(struct userNode* user, struct chanNode* channel);
435
436 typedef void (*part_func_t) (struct modeNode *mn, const char *reason, void *extra);
437 void reg_part_func(part_func_t handler, void *extra);
438 void unreg_part_func(part_func_t handler, void *extra);
439 void DelChannelUser(struct userNode* user, struct chanNode* channel, const char *reason, int deleting);
440 void KickChannelUser(struct userNode* target, struct chanNode* channel, struct userNode *kicker, const char *why);
441
442 typedef void (*kick_func_t) (struct userNode *kicker, struct userNode *user, struct chanNode *chan, void *extra);
443 void reg_kick_func(kick_func_t handler, void *extra);
444 void ChannelUserKicked(struct userNode* kicker, struct userNode* victim, struct chanNode* channel);
445
446 int ChannelBanExists(struct chanNode *channel, const char *ban);
447 int ChannelExemptExists(struct chanNode *channel, const char *exempt);
448
449 typedef int (*topic_func_t)(struct userNode *who, struct chanNode *chan, const char *old_topic, void *extra);
450 void reg_topic_func(topic_func_t handler, void *extra);
451 void SetChannelTopic(struct chanNode *channel, struct userNode *service, struct userNode *user, const char *topic, int announce);
452 struct userNode *IsInChannel(struct chanNode *channel, struct userNode *user);
453
454 void init_structs(void);
455
456 #endif