ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_whois.c
Revision: 92
Committed: Sat Oct 8 11:14:46 2005 UTC (20 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 11372 byte(s)
Log Message:
- Fixed bug in m_whois() that would allow users to send a WHOIS to remote
  servers with an empty argument via "WHOIS someserver.org :"

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     #include "common.h"
27     #include "handlers.h"
28     #include "client.h"
29     #include "hash.h"
30     #include "channel.h"
31     #include "channel_mode.h"
32     #include "ircd.h"
33     #include "numeric.h"
34     #include "s_conf.h"
35     #include "s_serv.h"
36     #include "send.h"
37     #include "msg.h"
38     #include "parse.h"
39     #include "modules.h"
40    
41     static void do_whois(struct Client *, int, char **);
42     static int single_whois(struct Client *, struct Client *);
43     static void whois_person(struct Client *, struct Client *);
44     static int global_whois(struct Client *, const char *);
45    
46     static void m_whois(struct Client *, struct Client *, int, char *[]);
47     static void mo_whois(struct Client *, struct Client *, int, char *[]);
48    
49     struct Message whois_msgtab = {
50     "WHOIS", 0, 0, 0, 0, MFLG_SLOW, 0,
51     { m_unregistered, m_whois, mo_whois, m_ignore, mo_whois, m_ignore }
52     };
53    
54     #ifndef STATIC_MODULES
55 knight 31 const char *_version = "$Revision$";
56 adx 30 static struct Callback *whois_cb;
57    
58     static void *
59     va_whois(va_list args)
60     {
61     struct Client *source_p = va_arg(args, struct Client *);
62     int parc = va_arg(args, int);
63     char **parv = va_arg(args, char **);
64    
65     do_whois(source_p, parc, parv);
66     return NULL;
67     }
68    
69     void
70     _modinit(void)
71     {
72     whois_cb = register_callback("doing_whois", va_whois);
73     mod_add_cmd(&whois_msgtab);
74     }
75    
76     void
77     _moddeinit(void)
78     {
79     mod_del_cmd(&whois_msgtab);
80     uninstall_hook(whois_cb, va_whois);
81     }
82     #endif
83    
84     /*
85     ** m_whois
86     ** parv[0] = sender prefix
87     ** parv[1] = nickname masklist
88     */
89     static void
90     m_whois(struct Client *client_p, struct Client *source_p,
91     int parc, char *parv[])
92     {
93     static time_t last_used = 0;
94    
95     if (parc < 2 || EmptyString(parv[1]))
96     {
97     sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
98     me.name, source_p->name);
99     return;
100     }
101    
102 michael 92 if (parc > 2 && !EmptyString(parv[2]))
103 adx 30 {
104     /* seeing as this is going across servers, we should limit it */
105     if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
106     {
107     sendto_one(source_p, form_str(RPL_LOAD2HI),
108     me.name, source_p->name);
109     return;
110     }
111     else
112     last_used = CurrentTime;
113    
114     /* if we have serverhide enabled, they can either ask the clients
115     * server, or our server.. I dont see why they would need to ask
116     * anything else for info about the client.. --fl_
117     */
118     if (ConfigFileEntry.disable_remote)
119     parv[1] = parv[2];
120    
121     if (hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1,
122     parc, parv) != HUNTED_ISME)
123     return;
124    
125     parv[1] = parv[2];
126     }
127    
128     #ifdef STATIC_MODULES
129     do_whois(source_p, parc, parv);
130     #else
131     execute_callback(whois_cb, source_p, parc, parv);
132     #endif
133     }
134    
135     /*
136     ** mo_whois
137     ** parv[0] = sender prefix
138     ** parv[1] = nickname masklist
139     */
140     static void
141     mo_whois(struct Client *client_p, struct Client *source_p,
142     int parc, char *parv[])
143     {
144     if (parc < 2 || EmptyString(parv[1]))
145     {
146     sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
147     me.name, source_p->name);
148     return;
149     }
150    
151 michael 92 if (parc > 2 && !EmptyString(parv[2]))
152 adx 30 {
153     if (hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1,
154     parc, parv) != HUNTED_ISME)
155     return;
156    
157     parv[1] = parv[2];
158     }
159    
160     #ifdef STATIC_MODULES
161     do_whois(source_p, parc, parv);
162     #else
163     execute_callback(whois_cb, source_p, parc, parv);
164     #endif
165     }
166    
167     /* do_whois()
168     *
169     * inputs - pointer to /whois source
170     * - number of parameters
171     * - pointer to parameters array
172     * output - pointer to void
173     * side effects - Does whois
174     */
175     static void
176     do_whois(struct Client *source_p, int parc, char **parv)
177     {
178     struct Client *target_p;
179     char *nick;
180     char *p = NULL;
181     int found = 0;
182    
183     nick = parv[1];
184     while (*nick == ',')
185     nick++;
186     if ((p = strchr(nick,',')) != NULL)
187     *p = '\0';
188    
189     if (*nick == '\0')
190     return;
191    
192     collapse(nick);
193    
194     if (strpbrk(nick, "?#*") == NULL)
195     {
196     if ((target_p = find_client(nick)) != NULL)
197     {
198     if (IsServer(source_p->from))
199 michael 92 client_burst_if_needed(source_p->from, target_p);
200 adx 30
201     if (IsClient(target_p))
202     {
203 michael 92 whois_person(source_p, target_p);
204     found = 1;
205 adx 30 }
206     }
207     else if (!ServerInfo.hub && uplink && IsCapable(uplink, CAP_LL))
208     {
209     if (parc > 2)
210     sendto_one(uplink,":%s WHOIS %s :%s",
211     source_p->name, nick, nick);
212     else
213     sendto_one(uplink,":%s WHOIS %s",
214     source_p->name, nick);
215     return;
216     }
217     }
218     else /* wilds is true */
219     {
220     /* disallow wild card whois on lazylink leafs for now */
221     if (!ServerInfo.hub && uplink && IsCapable(uplink, CAP_LL))
222     return;
223    
224     /* Oh-oh wilds is true so have to do it the hard expensive way */
225     if (MyClient(source_p))
226     found = global_whois(source_p, nick);
227     }
228    
229     if (!found)
230     {
231     if (!IsDigit(*nick))
232     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
233 michael 92 me.name, source_p->name, nick);
234 adx 30 }
235    
236     sendto_one(source_p, form_str(RPL_ENDOFWHOIS),
237     me.name, source_p->name, parv[1]);
238     }
239    
240     /* global_whois()
241     *
242     * Inputs - source_p client to report to
243     * - target_p client to report on
244     * Output - if found return 1
245     * Side Effects - do a single whois on given client
246     * writing results to source_p
247     */
248     static int
249     global_whois(struct Client *source_p, const char *nick)
250     {
251 michael 92 dlink_node *ptr = NULL;
252     struct Client *target_p = NULL;
253 adx 30 int found = 0;
254    
255     DLINK_FOREACH(ptr, global_client_list.head)
256     {
257     target_p = ptr->data;
258    
259     if (!IsClient(target_p))
260     continue;
261    
262     if (!match(nick, target_p->name))
263     continue;
264    
265     assert(target_p->servptr != NULL);
266    
267     /* 'Rules' established for sending a WHOIS reply:
268     *
269     *
270     * - if wildcards are being used dont send a reply if
271     * the querier isnt any common channels and the
272     * client in question is invisible and wildcards are
273     * in use (allow exact matches only);
274     *
275     * - only send replies about common or public channels
276     * the target user(s) are on;
277     */
278    
279     found |= single_whois(source_p, target_p);
280     }
281    
282 michael 92 return found;
283 adx 30 }
284    
285     /* single_whois()
286     *
287     * Inputs - source_p client to report to
288     * - target_p client to report on
289     * Output - if found return 1
290     * Side Effects - do a single whois on given client
291     * writing results to source_p
292     */
293     static int
294     single_whois(struct Client *source_p, struct Client *target_p)
295     {
296 michael 92 dlink_node *ptr = NULL;
297     struct Channel *chptr = NULL;
298 adx 30
299     if (!IsInvisible(target_p) || target_p == source_p)
300     {
301     /* always show user if they are visible (no +i) */
302     whois_person(source_p, target_p);
303     return 1;
304     }
305    
306     /* target_p is +i. Check if it is on any common channels with source_p */
307     DLINK_FOREACH(ptr, target_p->channel.head)
308     {
309     chptr = ((struct Membership *) ptr->data)->chptr;
310     if (IsMember(source_p, chptr))
311     {
312     whois_person(source_p, target_p);
313     return 1;
314     }
315     }
316    
317     return 0;
318     }
319    
320     /* whois_person()
321     *
322     * inputs - source_p client to report to
323     * - target_p client to report on
324     * output - NONE
325     * side effects -
326     */
327     static void
328     whois_person(struct Client *source_p, struct Client *target_p)
329     {
330     char buf[IRCD_BUFSIZE];
331     dlink_node *lp;
332     struct Client *server_p;
333     struct Channel *chptr;
334     struct Membership *ms;
335     int cur_len = 0;
336     int mlen;
337     char *t = NULL;
338     int tlen;
339     int reply_to_send = NO;
340    
341     server_p = target_p->servptr;
342    
343     sendto_one(source_p, form_str(RPL_WHOISUSER),
344     me.name, source_p->name, target_p->name,
345     target_p->username, target_p->host, target_p->info);
346    
347     cur_len = mlen = ircsprintf(buf, form_str(RPL_WHOISCHANNELS),
348     me.name, source_p->name, target_p->name, "");
349     t = buf + mlen;
350    
351     DLINK_FOREACH(lp, target_p->channel.head)
352     {
353     ms = lp->data;
354     chptr = ms->chptr;
355    
356     if (ShowChannel(source_p, chptr))
357     {
358     /* Don't show local channels if user is doing a remote whois */
359     if (!MyConnect(source_p) && (chptr->chname[0] == '&'))
360 michael 92 continue;
361 adx 30
362     if ((cur_len + 3 + strlen(chptr->chname) + 1) > (IRCD_BUFSIZE - 2))
363     {
364 michael 92 *(t - 1) = '\0';
365     sendto_one(source_p, "%s", buf);
366     cur_len = mlen;
367     t = buf + mlen;
368 adx 30 }
369    
370     tlen = ircsprintf(t, "%s%s ", get_member_status(ms, YES), chptr->chname);
371     t += tlen;
372     cur_len += tlen;
373     reply_to_send = YES;
374     }
375     }
376    
377     if (reply_to_send)
378     {
379     *(t - 1) = '\0';
380     sendto_one(source_p, "%s", buf);
381     }
382    
383     if (IsOper(source_p) || !ConfigServerHide.hide_servers || target_p == source_p)
384     sendto_one(source_p, form_str(RPL_WHOISSERVER),
385     me.name, source_p->name, target_p->name,
386     server_p->name, server_p->info);
387     else
388     sendto_one(source_p, form_str(RPL_WHOISSERVER),
389 michael 92 me.name, source_p->name, target_p->name,
390 adx 30 ConfigServerHide.hidden_name,
391 michael 92 ServerInfo.network_desc);
392 adx 30
393     if (target_p->away != NULL)
394     sendto_one(source_p, form_str(RPL_AWAY),
395     me.name, source_p->name, target_p->name,
396     target_p->away);
397    
398     if (IsOper(target_p))
399     sendto_one(source_p, form_str((IsAdmin(target_p) &&
400     !IsOperHiddenAdmin(target_p)) ? RPL_WHOISADMIN :
401     RPL_WHOISOPERATOR), me.name, source_p->name, target_p->name);
402    
403     if (IsOper(source_p) && IsCaptured(target_p))
404     sendto_one(source_p, form_str(RPL_ISCAPTURED),
405     me.name, source_p->name, target_p->name);
406    
407     if (ConfigFileEntry.use_whois_actually && (target_p->sockhost[0] != '\0') &&
408     !(ConfigFileEntry.hide_spoof_ips && IsIPSpoof(target_p)) &&
409     !(target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
410     {
411     if (IsAdmin(source_p) || source_p == target_p)
412     sendto_one(source_p, form_str(RPL_WHOISACTUALLY),
413     me.name, source_p->name, target_p->name, target_p->sockhost);
414     else
415     sendto_one(source_p, form_str(RPL_WHOISACTUALLY),
416     me.name, source_p->name, target_p->name,
417     IsIPSpoof(target_p) || IsOper(target_p) ?
418 michael 92 "255.255.255.255" : target_p->sockhost);
419 adx 30 }
420    
421     if (MyConnect(target_p)) /* Can't do any of this if not local! db */
422     {
423     #ifdef HAVE_LIBCRYPTO
424     if (target_p->localClient->fd.ssl)
425     sendto_one(source_p, form_str(RPL_WHOISSSL),
426     me.name, source_p->name, target_p->name);
427     #endif
428     sendto_one(source_p, form_str(RPL_WHOISIDLE),
429     me.name, source_p->name, target_p->name,
430     CurrentTime - target_p->localClient->last,
431     target_p->firsttime);
432     }
433     }

Properties

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