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