2 * IRC - Internet Relay Chat, ircd/m_whois.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * $Id: m_whois.c,v 1.37 2005/07/15 21:12:02 entrope Exp $
27 * m_functions execute protocol messages on this server:
29 * cptr is always NON-NULL, pointing to a *LOCAL* client
30 * structure (with an open socket connected!). This
31 * identifies the physical socket where the message
32 * originated (or which caused the m_function to be
33 * executed--some m_functions may call others...).
35 * sptr is the source of the message, defined by the
36 * prefix part of the message if present. If not
37 * or prefix not found, then sptr==cptr.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
63 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64 * *cannot* be a local connection, unless it's
65 * actually cptr!). [MyConnect(x) should probably
66 * be defined as (x == x->from) --msa ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
73 * parv[0], sender (prefix string), if not present
74 * this points to an empty string.
75 * parv[1]...parv[parc-1]
76 * pointers to additional parameters
77 * parv[parc] == NULL, *always*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
88 #include "ircd_features.h"
90 #include "ircd_reply.h"
91 #include "ircd_string.h"
100 /* #include <assert.h> -- Now using assert in ircd_log.h */
105 * * Rewritten to make this understandable
106 * * You can no longer /whois unregistered clients.
110 * /whois nick always shows the nick.
111 * /whois wild* shows the nick if:
112 * * they aren't +i and aren't on any channels.
113 * * they are on a common channel.
114 * * they aren't +i and are on a public channel. (not +p and not +s)
115 * * they aren't +i and are on a private channel. (+p but not +s)
116 * Or to look at it another way (I think):
117 * * +i users are only shown if your on a common channel.
118 * * users on +s channels only aren't shown.
120 * whois doesn't show what channels a +k client is on, for the reason that
121 * /whois X or /whois W floods a user off the server. :)
123 * nb: if the code and this comment disagree, the codes right and I screwed
128 * Send whois information for acptr to sptr
130 static void do_whois(struct Client
* sptr
, struct Client
*acptr
, int parc
)
132 struct Client
*a2cptr
=0;
133 struct Channel
*chptr
=0;
136 static char buf
[512];
138 const struct User
* user
= cli_user(acptr
);
139 const char* name
= (!*(cli_name(acptr
))) ? "?" : cli_name(acptr
);
140 a2cptr
= feature_bool(FEAT_HIS_WHOIS_SERVERNAME
) && !IsAnOper(sptr
)
141 && sptr
!= acptr
? &his
: user
->server
;
143 send_reply(sptr
, RPL_WHOISUSER
, name
, user
->username
, user
->host
,
146 /* Display the channels this user is on. */
147 if ((!IsChannelService(acptr
) && !IsNoChan(acptr
)) || (acptr
==sptr
))
149 struct Membership
* chan
;
150 mlen
= strlen(cli_name(&me
)) + strlen(cli_name(sptr
)) + 12 + strlen(name
);
153 for (chan
= user
->channel
; chan
; chan
= chan
->next_channel
)
155 chptr
= chan
->channel
;
157 if (!ShowChannel(sptr
, chptr
)
158 && !(IsOper(sptr
) && IsLocalChannel(chptr
->chname
)))
161 if (acptr
!= sptr
&& IsZombie(chan
))
164 /* Don't show local channels when HIS is defined, unless it's a
165 * remote WHOIS --ULtimaTe_
167 if (IsLocalChannel(chptr
->chname
) && (acptr
!= sptr
) && (parc
== 2)
168 && feature_bool(FEAT_HIS_WHOIS_LOCALCHAN
) && !IsAnOper(sptr
))
171 if (len
+strlen(chptr
->chname
) + mlen
> BUFSIZE
- 5)
173 send_reply(sptr
, SND_EXPLICIT
| RPL_WHOISCHANNELS
, "%s :%s", name
, buf
);
178 *(buf
+ len
++) = '-';
179 if (IsOper(sptr
) && !ShowChannel(sptr
, chptr
))
180 *(buf
+ len
++) = '*';
181 if (IsDelayedJoin(chan
) && (sptr
!= acptr
))
182 *(buf
+ len
++) = '<';
183 else if (IsChanOp(chan
))
184 *(buf
+ len
++) = '@';
185 else if (HasVoice(chan
))
186 *(buf
+ len
++) = '+';
187 else if (IsZombie(chan
))
188 *(buf
+ len
++) = '!';
191 strcpy(buf
+ len
, chptr
->chname
);
192 len
+= strlen(chptr
->chname
);
193 strcat(buf
+ len
, " ");
197 send_reply(sptr
, RPL_WHOISCHANNELS
, name
, buf
);
200 send_reply(sptr
, RPL_WHOISSERVER
, name
, cli_name(a2cptr
),
206 send_reply(sptr
, RPL_AWAY
, name
, user
->away
);
208 if (SeeOper(sptr
,acptr
))
209 send_reply(sptr
, RPL_WHOISOPERATOR
, name
);
211 if (IsAccount(acptr
))
212 send_reply(sptr
, RPL_WHOISACCOUNT
, name
, user
->account
);
214 if ((HasHiddenHost(acptr
) || HasSetHost(acptr
)) && (IsAnOper(sptr
) || acptr
== sptr
))
215 send_reply(sptr
, RPL_WHOISACTUALLY
, name
, user
->realusername
,
216 user
->realhost
, ircd_ntoa(&cli_ip(acptr
)));
218 if (!IsAnOper(sptr
) && IsParanoid(acptr
) && IsAnOper(acptr
))
219 sendcmdto_one(&me
, CMD_NOTICE
, acptr
, "%C :whois: %s performed a /WHOIS on you.", acptr
, cli_name(sptr
));
221 /* Hint: if your looking to add more flags to a user, eg +h, here's
222 * probably a good place to add them :)
225 if (MyConnect(acptr
) &&
227 (!IsNoIdle(acptr
) && (!feature_bool(FEAT_HIS_WHOIS_IDLETIME
) ||
228 sptr
== acptr
|| parc
>= 3))))
229 send_reply(sptr
, RPL_WHOISIDLE
, name
, CurrentTime
- user
->last
,
230 cli_firsttime(acptr
));
235 * Search and return as many people as matched by the wild 'nick'.
236 * returns the number of people found (or, obviously, 0, if none where
239 static int do_wilds(struct Client
* sptr
, char *nick
, int count
, int parc
)
241 struct Client
*acptr
; /* Current client we're considering */
242 struct User
*user
; /* the user portion of the client */
243 const char *name
; /* the name of this client */
244 struct Membership
* chan
;
245 int invis
; /* does +i apply? */
246 int member
; /* Is this user on any channels? */
247 int showperson
; /* Should we show this person? */
248 int found
= 0 ; /* How many were found? */
250 /* Ech! This is hideous! */
251 for (acptr
= GlobalClientList
; (acptr
= next_client(acptr
, nick
));
252 acptr
= cli_next(acptr
))
254 if (!IsRegistered(acptr
))
260 * I'm always last :-) and acptr->next == 0!!
262 * Isomer: Does this strike anyone else as being a horrible hideous
266 assert(!cli_next(acptr
));
271 * 'Rules' established for sending a WHOIS reply:
273 * - if wildcards are being used don't send a reply if
274 * the querier isn't any common channels and the
275 * client in question is invisible.
277 * - only send replies about common or public channels
278 * the target user(s) are on;
280 user
= cli_user(acptr
);
281 name
= (!*(cli_name(acptr
))) ? "?" : cli_name(acptr
);
284 invis
= (acptr
!= sptr
) && IsInvisible(acptr
);
285 member
= (user
&& user
->channel
) ? 1 : 0;
286 showperson
= !invis
&& !member
;
288 /* Should we show this person now? */
291 do_whois(sptr
, acptr
, parc
);
292 if (count
+found
>MAX_WHOIS_LINES
)
297 /* Step through the channels this user is on */
298 for (chan
= user
->channel
; chan
; chan
= chan
->next_channel
)
300 struct Channel
*chptr
= chan
->channel
;
302 /* If this is a public channel, show the person */
303 if (!invis
&& PubChannel(chptr
)) {
308 /* if this channel is +p and not +s, show them */
309 if (!invis
&& HiddenChannel(chptr
) && !SecretChannel(chptr
)) {
314 member
= find_channel_member(sptr
, chptr
) ? 1 : 0;
315 if (invis
&& !member
)
318 /* If sptr isn't really on this channel, skip it */
322 /* Is this a common channel? */
327 } /* of for (chan in channels) */
329 /* Don't show this person */
333 do_whois(sptr
, acptr
, parc
);
335 if (count
+found
>MAX_WHOIS_LINES
)
337 } /* of global client list */
343 * m_whois - generic message handler
345 * parv[0] = sender prefix
346 * parv[1] = nickname masklist
350 * parv[1] = target server, or a nickname representing a server to target.
351 * parv[2] = nickname masklist
353 int m_whois(struct Client
* cptr
, struct Client
* sptr
, int parc
, char* parv
[])
364 send_reply(sptr
, ERR_NONICKNAMEGIVEN
);
370 /* For convenience: Accept a nickname as first parameter, by replacing
371 * it with the correct servername - as is needed by hunt_server().
372 * This is the secret behind the /whois nick nick trick.
374 if (feature_int(FEAT_HIS_REMOTE
))
376 /* If remote queries are disabled, then use the *second* parameter of
377 * of whois, so /whois nick nick still works.
381 if (!FindUser(parv
[2]))
383 send_reply(sptr
, ERR_NOSUCHNICK
, parv
[2]);
384 send_reply(sptr
, RPL_ENDOFWHOIS
, parv
[2]);
391 if (hunt_server_cmd(sptr
, CMD_WHOIS
, cptr
, 0, "%C :%s", 1, parc
, parv
) !=
398 for (tmp
= parv
[1]; (nick
= ircd_strtok(&p
, tmp
, ",")); tmp
= 0)
406 wilds
= (strchr(nick
, '?') || strchr(nick
, '*'));
408 struct Client
*acptr
= 0;
410 acptr
= FindUser(nick
);
411 if (acptr
&& !IsServer(acptr
)) {
412 do_whois(sptr
, acptr
, parc
);
418 if (++wildscount
> 3) {
419 send_reply(sptr
, ERR_QUERYTOOLONG
, parv
[1]);
422 found
=do_wilds(sptr
, nick
, total
, parc
);
426 send_reply(sptr
, ERR_NOSUCHNICK
, nick
);
428 if (total
>= MAX_WHOIS_LINES
) {
429 send_reply(sptr
, ERR_QUERYTOOLONG
, parv
[1]);
434 } /* of tokenised parm[1] */
435 send_reply(sptr
, RPL_ENDOFWHOIS
, parv
[1]);
441 * ms_whois - server message handler
443 * parv[0] = sender prefix
444 * parv[1] = nickname masklist
448 * parv[1] = target server, or a nickname representing a server to target.
449 * parv[2] = nickname masklist
451 int ms_whois(struct Client
* cptr
, struct Client
* sptr
, int parc
, char* parv
[])
461 send_reply(sptr
, ERR_NONICKNAMEGIVEN
);
467 if (hunt_server_cmd(sptr
, CMD_WHOIS
, cptr
, 0, "%C :%s", 1, parc
, parv
) !=
475 for (tmp
= parv
[1]; (nick
= ircd_strtok(&p
, tmp
, ",")); tmp
= 0)
477 struct Client
*acptr
= 0;
484 acptr
= FindUser(nick
);
485 if (acptr
&& !IsServer(acptr
)) {
487 do_whois(sptr
, acptr
, parc
);
491 send_reply(sptr
, ERR_NOSUCHNICK
, nick
);
495 if (total
>= MAX_WHOIS_LINES
) {
496 send_reply(sptr
, ERR_QUERYTOOLONG
, parv
[1]);
502 } /* of tokenised parm[1] */
503 send_reply(sptr
, RPL_ENDOFWHOIS
, parv
[1]);