ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/contrib/m_services.c
Revision: 914
Committed: Wed Nov 7 23:40:08 2007 UTC (16 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 12384 byte(s)
Log Message:
- Autotoolized contrib/ and made it compile cleanly

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 #ifndef STATIC_MODULES
188 void
189 _modinit(void)
190 {
191 mod_add_cmd(&svsnick_msgtab);
192 mod_add_cmd(&botserv_msgtab);
193 mod_add_cmd(&chanserv_msgtab);
194 mod_add_cmd(&global_msgtab);
195 mod_add_cmd(&helpserv_msgtab);
196 mod_add_cmd(&hostserv_msgtab);
197 mod_add_cmd(&identify_msgtab);
198 mod_add_cmd(&memoserv_msgtab);
199 mod_add_cmd(&nickserv_msgtab);
200 mod_add_cmd(&operserv_msgtab);
201 mod_add_cmd(&seenserv_msgtab);
202 mod_add_cmd(&statserv_msgtab);
203 mod_add_cmd(&bs_msgtab);
204 mod_add_cmd(&ns_msgtab);
205 mod_add_cmd(&cs_msgtab);
206 mod_add_cmd(&ms_msgtab);
207 mod_add_cmd(&os_msgtab);
208 }
209
210 void
211 _moddeinit(void)
212 {
213 mod_del_cmd(&svsnick_msgtab);
214 mod_del_cmd(&botserv_msgtab);
215 mod_del_cmd(&chanserv_msgtab);
216 mod_del_cmd(&global_msgtab);
217 mod_del_cmd(&helpserv_msgtab);
218 mod_del_cmd(&hostserv_msgtab);
219 mod_del_cmd(&identify_msgtab);
220 mod_del_cmd(&memoserv_msgtab);
221 mod_del_cmd(&nickserv_msgtab);
222 mod_del_cmd(&operserv_msgtab);
223 mod_del_cmd(&seenserv_msgtab);
224 mod_del_cmd(&statserv_msgtab);
225 mod_del_cmd(&bs_msgtab);
226 mod_del_cmd(&ns_msgtab);
227 mod_del_cmd(&cs_msgtab);
228 mod_del_cmd(&ms_msgtab);
229 mod_del_cmd(&os_msgtab);
230 }
231
232 const char *_version = "$Revision$";
233 #endif
234
235 /*
236 * mo_svsnick()
237 *
238 * parv[0] = sender prefix
239 * parv[1] = user to force
240 * parv[2] = nick to force them to
241 */
242 static void
243 mo_svsnick(struct Client *client_p, struct Client *source_p,
244 int parc, char *parv[])
245 {
246 char newnick[NICKLEN];
247 struct Client *target_p = NULL;
248
249 if (MyClient(source_p) && !IsOperAdmin(source_p))
250 {
251 sendto_one(source_p, form_str(ERR_NOPRIVS),
252 me.name, parv[0], "SVSNICK");
253 return;
254 }
255
256 if (parc < 3 || *parv[2] == '\0')
257 {
258 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
259 me.name, parv[0], "SVSNICK");
260 return;
261 }
262
263 if ((target_p = find_person(client_p, parv[1])) == NULL)
264 {
265 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
266 me.name, parv[0], parv[1]);
267 return;
268 }
269
270 /* terminate nick to NICKLEN */
271 strlcpy(newnick, parv[2], sizeof(newnick));
272
273 if (!clean_nick_name(newnick, 1))
274 {
275 if (IsClient(source_p))
276 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- Invalid new ",
277 "nickname: %s", me.name, parv[0], newnick);
278 return;
279 }
280
281 if (find_client(newnick) != NULL)
282 {
283 if (IsClient(source_p))
284 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- Nickname %s is "
285 "already in use", me.name, parv[0], newnick);
286 return;
287 }
288
289 if (MyConnect(target_p))
290 change_local_nick(&me, target_p, newnick);
291 else
292 sendto_one(target_p, ":%s ENCAP %s SVSNICK %s %s",
293 me.name, target_p->servptr->name, ID(target_p), newnick);
294 }
295
296 /*
297 * These generate the services functions through
298 * a macro.
299 */
300 services_function(m_botserv, "BotServ", "BOTSERV" )
301 services_function(m_chanserv, "ChanServ", "CHANSERV")
302 services_function(m_global, "Global", "GLOBAL" )
303 services_function(m_helpserv, "HelpServ", "HELPSERV")
304 services_function(m_hostserv, "HostServ", "HOSTSERV")
305 services_function(m_memoserv, "MemoServ", "MEMOSERV")
306 services_function(m_nickserv, "NickServ", "NICKSERV")
307 services_function(m_operserv, "OperServ", "OPERSERV")
308 services_function(m_seenserv, "SeenServ", "SEENSERV")
309 services_function(m_statserv, "StatServ", "STATSERV")
310
311 /*
312 * get_string()
313 *
314 * Reverse the array parv back into a normal string assuming
315 * there are "parc" indicies in the array.
316 *
317 * Originally GetString() written by sidewndr.
318 * Modified by Michael for use with hybrid-7.
319 */
320 static void
321 get_string(int parc, char *parv[], char *buf)
322 {
323 int ii = 0;
324 int bw = 0;
325
326 for (; ii < parc; ++ii)
327 bw += ircsprintf(buf+bw, "%s ", parv[ii]);
328 buf[bw-1] = '\0';
329 }
330
331 /*
332 * clean_nick_name()
333 *
334 * input - nickname
335 * output - none
336 * side effects - walks through the nickname, returning 0 if erroneous
337 */
338 static int
339 clean_nick_name(char *nick, int local)
340 {
341 assert(nick);
342
343 /* nicks can't start with a digit or - or be 0 length */
344 /* This closer duplicates behaviour of hybrid-6 */
345
346 if (*nick == '-' || (IsDigit(*nick) && local) || *nick == '\0')
347 return 0;
348
349 for (; *nick; ++nick)
350 if (!IsNickChar(*nick))
351 return 0;
352
353 return 1;
354 }
355
356 /*
357 * m_identify()
358 *
359 * parv[0] = sender prefix
360 * parv[1] = NickServ Password or Channel
361 * parv[2] = ChanServ Password
362 */
363 static void
364 m_identify(struct Client *client_p, struct Client *source_p,
365 int parc, char *parv[])
366 {
367 struct Client *target_p = NULL;
368
369 switch (parc)
370 {
371 case 2:
372 if (!(target_p = find_server(SERVICES_NAME)))
373 sendto_one(source_p, form_str(ERR_SERVICESDOWN),
374 me.name, source_p->name);
375 else
376 sendto_one(target_p, ":%s PRIVMSG NickServ@%s :IDENTIFY %s",
377 source_p->name, SERVICES_NAME, parv[1]);
378 break;
379
380 case 3:
381 if (!(target_p = find_server(SERVICES_NAME)))
382 sendto_one(source_p, form_str(ERR_SERVICESDOWN),
383 me.name, source_p->name);
384 else
385 sendto_one(target_p, ":%s PRIVMSG ChanServ@%s :IDENTIFY %s %s",
386 source_p->name, SERVICES_NAME, parv[1], parv[2]);
387 break;
388
389 default:
390 sendto_one(source_p, ":%s NOTICE %s :Syntax: IDENTIFY <password> "
391 "- for nickname", me.name, source_p->name);
392 sendto_one(source_p, ":%s NOTICE %s :Syntax: IDENTIFY <channel> "
393 "<password> - for channel", me.name, source_p->name);
394 break;
395 }
396 }
397
398 /*
399 * deliver_services_msg()
400 *
401 * parv[0] = sender prefix
402 * servmsg = message for services (utilising GetString())
403 *
404 * Borrowed from HybServ -- knight-
405 */
406 static void
407 deliver_services_msg(const char *service, const char *command,
408 struct Client *client_p,
409 struct Client *source_p, int parc, char *parv[])
410 {
411 struct Client *target_p = NULL;
412 char buf[IRCD_BUFSIZE] = { '\0' };
413
414 if (parc < 2 || *parv[1] == '\0')
415 {
416 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
417 me.name, source_p->name, command);
418 return;
419 }
420
421 if (!(target_p = find_server(SERVICES_NAME)))
422 sendto_one(source_p, form_str(ERR_SERVICESDOWN),
423 me.name, source_p->name);
424 else
425 {
426 get_string(parc - 1, parv + 1, buf);
427 sendto_one(target_p, ":%s PRIVMSG %s@%s :%s",
428 source_p->name, service, SERVICES_NAME, buf);
429 }
430 }

Properties

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