2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* m_trace.c: Traces a path to a client/server.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "class.h"
|
|
|
|
#include "hook.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "hash.h"
|
2008-04-20 05:47:38 +00:00
|
|
|
#include "match.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "ircd.h"
|
|
|
|
#include "numeric.h"
|
|
|
|
#include "s_serv.h"
|
|
|
|
#include "s_conf.h"
|
|
|
|
#include "s_newconf.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "msg.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "modules.h"
|
|
|
|
|
2016-02-11 02:54:17 +00:00
|
|
|
static int m_trace(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
static void trace_spy(struct Client *, struct Client *);
|
|
|
|
|
|
|
|
struct Message trace_msgtab = {
|
2016-02-19 22:42:40 +00:00
|
|
|
"TRACE", 0, 0, 0, 0,
|
2007-01-25 06:40:21 +00:00
|
|
|
{mg_unreg, {m_trace, 0}, {m_trace, 0}, mg_ignore, mg_ignore, {m_trace, 0}}
|
|
|
|
};
|
|
|
|
|
|
|
|
int doing_trace_hook;
|
|
|
|
|
|
|
|
mapi_clist_av1 trace_clist[] = { &trace_msgtab, NULL };
|
|
|
|
mapi_hlist_av1 trace_hlist[] = {
|
|
|
|
{ "doing_trace", &doing_trace_hook },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
2016-03-07 06:03:39 +00:00
|
|
|
DECLARE_MODULE_AV2(trace, NULL, NULL, trace_clist, trace_hlist, NULL, NULL, NULL, NULL);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
static void count_downlinks(struct Client *server_p, int *pservcount, int *pusercount);
|
2008-06-28 14:20:24 +00:00
|
|
|
static int report_this_status(struct Client *source_p, struct Client *target_p);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-06-28 10:27:33 +00:00
|
|
|
static const char *empty_sockhost = "255.255.255.255";
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* m_trace
|
|
|
|
* parv[1] = servername
|
|
|
|
*/
|
|
|
|
static int
|
2016-02-11 02:54:17 +00:00
|
|
|
m_trace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
struct Client *target_p = NULL;
|
|
|
|
struct Class *cltmp;
|
|
|
|
const char *tname;
|
|
|
|
int doall = 0;
|
|
|
|
int cnt = 0, wilds, dow;
|
2008-04-01 20:18:48 +00:00
|
|
|
rb_dlink_node *ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if(parc > 1)
|
|
|
|
{
|
|
|
|
tname = parv[1];
|
|
|
|
|
|
|
|
if(parc > 2)
|
|
|
|
{
|
|
|
|
if(hunt_server(client_p, source_p, ":%s TRACE %s :%s", 2, parc, parv) !=
|
|
|
|
HUNTED_ISME)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tname = me.name;
|
|
|
|
|
|
|
|
/* if we have 3 parameters, then the command is directed at us. So
|
|
|
|
* we shouldnt be forwarding it anywhere.
|
|
|
|
*/
|
|
|
|
if(parc < 3)
|
|
|
|
{
|
|
|
|
switch (hunt_server(client_p, source_p, ":%s TRACE :%s", 1, parc, parv))
|
|
|
|
{
|
|
|
|
case HUNTED_PASS: /* note: gets here only if parv[1] exists */
|
|
|
|
{
|
|
|
|
struct Client *ac2ptr;
|
|
|
|
|
|
|
|
if(MyClient(source_p))
|
|
|
|
ac2ptr = find_named_client(tname);
|
|
|
|
else
|
|
|
|
ac2ptr = find_client(tname);
|
|
|
|
|
|
|
|
if(ac2ptr == NULL)
|
|
|
|
{
|
2011-01-08 16:47:05 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, global_serv_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
ac2ptr = ptr->data;
|
|
|
|
|
2007-02-01 01:07:42 +00:00
|
|
|
if(match(tname, ac2ptr->name))
|
2007-01-25 06:40:21 +00:00
|
|
|
break;
|
|
|
|
else
|
|
|
|
ac2ptr = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* giving this out with flattened links defeats the
|
|
|
|
* object --fl
|
|
|
|
*/
|
|
|
|
if(IsOper(source_p) || IsExemptShide(source_p) ||
|
|
|
|
!ConfigServerHide.flatten_links)
|
2014-03-03 04:25:47 +00:00
|
|
|
sendto_one_numeric(source_p, RPL_TRACELINK,
|
2007-01-25 06:40:21 +00:00
|
|
|
form_str(RPL_TRACELINK),
|
2014-03-03 04:25:47 +00:00
|
|
|
ircd_version,
|
2007-01-25 06:40:21 +00:00
|
|
|
ac2ptr ? ac2ptr->name : tname,
|
|
|
|
ac2ptr ? ac2ptr->from->name : "EEK!");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case HUNTED_ISME:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(match(tname, me.name))
|
|
|
|
{
|
|
|
|
doall = 1;
|
|
|
|
}
|
|
|
|
/* if theyre tracing our SID, we need to move tname to our name so
|
|
|
|
* we dont give the sid in ENDOFTRACE
|
|
|
|
*/
|
|
|
|
else if(!MyClient(source_p) && !strcmp(tname, me.id))
|
|
|
|
{
|
|
|
|
doall = 1;
|
|
|
|
tname = me.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
wilds = strchr(tname, '*') || strchr(tname, '?');
|
|
|
|
dow = wilds || doall;
|
|
|
|
|
|
|
|
/* specific trace */
|
|
|
|
if(dow == 0)
|
|
|
|
{
|
|
|
|
if(MyClient(source_p) || parc > 2)
|
|
|
|
target_p = find_named_person(tname);
|
|
|
|
else
|
|
|
|
target_p = find_person(tname);
|
|
|
|
|
|
|
|
/* tname could be pointing to an ID at this point, so reset
|
|
|
|
* it to target_p->name if we have a target --fl
|
|
|
|
*/
|
|
|
|
if(target_p != NULL)
|
|
|
|
{
|
2008-06-28 14:20:24 +00:00
|
|
|
report_this_status(source_p, target_p);
|
2007-01-25 06:40:21 +00:00
|
|
|
tname = target_p->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_spy(source_p, target_p);
|
|
|
|
|
2014-03-03 04:25:47 +00:00
|
|
|
sendto_one_numeric(source_p, RPL_ENDOFTRACE,
|
2007-01-25 06:40:21 +00:00
|
|
|
form_str(RPL_ENDOFTRACE), tname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_spy(source_p, NULL);
|
|
|
|
|
2014-03-03 04:25:47 +00:00
|
|
|
/* give non-opers a limited trace output of themselves (if local),
|
2007-01-25 06:40:21 +00:00
|
|
|
* opers and servers (if no shide) --fl
|
|
|
|
*/
|
|
|
|
if(!IsOper(source_p))
|
|
|
|
{
|
|
|
|
if(MyClient(source_p))
|
|
|
|
{
|
|
|
|
if(doall || (wilds && match(tname, source_p->name)))
|
2008-06-28 14:20:24 +00:00
|
|
|
report_this_status(source_p, source_p);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2008-04-01 20:18:48 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, local_oper_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
|
|
|
if(!doall && wilds && (match(tname, target_p->name) == 0))
|
|
|
|
continue;
|
|
|
|
|
2008-06-28 14:20:24 +00:00
|
|
|
report_this_status(source_p, target_p);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IsExemptShide(source_p) || !ConfigServerHide.flatten_links)
|
|
|
|
{
|
2008-04-01 20:18:48 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, serv_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
|
|
|
if(!doall && wilds && !match(tname, target_p->name))
|
|
|
|
continue;
|
|
|
|
|
2008-06-28 14:20:24 +00:00
|
|
|
report_this_status(source_p, target_p);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-03 04:25:47 +00:00
|
|
|
sendto_one_numeric(source_p, RPL_ENDOFTRACE,
|
2007-01-25 06:40:21 +00:00
|
|
|
form_str(RPL_ENDOFTRACE), tname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* source_p is opered */
|
|
|
|
|
|
|
|
/* report all direct connections */
|
2008-04-01 20:18:48 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, lclient_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
|
|
|
/* dont show invisible users to remote opers */
|
|
|
|
if(IsInvisible(target_p) && dow && !MyConnect(source_p) && !IsOper(target_p))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(!doall && wilds && !match(tname, target_p->name))
|
|
|
|
continue;
|
|
|
|
|
2008-06-03 18:52:00 +00:00
|
|
|
/* remote opers may not see invisible normal users */
|
|
|
|
if(dow && !MyConnect(source_p) && !IsOper(target_p) &&
|
|
|
|
IsInvisible(target_p))
|
|
|
|
continue;
|
|
|
|
|
2008-06-28 14:20:24 +00:00
|
|
|
cnt = report_this_status(source_p, target_p);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2008-04-01 20:18:48 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, serv_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
|
|
|
if(!doall && wilds && !match(tname, target_p->name))
|
|
|
|
continue;
|
|
|
|
|
2008-06-28 14:20:24 +00:00
|
|
|
cnt = report_this_status(source_p, target_p);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(MyConnect(source_p))
|
|
|
|
{
|
2008-04-01 20:18:48 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, unknown_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
|
|
|
if(!doall && wilds && !match(tname, target_p->name))
|
|
|
|
continue;
|
|
|
|
|
2008-06-28 14:20:24 +00:00
|
|
|
cnt = report_this_status(source_p, target_p);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!cnt)
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER),
|
|
|
|
tname);
|
|
|
|
|
|
|
|
/* let the user have some idea that its at the end of the
|
|
|
|
* trace
|
|
|
|
*/
|
2014-03-03 04:25:47 +00:00
|
|
|
sendto_one_numeric(source_p, RPL_ENDOFTRACE,
|
2007-01-25 06:40:21 +00:00
|
|
|
form_str(RPL_ENDOFTRACE), tname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(doall)
|
|
|
|
{
|
2008-04-01 20:18:48 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, class_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
cltmp = ptr->data;
|
|
|
|
|
|
|
|
if(CurrUsers(cltmp) > 0)
|
|
|
|
sendto_one_numeric(source_p, RPL_TRACECLASS,
|
2014-03-03 04:25:47 +00:00
|
|
|
form_str(RPL_TRACECLASS),
|
2007-01-25 06:40:21 +00:00
|
|
|
ClassName(cltmp), CurrUsers(cltmp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), tname);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* count_downlinks
|
|
|
|
*
|
|
|
|
* inputs - pointer to server to count
|
|
|
|
* - pointers to server and user count
|
|
|
|
* output - NONE
|
|
|
|
* side effects - server and user counts are added to given values
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
count_downlinks(struct Client *server_p, int *pservcount, int *pusercount)
|
|
|
|
{
|
2008-04-01 20:18:48 +00:00
|
|
|
rb_dlink_node *ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
(*pservcount)++;
|
2008-04-01 20:18:48 +00:00
|
|
|
*pusercount += rb_dlink_list_length(&server_p->serv->users);
|
|
|
|
RB_DLINK_FOREACH(ptr, server_p->serv->servers.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
count_downlinks(ptr->data, pservcount, pusercount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* report_this_status
|
|
|
|
*
|
|
|
|
* inputs - pointer to client to report to
|
|
|
|
* - pointer to client to report about
|
|
|
|
* output - counter of number of hits
|
|
|
|
* side effects - NONE
|
|
|
|
*/
|
|
|
|
static int
|
2008-06-28 14:20:24 +00:00
|
|
|
report_this_status(struct Client *source_p, struct Client *target_p)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
const char *class_name;
|
|
|
|
char ip[HOSTIPLEN];
|
|
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
/* sanity check - should never happen */
|
|
|
|
if(!MyConnect(target_p))
|
|
|
|
return 0;
|
|
|
|
|
2008-04-20 04:55:41 +00:00
|
|
|
rb_inet_ntop_sock((struct sockaddr *)&target_p->localClient->ip, ip, sizeof(ip));
|
2007-01-25 06:40:21 +00:00
|
|
|
class_name = get_client_class(target_p);
|
|
|
|
|
|
|
|
if(IsAnyServer(target_p))
|
2008-06-28 10:13:50 +00:00
|
|
|
name = target_p->name;
|
2007-01-25 06:40:21 +00:00
|
|
|
else
|
|
|
|
name = get_client_name(target_p, HIDE_IP);
|
|
|
|
|
|
|
|
switch (target_p->status)
|
|
|
|
{
|
|
|
|
case STAT_CONNECTING:
|
|
|
|
sendto_one_numeric(source_p, RPL_TRACECONNECTING,
|
|
|
|
form_str(RPL_TRACECONNECTING),
|
|
|
|
class_name, name);
|
|
|
|
cnt++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STAT_HANDSHAKE:
|
|
|
|
sendto_one_numeric(source_p, RPL_TRACEHANDSHAKE,
|
|
|
|
form_str(RPL_TRACEHANDSHAKE),
|
|
|
|
class_name, name);
|
|
|
|
cnt++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STAT_ME:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STAT_UNKNOWN:
|
|
|
|
/* added time -Taner */
|
|
|
|
sendto_one_numeric(source_p, RPL_TRACEUNKNOWN,
|
|
|
|
form_str(RPL_TRACEUNKNOWN),
|
|
|
|
class_name, name, ip,
|
2014-02-23 21:46:06 +00:00
|
|
|
(unsigned long)(rb_current_time() - target_p->localClient->firsttime));
|
2007-01-25 06:40:21 +00:00
|
|
|
cnt++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STAT_CLIENT:
|
2008-06-28 19:08:04 +00:00
|
|
|
{
|
2013-02-21 11:44:16 +00:00
|
|
|
sendto_one_numeric(source_p,
|
|
|
|
IsOper(target_p) ? RPL_TRACEOPERATOR : RPL_TRACEUSER,
|
|
|
|
IsOper(target_p) ? form_str(RPL_TRACEOPERATOR) : form_str(RPL_TRACEUSER),
|
2008-06-28 19:08:04 +00:00
|
|
|
class_name, name,
|
|
|
|
show_ip(source_p, target_p) ? ip : empty_sockhost,
|
2011-11-12 23:22:09 +00:00
|
|
|
(unsigned long)(rb_current_time() - target_p->localClient->lasttime),
|
|
|
|
(unsigned long)(rb_current_time() - target_p->localClient->last));
|
2008-06-28 19:08:04 +00:00
|
|
|
|
|
|
|
cnt++;
|
|
|
|
}
|
2008-06-28 14:20:24 +00:00
|
|
|
break;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
case STAT_SERVER:
|
|
|
|
{
|
|
|
|
int usercount = 0;
|
|
|
|
int servcount = 0;
|
|
|
|
|
|
|
|
count_downlinks(target_p, &servcount, &usercount);
|
|
|
|
|
|
|
|
sendto_one_numeric(source_p, RPL_TRACESERVER, form_str(RPL_TRACESERVER),
|
|
|
|
class_name, servcount, usercount, name,
|
|
|
|
*(target_p->serv->by) ? target_p->serv->by : "*", "*",
|
2011-11-12 23:22:09 +00:00
|
|
|
me.name,
|
|
|
|
(unsigned long)(rb_current_time() - target_p->localClient->lasttime));
|
2007-01-25 06:40:21 +00:00
|
|
|
cnt++;
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* ...we actually shouldn't come here... --msa */
|
2014-03-03 04:25:47 +00:00
|
|
|
sendto_one_numeric(source_p, RPL_TRACENEWTYPE,
|
2011-11-12 23:22:09 +00:00
|
|
|
form_str(RPL_TRACENEWTYPE), name);
|
2007-01-25 06:40:21 +00:00
|
|
|
cnt++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* trace_spy()
|
|
|
|
*
|
|
|
|
* input - pointer to client
|
|
|
|
* output - none
|
|
|
|
* side effects - hook event doing_trace is called
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
trace_spy(struct Client *source_p, struct Client *target_p)
|
|
|
|
{
|
|
|
|
hook_data_client hdata;
|
|
|
|
|
|
|
|
hdata.client = source_p;
|
|
|
|
hdata.target = target_p;
|
|
|
|
|
|
|
|
call_hook(doing_trace_hook, &hdata);
|
|
|
|
}
|