ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.3/contrib/m_services.c
Revision: 1121
Committed: Sun Jan 9 11:03:03 2011 UTC (15 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 12354 byte(s)
Log Message:
- removed all instances of STATIC_MODULES since we don't have
  static modules anymore
- removed m_mkpasswd module from contrib

File Contents

# Content
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_user.h"
60 #include "whowas.h"
61 #include "s_serv.h"
62 #include "send.h"
63 #include "list.h"
64 #include "channel.h"
65 #include "s_log.h"
66 #include "resv.h"
67 #include "msg.h"
68 #include "parse.h"
69 #include "modules.h"
70 #include "common.h"
71 #include "packet.h"
72 #include "sprintf_irc.h"
73
74 /* Custom Macros */
75 #define services_function(a,b,c) static void a(struct Client *client_p,\
76 struct Client *source_p, int parc,\
77 char *parv[]) \
78 { deliver_services_msg(b, c, client_p, source_p, parc, parv); }
79
80 static void mo_svsnick(struct Client *, struct Client *, int, char *[]);
81
82 static void m_botserv(struct Client *, struct Client *, int, char *[]);
83 static void m_chanserv(struct Client *, struct Client *, int, char *[]);
84 static void m_global(struct Client *, struct Client *, int, char *[]);
85 static void m_helpserv(struct Client *, struct Client *, int, char *[]);
86 static void m_hostserv(struct Client *, struct Client *, int, char *[]);
87 static void m_identify(struct Client *, struct Client *, int, char *[]);
88 static void m_memoserv(struct Client *, struct Client *, int, char *[]);
89 static void m_nickserv(struct Client *, struct Client *, int, char *[]);
90 static void m_operserv(struct Client *, struct Client *, int, char *[]);
91 static void m_seenserv(struct Client *, struct Client *, int, char *[]);
92 static void m_statserv(struct Client *, struct Client *, int, char *[]);
93
94 static void get_string(int, char *[], char *);
95 static int clean_nick_name(char *, int);
96 static void deliver_services_msg(const char *, const char *, struct Client *,
97 struct Client *, int, char *[]);
98
99 /* SVS commands */
100 struct Message svsnick_msgtab = {
101 "SVSNICK", 0, 0, 3, 0, MFLG_SLOW, 0,
102 {m_unregistered, m_not_oper, mo_svsnick, mo_svsnick, mo_svsnick, m_ignore}
103 };
104
105 /* Services */
106 struct Message botserv_msgtab = {
107 "BOTSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
108 {m_unregistered, m_botserv, m_ignore, m_ignore, m_botserv, m_ignore}
109 };
110
111 struct Message chanserv_msgtab = {
112 "CHANSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
113 {m_unregistered, m_chanserv, m_ignore, m_ignore, m_chanserv, m_ignore}
114 };
115
116 struct Message global_msgtab = {
117 "GLOBAL", 0, 0, 1, 0, MFLG_SLOW, 0,
118 {m_unregistered, m_global, m_ignore, m_ignore, m_global, m_ignore}
119 };
120
121 struct Message helpserv_msgtab = {
122 "HELPSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
123 {m_unregistered, m_helpserv, m_ignore, m_ignore, m_helpserv, m_ignore}
124 };
125
126 struct Message hostserv_msgtab = {
127 "HOSTSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
128 {m_unregistered, m_hostserv, m_ignore, m_ignore, m_hostserv, m_ignore}
129 };
130
131 struct Message memoserv_msgtab = {
132 "MEMOSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
133 {m_unregistered, m_memoserv, m_ignore, m_ignore, m_memoserv, m_ignore}
134 };
135
136 struct Message nickserv_msgtab = {
137 "NICKSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
138 {m_unregistered, m_nickserv, m_ignore, m_ignore, m_nickserv, m_ignore}
139 };
140
141 struct Message operserv_msgtab = {
142 "OPERSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
143 {m_unregistered, m_operserv, m_ignore, m_ignore, m_operserv, m_ignore}
144 };
145
146 struct Message seenserv_msgtab = {
147 "SEENSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
148 {m_unregistered, m_seenserv, m_ignore, m_ignore, m_seenserv, m_ignore}
149 };
150
151 struct Message statserv_msgtab = {
152 "STATSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
153 {m_unregistered, m_statserv, m_ignore, m_ignore, m_statserv, m_ignore}
154 };
155
156 /* Short-hand aliases for NickServ, ChanServ, MemoServ and OperServ */
157 struct Message cs_msgtab = {
158 "CS", 0, 0, 1, 0, MFLG_SLOW, 0,
159 {m_unregistered, m_chanserv, m_ignore, m_ignore, m_chanserv, m_ignore}
160 };
161
162 struct Message identify_msgtab = {
163 "IDENTIFY", 0, 0, 0, 2, MFLG_SLOW, 0,
164 {m_unregistered, m_identify, m_ignore, m_ignore, m_identify, m_ignore}
165 };
166
167 struct Message ms_msgtab = {
168 "MS", 0, 0, 1, 0, MFLG_SLOW, 0,
169 {m_unregistered, m_memoserv, m_ignore, m_ignore, m_memoserv, m_ignore}
170 };
171
172 struct Message ns_msgtab = {
173 "NS", 0, 0, 1, 0, MFLG_SLOW, 0,
174 {m_unregistered, m_nickserv, m_ignore, m_ignore, m_nickserv, m_ignore}
175 };
176
177 struct Message os_msgtab = {
178 "OS", 0, 0, 1, 0, MFLG_SLOW, 0,
179 {m_unregistered, m_operserv, m_ignore, m_ignore, m_operserv, m_ignore}
180 };
181
182 struct Message bs_msgtab = {
183 "BS", 0, 0, 1, 0, MFLG_SLOW, 0,
184 {m_unregistered, m_botserv, m_ignore, m_ignore, m_botserv, m_ignore}
185 };
186
187 void
188 _modinit(void)
189 {
190 mod_add_cmd(&svsnick_msgtab);
191 mod_add_cmd(&botserv_msgtab);
192 mod_add_cmd(&chanserv_msgtab);
193 mod_add_cmd(&global_msgtab);
194 mod_add_cmd(&helpserv_msgtab);
195 mod_add_cmd(&hostserv_msgtab);
196 mod_add_cmd(&identify_msgtab);
197 mod_add_cmd(&memoserv_msgtab);
198 mod_add_cmd(&nickserv_msgtab);
199 mod_add_cmd(&operserv_msgtab);
200 mod_add_cmd(&seenserv_msgtab);
201 mod_add_cmd(&statserv_msgtab);
202 mod_add_cmd(&bs_msgtab);
203 mod_add_cmd(&ns_msgtab);
204 mod_add_cmd(&cs_msgtab);
205 mod_add_cmd(&ms_msgtab);
206 mod_add_cmd(&os_msgtab);
207 }
208
209 void
210 _moddeinit(void)
211 {
212 mod_del_cmd(&svsnick_msgtab);
213 mod_del_cmd(&botserv_msgtab);
214 mod_del_cmd(&chanserv_msgtab);
215 mod_del_cmd(&global_msgtab);
216 mod_del_cmd(&helpserv_msgtab);
217 mod_del_cmd(&hostserv_msgtab);
218 mod_del_cmd(&identify_msgtab);
219 mod_del_cmd(&memoserv_msgtab);
220 mod_del_cmd(&nickserv_msgtab);
221 mod_del_cmd(&operserv_msgtab);
222 mod_del_cmd(&seenserv_msgtab);
223 mod_del_cmd(&statserv_msgtab);
224 mod_del_cmd(&bs_msgtab);
225 mod_del_cmd(&ns_msgtab);
226 mod_del_cmd(&cs_msgtab);
227 mod_del_cmd(&ms_msgtab);
228 mod_del_cmd(&os_msgtab);
229 }
230
231 const char *_version = "$Revision$";
232
233 /*
234 * mo_svsnick()
235 *
236 * parv[0] = sender prefix
237 * parv[1] = user to force
238 * parv[2] = nick to force them to
239 */
240 static void
241 mo_svsnick(struct Client *client_p, struct Client *source_p,
242 int parc, char *parv[])
243 {
244 char newnick[NICKLEN];
245 struct Client *target_p = NULL;
246
247 if (MyClient(source_p) && !IsOperAdmin(source_p))
248 {
249 sendto_one(source_p, form_str(ERR_NOPRIVS),
250 me.name, parv[0], "SVSNICK");
251 return;
252 }
253
254 if (parc < 3 || *parv[2] == '\0')
255 {
256 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
257 me.name, parv[0], "SVSNICK");
258 return;
259 }
260
261 if ((target_p = find_person(client_p, parv[1])) == NULL)
262 {
263 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
264 me.name, parv[0], parv[1]);
265 return;
266 }
267
268 /* terminate nick to NICKLEN */
269 strlcpy(newnick, parv[2], sizeof(newnick));
270
271 if (!clean_nick_name(newnick, 1))
272 {
273 if (IsClient(source_p))
274 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- Invalid new ",
275 "nickname: %s", me.name, parv[0], newnick);
276 return;
277 }
278
279 if (find_client(newnick) != NULL)
280 {
281 if (IsClient(source_p))
282 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- Nickname %s is "
283 "already in use", me.name, parv[0], newnick);
284 return;
285 }
286
287 if (MyConnect(target_p))
288 change_local_nick(&me, target_p, newnick);
289 else
290 sendto_one(target_p, ":%s ENCAP %s SVSNICK %s %s",
291 me.name, target_p->servptr->name, ID(target_p), newnick);
292 }
293
294 /*
295 * These generate the services functions through
296 * a macro.
297 */
298 services_function(m_botserv, "BotServ", "BOTSERV" )
299 services_function(m_chanserv, "ChanServ", "CHANSERV")
300 services_function(m_global, "Global", "GLOBAL" )
301 services_function(m_helpserv, "HelpServ", "HELPSERV")
302 services_function(m_hostserv, "HostServ", "HOSTSERV")
303 services_function(m_memoserv, "MemoServ", "MEMOSERV")
304 services_function(m_nickserv, "NickServ", "NICKSERV")
305 services_function(m_operserv, "OperServ", "OPERSERV")
306 services_function(m_seenserv, "SeenServ", "SEENSERV")
307 services_function(m_statserv, "StatServ", "STATSERV")
308
309 /*
310 * get_string()
311 *
312 * Reverse the array parv back into a normal string assuming
313 * there are "parc" indicies in the array.
314 *
315 * Originally GetString() written by sidewndr.
316 * Modified by Michael for use with hybrid-7.
317 */
318 static void
319 get_string(int parc, char *parv[], char *buf)
320 {
321 int ii = 0;
322 int bw = 0;
323
324 for (; ii < parc; ++ii)
325 bw += ircsprintf(buf+bw, "%s ", parv[ii]);
326 buf[bw-1] = '\0';
327 }
328
329 /*
330 * clean_nick_name()
331 *
332 * input - nickname
333 * output - none
334 * side effects - walks through the nickname, returning 0 if erroneous
335 */
336 static int
337 clean_nick_name(char *nick, int local)
338 {
339 assert(nick);
340
341 /* nicks can't start with a digit or - or be 0 length */
342 /* This closer duplicates behaviour of hybrid-6 */
343
344 if (*nick == '-' || (IsDigit(*nick) && local) || *nick == '\0')
345 return 0;
346
347 for (; *nick; ++nick)
348 if (!IsNickChar(*nick))
349 return 0;
350
351 return 1;
352 }
353
354 /*
355 * m_identify()
356 *
357 * parv[0] = sender prefix
358 * parv[1] = NickServ Password or Channel
359 * parv[2] = ChanServ Password
360 */
361 static void
362 m_identify(struct Client *client_p, struct Client *source_p,
363 int parc, char *parv[])
364 {
365 struct Client *target_p = NULL;
366
367 switch (parc)
368 {
369 case 2:
370 if (!(target_p = find_server(SERVICES_NAME)))
371 sendto_one(source_p, form_str(ERR_SERVICESDOWN),
372 me.name, source_p->name);
373 else
374 sendto_one(target_p, ":%s PRIVMSG NickServ@%s :IDENTIFY %s",
375 source_p->name, SERVICES_NAME, parv[1]);
376 break;
377
378 case 3:
379 if (!(target_p = find_server(SERVICES_NAME)))
380 sendto_one(source_p, form_str(ERR_SERVICESDOWN),
381 me.name, source_p->name);
382 else
383 sendto_one(target_p, ":%s PRIVMSG ChanServ@%s :IDENTIFY %s %s",
384 source_p->name, SERVICES_NAME, parv[1], parv[2]);
385 break;
386
387 default:
388 sendto_one(source_p, ":%s NOTICE %s :Syntax: IDENTIFY <password> "
389 "- for nickname", me.name, source_p->name);
390 sendto_one(source_p, ":%s NOTICE %s :Syntax: IDENTIFY <channel> "
391 "<password> - for channel", me.name, source_p->name);
392 break;
393 }
394 }
395
396 /*
397 * deliver_services_msg()
398 *
399 * parv[0] = sender prefix
400 * servmsg = message for services (utilising GetString())
401 *
402 * Borrowed from HybServ -- knight-
403 */
404 static void
405 deliver_services_msg(const char *service, const char *command,
406 struct Client *client_p,
407 struct Client *source_p, int parc, char *parv[])
408 {
409 struct Client *target_p = NULL;
410 char buf[IRCD_BUFSIZE] = { '\0' };
411
412 if (parc < 2 || *parv[1] == '\0')
413 {
414 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
415 me.name, source_p->name, command);
416 return;
417 }
418
419 if (!(target_p = find_server(SERVICES_NAME)))
420 sendto_one(source_p, form_str(ERR_SERVICESDOWN),
421 me.name, source_p->name);
422 else
423 {
424 get_string(parc - 1, parv + 1, buf);
425 sendto_one(target_p, ":%s PRIVMSG %s@%s :%s",
426 source_p->name, service, SERVICES_NAME, buf);
427 }
428 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision