]> jfr.im git - solanum.git/blobdiff - modules/m_scan.c
Mailmap and copyright update for Ariadne
[solanum.git] / modules / m_scan.c
index 4419fad5a08d0a302eec3189d620f5f9048145e2..c47a58ed25655f97a9710513087edec9a43dc68e 100644 (file)
@@ -1,8 +1,8 @@
 /*
- *  charybdis: an advanced Internet Relay Chat Daemon(ircd).
+ *  Solanum: a slightly advanced ircd
  *  m_scan.c: Provides information about various targets on various topics
  *
- *  Copyright (c) 2006 William Pitcock <nenolod -at- nenolod.net>
+ *  Copyright (c) 2006 Ariadne Conill <ariadne -at- dereferenced.org>
  *
  *  Redistribution and use in source and binary forms, with or without
  *  modification, are permitted provided that the following conditions are
@@ -27,8 +27,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_scan.c 1853 2006-08-24 18:30:52Z jilles $
  */
 
 #include "stdinc.h"
 #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 "commio.h"
 #include "s_serv.h"
 #include "s_conf.h"
 #include "s_newconf.h"
 #include "msg.h"
 #include "parse.h"
 #include "modules.h"
+#include "logger.h"
+
+static const char scan_desc[] =
+       "Provides the SCAN command to show users that have a mode set or cleared";
 
