ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_whois.c
Revision: 479
Committed: Fri Feb 24 11:28:05 2006 UTC (20 years, 5 months ago) by adx
Content type: text/x-csrc
File size: 10858 byte(s)
Log Message:
+ fixed a stupid

File Contents

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

Properties

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