1 |
/* |
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 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "list.h" |
27 |
#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 |
#include "conf.h" |
34 |
#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 |
|
43 |
static void do_whois(struct Client *, int, char *[]); |
44 |
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 |
static time_t last_used = 0; |
59 |
|
60 |
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 |
if (parc > 2 && !EmptyString(parv[2])) |
68 |
{ |
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 |
last_used = CurrentTime; |
78 |
|
79 |
/* 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 |
do_whois(source_p, parc, parv); |
94 |
} |
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 |
if (parc > 2 && !EmptyString(parv[2])) |
113 |
{ |
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 |
do_whois(source_p, parc, parv); |
122 |
} |
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 |
do_whois(struct Client *source_p, int parc, char *parv[]) |
134 |
{ |
135 |
static time_t last_used = 0; |
136 |
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 |
if ((target_p = hash_find_client(nick)) != NULL) |
155 |
{ |
156 |
if (IsClient(target_p)) |
157 |
{ |
158 |
whois_person(source_p, target_p); |
159 |
found = 1; |
160 |
} |
161 |
} |
162 |
} |
163 |
else /* wilds is true */ |
164 |
{ |
165 |
if (!HasUMode(source_p, UMODE_OPER)) |
166 |
{ |
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 |
/* 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 |
return found; |
236 |
} |
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 |
dlink_node *ptr = NULL; |
250 |
|
251 |
if (!HasUMode(target_p, UMODE_INVISIBLE) || target_p == source_p) |
252 |
{ |
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 |
struct Channel *chptr = ((struct Membership *) ptr->data)->chptr; |
262 |
|
263 |
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 |
int reply_to_send = 0; |
293 |
int show_ip = 0; |
294 |
|
295 |
server_p = target_p->servptr; |
296 |
|
297 |
sendto_one(source_p, form_str(RPL_WHOISUSER), |
298 |
me.name, source_p->name, target_p->name, |
299 |
target_p->username, target_p->host, target_p->info); |
300 |
|
301 |
cur_len = mlen = snprintf(buf, sizeof(buf), form_str(RPL_WHOISCHANNELS), |
302 |
me.name, source_p->name, target_p->name, ""); |
303 |
t = buf + mlen; |
304 |
|
305 |
DLINK_FOREACH(lp, target_p->channel.head) |
306 |
{ |
307 |
ms = lp->data; |
308 |
chptr = ms->chptr; |
309 |
|
310 |
if (ShowChannel(source_p, chptr)) |
311 |
{ |
312 |
if ((cur_len + 3 + strlen(chptr->chname) + 1) > (IRCD_BUFSIZE - 2)) |
313 |
{ |
314 |
*(t - 1) = '\0'; |
315 |
sendto_one(source_p, "%s", buf); |
316 |
cur_len = mlen; |
317 |
t = buf + mlen; |
318 |
} |
319 |
|
320 |
tlen = ircsprintf(t, "%s%s ", get_member_status(ms, 1), chptr->chname); |
321 |
t += tlen; |
322 |
cur_len += tlen; |
323 |
reply_to_send = 1; |
324 |
} |
325 |
} |
326 |
|
327 |
if (reply_to_send) |
328 |
{ |
329 |
*(t - 1) = '\0'; |
330 |
sendto_one(source_p, "%s", buf); |
331 |
} |
332 |
|
333 |
if (HasUMode(source_p, UMODE_OPER) || !ConfigServerHide.hide_servers || target_p == source_p) |
334 |
sendto_one(source_p, form_str(RPL_WHOISSERVER), |
335 |
me.name, source_p->name, target_p->name, |
336 |
server_p->name, server_p->info); |
337 |
else |
338 |
sendto_one(source_p, form_str(RPL_WHOISSERVER), |
339 |
me.name, source_p->name, target_p->name, |
340 |
ConfigServerHide.hidden_name, |
341 |
ServerInfo.network_desc); |
342 |
|
343 |
if (HasUMode(target_p, UMODE_REGISTERED)) |
344 |
sendto_one(source_p, form_str(RPL_WHOISREGNICK), |
345 |
me.name, source_p->name, target_p->name); |
346 |
|
347 |
if (target_p->away[0]) |
348 |
sendto_one(source_p, form_str(RPL_AWAY), |
349 |
me.name, source_p->name, target_p->name, |
350 |
target_p->away); |
351 |
|
352 |
if (HasUMode(target_p, UMODE_CALLERID) && !HasUMode(target_p, UMODE_SOFTCALLERID)) |
353 |
sendto_one(source_p, form_str(RPL_TARGUMODEG), |
354 |
me.name, source_p->name, target_p->name); |
355 |
|
356 |
if (HasUMode(target_p, UMODE_OPER)) |
357 |
if (!HasUMode(target_p, UMODE_HIDDEN) || HasUMode(source_p, UMODE_OPER)) |
358 |
sendto_one(source_p, form_str(HasUMode(target_p, UMODE_ADMIN) ? RPL_WHOISADMIN : |
359 |
RPL_WHOISOPERATOR), |
360 |
me.name, source_p->name, target_p->name); |
361 |
|
362 |
if (strcmp(target_p->sockhost, "0")) |
363 |
{ |
364 |
if (HasUMode(source_p, UMODE_ADMIN) || source_p == target_p) |
365 |
show_ip = 1; |
366 |
else if (IsIPSpoof(target_p)) |
367 |
show_ip = (HasUMode(source_p, UMODE_OPER) && !ConfigFileEntry.hide_spoof_ips); |
368 |
else |
369 |
show_ip = 1; |
370 |
|
371 |
sendto_one(source_p, form_str(RPL_WHOISACTUALLY), |
372 |
me.name, source_p->name, target_p->name, |
373 |
show_ip ? target_p->sockhost : "255.255.255.255"); |
374 |
} |
375 |
|
376 |
if (MyConnect(target_p)) /* Can't do any of this if not local! db */ |
377 |
{ |
378 |
#ifdef HAVE_LIBCRYPTO |
379 |
if (target_p->localClient->fd.ssl) |
380 |
sendto_one(source_p, form_str(RPL_WHOISSECURE), |
381 |
me.name, source_p->name, target_p->name); |
382 |
#endif |
383 |
sendto_one(source_p, form_str(RPL_WHOISIDLE), |
384 |
me.name, source_p->name, target_p->name, |
385 |
CurrentTime - target_p->localClient->last_privmsg, |
386 |
target_p->localClient->firsttime); |
387 |
|
388 |
if (HasUMode(target_p, UMODE_OPER) && target_p != source_p) |
389 |
if (HasUMode(target_p, UMODE_SPY)) |
390 |
sendto_one(target_p, ":%s NOTICE %s :*** Notice -- %s (%s@%s) [%s] is doing " |
391 |
"a whois on you", me.name, target_p->name, source_p->name, |
392 |
source_p->username, source_p->host, source_p->servptr->name); |
393 |
} |
394 |
} |
395 |
|
396 |
static struct Message whois_msgtab = { |
397 |
"WHOIS", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
398 |
{ m_unregistered, m_whois, mo_whois, m_ignore, mo_whois, m_ignore } |
399 |
}; |
400 |
|
401 |
static void |
402 |
module_init(void) |
403 |
{ |
404 |
mod_add_cmd(&whois_msgtab); |
405 |
} |
406 |
|
407 |
static void |
408 |
module_exit(void) |
409 |
{ |
410 |
mod_del_cmd(&whois_msgtab); |
411 |
} |
412 |
|
413 |
struct module module_entry = { |
414 |
.node = { NULL, NULL, NULL }, |
415 |
.name = NULL, |
416 |
.version = "$Revision$", |
417 |
.handle = NULL, |
418 |
.modinit = module_init, |
419 |
.modexit = module_exit, |
420 |
.flags = 0 |
421 |
}; |