| 1 |
|
/* |
| 2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
< |
* m_etrace.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) 2004-2021 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 |
| 15 |
|
* |
| 16 |
|
* You should have received a copy of the GNU General Public License |
| 17 |
|
* along with this program; if not, write to the Free Software |
| 18 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
|
* USA |
| 20 |
< |
* |
| 21 |
< |
* $Id$ |
| 20 |
> |
*/ |
| 21 |
> |
|
| 22 |
> |
/*! \file m_etrace.c |
| 23 |
> |
* \brief Includes required functions for processing the ETRACE command. |
| 24 |
> |
* \version $Id$ |
| 25 |
|
*/ |
| 26 |
|
|
| 27 |
|
#include "stdinc.h" |
| 31 |
|
#include "irc_string.h" |
| 32 |
|
#include "ircd.h" |
| 33 |
|
#include "numeric.h" |
| 34 |
< |
#include "fdlist.h" |
| 33 |
< |
#include "s_bsd.h" |
| 34 |
< |
#include "s_serv.h" |
| 34 |
> |
#include "server.h" |
| 35 |
|
#include "send.h" |
| 36 |
|
#include "parse.h" |
| 37 |
|
#include "modules.h" |
| 38 |
|
#include "conf.h" |
| 39 |
< |
#include "conf_class.h" |
| 39 |
> |
#include "patchlevel.h" |
| 40 |
|
|
| 41 |
|
|
| 42 |
< |
static void report_this_status(struct Client *, struct Client *, int); |
| 42 |
> |
/* report_this_status() |
| 43 |
> |
* |
| 44 |
> |
* inputs - pointer to client to report to |
| 45 |
> |
* - pointer to client to report about |
| 46 |
> |
* - flag full etrace or not |
| 47 |
> |
* output - NONE |
| 48 |
> |
* side effects - NONE |
| 49 |
> |
*/ |
| 50 |
> |
static void |
| 51 |
> |
report_this_status(struct Client *source_p, const struct Client *target_p) |
| 52 |
> |
{ |
| 53 |
> |
if (target_p->status != STAT_CLIENT) |
| 54 |
> |
return; |
| 55 |
> |
|
| 56 |
> |
sendto_one_numeric(source_p, &me, RPL_ETRACE, |
| 57 |
> |
HasUMode(target_p, UMODE_OPER) ? "Oper" : "User", |
| 58 |
> |
get_client_class(&target_p->connection->confs), |
| 59 |
> |
target_p->name, |
| 60 |
> |
target_p->username, |
| 61 |
> |
target_p->host, |
| 62 |
> |
target_p->sockhost, |
| 63 |
> |
target_p->info); |
| 64 |
> |
} |
| 65 |
|
|
| 66 |
|
/* |
| 67 |
|
* do_etrace() |
| 68 |
|
*/ |
| 69 |
|
static void |
| 70 |
< |
do_etrace(struct Client *source_p, int parc, char *parv[]) |
| 70 |
> |
do_etrace(struct Client *source_p, const char *name) |
| 71 |
|
{ |
| 72 |
< |
const char *tname = NULL; |
| 73 |
< |
struct Client *target_p = NULL; |
| 52 |
< |
int wilds = 0; |
| 53 |
< |
int do_all = 0; |
| 54 |
< |
int full_etrace = 0; |
| 55 |
< |
dlink_node *ptr; |
| 72 |
> |
bool doall = false; |
| 73 |
> |
dlink_node *node; |
| 74 |
|
|
| 75 |
|
sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE, |
| 76 |
|
"ETRACE requested by %s (%s@%s) [%s]", |
| 77 |
|
source_p->name, source_p->username, |
| 78 |
|
source_p->host, source_p->servptr->name); |
| 79 |
|
|
| 80 |
< |
if (parc > 1) |
| 81 |
< |
{ |
| 82 |
< |
if (irccmp(parv[1], "-full") == 0) |
| 83 |
< |
{ |
| 84 |
< |
++parv; |
| 85 |
< |
--parc; |
| 68 |
< |
full_etrace = 1; |
| 69 |
< |
} |
| 70 |
< |
} |
| 71 |
< |
|
| 72 |
< |
if (parc > 1) |
| 73 |
< |
{ |
| 74 |
< |
tname = parv[1]; |
| 75 |
< |
|
| 76 |
< |
if (tname != NULL) |
| 77 |
< |
wilds = has_wildcards(tname); |
| 78 |
< |
else |
| 79 |
< |
tname = "*"; |
| 80 |
< |
} |
| 81 |
< |
else |
| 82 |
< |
{ |
| 83 |
< |
do_all = 1; |
| 84 |
< |
tname = "*"; |
| 85 |
< |
} |
| 86 |
< |
|
| 87 |
< |
if (HasUMode(source_p, UMODE_CCONN_FULL)) |
| 88 |
< |
full_etrace = 1; |
| 80 |
> |
if (EmptyString(name)) |
| 81 |
> |
doall = true; |
| 82 |
> |
else if (match(name, me.name) == 0) |
| 83 |
> |
doall = true; |
| 84 |
> |
else if (!MyClient(source_p) && strcmp(name, me.id) == 0) |
| 85 |
> |
doall = true; |
| 86 |
|
|
| 87 |
< |
if (!wilds && !do_all) |
| 87 |
> |
DLINK_FOREACH(node, local_client_list.head) |
| 88 |
|
{ |
| 89 |
< |
target_p = hash_find_client(tname); |
| 89 |
> |
const struct Client *target_p = node->data; |
| 90 |
|
|
| 91 |
< |
if (target_p && MyClient(target_p)) |
| 92 |
< |
report_this_status(source_p, target_p, full_etrace); |
| 96 |
< |
|
| 97 |
< |
sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, |
| 98 |
< |
source_p->name, tname); |
| 99 |
< |
return; |
| 91 |
> |
if (doall == true || match(name, target_p->name) == 0) |
| 92 |
> |
report_this_status(source_p, target_p); |
| 93 |
|
} |
| 94 |
|
|
| 95 |
< |
DLINK_FOREACH(ptr, local_client_list.head) |
| 103 |
< |
{ |
| 104 |
< |
target_p = ptr->data; |
| 105 |
< |
|
| 106 |
< |
if (wilds) |
| 107 |
< |
{ |
| 108 |
< |
if (!match(tname, target_p->name)) |
| 109 |
< |
report_this_status(source_p, target_p, full_etrace); |
| 110 |
< |
} |
| 111 |
< |
else |
| 112 |
< |
report_this_status(source_p, target_p, full_etrace); |
| 113 |
< |
} |
| 114 |
< |
|
| 115 |
< |
sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, |
| 116 |
< |
source_p->name, tname); |
| 117 |
< |
} |
| 118 |
< |
|
| 119 |
< |
/* mo_etrace() |
| 120 |
< |
* parv[0] = sender prefix |
| 121 |
< |
* parv[1] = servername |
| 122 |
< |
*/ |
| 123 |
< |
static void |
| 124 |
< |
mo_etrace(struct Client *client_p, struct Client *source_p, |
| 125 |
< |
int parc, char *parv[]) |
| 126 |
< |
{ |
| 127 |
< |
do_etrace(source_p, parc, parv); |
| 95 |
> |
sendto_one_numeric(source_p, &me, RPL_ETRACEEND, me.name); |
| 96 |
|
} |
| 97 |
|
|
| 98 |
< |
/* report_this_status() |
| 98 |
> |
/*! \brief ETRACE command handler |
| 99 |
|
* |
| 100 |
< |
* inputs - pointer to client to report to |
| 101 |
< |
* - pointer to client to report about |
| 102 |
< |
* - flag full etrace or not |
| 103 |
< |
* output - NONE |
| 104 |
< |
* side effects - NONE |
| 100 |
> |
* \param source_p Pointer to allocated Client struct from which the message |
| 101 |
> |
* originally comes from. This can be a local or remote client. |
| 102 |
> |
* \param parc Integer holding the number of supplied arguments. |
| 103 |
> |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 104 |
> |
* pointers. |
| 105 |
> |
* \note Valid arguments for this command are: |
| 106 |
> |
* - parv[0] = command |
| 107 |
> |
* - parv[1] = nick name to trace |
| 108 |
> |
* - parv[2] = nick or server name to forward the etrace to |
| 109 |
|
*/ |
| 110 |
|
static void |
| 111 |
< |
report_this_status(struct Client *source_p, struct Client *target_p, |
| 140 |
< |
int full_etrace) |
| 111 |
> |
mo_etrace(struct Client *source_p, int parc, char *parv[]) |
| 112 |
|
{ |
| 113 |
< |
if (target_p->status == STAT_CLIENT) |
| 114 |
< |
{ |
| 115 |
< |
if (full_etrace) |
| 116 |
< |
{ |
| 117 |
< |
if (ConfigFileEntry.hide_spoof_ips) |
| 118 |
< |
sendto_one(source_p, form_str(RPL_ETRACE_FULL), |
| 119 |
< |
me.name, |
| 120 |
< |
source_p->name, |
| 121 |
< |
HasUMode(target_p, UMODE_OPER) ? "Oper" : "User", |
| 122 |
< |
get_client_class(&target_p->localClient->confs), |
| 123 |
< |
target_p->name, |
| 124 |
< |
target_p->username, |
| 125 |
< |
target_p->host, |
| 126 |
< |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
| 127 |
< |
IsIPSpoof(target_p) ? "<hidden>" : target_p->localClient->client_host, |
| 128 |
< |
IsIPSpoof(target_p) ? "<hidden>" : target_p->localClient->client_server, |
| 158 |
< |
target_p->info); |
| 159 |
< |
else |
| 160 |
< |
sendto_one(source_p, form_str(RPL_ETRACE_FULL), |
| 161 |
< |
me.name, |
| 162 |
< |
source_p->name, |
| 163 |
< |
HasUMode(target_p, UMODE_OPER) ? "Oper" : "User", |
| 164 |
< |
get_client_class(&target_p->localClient->confs), |
| 165 |
< |
target_p->name, |
| 166 |
< |
target_p->username, |
| 167 |
< |
target_p->host, |
| 168 |
< |
target_p->sockhost, |
| 169 |
< |
target_p->localClient->client_host, |
| 170 |
< |
target_p->localClient->client_server, |
| 171 |
< |
target_p->info); |
| 172 |
< |
} |
| 173 |
< |
else |
| 174 |
< |
{ |
| 175 |
< |
if (ConfigFileEntry.hide_spoof_ips) |
| 176 |
< |
sendto_one(source_p, form_str(RPL_ETRACE), |
| 177 |
< |
me.name, |
| 178 |
< |
source_p->name, |
| 179 |
< |
HasUMode(target_p, UMODE_OPER) ? "Oper" : "User", |
| 180 |
< |
get_client_class(&target_p->localClient->confs), |
| 181 |
< |
target_p->name, |
| 182 |
< |
target_p->username, |
| 183 |
< |
target_p->host, |
| 184 |
< |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
| 185 |
< |
target_p->info); |
| 186 |
< |
else |
| 187 |
< |
sendto_one(source_p, form_str(RPL_ETRACE), |
| 188 |
< |
me.name, |
| 189 |
< |
source_p->name, |
| 190 |
< |
HasUMode(target_p, UMODE_OPER) ? "Oper" : "User", |
| 191 |
< |
get_client_class(&target_p->localClient->confs), |
| 192 |
< |
target_p->name, |
| 193 |
< |
target_p->username, |
| 194 |
< |
target_p->host, |
| 195 |
< |
target_p->sockhost, |
| 196 |
< |
target_p->info); |
| 197 |
< |
} |
| 113 |
> |
if (parc > 2) |
| 114 |
> |
if (server_hunt(source_p, ":%s ETRACE %s :%s", 2, parv)->ret != HUNTED_ISME) |
| 115 |
> |
return; |
| 116 |
> |
|
| 117 |
> |
const struct server_hunt *hunt = server_hunt(source_p, ":%s ETRACE :%s", 1, parv); |
| 118 |
> |
switch (hunt->ret) |
| 119 |
> |
{ |
| 120 |
> |
case HUNTED_PASS: |
| 121 |
> |
sendto_one_numeric(source_p, &me, RPL_TRACELINK, |
| 122 |
> |
PATCHLEVEL, hunt->target_p->name, hunt->target_p->from->name); |
| 123 |
> |
break; |
| 124 |
> |
case HUNTED_ISME: |
| 125 |
> |
do_etrace(source_p, parv[1]); |
| 126 |
> |
break; |
| 127 |
> |
default: |
| 128 |
> |
break; |
| 129 |
|
} |
| 130 |
|
} |
| 131 |
|
|
| 132 |
< |
static struct Message etrace_msgtab = { |
| 133 |
< |
"ETRACE", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
| 134 |
< |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_etrace, m_ignore} |
| 132 |
> |
static struct Message etrace_msgtab = |
| 133 |
> |
{ |
| 134 |
> |
.cmd = "ETRACE", |
| 135 |
> |
.handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered }, |
| 136 |
> |
.handlers[CLIENT_HANDLER] = { .handler = m_not_oper }, |
| 137 |
> |
.handlers[SERVER_HANDLER] = { .handler = mo_etrace }, |
| 138 |
> |
.handlers[ENCAP_HANDLER] = { .handler = m_ignore }, |
| 139 |
> |
.handlers[OPER_HANDLER] = { .handler = mo_etrace } |
| 140 |
|
}; |
| 141 |
|
|
| 142 |
|
static void |
| 151 |
|
mod_del_cmd(&etrace_msgtab); |
| 152 |
|
} |
| 153 |
|
|
| 154 |
< |
struct module module_entry = { |
| 155 |
< |
.node = { NULL, NULL, NULL }, |
| 220 |
< |
.name = NULL, |
| 154 |
> |
struct module module_entry = |
| 155 |
> |
{ |
| 156 |
|
.version = "$Revision$", |
| 222 |
– |
.handle = NULL, |
| 157 |
|
.modinit = module_init, |
| 158 |
|
.modexit = module_exit, |
| 225 |
– |
.flags = 0 |
| 159 |
|
}; |