]> jfr.im git - solanum.git/blobdiff - modules/m_etrace.c
extensions/umode_hide_idle_time: mask times for hidden sources (#373)
[solanum.git] / modules / m_etrace.c
index b9bf4c1304a32a03e0de1c9cae3c29e8a16bb334..abeedc897710f39fc4e1e750c6c4ed110fc900e6 100644 (file)
@@ -28,8 +28,6 @@
  *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  *  IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  *  POSSIBILITY OF SUCH DAMAGE.
- *
- *  $Id: m_etrace.c 3161 2007-01-25 07:23:01Z nenolod $
  */
 
 #include "stdinc.h"
@@ -37,9 +35,8 @@
 #include "hook.h"
 #include "client.h"
 #include "hash.h"
-#include "common.h"
 #include "hash.h"
-#include "irc_string.h"
+#include "match.h"
 #include "ircd.h"
 #include "numeric.h"
 #include "s_serv.h"
 #include "msg.h"
 #include "parse.h"
 #include "modules.h"
+#include "logger.h"
+#include "supported.h"
+
+static const char etrace_desc[] =
+    "Provides enhanced tracing facilities to opers (ETRACE, CHANTRACE, and MASKTRACE)";
 
-static int mo_etrace(struct Client *, struct Client *, int, const char **);
-static int me_etrace(struct Client *, struct Client *, int, const char **);
-static int mo_chantrace(struct Client *, struct Client *, int, const char **);
-static int mo_masktrace(struct Client *, struct Client *, int, const char **);
+static void mo_etrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void me_etrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void m_chantrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void mo_masktrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
 
 struct Message etrace_msgtab = {
-       "ETRACE", 0, 0, 0, MFLG_SLOW,
+       "ETRACE", 0, 0, 0, 0,
        {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, {me_etrace, 0}, {mo_etrace, 0}}
 };
 struct Message chantrace_msgtab = {
-       "CHANTRACE", 0, 0, 0, MFLG_SLOW,
-       {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_chantrace, 2}}
+       "CHANTRACE", 0, 0, 0, 0,
+       {mg_ignore, {m_chantrace, 2}, mg_ignore, mg_ignore, mg_ignore, {m_chantrace, 2}}
 };
 struct Message masktrace_msgtab = {
-       "MASKTRACE", 0, 0, 0, MFLG_SLOW,
+       "MASKTRACE", 0, 0, 0, 0,
        {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_masktrace, 2}}
 };
 
+static int
+_modinit(void)
+{
+    add_isupport("ETRACE", isupport_string, "");
+
+    return 0;
+}
+
+static void
+_moddeinit(void)
+{
+    delete_isupport("ETRACE");
+}
+
 mapi_clist_av1 etrace_clist[] = { &etrace_msgtab, &chantrace_msgtab, &masktrace_msgtab, NULL };
-DECLARE_MODULE_AV1(etrace, NULL, NULL, etrace_clist, NULL, NULL, "$Revision: 3161 $");
+
+DECLARE_MODULE_AV2(etrace, _modinit, _moddeinit, etrace_clist, NULL, NULL, NULL, NULL, etrace_desc);
 
 static void do_etrace(struct Client *source_p, int ipv4, int ipv6);
 static void do_etrace_full(struct Client *source_p);
@@ -80,23 +97,20 @@ static const char *spoofed_sockhost = "0";
 
 /*
  * m_etrace
- *      parv[0] = sender prefix
  *      parv[1] = options [or target]
  *     parv[2] = [target]
  */
-static int
-mo_etrace(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+mo_etrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        if(parc > 1 && !EmptyString(parv[1]))
        {
                if(!irccmp(parv[1], "-full"))
                        do_etrace_full(source_p);
-#ifdef RB_IPV6
                else if(!irccmp(parv[1], "-v6"))
                        do_etrace(source_p, 0, 1);
                else if(!irccmp(parv[1], "-v4"))
                        do_etrace(source_p, 1, 0);
-#endif
                else
                {
                        struct Client *target_p = find_named_person(parv[1]);
@@ -109,7 +123,10 @@ mo_etrace(struct Client *client_p, struct Client *source_p, int parc, const char
                                                target_p->servptr->name,
                                                get_id(target_p, target_p));
                                else
+                               {
                                        do_single_etrace(source_p, target_p);
+                                       sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), target_p->name);
+                               }
                        }
                        else
                                sendto_one_numeric(source_p, ERR_NOSUCHNICK,
@@ -118,26 +135,22 @@ mo_etrace(struct Client *client_p, struct Client *source_p, int parc, const char
        }
        else
                do_etrace(source_p, 1, 1);
-
-       return 0;
 }
 
