1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_ctrace.c: Traces a given class |
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 |
* $Id: m_ctrace.c 801 2006-08-30 16:54:25Z adx $ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "conf/conf.h" |
27 |
#include "handlers.h" |
28 |
#include "client.h" |
29 |
#include "hash.h" |
30 |
#include "common.h" |
31 |
#include "ircd.h" |
32 |
#include "numeric.h" |
33 |
#include "server.h" |
34 |
#include "send.h" |
35 |
#include "msg.h" |
36 |
#include "parse.h" |
37 |
#include "parse_aline.h" |
38 |
|
39 |
static void *do_ctrace(va_list); |
40 |
static void mo_ctrace(struct Client *, struct Client *, int, char *[]); |
41 |
static void report_this_status(struct Client *, struct Client *); |
42 |
|
43 |
struct Message ctrace_msgtab = { |
44 |
"CTRACE", 0, 0, 2, 0, MFLG_SLOW, 0, |
45 |
{ m_unregistered, m_not_oper, m_ignore, m_ignore, mo_ctrace, m_ignore } |
46 |
}; |
47 |
|
48 |
static struct Callback *ctrace_cb; |
49 |
|
50 |
INIT_MODULE(m_ctrace, "$Revision: 801 $") |
51 |
{ |
52 |
ctrace_cb = register_callback("doing_ctrace", do_ctrace); |
53 |
mod_add_cmd(&ctrace_msgtab); |
54 |
} |
55 |
|
56 |
CLEANUP_MODULE |
57 |
{ |
58 |
mod_del_cmd(&ctrace_msgtab); |
59 |
uninstall_hook(ctrace_cb, do_ctrace); |
60 |
} |
61 |
|
62 |
|
63 |
/* |
64 |
** mo_ctrace |
65 |
** parv[0] = sender prefix |
66 |
** parv[1] = classname |
67 |
*/ |
68 |
static void |
69 |
mo_ctrace(struct Client *client_p, struct Client *source_p, |
70 |
int parc, char *parv[]) |
71 |
{ |
72 |
if (EmptyString(parv[1])) |
73 |
{ |
74 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
75 |
me.name, source_p->name, "CTRACE"); |
76 |
return; |
77 |
} |
78 |
|
79 |
execute_callback(ctrace_cb, source_p, parc, parv); |
80 |
} |
81 |
|
82 |
/* |
83 |
* do_ctrace |
84 |
*/ |
85 |
static void * |
86 |
do_ctrace(va_list args) |
87 |
{ |
88 |
struct Client *source_p = va_arg(args, struct Client *); |
89 |
char **parv; |
90 |
struct Client *target_p; |
91 |
char *class_looking_for; |
92 |
const char *class_name; |
93 |
dlink_node *ptr; |
94 |
|
95 |
va_arg(args, int); |
96 |
parv = va_arg(args, char **); |
97 |
class_looking_for = parv[1]; |
98 |
|
99 |
/* report all direct connections */ |
100 |
DLINK_FOREACH(ptr, local_client_list.head) |
101 |
{ |
102 |
target_p = ptr->data; |
103 |
|
104 |
class_name = target_p->localClient->class->name; |
105 |
if ((class_name != NULL) && match(class_looking_for, class_name)) |
106 |
report_this_status(source_p, target_p); |
107 |
} |
108 |
|
109 |
sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, |
110 |
source_p->name, class_looking_for); |
111 |
return NULL; |
112 |
} |
113 |
|
114 |
/* |
115 |
* report_this_status |
116 |
* |
117 |
* inputs - pointer to client to report to |
118 |
* - pointer to client to report about |
119 |
* output - counter of number of hits |
120 |
* side effects - NONE |
121 |
*/ |
122 |
static void |
123 |
report_this_status(struct Client *source_p, struct Client *target_p) |
124 |
{ |
125 |
const char *name = NULL; |
126 |
const char *class_name = NULL; |
127 |
|
128 |
name = get_client_name(target_p, HIDE_IP); |
129 |
class_name = target_p->localClient->class->name; |
130 |
|
131 |
switch (target_p->status) |
132 |
{ |
133 |
case STAT_CLIENT: |
134 |
if ((IsOper(source_p) && (MyClient(source_p) || !IsInvisible(target_p))) |
135 |
|| IsOper(target_p)) |
136 |
{ |
137 |
if (IsAdmin(target_p) && !General.hide_spoof_ips) |
138 |
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
139 |
me.name, source_p->name, class_name, name, |
140 |
IsAdmin(source_p) ? target_p->sockhost : "255.255.255.255", |
141 |
CurrentTime - target_p->lasttime, |
142 |
CurrentTime - target_p->localClient->last); |
143 |
else if (IsOper(target_p)) |
144 |
{ |
145 |
if (General.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->lasttime, |
150 |
CurrentTime - target_p->localClient->last); |
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->lasttime, |
156 |
CurrentTime - target_p->localClient->last); |
157 |
} |
158 |
else |
159 |
{ |
160 |
if (General.hide_spoof_ips) |
161 |
sendto_one(source_p, form_str(RPL_TRACEUSER), |
162 |
me.name, source_p->name, class_name, name, |
163 |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
164 |
CurrentTime - target_p->lasttime, |
165 |
CurrentTime - target_p->localClient->last); |
166 |
else |
167 |
sendto_one(source_p, form_str(RPL_TRACEUSER), |
168 |
me.name, source_p->name, class_name, name, |
169 |
(IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost), |
170 |
CurrentTime - target_p->lasttime, |
171 |
CurrentTime - target_p->localClient->last); |
172 |
} |
173 |
} |
174 |
break; |
175 |
case STAT_SERVER: |
176 |
if (!IsAdmin(source_p)) |
177 |
name = get_client_name(target_p, MASK_IP); |
178 |
|
179 |
sendto_one(source_p, form_str(RPL_TRACESERVER), |
180 |
me.name, source_p->name, class_name, 0, |
181 |
0, name, *(target_p->serv->by) ? |
182 |
target_p->serv->by : "*", "*", |
183 |
me.name, CurrentTime - target_p->lasttime); |
184 |
break; |
185 |
|
186 |
default: /* ...we actually shouldn't come here... --msa */ |
187 |
sendto_one(source_p, form_str(RPL_TRACENEWTYPE), me.name, |
188 |
source_p->name, name); |
189 |
break; |
190 |
} |
191 |
} |