ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/sendpass.C
Revision: 1.4
Committed: Tue Aug 28 17:08:10 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +18 -23 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

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.4 * $Id: sendpass.C,v 1.3 2007-07-21 13:23:20 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.4 static char const rcsid[] = "$Id: sendpass.C,v 1.3 2007-07-21 13:23:20 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     metadata *md;
50    
51     if (!name)
52     {
53     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SENDPASS");
54     command_fail (si, fault_needmoreparams, _("Syntax: SENDPASS <nickname>"));
55     return;
56     }
57    
58     if (!(mu = myuser_find (name)))
59     {
60     command_fail (si, fault_nosuch_target, _("\2%s\2 is not registered."), name);
61     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     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     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     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     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     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     command_fail (si, fault_emailfail, _("Email send failed."));
119    
120     if (newpass != NULL)
121 pippijn 1.4 sfree (newpass);
122 pippijn 1.1
123     return;
124     }