ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_whois.c
Revision: 885
Committed: Wed Oct 31 18:09:24 2007 UTC (18 years, 11 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/modules/m_whois.c
File size: 11257 byte(s)
Log Message:
- Removed LazyLinks in 7.2 to stop people from asking why we keep
  broken code for half a decade. LL will be implemented in a smarter
  fashion in due time

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

Properties

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