40 |
|
#include "parse.h" |
41 |
|
#include "modules.h" |
42 |
|
#include "s_conf.h" |
43 |
– |
#include "irc_getnameinfo.h" |
43 |
|
|
44 |
< |
static void m_trace(struct Client *, struct Client *, int, char **); |
45 |
< |
static void ms_trace(struct Client*, struct Client*, int, char**); |
46 |
< |
static void mo_trace(struct Client*, struct Client*, int, char**); |
47 |
< |
static void do_actual_trace(struct Client *, int, char **); |
44 |
> |
static void m_trace(struct Client *, struct Client *, int, char *[]); |
45 |
> |
static void ms_trace(struct Client *, struct Client *, int, char *[]); |
46 |
> |
static void mo_trace(struct Client *, struct Client *, int, char *[]); |
47 |
> |
static void do_actual_trace(struct Client *, int, char *[]); |
48 |
|
|
49 |
|
struct Message trace_msgtab = { |
50 |
|
"TRACE", 0, 0, 0, 0, MFLG_SLOW, 0, |
51 |
< |
{m_unregistered, m_trace, ms_trace, m_ignore, mo_trace, m_ignore} |
51 |
> |
{ m_unregistered, m_trace, ms_trace, m_ignore, mo_trace, m_ignore } |
52 |
|
}; |
53 |
|
|
54 |
|
#ifndef STATIC_MODULES |
81 |
|
} |
82 |
|
#endif |
83 |
|
|
84 |
< |
static int report_this_status(struct Client *source_p, struct Client *target_p, |
85 |
< |
int dow, int link_u_p, int link_u_s); |
84 |
> |
static void report_this_status(struct Client *, struct Client *, int); |
85 |
> |
|
86 |
> |
static void |
87 |
> |
trace_get_dependent(int *const server, |
88 |
> |
int *const client, const struct Client *target_p) |
89 |
> |
{ |
90 |
> |
const dlink_node *ptr = NULL; |
91 |
> |
|
92 |
> |
(*server)++; |
93 |
> |
(*client) += dlink_list_length(&target_p->serv->client_list); |
94 |
> |
|
95 |
> |
DLINK_FOREACH(ptr, target_p->serv->server_list.head) |
96 |
> |
trace_get_dependent(server, client, ptr->data); |
97 |
> |
} |
98 |
|
|
99 |
|
/* |
100 |
|
* m_trace() |
190 |
|
} |
191 |
|
|
192 |
|
static void |
193 |
< |
do_actual_trace(struct Client *source_p, int parc, char **parv) |
193 |
> |
do_actual_trace(struct Client *source_p, int parc, char *parv[]) |
194 |
|
{ |
195 |
|
struct Client *target_p = NULL; |
196 |
|
struct ConfItem *conf; |
197 |
|
struct ClassItem *cltmp; |
198 |
|
int doall = 0; |
199 |
< |
int cnt = 0, wilds, dow; |
199 |
> |
int wilds, dow; |
200 |
|
dlink_node *ptr; |
201 |
|
const char *from, *to, *tname; |
202 |
|
|
233 |
|
{ |
234 |
|
const char *name; |
235 |
|
const char *class_name; |
225 |
– |
char ipaddr[HOSTIPLEN]; |
236 |
|
|
237 |
|
target_p = find_client(tname); |
238 |
|
|
239 |
|
if (target_p && IsClient(target_p)) |
240 |
|
{ |
241 |
|
name = get_client_name(target_p, HIDE_IP); |
232 |
– |
/* should we not use sockhost here? - stu */ |
233 |
– |
irc_getnameinfo((struct sockaddr*)&target_p->localClient->ip, |
234 |
– |
target_p->localClient->ip.ss_len, ipaddr, HOSTIPLEN, NULL, 0, |
235 |
– |
NI_NUMERICHOST); |
236 |
– |
|
242 |
|
class_name = get_client_class(target_p); |
243 |
|
|
244 |
|
if (IsOper(target_p)) |
245 |
|
{ |
246 |
|
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
247 |
|
from, to, class_name, name, |
248 |
< |
IsIPSpoof(target_p) ? "255.255.255.255" : ipaddr, |
248 |
> |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
249 |
|
CurrentTime - target_p->lasttime, |
250 |
|
CurrentTime - target_p->localClient->last); |
251 |
|
} |
253 |
|
{ |
254 |
|
sendto_one(source_p,form_str(RPL_TRACEUSER), |
255 |
|
from, to, class_name, name, |
256 |
< |
IsIPSpoof(target_p) ? "255.255.255.255" : ipaddr, |
256 |
> |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
257 |
|
CurrentTime - target_p->lasttime, |
258 |
|
CurrentTime - target_p->localClient->last); |
259 |
|
} |
278 |
|
if (!dow && irccmp(tname, target_p->name)) |
279 |
|
continue; |
280 |
|
|
281 |
< |
cnt = report_this_status(source_p, target_p, dow, 0, 0); |
281 |
> |
report_this_status(source_p, target_p, dow); |
282 |
|
} |
283 |
|
|
284 |
|
DLINK_FOREACH(ptr, serv_list.head) |
290 |
|
if (!dow && irccmp(tname, target_p->name)) |
291 |
|
continue; |
292 |
|
|
293 |
< |
cnt = report_this_status(source_p, target_p, dow, |
289 |
< |
target_p->serv->dep_users, target_p->serv->dep_servers); |
293 |
> |
report_this_status(source_p, target_p, dow); |
294 |
|
} |
295 |
|
|
296 |
|
/* This section is to report the unknowns */ |
303 |
|
if (!dow && irccmp(tname, target_p->name)) |
304 |
|
continue; |
305 |
|
|
306 |
< |
cnt = report_this_status(source_p, target_p, dow, 0, 0); |
306 |
> |
report_this_status(source_p, target_p, dow); |
307 |
|
} |
308 |
|
|
309 |
|
DLINK_FOREACH(ptr, class_items.head) |
310 |
|
{ |
311 |
|
conf = ptr->data; |
312 |
< |
cltmp = (struct ClassItem *)map_to_conf(conf); |
312 |
> |
cltmp = map_to_conf(conf); |
313 |
> |
|
314 |
|
if (CurrUserCount(cltmp) > 0) |
315 |
|
sendto_one(source_p, form_str(RPL_TRACECLASS), |
316 |
< |
from, to, conf->name, CurrUserCount(cltmp)); |
316 |
> |
from, to, conf->name, CurrUserCount(cltmp)); |
317 |
|
} |
318 |
|
|
319 |
|
sendto_one(source_p, form_str(RPL_ENDOFTRACE), from, to, tname); |
320 |
|
} |
321 |
|
|
317 |
– |
|
322 |
|
/* |
323 |
|
** ms_trace |
324 |
|
** parv[0] = sender prefix |
342 |
|
* output - counter of number of hits |
343 |
|
* side effects - NONE |
344 |
|
*/ |
345 |
< |
static int |
346 |
< |
report_this_status(struct Client *source_p, struct Client *target_p, |
343 |
< |
int dow, int link_u_p, int link_s_p) |
345 |
> |
static void |
346 |
> |
report_this_status(struct Client *source_p, struct Client *target_p, int dow) |
347 |
|
{ |
348 |
|
const char *name; |
349 |
|
const char *class_name; |
350 |
|
const char *from, *to; |
348 |
– |
char ip[HOSTIPLEN]; |
349 |
– |
int cnt = 0; |
351 |
|
|
352 |
|
if (!MyConnect(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p)) |
353 |
|
{ |
360 |
|
to = source_p->name; |
361 |
|
} |
362 |
|
|
362 |
– |
/* Should this be sockhost? - stu */ |
363 |
– |
irc_getnameinfo((struct sockaddr*)&target_p->localClient->ip, |
364 |
– |
target_p->localClient->ip.ss_len, ip, HOSTIPLEN, NULL, 0, |
365 |
– |
NI_NUMERICHOST); |
363 |
|
name = get_client_name(target_p, HIDE_IP); |
364 |
|
class_name = get_client_class(target_p); |
365 |
|
|
366 |
|
set_time(); |
367 |
|
|
368 |
< |
switch(target_p->status) |
368 |
> |
switch (target_p->status) |
369 |
|
{ |
370 |
|
case STAT_CONNECTING: |
371 |
|
sendto_one(source_p, form_str(RPL_TRACECONNECTING), |
372 |
|
from, to, class_name, |
373 |
|
IsOperAdmin(source_p) ? name : target_p->name); |
377 |
– |
|
378 |
– |
cnt++; |
374 |
|
break; |
375 |
|
case STAT_HANDSHAKE: |
376 |
|
sendto_one(source_p, form_str(RPL_TRACEHANDSHAKE), |
377 |
|
from, to, class_name, |
378 |
|
IsOperAdmin(source_p) ? name : target_p->name); |
384 |
– |
|
385 |
– |
cnt++; |
379 |
|
break; |
380 |
|
case STAT_ME: |
381 |
|
break; |
382 |
|
case STAT_UNKNOWN: |
383 |
|
/* added time -Taner */ |
384 |
|
sendto_one(source_p, form_str(RPL_TRACEUNKNOWN), |
385 |
< |
from, to, class_name, name, ip, |
385 |
> |
from, to, class_name, name, target_p->sockhost, |
386 |
|
target_p->firsttime ? CurrentTime - target_p->firsttime : -1); |
394 |
– |
cnt++; |
387 |
|
break; |
388 |
|
case STAT_CLIENT: |
389 |
< |
/* Only opers see users if there is a wildcard |
389 |
> |
/* |
390 |
> |
* Only opers see users if there is a wildcard |
391 |
|
* but anyone can see all the opers. |
392 |
|
*/ |
393 |
|
if ((IsOper(source_p) && |
397 |
|
if (IsAdmin(target_p) && !ConfigFileEntry.hide_spoof_ips) |
398 |
|
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
399 |
|
from, to, class_name, name, |
400 |
< |
IsOperAdmin(source_p) ? ip : "255.255.255.255", |
400 |
> |
IsOperAdmin(source_p) ? target_p->sockhost : "255.255.255.255", |
401 |
|
CurrentTime - target_p->lasttime, |
402 |
|
CurrentTime - target_p->localClient->last); |
403 |
|
|
406 |
|
if (ConfigFileEntry.hide_spoof_ips) |
407 |
|
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
408 |
|
from, to, class_name, name, |
409 |
< |
IsIPSpoof(target_p) ? "255.255.255.255" : ip, |
409 |
> |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
410 |
|
CurrentTime - target_p->lasttime, |
411 |
|
CurrentTime - target_p->localClient->last); |
412 |
|
else |
413 |
|
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
414 |
|
from, to, class_name, name, |
415 |
< |
MyOper(source_p) ? ip : |
416 |
< |
(IsIPSpoof(target_p) ? "255.255.255.255" : ip), |
415 |
> |
MyOper(source_p) ? target_p->sockhost : |
416 |
> |
(IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost), |
417 |
|
CurrentTime - target_p->lasttime, |
418 |
|
CurrentTime - target_p->localClient->last); |
419 |
|
} |
428 |
|
if (ConfigFileEntry.hide_spoof_ips) |
429 |
|
sendto_one(source_p, format_str, |
430 |
|
from, to, class_name, name, |
431 |
< |
IsIPSpoof(target_p) ? "255.255.255.255" : ip, |
431 |
> |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
432 |
|
CurrentTime - target_p->lasttime, |
433 |
|
CurrentTime - target_p->localClient->last); |
434 |
|
else |
435 |
|
sendto_one(source_p, format_str, |
436 |
|
from, to, class_name, name, |
437 |
< |
MyOper(source_p) ? ip : |
438 |
< |
(IsIPSpoof(target_p) ? "255.255.255.255" : ip), |
437 |
> |
MyOper(source_p) ? target_p->sockhost : |
438 |
> |
(IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost), |
439 |
|
CurrentTime - target_p->lasttime, |
440 |
|
CurrentTime - target_p->localClient->last); |
441 |
|
} |
449 |
– |
cnt++; |
442 |
|
} |
443 |
|
break; |
444 |
|
case STAT_SERVER: |
445 |
< |
if(!IsOperAdmin(source_p)) |
445 |
> |
{ |
446 |
> |
int clients = 0; |
447 |
> |
int servers = 0; |
448 |
> |
|
449 |
> |
trace_get_dependent(&servers, &clients, target_p); |
450 |
> |
|
451 |
> |
if (!IsOperAdmin(source_p)) |
452 |
|
name = get_client_name(target_p, MASK_IP); |
453 |
|
|
454 |
|
sendto_one(source_p, form_str(RPL_TRACESERVER), |
455 |
< |
from, to, class_name, link_s_p, |
456 |
< |
link_u_p, name, *(target_p->serv->by) ? |
455 |
> |
from, to, class_name, servers, |
456 |
> |
clients, name, *(target_p->serv->by) ? |
457 |
|
target_p->serv->by : "*", "*", |
458 |
|
me.name, CurrentTime - target_p->lasttime); |
461 |
– |
cnt++; |
459 |
|
break; |
460 |
+ |
} |
461 |
|
|
462 |
|
default: /* ...we actually shouldn't come here... --msa */ |
463 |
|
sendto_one(source_p, form_str(RPL_TRACENEWTYPE), |
464 |
< |
from, to, name); |
467 |
< |
cnt++; |
464 |
> |
from, to, name); |
465 |
|
break; |
466 |
|
} |
470 |
– |
|
471 |
– |
return cnt; |
467 |
|
} |