ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/m_capture.c
Revision: 113
Committed: Wed Oct 12 14:50:01 2005 UTC (20 years, 9 months ago) by knight
Content type: text/x-csrc
File size: 7375 byte(s)
Log Message:
- Fix another valid_wild_card() implicit

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_capture.c: Makes a designated client captive
4     *
5     * Copyright (C) 2002 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 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "common.h"
27     #include "handlers.h"
28     #include "client.h"
29     #include "hash.h"
30     #include "channel.h"
31     #include "channel_mode.h"
32     #include "hash.h"
33     #include "ircd.h"
34     #include "numeric.h"
35     #include "s_conf.h"
36     #include "s_serv.h"
37     #include "send.h"
38     #include "msg.h"
39     #include "parse.h"
40     #include "modules.h"
41 knight 113 #include "parse_aline.h"
42 adx 30
43     static void mo_capture(struct Client *, struct Client *, int, char *[]);
44     static void mo_uncapture(struct Client *, struct Client *, int, char *[]);
45    
46     struct Message capture_msgtab = {
47     "CAPTURE", 0, 0, 0, 0, MFLG_SLOW, 0,
48     {m_unregistered, m_ignore, mo_capture, mo_capture, mo_capture, m_ignore}
49     };
50    
51     struct Message uncapture_msgtab = {
52     "UNCAPTURE", 0, 0, 0, 0, MFLG_SLOW, 0,
53     {m_unregistered, m_ignore, mo_uncapture, mo_uncapture, mo_uncapture, m_ignore}
54     };
55    
56     #ifndef STATIC_MODULES
57     void
58     _modinit(void)
59     {
60     mod_add_cmd(&capture_msgtab);
61     mod_add_cmd(&uncapture_msgtab);
62     }
63    
64     void
65     _moddeinit(void)
66     {
67     mod_del_cmd(&capture_msgtab);
68     mod_del_cmd(&uncapture_msgtab);
69     }
70    
71 knight 31 const char *_version = "$Revision$";
72 adx 30 #endif
73    
74     /* mo_capture
75     * parv[0] = sender prefix
76     * parv[1] = nickname masklist
77     */
78     static void
79     mo_capture(struct Client *client_p, struct Client *source_p,
80     int parc, char *parv[])
81     {
82     struct Client *target_p = NULL;
83     char *nick = NULL, *user = NULL, *host = NULL;
84     char *p = NULL;
85     dlink_node *ptr = NULL;
86    
87     if (parc < 2 || EmptyString(parv[1]))
88     {
89     sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
90     me.name, source_p->name);
91     return;
92     }
93    
94     /* XXX Add oper flag in future ? */
95    
96     if (MyClient(source_p) && !IsAdmin(source_p))
97     {
98     sendto_one(source_p, form_str(ERR_NOPRIVS),
99     me.name, source_p->name, "CAPTURE");
100     return;
101     }
102    
103     if ((p = strchr(parv[1], '@')) == NULL)
104     {
105     if ((target_p = find_client(parv[1])) != NULL && IsClient(target_p))
106     {
107     if (MyConnect(target_p) && source_p != target_p)
108     {
109     if (IsOper(target_p))
110     {
111     sendto_one(source_p, form_str(ERR_NOPRIVS),
112     me.name, source_p->name, "CAPTURE");
113     return;
114     }
115    
116     if (!IsCaptured(target_p))
117     {
118     sendto_realops_flags(UMODE_ALL, L_ALL, "Captured %s (%s@%s)",
119     target_p->name, target_p->username,
120     target_p->host);
121     SetCaptured(target_p);
122     }
123    
124     sendto_one(source_p, form_str(RPL_ISCAPTURED),
125     me.name, source_p->name, target_p->name);
126     }
127     else if (IsCapable(target_p->from, CAP_ENCAP))
128     sendto_one(target_p, ":%s ENCAP %s CAPTURE %s",
129     source_p->name, target_p->from->name, target_p->name);
130     }
131     else
132     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
133     me.name, source_p->name, parv[1]);
134     }
135     else
136     {
137     unsigned int matches = 0;
138    
139     /* p != NULL so user @ host given */
140     nick = parv[1];
141     *p++ = '\0';
142     host = p;
143    
144     if ((p = strchr(nick, '!')) != NULL)
145     {
146     *p++ = '\0';
147     user = p;
148     }
149     else
150     {
151     user = nick;
152     nick = "*";
153     }
154    
155     if (!valid_wild_card(source_p, YES, 3, nick, user, host))
156     return;
157    
158     if (IsClient(client_p))
159     sendto_server(client_p, NULL, NULL, CAP_ENCAP, 0, 0,
160     ":%s ENCAP * CAPTURE %s!%s@%s",
161     source_p->name, nick, user, host);
162    
163     DLINK_FOREACH(ptr, local_client_list.head)
164     {
165     target_p = ptr->data;
166    
167     if ((source_p == target_p) || IsOper(target_p) || IsCaptured(target_p))
168     continue;
169    
170     if (match(nick, target_p->name) &&
171     match(host, target_p->host) && match(user, target_p->username))
172     {
173     SetCaptured(target_p);
174     ++matches;
175     }
176     }
177    
178     sendto_realops_flags(UMODE_ALL, L_ALL,
179     "Bulk captured %s!%s@%s, %u local match(es)",
180     nick, user, host, matches);
181     }
182     }
183    
184     /* mo_uncapture
185     * parv[0] = sender prefix
186     * parv[1] = nickname masklist
187     */
188     static void
189     mo_uncapture(struct Client *client_p, struct Client *source_p,
190     int parc, char *parv[])
191     {
192     struct Client *target_p = NULL;
193     char *nick = NULL, *user = NULL, *host = NULL, *p = NULL;
194     dlink_node *ptr = NULL;
195    
196     if (MyClient(source_p) && !IsAdmin(source_p))
197     {
198     sendto_one(source_p, form_str(ERR_NOPRIVS),
199     me.name, source_p->name, "CAPTURE");
200     return;
201     }
202    
203     if (parc < 2 || EmptyString(parv[1]))
204     {
205     sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
206     me.name, source_p->name);
207     return;
208     }
209    
210     if ((p = strchr(parv[1], '@')) == NULL)
211     {
212     if ((target_p = find_client(parv[1])) != NULL && IsClient(target_p))
213     {
214     if (MyConnect(target_p))
215     {
216     if (IsCaptured(target_p))
217     {
218     ClearCaptured(target_p);
219    
220     sendto_realops_flags(UMODE_ALL, L_ALL, "Uncaptured %s (%s@%s)",
221     target_p->name, target_p->username,
222     target_p->host);
223     }
224    
225     sendto_one(source_p, form_str(RPL_ISUNCAPTURED),
226     me.name, source_p->name, target_p->name);
227     }
228     else if (IsCapable(target_p->from, CAP_ENCAP))
229     sendto_one(target_p, ":%s ENCAP %s UNCAPTURE %s",
230     source_p->name, target_p->from->name, target_p->name);
231     }
232     else
233     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
234     me.name, source_p->name, parv[1]);
235     }
236     else
237     {
238     unsigned int matches = 0;
239    
240     /* p != NULL so user @ host given */
241     nick = parv[1];
242     *p++ = '\0';
243     host = p;
244    
245     if ((p = strchr(nick, '!')) != NULL)
246     {
247     *p++ = '\0';
248     user = p;
249     }
250     else
251     {
252     user = nick;
253     nick = "*";
254     }
255    
256     if (IsClient(client_p))
257     sendto_server(client_p, NULL, NULL, CAP_ENCAP, 0, 0,
258     ":%s ENCAP * UNCAPTURE %s!%s@%s",
259     source_p->name, nick, user, host);
260    
261     DLINK_FOREACH(ptr, local_client_list.head)
262     {
263     target_p = ptr->data;
264    
265     if (!IsCaptured(target_p))
266     continue;
267    
268     if (match(nick, target_p->name) &&
269     match(host, target_p->host) && match(user, target_p->username))
270     {
271     ClearCaptured(target_p);
272     ++matches;
273     }
274     }
275    
276     sendto_realops_flags(UMODE_ALL, L_ALL,
277     "Bulk uncaptured %s!%s@%s, %u local match(es)",
278     nick, user, host, matches);
279     }
280     }

Properties

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