int csa_docheckhashpass(void *source, int cargc, char **cargv);
int csa_docreateaccount(void *source, int cargc, char **cargv);
int csa_dosettempemail(void *source, int cargc, char **cargv);
+int csa_dosetemail(void *source, int cargc, char **cargv);
int csa_doresendemail(void *source, int cargc, char **cargv);
int csa_doactivateuser(void *source, int cargc, char **cargv);
+int csa_doaddchan(void *source, int argc, char **argv);
+int csa_doremoteauth(void *source, int argc, char **argv);
+
static int decrypt_password(unsigned char *secret, int keybits, char *buf, int bufsize, char *encrypted);
static int hex_to_int(char *input, unsigned char *buf, int buflen);
0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
-void _init(void) {
+static void relayfinishinit(int, void *);
+
+void relayfinishinit(int hooknum, void *arg) {
sstring *s;
+ deregisterhook(HOOK_CHANSERV_DBLOADED, relayfinishinit);
+
registercontrolhelpcmd("checkhashpass", NO_RELAY, 3, csa_docheckhashpass, "Usage: checkhashpass <username> <digest> ?junk?");
registercontrolhelpcmd("settempemail", NO_RELAY, 2, csa_dosettempemail, "Usage: settempemail <userid> <email address>");
+ registercontrolhelpcmd("setemail", NO_RELAY, 3, csa_dosetemail, "Usage: setmail <userid> <timestamp> <email address>");
registercontrolhelpcmd("resendemail", NO_RELAY, 1, csa_doresendemail, "Usage: resendemail <userid>");
registercontrolhelpcmd("activateuser", NO_RELAY, 1, csa_doactivateuser, "Usage: activateuser <userid>");
+ registercontrolhelpcmd("addchan", NO_RELAY, 3, csa_doaddchan, "Usage: addchan <channel> <userid> <channel type>");
+ registercontrolhelpcmd("remoteauth", NO_RELAY, 6, csa_doremoteauth, "Usage: remoteauth <username> <digest> <junk> <nick> <ident> <host>");
s=getcopyconfigitem("chanserv","createaccountsecret","",128);
if(!s || !s->content || !s->content[0]) {
} else if(s->length != KEY_BITS / 8 * 2 || !hex_to_int(s->content, createaccountsecret, sizeof(createaccountsecret))) {
Error("chanserv_relay",ERR_WARNING,"createaccountsecret must be a %d character hex string.", KEY_BITS / 8 * 2);
} else {
- registercontrolhelpcmd("createaccount", NO_RELAY, 4, csa_docreateaccount, "Usage: createaccount <execute> <username> <email address> <encrypted password>");
+ registercontrolhelpcmd("createaccount", NO_RELAY, 5, csa_docreateaccount, "Usage: createaccount <execute> <username> <email address> <encrypted password> <activate user>");
createaccountsecret_ok = 1;
}
freesstring(s);
}
+void _init(void) {
+ registerhook(HOOK_CHANSERV_DBLOADED, relayfinishinit);
+
+ if(chanservdb_ready)
+ relayfinishinit(HOOK_CHANSERV_DBLOADED, NULL);
+}
+
void _fini(void) {
deregistercontrolcmd("checkhashpass", csa_docheckhashpass);
deregistercontrolcmd("settempemail", csa_dosettempemail);
+ deregistercontrolcmd("setemail", csa_dosetemail);
deregistercontrolcmd("resendemail", csa_doresendemail);
deregistercontrolcmd("activateuser", csa_doactivateuser);
+ deregistercontrolcmd("addchan", csa_doaddchan);
if(createaccountsecret_ok)
deregistercontrolcmd("createaccount", csa_docreateaccount);
+
+ deregisterhook(HOOK_CHANSERV_DBLOADED, relayfinishinit);
}
int csa_docheckhashpass(void *source, int cargc, char **cargv) {
return CMD_OK;
}
+static void controlremotereply(nick *target, char *message) {
+ controlreply(target, "REMOTEAUTH FAILTEXT %s", message);
+}
+
+static void remote_reply(nick *sender, int message_id, ...) {
+ va_list va;
+ va_start(va, message_id);
+ chanservstdvmessage(sender, NULL, message_id, -1 * (int)(strlen("REMOTEAUTH FAILTEXT ")), controlremotereply, va);
+ va_end(va);
+}
+
+int csa_doremoteauth(void *source, int cargc, char **cargv) {
+ nick *sender=(nick *)source;
+ reguser *rup;
+
+ if(cargc<6) {
+ controlreply(sender, "REMOTEAUTH FAILREASON args");
+ return CMD_ERROR;
+ }
+
+ char *account = cargv[0];
+ char *digest = cargv[1];
+ char *junk = cargv[2];
+ char *nick = cargv[3];
+ char *ident = cargv[4];
+ char *hostname = cargv[5];
+
+ if (!(rup=findreguserbynick(account))) {
+ controlreply(sender, "REMOTEAUTH FAILREASON user");
+ return CMD_ERROR;
+ }
+
+ if(!checkhashpass(rup, junk, digest)) {
+ controlreply(sender, "REMOTEAUTH FAILREASON digest");
+ return CMD_ERROR;
+ }
+
+ if (!csa_completeauth2(rup, nick, ident, hostname, "REMOTEAUTH", remote_reply, sender)) {
+ controlreply(sender, "REMOTEAUTH END");
+ return CMD_ERROR;
+ }
+
+ /* username:ts:authid */
+ controlreply(sender, "REMOTEAUTH OK %s %ld %ld", rup->username, rup->lastauth ? rup->lastauth : getnettime(), rup->ID);
+
+ /* note: NO HOOK_CHANSERV_AUTH */
+
+ return CMD_OK;
+}
+
static char *email_to_error(char *email) {
maildomain *mdp, *smdp;
char *local;
char account_info[512];
char passbuf[512];
int do_create;
+ int activate;
- if(cargc<4) {
+ if(cargc<5) {
controlreply(sender, "CREATEACCOUNT FALSE args");
return CMD_ERROR;
}
}
password = passbuf;
}
+ activate = cargv[4][0] == '1';
if(username) {
if (findreguserbynick(username)) {
error_password = "passwordlong";
} else if(r == QM_PWTOWEAK) {
error_password = "passwordweak";
+ } else if(r == QM_PWINVALID) {
+ error_password = "passwordinvalid";
} else if(r != -1) {
error_password = "passwordunknown";
}
do_create = 1;
rup = csa_createaccount(username, password, email);
- USetInactive(rup);
- cs_log(sender,"CREATEACCOUNT created auth %s (%s)",rup->username,rup->email->content);
+ if(!activate)
+ USetInactive(rup);
+
+ cs_log(sender,"CREATEACCOUNT created auth %s (%s) %s",rup->username,rup->email->content,activate?"(active)": "(inactive)");
csdb_createuser(rup);
- snprintf(account_info, sizeof(account_info), " %u", rup->ID);
+ snprintf(account_info, sizeof(account_info), " %u %lu", rup->ID, (unsigned long)rup->lastpasschange);
- sendemail(rup);
+ if(!activate)
+ sendemail(rup);
} else {
account_info[0] = '\0';
do_create = 0;
return CMD_OK;
}
+int csa_dosetemail(void *source, int cargc, char **cargv) {
+ char *email;
+ char *error;
+ reguser *rup;
+ nick *sender=(nick *)source;
+
+ if(cargc<3) {
+ controlreply(sender, "SETEMAIL FALSE args");
+ return CMD_ERROR;
+ }
+
+ rup = findreguserbyID(atoi(cargv[0]));
+ if(rup == NULL) {
+ controlreply(sender, "SETEMAIL FALSE useridnotexist");
+ return CMD_ERROR;
+ }
+
+ if(UHasStaffPriv(rup)) {
+ controlreply(sender, "SETEMAIL FALSE privuser");
+ return CMD_ERROR;
+ }
+
+ if(UHasSuspension(rup)) {
+ controlreply(sender, "SETEMAIL FALSE suspended");
+ return CMD_ERROR;
+ }
+
+ if(rup->lastpasschange > atoi(cargv[1])) {
+ controlreply(sender, "SETEMAIL FALSE passwordchanged");
+ return CMD_ERROR;
+ }
+
+ email = cargv[2];
+
+ if(!strcmp(email, rup->email->content)) {
+ /* setting to the same thing? fine! */
+ controlreply(sender, "SETEMAIL TRUE");
+ return CMD_OK;
+ }
+
+ error = email_to_error(email);
+ if(error) {
+ controlreply(sender, "SETEMAIL FALSE %s", error);
+ return CMD_ERROR;
+ }
+
+ freesstring(rup->email);
+ rup->email=getsstring(email,EMAILLEN);
+ cs_log(sender,"SETEMAIL OK username %s email %s",rup->username, rup->email->content);
+
+ csdb_updateuser(rup);
+
+ controlreply(sender, "SETEMAIL TRUE");
+
+ return CMD_OK;
+}
+
int csa_doresendemail(void *source, int cargc, char **cargv) {
reguser *rup;
nick *sender=(nick *)source;
return CMD_OK;
}
+int csa_doaddchan(void *source, int cargc, char **cargv) {
+ nick *sender=(nick *)source;
+ reguser *rup = getreguserfromnick(sender), *founder;
+ chanindex *cip;
+ short type;
+ regchan *rcp;
+
+ if(cargc<3) {
+ controlreply(sender, "ADDCHAN FALSE args");
+ return CMD_ERROR;
+ }
+
+ if (*cargv[0] != '#' || strlen(cargv[0]) > CHANNELLEN) {
+ controlreply(sender, "ADDCHAN FALSE invalidchannel");
+ return CMD_ERROR;
+ }
+
+ if (!(cip=findorcreatechanindex(cargv[0]))) {
+ controlreply(sender, "ADDCHAN FALSE invalidchannel");
+ return CMD_ERROR;
+ }
+
+ founder = findreguserbyID(atoi(cargv[1]));
+ if(founder == NULL) {
+ controlreply(sender, "ADDCHAN FALSE useridnotexist");
+ return CMD_ERROR;
+ }
+
+ if(UIsInactive(founder)) {
+ controlreply(sender, "ADDCHAN FALSE accountinactive");
+ return CMD_ERROR;
+ }
+
+ for(type=CHANTYPES-1;type;type--)
+ if(!ircd_strcmp(chantypes[type]->content, cargv[2]))
+ break;
+
+ if(!type) {
+ controlreply(sender, "ADDCHAN FALSE invalidchantype");
+ return CMD_ERROR;
+ }
+
+ rcp = cs_addchan(cip, sender, rup, founder, QCFLAG_JOINED | QCFLAG_AUTOOP | QCFLAG_BITCH | QCFLAG_FORCETOPIC | QCFLAG_PROTECT | QCFLAG_TOPICSAVE, CHANMODE_NOCTCP | CHANMODE_DELJOINS | CHANMODE_MODNOAUTH | CHANMODE_NONOTICE | CHANMODE_NOEXTMSG | CHANMODE_SINGLETARG | CHANMODE_TOPICLIMIT | CHANMODE_NOQUITMSG, 0, type);
+ if(!rcp) {
+ controlreply(sender, "ADDCHAN FALSE alreadyregistered");
+ return CMD_ERROR;
+ }
+
+ cs_log(sender, "ADDCHAN %s #%s %s %s", cip->name->content, founder->username, printflags(rcp->flags, rcflags), chantypes[type]->content);
+ controlreply(sender, "ADDCHAN TRUE %u", rcp->ID);
+ return CMD_OK;
+}
+
static int hex_to_int(char *input, unsigned char *buf, int buflen) {
int i;
for(i=0;i<buflen;i++) {