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 "client.h" |
28 |
#include "hash.h" |
29 |
#include "irc_string.h" |
30 |
#include "ircd.h" |
31 |
#include "numeric.h" |
32 |
#include "fdlist.h" |
33 |
#include "s_bsd.h" |
34 |
#include "s_serv.h" |
35 |
#include "send.h" |
36 |
#include "parse.h" |
37 |
#include "modules.h" |
38 |
#include "conf.h" |
39 |
#include "conf_class.h" |
40 |
|
41 |
|
42 |
static void report_this_status(struct Client *, struct Client *, int); |
43 |
|
44 |
/* |
45 |
* do_etrace() |
46 |
*/ |
47 |
static void |
48 |
do_etrace(struct Client *source_p, int parc, char *parv[]) |
49 |
{ |
50 |
const char *tname = NULL; |
51 |
struct Client *target_p = NULL; |
52 |
int wilds = 0; |
53 |
int do_all = 0; |
54 |
int full_etrace = 0; |
55 |
dlink_node *ptr; |
56 |
|
57 |
sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE, |
58 |
"ETRACE requested by %s (%s@%s) [%s]", |
59 |
source_p->name, source_p->username, |
60 |
source_p->host, source_p->servptr->name); |
61 |
|
62 |
if (parc > 1) |
63 |
{ |
64 |
if (irccmp(parv[1], "-full") == 0) |
65 |
{ |
66 |
++parv; |
67 |
--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; |
89 |
|
90 |
if (!wilds && !do_all) |
91 |
{ |
92 |
target_p = hash_find_client(tname); |
93 |
|
94 |
if (target_p && MyClient(target_p)) |
95 |
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; |
100 |
} |
101 |
|
102 |
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); |
128 |
} |
129 |
|
130 |
/* report_this_status() |
131 |
* |
132 |
* inputs - pointer to client to report to |
133 |
* - pointer to client to report about |
134 |
* - flag full etrace or not |
135 |
* output - NONE |
136 |
* side effects - NONE |
137 |
*/ |
138 |
static void |
139 |
report_this_status(struct Client *source_p, struct Client *target_p, |
140 |
int full_etrace) |
141 |
{ |
142 |
if (target_p->status == STAT_CLIENT) |
143 |
{ |
144 |
if (full_etrace) |
145 |
{ |
146 |
if (ConfigFileEntry.hide_spoof_ips) |
147 |
sendto_one(source_p, form_str(RPL_ETRACE_FULL), |
148 |
me.name, |
149 |
source_p->name, |
150 |
HasUMode(target_p, UMODE_OPER) ? "Oper" : "User", |
151 |
get_client_class(&target_p->localClient->confs), |
152 |
target_p->name, |
153 |
target_p->username, |
154 |
target_p->host, |
155 |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
156 |
IsIPSpoof(target_p) ? "<hidden>" : target_p->localClient->client_host, |
157 |
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 |
} |
198 |
} |
199 |
} |
200 |
|
201 |
static struct Message etrace_msgtab = { |
202 |
"ETRACE", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
203 |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_etrace, m_ignore} |
204 |
}; |
205 |
|
206 |
static void |
207 |
module_init(void) |
208 |
{ |
209 |
mod_add_cmd(&etrace_msgtab); |
210 |
} |
211 |
|
212 |
static void |
213 |
module_exit(void) |
214 |
{ |
215 |
mod_del_cmd(&etrace_msgtab); |
216 |
} |
217 |
|
218 |
struct module module_entry = { |
219 |
.node = { NULL, NULL, NULL }, |
220 |
.name = NULL, |
221 |
.version = "$Revision$", |
222 |
.handle = NULL, |
223 |
.modinit = module_init, |
224 |
.modexit = module_exit, |
225 |
.flags = 0 |
226 |
}; |