added gnutls backend and moved backend code into new files
[ircu2.10.12-pk.git] / ircd / m_whois.c
index 5dda1a572a2edd3279c7e48ad4967595eb739e58..01c9db55db3d1d8311a6b89f76bc40ffa79a9930 100644 (file)
@@ -86,6 +86,7 @@
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_features.h"
+#include "ircd_log.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
 #include "match.h"
 #include "send.h"
 #include "whocmds.h"
 
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
 #include <string.h>
 
 /*
  * 2000-07-01: Isomer
  *  * Rewritten to make this understandable
- *  * You can nolonger /whois unregistered clients.
+ *  * You can no longer /whois unregistered clients.
  *  
  *
  * General rules:
@@ -136,7 +137,8 @@ static void do_whois(struct Client* sptr, struct Client *acptr, int parc)
   
   const struct User* user = cli_user(acptr);
   const char* name = (!*(cli_name(acptr))) ? "?" : cli_name(acptr);  
-  a2cptr = user->server;
+  a2cptr = feature_bool(FEAT_HIS_WHOIS_SERVERNAME) && !IsAnOper(sptr)
+      && sptr != acptr ? &his : user->server;
   assert(user);
   send_reply(sptr, RPL_WHOISUSER, name, user->username, user->host,
                   cli_info(acptr));
@@ -152,13 +154,21 @@ static void do_whois(struct Client* sptr, struct Client *acptr, int parc)
     {
        chptr = chan->channel;
        
-       if (!ShowChannel(sptr, chptr))
+       if (!ShowChannel(sptr, chptr)
+           && !(IsOper(sptr) && IsLocalChannel(chptr->chname)))
           continue;
-          
+
        if (acptr != sptr && IsZombie(chan))
           continue;
-          
-       if (len+strlen(chptr->chname) + mlen > BUFSIZE - 5) 
+
+       /* Don't show local channels when HIS is defined, unless it's a
+       * remote WHOIS --ULtimaTe_
+       */
+       if (IsLocalChannel(chptr->chname) && (acptr != sptr) && (parc == 2)
+           && feature_bool(FEAT_HIS_WHOIS_LOCALCHAN) && !IsAnOper(sptr))
+         continue;
+
+       if (len+strlen(chptr->chname) + mlen > BUFSIZE - 5)
        {
           send_reply(sptr, SND_EXPLICIT | RPL_WHOISCHANNELS, "%s :%s", name, buf);
           *buf = '\0';
@@ -166,9 +176,13 @@ static void do_whois(struct Client* sptr, struct Client *acptr, int parc)
        }
        if (IsDeaf(acptr))
          *(buf + len++) = '-';
-       if (is_chan_op(acptr, chptr))
+       if (!ShowChannel(sptr, chptr))
+         *(buf + len++) = '*';
+       if (IsDelayedJoin(chan) && (sptr != acptr))
+         *(buf + len++) = '<';
+       else if (IsChanOp(chan))
          *(buf + len++) = '@';
-       else if (has_voice(acptr, chptr))
+       else if (HasVoice(chan))
          *(buf + len++) = '+';
        else if (IsZombie(chan))
          *(buf + len++) = '!';
@@ -183,21 +197,15 @@ static void do_whois(struct Client* sptr, struct Client *acptr, int parc)
         send_reply(sptr, RPL_WHOISCHANNELS, name, buf);
   }
 
