ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/contrib/m_ctrace.c
Revision: 32
Committed: Sun Oct 2 20:41:23 2005 UTC (18 years, 5 months ago) by knight
Content type: text/x-csrc
Original Path: ircd-hybrid/contrib/m_ctrace.c
File size: 6462 byte(s)
Log Message:
- svn:keywords

File Contents

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

Properties

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