]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chanserv.h
Added new USERS command - shows channel users with account names and Q flags.
[irc/quakenet/newserv.git] / chanserv / chanserv.h
1 /*
2 * chanserv.h:
3 * Top level data structures and function prototypes for the
4 * channel service module
5 */
6
7 #ifndef __CHANSERV_H
8 #define __CHANSERV_H
9
10 #define _GNU_SOURCE
11 #include <string.h>
12 #include <time.h>
13 #include "../lib/sstring.h"
14 #include "../core/schedule.h"
15 #include "../lib/flags.h"
16 #include "../nick/nick.h"
17 #include "../channel/channel.h"
18 #include "../parser/parser.h"
19 #include "../localuser/localuserchannel.h"
20 #include "../pqsql/pqsql.h"
21
22 #define CS_PARANOID
23
24 #ifdef CS_PARANOID
25 #include <assert.h>
26 #endif
27
28 /* Q9 Version */
29 #define QVERSION "1.00-RC1"
30
31 /* Mini-hash of known users on channels to make lookups faster;
32 * how big do we make it? */
33 #define REGCHANUSERHASHSIZE 5
34 #define PASSLEN 10
35 #define WELCOMELEN 250
36 #define INFOLEN 100
37 #define AUTOLIMIT_INTERVAL 60
38 #define COUNTERSYNCINTERVAL 600
39 #define LINGERTIME 300
40 #define DUMPINTERVAL 300
41 #define EMAILLEN 60
42 #define CHANTYPES 8
43 #define CHANOPHISTORY 10
44
45 /* Suspension and g-line hit count limits */
46 #define MAXGLINEUSERS 50
47 #define MAXSUSPENDHIT 500
48
49 /* Maximum number of times a user may attempt to auth */
50 #define MAXAUTHATTEMPT 5
51
52 /* Maximum number of hellos in a session */
53 #define MAXHELLOS 3
54
55 /* Maximum number of times a user may actually be authed */
56 #define MAXAUTHCOUNT 2
57
58 /* Maximum number of accounts that may share an email address */
59 #define MD_DEFAULTACTLIMIT 2
60
61 /* If set will issue warnings when authgate cached stuff changes */
62 #define AUTHGATE_WARNINGS
63
64 /* Cleanup options */
65 #define CLEANUP_ACCOUNT_INACTIVE 80
66 #define CLEANUP_ACCOUNT_UNUSED 10
67 #define CLEANUP_CHANNEL_INACTIVE 30
68
69 /* Sizes of the main hashes */
70 #define REGUSERHASHSIZE 60000
71 #define MAILDOMAINHASHSIZE 60000
72
73 /* Number of languages and messages */
74 #define MAXLANG 50
75 #define MAXMESSAGES 200
76
77 /* Maximum number of user chanlevs and bans */
78 #define MAXCHANLEVS 250
79 #define MAXBANS 50
80
81 /* Sources of entropy and standard length defines */
82 #define ENTROPYSOURCE "/dev/urandom"
83 #define ENTROPYLEN 8
84
85 /* The list of messages */
86 #define QM_PROTECTED 0
87 #define QM_UNKNOWNCMD 1
88 #define QM_SECUREONLY 2
89 #define QM_AUTHEDONLY 3
90 #define QM_UNAUTHEDONLY 4
91 #define QM_COMMANDLIST 5
92 #define QM_ENDOFLIST 6
93 #define QM_DONE 7
94 #define QM_NOTENOUGHPARAMS 8
95 #define QM_UNKNOWNCHAN 9
96 #define QM_NOACCESSONCHAN 10
97 #define QM_CURCHANFLAGS 11
98 #define QM_CURFORCEMODES 12
99 #define QM_NOACCESS 13
100 #define QM_UNKNOWNUSER 14
101 #define QM_USERNOTAUTHED 15
102 #define QM_CHANLEVHEADER 16
103 #define QM_CHANLEVCOLSHORT 17
104 #define QM_CHANLEVCOLFULL 18
105 #define QM_NOUSERSONCHANLEV 19
106 #define QM_CHANUSERFLAGS 20
107 #define QM_CHANUSERUNKNOWN 21
108 #define QM_INVALIDCHANLEVCHANGE 22
109 #define QM_USERISAUTHEDAS 23
110 #define QM_USERISHELPER 24
111 #define QM_USERISOPER 25
112 #define QM_USERISADMIN 26
113 #define QM_USERISDEV 27
114 #define QM_WHOISHEADER 28
115 #define QM_WHOISCOLS 29
116 #define QM_USERONNOCHANS 30
117 #define QM_CHANAUTOLIMIT 31
118 #define QM_CHANBANAUTOREMOVE 32
119 #define QM_NOCHANBANAUTOREMOVE 33
120 #define QM_INVALIDCHANNAME 34
121 #define QM_ALREADYREGISTERED 35
122 #define QM_CURUSERFLAGS 36
123 #define QM_WELCOMEMESSAGEIS 37
124 #define QM_GLOBALINFO 38
125 #define QM_CHANNELINFO 39
126 #define QM_PROTECTEDNICK 40
127 #define QM_NICKWASFAKED 41
128 #define QM_NOTPROTECTED 42
129 #define QM_SAMEAUTH 43
130 #define QM_AUTHFAIL 44
131 #define QM_AUTHOK 45
132 #define QM_NEWACCOUNT 46
133 #define QM_AUTHNAMEINUSE 47
134 #define QM_ALREADYONCHAN 48
135 #define QM_NOTONCHAN 49
136 #define QM_ALREADYOPPED 50
137 #define QM_USERNOTONCHAN 51
138 #define QM_USEROPPEDONCHAN 52
139 #define QM_CANTOP 53
140 #define QM_NOTOPPED 54
141 #define QM_ALREADYVOICED 55
142 #define QM_NOTVOICED 56
143 #define QM_USERVOICEDONCHAN 57
144 #define QM_REGBANHEADER 58
145 #define QM_NOBANS 59
146 #define QM_REMOVEDCHANBAN 60
147 #define QM_NOTREMOVEDPERMBAN 61
148 #define QM_REMOVEDPERMBAN 62
149 #define QM_CANTVOICE 63
150 #define QM_NOHELP 64
151 #define QM_WHOISHEADER_NICK 65
152 #define QM_WHOISHEADER_AUTH 66
153 #define QM_WHOIS_USERS 67
154 #define QM_WHOIS_LASTAUTH 68
155 #define QM_WHOIS_LASTUSERHOST 69
156 #define QM_WHOIS_USERID 70
157 #define QM_WHOIS_INFO 71
158 #define QM_WHOIS_COMMENT 72
159 #define QM_WHOIS_FLAGS 73
160 #define QM_WHOIS_CREATED 74
161 #define QM_WHOIS_CHANHEADER 75
162 #define QM_WHOIS_EMAIL 76
163 #define QM_WHOIS_EMAILSET 77
164 #define QM_COMMENT 78
165 #define QM_NOCOMMENT 79
166 #define QM_BADAUTH 80
167 #define QM_USERHASBADAUTH 81
168 #define QM_BADEMAIL 82
169 #define QM_MAILTHROTTLED 83
170 #define QM_MAILQUEUED 84
171 #define QM_PWDONTMATCH 85
172 #define QM_PWTOSHORT 86
173 #define QM_PWCHANGED 87
174 #define QM_INVALIDDURATION2 88
175 #define QM_EMAILCHANGED 89
176 #define QM_EMAILDONTMATCH 90
177 #define QM_INVALIDEMAIL 91
178 #define QM_EMAILTOOSHORT 92
179 #define QM_NOTYOUREMAIL 93
180 #define QM_EMAILNOAT 94
181 #define QM_EMAILATEND 95
182 #define QM_EMAILINVCHR 96
183 #define QM_CHANNELNOTSUSPENDED 97
184 #define QM_CHANNELALREADYSUSPENDED 98
185 #define QM_CHANTYPE 99
186 #define QM_UNKNOWNCHANTYPE 100
187 #define QM_FOUNDER 101
188 #define QM_ADDEDBY 102
189 #define QM_ALREADYKNOWNONCHAN 103
190 #define QM_CANNOTREMOVEOWNER 104
191 #define QM_CANNOTREMOVEMASTER 105
192 #define QM_UNKNOWNBAN 106
193 #define QM_YOURLANGUAGE 107
194 #define QM_LANGUAGELIST 108
195 #define QM_UNKNOWNLANGUAGE 109
196 #define QM_WHOIS_USERLANG 110
197 #define QM_CHANTYPEIS 111
198 #define QM_STATSHEADER 112
199 #define QM_STATSADDED 113
200 #define QM_STATSJOINS 114
201 #define QM_STATSLASTACTIVE 115
202 #define QM_AUTHSUSPENDED 116
203 #define QM_REASON 117
204 #define QM_EXPIRES 118
205 #define QM_TOOMANYAUTHS 119
206 #define QM_INVALIDDURATION 120
207 #define QM_DISCONNECTINGUSER 121
208 #define QM_USERALREADYSUSPENDED 122
209 #define QM_USERNOTSUSPENDED 123
210 #define QM_SPEWHEADER 124
211 #define QM_TOOMANYRESULTS 125
212 #define QM_RESULTCOUNT 126
213 #define QM_SUSPENDKILL 127
214 #define QM_LISTFLAGSHEADER 128
215 #define QM_SUSPENDUSERLISTHEADER 129
216 #define QM_SUSPENDCHANLISTHEADER 130
217 #define QM_NOREQUESTOWNER 131
218 #define QM_GRANTEDOWNER 132
219 #define QM_AUTHHISTORYHEADER 133
220 #define QM_CURDOMAINMODES 134
221 #define QM_SPEWDOMAINHEADER 135
222 #define QM_DOMAINLIMIT 136
223 #define QM_PWTOWEAK 137
224 #define QM_GIVEOWNERNOTMASTER 138
225 #define QM_GIVEOWNERALREADYOWNER 139
226 #define QM_GIVEOWNERNEEDHASH 140
227 #define QM_GIVEOWNERWRONGHASH 141
228 #define QM_SHOWINGDURATION 142
229 #define QM_INVALIDACCOUNTNAME 143
230 #define QM_CHALLENGEBADALGORITHM 144
231 #define QM_NOCHALLENGE 145
232 #define QM_USEGIVEOWNER 146
233 #define QM_NOFLAGSPECIFIED 147
234 #define QM_NEWBANALREADYBANNED 148
235 #define QM_NEWBANOVERLAPS 149
236 #define QM_REPLACINGTEMPBAN 150
237 #define QM_PERMBANALREADYSET 151
238 #define QM_NOTREPLACINGBANLDURATION 152
239 #define QM_REPLACINGBANSDURATION 153
240 #define QM_TOOMANYCHANLEVS 154
241 #define QM_TOOMANYBANS 155
242 #define QM_WARNNOTREMOVEDPERMBAN 156
243 #define QM_MAXHELLOLIMIT 157
244 #define QM_ADDRESSLIMIT 158
245 #define QM_DOMAINBANNED 159
246 #define QM_TYPEHELPFORHELP 160
247 #define QM_REQUESTPASSPRIVUSER 161
248 #define QM_EMAILMATCHESOLD 162
249 #define QM_INVALIDLIMIT 163
250 #define QM_ACCOUNTLOCKED 164
251 #define QM_ACCOUNTNOTLOCKED 165
252 #define QM_RESETOK 166
253 #define QM_BADRESETCODE 167
254 #define QM_CHALLENGEDDEPRECATED 168
255 #define QM_CHANLEVSUMMARY 169
256 #define QM_MAILLOCKHEADER 170
257 #define QM_MAILLOCKLINE 171
258 #define QM_MAILLOCKDOESNTEXIST 172
259 #define QM_MAILLOCKALREADYEXISTS 173
260 #define QM_MAILLOCKED 174
261 #define QM_NOACCESSONUSER 175
262 #define QM_NOCHANOPHISTORY 176
263 #define QM_CHANOPHISTORYHEADER 177
264 #define QM_OTHERUSERAUTHEDLIMIT 178
265 #define QM_OTHERUSERAUTHED 179
266 #define QM_STATSRESET 180
267 #define QM_CHANLEVEMPTIEDCHANNEL 181
268 #define QM_CHANLEVCHANGED 182
269 #define QM_CHANLEVREMOVED 183
270 #define QM_CHANLEVNOCHANGE 184
271 #define QM_USERSHEADER 185
272 #define QM_EMPTYCHAN 186
273 #define QM_USERSSUMMARY 187
274
275 /* List of privileged operations */
276
277 #define QPRIV_SUSPENDBYPASS 1
278 #define QPRIV_VIEWCHANFLAGS 100
279 #define QPRIV_VIEWFULLCHANLEV 101
280 #define QPRIV_VIEWFULLWHOIS 102
281 #define QPRIV_VIEWCHANMODES 103
282 #define QPRIV_VIEWAUTOLIMIT 104
283 #define QPRIV_VIEWBANTIMER 105
284 #define QPRIV_VIEWUSERFLAGS 106
285 #define QPRIV_VIEWWELCOME 107
286 #define QPRIV_VIEWCOMMENTS 108
287 #define QPRIV_VIEWEMAIL 109
288
289 #define QPRIV_CHANGECHANFLAGS 200
290 #define QPRIV_CHANGECHANLEV 201
291 #define QPRIV_CHANGECHANMODES 202
292 #define QPRIV_CHANGEAUTOLIMIT 203
293 #define QPRIV_CHANGEBANTIMER 204
294 #define QPRIV_CHANGEUSERFLAGS 205
295 #define QPRIV_CHANGEWELCOME 206
296
297 /* List of access checks */
298
299 #define CA_AUTHED 0x0001
300 #define CA_TOPICPRIV 0x0008
301 #define CA_KNOWN 0x0010
302 #define CA_VOICEPRIV 0x0020
303 #define CA_OPPRIV 0x0040
304 #define CA_MASTERPRIV 0x0080
305 #define CA_OWNERPRIV 0x0100
306 /* SPARE 0x0200 */
307 #define CA_ONCHAN 0x0400
308 #define CA_OFFCHAN 0x0800
309 #define CA_OPPED 0x1000
310 #define CA_DEOPPED 0x2000
311 #define CA_VOICED 0x4000
312 #define CA_DEVOICED 0x8000
313
314 #define CA_NEEDKNOWN (CA_KNOWN|CA_OPPRIV|CA_MASTERPRIV|CA_TOPICPRIV|CA_OWNERPRIV)
315 #define CA_ONCHANREQ (CA_ONCHAN|CA_OPPED|CA_DEOPPED|CA_VOICED|CA_DEVOICED)
316
317
318 /* User flags */
319 #define QUFLAG_NOINFO 0x0001 /* +s */
320 #define QUFLAG_GLINE 0x0002 /* +g */
321 #define QUFLAG_NOTICE 0x0004 /* +n */
322 /* SPARE FLAG 0x0008 */
323 #define QUFLAG_SUSPENDED 0x0010 /* +z */
324 #define QUFLAG_OPER 0x0020 /* +o */
325 #define QUFLAG_DEV 0x0040 /* +d */
326 #define QUFLAG_PROTECT 0x0080 /* +p */
327 #define QUFLAG_HELPER 0x0100 /* +h */
328 #define QUFLAG_ADMIN 0x0200 /* +a */
329 #define QUFLAG_INFO 0x0400 /* +i */
330 #define QUFLAG_DELAYEDGLINE 0x0800 /* +G */
331 #define QUFLAG_NOAUTHLIMIT 0x1000 /* +L */
332 #define QUFLAG_CLEANUPEXEMPT 0x4000 /* +D */
333 #define QUFLAG_TRUST 0x8000 /* +T */
334 #define QUFLAG_ALL 0xdff7
335
336 #define UIsNoInfo(x) ((x)->flags & QUFLAG_NOINFO)
337 #define UIsGline(x) ((x)->flags & QUFLAG_GLINE)
338 #define UIsNotice(x) ((x)->flags & QUFLAG_NOTICE)
339 #define UIsSuspended(x) ((x)->flags & QUFLAG_SUSPENDED)
340 #define UIsOper(x) ((x)->flags & QUFLAG_OPER)
341 #define UIsDev(x) ((x)->flags & QUFLAG_DEV)
342 #define UIsProtect(x) ((x)->flags & QUFLAG_PROTECT)
343 #define UIsHelper(x) ((x)->flags & QUFLAG_HELPER)
344 #define UIsAdmin(x) ((x)->flags & QUFLAG_ADMIN)
345 #define UIsInfo(x) ((x)->flags & QUFLAG_INFO)
346 #define UIsDelayedGline(x) ((x)->flags & QUFLAG_DELAYEDGLINE)
347 #define UIsNoAuthLimit(x) ((x)->flags & QUFLAG_NOAUTHLIMIT)
348 #define UIsCleanupExempt(x) ((x)->flags & QUFLAG_CLEANUPEXEMPT)
349
350 #define UHasSuspension(x) ((x)->flags & (QUFLAG_GLINE|QUFLAG_DELAYEDGLINE|QUFLAG_SUSPENDED))
351
352 #define UHasHelperPriv(x) ((x)->flags & (QUFLAG_HELPER | QUFLAG_OPER | QUFLAG_ADMIN | QUFLAG_DEV))
353 #define UHasOperPriv(x) ((x)->flags & (QUFLAG_OPER | QUFLAG_ADMIN | QUFLAG_DEV))
354 #define UHasAdminPriv(x) ((x)->flags & (QUFLAG_ADMIN | QUFLAG_DEV))
355
356 #define USetGline(x) ((x)->flags |= QUFLAG_GLINE)
357 #define USetNotice(x) ((x)->flags |= QUFLAG_NOTICE)
358 #define USetSuspended(x) ((x)->flags |= QUFLAG_SUSPENDED)
359 #define USetOper(x) ((x)->flags |= QUFLAG_OPER)
360 #define USetDev(x) ((x)->flags |= QUFLAG_DEV)
361 #define USetProtect(x) ((x)->flags |= QUFLAG_PROTECT)
362 #define USetHelper(x) ((x)->flags |= QUFLAG_HELPER)
363 #define USetAdmin(x) ((x)->flags |= QUFLAG_ADMIN)
364 #define USetInfo(x) ((x)->flags |= QUFLAG_INFO)
365 #define USetDelayedGline(x) ((x)->flags |= QUFLAG_DELAYEDGLINE)
366 #define USetNoAuthLimit(x) ((x)->flags |= QUFLAG_NOAUTHLIMIT)
367 #define USetCleanupExempt(x) ((x)->flags |= QUFLAG_CLEANUPEXEMPT)
368 #define USetTrust(x) ((x)->flags |= QUFLAG_TRUST)
369
370 #define UClearGline(x) ((x)->flags &= ~QUFLAG_GLINE)
371 #define UClearNotice(x) ((x)->flags &= ~QUFLAG_NOTICE)
372 #define UClearSuspended(x) ((x)->flags &= ~QUFLAG_SUSPENDED)
373 #define UClearOper(x) ((x)->flags &= ~QUFLAG_OPER)
374 #define UClearDev(x) ((x)->flags &= ~QUFLAG_DEV)
375 #define UClearProtect(x) ((x)->flags &= ~QUFLAG_PROTECT)
376 #define UClearHelper(x) ((x)->flags &= ~QUFLAG_HELPER)
377 #define UClearAdmin(x) ((x)->flags &= ~QUFLAG_ADMIN)
378 #define UClearInfo(x) ((x)->flags &= ~QUFLAG_INFO)
379 #define UClearDelayedGline(x) ((x)->flags &= ~QUFLAG_DELAYEDGLINE)
380 #define UClearNoAuthLimit(x) ((x)->flags &= ~QUFLAG_NOAUTHLIMIT)
381 #define UClearCleanupExempt(x) ((x)->flags &= ~QUFLAG_CLEANUPEXEMPT)
382 #define UClearTrust(x) ((x)->flags &= ~QUFLAG_TRUST)
383
384 /* email */
385 #define MAX_RESEND_TIME 2*3600L /* cooling off period */
386 #define VALID_EMAIL "^[-_.+[:alpha:][:digit:]]+(\\.[-_[:digit:][:alpha:]]+)*@([[:digit:][:alpha:]](-?[[:digit:][:alpha:]])*\\.)+[[:alpha:]]{2}([zmuvtgo]|fo|me|seum|op|ro)?$"
387
388 #define VALID_ACCOUNT_NAME "^[-a-z0-9]*$"
389
390 #define QMAIL_NEWACCOUNT 1 /* new account */
391 #define QMAIL_REQPW 2 /* requestpassword */
392 #define QMAIL_NEWPW 3 /* new password */
393 #define QMAIL_RESET 4 /* reset account */
394 #define QMAIL_NEWEMAIL 5 /* new email address */
395
396
397 /* Channel flags */
398 #define QCFLAG_AUTOOP 0x0001 /* +a */
399 #define QCFLAG_BITCH 0x0002 /* +b */
400 #define QCFLAG_AUTOLIMIT 0x0004 /* +c */
401 #define QCFLAG_ENFORCE 0x0008 /* +e */
402 #define QCFLAG_FORCETOPIC 0x0010 /* +f */
403 #define QCFLAG_AUTOVOICE 0x0020 /* +g */
404 #define QCFLAG_INFO 0x0040 /* +i */
405 #define QCFLAG_JOINED 0x0080 /* +j */
406 #define QCFLAG_KNOWNONLY 0x0100 /* +k */
407 #define QCFLAG_PROTECT 0x0200 /* +p */
408 #define QCFLAG_NOINFO 0x0400 /* +s */
409 #define QCFLAG_TOPICSAVE 0x0800 /* +t */
410 #define QCFLAG_VOICEALL 0x1000 /* +v */
411 #define QCFLAG_WELCOME 0x2000 /* +w */
412 #define QCFLAG_SUSPENDED 0x4000 /* +z */
413
414 #define CIsAutoOp(x) ((x)->flags & QCFLAG_AUTOOP)
415 #define CIsBitch(x) ((x)->flags & QCFLAG_BITCH)
416 #define CIsAutoLimit(x) ((x)->flags & QCFLAG_AUTOLIMIT)
417 #define CIsEnforce(x) ((x)->flags & QCFLAG_ENFORCE)
418 #define CIsForceTopic(x) ((x)->flags & QCFLAG_FORCETOPIC)
419 #define CIsAutoVoice(x) ((x)->flags & QCFLAG_AUTOVOICE)
420 #define CIsJoined(x) ((x)->flags & QCFLAG_JOINED)
421 #define CIsKnownOnly(x) ((x)->flags & QCFLAG_KNOWNONLY)
422 #define CIsProtect(x) ((x)->flags & QCFLAG_PROTECT)
423 #define CIsTopicSave(x) ((x)->flags & QCFLAG_TOPICSAVE)
424 #define CIsVoiceAll(x) ((x)->flags & QCFLAG_VOICEALL)
425 #define CIsWelcome(x) ((x)->flags & QCFLAG_WELCOME)
426 #define CIsSuspended(x) ((x)->flags & QCFLAG_SUSPENDED)
427 #define CIsInfo(x) ((x)->flags & QCFLAG_INFO)
428 #define CIsNoInfo(x) ((x)->flags & QCFLAG_NOINFO)
429
430 #define CSetAutoOp(x) ((x)->flags |= QCFLAG_AUTOOP)
431 #define CSetBitch(x) ((x)->flags |= QCFLAG_BITCH)
432 #define CSetAutoLimit(x) ((x)->flags |= QCFLAG_AUTOLIMIT)
433 #define CSetEnforce(x) ((x)->flags |= QCFLAG_ENFORCE)
434 #define CSetForceTopic(x) ((x)->flags |= QCFLAG_FORCETOPIC)
435 #define CSetAutoVoice(x) ((x)->flags |= QCFLAG_AUTOVOICE)
436 #define CSetJoined(x) ((x)->flags |= QCFLAG_JOINED)
437 #define CSetKnownOnly(x) ((x)->flags |= QCFLAG_KNOWNONLY)
438 #define CSetProtect(x) ((x)->flags |= QCFLAG_PROTECT)
439 #define CSetTopicSave(x) ((x)->flags |= QCFLAG_TOPICSAVE)
440 #define CSetVoiceAll(x) ((x)->flags |= QCFLAG_VOICEALL)
441 #define CSetWelcome(x) ((x)->flags |= QCFLAG_WELCOME)
442 #define CSetSuspended(x) ((x)->flags |= QCFLAG_SUSPENDED)
443
444 #define CClearAutoOp(x) ((x)->flags &= ~QCFLAG_AUTOOP)
445 #define CClearBitch(x) ((x)->flags &= ~QCFLAG_BITCH)
446 #define CClearAutoLimit(x) ((x)->flags &= ~QCFLAG_AUTOLIMIT)
447 #define CClearEnforce(x) ((x)->flags &= ~QCFLAG_ENFORCE)
448 #define CClearForceTopic(x) ((x)->flags &= ~QCFLAG_FORCETOPIC)
449 #define CClearAutoVoice(x) ((x)->flags &= ~QCFLAG_AUTOVOICE)
450 #define CClearJoined(x) ((x)->flags &= ~QCFLAG_JOINED)
451 #define CClearKnownOnly(x) ((x)->flags &= ~QCFLAG_KNOWNONLY)
452 #define CClearProtect(x) ((x)->flags &= ~QCFLAG_PROTECT)
453 #define CClearTopicSave(x) ((x)->flags &= ~QCFLAG_TOPICSAVE)
454 #define CClearVoiceAll(x) ((x)->flags &= ~QCFLAG_VOICEALL)
455 #define CClearWelcome(x) ((x)->flags &= ~QCFLAG_WELCOME)
456 #define CClearSuspended(x) ((x)->flags &= ~QCFLAG_SUSPENDED)
457
458 #define QCFLAG_USERCONTROL (QCFLAG_AUTOOP|QCFLAG_BITCH|QCFLAG_AUTOLIMIT| \
459 QCFLAG_ENFORCE|QCFLAG_FORCETOPIC|QCFLAG_AUTOVOICE| \
460 QCFLAG_PROTECT|QCFLAG_TOPICSAVE|QCFLAG_VOICEALL| \
461 QCFLAG_WELCOME|QCFLAG_KNOWNONLY)
462
463 #define QCFLAG_ALL 0x7fff
464
465
466 /* Channel user ("chanlev") flags */
467 /* Slightly funny order here: list the "biggest" flags at the
468 * top so we can do sorted "chanlev" output more easily */
469 #define QCUFLAG_OWNER 0x8000 /* +n */
470 #define QCUFLAG_MASTER 0x4000 /* +m */
471 #define QCUFLAG_OP 0x2000 /* +o */
472 #define QCUFLAG_VOICE 0x1000 /* +v */
473 #define QCUFLAG_AUTOOP 0x0001 /* +a */
474 #define QCUFLAG_BANNED 0x0002 /* +b */
475 #define QCUFLAG_DENY 0x0004 /* +d */
476 #define QCUFLAG_AUTOVOICE 0x0008 /* +g */
477 #define QCUFLAG_QUIET 0x0010 /* +q */
478 #define QCUFLAG_NOINFO 0x0020 /* +s */
479 #define QCUFLAG_TOPIC 0x0040 /* +t */
480 #define QCUFLAG_HIDEWELCOME 0x0080 /* +w */
481 #define QCUFLAG_PROTECT 0x0100 /* +p */
482 #define QCUFLAG_INFO 0x0200 /* +i */
483 #define QCUFLAG_KNOWN 0x0400 /* +k */
484 #define QCUFLAG_AUTOINVITE 0x0800 /* +j */
485
486 #define QCUFLAG_SIGNIFICANT (QCUFLAG_MASTER|QCUFLAG_OWNER|QCUFLAG_OP)
487
488 #define QCUFLAG_MASTERCON (QCUFLAG_AUTOOP|QCUFLAG_BANNED|QCUFLAG_DENY| \
489 QCUFLAG_GIVE|QCUFLAG_OP|QCUFLAG_QUIET|QCUFLAG_TOPIC| \
490 QCUFLAG_VOICE|QCUFLAG_PROTECT)
491
492 #define QCUFLAG_SELFCON (QCUFLAG_OP | QCUFLAG_VOICE | QCUFLAG_AUTOOP | QCUFLAG_AUTOVOICE | \
493 QCUFLAG_TOPIC | QCUFLAG_INFO)
494
495 #define QCUFLAGS_PUBLIC (QCUFLAG_OWNER | QCUFLAG_MASTER | QCUFLAG_OP | QCUFLAG_VOICE | \
496 QCUFLAG_KNOWN | QCUFLAG_AUTOOP | QCUFLAG_AUTOVOICE | QCUFLAG_TOPIC | \
497 QCUFLAG_PROTECT)
498
499 #define QCUFLAGS_PUNISH (QCUFLAG_BANNED | QCUFLAG_QUIET | QCUFLAG_DENY)
500 #define QCUFLAGS_PERSONAL (QCUFLAG_HIDEWELCOME | QCUFLAG_AUTOINVITE)
501
502 #define QCUFLAG_ALL 0xffff
503
504 #define CUIsOwner(x) ((x)->flags & QCUFLAG_OWNER)
505 #define CUIsMaster(x) ((x)->flags & QCUFLAG_MASTER)
506 #define CUIsOp(x) ((x)->flags & QCUFLAG_OP)
507 #define CUIsVoice(x) ((x)->flags & QCUFLAG_VOICE)
508 #define CUIsAutoOp(x) ((x)->flags & QCUFLAG_AUTOOP)
509 #define CUIsBanned(x) ((x)->flags & QCUFLAG_BANNED)
510 #define CUIsDeny(x) ((x)->flags & QCUFLAG_DENY)
511 #define CUIsAutoVoice(x) ((x)->flags & QCUFLAG_AUTOVOICE)
512 #define CUIsQuiet(x) ((x)->flags & QCUFLAG_QUIET)
513 #define CUIsNoInfo(x) ((x)->flags & QCUFLAG_NOINFO)
514 #define CUIsTopic(x) ((x)->flags & QCUFLAG_TOPIC)
515 #define CUIsHideWelcome(x) ((x)->flags & QCUFLAG_HIDEWELCOME)
516 #define CUIsProtect(x) ((x)->flags & QCUFLAG_PROTECT)
517 #define CUIsInfo(x) ((x)->flags & QCUFLAG_INFO)
518 #define CUIsKnown(x) ((x)->flags & QCUFLAG_KNOWN)
519 #define CUIsAutoInvite(x) ((x)->flags & QCUFLAG_AUTOINVITE)
520
521 #define CUKnown(x) (CUIsKnown(x) || CUHasVoicePriv(x))
522 #define CUHasVoicePriv(x) ((x)->flags & (QCUFLAG_VOICE | QCUFLAG_OP | QCUFLAG_MASTER | QCUFLAG_OWNER))
523 #define CUHasOpPriv(x) ((x)->flags & (QCUFLAG_OP | QCUFLAG_MASTER | QCUFLAG_OWNER))
524 #define CUHasMasterPriv(x) ((x)->flags & (QCUFLAG_MASTER | QCUFLAG_OWNER))
525 #define CUHasTopicPriv(x) ((x)->flags & (QCUFLAG_MASTER | QCUFLAG_OWNER | QCUFLAG_TOPIC))
526
527 #define CUSetOwner(x) ((x)->flags |= QCUFLAG_OWNER)
528 #define CUSetMaster(x) ((x)->flags |= QCUFLAG_MASTER)
529 #define CUSetOp(x) ((x)->flags |= QCUFLAG_OP)
530 #define CUSetVoice(x) ((x)->flags |= QCUFLAG_VOICE)
531 #define CUSetAutoOp(x) ((x)->flags |= QCUFLAG_AUTOOP)
532 #define CUSetBanned(x) ((x)->flags |= QCUFLAG_BANNED)
533 #define CUSetDeny(x) ((x)->flags |= QCUFLAG_DENY)
534 #define CUSetAutoVoice(x) ((x)->flags |= QCUFLAG_AUTOVOICE)
535 #define CUSetQuiet(x) ((x)->flags |= QCUFLAG_QUIET)
536 #define CUSetTopic(x) ((x)->flags |= QCUFLAG_TOPIC)
537 #define CUSetHideWelcome(x) ((x)->flags |= QCUFLAG_HIDEWELCOME)
538 #define CUSetKnown(x) ((x)->flags |= QCUFLAG_KNOWN)
539 #define CUSetAutoInvite(x) ((x)->flags |= QCUFLAG_AUTOINVITE)
540
541 #define CUClearOwner(x) ((x)->flags &= ~QCUFLAG_OWNER)
542 #define CUClearMaster(x) ((x)->flags &= ~QCUFLAG_MASTER)
543 #define CUClearOp(x) ((x)->flags &= ~QCUFLAG_OP)
544 #define CUClearVoice(x) ((x)->flags &= ~QCUFLAG_VOICE)
545 #define CUClearAutoOp(x) ((x)->flags &= ~QCUFLAG_AUTOOP)
546 #define CUClearBanned(x) ((x)->flags &= ~QCUFLAG_BANNED)
547 #define CUClearDeny(x) ((x)->flags &= ~QCUFLAG_DENY)
548 #define CUClearAutoVoice(x) ((x)->flags &= ~QCUFLAG_AUTOVOICE)
549 #define CUClearQuiet(x) ((x)->flags &= ~QCUFLAG_QUIET)
550 #define CUClearTopic(x) ((x)->flags &= ~QCUFLAG_TOPIC)
551 #define CUClearHideWelcome(x) ((x)->flags &= ~QCUFLAG_HIDEWELCOME)
552 #define CUClearKnown(x) ((x)->flags &= ~QCUFLAG_KNOWN)
553 #define CUClearAutoInvite(x) ((x)->flags &= ~QCUFLAG_AUTOINVITE)
554
555 #define QCSTAT_OPCHECK 0x0001 /* Do op check */
556 #define QCSTAT_MODECHECK 0x0002 /* Do mode check */
557 #define QCSTAT_BANCHECK 0x0004 /* Do ban check */
558
559 #define QUSTAT_DEAD 0x8000 /* User has been deleted.. */
560
561 #define QCMD_SECURE 0x0001 /* Must use "user@server" to use this command */
562 #define QCMD_AUTHED 0x0002 /* Only available to authed users */
563 #define QCMD_NOTAUTHED 0x0004 /* Only available to NON-authed users */
564
565 #define QCMD_HELPER 0x0010 /* Only available to helpers */
566 #define QCMD_OPER 0x0020 /* Only available to opers */
567 #define QCMD_ADMIN 0x0040 /* Only available to admins */
568 #define QCMD_DEV 0x0080 /* Only available to developers */
569
570 #define QCMD_ALIAS 0x0100 /* Don't list on SHOWCOMMANDS */
571
572 #define CS_INIT_DB 0x1 /* Loading database.. */
573 #define CS_INIT_NOUSER 0x2 /* Loaded DB, waiting for user to be created */
574 #define CS_INIT_READY 0x3 /* Ready for action! */
575
576 struct regchanuser;
577 struct reguser;
578
579 typedef struct maildomain {
580 #ifdef CS_PARANOID
581 unsigned int maildomain_magic;
582 #endif
583 unsigned int ID;
584 sstring *name;
585 unsigned int count;
586 unsigned int limit;
587 unsigned int actlimit;
588 flag_t flags;
589 struct reguser *users;
590 struct maildomain *parent;
591 struct maildomain *nextbyname;
592 struct maildomain *nextbyID;
593 } maildomain;
594
595 #define MDFLAG_LIMIT 0x0001 /* +l */
596 #define MDFLAG_BANNED 0x0002 /* +b */
597 #define MDFLAG_ACTLIMIT 0x0004 /* +u */
598 #define MDFLAG_ALL 0x0007
599
600 #define MDFLAG_DEFAULT MDFLAG_ACTLIMIT
601
602 #define MDHasLimit(x) ((x)->flags & MDFLAG_LIMIT)
603 #define MDSetLimit(x) ((x)->flags |= MDFLAG_LIMIT)
604 #define MDClearLimit(x) ((x)->flags &= ~MDFLAG_LIMIT)
605 #define MDIsBanned(x) ((x)->flags & MDFLAG_BANNED)
606 #define MDSetBanned(x) ((x)->flags |= MDFLAG_BANNED)
607 #define MDClearBanned(x) ((x)->flags &= ~MDFLAG_BANNED)
608 #define MDHasActLimit(x) ((x)->flags & MDFLAG_ACTLIMIT)
609 #define MDSetActLimit(x) ((x)->flags |= MDFLAG_ACTLIMIT)
610 #define MDClearActLimit(x) ((x)->flags &= ~MDFLAG_ACTLIMIT)
611
612 /* "Q" ban */
613 typedef struct regban {
614 #ifdef CS_PARANOID
615 unsigned int regchanban_magic;
616 #endif
617 unsigned int ID; /* ID in the database */
618 struct chanban *cbp; /* Standard chanban struct */
619 unsigned int setby; /* Who set the ban */
620 time_t expiry; /* When the ban expires */
621 sstring *reason; /* Reason to attach to related kicks */
622 struct regban *next; /* Next ban on this channel */
623 } regban;
624
625 /* Registered channel */
626 typedef struct regchan {
627 #ifdef CS_PARANOID
628 unsigned int regchan_magic;
629 #endif
630 unsigned int ID; /* Unique number from database */
631 chanindex *index; /* Pointer to the channel index record */
632 time_t ltimestamp; /* The last timestamp we saw on this channel */
633
634 flag_t flags; /* Chanflags */
635 flag_t status; /* Runtime status codes */
636 flag_t forcemodes; /* Forced modes */
637 flag_t denymodes; /* Denied modes */
638
639 short limit; /* Limit to enforce if +l is set */
640 short autolimit; /* How many slots to leave when autolimiting */
641 short banstyle; /* Ban style for +b type bans */
642
643 time_t created; /* When the service was added */
644 time_t lastactive; /* When the channel was last "active" */
645 time_t statsreset; /* When the users stats were last reset */
646 time_t ostatsreset; /* When the oper stats were last reset */
647 time_t banduration; /* How long to remove bans after (0=don't) */
648 time_t autoupdate; /* When the autolimit next needs checking */
649 time_t lastbancheck; /* Timestamp of last ban check */
650 time_t lastcountersync; /* When the counters were last synced.. */
651 time_t lastpart; /* When the last user left the channel */
652 time_t suspendtime; /* When the channel was suspended */
653
654 unsigned int founder; /* founder */
655 unsigned int addedby; /* oper adding chan */
656 unsigned int suspendby; /* who suspended chan */
657
658 short chantype; /* What "type" the channel is */
659
660 unsigned int totaljoins; /* Total joins since created */
661 unsigned int tripjoins; /* Total joins since last stats reset */
662 unsigned int otripjoins; /* Total joins since last oper stats reset */
663 unsigned int maxusers; /* Max users since created */
664 unsigned int tripusers; /* Max users since last stats reset */
665 unsigned int otripusers; /* Max users since last oper stats reset */
666
667 sstring *welcome; /* Welcome message */
668 sstring *topic; /* "default" topic set by settopic */
669 sstring *key; /* Key as enforced by +k */
670 sstring *suspendreason; /* Suspend reason */
671 sstring *comment; /* Oper-settable channel comment */
672
673 void *checksched; /* Handle for channel check schedule */
674
675 struct regchanuser *regusers[REGCHANUSERHASHSIZE];
676 struct regban *bans; /* List of bans on the channel */
677
678 char chanopnicks[CHANOPHISTORY][NICKLEN+1]; /* Last CHANOPHISTORY ppl to get ops */
679 unsigned int chanopaccts[CHANOPHISTORY]; /* Which account was responsible for each one */
680 short chanoppos; /* Position in the array */
681 } regchan;
682
683 /* Registered user */
684 typedef struct reguser {
685 #ifdef CS_PARANOID
686 unsigned int reguser_magic;
687 #endif
688 unsigned int ID; /* From the database */
689
690 char username[NICKLEN+1];
691
692 time_t created;
693 time_t lastauth;
694 time_t lastemailchange;
695
696 flag_t flags; /* user flags */
697 flag_t status; /* runtime status */
698 short languageid; /* what language to speak to the user */
699
700 unsigned int suspendby; /* Userid of oper who suspended this user */
701 time_t suspendexp; /* Expiry date of suspension */
702 time_t suspendtime; /* When user was suspended */
703 time_t lockuntil; /* Time until users account is unlocked (pass change, email, etc) */
704
705 char password[PASSLEN+1];
706
707 sstring *localpart;
708 maildomain *domain;
709
710 sstring *email; /* Registered e-mail */
711 sstring *lastemail; /* Last registered e-mail */
712 sstring *lastuserhost; /* Last user@host */
713 sstring *suspendreason; /* Why the account is suspended */
714 sstring *comment; /* Oper-settable user comment */
715 sstring *info; /* User-settable info line */
716
717 struct regchanuser *knownon; /* Which channels this user is known on */
718
719 /* These fields are for the nick protection system */
720 void *checkshd; /* When we're going to check for an imposter */
721 int stealcount; /* How many times we've had to free the nick up */
722 nick *fakeuser; /* If we had to "take" the nick, here's the pointer */
723
724 struct reguser *nextbydomain;
725 struct reguser *nextbyname;
726 struct reguser *nextbyID;
727 } reguser;
728
729 /* Registered channel user */
730 typedef struct regchanuser {
731 #ifdef CS_PARANOID
732 unsigned int regchanuser_magic;
733 #endif
734 struct reguser *user;
735 struct regchan *chan;
736 flag_t flags;
737 time_t changetime; /* Timestamp of last "significant" change */
738 time_t usetime; /* Timestamp of last use */
739 sstring *info; /* User-settable info line */
740 struct regchanuser *nextbyuser;
741 struct regchanuser *nextbychan;
742 } regchanuser;
743
744 typedef struct cslang {
745 char code[3];
746 sstring *name;
747 } cslang;
748
749 typedef struct cmdsummary {
750 sstring *def;
751 sstring *bylang[MAXLANG];
752 char *defhelp;
753 } cmdsummary;
754
755 typedef struct activeuser {
756 #ifdef CS_PARANOID
757 unsigned int activeuser_magic;
758 #endif
759 unsigned short authattempts; /* number of times user has attempted to auth */
760 unsigned short helloattempts; /* number of times user has attempted to hello... */
761 unsigned char entropy[ENTROPYLEN]; /* entropy used for challengeauth */
762 time_t entropyttl;
763 struct activeuser *next; /* purely for keeping track of free, but not free'd structures */
764 } activeuser;
765
766 typedef struct maillock {
767 #ifdef CS_PARANOID
768 unsigned int maillock_magic;
769 #endif
770 unsigned int id;
771 sstring *pattern;
772 sstring *reason;
773 unsigned int createdby;
774 time_t created;
775 struct maillock *next;
776 } maillock;
777
778 #ifdef CS_PARANOID
779
780 #define REGUSERMAGIC 0x4d42de03
781 #define REGCHANMAGIC 0x5bf2aa30
782 #define REGCHANUSERMAGIC 0x19628b63
783 #define REGCHANBANMAGIC 0x5a6f555a
784 #define ACTIVEUSERMAGIC 0x897f98a0
785 #define MAILDOMAINMAGIC 0x27cde46f
786 #define MAILLOCKMAGIC 0x3c81d762
787
788 #define verifyreguser(x) assert((x)->reguser_magic == REGUSERMAGIC)
789 #define verifyregchan(x) assert((x)->regchan_magic == REGCHANMAGIC)
790 #define verifyregchanuser(x) assert((x)->regchanuser_magic == REGCHANUSERMAGIC)
791 #define verifyregchanban(x) assert((x)->regchanban_magic == REGCHANBANMAGIC)
792 #define verifyactiveuser(x) assert((x)->activeuser_magic == ACTIVEUSERMAGIC)
793 #define verifymaildomain(x) assert((x)->maildomain_magic == MAILDOMAINMAGIC)
794 #define verifymaillock(x) assert((x)->maillock_magic == MAILLOCKMAGIC)
795
796 #define tagreguser(x) ((x)->reguser_magic = REGUSERMAGIC)
797 #define tagregchan(x) ((x)->regchan_magic = REGCHANMAGIC)
798 #define tagregchanuser(x) ((x)->regchanuser_magic = REGCHANUSERMAGIC)
799 #define tagregchanban(x) ((x)->regchanban_magic = REGCHANBANMAGIC)
800 #define tagactiveuser(x) ((x)->activeuser_magic = ACTIVEUSERMAGIC)
801 #define tagmaildomain(x) ((x)->maildomain_magic = MAILDOMAINMAGIC)
802 #define tagmaillock(x) ((x)->maillock_magic = MAILLOCKMAGIC)
803 #else
804
805 #define verifyreguser(x)
806 #define verifyregchan(x)
807 #define verifyregchanuser(x)
808 #define verifyregchanban(x)
809 #define verifyactiveuser(x)
810 #define verifymaildomain(x)
811 #define verifymaillock(x)
812
813 #define tagreguser(x)
814 #define tagregchan(x)
815 #define tagregchanuser(x)
816 #define tagregchanban(x)
817 #define tagactiveuser(x)
818 #define tagmaildomain(x)
819 #define tagmaillock(x)
820
821 #endif
822
823 #define getactiveuserfromnick(x) ((activeuser*)(x)->exts[chanservnext])
824 #define getreguserfromnick(x) ((x)->auth?(reguser *)(x)->auth->exts[chanservaext]:NULL)
825
826 /* Global variables for chanserv module */
827 extern unsigned int lastuserID;
828 extern unsigned int lastchannelID;
829 extern unsigned int lastbanID;
830 extern unsigned int lastdomainID;
831 extern unsigned int lastmaillockID;
832
833 extern int chanserv_init_status;
834 extern int chanservdb_ready;
835 extern PQModuleIdentifier q9pqid, q9apqid, q9cpqid, q9upqid;
836
837 extern maildomain *maildomainnametable[MAILDOMAINHASHSIZE];
838 extern maildomain *maildomainIDtable[MAILDOMAINHASHSIZE];
839
840 extern reguser *regusernicktable[REGUSERHASHSIZE];
841 extern reguser *deadusers;
842
843 extern nick *chanservnick;
844 extern int chanservext;
845 extern int chanservnext;
846 extern int chanservaext;
847
848 extern cslang *cslanguages[MAXLANG];
849 extern unsigned int cslangcount;
850
851 extern sstring *csmessages[MAXLANG][MAXMESSAGES];
852 extern char *defaultmessages[MAXMESSAGES];
853
854 extern const flag rcflags[];
855 extern const flag rcuflags[];
856 extern const flag ruflags[];
857 extern const flag mdflags[];
858
859 extern CommandTree *cscommands;
860
861 extern sstring **chantypes;
862
863 extern maillock *maillocks;
864
865 /* Function prototypes */
866
867 /* chanserv.c */
868 void chanserv_finalinit();
869
870 /* chanservalloc.c */
871 void chanservallocinit();
872 void csfreeall();
873 regchan *getregchan();
874 void freeregchan(regchan *rcp);
875 reguser *getreguser();
876 void freereguser(reguser *rup);
877 regchanuser *getregchanuser();
878 void freeregchanuser(regchanuser *rcup);
879 regban *getregban();
880 void freeregban(regban *rbp);
881 activeuser *getactiveuser();
882 void freeactiveuser(activeuser *aup);
883 maildomain *getmaildomain();
884 void freemaildomain(maildomain *mdp);
885 maillock *getmaillock();
886 void freemaillock(maillock *mlp);
887
888 /* chanservhash.c */
889 void chanservhashinit();
890 void addregusertohash(reguser *rup);
891 reguser *findreguserbyID(unsigned int ID);
892 reguser *findreguserbynick(const char *nick);
893 reguser *findreguser(nick *sender, const char *str);
894 void removereguserfromhash(reguser *rup);
895 void addregchantohash(regchan *rcp);
896 regchan *findregchanbyID(unsigned int ID);
897 regchan *findregchanbyname(const char *name);
898 void removeregchanfromhash(regchan *rcp);
899 void addregusertochannel(regchanuser *rcup);
900 regchanuser *findreguseronchannel(regchan *rcp, reguser *rup);
901 void delreguserfromchannel(regchan *rcp, reguser *rup);
902 void addmaildomaintohash(maildomain *mdp);
903 maildomain *findmaildomainbyID(unsigned int ID);
904 maildomain *findmaildomainbydomain(char *domain);
905 maildomain *findmaildomainbyemail(char *email);
906 maildomain *findorcreatemaildomain(char *email);
907 maildomain *findnearestmaildomain(char *domain);
908 void removemaildomainfromhash(maildomain *mdp);
909 void addregusertomaildomain(reguser *rup, maildomain *mdp);
910 void delreguserfrommaildomain(reguser *rup, maildomain *mdp);
911 reguser *findreguserbyemail(const char *email);
912
913 /* chanservdb.c */
914 int chanservdbinit();
915 void loadmessages();
916 void loadcommandsummary(Command *cmd);
917 void chanservdbclose();
918 void csdb_updatetopic(regchan *rcp);
919 void csdb_updatelastjoin(regchanuser *rcup);
920 void csdb_updateauthinfo(reguser *rup);
921 void csdb_updatechannel(regchan *rcp);
922 void csdb_createchannel(regchan *rcp);
923 void csdb_deletechannel(regchan *rcp);
924 void csdb_deleteuser(reguser *rup);
925 void csdb_updatechannelcounters(regchan *rcp);
926 void csdb_updatechanneltimestamp(regchan *rcp);
927 void csdb_updatechanuser(regchanuser *rcup);
928 void csdb_createchanuser(regchanuser *rcup);
929 void csdb_deletechanuser(regchanuser *rcup);
930 void csdb_createuser(reguser *rup);
931 void csdb_updateuser(reguser *rup);
932 void csdb_createban(regchan *rcp, regban *rbp);
933 void csdb_deleteban(regban *rbp);
934 void csdb_updateban(regchan *rcp, regban *rbp);
935 char *csdb_gethelpstr(char *command, int language);
936 void csdb_createmail(reguser *rup, int type);
937 void csdb_dohelp(nick *np, Command *cmd);
938
939 #define q9asyncquery(handler, tag, format, ...) pqasyncqueryi(q9pqid, handler, tag, format , ##__VA_ARGS__)
940 #define q9a_asyncquery(handler, tag, format, ...) pqasyncqueryi(q9apqid, handler, tag, format , ##__VA_ARGS__)
941 #define q9u_asyncquery(handler, tag, format, ...) pqasyncqueryi(q9upqid, handler, tag, format , ##__VA_ARGS__)
942 #define q9c_asyncquery(handler, tag, format, ...) pqasyncqueryi(q9cpqid, handler, tag, format , ##__VA_ARGS__)
943
944 /* chanservcrypto.c */
945 typedef int (*CRAlgorithm)(char *, const char *, const char *, const char *);
946 void chanservcryptoinit(void);
947 void chanservcryptofree(void);
948 void cs_getrandbytes(unsigned char *buf, size_t bytes);
949 char *cs_calcchallenge(const unsigned char *entropy);
950 CRAlgorithm cs_cralgorithm(const char *algorithm);
951 const char *cs_cralgorithmlist(void);
952 int cs_checkhashpass(const char *username, const char *password, const char *junk, const char *hash);
953 char *csc_generateresetcode(time_t lockuntil, char *username);
954
955 /* chanservuser.c */
956 void chanservreguser(void *arg);
957 void chanservjoinchan(channel *cp);
958 #define chanservsendmessage(np, fmt, args...) chanservsendmessage_real(np, 0, fmt , ## args)
959 #define chanservsendmessageoneline(np, fmt, args...) chanservsendmessage_real(np, 1, fmt , ## args)
960 void chanservsendmessage_real(nick *np, int oneline, char *message, ... );
961 void chanservwallmessage(char *message, ... );
962 void chanservcommandinit();
963 void chanservcommandclose();
964 void chanservstdmessage(nick *np, int messageid, ... );
965 void chanservaddcommand(char *command, int flags, int maxparams, CommandHandler handler, char *description, const char *help);
966 void chanservremovecommand(char *command, CommandHandler handler);
967 void chanservaddctcpcommand(char *command, CommandHandler hander);
968 void chanservremovectcpcommand(char *command, CommandHandler handler);
969 void chanservkillstdmessage(nick *target, int messageid, ... );
970 int checkpassword(reguser *rup, const char *pass);
971 int setpassword(reguser *rup, const char *pass);
972 /*reguser *getreguserfromnick(nick *np);
973 activeuser *getactiveuserfromnick(nick *np);*/
974 void cs_checknick(nick *np);
975 void cs_checkchanmodes(channel *cp);
976 void cs_docheckchanmodes(channel *cp, modechanges *changes);
977 void cs_docheckopvoice(channel *cp, modechanges *changes);
978 void cs_checkbans(channel *cp);
979 void cs_schedupdate(chanindex *cip, int mintime, int maxtime);
980 void cs_timerfunc(void *arg);
981 void cs_removechannel(regchan *rcp);
982 int cs_removechannelifempty(nick *sender, regchan *rcp);
983 void cs_doallautomodes(nick *np);
984 void cs_checknickbans(nick *np);
985 void cs_setregban(chanindex *cip, regban *rbp);
986 int cs_bancheck(nick *np, channel *cp);
987 void cs_banuser(modechanges *changes, chanindex *cip, nick *np, const char *reason);
988 void cs_removeuser(reguser *rup);
989 int checkresponse(reguser *rup, const unsigned char *entropy, const char *response, CRAlgorithm algorithm);
990 int checkhashpass(reguser *rup, const char *junk, const char *hash);
991 flag_t cs_sanitisechanlev(flag_t flags);
992 typedef int (*UnbanFN)(void *arg, struct chanban *ban);
993 int cs_unbanfn(nick *sender, chanindex *cip, UnbanFN fn, void *arg, int removepermbans, int abortonfailure);
994 void cs_logchanop(regchan *rcp, char *nick, reguser *rup);
995
996 /* chanservstdcmds.c */
997 int cs_doshowcommands(void *source, int cargc, char **cargv);
998 int cs_dohelp(void *source, int cargc, char **cargv);
999 int cs_doquit(void *source, int cargc, char **cargv);
1000 int cs_dorename(void *source, int cargc, char **cargv);
1001 int cs_dorehash(void *source, int cargc, char **cargv);
1002 int cs_doversion(void *source, int cargc, char **cargv);
1003 int cs_doctcpping(void *source, int cargc, char **cargv);
1004 int cs_doctcpversion(void *source, int cargc, char **cargv);
1005 int cs_doctcpgender(void *source, int cargc, char **cargv);
1006 int cs_sendhelp(nick *sender, char *cmd, int oneline);
1007
1008 /* chanservnetevents.c */
1009 void cs_handlenick(int hooknum, void *arg);
1010 void cs_handlesethost(int hooknum, void *arg);
1011 void cs_handlelostnick(int hooknum, void *arg);
1012 void cs_handlenewchannel(int hooknum, void *arg);
1013 void cs_handlelostchannel(int hooknum, void *arg);
1014 void cs_handlejoin(int hooknum, void *arg);
1015 void cs_handlemodechange(int hooknum, void *arg);
1016 void cs_handleburst(int hooknum, void *arg);
1017 void cs_handletopicchange(int hooknum, void *arg);
1018 void cs_handleopchange(int hooknum, void *arg);
1019 void cs_handlenewban(int hooknum, void *arg);
1020 void cs_handlechanlostuser(int hooknum, void *arg);
1021
1022 /* chanservmessages.c */
1023 void initmessages();
1024
1025 /* chanservprivs.c */
1026 int cs_privcheck(int privnum, nick *np);
1027 chanindex *cs_checkaccess(nick *np, const char *chan, unsigned int flags, chanindex *cip, const char *cmdname, int priv, int quiet);
1028
1029 /* chanservlog.c */
1030 void cs_initlog();
1031 void cs_closelog();
1032 void cs_log(nick *np, char *event, ...);
1033
1034 /* chanservdump.c */
1035 int dumplastjoindata(const char *filename);
1036 int readlastjoindata(const char *filename);
1037
1038 /* chanservschedule.c */
1039 void chanservdgline(void *arg);
1040
1041 /* authlib.c */
1042 int csa_checkeboy(nick *sender, char *eboy);
1043 void csa_createrandompw(char *pw, int n);
1044 int csa_checkthrottled(nick *sender, reguser *rup, char *s);
1045
1046 /* chanservdb_updates.c */
1047 void csdb_updateauthinfo(reguser *rup);
1048 void csdb_updatelastjoin(regchanuser *rcup);
1049 void csdb_updatetopic(regchan *rcp);
1050 void csdb_updatechannel(regchan *rcp);
1051 void csdb_updatechannelcounters(regchan *rcp);
1052 void csdb_updatechanneltimestamp(regchan *rcp);
1053 void csdb_createchannel(regchan *rcp);
1054 void csdb_deletechannel(regchan *rcp);
1055 void csdb_deleteuser(reguser *rup);
1056 void csdb_updateuser(reguser *rup);
1057 void csdb_createuser(reguser *rup);
1058 void csdb_updatechanuser(regchanuser *rcup);
1059 void csdb_createchanuser(regchanuser *rcup);
1060 void csdb_deletechanuser(regchanuser *rcup);
1061 void csdb_createban(regchan *rcp, regban *rbp);
1062 void csdb_deleteban(regban *rbp);
1063 void csdb_createmail(reguser *rup, int type);
1064 void csdb_deletemaildomain(maildomain *mdp);
1065 void csdb_createmaildomain(maildomain *mdp);
1066 void csdb_updatemaildomain(maildomain *mdp);
1067 void csdb_chanlevhistory_insert(regchan *rcp, nick *np, reguser *trup, flag_t oldflags, flag_t newflags);
1068 void csdb_accounthistory_insert(nick *np, char *oldpass, char *newpass, sstring *oldemail, sstring *newemail);
1069 void csdb_cleanuphistories();
1070 void csdb_deletemaillock(maillock *mlp);
1071 void csdb_createmaillock(maillock *mlp);
1072 void csdb_updatemaillock(maillock *mlp);
1073
1074 #endif