Store the creation time of klines and dlines as a time_t instead of as text.

The value 0 indicates the creation time is unknown (currently the case
for bandb).
Also store a creation time for xlines and resvs, but do not use it yet.
This commit is contained in:
Jilles Tjoelker 2010-02-28 00:46:56 +01:00
parent 58c728aed8
commit b52c294986
10 changed files with 65 additions and 36 deletions

View File

@ -61,7 +61,7 @@ extern void inotice(const char *fmt, ...) AFP(1, 2);
extern void iwarn(const char *fmt, ...) AFP(1, 2);
extern void ierror(const char *fmt, ...) AFP(1, 2);
extern void report_operspy(struct Client *, const char *, const char *);
extern const char *smalldate(void);
extern const char *smalldate(time_t);
extern void ilog_error(const char *);
#endif

View File

@ -67,6 +67,7 @@ struct ConfItem
char *user; /* user part of user@host */
int port;
time_t hold; /* Hold action until this time (calendar time) */
time_t created; /* Creation time (for klines etc) */
char *className; /* Name of class */
struct Class *c_class; /* Class of connection */
rb_patricia_node_t *pnode; /* Our patricia node */

View File

@ -214,7 +214,6 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
struct ConfItem *aconf;
char *oper_reason;
char dlbuffer[IRCD_BUFSIZE];
const char *current_date;
struct rb_sockaddr_storage daddr;
int t = AF_INET, ty, b;
const char *creason;
@ -285,10 +284,10 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
}
rb_set_time();
current_date = smalldate();
aconf = make_conf();
aconf->status = CONF_DLINE;
aconf->created = rb_current_time();
aconf->host = rb_strdup(dlhost);
/* Look for an oper reason */
@ -304,8 +303,8 @@ 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 (%s)",
(int) (tdline_time / 60), reason, current_date);
"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);
@ -335,8 +334,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
}
else
{
rb_snprintf(dlbuffer, sizeof(dlbuffer), "%s (%s)", reason, current_date);
aconf->passwd = rb_strdup(dlbuffer);
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

@ -75,9 +75,9 @@ static int valid_wild_card(struct Client *source_p, const char *user, const char
static void handle_remote_kline(struct Client *source_p, int tkline_time,
const char *user, const char *host, const char *reason);
static void apply_kline(struct Client *source_p, struct ConfItem *aconf,
const char *reason, const char *oper_reason, const char *current_date);
const char *reason, const char *oper_reason);
static void apply_tkline(struct Client *source_p, struct ConfItem *aconf,
const char *, const char *, const char *, int);
const char *, const char *, int);
static int already_placed_kline(struct Client *, const char *, const char *, int);
static void handle_remote_unkline(struct Client *source_p, const char *user, const char *host);
@ -101,7 +101,6 @@ mo_kline(struct Client *client_p, struct Client *source_p, int parc, const char
char buffer[IRCD_BUFSIZE];
char *reason = def;
char *oper_reason;
const char *current_date;
const char *target_server = NULL;
struct ConfItem *aconf;
int tkline_time = 0;
@ -169,9 +168,9 @@ mo_kline(struct Client *client_p, struct Client *source_p, int parc, const char
return 0;
rb_set_time();
current_date = smalldate();
aconf = make_conf();
aconf->status = CONF_KILL;
aconf->created = rb_current_time();
aconf->host = rb_strdup(host);
aconf->user = rb_strdup(user);
aconf->port = 0;
@ -189,16 +188,15 @@ 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 (%s)",
(int) (tkline_time / 60), reason, current_date);
"Temporary K-line %d min. - %s",
(int) (tkline_time / 60), reason);
aconf->passwd = rb_strdup(buffer);
apply_tkline(source_p, aconf, reason, oper_reason, current_date, tkline_time);
apply_tkline(source_p, aconf, reason, oper_reason, tkline_time);
}
else
{
rb_snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
aconf->passwd = rb_strdup(buffer);
apply_kline(source_p, aconf, reason, oper_reason, current_date);
aconf->passwd = rb_strdup(reason);
apply_kline(source_p, aconf, reason, oper_reason);
}
if(ConfigFileEntry.kline_delay)
@ -265,7 +263,6 @@ handle_remote_kline(struct Client *source_p, int tkline_time,
const char *user, const char *host, const char *kreason)
{
char buffer[BUFSIZE];
const char *current_date;
char *reason = LOCAL_COPY(kreason);
struct ConfItem *aconf = NULL;
char *oper_reason;
@ -285,6 +282,7 @@ handle_remote_kline(struct Client *source_p, int tkline_time,
aconf = make_conf();
aconf->status = CONF_KILL;
aconf->created = rb_current_time();
aconf->user = rb_strdup(user);
aconf->host = rb_strdup(host);
@ -298,21 +296,18 @@ handle_remote_kline(struct Client *source_p, int tkline_time,
aconf->spasswd = rb_strdup(oper_reason);
}
current_date = smalldate();
if(tkline_time > 0)
{
rb_snprintf(buffer, sizeof(buffer),
"Temporary K-line %d min. - %s (%s)",
(int) (tkline_time / 60), reason, current_date);
"Temporary K-line %d min. - %s",
(int) (tkline_time / 60), reason);
aconf->passwd = rb_strdup(buffer);
apply_tkline(source_p, aconf, reason, oper_reason, current_date, tkline_time);
apply_tkline(source_p, aconf, reason, oper_reason, tkline_time);
}
else
{
rb_snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
aconf->passwd = rb_strdup(buffer);
apply_kline(source_p, aconf, reason, oper_reason, current_date);
aconf->passwd = rb_strdup(reason);
apply_kline(source_p, aconf, reason, oper_reason);
}
if(ConfigFileEntry.kline_delay)
@ -480,7 +475,7 @@ handle_remote_unkline(struct Client *source_p, const char *user, const char *hos
*/
static void
apply_kline(struct Client *source_p, struct ConfItem *aconf,
const char *reason, const char *oper_reason, const char *current_date)
const char *reason, const char *oper_reason)
{
add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf);
bandb_add(BANDB_KLINE, source_p, aconf->user, aconf->host,
@ -517,7 +512,7 @@ apply_kline(struct Client *source_p, struct ConfItem *aconf,
*/
static void
apply_tkline(struct Client *source_p, struct ConfItem *aconf,
const char *reason, const char *oper_reason, const char *current_date, int tkline_time)
const char *reason, const char *oper_reason, int tkline_time)
{
aconf->hold = rb_current_time() + tkline_time;
add_temp_kline(aconf);

View File

@ -218,6 +218,7 @@ parse_resv(struct Client *source_p, const char *name, const char *reason, int te
aconf = make_conf();
aconf->status = CONF_RESV_CHANNEL;
aconf->port = 0;
aconf->created = rb_current_time();
aconf->host = rb_strdup(name);
aconf->passwd = rb_strdup(reason);
add_to_resv_hash(aconf->host, aconf);
@ -281,6 +282,7 @@ parse_resv(struct Client *source_p, const char *name, const char *reason, int te
aconf = make_conf();
aconf->status = CONF_RESV_NICK;
aconf->port = 0;
aconf->created = rb_current_time();
aconf->host = rb_strdup(name);
aconf->passwd = rb_strdup(reason);
rb_dlinkAddAlloc(aconf, &resv_conf_list);

View File

@ -275,6 +275,7 @@ apply_xline(struct Client *source_p, const char *name, const char *reason, int t
aconf = make_conf();
aconf->status = CONF_XLINE;
aconf->created = rb_current_time();
aconf->host = rb_strdup(name);
aconf->passwd = rb_strdup(reason);
collapse(aconf->host);

View File

@ -417,11 +417,20 @@ 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))
{
reason = aconf->passwd;
exit_reason = aconf->passwd;
if(aconf->created)
{
rb_snprintf(reasonbuf, sizeof reasonbuf, "%s (%s)",
aconf->passwd,
smalldate(aconf->created));
reason = reasonbuf;
}
else
reason = aconf->passwd;
exit_reason = reason;
}
else
{

View File

@ -480,6 +480,7 @@ accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, voi
char buf[BUFSIZE];
struct ConfItem *aconf;
static time_t last_oper_notice = 0;
int len;
if(listener->ssl && (!ssl_ok || !get_ssld_count()))
{
@ -519,7 +520,10 @@ accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, voi
if(ConfigFileEntry.dline_with_reason)
{
if (rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd) >= (int)(sizeof(buf)-1))
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);
if (len >= (int)(sizeof(buf)-1))
{
buf[sizeof(buf) - 3] = '\r';
buf[sizeof(buf) - 2] = '\n';

View File

@ -180,7 +180,8 @@ ilog(ilogfile dest, const char *format, ...)
rb_vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
rb_snprintf(buf2, sizeof(buf2), "%s %s\n", smalldate(), buf);
rb_snprintf(buf2, sizeof(buf2), "%s %s\n",
smalldate(rb_current_time()), buf);
if(fputs(buf2, logfile) < 0)
{
@ -266,11 +267,10 @@ report_operspy(struct Client *source_p, const char *token, const char *arg)
}
const char *
smalldate(void)
smalldate(time_t ltime)
{
static char buf[MAX_DATE_STRING];
struct tm *lt;
time_t ltime = rb_current_time();
lt = localtime(&ltime);

View File

@ -305,6 +305,8 @@ 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))
{
@ -375,9 +377,18 @@ verify_access(struct Client *client_p, const char *username)
{
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, aconf->passwd);
me.name, client_p->name, reason);
}
add_reject(client_p, aconf->user, aconf->host);
return (BANNED_CLIENT);
@ -1061,11 +1072,19 @@ get_printable_kline(struct Client *source_p, struct ConfItem *aconf,
char **user, char **oper_reason)
{
static char null[] = "<NULL>";
static char reasonbuf[BUFSIZE];
*host = EmptyString(aconf->host) ? null : aconf->host;
*reason = EmptyString(aconf->passwd) ? null : aconf->passwd;
*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;
}
if(EmptyString(aconf->spasswd) || !IsOper(source_p))
*oper_reason = NULL;
else