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