1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_services.c: SVS commands and Services support |
4 |
* |
5 |
* Copyright (C) 2005 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
/* |
25 |
* |
26 |
* With code from 'bane' the URL following is valid as of this date. |
27 |
* http://hybserv2.net/file/trunk/contrib/hybrid_services.c |
28 |
* |
29 |
* |
30 |
* Copyright (C) 2002, 2003, 2004, 2005 by Dragan 'bane' Dosen and the |
31 |
* Hybrid Development Team. |
32 |
* |
33 |
* Based on m_services.c, originally from bahamut ircd. |
34 |
* |
35 |
* Contact info: |
36 |
* |
37 |
* E-mail : bane@idolnet.org |
38 |
* IRC : (*) bane, idolNET, irc.idolnet.org, #twilight_zone |
39 |
*/ |
40 |
|
41 |
/* MODULE CONFIGURATION FOLLOWS -- please read!! */ |
42 |
|
43 |
/* Change this to the name of your services server |
44 |
* otherwise the services aliases will not work! |
45 |
*/ |
46 |
#define SERVICES_NAME "services.yournet.net" |
47 |
|
48 |
/* END OF MODULE CONFIGURATION */ |
49 |
|
50 |
#include "stdinc.h" |
51 |
#include "handlers.h" |
52 |
#include "client.h" |
53 |
#include "hash.h" |
54 |
#include "fdlist.h" |
55 |
#include "irc_string.h" |
56 |
#include "ircd.h" |
57 |
#include "numeric.h" |
58 |
#include "s_conf.h" |
59 |
#include "s_stats.h" |
60 |
#include "s_user.h" |
61 |
#include "whowas.h" |
62 |
#include "s_serv.h" |
63 |
#include "send.h" |
64 |
#include "list.h" |
65 |
#include "channel.h" |
66 |
#include "s_log.h" |
67 |
#include "resv.h" |
68 |
#include "msg.h" |
69 |
#include "parse.h" |
70 |
#include "modules.h" |
71 |
#include "common.h" |
72 |
#include "packet.h" |
73 |
#include "sprintf_irc.h" |
74 |
|
75 |
/* Custom Macros */ |
76 |
#define services_function(a,b,c) static void a(struct Client *client_p,\ |
77 |
struct Client *source_p, int parc,\ |
78 |
char *parv[]) \ |
79 |
{ deliver_services_msg(b, c, client_p, source_p, parc, parv); } |
80 |
|
81 |
static void mo_svsnick(struct Client *, struct Client *, int, char *[]); |
82 |
|
83 |
static void m_botserv(struct Client *, struct Client *, int, char *[]); |
84 |
static void m_chanserv(struct Client *, struct Client *, int, char *[]); |
85 |
static void m_global(struct Client *, struct Client *, int, char *[]); |
86 |
static void m_helpserv(struct Client *, struct Client *, int, char *[]); |
87 |
static void m_hostserv(struct Client *, struct Client *, int, char *[]); |
88 |
static void m_identify(struct Client *, struct Client *, int, char *[]); |
89 |
static void m_memoserv(struct Client *, struct Client *, int, char *[]); |
90 |
static void m_nickserv(struct Client *, struct Client *, int, char *[]); |
91 |
static void m_operserv(struct Client *, struct Client *, int, char *[]); |
92 |
static void m_seenserv(struct Client *, struct Client *, int, char *[]); |
93 |
static void m_statserv(struct Client *, struct Client *, int, char *[]); |
94 |
|
95 |
static void get_string(int, char *[], char *); |
96 |
static int clean_nick_name(char *, int); |
97 |
static void deliver_services_msg(const char *, const char *, struct Client *, |
98 |
struct Client *, int, char *[]); |
99 |
|
100 |
/* SVS commands */ |
101 |
struct Message svsnick_msgtab = { |
102 |
"SVSNICK", 0, 0, 3, 0, MFLG_SLOW, 0, |
103 |
{m_unregistered, m_not_oper, mo_svsnick, mo_svsnick, mo_svsnick, m_ignore} |
104 |
}; |
105 |
|
106 |
/* Services */ |
107 |
struct Message botserv_msgtab = { |
108 |
"BOTSERV", 0, 0, 1, 0, MFLG_SLOW, 0, |
109 |
{m_unregistered, m_botserv, m_ignore, m_ignore, m_botserv, m_ignore} |
110 |
}; |
111 |
|
112 |
struct Message chanserv_msgtab = { |
113 |
"CHANSERV", 0, 0, 1, 0, MFLG_SLOW, 0, |
114 |
{m_unregistered, m_chanserv, m_ignore, m_ignore, m_chanserv, m_ignore} |
115 |
}; |
116 |
|
117 |
struct Message global_msgtab = { |
118 |
"GLOBAL", 0, 0, 1, 0, MFLG_SLOW, 0, |
119 |
{m_unregistered, m_global, m_ignore, m_ignore, m_global, m_ignore} |
120 |
}; |
121 |
|
122 |
struct Message helpserv_msgtab = { |
123 |
"HELPSERV", 0, 0, 1, 0, MFLG_SLOW, 0, |
124 |
{m_unregistered, m_helpserv, m_ignore, m_ignore, m_helpserv, m_ignore} |
125 |
}; |
126 |
|
127 |
struct Message hostserv_msgtab = { |
128 |
"HOSTSERV", 0, 0, 1, 0, MFLG_SLOW, 0, |
129 |
{m_unregistered, m_hostserv, m_ignore, m_ignore, m_hostserv, m_ignore} |
130 |
}; |
131 |
|
132 |
struct Message memoserv_msgtab = { |
133 |
"MEMOSERV", 0, 0, 1, 0, MFLG_SLOW, 0, |
134 |
{m_unregistered, m_memoserv, m_ignore, m_ignore, m_memoserv, m_ignore} |
135 |
}; |
136 |
|
137 |
struct Message nickserv_msgtab = { |
138 |
"NICKSERV", 0, 0, 1, 0, MFLG_SLOW, 0, |
139 |
{m_unregistered, m_nickserv, m_ignore, m_ignore, m_nickserv, m_ignore} |
140 |
}; |
141 |
|
142 |
struct Message operserv_msgtab = { |
143 |
"OPERSERV", 0, 0, 1, 0, MFLG_SLOW, 0, |
144 |
{m_unregistered, m_operserv, m_ignore, m_ignore, m_operserv, m_ignore} |
145 |
}; |
146 |
|
147 |
struct Message seenserv_msgtab = { |
148 |
"SEENSERV", 0, 0, 1, 0, MFLG_SLOW, 0, |
149 |
{m_unregistered, m_seenserv, m_ignore, m_ignore, m_seenserv, m_ignore} |
150 |
}; |
151 |
|
152 |
struct Message statserv_msgtab = { |
153 |
"STATSERV", 0, 0, 1, 0, MFLG_SLOW, 0, |
154 |
{m_unregistered, m_statserv, m_ignore, m_ignore, m_statserv, m_ignore} |
155 |
}; |
156 |
|
157 |
/* Short-hand aliases for NickServ, ChanServ, MemoServ and OperServ */ |
158 |
struct Message cs_msgtab = { |
159 |
"CS", 0, 0, 1, 0, MFLG_SLOW, 0, |
160 |
{m_unregistered, m_chanserv, m_ignore, m_ignore, m_chanserv, m_ignore} |
161 |
}; |
162 |
|
163 |
struct Message identify_msgtab = { |
164 |
"IDENTIFY", 0, 0, 0, 2, MFLG_SLOW, 0, |
165 |
{m_unregistered, m_identify, m_ignore, m_ignore, m_identify, m_ignore} |
166 |
}; |
167 |
|
168 |
struct Message ms_msgtab = { |
169 |
"MS", 0, 0, 1, 0, MFLG_SLOW, 0, |
170 |
{m_unregistered, m_memoserv, m_ignore, m_ignore, m_memoserv, m_ignore} |
171 |
}; |
172 |
|
173 |
struct Message ns_msgtab = { |
174 |
"NS", 0, 0, 1, 0, MFLG_SLOW, 0, |
175 |
{m_unregistered, m_nickserv, m_ignore, m_ignore, m_nickserv, m_ignore} |
176 |
}; |
177 |
|
178 |
struct Message os_msgtab = { |
179 |
"OS", 0, 0, 1, 0, MFLG_SLOW, 0, |
180 |
{m_unregistered, m_operserv, m_ignore, m_ignore, m_operserv, m_ignore} |
181 |
}; |
182 |
|
183 |
#ifndef STATIC_MODULES |
184 |
void |
185 |
_modinit(void) |
186 |
{ |
187 |
mod_add_cmd(&svsnick_msgtab); |
188 |
mod_add_cmd(&botserv_msgtab); |
189 |
mod_add_cmd(&chanserv_msgtab); |
190 |
mod_add_cmd(&global_msgtab); |
191 |
mod_add_cmd(&helpserv_msgtab); |
192 |
mod_add_cmd(&hostserv_msgtab); |
193 |
mod_add_cmd(&identify_msgtab); |
194 |
mod_add_cmd(&memoserv_msgtab); |
195 |
mod_add_cmd(&nickserv_msgtab); |
196 |
mod_add_cmd(&operserv_msgtab); |
197 |
mod_add_cmd(&seenserv_msgtab); |
198 |
mod_add_cmd(&statserv_msgtab); |
199 |
mod_add_cmd(&ns_msgtab); |
200 |
mod_add_cmd(&cs_msgtab); |
201 |
mod_add_cmd(&ms_msgtab); |
202 |
mod_add_cmd(&os_msgtab); |
203 |
} |
204 |
|
205 |
void |
206 |
_moddeinit(void) |
207 |
{ |
208 |
mod_del_cmd(&svsnick_msgtab); |
209 |
mod_del_cmd(&botserv_msgtab); |
210 |
mod_del_cmd(&chanserv_msgtab); |
211 |
mod_del_cmd(&global_msgtab); |
212 |
mod_del_cmd(&helpserv_msgtab); |
213 |
mod_del_cmd(&hostserv_msgtab); |
214 |
mod_del_cmd(&identify_msgtab); |
215 |
mod_del_cmd(&memoserv_msgtab); |
216 |
mod_del_cmd(&nickserv_msgtab); |
217 |
mod_del_cmd(&operserv_msgtab); |
218 |
mod_del_cmd(&seenserv_msgtab); |
219 |
mod_del_cmd(&statserv_msgtab); |
220 |
mod_del_cmd(&ns_msgtab); |
221 |
mod_del_cmd(&cs_msgtab); |
222 |
mod_del_cmd(&ms_msgtab); |
223 |
mod_del_cmd(&os_msgtab); |
224 |
} |
225 |
|
226 |
const char *_version = "$Revision$"; |
227 |
#endif |
228 |
|
229 |
/* |
230 |
* mo_svsnick() |
231 |
* |
232 |
* parv[0] = sender prefix |
233 |
* parv[1] = user to force |
234 |
* parv[2] = nick to force them to |
235 |
*/ |
236 |
static void |
237 |
mo_svsnick(struct Client *client_p, struct Client *source_p, |
238 |
int parc, char *parv[]) |
239 |
{ |
240 |
char newnick[NICKLEN]; |
241 |
struct Client *target_p = NULL; |
242 |
|
243 |
if (MyClient(source_p) && !IsOperAdmin(source_p)) |
244 |
{ |
245 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
246 |
me.name, parv[0], "SVSNICK"); |
247 |
return; |
248 |
} |
249 |
|
250 |
if (parc < 3 || *parv[2] == '\0') |
251 |
{ |
252 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
253 |
me.name, parv[0], "SVSNICK"); |
254 |
return; |
255 |
} |
256 |
|
257 |
if ((target_p = find_person(client_p, parv[1])) == NULL) |
258 |
{ |
259 |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
260 |
me.name, parv[0], parv[1]); |
261 |
return; |
262 |
} |
263 |
|
264 |
/* terminate nick to NICKLEN */ |
265 |
strlcpy(newnick, parv[2], sizeof(newnick)); |
266 |
|
267 |
if (!clean_nick_name(newnick, 1)) |
268 |
{ |
269 |
if (IsClient(source_p)) |
270 |
sendto_one(source_p, ":%s NOTICE %s :*** Notice -- Invalid new ", |
271 |
"nickname: %s", me.name, parv[0], newnick); |
272 |
return; |
273 |
} |
274 |
|
275 |
if (find_client(newnick) != NULL) |
276 |
{ |
277 |
if (IsClient(source_p)) |
278 |
sendto_one(source_p, ":%s NOTICE %s :*** Notice -- Nickname %s is " |
279 |
"already in use", me.name, parv[0], newnick); |
280 |
return; |
281 |
} |
282 |
|
283 |
if (MyConnect(target_p)) |
284 |
change_local_nick(&me, target_p, newnick); |
285 |
else |
286 |
sendto_one(target_p, ":%s ENCAP %s SVSNICK %s %s", |
287 |
me.name, target_p->servptr->name, ID(target_p), newnick); |
288 |
} |
289 |
|
290 |
/* |
291 |
* These generate the services functions through |
292 |
* a macro. |
293 |
*/ |
294 |
services_function(m_botserv, "BotServ", "BOTSERV" ) |
295 |
services_function(m_chanserv, "ChanServ", "CHANSERV") |
296 |
services_function(m_global, "Global", "GLOBAL" ) |
297 |
services_function(m_helpserv, "HelpServ", "HELPSERV") |
298 |
services_function(m_hostserv, "HostServ", "HOSTSERV") |
299 |
services_function(m_memoserv, "MemoServ", "MEMOSERV") |
300 |
services_function(m_nickserv, "NickServ", "NICKSERV") |
301 |
services_function(m_operserv, "OperServ", "OPERSERV") |
302 |
services_function(m_seenserv, "SeenServ", "SEENSERV") |
303 |
services_function(m_statserv, "StatServ", "STATSERV") |
304 |
|
305 |
/* |
306 |
* get_string() |
307 |
* |
308 |
* Reverse the array parv back into a normal string assuming |
309 |
* there are "parc" indicies in the array. |
310 |
* |
311 |
* Originally GetString() written by sidewndr. |
312 |
* Modified by Michael for use with hybrid-7. |
313 |
*/ |
314 |
static void |
315 |
get_string(int parc, char *parv[], char *buf) |
316 |
{ |
317 |
int ii = 0; |
318 |
int bw = 0; |
319 |
|
320 |
for (; ii < parc; ++ii) |
321 |
bw += ircsprintf(buf+bw, "%s ", parv[ii]); |
322 |
buf[bw-1] = '\0'; |
323 |
} |
324 |
|
325 |
/* |
326 |
* clean_nick_name() |
327 |
* |
328 |
* input - nickname |
329 |
* output - none |
330 |
* side effects - walks through the nickname, returning 0 if erroneous |
331 |
*/ |
332 |
static int |
333 |
clean_nick_name(char *nick, int local) |
334 |
{ |
335 |
assert(nick); |
336 |
|
337 |
/* nicks can't start with a digit or - or be 0 length */ |
338 |
/* This closer duplicates behaviour of hybrid-6 */ |
339 |
|
340 |
if (*nick == '-' || (IsDigit(*nick) && local) || *nick == '\0') |
341 |
return 0; |
342 |
|
343 |
for (; *nick; ++nick) |
344 |
if (!IsNickChar(*nick)) |
345 |
return 0; |
346 |
|
347 |
return 1; |
348 |
} |
349 |
|
350 |
/* |
351 |
* m_identify() |
352 |
* |
353 |
* parv[0] = sender prefix |
354 |
* parv[1] = NickServ Password or Channel |
355 |
* parv[2] = ChanServ Password |
356 |
*/ |
357 |
static void |
358 |
m_identify(struct Client *client_p, struct Client *source_p, |
359 |
int parc, char *parv[]) |
360 |
{ |
361 |
struct Client *target_p = NULL; |
362 |
|
363 |
switch (parc) |
364 |
{ |
365 |
case 2: |
366 |
if (!(target_p = find_server(SERVICES_NAME))) |
367 |
sendto_one(source_p, form_str(ERR_SERVICESDOWN), |
368 |
me.name, source_p->name); |
369 |
else |
370 |
sendto_one(target_p, ":%s PRIVMSG NickServ@%s :IDENTIFY %s", |
371 |
source_p->name, SERVICES_NAME, parv[1]); |
372 |
break; |
373 |
|
374 |
case 3: |
375 |
if (!(target_p = find_server(SERVICES_NAME))) |
376 |
sendto_one(source_p, form_str(ERR_SERVICESDOWN), |
377 |
me.name, source_p->name); |
378 |
else |
379 |
sendto_one(target_p, ":%s PRIVMSG ChanServ@%s :IDENTIFY %s %s", |
380 |
source_p->name, SERVICES_NAME, parv[1], parv[2]); |
381 |
break; |
382 |
|
383 |
default: |
384 |
sendto_one(source_p, ":%s NOTICE %s :Syntax: IDENTIFY <password> " |
385 |
"- for nickname", me.name, source_p->name); |
386 |
sendto_one(source_p, ":%s NOTICE %s :Syntax: IDENTIFY <channel> " |
387 |
"<password> - for channel", me.name, source_p->name); |
388 |
break; |
389 |
} |
390 |
} |
391 |
|
392 |
/* |
393 |
* deliver_services_msg() |
394 |
* |
395 |
* parv[0] = sender prefix |
396 |
* servmsg = message for services (utilising GetString()) |
397 |
* |
398 |
* Borrowed from HybServ -- knight- |
399 |
*/ |
400 |
static void |
401 |
deliver_services_msg(const char *service, const char *command, |
402 |
struct Client *client_p, |
403 |
struct Client *source_p, int parc, char *parv[]) |
404 |
{ |
405 |
struct Client *target_p = NULL; |
406 |
char buf[IRCD_BUFSIZE] = { '\0' }; |
407 |
|
408 |
if (parc < 2 || *parv[1] == '\0') |
409 |
{ |
410 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
411 |
me.name, source_p->name, command); |
412 |
return; |
413 |
} |
414 |
|
415 |
if (!(target_p = find_server(SERVICES_NAME))) |
416 |
sendto_one(source_p, form_str(ERR_SERVICESDOWN), |
417 |
me.name, source_p->name); |
418 |
else |
419 |
{ |
420 |
get_string(parc - 1, parv + 1, buf); |
421 |
sendto_one(target_p, ":%s PRIVMSG %s@%s :%s", |
422 |
source_p->name, service, SERVICES_NAME, buf); |
423 |
} |
424 |
} |