ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/m_capture.c
Revision: 1155
Committed: Tue Aug 9 20:27:45 2011 UTC (14 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 7348 byte(s)
Log Message:
- recreate "trunk"

File Contents

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

Properties

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