Q and ticketauth now send authflags.
CSDIRS=database chancmds usercmds authcmds authtracker newsearch
.PHONY: all dirs $(CSDIRS) clean
-all: chanserv.so chanserv_protect.so chanserv_grep.so chanserv_relay.so dirs
+all: chanserv.so chanserv_protect.so chanserv_grep.so chanserv_relay.so chanserv_flags.so dirs
dirs: $(CSDIRS)
ln -sf */*.so .
chanserv_relay.so: chanserv_relay.o
+chanserv_flags.so: chanserv_flags.o
chanservstdmessage(sender, QM_AUTHOK, rup->username);
cs_log(sender,"%s OK username %s", authtype,rup->username);
- localusersetaccountflags(sender, rup->username, rup->ID, 0, rup->lastauth);
+
+ localusersetaccount(sender, rup->username, rup->ID, cs_accountflagmap(rup), rup->lastauth);
return CMD_OK;
}
sstring **chantypes;
sstring *cs_quitreason;
-const flag rcflags[] = {
- { 'a', QCFLAG_AUTOOP },
- { 'b', QCFLAG_BITCH },
- { 'c', QCFLAG_AUTOLIMIT },
- { 'e', QCFLAG_ENFORCE },
- { 'f', QCFLAG_FORCETOPIC },
- { 'g', QCFLAG_AUTOVOICE },
- { 'i', QCFLAG_INFO },
- { 'j', QCFLAG_JOINED },
- { 'k', QCFLAG_KNOWNONLY },
- { 'p', QCFLAG_PROTECT },
- { 's', QCFLAG_NOINFO },
- { 't', QCFLAG_TOPICSAVE },
- { 'v', QCFLAG_VOICEALL },
- { 'w', QCFLAG_WELCOME },
- { 'z', QCFLAG_SUSPENDED },
- { '\0', 0 } };
-
-const flag rcuflags[] = {
- { 'a', QCUFLAG_AUTOOP },
- { 'b', QCUFLAG_BANNED },
- { 'd', QCUFLAG_DENY },
- { 'g', QCUFLAG_AUTOVOICE },
- { 'i', QCUFLAG_INFO },
- { 'j', QCUFLAG_AUTOINVITE },
- { 'k', QCUFLAG_KNOWN },
- { 'm', QCUFLAG_MASTER },
- { 'n', QCUFLAG_OWNER },
- { 'o', QCUFLAG_OP },
- { 'p', QCUFLAG_PROTECT },
- { 'q', QCUFLAG_QUIET },
- { 's', QCUFLAG_NOINFO },
- { 't', QCUFLAG_TOPIC },
- { 'v', QCUFLAG_VOICE },
- { 'w', QCUFLAG_HIDEWELCOME },
- { '\0', 0 } };
-
-const flag ruflags[] = {
- { 'a', QUFLAG_ADMIN },
- { 'd', QUFLAG_DEV },
- { 'D', QUFLAG_CLEANUPEXEMPT },
- { 'g', QUFLAG_GLINE },
- { 'G', QUFLAG_DELAYEDGLINE },
- { 'h', QUFLAG_HELPER },
- { 'i', QUFLAG_INFO },
- { 'L', QUFLAG_NOAUTHLIMIT },
- { 'n', QUFLAG_NOTICE },
- { 'o', QUFLAG_OPER },
- { 'p', QUFLAG_PROTECT },
- { 'q', QUFLAG_STAFF },
- { 's', QUFLAG_NOINFO },
- { 'T', QUFLAG_TRUST },
- { 'z', QUFLAG_SUSPENDED },
- { '\0', 0 } };
-
-const flag mdflags[] = {
- { 'l', MDFLAG_LIMIT },
- { 'b', MDFLAG_BANNED },
- { 'u', MDFLAG_ACTLIMIT },
- { '\0', 0 } };
-
void chanservfreestuff();
void chanservfinishinit(int hooknum, void *arg);
/* 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
--- /dev/null
+#include "../chanserv/chanserv.h"
+
+const flag rcflags[] = {
+ { 'a', QCFLAG_AUTOOP },
+ { 'b', QCFLAG_BITCH },
+ { 'c', QCFLAG_AUTOLIMIT },
+ { 'e', QCFLAG_ENFORCE },
+ { 'f', QCFLAG_FORCETOPIC },
+ { 'g', QCFLAG_AUTOVOICE },
+ { 'i', QCFLAG_INFO },
+ { 'j', QCFLAG_JOINED },
+ { 'k', QCFLAG_KNOWNONLY },
+ { 'p', QCFLAG_PROTECT },
+ { 's', QCFLAG_NOINFO },
+ { 't', QCFLAG_TOPICSAVE },
+ { 'v', QCFLAG_VOICEALL },
+ { 'w', QCFLAG_WELCOME },
+ { 'z', QCFLAG_SUSPENDED },
+ { '\0', 0 } };
+
+const flag rcuflags[] = {
+ { 'a', QCUFLAG_AUTOOP },
+ { 'b', QCUFLAG_BANNED },
+ { 'd', QCUFLAG_DENY },
+ { 'g', QCUFLAG_AUTOVOICE },
+ { 'i', QCUFLAG_INFO },
+ { 'j', QCUFLAG_AUTOINVITE },
+ { 'k', QCUFLAG_KNOWN },
+ { 'm', QCUFLAG_MASTER },
+ { 'n', QCUFLAG_OWNER },
+ { 'o', QCUFLAG_OP },
+ { 'p', QCUFLAG_PROTECT },
+ { 'q', QCUFLAG_QUIET },
+ { 's', QCUFLAG_NOINFO },
+ { 't', QCUFLAG_TOPIC },
+ { 'v', QCUFLAG_VOICE },
+ { 'w', QCUFLAG_HIDEWELCOME },
+
+ { '\0', 0 } };
+
+const flag ruflags[] = {
+ { 'a', QUFLAG_ADMIN },
+ { 'd', QUFLAG_DEV },
+ { 'D', QUFLAG_CLEANUPEXEMPT },
+ { 'g', QUFLAG_GLINE },
+ { 'G', QUFLAG_DELAYEDGLINE },
+ { 'h', QUFLAG_HELPER },
+ { 'i', QUFLAG_INFO },
+ { 'L', QUFLAG_NOAUTHLIMIT },
+ { 'n', QUFLAG_NOTICE },
+ { 'o', QUFLAG_OPER },
+ { 'p', QUFLAG_PROTECT },
+ { 'q', QUFLAG_STAFF },
+ { 's', QUFLAG_NOINFO },
+ { 'T', QUFLAG_TRUST },
+ { 'z', QUFLAG_SUSPENDED },
+ { '\0', 0 } };
+
+const flag mdflags[] = {
+ { 'l', MDFLAG_LIMIT },
+ { 'b', MDFLAG_BANNED },
+ { 'u', MDFLAG_ACTLIMIT },
+ { '\0', 0 } };
+
+flag_t cs_accountflagmap(reguser *rup) {
+ authname a2, *a = &a2;
+ a->flags = 0;
+
+ if(UIsOper(rup))
+ SetOperFlag(a);
+
+ if(UIsDev(rup))
+ SetDeveloper(a);
+
+ if(UIsAdmin(rup))
+ SetAdmin(a);
+
+ if(UIsStaff(rup))
+ SetStaff(a);
+
+ if(UIsHelper(rup))
+ SetSupport(a);
+
+ return a->flags;
+}
+
+flag_t cs_accountflagmap_str(char *flags) {
+ reguser r2, *r = &r2;
+
+ setflags(&r->flags, QUFLAG_ALL, flags, ruflags, REJECT_NONE);
+
+ return cs_accountflagmap(r);
+}
int csu_douserflags(void *source, int cargc, char **cargv) {
nick *sender=source;
reguser *rup=getreguserfromnick(sender), *target;
+ authname *anp;
int arg=0, wasorisoper;
flag_t flagmask, changemask, oldflags;
char flagbuf[30];
#endif
}
csdb_updateuser(target);
+
+ if ((anp=findauthname(rup->ID)))
+ localusersetaccountflags(anp, cs_accountflagmap(target));
+
chanservstdmessage(sender, QM_DONE);
}
newuser->nextbyrealname=newuser->realname->nicks;
newuser->realname->nicks=newuser;
newuser->umodes=umodes;
-
+
memset(&ipaddress, 0, sizeof(ipaddress));
((unsigned short *)(ipaddress.in6_16))[5] = 65535;
((unsigned short *)(ipaddress.in6_16))[6] = 127;
} else {
newuser->opername = NULL;
}
+
+ newuser->accountts=0;
+ newuser->auth=NULL;
+ newuser->authname=NULL;
if (IsAccount(newuser)) {
- strncpy(newuser->authname,authname,ACCOUNTLEN);
newuser->accountts=newuser->timestamp;
if (authid) {
- newuser->auth=findorcreateauthname(authid, newuser->authname);
+ newuser->auth=findorcreateauthname(authid, authname);
+ newuser->authname=newuser->auth->name;
newuser->auth->usercount++;
newuser->nextbyauthname=newuser->auth->nicks;
newuser->auth->nicks=newuser;
newuser->auth->flags=accountflags;
} else {
- newuser->auth=NULL;
+ /*
+ this is done for three reasons:
+ 1: so I don't have to change 500 pieces of code
+ 2: so services can be authed with special reserved ids
+ 3: saves space over the old authname per user method
+ */
+ newuser->authname=malloc(strlen(authname) + 1);
+ strcpy(newuser->authname,authname);
}
- } else {
- newuser->authname[0]='\0';
- newuser->accountts=0;
- newuser->auth=NULL;
}
-
+
if (connected) {
/* Check for nick collision */
if ((np=getnickbynick(nickname))!=NULL) {
operbuf[0] = '\0';
}
+ accountbuf[0]='\0';
if (IsAccount(np)) {
if (np->auth) {
if(np->auth->flags) {
} else {
snprintf(accountbuf,sizeof(accountbuf)," %s:%ld:%lu",np->authname,np->accountts,np->auth->userid);
}
- } else {
+ } else if(np->authname) {
snprintf(accountbuf,sizeof(accountbuf)," %s:%ld:0",np->authname,np->accountts);
}
- } else {
- accountbuf[0]='\0';
}
irc_send("%s N %s 1 %ld %s %s %s%s%s %s %s :%s",
}
}
-/* Auth user */
-void localusersetaccountflags(nick *np, char *accname, unsigned long accid, flag_t accountflags, time_t authTS) {
+void sendaccountmessage(nick *np) {
+ if (connected) {
+ if (np->auth) {
+ if (np->auth->flags) {
+ irc_send("%s AC %s %s %ld %lu %lu",mynumeric->content, longtonumeric(np->numeric,5), np->authname, np->accountts, np->auth->userid, np->auth->flags);
+ } else {
+ irc_send("%s AC %s %s %ld %lu",mynumeric->content, longtonumeric(np->numeric,5), np->authname, np->accountts, np->auth->userid);
+ }
+ } else {
+ irc_send("%s AC %s %s %ld 0",mynumeric->content, longtonumeric(np->numeric,5), np->authname, np->accountts);
+ }
+ }
+}
+
+/* Auth user, don't use to set flags after authing */
+void localusersetaccount(nick *np, char *accname, unsigned long accid, flag_t accountflags, time_t authTS) {
if (IsAccount(np)) {
Error("localuser",ERR_WARNING,"Tried to set account on user %s already authed", np->nick);
return;
}
SetAccount(np);
- strncpy(np->authname, accname, ACCOUNTLEN);
- np->authname[ACCOUNTLEN]='\0';
np->accountts=authTS?authTS:getnettime();
if (accid) {
np->auth=findorcreateauthname(accid, accname);
np->auth->usercount++;
+ np->authname=np->auth->name;
np->nextbyauthname=np->auth->nicks;
np->auth->nicks=np;
np->auth->flags=accountflags;
} else {
np->auth=NULL;
+ np->authname=malloc(strlen(accname) + 1);
+ strcpy(np->authname,accname);
}
- if (connected) {
- if (np->auth) {
- if (np->auth->flags) {
- irc_send("%s AC %s %s %ld %lu %lu",mynumeric->content, longtonumeric(np->numeric,5), np->authname, np->accountts, np->auth->userid, np->auth->flags);
- } else {
- irc_send("%s AC %s %s %ld %lu",mynumeric->content, longtonumeric(np->numeric,5), np->authname, np->accountts, np->auth->userid);
- }
- } else {
- irc_send("%s AC %s %s %ld 0",mynumeric->content, longtonumeric(np->numeric,5), np->authname, np->accountts);
- }
- }
+ sendaccountmessage(np);
triggerhook(HOOK_NICK_ACCOUNT, np);
}
np->umodes = newmodes;
}
+
+void localusersetaccountflags(authname *anp, flag_t accountflags) {
+ void *arg[2];
+ nick *np;
+
+ arg[0] = (void *)anp;
+ arg[1] = (void *)(long)anp->flags;
+ anp->flags = accountflags;
+
+ for(np=anp->nicks;np;np=np->next)
+ sendaccountmessage(np);
+
+ triggerhook(HOOK_AUTH_FLAGSUPDATED, arg);
+}
void sendsecuremessagetouser(nick *source, nick *target, char *servername, char *format, ... );
void sendnoticetouser(nick *source, nick *target, char *format, ... );
void killuser(nick *source, nick *target, char *format, ... );
-#define localusersetaccount(np, accname) localusersetaccountflags(np, accname, 0)
-void localusersetaccountflags(nick *np, char *accname, unsigned long accid, flag_t accountflags, time_t authTS);
+void localusersetaccount(nick *np, char *accname, unsigned long accid, flag_t accountflags, time_t authTS);
void localusersetumodes(nick *np, flag_t newmodes);
void sethostuser(nick *target, char *ident, char *host);
+void localusersetaccountflags(authname *anp, flag_t accountflags);
#endif
const flag accountflags[] = {
{ 'q', AFLAG_STAFF },
- { 's', AFLAG_SUPPORT },
+ { 'h', AFLAG_SUPPORT },
{ 'o', AFLAG_OPER },
{ 'a', AFLAG_ADMIN },
{ 'd', AFLAG_DEVELOPER },
freesstring(np->shident);
freesstring(np->sethost);
freesstring(np->opername);
+ if(!np->auth && np->authname)
+ free(np->authname);
}
}
releaserealname(np->realname);
releasehost(np->host);
- if(IsAccount(np) && np->auth)
- {
- np->auth->usercount--;
+ if(IsAccount(np)) {
+ if(!np->auth) {
+ if(np->authname)
+ free(np->authname);
+ } else {
+ np->auth->usercount--;
- for (nh=&(np->auth->nicks);*nh;nh=&((*nh)->nextbyauthname)) {
- if (*nh==np) {
- *nh=np->nextbyauthname;
- break;
+ for (nh=&(np->auth->nicks);*nh;nh=&((*nh)->nextbyauthname)) {
+ if (*nh==np) {
+ *nh=np->nextbyauthname;
+ break;
+ }
}
- }
- releaseauthname(np->auth);
+ releaseauthname(np->auth);
+ }
}
freesstring(np->shident); /* freesstring(NULL) is OK */
#define ClearHideIdle(x) ((x)->umodes &= ~UMODE_HIDEIDLE)
#define ClearParanoid(x) ((x)->umodes &= ~UMODE_PARANOID)
-#define IsStaff(x) ((x)->umodes & AFLAG_STAFF)
-#define IsDeveloper(x) ((x)->umodes & AFLAG_DEVELOPER)
-#define IsSupport(x) ((x)->umodes & AFLAG_SUPPORT)
-#define IsAdmin(x) ((x)->umodes & AFLAG_ADMIN)
-#define IsOperFlag(x) ((x)->umodes & AFLAG_OPER)
-
-#define SetStaff(x) ((x)->umodes |= AFLAG_STAFF)
-#define SetDeveloper(x) ((x)->umodes |= AFLAG_DEVELOPER)
-#define SetSupport(x) ((x)->umodes |= AFLAG_SUPPORT)
-#define SetAdmin(x) ((x)->umodes |= AFLAG_ADMIN)
-#define SetOperFlag(x) ((x)->umodes |= AFLAG_OPER)
-
-#define ClearStaff(x) ((x)->umodes &= ~AFLAG_STAFF)
-#define ClearDeveloper(x) ((x)->umodes &= ~AFLAG_DEVELOPER)
-#define ClearSupport(x) ((x)->umodes &= ~AFLAG_SUPPORT)
-#define ClearAdmin(x) ((x)->umodes &= ~AFLAG_ADMIN)
-#define ClearOperFlag(x) ((x)->umodes &= ~AFLAG_OPER)
+#define IsStaff(x) ((x)->flags & AFLAG_STAFF)
+#define IsDeveloper(x) ((x)->flags & AFLAG_DEVELOPER)
+#define IsSupport(x) ((x)->flags & AFLAG_SUPPORT)
+#define IsAdmin(x) ((x)->flags & AFLAG_ADMIN)
+#define IsOperFlag(x) ((x)->flags & AFLAG_OPER)
+
+#define SetStaff(x) ((x)->flags |= AFLAG_STAFF)
+#define SetDeveloper(x) ((x)->flags |= AFLAG_DEVELOPER)
+#define SetSupport(x) ((x)->flags |= AFLAG_SUPPORT)
+#define SetAdmin(x) ((x)->flags |= AFLAG_ADMIN)
+#define SetOperFlag(x) ((x)->flags |= AFLAG_OPER)
+
+#define ClearStaff(x) ((x)->flags &= ~AFLAG_STAFF)
+#define ClearDeveloper(x) ((x)->flags &= ~AFLAG_DEVELOPER)
+#define ClearSupport(x) ((x)->flags &= ~AFLAG_SUPPORT)
+#define ClearAdmin(x) ((x)->flags &= ~AFLAG_ADMIN)
+#define ClearOperFlag(x) ((x)->flags &= ~AFLAG_OPER)
typedef struct host {
sstring *name;
sstring *sethost;
sstring *opername;
flag_t umodes;
- char authname[ACCOUNTLEN+1];
+ char *authname;
authname *auth; /* This requires User ID numbers to work */
time_t timestamp;
time_t accountts;
np->umodes=0;
np->marker=0;
memset(np->exts, 0, MAXNICKEXTS * sizeof(void *));
- np->authname[0]='\0';
+ np->authname=NULL;
np->auth=NULL;
np->accountts=0;
if(cargc>=9) {
sethostarg++;
if ((accountts=strchr(cargv[accountarg],':'))) {
- time_t accountts_t=strtoul(accountts,&accountid,10)
*accountts++='\0';
+ np->accountts=strtoul(accountts,&accountid,10);
if(accountid) {
- strncpy(np->authname,cargv[accountarg],ACCOUNTLEN);
- np->authname[ACCOUNTLEN]='\0';
- np->accountts=accountts_t;
-
userid=strtoul(accountid + 1,&accountflags,10);
- if(!userid) {
- np->auth=NULL;
- } else {
+ if(userid) {
np->auth=findorcreateauthname(userid, cargv[accountarg]);
+ np->authname=np->auth->name;
np->auth->usercount++;
np->nextbyauthname=np->auth->nicks;
np->auth->nicks=np;
if(accountflags)
np->auth->flags=strtoul(accountflags + 1,NULL,10);
}
+ } else {
+ np->authname=malloc(strlen(cargv[accountarg]) + 1);
+ strcpy(np->authname,cargv[accountarg]);
}
}
}
accountts=strtoul(cargv[2],NULL,10);
userid=strtoul(cargv[3],NULL,10);
- if(cargv>=5)
+ if(cargc>=5)
accountflags=strtoul(cargv[4],NULL,10);
/* allow user flags to change if all fields match */
if (IsAccount(target)) {
void *arg[2];
- if (!target->auth || strcmp(target->authname,cargv[1]) || (target->auth->userid != userid) || (target->accountts != accountts)) {
+ if (!target->auth || strcmp(target->auth->name,cargv[1]) || (target->auth->userid != userid) || (target->accountts != accountts)) {
return CMD_OK;
}
}
SetAccount(target);
- strncpy(target->authname,cargv[1],ACCOUNTLEN);
- target->authname[ACCOUNTLEN]='\0';
target->accountts=accountts;
if(!userid) {
target->auth=NULL;
+ target->authname=malloc(strlen(cargv[1]) + 1);
+ strcpy(target->authname,cargv[1]);
} else {
target->auth=findorcreateauthname(userid, target->authname);
target->auth->usercount++;
+ target->authname=target->auth->name;
target->nextbyauthname = target->auth->nicks;
target->auth->nicks = target;
if (cargc>=5)
#include "../localuser/localuser.h"
#include "../core/hooks.h"
#include "../irc/irc.h"
+#include "../chanserv/chanserv.h"
#define WARN_CHANNEL "#twilightzone"
int ta_ticketauth(void *source, int cargc, char **cargv) {
nick *np = (nick *)source;
- char buffer[1024], *uhmac, *acc, *junk;
+ char buffer[1024], *uhmac, *acc, *junk, *flags;
unsigned char digest[32];
int expiry, acclen, id;
hmacsha256 hmac;
return CMD_ERROR;
}
- if(cargc != 5)
+ if(cargc != 6)
return CMD_USAGE;
acc = cargv[0];
expiry = atoi(cargv[1]);
id = atoi(cargv[2]);
acclen = strlen(acc);
- junk = cargv[3];
- uhmac = cargv[4];
+ flags = cargv[3];
+ junk = cargv[4];
+ uhmac = cargv[5];
if((acclen <= 1) || (acclen > ACCOUNTLEN)) {
controlreply(np, "Bad account.");
controlreply(np, "Ticket valid, authing. . .");
- localusersetaccountflags(np, acc, id, 0, 0);
+ localusersetaccount(np, acc, id, 0, cs_accountflagmap_str(flags));
controlreply(np, "Done.");
return CMD_OK;