int do_resendcode(User * u) { char *buffer = NULL; char *nick = NULL; NickAlias *na = NULL; buffer = moduleGetLastBuffer(); if (buffer) nick = myStrGetToken(buffer, ' ', 0); if (!nick) { moduleNoticeLang(s_NickServ, u, RESENDCODE_SYNTAX); } else if (!anope_valid_nick(nick)) { notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, nick); } else if (!(na = findnick(nick))) { notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick); } else if (nick_identified(na->u)) { notice_lang(s_NickServ, u, NICK_ALREADY_IDENTIFIED); } else if (!(moduleGetData(&na->nc->moduleData, MODULEDATAKEY))) { moduleNoticeLang(s_NickServ, u, RESETPASS_NOT_REQUESTED, u->nick); } else { if (do_sendmail(u, na) != 0) { alog(LOG_COULDNT_SENDMAIL, MYNAME, na->nick); } else { moduleNoticeLang(s_NickServ, u, RESETPASS_SUCCESS, na->nick); moduleNoticeLang(s_NickServ, u, RESETPASS_INSTRUC); } } return MOD_CONT; }
int do_confirm(User * u) { char *buffer = NULL; char *nick = NULL; char *passcode = NULL; char *moduledata = NULL; NickAlias *na = NULL; buffer = moduleGetLastBuffer(); if (buffer) { nick = myStrGetToken(buffer, ' ', 0); passcode = myStrGetToken(buffer, ' ', 1); } if (!nick) { moduleNoticeLang(s_NickServ, u, ENTERCODE_SYNTAX); } else if (!anope_valid_nick(nick)) { notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, nick); } else if (!(na = findnick(nick))) { notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick); } else if (nick_identified(na->u)) { notice_lang(s_NickServ, u, NICK_ALREADY_IDENTIFIED); } else if (!passcode) { moduleNoticeLang(s_NickServ, u, ENTERCODE_SYNTAX); } else { if (!(moduledata = moduleGetData(&na->nc->moduleData, MODULEDATAKEY))) { moduleNoticeLang(s_NickServ, u, RESETPASS_NOT_REQUESTED, nick); } else if (strcmp(passcode, moduledata) != 0) { moduleNoticeLang(s_NickServ, u, ENTERCODE_WRONG_PASSCODE); free(moduledata); } else { ns_setpassword(u, na->nc); moduleDelData(&na->nc->moduleData, MODULEDATAKEY); free(moduledata); } } return MOD_CONT; }
int do_saregister(User *u) { char *buf, *nick, *pass, *email; NickRequest *nr; NickAlias *na; User *user; buf = moduleGetLastBuffer(); nick = myStrGetToken(buf, ' ', 0); pass = myStrGetToken(buf, ' ', 1); email = myStrGetToken(buf, ' ', 2); if (!email) { notice_user(s_NickServ, u, "Syntax: \2SAREGISTER \37nick\37 \37password\37 \37email\37"); notice_lang(s_NickServ, u, MORE_INFO, s_NickServ, "SAREGISTER"); } else if (readonly) { notice_lang(s_NickServ, u, NICK_REGISTRATION_DISABLED); } else if ((nr = findrequestnick(nick))) { notice_lang(s_NickServ, u, NICK_REQUESTED); } else if (!anope_valid_nick(nick)) { notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, nick); } else if ((na = findnick(nick))) { if (na->status & NS_VERBOTEN) notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED, nick); else notice_lang(s_NickServ, u, NICK_ALREADY_REGISTERED, nick); } else if (!MailValidate(email)) { notice_lang(s_NickServ, u, MAIL_X_INVALID, email); } else { na = makenick(nick); if (!na) { alog("%s: makenick(%s) failed", s_NickServ, u->nick); notice_lang(s_NickServ, u, NICK_REGISTRATION_FAILED); } else { user = finduser(nick); enc_encrypt(pass, strlen(pass), na->nc->pass, PASSMAX - 1); na->nc->flags |= NSDefFlags; na->nc->memos.memomax = MSMaxMemos; if (user) na->last_usermask = user->vhost ? sstrdup(user->vhost) : sstrdup(user->host); else na->last_usermask = sstrdup("*@*"); if (user) na->last_realname = sstrdup(user->realname); else na->last_realname = sstrdup("unknown"); na->time_registered = na->last_seen = time(NULL); na->nc->language = NSDefLanguage; na->nc->email = sstrdup(email); send_event(EVENT_NICK_REGISTERED, 1, nick); alog("%s: %s (%s@%s) used saregister to register %s", s_NickServ, u->nick, u->username, u->host, nick); notice_user(s_NickServ, u, "Nick \2%s\2 has been registered", nick); if (user) { user->na = na; validate_user(user); } } } if (email) free(email); if (pass) free(pass); if (nick) free(nick); return MOD_CONT; }
int do_resetpass(User * u) { char *buffer = NULL; char *nick = NULL; char *email = NULL; char passcode[PASSCODELEN]; char *callBackinfo[1]; NickAlias *na = NULL; if ((RestrictReset == 1) && !(is_oper(u))) { notice_lang(s_NickServ, u, ACCESS_DENIED); return MOD_CONT; } buffer = moduleGetLastBuffer(); nick = myStrGetToken(buffer, ' ', 0); email = myStrGetToken(buffer, ' ', 1); if (!nick) { moduleNoticeLang(s_NickServ, u, RESETPASS_SYNTAX); } else if (!anope_valid_nick(nick)) { notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, nick); } else if (!(na = findnick(nick))) { notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick); } else if (na->status & NS_VERBOTEN) { notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick); } else if (na->nc->flags & NI_SUSPENDED) { notice_lang(s_NickServ, u, NICK_X_SUSPENDED, na->nick); } else if (!na->nc->email) { notice_user(s_NickServ, u, "%s has no email associated with their account.", na->nick); } else if (moduleGetData(&na->nc->moduleData, MODULEDATAKEY)) { moduleNoticeLang(s_NickServ, u, RESETPASS_ALREADY_REQUESTED1, na->nick); moduleNoticeLang(s_NickServ, u, RESETPASS_ALREADY_REQUESTED2); } else if (!email && !is_oper(u) && !is_helpop(u)) { notice(s_NickServ, u->nick, "You need to provide the e-mail address associated with the account you are trying to reset the password on."); notice(s_NickServ, u->nick, "Syntax: /ns resetpass <nickname> <e-mail>"); } else if (!is_oper(u) && !is_helpop(u) && strcasecmp(email, na->nc->email)) { notice(s_NickServ, u->nick, "The e-mail address %s does not match the one associated with account %s.", email, na->nc->display); } else { generatePassCode(passcode); moduleAddData(&na->nc->moduleData, MODULEDATAKEY, passcode); if (do_sendmail(u, na) != 0) { alog(LOG_COULDNT_SENDMAIL, MYNAME, na->nick); moduleDelData(&na->nc->moduleData, MODULEDATAKEY); } else { callBackinfo[0] = na->nick; moduleAddCallback(MYNAME, time(NULL) + ExpirePassCode, expirePassCode, 1, callBackinfo); alog(LOG_RESETPASS_REQUESTED, MYNAME, u->nick, na->nick); moduleNoticeLang(s_NickServ, u, RESETPASS_SUCCESS, na->nick); moduleNoticeLang(s_NickServ, u, RESETPASS_INSTRUC); } } if (nick) free(nick); if (email) free(email); return MOD_CONT; }