]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - modules/m_xline.c
Change xlines to store spaces as \s.
[irc/rqf/shadowircd.git] / modules / m_xline.c
index 5264fb92af7a075b8040cfcbcc150fb100900073..1aff1c9b51351e20ba147379cfca587f2a6d7fe7 100644 (file)
@@ -31,7 +31,6 @@
  */
 
 #include "stdinc.h"
-#include "tools.h"
 #include "send.h"
 #include "channel.h"
 #include "client.h"
 #include "class.h"
 #include "ircd.h"
 #include "numeric.h"
-#include "memory.h"
-#include "s_log.h"
+#include "logger.h"
 #include "s_serv.h"
 #include "whowas.h"
-#include "irc_string.h"
-#include "sprintf_irc.h"
+#include "match.h"
 #include "hash.h"
 #include "msg.h"
 #include "parse.h"
 #include "modules.h"
 #include "s_conf.h"
 #include "s_newconf.h"
+#include "reject.h"
 
 static int mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
 static int ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
@@ -86,7 +84,7 @@ static void handle_remote_xline(struct Client *source_p, int temp_time,
                                const char *name, const char *reason);
 static void handle_remote_unxline(struct Client *source_p, const char *name);
 
-static int remove_xline(struct Client *source_p, const char *name);
+static void remove_xline(struct Client *source_p, const char *name);
 static int remove_xline_from_file(struct Client *source_p, const char *gecos);
 
 
@@ -153,7 +151,7 @@ mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char
                if(!match(target_server, me.name))
                        return 0;
        }
-       else if(dlink_list_length(&cluster_conf_list) > 0)
+       else if(rb_dlink_list_length(&cluster_conf_list) > 0)
                cluster_xline(source_p, temp_time, name, reason);
 
        if((aconf = find_xline_mask(name)) != NULL)
@@ -178,8 +176,8 @@ mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char
 static int
 ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
-       /* parv[0]  parv[1]      parv[2]  parv[3]  parv[4]
-        * oper     target serv  xline    type     reason
+       /* source_p  parv[1]      parv[2]  parv[3]  parv[4]
+        * oper      target serv  xline    type     reason
         */
        propagate_xline(source_p, parv[1], 0, parv[2], parv[3], parv[4]);
 
@@ -282,47 +280,13 @@ apply_xline(struct Client *source_p, const char *name, const char *reason,
        aconf = make_conf();
        aconf->status = CONF_XLINE;
 
-       if(strstr(name, "\\s"))
-       {
-               char *tmp = LOCAL_COPY(name);
-               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';
-               DupString(aconf->name, tmp);
-       }
-       else
-               DupString(aconf->name, name);
-
-       DupString(aconf->passwd, reason);
+       aconf->name = rb_strdup(name);
+       aconf->passwd = rb_strdup(reason);
        collapse(aconf->name);
 
        if(temp_time > 0)
        {
-               aconf->hold = CurrentTime + temp_time;
+               aconf->hold = rb_current_time() + temp_time;
 
                sendto_realops_snomask(SNO_GENERAL, L_ALL,
                             "%s added temporary %d min. X-Line for [%s] [%s]",
@@ -346,7 +310,7 @@ apply_xline(struct Client *source_p, const char *name, const char *reason,
                        get_oper_name(source_p), name, reason);
        }
 
-       dlinkAddAlloc(aconf, &xline_conf_list);
+       rb_dlinkAddAlloc(aconf, &xline_conf_list);
        check_xlines();
 }
 
@@ -372,9 +336,9 @@ write_xline(struct Client *source_p, struct ConfItem *aconf)
                return;
        }
 
