ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_whois.c
Revision: 478
Committed: Fri Feb 24 11:27:13 2006 UTC (20 years, 5 months ago) by adx
Content type: text/x-csrc
File size: 10834 byte(s)
Log Message:
+ work against malformed numerics on "WHOIS :  "
+ actually the same needs to be done in many other modules...

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

Properties

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