ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/contrib/m_capture.c
Revision: 34
Committed: Sun Oct 2 21:05:51 2005 UTC (18 years, 5 months ago) by lusky
Content type: text/x-csrc
File size: 7454 byte(s)
Log Message:
create 7.2 branch, we can move/rename it as needed.


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

Properties

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