Anope IRC Services  Version 1.8
cs_sendpass.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_sendpass(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("SENDPASS", do_sendpass, NULL, CHAN_HELP_SENDPASS,
35  -1, -1, -1, -1);
37 
39 
40  if (UseMail) {
41  return MOD_CONT;
42  } else {
43  return MOD_STOP;
44  }
45 }
46 
50 void AnopeFini(void)
51 {
52 
53 }
54 
55 
56 
61 static void myChanServHelp(User * u)
62 {
63  if (!RestrictMail || is_services_oper(u))
64  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_SENDPASS);
65 }
66 
72 static int do_sendpass(User * u)
73 {
74 
75  char *chan = strtok(NULL, " ");
76  ChannelInfo *ci;
77  NickCore *founder;
78 
79  if (!chan) {
80  syntax_error(s_ChanServ, u, "SENDPASS", CHAN_SENDPASS_SYNTAX);
81  } else if (RestrictMail && !is_services_oper(u)) {
82  notice_lang(s_ChanServ, u, PERMISSION_DENIED);
83  } else if (!(ci = cs_findchan(chan)) || !(founder = ci->founder)) {
84  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
85  } else if (ci->flags & CI_VERBOTEN) {
86  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
87  } else {
88  char buf[BUFSIZE];
89  char tmp_pass[PASSMAX];
90  if(enc_decrypt(ci->founderpass,tmp_pass,PASSMAX - 1)==1) {
91  MailInfo *mail;
92 
93  snprintf(buf, sizeof(buf),
94  getstring2(founder, CHAN_SENDPASS_SUBJECT), ci->name);
95  mail = MailBegin(u, founder, buf, s_ChanServ);
96  if (!mail)
97  return MOD_CONT;
98 
99  fprintf(mail->pipe, "%s", getstring2(founder, CHAN_SENDPASS_HEAD));
100  fprintf(mail->pipe, "\n\n");
101  fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_LINE_1),
102  ci->name);
103  fprintf(mail->pipe, "\n\n");
104  fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_LINE_2),
105  tmp_pass);
106  fprintf(mail->pipe, "\n\n");
107  fprintf(mail->pipe, "%s", getstring2(founder, CHAN_SENDPASS_LINE_3));
108  fprintf(mail->pipe, "\n\n");
109  fprintf(mail->pipe, "%s", getstring2(founder, CHAN_SENDPASS_LINE_4));
110  fprintf(mail->pipe, "\n\n");
111  fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_LINE_5),
112  NetworkName);
113  fprintf(mail->pipe, "\n.\n");
114 
115  MailEnd(mail);
116 
117  alog("%s: %s!%s@%s used SENDPASS on %s", s_ChanServ, u->nick,
118  u->username, u->host, chan);
119  notice_lang(s_ChanServ, u, CHAN_SENDPASS_OK, chan);
120  } else {
121  notice_lang(s_ChanServ, u, CHAN_SENDPASS_UNAVAILABLE);
122  }
123  }
124  return MOD_CONT;
125 }
char nick[NICKMAX]
Definition: services.h:875
E int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: compat.c:37
char founderpass[PASSMAX]
Definition: services.h:658
E int UseMail
Definition: extern.h:369
#define CI_VERBOTEN
Definition: services.h:725
int AnopeInit(int argc, char **argv)
Definition: cs_sendpass.c:26
char * host
Definition: services.h:878
void AnopeFini(void)
Definition: cs_sendpass.c:50
#define getstring2(nc, index)
Definition: extern.h:733
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
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
struct smtp_message mail
Definition: smtp.h:125
#define MOD_STOP
Definition: modules.h:53
uint32 flags
Definition: services.h:669
FILE * pipe
Definition: services.h:1068
static void myChanServHelp(User *u)
Definition: cs_sendpass.c:61
#define PASSMAX
Definition: config.h:65
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
MDE void moduleSetChanHelp(void(*func)(User *u))
Definition: modules.c:2090
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 void MailEnd(MailInfo *mail)
Definition: mail.c:206
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
static int do_sendpass(User *u)
Definition: cs_sendpass.c:72
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
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_ChanServ
Definition: extern.h:285
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
NickCore * founder
Definition: services.h:655
#define BUFSIZE
Definition: config.h:47
#define MOD_UNIQUE
Definition: module.h:11