Anope IRC Services  Version 1.8
ns_sendpass.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_sendpass(User * u);
18 
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("SENDPASS", do_sendpass, NULL, NICK_HELP_SENDPASS,
36  -1, -1, -1, -1);
38 
40  if (!UseMail) {
41  return MOD_STOP;
42  }
43 
44  return MOD_CONT;
45 }
46 
50 void AnopeFini(void)
51 {
52 
53 }
54 
59 static void myNickServHelp(User * u)
60 {
61  if (!RestrictMail || is_services_oper(u))
62  notice_lang(s_NickServ, u, NICK_HELP_CMD_SENDPASS);
63 }
64 
70 static int do_sendpass(User * u)
71 {
72 
73  char *nick = strtok(NULL, " ");
74  NickAlias *na;
75 
76  if (!nick) {
77  syntax_error(s_NickServ, u, "SENDPASS", NICK_SENDPASS_SYNTAX);
78  } else if (RestrictMail && !is_services_oper(u)) {
79  notice_lang(s_NickServ, u, PERMISSION_DENIED);
80  } else if (!(na = findnick(nick))) {
81  notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
82  } else if (na->status & NS_VERBOTEN) {
83  notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
84  } else {
85  char buf[BUFSIZE];
86  char tmp_pass[PASSMAX];
87  if(enc_decrypt(na->nc->pass,tmp_pass,PASSMAX - 1)==1) {
88  MailInfo *mail;
89 
90  snprintf(buf, sizeof(buf), getstring(na, NICK_SENDPASS_SUBJECT),
91  na->nick);
92  mail = MailBegin(u, na->nc, buf, s_NickServ);
93  if (!mail)
94  return MOD_CONT;
95 
96  fprintf(mail->pipe, "%s", getstring(na, NICK_SENDPASS_HEAD));
97  fprintf(mail->pipe, "\n\n");
98  fprintf(mail->pipe, getstring(na, NICK_SENDPASS_LINE_1), na->nick);
99  fprintf(mail->pipe, "\n\n");
100  fprintf(mail->pipe, getstring(na, NICK_SENDPASS_LINE_2),
101  tmp_pass);
102  fprintf(mail->pipe, "\n\n");
103  fprintf(mail->pipe, "%s", getstring(na, NICK_SENDPASS_LINE_3));
104  fprintf(mail->pipe, "\n\n");
105  fprintf(mail->pipe, "%s", getstring(na, NICK_SENDPASS_LINE_4));
106  fprintf(mail->pipe, "\n\n");
107  fprintf(mail->pipe, getstring(na, NICK_SENDPASS_LINE_5),
108  NetworkName);
109  fprintf(mail->pipe, "\n.\n");
110 
111  MailEnd(mail);
112 
113  alog("%s: %s!%s@%s used SENDPASS on %s", s_NickServ, u->nick,
114  u->username, u->host, nick);
115  notice_lang(s_NickServ, u, NICK_SENDPASS_OK, nick);
116  } else {
117  notice_lang(s_NickServ, u, NICK_SENDPASS_UNAVAILABLE);
118  }
119  }
120 
121  return MOD_CONT;
122 }
static int do_sendpass(User *u)
Definition: ns_sendpass.c:70
char nick[NICKMAX]
Definition: services.h:875
E int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: compat.c:37
E NickAlias * findnick(const char *nick)
Definition: db-merger.c:1857
E int UseMail
Definition: extern.h:369
#define NS_VERBOTEN
Definition: services.h:1273
#define getstring(na, index)
Definition: extern.h:731
char * host
Definition: services.h:878
E char * NetworkName
Definition: extern.h:281
E void E void E void E void E MailInfo * MailBegin(User *u, NickCore *nc, char *subject, char *service)
Definition: mail.c:93
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
NickCore * nc
Definition: services.h:533
void AnopeFini(void)
Definition: ns_sendpass.c:50
struct smtp_message mail
Definition: smtp.h:125
#define MOD_STOP
Definition: modules.h:53
static void myNickServHelp(User *u)
Definition: ns_sendpass.c:59
FILE * pipe
Definition: services.h:1068
#define PASSMAX
Definition: config.h:65
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
E void MailEnd(MailInfo *mail)
Definition: mail.c:206
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
char pass[PASSMAX]
Definition: services.h:543
E int is_services_oper(User *u)
Definition: operserv.c:606
E int RestrictMail
Definition: extern.h:372
E int enc_decrypt(const char *src, char *dest, int size)
Definition: encrypt.c:80
E char * s_NickServ
Definition: extern.h:284
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
int AnopeInit(int argc, char **argv)
Definition: ns_sendpass.c:27
#define BUFSIZE
Definition: config.h:47
#define NICKSERV
Definition: modules.h:59
#define MOD_UNIQUE
Definition: module.h:11