Anope IRC Services  Version 1.8
ns_ghost.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_ghost(User * u);
18 static void myNickServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
31  moduleAddVersion(VERSION_STRING);
33 
34  c = createCommand("GHOST", do_ghost, NULL, NICK_HELP_GHOST, -1, -1, -1,
35  -1);
37 
39 
40  return MOD_CONT;
41 }
42 
46 void AnopeFini(void)
47 {
48 
49 }
50 
51 
52 
57 static void myNickServHelp(User * u)
58 {
59  notice_lang(s_NickServ, u, NICK_HELP_CMD_GHOST);
60 }
61 
67 static int do_ghost(User * u)
68 {
69  char *nick = strtok(NULL, " ");
70  char *pass = strtok(NULL, " ");
71  NickAlias *na;
72  User *u2;
73 
74  if (!nick) {
75  syntax_error(s_NickServ, u, "GHOST", NICK_GHOST_SYNTAX);
76  } else if (!(u2 = finduser(nick))) {
77  notice_lang(s_NickServ, u, NICK_X_NOT_IN_USE, nick);
78  } else if (!(na = u2->na)) {
79  notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
80  } else if (na->status & NS_VERBOTEN) {
81  notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
82  } else if (na->nc->flags & NI_SUSPENDED) {
83  notice_lang(s_NickServ, u, NICK_X_SUSPENDED, na->nick);
84  } else if (stricmp(nick, u->nick) == 0) {
85  notice_lang(s_NickServ, u, NICK_NO_GHOST_SELF);
86  } else if (pass) {
87  int res = enc_check_password(pass, na->nc->pass);
88  if (res == 1) {
89  char buf[NICKMAX + 32];
90  snprintf(buf, sizeof(buf), "GHOST command used by %s",
91  u->nick);
92 
94  alog("%s: %s!%s@%s used GHOST on %s",
95  s_NickServ, u->nick, u->username, u->host, u2->nick);
96  kill_user(s_NickServ, nick, buf);
97  notice_lang(s_NickServ, u, NICK_GHOST_KILLED, nick);
99  } else {
100  notice_lang(s_NickServ, u, ACCESS_DENIED);
101  if (res == 0) {
102  alog("%s: GHOST: invalid password for %s by %s!%s@%s",
103  s_NickServ, nick, u->nick, u->username, u->host);
104  bad_password(u);
105  }
106  }
107  } else {
108  if (group_identified(u, na->nc)
109  || (!(na->nc->flags & NI_SECURE) && is_on_access(u, na->nc))) {
110  char buf[NICKMAX + 32];
111  snprintf(buf, sizeof(buf), "GHOST command used by %s",
112  u->nick);
113 
115  alog("%s: %s!%s@%s used GHOST on %s",
116  s_NickServ, u->nick, u->username, u->host, u2->nick);
117  kill_user(s_NickServ, nick, buf);
118  notice_lang(s_NickServ, u, NICK_GHOST_KILLED, nick);
120  } else {
121  notice_lang(s_NickServ, u, ACCESS_DENIED);
122  }
123  }
124 
125  return MOD_CONT;
126 }
#define EVENT_NICK_GHOSTED
Definition: events.h:52
E int is_on_access(User *u, NickCore *nc)
Definition: nickserv.c:1289
char nick[NICKMAX]
Definition: services.h:875
E int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: compat.c:37
#define EVENT_STOP
Definition: events.h:15
#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
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
E void kill_user(char *source, char *user, char *reason)
Definition: actions.c:51
NickCore * nc
Definition: services.h:533
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
#define EVENT_START
Definition: events.h:14
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
static int do_ghost(User *u)
Definition: ns_ghost.c:67
void AnopeFini(void)
Definition: ns_ghost.c:46
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
char pass[PASSMAX]
Definition: services.h:543
int AnopeInit(int argc, char **argv)
Definition: ns_ghost.c:26
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
static void myNickServHelp(User *u)
Definition: ns_ghost.c:57
#define NICKSERV
Definition: modules.h:59
NickAlias * na
Definition: services.h:892
#define MOD_UNIQUE
Definition: module.h:11