ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/setpass.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 © 2007 Atheme Development Group
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 NickServ SETPASS function.
6     *
7 pippijn 1.2 * $Id: setpass.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_setpass_listeners : callback::has_listeners
16     {
17     };
18    
19     ns_setpass_listeners listeners;
20    
21     DECLARE_MODULE_V1 ("nickserv/setpass", false, _modinit, _moddeinit, rcsid, "The Ermyth Team <http://ermyth.schmorp.de>");
22    
23     static void clear_setpass_key (void *vptr);
24     static void ns_cmd_setpass (sourceinfo_t *si, int parc, char *parv[]);
25    
26     command_t ns_setpass = { "SETPASS", N_("Changes a password using an authcode."), AC_NONE, 3, ns_cmd_setpass };
27    
28     cmdvec *ns_cmdtree;
29     helpvec *ns_helptree;
30    
31     void
32     _modinit (module_t *m)
33     {
34     MODULE_USE_SYMBOL_T (ns_cmdtree, cmdvec, "nickserv/main", "ns_cmdtree");
35     MODULE_USE_SYMBOL_T (ns_helptree, helpvec, "nickserv/main", "ns_helptree");
36    
37     hook_add_event ("user_identify");
38     hook_add_hook ("user_identify", clear_setpass_key);
39     ns_cmdtree << ns_setpass;
40     help_addentry (ns_helptree, "SETPASS", "help/nickserv/setpass", NULL);
41     }
42    
43     void
44     _moddeinit ()
45     {
46     hook_del_hook ("user_identify", clear_setpass_key);
47     ns_cmdtree >> ns_setpass;
48     help_delentry (ns_helptree, "SETPASS");
49     }
50    
51     static void
52     ns_cmd_setpass (sourceinfo_t *si, int parc, char *parv[])
53     {
54     myuser_t *mu;
55     metadata *md;
56     char *nick = parv[0];
57     char *key = parv[1];
58     char *password = parv[2];
59    
60     if (!nick || !key || !password)
61     {
62     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SETPASS");
63     command_fail (si, fault_needmoreparams, _("Syntax: SETPASS <account> <key> <newpass>"));
64     return;
65     }
66    
67     if (strchr (password, ' '))
68     {
69     command_fail (si, fault_badparams, STR_INVALID_PARAMS, "SETPASS");
70     command_fail (si, fault_badparams, _("Syntax: SETPASS <account> <key> <newpass>"));
71     return;
72     }
73    
74     if (!(mu = myuser_find (nick)))
75     {
76     command_fail (si, fault_nosuch_target, _("\2%s\2 is not registered."), nick);
77     return;
78     }
79    
80     if (strlen (password) > 32)
81     {
82     command_fail (si, fault_badparams, STR_INVALID_PARAMS, "SETPASS");
83     return;
84     }
85    
86     if (!strcasecmp (password, mu->name))
87     {
88     command_fail (si, fault_badparams, _("You cannot use your nickname as a password."));
89     command_fail (si, fault_badparams, _("Syntax: SETPASS <account> <key> <newpass>"));
90     return;
91     }
92    
93     md = mu->find_metadata ("private:setpass:key");
94     if (md != NULL && crypt_verify_password (key, md->value))
95     {
96     snoop ("SETPASS:VS: \2%s\2 by \2%s\2", mu->name, get_source_name (si));
97     logcommand (si, CMDLOG_SET, "SETPASS %s", mu->name);
98     set_password (mu, password);
99     mu->del_metadata ("private:setpass:key");
100    
101     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);
102    
103     return;
104     }
105    
106     if (md != NULL)
107     {
108     snoop ("SETPASS:VF: \2%s\2 by \2%s\2", mu->name, get_source_name (si));
109     logcommand (si, CMDLOG_SET, "failed SETPASS (invalid key)");
110     }
111     command_fail (si, fault_badparams, _("Verification failed. Invalid key for \2%s\2."), mu->name);
112    
113     return;
114     }
115    
116     static void
117     clear_setpass_key (void *vptr)
118     {
119     user_t *u = static_cast<user_t *> (vptr);
120     myuser_t *mu = u->myuser;
121     metadata *md;
122    
123     if (!(md = mu->find_metadata ("private:setpass:key")))
124     return;
125    
126     mu->del_metadata ("private:setpass:key");
127     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.");
128     }