]> jfr.im git - solanum.git/blobdiff - modules/m_chghost.c
Merge branch 'master' of github.com:charybdis-ircd/charybdis into elizafox-cleanups
[solanum.git] / modules / m_chghost.c
index fbb9022e80ee426dff520d7081a097807912d985..6694bad4f12b36af83519d7ad28b73882f89f07b 100644 (file)
@@ -10,7 +10,6 @@
  */
 
 #include "stdinc.h"
-#include "tools.h"
 #include "send.h"
 #include "channel.h"
 #include "client.h"
@@ -18,7 +17,6 @@
 #include "config.h"
 #include "ircd.h"
 #include "numeric.h"
-#include "memory.h"
 #include "s_conf.h"
 #include "s_newconf.h"
 #include "s_serv.h"
 #include "msg.h"
 #include "parse.h"
 #include "modules.h"
-#include "sprintf_irc.h"
 #include "whowas.h"
 #include "monitor.h"
 
-static int me_realhost(struct Client *, struct Client *, int, const char **);
-static int ms_chghost(struct Client *, struct Client *, int, const char **);
-static int me_chghost(struct Client *, struct Client *, int, const char **);
-static int mo_chghost(struct Client *, struct Client *, int, const char **);
+static const char chghost_desc[] = "Provides commands used to change and retrieve client hostnames";
+
+static void me_realhost(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void ms_chghost(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void me_chghost(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void mo_chghost(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
 
 struct Message realhost_msgtab = {
-       "REALHOST", 0, 0, 0, MFLG_SLOW,
+       "REALHOST", 0, 0, 0, 0,
        {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_realhost, 2}, mg_ignore}
 };
 
 struct Message chghost_msgtab = {
-       "CHGHOST", 0, 0, 0, MFLG_SLOW,
+       "CHGHOST", 0, 0, 0, 0,
        {mg_ignore, mg_not_oper, {ms_chghost, 3}, {ms_chghost, 3}, {me_chghost, 3}, {mo_chghost, 3}}
 };
 
 mapi_clist_av1 chghost_clist[] = { &chghost_msgtab, &realhost_msgtab, NULL };
 
-DECLARE_MODULE_AV1(chghost, NULL, NULL, chghost_clist, NULL, NULL, "$Revision: 3227 $");
+DECLARE_MODULE_AV2(chghost, NULL, NULL, chghost_clist, NULL, NULL, NULL, NULL, chghost_desc);
 
 /* clean_host()
  *
  * input       - host to check
- * output      - 0 if erroneous, else 0
+ * output      - 0 if erroneous, else 1
  * side effects -
  */
 static int
 clean_host(const char *host)
 {
        int len = 0;
+       const char *last_slash = 0;
+
+       if (*host == '\0' || *host == ':')
+               return 0;
 
        for(; *host; host++)
        {
@@ -67,17 +70,21 @@ clean_host(const char *host)
 
                if(!IsHostChar(*host))
                        return 0;
+               if(*host == '/')
+                       last_slash = host;
        }
 
        if(len > HOSTLEN)
                return 0;
 
+       if(last_slash && IsDigit(last_slash[1]))
+               return 0;
+
        return 1;
 }
 
 /*
  * me_realhost
- * parv[0] = origin
  * parv[1] = real host
  *
  * Yes this contains a little race condition if someone does a whois
@@ -85,21 +92,21 @@ clean_host(const char *host)
  * I don't think that's a big problem as the whole thing is a
  * race condition.
  */
-static int
-me_realhost(struct Client *client_p, struct Client *source_p,
+static void
+me_realhost(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
        int parc, const char *parv[])
 {
        if (!IsPerson(source_p))
-               return 0;
+               return;
 
        del_from_hostname_hash(source_p->orighost, source_p);
-       strlcpy(source_p->orighost, parv[1], sizeof source_p->orighost);
+       rb_strlcpy(source_p->orighost, parv[1], sizeof source_p->orighost);
        if (irccmp(source_p->host, source_p->orighost))
                SetDynSpoof(source_p);
        else
                ClearDynSpoof(source_p);
        add_to_hostname_hash(source_p->orighost, source_p);
-       return 0;
+       return;
 }
 
 static int
@@ -140,18 +147,17 @@ do_chghost(struct Client *source_p, struct Client *target_p,
 
 /*
  * ms_chghost
- * parv[0] = origin
  * parv[1] = target
  * parv[2] = host
  */
-static int
-ms_chghost(struct Client *client_p, struct Client *source_p,
+static void
+ms_chghost(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
        int parc, const char *parv[])
 {
        struct Client *target_p;
 
        if (!(target_p = find_person(parv[1])))
-               return -1;
+               return;
 
        if (do_chghost(source_p, target_p, parv[2], 0))
        {
@@ -161,45 +167,40 @@ ms_chghost(struct Client *client_p, struct Client *source_p,
                sendto_server(client_p, NULL,
                        CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s",
                        use_id(source_p), use_id(target_p), parv[2]);
-               sendto_server(client_p, NULL,
-                       NOCAPS, CAP_TS6, ":%s ENCAP * CHGHOST %s :%s",
-                       source_p->name, target_p->name, parv[2]);
        }
 
-       return 0;
+       return;
 }
 
 /*
  * me_chghost
- * parv[0] = origin
  * parv[1] = target
  * parv[2] = host
  */
-static int
-me_chghost(struct Client *client_p, struct Client *source_p,
+static void
+me_chghost(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
        int parc, const char *parv[])
 {
        struct Client *target_p;
 
        if (!(target_p = find_person(parv[1])))
-               return -1;
+               return;
 
        do_chghost(source_p, target_p, parv[2], 1);
 
-       return 0;
+       return;
 }
 
 /*
  * mo_chghost
- * parv[0] = origin
  * parv[1] = target
  * parv[2] = host
  */
 /* Disable this because of the abuse potential -- jilles
  * No, make it toggleable via ./configure. --nenolod
  */
-static int
-mo_chghost(struct Client *client_p, struct Client *source_p,
+static void
+mo_chghost(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
        int parc, const char *parv[])
 {
 #ifdef ENABLE_OPER_CHGHOST
@@ -209,20 +210,20 @@ mo_chghost(struct Client *client_p, struct Client *source_p,
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS),
                           me.name, source_p->name, "admin");
-               return 0;
+               return;
        }
 
        if (!(target_p = find_named_person(parv[1])))
        {
                sendto_one_numeric(source_p, ERR_NOSUCHNICK,
                                form_str(ERR_NOSUCHNICK), parv[1]);
-               return 0;
+               return;
        }
 
        if (!clean_host(parv[2]))
        {
                sendto_one_notice(source_p, ":Hostname %s is invalid", parv[2]);
-               return 0;
+               return;
        }
 
        do_chghost(source_p, target_p, parv[2], 0);
@@ -233,13 +234,11 @@ mo_chghost(struct Client *client_p, struct Client *source_p,
        sendto_server(NULL, NULL,
                CAP_TS6, CAP_EUID, ":%s ENCAP * CHGHOST %s :%s",
                use_id(source_p), use_id(target_p), parv[2]);
-       sendto_server(NULL, NULL,
-               NOCAPS, CAP_TS6, ":%s ENCAP * CHGHOST %s :%s",
-               source_p->name, target_p->name, parv[2]);
 #else
-       sendto_one_notice(source_p, ":CHGHOST is disabled");
+       sendto_one_numeric(source_p, ERR_DISABLED, form_str(ERR_DISABLED),
+                       "CHGHOST");
 #endif
 
-       return 0;
+       return;
 }