| 1 |
adx |
30 |
/* |
| 2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
|
|
* m_etrace.c: Traces a path to a client/server. |
| 4 |
|
|
* |
| 5 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 6 |
|
|
* |
| 7 |
|
|
* This program is free software; you can redistribute it and/or modify |
| 8 |
|
|
* it under the terms of the GNU General Public License as published by |
| 9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
|
|
* (at your option) any later version. |
| 11 |
|
|
* |
| 12 |
|
|
* This program is distributed in the hope that it will be useful, |
| 13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
|
|
* GNU General Public License for more details. |
| 16 |
|
|
* |
| 17 |
|
|
* You should have received a copy of the GNU General Public License |
| 18 |
|
|
* along with this program; if not, write to the Free Software |
| 19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
|
|
* USA |
| 21 |
|
|
* |
| 22 |
knight |
31 |
* $Id$ |
| 23 |
adx |
30 |
*/ |
| 24 |
|
|
|
| 25 |
|
|
#include "stdinc.h" |
| 26 |
|
|
#include "handlers.h" |
| 27 |
|
|
#include "tools.h" |
| 28 |
|
|
#include "hook.h" |
| 29 |
|
|
#include "client.h" |
| 30 |
|
|
#include "hash.h" |
| 31 |
|
|
#include "common.h" |
| 32 |
|
|
#include "irc_string.h" |
| 33 |
|
|
#include "ircd.h" |
| 34 |
|
|
#include "numeric.h" |
| 35 |
|
|
#include "fdlist.h" |
| 36 |
|
|
#include "s_bsd.h" |
| 37 |
|
|
#include "s_serv.h" |
| 38 |
|
|
#include "send.h" |
| 39 |
|
|
#include "msg.h" |
| 40 |
|
|
#include "parse.h" |
| 41 |
|
|
#include "modules.h" |
| 42 |
|
|
#include "s_conf.h" |
| 43 |
|
|
#include "irc_getnameinfo.h" |
| 44 |
|
|
|
| 45 |
db |
856 |
#define FORM_STR_RPL_ETRACE ":%s 709 %s %s %s %s %s %s %s :%s" |
| 46 |
|
|
#define FORM_STR_RPL_ETRACE_FULL ":%s 708 %s %s %s %s %s %s %s %s %s :%s" |
| 47 |
adx |
30 |
|
| 48 |
|
|
static void do_etrace(struct Client *, int, char **); |
| 49 |
|
|
static void mo_etrace(struct Client *, struct Client *, int, char *[]); |
| 50 |
|
|
|
| 51 |
|
|
struct Message etrace_msgtab = { |
| 52 |
|
|
"ETRACE", 0, 0, 0, 0, MFLG_SLOW, 0, |
| 53 |
michael |
172 |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_etrace, m_ignore} |
| 54 |
adx |
30 |
}; |
| 55 |
|
|
|
| 56 |
|
|
#ifndef STATIC_MODULES |
| 57 |
knight |
31 |
const char *_version = "$Revision$"; |
| 58 |
adx |
30 |
static struct Callback *etrace_cb; |
| 59 |
|
|
|
| 60 |
|
|
static void * |
| 61 |
|
|
va_etrace(va_list args) |
| 62 |
|
|
{ |
| 63 |
|
|
struct Client *source_p = va_arg(args, struct Client *); |
| 64 |
|
|
int parc = va_arg(args, int); |
| 65 |
|
|
char **parv = va_arg(args, char **); |
| 66 |
|
|
|
| 67 |
|
|
do_etrace(source_p, parc, parv); |
| 68 |
|
|
return NULL; |
| 69 |
|
|
} |
| 70 |
|
|
|
| 71 |
|
|
void |
| 72 |
|
|
_modinit(void) |
| 73 |
|
|
{ |
| 74 |
|
|
etrace_cb = register_callback("doing_etrace", va_etrace); |
| 75 |
|
|
mod_add_cmd(&etrace_msgtab); |
| 76 |
|
|
} |
| 77 |
|
|
|
| 78 |
|
|
void |
| 79 |
|
|
_moddeinit(void) |
| 80 |
|
|
{ |
| 81 |
|
|
mod_del_cmd(&etrace_msgtab); |
| 82 |
|
|
uninstall_hook(etrace_cb, va_etrace); |
| 83 |
|
|
} |
| 84 |
|
|
#endif |
| 85 |
|
|
|
| 86 |
db |
849 |
static void report_this_status(struct Client *, struct Client *, int); |
| 87 |
adx |
30 |
|
| 88 |
|
|
/* |
| 89 |
|
|
* do_etrace() |
| 90 |
|
|
*/ |
| 91 |
|
|
static void |
| 92 |
|
|
do_etrace(struct Client *source_p, int parc, char **parv) |
| 93 |
|
|
{ |
| 94 |
|
|
const char *tname = NULL; |
| 95 |
|
|
struct Client *target_p = NULL; |
| 96 |
|
|
int wilds = 0; |
| 97 |
|
|
int do_all = 0; |
| 98 |
db |
849 |
int full_etrace = 0; |
| 99 |
adx |
30 |
dlink_node *ptr; |
| 100 |
|
|
|
| 101 |
db |
849 |
if (parc > 1) |
| 102 |
adx |
30 |
{ |
| 103 |
db |
849 |
if (irccmp(parv[1], "-full") == 0) |
| 104 |
|
|
{ |
| 105 |
|
|
parv++; |
| 106 |
|
|
parc--; |
| 107 |
|
|
full_etrace = 1; |
| 108 |
|
|
} |
| 109 |
|
|
} |
| 110 |
|
|
|
| 111 |
|
|
if (parc > 1) |
| 112 |
|
|
{ |
| 113 |
adx |
30 |
tname = parv[1]; |
| 114 |
db |
849 |
|
| 115 |
adx |
30 |
if (tname != NULL) |
| 116 |
|
|
wilds = strchr(tname, '*') || strchr(tname, '?'); |
| 117 |
|
|
else |
| 118 |
|
|
tname = "*"; |
| 119 |
|
|
} |
| 120 |
|
|
else |
| 121 |
|
|
{ |
| 122 |
|
|
do_all = 1; |
| 123 |
|
|
tname = "*"; |
| 124 |
|
|
} |
| 125 |
|
|
|
| 126 |
db |
856 |
if (IsFull(source_p)) |
| 127 |
|
|
full_etrace = 1; |
| 128 |
|
|
|
| 129 |
adx |
30 |
if (!wilds && !do_all) |
| 130 |
|
|
{ |
| 131 |
|
|
target_p = find_client(tname); |
| 132 |
|
|
|
| 133 |
|
|
if (target_p && MyClient(target_p)) |
| 134 |
db |
849 |
report_this_status(source_p, target_p, full_etrace); |
| 135 |
adx |
30 |
|
| 136 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, |
| 137 |
|
|
source_p->name, tname); |
| 138 |
|
|
return; |
| 139 |
|
|
} |
| 140 |
|
|
|
| 141 |
|
|
DLINK_FOREACH(ptr, local_client_list.head) |
| 142 |
|
|
{ |
| 143 |
|
|
target_p = ptr->data; |
| 144 |
|
|
|
| 145 |
|
|
if (wilds) |
| 146 |
|
|
{ |
| 147 |
|
|
if (match(tname, target_p->name) || match(target_p->name, tname)) |
| 148 |
db |
849 |
report_this_status(source_p, target_p, full_etrace); |
| 149 |
adx |
30 |
} |
| 150 |
|
|
else |
| 151 |
db |
849 |
report_this_status(source_p, target_p, full_etrace); |
| 152 |
adx |
30 |
} |
| 153 |
|
|
|
| 154 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, |
| 155 |
|
|
source_p->name, tname); |
| 156 |
|
|
} |
| 157 |
|
|
|
| 158 |
|
|
/* mo_etrace() |
| 159 |
|
|
* parv[0] = sender prefix |
| 160 |
|
|
* parv[1] = servername |
| 161 |
|
|
*/ |
| 162 |
|
|
static void |
| 163 |
|
|
mo_etrace(struct Client *client_p, struct Client *source_p, |
| 164 |
|
|
int parc, char *parv[]) |
| 165 |
|
|
{ |
| 166 |
|
|
#ifdef STATIC_MODULES |
| 167 |
|
|
do_etrace(source_p, parc, parv); |
| 168 |
|
|
#else |
| 169 |
|
|
execute_callback(etrace_cb, source_p, parc, parv); |
| 170 |
|
|
#endif |
| 171 |
|
|
} |
| 172 |
|
|
|
| 173 |
|
|
/* report_this_status() |
| 174 |
|
|
* |
| 175 |
|
|
* inputs - pointer to client to report to |
| 176 |
|
|
* - pointer to client to report about |
| 177 |
db |
849 |
* - flag full etrace or not |
| 178 |
adx |
30 |
* output - NONE |
| 179 |
|
|
* side effects - NONE |
| 180 |
|
|
*/ |
| 181 |
|
|
static void |
| 182 |
db |
849 |
report_this_status(struct Client *source_p, struct Client *target_p, |
| 183 |
|
|
int full_etrace) |
| 184 |
adx |
30 |
{ |
| 185 |
|
|
const char *name; |
| 186 |
|
|
const char *class_name; |
| 187 |
|
|
char ip[HOSTIPLEN]; |
| 188 |
|
|
|
| 189 |
|
|
/* Should this be sockhost? - stu */ |
| 190 |
|
|
irc_getnameinfo((struct sockaddr*)&target_p->localClient->ip, |
| 191 |
|
|
target_p->localClient->ip.ss_len, ip, HOSTIPLEN, NULL, 0, |
| 192 |
|
|
NI_NUMERICHOST); |
| 193 |
|
|
|
| 194 |
|
|
name = get_client_name(target_p, HIDE_IP); |
| 195 |
|
|
class_name = get_client_class(target_p); |
| 196 |
|
|
|
| 197 |
|
|
set_time(); |
| 198 |
|
|
|
| 199 |
|
|
if (target_p->status == STAT_CLIENT) |
| 200 |
|
|
{ |
| 201 |
db |
849 |
if (full_etrace) |
| 202 |
|
|
{ |
| 203 |
|
|
if (ConfigFileEntry.hide_spoof_ips) |
| 204 |
|
|
sendto_one(source_p, FORM_STR_RPL_ETRACE_FULL, |
| 205 |
|
|
me.name, |
| 206 |
|
|
source_p->name, |
| 207 |
|
|
IsOper(target_p) ? "Oper" : "User", |
| 208 |
|
|
class_name, |
| 209 |
|
|
target_p->name, |
| 210 |
|
|
target_p->username, |
| 211 |
db |
856 |
target_p->host, |
| 212 |
db |
849 |
IsIPSpoof(target_p) ? "255.255.255.255" : ip, |
| 213 |
|
|
IsIPSpoof(target_p) ? "<hidden>" : target_p->client_host, |
| 214 |
|
|
IsIPSpoof(target_p) ? "<hidden>" : target_p->client_server, |
| 215 |
|
|
target_p->info); |
| 216 |
|
|
else |
| 217 |
|
|
sendto_one(source_p, FORM_STR_RPL_ETRACE_FULL, |
| 218 |
|
|
me.name, |
| 219 |
|
|
source_p->name, |
| 220 |
|
|
IsOper(target_p) ? "Oper" : "User", |
| 221 |
|
|
class_name, |
| 222 |
|
|
target_p->name, |
| 223 |
|
|
target_p->username, |
| 224 |
db |
856 |
target_p->host, |
| 225 |
db |
849 |
ip, |
| 226 |
|
|
target_p->client_host, |
| 227 |
|
|
target_p->client_server, |
| 228 |
|
|
target_p->info); |
| 229 |
|
|
} |
| 230 |
adx |
30 |
else |
| 231 |
db |
849 |
{ |
| 232 |
|
|
if (ConfigFileEntry.hide_spoof_ips) |
| 233 |
|
|
sendto_one(source_p, FORM_STR_RPL_ETRACE, |
| 234 |
|
|
me.name, |
| 235 |
|
|
source_p->name, |
| 236 |
|
|
IsOper(target_p) ? "Oper" : "User", |
| 237 |
|
|
class_name, |
| 238 |
|
|
target_p->name, |
| 239 |
|
|
target_p->username, |
| 240 |
db |
856 |
target_p->host, |
| 241 |
db |
849 |
IsIPSpoof(target_p) ? "255.255.255.255" : ip, |
| 242 |
|
|
target_p->info); |
| 243 |
|
|
else |
| 244 |
|
|
sendto_one(source_p, FORM_STR_RPL_ETRACE, |
| 245 |
|
|
me.name, |
| 246 |
|
|
source_p->name, |
| 247 |
|
|
IsOper(target_p) ? "Oper" : "User", |
| 248 |
|
|
class_name, |
| 249 |
|
|
target_p->name, |
| 250 |
|
|
target_p->username, |
| 251 |
db |
856 |
target_p->host, |
| 252 |
db |
849 |
ip, |
| 253 |
|
|
target_p->info); |
| 254 |
|
|
} |
| 255 |
adx |
30 |
} |
| 256 |
|
|
} |