Anope IRC Services  Version 1.8
ns_release.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_release(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("RELEASE", do_release, NULL, -1, -1, -1, -1, -1);
38 
40 
41  return MOD_CONT;
42 }
43 
47 void AnopeFini(void)
48 {
49 
50 }
51 
52 
53 
58 static void myNickServHelp(User * u)
59 {
60  notice_lang(s_NickServ, u, NICK_HELP_CMD_RELEASE);
61 }
62 
67 static int myHelpResonse(User * u)
68 {
69  char relstr[192];
70 
71  /* Convert NSReleaseTimeout seconds to string format */
72  duration(u->na, relstr, sizeof(relstr), NSReleaseTimeout);
73 
74  notice_help(s_NickServ, u, NICK_HELP_RELEASE, relstr);
76 
77  return MOD_CONT;
78 }
79 
85 static int do_release(User * u)
86 {
87  char *nick = strtok(NULL, " ");
88  char *pass = strtok(NULL, " ");
89  NickAlias *na;
90 
91  if (!nick) {
92  syntax_error(s_NickServ, u, "RELEASE", NICK_RELEASE_SYNTAX);
93  } else if (!(na = findnick(nick))) {
94  notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
95  } else if (na->status & NS_VERBOTEN) {
96  notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
97  } else if (na->nc->flags & NI_SUSPENDED) {
98  notice_lang(s_NickServ, u, NICK_X_SUSPENDED, na->nick);
99  } else if (!(na->status & NS_KILL_HELD)) {
100  notice_lang(s_NickServ, u, NICK_RELEASE_NOT_HELD, nick);
101  } else if (pass) {
102  int res = enc_check_password(pass, na->nc->pass);
103  if (res == 1) {
104  release(na, 0);
105  notice_lang(s_NickServ, u, NICK_RELEASED);
106  } else {
107  notice_lang(s_NickServ, u, ACCESS_DENIED);
108  if (res == 0) {
109  alog("%s: RELEASE: invalid password for %s by %s!%s@%s",
110  s_NickServ, nick, u->nick, u->username, u->host);
111  bad_password(u);
112  }
113  }
114  } else {
115  if (group_identified(u, na->nc)
116  || (!(na->nc->flags & NI_SECURE) && is_on_access(u, na->nc))) {
117  release(na, 0);
118  notice_lang(s_NickServ, u, NICK_RELEASED);
119  } else {
120  notice_lang(s_NickServ, u, ACCESS_DENIED);
121  }
122  }
123  return MOD_CONT;
124 }
125 
126 /* EOF */
int AnopeInit(int argc, char **argv)
Definition: ns_release.c:29
E int is_on_access(User *u, NickCore *nc)
Definition: nickserv.c:1289
#define NS_KILL_HELD
Definition: services.h:1278
char nick[NICKMAX]
Definition: services.h:875
E NickAlias * findnick(const char *nick)
Definition: db-merger.c:1857
#define NI_SUSPENDED
Definition: services.h:1308
E int enc_check_password(const char *plaintext, const char *password)
Definition: encrypt.c:95
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 group_identified(User *u, NickCore *nc)
Definition: nickserv.c:1151
#define NS_VERBOTEN
Definition: services.h:1273
char * host
Definition: services.h:878
Command * c
Definition: ns_release.c:17
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 release(NickAlias *na, int from_timeout)
Definition: nickserv.c:1705
uint16 status
Definition: services.h:532
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
static int do_release(User *u)
Definition: ns_release.c:85
E void notice_help(char *source, User *dest, int message,...)
Definition: send.c:220
E void alog(const char *fmt,...) FORMAT(printf
void AnopeFini(void)
Definition: ns_release.c:47
#define MOD_CONT
Definition: modules.h:54
static int myHelpResonse(User *u)
Definition: ns_release.c:67
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
uint32 flags
Definition: services.h:548
static void myNickServHelp(User *u)
Definition: ns_release.c:58
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