ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_trace.c
Revision: 1832
Committed: Fri Apr 19 19:16:09 2013 UTC (13 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 12166 byte(s)
Log Message:
- Made all numeric defines use the actual string instead of the numeric value
  which allows to use gcc's printf format attribute
- Remove current message locale implementation

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_trace.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 "client.h"
28     #include "hash.h"
29     #include "irc_string.h"
30     #include "ircd.h"
31     #include "numeric.h"
32     #include "s_bsd.h"
33     #include "s_serv.h"
34     #include "send.h"
35     #include "parse.h"
36     #include "modules.h"
37 michael 1309 #include "conf.h"
38 michael 1632 #include "conf_class.h"
39 adx 30
40 michael 1230
41 michael 889 static void do_actual_trace(struct Client *, int, char *[]);
42     static void report_this_status(struct Client *, struct Client *, int);
43 adx 30
44 michael 889 static void
45     trace_get_dependent(int *const server,
46     int *const client, const struct Client *target_p)
47     {
48     const dlink_node *ptr = NULL;
49    
50     (*server)++;
51     (*client) += dlink_list_length(&target_p->serv->client_list);
52    
53     DLINK_FOREACH(ptr, target_p->serv->server_list.head)
54     trace_get_dependent(server, client, ptr->data);
55     }
56    
57 adx 30 /*
58     * m_trace()
59     *
60     * parv[0] = sender prefix
61     * parv[1] = target client/server to trace
62     */
63     static void
64     m_trace(struct Client *client_p, struct Client *source_p,
65     int parc, char *parv[])
66     {
67     const char *tname;
68    
69     if (parc > 1)
70     tname = parv[1];
71     else
72     tname = me.name;
73    
74 michael 1832 sendto_one(source_p, RPL_ENDOFTRACE,
75 adx 30 me.name, source_p->name, tname);
76     }
77    
78    
79     /* mo_trace()
80     * parv[0] = sender prefix
81     * parv[1] = servername
82     */
83     static void
84     mo_trace(struct Client *client_p, struct Client *source_p,
85     int parc, char *parv[])
86     {
87     dlink_node *ptr;
88     const char *tname;
89     const char *from, *to;
90    
91     if (parc > 2)
92     if (hunt_server(client_p, source_p, ":%s TRACE %s :%s", 2, parc, parv))
93     return;
94    
95     if (parc > 1)
96     tname = parv[1];
97     else
98     tname = me.name;
99    
100     if (!MyConnect(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
101     {
102     from = me.id;
103     to = source_p->id;
104     }
105     else
106     {
107     from = me.name;
108     to = source_p->name;
109     }
110    
111     switch (hunt_server(client_p, source_p, ":%s TRACE :%s", 1, parc, parv))
112     {
113     case HUNTED_PASS: /* note: gets here only if parv[1] exists */
114     {
115     struct Client *ac2ptr = NULL;
116    
117 michael 1169 if ((ac2ptr = hash_find_client(tname)) == NULL)
118 adx 30 {
119     DLINK_FOREACH(ptr, global_client_list.head)
120     {
121     ac2ptr = ptr->data;
122    
123 michael 1652 if (!match(tname, ac2ptr->name))
124 adx 30 break;
125     else
126     ac2ptr = NULL;
127     }
128     }
129    
130     if (ac2ptr != NULL)
131 michael 1832 sendto_one(source_p, RPL_TRACELINK, from, to,
132 adx 30 ircd_version, tname, ac2ptr->from->name);
133     else
134 michael 1832 sendto_one(source_p, RPL_TRACELINK, from, to,
135 adx 30 ircd_version, tname, "ac2ptr_is_NULL!!");
136     return;
137     }
138 michael 1121
139 adx 30 case HUNTED_ISME:
140 michael 1149 do_actual_trace(source_p, parc, parv);
141 adx 30 break;
142     default:
143     return;
144     }
145     }
146    
147 michael 1149 /*
148     ** ms_trace
149     ** parv[0] = sender prefix
150     ** parv[1] = servername
151     */
152 adx 30 static void
153 michael 1149 ms_trace(struct Client *client_p, struct Client *source_p,
154     int parc, char *parv[])
155     {
156     if (hunt_server(client_p, source_p, ":%s TRACE %s :%s", 2, parc, parv))
157     return;
158    
159 michael 1219 if (HasUMode(source_p, UMODE_OPER))
160 michael 1149 mo_trace(client_p, source_p, parc, parv);
161     }
162    
163     static void
164 michael 889 do_actual_trace(struct Client *source_p, int parc, char *parv[])
165 adx 30 {
166     struct Client *target_p = NULL;
167     int doall = 0;
168 michael 889 int wilds, dow;
169 adx 30 dlink_node *ptr;
170     const char *from, *to, *tname;
171    
172     if (parc > 1)
173     tname = parv[1];
174     else
175     tname = me.name;
176    
177     if (!MyConnect(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
178     {
179     from = me.id;
180     to = source_p->id;
181     }
182     else
183     {
184     from = me.name;
185     to = source_p->name;
186     }
187    
188 michael 1618 sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
189 michael 1144 "TRACE requested by %s (%s@%s) [%s]",
190     source_p->name, source_p->username,
191     source_p->host, source_p->servptr->name);
192    
193 michael 1652 if (!match(tname, me.name))
194 michael 1243 doall = 1;
195 adx 30 else if (!MyClient(source_p) && !strcmp(tname, me.id))
196     {
197 michael 1243 doall = 1;
198 adx 30 tname = me.name;
199     }
200    
201 michael 1400 wilds = !parv[1] || has_wildcards(tname);
202 adx 30 dow = wilds || doall;
203    
204     set_time();
205 michael 1219 if (!HasUMode(source_p, UMODE_OPER) || !dow) /* non-oper traces must be full nicks */
206 adx 30 /* lets also do this for opers tracing nicks */
207     {
208     const char *name;
209 michael 1169 target_p = hash_find_client(tname);
210 adx 30
211     if (target_p && IsClient(target_p))
212     {
213     name = get_client_name(target_p, HIDE_IP);
214    
215 michael 1219 if (HasUMode(target_p, UMODE_OPER))
216 adx 30 {
217 michael 1832 sendto_one(source_p, RPL_TRACEOPERATOR,
218 michael 1632 from, to, get_client_class(&target_p->localClient->confs), name,
219 michael 891 IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost,
220 michael 1241 CurrentTime - target_p->localClient->lasttime,
221 michael 1783 idle_time_get(source_p, target_p));
222 adx 30 }
223     else
224     {
225 michael 1832 sendto_one(source_p, RPL_TRACEUSER,
226 michael 1632 from, to, get_client_class(&target_p->localClient->confs), name,
227 michael 891 IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost,
228 michael 1241 CurrentTime - target_p->localClient->lasttime,
229 michael 1783 idle_time_get(source_p, target_p));
230 adx 30 }
231     }
232    
233 michael 1832 sendto_one(source_p, RPL_ENDOFTRACE,
234 adx 30 from, to, tname);
235     return;
236     }
237    
238     /* report all direct connections */
239     DLINK_FOREACH(ptr, local_client_list.head)
240     {
241     target_p = ptr->data;
242    
243 michael 1219 if (HasUMode(target_p, UMODE_INVISIBLE) && dow &&
244     !(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) &&
245     !HasUMode(target_p, UMODE_OPER) && (target_p != source_p))
246 adx 30 continue;
247 michael 1652 if (!doall && wilds && match(tname, target_p->name))
248 adx 30 continue;
249     if (!dow && irccmp(tname, target_p->name))
250     continue;
251    
252 michael 889 report_this_status(source_p, target_p, dow);
253 adx 30 }
254    
255     DLINK_FOREACH(ptr, serv_list.head)
256     {
257     target_p = ptr->data;
258    
259 michael 1652 if (!doall && wilds && match(tname, target_p->name))
260 adx 30 continue;
261     if (!dow && irccmp(tname, target_p->name))
262     continue;
263    
264 michael 889 report_this_status(source_p, target_p, dow);
265 adx 30 }
266    
267     /* This section is to report the unknowns */
268     DLINK_FOREACH(ptr, unknown_list.head)
269     {
270     target_p = ptr->data;
271    
272 michael 1652 if (!doall && wilds && match(tname, target_p->name))
273 adx 30 continue;
274     if (!dow && irccmp(tname, target_p->name))
275     continue;
276    
277 michael 889 report_this_status(source_p, target_p, dow);
278 adx 30 }
279    
280 michael 1632 DLINK_FOREACH(ptr, class_get_list()->head)
281 adx 30 {
282 michael 1632 const struct ClassItem *class = ptr->data;
283 michael 889
284 michael 1632 if (class->ref_count > 0)
285 michael 1832 sendto_one(source_p, RPL_TRACECLASS,
286 michael 1632 from, to, class->name, class->ref_count);
287 adx 30 }
288    
289 michael 1832 sendto_one(source_p, RPL_ENDOFTRACE, from, to, tname);
290 adx 30 }
291    
292     /* report_this_status()
293     *
294     * inputs - pointer to client to report to
295     * - pointer to client to report about
296     * output - counter of number of hits
297     * side effects - NONE
298     */
299 michael 889 static void
300     report_this_status(struct Client *source_p, struct Client *target_p, int dow)
301 adx 30 {
302     const char *name;
303     const char *class_name;
304     const char *from, *to;
305    
306     if (!MyConnect(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
307     {
308     from = me.id;
309     to = source_p->id;
310     }
311     else
312     {
313     from = me.name;
314     to = source_p->name;
315     }
316    
317     name = get_client_name(target_p, HIDE_IP);
318 michael 1632 class_name = get_client_class(&target_p->localClient->confs);
319 adx 30
320     set_time();
321    
322 michael 889 switch (target_p->status)
323 adx 30 {
324     case STAT_CONNECTING:
325 michael 1832 sendto_one(source_p, RPL_TRACECONNECTING,
326 adx 30 from, to, class_name,
327 michael 1219 HasUMode(source_p, UMODE_ADMIN) ? name : target_p->name);
328 adx 30 break;
329     case STAT_HANDSHAKE:
330 michael 1832 sendto_one(source_p, RPL_TRACEHANDSHAKE,
331 adx 30 from, to, class_name,
332 michael 1219 HasUMode(source_p, UMODE_ADMIN) ? name : target_p->name);
333 adx 30 break;
334     case STAT_ME:
335     break;
336     case STAT_UNKNOWN:
337     /* added time -Taner */
338 michael 1832 sendto_one(source_p, RPL_TRACEUNKNOWN,
339 michael 891 from, to, class_name, name, target_p->sockhost,
340 michael 1241 target_p->localClient->firsttime ? /* TBD: can't be 0 */
341     CurrentTime - target_p->localClient->firsttime : -1);
342 adx 30 break;
343     case STAT_CLIENT:
344 michael 891 /*
345     * Only opers see users if there is a wildcard
346 adx 30 * but anyone can see all the opers.
347     */
348 michael 1219 if ((HasUMode(source_p, UMODE_OPER) &&
349     (MyClient(source_p) || !(dow && HasUMode(target_p, UMODE_INVISIBLE))))
350     || !dow || HasUMode(target_p, UMODE_OPER))
351 adx 30 {
352 michael 1219 if (HasUMode(target_p, UMODE_ADMIN) && !ConfigFileEntry.hide_spoof_ips)
353 michael 1832 sendto_one(source_p, RPL_TRACEOPERATOR,
354 adx 30 from, to, class_name, name,
355 michael 1219 HasUMode(source_p, UMODE_ADMIN) ? target_p->sockhost : "255.255.255.255",
356 michael 1241 CurrentTime - target_p->localClient->lasttime,
357 michael 1783 idle_time_get(source_p, target_p));
358 adx 30
359 michael 1219 else if (HasUMode(target_p, UMODE_OPER))
360 adx 30 {
361     if (ConfigFileEntry.hide_spoof_ips)
362 michael 1832 sendto_one(source_p, RPL_TRACEOPERATOR,
363 adx 30 from, to, class_name, name,
364 michael 891 IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost,
365 michael 1241 CurrentTime - target_p->localClient->lasttime,
366 michael 1783 idle_time_get(source_p, target_p));
367 adx 30 else
368 michael 1832 sendto_one(source_p, RPL_TRACEOPERATOR,
369 adx 30 from, to, class_name, name,
370 michael 891 MyOper(source_p) ? target_p->sockhost :
371     (IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost),
372 michael 1241 CurrentTime - target_p->localClient->lasttime,
373 michael 1783 idle_time_get(source_p, target_p));
374 adx 30 }
375     else
376     {
377     if (ConfigFileEntry.hide_spoof_ips)
378 michael 1832 sendto_one(source_p, RPL_TRACEUSER,
379 adx 30 from, to, class_name, name,
380 michael 891 IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost,
381 michael 1241 CurrentTime - target_p->localClient->lasttime,
382 michael 1783 idle_time_get(source_p, target_p));
383 adx 30 else
384 michael 1832 sendto_one(source_p, RPL_TRACEUSER,
385 adx 30 from, to, class_name, name,
386 michael 891 MyOper(source_p) ? target_p->sockhost :
387     (IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost),
388 michael 1241 CurrentTime - target_p->localClient->lasttime,
389 michael 1783 idle_time_get(source_p, target_p));
390 adx 30 }
391     }
392     break;
393     case STAT_SERVER:
394 michael 889 {
395     int clients = 0;
396     int servers = 0;
397    
398     trace_get_dependent(&servers, &clients, target_p);
399    
400 michael 1219 if (!HasUMode(source_p, UMODE_ADMIN))
401 adx 30 name = get_client_name(target_p, MASK_IP);
402    
403 michael 1832 sendto_one(source_p, RPL_TRACESERVER,
404 michael 889 from, to, class_name, servers,
405     clients, name, *(target_p->serv->by) ?
406 adx 30 target_p->serv->by : "*", "*",
407 michael 1241 me.name, CurrentTime - target_p->localClient->lasttime);
408 adx 30 break;
409 michael 889 }
410 adx 30
411     default: /* ...we actually shouldn't come here... --msa */
412 michael 1832 sendto_one(source_p, RPL_TRACENEWTYPE,
413 michael 889 from, to, name);
414 adx 30 break;
415     }
416     }
417 michael 1230
418     static struct Message trace_msgtab = {
419     "TRACE", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
420     { m_unregistered, m_trace, ms_trace, m_ignore, mo_trace, m_ignore }
421     };
422    
423     static void
424     module_init(void)
425     {
426     mod_add_cmd(&trace_msgtab);
427     }
428    
429     static void
430     module_exit(void)
431     {
432     mod_del_cmd(&trace_msgtab);
433     }
434    
435     struct module module_entry = {
436     .node = { NULL, NULL, NULL },
437     .name = NULL,
438     .version = "$Revision$",
439     .handle = NULL,
440     .modinit = module_init,
441     .modexit = module_exit,
442     .flags = 0
443     };

Properties

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