ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/m_ctrace.c
Revision: 76
Committed: Tue Oct 4 19:38:49 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 6333 byte(s)
Log Message:
- fixed contrib #includes

File Contents

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

Properties

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