ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_whois.c
Revision: 470
Committed: Fri Feb 17 05:07:43 2006 UTC (20 years, 5 months ago) by db
Content type: text/x-csrc
File size: 10612 byte(s)
Log Message:
- fix compile errors with moved modules.h
- fix a few missing includes, msg.h and parse.h


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

Properties

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