-static int mo_scan(struct Client *, struct Client *, int, const char **);
-static int scan_umodes(struct Client *, struct Client *, int, const char **);
-/*static int scan_cmodes(struct Client *, struct Client *, int, const char **);*/
+static void mo_scan(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void scan_umodes(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
 
 struct Message scan_msgtab = {
-       "SCAN", 0, 0, 0, MFLG_SLOW,
+       "SCAN", 0, 0, 0, 0,
        {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_scan, 2}}
 };
 
 mapi_clist_av1 scan_clist[] = { &scan_msgtab, NULL };
-DECLARE_MODULE_AV1(scan, NULL, NULL, scan_clist, NULL, NULL, "$Revision: 1853 $");
 
-typedef int (*scan_handler)(struct Client *, struct Client *, int, 
+DECLARE_MODULE_AV2(scan, NULL, NULL, scan_clist, NULL, NULL, NULL, NULL, scan_desc);
+
+typedef void (*scan_handler)(struct MsgBuf *, struct Client *, struct Client *, int,
        const char **);
 
 struct scan_cmd {
@@ -80,12 +80,11 @@ static const char *spoofed_sockhost = "0";
 
 /*
  * m_scan
- *      parv[0] = sender prefix
  *      parv[1] = options [or target]
  *     parv[2] = [target]
  */
-static int
-mo_scan(struct Client *client_p, struct Client *source_p, int parc, 
+static void
+mo_scan(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc,
        const char *parv[])
 {
        struct scan_cmd *sptr;
@@ -94,29 +93,26 @@ mo_scan(struct Client *client_p, struct Client *source_p, int parc,
        {
                if (!irccmp(sptr->name, parv[1]))
                {
-                       if (sptr->operlevel == L_ADMIN &&
-                               !IsOperAdmin(source_p))
-                               return -1;
-                       else
-                               return sptr->handler(client_p, source_p, parc, parv);
+                       if (!(sptr->operlevel == L_ADMIN && !IsOperAdmin(source_p)))
+                               sptr->handler(msgbuf_p, client_p, source_p, parc, parv);
+
+                       return;
                }
        }
 
        sendto_one_notice(source_p, ":*** %s is not an implemented SCAN target",
                          parv[1]);
-
-       return 0;
 }
 
-static int
-scan_umodes(struct Client *client_p, struct Client *source_p, int parc,
+static void
+scan_umodes(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc,
        const char *parv[])
 {
        unsigned int allowed_umodes = 0, disallowed_umodes = 0;
        int what = MODE_ADD;
        int mode;
-       int list_users = YES;
-       int list_max = 0;
+       bool list_users = true;
+       int list_max = 500;
        int list_count = 0, count = 0;
        const char *mask = NULL;
        const char *c;
@@ -133,7 +129,13 @@ scan_umodes(struct Client *client_p, struct Client *source_p, int parc,
                        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
                                me.name, source_p->name, "SCAN UMODES");
 
-               return -1;
+               return;
+       }
+
+       if (parv[2][0] != '+' && parv[2][0] != '-')
+       {
+               sendto_one_notice(source_p, ":SCAN UMODES: umodes parameter must start with '+' or '-'");
+               return;
        }
 
        for (c = parv[2]; *c; c++)
@@ -160,9 +162,9 @@ scan_umodes(struct Client *client_p, struct Client *source_p, int parc,
        for (i = 3; i < parc; i++)
        {
                if (!irccmp(parv[i], "no-list"))
-                       list_users = NO;
+                       list_users = false;
                else if (!irccmp(parv[i], "list"))
-                       list_users = YES;
+                       list_users = true;
                else if (!irccmp(parv[i], "global"))
                        target_list = &global_client_list;
                else if (i < (parc - 1))
@@ -171,19 +173,29 @@ scan_umodes(struct Client *client_p, struct Client *source_p, int parc,
                                list_max = atoi(parv[++i]);
                        else if (!irccmp(parv[i], "mask"))
                                mask = parv[++i];
+                       else
+                       {
+                               sendto_one_notice(source_p, ":SCAN UMODES: invalid parameters");
+                               return;
+                       }
+               }
+               else
+               {
+                       sendto_one_notice(source_p, ":SCAN UMODES: invalid parameters");
+                       return;
                }
        }
-       if (target_list == &global_client_list && (list_users || mask))
+       if (target_list == &global_client_list && list_users)
        {
                if (IsOperSpy(source_p))
                {
                        if (!ConfigFileEntry.operspy_dont_care_user_info)
                        {
-                               strlcpy(buf, "UMODES", sizeof buf);
+                               rb_strlcpy(buf, "UMODES", sizeof buf);
                                for (i = 2; i < parc; i++)
                                {
-                                       strlcat(buf, " ", sizeof buf);
-                                       strlcat(buf, parv[i], sizeof buf);
+                                       rb_strlcat(buf, " ", sizeof buf);
+                                       rb_strlcat(buf, parv[i], sizeof buf);
                                }
                                report_operspy(source_p, "SCAN", buf);
                        }
@@ -192,7 +204,7 @@ scan_umodes(struct Client *client_p, struct Client *source_p, int parc,
                {
                        sendto_one(source_p, form_str(ERR_NOPRIVS),
                                   me.name, source_p->name, "oper_spy");
-                       return -1;
+                       return;
                }
        }
 
@@ -225,7 +237,7 @@ scan_umodes(struct Client *client_p, struct Client *source_p, int parc,
 
                if (mask != NULL)
                {
-                       ircsnprintf(maskbuf, BUFSIZE, "%s!%s@%s",
+                       snprintf(maskbuf, BUFSIZE, "%s!%s@%s",
                                target_p->name, target_p->username, target_p->host);
 
                        if (!match(mask, maskbuf))
@@ -252,7 +264,7 @@ scan_umodes(struct Client *client_p, struct Client *source_p, int parc,
                        sendto_one_numeric(source_p, RPL_SCANUMODES,
                                                form_str(RPL_SCANUMODES),
                                                target_p->name, target_p->username,
-                                               target_p->host, sockhost, 
+                                               target_p->host, sockhost,
                                                target_p->servptr->name, modebuf,
                                                target_p->info);
                }
@@ -261,6 +273,4 @@ scan_umodes(struct Client *client_p, struct Client *source_p, int parc,
 
        sendto_one_numeric(source_p, RPL_SCANMATCHED,
                        form_str(RPL_SCANMATCHED), count);
-
-       return 0;
 }