1 |
/* |
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 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "list.h" |
27 |
#include "handlers.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 |
|
44 |
#define FORM_STR_RPL_ETRACE ":%s 709 %s %s %s %s %s %s %s :%s" |
45 |
#define FORM_STR_RPL_ETRACE_FULL ":%s 708 %s %s %s %s %s %s %s %s %s :%s" |
46 |
|
47 |
static void do_etrace(struct Client *, int, char **); |
48 |
static void mo_etrace(struct Client *, struct Client *, int, char *[]); |
49 |
|
50 |
struct Message etrace_msgtab = { |
51 |
"ETRACE", 0, 0, 0, 0, MFLG_SLOW, 0, |
52 |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_etrace, m_ignore} |
53 |
}; |
54 |
|
55 |
#ifndef STATIC_MODULES |
56 |
const char *_version = "$Revision$"; |
57 |
static struct Callback *etrace_cb; |
58 |
|
59 |
static void * |
60 |
va_etrace(va_list args) |
61 |
{ |
62 |
struct Client *source_p = va_arg(args, struct Client *); |
63 |
int parc = va_arg(args, int); |
64 |
char **parv = va_arg(args, char **); |
65 |
|
66 |
do_etrace(source_p, parc, parv); |
67 |
return NULL; |
68 |
} |
69 |
|
70 |
void |
71 |
_modinit(void) |
72 |
{ |
73 |
etrace_cb = register_callback("doing_etrace", va_etrace); |
74 |
mod_add_cmd(&etrace_msgtab); |
75 |
} |
76 |
|
77 |
void |
78 |
_moddeinit(void) |
79 |
{ |
80 |
mod_del_cmd(&etrace_msgtab); |
81 |
uninstall_hook(etrace_cb, va_etrace); |
82 |
} |
83 |
#endif |
84 |
|
85 |
static void report_this_status(struct Client *, struct Client *, int); |
86 |
|
87 |
/* |
88 |
* do_etrace() |
89 |
*/ |
90 |
static void |
91 |
do_etrace(struct Client *source_p, int parc, char **parv) |
92 |
{ |
93 |
const char *tname = NULL; |
94 |
struct Client *target_p = NULL; |
95 |
int wilds = 0; |
96 |
int do_all = 0; |
97 |
int full_etrace = 0; |
98 |
dlink_node *ptr; |
99 |
|
100 |
if (parc > 1) |
101 |
{ |
102 |
if (irccmp(parv[1], "-full") == 0) |
103 |
{ |
104 |
parv++; |
105 |
parc--; |
106 |
full_etrace = 1; |
107 |
} |
108 |
} |
109 |
|
110 |
if (parc > 1) |
111 |
{ |
112 |
tname = parv[1]; |
113 |
|
114 |
if (tname != NULL) |
115 |
wilds = strchr(tname, '*') || strchr(tname, '?'); |
116 |
else |
117 |
tname = "*"; |
118 |
} |
119 |
else |
120 |
{ |
121 |
do_all = 1; |
122 |
tname = "*"; |
123 |
} |
124 |
|
125 |
if (IsFull(source_p)) |
126 |
full_etrace = 1; |
127 |
|
128 |
if (!wilds && !do_all) |
129 |
{ |
130 |
target_p = find_client(tname); |
131 |
|
132 |
if (target_p && MyClient(target_p)) |
133 |
report_this_status(source_p, target_p, full_etrace); |
134 |
|
135 |
sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, |
136 |
source_p->name, tname); |
137 |
return; |
138 |
} |
139 |
|
140 |
DLINK_FOREACH(ptr, local_client_list.head) |
141 |
{ |
142 |
target_p = ptr->data; |
143 |
|
144 |
if (wilds) |
145 |
{ |
146 |
if (match(tname, target_p->name) || match(target_p->name, tname)) |
147 |
report_this_status(source_p, target_p, full_etrace); |
148 |
} |
149 |
else |
150 |
report_this_status(source_p, target_p, full_etrace); |
151 |
} |
152 |
|
153 |
sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, |
154 |
source_p->name, tname); |
155 |
} |
156 |
|
157 |
/* mo_etrace() |
158 |
* parv[0] = sender prefix |
159 |
* parv[1] = servername |
160 |
*/ |
161 |
static void |
162 |
mo_etrace(struct Client *client_p, struct Client *source_p, |
163 |
int parc, char *parv[]) |
164 |
{ |
165 |
#ifdef STATIC_MODULES |
166 |
do_etrace(source_p, parc, parv); |
167 |
#else |
168 |
execute_callback(etrace_cb, source_p, parc, parv); |
169 |
#endif |
170 |
} |
171 |
|
172 |
/* report_this_status() |
173 |
* |
174 |
* inputs - pointer to client to report to |
175 |
* - pointer to client to report about |
176 |
* - flag full etrace or not |
177 |
* output - NONE |
178 |
* side effects - NONE |
179 |
*/ |
180 |
static void |
181 |
report_this_status(struct Client *source_p, struct Client *target_p, |
182 |
int full_etrace) |
183 |
{ |
184 |
const char *name; |
185 |
const char *class_name; |
186 |
|
187 |
name = get_client_name(target_p, HIDE_IP); |
188 |
class_name = get_client_class(target_p); |
189 |
|
190 |
set_time(); |
191 |
|
192 |
if (target_p->status == STAT_CLIENT) |
193 |
{ |
194 |
if (full_etrace) |
195 |
{ |
196 |
if (ConfigFileEntry.hide_spoof_ips) |
197 |
sendto_one(source_p, FORM_STR_RPL_ETRACE_FULL, |
198 |
me.name, |
199 |
source_p->name, |
200 |
IsOper(target_p) ? "Oper" : "User", |
201 |
class_name, |
202 |
target_p->name, |
203 |
target_p->username, |
204 |
target_p->host, |
205 |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
206 |
IsIPSpoof(target_p) ? "<hidden>" : target_p->client_host, |
207 |
IsIPSpoof(target_p) ? "<hidden>" : target_p->client_server, |
208 |
target_p->info); |
209 |
else |
210 |
sendto_one(source_p, FORM_STR_RPL_ETRACE_FULL, |
211 |
me.name, |
212 |
source_p->name, |
213 |
IsOper(target_p) ? "Oper" : "User", |
214 |
class_name, |
215 |
target_p->name, |
216 |
target_p->username, |
217 |
target_p->host, |
218 |
target_p->sockhost, |
219 |
target_p->client_host, |
220 |
target_p->client_server, |
221 |
target_p->info); |
222 |
} |
223 |
else |
224 |
{ |
225 |
if (ConfigFileEntry.hide_spoof_ips) |
226 |
sendto_one(source_p, FORM_STR_RPL_ETRACE, |
227 |
me.name, |
228 |
source_p->name, |
229 |
IsOper(target_p) ? "Oper" : "User", |
230 |
class_name, |
231 |
target_p->name, |
232 |
target_p->username, |
233 |
target_p->host, |
234 |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
235 |
target_p->info); |
236 |
else |
237 |
sendto_one(source_p, FORM_STR_RPL_ETRACE, |
238 |
me.name, |
239 |
source_p->name, |
240 |
IsOper(target_p) ? "Oper" : "User", |
241 |
class_name, |
242 |
target_p->name, |
243 |
target_p->username, |
244 |
target_p->host, |
245 |
target_p->sockhost, |
246 |
target_p->info); |
247 |
} |
248 |
} |
249 |
} |