| 1 |
adx |
30 |
/* |
| 2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
|
|
* m_ltrace.c: Traces a path to a client/server. |
| 4 |
|
|
* |
| 5 |
|
|
* Copyright (C) 2002 Hybrid Development Team |
| 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 "client.h" |
| 28 |
|
|
#include "common.h" |
| 29 |
|
|
#include "hash.h" |
| 30 |
|
|
#include "ircd.h" |
| 31 |
|
|
#include "numeric.h" |
| 32 |
|
|
#include "s_serv.h" |
| 33 |
|
|
#include "s_conf.h" |
| 34 |
|
|
#include "send.h" |
| 35 |
|
|
#include "msg.h" |
| 36 |
|
|
#include "parse.h" |
| 37 |
|
|
#include "modules.h" |
| 38 |
|
|
|
| 39 |
|
|
static void do_ltrace(struct Client *, int, char **); |
| 40 |
|
|
static void m_ltrace(struct Client *, struct Client *, int, char **); |
| 41 |
|
|
static void mo_ltrace(struct Client *, struct Client *, int, char **); |
| 42 |
|
|
|
| 43 |
|
|
struct Message ltrace_msgtab = { |
| 44 |
|
|
"LTRACE", 0, 0, 0, 0, MFLG_SLOW, 0, |
| 45 |
|
|
{m_unregistered, m_ltrace, mo_ltrace, m_ignore, mo_ltrace, m_ignore} |
| 46 |
|
|
}; |
| 47 |
|
|
|
| 48 |
|
|
#ifndef STATIC_MODULES |
| 49 |
knight |
31 |
const char *_version = "$Revision$"; |
| 50 |
adx |
30 |
static struct Callback *ltrace_cb; |
| 51 |
|
|
|
| 52 |
|
|
static void * |
| 53 |
|
|
va_ltrace(va_list args) |
| 54 |
|
|
{ |
| 55 |
|
|
struct Client *source_p = va_arg(args, struct Client *); |
| 56 |
|
|
int parc = va_arg(args, int); |
| 57 |
|
|
char **parv = va_arg(args, char **); |
| 58 |
|
|
|
| 59 |
|
|
do_ltrace(source_p, parc, parv); |
| 60 |
|
|
return NULL; |
| 61 |
|
|
} |
| 62 |
|
|
|
| 63 |
|
|
void |
| 64 |
|
|
_modinit(void) |
| 65 |
|
|
{ |
| 66 |
|
|
ltrace_cb = register_callback("doing_ltrace", va_ltrace); |
| 67 |
|
|
mod_add_cmd(<race_msgtab); |
| 68 |
|
|
} |
| 69 |
|
|
|
| 70 |
|
|
void |
| 71 |
|
|
_moddeinit(void) |
| 72 |
|
|
{ |
| 73 |
|
|
mod_del_cmd(<race_msgtab); |
| 74 |
|
|
uninstall_hook(ltrace_cb, va_ltrace); |
| 75 |
|
|
} |
| 76 |
|
|
#endif |
| 77 |
|
|
|
| 78 |
|
|
static int report_this_status(struct Client *source_p, struct Client *target_p,int dow, |
| 79 |
|
|
int link_u_p, int link_u_s); |
| 80 |
|
|
|
| 81 |
|
|
/* |
| 82 |
|
|
* m_ltrace() |
| 83 |
|
|
* |
| 84 |
|
|
* parv[0] = sender prefix |
| 85 |
|
|
* parv[1] = target client/server to trace |
| 86 |
|
|
*/ |
| 87 |
|
|
static void |
| 88 |
|
|
m_ltrace(struct Client *client_p, struct Client *source_p, |
| 89 |
|
|
int parc, char *parv[]) |
| 90 |
|
|
{ |
| 91 |
|
|
char *tname; |
| 92 |
|
|
|
| 93 |
|
|
if (parc > 1) |
| 94 |
|
|
tname = parv[1]; |
| 95 |
|
|
else |
| 96 |
|
|
tname = me.name; |
| 97 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFTRACE), |
| 98 |
|
|
me.name, parv[0], tname); |
| 99 |
|
|
} |
| 100 |
|
|
|
| 101 |
|
|
/* |
| 102 |
|
|
* do_ltrace |
| 103 |
|
|
*/ |
| 104 |
|
|
static void |
| 105 |
|
|
do_ltrace(struct Client *source_p, int parc, char **parv) |
| 106 |
|
|
{ |
| 107 |
|
|
struct Client *target_p = NULL; |
| 108 |
|
|
int doall; |
| 109 |
|
|
int wilds, dow; |
| 110 |
|
|
dlink_node *ptr; |
| 111 |
|
|
char *looking_for = parv[0]; |
| 112 |
|
|
char *tname = parc > 1 ? parv[1] : me.name; |
| 113 |
|
|
|
| 114 |
|
|
switch (hunt_server(source_p->from, source_p, ":%s LTRACE :%s", 1,parc,parv)) |
| 115 |
|
|
{ |
| 116 |
|
|
case HUNTED_PASS: /* note: gets here only if parv[1] exists */ |
| 117 |
|
|
{ |
| 118 |
|
|
struct Client *ac2ptr = NULL; |
| 119 |
|
|
|
| 120 |
|
|
if ((ac2ptr = find_client(tname)) == NULL) |
| 121 |
|
|
DLINK_FOREACH(ptr, global_client_list.head) |
| 122 |
|
|
{ |
| 123 |
|
|
ac2ptr = ptr->data; |
| 124 |
|
|
|
| 125 |
|
|
if (match(tname, ac2ptr->name) || match(ac2ptr->name, tname)) |
| 126 |
|
|
break; |
| 127 |
|
|
else |
| 128 |
|
|
ac2ptr = NULL; |
| 129 |
|
|
} |
| 130 |
|
|
|
| 131 |
|
|
if (ac2ptr != NULL) |
| 132 |
|
|
sendto_one(source_p, form_str(RPL_TRACELINK), me.name, looking_for, |
| 133 |
|
|
ircd_version, tname, ac2ptr->from->name); |
| 134 |
|
|
else |
| 135 |
|
|
sendto_one(source_p, form_str(RPL_TRACELINK), me.name, looking_for, |
| 136 |
|
|
ircd_version, tname, "ac2ptr_is_NULL!!"); |
| 137 |
|
|
return; |
| 138 |
|
|
} |
| 139 |
|
|
case HUNTED_ISME: |
| 140 |
|
|
break; |
| 141 |
|
|
default: |
| 142 |
|
|
return; |
| 143 |
|
|
} |
| 144 |
|
|
|
| 145 |
|
|
doall = (parv[1] && (parc > 1)) ? match(tname, me.name): TRUE; |
| 146 |
michael |
290 |
wilds = !parv[1] || has_wildcards(tname); |
| 147 |
adx |
30 |
dow = wilds || doall; |
| 148 |
|
|
|
| 149 |
|
|
/* lusers cant issue ltrace.. */ |
| 150 |
|
|
if (!dow) |
| 151 |
|
|
{ |
| 152 |
|
|
const char* name; |
| 153 |
|
|
const char* class_name; |
| 154 |
|
|
char ipaddr[HOSTIPLEN]; |
| 155 |
|
|
|
| 156 |
|
|
target_p = find_client(tname); |
| 157 |
|
|
|
| 158 |
|
|
if (target_p && IsClient(target_p)) |
| 159 |
|
|
{ |
| 160 |
|
|
name = get_client_name(target_p, HIDE_IP); |
| 161 |
|
|
/* Should this be sockhost? - stu */ |
| 162 |
|
|
irc_getnameinfo((struct sockaddr*)&target_p->localClient->ip, |
| 163 |
|
|
target_p->localClient->ip.ss_len, ipaddr, |
| 164 |
|
|
HOSTIPLEN, NULL, 0, NI_NUMERICHOST); |
| 165 |
db |
161 |
class_name = ((struct ConfItem *)target_p->localClient->class->conf_ptr)->name; |
| 166 |
adx |
30 |
|
| 167 |
|
|
if (IsOper(target_p)) |
| 168 |
|
|
{ |
| 169 |
|
|
if (ConfigFileEntry.hide_spoof_ips) |
| 170 |
|
|
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
| 171 |
|
|
me.name, source_p->name, class_name, name, |
| 172 |
|
|
(IsIPSpoof(target_p) ? "255.255.255.255" : ipaddr), |
| 173 |
|
|
CurrentTime - target_p->lasttime, |
| 174 |
|
|
CurrentTime - target_p->localClient->last); |
| 175 |
|
|
else |
| 176 |
|
|
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
| 177 |
|
|
me.name, source_p->name, class_name, name, |
| 178 |
|
|
(IsIPSpoof(target_p) ? "255.255.255.255" : ipaddr), |
| 179 |
|
|
CurrentTime - target_p->lasttime, |
| 180 |
|
|
CurrentTime - target_p->localClient->last); |
| 181 |
|
|
} |
| 182 |
|
|
} |
| 183 |
|
|
|
| 184 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFTRACE), |
| 185 |
|
|
me.name, source_p->name, tname); |
| 186 |
|
|
return; |
| 187 |
|
|
} |
| 188 |
|
|
|
| 189 |
|
|
/* report all opers */ |
| 190 |
|
|
DLINK_FOREACH(ptr, local_client_list.head) |
| 191 |
|
|
{ |
| 192 |
|
|
target_p = ptr->data; |
| 193 |
|
|
|
| 194 |
|
|
if (!IsOper(target_p)) |
| 195 |
|
|
continue; |
| 196 |
|
|
|
| 197 |
|
|
if (!doall && wilds && !match(tname, target_p->name)) |
| 198 |
|
|
continue; |
| 199 |
|
|
|
| 200 |
|
|
if (!dow && irccmp(tname, target_p->name)) |
| 201 |
|
|
continue; |
| 202 |
|
|
|
| 203 |
|
|
report_this_status(source_p, target_p, dow, 0, 0); |
| 204 |
|
|
} |
| 205 |
|
|
|
| 206 |
|
|
/* report all servers */ |
| 207 |
|
|
DLINK_FOREACH(ptr, serv_list.head) |
| 208 |
|
|
{ |
| 209 |
|
|
target_p = ptr->data; |
| 210 |
|
|
|
| 211 |
|
|
if (!doall && wilds && !match(tname, target_p->name)) |
| 212 |
|
|
continue; |
| 213 |
|
|
if (!dow && irccmp(tname, target_p->name)) |
| 214 |
|
|
continue; |
| 215 |
|
|
|
| 216 |
|
|
report_this_status(source_p, target_p, dow, target_p->serv->dep_users, |
| 217 |
|
|
target_p->serv->dep_servers); |
| 218 |
|
|
} |
| 219 |
|
|
|
| 220 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, parv[0], tname); |
| 221 |
|
|
} |
| 222 |
|
|
|
| 223 |
|
|
/* |
| 224 |
|
|
* mo_ltrace |
| 225 |
|
|
* parv[0] = sender prefix |
| 226 |
|
|
* parv[1] = servername |
| 227 |
|
|
*/ |
| 228 |
|
|
static void |
| 229 |
|
|
mo_ltrace(struct Client *client_p, struct Client *source_p, |
| 230 |
|
|
int parc, char *parv[]) |
| 231 |
|
|
{ |
| 232 |
|
|
if (!IsOper(source_p)) |
| 233 |
|
|
{ |
| 234 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, parv[0], |
| 235 |
|
|
parc > 1 ? parv[1] : me.name); |
| 236 |
|
|
return; |
| 237 |
|
|
} |
| 238 |
|
|
|
| 239 |
|
|
if (parc > 2) |
| 240 |
|
|
if (hunt_server(client_p, source_p, ":%s LTRACE %s :%s", 2, parc, parv)) |
| 241 |
|
|
return; |
| 242 |
|
|
|
| 243 |
|
|
#ifdef STATIC_MODULES |
| 244 |
|
|
do_ltrace(source_p, parc, parv); |
| 245 |
|
|
#else |
| 246 |
|
|
execute_callback(ltrace_cb, source_p, parc, parv); |
| 247 |
|
|
#endif |
| 248 |
|
|
} |
| 249 |
|
|
|
| 250 |
|
|
/* |
| 251 |
|
|
* report_this_status |
| 252 |
|
|
* |
| 253 |
|
|
* inputs - pointer to client to report to |
| 254 |
|
|
* - pointer to client to report about |
| 255 |
|
|
* output - counter of number of hits |
| 256 |
|
|
* side effects - NONE |
| 257 |
|
|
*/ |
| 258 |
|
|
static int |
| 259 |
|
|
report_this_status(struct Client *source_p, struct Client *target_p, |
| 260 |
|
|
int dow, int link_u_p, int link_s_p) |
| 261 |
|
|
{ |
| 262 |
|
|
const char *name = NULL; |
| 263 |
|
|
const char *class_name = NULL; |
| 264 |
|
|
char ip[HOSTIPLEN]; |
| 265 |
|
|
|
| 266 |
|
|
/* Should this be sockhost? - stu */ |
| 267 |
|
|
irc_getnameinfo((struct sockaddr *)&target_p->localClient->ip, |
| 268 |
|
|
target_p->localClient->ip.ss_len, ip, |
| 269 |
|
|
HOSTIPLEN, NULL, 0, NI_NUMERICHOST); |
| 270 |
|
|
|
| 271 |
|
|
name = get_client_name(target_p, HIDE_IP); |
| 272 |
db |
161 |
class_name = ((struct ConfItem *)target_p->localClient->class->conf_ptr)->name; |
| 273 |
adx |
30 |
|
| 274 |
|
|
switch (target_p->status) |
| 275 |
|
|
{ |
| 276 |
|
|
case STAT_CONNECTING: |
| 277 |
|
|
sendto_one(source_p, form_str(RPL_TRACECONNECTING), me.name, |
| 278 |
|
|
source_p->name, class_name, |
| 279 |
|
|
IsAdmin(source_p) ? name : target_p->name); |
| 280 |
|
|
break; |
| 281 |
|
|
|
| 282 |
|
|
case STAT_HANDSHAKE: |
| 283 |
|
|
sendto_one(source_p, form_str(RPL_TRACEHANDSHAKE), me.name, |
| 284 |
|
|
source_p->name, class_name, |
| 285 |
|
|
IsAdmin(source_p) ? name : target_p->name); |
| 286 |
|
|
break; |
| 287 |
|
|
|
| 288 |
|
|
case STAT_CLIENT: |
| 289 |
|
|
if (IsAdmin(target_p)) |
| 290 |
|
|
{ |
| 291 |
|
|
if (ConfigFileEntry.hide_spoof_ips) |
| 292 |
|
|
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
| 293 |
|
|
me.name, source_p->name, class_name, name, |
| 294 |
|
|
(IsIPSpoof(target_p) ? "255.255.255.255" : ip), |
| 295 |
|
|
CurrentTime - target_p->lasttime, |
| 296 |
|
|
CurrentTime - target_p->localClient->last); |
| 297 |
|
|
else |
| 298 |
|
|
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
| 299 |
|
|
me.name, source_p->name, class_name, name, |
| 300 |
|
|
IsAdmin(source_p) ? ip : |
| 301 |
|
|
(IsIPSpoof(target_p) ? "255.255.255.255" : ip), |
| 302 |
|
|
CurrentTime - target_p->lasttime, |
| 303 |
|
|
CurrentTime - target_p->localClient->last); |
| 304 |
|
|
} |
| 305 |
|
|
else if (IsOper(target_p)) |
| 306 |
|
|
{ |
| 307 |
|
|
if (ConfigFileEntry.hide_spoof_ips) |
| 308 |
|
|
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
| 309 |
|
|
me.name, source_p->name, class_name, name, |
| 310 |
|
|
(IsIPSpoof(target_p) ? "255.255.255.255" : ip), |
| 311 |
|
|
CurrentTime - target_p->lasttime, |
| 312 |
|
|
CurrentTime - target_p->localClient->last); |
| 313 |
|
|
else |
| 314 |
|
|
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
| 315 |
|
|
me.name, source_p->name, class_name, name, |
| 316 |
|
|
(IsIPSpoof(target_p) ? "255.255.255.255" : ip), |
| 317 |
|
|
CurrentTime - target_p->lasttime, |
| 318 |
|
|
CurrentTime - target_p->localClient->last); |
| 319 |
|
|
} |
| 320 |
|
|
break; |
| 321 |
|
|
|
| 322 |
|
|
case STAT_SERVER: |
| 323 |
|
|
if(!IsAdmin(source_p)) |
| 324 |
db |
161 |
class_name = ((struct ConfItem *)target_p->localClient->class->conf_ptr)->name; |
| 325 |
adx |
30 |
|
| 326 |
|
|
sendto_one(source_p, form_str(RPL_TRACESERVER), |
| 327 |
|
|
me.name, source_p->name, class_name, link_s_p, |
| 328 |
|
|
link_u_p, name, *(target_p->serv->by) ? |
| 329 |
|
|
target_p->serv->by : "*", "*", |
| 330 |
|
|
me.name, CurrentTime - target_p->lasttime); |
| 331 |
|
|
break; |
| 332 |
|
|
|
| 333 |
|
|
case STAT_ME: |
| 334 |
|
|
case STAT_UNKNOWN: |
| 335 |
|
|
break; |
| 336 |
|
|
|
| 337 |
|
|
default: /* ...we actually shouldn't come here... --msa */ |
| 338 |
|
|
sendto_one(source_p, form_str(RPL_TRACENEWTYPE), me.name, |
| 339 |
|
|
source_p->name, name); |
| 340 |
|
|
break; |
| 341 |
|
|
} |
| 342 |
|
|
|
| 343 |
|
|
return 0; |
| 344 |
|
|
} |