ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/verify.C
Revision: 1.6
Committed: Thu Aug 30 19:56:24 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +21 -21 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 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 VERIFY function.
6     *
7 pippijn 1.6 * $Id: verify.C,v 1.5 2007-08-28 22:18:31 pippijn Exp $
8 pippijn 1.1 */
9    
10     #include "atheme.h"
11 pippijn 1.4 #include <ermyth/module.h>
12 pippijn 1.1 #include <account/myuser.h>
13    
14 pippijn 1.6 static char const rcsid[] = "$Id: verify.C,v 1.5 2007-08-28 22:18:31 pippijn Exp $";
15 pippijn 1.1
16 pippijn 1.4 REGISTER_MODULE ("nickserv/verify", false, "The Ermyth Team <http://ermyth.schmorp.de>");
17 pippijn 1.1
18     static void ns_cmd_verify (sourceinfo_t *si, int parc, char *parv[]);
19     static void ns_cmd_fverify (sourceinfo_t *si, int parc, char *parv[]);
20    
21 pippijn 1.4 command_t const ns_verify = { "VERIFY", N_("Verifies a nickname registration."), AC_NONE, 3, ns_cmd_verify };
22     command_t const ns_fverify = { "FVERIFY", N_("Forcefully verifies a nickname registration."), PRIV_USER_ADMIN, 2, ns_cmd_fverify };
23 pippijn 1.1
24 pippijn 1.4 E cmdvec ns_cmdtree;
25     E helpvec ns_helptree;
26 pippijn 1.1
27 pippijn 1.4 bool
28     _modinit (module *m)
29 pippijn 1.1 {
30     ns_cmdtree << ns_verify;
31     help_addentry (ns_helptree, "VERIFY", "help/nickserv/verify", NULL);
32     ns_cmdtree << ns_fverify;
33     help_addentry (ns_helptree, "FVERIFY", "help/nickserv/fverify", NULL);
34 pippijn 1.4
35     return true;
36 pippijn 1.1 }
37    
38     void
39     _moddeinit ()
40     {
41     ns_cmdtree >> ns_verify;
42     help_delentry (ns_helptree, "VERIFY");
43     ns_cmdtree >> ns_fverify;
44     help_delentry (ns_helptree, "FVERIFY");
45     }
46    
47     static void
48     ns_cmd_verify (sourceinfo_t *si, int parc, char *parv[])
49     {
50     myuser_t *mu;
51 pippijn 1.6 metadata::item *md;
52 pippijn 1.1 char *op = parv[0];
53     char *nick = parv[1];
54     char *key = parv[2];
55     myuser_t::login_vector::iterator it, it_end;
56    
57     if (!op || !nick || !key)
58     {
59 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "VERIFY");
60     command_fail (si, fault::needmoreparams, _("Syntax: VERIFY <operation> <nickname> <key>"));
61 pippijn 1.1 return;
62     }
63    
64 pippijn 1.5 if (!(mu = myuser_t::find (nick)))
65 pippijn 1.1 {
66 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), nick);
67 pippijn 1.1 return;
68     }
69    
70     /* forcing users to log in before we verify
71     * prevents some information leaks
72     */
73     if (!(si->smu == mu))
74     {
75 pippijn 1.6 command_fail (si, fault::badparams, _("Please log in before attempting to verify your registration."));
76 pippijn 1.1 return;
77     }
78    
79     if (!strcasecmp (op, "REGISTER"))
80     {
81     if (!(mu->flags & MU_WAITAUTH) || !(md = mu->find_metadata ("private:verify:register:key")))
82     {
83 pippijn 1.6 command_fail (si, fault::badparams, _("\2%s\2 is not awaiting authorization."), nick);
84 pippijn 1.1 return;
85     }
86    
87     if (!strcasecmp (key, md->value))
88     {
89     mu->flags &= ~MU_WAITAUTH;
90    
91     snoop ("REGISTER:VS: \2%s\2 by \2%s\2", mu->email, get_source_name (si));
92     logcommand (si, CMDLOG_SET, "VERIFY REGISTER (email: %s)", mu->email);
93    
94     mu->del_metadata ("private:verify:register:key");
95     mu->del_metadata ("private:verify:register:timestamp");
96    
97     command_success_nodata (si, _("\2%s\2 has now been verified."), mu->name);
98     command_success_nodata (si, _("Thank you for verifying your e-mail address! You have taken steps in ensuring that your registrations are not exploited."));
99     for (it = mu->logins.begin (), it_end = mu->logins.end (); it != it_end; ++it)
100 pippijn 1.4 phandler->ircd_on_login ((*it)->nick, mu->name, NULL);
101 pippijn 1.1
102     return;
103     }
104    
105     snoop ("REGISTER:VF: \2%s\2 by \2%s\2", mu->email, get_source_name (si));
106     logcommand (si, CMDLOG_SET, "failed VERIFY REGISTER (invalid key)");
107 pippijn 1.6 command_fail (si, fault::badparams, _("Verification failed. Invalid key for \2%s\2."), mu->name);
108 pippijn 1.1
109     return;
110     }
111     else if (!strcasecmp (op, "EMAILCHG"))
112     {
113     if (!(md = mu->find_metadata ("private:verify:emailchg:key")))
114     {
115 pippijn 1.6 command_fail (si, fault::badparams, _("\2%s\2 is not awaiting authorization."), nick);
116 pippijn 1.1 return;
117     }
118    
119     if (!strcasecmp (key, md->value))
120     {
121     md = mu->find_metadata ("private:verify:emailchg:newemail");
122    
123     strlcpy (mu->email, md->value, EMAILLEN);
124    
125     snoop ("SET:EMAIL:VS: \2%s\2 by \2%s\2", mu->email, get_source_name (si));
126     logcommand (si, CMDLOG_SET, "VERIFY EMAILCHG (email: %s)", mu->email);
127    
128     mu->del_metadata ("private:verify:emailchg:key");
129     mu->del_metadata ("private:verify:emailchg:newemail");
130     mu->del_metadata ("private:verify:emailchg:timestamp");
131    
132     command_success_nodata (si, _("\2%s\2 has now been verified."), mu->email);
133    
134     return;
135     }
136    
137     snoop ("REGISTER:VF: \2%s\2 by \2%s\2", mu->email, get_source_name (si));
138     logcommand (si, CMDLOG_SET, "failed VERIFY EMAILCHG (invalid key)");
139 pippijn 1.6 command_fail (si, fault::badparams, _("Verification failed. Invalid key for \2%s\2."), mu->name);
140 pippijn 1.1
141     return;
142     }
143     else
144     {
145 pippijn 1.6 command_fail (si, fault::badparams, _("Invalid operation specified for \2VERIFY\2."));
146     command_fail (si, fault::badparams, _("Please double-check your verification e-mail."));
147 pippijn 1.1 return;
148     }
149     }
150    
151     static void
152     ns_cmd_fverify (sourceinfo_t *si, int parc, char *parv[])
153     {
154     myuser_t *mu;
155 pippijn 1.6 metadata::item *md;
156 pippijn 1.1 char *op = parv[0];
157     char *nick = parv[1];
158     myuser_t::login_vector::iterator it, it_end;
159    
160     if (!op || !nick)
161     {
162 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "FVERIFY");
163     command_fail (si, fault::needmoreparams, _("Syntax: FVERIFY <operation> <nickname>"));
164 pippijn 1.1 return;
165     }
166    
167 pippijn 1.5 if (!(mu = myuser_t::find (nick)))
168 pippijn 1.1 {
169 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), nick);
170 pippijn 1.1 return;
171     }
172    
173     if (!strcasecmp (op, "REGISTER"))
174     {
175     if (!(mu->flags & MU_WAITAUTH) || !(md = mu->find_metadata ("private:verify:register:key")))
176     {
177 pippijn 1.6 command_fail (si, fault::badparams, _("\2%s\2 is not awaiting authorization."), nick);
178 pippijn 1.1 return;
179     }
180    
181     mu->flags &= ~MU_WAITAUTH;
182    
183     snoop ("REGISTER:VS: \2%s\2 for \2%s\2 by \2%s\2", mu->email, mu->name, get_source_name (si));
184     logcommand (si, CMDLOG_REGISTER, "FVERIFY REGISTER %s (email: %s)", mu->name, mu->email);
185    
186     mu->del_metadata ("private:verify:register:key");
187     mu->del_metadata ("private:verify:register:timestamp");
188    
189     command_success_nodata (si, _("\2%s\2 has now been verified."), mu->name);
190     for (it = mu->logins.begin (), it_end = mu->logins.end (); it != it_end; ++it)
191 pippijn 1.4 phandler->ircd_on_login ((*it)->nick, mu->name, NULL);
192 pippijn 1.1
193     return;
194     }
195     else if (!strcasecmp (op, "EMAILCHG"))
196     {
197     if (!(md = mu->find_metadata ("private:verify:emailchg:key")))
198     {
199 pippijn 1.6 command_fail (si, fault::badparams, _("\2%s\2 is not awaiting authorization."), nick);
200 pippijn 1.1 return;
201     }
202    
203     md = mu->find_metadata ("private:verify:emailchg:newemail");
204    
205     strlcpy (mu->email, md->value, EMAILLEN);
206    
207     snoop ("SET:EMAIL:VS: \2%s\2 for \2%s\2 by \2%s\2", mu->email, mu->name, get_source_name (si));
208     logcommand (si, CMDLOG_REGISTER, "FVERIFY EMAILCHG %s (email: %s)", mu->name, mu->email);
209    
210     mu->del_metadata ("private:verify:emailchg:key");
211     mu->del_metadata ("private:verify:emailchg:newemail");
212     mu->del_metadata ("private:verify:emailchg:timestamp");
213    
214     command_success_nodata (si, _("\2%s\2 has now been verified."), mu->email);
215    
216     return;
217     }
218     else
219     {
220 pippijn 1.6 command_fail (si, fault::badparams, _("Invalid operation specified for \2FVERIFY\2."));
221     command_fail (si, fault::badparams, _("Valid operations are REGISTER and EMAILCHG."));
222 pippijn 1.1 return;
223     }
224     }