Generate the "Temporary K-line %d min" part from aconf->hold - aconf->created.

This commit is contained in:
Jilles Tjoelker 2010-02-28 16:27:06 +01:00
parent ce60772db6
commit 157c1f04bd
6 changed files with 37 additions and 63 deletions

View 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 **);

View 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,

View 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)
{

View 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

View 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';

View 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;