]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd). | |
3 | * m_etrace.c: Gives local opers a trace output with added info. | |
4 | * | |
5 | * Copyright (C) 2002-2003 Lee Hardy <lee@leeh.co.uk> | |
6 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions are | |
10 | * met: | |
11 | * | |
12 | * 1.Redistributions of source code must retain the above copyright notice, | |
13 | * this list of conditions and the following disclaimer. | |
14 | * 2.Redistributions in binary form must reproduce the above copyright | |
15 | * notice, this list of conditions and the following disclaimer in the | |
16 | * documentation and/or other materials provided with the distribution. | |
17 | * 3.The name of the author may not be used to endorse or promote products | |
18 | * derived from this software without specific prior written permission. | |
19 | * | |
20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
30 | * POSSIBILITY OF SUCH DAMAGE. | |
31 | */ | |
32 | ||
33 | #include "stdinc.h" | |
34 | #include "class.h" | |
35 | #include "hook.h" | |
36 | #include "client.h" | |
37 | #include "hash.h" | |
38 | #include "hash.h" | |
39 | #include "match.h" | |
40 | #include "ircd.h" | |
41 | #include "numeric.h" | |
42 | #include "s_serv.h" | |
43 | #include "s_conf.h" | |
44 | #include "s_newconf.h" | |
45 | #include "send.h" | |
46 | #include "msg.h" | |
47 | #include "parse.h" | |
48 | #include "modules.h" | |
49 | #include "logger.h" | |
50 | #include "supported.h" | |
51 | ||
52 | static const char etrace_desc[] = | |
53 | "Provides enhanced tracing facilities to opers (ETRACE, CHANTRACE, and MASKTRACE)"; | |
54 | ||
55 | static void mo_etrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
56 | static void me_etrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
57 | static void m_chantrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
58 | static void mo_masktrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
59 | ||
60 | struct Message etrace_msgtab = { | |
61 | "ETRACE", 0, 0, 0, 0, | |
62 | {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, {me_etrace, 0}, {mo_etrace, 0}} | |
63 | }; | |
64 | struct Message chantrace_msgtab = { | |
65 | "CHANTRACE", 0, 0, 0, 0, | |
66 | {mg_ignore, {m_chantrace, 2}, mg_ignore, mg_ignore, mg_ignore, {m_chantrace, 2}} | |
67 | }; | |
68 | struct Message masktrace_msgtab = { | |
69 | "MASKTRACE", 0, 0, 0, 0, | |
70 | {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_masktrace, 2}} | |
71 | }; | |
72 | ||
73 | static int | |
74 | _modinit(void) | |
75 | { | |
76 | add_isupport("ETRACE", isupport_string, ""); | |
77 | ||
78 | return 0; | |
79 | } | |
80 | ||
81 | static void | |
82 | _moddeinit(void) | |
83 | { | |
84 | delete_isupport("ETRACE"); | |
85 | } | |
86 | ||
87 | mapi_clist_av1 etrace_clist[] = { &etrace_msgtab, &chantrace_msgtab, &masktrace_msgtab, NULL }; | |
88 | ||
89 | DECLARE_MODULE_AV2(etrace, _modinit, _moddeinit, etrace_clist, NULL, NULL, NULL, NULL, etrace_desc); | |
90 | ||
91 | static void do_etrace(struct Client *source_p, int ipv4, int ipv6); | |
92 | static void do_etrace_full(struct Client *source_p); | |
93 | static void do_single_etrace(struct Client *source_p, struct Client *target_p); | |
94 | ||
95 | static const char *empty_sockhost = "255.255.255.255"; | |
96 | static const char *spoofed_sockhost = "0"; | |
97 | ||
98 | /* | |
99 | * m_etrace | |
100 | * parv[1] = options [or target] | |
101 | * parv[2] = [target] | |
102 | */ | |
103 | static void | |
104 | mo_etrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
105 | { | |
106 | if(parc > 1 && !EmptyString(parv[1])) | |
107 | { | |
108 | if(!irccmp(parv[1], "-full")) | |
109 | do_etrace_full(source_p); | |
110 | else if(!irccmp(parv[1], "-v6")) | |
111 | do_etrace(source_p, 0, 1); | |
112 | else if(!irccmp(parv[1], "-v4")) | |
113 | do_etrace(source_p, 1, 0); | |
114 | else | |
115 | { | |
116 | struct Client *target_p = find_named_person(parv[1]); | |
117 | ||
118 | if(target_p) | |
119 | { | |
120 | if(!MyClient(target_p)) | |
121 | sendto_one(target_p, ":%s ENCAP %s ETRACE %s", | |
122 | get_id(source_p, target_p), | |
123 | target_p->servptr->name, | |
124 | get_id(target_p, target_p)); | |
125 | else | |
126 | { | |
127 | do_single_etrace(source_p, target_p); | |
128 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), target_p->name); | |
129 | } | |
130 | } | |
131 | else | |
132 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
133 | form_str(ERR_NOSUCHNICK), parv[1]); | |
134 | } | |
135 | } | |
136 | else | |
137 | do_etrace(source_p, 1, 1); | |
138 | } | |
139 | ||
140 | static void | |
141 | me_etrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
142 | { | |
143 | struct Client *target_p; | |
144 | ||
145 | if(!IsOper(source_p) || parc < 2 || EmptyString(parv[1])) | |
146 | return; | |
147 | ||
148 | /* we cant etrace remote clients.. we shouldnt even get sent them */ | |
149 | if((target_p = find_person(parv[1])) && MyClient(target_p)) | |
150 | do_single_etrace(source_p, target_p); | |
151 | ||
152 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), | |
153 | target_p ? target_p->name : parv[1]); | |
154 | } | |
155 | ||
156 | static void | |
157 | do_etrace(struct Client *source_p, int ipv4, int ipv6) | |
158 | { | |
159 | struct Client *target_p; | |
160 | rb_dlink_node *ptr; | |
161 | ||
162 | /* report all direct connections */ | |
163 | RB_DLINK_FOREACH(ptr, lclient_list.head) | |
164 | { | |
165 | target_p = ptr->data; | |
166 | ||
167 | if((!ipv4 && GET_SS_FAMILY(&target_p->localClient->ip) == AF_INET) || | |
168 | (!ipv6 && GET_SS_FAMILY(&target_p->localClient->ip) == AF_INET6)) | |
169 | continue; | |
170 | ||
171 | sendto_one(source_p, form_str(RPL_ETRACE), | |
172 | me.name, source_p->name, | |
173 | SeesOper(target_p, source_p) ? "Oper" : "User", | |
174 | get_client_class(target_p), | |
175 | target_p->name, target_p->username, target_p->host, | |
176 | show_ip(source_p, target_p) ? target_p->sockhost : "255.255.255.255", | |
177 | target_p->info); | |
178 | } | |
179 | ||
180 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); | |
181 | } | |
182 | ||
183 | static void | |
184 | do_etrace_full(struct Client *source_p) | |
185 | { | |
186 | rb_dlink_node *ptr; | |
187 | ||
188 | RB_DLINK_FOREACH(ptr, lclient_list.head) | |
189 | { | |
190 | do_single_etrace(source_p, ptr->data); | |
191 | } | |
192 | ||
193 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); | |
194 | } | |
195 | ||
196 | /* | |
197 | * do_single_etrace - searches local clients and displays those matching | |
198 | * a pattern | |
199 | * input - source client, target client | |
200 | * output - etrace results | |
201 | * side effects - etrace results are displayed | |
202 | */ | |
203 | static void | |
204 | do_single_etrace(struct Client *source_p, struct Client *target_p) | |
205 | { | |
206 | /* note, we hide fullcaps for spoofed users, as mirc can often | |
207 | * advertise its internal ip address in the field --fl | |
208 | */ | |
209 | if(!show_ip(source_p, target_p)) | |
210 | sendto_one(source_p, form_str(RPL_ETRACEFULL), | |
211 | me.name, source_p->name, | |
212 | SeesOper(target_p, source_p) ? "Oper" : "User", | |
213 | get_client_class(target_p), | |
214 | target_p->name, target_p->username, target_p->host, | |
215 | "255.255.255.255", "<hidden> <hidden>", target_p->info); | |
216 | else | |
217 | sendto_one(source_p, form_str(RPL_ETRACEFULL), | |
218 | me.name, source_p->name, | |
219 | SeesOper(target_p, source_p) ? "Oper" : "User", | |
220 | get_client_class(target_p), | |
221 | target_p->name, target_p->username, | |
222 | target_p->host, target_p->sockhost, | |
223 | target_p->localClient->fullcaps, target_p->info); | |
224 | } | |
225 | ||
226 | static void | |
227 | m_chantrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
228 | { | |
229 | struct Client *target_p; | |
230 | struct Channel *chptr; | |
231 | struct membership *msptr; | |
232 | const char *sockhost; | |
233 | const char *name; | |
234 | rb_dlink_node *ptr; | |
235 | int operspy = 0; | |
236 | ||
237 | name = parv[1]; | |
238 | ||
239 | if(IsOperSpy(source_p) && parv[1][0] == '!') | |
240 | { | |
241 | name++; | |
242 | operspy = 1; | |
243 | ||
244 | if(EmptyString(name)) | |
245 | { | |
246 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), | |
247 | me.name, source_p->name, "CHANTRACE"); | |
248 | return; | |
249 | } | |
250 | } | |
251 | ||
252 | if((chptr = find_channel(name)) == NULL) | |
253 | { | |
254 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), | |
255 | name); | |
256 | return; | |
257 | } | |
258 | ||
259 | /* dont report operspys for nonexistant channels. */ | |
260 | if(operspy) | |
261 | report_operspy(source_p, "CHANTRACE", chptr->chname); | |
262 | ||
263 | if(!operspy && !IsMember(client_p, chptr)) | |
264 | { | |
265 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), | |
266 | chptr->chname); | |
267 | return; | |
268 | } | |
269 | ||
270 | RB_DLINK_FOREACH(ptr, chptr->members.head) | |
271 | { | |
272 | msptr = ptr->data; | |
273 | target_p = msptr->client_p; | |
274 | ||
275 | if(EmptyString(target_p->sockhost)) | |
276 | sockhost = empty_sockhost; | |
277 | else if(!show_ip(source_p, target_p)) | |
278 | sockhost = spoofed_sockhost; | |
279 | else | |
280 | sockhost = target_p->sockhost; | |
281 | ||
282 | sendto_one(source_p, form_str(RPL_ETRACE), | |
283 | me.name, source_p->name, | |
284 | SeesOper(target_p, source_p) ? "Oper" : "User", | |
285 | /* class field -- pretend its server.. */ | |
286 | target_p->servptr->name, | |
287 | target_p->name, target_p->username, target_p->host, | |
288 | sockhost, target_p->info); | |
289 | } | |
290 | ||
291 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); | |
292 | } | |
293 | ||
294 | static void | |
295 | match_masktrace(struct Client *source_p, rb_dlink_list *list, | |
296 | const char *username, const char *hostname, const char *name, | |
297 | const char *gecos) | |
298 | { | |
299 | struct Client *target_p; | |
300 | rb_dlink_node *ptr; | |
301 | const char *sockhost; | |
302 | ||
303 | RB_DLINK_FOREACH(ptr, list->head) | |
304 | { | |
305 | target_p = ptr->data; | |
306 | if(!IsPerson(target_p)) | |
307 | continue; | |
308 | ||
309 | if(EmptyString(target_p->sockhost)) | |
310 | sockhost = empty_sockhost; | |
311 | else if(!show_ip(source_p, target_p)) | |
312 | sockhost = spoofed_sockhost; | |
313 | else | |
314 | sockhost = target_p->sockhost; | |
315 | ||
316 | if(match(username, target_p->username) && | |
317 | (match(hostname, target_p->host) || | |
318 | match(hostname, target_p->orighost) || | |
319 | match(hostname, sockhost) || match_ips(hostname, sockhost))) | |
320 | { | |
321 | if(name != NULL && !match(name, target_p->name)) | |
322 | continue; | |
323 | ||
324 | if(gecos != NULL && !match_esc(gecos, target_p->info)) | |
325 | continue; | |
326 | ||
327 | sendto_one(source_p, form_str(RPL_ETRACE), | |
328 | me.name, source_p->name, | |
329 | SeesOper(target_p, source_p) ? "Oper" : "User", | |
330 | /* class field -- pretend its server.. */ | |
331 | target_p->servptr->name, | |
332 | target_p->name, target_p->username, target_p->host, | |
333 | sockhost, target_p->info); | |
334 | } | |
335 | } | |
336 | } | |
337 | ||
338 | static void | |
339 | mo_masktrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, | |
340 | const char *parv[]) | |
341 | { | |
342 | char *name, *username, *hostname, *gecos; | |
343 | ||
344 | name = LOCAL_COPY(parv[1]); | |
345 | collapse(name); | |
346 | ||
347 | if(parc > 2 && !EmptyString(parv[2])) | |
348 | { | |
349 | gecos = LOCAL_COPY(parv[2]); | |
350 | collapse_esc(gecos); | |
351 | } else | |
352 | gecos = NULL; | |
353 | ||
354 | ||
355 | if((hostname = strchr(name, '@')) == NULL) | |
356 | { | |
357 | sendto_one_notice(source_p, ":Invalid parameters"); | |
358 | return; | |
359 | } | |
360 | ||
361 | *hostname++ = '\0'; | |
362 | ||
363 | if((username = strchr(name, '!')) == NULL) | |
364 | { | |
365 | username = name; | |
366 | name = NULL; | |
367 | } else | |
368 | *username++ = '\0'; | |
369 | ||
370 | if(EmptyString(username) || EmptyString(hostname)) | |
371 | { | |
372 | sendto_one_notice(source_p, ":Invalid parameters"); | |
373 | return; | |
374 | } | |
375 | ||
376 | match_masktrace(source_p, &global_client_list, username, hostname, name, gecos); | |
377 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); | |
378 | } |