]> jfr.im git - irc/rqf/shadowircd.git/commitdiff
Generate the "Temporary K-line %d min" part from aconf->hold - aconf->created.
authorJilles Tjoelker <redacted>
Sun, 28 Feb 2010 15:27:06 +0000 (16:27 +0100)
committerJilles Tjoelker <redacted>
Sun, 28 Feb 2010 15:27:06 +0000 (16:27 +0100)
include/s_conf.h
modules/m_dline.c
modules/m_kline.c
src/client.c
src/listener.c
src/s_conf.c

index 6ca99941ffdbb7c7e9fe0bfcf494dd30d72488f1..4dbdd6030848e6b464b9480882d669db8af0ff72 100644 (file)
@@ -349,6 +349,7 @@ extern struct ConfItem *find_tkline(const char *, const char *, struct sockaddr
 extern char *show_iline_prefix(struct Client *, struct ConfItem *, char *);
 extern void get_printable_conf(struct ConfItem *,
                               char **, char **, char **, char **, int *, char **);
+extern char *get_user_ban_reason(struct ConfItem *aconf);
 extern void get_printable_kline(struct Client *, struct ConfItem *,
                                char **, char **, char **, char **);
 
index 64e5f34516214084e26ab229115f7778f95cd06b..912091c250c921566fbf81d865b7e56743bca836 100644 (file)
@@ -213,7 +213,6 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
 {
        struct ConfItem *aconf;
        char *oper_reason;
-       char dlbuffer[IRCD_BUFSIZE];
        struct rb_sockaddr_storage daddr;
        int t = AF_INET, ty, b;
        const char *creason;
@@ -289,6 +288,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
        aconf->status = CONF_DLINE;
        aconf->created = rb_current_time();
        aconf->host = rb_strdup(dlhost);
+       aconf->passwd = rb_strdup(reason);
 
        /* Look for an oper reason */
        if((oper_reason = strchr(reason, '|')) != NULL)
@@ -302,10 +302,6 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
 
        if(tdline_time > 0)
        {
-               rb_snprintf(dlbuffer, sizeof(dlbuffer),
-                           "Temporary D-line %d min. - %s",
-                           (int) (tdline_time / 60), reason);
-               aconf->passwd = rb_strdup(dlbuffer);
                aconf->hold = rb_current_time() + tdline_time;
                add_temp_dline(aconf);
 
@@ -334,7 +330,6 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
        }
        else
        {
-               aconf->passwd = rb_strdup(reason);
                add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf);
 
                bandb_add(BANDB_DLINE, source_p, aconf->host, NULL,
index 8e72860b418304e8dadfeeee6b3231bfa8000335..18dbdca7738dd2619339a7ffcbc4a3544bfa308f 100644 (file)
@@ -98,7 +98,6 @@ mo_kline(struct Client *client_p, struct Client *source_p, int parc, const char
        char def[] = "No Reason";
        char user[USERLEN + 2];
        char host[HOSTLEN + 2];
-       char buffer[IRCD_BUFSIZE];
        char *reason = def;
        char *oper_reason;
        const char *target_server = NULL;
@@ -174,6 +173,7 @@ mo_kline(struct Client *client_p, struct Client *source_p, int parc, const char
        aconf->host = rb_strdup(host);
        aconf->user = rb_strdup(user);
        aconf->port = 0;
+       aconf->passwd = rb_strdup(reason);
 
        /* Look for an oper reason */
        if((oper_reason = strchr(reason, '|')) != NULL)
@@ -186,18 +186,9 @@ mo_kline(struct Client *client_p, struct Client *source_p, int parc, const char
        }
 
        if(tkline_time > 0)
-       {
-               rb_snprintf(buffer, sizeof(buffer),
-                           "Temporary K-line %d min. - %s",
-                           (int) (tkline_time / 60), reason);
-               aconf->passwd = rb_strdup(buffer);
                apply_tkline(source_p, aconf, reason, oper_reason, tkline_time);
-       }
        else
-       {
-               aconf->passwd = rb_strdup(reason);
                apply_kline(source_p, aconf, reason, oper_reason);
-       }
 
        if(ConfigFileEntry.kline_delay)
        {
@@ -262,7 +253,6 @@ static void
 handle_remote_kline(struct Client *source_p, int tkline_time,
                    const char *user, const char *host, const char *kreason)
 {
-       char buffer[BUFSIZE];
        char *reason = LOCAL_COPY(kreason);
        struct ConfItem *aconf = NULL;
        char *oper_reason;
@@ -285,6 +275,7 @@ handle_remote_kline(struct Client *source_p, int tkline_time,
        aconf->created = rb_current_time();
        aconf->user = rb_strdup(user);
        aconf->host = rb_strdup(host);
+       aconf->passwd = rb_strdup(reason);
 
        /* Look for an oper reason */
        if((oper_reason = strchr(reason, '|')) != NULL)
@@ -297,18 +288,9 @@ handle_remote_kline(struct Client *source_p, int tkline_time,
        }
 
        if(tkline_time > 0)
-       {
-               rb_snprintf(buffer, sizeof(buffer),
-                           "Temporary K-line %d min. - %s",
-                           (int) (tkline_time / 60), reason);
-               aconf->passwd = rb_strdup(buffer);
                apply_tkline(source_p, aconf, reason, oper_reason, tkline_time);
-       }
        else
-       {
-               aconf->passwd = rb_strdup(reason);
                apply_kline(source_p, aconf, reason, oper_reason);
-       }
 
        if(ConfigFileEntry.kline_delay)
        {
index 816a5d2320491ee8a5f15dc0801d2e0911c1dc0c..534bec2860a2e92ad67cd83af392d5743153b354 100644 (file)
@@ -423,19 +423,10 @@ notify_banned_client(struct Client *client_p, struct ConfItem *aconf, int ban)
        static const char k_lined[] = "K-lined";
        const char *reason = NULL;
        const char *exit_reason = conn_closed;
-       char reasonbuf[BUFSIZE];
 
-       if(ConfigFileEntry.kline_with_reason && !EmptyString(aconf->passwd))
+       if(ConfigFileEntry.kline_with_reason)
        {
-               if(aconf->created)
-               {
-                       rb_snprintf(reasonbuf, sizeof reasonbuf, "%s (%s)",
-                                       aconf->passwd,
-                                       smalldate(aconf->created));
-                       reason = reasonbuf;
-               }
-               else
-                       reason = aconf->passwd;
+               reason = get_user_ban_reason(aconf);
                exit_reason = reason;
        }
        else
index 1ac42b02debee324c4a9087b8150c751ee4920c0..3b8a1fbc83d1d2bcc67514922837cd6ddbc56ce8 100644 (file)
@@ -520,9 +520,7 @@ accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, voi
                        
                if(ConfigFileEntry.dline_with_reason)
                {
-                       len = aconf->created ?
-                               rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s (%s)\r\n", aconf->passwd, smalldate(aconf->created)) :
-                               rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd);
+                       len = rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", get_user_ban_reason(aconf));
                        if (len >= (int)(sizeof(buf)-1))
                        {
                                buf[sizeof(buf) - 3] = '\r';
index ae83d7aa8c7df7f869292d60e990d03df7b8f009..c3df6fd04d06b982d2acec9a8666cbc305fa97ea 100644 (file)
@@ -306,8 +306,6 @@ verify_access(struct Client *client_p, const char *username)
 {
        struct ConfItem *aconf;
        char non_ident[USERLEN + 1];
-       char reasonbuf[BUFSIZE];
-       char *reason;
 
        if(IsGotId(client_p))
        {
@@ -377,20 +375,10 @@ verify_access(struct Client *client_p, const char *username)
        else if(aconf->status & CONF_KILL)
        {
                if(ConfigFileEntry.kline_with_reason)
-               {
-                       if(aconf->created)
-                       {
-                               snprintf(reasonbuf, sizeof reasonbuf, "%s (%s)",
-                                               aconf->passwd,
-                                               smalldate(aconf->created));
-                               reason = reasonbuf;
-                       }
-                       else
-                               reason = aconf->passwd;
                        sendto_one(client_p,
                                        form_str(ERR_YOUREBANNEDCREEP),
-                                       me.name, client_p->name, reason);
-               }
+                                       me.name, client_p->name,
+                                       get_user_ban_reason(aconf));
                add_reject(client_p, aconf->user, aconf->host);
                return (BANNED_CLIENT);
        }
@@ -1135,24 +1123,43 @@ get_printable_conf(struct ConfItem *aconf, char **name, char **host,
        *port = (int) aconf->port;
 }
 
+char *
+get_user_ban_reason(struct ConfItem *aconf)
+{
+       static char reasonbuf[BUFSIZE];
+
+       if (aconf->flags & CONF_FLAGS_TEMPORARY &&
+                       (aconf->status == CONF_KILL || aconf->status == CONF_DLINE))
+               rb_snprintf(reasonbuf, sizeof reasonbuf,
+                               "Temporary %c-line %d min. - ",
+                               aconf->status == CONF_DLINE ? 'D' : 'K',
+                               (aconf->hold - aconf->created) / 60);
+       else
+               reasonbuf[0] = '\0';
+       if (aconf->passwd)
+               rb_strlcat(reasonbuf, aconf->passwd, sizeof reasonbuf);
+       else
+               rb_strlcat(reasonbuf, "No Reason", sizeof reasonbuf);
+       if (aconf->created)
+       {
+               rb_strlcat(reasonbuf, " (", sizeof reasonbuf);
+               rb_strlcat(reasonbuf, smalldate(aconf->created),
+                               sizeof reasonbuf);
+               rb_strlcat(reasonbuf, ")", sizeof reasonbuf);
+       }
+       return reasonbuf;
+}
+
 void
 get_printable_kline(struct Client *source_p, struct ConfItem *aconf, 
                    char **host, char **reason,
                    char **user, char **oper_reason)
 {
        static char null[] = "<NULL>";
-       static char reasonbuf[BUFSIZE];
 
        *host = EmptyString(aconf->host) ? null : aconf->host;
        *user = EmptyString(aconf->user) ? null : aconf->user;
-
-       *reason = EmptyString(aconf->passwd) ? null : aconf->passwd;
-       if(aconf->created)
-       {
-               rb_snprintf(reasonbuf, sizeof reasonbuf, "%s (%s)",
-                               *reason, smalldate(aconf->created));
-               *reason = reasonbuf;
-       }
+       *reason = get_user_ban_reason(aconf);
 
        if(EmptyString(aconf->spasswd) || !IsOper(source_p))
                *oper_reason = NULL;