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