Anope IRC Services  Version 1.8
ns_recover.c
Go to the documentation of this file.
1 /* NickServ core functions
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  *
12  */
13 /*************************************************************************/
14 
15 #include "module.h"
16 
18 
19 static int do_recover(User * u);
20 static void myNickServHelp(User * u);
21 static int myHelpResonse(User * u);
22 
29 int AnopeInit(int argc, char **argv)
30 {
31  moduleAddAuthor("Anope");
32  moduleAddVersion(VERSION_STRING);
34 
35  c = createCommand("RECOVER", do_recover, NULL, -1, -1, -1, -1, -1);
38 
40 
41  return MOD_CONT;
42 }
43 
47 void AnopeFini(void)
48 {
49 
50 }
51 
56 static void myNickServHelp(User * u)
57 {
58  notice_lang(s_NickServ, u, NICK_HELP_CMD_RECOVER);
59 }
60 
65 static int myHelpResonse(User * u)
66 {
67  char relstr[192];
68 
69  /* Convert NSReleaseTimeout seconds to string format */
70  duration(u->na, relstr, sizeof(relstr), NSReleaseTimeout);
71 
72  notice_help(s_NickServ, u, NICK_HELP_RECOVER, relstr);
74 
75  return MOD_CONT;
76 }
77 
83 static int do_recover(User * u)
84 {
85  char *nick = strtok(NULL, " ");
86  char *pass = strtok(NULL, " ");
87  NickAlias *na;
88  User *u2;
89 
90  if (!nick) {
91  syntax_error(s_NickServ, u, "RECOVER", NICK_RECOVER_SYNTAX);
92  } else if (!(u2 = finduser(nick))) {
93  notice_lang(s_NickServ, u, NICK_X_NOT_IN_USE, nick);
94  } else if (!(na = u2->na)) {
95  notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
96  } else if (na->status & NS_VERBOTEN) {
97  notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
98  } else if (na->nc->flags & NI_SUSPENDED) {
99  notice_lang(s_NickServ, u, NICK_X_SUSPENDED, na->nick);
100  } else if (stricmp(nick, u->nick) == 0) {
101  notice_lang(s_NickServ, u, NICK_NO_RECOVER_SELF);
102  } else if (pass) {
103  int res = enc_check_password(pass, na->nc->pass);
104 
105  if (res == 1) {
106  char relstr[192];
107 
109  alog("%s: %s!%s@%s used RECOVER on %s",
110  s_NickServ, u->nick, u->username, u->host, u2->nick);
111  notice_lang(s_NickServ, u2, FORCENICKCHANGE_NOW);
112  collide(na, 0);
113 
114  /* Convert NSReleaseTimeout seconds to string format */
115  duration(u2->na, relstr, sizeof(relstr), NSReleaseTimeout);
116 
117  notice_lang(s_NickServ, u, NICK_RECOVERED, s_NickServ, nick, relstr);
119  } else {
120  notice_lang(s_NickServ, u, ACCESS_DENIED);
121  if (res == 0) {
122  alog("%s: RECOVER: invalid password for %s by %s!%s@%s",
123  s_NickServ, nick, u->nick, u->username, u->host);
124  bad_password(u);
125  }
126  }
127  } else {
128  if (group_identified(u, na->nc)
129  || (!(na->nc->flags & NI_SECURE) && is_on_access(u, na->nc))) {
130  char relstr[192];
131 
133  alog("%s: %s!%s@%s used RECOVER on %s",
134  s_NickServ, u->nick, u->username, u->host, u2->nick);
135  notice_lang(s_NickServ, u2, FORCENICKCHANGE_NOW);
136  collide(na, 0);
137 
138  /* Convert NSReleaseTimeout second to string format */
139  duration(u2->na, relstr, sizeof(relstr), NSReleaseTimeout);
140 
141  notice_lang(s_NickServ, u, NICK_RECOVERED, s_NickServ, nick, relstr);
143  } else {
144  notice_lang(s_NickServ, u, ACCESS_DENIED);
145  }
146  }
147 
148  return MOD_CONT;
149 }
150 
151 /* EOF */
E int is_on_access(User *u, NickCore *nc)
Definition: nickserv.c:1289
char nick[NICKMAX]
Definition: services.h:875
#define EVENT_STOP
Definition: events.h:15
#define EVENT_NICK_RECOVERED
Definition: events.h:53
#define NI_SUSPENDED
Definition: services.h:1308
E int enc_check_password(const char *plaintext, const char *password)
Definition: encrypt.c:95
E void send_event(const char *name, int argc,...)
Definition: events.c:37
MDE void do_help_limited(char *service, User *u, Command *c)
Definition: commands.c:137
E char * duration(NickAlias *na, char *buf, int bufsize, time_t seconds)
Definition: misc.c:402
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
E int group_identified(User *u, NickCore *nc)
Definition: nickserv.c:1151
#define NS_VERBOTEN
Definition: services.h:1273
char * host
Definition: services.h:878
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
E void bad_password(User *u)
Definition: actions.c:24
NickCore * nc
Definition: services.h:533
E void collide(NickAlias *na, int from_timeout)
Definition: nickserv.c:1671
E User * finduser(const char *nick)
Definition: users.c:323
uint16 status
Definition: services.h:532
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
void AnopeFini(void)
Definition: ns_recover.c:47
E void notice_help(char *source, User *dest, int message,...)
Definition: send.c:220
E void alog(const char *fmt,...) FORMAT(printf
static int do_recover(User *u)
Definition: ns_recover.c:83
int AnopeInit(int argc, char **argv)
Definition: ns_recover.c:29
#define MOD_CONT
Definition: modules.h:54
#define EVENT_START
Definition: events.h:14
static void myNickServHelp(User *u)
Definition: ns_recover.c:56
char * nick
Definition: services.h:526
char * username
Definition: services.h:877
#define NI_SECURE
Definition: services.h:1291
MDE void moduleSetNickHelp(void(*func)(User *u))
Definition: modules.c:2078
Definition: modules.h:99
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
E int NSReleaseTimeout
Definition: extern.h:388
char pass[PASSMAX]
Definition: services.h:543
MDE int moduleAddHelp(Command *c, int(*func)(User *u))
Definition: modules.c:2064
static int myHelpResonse(User *u)
Definition: ns_recover.c:65
uint32 flags
Definition: services.h:548
E char * s_NickServ
Definition: extern.h:284
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define NICKSERV
Definition: modules.h:59
NickAlias * na
Definition: services.h:892
#define MOD_UNIQUE
Definition: module.h:11