ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/contrib/m_services.c
Revision: 812
Committed: Thu Sep 7 09:41:54 2006 UTC (20 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 12041 byte(s)
Log Message:
- Imported contrib/

File Contents

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

Properties

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