ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/nickserv/verify.C
Revision: 1.9
Committed: Sat Sep 22 14:27:28 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +3 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

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