-static int
-me_etrace(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+me_etrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct Client *target_p;
 
        if(!IsOper(source_p) || parc < 2 || EmptyString(parv[1]))
-               return 0;
+               return;
 
        /* we cant etrace remote clients.. we shouldnt even get sent them */
        if((target_p = find_person(parv[1])) && MyClient(target_p))
                do_single_etrace(source_p, target_p);
 
-        sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), 
+        sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE),
                                target_p ? target_p->name : parv[1]);
-
-       return 0;
 }
 
 static void
@@ -151,15 +164,13 @@ do_etrace(struct Client *source_p, int ipv4, int ipv6)
        {
                target_p = ptr->data;
 
-#ifdef RB_IPV6
-               if((!ipv4 && target_p->localClient->ip.ss_family == AF_INET) ||
-                  (!ipv6 && target_p->localClient->ip.ss_family == AF_INET6))
+               if((!ipv4 && GET_SS_FAMILY(&target_p->localClient->ip) == AF_INET) ||
+                  (!ipv6 && GET_SS_FAMILY(&target_p->localClient->ip) == AF_INET6))
                        continue;
-#endif
 
                sendto_one(source_p, form_str(RPL_ETRACE),
-                          me.name, source_p->name, 
-                          IsOper(target_p) ? "Oper" : "User", 
+                          me.name, source_p->name,
+                          SeesOper(target_p, source_p) ? "Oper" : "User",
                           get_client_class(target_p),
                           target_p->name, target_p->username, target_p->host,
                           show_ip(source_p, target_p) ? target_p->sockhost : "255.255.255.255",
@@ -197,23 +208,23 @@ do_single_etrace(struct Client *source_p, struct Client *target_p)
         */
        if(!show_ip(source_p, target_p))
                sendto_one(source_p, form_str(RPL_ETRACEFULL),
-                               me.name, source_p->name, 
-                               IsOper(target_p) ? "Oper" : "User",
+                               me.name, source_p->name,
+                               SeesOper(target_p, source_p) ? "Oper" : "User",
                                get_client_class(target_p),
-                               target_p->name, target_p->username, target_p->host, 
+                               target_p->name, target_p->username, target_p->host,
                                "255.255.255.255", "<hidden> <hidden>", target_p->info);
        else
                sendto_one(source_p, form_str(RPL_ETRACEFULL),
-                               me.name, source_p->name, 
-                               IsOper(target_p) ? "Oper" : "User",
+                               me.name, source_p->name,
+                               SeesOper(target_p, source_p) ? "Oper" : "User",
                                get_client_class(target_p),
-                               target_p->name, target_p->username, 
+                               target_p->name, target_p->username,
                                target_p->host, target_p->sockhost,
                                target_p->localClient->fullcaps, target_p->info);
 }
 
-static int
-mo_chantrace(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+m_chantrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        struct Client *target_p;
        struct Channel *chptr;
@@ -234,7 +245,7 @@ mo_chantrace(struct Client *client_p, struct Client *source_p, int parc, const c
                {
                        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
                                        me.name, source_p->name, "CHANTRACE");
-                       return 0;
+                       return;
                }
        }
 
@@ -242,7 +253,7 @@ mo_chantrace(struct Client *client_p, struct Client *source_p, int parc, const c
        {
                sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL),
                                name);
-               return 0;
+               return;
        }
 
        /* dont report operspys for nonexistant channels. */
@@ -253,7 +264,7 @@ mo_chantrace(struct Client *client_p, struct Client *source_p, int parc, const c
        {
                sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL),
                                chptr->chname);
-               return 0;
+               return;
        }
 
        RB_DLINK_FOREACH(ptr, chptr->members.head)
@@ -269,8 +280,8 @@ mo_chantrace(struct Client *client_p, struct Client *source_p, int parc, const c
                        sockhost = target_p->sockhost;
 
                sendto_one(source_p, form_str(RPL_ETRACE),
-                               me.name, source_p->name, 
-                               IsOper(target_p) ? "Oper" : "User",
+                               me.name, source_p->name,
+                               SeesOper(target_p, source_p) ? "Oper" : "User",
                                /* class field -- pretend its server.. */
                                target_p->servptr->name,
                                target_p->name, target_p->username, target_p->host,
@@ -278,7 +289,6 @@ mo_chantrace(struct Client *client_p, struct Client *source_p, int parc, const c
        }
 
        sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name);
-       return 0;
 }
 
 static void
