ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/sendpass.C
Revision: 1.8
Committed: Sun Sep 16 18:54:43 2007 UTC (19 years ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.7: +10 -5 lines
Log Message:
#defines to enum

File Contents

# User Rev Content
1 pippijn 1.8 /**
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 pippijn 1.4 * Copyright © 2005 William Pitcock, et al.
10 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
11 pippijn 1.1 *
12 pippijn 1.8 * $Id: sendpass.C,v 1.7 2007-09-05 11:23:13 pippijn Exp $
13 pippijn 1.1 */
14    
15     #include "atheme.h"
16 pippijn 1.4 #include <ermyth/crypto.h>
17     #include <ermyth/module.h>
18 pippijn 1.1 #include <account/myuser.h>
19    
20 pippijn 1.8 static char const rcsid[] = "$Id: sendpass.C,v 1.7 2007-09-05 11:23:13 pippijn Exp $";
21 pippijn 1.1
22 pippijn 1.4 REGISTER_MODULE ("nickserv/sendpass", false, "The Ermyth Team <http://ermyth.schmorp.de>");
23 pippijn 1.1
24     static void ns_cmd_sendpass (sourceinfo_t *si, int parc, char *parv[]);
25    
26 pippijn 1.4 command_t const ns_sendpass = { "SENDPASS", N_("Email registration passwords."), PRIV_USER_SENDPASS, 1, ns_cmd_sendpass };
27 pippijn 1.1
28 pippijn 1.4 E cmdvec ns_cmdtree;
29     E helpvec ns_helptree;
30 pippijn 1.1
31 pippijn 1.4 bool
32     _modinit (module *m)
33 pippijn 1.1 {
34     ns_cmdtree << ns_sendpass;
35     help_addentry (ns_helptree, "SENDPASS", "help/nickserv/sendpass", NULL);
36 pippijn 1.4
37     return true;
38 pippijn 1.1 }
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 pippijn 1.7 metadata *md;
55 pippijn 1.1
56     if (!name)
57     {
58 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "SENDPASS");
59     command_fail (si, fault::needmoreparams, _("Syntax: SENDPASS <nickname>"));
60 pippijn 1.1 return;
61     }
62    
63 pippijn 1.5 if (!(mu = myuser_t::find (name)))
64 pippijn 1.1 {
65 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), name);
66 pippijn 1.1 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 pippijn 1.6 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 pippijn 1.1 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 pippijn 1.6 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 pippijn 1.1 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 pippijn 1.4 mu->add_metadata ("private:setpass:key", crypter->crypt (key, crypto::gen_salt ()));
98 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::emailfail, _("Email send failed."));
104 pippijn 1.4 sfree (key);
105 pippijn 1.1 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 pippijn 1.4 mu->set_password (newpass);
114 pippijn 1.1 }
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 pippijn 1.6 command_fail (si, fault::emailfail, _("Email send failed."));
124 pippijn 1.1
125     if (newpass != NULL)
126 pippijn 1.4 sfree (newpass);
127 pippijn 1.1
128     return;
129     }