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