1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
< |
* m_trace.c: Traces a path to a client/server. |
2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
4 |
> |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
* USA |
20 |
< |
* |
21 |
< |
* $Id$ |
20 |
> |
*/ |
21 |
> |
|
22 |
> |
/*! \file m_trace.c |
23 |
> |
* \brief Includes required functions for processing the TRACE command. |
24 |
> |
* \version $Id$ |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
37 |
|
#include "parse.h" |
38 |
|
#include "modules.h" |
39 |
|
#include "conf.h" |
40 |
+ |
#include "conf_class.h" |
41 |
|
|
42 |
|
|
43 |
|
static void do_actual_trace(struct Client *, int, char *[]); |
44 |
|
static void report_this_status(struct Client *, struct Client *, int); |
45 |
|
|
46 |
|
static void |
47 |
< |
trace_get_dependent(int *const server, |
48 |
< |
int *const client, const struct Client *target_p) |
47 |
> |
trace_get_dependent(unsigned int *const server, |
48 |
> |
unsigned int *const client, const struct Client *target_p) |
49 |
|
{ |
50 |
|
const dlink_node *ptr = NULL; |
51 |
|
|
62 |
|
* parv[0] = sender prefix |
63 |
|
* parv[1] = target client/server to trace |
64 |
|
*/ |
65 |
< |
static void |
65 |
> |
static int |
66 |
|
m_trace(struct Client *client_p, struct Client *source_p, |
67 |
|
int parc, char *parv[]) |
68 |
|
{ |
69 |
< |
const char *tname; |
69 |
> |
const char *tname = NULL; |
70 |
|
|
71 |
|
if (parc > 1) |
72 |
|
tname = parv[1]; |
75 |
|
|
76 |
|
sendto_one(source_p, form_str(RPL_ENDOFTRACE), |
77 |
|
me.name, source_p->name, tname); |
78 |
+ |
return 0; |
79 |
|
} |
80 |
|
|
77 |
– |
|
81 |
|
/* mo_trace() |
82 |
|
* parv[0] = sender prefix |
83 |
|
* parv[1] = servername |
84 |
|
*/ |
85 |
< |
static void |
85 |
> |
static int |
86 |
|
mo_trace(struct Client *client_p, struct Client *source_p, |
87 |
|
int parc, char *parv[]) |
88 |
|
{ |
91 |
|
const char *from, *to; |
92 |
|
|
93 |
|
if (parc > 2) |
94 |
< |
if (hunt_server(client_p, source_p, ":%s TRACE %s :%s", 2, parc, parv)) |
95 |
< |
return; |
94 |
> |
if (hunt_server(client_p, source_p, ":%s TRACE %s :%s", 2, parc, parv) != HUNTED_ISME) |
95 |
> |
return 0; |
96 |
|
|
97 |
|
if (parc > 1) |
98 |
|
tname = parv[1]; |
122 |
|
{ |
123 |
|
ac2ptr = ptr->data; |
124 |
|
|
125 |
< |
if (match(tname, ac2ptr->name)) |
125 |
> |
if (!match(tname, ac2ptr->name)) |
126 |
|
break; |
127 |
|
else |
128 |
|
ac2ptr = NULL; |
135 |
|
else |
136 |
|
sendto_one(source_p, form_str(RPL_TRACELINK), from, to, |
137 |
|
ircd_version, tname, "ac2ptr_is_NULL!!"); |
138 |
< |
return; |
138 |
> |
return 0; |
139 |
|
} |
140 |
|
|
141 |
|
case HUNTED_ISME: |
142 |
|
do_actual_trace(source_p, parc, parv); |
143 |
|
break; |
144 |
|
default: |
145 |
< |
return; |
145 |
> |
return 0; |
146 |
|
} |
147 |
+ |
|
148 |
+ |
return 0; |
149 |
|
} |
150 |
|
|
151 |
|
/* |
153 |
|
** parv[0] = sender prefix |
154 |
|
** parv[1] = servername |
155 |
|
*/ |
156 |
< |
static void |
156 |
> |
static int |
157 |
|
ms_trace(struct Client *client_p, struct Client *source_p, |
158 |
|
int parc, char *parv[]) |
159 |
|
{ |
160 |
< |
if (hunt_server(client_p, source_p, ":%s TRACE %s :%s", 2, parc, parv)) |
161 |
< |
return; |
160 |
> |
if (hunt_server(client_p, source_p, ":%s TRACE %s :%s", |
161 |
> |
2, parc, parv) != HUNTED_ISME) |
162 |
> |
return 0; |
163 |
|
|
164 |
|
if (HasUMode(source_p, UMODE_OPER)) |
165 |
|
mo_trace(client_p, source_p, parc, parv); |
166 |
+ |
return 0; |
167 |
|
} |
168 |
|
|
169 |
|
static void |
170 |
|
do_actual_trace(struct Client *source_p, int parc, char *parv[]) |
171 |
|
{ |
172 |
|
struct Client *target_p = NULL; |
166 |
– |
struct ConfItem *conf; |
167 |
– |
struct ClassItem *cltmp; |
173 |
|
int doall = 0; |
174 |
|
int wilds, dow; |
175 |
|
dlink_node *ptr; |
196 |
|
source_p->name, source_p->username, |
197 |
|
source_p->host, source_p->servptr->name); |
198 |
|
|
199 |
< |
if (match(tname, me.name)) |
199 |
> |
if (!match(tname, me.name)) |
200 |
|
doall = 1; |
201 |
|
else if (!MyClient(source_p) && !strcmp(tname, me.id)) |
202 |
|
{ |
212 |
|
/* lets also do this for opers tracing nicks */ |
213 |
|
{ |
214 |
|
const char *name; |
210 |
– |
const char *class_name; |
211 |
– |
|
215 |
|
target_p = hash_find_client(tname); |
216 |
< |
|
217 |
< |
if (target_p && IsClient(target_p)) |
216 |
> |
|
217 |
> |
if (target_p && IsClient(target_p)) |
218 |
|
{ |
219 |
|
name = get_client_name(target_p, HIDE_IP); |
217 |
– |
class_name = get_client_class(target_p); |
220 |
|
|
221 |
|
if (HasUMode(target_p, UMODE_OPER)) |
222 |
|
{ |
223 |
|
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
224 |
< |
from, to, class_name, name, |
224 |
> |
from, to, get_client_class(&target_p->localClient->confs), name, |
225 |
|
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
226 |
|
CurrentTime - target_p->localClient->lasttime, |
227 |
< |
CurrentTime - target_p->localClient->last_privmsg); |
227 |
> |
idle_time_get(source_p, target_p)); |
228 |
|
} |
229 |
|
else |
230 |
|
{ |
231 |
|
sendto_one(source_p,form_str(RPL_TRACEUSER), |
232 |
< |
from, to, class_name, name, |
233 |
< |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
232 |
> |
from, to, get_client_class(&target_p->localClient->confs), name, |
233 |
> |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
234 |
|
CurrentTime - target_p->localClient->lasttime, |
235 |
< |
CurrentTime - target_p->localClient->last_privmsg); |
235 |
> |
idle_time_get(source_p, target_p)); |
236 |
|
} |
237 |
|
} |
238 |
< |
|
238 |
> |
|
239 |
|
sendto_one(source_p, form_str(RPL_ENDOFTRACE), |
240 |
|
from, to, tname); |
241 |
|
return; |
247 |
|
target_p = ptr->data; |
248 |
|
|
249 |
|
if (HasUMode(target_p, UMODE_INVISIBLE) && dow && |
250 |
< |
!(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) && |
251 |
< |
!HasUMode(target_p, UMODE_OPER) && (target_p != source_p)) |
250 |
> |
!(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) && |
251 |
> |
!HasUMode(target_p, UMODE_OPER) && (target_p != source_p)) |
252 |
|
continue; |
253 |
< |
if (!doall && wilds && !match(tname, target_p->name)) |
253 |
> |
if (!doall && wilds && match(tname, target_p->name)) |
254 |
|
continue; |
255 |
|
if (!dow && irccmp(tname, target_p->name)) |
256 |
|
continue; |
262 |
|
{ |
263 |
|
target_p = ptr->data; |
264 |
|
|
265 |
< |
if (!doall && wilds && !match(tname, target_p->name)) |
265 |
> |
if (!doall && wilds && match(tname, target_p->name)) |
266 |
|
continue; |
267 |
|
if (!dow && irccmp(tname, target_p->name)) |
268 |
|
continue; |
275 |
|
{ |
276 |
|
target_p = ptr->data; |
277 |
|
|
278 |
< |
if (!doall && wilds && !match(tname, target_p->name)) |
278 |
> |
if (!doall && wilds && match(tname, target_p->name)) |
279 |
|
continue; |
280 |
|
if (!dow && irccmp(tname, target_p->name)) |
281 |
|
continue; |
283 |
|
report_this_status(source_p, target_p, dow); |
284 |
|
} |
285 |
|
|
286 |
< |
DLINK_FOREACH(ptr, class_items.head) |
286 |
> |
DLINK_FOREACH(ptr, class_get_list()->head) |
287 |
|
{ |
288 |
< |
conf = ptr->data; |
287 |
< |
cltmp = map_to_conf(conf); |
288 |
> |
const struct ClassItem *class = ptr->data; |
289 |
|
|
290 |
< |
if (cltmp->curr_user_count > 0) |
290 |
> |
if (class->ref_count > 0) |
291 |
|
sendto_one(source_p, form_str(RPL_TRACECLASS), |
292 |
< |
from, to, conf->name, cltmp->curr_user_count); |
292 |
> |
from, to, class->name, class->ref_count); |
293 |
|
} |
294 |
|
|
295 |
|
sendto_one(source_p, form_str(RPL_ENDOFTRACE), from, to, tname); |
321 |
|
} |
322 |
|
|
323 |
|
name = get_client_name(target_p, HIDE_IP); |
324 |
< |
class_name = get_client_class(target_p); |
324 |
> |
class_name = get_client_class(&target_p->localClient->confs); |
325 |
|
|
326 |
|
set_time(); |
327 |
|
|
329 |
|
{ |
330 |
|
case STAT_CONNECTING: |
331 |
|
sendto_one(source_p, form_str(RPL_TRACECONNECTING), |
332 |
< |
from, to, class_name, |
333 |
< |
HasUMode(source_p, UMODE_ADMIN) ? name : target_p->name); |
332 |
> |
from, to, class_name, |
333 |
> |
HasUMode(source_p, UMODE_ADMIN) ? name : target_p->name); |
334 |
|
break; |
335 |
|
case STAT_HANDSHAKE: |
336 |
|
sendto_one(source_p, form_str(RPL_TRACEHANDSHAKE), |
337 |
< |
from, to, class_name, |
337 |
> |
from, to, class_name, |
338 |
|
HasUMode(source_p, UMODE_ADMIN) ? name : target_p->name); |
339 |
|
break; |
340 |
|
case STAT_ME: |
342 |
|
case STAT_UNKNOWN: |
343 |
|
/* added time -Taner */ |
344 |
|
sendto_one(source_p, form_str(RPL_TRACEUNKNOWN), |
345 |
< |
from, to, class_name, name, target_p->sockhost, |
346 |
< |
target_p->localClient->firsttime ? /* TBD: can't be 0 */ |
346 |
< |
CurrentTime - target_p->localClient->firsttime : -1); |
345 |
> |
from, to, class_name, name, target_p->sockhost, |
346 |
> |
CurrentTime - target_p->localClient->firsttime); |
347 |
|
break; |
348 |
|
case STAT_CLIENT: |
349 |
|
/* |
351 |
|
* but anyone can see all the opers. |
352 |
|
*/ |
353 |
|
if ((HasUMode(source_p, UMODE_OPER) && |
354 |
< |
(MyClient(source_p) || !(dow && HasUMode(target_p, UMODE_INVISIBLE)))) |
355 |
< |
|| !dow || HasUMode(target_p, UMODE_OPER)) |
356 |
< |
{ |
354 |
> |
(MyClient(source_p) || !(dow && HasUMode(target_p, UMODE_INVISIBLE)))) |
355 |
> |
|| !dow || HasUMode(target_p, UMODE_OPER)) |
356 |
> |
{ |
357 |
|
if (HasUMode(target_p, UMODE_ADMIN) && !ConfigFileEntry.hide_spoof_ips) |
358 |
< |
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
358 |
> |
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
359 |
|
from, to, class_name, name, |
360 |
|
HasUMode(source_p, UMODE_ADMIN) ? target_p->sockhost : "255.255.255.255", |
361 |
|
CurrentTime - target_p->localClient->lasttime, |
362 |
< |
CurrentTime - target_p->localClient->last_privmsg); |
363 |
< |
|
364 |
< |
else if (HasUMode(target_p, UMODE_OPER)) |
362 |
> |
idle_time_get(source_p, target_p)); |
363 |
> |
|
364 |
> |
else if (HasUMode(target_p, UMODE_OPER)) |
365 |
|
{ |
366 |
< |
if (ConfigFileEntry.hide_spoof_ips) |
367 |
< |
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
368 |
< |
from, to, class_name, name, |
369 |
< |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
370 |
< |
CurrentTime - target_p->localClient->lasttime, |
371 |
< |
CurrentTime - target_p->localClient->last_privmsg); |
372 |
< |
else |
366 |
> |
if (ConfigFileEntry.hide_spoof_ips) |
367 |
> |
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
368 |
> |
from, to, class_name, name, |
369 |
> |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
370 |
> |
CurrentTime - target_p->localClient->lasttime, |
371 |
> |
idle_time_get(source_p, target_p)); |
372 |
> |
else |
373 |
|
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
374 |
|
from, to, class_name, name, |
375 |
|
MyOper(source_p) ? target_p->sockhost : |
376 |
|
(IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost), |
377 |
|
CurrentTime - target_p->localClient->lasttime, |
378 |
< |
CurrentTime - target_p->localClient->last_privmsg); |
379 |
< |
} |
380 |
< |
else |
378 |
> |
idle_time_get(source_p, target_p)); |
379 |
> |
} |
380 |
> |
else |
381 |
|
{ |
382 |
|
if (ConfigFileEntry.hide_spoof_ips) |
383 |
< |
sendto_one(source_p, form_str(RPL_TRACEUSER), |
384 |
< |
from, to, class_name, name, |
383 |
> |
sendto_one(source_p, form_str(RPL_TRACEUSER), |
384 |
> |
from, to, class_name, name, |
385 |
|
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
386 |
< |
CurrentTime - target_p->localClient->lasttime, |
387 |
< |
CurrentTime - target_p->localClient->last_privmsg); |
388 |
< |
else |
386 |
> |
CurrentTime - target_p->localClient->lasttime, |
387 |
> |
idle_time_get(source_p, target_p)); |
388 |
> |
else |
389 |
|
sendto_one(source_p, form_str(RPL_TRACEUSER), |
390 |
|
from, to, class_name, name, |
391 |
|
MyOper(source_p) ? target_p->sockhost : |
392 |
|
(IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost), |
393 |
|
CurrentTime - target_p->localClient->lasttime, |
394 |
< |
CurrentTime - target_p->localClient->last_privmsg); |
395 |
< |
} |
396 |
< |
} |
394 |
> |
idle_time_get(source_p, target_p)); |
395 |
> |
} |
396 |
> |
} |
397 |
|
break; |
398 |
|
case STAT_SERVER: |
399 |
|
{ |
400 |
< |
int clients = 0; |
401 |
< |
int servers = 0; |
400 |
> |
unsigned int clients = 0; |
401 |
> |
unsigned int servers = 0; |
402 |
|
|
403 |
|
trace_get_dependent(&servers, &clients, target_p); |
404 |
|
|
406 |
|
name = get_client_name(target_p, MASK_IP); |
407 |
|
|
408 |
|
sendto_one(source_p, form_str(RPL_TRACESERVER), |
409 |
< |
from, to, class_name, servers, |
410 |
< |
clients, name, *(target_p->serv->by) ? |
411 |
< |
target_p->serv->by : "*", "*", |
412 |
< |
me.name, CurrentTime - target_p->localClient->lasttime); |
409 |
> |
from, to, class_name, servers, |
410 |
> |
clients, name, *(target_p->serv->by) ? |
411 |
> |
target_p->serv->by : "*", "*", |
412 |
> |
me.name, CurrentTime - target_p->localClient->lasttime); |
413 |
|
break; |
414 |
|
} |
415 |
< |
|
416 |
< |
default: /* ...we actually shouldn't come here... --msa */ |
415 |
> |
|
416 |
> |
default: /* ...we actually shouldn't come here... --msa */ |
417 |
|
sendto_one(source_p, form_str(RPL_TRACENEWTYPE), |
418 |
|
from, to, name); |
419 |
|
break; |
420 |
|
} |
421 |
|
} |
422 |
|
|
423 |
< |
static struct Message trace_msgtab = { |
423 |
> |
static struct Message trace_msgtab = |
424 |
> |
{ |
425 |
|
"TRACE", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
426 |
|
{ m_unregistered, m_trace, ms_trace, m_ignore, mo_trace, m_ignore } |
427 |
|
}; |
438 |
|
mod_del_cmd(&trace_msgtab); |
439 |
|
} |
440 |
|
|
441 |
< |
struct module module_entry = { |
441 |
> |
struct module module_entry = |
442 |
> |
{ |
443 |
|
.node = { NULL, NULL, NULL }, |
444 |
|
.name = NULL, |
445 |
|
.version = "$Revision$", |