summaryrefslogtreecommitdiff
path: root/src/nickserv.c
diff options
context:
space:
mode:
authorrob rob@31f1291d-b8d6-0310-a050-a5561fc1590b <rob rob@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864>2005-05-02 19:02:12 +0000
committerrob rob@31f1291d-b8d6-0310-a050-a5561fc1590b <rob rob@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864>2005-05-02 19:02:12 +0000
commite0583918834a3f8683e430adf3923ea89d2a449a (patch)
treeff36ada734c3874d3be1a806e3a2b994386b54ed /src/nickserv.c
parent49491770383e66f1b8074d8b0f80026e3086e9d8 (diff)
BUILD : 1.7.8 (753) BUGS : N/a NOTES : Merged anope-dev with trunk
git-svn-id: svn://svn.anope.org/anope/trunk@753 31f1291d-b8d6-0310-a050-a5561fc1590b git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@516 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/nickserv.c')
-rw-r--r--src/nickserv.c2599
1 files changed, 14 insertions, 2585 deletions
diff --git a/src/nickserv.c b/src/nickserv.c
index 76dfcf21f..ac0cdd0ae 100644
--- a/src/nickserv.c
+++ b/src/nickserv.c
@@ -36,111 +36,21 @@ extern char *getvHost(char *nick);
void alpha_insert_alias(NickAlias * na);
void insert_core(NickCore * nc);
void insert_requestnick(NickRequest * nr);
-static NickAlias *makenick(const char *nick);
-static NickRequest *makerequest(const char *nick);
-static NickAlias *makealias(const char *nick, NickCore * nc);
-static void change_core_display(NickCore * nc, char *newdisplay);
+void change_core_display(NickCore * nc, char *newdisplay);
-static void collide(NickAlias * na, int from_timeout);
-static void release(NickAlias * na, int from_timeout);
+void collide(NickAlias * na, int from_timeout);
+void release(NickAlias * na, int from_timeout);
static void add_ns_timeout(NickAlias * na, int type, time_t delay);
-static void del_ns_timeout(NickAlias * na, int type);
+void del_ns_timeout(NickAlias * na, int type);
int delnickrequest(NickRequest * nr);
NickRequest *findrequestnick(const char *nick);
-static int do_sendregmail(User * u, NickRequest * nr);
-static int do_setmodes(User * u);
-
-static int do_help(User * u);
-static int do_register(User * u);
-static int do_confirm(User * u);
-static int do_group(User * u);
-static int do_nickupdate(User * u);
-static int do_identify(User * u);
-static int do_logout(User * u);
-static int do_drop(User * u);
-static int do_set(User * u);
-static int do_set_display(User * u, NickCore * nc, char *param);
-static int do_set_password(User * u, NickCore * nc, char *param);
-static int do_set_language(User * u, NickCore * nc, char *param);
-static int do_set_url(User * u, NickCore * nc, char *param);
-static int do_set_email(User * u, NickCore * nc, char *param);
-static int do_set_greet(User * u, NickCore * nc, char *param);
-static int do_set_icq(User * u, NickCore * nc, char *param);
-static int do_set_kill(User * u, NickCore * nc, char *param);
-static int do_set_secure(User * u, NickCore * nc, char *param);
-static int do_set_private(User * u, NickCore * nc, char *param);
-static int do_set_msg(User * u, NickCore * nc, char *param);
-static int do_set_hide(User * u, NickCore * nc, char *param);
-static int do_set_noexpire(User * u, NickAlias * nc, char *param);
-static int do_access(User * u);
-static int do_info(User * u);
-static int do_list(User * u);
-static int do_alist(User * u);
-static int do_glist(User * u);
-static int do_recover(User * u);
-static int do_release(User * u);
-static int do_ghost(User * u);
-static int do_status(User * u);
-static int do_getpass(User * u);
-static int do_getemail(User * u);
-static int do_sendpass(User * u);
-static int do_forbid(User * u);
-static int do_resend(User * u);
-static int do_suspend(User * u);
-static int do_unsuspend(User * u);
-
-/* Obsolete commands */
-static int do_link(User * u);
-static int do_unlink(User * u);
-static int do_listlinks(User * u);
+int do_setmodes(User * u);
/*************************************************************************/
/* *INDENT-OFF* */
void moduleAddNickServCmds(void) {
- Command *c;
- c = createCommand("HELP", do_help, NULL, -1, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("REGISTER", do_register, NULL, NICK_HELP_REGISTER, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("RESEND", do_resend, NULL, -1, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("CONFIRM", do_confirm, NULL, -1, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("GROUP", do_group, NULL, NICK_HELP_GROUP, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("UPDATE", do_nickupdate, NULL, NICK_HELP_UPDATE, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("ID", do_identify, NULL, NICK_HELP_IDENTIFY, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("IDENTIFY", do_identify, NULL, NICK_HELP_IDENTIFY, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SIDENTIFY",do_identify, NULL, -1, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("LOGOUT", do_logout, NULL, -1,NICK_HELP_LOGOUT, -1,NICK_SERVADMIN_HELP_LOGOUT, NICK_SERVADMIN_HELP_LOGOUT); addCoreCommand(NICKSERV,c);
- c = createCommand("DROP", do_drop, NULL, -1,NICK_HELP_DROP, -1,NICK_SERVADMIN_HELP_DROP, NICK_SERVADMIN_HELP_DROP); addCoreCommand(NICKSERV,c);
- c = createCommand("LINK", do_link, NULL, -1, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("UNLINK", do_unlink, NULL, -1, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("LISTLINKS",do_listlinks, NULL, -1, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("ACCESS", do_access, NULL, NICK_HELP_ACCESS, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SET", do_set, NULL, NICK_HELP_SET,-1, -1,NICK_SERVADMIN_HELP_SET, NICK_SERVADMIN_HELP_SET); addCoreCommand(NICKSERV,c);
- c = createCommand("SET DISPLAY", NULL, NULL, NICK_HELP_SET_DISPLAY, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SET PASSWORD", NULL, NULL, NICK_HELP_SET_PASSWORD, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SET URL", NULL, NULL, NICK_HELP_SET_URL, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SET EMAIL", NULL, NULL, NICK_HELP_SET_EMAIL, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SET ICQ", NULL, NULL, NICK_HELP_SET_ICQ, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SET GREET", NULL, NULL, NICK_HELP_SET_GREET, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SET KILL", NULL, NULL, NICK_HELP_SET_KILL, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SET SECURE", NULL, NULL, NICK_HELP_SET_SECURE, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SET PRIVATE", NULL, NULL, NICK_HELP_SET_PRIVATE, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SET MSG", NULL, NULL, NICK_HELP_SET_MSG, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SET HIDE", NULL, NULL, NICK_HELP_SET_HIDE, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SET NOEXPIRE", NULL, NULL, -1, -1,-1,NICK_SERVADMIN_HELP_SET_NOEXPIRE,NICK_SERVADMIN_HELP_SET_NOEXPIRE); addCoreCommand(NICKSERV,c);
- c = createCommand("RECOVER", do_recover, NULL, NICK_HELP_RECOVER, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("RELEASE", do_release, NULL, NICK_HELP_RELEASE, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("GHOST", do_ghost, NULL, NICK_HELP_GHOST, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("INFO", do_info, NULL, NICK_HELP_INFO,-1, NICK_HELP_INFO, NICK_SERVADMIN_HELP_INFO,NICK_SERVADMIN_HELP_INFO); addCoreCommand(NICKSERV,c);
- c = createCommand("LIST", do_list, NULL, -1,NICK_HELP_LIST, -1,NICK_SERVADMIN_HELP_LIST, NICK_SERVADMIN_HELP_LIST); addCoreCommand(NICKSERV,c);
- c = createCommand("ALIST", do_alist, NULL, -1,NICK_HELP_ALIST, -1,NICK_SERVADMIN_HELP_ALIST, NICK_SERVADMIN_HELP_ALIST); addCoreCommand(NICKSERV,c);
- c = createCommand("GLIST", do_glist, NULL, -1,NICK_HELP_GLIST, -1,NICK_SERVADMIN_HELP_GLIST, NICK_SERVADMIN_HELP_GLIST); addCoreCommand(NICKSERV,c);
- c = createCommand("STATUS", do_status, NULL, NICK_HELP_STATUS, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("SENDPASS", do_sendpass, NULL, NICK_HELP_SENDPASS, -1,-1,-1,-1); addCoreCommand(NICKSERV,c);
- c = createCommand("GETPASS", do_getpass, is_services_admin, -1,-1, -1,NICK_SERVADMIN_HELP_GETPASS, NICK_SERVADMIN_HELP_GETPASS); addCoreCommand(NICKSERV,c);
- c = createCommand("GETEMAIL", do_getemail, is_services_admin, -1,-1, -1,NICK_SERVADMIN_HELP_GETEMAIL, NICK_SERVADMIN_HELP_GETEMAIL); addCoreCommand(NICKSERV,c);
- c = createCommand("FORBID", do_forbid, is_services_admin, -1,-1, -1,NICK_SERVADMIN_HELP_FORBID, NICK_SERVADMIN_HELP_FORBID); addCoreCommand(NICKSERV,c);
- c = createCommand("SUSPEND", do_suspend, is_services_admin, -1,-1, -1,NICK_SERVADMIN_HELP_SUSPEND, NICK_SERVADMIN_HELP_SUSPEND); addCoreCommand(NICKSERV,c);
- c = createCommand("UNSUSPEND",do_unsuspend,is_services_admin, -1,-1, -1,NICK_SERVADMIN_HELP_UNSUSPEND, NICK_SERVADMIN_HELP_UNSUSPEND); addCoreCommand(NICKSERV,c);
+ modules_core_init(NickServCoreNumber, NickServCoreModules);
}
/* *INDENT-ON* */
/*************************************************************************/
@@ -1240,7 +1150,7 @@ void expire_nicks()
(na->nc->email ? na->nc->email : "none"));
tmpnick = sstrdup(na->nick);
delnick(na);
- send_event(EVENT_NICK_EXPIRE, tmpnick);
+ send_event(EVENT_NICK_EXPIRE, 1, tmpnick);
free(tmpnick);
}
}
@@ -1451,67 +1361,12 @@ void insert_requestnick(NickRequest * nr)
}
/*************************************************************************/
-/* Creates a new Nick Request */
-static NickRequest *makerequest(const char *nick)
-{
- NickRequest *nr;
-
- nr = scalloc(1, sizeof(NickRequest));
- nr->nick = sstrdup(nick);
- insert_requestnick(nr);
- alog("%s: Nick %s has been requested", s_NickServ, nr->nick);
- return nr;
-}
-
-
-
-/* Creates a full new nick (alias + core) in NickServ database. */
-
-static NickAlias *makenick(const char *nick)
-{
- NickAlias *na;
- NickCore *nc;
-
- /* First make the core */
- nc = scalloc(1, sizeof(NickCore));
- nc->display = sstrdup(nick);
- slist_init(&nc->aliases);
- insert_core(nc);
- alog("%s: group %s has been created", s_NickServ, nc->display);
-
- /* Then make the alias */
- na = scalloc(1, sizeof(NickAlias));
- na->nick = sstrdup(nick);
- na->nc = nc;
- slist_add(&nc->aliases, na);
- alpha_insert_alias(na);
- return na;
-}
-
-/*************************************************************************/
-
-/* Creates a new alias in NickServ database. */
-
-static NickAlias *makealias(const char *nick, NickCore * nc)
-{
- NickAlias *na;
-
- /* Just need to make the alias */
- na = scalloc(1, sizeof(NickAlias));
- na->nick = sstrdup(nick);
- na->nc = nc;
- slist_add(&nc->aliases, na);
- alpha_insert_alias(na);
- return na;
-}
-
-/*************************************************************************/
/* Sets nc->display to newdisplay. If newdisplay is NULL, it will change
* it to the first alias in the list.
*/
-static void change_core_display(NickCore * nc, char *newdisplay)
+void change_core_display(NickCore * nc, char *newdisplay)
{
if (!newdisplay) {
NickAlias *na;
@@ -1745,7 +1600,7 @@ int delnick(NickAlias * na)
* This is watched for and done in cancel_user(). -TheShadow
*/
-static void collide(NickAlias * na, int from_timeout)
+void collide(NickAlias * na, int from_timeout)
{
char guestnick[NICKMAX];
@@ -1779,7 +1634,7 @@ static void collide(NickAlias * na, int from_timeout)
/* Release hold on a nick. */
-static void release(NickAlias * na, int from_timeout)
+void release(NickAlias * na, int from_timeout)
{
if (!from_timeout)
del_ns_timeout(na, TO_RELEASE);
@@ -1905,7 +1760,7 @@ void add_ns_timeout(NickAlias * na, int type, time_t delay)
/* Delete a collide/release timeout. */
-static void del_ns_timeout(NickAlias * na, int type)
+void del_ns_timeout(NickAlias * na, int type)
{
struct my_timeout *t, *t2;
@@ -1962,675 +1817,6 @@ void clean_ns_timeouts(NickAlias * na)
/*************************************************************************/
/*********************** NickServ command routines ***********************/
/*************************************************************************/
-
-/* Return a help message. */
-
-static int do_help(User * u)
-{
- char *cmd = strtok(NULL, "");
-
- if (!cmd) {
- notice_help(s_NickServ, u, NICK_HELP);
- if (NSExpire >= 86400)
- notice_help(s_NickServ, u, NICK_HELP_EXPIRES,
- NSExpire / 86400);
- if (is_services_oper(u))
- notice_help(s_NickServ, u, NICK_SERVADMIN_HELP);
- moduleDisplayHelp(1, u);
- } else if (stricmp(cmd, "SET LANGUAGE") == 0) {
- int i;
- notice_help(s_NickServ, u, NICK_HELP_SET_LANGUAGE);
- for (i = 0; i < NUM_LANGS && langlist[i] >= 0; i++)
- notice_user(s_NickServ, u, " %2d) %s", i + 1,
- langnames[langlist[i]]);
- } else {
- mod_help_cmd(s_NickServ, u, NICKSERV, cmd);
- }
- return MOD_CONT;
-}
-
-/*************************************************************************/
-
-/* Register a nick. */
-
-static int do_register(User * u)
-{
- NickRequest *nr = NULL, *anr = NULL;
- NickCore *nc = NULL;
- int prefixlen = strlen(NSGuestNickPrefix);
- int nicklen = strlen(u->nick);
- char *pass = strtok(NULL, " ");
- char *email = strtok(NULL, " ");
- char passcode[11];
- int idx, min = 1, max = 62, i = 0;
- int chars[] =
- { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
- 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
- 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
- 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
- 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
- };
-
- if (readonly) {
- notice_lang(s_NickServ, u, NICK_REGISTRATION_DISABLED);
- return MOD_CONT;
- }
-
- if (checkDefCon(DEFCON_NO_NEW_NICKS)) {
- notice_lang(s_NickServ, u, OPER_DEFCON_DENIED);
- return MOD_CONT;
- }
-
- if (!is_oper(u) && NickRegDelay
- && ((time(NULL) - u->my_signon) < NickRegDelay)) {
- notice_lang(s_NickServ, u, NICK_REG_DELAY, NickRegDelay);
- return MOD_CONT;
- }
-
- if ((anr = findrequestnick(u->nick))) {
- notice_lang(s_NickServ, u, NICK_REQUESTED);
- return MOD_CONT;
- }
- /* Prevent "Guest" nicks from being registered. -TheShadow */
-
- /* Guest nick can now have a series of between 1 and 7 digits.
- * --lara
- */
- if (nicklen <= prefixlen + 7 && nicklen >= prefixlen + 1 &&
- stristr(u->nick, NSGuestNickPrefix) == u->nick &&
- strspn(u->nick + prefixlen, "1234567890") == nicklen - prefixlen) {
- notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick);
- return MOD_CONT;
- }
-
- if (RestrictOperNicks) {
- for (i = 0; i < RootNumber; i++) {
- if (stristr(u->nick, ServicesRoots[i]) && !is_oper(u)) {
- notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED,
- u->nick);
- return MOD_CONT;
- }
- }
- for (i = 0; i < servadmins.count && (nc = servadmins.list[i]); i++) {
- if (stristr(u->nick, nc->display) && !is_oper(u)) {
- notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED,
- u->nick);
- return MOD_CONT;
- }
- }
- for (i = 0; i < servopers.count && (nc = servopers.list[i]); i++) {
- if (stristr(u->nick, nc->display) && !is_oper(u)) {
- notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED,
- u->nick);
- return MOD_CONT;
- }
- }
- }
-
- if (!pass) {
- if (NSForceEmail) {
- syntax_error(s_NickServ, u, "REGISTER",
- NICK_REGISTER_SYNTAX_EMAIL);
- } else {
- syntax_error(s_NickServ, u, "REGISTER", NICK_REGISTER_SYNTAX);
- }
- } else if (NSForceEmail && !email) {
- syntax_error(s_NickServ, u, "REGISTER",
- NICK_REGISTER_SYNTAX_EMAIL);
- } else if (time(NULL) < u->lastnickreg + NSRegDelay) {
- notice_lang(s_NickServ, u, NICK_REG_PLEASE_WAIT, NSRegDelay);
- } else if (u->na) { /* i.e. there's already such a nick regged */
- if (u->na->status & NS_VERBOTEN) {
- alog("%s: %s@%s tried to register FORBIDden nick %s",
- s_NickServ, u->username, u->host, u->nick);
- notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick);
- } else {
- notice_lang(s_NickServ, u, NICK_ALREADY_REGISTERED, u->nick);
- }
- } else if (stricmp(u->nick, pass) == 0
- || (StrictPasswords && strlen(pass) < 5)) {
- notice_lang(s_NickServ, u, MORE_OBSCURE_PASSWORD);
- } else if (email && !MailValidate(email)) {
- notice_lang(s_NickServ, u, MAIL_X_INVALID, email);
- } else {
-#ifdef USE_ENCRYPTION
- if (strlen(pass) > PASSMAX) {
- pass[PASSMAX] = 0;
- notice_lang(s_NickServ, u, PASSWORD_TRUNCATED, PASSMAX);
- }
-#else
- if (strlen(pass) > PASSMAX - 1) { /* -1 for null byte */
- pass[PASSMAX] = 0;
- notice_lang(s_NickServ, u, PASSWORD_TRUNCATED, PASSMAX - 1);
- }
-#endif
- for (idx = 0; idx < 9; idx++) {
- passcode[idx] =
- chars[(1 +
- (int) (((float) (max - min)) * getrandom16() /
- (65535 + 1.0)) + min)];
- } passcode[idx] = '\0';
- nr = makerequest(u->nick);
- nr->passcode = sstrdup(passcode);
- nr->password = sstrdup(pass);
- if (email) {
- nr->email = sstrdup(email);
- }
- nr->requested = time(NULL);
- if (NSEmailReg) {
- if (do_sendregmail(u, nr) == 0) {
- notice_lang(s_NickServ, u, NICK_ENTER_REG_CODE, email,
- s_NickServ);
- alog("%s: sent registration verification code to %s",
- s_NickServ, nr->email);
- } else {
- alog("%s: Unable to send registration verification mail",
- s_NickServ);
- notice_lang(s_NickServ, u, NICK_REG_UNABLE);
- delnickrequest(nr); /* Delete the NickRequest if we couldnt send the mail */
- return MOD_CONT;
- }
- } else {
- do_confirm(u);
- }
-
- }
- return MOD_CONT;
-}
-
-
-static int do_resend(User * u)
-{
- NickRequest *nr = NULL;
- if (NSEmailReg) {
- if ((nr = findrequestnick(u->nick))) {
- if (do_sendregmail(u, nr) == 0) {
- notice_lang(s_NickServ, u, NICK_REG_RESENT, nr->email);
- alog("%s: re-sent registration verification code for %s to %s", s_NickServ, nr->nick, nr->email);
- } else {
- alog("%s: Unable to re-send registration verification mail for %s", s_NickServ, nr->nick);
- return MOD_CONT;
- }
- }
- }
- return MOD_CONT;
-}
-
-static int do_sendregmail(User * u, NickRequest * nr)
-{
- MailInfo *mail = NULL;
- char buf[BUFSIZE];
-
- if (!(nr || u)) {
- return -1;
- }
- snprintf(buf, sizeof(buf), getstring2(NULL, NICK_REG_MAIL_SUBJECT),
- nr->nick);
- mail = MailRegBegin(u, nr, buf, s_NickServ);
- if (!mail) {
- return -1;
- }
- fprintf(mail->pipe, getstring2(NULL, NICK_REG_MAIL_HEAD));
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring2(NULL, NICK_REG_MAIL_LINE_1), nr->nick);
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring2(NULL, NICK_REG_MAIL_LINE_2), s_NickServ,
- nr->passcode);
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring2(NULL, NICK_REG_MAIL_LINE_3));
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring2(NULL, NICK_REG_MAIL_LINE_4));
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring2(NULL, NICK_REG_MAIL_LINE_5),
- NetworkName);
- fprintf(mail->pipe, "\n.\n");
- MailEnd(mail);
- return 0;
-}
-
-static int do_confirm(User * u)
-{
-
- NickRequest *nr = NULL;
- NickAlias *na = NULL;
- char *passcode = strtok(NULL, " ");
- char *pass = NULL;
- char *email = NULL;
- int forced = 0;
- User *utmp = NULL;
-#ifdef USE_ENCRYPTION
- int len;
-#endif
- nr = findrequestnick(u->nick);
-
- if (NSEmailReg) {
- if (!passcode) {
- notice_lang(s_NickServ, u, NICK_CONFIRM_INVALID);
- return MOD_CONT;
- }
-
- if (!nr) {
- if (is_services_admin(u)) {
-/* If an admin, thier nick is obviously already regged, so look at the passcode to get the nick
- of the user they are trying to validate, and push that user through regardless of passcode */
- nr = findrequestnick(passcode);
- if (nr) {
- utmp = finduser(passcode);
- if (utmp) {
- sprintf(passcode,
- "FORCE_ACTIVATION_DUE_TO_OPER_CONFIRM %s",
- nr->passcode);
- passcode = strtok(passcode, " ");
- notice_lang(s_NickServ, u, NICK_FORCE_REG,
- nr->nick);
- do_confirm(utmp);
- return MOD_CONT;
- } else {
- passcode = sstrdup(nr->passcode);
- forced = 1;
- }
- } else {
- notice_lang(s_NickServ, u, NICK_CONFIRM_NOT_FOUND,
- s_NickServ);
- return MOD_CONT;
- }
- } else {
- notice_lang(s_NickServ, u, NICK_CONFIRM_NOT_FOUND,
- s_NickServ);
- return MOD_CONT;
- }
- }
-
- if (stricmp(nr->passcode, passcode) != 0) {
- notice_lang(s_NickServ, u, NICK_CONFIRM_INVALID);
- return MOD_CONT;
- }
- }
-
- if (!nr) {
- notice_lang(s_NickServ, u, NICK_REGISTRATION_FAILED);
- return MOD_CONT;
- }
- pass = sstrdup(nr->password);
-
- if (nr->email) {
- email = sstrdup(nr->email);
- }
- na = makenick(nr->nick);
-
- if (na) {
- int i;
- char tsbuf[16];
-
-#ifdef USE_ENCRYPTION
- len = strlen(pass);
- na->nc->pass = smalloc(PASSMAX);
- if (encrypt(pass, len, na->nc->pass, PASSMAX) < 0) {
- memset(pass, 0, strlen(pass));
- alog("%s: Failed to encrypt password for %s (register)",
- s_NickServ, nr->nick);
- notice_lang(s_NickServ, u, NICK_REGISTRATION_FAILED);
- return MOD_CONT;
- }
- memset(pass, 0, strlen(pass));
- na->status = (int16) (NS_IDENTIFIED | NS_RECOGNIZED);
- na->nc->flags |= NI_ENCRYPTEDPW;
-#else
- na->nc->pass = sstrdup(pass);
- na->status = (int16) (NS_IDENTIFIED | NS_RECOGNIZED);
-#endif
- na->nc->flags |= NSDefFlags;
- for (i = 0; i < RootNumber; i++) {
- if (!stricmp(ServicesRoots[i], nr->nick)) {
- na->nc->flags |= NI_SERVICES_ROOT;
- break;
- }
- }
- na->nc->memos.memomax = MSMaxMemos;
- na->nc->channelmax = CSMaxReg;
- if (forced == 1) {
- na->last_usermask = sstrdup("*@*");
- na->last_realname = sstrdup("unknown");
- } else {
- na->last_usermask =
- scalloc(strlen(common_get_vident(u)) +
- strlen(common_get_vhost(u)) + 2, 1);
- sprintf(na->last_usermask, "%s@%s", common_get_vident(u),
- common_get_vhost(u));
- na->last_realname = sstrdup(u->realname);
- }
- na->time_registered = na->last_seen = time(NULL);
- if (NSAddAccessOnReg) {
- na->nc->accesscount = 1;
- na->nc->access = scalloc(sizeof(char *), 1);
- na->nc->access[0] = create_mask(u);
- } else {
- na->nc->accesscount = 0;
- na->nc->access = NULL;
- }
- na->nc->language = NSDefLanguage;
- if (email)
- na->nc->email = sstrdup(email);
- if (forced != 1) {
- u->na = na;
- na->u = u;
- alog("%s: '%s' registered by %s@%s (e-mail: %s)", s_NickServ,
- u->nick, u->username, u->host, (email ? email : "none"));
- if (NSAddAccessOnReg)
- notice_lang(s_NickServ, u, NICK_REGISTERED, u->nick,
- na->nc->access[0]);
- else
- notice_lang(s_NickServ, u, NICK_REGISTERED_NO_MASK,
- u->nick);
- send_event(EVENT_NICK_REGISTERED, u->nick);
-#ifndef USE_ENCRYPTION
- notice_lang(s_NickServ, u, NICK_PASSWORD_IS, na->nc->pass);
-#endif
- u->lastnickreg = time(NULL);
- if (ircd->modeonreg) {
- if (ircd->tsonmode) {
- snprintf(tsbuf, sizeof(tsbuf), "%lu",
- (unsigned long int) u->timestamp);
- common_svsmode(u, ircd->modeonreg, tsbuf);
- } else {
- common_svsmode(u, ircd->modeonreg, NULL);
- }
- }
-
- } else {
- notice_lang(s_NickServ, u, NICK_FORCE_REG, nr->nick);
- }
- delnickrequest(nr); /* remove the nick request */
- } else {
- alog("%s: makenick(%s) failed", s_NickServ, u->nick);
- notice_lang(s_NickServ, u, NICK_REGISTRATION_FAILED);
- }
-
- /* Enable nick tracking if enabled */
- if (NSNickTracking)
- nsStartNickTracking(u);
-
- return MOD_CONT;
-}
-
-/*************************************************************************/
-
-/* Register a nick in a specified group. */
-
-static int do_group(User * u)
-{
- NickAlias *na, *target;
- NickCore *nc;
- char *nick = strtok(NULL, " ");
- char *pass = strtok(NULL, " ");
- int i;
- char tsbuf[16];
-
- if (NSEmailReg && (findrequestnick(u->nick))) {
- notice_lang(s_NickServ, u, NICK_REQUESTED);
- return MOD_CONT;
- }
-
- if (readonly) {
- notice_lang(s_NickServ, u, NICK_GROUP_DISABLED);
- return MOD_CONT;
- }
- if (checkDefCon(DEFCON_NO_NEW_NICKS)) {
- notice_lang(s_NickServ, u, OPER_DEFCON_DENIED);
- return MOD_CONT;
- }
-
- if (RestrictOperNicks) {
- for (i = 0; i < RootNumber; i++) {
- if (stristr(u->nick, ServicesRoots[i]) && !is_oper(u)) {
- notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED,
- u->nick);
- return MOD_CONT;
- }
- }
- for (i = 0; i < servadmins.count && (nc = servadmins.list[i]); i++) {
- if (stristr(u->nick, nc->display) && !is_oper(u)) {
- notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED,
- u->nick);
- return MOD_CONT;
- }
- }
- for (i = 0; i < servopers.count && (nc = servopers.list[i]); i++) {
- if (stristr(u->nick, nc->display) && !is_oper(u)) {
- notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED,
- u->nick);
- return MOD_CONT;
- }
- }
- }
-
- if (!nick || !pass) {
- syntax_error(s_NickServ, u, "GROUP", NICK_GROUP_SYNTAX);
- } else if (time(NULL) < u->lastnickreg + NSRegDelay) {
- notice_lang(s_NickServ, u, NICK_GROUP_PLEASE_WAIT, NSRegDelay);
- } else if (u->na && (u->na->status & NS_VERBOTEN)) {
- alog("%s: %s@%s tried to use GROUP from FORBIDden nick %s",
- s_NickServ, u->username, u->host, u->nick);
- notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, u->nick);
- } else if (u->na && (u->na->nc->flags & NI_SUSPENDED)) {
- alog("%s: %s@%s tried to use GROUP from SUSPENDED nick %s",
- s_NickServ, u->username, u->host, u->nick);
- notice_lang(s_NickServ, u, NICK_X_SUSPENDED, u->nick);
- } else if (u->na && NSNoGroupChange) {
- notice_lang(s_NickServ, u, NICK_GROUP_CHANGE_DISABLED, s_NickServ);
- } else if (u->na && !nick_identified(u)) {
- notice_lang(s_NickServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ);
- } else if (!(target = findnick(nick))) {
- notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
- } else if (target && (target->nc->flags & NI_SUSPENDED)) {
- alog("%s: %s@%s tried to use GROUP from SUSPENDED nick %s",
- s_NickServ, u->username, u->host, u->nick);
- notice_lang(s_NickServ, u, NICK_X_SUSPENDED, target->nick);
- } else if (target->status & NS_VERBOTEN) {
- notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, nick);
- } else if (u->na && target->nc == u->na->nc) {
- notice_lang(s_NickServ, u, NICK_GROUP_SAME, target->nick);
- } else if (NSMaxAliases && (target->nc->aliases.count >= NSMaxAliases)
- && !nick_is_services_admin(target->nc)) {
- notice_lang(s_NickServ, u, NICK_GROUP_TOO_MANY, target->nick,
- s_NickServ, s_NickServ);
- } else if (check_password(pass, target->nc->pass) != 1) {
- alog("%s: Failed GROUP for %s!%s@%s (invalid password)",
- s_NickServ, u->nick, u->username, u->host);
- notice_lang(s_NickServ, u, PASSWORD_INCORRECT);
- bad_password(u);
- } else {
- /* If the nick is already registered, drop it.
- * If not, check that it is valid.
- */
- if (u->na) {
- delnick(u->na);
- } else {
- int prefixlen = strlen(NSGuestNickPrefix);
- int nicklen = strlen(u->nick);
-
- if (nicklen <= prefixlen + 7 && nicklen >= prefixlen + 1
- && stristr(u->nick, NSGuestNickPrefix) == u->nick
- && strspn(u->nick + prefixlen,
- "1234567890") == nicklen - prefixlen) {
- notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED,
- u->nick);
- return MOD_CONT;
- }
- }
- na = makealias(u->nick, target->nc);
-
- if (na) {
- na->last_usermask =
- scalloc(strlen(common_get_vident(u)) +
- strlen(common_get_vhost(u)) + 2, 1);
- sprintf(na->last_usermask, "%s@%s", common_get_vident(u),
- common_get_vhost(u));
- na->last_realname = sstrdup(u->realname);
- na->time_registered = na->last_seen = time(NULL);
- na->status = (int16) (NS_IDENTIFIED | NS_RECOGNIZED);
-
- if (!(na->nc->flags & NI_SERVICES_ROOT)) {
- for (i = 0; i < RootNumber; i++) {
- if (!stricmp(ServicesRoots[i], u->nick)) {
- na->nc->flags |= NI_SERVICES_ROOT;
- break;
- }
- }
- }
-
- u->na = na;
- na->u = u;
-
-#ifdef USE_RDB
- /* Is this really needed? Since this is a new alias it will get
- * its unique id on the next update, since it was previously
- * deleted by delnick. Must observe...
- */
- if (rdb_open()) {
- rdb_save_ns_alias(na);
- rdb_close();
- }
-#endif
- send_event(EVENT_GROUP, u->nick);
- alog("%s: %s!%s@%s makes %s join group of %s (%s) (e-mail: %s)", s_NickServ, u->nick, u->username, u->host, u->nick, target->nick, target->nc->display, (target->nc->email ? target->nc->email : "none"));
- notice_lang(s_NickServ, u, NICK_GROUP_JOINED, target->nick);
-
- u->lastnickreg = time(NULL);
- snprintf(tsbuf, sizeof(tsbuf), "%lu",
- (unsigned long int) u->timestamp);
- if (ircd->modeonreg) {
- if (ircd->tsonmode) {
- common_svsmode(u, ircd->modeonreg, tsbuf);
- } else {
- common_svsmode(u, ircd->modeonreg, NULL);
- }
- }
-
- check_memos(u);
- } else {
- alog("%s: makealias(%s) failed", s_NickServ, u->nick);
- notice_lang(s_NickServ, u, NICK_GROUP_FAILED);
- }
- }
- return MOD_CONT;
-}
-
-/*************************************************************************/
-
-static int do_nickupdate(User * u)
-{
- NickAlias *na;
-
- if (!nick_identified(u)) {
- notice_lang(s_NickServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ);
- } else {
- na = u->na;
- if (NSModeOnID)
- do_setmodes(u);
- check_memos(u);
- if (na->last_realname)
- free(na->last_realname);
- na->last_realname = sstrdup(u->realname);
- na->status |= NS_IDENTIFIED;
- na->last_seen = time(NULL);
- if (ircd->vhost) {
- do_on_id(u);
- }
- notice_lang(s_NickServ, u, NICK_UPDATE_SUCCESS, s_NickServ);
- }
- return MOD_CONT;
-}
-
-/*************************************************************************/
-
-static int do_identify(User * u)
-{
- char *pass = strtok(NULL, " ");
- NickAlias *na;
- NickRequest *nr;
- int res;
- char tsbuf[16];
-
- if (!pass) {
- syntax_error(s_NickServ, u, "IDENTIFY", NICK_IDENTIFY_SYNTAX);
- } else if (!(na = u->na)) {
- if ((nr = findrequestnick(u->nick))) {
- notice_lang(s_NickServ, u, NICK_IS_PREREG);
- } else {
- notice_lang(s_NickServ, u, NICK_NOT_REGISTERED);
- }
- } 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 (nick_identified(u)) {
- notice_lang(s_NickServ, u, NICK_ALREADY_IDENTIFIED);
- } else if (!(res = check_password(pass, na->nc->pass))) {
- alog("%s: Failed IDENTIFY for %s!%s@%s", s_NickServ, u->nick,
- u->username, u->host);
- notice_lang(s_NickServ, u, PASSWORD_INCORRECT);
- bad_password(u);
- } else if (res == -1) {
- notice_lang(s_NickServ, u, NICK_IDENTIFY_FAILED);
- } else {
- if (!(na->status & NS_IDENTIFIED) && !(na->status & NS_RECOGNIZED)) {
- if (na->last_usermask)
- free(na->last_usermask);
- na->last_usermask =
- scalloc(strlen(common_get_vident(u)) +
- strlen(common_get_vhost(u)) + 2, 1);
- sprintf(na->last_usermask, "%s@%s", common_get_vident(u),
- common_get_vhost(u));
- if (na->last_realname)
- free(na->last_realname);
- na->last_realname = sstrdup(u->realname);
- }
-
- na->status |= NS_IDENTIFIED;
- na->last_seen = time(NULL);
- snprintf(tsbuf, sizeof(tsbuf), "%lu",
- (unsigned long int) u->timestamp);
-
- if (ircd->modeonreg) {
- if (ircd->tsonmode) {
- common_svsmode(u, ircd->modeonreg, tsbuf);
- } else {
- common_svsmode(u, ircd->modeonreg, "");
- }
- }
- send_event(EVENT_NICK_IDENTIFY, u->nick);
- alog("%s: %s!%s@%s identified for nick %s", s_NickServ, u->nick,
- u->username, u->host, u->nick);
- notice_lang(s_NickServ, u, NICK_IDENTIFY_SUCCEEDED);
- if (ircd->vhost) {
- do_on_id(u);
- }
- if (NSModeOnID) {
- do_setmodes(u);
- }
-
- if (NSForceEmail && u->na && !u->na->nc->email) {
- notice_lang(s_NickServ, u, NICK_IDENTIFY_EMAIL_REQUIRED);
- notice_help(s_NickServ, u, NICK_IDENTIFY_EMAIL_HOWTO);
- }
-
- if (!(na->status & NS_RECOGNIZED))
- check_memos(u);
-
- /* Enable nick tracking if enabled */
- if (NSNickTracking)
- nsStartNickTracking(u);
-
- /* Clear any timers */
- if (na->nc->flags & NI_KILLPROTECT) {
- del_ns_timeout(na, TO_COLLIDE);
- }
-
- }
- return MOD_CONT;
-}
-
int should_mode_change(int16 status, int16 mode)
{
switch (mode) {
@@ -2678,7 +1864,9 @@ int should_mode_change(int16 status, int16 mode)
return 1;
}
-static int do_setmodes(User * u)
+/*************************************************************************/