1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
/* NickServ core functions
*
* (C) 2003-2010 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*
* $Id$
*
*/
/*************************************************************************/
#include "module.h"
class CommandNSGroup : public Command
{
public:
CommandNSGroup() : Command("GROUP", 2, 2)
{
this->SetFlag(CFLAG_ALLOW_UNREGISTERED);
}
CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms)
{
NickAlias *na, *target;
const char *nick = params[0].c_str();
std::string pass = params[1].c_str();
std::list<std::pair<std::string, std::string> >::iterator it;
if (Config.NSEmailReg && findrequestnick(u->nick.c_str()))
{
notice_lang(Config.s_NickServ, u, NICK_REQUESTED);
return MOD_CONT;
}
if (readonly)
{
notice_lang(Config.s_NickServ, u, NICK_GROUP_DISABLED);
return MOD_CONT;
}
if (!ircdproto->IsNickValid(u->nick.c_str()))
{
notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, u->nick.c_str());
return MOD_CONT;
}
if (Config.RestrictOperNicks)
{
for (it = Config.Opers.begin(); it != Config.Opers.end(); ++it)
{
std::string nick = it->first;
if (stristr(u->nick.c_str(), nick.c_str()) && !is_oper(u))
{
notice_lang(Config.s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick.c_str());
return MOD_CONT;
}
}
}
na = findnick(u->nick);
if (!(target = findnick(nick)))
notice_lang(Config.s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
else if (time(NULL) < u->lastnickreg + Config.NSRegDelay)
notice_lang(Config.s_NickServ, u, NICK_GROUP_PLEASE_WAIT, (Config.NSRegDelay + u->lastnickreg) - time(NULL));
else if (u->Account() && u->Account()->HasFlag(NI_SUSPENDED))
{
Alog() << Config.s_NickServ << ": " << u->GetMask() << " tried to use GROUP from SUSPENDED nick " << target->nick;
notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, u->nick.c_str());
}
else if (target && target->nc->HasFlag(NI_SUSPENDED))
{
Alog() << Config.s_NickServ << ": " << u->GetMask() << " tried to use GROUP for SUSPENDED nick " << target->nick;
notice_lang(Config.s_NickServ, u, NICK_X_SUSPENDED, target->nick);
}
else if (target->HasFlag(NS_FORBIDDEN))
notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, nick);
else if (na && target->nc == na->nc)
notice_lang(Config.s_NickServ, u, NICK_GROUP_SAME, target->nick);
else if (na && na->nc != u->Account())
notice_lang(Config.s_NickServ, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ);
else if (Config.NSMaxAliases && (target->nc->aliases.count >= Config.NSMaxAliases) && !target->nc->IsServicesOper())
notice_lang(Config.s_NickServ, u, NICK_GROUP_TOO_MANY, target->nick, Config.s_NickServ, Config.s_NickServ);
else if (enc_check_password(pass, target->nc->pass) != 1)
{
Alog() << Config.s_NickServ << ": Failed GROUP for " << u->GetMask() << " (invalid password)";
notice_lang(Config.s_NickServ, u, PASSWORD_INCORRECT);
if (bad_password(u))
return MOD_STOP;
}
else
{
/* If the nick is already registered, drop it.
* If not, check that it is valid.
*/
if (na)
delete na;
else
{
int prefixlen = strlen(Config.NSGuestNickPrefix);
int nicklen = u->nick.length();
if (nicklen <= prefixlen + 7 && nicklen >= prefixlen + 1 && stristr(u->nick.c_str(), Config.NSGuestNickPrefix) == u->nick.c_str() && strspn(u->nick.c_str() + prefixlen, "1234567890") == nicklen - prefixlen)
{
notice_lang(Config.s_NickServ, u, NICK_CANNOT_BE_REGISTERED, u->nick.c_str());
return MOD_CONT;
}
}
na = new NickAlias(u->nick, target->nc);
if (na)
{
std::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost();
na->last_usermask = sstrdup(last_usermask.c_str());
na->last_realname = sstrdup(u->realname);
na->time_registered = na->last_seen = time(NULL);
u->Login(na->nc);
FOREACH_MOD(I_OnNickGroup, OnNickGroup(u, target));
ircdproto->SetAutoIdentificationToken(u);
Alog() << Config.s_NickServ << ": " << u->GetMask() << " makes " << u->nick
<< " join group of " << target->nick << " (" << target->nc->display
<< ") (e-mail: " << (target->nc->email ? target->nc->email : "none") << ")";
notice_lang(Config.s_NickServ, u, NICK_GROUP_JOINED, target->nick);
u->lastnickreg = time(NULL);
check_memos(u);
}
else
{
Alog() << Config.s_NickServ << ": makealias(" << u->nick << ") failed";
notice_lang(Config.s_NickServ, u, NICK_GROUP_FAILED);
}
}
return MOD_CONT;
}
bool OnHelp(User *u, const ci::string &subcommand)
{
notice_help(Config.s_NickServ, u, NICK_HELP_GROUP);
return true;
}
void OnSyntaxError(User *u, const ci::string &subcommand)
{
syntax_error(Config.s_NickServ, u, "GROUP", NICK_GROUP_SYNTAX);
}
};
class CommandNSGList : public Command
{
public:
CommandNSGList() : Command("GLIST", 0, 1)
{
}
CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms)
{
const char *nick = params.size() ? params[0].c_str() : NULL;
NickCore *nc = u->Account();
int i;
if (nick && (stricmp(nick, u->nick.c_str()) && !u->Account()->IsServicesOper()))
notice_lang(Config.s_NickServ, u, ACCESS_DENIED, Config.s_NickServ);
else if (nick && (!findnick(nick) || !(nc = findnick(nick)->nc)))
notice_lang(Config.s_NickServ, u, !nick ? NICK_NOT_REGISTERED : NICK_X_NOT_REGISTERED, nick);
else
{
time_t expt;
struct tm *tm;
char buf[BUFSIZE];
int wont_expire;
notice_lang(Config.s_NickServ, u, nick ? NICK_GLIST_HEADER_X : NICK_GLIST_HEADER, nc->display);
for (i = 0; i < nc->aliases.count; ++i)
{
NickAlias *na2 = static_cast<NickAlias *>(nc->aliases.list[i]);
if (na2->nc == nc)
{
if (!(wont_expire = na2->HasFlag(NS_NO_EXPIRE)))
{
expt = na2->last_seen + Config.NSExpire;
tm = localtime(&expt);
strftime_lang(buf, sizeof(buf), finduser(na2->nick), STRFTIME_DATE_TIME_FORMAT, tm);
}
notice_lang(Config.s_NickServ, u, u->Account()->IsServicesOper() && !wont_expire ? NICK_GLIST_REPLY_ADMIN : NICK_GLIST_REPLY, wont_expire ? '!' : ' ', na2->nick, buf);
}
}
notice_lang(Config.s_NickServ, u, NICK_GLIST_FOOTER, nc->aliases.count);
}
return MOD_CONT;
}
bool OnHelp(User *u, const ci::string &subcommand)
{
if (u->Account() && u->Account()->IsServicesOper())
notice_help(Config.s_NickServ, u, NICK_SERVADMIN_HELP_GLIST);
else
notice_help(Config.s_NickServ, u, NICK_HELP_GLIST);
return true;
}
};
class NSGroup : public Module
{
public:
NSGroup(const std::string &modname, const std::string &creator) : Module(modname, creator)
{
this->SetAuthor("Anope");
this->SetVersion("$Id$");
this->SetType(CORE);
this->AddCommand(NICKSERV, new CommandNSGroup());
this->AddCommand(NICKSERV, new CommandNSGList());
ModuleManager::Attach(I_OnNickServHelp, this);
}
void OnNickServHelp(User *u)
{
notice_lang(Config.s_NickServ, u, NICK_HELP_CMD_GROUP);
notice_lang(Config.s_NickServ, u, NICK_HELP_CMD_GLIST);
}
};
MODULE_INIT(NSGroup)
|