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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1652 - (show annotations)
Tue Nov 13 20:28:53 2012 UTC (7 years, 7 months ago) by michael
File MIME type: text/x-chdr
File size: 10007 byte(s)
- changed match() polarity. match() now returns 0 on match and 1 on non-match
  This cleans up several places where function pointers of different matching
  functions like irccmp/strcmp/match are passed to other functions.
- added improved collapse() to match.c

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

Properties

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

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