/[svn]/ircd-hybrid-7.2/contrib/m_ltrace.c
ViewVC logotype

Contents of /ircd-hybrid-7.2/contrib/m_ltrace.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 891 - (show annotations)
Thu Nov 1 13:44:50 2007 UTC (11 years, 11 months ago) by michael
File MIME type: text/x-chdr
File size: 9962 byte(s)
- Avoid useless irc_getnameinfo calls in several places

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

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.26