ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/sendpass.C
Revision: 1.6
Committed: Thu Aug 30 19:56:23 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +10 -10 lines
Log Message:
- put faultcodes into their own namespace
- removed old files
- limited header garbage in atheme.h
- macros to inline bools for connection_t::is_*
- put some connection_t functions into the connection_t class

File Contents

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