ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/register.C
Revision: 1.4
Committed: Tue Aug 28 17:08:10 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +45 -61 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

File Contents

# User Rev Content
1 pippijn 1.1 /*
2 pippijn 1.4 * 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 NickServ REGISTER function.
6     *
7 pippijn 1.4 * $Id: register.C,v 1.3 2007-07-21 13:23:20 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/mynick.h>
13     #include <account/myuser.h>
14 pippijn 1.4 #include <boost/foreach.hpp>
15 pippijn 1.1
16 pippijn 1.4 static char const rcsid[] = "$Id: register.C,v 1.3 2007-07-21 13:23:20 pippijn Exp $";
17 pippijn 1.1
18 pippijn 1.4 REGISTER_MODULE ("nickserv/register", false, "The Ermyth Team <http://ermyth.schmorp.de>");
19 pippijn 1.1
20     static void ns_cmd_register (sourceinfo_t *si, int parc, char *parv[]);
21    
22 pippijn 1.4 command_t const ns_register = { "REGISTER", N_("Registers a nickname."), AC_NONE, 3, ns_cmd_register };
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 static unsigned tcnt = 0;
28 pippijn 1.1
29     static void
30     ns_cmd_register (sourceinfo_t *si, int parc, char *parv[])
31     {
32     myuser_t *mu;
33 pippijn 1.4 myuser_t *tmu;
34 pippijn 1.1 mynick_t *mn;
35     char *account;
36     char *pass = parv[0];
37     char *email = parv[1];
38     char lau[BUFSIZE], lao[BUFSIZE];
39    
40     if (si->smu)
41     {
42     command_fail (si, fault_already_authed, _("You are already logged in."));
43     return;
44     }
45    
46     if (nicksvs.no_nick_ownership || si->su == NULL)
47     account = parv[0], pass = parv[1], email = parv[2];
48     else
49     account = si->su->nick, pass = parv[0], email = parv[1];
50    
51     if (!account || !pass || !email)
52     {
53     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "REGISTER");
54     if (nicksvs.no_nick_ownership || si->su == NULL)
55     command_fail (si, fault_needmoreparams, _("Syntax: REGISTER <account> <password> <email>"));
56     else
57     command_fail (si, fault_needmoreparams, _("Syntax: REGISTER <password> <email>"));
58     return;
59     }
60    
61     if ((strlen (pass) > 32) || (strlen (email) >= EMAILLEN))
62     {
63     command_fail (si, fault_badparams, STR_INVALID_PARAMS, "REGISTER");
64     return;
65     }
66    
67     if (!nicksvs.no_nick_ownership && si->su == NULL && user_find_named (account))
68     {
69     command_fail (si, fault_noprivs, _("A user matching this account is already on IRC."));
70     return;
71     }
72    
73     if (!nicksvs.no_nick_ownership && IsDigit (*account))
74     {
75     command_fail (si, fault_badparams, _("For security reasons, you can't register your UID."));
76     command_fail (si, fault_badparams, _("Please change to a real nickname, and try again."));
77     return;
78     }
79    
80     if (nicksvs.no_nick_ownership || si->su == NULL)
81     {
82     if (strchr (account, ' ') || strchr (account, '\n') || strchr (account, '\r') || account[0] == '=' || account[0] == '#' || account[0] == '@' || account[0] == '+' || account[0] == '%' || account[0] == '!' || strchr (account, ','))
83     {
84     command_fail (si, fault_badparams, _("The account name \2%s\2 is invalid."), account);
85     return;
86     }
87     }
88    
89     if ((si->su != NULL && !strcasecmp (pass, si->su->nick)) || !strcasecmp (pass, account))
90     {
91     command_fail (si, fault_badparams, _("You cannot use your nickname as a password."));
92     if (nicksvs.no_nick_ownership || si->su == NULL)
93     command_fail (si, fault_needmoreparams, _("Syntax: REGISTER <account> <password> <email>"));
94     else
95     command_fail (si, fault_needmoreparams, _("Syntax: REGISTER <password> <email>"));
96     return;
97     }
98    
99     if (!validemail (email))
100     {
101     command_fail (si, fault_badparams, _("\2%s\2 is not a valid email address."), email);
102     return;
103     }
104    
105     /* make sure it isn't registered already */
106     if (nicksvs.no_nick_ownership ? myuser_find (account) != NULL : mynick_find (account) != NULL)
107     {
108     command_fail (si, fault_alreadyexists, _("\2%s\2 is already registered."), account);
109     return;
110     }
111    
112 pippijn 1.4 if (!user_t::callback.can_register (si, account, email))
113 pippijn 1.1 return;
114    
115     /* make sure they're within limits */
116     tcnt = 0;
117 pippijn 1.4 foreach (myuser_pair &mupair, mulist)
118     {
119     tmu = mupair.second;
120    
121     if (!strcasecmp (email, tmu->email))
122     tcnt++;
123    
124     /* optimization: if tcnt >= me.maxusers, quit iterating. -nenolod */
125     if (tcnt >= me.maxusers)
126     break;
127     }
128    
129 pippijn 1.1 if (tcnt >= me.maxusers)
130     {
131     command_fail (si, fault_toomany, _("\2%s\2 has too many nicknames registered."), email);
132     return;
133     }
134    
135     mu = myuser_add (account, pass, email, config_options.defuflags | MU_NOBURSTLOGIN);
136     mu->registered = NOW;
137     mu->lastlogin = NOW;
138     if (!nicksvs.no_nick_ownership)
139     {
140     mn = mynick_add (mu, mu->name);
141     mn->registered = NOW;
142     mn->lastseen = NOW;
143     }
144    
145     if (me.auth == AUTH_EMAIL)
146     {
147     char *key = gen_pw (12);
148     mu->flags |= MU_WAITAUTH;
149    
150     mu->add_metadata ("private:verify:register:key", key);
151 pippijn 1.4 mu->add_metadata ("private:verify:register:timestamp", itoa (NOW));
152 pippijn 1.1
153     if (!sendemail (si->su != NULL ? si->su : si->service->me, EMAIL_REGISTER, mu, key))
154     {
155     command_fail (si, fault_emailfail, _("Sending email failed, sorry! Registration aborted."));
156     object_unref (mu);
157 pippijn 1.4 sfree (key);
158 pippijn 1.1 return;
159     }
160    
161     command_success_nodata (si, _("An email containing nickname activation instructions has been sent to \2%s\2."), mu->email);
162     command_success_nodata (si, _("If you do not complete registration within one day, your nickname will expire."));
163    
164 pippijn 1.4 sfree (key);
165 pippijn 1.1 }
166    
167     if (si->su != NULL)
168     {
169     si->su->myuser = mu;
170     mu->logins.insert (si->su);
171    
172     if (!(mu->flags & MU_WAITAUTH))
173     /* only grant ircd registered status if it's verified */
174 pippijn 1.4 phandler->ircd_on_login (si->su->nick, mu->name, NULL);
175 pippijn 1.1 }
176    
177     if (!nicksvs.no_nick_ownership && si->su != NULL)
178     snoop ("REGISTER: \2%s\2 to \2%s\2", account, email);
179     else
180     snoop ("REGISTER: \2%s\2 to \2%s\2 by \2%s\2", account, email, si->su != NULL ? si->su->nick : get_source_name (si));
181     logcommand (si, CMDLOG_REGISTER, "REGISTER to %s", email);
182     if (is_soper (mu))
183     {
184     wallops ("%s registered the nick \2%s\2 and gained services operator privileges.", get_oper_name (si), mu->name);
185     snoop ("SOPER: \2%s\2 as \2%s\2", get_oper_name (si), mu->name);
186     }
187    
188     command_success_nodata (si, _("\2%s\2 is now registered to \2%s\2."), mu->name, mu->email);
189     command_success_nodata (si, _("The password is \2%s\2. Please write this down for future reference."), pass);
190 pippijn 1.4 mu->callback.registered (mu);
191 pippijn 1.1
192     if (si->su != NULL)
193     {
194     snprintf (lau, BUFSIZE, "%s@%s", si->su->user, si->su->vhost);
195     mu->add_metadata ("private:host:vhost", lau);
196    
197     snprintf (lao, BUFSIZE, "%s@%s", si->su->user, si->su->host);
198     mu->add_metadata ("private:host:actual", lao);
199     }
200     }
201 pippijn 1.4
202     bool
203     _modinit (module *m)
204     {
205     ns_cmdtree << ns_register;
206     help_addentry (ns_helptree, "REGISTER", "help/nickserv/register", NULL);
207    
208     return true;
209     }
210    
211     void
212     _moddeinit ()
213     {
214     ns_cmdtree >> ns_register;
215     help_delentry (ns_helptree, "REGISTER");
216     }