Anope IRC Services  Version 1.8
ns_suspend.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 
17 static int do_suspend(User * u);
18 static int do_unsuspend(User * u);
19 static void myNickServHelp(User * u);
20 
27 int AnopeInit(int argc, char **argv)
28 {
29  Command *c;
30 
31  moduleAddAuthor("Anope");
32  moduleAddVersion(VERSION_STRING);
34 
35  c = createCommand("SUSPEND", do_suspend, is_services_oper, -1, -1,
36  NICK_SERVADMIN_HELP_SUSPEND,
37  NICK_SERVADMIN_HELP_SUSPEND,
38  NICK_SERVADMIN_HELP_SUSPEND);
40  c = createCommand("UNSUSPEND", do_unsuspend, is_services_oper, -1, -1,
41  NICK_SERVADMIN_HELP_UNSUSPEND,
42  NICK_SERVADMIN_HELP_UNSUSPEND,
43  NICK_SERVADMIN_HELP_UNSUSPEND);
45 
47 
48  return MOD_CONT;
49 }
50 
54 void AnopeFini(void)
55 {
56 
57 }
58 
63 static void myNickServHelp(User * u)
64 {
65  if (is_services_oper(u)) {
66  notice_lang(s_NickServ, u, NICK_HELP_CMD_SUSPEND);
67  notice_lang(s_NickServ, u, NICK_HELP_CMD_UNSUSPEND);
68  }
69 }
70 
76 static int do_suspend(User * u)
77 {
78  NickAlias *na, *na2;
79  User *u2;
80  char *nick = strtok(NULL, " ");
81  char *reason = strtok(NULL, "");
82  int i;
83 
84  if (!nick || !reason) {
85  syntax_error(s_NickServ, u, "SUSPEND", NICK_SUSPEND_SYNTAX);
86  return MOD_CONT;
87  }
88 
89  if (readonly) {
90  notice_lang(s_NickServ, u, READ_ONLY_MODE);
91  return MOD_CONT;
92  }
93 
94  if ((na = findnick(nick)) == NULL) {
95  notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
96  return MOD_CONT;
97  }
98 
99  if (na->status & NS_VERBOTEN) {
100  notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
101  return MOD_CONT;
102  }
103 
105  && !is_services_root(u)) {
106  notice_lang(s_NickServ, u, PERMISSION_DENIED);
107  return MOD_CONT;
108  }
109 
110  if (na) {
111  na->nc->flags |= NI_SUSPENDED;
112  na->nc->flags |= NI_SECURE;
114 
115  for (i = 0; i < na->nc->aliases.count; i++) {
116  na2 = na->nc->aliases.list[i];
117  if (na2->nc == na->nc) {
118  na2->status &= ~(NS_IDENTIFIED | NS_RECOGNIZED);
119  if (na2->last_quit)
120  free(na2->last_quit);
121  na2->last_quit = sstrdup(reason);
122  /* remove nicktracking */
123  if ((u2 = finduser(na2->nick))) {
124  if (u2->nickTrack) {
125  free(u2->nickTrack);
126  u2->nickTrack = NULL;
127  }
128  }
129  /* force guestnick */
130  collide(na2, 0);
131  }
132  }
133 
134  if (WallForbid)
135  anope_cmd_global(s_NickServ, "\2%s\2 used SUSPEND on \2%s\2",
136  u->nick, nick);
137 
138  alog("%s: %s set SUSPEND for nick %s", s_NickServ, u->nick, nick);
139  notice_lang(s_NickServ, u, NICK_SUSPEND_SUCCEEDED, nick);
141 
142  } else {
143 
144  alog("%s: Valid SUSPEND for %s by %s failed", s_NickServ, nick,
145  u->nick);
146  notice_lang(s_NickServ, u, NICK_SUSPEND_FAILED, nick);
147 
148  }
149  return MOD_CONT;
150 }
151 
152 /*************************************************************************/
153 
154 static int do_unsuspend(User * u)
155 {
156  NickAlias *na;
157  char *nick = strtok(NULL, " ");
158 
159  if (!nick) {
160  syntax_error(s_NickServ, u, "UNSUSPEND", NICK_UNSUSPEND_SYNTAX);
161  return MOD_CONT;
162  }
163 
164  if (readonly) {
165  notice_lang(s_NickServ, u, READ_ONLY_MODE);
166  return MOD_CONT;
167  }
168 
169  if ((na = findnick(nick)) == NULL) {
170  notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
171  return MOD_CONT;
172  }
173 
174  if (na->status & NS_VERBOTEN) {
175  notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
176  return MOD_CONT;
177  }
179  && !is_services_root(u)) {
180  notice_lang(s_NickServ, u, PERMISSION_DENIED);
181  return MOD_CONT;
182  }
183 
184  if (na) {
185  na->nc->flags &= ~NI_SUSPENDED;
186 
187  if (WallForbid)
188  anope_cmd_global(s_NickServ, "\2%s\2 used UNSUSPEND on \2%s\2",
189  u->nick, nick);
190 
191  alog("%s: %s set UNSUSPEND for nick %s", s_NickServ, u->nick,
192  nick);
193  notice_lang(s_NickServ, u, NICK_UNSUSPEND_SUCCEEDED, nick);
195 
196  } else {
197 
198  alog("%s: Valid UNSUSPEND for %s by %s failed", s_NickServ, nick,
199  u->nick);
200  notice_lang(s_NickServ, u, NICK_UNSUSPEND_FAILED, nick);
201 
202  }
203 
204  return MOD_CONT;
205 
206 }
E int nick_is_services_admin(NickCore *nc)
Definition: operserv.c:636
#define NI_KILL_IMMED
Definition: services.h:1301
E int readonly
Definition: extern.h:776
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
static int do_unsuspend(User *u)
Definition: ns_suspend.c:154
#define EVENT_NICK_UNSUSPEND
Definition: events.h:60
char * last_quit
Definition: services.h:527
E void send_event(const char *name, int argc,...)
Definition: events.c:37
E int WallForbid
Definition: extern.h:467
E int NSSecureAdmins
Definition: extern.h:394
#define NS_RECOGNIZED
Definition: services.h:1276
#define NS_VERBOTEN
Definition: services.h:1273
static int do_suspend(User *u)
Definition: ns_suspend.c:76
#define NI_KILLPROTECT
Definition: services.h:1290
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
static void myNickServHelp(User *u)
Definition: ns_suspend.c:63
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 char * sstrdup(const char *s)
Definition: memory.c:105
NickCore * nc
Definition: services.h:533
E int is_services_root(User *u)
Definition: operserv.c:577
void ** list
Definition: slist.h:21
int16 count
Definition: slist.h:23
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
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
int AnopeInit(int argc, char **argv)
Definition: ns_suspend.c:27
char * nick
Definition: services.h:526
#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
void AnopeFini(void)
Definition: ns_suspend.c:54
#define NS_IDENTIFIED
Definition: services.h:1275
SList aliases
Definition: services.h:559
E int is_services_oper(User *u)
Definition: operserv.c:606
#define EVENT_NICK_SUSPENDED
Definition: events.h:59
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
char * nickTrack
Definition: services.h:885
#define NI_KILL_QUICK
Definition: services.h:1300
#define NICKSERV
Definition: modules.h:59
#define MOD_UNIQUE
Definition: module.h:11
E void anope_cmd_global(char *source, const char *fmt,...)
Definition: ircd.c:506