ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/contrib/m_ltrace.c
Revision: 1219
Committed: Sun Sep 18 09:02:38 2011 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 9854 byte(s)
Log Message:
- Start cleaning up macros in client.h. Replace several ClientHasSomeCoolFlag()
with simple HasFlag/HasUMode macros.

File Contents

# Content
1 /*
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 * $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 "irc_string.h"
32 #include "ircd.h"
33 #include "numeric.h"
34 #include "fdlist.h"
35 #include "s_bsd.h"
36 #include "s_serv.h"
37 #include "s_conf.h"
38 #include "send.h"
39 #include "msg.h"
40 #include "parse.h"
41 #include "modules.h"
42
43 static void do_ltrace(struct Client *, int, char *[]);
44 static void m_ltrace(struct Client *, struct Client *, int, char *[]);
45 static void mo_ltrace(struct Client *, struct Client *, int, char *[]);
46
47 struct Message ltrace_msgtab = {
48 "LTRACE", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
49 {m_unregistered, m_ltrace, mo_ltrace, m_ignore, mo_ltrace, m_ignore}
50 };
51
52 const char *_version = "$Revision$";
53
54 void
55 _modinit(void)
56 {
57 mod_add_cmd(&ltrace_msgtab);
58 }
59
60 void
61 _moddeinit(void)
62 {
63 mod_del_cmd(&ltrace_msgtab);
64 }
65
66 static void report_this_status(struct Client *, struct Client *, int);
67
68 static void
69 trace_get_dependent(int *const server,
70 int *const client, const struct Client *target_p)
71 {
72 const dlink_node *ptr = NULL;
73
74 (*server)++;
75 (*client) += dlink_list_length(&target_p->serv->client_list);
76
77 DLINK_FOREACH(ptr, target_p->serv->server_list.head)
78 trace_get_dependent(server, client, ptr->data);
79 }
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 = hash_find_client(tname)) == NULL)
121 DLINK_FOREACH(ptr, global_client_list.head)
122 {
123 ac2ptr = ptr->data;
124
125 if (match(tname, ac2ptr->name))
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 sendto_realops_flags(UMODE_SPY, L_ALL,
146 "LTRACE requested by %s (%s@%s) [%s]",
147 source_p->name, source_p->username,
148 source_p->host, source_p->servptr->name);
149
150 doall = (parv[1] && (parc > 1)) ? match(tname, me.name) : 1;
151 wilds = !parv[1] || strchr(tname, '*') || strchr(tname, '?');
152 dow = wilds || doall;
153
154 /* lusers cant issue ltrace.. */
155 if (!dow)
156 {
157 const char* name;
158 const char* class_name;
159
160 target_p = hash_find_client(tname);
161
162 if (target_p && IsClient(target_p))
163 {
164 name = get_client_name(target_p, HIDE_IP);
165 class_name = get_client_class(target_p);
166
167 if (HasUMode(target_p, UMODE_OPER))
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" : target_p->sockhost),
173 CurrentTime - target_p->lasttime,
174 CurrentTime - target_p->localClient->last_privmsg);
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" : target_p->sockhost),
179 CurrentTime - target_p->lasttime,
180 CurrentTime - target_p->localClient->last_privmsg);
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 (!HasUMode(target_p, UMODE_OPER))
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);
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);
217 }
218
219 sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, parv[0], tname);
220 }
221
222 /*
223 * mo_ltrace
224 * parv[0] = sender prefix
225 * parv[1] = servername
226 */
227 static void
228 mo_ltrace(struct Client *client_p, struct Client *source_p,
229 int parc, char *parv[])
230 {
231 if (!HasUMode(source_p, UMODE_OPER))
232 {
233 sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, parv[0],
234 parc > 1 ? parv[1] : me.name);
235 return;
236 }
237
238 if (parc > 2)
239 if (hunt_server(client_p, source_p, ":%s LTRACE %s :%s", 2, parc, parv))
240 return;
241
242 do_ltrace(source_p, parc, parv);
243 }
244
245 /*
246 * report_this_status
247 *
248 * inputs - pointer to client to report to
249 * - pointer to client to report about
250 * output - counter of number of hits
251 * side effects - NONE
252 */
253 static void
254 report_this_status(struct Client *source_p, struct Client *target_p,
255 int dow)
256 {
257 const char *name = NULL;
258 const char *class_name = NULL;
259
260 name = get_client_name(target_p, HIDE_IP);
261 class_name = get_client_class(target_p);
262
263 switch (target_p->status)
264 {
265 case STAT_CONNECTING:
266 sendto_one(source_p, form_str(RPL_TRACECONNECTING), me.name,
267 source_p->name, class_name,
268 HasUMode(source_p, UMODE_ADMIN) ? name : target_p->name);
269 break;
270
271 case STAT_HANDSHAKE:
272 sendto_one(source_p, form_str(RPL_TRACEHANDSHAKE), me.name,
273 source_p->name, class_name,
274 HasUMode(source_p, UMODE_ADMIN) ? name : target_p->name);
275 break;
276
277 case STAT_CLIENT:
278 if (HasUMode(target_p, UMODE_ADMIN))
279 {
280 if (ConfigFileEntry.hide_spoof_ips)
281 sendto_one(source_p, form_str(RPL_TRACEOPERATOR),
282 me.name, source_p->name, class_name, name,
283 (IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost),
284 CurrentTime - target_p->lasttime,
285 CurrentTime - target_p->localClient->last_privmsg);
286 else
287 sendto_one(source_p, form_str(RPL_TRACEOPERATOR),
288 me.name, source_p->name, class_name, name,
289 HasUMode(source_p, UMODE_ADMIN) ? target_p->sockhost :
290 (IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost),
291 CurrentTime - target_p->lasttime,
292 CurrentTime - target_p->localClient->last_privmsg);
293 }
294 else if (HasUMode(target_p, UMODE_OPER))
295 {
296 if (ConfigFileEntry.hide_spoof_ips)
297 sendto_one(source_p, form_str(RPL_TRACEOPERATOR),
298 me.name, source_p->name, class_name, name,
299 (IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost),
300 CurrentTime - target_p->lasttime,
301 CurrentTime - target_p->localClient->last_privmsg);
302 else
303 sendto_one(source_p, form_str(RPL_TRACEOPERATOR),
304 me.name, source_p->name, class_name, name,
305 (IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost),
306 CurrentTime - target_p->lasttime,
307 CurrentTime - target_p->localClient->last_privmsg);
308 }
309 break;
310
311 case STAT_SERVER:
312 {
313 int clients = 0;
314 int servers = 0;
315
316 trace_get_dependent(&servers, &clients, target_p);
317
318 if (!HasUMode(source_p, UMODE_ADMIN))
319 name = get_client_name(target_p, MASK_IP);
320
321 sendto_one(source_p, form_str(RPL_TRACESERVER),
322 me.name, source_p->name, class_name, servers,
323 clients, name, *(target_p->serv->by) ?
324 target_p->serv->by : "*", "*",
325 me.name, CurrentTime - target_p->lasttime);
326 break;
327 }
328
329 case STAT_ME:
330 case STAT_UNKNOWN:
331 break;
332
333 default: /* ...we actually shouldn't come here... --msa */
334 sendto_one(source_p, form_str(RPL_TRACENEWTYPE), me.name,
335 source_p->name, name);
336 break;
337 }
338 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision