ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/contrib/m_ltrace.c
Revision: 32
Committed: Sun Oct 2 20:41:23 2005 UTC (18 years, 6 months ago) by knight
Content type: text/x-csrc
Original Path: ircd-hybrid/contrib/m_ltrace.c
File size: 10110 byte(s)
Log Message:
- svn:keywords

File Contents

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

Properties

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