#define _GNU_SOURCE
#include <string.h>
#include <time.h>
+#include <stdarg.h>
#include "../lib/sstring.h"
#include "../core/schedule.h"
#include "../lib/flags.h"
#include "../channel/channel.h"
#include "../parser/parser.h"
#include "../localuser/localuserchannel.h"
-#include "../pqsql/pqsql.h"
+#include "../dbapi/dbapi.h"
#define CS_PARANOID
#endif
/* Q9 Version */
-#define QVERSION "1.00-RC1"
+#define QVERSION "1.00"
/* Mini-hash of known users on channels to make lookups faster;
* how big do we make it? */
/* Maximum number of accounts that may share an email address */
#define MD_DEFAULTACTLIMIT 2
+/* If set will issue warnings when authgate cached stuff changes */
+#define AUTHGATE_WARNINGS
+
+/* Challenge auth faq site */
+#define CHALLENGEAUTHSITE "http://www.quakenet.org/development/challengeauth/"
+
+/* Cleanup options */
+#define CLEANUP_ACCOUNT_INACTIVE 80
+#define CLEANUP_ACCOUNT_UNUSED 10
+#define CLEANUP_CHANNEL_INACTIVE 40
+
/* Sizes of the main hashes */
#define REGUSERHASHSIZE 60000
#define MAILDOMAINHASHSIZE 60000
/* Number of languages and messages */
#define MAXLANG 50
-#define MAXMESSAGES 200
/* Maximum number of user chanlevs and bans */
-#define MAXCHANLEVS 250
+#define MAXCHANLEVS 500
#define MAXBANS 50
/* Sources of entropy and standard length defines */
#define ENTROPYSOURCE "/dev/urandom"
#define ENTROPYLEN 8
-/* The list of messages */
-#define QM_PROTECTED 0
-#define QM_UNKNOWNCMD 1
-#define QM_SECUREONLY 2
-#define QM_AUTHEDONLY 3
-#define QM_UNAUTHEDONLY 4
-#define QM_COMMANDLIST 5
-#define QM_ENDOFLIST 6
-#define QM_DONE 7
-#define QM_NOTENOUGHPARAMS 8
-#define QM_UNKNOWNCHAN 9
-#define QM_NOACCESSONCHAN 10
-#define QM_CURCHANFLAGS 11
-#define QM_CURFORCEMODES 12
-#define QM_NOACCESS 13
-#define QM_UNKNOWNUSER 14
-#define QM_USERNOTAUTHED 15
-#define QM_CHANLEVHEADER 16
-#define QM_CHANLEVCOLSHORT 17
-#define QM_CHANLEVCOLFULL 18
-#define QM_NOUSERSONCHANLEV 19
-#define QM_CHANUSERFLAGS 20
-#define QM_CHANUSERUNKNOWN 21
-#define QM_INVALIDCHANLEVCHANGE 22
-#define QM_USERISAUTHEDAS 23
-#define QM_USERISHELPER 24
-#define QM_USERISOPER 25
-#define QM_USERISADMIN 26
-#define QM_USERISDEV 27
-#define QM_WHOISHEADER 28
-#define QM_WHOISCOLS 29
-#define QM_USERONNOCHANS 30
-#define QM_CHANAUTOLIMIT 31
-#define QM_CHANBANAUTOREMOVE 32
-#define QM_NOCHANBANAUTOREMOVE 33
-#define QM_INVALIDCHANNAME 34
-#define QM_ALREADYREGISTERED 35
-#define QM_CURUSERFLAGS 36
-#define QM_WELCOMEMESSAGEIS 37
-#define QM_GLOBALINFO 38
-#define QM_CHANNELINFO 39
-#define QM_PROTECTEDNICK 40
-#define QM_NICKWASFAKED 41
-#define QM_NOTPROTECTED 42
-#define QM_SAMEAUTH 43
-#define QM_AUTHFAIL 44
-#define QM_AUTHOK 45
-#define QM_NEWACCOUNT 46
-#define QM_AUTHNAMEINUSE 47
-#define QM_ALREADYONCHAN 48
-#define QM_NOTONCHAN 49
-#define QM_ALREADYOPPED 50
-#define QM_USERNOTONCHAN 51
-#define QM_USEROPPEDONCHAN 52
-#define QM_CANTOP 53
-#define QM_NOTOPPED 54
-#define QM_ALREADYVOICED 55
-#define QM_NOTVOICED 56
-#define QM_USERVOICEDONCHAN 57
-#define QM_REGBANHEADER 58
-#define QM_NOBANS 59
-#define QM_REMOVEDCHANBAN 60
-#define QM_NOTREMOVEDPERMBAN 61
-#define QM_REMOVEDPERMBAN 62
-#define QM_CANTVOICE 63
-#define QM_NOHELP 64
-#define QM_WHOISHEADER_NICK 65
-#define QM_WHOISHEADER_AUTH 66
-#define QM_WHOIS_USERS 67
-#define QM_WHOIS_LASTAUTH 68
-#define QM_WHOIS_LASTUSERHOST 69
-#define QM_WHOIS_USERID 70
-#define QM_WHOIS_INFO 71
-#define QM_WHOIS_COMMENT 72
-#define QM_WHOIS_FLAGS 73
-#define QM_WHOIS_CREATED 74
-#define QM_WHOIS_CHANHEADER 75
-#define QM_WHOIS_EMAIL 76
-#define QM_WHOIS_EMAILSET 77
-#define QM_COMMENT 78
-#define QM_NOCOMMENT 79
-#define QM_BADAUTH 80
-#define QM_USERHASBADAUTH 81
-#define QM_BADEMAIL 82
-#define QM_MAILTHROTTLED 83
-#define QM_MAILQUEUED 84
-#define QM_PWDONTMATCH 85
-#define QM_PWTOSHORT 86
-#define QM_PWCHANGED 87
-#define QM_INVALIDDURATION2 88
-#define QM_EMAILCHANGED 89
-#define QM_EMAILDONTMATCH 90
-#define QM_INVALIDEMAIL 91
-#define QM_EMAILTOOSHORT 92
-#define QM_NOTYOUREMAIL 93
-#define QM_EMAILNOAT 94
-#define QM_EMAILATEND 95
-#define QM_EMAILINVCHR 96
-#define QM_CHANNELNOTSUSPENDED 97
-#define QM_CHANNELALREADYSUSPENDED 98
-#define QM_CHANTYPE 99
-#define QM_UNKNOWNCHANTYPE 100
-#define QM_FOUNDER 101
-#define QM_ADDEDBY 102
-#define QM_ALREADYKNOWNONCHAN 103
-#define QM_CANNOTREMOVEOWNER 104
-#define QM_CANNOTREMOVEMASTER 105
-#define QM_UNKNOWNBAN 106
-#define QM_YOURLANGUAGE 107
-#define QM_LANGUAGELIST 108
-#define QM_UNKNOWNLANGUAGE 109
-#define QM_WHOIS_USERLANG 110
-#define QM_CHANTYPEIS 111
-#define QM_STATSHEADER 112
-#define QM_STATSADDED 113
-#define QM_STATSJOINS 114
-#define QM_STATSLASTACTIVE 115
-#define QM_AUTHSUSPENDED 116
-#define QM_REASON 117
-#define QM_EXPIRES 118
-#define QM_TOOMANYAUTHS 119
-#define QM_INVALIDDURATION 120
-#define QM_DISCONNECTINGUSER 121
-#define QM_USERALREADYSUSPENDED 122
-#define QM_USERNOTSUSPENDED 123
-#define QM_SPEWHEADER 124
-#define QM_TOOMANYRESULTS 125
-#define QM_RESULTCOUNT 126
-#define QM_SUSPENDKILL 127
-#define QM_LISTFLAGSHEADER 128
-#define QM_SUSPENDUSERLISTHEADER 129
-#define QM_SUSPENDCHANLISTHEADER 130
-#define QM_NOREQUESTOWNER 131
-#define QM_GRANTEDOWNER 132
-#define QM_AUTHHISTORYHEADER 133
-#define QM_CURDOMAINMODES 134
-#define QM_SPEWDOMAINHEADER 135
-#define QM_DOMAINLIMIT 136
-#define QM_PWTOWEAK 137
-#define QM_GIVEOWNERNOTMASTER 138
-#define QM_GIVEOWNERALREADYOWNER 139
-#define QM_GIVEOWNERNEEDHASH 140
-#define QM_GIVEOWNERWRONGHASH 141
-#define QM_SHOWINGDURATION 142
-#define QM_INVALIDACCOUNTNAME 143
-#define QM_CHALLENGEBADALGORITHM 144
-#define QM_NOCHALLENGE 145
-#define QM_USEGIVEOWNER 146
-#define QM_NOFLAGSPECIFIED 147
-#define QM_NEWBANALREADYBANNED 148
-#define QM_NEWBANOVERLAPS 149
-#define QM_REPLACINGTEMPBAN 150
-#define QM_PERMBANALREADYSET 151
-#define QM_NOTREPLACINGBANLDURATION 152
-#define QM_REPLACINGBANSDURATION 153
-#define QM_TOOMANYCHANLEVS 154
-#define QM_TOOMANYBANS 155
-#define QM_WARNNOTREMOVEDPERMBAN 156
-#define QM_MAXHELLOLIMIT 157
-#define QM_ADDRESSLIMIT 158
-#define QM_DOMAINBANNED 159
-#define QM_TYPEHELPFORHELP 160
-#define QM_REQUESTPASSPRIVUSER 161
-#define QM_EMAILMATCHESOLD 162
-#define QM_INVALIDLIMIT 163
-#define QM_ACCOUNTLOCKED 164
-#define QM_ACCOUNTNOTLOCKED 165
-#define QM_RESETOK 166
-#define QM_BADRESETCODE 167
-#define QM_CHALLENGEDDEPRECATED 168
-#define QM_CHANLEVSUMMARY 169
-#define QM_MAILLOCKHEADER 170
-#define QM_MAILLOCKLINE 171
-#define QM_MAILLOCKDOESNTEXIST 172
-#define QM_MAILLOCKALREADYEXISTS 173
-#define QM_MAILLOCKED 174
-#define QM_NOACCESSONUSER 175
-#define QM_NOCHANOPHISTORY 176
-#define QM_CHANOPHISTORYHEADER 177
-#define QM_OTHERUSERAUTHEDLIMIT 178
-#define QM_OTHERUSERAUTHED 179
+#include "chanserv_messages.h"
/* List of privileged operations */
#define QPRIV_VIEWWELCOME 107
#define QPRIV_VIEWCOMMENTS 108
#define QPRIV_VIEWEMAIL 109
+#define QPRIV_VIEWCHANSUSPENSION 110
+#define QPRIV_VIEWSUSPENDEDBY 111
#define QPRIV_CHANGECHANFLAGS 200
#define QPRIV_CHANGECHANLEV 201
/* User flags */
-/* SPARE FLAG 0x0001 */
+#define QUFLAG_NOINFO 0x0001 /* +s */
#define QUFLAG_GLINE 0x0002 /* +g */
#define QUFLAG_NOTICE 0x0004 /* +n */
-/* SPARE FLAG 0x0008 */
+#define QUFLAG_STAFF 0x0008 /* +q */
#define QUFLAG_SUSPENDED 0x0010 /* +z */
#define QUFLAG_OPER 0x0020 /* +o */
#define QUFLAG_DEV 0x0040 /* +d */
#define QUFLAG_NOAUTHLIMIT 0x1000 /* +L */
#define QUFLAG_CLEANUPEXEMPT 0x4000 /* +D */
#define QUFLAG_TRUST 0x8000 /* +T */
-#define QUFLAG_ALL 0xdff6
+#define QUFLAG_ALL 0xdfff
+#define UIsNoInfo(x) ((x)->flags & QUFLAG_NOINFO)
#define UIsGline(x) ((x)->flags & QUFLAG_GLINE)
#define UIsNotice(x) ((x)->flags & QUFLAG_NOTICE)
#define UIsSuspended(x) ((x)->flags & QUFLAG_SUSPENDED)
#define UIsDelayedGline(x) ((x)->flags & QUFLAG_DELAYEDGLINE)
#define UIsNoAuthLimit(x) ((x)->flags & QUFLAG_NOAUTHLIMIT)
#define UIsCleanupExempt(x) ((x)->flags & QUFLAG_CLEANUPEXEMPT)
+#define UIsStaff(x) ((x)->flags & QUFLAG_STAFF)
#define UHasSuspension(x) ((x)->flags & (QUFLAG_GLINE|QUFLAG_DELAYEDGLINE|QUFLAG_SUSPENDED))
+#define UHasStaffPriv(x) ((x)->flags * (QUFLAG_STAFF | QUFLAG_HELPER | QUFLAG_OPER | QUFLAG_ADMIN | QUFLAG_DEV))
#define UHasHelperPriv(x) ((x)->flags & (QUFLAG_HELPER | QUFLAG_OPER | QUFLAG_ADMIN | QUFLAG_DEV))
#define UHasOperPriv(x) ((x)->flags & (QUFLAG_OPER | QUFLAG_ADMIN | QUFLAG_DEV))
#define UHasAdminPriv(x) ((x)->flags & (QUFLAG_ADMIN | QUFLAG_DEV))
#define QCFLAG_JOINED 0x0080 /* +j */
#define QCFLAG_KNOWNONLY 0x0100 /* +k */
#define QCFLAG_PROTECT 0x0200 /* +p */
+#define QCFLAG_NOINFO 0x0400 /* +s */
#define QCFLAG_TOPICSAVE 0x0800 /* +t */
#define QCFLAG_VOICEALL 0x1000 /* +v */
#define QCFLAG_WELCOME 0x2000 /* +w */
#define CIsWelcome(x) ((x)->flags & QCFLAG_WELCOME)
#define CIsSuspended(x) ((x)->flags & QCFLAG_SUSPENDED)
#define CIsInfo(x) ((x)->flags & QCFLAG_INFO)
+#define CIsNoInfo(x) ((x)->flags & QCFLAG_NOINFO)
#define CSetAutoOp(x) ((x)->flags |= QCFLAG_AUTOOP)
#define CSetBitch(x) ((x)->flags |= QCFLAG_BITCH)
QCFLAG_PROTECT|QCFLAG_TOPICSAVE|QCFLAG_VOICEALL| \
QCFLAG_WELCOME|QCFLAG_KNOWNONLY)
-#define QCFLAG_ALL 0x7bff
+#define QCFLAG_ALL 0x7fff
/* Channel user ("chanlev") flags */
#define QCUFLAG_DENY 0x0004 /* +d */
#define QCUFLAG_AUTOVOICE 0x0008 /* +g */
#define QCUFLAG_QUIET 0x0010 /* +q */
+#define QCUFLAG_NOINFO 0x0020 /* +s */
#define QCUFLAG_TOPIC 0x0040 /* +t */
#define QCUFLAG_HIDEWELCOME 0x0080 /* +w */
#define QCUFLAG_PROTECT 0x0100 /* +p */
-#define QCUFLAG_HIDEINFO 0x0200 /* +i */
+#define QCUFLAG_INFO 0x0200 /* +i */
#define QCUFLAG_KNOWN 0x0400 /* +k */
#define QCUFLAG_AUTOINVITE 0x0800 /* +j */
QCUFLAG_VOICE|QCUFLAG_PROTECT)
#define QCUFLAG_SELFCON (QCUFLAG_OP | QCUFLAG_VOICE | QCUFLAG_AUTOOP | QCUFLAG_AUTOVOICE | \
- QCUFLAG_TOPIC | QCUFLAG_HIDEINFO)
+ QCUFLAG_TOPIC | QCUFLAG_INFO)
-#define QCUFLAGS_PERSONAL (QCUFLAG_HIDEINFO | QCUFLAG_HIDEWELCOME | QCUFLAG_AUTOINVITE)
+#define QCUFLAGS_PUBLIC (QCUFLAG_OWNER | QCUFLAG_MASTER | QCUFLAG_OP | QCUFLAG_VOICE | \
+ QCUFLAG_KNOWN | QCUFLAG_AUTOOP | QCUFLAG_AUTOVOICE | QCUFLAG_TOPIC | \
+ QCUFLAG_PROTECT)
+
+#define QCUFLAGS_PUNISH (QCUFLAG_BANNED | QCUFLAG_QUIET | QCUFLAG_DENY)
+#define QCUFLAGS_PERSONAL (QCUFLAG_HIDEWELCOME | QCUFLAG_AUTOINVITE)
-#define QCUFLAG_ALL 0xffdf
+#define QCUFLAG_ALL 0xffff
#define CUIsOwner(x) ((x)->flags & QCUFLAG_OWNER)
#define CUIsMaster(x) ((x)->flags & QCUFLAG_MASTER)
#define CUIsDeny(x) ((x)->flags & QCUFLAG_DENY)
#define CUIsAutoVoice(x) ((x)->flags & QCUFLAG_AUTOVOICE)
#define CUIsQuiet(x) ((x)->flags & QCUFLAG_QUIET)
+#define CUIsNoInfo(x) ((x)->flags & QCUFLAG_NOINFO)
#define CUIsTopic(x) ((x)->flags & QCUFLAG_TOPIC)
#define CUIsHideWelcome(x) ((x)->flags & QCUFLAG_HIDEWELCOME)
#define CUIsProtect(x) ((x)->flags & QCUFLAG_PROTECT)
-#define CUIsHideInfo(x) ((x)->flags & QCUFLAG_HIDEINFO)
+#define CUIsInfo(x) ((x)->flags & QCUFLAG_INFO)
#define CUIsKnown(x) ((x)->flags & QCUFLAG_KNOWN)
#define CUIsAutoInvite(x) ((x)->flags & QCUFLAG_AUTOINVITE)
flag_t forcemodes; /* Forced modes */
flag_t denymodes; /* Denied modes */
- short limit; /* Limit to enforce if +l is set */
+ unsigned short limit; /* Limit to enforce if +l is set */
short autolimit; /* How many slots to leave when autolimiting */
short banstyle; /* Ban style for +b type bans */
extern int chanserv_init_status;
extern int chanservdb_ready;
-extern PQModuleIdentifier q9pqid, q9apqid, q9cpqid, q9upqid;
+extern DBModuleIdentifier q9dbid, q9adbid, q9cdbid, q9udbid;
extern maildomain *maildomainnametable[MAILDOMAINHASHSIZE];
extern maildomain *maildomainIDtable[MAILDOMAINHASHSIZE];
extern unsigned int cslangcount;
extern sstring *csmessages[MAXLANG][MAXMESSAGES];
-extern char *defaultmessages[MAXMESSAGES];
extern const flag rcflags[];
extern const flag rcuflags[];
extern maillock *maillocks;
+extern sstring *cs_quitreason;
+
/* Function prototypes */
/* chanserv.c */
void csdb_createmail(reguser *rup, int type);
void csdb_dohelp(nick *np, Command *cmd);
-#define q9asyncquery(handler, tag, format, ...) pqasyncqueryi(q9pqid, handler, tag, format , ##__VA_ARGS__)
-#define q9a_asyncquery(handler, tag, format, ...) pqasyncqueryi(q9apqid, handler, tag, format , ##__VA_ARGS__)
-#define q9u_asyncquery(handler, tag, format, ...) pqasyncqueryi(q9upqid, handler, tag, format , ##__VA_ARGS__)
-#define q9c_asyncquery(handler, tag, format, ...) pqasyncqueryi(q9cpqid, handler, tag, format , ##__VA_ARGS__)
+#define q9asyncquery(handler, tag, format, ...) dbasyncqueryi(q9dbid, handler, tag, format , ##__VA_ARGS__)
+#define q9a_asyncquery(handler, tag, format, ...) dbasyncqueryi(q9adbid, handler, tag, format , ##__VA_ARGS__)
+#define q9u_asyncquery(handler, tag, format, ...) dbasyncqueryi(q9udbid, handler, tag, format , ##__VA_ARGS__)
+#define q9c_asyncquery(handler, tag, format, ...) dbasyncqueryi(q9cdbid, handler, tag, format , ##__VA_ARGS__)
/* chanservcrypto.c */
typedef int (*CRAlgorithm)(char *, const char *, const char *, const char *);
void cs_schedupdate(chanindex *cip, int mintime, int maxtime);
void cs_timerfunc(void *arg);
void cs_removechannel(regchan *rcp);
+int cs_removechannelifempty(nick *sender, regchan *rcp);
void cs_doallautomodes(nick *np);
void cs_checknickbans(nick *np);
void cs_setregban(chanindex *cip, regban *rbp);
int cs_doshowcommands(void *source, int cargc, char **cargv);
int cs_dohelp(void *source, int cargc, char **cargv);
int cs_doquit(void *source, int cargc, char **cargv);
+int cs_dosetquitreason(void *source, int cargc, char **cargv);
int cs_dorename(void *source, int cargc, char **cargv);
int cs_dorehash(void *source, int cargc, char **cargv);
int cs_doversion(void *source, int cargc, char **cargv);
void csdb_createmaillock(maillock *mlp);
void csdb_updatemaillock(maillock *mlp);
+/* q9snprintf.c */
+void q9snprintf(char *buf, size_t size, const char *format, const char *args, ...);
+void q9vsnprintf(char *buf, size_t size, const char *format, const char *args, va_list ap);
+
+/* chanserv_flags.c */
+flag_t cs_accountflagmap(reguser *rup);
+flag_t cs_accountflagmap_str(char *flags);
+
#endif