ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_whois.c
Revision: 1874
Committed: Sat Apr 27 09:27:34 2013 UTC (13 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 8207 byte(s)
Log Message:
- WHOIS may no longer accept wildcards

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_whois.c: Shows who a user is.
4     *
5     * Copyright (C) 2005 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 "client.h"
28     #include "hash.h"
29     #include "channel.h"
30     #include "channel_mode.h"
31     #include "ircd.h"
32     #include "numeric.h"
33 michael 1309 #include "conf.h"
34 adx 30 #include "s_misc.h"
35     #include "s_serv.h"
36     #include "send.h"
37     #include "irc_string.h"
38     #include "parse.h"
39     #include "modules.h"
40    
41 michael 1243
42 michael 1225 static void do_whois(struct Client *, int, char *[]);
43 adx 30 static void whois_person(struct Client *, struct Client *);
44    
45    
46     /*
47     ** m_whois
48     ** parv[0] = sender prefix
49     ** parv[1] = nickname masklist
50     */
51     static void
52     m_whois(struct Client *client_p, struct Client *source_p,
53     int parc, char *parv[])
54     {
55 adx 269 static time_t last_used = 0;
56    
57 adx 30 if (parc < 2 || EmptyString(parv[1]))
58     {
59 michael 1834 sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
60 adx 30 me.name, source_p->name);
61     return;
62     }
63    
64 michael 93 if (parc > 2 && !EmptyString(parv[2]))
65 adx 30 {
66     /* seeing as this is going across servers, we should limit it */
67     if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
68     {
69 michael 1834 sendto_one(source_p, form_str(RPL_LOAD2HI),
70 adx 30 me.name, source_p->name);
71     return;
72     }
73    
74 michael 1121 last_used = CurrentTime;
75    
76 adx 30 /* if we have serverhide enabled, they can either ask the clients
77     * server, or our server.. I dont see why they would need to ask
78     * anything else for info about the client.. --fl_
79     */
80     if (ConfigFileEntry.disable_remote)
81     parv[1] = parv[2];
82    
83     if (hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1,
84     parc, parv) != HUNTED_ISME)
85     return;
86    
87     parv[1] = parv[2];
88     }
89    
90 michael 1225 do_whois(source_p, parc, parv);
91 adx 30 }
92    
93     /*
94     ** mo_whois
95     ** parv[0] = sender prefix
96     ** parv[1] = nickname masklist
97     */
98     static void
99     mo_whois(struct Client *client_p, struct Client *source_p,
100     int parc, char *parv[])
101     {
102     if (parc < 2 || EmptyString(parv[1]))
103     {
104 michael 1834 sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
105 adx 30 me.name, source_p->name);
106     return;
107     }
108    
109 michael 93 if (parc > 2 && !EmptyString(parv[2]))
110 adx 30 {
111     if (hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1,
112     parc, parv) != HUNTED_ISME)
113     return;
114    
115     parv[1] = parv[2];
116     }
117    
118 michael 1225 do_whois(source_p, parc, parv);
119 adx 30 }
120    
121     /* do_whois()
122     *
123     * inputs - pointer to /whois source
124     * - number of parameters
125     * - pointer to parameters array
126     * output - pointer to void
127     * side effects - Does whois
128     */
129     static void
130 michael 1225 do_whois(struct Client *source_p, int parc, char *parv[])
131 adx 30 {
132 michael 1874 struct Client *target_p = NULL;
133     char *nick = parv[1];
134 adx 30 char *p = NULL;
135    
136 michael 1874 if ((p = strchr(nick, ',')) != NULL)
137 adx 30 *p = '\0';
138     if (*nick == '\0')
139     return;
140    
141 michael 1874 if ((target_p = hash_find_client(nick)) && IsClient(target_p))
142     whois_person(source_p, target_p);
143     else if (!IsDigit(*nick))
144     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
145     me.name, source_p->name, nick);
146 adx 30
147 michael 1834 sendto_one(source_p, form_str(RPL_ENDOFWHOIS),
148 michael 1874 me.name, source_p->name, nick);
149 adx 30 }
150    
151     /* whois_person()
152     *
153     * inputs - source_p client to report to
154     * - target_p client to report on
155     * output - NONE
156     * side effects -
157     */
158     static void
159     whois_person(struct Client *source_p, struct Client *target_p)
160     {
161     char buf[IRCD_BUFSIZE];
162 michael 1874 const dlink_node *lp = NULL;
163     char *t = NULL;
164 adx 30 int cur_len = 0;
165 michael 1874 int show_ip = 0;
166     int mlen = 0;
167     int tlen = 0;
168 michael 1243 int reply_to_send = 0;
169 adx 30
170 michael 1874 sendto_one(source_p, form_str(RPL_WHOISUSER), me.name,
171     source_p->name, target_p->name,
172 adx 30 target_p->username, target_p->host, target_p->info);
173    
174 michael 1834 cur_len = mlen = snprintf(buf, sizeof(buf), form_str(RPL_WHOISCHANNELS),
175 michael 1233 me.name, source_p->name, target_p->name, "");
176 adx 30 t = buf + mlen;
177    
178     DLINK_FOREACH(lp, target_p->channel.head)
179     {
180 michael 1874 const struct Membership *ms = lp->data;
181 adx 30
182 michael 1874 if (ShowChannel(source_p, ms->chptr))
183 adx 30 {
184 michael 1874 if ((cur_len + 3 + strlen(ms->chptr->chname) + 1) > (IRCD_BUFSIZE - 2))
185 adx 30 {
186     *(t - 1) = '\0';
187     sendto_one(source_p, "%s", buf);
188     cur_len = mlen;
189     t = buf + mlen;
190     }
191    
192 michael 1874 tlen = sprintf(t, "%s%s ", get_member_status(ms, 1), ms->chptr->chname);
193 adx 30 t += tlen;
194     cur_len += tlen;
195 michael 1243 reply_to_send = 1;
196 adx 30 }
197     }
198    
199     if (reply_to_send)
200     {
201     *(t - 1) = '\0';
202     sendto_one(source_p, "%s", buf);
203     }
204    
205 michael 1219 if (HasUMode(source_p, UMODE_OPER) || !ConfigServerHide.hide_servers || target_p == source_p)
206 michael 1834 sendto_one(source_p, form_str(RPL_WHOISSERVER),
207 adx 30 me.name, source_p->name, target_p->name,
208 michael 1874 target_p->servptr->name, target_p->servptr->info);
209 adx 30 else
210 michael 1834 sendto_one(source_p, form_str(RPL_WHOISSERVER),
211 adx 30 me.name, source_p->name, target_p->name,
212     ConfigServerHide.hidden_name,
213     ServerInfo.network_desc);
214    
215 michael 1164 if (HasUMode(target_p, UMODE_REGISTERED))
216 michael 1834 sendto_one(source_p, form_str(RPL_WHOISREGNICK),
217 michael 1162 me.name, source_p->name, target_p->name);
218 michael 1158
219 michael 1483 if (target_p->away[0])
220 michael 1834 sendto_one(source_p, form_str(RPL_AWAY),
221 adx 30 me.name, source_p->name, target_p->name,
222     target_p->away);
223    
224 michael 1333 if (HasUMode(target_p, UMODE_CALLERID) && !HasUMode(target_p, UMODE_SOFTCALLERID))
225 michael 1834 sendto_one(source_p, form_str(RPL_TARGUMODEG),
226 adx 660 me.name, source_p->name, target_p->name);
227    
228 michael 1219 if (HasUMode(target_p, UMODE_OPER))
229 michael 1294 if (!HasUMode(target_p, UMODE_HIDDEN) || HasUMode(source_p, UMODE_OPER))
230 michael 1834 sendto_one(source_p, form_str(HasUMode(target_p, UMODE_ADMIN) ? RPL_WHOISADMIN :
231     RPL_WHOISOPERATOR),
232 michael 1294 me.name, source_p->name, target_p->name);
233 adx 30
234 michael 1811 if (target_p->sockhost[0] && strcmp(target_p->sockhost, "0"))
235 adx 30 {
236 michael 1547 if (HasUMode(source_p, UMODE_ADMIN) || source_p == target_p)
237     show_ip = 1;
238     else if (IsIPSpoof(target_p))
239     show_ip = (HasUMode(source_p, UMODE_OPER) && !ConfigFileEntry.hide_spoof_ips);
240     else
241     show_ip = 1;
242 db 280
243 michael 1834 sendto_one(source_p, form_str(RPL_WHOISACTUALLY),
244 michael 1547 me.name, source_p->name, target_p->name,
245     show_ip ? target_p->sockhost : "255.255.255.255");
246 adx 30 }
247    
248     if (MyConnect(target_p)) /* Can't do any of this if not local! db */
249     {
250     #ifdef HAVE_LIBCRYPTO
251     if (target_p->localClient->fd.ssl)
252 michael 1834 sendto_one(source_p, form_str(RPL_WHOISSECURE),
253 adx 30 me.name, source_p->name, target_p->name);
254     #endif
255 michael 1834 sendto_one(source_p, form_str(RPL_WHOISIDLE),
256 adx 30 me.name, source_p->name, target_p->name,
257 michael 1783 idle_time_get(source_p, target_p),
258 michael 1241 target_p->localClient->firsttime);
259 michael 1144
260 michael 1219 if (HasUMode(target_p, UMODE_OPER) && target_p != source_p)
261     if (HasUMode(target_p, UMODE_SPY))
262 michael 1144 sendto_one(target_p, ":%s NOTICE %s :*** Notice -- %s (%s@%s) [%s] is doing "
263     "a whois on you", me.name, target_p->name, source_p->name,
264     source_p->username, source_p->host, source_p->servptr->name);
265 adx 30 }
266     }
267 michael 1230
268     static struct Message whois_msgtab = {
269     "WHOIS", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
270     { m_unregistered, m_whois, mo_whois, m_ignore, mo_whois, m_ignore }
271     };
272    
273     static void
274     module_init(void)
275     {
276     mod_add_cmd(&whois_msgtab);
277     }
278    
279     static void
280     module_exit(void)
281     {
282     mod_del_cmd(&whois_msgtab);
283     }
284    
285     struct module module_entry = {
286     .node = { NULL, NULL, NULL },
287     .name = NULL,
288     .version = "$Revision$",
289     .handle = NULL,
290     .modinit = module_init,
291     .modexit = module_exit,
292     .flags = 0
293     };

Properties

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