-       ircsprintf(buffer, "\"%s\",\"0\",\"%s\",\"%s\",%ld\n",
+       rb_sprintf(buffer, "\"%s\",\"0\",\"%s\",\"%s\",%ld\n",
                   aconf->name, aconf->passwd,
-                  get_oper_name(source_p), CurrentTime);
+                  get_oper_name(source_p), (long) rb_current_time());
 
        if(fputs(buffer, out) == -1)
        {
@@ -417,9 +381,9 @@ cluster_xline(struct Client *source_p, int temp_time, const char *name,
                const char *reason)
 {
        struct remote_conf *shared_p;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
 
-       DLINK_FOREACH(ptr, cluster_conf_list.head)
+       RB_DLINK_FOREACH(ptr, cluster_conf_list.head)
        {
                shared_p = ptr->data;
 
@@ -474,7 +438,7 @@ mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const cha
                if(match(parv[3], me.name) == 0)
                        return 0;
        }
-       else if(dlink_list_length(&cluster_conf_list))
+       else if(rb_dlink_list_length(&cluster_conf_list))
                cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER,
                                "%s", parv[1]);
 
@@ -490,8 +454,8 @@ mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const cha
 static int
 ms_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
-       /* parv[0]  parv[1]        parv[2]
-        * oper     target server  gecos
+       /* source_p  parv[1]        parv[2]
+        * oper      target server  gecos
         */
        propagate_generic(source_p, "UNXLINE", parv[1], CAP_CLUSTER,
                        "%s", parv[2]);
@@ -529,47 +493,53 @@ handle_remote_unxline(struct Client *source_p, const char *name)
        return;
 }
 
-static int
+static void
 remove_xline(struct Client *source_p, const char *name)
 {
        struct ConfItem *aconf;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
+       char *encoded;
+
+       encoded = xline_encode_spaces(name);
 
-       DLINK_FOREACH(ptr, xline_conf_list.head)
+       RB_DLINK_FOREACH(ptr, xline_conf_list.head)
        {
                aconf = ptr->data;
 
-               if(!irccmp(aconf->name, name))
+               if(!irccmp(aconf->name, encoded))
                {
                        if (!aconf->hold)
                        {
-                               if (!remove_xline_from_file(source_p, name))
-                                       return 0;
+                               if (!remove_xline_from_file(source_p, encoded))
+                                       return;
                        }
                        else
                        {
                                sendto_one_notice(source_p, 
                                                ":X-Line for [%s] is removed",
-                                               name);
+                                               encoded);
                                sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                                "%s has removed the temporary X-Line for: [%s]",
-                                               get_oper_name(source_p), name);
+                                               get_oper_name(source_p), encoded);
                                ilog(L_KLINE, "UX %s %s", 
-                                               get_oper_name(source_p), name);
+                                               get_oper_name(source_p), encoded);
                        }
                        
+                       remove_reject_mask(aconf->name, NULL);
                        free_conf(aconf);
-                       dlinkDestroy(ptr, &xline_conf_list);
-                       return 1;
+                       rb_dlinkDestroy(ptr, &xline_conf_list);
+                       rb_free(encoded);
+                       return;
                }
        }
 
-       sendto_one_notice(source_p, ":No X-Line for %s", name);
+       sendto_one_notice(source_p, ":No X-Line for %s", encoded);
+       rb_free(encoded);
 
-       return 0;
+       return;
 }
 
-/* remove_xline()
+/* remove_xline_from_file()
  *
  * inputs      - gecos to remove
  * outputs     - 
@@ -587,11 +557,12 @@ remove_xline_from_file(struct Client *source_p, const char *huntgecos)
        const char *gecos;
        mode_t oldumask;
        char *p;
+       char *encoded;
        int error_on_write = 0;
        int found_xline = 0;
 
        filename = ConfigFileEntry.xlinefile;
-       ircsnprintf(temppath, sizeof(temppath),
+       rb_snprintf(temppath, sizeof(temppath),
                 "%s.tmp", ConfigFileEntry.xlinefile);
 
        if((in = fopen(filename, "r")) == NULL)
@@ -622,7 +593,7 @@ remove_xline_from_file(struct Client *source_p, const char *huntgecos)
                        break;
                }
 
-               strlcpy(buff, buf, sizeof(buff));
+               rb_strlcpy(buff, buf, sizeof(buff));
 
                if((p = strchr(buff, '\n')) != NULL)
                        *p = '\0';
@@ -640,10 +611,12 @@ remove_xline_from_file(struct Client *source_p, const char *huntgecos)
                }
 
                /* matching.. */
-               if(irccmp(gecos, huntgecos) == 0)
+               encoded = xline_encode_spaces(gecos);
+               if(irccmp(encoded, huntgecos) == 0)
                        found_xline++;
                else
                        error_on_write = (fputs(buf, out) < 0) ? YES : NO;
+               rb_free(encoded);
        }
 
        fclose(in);