ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_whois.c
(Generate patch)

Comparing:
ircd-hybrid/modules/m_whois.c (file contents), Revision 31 by knight, Sun Oct 2 20:34:05 2005 UTC vs.
ircd-hybrid/trunk/modules/m_whois.c (file contents), Revision 2246 by michael, Sun Jun 16 10:48:39 2013 UTC

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

Comparing:
ircd-hybrid/modules/m_whois.c (property svn:keywords), Revision 31 by knight, Sun Oct 2 20:34:05 2005 UTC vs.
ircd-hybrid/trunk/modules/m_whois.c (property svn:keywords), Revision 2246 by michael, Sun Jun 16 10:48:39 2013 UTC

# Line 1 | Line 1
1 < "Id Revision"
1 > Id Revision

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)