ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/releases/8.1.0beta3/modules/m_whois.c
Revision: 268
Committed: Mon Nov 14 11:02:39 2005 UTC (20 years, 11 months ago) by adx
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/modules/m_whois.c
File size: 11694 byte(s)
Log Message:
+ add more load2hi protection
+ style fixes

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 adx 268 static time_t last_used = 0;
49    
50 adx 30 static void do_whois(struct Client *, int, char **);
51     static int single_whois(struct Client *, struct Client *);
52     static void whois_person(struct Client *, struct Client *);
53     static int global_whois(struct Client *, const char *);
54    
55     static void m_whois(struct Client *, struct Client *, int, char *[]);
56     static void mo_whois(struct Client *, struct Client *, int, char *[]);
57    
58     struct Message whois_msgtab = {
59     "WHOIS", 0, 0, 0, 0, MFLG_SLOW, 0,
60     { m_unregistered, m_whois, mo_whois, m_ignore, mo_whois, m_ignore }
61     };
62    
63     #ifndef STATIC_MODULES
64 knight 31 const char *_version = "$Revision$";
65 adx 30 static struct Callback *whois_cb;
66    
67     static void *
68     va_whois(va_list args)
69     {
70     struct Client *source_p = va_arg(args, struct Client *);
71     int parc = va_arg(args, int);
72     char **parv = va_arg(args, char **);
73    
74     do_whois(source_p, parc, parv);
75     return NULL;
76     }
77    
78     void
79     _modinit(void)
80     {
81     whois_cb = register_callback("doing_whois", va_whois);
82     mod_add_cmd(&whois_msgtab);
83     }
84    
85     void
86     _moddeinit(void)
87     {
88     mod_del_cmd(&whois_msgtab);
89     uninstall_hook(whois_cb, va_whois);
90     }
91     #endif
92    
93     /*
94     ** m_whois
95     ** parv[0] = sender prefix
96     ** parv[1] = nickname masklist
97     */
98     static void
99     m_whois(struct Client *client_p, struct Client *source_p,
100     int parc, char *parv[])
101     {
102     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     struct Client *target_p;
186     char *nick;
187     char *p = NULL;
188     int found = 0;
189    
190     nick = parv[1];
191     while (*nick == ',')
192     nick++;
193     if ((p = strchr(nick,',')) != NULL)
194     *p = '\0';
195    
196     if (*nick == '\0')
197     return;
198    
199     collapse(nick);
200    
201     if (strpbrk(nick, "?#*") == NULL)
202     {
203     if ((target_p = find_client(nick)) != NULL)
204     {
205     if (IsServer(source_p->from))
206 adx 268 client_burst_if_needed(source_p->from, target_p);
207 adx 30
208     if (IsClient(target_p))
209     {
210 adx 268 whois_person(source_p, target_p);
211     found = 1;
212 adx 30 }
213     }
214     else if (!ServerInfo.hub && uplink && IsCapable(uplink, CAP_LL))
215     {
216     if (parc > 2)
217     sendto_one(uplink,":%s WHOIS %s :%s",
218     source_p->name, nick, nick);
219     else
220     sendto_one(uplink,":%s WHOIS %s",
221     source_p->name, nick);
222     return;
223     }
224     }
225     else /* wilds is true */
226     {
227     /* disallow wild card whois on lazylink leafs for now */
228     if (!ServerInfo.hub && uplink && IsCapable(uplink, CAP_LL))
229     return;
230    
231 adx 268 if (!IsOper(source_p))
232     {
233     if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
234     {
235     sendto_one(source_p, form_str(RPL_LOAD2HI),
236     me.name, source_p->name);
237     return;
238     }
239     else
240     last_used = CurrentTime;
241     }
242    
243 adx 30 /* Oh-oh wilds is true so have to do it the hard expensive way */
244     if (MyClient(source_p))
245     found = global_whois(source_p, nick);
246     }
247    
248     if (!found)
249     {
250     if (!IsDigit(*nick))
251     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
252     me.name, source_p->name, nick);
253     }
254    
255     sendto_one(source_p, form_str(RPL_ENDOFWHOIS),
256     me.name, source_p->name, parv[1]);
257     }
258    
259     /* global_whois()
260     *
261     * Inputs - source_p client to report to
262     * - target_p client to report on
263     * Output - if found return 1
264     * Side Effects - do a single whois on given client
265     * writing results to source_p
266     */
267     static int
268     global_whois(struct Client *source_p, const char *nick)
269     {
270     dlink_node *ptr;
271     struct Client *target_p;
272     int found = 0;
273    
274     DLINK_FOREACH(ptr, global_client_list.head)
275     {
276     target_p = ptr->data;
277    
278     if (!IsClient(target_p))
279     continue;
280    
281     if (!match(nick, target_p->name))
282     continue;
283    
284     assert(target_p->servptr != NULL);
285    
286     /* 'Rules' established for sending a WHOIS reply:
287     *
288     *
289     * - if wildcards are being used dont send a reply if
290     * the querier isnt any common channels and the
291     * client in question is invisible and wildcards are
292     * in use (allow exact matches only);
293     *
294     * - only send replies about common or public channels
295     * the target user(s) are on;
296     */
297    
298     found |= single_whois(source_p, target_p);
299     }
300    
301     return (found);
302     }
303    
304     /* single_whois()
305     *
306     * Inputs - source_p client to report to
307     * - target_p client to report on
308     * Output - if found return 1
309     * Side Effects - do a single whois on given client
310     * writing results to source_p
311     */
312     static int
313     single_whois(struct Client *source_p, struct Client *target_p)
314     {
315     dlink_node *ptr;
316     struct Channel *chptr;
317    
318     if (!IsInvisible(target_p) || target_p == source_p)
319     {
320     /* always show user if they are visible (no +i) */
321     whois_person(source_p, target_p);
322     return 1;
323     }
324    
325     /* target_p is +i. Check if it is on any common channels with source_p */
326     DLINK_FOREACH(ptr, target_p->channel.head)
327     {
328     chptr = ((struct Membership *) ptr->data)->chptr;
329     if (IsMember(source_p, chptr))
330     {
331     whois_person(source_p, target_p);
332     return 1;
333     }
334     }
335    
336     return 0;
337     }
338    
339     /* whois_person()
340     *
341     * inputs - source_p client to report to
342     * - target_p client to report on
343     * output - NONE
344     * side effects -
345     */
346     static void
347     whois_person(struct Client *source_p, struct Client *target_p)
348     {
349     char buf[IRCD_BUFSIZE];
350     dlink_node *lp;
351     struct Client *server_p;
352     struct Channel *chptr;
353     struct Membership *ms;
354     int cur_len = 0;
355     int mlen;
356     char *t = NULL;
357     int tlen;
358     int reply_to_send = NO;
359    
360     server_p = target_p->servptr;
361    
362     sendto_one(source_p, form_str(RPL_WHOISUSER),
363     me.name, source_p->name, target_p->name,
364     target_p->username, target_p->host, target_p->info);
365    
366     cur_len = mlen = ircsprintf(buf, form_str(RPL_WHOISCHANNELS),
367     me.name, source_p->name, target_p->name, "");
368     t = buf + mlen;
369    
370     DLINK_FOREACH(lp, target_p->channel.head)
371     {
372     ms = lp->data;
373     chptr = ms->chptr;
374    
375     if (ShowChannel(source_p, chptr))
376     {
377     /* Don't show local channels if user is doing a remote whois */
378     if (!MyConnect(source_p) && (chptr->chname[0] == '&'))
379     continue;
380    
381     if ((cur_len + 3 + strlen(chptr->chname) + 1) > (IRCD_BUFSIZE - 2))
382     {
383     *(t - 1) = '\0';
384     sendto_one(source_p, "%s", buf);
385     cur_len = mlen;
386     t = buf + mlen;
387     }
388    
389     tlen = ircsprintf(t, "%s%s ", get_member_status(ms, YES), chptr->chname);
390     t += tlen;
391     cur_len += tlen;
392     reply_to_send = YES;
393     }
394     }
395    
396     if (reply_to_send)
397     {
398     *(t - 1) = '\0';
399     sendto_one(source_p, "%s", buf);
400     }
401    
402     if (IsOper(source_p) || !ConfigServerHide.hide_servers || target_p == source_p)
403     sendto_one(source_p, form_str(RPL_WHOISSERVER),
404     me.name, source_p->name, target_p->name,
405     server_p->name, server_p->info);
406     else
407     sendto_one(source_p, form_str(RPL_WHOISSERVER),
408     me.name, source_p->name, target_p->name,
409     ConfigServerHide.hidden_name,
410     ServerInfo.network_desc);
411    
412     if (target_p->away != NULL)
413     sendto_one(source_p, form_str(RPL_AWAY),
414     me.name, source_p->name, target_p->name,
415     target_p->away);
416    
417     if (IsOper(target_p))
418     sendto_one(source_p, form_str((IsAdmin(target_p) &&
419     !IsOperHiddenAdmin(target_p)) ? RPL_WHOISADMIN :
420     RPL_WHOISOPERATOR), me.name, source_p->name, target_p->name);
421    
422     if (IsOper(source_p) && IsCaptured(target_p))
423     sendto_one(source_p, form_str(RPL_ISCAPTURED),
424     me.name, source_p->name, target_p->name);
425    
426     if (ConfigFileEntry.use_whois_actually && (target_p->sockhost[0] != '\0') &&
427     !(ConfigFileEntry.hide_spoof_ips && IsIPSpoof(target_p)) &&
428     !(target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
429     {
430     if (IsAdmin(source_p) || source_p == target_p)
431     sendto_one(source_p, form_str(RPL_WHOISACTUALLY),
432     me.name, source_p->name, target_p->name, target_p->sockhost);
433     else
434     sendto_one(source_p, form_str(RPL_WHOISACTUALLY),
435     me.name, source_p->name, target_p->name,
436     IsIPSpoof(target_p) || IsOper(target_p) ?
437     "255.255.255.255" : target_p->sockhost);
438     }
439    
440     if (MyConnect(target_p)) /* Can't do any of this if not local! db */
441     {
442     #ifdef HAVE_LIBCRYPTO
443     if (target_p->localClient->fd.ssl)
444     sendto_one(source_p, form_str(RPL_WHOISSSL),
445     me.name, source_p->name, target_p->name);
446     #endif
447     sendto_one(source_p, form_str(RPL_WHOISIDLE),
448     me.name, source_p->name, target_p->name,
449     CurrentTime - target_p->localClient->last,
450     target_p->firsttime);
451     }
452     }

Properties

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