[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Anti-Nick-Flood (ANF) patch



Hi,

the following patch adds a delay of 5 seconds between two consecutive nick
changes, which means that you have to wait at least 5 seconds before you can
again change your nick after a previous nick change...
This should make nick flooding impossible (nick floods by the same user).

I've tested it locally in a mini-network (2 servers) - it worked fine.

The patch is diff'ed against 2.9.3b12.

Bye, Kasi

--- cut here ---
diff -cr irc2.9.3b12.old/include/numeric.h irc2.9.3b12/include/numeric.h
*** irc2.9.3b12.old/include/numeric.h	Mon Jul  1 14:28:12 1996
--- irc2.9.3b12/include/numeric.h	Sat Apr  5 13:05:29 1997
***************
*** 18,23 ****
--- 18,29 ----
   */
  
  /*
+  * -- Kasi -- 5 Apr 1997
+  *
+  * Added ERR_NICKCHANGEDELAY
+  */
+ 
+ /*
   * -- Avalon -- 1 Sep 1992
   *
   * Added RPL_TRACELOG, RPL_STATSOLINE
***************
*** 158,163 ****
--- 164,170 ----
  #define	ERR_NICKCOLLISION    436
  #define ERR_UNAVAILRESOURCE  437
  /* #define ERR_DEAD    438  reserved for later use -krys */
+ #define ERR_NICKCHANGEDELAY  439
  
  #define ERR_USERNOTINCHANNEL 441
  #define ERR_NOTONCHANNEL     442
diff -cr irc2.9.3b12.old/include/struct.h irc2.9.3b12/include/struct.h
*** irc2.9.3b12.old/include/struct.h	Mon Mar 24 15:38:31 1997
--- irc2.9.3b12/include/struct.h	Sat Apr  5 15:53:29 1997
***************
*** 378,383 ****
--- 378,384 ----
  	Link	*uwas;		/* chain of whowas pointer blocks */
  	char	*away;		/* pointer to away message */
  	time_t	last;
+ 	time_t  last_changed;   /* time of the last nick change */
  	int	refcnt;		/* Number of times this block is referenced
  				** from aClient (field user), aServer (field
  				** by) and whowas array (field ww_user).
diff -cr irc2.9.3b12.old/ircd/s_err.c irc2.9.3b12/ircd/s_err.c
*** irc2.9.3b12.old/ircd/s_err.c	Tue Mar 18 15:09:05 1997
--- irc2.9.3b12/ircd/s_err.c	Sat Apr  5 13:20:38 1997
***************
*** 80,88 ****
  /* 437 */	ERR_UNAVAILRESOURCE,
  		"%s :Nick/channel is temporarily unavailable",
  /* 438 */	0, (char *)NULL, /* reserved for later use -krys */
! 		0, (char *)NULL, 0, (char *)NULL,
! 		ERR_USERNOTINCHANNEL, "%s %s :They aren't on that channel",
! 		ERR_NOTONCHANNEL, "%s :You're not on that channel",
  /* 443 */	ERR_USERONCHANNEL, "%s %s :is already on channel",
  /* 444 */	ERR_NOLOGIN, "%s :User not logged in",
  #ifndef	ENABLE_SUMMON
--- 80,90 ----
  /* 437 */	ERR_UNAVAILRESOURCE,
  		"%s :Nick/channel is temporarily unavailable",
  /* 438 */	0, (char *)NULL, /* reserved for later use -krys */
! /* 439 */	ERR_NICKCHANGEDELAY,
! 		":Delayed - try it again after a few seconds",
! 		0, (char *)NULL,
! /* 441 */	ERR_USERNOTINCHANNEL, "%s %s :They aren't on that channel",
! /* 442 */	ERR_NOTONCHANNEL, "%s :You're not on that channel",
  /* 443 */	ERR_USERONCHANNEL, "%s %s :is already on channel",
  /* 444 */	ERR_NOLOGIN, "%s :User not logged in",
  #ifndef	ENABLE_SUMMON
diff -cr irc2.9.3b12.old/ircd/s_user.c irc2.9.3b12/ircd/s_user.c
*** irc2.9.3b12.old/ircd/s_user.c	Thu Mar 27 20:00:16 1997
--- irc2.9.3b12/ircd/s_user.c	Sat Apr  5 15:27:21 1997
***************
*** 611,616 ****
--- 611,617 ----
  	aClient *acptr;
  	int	delayed = 0;
  	char	nick[NICKLEN+2], *s, *user, *host;
+ 	time_t  now; /* current time */
  
  	if (IsService(sptr))
     	    {
***************
*** 623,628 ****
--- 624,644 ----
  		sendto_one(sptr, err_str(ERR_NONICKNAMEGIVEN, parv[0]));
  		return 1;
  	    }
+ 	/*
+ 	** Anti-Nick-Flood (ANF)
+ 	** Check 1. whether it's one of my users, 2. whether the user has
+ 	** already registered, 3. whether it's not the first nick change of
+ 	** that user and finally, whether the last nick change occured at 
+ 	** least 5 seconds before this one.
+ 	** If all is TRUE, send out an error message.
+ 	**                                                            -Kasi
+ 	*/
+ 	if (MyConnect(sptr) && sptr->user && sptr->user->last_changed &&
+ 	    ((time(&now) - sptr->user->last_changed) < 6))
+ 	    {
+ 	        sendto_one(sptr, err_str(ERR_NICKCHANGEDELAY, parv[0]));
+ 		return 1;
+ 	    }
  	if (MyConnect(sptr) && (s = (char *)index(parv[1], '~')))
  		*s = '\0';
  	strncpyzt(nick, parv[1], NICKLEN+1);
***************
*** 888,893 ****
--- 904,911 ----
  					   err_str(ERR_RESTRICTED, nick));
  				return 2;
  			    }
+ 			/* set the time of this nick change */
+ 			sptr->user->last_changed = time(&now);
  		}
  		/*
  		** Client just changing his/her nick. If he/she is
--- cut here ---

-- 
Kaspar Landsberg, <kl@xxxxxxxxxxxxxxx>