Anope IRC Services  Version 1.8
ns_forbid.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_forbid(User * u);
18 static void myNickServHelp(User * u);
19 NickAlias *makenick(const char *nick);
20 
27 int AnopeInit(int argc, char **argv)
28 {
29  Command *c;
30 
31  moduleAddAuthor("Anope");
32  moduleAddVersion(VERSION_STRING);
34 
35  c = createCommand("FORBID", do_forbid, is_services_admin, -1, -1, -1,
36  NICK_SERVADMIN_HELP_FORBID,
37  NICK_SERVADMIN_HELP_FORBID);
39 
41 
42  return MOD_CONT;
43 }
44 
48 void AnopeFini(void)
49 {
50 
51 }
52 
53 
54 
59 static void myNickServHelp(User * u)
60 {
61  if (is_services_admin(u)) {
62  notice_lang(s_NickServ, u, NICK_HELP_CMD_FORBID);
63  }
64 }
65 
71 static int do_forbid(User * u)
72 {
73  NickAlias *na;
74  char *nick = strtok(NULL, " ");
75  char *reason = strtok(NULL, "");
76  char *ch;
77 
78  /* Assumes that permission checking has already been done. */
79  if (!nick || (ForceForbidReason && !reason)) {
80  syntax_error(s_NickServ, u, "FORBID",
81  (ForceForbidReason ? NICK_FORBID_SYNTAX_REASON :
82  NICK_FORBID_SYNTAX));
83  return MOD_CONT;
84  }
85 
86  if (readonly)
87  notice_lang(s_NickServ, u, READ_ONLY_MODE);
88  if (!anope_valid_nick(nick)) {
89  notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, nick);
90  return MOD_CONT;
91  }
92 
93  if (isdigit(nick[0]) || nick[0] == '-' || strlen(nick) > NICKMAX - 1)
94  {
95  notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, nick);
96  return MOD_CONT;
97  }
98  for (ch = nick; *ch; ch++)
99  {
100  if (!isvalidnick(*ch))
101  {
102  notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, nick);
103  return MOD_CONT;
104  }
105  }
106 
107  if ((na = findnick(nick)) != NULL) {
109  && !is_services_root(u)) {
110  notice_lang(s_NickServ, u, PERMISSION_DENIED);
111  return MOD_CONT;
112  }
113  delnick(na);
114  send_event(EVENT_NICK_DROPPED, 1, nick);
115  }
116  na = makenick(nick);
117  if (na) {
118  na->status |= NS_VERBOTEN;
119  na->last_usermask = sstrdup(u->nick);
120  if (reason)
121  na->last_realname = sstrdup(reason);
122 
123  na->u = finduser(na->nick);
124  if (na->u)
125  na->u->na = na;
126 
127  if (na->u) {
128  notice_lang(s_NickServ, na->u, FORCENICKCHANGE_NOW);
129  collide(na, 0);
130  }
131 
132 
133  if (ircd->sqline) {
134  anope_cmd_sqline(na->nick, ((reason) ? reason : "Forbidden"));
135  }
136 
137  if (WallForbid)
138  anope_cmd_global(s_NickServ, "\2%s\2 used FORBID on \2%s\2",
139  u->nick, nick);
140 
141  alog("%s: %s set FORBID for nick %s", s_NickServ, u->nick, nick);
142  notice_lang(s_NickServ, u, NICK_FORBID_SUCCEEDED, nick);
144  } else {
145  alog("%s: Valid FORBID for %s by %s failed", s_NickServ, nick,
146  u->nick);
147  notice_lang(s_NickServ, u, NICK_FORBID_FAILED, nick);
148  }
149  return MOD_CONT;
150 }
151 
152 NickAlias *makenick(const char *nick)
153 {
154  NickAlias *na;
155  NickCore *nc;
156 
157  /* First make the core */
158  nc = scalloc(1, sizeof(NickCore));
159  nc->display = sstrdup(nick);
160  slist_init(&nc->aliases);
161  insert_core(nc);
162  alog("%s: group %s has been created", s_NickServ, nc->display);
163 
164  /* Then make the alias */
165  na = scalloc(1, sizeof(NickAlias));
166  na->nick = sstrdup(nick);
167  na->nc = nc;
168  slist_add(&nc->aliases, na);
169  alpha_insert_alias(na);
170  return na;
171 }
E int nick_is_services_admin(NickCore *nc)
Definition: operserv.c:636
static int do_forbid(User *u)
Definition: ns_forbid.c:71
E int readonly
Definition: extern.h:776
E void insert_core(NickCore *nc)
Definition: nickserv.c:1370
char nick[NICKMAX]
Definition: services.h:875
E NickAlias * findnick(const char *nick)
Definition: db-merger.c:1857
E IRCDVar * ircd
Definition: extern.h:39
E void send_event(const char *name, int argc,...)
Definition: events.c:37
E int delnick(NickAlias *na)
Definition: nickserv.c:1586
#define EVENT_NICK_FORBIDDEN
Definition: events.h:46
E int WallForbid
Definition: extern.h:467
E int NSSecureAdmins
Definition: extern.h:394
#define NS_VERBOTEN
Definition: services.h:1273
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
NickAlias * makenick(const char *nick)
Definition: ns_forbid.c:152
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
E void alpha_insert_alias(NickAlias *na)
Definition: nickserv.c:1338
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 void * scalloc(long elsize, long els)
Definition: memory.c:55
int AnopeInit(int argc, char **argv)
Definition: ns_forbid.c:27
char * display
Definition: services.h:542
E int is_services_root(User *u)
Definition: operserv.c:577
void AnopeFini(void)
Definition: ns_forbid.c:48
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 anope_cmd_sqline(char *mask, char *reason)
Definition: ircd.c:524
E void alog(const char *fmt,...) FORMAT(printf
int sqline
Definition: services.h:314
#define MOD_CONT
Definition: modules.h:54
E int is_services_admin(User *u)
Definition: operserv.c:591
char * nick
Definition: services.h:526
char * last_realname
Definition: services.h:528
MDE void moduleSetNickHelp(void(*func)(User *u))
Definition: modules.c:2078
static void myNickServHelp(User *u)
Definition: ns_forbid.c:59
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
#define NICKMAX
Definition: config.h:62
SList aliases
Definition: services.h:559
E void slist_init(SList *slist)
Definition: slist.c:302
E int ForceForbidReason
Definition: extern.h:351
E int slist_add(SList *slist, void *item)
Definition: slist.c:29
User * u
Definition: services.h:536
E char * s_NickServ
Definition: extern.h:284
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define isvalidnick(c)
Definition: services.h:1407
char * last_usermask
Definition: services.h:529
E int anope_valid_nick(char *nick)
Definition: ircd.c:661
#define EVENT_NICK_DROPPED
Definition: events.h:45
#define NICKSERV
Definition: modules.h:59
NickAlias * na
Definition: services.h:892
#define MOD_UNIQUE
Definition: module.h:11
E void anope_cmd_global(char *source, const char *fmt,...)
Definition: ircd.c:506