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 bebc68755d
commit ce60772db6
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 iwarn(const char *fmt, ...) AFP(1, 2);
extern void ierror(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 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 *); extern void ilog_error(const char *);
#endif #endif

View File

@ -69,6 +69,7 @@ struct ConfItem
char *user; /* user part of user@host */ char *user; /* user part of user@host */
int port; int port;
time_t hold; /* Hold action until this time (calendar time) */ time_t hold; /* Hold action until this time (calendar time) */
time_t created; /* Creation time (for klines etc) */
char *className; /* Name of class */ char *className; /* Name of class */
struct Class *c_class; /* Class of connection */ struct Class *c_class; /* Class of connection */
rb_patricia_node_t *pnode; /* Our patricia node */ 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; struct ConfItem *aconf;
char *oper_reason; char *oper_reason;
char dlbuffer[IRCD_BUFSIZE]; char dlbuffer[IRCD_BUFSIZE];
const char *current_date;
struct rb_sockaddr_storage daddr; struct rb_sockaddr_storage daddr;
int t = AF_INET, ty, b; int t = AF_INET, ty, b;
const char *creason; const char *creason;
@ -285,10 +284,10 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
} }
rb_set_time(); rb_set_time();
current_date = smalldate();
aconf = make_conf(); aconf = make_conf();
aconf->status = CONF_DLINE; aconf->status = CONF_DLINE;
aconf->created = rb_current_time();
aconf->host = rb_strdup(dlhost); aconf->host = rb_strdup(dlhost);
/* Look for an oper reason */ /* 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) if(tdline_time > 0)
{ {
rb_snprintf(dlbuffer, sizeof(dlbuffer), rb_snprintf(dlbuffer, sizeof(dlbuffer),
"Temporary D-line %d min. - %s (%s)", "Temporary D-line %d min. - %s",
(int) (tdline_time / 60), reason, current_date); (int) (tdline_time / 60), reason);
aconf->passwd = rb_strdup(dlbuffer); aconf->passwd = rb_strdup(dlbuffer);
aconf->hold = rb_current_time() + tdline_time; aconf->hold = rb_current_time() + tdline_time;
add_temp_dline(aconf); add_temp_dline(aconf);
@ -335,8 +334,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
} }
else else
{ {
rb_snprintf(dlbuffer, sizeof(dlbuffer), "%s (%s)", reason, current_date); aconf->passwd = rb_strdup(reason);
aconf->passwd = rb_strdup(dlbuffer);
add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf); add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf);
bandb_add(BANDB_DLINE, source_p, aconf->host, NULL, 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, static void handle_remote_kline(struct Client *source_p, int tkline_time,
const char *user, const char *host, const char *reason); const char *user, const char *host, const char *reason);
static void apply_kline(struct Client *source_p, struct ConfItem *aconf, 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, 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 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); 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 buffer[IRCD_BUFSIZE];
char *reason = def; char *reason = def;
char *oper_reason; char *oper_reason;
const char *current_date;
const char *target_server = NULL; const char *target_server = NULL;
struct ConfItem *aconf; struct ConfItem *aconf;
int tkline_time = 0; int tkline_time = 0;
@ -169,9 +168,9 @@ mo_kline(struct Client *client_p, struct Client *source_p, int parc, const char
return 0; return 0;
rb_set_time(); rb_set_time();
current_date = smalldate();
aconf = make_conf(); aconf = make_conf();
aconf->status = CONF_KILL; aconf->status = CONF_KILL;
aconf->created = rb_current_time();
aconf->host = rb_strdup(host); aconf->host = rb_strdup(host);
aconf->user = rb_strdup(user); aconf->user = rb_strdup(user);
aconf->port = 0; 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) if(tkline_time > 0)
{ {
rb_snprintf(buffer, sizeof(buffer), rb_snprintf(buffer, sizeof(buffer),
"Temporary K-line %d min. - %s (%s)", "Temporary K-line %d min. - %s",
(int) (tkline_time / 60), reason, current_date); (int) (tkline_time / 60), reason);
aconf->passwd = rb_strdup(buffer); 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 else
{ {
rb_snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date); aconf->passwd = rb_strdup(reason);
aconf->passwd = rb_strdup(buffer); apply_kline(source_p, aconf, reason, oper_reason);
apply_kline(source_p, aconf, reason, oper_reason, current_date);
} }
if(ConfigFileEntry.kline_delay) 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) const char *user, const char *host, const char *kreason)
{ {
char buffer[BUFSIZE]; char buffer[BUFSIZE];
const char *current_date;
char *reason = LOCAL_COPY(kreason); char *reason = LOCAL_COPY(kreason);
struct ConfItem *aconf = NULL; struct ConfItem *aconf = NULL;
char *oper_reason; char *oper_reason;
@ -285,6 +282,7 @@ handle_remote_kline(struct Client *source_p, int tkline_time,
aconf = make_conf(); aconf = make_conf();
aconf->status = CONF_KILL; aconf->status = CONF_KILL;
aconf->created = rb_current_time();
aconf->user = rb_strdup(user); aconf->user = rb_strdup(user);
aconf->host = rb_strdup(host); 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); aconf->spasswd = rb_strdup(oper_reason);
} }
current_date = smalldate();
if(tkline_time > 0) if(tkline_time > 0)
{ {
rb_snprintf(buffer, sizeof(buffer), rb_snprintf(buffer, sizeof(buffer),
"Temporary K-line %d min. - %s (%s)", "Temporary K-line %d min. - %s",
(int) (tkline_time / 60), reason, current_date); (int) (tkline_time / 60), reason);
aconf->passwd = rb_strdup(buffer); 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 else
{ {
rb_snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date); aconf->passwd = rb_strdup(reason);
aconf->passwd = rb_strdup(buffer); apply_kline(source_p, aconf, reason, oper_reason);
apply_kline(source_p, aconf, reason, oper_reason, current_date);
} }
if(ConfigFileEntry.kline_delay) if(ConfigFileEntry.kline_delay)
@ -480,7 +475,7 @@ handle_remote_unkline(struct Client *source_p, const char *user, const char *hos
*/ */
static void static void
apply_kline(struct Client *source_p, struct ConfItem *aconf, 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); add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf);
bandb_add(BANDB_KLINE, source_p, aconf->user, aconf->host, 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 static void
apply_tkline(struct Client *source_p, struct ConfItem *aconf, 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; aconf->hold = rb_current_time() + tkline_time;
add_temp_kline(aconf); 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 = make_conf();
aconf->status = CONF_RESV_CHANNEL; aconf->status = CONF_RESV_CHANNEL;
aconf->port = 0; aconf->port = 0;
aconf->created = rb_current_time();
aconf->host = rb_strdup(name); aconf->host = rb_strdup(name);
aconf->passwd = rb_strdup(reason); aconf->passwd = rb_strdup(reason);
add_to_resv_hash(aconf->host, aconf); 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 = make_conf();
aconf->status = CONF_RESV_NICK; aconf->status = CONF_RESV_NICK;
aconf->port = 0; aconf->port = 0;
aconf->created = rb_current_time();
aconf->host = rb_strdup(name); aconf->host = rb_strdup(name);
aconf->passwd = rb_strdup(reason); aconf->passwd = rb_strdup(reason);
rb_dlinkAddAlloc(aconf, &resv_conf_list); 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 = make_conf();
aconf->status = CONF_XLINE; aconf->status = CONF_XLINE;
aconf->created = rb_current_time();
aconf->host = rb_strdup(name); aconf->host = rb_strdup(name);
aconf->passwd = rb_strdup(reason); aconf->passwd = rb_strdup(reason);
collapse(aconf->host); collapse(aconf->host);

View File

@ -423,11 +423,20 @@ notify_banned_client(struct Client *client_p, struct ConfItem *aconf, int ban)
static const char k_lined[] = "K-lined"; static const char k_lined[] = "K-lined";
const char *reason = NULL; const char *reason = NULL;
const char *exit_reason = conn_closed; const char *exit_reason = conn_closed;
char reasonbuf[BUFSIZE];
if(ConfigFileEntry.kline_with_reason && !EmptyString(aconf->passwd)) if(ConfigFileEntry.kline_with_reason && !EmptyString(aconf->passwd))
{ {
if(aconf->created)
{
rb_snprintf(reasonbuf, sizeof reasonbuf, "%s (%s)",
aconf->passwd,
smalldate(aconf->created));
reason = reasonbuf;
}
else
reason = aconf->passwd; reason = aconf->passwd;
exit_reason = aconf->passwd; exit_reason = reason;
} }
else else
{ {

View File

@ -480,6 +480,7 @@ accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, voi
char buf[BUFSIZE]; char buf[BUFSIZE];
struct ConfItem *aconf; struct ConfItem *aconf;
static time_t last_oper_notice = 0; static time_t last_oper_notice = 0;
int len;
if(listener->ssl && (!ssl_ok || !get_ssld_count())) 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(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) - 3] = '\r';
buf[sizeof(buf) - 2] = '\n'; buf[sizeof(buf) - 2] = '\n';

View File

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

View File

@ -306,6 +306,8 @@ verify_access(struct Client *client_p, const char *username)
{ {
struct ConfItem *aconf; struct ConfItem *aconf;
char non_ident[USERLEN + 1]; char non_ident[USERLEN + 1];
char reasonbuf[BUFSIZE];
char *reason;
if(IsGotId(client_p)) if(IsGotId(client_p))
{ {
@ -376,9 +378,18 @@ verify_access(struct Client *client_p, const char *username)
{ {
if(ConfigFileEntry.kline_with_reason) 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, sendto_one(client_p,
form_str(ERR_YOUREBANNEDCREEP), 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); add_reject(client_p, aconf->user, aconf->host);
return (BANNED_CLIENT); return (BANNED_CLIENT);
@ -1130,11 +1141,19 @@ get_printable_kline(struct Client *source_p, struct ConfItem *aconf,
char **user, char **oper_reason) char **user, char **oper_reason)
{ {
static char null[] = "<NULL>"; static char null[] = "<NULL>";
static char reasonbuf[BUFSIZE];
*host = EmptyString(aconf->host) ? null : aconf->host; *host = EmptyString(aconf->host) ? null : aconf->host;
*reason = EmptyString(aconf->passwd) ? null : aconf->passwd;
*user = EmptyString(aconf->user) ? null : aconf->user; *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)) if(EmptyString(aconf->spasswd) || !IsOper(source_p))
*oper_reason = NULL; *oper_reason = NULL;
else else