ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/m_ctrace.c
Revision: 161
Committed: Thu Oct 20 02:10:27 2005 UTC (20 years, 9 months ago) by db
Content type: text/x-csrc
File size: 6448 byte(s)
Log Message:
- Make contrib compile with HEAD


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 knight 112 #include "parse_aline.h"
39 adx 30
40     static void do_ctrace(struct Client *, 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 knight 31 const char *_version = "$Revision$";
50 adx 30 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 michael 106 int parc = va_arg(args, int);
57 adx 30 char **parv = va_arg(args, char **);
58    
59     do_ctrace(source_p, 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, 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, char **parv)
108     {
109     struct Client *target_p = NULL;
110     char *class_looking_for;
111     const char *class_name;
112     dlink_node *ptr;
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 db 161 class_name = ((struct ConfItem *)target_p->localClient->class->conf_ptr)->name;
123 adx 30 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 db 161 class_name = ((struct ConfItem *)target_p->localClient->class->conf_ptr)->name;
153 adx 30
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