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 |
michael |
1011 |
#include "list.h" |
27 |
adx |
30 |
#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 |
db |
856 |
#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 |
adx |
30 |
|
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 |
michael |
172 |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_etrace, m_ignore} |
53 |
adx |
30 |
}; |
54 |
|
|
|
55 |
|
|
#ifndef STATIC_MODULES |
56 |
knight |
31 |
const char *_version = "$Revision$"; |
57 |
adx |
30 |
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 |
db |
849 |
static void report_this_status(struct Client *, struct Client *, int); |
86 |
adx |
30 |
|
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 |
db |
849 |
int full_etrace = 0; |
98 |
adx |
30 |
dlink_node *ptr; |
99 |
|
|
|
100 |
db |
849 |
if (parc > 1) |
101 |
adx |
30 |
{ |
102 |
db |
849 |
if (irccmp(parv[1], "-full") == 0) |
103 |
|
|
{ |
104 |
|
|
parv++; |
105 |
|
|
parc--; |
106 |
|
|
full_etrace = 1; |
107 |
|
|
} |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
if (parc > 1) |
111 |
|
|
{ |
112 |
adx |
30 |
tname = parv[1]; |
113 |
db |
849 |
|
114 |
adx |
30 |
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 |
db |
856 |
if (IsFull(source_p)) |
126 |
|
|
full_etrace = 1; |
127 |
|
|
|
128 |
adx |
30 |
if (!wilds && !do_all) |
129 |
|
|
{ |
130 |
|
|
target_p = find_client(tname); |
131 |
|
|
|
132 |
|
|
if (target_p && MyClient(target_p)) |
133 |
db |
849 |
report_this_status(source_p, target_p, full_etrace); |
134 |
adx |
30 |
|
135 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, |
136 |
michael |
891 |
source_p->name, tname); |
137 |
adx |
30 |
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 |
michael |
891 |
report_this_status(source_p, target_p, full_etrace); |
148 |
adx |
30 |
} |
149 |
|
|
else |
150 |
db |
849 |
report_this_status(source_p, target_p, full_etrace); |
151 |
adx |
30 |
} |
152 |
|
|
|
153 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, |
154 |
michael |
891 |
source_p->name, tname); |
155 |
adx |
30 |
} |
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 |
db |
849 |
* - flag full etrace or not |
177 |
adx |
30 |
* output - NONE |
178 |
|
|
* side effects - NONE |
179 |
|
|
*/ |
180 |
|
|
static void |
181 |
db |
849 |
report_this_status(struct Client *source_p, struct Client *target_p, |
182 |
|
|
int full_etrace) |
183 |
adx |
30 |
{ |
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 |
db |
849 |
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 |
db |
856 |
target_p->host, |
205 |
michael |
891 |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
206 |
db |
849 |
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 |
db |
856 |
target_p->host, |
218 |
michael |
891 |
target_p->sockhost, |
219 |
db |
849 |
target_p->client_host, |
220 |
|
|
target_p->client_server, |
221 |
|
|
target_p->info); |
222 |
|
|
} |
223 |
adx |
30 |
else |
224 |
db |
849 |
{ |
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 |
db |
856 |
target_p->host, |
234 |
michael |
891 |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
235 |
db |
849 |
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 |
db |
856 |
target_p->host, |
245 |
michael |
891 |
target_p->sockhost, |
246 |
db |
849 |
target_p->info); |
247 |
|
|
} |
248 |
adx |
30 |
} |
249 |
|
|
} |