Anope IRC Services  Version 1.8
cs_identify.c
Go to the documentation of this file.
1 /* ChanServ 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_identify(User * u);
18 static void myChanServHelp(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("IDENTIFY", do_identify, NULL, CHAN_HELP_IDENTIFY,
35  -1, -1, -1, -1);
37 
38  c = createCommand("ID", do_identify, NULL, CHAN_HELP_IDENTIFY, -1, -1,
39  -1, -1);
41 
43 
44  return MOD_CONT;
45 }
46 
50 void AnopeFini(void)
51 {
52 
53 }
54 
55 
56 
61 static void myChanServHelp(User * u)
62 {
63  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_IDENTIFY);
64 }
65 
71 static int do_identify(User * u)
72 {
73  char *chan = strtok(NULL, " ");
74  char *pass = strtok(NULL, " ");
75  ChannelInfo *ci;
76  struct u_chaninfolist *uc;
77 
78  if (!pass) {
79  syntax_error(s_ChanServ, u, "IDENTIFY", CHAN_IDENTIFY_SYNTAX);
80  } else if (!(ci = cs_findchan(chan))) {
81  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
82  } else if (ci->flags & CI_VERBOTEN) {
83  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
84  } else if (!nick_identified(u)) {
85  notice_lang(s_ChanServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ);
86  } else if (is_founder(u, ci)) {
87  notice_lang(s_ChanServ, u, NICK_ALREADY_IDENTIFIED);
88  } else {
89  int res;
90 
91  if ((res = enc_check_password(pass, ci->founderpass)) == 1) {
92  if (!is_identified(u, ci)) {
93  uc = scalloc(sizeof(*uc), 1);
94  uc->next = u->founder_chans;
95  if (u->founder_chans)
96  u->founder_chans->prev = uc;
97  u->founder_chans = uc;
98  uc->chan = ci;
99  alog("%s: %s!%s@%s identified for %s", s_ChanServ, u->nick,
100  u->username, u->host, ci->name);
101  }
102 
103  notice_lang(s_ChanServ, u, CHAN_IDENTIFY_SUCCEEDED, chan);
104  } else if (res < 0) {
105  alog("%s: check_password failed for %s", s_ChanServ, ci->name);
106  notice_lang(s_ChanServ, u, CHAN_IDENTIFY_FAILED);
107  } else {
108  alog("%s: Failed IDENTIFY for %s by %s!%s@%s",
109  s_ChanServ, ci->name, u->nick, u->username, u->host);
110  notice_lang(s_ChanServ, u, PASSWORD_INCORRECT);
111  bad_password(u);
112  }
113 
114  }
115  return MOD_CONT;
116 }
char nick[NICKMAX]
Definition: services.h:875
struct user_::u_chaninfolist * founder_chans
E int enc_check_password(const char *plaintext, const char *password)
Definition: encrypt.c:95
E int is_identified(User *user, ChannelInfo *ci)
Definition: chanserv.c:2295
E int nick_identified(User *u)
Definition: nickserv.c:1111
char founderpass[PASSMAX]
Definition: services.h:658
#define CI_VERBOTEN
Definition: services.h:725
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
char name[CHANMAX]
Definition: services.h:654
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
static void myChanServHelp(User *u)
Definition: cs_identify.c:61
E void bad_password(User *u)
Definition: actions.c:24
E void * scalloc(long elsize, long els)
Definition: memory.c:55
void AnopeFini(void)
Definition: cs_identify.c:50
uint32 flags
Definition: services.h:669
static int do_identify(User *u)
Definition: cs_identify.c:71
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
ChannelInfo * chan
Definition: services.h:906
MDE void moduleSetChanHelp(void(*func)(User *u))
Definition: modules.c:2090
int AnopeInit(int argc, char **argv)
Definition: cs_identify.c:26
Command * c
Definition: ns_recover.c:17
#define CHANSERV
Definition: modules.h:60
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
E int is_founder(User *user, ChannelInfo *ci)
Definition: chanserv.c:2255
char * username
Definition: services.h:877
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
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
E char * s_ChanServ
Definition: extern.h:285
struct u_chaninfolist * prev
Definition: services.h:905
E char * s_NickServ
Definition: extern.h:284
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define MOD_UNIQUE
Definition: module.h:11