@@ -288,52 +298,14 @@ match_masktrace(struct Client *source_p, rb_dlink_list *list,
 {
        struct Client *target_p;
        rb_dlink_node *ptr;
-       const char *sockhost;   
-       char *mangle_gecos = NULL;
-       
-       if(gecos != NULL)
-       {
-               if(strstr(gecos, "\\s"))
-               {
-                       char *tmp = LOCAL_COPY(gecos);
-                       char *orig = tmp;
-                       char *new = tmp;
-                       while(*orig)
-                       {
-                               if(*orig == '\\' && *(orig + 1) != '\0')
-                                       {
-                                       if(*(orig + 1) == 's')
-                                       {
-                                               *new++ = ' ';
-                                               orig += 2;   
-                                       }
-                                       /* otherwise skip that and the escaped
-                                        * character after it, so we dont mistake
-                                        * \\s as \s --fl
-                                        */
-                                       else
-                                       {   
-                                               *new++ = *orig++;
-                                               *new++ = *orig++;
-                                       }
-                               }
-                               else
-                                       *new++ = *orig++;
-                       }
-       
-                       *new = '\0';
-                       mangle_gecos = LOCAL_COPY(tmp);
-               }
-               else
-                       mangle_gecos = LOCAL_COPY(gecos);
-       }
+       const char *sockhost;
 
        RB_DLINK_FOREACH(ptr, list->head)
        {
                target_p = ptr->data;
                if(!IsPerson(target_p))
                        continue;
-               
+
                if(EmptyString(target_p->sockhost))
                        sockhost = empty_sockhost;
                else if(!show_ip(source_p, target_p))
@@ -349,12 +321,12 @@ match_masktrace(struct Client *source_p, rb_dlink_list *list,
                        if(name != NULL && !match(name, target_p->name))
                                continue;
 
-                       if(mangle_gecos != NULL && !match_esc(mangle_gecos, target_p->info))
+                       if(gecos != NULL && !match_esc(gecos, target_p->info))
                                continue;
-                       
+
                        sendto_one(source_p, form_str(RPL_ETRACE),
-                               me.name, source_p->name, 
-                               IsOper(target_p) ? "Oper" : "User",
+                               me.name, source_p->name,
+                               SeesOper(target_p, source_p) ? "Oper" : "User",
                                /* class field -- pretend its server.. */
                                target_p->servptr->name,
                                target_p->name, target_p->username, target_p->host,
@@ -363,41 +335,31 @@ match_masktrace(struct Client *source_p, rb_dlink_list *list,
        }
 }
 
-static int
-mo_masktrace(struct Client *client_p, struct Client *source_p, int parc, 
+static void
+mo_masktrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc,
        const char *parv[])
 {
        char *name, *username, *hostname, *gecos;
-       const char *mask;
-       int operspy = 0;
 
-       mask = parv[1]; 
-       name = LOCAL_COPY(parv[1]);     
+       name = LOCAL_COPY(parv[1]);
        collapse(name);
 
-       if(IsOperSpy(source_p) && parv[1][0] == '!')
-       {
-               name++;
-               mask++;
-               operspy = 1;
-       }               
-       
        if(parc > 2 && !EmptyString(parv[2]))
        {
                gecos = LOCAL_COPY(parv[2]);
                collapse_esc(gecos);
        } else
                gecos = NULL;
-       
+
 
        if((hostname = strchr(name, '@')) == NULL)
        {
                sendto_one_notice(source_p, ":Invalid parameters");
-               return 0;
+               return;
        }
 
        *hostname++ = '\0';
-       
+
        if((username = strchr(name, '!')) == NULL)
        {
                username = name;
@@ -408,25 +370,9 @@ mo_masktrace(struct Client *client_p, struct Client *source_p, int parc,
        if(EmptyString(username) || EmptyString(hostname))
        {
                sendto_one_notice(source_p, ":Invalid parameters");
-               return 0;
+               return;
        }
-                       
-       if(operspy) {
-               if (!ConfigFileEntry.operspy_dont_care_user_info)
-               {
-                       char buf[512];
-                       strlcpy(buf, mask, sizeof(buf));
-                       if(!EmptyString(gecos)) {
-                               strlcat(buf, " ", sizeof(buf));
-                               strlcat(buf, gecos, sizeof(buf));
-                       }               
-
-                       report_operspy(source_p, "MASKTRACE", buf);     
-               }
-               match_masktrace(source_p, &global_client_list, username, hostname, name, gecos);                
-       } else
-               match_masktrace(source_p, &lclient_list, username, hostname, name, gecos);
 
-       sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); 
-       return 0;
+       match_masktrace(source_p, &global_client_list, username, hostname, name, gecos);
+       sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name);
 }