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

File Contents

# Content
1 /**
2 * ns_fregister.C: This file contains code for the NickServ FREGISTER 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-2007 William Pitcock, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: ns_fregister.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <libermyth.h>
17 #include <ermyth/module.h>
18 #include <account/myuser.h>
19 #include <account/mynick.h>
20
21 static char const rcsid[] = "$Id: ns_fregister.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $";
22
23 REGISTER_MODULE ("nickserv/fregister", false, "The Ermyth Team <http://ermyth.xinutec.org>");
24
25 static void ns_cmd_fregister (sourceinfo_t *si, int parc, char *parv[]);
26
27 command_t const ns_fregister = { "FREGISTER", "Registers a nickname on behalf of another user.", PRIV_USER_FREGISTER, 20, ns_cmd_fregister };
28
29 E cmdvec ns_cmdtree;
30 E helpvec ns_helptree;
31
32 bool
33 _modinit (module *m)
34 {
35 ns_cmdtree << ns_fregister;
36 help_addentry (ns_helptree, "FREGISTER", "help/nickserv/fregister", NULL);
37
38 return true;
39 }
40
41 void
42 _moddeinit ()
43 {
44 ns_cmdtree >> ns_fregister;
45 help_delentry (ns_helptree, "FREGISTER");
46 }
47
48 static void
49 ns_cmd_fregister (sourceinfo_t *si, int parc, char *parv[])
50 {
51 myuser_t *mu;
52 mynick_t *mn;
53 char *account;
54 char *pass;
55 char *email;
56 int i, uflags = 0;
57
58 account = parv[0], pass = parv[1], email = parv[2];
59
60 if (!account || !pass || !email)
61 {
62 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "FREGISTER");
63 command_fail (si, fault::needmoreparams, "Syntax: FREGISTER <account> <password> <email> [CRYPTPASS]");
64 return;
65 }
66
67 for (i = 3; i < parc; i++)
68 {
69 if (!strcasecmp (parv[i], "CRYPTPASS"))
70 uflags |= MU_CRYPTPASS;
71 else if (!strcasecmp (parv[i], "HIDEMAIL"))
72 uflags |= MU_HIDEMAIL;
73 else if (!strcasecmp (parv[i], "NOOP"))
74 uflags |= MU_NOOP;
75 else if (!strcasecmp (parv[i], "NEVEROP"))
76 uflags |= MU_NEVEROP;
77 }
78
79 if ((!(uflags & MU_CRYPTPASS) && strlen (pass) > 32) || strlen (email) >= EMAILLEN)
80 {
81 command_fail (si, fault::badparams, STR_INVALID_PARAMS, "FREGISTER");
82 return;
83 }
84
85 if (!nicksvs.no_nick_ownership && IsDigit (*account))
86 {
87 command_fail (si, fault::badparams, "For security reasons, you can't register your UID.");
88 return;
89 }
90
91 if (strchr (account, ' ') || strchr (account, '\n') || strchr (account, '\r') || account[0] == '=' || account[0] == '#' || account[0] == '@' || account[0] == '+' || account[0] == '%' || account[0] == '!' || strchr (account, ','))
92 {
93 command_fail (si, fault::badparams, "The account name \2%s\2 is invalid.", account);
94 return;
95 }
96
97 if (!validemail (email))
98 {
99 command_fail (si, fault::badparams, "\2%s\2 is not a valid email address.", email);
100 return;
101 }
102
103 /* make sure it isn't registered already */
104 if (nicksvs.no_nick_ownership ? myuser_t::find (account) != NULL : mynick_t::find (account) != NULL)
105 {
106 command_fail (si, fault::alreadyexists, "\2%s\2 is already registered.", account);
107 return;
108 }
109
110 mu = myuser_t::create (account, pass, email, uflags | config_options.defuflags | MU_NOBURSTLOGIN);
111 mu->registered = NOW;
112 mu->lastlogin = NOW;
113 if (!nicksvs.no_nick_ownership)
114 {
115 mn = mynick_t::create (mu, mu->name);
116 mn->registered = NOW;
117 mn->lastseen = NOW;
118 }
119
120 snoop ("FREGISTER: \2%s\2 to \2%s\2 by \2%s\2", account, email, get_oper_name (si));
121 logcommand (si, CMDLOG_REGISTER, "FREGISTER %s to %s", account, email);
122 if (is_soper (mu))
123 {
124 wallops ("%s used FREGISTER on account \2%s\2 with services operator privileges.", get_oper_name (si), mu->name);
125 snoop ("SOPER: \2%s\2", mu->name);
126 }
127
128 command_success_nodata (si, "\2%s\2 is now registered to \2%s\2.", mu->name, mu->email);
129 mu->callback.registered (mu);
130 }