]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_etrace.c
Log unknown class in auth errors to ircd.log as well.
[irc/rqf/shadowircd.git] / modules / m_etrace.c
CommitLineData
212380e3 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 *
5366977b 32 * $Id: m_etrace.c 3161 2007-01-25 07:23:01Z nenolod $
212380e3 33 */
34
35#include "stdinc.h"
36#include "class.h"
37#include "hook.h"
38#include "client.h"
39#include "hash.h"
40#include "common.h"
41#include "hash.h"
13ae2f4b 42#include "match.h"
212380e3 43#include "ircd.h"
44#include "numeric.h"
212380e3 45#include "s_serv.h"
46#include "s_conf.h"
47#include "s_newconf.h"
48#include "send.h"
49#include "msg.h"
50#include "parse.h"
51#include "modules.h"
52
53static int mo_etrace(struct Client *, struct Client *, int, const char **);
54static int me_etrace(struct Client *, struct Client *, int, const char **);
28823cd3 55static int m_chantrace(struct Client *, struct Client *, int, const char **);
212380e3 56static int mo_masktrace(struct Client *, struct Client *, int, const char **);
57
58struct Message etrace_msgtab = {
59 "ETRACE", 0, 0, 0, MFLG_SLOW,
60 {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, {me_etrace, 0}, {mo_etrace, 0}}
61};
62struct Message chantrace_msgtab = {
63 "CHANTRACE", 0, 0, 0, MFLG_SLOW,
28823cd3 64 {mg_ignore, {m_chantrace, 2}, mg_ignore, mg_ignore, mg_ignore, {m_chantrace, 2}}
212380e3 65};
66struct Message masktrace_msgtab = {
67 "MASKTRACE", 0, 0, 0, MFLG_SLOW,
68 {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_masktrace, 2}}
69};
70
71mapi_clist_av1 etrace_clist[] = { &etrace_msgtab, &chantrace_msgtab, &masktrace_msgtab, NULL };
5366977b 72DECLARE_MODULE_AV1(etrace, NULL, NULL, etrace_clist, NULL, NULL, "$Revision: 3161 $");
212380e3 73
74static void do_etrace(struct Client *source_p, int ipv4, int ipv6);
75static void do_etrace_full(struct Client *source_p);
76static void do_single_etrace(struct Client *source_p, struct Client *target_p);
77
78static const char *empty_sockhost = "255.255.255.255";
79static const char *spoofed_sockhost = "0";
80
81/*
82 * m_etrace
212380e3 83 * parv[1] = options [or target]
84 * parv[2] = [target]
85 */
86static int
87mo_etrace(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
88{
89 if(parc > 1 && !EmptyString(parv[1]))
90 {
91 if(!irccmp(parv[1], "-full"))
92 do_etrace_full(source_p);
2c2e0aa9 93#ifdef RB_IPV6
212380e3 94 else if(!irccmp(parv[1], "-v6"))
95 do_etrace(source_p, 0, 1);
96 else if(!irccmp(parv[1], "-v4"))
97 do_etrace(source_p, 1, 0);
98#endif
99 else
100 {
101 struct Client *target_p = find_named_person(parv[1]);
102
103 if(target_p)
104 {
105 if(!MyClient(target_p))
106 sendto_one(target_p, ":%s ENCAP %s ETRACE %s",
107 get_id(source_p, target_p),
c88cdb00 108 target_p->servptr->name,
212380e3 109 get_id(target_p, target_p));
110 else
111 do_single_etrace(source_p, target_p);
112 }
113 else
114 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
115 form_str(ERR_NOSUCHNICK), parv[1]);
116 }
117 }
118 else
119 do_etrace(source_p, 1, 1);
120
121 return 0;
122}
123
124static int
125me_etrace(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
126{
127 struct Client *target_p;
128
129 if(!IsOper(source_p) || parc < 2 || EmptyString(parv[1]))
130 return 0;
131
132 /* we cant etrace remote clients.. we shouldnt even get sent them */
133 if((target_p = find_person(parv[1])) && MyClient(target_p))
134 do_single_etrace(source_p, target_p);
135
136 sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE),
137 target_p ? target_p->name : parv[1]);
138
139 return 0;
140}
141
142static void
143do_etrace(struct Client *source_p, int ipv4, int ipv6)
144{
145 struct Client *target_p;
08d11e34 146 rb_dlink_node *ptr;
212380e3 147
148 /* report all direct connections */
08d11e34 149 RB_DLINK_FOREACH(ptr, lclient_list.head)
212380e3 150 {
151 target_p = ptr->data;
152
2c2e0aa9 153#ifdef RB_IPV6
212380e3 154 if((!ipv4 && target_p->localClient->ip.ss_family == AF_INET) ||
155 (!ipv6 && target_p->localClient->ip.ss_family == AF_INET6))
156 continue;
157#endif
158
159 sendto_one(source_p, form_str(RPL_ETRACE),
160 me.name, source_p->name,
161 IsOper(target_p) ? "Oper" : "User",
162 get_client_class(target_p),
163 target_p->name, target_p->username, target_p->host,
164 show_ip(source_p, target_p) ? target_p->sockhost : "255.255.255.255",
165 target_p->info);
166 }
167
168 sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name);
169}
170
171static void
172do_etrace_full(struct Client *source_p)
173{
08d11e34 174 rb_dlink_node *ptr;
212380e3 175
08d11e34 176 RB_DLINK_FOREACH(ptr, lclient_list.head)
212380e3 177 {
178 do_single_etrace(source_p, ptr->data);
179 }
180
181 sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name);
182}
183
184/*
185 * do_single_etrace - searches local clients and displays those matching
186 * a pattern
187 * input - source client, target client
188 * output - etrace results
189 * side effects - etrace results are displayed
190 */
191static void
192do_single_etrace(struct Client *source_p, struct Client *target_p)
193{
194 /* note, we hide fullcaps for spoofed users, as mirc can often
195 * advertise its internal ip address in the field --fl
196 */
197 if(!show_ip(source_p, target_p))
198 sendto_one(source_p, form_str(RPL_ETRACEFULL),
199 me.name, source_p->name,
200 IsOper(target_p) ? "Oper" : "User",
201 get_client_class(target_p),
202 target_p->name, target_p->username, target_p->host,
203 "255.255.255.255", "<hidden> <hidden>", target_p->info);
204 else
205 sendto_one(source_p, form_str(RPL_ETRACEFULL),
206 me.name, source_p->name,
207 IsOper(target_p) ? "Oper" : "User",
208 get_client_class(target_p),
209 target_p->name, target_p->username,
210 target_p->host, target_p->sockhost,
211 target_p->localClient->fullcaps, target_p->info);
212}
213
214static int
28823cd3 215m_chantrace(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3 216{
217 struct Client *target_p;
218 struct Channel *chptr;
219 struct membership *msptr;
220 const char *sockhost;
221 const char *name;
08d11e34 222 rb_dlink_node *ptr;
212380e3 223 int operspy = 0;
224
225 name = parv[1];
226
227 if(IsOperSpy(source_p) && parv[1][0] == '!')
228 {
229 name++;
230 operspy = 1;
231
232 if(EmptyString(name))
233 {
234 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
235 me.name, source_p->name, "CHANTRACE");
236 return 0;
237 }
238 }
239
240 if((chptr = find_channel(name)) == NULL)
241 {
242 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL),
243 name);
244 return 0;
245 }
246
247 /* dont report operspys for nonexistant channels. */
248 if(operspy)
249 report_operspy(source_p, "CHANTRACE", chptr->chname);
250
251 if(!operspy && !IsMember(client_p, chptr))
252 {
253 sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL),
254 chptr->chname);
255 return 0;
256 }
257
08d11e34 258 RB_DLINK_FOREACH(ptr, chptr->members.head)
212380e3 259 {
260 msptr = ptr->data;
261 target_p = msptr->client_p;
262
263 if(EmptyString(target_p->sockhost))
264 sockhost = empty_sockhost;
265 else if(!show_ip(source_p, target_p))
266 sockhost = spoofed_sockhost;
267 else
268 sockhost = target_p->sockhost;
269
270 sendto_one(source_p, form_str(RPL_ETRACE),
271 me.name, source_p->name,
272 IsOper(target_p) ? "Oper" : "User",
273 /* class field -- pretend its server.. */
274 target_p->servptr->name,
275 target_p->name, target_p->username, target_p->host,
276 sockhost, target_p->info);
277 }
278
279 sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name);
280 return 0;
281}
282
283static void
08d11e34 284match_masktrace(struct Client *source_p, rb_dlink_list *list,
212380e3 285 const char *username, const char *hostname, const char *name,
286 const char *gecos)
287{
288 struct Client *target_p;
08d11e34 289 rb_dlink_node *ptr;
212380e3 290 const char *sockhost;
291 char *mangle_gecos = NULL;
292
293 if(gecos != NULL)
294 {
295 if(strstr(gecos, "\\s"))
296 {
297 char *tmp = LOCAL_COPY(gecos);
298 char *orig = tmp;
299 char *new = tmp;
300 while(*orig)
301 {
302 if(*orig == '\\' && *(orig + 1) != '\0')
303 {
304 if(*(orig + 1) == 's')
305 {
306 *new++ = ' ';
307 orig += 2;
308 }
309 /* otherwise skip that and the escaped
310 * character after it, so we dont mistake
311 * \\s as \s --fl
312 */
313 else
314 {
315 *new++ = *orig++;
316 *new++ = *orig++;
317 }
318 }
319 else
320 *new++ = *orig++;
321 }
322
323 *new = '\0';
324 mangle_gecos = LOCAL_COPY(tmp);
325 }
326 else
327 mangle_gecos = LOCAL_COPY(gecos);
328 }
329
08d11e34 330 RB_DLINK_FOREACH(ptr, list->head)
212380e3 331 {
332 target_p = ptr->data;
333 if(!IsPerson(target_p))
334 continue;
335
336 if(EmptyString(target_p->sockhost))
337 sockhost = empty_sockhost;
338 else if(!show_ip(source_p, target_p))
339 sockhost = spoofed_sockhost;
340 else
341 sockhost = target_p->sockhost;
342
343 if(match(username, target_p->username) &&
344 (match(hostname, target_p->host) ||
345 match(hostname, target_p->orighost) ||
346 match(hostname, sockhost) || match_ips(hostname, sockhost)))
347 {
348 if(name != NULL && !match(name, target_p->name))
349 continue;
350
351 if(mangle_gecos != NULL && !match_esc(mangle_gecos, target_p->info))
352 continue;
353
354 sendto_one(source_p, form_str(RPL_ETRACE),
355 me.name, source_p->name,
356 IsOper(target_p) ? "Oper" : "User",
357 /* class field -- pretend its server.. */
358 target_p->servptr->name,
359 target_p->name, target_p->username, target_p->host,
360 sockhost, target_p->info);
361 }
362 }
363}
364
365static int
366mo_masktrace(struct Client *client_p, struct Client *source_p, int parc,
367 const char *parv[])
368{
369 char *name, *username, *hostname, *gecos;
370 const char *mask;
371 int operspy = 0;
372
373 mask = parv[1];
374 name = LOCAL_COPY(parv[1]);
375 collapse(name);
376
377 if(IsOperSpy(source_p) && parv[1][0] == '!')
378 {
379 name++;
380 mask++;
381 operspy = 1;
382 }
383
384 if(parc > 2 && !EmptyString(parv[2]))
385 {
386 gecos = LOCAL_COPY(parv[2]);
387 collapse_esc(gecos);
388 } else
389 gecos = NULL;
390
391
392 if((hostname = strchr(name, '@')) == NULL)
393 {
5366977b 394 sendto_one_notice(source_p, ":Invalid parameters");
212380e3 395 return 0;
396 }
397
398 *hostname++ = '\0';
399
400 if((username = strchr(name, '!')) == NULL)
401 {
402 username = name;
403 name = NULL;
404 } else
405 *username++ = '\0';
406
407 if(EmptyString(username) || EmptyString(hostname))
408 {
5366977b 409 sendto_one_notice(source_p, ":Invalid parameters");
212380e3 410 return 0;
411 }
412
413 if(operspy) {
414 if (!ConfigFileEntry.operspy_dont_care_user_info)
415 {
416 char buf[512];
907468c4 417 rb_strlcpy(buf, mask, sizeof(buf));
212380e3 418 if(!EmptyString(gecos)) {
a64c5173
VY
419 rb_strlcat(buf, " ", sizeof(buf));
420 rb_strlcat(buf, gecos, sizeof(buf));
212380e3 421 }
422
423 report_operspy(source_p, "MASKTRACE", buf);
424 }
425 match_masktrace(source_p, &global_client_list, username, hostname, name, gecos);
426 } else
427 match_masktrace(source_p, &lclient_list, username, hostname, name, gecos);
428
429 sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name);
430 return 0;
431}