ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/m_capture.c
Revision: 1028
Committed: Sun Nov 8 13:03:38 2009 UTC (16 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 7378 byte(s)
Log Message:
- move ircd-hybrid-7.2 to trunk

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

Properties

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