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$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "handlers.h" |
27 |
#include "tools.h" |
28 |
#include "hook.h" |
29 |
#include "client.h" |
30 |
#include "hash.h" |
31 |
#include "common.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_conf.h" |
38 |
#include "s_serv.h" |
39 |
#include "send.h" |
40 |
#include "msg.h" |
41 |
#include "parse.h" |
42 |
#include "modules.h" |
43 |
|
44 |
static void do_ctrace(struct Client *, int, char *[]); |
45 |
static void mo_ctrace(struct Client *, struct Client *, int, char *[]); |
46 |
|
47 |
struct Message ctrace_msgtab = { |
48 |
"CTRACE", 0, 0, 2, 0, MFLG_SLOW, 0, |
49 |
{m_unregistered, m_not_oper, m_ignore, m_ignore, mo_ctrace, m_ignore} |
50 |
}; |
51 |
|
52 |
#ifndef STATIC_MODULES |
53 |
const char *_version = "$Revision$"; |
54 |
static struct Callback *ctrace_cb; |
55 |
|
56 |
static void * |
57 |
va_ctrace(va_list args) |
58 |
{ |
59 |
struct Client *source_p = va_arg(args, struct Client *); |
60 |
int parc = va_arg(args, int); |
61 |
char **parv = va_arg(args, char **); |
62 |
|
63 |
do_ctrace(source_p, parc, parv); |
64 |
return NULL; |
65 |
} |
66 |
|
67 |
void |
68 |
_modinit(void) |
69 |
{ |
70 |
ctrace_cb = register_callback("doing_ctrace", va_ctrace); |
71 |
mod_add_cmd(&ctrace_msgtab); |
72 |
} |
73 |
|
74 |
void |
75 |
_moddeinit(void) |
76 |
{ |
77 |
mod_del_cmd(&ctrace_msgtab); |
78 |
uninstall_hook(ctrace_cb, va_ctrace); |
79 |
} |
80 |
#endif |
81 |
|
82 |
static void report_this_status(struct Client *, struct Client *); |
83 |
|
84 |
/* |
85 |
** mo_ctrace |
86 |
** parv[0] = sender prefix |
87 |
** parv[1] = classname |
88 |
*/ |
89 |
static void |
90 |
mo_ctrace(struct Client *client_p, struct Client *source_p, |
91 |
int parc, char *parv[]) |
92 |
{ |
93 |
if (EmptyString(parv[1])) |
94 |
{ |
95 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
96 |
me.name, parv[0], "CTRACE"); |
97 |
return; |
98 |
} |
99 |
|
100 |
#ifdef STATIC_MODULES |
101 |
do_ctrace(source_p, parc, parv); |
102 |
#else |
103 |
execute_callback(ctrace_cb, source_p, parc, parv); |
104 |
#endif |
105 |
} |
106 |
|
107 |
/* |
108 |
* do_ctrace |
109 |
*/ |
110 |
static void |
111 |
do_ctrace(struct Client *source_p, int parc, char *parv[]) |
112 |
{ |
113 |
struct Client *target_p = NULL; |
114 |
char *class_looking_for; |
115 |
const char *class_name; |
116 |
dlink_node *ptr; |
117 |
|
118 |
class_looking_for = parv[1]; |
119 |
|
120 |
/* report all direct connections */ |
121 |
|
122 |
DLINK_FOREACH(ptr, local_client_list.head) |
123 |
{ |
124 |
target_p = ptr->data; |
125 |
|
126 |
class_name = get_client_class(target_p); |
127 |
if ((class_name != NULL) && match(class_looking_for, class_name)) |
128 |
report_this_status(source_p, target_p); |
129 |
} |
130 |
|
131 |
sendto_one(source_p, form_str(RPL_ENDOFTRACE), me.name, |
132 |
parv[0], class_looking_for); |
133 |
} |
134 |
|
135 |
/* |
136 |
* report_this_status |
137 |
* |
138 |
* inputs - pointer to client to report to |
139 |
* - pointer to client to report about |
140 |
* output - counter of number of hits |
141 |
* side effects - NONE |
142 |
*/ |
143 |
static void |
144 |
report_this_status(struct Client *source_p, struct Client *target_p) |
145 |
{ |
146 |
const char *name = NULL; |
147 |
const char *class_name = NULL; |
148 |
|
149 |
name = get_client_name(target_p, HIDE_IP); |
150 |
class_name = get_client_class(target_p); |
151 |
|
152 |
switch(target_p->status) |
153 |
{ |
154 |
case STAT_CLIENT: |
155 |
|
156 |
if ((IsOper(source_p) && |
157 |
(MyClient(source_p) || !IsInvisible(target_p))) |
158 |
|| IsOper(target_p)) |
159 |
{ |
160 |
if (IsAdmin(target_p) && !ConfigFileEntry.hide_spoof_ips) |
161 |
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
162 |
me.name, source_p->name, class_name, name, |
163 |
IsAdmin(source_p) ? target_p->sockhost : "255.255.255.255", |
164 |
CurrentTime - target_p->lasttime, |
165 |
CurrentTime - target_p->localClient->last); |
166 |
else if (IsOper(target_p)) |
167 |
{ |
168 |
if (ConfigFileEntry.hide_spoof_ips) |
169 |
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
170 |
me.name, source_p->name, class_name, name, |
171 |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
172 |
CurrentTime - target_p->lasttime, |
173 |
CurrentTime - target_p->localClient->last); |
174 |
else |
175 |
sendto_one(source_p, form_str(RPL_TRACEOPERATOR), |
176 |
me.name, source_p->name, class_name, name, |
177 |
(IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost), |
178 |
CurrentTime - target_p->lasttime, |
179 |
CurrentTime - target_p->localClient->last); |
180 |
} |
181 |
else |
182 |
{ |
183 |
if (ConfigFileEntry.hide_spoof_ips) |
184 |
sendto_one(source_p, form_str(RPL_TRACEUSER), |
185 |
me.name, source_p->name, class_name, name, |
186 |
IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost, |
187 |
CurrentTime - target_p->lasttime, |
188 |
CurrentTime - target_p->localClient->last); |
189 |
else |
190 |
sendto_one(source_p, form_str(RPL_TRACEUSER), |
191 |
me.name, source_p->name, class_name, name, |
192 |
(IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost), |
193 |
CurrentTime - target_p->lasttime, |
194 |
CurrentTime - target_p->localClient->last); |
195 |
} |
196 |
} |
197 |
break; |
198 |
case STAT_SERVER: |
199 |
if (!IsAdmin(source_p)) |
200 |
name = get_client_name(target_p, MASK_IP); |
201 |
|
202 |
sendto_one(source_p, form_str(RPL_TRACESERVER), |
203 |
me.name, source_p->name, class_name, 0, |
204 |
0, name, *(target_p->serv->by) ? |
205 |
target_p->serv->by : "*", "*", |
206 |
me.name, CurrentTime - target_p->lasttime); |
207 |
break; |
208 |
|
209 |
default: /* ...we actually shouldn't come here... --msa */ |
210 |
sendto_one(source_p, form_str(RPL_TRACENEWTYPE), me.name, |
211 |
source_p->name, name); |
212 |
break; |
213 |
} |
214 |
} |