ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/sendpass.C
Revision: 1.2
Committed: Sat Jul 21 01:29:09 2007 UTC (19 years, 3 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.1: +2 -2 lines
Log Message:
- moved to new documentation system
- fixed small build error

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * 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     * This file contains code for the CService SENDPASS function.
6     *
7 pippijn 1.2 * $Id: sendpass.C,v 1.1 2007-07-19 08:24:54 pippijn Exp $
8 pippijn 1.1 */
9    
10     #include "atheme.h"
11     #include <account/myuser.h>
12    
13     static char const rcsid[] = "$Id";
14    
15     struct ns_sendpass_listeners : callback::has_listeners
16     {
17     };
18    
19     ns_sendpass_listeners listeners;
20    
21     DECLARE_MODULE_V1 ("nickserv/sendpass", false, _modinit, _moddeinit, rcsid, "The Ermyth Team <http://ermyth.schmorp.de>");
22    
23     static void ns_cmd_sendpass (sourceinfo_t *si, int parc, char *parv[]);
24    
25     command_t ns_sendpass = { "SENDPASS", N_("Email registration passwords."), PRIV_USER_SENDPASS, 1, ns_cmd_sendpass };
26    
27     cmdvec *ns_cmdtree;
28     helpvec *ns_helptree;
29    
30     void
31     _modinit (module_t *m)
32     {
33     MODULE_USE_SYMBOL_T (ns_cmdtree, cmdvec, "nickserv/main", "ns_cmdtree");
34     MODULE_USE_SYMBOL_T (ns_helptree, helpvec, "nickserv/main", "ns_helptree");
35    
36     ns_cmdtree << ns_sendpass;
37     help_addentry (ns_helptree, "SENDPASS", "help/nickserv/sendpass", NULL);
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_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", crypt_string (key, 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     free (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     set_password (mu, 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     free (newpass);
127    
128     return;
129     }