-  if (feature_bool(FEAT_HIS_WHOIS_SERVERNAME) && !IsAnOper(sptr) &&
-      sptr != acptr)
-    send_reply(sptr, RPL_WHOISSERVER, name, feature_str(FEAT_HIS_SERVERNAME),
-               feature_str(FEAT_HIS_SERVERINFO));
-  else
-    send_reply(sptr, RPL_WHOISSERVER, name, cli_name(a2cptr),
-              cli_info(a2cptr));
+  send_reply(sptr, RPL_WHOISSERVER, name, cli_name(a2cptr),
+             cli_info(a2cptr));
 
   if (user)
   {
     if (user->away)
        send_reply(sptr, RPL_AWAY, name, user->away);
 
-    if (IsAnOper(acptr) && (HasPriv(acptr, PRIV_DISPLAY) ||
-                           HasPriv(sptr, PRIV_SEE_OPERS)))
+    if (SeeOper(sptr,acptr))
        send_reply(sptr, RPL_WHOISOPERATOR, name);
 
     if (IsAccount(acptr))
@@ -205,15 +213,15 @@ static void do_whois(struct Client* sptr, struct Client *acptr, int parc)
 
     if (HasHiddenHost(acptr) && (IsAnOper(sptr) || acptr == sptr))
       send_reply(sptr, RPL_WHOISACTUALLY, name, user->username,
-                 user->realhost, ircd_ntoa((const char*) &(cli_ip(acptr))));
-    
+                 user->realhost, ircd_ntoa(&cli_ip(acptr)));
+
     /* Hint: if your looking to add more flags to a user, eg +h, here's
      *       probably a good place to add them :)
      */
-     
+
     if (MyConnect(acptr) && (!feature_bool(FEAT_HIS_WHOIS_IDLETIME) ||
                              (sptr == acptr || IsAnOper(sptr) || parc >= 3)))
-       send_reply(sptr, RPL_WHOISIDLE, name, CurrentTime - user->last, 
+       send_reply(sptr, RPL_WHOISIDLE, name, CurrentTime - user->last,
                   cli_firsttime(acptr));
   }
 }
@@ -225,16 +233,15 @@ static void do_whois(struct Client* sptr, struct Client *acptr, int parc)
  */
 static int do_wilds(struct Client* sptr, char *nick, int count, int parc)
 {
-  struct Client *acptr; /* Current client we're concidering */
+  struct Client *acptr; /* Current client we're considering */
   struct User *user;   /* the user portion of the client */
-  char *name;          /* the name of this client */
   struct Membership* chan; 
   int invis;           /* does +i apply? */
   int member;          /* Is this user on any channels? */
   int showperson;       /* Should we show this person? */
   int found = 0 ;      /* How many were found? */
   
-  /* Ech! This is hidious! */
+  /* Ech! This is hideous! */
   for (acptr = GlobalClientList; (acptr = next_client(acptr, nick));
       acptr = cli_next(acptr))
   {
@@ -246,7 +253,7 @@ static int do_wilds(struct Client* sptr, char *nick, int count, int parc)
     /*
      * I'm always last :-) and acptr->next == 0!!
      *
-     * Isomer: Does this strike anyone else as being a horrible hidious
+     * Isomer: Does this strike anyone else as being a horrible hideous
      *         hack?
      */
     if (IsMe(acptr)) {
@@ -257,15 +264,14 @@ static int do_wilds(struct Client* sptr, char *nick, int count, int parc)
     /*
      * 'Rules' established for sending a WHOIS reply:
      *
-     * - if wildcards are being used dont send a reply if
-     *   the querier isnt any common channels and the
+     * - if wildcards are being used don't send a reply if
+     *   the querier isn't any common channels and the
      *   client in question is invisible.
      *
      * - only send replies about common or public channels
      *   the target user(s) are on;
      */
     user = cli_user(acptr);
-    name = (!*(cli_name(acptr))) ? "?" : cli_name(acptr);
     assert(user);
 
     invis = (acptr != sptr) && IsInvisible(acptr);
@@ -344,6 +350,7 @@ int m_whois(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   char*           p = 0;
   int             found = 0;
   int            total = 0;
+  int             wildscount = 0;
 
   if (parc < 2)
   {
@@ -400,7 +407,13 @@ int m_whois(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       }
     }
     else /* wilds */
-       found=do_wilds(sptr, nick, total, parc);
+    {
+      if (++wildscount > 3) {
+        send_reply(sptr, ERR_QUERYTOOLONG, parv[1]);
+        break;
+      }
+      found=do_wilds(sptr, nick, total, parc);
+    }
 
     if (!found)
       send_reply(sptr, ERR_NOSUCHNICK, nick);