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