ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/nickserv/sendpass.C
Revision: 1.9
Committed: Sat Sep 22 14:27:28 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +3 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * sendpass.C: This file contains code for the ChanServ SENDPASS function.
3 *
4 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5 * Rights to this code are as documented in COPYING.
6 *
7 *
8 * Portions of this file were derived from sources bearing the following license:
9 * Copyright © 2005 William Pitcock, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: sendpass.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <ermyth/crypto.h>
17 #include <ermyth/module.h>
18 #include <account/myuser.h>
19
20 static char const rcsid[] = "$Id: sendpass.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $";
21
22 REGISTER_MODULE ("nickserv/sendpass", false, "The Ermyth Team <http://ermyth.xinutec.org>");
23
24 static void ns_cmd_sendpass (sourceinfo_t *si, int parc, char *parv[]);
25
26 command_t const ns_sendpass = { "SENDPASS", N_("Email registration passwords."), PRIV_USER_SENDPASS, 1, ns_cmd_sendpass };
27
28 E cmdvec ns_cmdtree;
29 E helpvec ns_helptree;
30
31 bool
32 _modinit (module *m)
33 {
34 ns_cmdtree << ns_sendpass;
35 help_addentry (ns_helptree, "SENDPASS", "help/nickserv/sendpass", NULL);
36
37 return true;
38 }
39
40 void
41 _moddeinit ()
42 {
43 ns_cmdtree >> ns_sendpass;
44 help_delentry (ns_helptree, "SENDPASS");
45 }
46
47 static void
48 ns_cmd_sendpass (sourceinfo_t *si, int parc, char *parv[])
49 {
50 myuser_t *mu;
51 char *name = parv[0];
52 char *newpass = NULL;
53 char *key;
54 metadata *md;
55
56 if (!name)
57 {
58 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "SENDPASS");
59 command_fail (si, fault::needmoreparams, _("Syntax: SENDPASS <nickname>"));
60 return;
61 }
62
63 if (!(mu = myuser_t::find (name)))
64 {
65 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), name);
66 return;
67 }
68
69 if (is_soper (mu) && !has_priv (si, PRIV_ADMIN))
70 {
71 logcommand (si, CMDLOG_ADMIN, "failed SENDPASS %s (is SOPER)", name);
72 command_fail (si, fault::badparams, _("\2%s\2 belongs to a services operator; you need %s privilege to send the password."), name, PRIV_ADMIN);
73 return;
74 }
75
76 if ((md = mu->find_metadata ("private:mark:setter")))
77 {
78 if (has_priv (si, PRIV_MARK))
79 {
80 command_success_nodata (si, _("Overriding MARK placed by %s on the nickname %s."), md->value, mu->name);
81 wallops ("%s sent the password for the \2MARKED\2 nickname %s.", get_oper_name (si), mu->name);
82 }
83 else
84 {
85 logcommand (si, CMDLOG_ADMIN, "failed SENDPASS %s (marked by %s)", mu->name, md->value);
86 command_fail (si, fault::badparams, _("This operation cannot be performed on %s, because the nickname has been marked by %s."), mu->name, md->value);
87 return;
88 }
89 }
90
91 /* alternative, safer method? */
92 if (si->service->cmdtree->find ("SETPASS"))
93 {
94 key = gen_pw (12);
95 if (sendemail (si->su != NULL ? si->su : si->service->me, EMAIL_SETPASS, mu, key))
96 {
97 mu->add_metadata ("private:setpass:key", crypter->crypt (key, crypto::gen_salt ()));
98 logcommand (si, CMDLOG_ADMIN, "SENDPASS %s (change key)", name);
99 snoop ("SENDPASS: \2%s\2 by \2%s\2", mu->name, get_oper_name (si));
100 command_success_nodata (si, _("The password change key for \2%s\2 has been sent to \2%s\2."), mu->name, mu->email);
101 }
102 else
103 command_fail (si, fault::emailfail, _("Email send failed."));
104 sfree (key);
105 return;
106 }
107
108 /* this is not without controversy... :) */
109 if (mu->flags & MU_CRYPTPASS)
110 {
111 command_success_nodata (si, _("The password for the nickname \2%s\2 is encrypted; a new password will be assigned and sent."), name);
112 newpass = gen_pw (12);
113 mu->set_password (newpass);
114 }
115
116 if (sendemail (si->su != NULL ? si->su : si->service->me, EMAIL_SENDPASS, mu, (newpass == NULL) ? mu->pass : newpass))
117 {
118 logcommand (si, CMDLOG_ADMIN, "SENDPASS %s", name);
119 snoop ("SENDPASS: \2%s\2 by \2%s\2", mu->name, get_oper_name (si));
120 command_success_nodata (si, _("The password for \2%s\2 has been sent to \2%s\2."), mu->name, mu->email);
121 }
122 else
123 command_fail (si, fault::emailfail, _("Email send failed."));
124
125 if (newpass != NULL)
126 sfree (newpass);
127
128 return;
129 }