Anope IRC Services  Version 1.8
ns_drop.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_drop(User * u);
18 static int do_unlink(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("DROP", do_drop, NULL, -1, NICK_HELP_DROP, -1,
36  NICK_SERVADMIN_HELP_DROP, NICK_SERVADMIN_HELP_DROP);
38  c = createCommand("UNLINK", do_unlink, NULL, -1, -1, -1, -1, -1);
40 
42 
43  return MOD_CONT;
44 }
45 
49 void AnopeFini(void)
50 {
51 
52 }
53 
54 
55 
60 static void myNickServHelp(User * u)
61 {
62  notice_lang(s_NickServ, u, NICK_HELP_CMD_DROP);
63 }
64 
70 static int do_drop(User * u)
71 {
72  char *nick = strtok(NULL, " ");
73  NickAlias *na;
74  NickRequest *nr = NULL;
75  int is_servadmin = is_services_admin(u);
76  int is_mine; /* Does the nick being dropped belong to the user that is dropping? */
77  char *my_nick = NULL;
78 
79  if (readonly && !is_servadmin) {
80  notice_lang(s_NickServ, u, NICK_DROP_DISABLED);
81  return MOD_CONT;
82  }
83 
84  if (!(na = (nick ? findnick(nick) : u->na))) {
85  if (nick) {
86  if ((nr = findrequestnick(nick)) && is_servadmin) {
87  if (readonly)
88  notice_lang(s_NickServ, u, READ_ONLY_MODE);
89  if (WallDrop)
91  "\2%s\2 used DROP on \2%s\2", u->nick,
92  nick);
93  alog("%s: %s!%s@%s dropped nickname %s (e-mail: %s)",
94  s_NickServ, u->nick, u->username, u->host,
95  nr->nick, nr->email);
96  delnickrequest(nr);
97  notice_lang(s_NickServ, u, NICK_X_DROPPED, nick);
98  } else {
99  notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
100  }
101  } else
102  notice_lang(s_NickServ, u, NICK_NOT_REGISTERED);
103  return MOD_CONT;
104  }
105 
106  is_mine = (u->na && (u->na->nc == na->nc));
107  if (is_mine && !nick)
108  my_nick = sstrdup(na->nick);
109 
110  if (is_mine && !nick_identified(u)) {
111  notice_lang(s_NickServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ);
112  } else if (!is_mine && !is_servadmin) {
113  notice_lang(s_NickServ, u, ACCESS_DENIED);
114  } else if (NSSecureAdmins && !is_mine && nick_is_services_admin(na->nc)
115  && !is_services_root(u)) {
116  notice_lang(s_NickServ, u, PERMISSION_DENIED);
117  } else {
118  if (readonly)
119  notice_lang(s_NickServ, u, READ_ONLY_MODE);
120 
121  if (ircd->sqline && (na->status & NS_VERBOTEN)) {
123  }
124 
125  alog("%s: %s!%s@%s dropped nickname %s (group %s) (e-mail: %s)",
126  s_NickServ, u->nick, u->username, u->host,
127  na->nick, na->nc->display,
128  (na->nc->email ? na->nc->email : "none"));
129  delnick(na);
130  send_event(EVENT_NICK_DROPPED, 1, (my_nick ? my_nick : nick));
131 
132  if (!is_mine) {
133  if (WallDrop)
134  anope_cmd_global(s_NickServ, "\2%s\2 used DROP on \2%s\2",
135  u->nick, nick);
136  notice_lang(s_NickServ, u, NICK_X_DROPPED, nick);
137  } else {
138  if (nick)
139  notice_lang(s_NickServ, u, NICK_X_DROPPED, nick);
140  else
141  notice_lang(s_NickServ, u, NICK_DROPPED);
142  if (my_nick) {
143  free(my_nick);
144  }
145  }
146  }
147  return MOD_CONT;
148 }
149 
150 
151 static int do_unlink(User * u)
152 {
153  notice_lang(s_NickServ, u, OBSOLETE_COMMAND, "DROP");
154  return MOD_CONT;
155 }
char * email
Definition: services.h:519
E int nick_is_services_admin(NickCore *nc)
Definition: operserv.c:636
int AnopeInit(int argc, char **argv)
Definition: ns_drop.c:27
static void myNickServHelp(User *u)
Definition: ns_drop.c:60
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
void AnopeFini(void)
Definition: ns_drop.c:49
E IRCDVar * ircd
Definition: extern.h:39
E int nick_identified(User *u)
Definition: nickserv.c:1111
E void send_event(const char *name, int argc,...)
Definition: events.c:37
E int delnick(NickAlias *na)
Definition: nickserv.c:1586
E int delnickrequest(NickRequest *nr)
Definition: nickserv.c:1554
E int NSSecureAdmins
Definition: extern.h:394
#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 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
char * display
Definition: services.h:542
E int is_services_root(User *u)
Definition: operserv.c:577
int my_nick(char *source, int ac, char **av)
Definition: events.c:43
E NickRequest * findrequestnick(const char *nick)
Definition: nickserv.c:1218
E int WallDrop
Definition: extern.h:466
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
int sqline
Definition: services.h:314
static int do_drop(User *u)
Definition: ns_drop.c:70
E void anope_cmd_unsqline(char *user)
Definition: ircd.c:357
#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 * username
Definition: services.h:877
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
static int do_unlink(User *u)
Definition: ns_drop.c:151
char * nick
Definition: services.h:516
E char * s_NickServ
Definition: extern.h:284
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#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
char * email
Definition: services.h:544
E void anope_cmd_global(char *source, const char *fmt,...)
Definition: ircd.c:506