3 * Top level data structures and function prototypes for the
4 * channel service module
14 #include "../lib/sstring.h"
15 #include "../core/schedule.h"
16 #include "../lib/flags.h"
17 #include "../nick/nick.h"
18 #include "../channel/channel.h"
19 #include "../parser/parser.h"
20 #include "../localuser/localuserchannel.h"
21 #include "../dbapi/dbapi.h"
30 #define QVERSION "1.00"
32 /* Mini-hash of known users on channels to make lookups faster;
33 * how big do we make it? */
34 #define REGCHANUSERHASHSIZE 5
36 #define WELCOMELEN 250
38 #define AUTOLIMIT_INTERVAL 60
39 #define COUNTERSYNCINTERVAL 600
40 #define LINGERTIME 300
41 #define DUMPINTERVAL 300
44 #define CHANOPHISTORY 10
46 /* Suspension and g-line hit count limits */
47 #define MAXGLINEUSERS 50
48 #define MAXSUSPENDHIT 500
50 /* Maximum number of times a user may attempt to auth */
51 #define MAXAUTHATTEMPT 5
53 /* Maximum number of hellos in a session */
56 /* Maximum number of times a user may actually be authed */
57 #define MAXAUTHCOUNT 2
59 /* Maximum number of accounts that may share an email address */
60 #define MD_DEFAULTACTLIMIT 2
62 /* If set will issue warnings when authgate cached stuff changes */
63 #define AUTHGATE_WARNINGS
65 /* Challenge auth faq site */
66 #define CHALLENGEAUTHSITE "http://www.quakenet.org/development/challengeauth/"
69 #define CLEANUP_ACCOUNT_INACTIVE 80
70 #define CLEANUP_ACCOUNT_UNUSED 10
71 #define CLEANUP_CHANNEL_INACTIVE 30
73 /* Sizes of the main hashes */
74 #define REGUSERHASHSIZE 60000
75 #define MAILDOMAINHASHSIZE 60000
77 /* Number of languages and messages */
80 /* Maximum number of user chanlevs and bans */
81 #define MAXCHANLEVS 250
84 /* Sources of entropy and standard length defines */
85 #define ENTROPYSOURCE "/dev/urandom"
88 #include "chanserv_messages.h"
90 /* List of privileged operations */
92 #define QPRIV_SUSPENDBYPASS 1
93 #define QPRIV_VIEWCHANFLAGS 100
94 #define QPRIV_VIEWFULLCHANLEV 101
95 #define QPRIV_VIEWFULLWHOIS 102
96 #define QPRIV_VIEWCHANMODES 103
97 #define QPRIV_VIEWAUTOLIMIT 104
98 #define QPRIV_VIEWBANTIMER 105
99 #define QPRIV_VIEWUSERFLAGS 106
100 #define QPRIV_VIEWWELCOME 107
101 #define QPRIV_VIEWCOMMENTS 108
102 #define QPRIV_VIEWEMAIL 109
104 #define QPRIV_CHANGECHANFLAGS 200
105 #define QPRIV_CHANGECHANLEV 201
106 #define QPRIV_CHANGECHANMODES 202
107 #define QPRIV_CHANGEAUTOLIMIT 203
108 #define QPRIV_CHANGEBANTIMER 204
109 #define QPRIV_CHANGEUSERFLAGS 205
110 #define QPRIV_CHANGEWELCOME 206
112 /* List of access checks */
114 #define CA_AUTHED 0x0001
115 #define CA_TOPICPRIV 0x0008
116 #define CA_KNOWN 0x0010
117 #define CA_VOICEPRIV 0x0020
118 #define CA_OPPRIV 0x0040
119 #define CA_MASTERPRIV 0x0080
120 #define CA_OWNERPRIV 0x0100
122 #define CA_ONCHAN 0x0400
123 #define CA_OFFCHAN 0x0800
124 #define CA_OPPED 0x1000
125 #define CA_DEOPPED 0x2000
126 #define CA_VOICED 0x4000
127 #define CA_DEVOICED 0x8000
129 #define CA_NEEDKNOWN (CA_KNOWN|CA_OPPRIV|CA_MASTERPRIV|CA_TOPICPRIV|CA_OWNERPRIV)
130 #define CA_ONCHANREQ (CA_ONCHAN|CA_OPPED|CA_DEOPPED|CA_VOICED|CA_DEVOICED)
134 #define QUFLAG_NOINFO 0x0001 /* +s */
135 #define QUFLAG_GLINE 0x0002 /* +g */
136 #define QUFLAG_NOTICE 0x0004 /* +n */
137 #define QUFLAG_STAFF 0x0008 /* +q */
138 #define QUFLAG_SUSPENDED 0x0010 /* +z */
139 #define QUFLAG_OPER 0x0020 /* +o */
140 #define QUFLAG_DEV 0x0040 /* +d */
141 #define QUFLAG_PROTECT 0x0080 /* +p */
142 #define QUFLAG_HELPER 0x0100 /* +h */
143 #define QUFLAG_ADMIN 0x0200 /* +a */
144 #define QUFLAG_INFO 0x0400 /* +i */
145 #define QUFLAG_DELAYEDGLINE 0x0800 /* +G */
146 #define QUFLAG_NOAUTHLIMIT 0x1000 /* +L */
147 #define QUFLAG_CLEANUPEXEMPT 0x4000 /* +D */
148 #define QUFLAG_TRUST 0x8000 /* +T */
149 #define QUFLAG_ALL 0xdfff
151 #define UIsNoInfo(x) ((x)->flags & QUFLAG_NOINFO)
152 #define UIsGline(x) ((x)->flags & QUFLAG_GLINE)
153 #define UIsNotice(x) ((x)->flags & QUFLAG_NOTICE)
154 #define UIsSuspended(x) ((x)->flags & QUFLAG_SUSPENDED)
155 #define UIsOper(x) ((x)->flags & QUFLAG_OPER)
156 #define UIsDev(x) ((x)->flags & QUFLAG_DEV)
157 #define UIsProtect(x) ((x)->flags & QUFLAG_PROTECT)
158 #define UIsHelper(x) ((x)->flags & QUFLAG_HELPER)
159 #define UIsAdmin(x) ((x)->flags & QUFLAG_ADMIN)
160 #define UIsInfo(x) ((x)->flags & QUFLAG_INFO)
161 #define UIsDelayedGline(x) ((x)->flags & QUFLAG_DELAYEDGLINE)
162 #define UIsNoAuthLimit(x) ((x)->flags & QUFLAG_NOAUTHLIMIT)
163 #define UIsCleanupExempt(x) ((x)->flags & QUFLAG_CLEANUPEXEMPT)
164 #define UIsStaff(x) ((x)->flags & QUFLAG_STAFF)
166 #define UHasSuspension(x) ((x)->flags & (QUFLAG_GLINE|QUFLAG_DELAYEDGLINE|QUFLAG_SUSPENDED))
168 #define UHasStaffPriv(x) ((x)->flags * (QUFLAG_STAFF | QUFLAG_HELPER | QUFLAG_OPER | QUFLAG_ADMIN | QUFLAG_DEV))
169 #define UHasHelperPriv(x) ((x)->flags & (QUFLAG_HELPER | QUFLAG_OPER | QUFLAG_ADMIN | QUFLAG_DEV))
170 #define UHasOperPriv(x) ((x)->flags & (QUFLAG_OPER | QUFLAG_ADMIN | QUFLAG_DEV))
171 #define UHasAdminPriv(x) ((x)->flags & (QUFLAG_ADMIN | QUFLAG_DEV))
173 #define USetGline(x) ((x)->flags |= QUFLAG_GLINE)
174 #define USetNotice(x) ((x)->flags |= QUFLAG_NOTICE)
175 #define USetSuspended(x) ((x)->flags |= QUFLAG_SUSPENDED)
176 #define USetOper(x) ((x)->flags |= QUFLAG_OPER)
177 #define USetDev(x) ((x)->flags |= QUFLAG_DEV)
178 #define USetProtect(x) ((x)->flags |= QUFLAG_PROTECT)
179 #define USetHelper(x) ((x)->flags |= QUFLAG_HELPER)
180 #define USetAdmin(x) ((x)->flags |= QUFLAG_ADMIN)
181 #define USetInfo(x) ((x)->flags |= QUFLAG_INFO)
182 #define USetDelayedGline(x) ((x)->flags |= QUFLAG_DELAYEDGLINE)
183 #define USetNoAuthLimit(x) ((x)->flags |= QUFLAG_NOAUTHLIMIT)
184 #define USetCleanupExempt(x) ((x)->flags |= QUFLAG_CLEANUPEXEMPT)
185 #define USetTrust(x) ((x)->flags |= QUFLAG_TRUST)
187 #define UClearGline(x) ((x)->flags &= ~QUFLAG_GLINE)
188 #define UClearNotice(x) ((x)->flags &= ~QUFLAG_NOTICE)
189 #define UClearSuspended(x) ((x)->flags &= ~QUFLAG_SUSPENDED)
190 #define UClearOper(x) ((x)->flags &= ~QUFLAG_OPER)
191 #define UClearDev(x) ((x)->flags &= ~QUFLAG_DEV)
192 #define UClearProtect(x) ((x)->flags &= ~QUFLAG_PROTECT)
193 #define UClearHelper(x) ((x)->flags &= ~QUFLAG_HELPER)
194 #define UClearAdmin(x) ((x)->flags &= ~QUFLAG_ADMIN)
195 #define UClearInfo(x) ((x)->flags &= ~QUFLAG_INFO)
196 #define UClearDelayedGline(x) ((x)->flags &= ~QUFLAG_DELAYEDGLINE)
197 #define UClearNoAuthLimit(x) ((x)->flags &= ~QUFLAG_NOAUTHLIMIT)
198 #define UClearCleanupExempt(x) ((x)->flags &= ~QUFLAG_CLEANUPEXEMPT)
199 #define UClearTrust(x) ((x)->flags &= ~QUFLAG_TRUST)
202 #define MAX_RESEND_TIME 2*3600L /* cooling off period */
203 #define VALID_EMAIL "^[-_.+[:alpha:][:digit:]]+(\\.[-_[:digit:][:alpha:]]+)*@([[:digit:][:alpha:]](-?[[:digit:][:alpha:]])*\\.)+[[:alpha:]]{2}([zmuvtgo]|fo|me|seum|op|ro)?$"
205 #define VALID_ACCOUNT_NAME "^[-a-z0-9]*$"
207 #define QMAIL_NEWACCOUNT 1 /* new account */
208 #define QMAIL_REQPW 2 /* requestpassword */
209 #define QMAIL_NEWPW 3 /* new password */
210 #define QMAIL_RESET 4 /* reset account */
211 #define QMAIL_NEWEMAIL 5 /* new email address */
215 #define QCFLAG_AUTOOP 0x0001 /* +a */
216 #define QCFLAG_BITCH 0x0002 /* +b */
217 #define QCFLAG_AUTOLIMIT 0x0004 /* +c */
218 #define QCFLAG_ENFORCE 0x0008 /* +e */
219 #define QCFLAG_FORCETOPIC 0x0010 /* +f */
220 #define QCFLAG_AUTOVOICE 0x0020 /* +g */
221 #define QCFLAG_INFO 0x0040 /* +i */
222 #define QCFLAG_JOINED 0x0080 /* +j */
223 #define QCFLAG_KNOWNONLY 0x0100 /* +k */
224 #define QCFLAG_PROTECT 0x0200 /* +p */
225 #define QCFLAG_NOINFO 0x0400 /* +s */
226 #define QCFLAG_TOPICSAVE 0x0800 /* +t */
227 #define QCFLAG_VOICEALL 0x1000 /* +v */
228 #define QCFLAG_WELCOME 0x2000 /* +w */
229 #define QCFLAG_SUSPENDED 0x4000 /* +z */
231 #define CIsAutoOp(x) ((x)->flags & QCFLAG_AUTOOP)
232 #define CIsBitch(x) ((x)->flags & QCFLAG_BITCH)
233 #define CIsAutoLimit(x) ((x)->flags & QCFLAG_AUTOLIMIT)
234 #define CIsEnforce(x) ((x)->flags & QCFLAG_ENFORCE)
235 #define CIsForceTopic(x) ((x)->flags & QCFLAG_FORCETOPIC)
236 #define CIsAutoVoice(x) ((x)->flags & QCFLAG_AUTOVOICE)
237 #define CIsJoined(x) ((x)->flags & QCFLAG_JOINED)
238 #define CIsKnownOnly(x) ((x)->flags & QCFLAG_KNOWNONLY)
239 #define CIsProtect(x) ((x)->flags & QCFLAG_PROTECT)
240 #define CIsTopicSave(x) ((x)->flags & QCFLAG_TOPICSAVE)
241 #define CIsVoiceAll(x) ((x)->flags & QCFLAG_VOICEALL)
242 #define CIsWelcome(x) ((x)->flags & QCFLAG_WELCOME)
243 #define CIsSuspended(x) ((x)->flags & QCFLAG_SUSPENDED)
244 #define CIsInfo(x) ((x)->flags & QCFLAG_INFO)
245 #define CIsNoInfo(x) ((x)->flags & QCFLAG_NOINFO)
247 #define CSetAutoOp(x) ((x)->flags |= QCFLAG_AUTOOP)
248 #define CSetBitch(x) ((x)->flags |= QCFLAG_BITCH)
249 #define CSetAutoLimit(x) ((x)->flags |= QCFLAG_AUTOLIMIT)
250 #define CSetEnforce(x) ((x)->flags |= QCFLAG_ENFORCE)
251 #define CSetForceTopic(x) ((x)->flags |= QCFLAG_FORCETOPIC)
252 #define CSetAutoVoice(x) ((x)->flags |= QCFLAG_AUTOVOICE)
253 #define CSetJoined(x) ((x)->flags |= QCFLAG_JOINED)
254 #define CSetKnownOnly(x) ((x)->flags |= QCFLAG_KNOWNONLY)
255 #define CSetProtect(x) ((x)->flags |= QCFLAG_PROTECT)
256 #define CSetTopicSave(x) ((x)->flags |= QCFLAG_TOPICSAVE)
257 #define CSetVoiceAll(x) ((x)->flags |= QCFLAG_VOICEALL)
258 #define CSetWelcome(x) ((x)->flags |= QCFLAG_WELCOME)
259 #define CSetSuspended(x) ((x)->flags |= QCFLAG_SUSPENDED)
261 #define CClearAutoOp(x) ((x)->flags &= ~QCFLAG_AUTOOP)
262 #define CClearBitch(x) ((x)->flags &= ~QCFLAG_BITCH)
263 #define CClearAutoLimit(x) ((x)->flags &= ~QCFLAG_AUTOLIMIT)
264 #define CClearEnforce(x) ((x)->flags &= ~QCFLAG_ENFORCE)
265 #define CClearForceTopic(x) ((x)->flags &= ~QCFLAG_FORCETOPIC)
266 #define CClearAutoVoice(x) ((x)->flags &= ~QCFLAG_AUTOVOICE)
267 #define CClearJoined(x) ((x)->flags &= ~QCFLAG_JOINED)
268 #define CClearKnownOnly(x) ((x)->flags &= ~QCFLAG_KNOWNONLY)
269 #define CClearProtect(x) ((x)->flags &= ~QCFLAG_PROTECT)
270 #define CClearTopicSave(x) ((x)->flags &= ~QCFLAG_TOPICSAVE)
271 #define CClearVoiceAll(x) ((x)->flags &= ~QCFLAG_VOICEALL)
272 #define CClearWelcome(x) ((x)->flags &= ~QCFLAG_WELCOME)
273 #define CClearSuspended(x) ((x)->flags &= ~QCFLAG_SUSPENDED)
275 #define QCFLAG_USERCONTROL (QCFLAG_AUTOOP|QCFLAG_BITCH|QCFLAG_AUTOLIMIT| \
276 QCFLAG_ENFORCE|QCFLAG_FORCETOPIC|QCFLAG_AUTOVOICE| \
277 QCFLAG_PROTECT|QCFLAG_TOPICSAVE|QCFLAG_VOICEALL| \
278 QCFLAG_WELCOME|QCFLAG_KNOWNONLY)
280 #define QCFLAG_ALL 0x7fff
283 /* Channel user ("chanlev") flags */
284 /* Slightly funny order here: list the "biggest" flags at the
285 * top so we can do sorted "chanlev" output more easily */
286 #define QCUFLAG_OWNER 0x8000 /* +n */
287 #define QCUFLAG_MASTER 0x4000 /* +m */
288 #define QCUFLAG_OP 0x2000 /* +o */
289 #define QCUFLAG_VOICE 0x1000 /* +v */
290 #define QCUFLAG_AUTOOP 0x0001 /* +a */
291 #define QCUFLAG_BANNED 0x0002 /* +b */
292 #define QCUFLAG_DENY 0x0004 /* +d */
293 #define QCUFLAG_AUTOVOICE 0x0008 /* +g */
294 #define QCUFLAG_QUIET 0x0010 /* +q */
295 #define QCUFLAG_NOINFO 0x0020 /* +s */
296 #define QCUFLAG_TOPIC 0x0040 /* +t */
297 #define QCUFLAG_HIDEWELCOME 0x0080 /* +w */
298 #define QCUFLAG_PROTECT 0x0100 /* +p */
299 #define QCUFLAG_INFO 0x0200 /* +i */
300 #define QCUFLAG_KNOWN 0x0400 /* +k */
301 #define QCUFLAG_AUTOINVITE 0x0800 /* +j */
303 #define QCUFLAG_SIGNIFICANT (QCUFLAG_MASTER|QCUFLAG_OWNER|QCUFLAG_OP)
305 #define QCUFLAG_MASTERCON (QCUFLAG_AUTOOP|QCUFLAG_BANNED|QCUFLAG_DENY| \
306 QCUFLAG_GIVE|QCUFLAG_OP|QCUFLAG_QUIET|QCUFLAG_TOPIC| \
307 QCUFLAG_VOICE|QCUFLAG_PROTECT)
309 #define QCUFLAG_SELFCON (QCUFLAG_OP | QCUFLAG_VOICE | QCUFLAG_AUTOOP | QCUFLAG_AUTOVOICE | \
310 QCUFLAG_TOPIC | QCUFLAG_INFO)
312 #define QCUFLAGS_PUBLIC (QCUFLAG_OWNER | QCUFLAG_MASTER | QCUFLAG_OP | QCUFLAG_VOICE | \
313 QCUFLAG_KNOWN | QCUFLAG_AUTOOP | QCUFLAG_AUTOVOICE | QCUFLAG_TOPIC | \
316 #define QCUFLAGS_PUNISH (QCUFLAG_BANNED | QCUFLAG_QUIET | QCUFLAG_DENY)
317 #define QCUFLAGS_PERSONAL (QCUFLAG_HIDEWELCOME | QCUFLAG_AUTOINVITE)
319 #define QCUFLAG_ALL 0xffff
321 #define CUIsOwner(x) ((x)->flags & QCUFLAG_OWNER)
322 #define CUIsMaster(x) ((x)->flags & QCUFLAG_MASTER)
323 #define CUIsOp(x) ((x)->flags & QCUFLAG_OP)
324 #define CUIsVoice(x) ((x)->flags & QCUFLAG_VOICE)
325 #define CUIsAutoOp(x) ((x)->flags & QCUFLAG_AUTOOP)
326 #define CUIsBanned(x) ((x)->flags & QCUFLAG_BANNED)
327 #define CUIsDeny(x) ((x)->flags & QCUFLAG_DENY)
328 #define CUIsAutoVoice(x) ((x)->flags & QCUFLAG_AUTOVOICE)
329 #define CUIsQuiet(x) ((x)->flags & QCUFLAG_QUIET)
330 #define CUIsNoInfo(x) ((x)->flags & QCUFLAG_NOINFO)
331 #define CUIsTopic(x) ((x)->flags & QCUFLAG_TOPIC)
332 #define CUIsHideWelcome(x) ((x)->flags & QCUFLAG_HIDEWELCOME)
333 #define CUIsProtect(x) ((x)->flags & QCUFLAG_PROTECT)
334 #define CUIsInfo(x) ((x)->flags & QCUFLAG_INFO)
335 #define CUIsKnown(x) ((x)->flags & QCUFLAG_KNOWN)
336 #define CUIsAutoInvite(x) ((x)->flags & QCUFLAG_AUTOINVITE)
338 #define CUKnown(x) (CUIsKnown(x) || CUHasVoicePriv(x))
339 #define CUHasVoicePriv(x) ((x)->flags & (QCUFLAG_VOICE | QCUFLAG_OP | QCUFLAG_MASTER | QCUFLAG_OWNER))
340 #define CUHasOpPriv(x) ((x)->flags & (QCUFLAG_OP | QCUFLAG_MASTER | QCUFLAG_OWNER))
341 #define CUHasMasterPriv(x) ((x)->flags & (QCUFLAG_MASTER | QCUFLAG_OWNER))
342 #define CUHasTopicPriv(x) ((x)->flags & (QCUFLAG_MASTER | QCUFLAG_OWNER | QCUFLAG_TOPIC))
344 #define CUSetOwner(x) ((x)->flags |= QCUFLAG_OWNER)
345 #define CUSetMaster(x) ((x)->flags |= QCUFLAG_MASTER)
346 #define CUSetOp(x) ((x)->flags |= QCUFLAG_OP)
347 #define CUSetVoice(x) ((x)->flags |= QCUFLAG_VOICE)
348 #define CUSetAutoOp(x) ((x)->flags |= QCUFLAG_AUTOOP)
349 #define CUSetBanned(x) ((x)->flags |= QCUFLAG_BANNED)
350 #define CUSetDeny(x) ((x)->flags |= QCUFLAG_DENY)
351 #define CUSetAutoVoice(x) ((x)->flags |= QCUFLAG_AUTOVOICE)
352 #define CUSetQuiet(x) ((x)->flags |= QCUFLAG_QUIET)
353 #define CUSetTopic(x) ((x)->flags |= QCUFLAG_TOPIC)
354 #define CUSetHideWelcome(x) ((x)->flags |= QCUFLAG_HIDEWELCOME)
355 #define CUSetKnown(x) ((x)->flags |= QCUFLAG_KNOWN)
356 #define CUSetAutoInvite(x) ((x)->flags |= QCUFLAG_AUTOINVITE)
358 #define CUClearOwner(x) ((x)->flags &= ~QCUFLAG_OWNER)
359 #define CUClearMaster(x) ((x)->flags &= ~QCUFLAG_MASTER)
360 #define CUClearOp(x) ((x)->flags &= ~QCUFLAG_OP)
361 #define CUClearVoice(x) ((x)->flags &= ~QCUFLAG_VOICE)
362 #define CUClearAutoOp(x) ((x)->flags &= ~QCUFLAG_AUTOOP)
363 #define CUClearBanned(x) ((x)->flags &= ~QCUFLAG_BANNED)
364 #define CUClearDeny(x) ((x)->flags &= ~QCUFLAG_DENY)
365 #define CUClearAutoVoice(x) ((x)->flags &= ~QCUFLAG_AUTOVOICE)
366 #define CUClearQuiet(x) ((x)->flags &= ~QCUFLAG_QUIET)
367 #define CUClearTopic(x) ((x)->flags &= ~QCUFLAG_TOPIC)
368 #define CUClearHideWelcome(x) ((x)->flags &= ~QCUFLAG_HIDEWELCOME)
369 #define CUClearKnown(x) ((x)->flags &= ~QCUFLAG_KNOWN)
370 #define CUClearAutoInvite(x) ((x)->flags &= ~QCUFLAG_AUTOINVITE)
372 #define QCSTAT_OPCHECK 0x0001 /* Do op check */
373 #define QCSTAT_MODECHECK 0x0002 /* Do mode check */
374 #define QCSTAT_BANCHECK 0x0004 /* Do ban check */
376 #define QUSTAT_DEAD 0x8000 /* User has been deleted.. */
378 #define QCMD_SECURE 0x0001 /* Must use "user@server" to use this command */
379 #define QCMD_AUTHED 0x0002 /* Only available to authed users */
380 #define QCMD_NOTAUTHED 0x0004 /* Only available to NON-authed users */
382 #define QCMD_HELPER 0x0010 /* Only available to helpers */
383 #define QCMD_OPER 0x0020 /* Only available to opers */
384 #define QCMD_ADMIN 0x0040 /* Only available to admins */
385 #define QCMD_DEV 0x0080 /* Only available to developers */
387 #define QCMD_ALIAS 0x0100 /* Don't list on SHOWCOMMANDS */
389 #define CS_INIT_DB 0x1 /* Loading database.. */
390 #define CS_INIT_NOUSER 0x2 /* Loaded DB, waiting for user to be created */
391 #define CS_INIT_READY 0x3 /* Ready for action! */
396 typedef struct maildomain
{
398 unsigned int maildomain_magic
;
404 unsigned int actlimit
;
406 struct reguser
*users
;
407 struct maildomain
*parent
;
408 struct maildomain
*nextbyname
;
409 struct maildomain
*nextbyID
;
412 #define MDFLAG_LIMIT 0x0001 /* +l */
413 #define MDFLAG_BANNED 0x0002 /* +b */
414 #define MDFLAG_ACTLIMIT 0x0004 /* +u */
415 #define MDFLAG_ALL 0x0007
417 #define MDFLAG_DEFAULT MDFLAG_ACTLIMIT
419 #define MDHasLimit(x) ((x)->flags & MDFLAG_LIMIT)
420 #define MDSetLimit(x) ((x)->flags |= MDFLAG_LIMIT)
421 #define MDClearLimit(x) ((x)->flags &= ~MDFLAG_LIMIT)
422 #define MDIsBanned(x) ((x)->flags & MDFLAG_BANNED)
423 #define MDSetBanned(x) ((x)->flags |= MDFLAG_BANNED)
424 #define MDClearBanned(x) ((x)->flags &= ~MDFLAG_BANNED)
425 #define MDHasActLimit(x) ((x)->flags & MDFLAG_ACTLIMIT)
426 #define MDSetActLimit(x) ((x)->flags |= MDFLAG_ACTLIMIT)
427 #define MDClearActLimit(x) ((x)->flags &= ~MDFLAG_ACTLIMIT)
430 typedef struct regban
{
432 unsigned int regchanban_magic
;
434 unsigned int ID
; /* ID in the database */
435 struct chanban
*cbp
; /* Standard chanban struct */
436 unsigned int setby
; /* Who set the ban */
437 time_t expiry
; /* When the ban expires */
438 sstring
*reason
; /* Reason to attach to related kicks */
439 struct regban
*next
; /* Next ban on this channel */
442 /* Registered channel */
443 typedef struct regchan
{
445 unsigned int regchan_magic
;
447 unsigned int ID
; /* Unique number from database */
448 chanindex
*index
; /* Pointer to the channel index record */
449 time_t ltimestamp
; /* The last timestamp we saw on this channel */
451 flag_t flags
; /* Chanflags */
452 flag_t status
; /* Runtime status codes */
453 flag_t forcemodes
; /* Forced modes */
454 flag_t denymodes
; /* Denied modes */
456 unsigned short limit
; /* Limit to enforce if +l is set */
457 short autolimit
; /* How many slots to leave when autolimiting */
458 short banstyle
; /* Ban style for +b type bans */
460 time_t created
; /* When the service was added */
461 time_t lastactive
; /* When the channel was last "active" */
462 time_t statsreset
; /* When the users stats were last reset */
463 time_t ostatsreset
; /* When the oper stats were last reset */
464 time_t banduration
; /* How long to remove bans after (0=don't) */
465 time_t autoupdate
; /* When the autolimit next needs checking */
466 time_t lastbancheck
; /* Timestamp of last ban check */
467 time_t lastcountersync
; /* When the counters were last synced.. */
468 time_t lastpart
; /* When the last user left the channel */
469 time_t suspendtime
; /* When the channel was suspended */
471 unsigned int founder
; /* founder */
472 unsigned int addedby
; /* oper adding chan */
473 unsigned int suspendby
; /* who suspended chan */
475 short chantype
; /* What "type" the channel is */
477 unsigned int totaljoins
; /* Total joins since created */
478 unsigned int tripjoins
; /* Total joins since last stats reset */
479 unsigned int otripjoins
; /* Total joins since last oper stats reset */
480 unsigned int maxusers
; /* Max users since created */
481 unsigned int tripusers
; /* Max users since last stats reset */
482 unsigned int otripusers
; /* Max users since last oper stats reset */
484 sstring
*welcome
; /* Welcome message */
485 sstring
*topic
; /* "default" topic set by settopic */
486 sstring
*key
; /* Key as enforced by +k */
487 sstring
*suspendreason
; /* Suspend reason */
488 sstring
*comment
; /* Oper-settable channel comment */
490 void *checksched
; /* Handle for channel check schedule */
492 struct regchanuser
*regusers
[REGCHANUSERHASHSIZE
];
493 struct regban
*bans
; /* List of bans on the channel */
495 char chanopnicks
[CHANOPHISTORY
][NICKLEN
+1]; /* Last CHANOPHISTORY ppl to get ops */
496 unsigned int chanopaccts
[CHANOPHISTORY
]; /* Which account was responsible for each one */
497 short chanoppos
; /* Position in the array */
500 /* Registered user */
501 typedef struct reguser
{
503 unsigned int reguser_magic
;
505 unsigned int ID
; /* From the database */
507 char username
[NICKLEN
+1];
511 time_t lastemailchange
;
513 flag_t flags
; /* user flags */
514 flag_t status
; /* runtime status */
515 short languageid
; /* what language to speak to the user */
517 unsigned int suspendby
; /* Userid of oper who suspended this user */
518 time_t suspendexp
; /* Expiry date of suspension */
519 time_t suspendtime
; /* When user was suspended */
520 time_t lockuntil
; /* Time until users account is unlocked (pass change, email, etc) */
522 char password
[PASSLEN
+1];
527 sstring
*email
; /* Registered e-mail */
528 sstring
*lastemail
; /* Last registered e-mail */
529 sstring
*lastuserhost
; /* Last user@host */
530 sstring
*suspendreason
; /* Why the account is suspended */
531 sstring
*comment
; /* Oper-settable user comment */
532 sstring
*info
; /* User-settable info line */
534 struct regchanuser
*knownon
; /* Which channels this user is known on */
536 /* These fields are for the nick protection system */
537 void *checkshd
; /* When we're going to check for an imposter */
538 int stealcount
; /* How many times we've had to free the nick up */
539 nick
*fakeuser
; /* If we had to "take" the nick, here's the pointer */
541 struct reguser
*nextbydomain
;
542 struct reguser
*nextbyname
;
543 struct reguser
*nextbyID
;
546 /* Registered channel user */
547 typedef struct regchanuser
{
549 unsigned int regchanuser_magic
;
551 struct reguser
*user
;
552 struct regchan
*chan
;
554 time_t changetime
; /* Timestamp of last "significant" change */
555 time_t usetime
; /* Timestamp of last use */
556 sstring
*info
; /* User-settable info line */
557 struct regchanuser
*nextbyuser
;
558 struct regchanuser
*nextbychan
;
561 typedef struct cslang
{
566 typedef struct cmdsummary
{
568 sstring
*bylang
[MAXLANG
];
572 typedef struct activeuser
{
574 unsigned int activeuser_magic
;
576 unsigned short authattempts
; /* number of times user has attempted to auth */
577 unsigned short helloattempts
; /* number of times user has attempted to hello... */
578 unsigned char entropy
[ENTROPYLEN
]; /* entropy used for challengeauth */
580 struct activeuser
*next
; /* purely for keeping track of free, but not free'd structures */
583 typedef struct maillock
{
585 unsigned int maillock_magic
;
590 unsigned int createdby
;
592 struct maillock
*next
;
597 #define REGUSERMAGIC 0x4d42de03
598 #define REGCHANMAGIC 0x5bf2aa30
599 #define REGCHANUSERMAGIC 0x19628b63
600 #define REGCHANBANMAGIC 0x5a6f555a
601 #define ACTIVEUSERMAGIC 0x897f98a0
602 #define MAILDOMAINMAGIC 0x27cde46f
603 #define MAILLOCKMAGIC 0x3c81d762
605 #define verifyreguser(x) assert((x)->reguser_magic == REGUSERMAGIC)
606 #define verifyregchan(x) assert((x)->regchan_magic == REGCHANMAGIC)
607 #define verifyregchanuser(x) assert((x)->regchanuser_magic == REGCHANUSERMAGIC)
608 #define verifyregchanban(x) assert((x)->regchanban_magic == REGCHANBANMAGIC)
609 #define verifyactiveuser(x) assert((x)->activeuser_magic == ACTIVEUSERMAGIC)
610 #define verifymaildomain(x) assert((x)->maildomain_magic == MAILDOMAINMAGIC)
611 #define verifymaillock(x) assert((x)->maillock_magic == MAILLOCKMAGIC)
613 #define tagreguser(x) ((x)->reguser_magic = REGUSERMAGIC)
614 #define tagregchan(x) ((x)->regchan_magic = REGCHANMAGIC)
615 #define tagregchanuser(x) ((x)->regchanuser_magic = REGCHANUSERMAGIC)
616 #define tagregchanban(x) ((x)->regchanban_magic = REGCHANBANMAGIC)
617 #define tagactiveuser(x) ((x)->activeuser_magic = ACTIVEUSERMAGIC)
618 #define tagmaildomain(x) ((x)->maildomain_magic = MAILDOMAINMAGIC)
619 #define tagmaillock(x) ((x)->maillock_magic = MAILLOCKMAGIC)
622 #define verifyreguser(x)
623 #define verifyregchan(x)
624 #define verifyregchanuser(x)
625 #define verifyregchanban(x)
626 #define verifyactiveuser(x)
627 #define verifymaildomain(x)
628 #define verifymaillock(x)
630 #define tagreguser(x)
631 #define tagregchan(x)
632 #define tagregchanuser(x)
633 #define tagregchanban(x)
634 #define tagactiveuser(x)
635 #define tagmaildomain(x)
636 #define tagmaillock(x)
640 #define getactiveuserfromnick(x) ((activeuser*)(x)->exts[chanservnext])
641 #define getreguserfromnick(x) ((x)->auth?(reguser *)(x)->auth->exts[chanservaext]:NULL)
643 /* Global variables for chanserv module */
644 extern unsigned int lastuserID
;
645 extern unsigned int lastchannelID
;
646 extern unsigned int lastbanID
;
647 extern unsigned int lastdomainID
;
648 extern unsigned int lastmaillockID
;
650 extern int chanserv_init_status
;
651 extern int chanservdb_ready
;
652 extern DBModuleIdentifier q9dbid
, q9adbid
, q9cdbid
, q9udbid
;
654 extern maildomain
*maildomainnametable
[MAILDOMAINHASHSIZE
];
655 extern maildomain
*maildomainIDtable
[MAILDOMAINHASHSIZE
];
657 extern reguser
*regusernicktable
[REGUSERHASHSIZE
];
658 extern reguser
*deadusers
;
660 extern nick
*chanservnick
;
661 extern int chanservext
;
662 extern int chanservnext
;
663 extern int chanservaext
;
665 extern cslang
*cslanguages
[MAXLANG
];
666 extern unsigned int cslangcount
;
668 extern sstring
*csmessages
[MAXLANG
][MAXMESSAGES
];
670 extern const flag rcflags
[];
671 extern const flag rcuflags
[];
672 extern const flag ruflags
[];
673 extern const flag mdflags
[];
675 extern CommandTree
*cscommands
;
677 extern sstring
**chantypes
;
679 extern maillock
*maillocks
;
681 /* Function prototypes */
684 void chanserv_finalinit();
686 /* chanservalloc.c */
687 void chanservallocinit();
689 regchan
*getregchan();
690 void freeregchan(regchan
*rcp
);
691 reguser
*getreguser();
692 void freereguser(reguser
*rup
);
693 regchanuser
*getregchanuser();
694 void freeregchanuser(regchanuser
*rcup
);
696 void freeregban(regban
*rbp
);
697 activeuser
*getactiveuser();
698 void freeactiveuser(activeuser
*aup
);
699 maildomain
*getmaildomain();
700 void freemaildomain(maildomain
*mdp
);
701 maillock
*getmaillock();
702 void freemaillock(maillock
*mlp
);
705 void chanservhashinit();
706 void addregusertohash(reguser
*rup
);
707 reguser
*findreguserbyID(unsigned int ID
);
708 reguser
*findreguserbynick(const char *nick
);
709 reguser
*findreguser(nick
*sender
, const char *str
);
710 void removereguserfromhash(reguser
*rup
);
711 void addregchantohash(regchan
*rcp
);
712 regchan
*findregchanbyID(unsigned int ID
);
713 regchan
*findregchanbyname(const char *name
);
714 void removeregchanfromhash(regchan
*rcp
);
715 void addregusertochannel(regchanuser
*rcup
);
716 regchanuser
*findreguseronchannel(regchan
*rcp
, reguser
*rup
);
717 void delreguserfromchannel(regchan
*rcp
, reguser
*rup
);
718 void addmaildomaintohash(maildomain
*mdp
);
719 maildomain
*findmaildomainbyID(unsigned int ID
);
720 maildomain
*findmaildomainbydomain(char *domain
);
721 maildomain
*findmaildomainbyemail(char *email
);
722 maildomain
*findorcreatemaildomain(char *email
);
723 maildomain
*findnearestmaildomain(char *domain
);
724 void removemaildomainfromhash(maildomain
*mdp
);
725 void addregusertomaildomain(reguser
*rup
, maildomain
*mdp
);
726 void delreguserfrommaildomain(reguser
*rup
, maildomain
*mdp
);
727 reguser
*findreguserbyemail(const char *email
);
730 int chanservdbinit();
732 void loadcommandsummary(Command
*cmd
);
733 void chanservdbclose();
734 void csdb_updatetopic(regchan
*rcp
);
735 void csdb_updatelastjoin(regchanuser
*rcup
);
736 void csdb_updateauthinfo(reguser
*rup
);
737 void csdb_updatechannel(regchan
*rcp
);
738 void csdb_createchannel(regchan
*rcp
);
739 void csdb_deletechannel(regchan
*rcp
);
740 void csdb_deleteuser(reguser
*rup
);
741 void csdb_updatechannelcounters(regchan
*rcp
);
742 void csdb_updatechanneltimestamp(regchan
*rcp
);
743 void csdb_updatechanuser(regchanuser
*rcup
);
744 void csdb_createchanuser(regchanuser
*rcup
);
745 void csdb_deletechanuser(regchanuser
*rcup
);
746 void csdb_createuser(reguser
*rup
);
747 void csdb_updateuser(reguser
*rup
);
748 void csdb_createban(regchan
*rcp
, regban
*rbp
);
749 void csdb_deleteban(regban
*rbp
);
750 void csdb_updateban(regchan
*rcp
, regban
*rbp
);
751 char *csdb_gethelpstr(char *command
, int language
);
752 void csdb_createmail(reguser
*rup
, int type
);
753 void csdb_dohelp(nick
*np
, Command
*cmd
);
755 #define q9asyncquery(handler, tag, format, ...) dbasyncqueryi(q9dbid, handler, tag, format , ##__VA_ARGS__)
756 #define q9a_asyncquery(handler, tag, format, ...) dbasyncqueryi(q9adbid, handler, tag, format , ##__VA_ARGS__)
757 #define q9u_asyncquery(handler, tag, format, ...) dbasyncqueryi(q9udbid, handler, tag, format , ##__VA_ARGS__)
758 #define q9c_asyncquery(handler, tag, format, ...) dbasyncqueryi(q9cdbid, handler, tag, format , ##__VA_ARGS__)
760 /* chanservcrypto.c */
761 typedef int (*CRAlgorithm
)(char *, const char *, const char *, const char *);
762 void chanservcryptoinit(void);
763 void chanservcryptofree(void);
764 void cs_getrandbytes(unsigned char *buf
, size_t bytes
);
765 char *cs_calcchallenge(const unsigned char *entropy
);
766 CRAlgorithm
cs_cralgorithm(const char *algorithm
);
767 const char *cs_cralgorithmlist(void);
768 int cs_checkhashpass(const char *username
, const char *password
, const char *junk
, const char *hash
);
769 char *csc_generateresetcode(time_t lockuntil
, char *username
);
772 void chanservreguser(void *arg
);
773 void chanservjoinchan(channel
*cp
);
774 #define chanservsendmessage(np, fmt, args...) chanservsendmessage_real(np, 0, fmt , ## args)
775 #define chanservsendmessageoneline(np, fmt, args...) chanservsendmessage_real(np, 1, fmt , ## args)
776 void chanservsendmessage_real(nick
*np
, int oneline
, char *message
, ... );
777 void chanservwallmessage(char *message
, ... );
778 void chanservcommandinit();
779 void chanservcommandclose();
780 void chanservstdmessage(nick
*np
, int messageid
, ... );
781 void chanservaddcommand(char *command
, int flags
, int maxparams
, CommandHandler handler
, char *description
, const char *help
);
782 void chanservremovecommand(char *command
, CommandHandler handler
);
783 void chanservaddctcpcommand(char *command
, CommandHandler hander
);
784 void chanservremovectcpcommand(char *command
, CommandHandler handler
);
785 void chanservkillstdmessage(nick
*target
, int messageid
, ... );
786 int checkpassword(reguser
*rup
, const char *pass
);
787 int setpassword(reguser
*rup
, const char *pass
);
788 /*reguser *getreguserfromnick(nick *np);
789 activeuser *getactiveuserfromnick(nick *np);*/
790 void cs_checknick(nick
*np
);
791 void cs_checkchanmodes(channel
*cp
);
792 void cs_docheckchanmodes(channel
*cp
, modechanges
*changes
);
793 void cs_docheckopvoice(channel
*cp
, modechanges
*changes
);
794 void cs_checkbans(channel
*cp
);
795 void cs_schedupdate(chanindex
*cip
, int mintime
, int maxtime
);
796 void cs_timerfunc(void *arg
);
797 void cs_removechannel(regchan
*rcp
);
798 int cs_removechannelifempty(nick
*sender
, regchan
*rcp
);
799 void cs_doallautomodes(nick
*np
);
800 void cs_checknickbans(nick
*np
);
801 void cs_setregban(chanindex
*cip
, regban
*rbp
);
802 int cs_bancheck(nick
*np
, channel
*cp
);
803 void cs_banuser(modechanges
*changes
, chanindex
*cip
, nick
*np
, const char *reason
);
804 void cs_removeuser(reguser
*rup
);
805 int checkresponse(reguser
*rup
, const unsigned char *entropy
, const char *response
, CRAlgorithm algorithm
);
806 int checkhashpass(reguser
*rup
, const char *junk
, const char *hash
);
807 flag_t
cs_sanitisechanlev(flag_t flags
);
808 typedef int (*UnbanFN
)(void *arg
, struct chanban
*ban
);
809 int cs_unbanfn(nick
*sender
, chanindex
*cip
, UnbanFN fn
, void *arg
, int removepermbans
, int abortonfailure
);
810 void cs_logchanop(regchan
*rcp
, char *nick
, reguser
*rup
);
812 /* chanservstdcmds.c */
813 int cs_doshowcommands(void *source
, int cargc
, char **cargv
);
814 int cs_dohelp(void *source
, int cargc
, char **cargv
);
815 int cs_doquit(void *source
, int cargc
, char **cargv
);
816 int cs_dorename(void *source
, int cargc
, char **cargv
);
817 int cs_dorehash(void *source
, int cargc
, char **cargv
);
818 int cs_doversion(void *source
, int cargc
, char **cargv
);
819 int cs_doctcpping(void *source
, int cargc
, char **cargv
);
820 int cs_doctcpversion(void *source
, int cargc
, char **cargv
);
821 int cs_doctcpgender(void *source
, int cargc
, char **cargv
);
822 int cs_sendhelp(nick
*sender
, char *cmd
, int oneline
);
824 /* chanservnetevents.c */
825 void cs_handlenick(int hooknum
, void *arg
);
826 void cs_handlesethost(int hooknum
, void *arg
);
827 void cs_handlelostnick(int hooknum
, void *arg
);
828 void cs_handlenewchannel(int hooknum
, void *arg
);
829 void cs_handlelostchannel(int hooknum
, void *arg
);
830 void cs_handlejoin(int hooknum
, void *arg
);
831 void cs_handlemodechange(int hooknum
, void *arg
);
832 void cs_handleburst(int hooknum
, void *arg
);
833 void cs_handletopicchange(int hooknum
, void *arg
);
834 void cs_handleopchange(int hooknum
, void *arg
);
835 void cs_handlenewban(int hooknum
, void *arg
);
836 void cs_handlechanlostuser(int hooknum
, void *arg
);
838 /* chanservmessages.c */
841 /* chanservprivs.c */
842 int cs_privcheck(int privnum
, nick
*np
);
843 chanindex
*cs_checkaccess(nick
*np
, const char *chan
, unsigned int flags
, chanindex
*cip
, const char *cmdname
, int priv
, int quiet
);
848 void cs_log(nick
*np
, char *event
, ...);
851 int dumplastjoindata(const char *filename
);
852 int readlastjoindata(const char *filename
);
854 /* chanservschedule.c */
855 void chanservdgline(void *arg
);
858 int csa_checkeboy(nick
*sender
, char *eboy
);
859 void csa_createrandompw(char *pw
, int n
);
860 int csa_checkthrottled(nick
*sender
, reguser
*rup
, char *s
);
862 /* chanservdb_updates.c */
863 void csdb_updateauthinfo(reguser
*rup
);
864 void csdb_updatelastjoin(regchanuser
*rcup
);
865 void csdb_updatetopic(regchan
*rcp
);
866 void csdb_updatechannel(regchan
*rcp
);
867 void csdb_updatechannelcounters(regchan
*rcp
);
868 void csdb_updatechanneltimestamp(regchan
*rcp
);
869 void csdb_createchannel(regchan
*rcp
);
870 void csdb_deletechannel(regchan
*rcp
);
871 void csdb_deleteuser(reguser
*rup
);
872 void csdb_updateuser(reguser
*rup
);
873 void csdb_createuser(reguser
*rup
);
874 void csdb_updatechanuser(regchanuser
*rcup
);
875 void csdb_createchanuser(regchanuser
*rcup
);
876 void csdb_deletechanuser(regchanuser
*rcup
);
877 void csdb_createban(regchan
*rcp
, regban
*rbp
);
878 void csdb_deleteban(regban
*rbp
);
879 void csdb_createmail(reguser
*rup
, int type
);
880 void csdb_deletemaildomain(maildomain
*mdp
);
881 void csdb_createmaildomain(maildomain
*mdp
);
882 void csdb_updatemaildomain(maildomain
*mdp
);
883 void csdb_chanlevhistory_insert(regchan
*rcp
, nick
*np
, reguser
*trup
, flag_t oldflags
, flag_t newflags
);
884 void csdb_accounthistory_insert(nick
*np
, char *oldpass
, char *newpass
, sstring
*oldemail
, sstring
*newemail
);
885 void csdb_cleanuphistories();
886 void csdb_deletemaillock(maillock
*mlp
);
887 void csdb_createmaillock(maillock
*mlp
);
888 void csdb_updatemaillock(maillock
*mlp
);
891 void q9snprintf(char *buf
, size_t size
, const char *format
, const char *args
, ...);
892 void q9vsnprintf(char *buf
, size_t size
, const char *format
, const char *args
, va_list ap
);