Commits

Anonymous committed e1aa5bf

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.

  • Participants
  • Parent commits 8a58f1e

Comments (0)

Files changed (10)

File include/logger.h

 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

File include/s_conf.h

 	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 */

File modules/m_dline.c

 	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;
 	}
 
 	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 */
 	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);
 	}
 	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,

File modules/m_kline.c

 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);
 	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;
 		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;
 	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)
 		    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;
 	aconf = make_conf();
 
 	aconf->status = CONF_KILL;
+	aconf->created = rb_current_time();
 	aconf->user = rb_strdup(user);
 	aconf->host = rb_strdup(host);
 
 			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)
  */
 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,
  */
 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);

File modules/m_resv.c

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

File modules/m_xline.c

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

File src/client.c

 	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
 	{

File src/listener.c

 	char buf[BUFSIZE];
 	struct ConfItem *aconf;
 	static time_t last_oper_notice = 0;
+	int len;
 
 	if(listener->ssl && (!ssl_ok || !get_ssld_count()))
 	{
 			
 		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';

File src/logger.c

 	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)
 	{
 }
 
 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);
 

File src/s_conf.c

 {
 	struct ConfItem *aconf;
 	char non_ident[USERLEN + 1];
+	char reasonbuf[BUFSIZE];
+	char *reason;
 
 	if(IsGotId(client_p))
 	{
 	{
 		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);
 		    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;
-	*user = EmptyString(aconf->user) ? null : aconf->user;
+	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;