ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_trace.c
Revision: 3116
Committed: Fri Mar 7 19:06:03 2014 UTC (10 years, 1 month ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/m_trace.c
File size: 11720 byte(s)
Log Message:
- m_trace.c: get rid of remaining from & to pointers

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 1997-2014 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * USA
20     */
21    
22 michael 2820 /*! \file m_trace.c
23     * \brief Includes required functions for processing the TRACE command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "client.h"
30     #include "hash.h"
31     #include "irc_string.h"
32     #include "ircd.h"
33     #include "numeric.h"
34     #include "s_bsd.h"
35     #include "s_serv.h"
36     #include "send.h"
37     #include "parse.h"
38     #include "modules.h"
39 michael 1309 #include "conf.h"
40 michael 1632 #include "conf_class.h"
41 adx 30
42 michael 1230
43 michael 889 static void do_actual_trace(struct Client *, int, char *[]);
44     static void report_this_status(struct Client *, struct Client *, int);
45 adx 30
46 michael 889 static void
47 michael 2262 trace_get_dependent(unsigned int *const server,
48     unsigned int *const client, const struct Client *target_p)
49 michael 889 {
50     const dlink_node *ptr = NULL;
51    
52     (*server)++;
53     (*client) += dlink_list_length(&target_p->serv->client_list);
54    
55     DLINK_FOREACH(ptr, target_p->serv->server_list.head)
56     trace_get_dependent(server, client, ptr->data);
57     }
58    
59 adx 30 /*
60     * m_trace()
61     *
62 michael 3096 * parv[0] = command
63 adx 30 * parv[1] = target client/server to trace
64     */
65 michael 2820 static int
66 adx 30 m_trace(struct Client *client_p, struct Client *source_p,
67     int parc, char *parv[])
68     {
69 michael 2262 const char *tname = NULL;
70 adx 30
71     if (parc > 1)
72     tname = parv[1];
73     else
74     tname = me.name;
75    
76 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFTRACE, tname);
77 michael 2820 return 0;
78 adx 30 }
79    
80     /* mo_trace()
81 michael 3096 * parv[0] = command
82 adx 30 * parv[1] = servername
83     */
84 michael 2820 static int
85 adx 30 mo_trace(struct Client *client_p, struct Client *source_p,
86     int parc, char *parv[])
87     {
88 michael 3116 dlink_node *ptr = NULL;
89     const char *tname = NULL;
90 adx 30
91     if (parc > 2)
92 michael 2746 if (hunt_server(client_p, source_p, ":%s TRACE %s :%s", 2, parc, parv) != HUNTED_ISME)
93 michael 2820 return 0;
94 adx 30
95     if (parc > 1)
96     tname = parv[1];
97     else
98     tname = me.name;
99    
100     switch (hunt_server(client_p, source_p, ":%s TRACE :%s", 1, parc, parv))
101     {
102     case HUNTED_PASS: /* note: gets here only if parv[1] exists */
103     {
104     struct Client *ac2ptr = NULL;
105    
106 michael 1169 if ((ac2ptr = hash_find_client(tname)) == NULL)
107 adx 30 {
108     DLINK_FOREACH(ptr, global_client_list.head)
109     {
110     ac2ptr = ptr->data;
111    
112 michael 1652 if (!match(tname, ac2ptr->name))
113 adx 30 break;
114     else
115     ac2ptr = NULL;
116     }
117     }
118    
119 michael 3109 if (ac2ptr != NULL)
120     sendto_one_numeric(source_p, &me, RPL_TRACELINK,
121     ircd_version, tname, ac2ptr->from->name);
122 adx 30 else
123 michael 3109 sendto_one_numeric(source_p, &me, RPL_TRACELINK,
124     ircd_version, tname, "ac2ptr_is_NULL!!");
125 michael 2820 return 0;
126 adx 30 }
127 michael 1121
128 adx 30 case HUNTED_ISME:
129 michael 1149 do_actual_trace(source_p, parc, parv);
130 adx 30 break;
131     default:
132 michael 2820 return 0;
133 adx 30 }
134 michael 2820
135     return 0;
136 adx 30 }
137    
138 michael 1149 /*
139     ** ms_trace
140 michael 3096 ** parv[0] = command
141 michael 1149 ** parv[1] = servername
142     */
143 michael 2820 static int
144 michael 1149 ms_trace(struct Client *client_p, struct Client *source_p,
145     int parc, char *parv[])
146     {
147 michael 2863 if (hunt_server(client_p, source_p, ":%s TRACE %s :%s",
148     2, parc, parv) != HUNTED_ISME)
149 michael 2820 return 0;
150 michael 1149
151 michael 1219 if (HasUMode(source_p, UMODE_OPER))
152 michael 1149 mo_trace(client_p, source_p, parc, parv);
153 michael 2820 return 0;
154 michael 1149 }
155    
156     static void
157 michael 889 do_actual_trace(struct Client *source_p, int parc, char *parv[])
158 adx 30 {
159     struct Client *target_p = NULL;
160     int doall = 0;
161 michael 889 int wilds, dow;
162 adx 30 dlink_node *ptr;
163 michael 3109 const char *tname;
164 adx 30
165     if (parc > 1)
166     tname = parv[1];
167     else
168     tname = me.name;
169    
170 michael 1618 sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
171 michael 1144 "TRACE requested by %s (%s@%s) [%s]",
172     source_p->name, source_p->username,
173     source_p->host, source_p->servptr->name);
174    
175 michael 1652 if (!match(tname, me.name))
176 michael 1243 doall = 1;
177 adx 30 else if (!MyClient(source_p) && !strcmp(tname, me.id))
178     {
179 michael 1243 doall = 1;
180 adx 30 tname = me.name;
181     }
182    
183 michael 1400 wilds = !parv[1] || has_wildcards(tname);
184 adx 30 dow = wilds || doall;
185    
186     set_time();
187 michael 1219 if (!HasUMode(source_p, UMODE_OPER) || !dow) /* non-oper traces must be full nicks */
188 adx 30 /* lets also do this for opers tracing nicks */
189     {
190     const char *name;
191 michael 1169 target_p = hash_find_client(tname);
192 michael 2345
193 michael 2820 if (target_p && IsClient(target_p))
194 adx 30 {
195     name = get_client_name(target_p, HIDE_IP);
196    
197 michael 1219 if (HasUMode(target_p, UMODE_OPER))
198 adx 30 {
199 michael 3109 sendto_one_numeric(source_p, &me, RPL_TRACEOPERATOR,
200     get_client_class(&target_p->localClient->confs), name,
201 michael 891 IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost,
202 michael 1241 CurrentTime - target_p->localClient->lasttime,
203 michael 1783 idle_time_get(source_p, target_p));
204 adx 30 }
205     else
206     {
207 michael 3109 sendto_one_numeric(source_p, &me, RPL_TRACEUSER,
208     get_client_class(&target_p->localClient->confs), name,
209 michael 2345 IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost,
210 michael 1241 CurrentTime - target_p->localClient->lasttime,
211 michael 1783 idle_time_get(source_p, target_p));
212 adx 30 }
213     }
214 michael 2345
215 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFTRACE, tname);
216 adx 30 return;
217     }
218    
219     /* report all direct connections */
220     DLINK_FOREACH(ptr, local_client_list.head)
221     {
222     target_p = ptr->data;
223    
224 michael 1219 if (HasUMode(target_p, UMODE_INVISIBLE) && dow &&
225 michael 2345 !(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) &&
226     !HasUMode(target_p, UMODE_OPER) && (target_p != source_p))
227 adx 30 continue;
228 michael 1652 if (!doall && wilds && match(tname, target_p->name))
229 adx 30 continue;
230     if (!dow && irccmp(tname, target_p->name))
231     continue;
232    
233 michael 889 report_this_status(source_p, target_p, dow);
234 adx 30 }
235    
236     DLINK_FOREACH(ptr, serv_list.head)
237     {
238     target_p = ptr->data;
239    
240 michael 1652 if (!doall && wilds && match(tname, target_p->name))
241 adx 30 continue;
242     if (!dow && irccmp(tname, target_p->name))
243     continue;
244    
245 michael 889 report_this_status(source_p, target_p, dow);
246 adx 30 }
247    
248     /* This section is to report the unknowns */
249     DLINK_FOREACH(ptr, unknown_list.head)
250     {
251     target_p = ptr->data;
252    
253 michael 1652 if (!doall && wilds && match(tname, target_p->name))
254 adx 30 continue;
255     if (!dow && irccmp(tname, target_p->name))
256     continue;
257    
258 michael 889 report_this_status(source_p, target_p, dow);
259 adx 30 }
260    
261 michael 1632 DLINK_FOREACH(ptr, class_get_list()->head)
262 adx 30 {
263 michael 1632 const struct ClassItem *class = ptr->data;
264 michael 889
265 michael 1632 if (class->ref_count > 0)
266 michael 3109 sendto_one_numeric(source_p, &me, RPL_TRACECLASS, class->name, class->ref_count);
267 adx 30 }
268    
269 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFTRACE, tname);
270 adx 30 }
271    
272     /* report_this_status()
273     *
274     * inputs - pointer to client to report to
275     * - pointer to client to report about
276     * output - counter of number of hits
277     * side effects - NONE
278     */
279 michael 889 static void
280     report_this_status(struct Client *source_p, struct Client *target_p, int dow)
281 adx 30 {
282     const char *name;
283     const char *class_name;
284    
285     name = get_client_name(target_p, HIDE_IP);
286 michael 1632 class_name = get_client_class(&target_p->localClient->confs);
287 adx 30
288     set_time();
289    
290 michael 889 switch (target_p->status)
291 adx 30 {
292     case STAT_CONNECTING:
293 michael 3109 sendto_one_numeric(source_p, &me, RPL_TRACECONNECTING, class_name,
294 michael 2345 HasUMode(source_p, UMODE_ADMIN) ? name : target_p->name);
295 adx 30 break;
296     case STAT_HANDSHAKE:
297 michael 3109 sendto_one_numeric(source_p, &me, RPL_TRACEHANDSHAKE, class_name,
298 michael 1219 HasUMode(source_p, UMODE_ADMIN) ? name : target_p->name);
299 adx 30 break;
300     case STAT_ME:
301     break;
302     case STAT_UNKNOWN:
303     /* added time -Taner */
304 michael 3109 sendto_one_numeric(source_p, &me, RPL_TRACEUNKNOWN, class_name,
305     name, target_p->sockhost,
306 michael 2359 CurrentTime - target_p->localClient->firsttime);
307 adx 30 break;
308     case STAT_CLIENT:
309 michael 891 /*
310     * Only opers see users if there is a wildcard
311 adx 30 * but anyone can see all the opers.
312     */
313 michael 1219 if ((HasUMode(source_p, UMODE_OPER) &&
314 michael 2345 (MyClient(source_p) || !(dow && HasUMode(target_p, UMODE_INVISIBLE))))
315     || !dow || HasUMode(target_p, UMODE_OPER))
316     {
317 michael 1219 if (HasUMode(target_p, UMODE_ADMIN) && !ConfigFileEntry.hide_spoof_ips)
318 michael 3109 sendto_one_numeric(source_p, &me, RPL_TRACEOPERATOR, class_name, name,
319 michael 1219 HasUMode(source_p, UMODE_ADMIN) ? target_p->sockhost : "255.255.255.255",
320 michael 1241 CurrentTime - target_p->localClient->lasttime,
321 michael 1783 idle_time_get(source_p, target_p));
322 michael 2345
323     else if (HasUMode(target_p, UMODE_OPER))
324 adx 30 {
325 michael 2345 if (ConfigFileEntry.hide_spoof_ips)
326 michael 3109 sendto_one_numeric(source_p, &me, RPL_TRACEOPERATOR, class_name, name,
327 michael 2345 IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost,
328     CurrentTime - target_p->localClient->lasttime,
329     idle_time_get(source_p, target_p));
330     else
331 michael 3109 sendto_one_numeric(source_p, &me, RPL_TRACEOPERATOR, class_name, name,
332 michael 891 MyOper(source_p) ? target_p->sockhost :
333     (IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost),
334 michael 1241 CurrentTime - target_p->localClient->lasttime,
335 michael 1783 idle_time_get(source_p, target_p));
336 michael 2345 }
337     else
338 adx 30 {
339     if (ConfigFileEntry.hide_spoof_ips)
340 michael 3109 sendto_one_numeric(source_p, &me, RPL_TRACEUSER, class_name, name,
341 michael 891 IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost,
342 michael 2345 CurrentTime - target_p->localClient->lasttime,
343     idle_time_get(source_p, target_p));
344     else
345 michael 3109 sendto_one_numeric(source_p, &me, RPL_TRACEUSER, class_name, name,
346 michael 891 MyOper(source_p) ? target_p->sockhost :
347     (IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost),
348 michael 1241 CurrentTime - target_p->localClient->lasttime,
349 michael 1783 idle_time_get(source_p, target_p));
350 michael 2345 }
351     }
352 adx 30 break;
353     case STAT_SERVER:
354 michael 889 {
355 michael 2262 unsigned int clients = 0;
356     unsigned int servers = 0;
357 michael 889
358     trace_get_dependent(&servers, &clients, target_p);
359    
360 michael 1219 if (!HasUMode(source_p, UMODE_ADMIN))
361 adx 30 name = get_client_name(target_p, MASK_IP);
362    
363 michael 3109 sendto_one_numeric(source_p, &me, RPL_TRACESERVER, class_name, servers,
364 michael 2345 clients, name, *(target_p->serv->by) ?
365     target_p->serv->by : "*", "*",
366     me.name, CurrentTime - target_p->localClient->lasttime);
367 adx 30 break;
368 michael 889 }
369 michael 2820
370 michael 3109 default: /* ...we actually shouldn't come here... --msa */
371     sendto_one_numeric(source_p, &me, RPL_TRACENEWTYPE, name);
372 adx 30 break;
373     }
374     }
375 michael 1230
376 michael 2820 static struct Message trace_msgtab =
377     {
378 michael 1230 "TRACE", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
379     { m_unregistered, m_trace, ms_trace, m_ignore, mo_trace, m_ignore }
380     };
381    
382     static void
383     module_init(void)
384     {
385     mod_add_cmd(&trace_msgtab);
386     }
387    
388     static void
389     module_exit(void)
390     {
391     mod_del_cmd(&trace_msgtab);
392     }
393    
394 michael 2820 struct module module_entry =
395     {
396 michael 1230 .node = { NULL, NULL, NULL },
397     .name = NULL,
398     .version = "$Revision$",
399     .handle = NULL,
400     .modinit = module_init,
401     .modexit = module_exit,
402     .flags = 0
403     };

Properties

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