ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/m_ctrace.c
Revision: 184
Committed: Sun Oct 23 14:51:05 2005 UTC (20 years, 9 months ago) by adx
Content type: text/x-csrc
File size: 6497 byte(s)
Log Message:
* make win32 port work with libio.dll

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

Properties

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