ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_whois.c
Revision: 1333
Committed: Sun Apr 1 16:28:53 2012 UTC (13 years, 4 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_whois.c
File size: 11370 byte(s)
Log Message:
- m_whois.c: fixed displaying of RPL_TARGUMODEG

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

Properties

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