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

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

Properties

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