ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/setpass.C
Revision: 1.8
Committed: Sun Sep 16 18:54:43 2007 UTC (19 years, 1 month 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     * setpass.C: This file contains code for the NickServ SETPASS 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 © 2007 Atheme Development Group
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: setpass.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: setpass.C,v 1.7 2007-09-05 11:23:13 pippijn Exp $";
21 pippijn 1.1
22 pippijn 1.4 REGISTER_MODULE ("nickserv/setpass", false, "The Ermyth Team <http://ermyth.schmorp.de>");
23 pippijn 1.1
24     static void ns_cmd_setpass (sourceinfo_t *si, int parc, char *parv[]);
25    
26 pippijn 1.4 command_t const ns_setpass = { "SETPASS", N_("Changes a password using an authcode."), AC_NONE, 3, ns_cmd_setpass };
27 pippijn 1.1
28 pippijn 1.4 E cmdvec ns_cmdtree;
29     E helpvec ns_helptree;
30 pippijn 1.1
31     static void
32     ns_cmd_setpass (sourceinfo_t *si, int parc, char *parv[])
33     {
34     myuser_t *mu;
35 pippijn 1.7 metadata *md;
36 pippijn 1.1 char *nick = parv[0];
37     char *key = parv[1];
38     char *password = parv[2];
39    
40     if (!nick || !key || !password)
41     {
42 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "SETPASS");
43     command_fail (si, fault::needmoreparams, _("Syntax: SETPASS <account> <key> <newpass>"));
44 pippijn 1.1 return;
45     }
46    
47     if (strchr (password, ' '))
48     {
49 pippijn 1.6 command_fail (si, fault::badparams, STR_INVALID_PARAMS, "SETPASS");
50     command_fail (si, fault::badparams, _("Syntax: SETPASS <account> <key> <newpass>"));
51 pippijn 1.1 return;
52     }
53    
54 pippijn 1.5 if (!(mu = myuser_t::find (nick)))
55 pippijn 1.1 {
56 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), nick);
57 pippijn 1.1 return;
58     }
59    
60     if (strlen (password) > 32)
61     {
62 pippijn 1.6 command_fail (si, fault::badparams, STR_INVALID_PARAMS, "SETPASS");
63 pippijn 1.1 return;
64     }
65    
66     if (!strcasecmp (password, mu->name))
67     {
68 pippijn 1.6 command_fail (si, fault::badparams, _("You cannot use your nickname as a password."));
69     command_fail (si, fault::badparams, _("Syntax: SETPASS <account> <key> <newpass>"));
70 pippijn 1.1 return;
71     }
72    
73     md = mu->find_metadata ("private:setpass:key");
74 pippijn 1.4 if (md != NULL && crypto::verify_password (key, md->value))
75 pippijn 1.1 {
76     snoop ("SETPASS:VS: \2%s\2 by \2%s\2", mu->name, get_source_name (si));
77     logcommand (si, CMDLOG_SET, "SETPASS %s", mu->name);
78 pippijn 1.4 mu->set_password (password);
79 pippijn 1.1 mu->del_metadata ("private:setpass:key");
80    
81     command_success_nodata (si, _("The password for \2%s\2 has been changed to \2%s\2. Please write this down for future reference."), mu->name, password);
82    
83     return;
84     }
85    
86     if (md != NULL)
87     {
88     snoop ("SETPASS:VF: \2%s\2 by \2%s\2", mu->name, get_source_name (si));
89     logcommand (si, CMDLOG_SET, "failed SETPASS (invalid key)");
90     }
91 pippijn 1.6 command_fail (si, fault::badparams, _("Verification failed. Invalid key for \2%s\2."), mu->name);
92 pippijn 1.1
93     return;
94     }
95    
96     static void
97 pippijn 1.4 clear_setpass_key (user_t *u)
98 pippijn 1.1 {
99     myuser_t *mu = u->myuser;
100 pippijn 1.7 metadata *md;
101 pippijn 1.1
102     if (!(md = mu->find_metadata ("private:setpass:key")))
103     return;
104    
105     mu->del_metadata ("private:setpass:key");
106     notice (nicksvs.nick, u->nick, "Warning: SENDPASS had been used to mail you a password recovery " "key. Since you have identified, that key is no longer valid.");
107     }
108 pippijn 1.4
109     bool
110     _modinit (module *m)
111     {
112     user_t::callback.identify.attach (clear_setpass_key);
113     ns_cmdtree << ns_setpass;
114     help_addentry (ns_helptree, "SETPASS", "help/nickserv/setpass", NULL);
115    
116     return true;
117     }
118    
119     void
120     _moddeinit ()
121     {
122     user_t::callback.identify.detach (clear_setpass_key);
123     ns_cmdtree >> ns_setpass;
124     help_delentry (ns_helptree, "SETPASS");
125     }