Anope IRC Services  Version 1.8
ns_identify.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 #define TO_COLLIDE 0 /* Collide the user with this nick */
18 #define TO_RELEASE 1 /* Release a collided nick */
19 
20 static int do_identify(User * u);
21 static void myNickServHelp(User * u);
22 
29 int AnopeInit(int argc, char **argv)
30 {
31  Command *c;
32 
33  moduleAddAuthor("Anope");
34  moduleAddVersion(VERSION_STRING);
36 
37  c = createCommand("ID", do_identify, NULL, NICK_HELP_IDENTIFY, -1, -1,
38  -1, -1);
40  c = createCommand("IDENTIFY", do_identify, NULL, NICK_HELP_IDENTIFY,
41  -1, -1, -1, -1);
43  c = createCommand("SIDENTIFY", do_identify, NULL, -1, -1, -1, -1, -1);
45 
46 
48 
49  return MOD_CONT;
50 }
51 
55 void AnopeFini(void)
56 {
57 
58 }
59 
64 static void myNickServHelp(User * u)
65 {
66  notice_lang(s_NickServ, u, NICK_HELP_CMD_IDENTIFY);
67 }
68 
74 static int do_identify(User * u)
75 {
76  char *pass = strtok(NULL, " ");
77  NickAlias *na;
78  NickRequest *nr;
79  int res;
80  char tsbuf[16];
81  char modes[512];
82  int len;
83 
84  if (!pass) {
85  syntax_error(s_NickServ, u, "IDENTIFY", NICK_IDENTIFY_SYNTAX);
86  } else if (!(na = u->na)) {
87  if ((nr = findrequestnick(u->nick))) {
88  notice_lang(s_NickServ, u, NICK_IS_PREREG);
89  } else {
90  notice_lang(s_NickServ, u, NICK_NOT_REGISTERED);
91  }
92  } else if (na->status & NS_VERBOTEN) {
93  notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
94  } else if (na->nc->flags & NI_SUSPENDED) {
95  notice_lang(s_NickServ, u, NICK_X_SUSPENDED, na->nick);
96  } else if (nick_identified(u)) {
97  notice_lang(s_NickServ, u, NICK_ALREADY_IDENTIFIED);
98  } else if (!(res = enc_check_password(pass, na->nc->pass))) {
99  alog("%s: Failed IDENTIFY for %s!%s@%s", s_NickServ, u->nick,
100  u->username, u->host);
101  notice_lang(s_NickServ, u, PASSWORD_INCORRECT);
102  bad_password(u);
103  } else if (res == -1) {
104  notice_lang(s_NickServ, u, NICK_IDENTIFY_FAILED);
105  } else {
106  if (!(na->status & NS_IDENTIFIED) && !(na->status & NS_RECOGNIZED)) {
107  if (na->last_usermask)
108  free(na->last_usermask);
109  na->last_usermask =
110  scalloc(strlen(common_get_vident(u)) +
111  strlen(common_get_vhost(u)) + 2, 1);
112  sprintf(na->last_usermask, "%s@%s", common_get_vident(u),
113  common_get_vhost(u));
114  if (na->last_realname)
115  free(na->last_realname);
116  na->last_realname = sstrdup(u->realname);
117  }
118 
119  na->status |= NS_IDENTIFIED;
120  na->last_seen = time(NULL);
121  snprintf(tsbuf, sizeof(tsbuf), "%lu",
122  (unsigned long int) u->timestamp);
123 
124  if (ircd->modeonreg) {
125  len = strlen(ircd->modeonreg);
126  strncpy(modes,ircd->modeonreg,512);
127  if(ircd->rootmodeonid && is_services_root(u)) {
128  strncat(modes,ircd->rootmodeonid,512-len);
129  } else if(ircd->adminmodeonid && is_services_admin(u)) {
130  strncat(modes,ircd->adminmodeonid,512-len);
131  } else if(ircd->opermodeonid && is_services_oper(u)) {
132  strncat(modes,ircd->opermodeonid,512-len);
133  }
134  if (ircd->tsonmode) {
135  common_svsmode(u, modes, tsbuf);
136  } else {
137  common_svsmode(u, modes, "");
138  }
139  }
141  alog("%s: %s!%s@%s identified for nick %s", s_NickServ, u->nick,
142  u->username, u->host, u->nick);
143  notice_lang(s_NickServ, u, NICK_IDENTIFY_SUCCEEDED);
144  if (ircd->vhost) {
145  do_on_id(u);
146  }
147  if (NSModeOnID) {
148  do_setmodes(u);
149  }
150 
151  if (NSForceEmail && u->na && !u->na->nc->email) {
152  notice_lang(s_NickServ, u, NICK_IDENTIFY_EMAIL_REQUIRED);
153  notice_help(s_NickServ, u, NICK_IDENTIFY_EMAIL_HOWTO);
154  }
155 
156  if (!(na->status & NS_RECOGNIZED))
157  check_memos(u);
158 
159  /* Enable nick tracking if enabled */
160  if (NSNickTracking)
162 
163  /* Clear any timers */
164  if (na->nc->flags & NI_KILLPROTECT) {
166  }
167 
168  }
169  return MOD_CONT;
170 }
#define EVENT_NICK_IDENTIFY
Definition: events.h:55
char nick[NICKMAX]
Definition: services.h:875
E int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: compat.c:37
char * adminmodeonid
Definition: services.h:309
#define NI_SUSPENDED
Definition: services.h:1308
E IRCDVar * ircd
Definition: extern.h:39
E int enc_check_password(const char *plaintext, const char *password)
Definition: encrypt.c:95
E int nick_identified(User *u)
Definition: nickserv.c:1111
E void send_event(const char *name, int argc,...)
Definition: events.c:37
E void del_ns_timeout(NickAlias *na, int type)
Definition: nickserv.c:1831
E int NSNickTracking
Definition: extern.h:399
char * opermodeonid
Definition: services.h:310
int vhost
Definition: services.h:301
void AnopeFini(void)
Definition: ns_identify.c:55
int AnopeInit(int argc, char **argv)
Definition: ns_identify.c:29
#define NS_RECOGNIZED
Definition: services.h:1276
E int NSModeOnID
Definition: extern.h:397
#define NS_VERBOTEN
Definition: services.h:1273
char * host
Definition: services.h:878
char * modeonreg
Definition: services.h:307
E void check_memos(User *u)
Definition: memoserv.c:86
#define NI_KILLPROTECT
Definition: services.h:1290
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 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
E int is_services_root(User *u)
Definition: operserv.c:577
E NickRequest * findrequestnick(const char *nick)
Definition: nickserv.c:1218
static void myNickServHelp(User *u)
Definition: ns_identify.c:64
E int do_setmodes(User *u)
Definition: nickserv.c:1940
uint16 status
Definition: services.h:532
E int do_on_id(User *u)
Definition: hostserv.c:582
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
E void notice_help(char *source, User *dest, int message,...)
Definition: send.c:220
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
E int is_services_admin(User *u)
Definition: operserv.c:591
#define TO_COLLIDE
Definition: ns_identify.c:17
char * nick
Definition: services.h:526
char * username
Definition: services.h:877
char * last_realname
Definition: services.h:528
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
int tsonmode
Definition: services.h:339
char pass[PASSMAX]
Definition: services.h:543
#define NS_IDENTIFIED
Definition: services.h:1275
E int is_services_oper(User *u)
Definition: operserv.c:606
static int do_identify(User *u)
Definition: ns_identify.c:74
uint32 flags
Definition: services.h:548
E void common_svsmode(User *u, char *modes, char *arg)
Definition: actions.c:228
time_t last_seen
Definition: services.h:531
E char * s_NickServ
Definition: extern.h:284
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
char * last_usermask
Definition: services.h:529
time_t timestamp
Definition: services.h:886
E int NSForceEmail
Definition: extern.h:383
char * rootmodeonid
Definition: services.h:308
E char * common_get_vhost(User *u)
Definition: actions.c:251
#define NICKSERV
Definition: modules.h:59
char * realname
Definition: services.h:883
E char * common_get_vident(User *u)
Definition: actions.c:272
NickAlias * na
Definition: services.h:892
#define MOD_UNIQUE
Definition: module.h:11
char * email
Definition: services.h:544
E void nsStartNickTracking(User *u)
Definition: nickserv.c:1962